Skip to content

Commit

Permalink
rework the preview state checker
Browse files Browse the repository at this point in the history
  • Loading branch information
James Bradbury committed Sep 14, 2022
1 parent 6aa2e56 commit 13d3b39
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/imgui_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,17 @@ imgui_helpers.do_preview = function(ctx, obj, change)
if obj.info.action ~= 'segment' or not reacoma.settings.slice_preview then
return false
end
local left = reaper.ImGui_MouseButton_Left()
local drag_preview = change > 0 and reacoma.settings.drag_preview
local end_drag_preview = not reacoma.settings.immediate_preview and not reaper.ImGui_IsMouseDown(ctx, left) and reacoma.settings.preview_pending
reacoma.settings.preview_pending = not end_drag_preview and (reacoma.settings.preview_pending or (change > 0 and not reacoma.settings.immediate_preview))
return drag_preview or end_drag_preview
local changing = change ~= 0
local dragging = reaper.ImGui_IsMouseDragging(ctx, reaper.ImGui_MouseButton_Left())
local mousedown = reaper.ImGui_IsMouseDown(ctx, reaper.ImGui_MouseButton_Left())
local mouseup = reacoma.global_state.mousedown and not mousedown
local immediate_preview = changing and dragging and reacoma.settings.slice_preview and reacoma.settings.immediate_preview
local mouseup_preview = mouseup and reacoma.settings.slice_preview

-- now store the state of the mousedown after checking
-- this lets you check the difference between mouse state
reacoma.global_state.mousedown = reaper.ImGui_IsMouseDown(ctx, reaper.ImGui_MouseButton_Left())
return immediate_preview or mouseup_preview
end

imgui_helpers.update_state = function(ctx, obj, update)
Expand Down

0 comments on commit 13d3b39

Please sign in to comment.