ScaleFactorChanged event not firing?

Hi,

It’s the first time I’m dealing with high resolution screens, so I’m still learning.
I need to know when a given window is on a screen with a different scale factor than it was before. While I could use the Moved event, I thought the ScaleFactorChanged event would be more appropriate.

So I tried in a blank project, and the window.ScaleFactorChanged event is never executed, even when I move the window to another screen (I have one “standard” screen and an iPad as the second, high-resolution, screen). The documentation doesn’t mention any “requirement” and is a bit vague. The forum is also empty, as the only threads I found say “the Xojo framework already handles scale factor, just let it do”, which isn’t my case.

Any idea?

How is the scale factor affecting your app?

I have some thoughts, but not an answer. If you would like me to share them let me know, I don’t want to derail your thread.

It’s a kind of drawing desktop app which, until now, I built only on standard-resolution screens (mine). Today, I’ve put my iPad as a second screen (sidecar) to attempt drawing with the pencil and when I move the window to that screen, I’m seeing the drawings occur midway (half coordinates) to where I’m touching with the pencil. Therefore, I need to know on which screen I am to convert the x and y coordinates of the MouseDown/MouseDrag/MouseUp events accordingly to the current scale factor.

Well, I’m always curious about things and never understood why it’s a problem to derive from the original subject in a thread’s forum, so I’m ok with your suggestion :wink:

Thank you.

I don’t know about sidecar (I don’t have an iPad) but I do have 3 monitors at different resolution on my Mac and the event does fire appropriately.

-Karen

With a Canvas / Graphics, you should be automatically getting another Paint event with the appropriate configuration if/when the screen resolution or dark mode state change.

The MouseDown / Drag coordinates should be accurate to the Canvas because Xojo abstracts all of the scaling stuff for us. It seems like a bug with Sidecar that you might not be getting the correct coordinates.

Because the Paint event will always be accurate, I find that I have never needed AppearanceChanged or ScaleFactorChanged.

One needs that for cashed dynamically drawn pictures (vs image sets).

I have done a lot of graphing with ChartDirector which uses Xojo Pictures.

In the ScaleFactorChanged event I NIL the cashed picture of the graph, and when the Paint event detects it is NIL, it recreates the graph picture at the right scale before painting it.

(have not bothered with changing graph colors for dark mode )

-karen

Ok, weird (on my side). Thanks.

Actually, I found the problem, and it was not about getting the correct coordinates, as my bad test tried to tell me.

Turns out my app can already use a scale defined by the user, and I had this code somewhere in the Paint event:

g2.ScaleX=UserScale
g2.ScaleY=UserScale

(UserScale being a double, defaulting to 1). I guess you now get the issue :wink:
The coordinates were actually right and drawing took place correctly, but the drawing was wrong. For my tests, I added a Graphics.DrawRectangle 0,0,100,100 to have a marker. Having forgotten about the UserScale thing, I originally thought the coordinates were wrong (as they are computed). I followed that track so deep that I didn’t see the whole picture (pun intended) and didn’t notice the problem was backward.
My code is now:
g2.ScaleX=UserScaleg.ScaleX
g2.ScaleY=UserScale
g.ScaleY
(g2 is a graphics that can be equal to g, or another source).

The documentation also shows this trick, by the way.

Thanks to your answers; I’ve learnt many things about hi-dpi today.

Just a heads up… There might be a bug somewhere with .height .width of display resolution when using HIDPI screens when scaling is not = 1. See the thread below, which might be applicable to you use-case.

I have not filed a case on this yet as I want to do some more testing on additional machines. In my case, the resolution returned when using HIDPI with scaling is not correct. Geoff did update the documents to indicate when using HIDPI you need to multiply the scaling by the returned .height / .width to get proper screen resolution.

Display Resolution - General - Xojo Programming Forum

Thanks. I’ve already encountered that fact on Windows for another app and have made changes accordingly.