Please make all example code DPI aware

Found an issue in the documentation ? Please report it here !

Moderator: Documentation Editors

Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Please make all example code DPI aware

Post by Little John »

Graphics example codes in the Help of PB 5.72 are not DPI aware.

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
When compiled with the compiler option
[ ] Enable DPI aware executable (Windows)
switched OFF, the result is fine:
Image


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

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
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).
User avatar
NicTheQuick
Addict
Addict
Posts: 1218
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Please make all example code DPI aware

Post by NicTheQuick »

I don't think you want to scale the 2D drawing functions itself. They are independent of the GUI. What you want is scaling the content of the ImageGadget when it is shown, not the underlying image.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Please make all example code DPI aware

Post by Little John »

NicTheQuick wrote:I don't think you want to scale the 2D drawing functions itself. They are independent of the GUI. What you want is scaling the content of the ImageGadget when it is shown, not the underlying image.
Sorry, I don't understand what you mean exactly. Can you please provide code that shows how that example for LineXY() should be written properly in your opinion?
User avatar
NicTheQuick
Addict
Addict
Posts: 1218
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Please make all example code DPI aware

Post by NicTheQuick »

Oh, sorry, I was not aware I am in the forum for bugs in the documentation. I thought you want to make 2D drawing functions DPI aware in general.
Of course in this case your solution is well suited. A more simple solution would be to resize the image just before setting it to the ImageGadget. Or changing the behaviour of the ImageGadget to resize itself to the DPI aware image version, so that the resizing happens in the background without changing the code at all. But the latter would mean that the behaviour of the ImageGadget has to be changed.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Please make all example code DPI aware

Post by Paul »

NicTheQuick wrote:I don't think you want to scale the 2D drawing functions itself.
By rescaling the 2D drawing functions as you use them, you end up with a crisp clear image. If you simply resize the final image before displaying it, you end up with a blurry image from stretching pixels. (which is what your apps look like if you make them non DPI aware and let Windows auto scale them for you)
Image Image
User avatar
NicTheQuick
Addict
Addict
Posts: 1218
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Please make all example code DPI aware

Post by NicTheQuick »

I know, I know. This statement of mine was before I realized we are in the documentation's bug section. I only wanted to say that you don't want automatic DPI awareness within the 2D drawing library.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Please make all example code DPI aware

Post by Saki »

The pixel based drawing functions have nothing to do with the DPI thing.

So it is not a mistake of the manual.

It is just difficult to understand and to handle.

The manual should rather go into more detail about these things.

Correctly, the line thickness must also be taken into account.
In so far the Vector Lib is here recommended..

In this respect, enlarging is in principle the right approach :wink:
地球上の平和
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Please make all example code DPI aware

Post by Paul »

NicTheQuick wrote:I know, I know. This statement ...
LOL, sorry Nic :lol:
Image Image
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Please make all example code DPI aware

Post by Little John »

Saki wrote:The pixel based drawing functions have nothing to do with the DPI thing.

So it is not a mistake of the manual.
These statements are wrong. Everyone can see this easily by looking at my first post in this thread.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Please make all example code DPI aware

Post by Saki »

Nevertheless they are two different things.
Your example above adapts one to the other, but still incomplete.
When scaling over 100%, the line thickness must also change.
How do you want to display this in the existing demo codes.
地球上の平和
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Please make all example code DPI aware

Post by Little John »

I just wrote that and how some examples in the Help could and should be improved. That's all.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Please make all example code DPI aware

Post by Saki »

Yes, but it should be treated in a separate part,
because the pixel-based commands do exactly what they are supposed to do.
地球上の平和
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Please make all example code DPI aware

Post by Little John »

I cannot explain it better than I already did. EOD.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Please make all example code DPI aware

Post by Saki »

It's OK, but as an OS specific thing it should also be treated separately,
as it is not universally valid on PB.
地球上の平和
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Please make all example code DPI aware

Post by Little John »

Saki wrote:It's OK, but as an OS specific thing it should also be treated separately,
as it is not universally valid on PB.
Sigh.
The PB code that I suggested (2nd code in the first post) runs fine on all supported platforms.
Post Reply