How I make DPI-aware apps
Re: How I make DPI-aware apps
I will take a look
Re: How I make DPI-aware apps
Great, thanks a lot!Fred wrote:I will take a look
Et cetera is my worst enemy
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: How I make DPI-aware apps
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.
For details see this code.
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: How I make DPI-aware apps
AFAIR we alread had that discussion ...chi wrote:Looks pretty much the same to me...
- Fangbeast
- PureBasic Protozoa
- Posts: 4749
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: How I make DPI-aware apps
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.
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.
Amateur Radio, D-STAR/VK3HAF
Re: How I make DPI-aware apps
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.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%?
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: How I make DPI-aware apps
Here is a good overview about different DPI scaling methods used by different Windows versions.Fangbeast wrote:Windows 10 makes this even worse.
Re: How I make DPI-aware apps
Excellent article, LJ. Thanks!
Re: How I make DPI-aware apps
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
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:
for other OS (Linux and Mac)?Code: Select all
Global dpi.d = GetDeviceCaps_ (GetDC_ (0), # LOGPIXELSX) / 100; The magic!
The idea: Make it a multi-platform feature!
Can we use the dpi to size the fonts?
I will follow this post with interest
Ulix
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
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
Et cetera is my worst enemy
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: How I make DPI-aware apps
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).
With PB 5.70, the value of dpi is always the same as the value of DesktopResolutionX():
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
- 1.25 here if DPI aware is checked in the compiler options,
- 1.0 if DPI aware is unchecked in the compiler options.
Re: How I make DPI-aware apps
PB's DPI-Awareness is only available on Windows right now... So this is a multi-platform approachLittle John wrote:Well ... what is the advantage of that code?
Last edited by chi on Fri Jan 25, 2019 6:49 pm, edited 1 time in total.
Et cetera is my worst enemy