scythe icon indicating copy to clipboard operation
scythe copied to clipboard

HiDPI support

Open jalovatt opened this issue 5 years ago • 12 comments

  • local ret, val = reaper.ThemeLayout_GetLayout("mcp", -3) -> 256 for regular, 512 for Retina
  • I think it would just require wrapping all gfx calls and doubling their coordinates/dimensions

jalovatt avatar Dec 12 '19 04:12 jalovatt

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

fliprubin avatar Dec 21 '19 17:12 fliprubin

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

mespotine avatar Jan 12 '20 21:01 mespotine

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?

jalovatt avatar Jan 13 '20 15:01 jalovatt

[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.

ply avatar Mar 22 '20 22:03 ply

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 avatar Mar 30 '20 23:03 jamesb93

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?

jamesb93 avatar Mar 31 '20 00:03 jamesb93

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.

jalovatt avatar Mar 31 '20 00:03 jalovatt

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.

jamesb93 avatar Mar 31 '20 00:03 jamesb93

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

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

jalovatt avatar Mar 31 '20 00:03 jalovatt

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

jamesb93 avatar Mar 31 '20 10:03 jamesb93

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.

jalovatt avatar Mar 31 '20 15:03 jalovatt

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.

mespotine avatar Apr 05 '20 19:04 mespotine