# Accurate canvas coordinate on HiDPI screen

I think I’m missing something - but I’m trying to get accurate mouse coordinates from a canvas on a HiDPI screen when displaying an image generated with BitmapForCaching. Say a canvas 400 x 200 pixels size is displaying an 800 x 400 image, ScaleFactor 2.0 - all looks good and crisp. But the coordinates returned in MouseMove are integers in the ranges X 0-399 and Y 0-199 and so it only gives an XY coordinate for 1 point in the image in every 4. I don’t know which would be more “correct” - but it would be useful either to have a fractional pixel position every 0.5 (for ScaleFactor 2.0 screen) or instead access to the full integer range that relates to the picture, X 0-799 and Y 0-399 in this case.

Getting the colour of the point under the mouse would be a start and there’s a few posts that refer to this, but in many cases the actual coordinate is needed to refer back to an array of data from which the picture was generated.

Many thanks for any insights on this, regards - Richard.

What do you want to do ?

Remember: a Pixel can be different to a Point.

The smallest color on screen is the Red dot / Green dot / Blue dot…

Thanks Emile,

What I’m trying to do is get the exact XY position of the mouse on the canvas. Easy enough from MouseMove, but on a HiDPI screen with an image as I described (800 x 400 drawn into a 400 x 200 canvas) - then MouseMove on the canvas has a range of 0-399 in X and 0-199 in Y. Multiply by the ScaleFactor (2.0) to relate to the original picture’s dimensions - but now there are gaps of 2 so you can only access alternate pixels of the image in X and Y, i.e. so 1 in every 4.

So if I could access either the fractional position within the dimensions of the canvas so X positions would be 0, 0.5, 1.0, 1.5 … 398.5, 399.0, 399.5, or alternatively, integers relative to the original picture so 0, 1, 2, 3…797, 798, 799.

I hope that makes sense.

Regards - Richard.

The mouse coordinates supplied by the OS doesn’t move in half point increments, so you’re not going to get what you want.

1 Like

OK, thanks Greg. I’ll wait and maybe one day it’ll appear.

Regards - Richard.

You’re going to wait a long time. There’s no reason for the OS to provide such a thing. The whole reason for retina displays is to make things look better while still behaving like a 1x screen.

I still do not understand the purpose, but what if you display the image at full resolution (1 screen pixel = 1 image pixel) and display only a part of the image.

In this case, you can get the information you want (probably). And, you may display a reduced view of your image in another window, so you have the whole information (à la GIMP / PhotoShop)…

1 Like

Thats the whole point Emile. Retina screens deal with points where there are multiple pixels per point.

A 1x screen has 1 pixel per point in each direction.

A 2x screen has 2 pixels per point in each direction, but the computer sees it as 1 and computes coordinates as 1.

It’s all about perceived display quality.

I even saw a screen shot I’ve done on a Windows 10 laptop to know the screen size that was 300 dpi !…

Dpi is tricky on screens. With 1x screens, Apple tried to target 72ppi and Microsoft 96ppi. (Pixels per inch). The trouble is that the pixel density of different screens doesn’t always translate to a factor where an inch of screen real estate is an exact number of pixels any more so it’s really hard to quantify.

Anyway, a 2x screen would effectively be 144ppi or 192ppi and a 3x screen would be 216ppi or 288ppi, but the actual screen rez hasn’t actually changed much. Apple and Microsoft both offer a way to use several different scale factors, and expose them differently. On Desktop, the scale factor of a Mac is always 2x on a 4K screen, regardless of the scale you choose, whereas the scale factor on windows is exposed in 25% increments and your X factor can range from 1.00 to 4.00 (1.25, 1.50 … 3.5, 3.75). IMO Xojo does handle these differences pretty well and does keep the concepts pretty consistent, even if the manufacturers are trying to make it hard to create a cross platform solution.

Thanks for your thoughts and replies.

@Greg. “The mouse coordinates supplied by the OS doesn’t move in half point increments…” and “There’s no reason for the OS to provide such a thing…”

Maybe they don’t provide it, but they must measure it or track it in some way - to give the smooth sub-point mouse movement on the screen. And - health warning - if you put your nose and eyes uncomfortably close to the screen and make slight mouse movements - the MouseMove event fires yet X and Y do not necessarily change. On my Win Surface which comes up with ScaleFactor 2.0 so four pixels within each point - as you mouse around the MouseMove event will fire within a given point as you move to one of the other three pixels that make up that point and the X Y coords don’t change (as we’re within the same point) - and then as you move to the adjacent point the X Y coords change as well.

@Emile. “I still do not understand the purpose, but what if you display the image at full resolution (1 screen pixel = 1 image pixel) and display only a part of the image.”

Of course, displaying at 1:1 is the pragmatic solution. I’d just wanted to get the absolute most crisp display, yet be able to ensure exact measurements at the mouse position. It is rather splitting hairs! If there’s features in an image to look at more carefully I’d be zooming in anyhow and have plenty of points and pixels to play with.