Please make all example code DPI aware
Posted: Sun Sep 13, 2020 9:13 am
Graphics example codes in the Help of PB 5.72 are not DPI aware.
For instance, this is the example code for LineXY():
When compiled with the compiler option
[ ] Enable DPI aware executable (Windows)
switched OFF, the result is fine:

But with that compiler option switched ON,
the result doesn't look as expected (DPI 125 %):

In order to make it look properly, we have to scale images and graphics functions by our own code.
Only windows and gadgets are scaled automatically by PureBasic.
So the code should be like this:
Using this code, the result always looks like the first picture above, regardless whether the compiler option
[ ] Enable DPI aware executable (Windows)
is switched OFF or ON (PB 5.72 on Windows).
For instance, this is the example code for LineXY():
Code: Select all
If OpenWindow(0, 0, 0, 200, 200, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateImage(0, 200, 200) And StartDrawing(ImageOutput(0))
Box(0, 0, 200, 200, RGB(255, 255, 255))
For Angle = 0 To 360 Step 3
LineXY(100, 100, 100+Cos(Radian(Angle))*90, 100+Sin(Radian(Angle))*90, RGB(Random(255), Random(255), Random(255)))
Next Angle
StopDrawing()
ImageGadget(0, 0, 0, 200, 200, ImageID(0))
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
[ ] Enable DPI aware executable (Windows)
switched OFF, the result is fine:

But with that compiler option switched ON,
the result doesn't look as expected (DPI 125 %):

In order to make it look properly, we have to scale images and graphics functions by our own code.
Only windows and gadgets are scaled automatically by PureBasic.
So the code should be like this:
Code: Select all
If OpenWindow(0, 0, 0, 200, 200, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateImage(0, DesktopScaledX(200), DesktopScaledY(200)) And StartDrawing(ImageOutput(0))
Box(0, 0, DesktopScaledX(200), DesktopScaledY(200), RGB(255, 255, 255))
For Angle = 0 To 360 Step 3
LineXY(DesktopScaledX(100), DesktopScaledY(100), DesktopScaledX(100+Cos(Radian(Angle))*90),
DesktopScaledY(100+Sin(Radian(Angle))*90), RGB(Random(255), Random(255), Random(255)))
Next Angle
StopDrawing()
ImageGadget(0, 0, 0, 200, 200, ImageID(0))
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
[ ] Enable DPI aware executable (Windows)
is switched OFF or ON (PB 5.72 on Windows).