I have a service in my application to listen to mouse pointer actions, save them and replay saved actions. It replays saved items based on the pointer offset saved for the recorded screensize
On replaying in different screensize, I have a helper function to calculate the delta of the offset for the new screensize.
adjustForScreenSize(MouseEventRecord record, double newWidth, double newHeight) {
double widthRatio = newWidth / record.screenWidth;
double heightRatio = newHeight / record.screenHeight;
double adjustedX = record.xPointer * widthRatio;
double adjustedY = record.yPointer * heightRatio;
double? adjustedXOffset = record.xOffset != null ? record.xOffset! * widthRatio : null;
double? adjustedYOffset = record.yOffset != null ? record.yOffset! * heightRatio : null;
return MouseEventRecord(
xPointer: adjustedX,
yPointer: adjustedY,
xOffset: adjustedXOffset,
yOffset: adjustedYOffset,
screenWidth: newWidth,
screenHeight: newHeight,
);
}
But this is not consistent in transforming the pointer offset. Let me know if I am missing anything
New contributor
Balamurugan Ilangovan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.