how to rotate reaimgui text, reaper lua script without imgui.transform
- User
how to rotate reaimgui text, reaper lua script without imgui.transform
- Assistant
Rotating text in ReaImGui (an Immediate Mode GUI library used within REAPER scripts through Lua or EEL) without using
imgui.Transform*functions presents a unique challenge, as the ReaImGui API does not provide a direct function to rotate text. Theimgui.Transform*functions would be the straightforward way to apply transformations, including rotation. However, since your requirement excludes their use, we'll discuss a workaround.As of my last update in April 2023, there's no built-in function in ReaImGui specifically for rotating text without using transformations. However, you can achieve a similar effect by rendering the text to an offscreen buffer (via a framebuffer or similar technique if supported) and then manipulating that buffer as an image, which you then can rotate. Unfortunately, direct support for such operations might be limited or require creative workarounds in Lua within the REAPER environment.
Given these constraints, one alternative approach is to use the native drawing capabilities provided by REAPER and Lua to draw rotated text without direct support in ReaImGui. This isn't as straightforward and might not integrate seamlessly into your ReaImGui-based GUI. Here's a conceptual outline of how you might approach it:
Using GDI (Windows) or CoreGraphics (macOS) for Text Rotation
-
Direct OS-Level Drawing: On Windows, you could use GDI (Graphical Device Interface) functions, and on macOS, CoreGraphics for drawing. This involves calling these functions from Lua, which might require additional libraries or FFI (Foreign Function Interface).
-
Rendering to an Image: The basic idea is to draw your text to an offscreen image/bitmap, apply the rotation at the system level, and then load this image back into your script to display in the GUI.
-
Integrating with ReaImGui: Once you have the rotated image, you might display it using
imgui.Imageor similar functions. However, this doesn't rotate the text directly through ReaImGui but achieves a similar end result.
LUA FFI Example (Conceptual):
-- WARNING: This is a conceptual snippet and won't work out-of-the-box. -- It's meant to illustrate the approach and will require adaptation. local ffi = require("ffi") if ffi.os == "Windows" then -- Define Windows GDI functions -- ffi.cdef[[ -- // GDI function definitions here -- ]] elseif ffi.os == "OSX" then -- CoreGraphics definition -- ffi.cdef[[ -- // CoreGraphics function definitions here -- ]] end -- Code to create an offscreen buffer, draw to it, rotate, and load the imagePractical Considerations:
- This approach is significantly more complex and may require bridging between different parts of the REAPER and OS APIs.
- Performance might be an issue, especially if you're frequently updating or redrawing the text.
- Cross-platform compatibility is a challenge since you'd need to implement it differently for Windows and macOS (and possibly Linux if REAPER is run via Wine).
Conclusion:
Without using
imgui.Transform*, rotating text in ReaImGui involves a rather indirect and potentially complex approach. If your project's scope and performance requirements allow, it might still be worth exploring native OS drawing capabilities. In most cases, reconsidering the UI design to avoid the need for rotating text, or leveraging the transformation functions despite their limitations, would be more practical paths forward. -
- User
oi
- Assistant
Olá! Como posso ajudar você hoje?
- User
-- Rykord Vertical Track FX List -- --NOTES--
-- want to make buttons resizable -- start window on a specific position (maybe preset position, maybe last position)
--NONCODE SKELETON
--SKELETON--
-- windowposition ✅ -- window size
-- if CountSelectedTracks == 1 -- for fx (0,i) -- create blue button with the name of the fx ✅ -- if left click the button opens the fx window ✅ -- if right click the button deletes the fx ✅ -- if left drag the button is draggable and drags the fx ✅ -- if alt left click the fx is bypassed
-- gray button to add fx with spacing from other buttons and other color -- if pressed ✅ -- inserts fx at i + 1 ✅-- if CountSelectedTracks > 1
-- black buttton saying "MULTIPLE TRACKS ARE SELECTED", button is unclickable-- if CountSelectedTracks == 0 -- black button saying "SELECT A TRACK", button is unclickable
-- let keyboard shortcuts through
--FUNCTIONS-- function print(...) reaper.ShowConsoleMsg(table.concat({...}, "\t") .. "\n") end
function IsAltKeyDown() local keyState = reaper.JS_Mouse_GetState(0) local altIsPressed = keyState & 8
return altIsPressed ~= 0end
function main() local _, open = reaper.ImGui_Begin(ctx, "FX LIST", true)
reaper.ImGui_PushFont(ctx, font_1) reaper.ImGui_SetNextWindowPos(ctx, x_position, y_position) if dock_position then reaper.ImGui_SetNextWindowDockID(ctx, -8) --CURRENT DOCK POSITION IS UNDER (DOCKID == -7)! end window_width, window_height = reaper.ImGui_GetWindowSize(ctx) button_width = window_width * 0.02 --SHOULD THESE BE GLOBAL? button_height = window_height * 0.9 --SHOULD THESE BE GLOBAL? reaper.ImGui_PushStyleVar(ctx, reaper.ImGui_StyleVar_FrameRounding(), 8) fx_list() reaper.ImGui_PopStyleVar(ctx, 1) reaper.ImGui_PopFont(ctx) if open then reaper.ImGui_End(ctx) reaper.defer(main) else local last_x_position, last_y_position = reaper.ImGui_GetWindowPos(ctx) reaper.SetExtState("RYKORD_TRACK_FX", "x_pos", last_x_position, true) reaper.SetExtState("RYKORD_TRACK_FX", "y_pos", last_y_position, true) local last_dock_position = reaper.ImGui_GetWindowDockID(ctx) reaper.SetExtState("RYKORD_TRACK_FX", "dock_position", last_dock_position, true) reaper.ImGui_End(ctx) endend
function swap_fx(track, new_index, source_index) reaper.TrackFX_CopyToTrack(track, source_index, track, new_index, true)
if source_index > new_index then reaper.TrackFX_CopyToTrack(track, new_index + 1, track, source_index, true) elseif source_index < new_index then reaper.TrackFX_CopyToTrack(track, new_index + -1, track, source_index, true) endend
function fx_list()
if reaper.CountSelectedTracks(0) == 1 then local selected_track = reaper.GetSelectedTrack(0, 0) local num_of_fx = reaper.TrackFX_GetCount(selected_track) --FX BUTTONS-- for i = 0, num_of_fx - 1 do reaper.ImGui_SameLine(ctx, 0, 10) local _, fx_name = reaper.TrackFX_GetFXName(selected_track, i) --VERIFICAR SE FX TAMBÉM TÊM 0 INDEX fx_name_label = fx_name:match(" (%S.*)$") fx_name_label = fx_name:gsub(".", "%0\n"):gsub("\n$", "") if reaper.TrackFX_GetEnabled(selected_track, i) then reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Button(), 0xF5CB5CFF) reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Text(), 0x000000FF) else reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Button(), 0xCFDBD5FF) reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Text(), 0x000000FF) end local fx_button_left_click = reaper.ImGui_Button(ctx, fx_name_label .. '##' .. i, button_width, button_height) local fx_button_right_click = reaper.ImGui_IsItemClicked(ctx, reaper.ImGui_MouseButton_Right()) local fx_button_middle_click = reaper.ImGui_IsItemClicked(ctx, reaper.ImGui_MouseButton_Middle()) if reaper.ImGui_BeginDragDropSource(ctx) then reaper.ImGui_SetDragDropPayload(ctx, "DND_FX", i) -- "DND_FX" is a type identifier for the payload reaper.ImGui_Button(ctx, fx_name .. '##' .. i, button_width, button_height) -- This will be the preview of the drag and drop reaper.ImGui_EndDragDropSource(ctx) end if reaper.ImGui_BeginDragDropTarget(ctx) then if reaper.ImGui_AcceptDragDropPayload(ctx, "DND_FX") then local _, _, payload, _, _= reaper.ImGui_GetDragDropPayload(ctx) local old_index = tonumber(payload) -- Swap the effects here using your own function swap_fx(selected_track, i, old_index) end reaper.ImGui_EndDragDropTarget(ctx) end reaper.ImGui_PopStyleColor(ctx, 2) if fx_button_left_click then reaper.TrackFX_SetOpen(selected_track, i, true) elseif fx_button_middle_click then if reaper.TrackFX_GetEnabled(selected_track, i) == true then reaper.TrackFX_SetEnabled(selected_track, i, false) else reaper.TrackFX_SetEnabled(selected_track, i, true) end elseif fx_button_right_click then reaper.TrackFX_Delete(selected_track, i) end end --ADD FX BUTTON-- reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Button(), 0xB3B6B7A1) reaper.ImGui_SameLine(ctx, 0, 10) local add_fx_press = reaper.ImGui_Button(ctx, "ADD FX", button_width, button_height) if add_fx_press then reaper.Main_OnCommand(40271, 0) end reaper.ImGui_PopStyleColor(ctx) elseif reaper.CountSelectedTracks(0) > 1 then reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Button(), 0x373F47FF) reaper.ImGui_Button(ctx, "MULTIPLE TRACKS SELECTED \n SELECT A SINGLE TRACK", 300, 60) reaper.ImGui_PopStyleColor(ctx) elseif reaper.CountSelectedTracks(0) == 0 then reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Button(), 0x373F47FF) reaper.ImGui_Button(ctx, " NO TRACK SELECTED \nSELECT A SINGLE TRACK", 300, 60) reaper.ImGui_PopStyleColor(ctx) endend
--RUN-- x_position = tonumber(reaper.GetExtState("RYKORD_TRACK_FX", "x_pos")) y_position = tonumber(reaper.GetExtState("RYKORD_TRACK_FX", "y_pos")) dock_position = tonumber(reaper.GetExtState("RYKORD_TRACK_FX", "dock_position")) window_width = nil window_height = nil font_1 = reaper.ImGui_CreateFont("C:\Users\franc\Desktop\Portable reapers\REAPER (x64)\Scripts\Rykord Scripts\SFPRODISPLAYREGULAR.OTF", 15)
ctx = reaper.ImGui_CreateContext("ctx")
reaper.ImGui_Attach(ctx, font_1)
main()
why doesn't the fx_name_label start from the second word?
- Assistant
The issue with your
fx_name_labelnot starting from the second word as intended is due to how you're extracting the name using Lua's string manipulation methods. Let's break down your original code and correct the issue.Initially, you had:
local _, fx_name = reaper.TrackFX_GetFXName(selected_track, i) fx_name_label = fx_name:match(" (%S.*)$") fx_name_label = fx_name:gsub(".", "%0\n"):gsub("\n$", "")In this snippet, your approach first tries to grab the portion of the FX name after the first space with the
matchmethod, but then you immediately overwritefx_name_labelby transformingfx_name(and not the modifiedfx_name_label) in the next line with a global substitution that affects every character. That's why the initial extraction attempt withmatchdoesn't seem to take effect properly.To extract the FX name starting from the second word and then apply your desired transformation, let's modify this as follows:
local _, fx_name = reaper.TrackFX_GetFXName(selected_track, i) -- Grabs the text after the first space fx_name_label = fx_name:match(" (%S.*)$") -- Now apply your transformation only to the extracted part, if it exists if fx_name_label ~= nil then fx_name_label = fx_name_label:gsub(".", "%0\n"):gsub("\n$", "") else -- In case the FX name has no space (thus match returns nil), use the whole name. fx_name_label = fx_name:gsub(".", "%0\n"):gsub("\n$", "") endThis modification applies your original intent properly:
- First, it tries to extract the portion after the first space (the second word onwards).
- Then, if successful, it performs your character transformation on this extracted part. If there's no space in the original string (meaning
matchwould returnnil), it falls back to using the entirefx_name.
Remember, the
match(" (%S.*)$")expression looks for a space followed by non-whitespace characters until the end of the string, effectively skipping the first word. But if your FX name starts without a space or is a single word,matchwill returnnil, which we handle in the conditional statement.By adjusting your script with the above correction,
fx_name_labelshould now properly start from the second word when it's available, and your character-by-character transformation with newlines will also apply as intended.