jalovatt / scythe

Lua GUI library and utility framework for Reaper scripts (formerly Lokasenna_GUI)
https://jalovatt.github.io/scythe
MIT License
26 stars 5 forks source link

HiDPI support #156

Open jalovatt opened 4 years ago

jalovatt commented 4 years ago
fliprubin commented 4 years ago

My monitor scales to 150% so I've been doing something like this, which I think will fit more scenarios:

local ret, val = reaper.ThemeLayout_GetLayout("mcp", -3)
local scaleFactor = val / 256

Then multiply coordinates and dimensions by the scale factor

mespotine commented 4 years ago

AFAIK, if ThemeLayout_GetLayout returns 512, set gfx.ext_retina=1 else leave it as 0.

jalovatt commented 4 years ago

AFAIK, if ThemeLayout_GetLayout returns 512, set gfx.ext_retina=1 else leave it as 0.

Would the drawing logic still have to double everything, or does HiDPI mode do that automatically?

ply commented 4 years ago

[edited to provide additional comments]

reaper.ThemeLayout_GetLayout("mcp", -3) looks like a good starting point, but it might not work with multi-monitor setup with different DPIs - it returns DPI of screen where the mixer is. I work with multimonitor aware v2 HiDPI mode (set in REAPERS's advanced UI settings), and I use gfx.ext_retina variable, which changes when window is moved to other monitor with different DPI. Unfortunately it works only when the gfx window is running, so I first gfx.init() a window to check the scaling, and then reopen the window if needed. It looks like this (for a simple script just displaying text, not using Scythe):

gfx.ext_retina = 1.0
gfx.init(NAME, w, h, dock, x, y)
if gfx.ext_retina ~= 1.0 then
    gfx.quit()
    gfx.init(NAME, w*gfx.ext_retina, h*gfx.ext_retina, dock, x, y)
end

Dimensions of the window change automatically when moving to a different screen. When I gfx.setfont(1, "Arial", fontsize*gfx.ext_retina, "b") with every window update it gets approximately right - I guess it's some rounding issue.

jamesb93 commented 4 years ago

AFAIK, if ThemeLayout_GetLayout returns 512, set gfx.ext_retina=1 else leave it as 0.

Would the drawing logic still have to double everything, or does HiDPI mode do that automatically?

Not sure how much further you got on this but I am running on a 2015 macbook pro with a retina screen and my value returned from reaper.ThemeLayout_GetLayout("mcp", -3) is actually 256. If I force gfx.ext_retina = 1 everything looks better anyway.

jamesb93 commented 4 years ago

Another problem is that even though the x and y ratios can be modified it seems that text remains incredibly small. I was able to manually remedy this by changing the font size which is passed to gfx at line 26 of the public/fonts. I'm not sure what a good interface for managing this is (or if it should be automatic).

My question is - what is a quick fix for me to pas my own 'scale' down to this part of your wonderful graphics library?

jalovatt commented 4 years ago

My question is - what is a quick fix for me to pas my own 'scale' down to this part of your wonderful graphics library?

There isn't one, sadly. User input is all handled in one place so that might not be too hard to make scaleable, but every element does its own drawing - all of them would have to be rewritten to be aware of the current scale and account for it.

The idea solution would be to add some utilities for translating screen space to/from the canvas' coordinates, then refactor the user input, event handling, and element drawing so that everything is done via those utilities.

That said, I've had to put the project on hold so whether I ever get that far is a separate question.

jamesb93 commented 4 years ago

My question is - what is a quick fix for me to pas my own 'scale' down to this part of your wonderful graphics library?

There isn't one, sadly. User input is all handled in one place so that might not be too hard to make scaleable, but every element does its own drawing - all of them would have to be rewritten to be aware of the current scale and account for it.

The idea solution would be to add some utilities for translating screen space to/from the canvas' coordinates, then refactor the user input, event handling, and element drawing so that everything is done via those utilities.

That said, I've had to put the project on hold so whether I ever get that far is a separate question.

hmm okay. I think then I will try and make some sort of ad hoc method for changing the font size according to the detected resolution and then scaling my elements by a scalar depending on th same thing. I don't have the architectural chops for lua but I have a fair bit of experience with reascript so I'd be happy to contribute if you need some jobs delegated.

one quick question - is reaper.ThemeLayout your own appendage to their table or functions? I couldn't find it in the API and I'd like to investigate how to use it further.

jalovatt commented 4 years ago

No, Scythe doesn't add anything to the existing namespaces (reaper and gfx).

API: retval, name = reaper.ThemeLayout_GetLayout( section, idx )

jamesb93 commented 4 years ago

Ah okay, it is documented in x-raym but not the official docs.

Is it possible to use the Font.set() to edit the font globally? I semi-understand the docs here but some extra clarity would be helpful.

https://jalovatt.github.io/scythe/#/public/font

jalovatt commented 4 years ago

It is in the official docs - in Reaper's Help menu, choose Reascript Documentation to have it generate docs for your current version. The theme stuff showed with with 6.0, I believe.

You can use Font.addFonts to override the base fonts. All of the presets are stored in Font.fonts, so you can iterate over that, calculated their scaled sizes, and then use addFonts to update it.

I should note, though, that font sizes don't scale linearly - 24pt will not necessarily be twice the size of 12pt. The most accurate solution would be to measure the pixel size of, say, m at a given font size, then repeatedly increase the font size until the text fits the correct scaled dimensions.

mespotine commented 4 years ago

The Get/Set Themelayout-functions were added somewhere in the 5.x-versions, probably to let users help testing the alpha-versions of the v6-default-theme.