Liberty BASIC Community Forum
« high dpi issues »

Welcome Guest. Please Login or Register.
Nov 20th, 2017, 05:59am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: high dpi issues  (Read 2001 times)
hooshnik
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 105
xx high dpi issues
« Thread started on: Feb 25th, 2016, 5:27pm »

Hello all,

I am having high DPI issues. I am mostly talking about text boxes. When the system DPI is put above 96dpi or 100% in windows my textboxes have the bottom half of their text cut off. I tried setting DPI aware to true and false in the exe manifest but I see no change at all.

Is there some way to lock the font DPI at the very least? All of my fonts are specified in points. I can change all fonts to pixels but this is a major pain and every font has a different Y ratio.
User IP Logged

looking for file "include" support? Check out Aplomb Scribe http://libertybasic.conforums.com/index.cgi?action=display&board=open&num=1434746448
Dan Teel
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1130
xx Re: high dpi issues
« Reply #1 on: Feb 25th, 2016, 10:06pm »

I guess you'd have to scale your user interface? https://msdn.microsoft.com/en-us/library/windows/desktop/ff684173(v=vs.85).aspx

So if you're DPI is set to 144, then make the textbox x/y width/height 1.5 of its original size?

I dont know. Never messed with that stuff at all.


Edit: Or, you can calculate what the font size should be to match what it would be at 96 DPI. So if the DPI is 144, then divide the original font size by 1.5, and then use that as your new font size? Not sure man undecided
« Last Edit: Feb 25th, 2016, 10:09pm by Dan Teel » User IP Logged

ZPtr.net
Stefan Pendl
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Computers are like babies, you must teach them what you like them to do ...


Homepage PM

Gender: Male
Posts: 5297
xx Re: high dpi issues
« Reply #2 on: Feb 26th, 2016, 12:46pm »

Dialog type windows scale most things except graphics based on the DPI settings.

You can use the function below to get the scaling factor.

Code:
    print GetScreenScale()
    end

function GetScreenScale()
    calldll #user32, "GetDC",_
        0   as ulong,_   ' entire screen
        hDC as ulong

    nIndex = _LOGPIXELSX

    calldll #gdi32, "GetDeviceCaps",_
        hDC    as ulong,_
        nIndex as ulong,_
        dpi    as ulong

    calldll #user32, "ReleaseDC",_
        0      as ulong,_   ' entire screen
        hDC    as ulong,_
        result as ulong     ' 1 = success

    GetScreenScale = dpi / 96
end function
 
User IP Logged

Stefan

Make sure to read and follow the Forum Guidelines

Liberty BASIC Pro 4.04, Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
hooshnik
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 105
xx Re: high dpi issues
« Reply #3 on: Feb 27th, 2016, 10:10am »

Thanks for the replies!

Stef that is quite a hack! It works. Deadlines deadlines.... sigh. I have 1 window with a small text editor like box in it. I can externalize it, luckily it's pretty trivial. At least this way I don't need a complete re-design or a regex I might regret later.
« Last Edit: Feb 27th, 2016, 10:10am by hooshnik » User IP Logged

looking for file "include" support? Check out Aplomb Scribe http://libertybasic.conforums.com/index.cgi?action=display&board=open&num=1434746448
hooshnik
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 105
xx Re: high dpi issues
« Reply #4 on: May 10th, 2016, 4:10pm »

I found a bug with this hack. I used lucida_console at 18 points and LB is clipping the text before the end of a statictext at 150% DPI mode. I know it was not going on the next line as I gave it 150 extra horizontal pixels or so just to display the letter 'e' at the end of the last word and it fails. Going to 16 points was enough to solve the problem for that case but it's still annoying to have a point limit.
User IP Logged

looking for file "include" support? Check out Aplomb Scribe http://libertybasic.conforums.com/index.cgi?action=display&board=open&num=1434746448
hooshnik
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 105
xx Re: high dpi issues
« Reply #5 on: Jul 25th, 2016, 5:02pm »

This hack is not working for a system DPI with greater than 125% on windows 7. Does anybody know of a workaround? It doesn't make sense to manually resize every single control and font for all windows. Can't test 150% on windows 10 yet but I'm working on it.
User IP Logged

looking for file "include" support? Check out Aplomb Scribe http://libertybasic.conforums.com/index.cgi?action=display&board=open&num=1434746448
Jim Hiley
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 202
xx Re: high dpi issues
« Reply #6 on: Jul 26th, 2016, 12:32am »

My method which seems to work, including under Wine is

Code:
test$="My great program"
gw=18
[testfont]
    gw=gw-2
    menuFont$="font ms_sans_serif ";gw
    #1.gb1, menuFont$
    #1.gb1, "stringwidth? test$ textWidth"
    if textWidth>85 then [testfont]
 

Start with a hidden graphics box (gb1)
set a larger than expected font size (gw=18)
print the test$ and see how long it is
keep reducing the size of the font until size is small enough

If high DPI users still have problems, give them the ability to change the target size (85 in my example)
Save the target size in a configuration file so you don't annoy the users again.

Once you know the size, use it for all your menus and text boxes.

Jim
« Last Edit: Jul 26th, 2016, 12:34am by Jim Hiley » User IP Logged

hooshnik
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 105
xx Re: high dpi issues
« Reply #7 on: Aug 1st, 2016, 5:07pm »

I just realized I'm going to have to use scan loops for every single window if I want to support a system DPI greater than 125%. Type dialog is useless when DPI is set above 125%. If my user leaves a window open and then opens another one, that one has to end up inside a scan loop. It must look for the enter key being pressed in the first window if it is supposed to support branching on the enter key being pressed. But how can that work? I'll have to see which window has focus.

Tedious. rolleyes I can see no other solution to this.
User IP Logged

looking for file "include" support? Check out Aplomb Scribe http://libertybasic.conforums.com/index.cgi?action=display&board=open&num=1434746448
Rod
Global Moderator
ImageImageImageImageImage


member is online

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5562
xx Re: high dpi issues
« Reply #8 on: Aug 2nd, 2016, 01:59am »

There are examples posted of how to discern which window/ control has focus with an API call. I think it is GetFocus you should search out. But it may not be be a complete fix.

So we have multiple windows with multiple font sizes? Perhaps some short code showing us all what you are up to might get more specific help and advice.

You have said elsewhere that you can have up to twenty pop up windows, what is the users take on that? Are some of the pop ups similar in appearance?
User IP Logged

CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2833
xx Re: high dpi issues
« Reply #9 on: Aug 2nd, 2016, 08:23am »

This is not a simple matter. Scaling a user interface can be tricky and it isn't well handled by Windows or by the Mac OS.

It's interesting to see people use their ingenuity to solve these problems. Gives me ideas. smiley

-Carl
User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2833
xx Re: high dpi issues
« Reply #10 on: Aug 2nd, 2016, 08:37am »

on Aug 1st, 2016, 5:07pm, hooshnik wrote:
I just realized I'm going to have to use scan loops for every single window if I want to support a system DPI greater than 125%. Type dialog is useless when DPI is set above 125%. If my user leaves a window open and then opens another one, that one has to end up inside a scan loop. It must look for the enter key being pressed in the first window if it is supposed to support branching on the enter key being pressed. But how can that work? I'll have to see which window has focus.

Tedious. rolleyes I can see no other solution to this.

Can you post a real simple example program? Not the scanning stuff, just of a window that doesn't scale well?

-Carl
User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
Stefan Pendl
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Computers are like babies, you must teach them what you like them to do ...


Homepage PM

Gender: Male
Posts: 5297
xx Re: high dpi issues
« Reply #11 on: Aug 2nd, 2016, 3:41pm »

The function I posted is not a hack, it is the only way to reliably get the scaling factor from the DPI settings.
If it doesn't work for you, then you are not scaling every aspect of the window and its controls.
You need to scale not only the size, but also the position of windows and controls.
In addition you need to scale the fonts, but there is a problem if Windows doesn't find the correct size of the font and therefore uses an approximation, mostly it is the next bigger font.
You may want to create the scaling based on the dialog-base-units too, but I think I skipped that due to being more complex.
If you use a window of type dialog, the scaling is done by Windows and you don't have to scale as much as with a regular window type window, see http://basic.wikispaces.com/HelpSearch_Pendl_new
« Last Edit: Aug 2nd, 2016, 3:42pm by Stefan Pendl » User IP Logged

Stefan

Make sure to read and follow the Forum Guidelines

Liberty BASIC Pro 4.04, Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
hooshnik
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 105
xx Re: high dpi issues
« Reply #12 on: Aug 2nd, 2016, 5:04pm »

on Aug 2nd, 2016, 3:41pm, Stefan Pendl wrote:
The function I posted is not a hack, it is the only way to reliably get the scaling factor from the DPI settings.
If it doesn't work for you, then you are not scaling every aspect of the window and its controls.
You need to scale not only the size, but also the position of windows and controls.
In addition you need to scale the fonts, but there is a problem if Windows doesn't find the correct size of the font and therefore uses an approximation, mostly it is the next bigger font.
You may want to create the scaling based on the dialog-base-units too, but I think I skipped that due to being more complex.
If you use a window of type dialog, the scaling is done by Windows and you don't have to scale as much as with a regular window type window, see http://basic.wikispaces.com/HelpSearch_Pendl_new


Hi Steph.

I noticed here you are pinning the DPI to a maximum of 1.25 because you know about the issue with dialog windows? Am I correct?

GetScreenScaleForDialog = min(1.25, ScreenScaleTmp)

As soon as you go to 150% on a dialog (windows7) the text starts to get clipped.

But anyway there is a better solution IF WE WANT TO RELY ON WINDOWS. We can change all fonts in the program to pixels regardless of whether it's a dialog or window. That way a scan loop wouldn't be needed.

As an aside... if we do not want to rely on windows and do everything manually (which according to some comments (rumors) about windows 10 anniversary edition that just came out) because right now at 225% scale factor on windows 10 explorer buttons look readable but very big and ugly compared to non-microsoft apps. I suppose Microsoft will fix this... but I wonder if it has anything to do with LB dialog DPI problems?

Is dialog box units really that great compared to just changing the fonts to pixels? This is getting complicated! Are you talking about this?:

https://support.microsoft.com/en-us/kb/145994
User IP Logged

looking for file "include" support? Check out Aplomb Scribe http://libertybasic.conforums.com/index.cgi?action=display&board=open&num=1434746448
hooshnik
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 105
xx Re: high dpi issues
« Reply #13 on: Aug 5th, 2016, 5:13pm »

on Aug 2nd, 2016, 08:37am, CarlGundel wrote:
Can you post a real simple example program? Not the scanning stuff, just of a window that doesn't scale well?

-Carl


I have isolated the bug more. If you use lucida_console it looks right at 150%. If you use ms_sans_serif at 150% it buggers up bad in dialog windows.

Do you still need a code snippet? I might post one anyway.
User IP Logged

looking for file "include" support? Check out Aplomb Scribe http://libertybasic.conforums.com/index.cgi?action=display&board=open&num=1434746448
hooshnik
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 105
xx Re: high dpi issues
« Reply #14 on: Aug 11th, 2016, 10:18am »

Dear oh dear. I just saw lucida_console break (in a button) at 150% in dialog windows (on w7) too.

What hell.
« Last Edit: Aug 11th, 2016, 12:20pm by hooshnik » User IP Logged

looking for file "include" support? Check out Aplomb Scribe http://libertybasic.conforums.com/index.cgi?action=display&board=open&num=1434746448
Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls