Display.lua and context sensitive menu for knob

This forum is for developers of Rack Extensions to discuss the RE SDK, share code, and offer tips to other developers.
User avatar
Murf
RE Developer
Posts: 670
Joined: 21 Jun 2019
Location: Brisbane, Australia

Post 30 Apr 2023

Hi All,
I have a graphic I need to render and it is just 20 or so "LED Display" computer style words that I have in a film strip, that behaves like a knob (I also have a knob linked to the same motherboard property to easily adjust it)

What I need is to be able to right click the display and have a menu of the 20 options show so you can easily get straight to them.

Rather than implement a LUA based font renderer (no the built in fonts wont do) is there any way way to link a custom displays gestures to a knob UI element? I would have to somehow overlay it over the top.
I know complex 1 can do this, as you see the flat little versions of the knobs when you are dragging cables.
When I try and overlay the knob with a custom display the I get an overlapping error on rendering.
Any thoughts most welcome!

Murf.

User avatar
buddard
RE Developer
Posts: 1255
Joined: 17 Jan 2015
Location: Stockholm

Post 30 Apr 2023

What actually happens in Complex-1 when you switch to "cable mode" is that all the knobs and switches in the main area of the panel disappear (using a visibility switch), and that area is replaced with a single, huge custom display. So all the knobs and other widgets you see there are actually drawn using custom display code.

If you want to draw a segment LED style display, you can do that with display code as well -- We did it for Pattern Mutator, for example.
But there is another route you can take if you want to avoid drawing the segments yourself.
The property you're representing is a stepped number property, right?
That means that you can use it as a visibility switch.
What you need to do is to take your 20 frame film strip and split it into individual frames of exactly the same size.
Then you place them all in the exact same location and bind them all to static_decoration widgets.
Each widget must be set up with the visibility switch so that it's only visible for a single value of the switch.

This way, you can set up any interaction you want in the custom display code, but the display itself is covered up by the currently visible static_decoration.

So let's say the property you want to change is called mode, something like this in motherboard_def.lua:

Code: Select all

  mode = jbox.number {
    steps = 20,
    default = 0,
    ui_type = jbox.ui_selector { ... },
    ui_name = jbox.ui_text("Mode"),
  },
And the frames in your filmstrip are called mode_1.png, mode_2.png, ..., mode_20.png

In device2D.lua you place them all on the same coordinates:

Code: Select all

mode_frames = {}
for i = 1, 20 do
  mode_frames["mode_" .. i] = { offset = { mode_x, mode_y }, { path = "mode_" .. i } }
end
(and add mode frames to the table of front panel graphics, of course)

And in hdgui_2D.lua (after declaring front = jbox.panel etc):

Code: Select all

for i = 1, 20 do
  table.insert(front.widgets, jbox.static_decoration {
    graphics = { node = "mode_" .. i },
    blend_mode = "normal",
    visibility_switch = "/custom_properties/mode",
    visibility_values = { i - 1 },
  })
end
Something along these lines, I didn't actually test this code, but it should work.
Then you have to place the custom display behind the decorations of course and implement the gesture functions that change the mode property.

I hope this helps, and feel free to ask followup questions!

User avatar
Murf
RE Developer
Posts: 670
Joined: 21 Jun 2019
Location: Brisbane, Australia

Post 30 Apr 2023

buddard wrote:
30 Apr 2023

I hope this helps, and feel free to ask followup questions!
Thanks very much that makes perfect sense, I was caught up with the fact that the display was overlapping with the knob (which i not allowed) but I assume it is allowed with a static widget.
I will try and implement this asap and let you know!
Murf.

User avatar
pongasoft
RE Developer
Posts: 483
Joined: 21 Apr 2016
Location: Las Vegas

Post 30 Apr 2023

That is exactly what I do in the source code I pointed to yesterday. I have custom displays whose only job is to handle the interaction and static decorations layered on top with visibility switch. And then you need to split the frames into individual images (like I have BankToggleAOn.png and BankToggleAOff.png).

I have described a custom_control to Reason Studios a few years back, that would be like a custom_display, but instead of drawing, you would return which film strip / frame number to render. Or even better, simply have a jbox.draw_image(x, y, "film_strip.png", frame_number).. that way you would not have to twist the SDK into these shenanigans just to accomplish something simple (and clearly that everybody needs). Of course that never happened...

User avatar
Murf
RE Developer
Posts: 670
Joined: 21 Jun 2019
Location: Brisbane, Australia

Post 30 Apr 2023

pongasoft wrote:
30 Apr 2023
That is exactly what I do in the source code I pointed to yesterday. I have custom displays whose only job is to handle the interaction and static decorations layered on top with visibility switch. And then you need to split the frames into individual images (like I have BankToggleAOn.png and BankToggleAOff.png).

I have described a custom_control to Reason Studios a few years back, that would be like a custom_display, but instead of drawing, you would return which film strip / frame number to render. Or even better, simply have a jbox.draw_image(x, y, "film_strip.png", frame_number).. that way you would not have to twist the SDK into these shenanigans just to accomplish something simple (and clearly that everybody needs). Of course that never happened...
Thanks Yan.

  • Information
  • Who is online

    Users browsing this forum: CommonCrawl [Bot] and 0 guests