Page 2 of 4

Re: How I make DPI-aware apps

Posted: Wed Jan 16, 2019 5:38 pm
by Fred
I will take a look

Re: How I make DPI-aware apps

Posted: Wed Jan 16, 2019 6:35 pm
by chi
Fred wrote:I will take a look
Great, thanks a lot!

Re: How I make DPI-aware apps

Posted: Sun Jan 20, 2019 9:48 pm
by Little John
Whether or not a text is too big for a given gadget because of the DPI setting also depends on the Windows version. Namely Windows versions < 8.1 do different font scaling compared to Windows versions >= 8.1.
For details see this code.

Re: How I make DPI-aware apps

Posted: Sun Jan 20, 2019 10:37 pm
by chi
Looks pretty much the same to me...
ImageImage

Re: How I make DPI-aware apps

Posted: Sun Jan 20, 2019 11:00 pm
by Little John
chi wrote:Looks pretty much the same to me...
AFAIR we alread had that discussion ...

Re: How I make DPI-aware apps

Posted: Mon Jan 21, 2019 1:04 am
by chi
yup

Re: How I make DPI-aware apps

Posted: Mon Jan 21, 2019 2:44 am
by Fangbeast
Windows 10 makes this even worse. I am using a 34 inch ultrawide and on 2560x1080 at 125% for my old eyes, the entire form gets enlarged off the screen.

I thought DPI awareness was supposed to somehow adjust everything to fit inside the current screen resolution even if the dpi was above 100%?

This has been the same with or without dpi settings on pb 5.7 and on older versions of pb.

Just weird. And each release of windows 10 keeps fiddling with the api used to produce the results.

Re: How I make DPI-aware apps

Posted: Mon Jan 21, 2019 8:12 am
by Dude
Fangbeast wrote:I thought DPI awareness was supposed to somehow adjust everything to fit inside the current screen resolution even if the dpi was above 100%?
That's what I thought, but it doesn't. I use Win 10 now (and Win 7 and Win XP for testing) and my tip in the first post of this topic works perfectly on all three systems at three different Windows DPI settings (100%, 125%, and 150%). That's good enough for me.

Re: How I make DPI-aware apps

Posted: Tue Jan 22, 2019 10:05 pm
by Little John
Fangbeast wrote:Windows 10 makes this even worse.
Here is a good overview about different DPI scaling methods used by different Windows versions.

Re: How I make DPI-aware apps

Posted: Tue Jan 22, 2019 10:21 pm
by Dude
Excellent article, LJ. Thanks!

Re: How I make DPI-aware apps

Posted: Wed Jan 23, 2019 11:22 pm
by Rinzwind
So what exactly does the new dpi aware feature do and doesnt do in pb 5.7? And if not fuly implemented yet, can we expect a fix soon? Or does it work “as designed”? A best practice tutorial would be welcome.

Re: How I make DPI-aware apps

Posted: Fri Jan 25, 2019 1:50 pm
by mestnyi
Ulix wrote:Translation by google!

Hello everyone !

Very interesting as a code, if I understand correctly if it is to obtain the same dimension (windows and gadgets)
whatever the resolution of the screen? or / and the setting of OS!

What is the equivalent of the instruction:

Code: Select all

Global dpi.d = GetDeviceCaps_ (GetDC_ (0), # LOGPIXELSX) / 100; The magic!
for other OS (Linux and Mac)?
The idea: Make it a multi-platform feature! :lol:

Can we use the dpi to size the fonts?

I will follow this post with interest

Ulix :wink:

Code: Select all

Global dpi.d

Define pic=CreateImage(#PB_Any,1,1)
StartVectorDrawing(ImageVectorOutput(pic))

dpi = VectorResolutionX()/100

StopDrawing()
FreeImage(pic)

OpenWindow(0,200,200,180*dpi,100*dpi,"test",#PB_Window_SystemMenu)

x=10*dpi
w=155*dpi
h=20*dpi

TextGadget(1,x,10*dpi,w,h,"This is text that fills the gadget",#PB_Text_Border)

StringGadget(2,x,40*dpi,w,h,"Another small test of fitted text")

ButtonGadget(3,x,70*dpi,w,h,"And last example of exact text")

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: How I make DPI-aware apps

Posted: Fri Jan 25, 2019 4:32 pm
by chi
You have to divide by the OS' default PPI... [Since the 1980s, the Microsoft Windows operating system has set the default display "DPI" to 96 PPI, while Apple/Macintosh computers have used a default of 72 PPI. Dots per inch - Wikipedia]

Code: Select all

Global dpi.d

Define pic=CreateImage(#PB_Any,1,1)
StartVectorDrawing(ImageVectorOutput(pic))

CompilerSelect #PB_Compiler_OS    
  CompilerCase #PB_OS_Windows
    ppi = 96    
  CompilerCase #PB_OS_MacOS
    ppi = 72 ;not tested (might have changed)  
  CompilerCase #PB_OS_Linux
    ppi = 96 ;not tested (might have changed)  
CompilerEndSelect

dpi = VectorResolutionX() / ppi

StopDrawing()
FreeImage(pic)

OpenWindow(0,200,200,180*dpi,100*dpi,"test",#PB_Window_SystemMenu)

x=10*dpi
w=155*dpi
h=20*dpi

TextGadget(1,x,10*dpi,w,h,"This is text that fills the gadget",#PB_Text_Border)

StringGadget(2,x,40*dpi,w,h,"Another small test of fitted text")

ButtonGadget(3,x,70*dpi,w,h,"And last example of exact text")

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: How I make DPI-aware apps

Posted: Fri Jan 25, 2019 6:12 pm
by Little John
Well ... what is the advantage of that code?

I changed it a bit, so that the actual result will be shown (tested on Windows 10).

Code: Select all

Define ppi.i, dpi.d

CreateImage(0, 1, 1)
StartVectorDrawing(ImageVectorOutput(0))

CompilerSelect #PB_Compiler_OS   
   CompilerCase #PB_OS_Windows
      ppi = 96   
   CompilerCase #PB_OS_MacOS
      ppi = 72   ; not tested (might have changed) 
   CompilerCase #PB_OS_Linux
      ppi = 96   ; not tested (might have changed) 
CompilerEndSelect

dpi = VectorResolutionX() / ppi
StopDrawing()
FreeImage(0)

Debug dpi

CompilerIf #PB_Compiler_Version >= 570
   Debug DesktopResolutionX()
CompilerEndIf
With PB 5.70, the value of dpi is always the same as the value of DesktopResolutionX():
  • 1.25 here if DPI aware is checked in the compiler options,
  • 1.0 if DPI aware is unchecked in the compiler options.
And with PB versions prior to 5.70, the value of dpi will always be 1.0, of course (except when there is additional code or a manifest that makes the program DPI aware).

Re: How I make DPI-aware apps

Posted: Fri Jan 25, 2019 6:38 pm
by chi
Little John wrote:Well ... what is the advantage of that code?
PB's DPI-Awareness is only available on Windows right now... So this is a multi-platform approach ;)