Desktop scaling in conjunction with DPI awareness

Just starting out? Need help? Post your questions and find answers here.
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Desktop scaling in conjunction with DPI awareness

Post by kpeters58 »

Code: Select all

EnableExplicit

Declare DrawColoredBox(NewColor) 

; Windows only (5.71 LTS):
; If the desktop of my PC is scaled to a value > 100%, the canvas and box are of different sizes 
; (canvas is bigger than the box by scale factor)
; This appears to be dependent of the compiler setting for DPI awareness - it is only broken if 
; both conditions are met:  DPI awareness on + desktop scale > 100%

Global Canvas_Color
  
Procedure TestWindow()
  If OpenWindow(0, 200, 200, 400, 400, "Test window")
    SetWindowColor(0, #Gray)
    ;SetGadgetColor(0, #PB_Gadget_BackColor, RGB(128, 128, 128))
    Canvas_Color = CanvasGadget(#PB_Any, 50, 50, 300, 300)
    DrawColoredBox(#Yellow)
    Repeat:  Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
EndProcedure

Procedure DrawColoredBox(NewColor) 
  Protected w = GadgetWidth(Canvas_Color), h = GadgetHeight(Canvas_Color)
  
  If StartDrawing(CanvasOutput(Canvas_Color))
    Box(0, 0, w, h, NewColor)
    DrawingMode(#PB_2DDrawing_Outlined) 
    Box(0, 0, w, h, #Black)
    StopDrawing()
  EndIf    
EndProcedure  

TestWindow()
PB 5.73 on Windows 10 & OS X High Sierra
breeze4me
Enthusiast
Enthusiast
Posts: 527
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: Desktop scaling in conjunction with DPI awareness

Post by breeze4me »

In that case, DesktopScaledX/Y should be used.

Code: Select all

EnableExplicit

Declare DrawColoredBox(NewColor) 

; Windows only (5.71 LTS):
; If the desktop of my PC is scaled to a value > 100%, the canvas and box are of different sizes 
; (canvas is bigger than the box by scale factor)
; This appears to be dependent of the compiler setting for DPI awareness - it is only broken if 
; both conditions are met:  DPI awareness on + desktop scale > 100%

Global Canvas_Color
  
Procedure TestWindow()
  If OpenWindow(0, 200, 200, 400, 400, "Test window")
    SetWindowColor(0, #Gray)
    ;SetGadgetColor(0, #PB_Gadget_BackColor, RGB(128, 128, 128))
    Canvas_Color = CanvasGadget(#PB_Any, 50, 50, 300, 300)
    DrawColoredBox(#Yellow)
    Repeat:  Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
EndProcedure

Procedure DrawColoredBox(NewColor) 
  Protected w = DesktopScaledX(GadgetWidth(Canvas_Color)), h = DesktopScaledY(GadgetHeight(Canvas_Color))
  
  If StartDrawing(CanvasOutput(Canvas_Color))
    Box(0, 0, w, h, NewColor)
    DrawingMode(#PB_2DDrawing_Outlined) 
    Box(0, 0, w, h, #Black)
    StopDrawing()
  EndIf    
EndProcedure  

TestWindow()
It may be better suited for the 'Feature Requests and Wishlists' section.
GadgetWidth/Height(#Gadget [, #PB_Gadget_ActualSize [| #PB_Gadget_ScaledSize]])
GadgetWidth/Height(#Gadget [, #PB_Gadget_RequiredSize [| #PB_Gadget_ScaledSize]])
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: Desktop scaling in conjunction with DPI awareness

Post by kpeters58 »

Yes, that would work nicely.

However, my point is that if gadgets are drawn scaled, why don't the same rules apply to 'drawings made by developers'?

Seems at minimum an inconsistency to me, if not an oversight = bug …

Or am I missing something and you can convince me of something else?
PB 5.73 on Windows 10 & OS X High Sierra
breeze4me
Enthusiast
Enthusiast
Posts: 527
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: Desktop scaling in conjunction with DPI awareness

Post by breeze4me »

The scaled pixels do not exactly match the unscaled pixels. (x1.25, x1.5, x1.75 ... the result is not always an integer)
So it is not suitable for graphics which require accuracy, especially drawing on an image or a canvas.

For example, a kind of grid lines are shown when the following code is executed on the 125% desktop resolution.
But on the 100% desktop resolution, a box filled with black is shown.

Code: Select all

If OpenWindow(0, 0, 0, 220, 220, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 10, 10, 200, 200)
  
  If StartDrawing(CanvasOutput(0))
    
    For x = 0 To 100
      For y = 0 To 100
        Plot(DesktopScaledX(x), DesktopScaledY(y), #Black)
      Next
    Next
    
    StopDrawing()
  EndIf
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
The application of DPI resolution factor in image(or canvas) is better done by each developer, because drawing on images(canvas) and scaling gadgets should be treated as separate issues.

(I'm not good at English, so it is difficult to explain it in more detail, sorry. :oops: )
Fred
Administrator
Administrator
Posts: 16686
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Desktop scaling in conjunction with DPI awareness

Post by Fred »

It's the expected behaviour, you will probably need to put an higher resolution picture in your canvas or it will look blury on higher DPI screen.
Post Reply