DPI independent GUI system

About Monkey 2 Forums Monkey 2 Programming Help DPI independent GUI system

This topic contains 12 replies, has 4 voices, and was last updated by  Danilo 2 years, 2 months ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #6681

    Danilo
    Participant

    Do we have functions yet, to get the DPI and screen size + screen resolution
    on all available platforms?
    I need such functions for Font sizes and scaling GUI controls. I think it’s essential, because
    it’s a big difference if you run an application on a 96 DPI monitor, or a 220 DPI monitor,
    or a 264 DPI iPad Pro.
    We can’t use fixed font & control sizes because of this, so some functions to get
    the required system informations are essential, in my opinion.
    Same thing applies to Printers, because it’s a big difference if you print with
    300, 600, 1200, or 2400 DPI.

    Your app/game may need to look different on a small iPhone, bigger iPad Pro,
    and 27″ or 32″ computer display.

    #6692

    AdamStrange
    Participant

    Well it is all based on sdl2 so the best place would be to look there.

    My initial finding is:

    #6697

    codifies
    Participant

    would it be adequate enough for your purposes to scale to a fixed ratio (ie 16:9) ?

    you can render to a large “virtual resolution” and downscale it depending on the screen size

    I posted some code that also scissor clips the letter box as needed.

    #6698

    codifies
    Participant

    http://monkey2.monkey-x.com/forums/topic/monkey-2-app-template/#post-6538

    you’ll need to add

    [/crayon]

    just before drawing on the canvas

    the only caveat might be if a small device has sufficient resources to cope with a large virtual resolution

    #6703

    Danilo
    Participant

    Thanks for the hint, AdamStrange! 🙂

    @codifies:
    Scaling is not an option for a GUI system. You may have seen this on Windows,
    if you have a high DPI display and set the Windows scaling to 150%, for example.
    If an application is not DPI-aware, the OS is scaling the controls, and the result
    is blurry looking controls and fonts.
    If an application is aware of DPI, it looks clear and crisp on all displays.

    #6704

    codifies
    Participant

    Scalimg down has always worked finne for me..?

    #6705

    impixi
    Participant

    I have a feeling the high dpi functionality is buggy at SDL2’s end (or within graphics drivers), at least on the MacOS platform. I run the following code on my 5k Retina iMac and receive incorrect results. It states that the DPIs are approx 108 and the desktop resolution is 2560×1440, all incorrect.

    EDIT: Just had a thought. The 27″ 5k iMac has a stated resolution of 5120×2880 at 218 PPI. The values I get from my code are half of those values. Might not be a “bug” after all, just “unexpected behaviour”.

    [/crayon]

    On the positive side, the undocumented WindowFlags.HighDPI creation flag works nicely, though I need to load my fonts at a larger size, obviously. Text is very sharp. (Ted2 makes use of that flag too).

    My next project is very text heavy, so I also would like bug-free DPI-related functionality, if possible…

    #6710

    Danilo
    Participant

    @impixi: Do you need to double the font sizes?

    #6711

    Danilo
    Participant

    Using the flag WindowFlags.HighDPI, the window size gets doubled automatically
    when moving a window from normal screen to a HiDPI screen.
    But MX2 does not update the render screen size. With Ted2Go it looks like this:

    #6715

    impixi
    Participant

    Do you need to double the font sizes?

    I’d assume it depends on the amount of DPI. Higher amounts would require higher multiples font size. IIRC, Ted2 fonts are really small by default. I have to use the “zoom” functionality of the “View” menu item – but only on the first run.

    Not sure about your problem above. Would have to see the relevant code… You might need an additional RequestRender call somewhere or to manually adjust View rects, etc…

    #6716

    Danilo
    Participant

    The problem in the image above is not my code. It is the Ted2Go editor when opened on
    a normal screen, and then moved to a Hi-DPI screen. It’s a bug, or missing feature,
    in Ted2(go) or MX2.
    You can test it if you switch to a Hi-DPI mode while Ted2(Go) is running.

    In my opinion the Ted2 fonts are too big, on a normal screen. Using ‘zoom out’ 2 or 3 times helps. 🙂

    On macOS you could probably use:

    to get the scale factor for the fonts. But this example shows it only for
    the main screen. It’s a bit more complicated when you use mixed screens and
    move a window from 100 DPI screen to a 200 DPI screen at runtime.
    NSWindow has also such a method, and it’s probably better to ask the window
    for the scale factor, so if the window gets moved onto another screen, the scale factor
    should change/update.

    #6719

    impixi
    Participant

    @danilo. Very interesting, thanks for the info… Don’t you just love all the complexity and “edge cases” associated with software development? 😉

    #6720

    Danilo
    Participant

    Yes, I love those cases… and also hate them sometimes… with the goal of fixing
    it in the development environment I currently use.
    I am testing the DPI-awareness of MX2 to understand the system and make it better
    and more useful. Maybe perfect – as perfect would be nice. Perfection is a nice goal. 😉

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.