Last active
January 16, 2023 19:36
-
-
Save cfillion/ada87efdf80874b86a3b2da30e2b836a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--dofile(reaper.GetResourcePath() .. | |
--'/Scripts/ReaTeam Extensions/API/imgui.lua')('0.7') | |
r = reaper | |
local demo, cache = {}, {} | |
function demo.EachEnum(enum) | |
local enum_cache = cache[enum] | |
if not enum_cache then | |
enum_cache = {} | |
cache[enum] = enum_cache | |
for func_name, func in pairs(reaper) do | |
local enum_name = func_name:match(('^ImGui_%s_(.+)$'):format(enum)) | |
if enum_name then | |
table.insert(enum_cache, { func(), enum_name }) | |
end | |
end | |
table.sort(enum_cache, function(a, b) return a[1] < b[1] end) | |
end | |
local i = 0 | |
return function() | |
i = i + 1 | |
if not enum_cache[i] then return end | |
return table.unpack(enum_cache[i]) | |
end | |
end | |
local ctx = reaper.ImGui_CreateContext('My script', reaper.ImGui_ConfigFlags_DockingEnable()) | |
local function loop() | |
local a = not b or b < reaper.ImGui_GetTime(ctx) | |
if a and reaper.ImGui_Begin(ctx, 'foo') then | |
if reaper.ImGui_Button(ctx, 'Button') then | |
reaper.ImGui_OpenPopup(ctx, 'Popup') | |
end | |
reaper.ImGui_Button(ctx, 'Button2') | |
if reaper.ImGui_IsItemHovered(ctx) and reaper.ImGui_IsMouseClicked(ctx, 0) then | |
b = reaper.ImGui_GetTime(ctx) + 4 | |
end | |
local open_modal = false | |
if reaper.ImGui_BeginPopup(ctx, 'Popup') then | |
if reaper.ImGui_BeginMenu(ctx, 'Menu') then | |
if reaper.ImGui_Selectable(ctx, 'Selectable') then | |
open_modal = true | |
end | |
reaper.ImGui_EndMenu(ctx) | |
end | |
reaper.ImGui_EndPopup(ctx) | |
end | |
if open_modal then | |
reaper.ImGui_OpenPopup(ctx, 'Modal') | |
end | |
if reaper.ImGui_BeginPopupModal(ctx, 'Modal') then | |
if reaper.ImGui_Button(ctx, 'Close1') then | |
reaper.ImGui_CloseCurrentPopup(ctx) | |
end | |
reaper.ImGui_Button(ctx, 'Close2') | |
if reaper.ImGui_IsItemHovered(ctx) and reaper.ImGui_IsMouseClicked(ctx, 0) then | |
reaper.ImGui_CloseCurrentPopup(ctx) | |
end | |
reaper.ImGui_EndPopup(ctx) | |
end | |
local buttons = 4 | |
r.ImGui_Text(ctx, 'Mouse down:') | |
for button = 0, buttons do | |
if r.ImGui_IsMouseDown(ctx, button) then | |
local duration = r.ImGui_GetMouseDownDuration(ctx, button) | |
r.ImGui_SameLine(ctx) | |
r.ImGui_Text(ctx, ('b%d (%.02f secs)'):format(button, duration)) | |
end | |
end | |
r.ImGui_Text(ctx, 'Keys down:') | |
for key, name in demo.EachEnum('Key') do | |
if r.ImGui_IsKeyDown(ctx, key) then | |
local duration = r.ImGui_GetKeyDownDuration(ctx, key) | |
r.ImGui_SameLine(ctx) | |
r.ImGui_Text(ctx, ('"%s" %d (%.02f secs)'):format(name, key, duration)) | |
end | |
end | |
reaper.ImGui_End(ctx) | |
end | |
reaper.defer(loop) | |
end | |
reaper.defer(loop) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment