From fdc84789fcbd49c3e345b6a63639786683590c6a Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 31 Dec 2023 16:21:21 -0800 Subject: [PATCH] switch all handlers to run either the app or editor --- 0004-on.update | 27 +++++++++-------- 0012-on.draw | 34 +++++++++++---------- 0013-on.keychord_press | 31 +++++++++---------- 0014-on.text_input | 9 +++--- 0015-on.key_release | 1 - 0016-on.mouse_press | 65 ++++++++++++++++++++-------------------- 0017-on.mouse_release | 39 ++++++++++++------------ 0021-draw_menu | 26 ---------------- 0064-show_code_button | 7 ----- 0065-hide_code_button | 7 ----- 0101-on.mouse_wheel_move | 15 +++++----- 0106-stop_button | 12 -------- 0158-on.quit | 3 ++ 13 files changed, 115 insertions(+), 161 deletions(-) delete mode 100644 0064-show_code_button delete mode 100644 0065-hide_code_button delete mode 100644 0106-stop_button create mode 100644 0158-on.quit diff --git a/0004-on.update b/0004-on.update index c0cfea0..906606e 100644 --- a/0004-on.update +++ b/0004-on.update @@ -1,16 +1,19 @@ on.update = function(dt) refresh_debug_animations() - -- == menu area - if Active_button and Active_button.expire <= Current_time then - Active_button = nil + if not Show_code then + if car.update then call_protected(car.update, dt) end + else + -- == menu area + if Active_button and Active_button.expire <= Current_time then + Active_button = nil + end + -- == settings area + update_sliders(Global_state, App.mouse_x()) + -- == main area + if Current_pane.editor_state.scrollbar_drag then + adjust_scrollbar(Current_pane.editor_state, App.mouse_y()) + elseif Current_pane.output_editor_state.scrollbar_drag then + adjust_scrollbar(Current_pane.output_editor_state, App.mouse_y()) + end end - -- == settings area - update_sliders(Global_state, App.mouse_x()) - -- == main area - if Current_pane.editor_state.scrollbar_drag then - adjust_scrollbar(Current_pane.editor_state, App.mouse_y()) - elseif Current_pane.output_editor_state.scrollbar_drag then - adjust_scrollbar(Current_pane.output_editor_state, App.mouse_y()) - end - if car.update then call_protected(car.update, dt) end end \ No newline at end of file diff --git a/0012-on.draw b/0012-on.draw index 1b86547..c14ebc5 100644 --- a/0012-on.draw +++ b/0012-on.draw @@ -1,26 +1,30 @@ on.draw = function() Global_state.button_handlers = {} Global_state.slider_handlers = {} - -- modal dialog - if Show_file_dialog then - draw_file_dialog() - return - end - Overflow_button = nil - love.graphics.setBackgroundColor(Background_color.r, Background_color.g, Background_color.b) - App.color(Foreground_color) - if car.draw then call_protected(car.draw) end - love.graphics.setFont(Font) - App.color(Normal_color) - love.graphics.setLineWidth(1) - if Show_code then + if not Show_code then + if car.draw then call_protected(car.draw) end + else + -- modal dialog + if Show_file_dialog then + draw_file_dialog() + return + end + Overflow_button = nil + love.graphics.setBackgroundColor(Background_color.r, Background_color.g, Background_color.b) + App.color(Foreground_color) + -- code editor + love.graphics.setFont(Font) + App.color(Normal_color) + love.graphics.setLineWidth(1) draw_editor_border() edit.draw(Current_pane.editor_state, --[[implicitly use Foreground_color]] nil, --[[hide_cursor]] nil, --[[show_line_numbers]] true) draw_scrollbar(Current_pane.editor_state) + -- output draw_output_border() edit.draw(Current_pane.output_editor_state, Foreground_color, --[[hide cursor]] true) draw_scrollbar(Current_pane.output_editor_state) + -- menu and debug UI + draw_menu() + draw_next_frames_of_animations() end - draw_menu() - draw_next_frames_of_animations() end \ No newline at end of file diff --git a/0013-on.keychord_press b/0013-on.keychord_press index 282cd5f..1bb4a96 100644 --- a/0013-on.keychord_press +++ b/0013-on.keychord_press @@ -1,21 +1,22 @@ on.keychord_press = function(chord, key) - if Show_file_dialog then - keychord_press_on_file_dialog(chord, key) - return - end - if chord == 'C-=' then - update_font_settings(Current_pane.editor_state.font_height+2) - elseif chord == 'C--' then - update_font_settings(Current_pane.editor_state.font_height-2) - elseif chord == 'C-0' then - update_font_settings(20) - elseif Show_code then - if Current_pane.editor_state.cursor_x then - -- send keys to editor if cursor is visible - edit.keychord_press(Current_pane.editor_state, chord, key) + if Show_code then + if Show_file_dialog then + keychord_press_on_file_dialog(chord, key) + return + end + if chord == 'C-=' then + update_font_settings(Current_pane.editor_state.font_height+2) + elseif chord == 'C--' then + update_font_settings(Current_pane.editor_state.font_height-2) + elseif chord == 'C-0' then + update_font_settings(20) + else + if Current_pane.editor_state.cursor_x then + -- send keys to editor if cursor is visible + edit.keychord_press(Current_pane.editor_state, chord, key) + end end else - -- editors hidden if car.keychord_press then call_protected(car.keychord_press, chord, key) end diff --git a/0014-on.text_input b/0014-on.text_input index be66d8f..3fa5506 100644 --- a/0014-on.text_input +++ b/0014-on.text_input @@ -1,12 +1,11 @@ on.text_input = function(t) - if Show_file_dialog then - text_input_on_file_dialog(t) - elseif Show_code then - if Current_pane.editor_state.cursor_x then + if Show_code then + if Show_file_dialog then + text_input_on_file_dialog(t) + elseif Current_pane.editor_state.cursor_x then edit.text_input(Current_pane.editor_state, t) end else - -- editors hidden if car.text_input then call_protected(car.text_input, t) end diff --git a/0015-on.key_release b/0015-on.key_release index b105510..1c49309 100644 --- a/0015-on.key_release +++ b/0015-on.key_release @@ -4,7 +4,6 @@ on.key_release = function(key, scancode) edit.key_release(Current_pane.editor_state, key, scancode) end else - -- editors hidden if car.key_release then call_protected(car.key_release, key, scancode) end diff --git a/0016-on.mouse_press b/0016-on.mouse_press index 6e8faa6..f4ed8fc 100644 --- a/0016-on.mouse_press +++ b/0016-on.mouse_press @@ -1,29 +1,36 @@ on.mouse_press = function(x,y, mouse_button) - -- == menu area - -- some hysteresis right after a button has been pressed - if Active_button then return end - if mouse_press_consumed_by_any_button(Global_state, x,y, mouse_button) then - Button_pressed = true - return - end - -- == settings area - if mouse_press_consumed_by_any_slider(Global_state, x,y) then - return - end - if Show_menu == 'settings' then - if on_area(Settings_menu_area, x,y) then - -- nothing atm in settings menu that isn't a button or slider - else - Show_menu = nil - -- On mobile devices, we can't depend on on.save_settings() triggering on quit. - -- So save settings every time we close the settings menu. - love.filesystem.write('config', json.encode(settings())) + if not Show_code then + if car.mouse_press then + call_protected(car.mouse_press, x,y, mouse_button) end - return - end - -- == main area - Show_menu = nil - if Show_code then + if car.mousepressed then + call_protected(car.mousepressed, x,y, mouse_button) + end + else + -- == menu area + -- some hysteresis right after a button has been pressed + if Active_button then return end + if mouse_press_consumed_by_any_button(Global_state, x,y, mouse_button) then + Button_pressed = true + return + end + -- == settings area + if mouse_press_consumed_by_any_slider(Global_state, x,y) then + return + end + if Show_menu == 'settings' then + if on_area(Settings_menu_area, x,y) then + -- nothing atm in settings menu that isn't a button or slider + else + Show_menu = nil + -- On mobile devices, we can't depend on on.save_settings() triggering on quit. + -- So save settings every time we close the settings menu. + love.filesystem.write('config', json.encode(settings())) + end + return + end + -- == main area + Show_menu = nil if on_editor_scrollbar(Current_pane.editor_state, x,y) then Current_pane.editor_state.scrollbar_drag = true local sbtopy = compute_scrollbar_topy(Current_pane.editor_state) @@ -40,13 +47,5 @@ on.mouse_press = function(x,y, mouse_button) elseif on_editor_scrollbar_area(Current_pane.output_editor_state, x,y) then -- nothing end - else - -- editors hidden - if car.mouse_press then - call_protected(car.mouse_press, x,y, mouse_button) - end - if car.mousepressed then - call_protected(car.mousepressed, x,y, mouse_button) - end end -end +end \ No newline at end of file diff --git a/0017-on.mouse_release b/0017-on.mouse_release index 37ff818..8fa4da7 100644 --- a/0017-on.mouse_release +++ b/0017-on.mouse_release @@ -1,18 +1,25 @@ on.mouse_release = function(x,y, mouse_button) - -- == menu area - if Button_pressed then - Button_pressed = nil - return - end - -- == settings area - Global_state.selected_slider = nil - if Show_menu == 'settings' then - if on_area(Settings_menu_area, x,y) then + if not Show_code then + if car.mouse_release then + call_protected(car.mouse_release, x,y, mouse_button) + end + if car.mousereleased then + call_protected(car.mousereleased, x,y, mouse_button) + end + else + -- == menu area + if Button_pressed then + Button_pressed = nil return end - end - -- == main area - if Show_code then + -- == settings area + Global_state.selected_slider = nil + if Show_menu == 'settings' then + if on_area(Settings_menu_area, x,y) then + return + end + end + -- == main area if Current_pane.editor_state.scrollbar_drag then adjust_scrollbar(Current_pane.editor_state, y) Current_pane.editor_state.scrollbar_drag = nil @@ -28,13 +35,5 @@ on.mouse_release = function(x,y, mouse_button) elseif on_editor_scrollbar_area(Current_pane.output_editor_state, x,y) then adjust_scrollbar(Current_pane.output_editor_state, y) end - else - -- editors hidden - if car.mouse_release then - call_protected(car.mouse_release, x,y, mouse_button) - end - if car.mousereleased then - call_protected(car.mousereleased, x,y, mouse_button) - end end end \ No newline at end of file diff --git a/0021-draw_menu b/0021-draw_menu index 52d4e13..5d9ff8a 100644 --- a/0021-draw_menu +++ b/0021-draw_menu @@ -11,36 +11,10 @@ draw_menu = function() App.color(Normal_color) x = x+5 + App.width(tostring(Current_pane_index)) + 10 x = run_button(x, y) - x = stop_button(x, y) - -- assume screen will always be wide enough to print this far without overflow - if not Overflow_button then - local w = App.width('code')+10 - local w2 = App.width('>>')+10 - if x+w+10+w2+10 < r then - App.color{r=0.5, g=0.5, b=0.5} - love.graphics.print('code', x, y) - x = x+w+10 - end - end - if Show_code then - x, y = hide_code_button(x, y, r) - else - x, y = show_code_button(x, y, r) - end x, y = save_button(x, y, r) x, y = load_button(x, y, r) x, y = copy_button(x, y, r) x, y = paste_button(x, y, r) - x, y = clear_pane_button(x, y, r) - if not Overflow_button then - local w = App.width('screen')+10 - local w2 = App.width('>>')+10 - if x+w+10+w2+10 < r then - App.color{r=0.5, g=0.5, b=0.5} - love.graphics.print('screen', x, y) - x = x+w+10 - end - end x, y = new_pane_button(x, y, r) x, y = delete_pane_button(x, y, r) -- nav buttons along sides diff --git a/0064-show_code_button b/0064-show_code_button deleted file mode 100644 index 75d8cea..0000000 --- a/0064-show_code_button +++ /dev/null @@ -1,7 +0,0 @@ -show_code_button = function(x, y, r) - return overflowable_button('show', x, y, r, - function() - Show_menu = nil - Show_code = true - end) -end diff --git a/0065-hide_code_button b/0065-hide_code_button deleted file mode 100644 index 162d5be..0000000 --- a/0065-hide_code_button +++ /dev/null @@ -1,7 +0,0 @@ -hide_code_button = function(x, y, r) - return overflowable_button('hide', x, y, r, - function() - Show_menu = nil - Show_code = false - end) -end diff --git a/0101-on.mouse_wheel_move b/0101-on.mouse_wheel_move index 60b2163..65b8efb 100644 --- a/0101-on.mouse_wheel_move +++ b/0101-on.mouse_wheel_move @@ -1,17 +1,16 @@ on.mouse_wheel_move = function(dx,dy) - if Show_code then - if App.mouse_y() < Current_pane.editor_state.bottom then - edit.mouse_wheel_move(Current_pane.editor_state, dx,dy) - else - edit.mouse_wheel_move(Current_pane.output_editor_state, dx,dy) - end - else - -- editors hidden + if not Show_code then if car.mouse_wheel_move then call_protected(car.mouse_wheel_move, dx,dy) end if car.wheelmoved then call_protected(car.wheelmoved, dx,dy) end + else + if App.mouse_y() < Current_pane.editor_state.bottom then + edit.mouse_wheel_move(Current_pane.editor_state, dx,dy) + else + edit.mouse_wheel_move(Current_pane.output_editor_state, dx,dy) + end end end \ No newline at end of file diff --git a/0106-stop_button b/0106-stop_button deleted file mode 100644 index 0c6a4d9..0000000 --- a/0106-stop_button +++ /dev/null @@ -1,12 +0,0 @@ -stop_button = function(x, y) - styled_button('stop', x,y, - function() - if car.quit then - call_protected(car.quit) - end - Show_menu = nil - clear_handlers() - end) - local w = App.width('stop')+10 - return x+w+10, y -end \ No newline at end of file diff --git a/0158-on.quit b/0158-on.quit new file mode 100644 index 0000000..c84eee3 --- /dev/null +++ b/0158-on.quit @@ -0,0 +1,3 @@ +on.quit = function() + call_protected(car.quit) +end \ No newline at end of file