From 7f4be7f277df506db3b7772c499348e8c11052a6 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Sun, 1 Mar 2020 12:06:22 -0800 Subject: [PATCH] DeskTop: Refactor button event loop, more flexible proc, save a bunch of bytes --- desktop/desktop_main.s | 158 ++++++++++++----------------------------- desktop/desktop_res.s | 4 +- 2 files changed, 47 insertions(+), 115 deletions(-) diff --git a/desktop/desktop_main.s b/desktop/desktop_main.s index d41a3826..238aa58e 100644 --- a/desktop/desktop_main.s +++ b/desktop/desktop_main.s @@ -13389,9 +13389,7 @@ content: jmp maybe_check_button_cancel check_button_ok: - jsr set_penmode_xor2 - MGTK_RELAY_CALL MGTK::PaintRect, desktop_aux::ok_button_rect - jsr button_loop_ok + yax_call button_event_loop, kAlertDialogID, desktop_aux::ok_button_rect bmi :+ lda #PromptResult::ok : rts @@ -13400,9 +13398,7 @@ check_button_yes: MGTK_RELAY_CALL MGTK::InRect, desktop_aux::yes_button_rect cmp #MGTK::inrect_inside bne check_button_no - jsr set_penmode_xor2 - MGTK_RELAY_CALL MGTK::PaintRect, desktop_aux::yes_button_rect - jsr button_loop_yes + yax_call button_event_loop, kAlertDialogID, desktop_aux::yes_button_rect bmi :+ lda #PromptResult::yes : rts @@ -13411,9 +13407,7 @@ check_button_no: MGTK_RELAY_CALL MGTK::InRect, desktop_aux::no_button_rect cmp #MGTK::inrect_inside bne check_button_all - jsr set_penmode_xor2 - MGTK_RELAY_CALL MGTK::PaintRect, desktop_aux::no_button_rect - jsr button_loop_no + yax_call button_event_loop, kAlertDialogID, desktop_aux::no_button_rect bmi :+ lda #PromptResult::no : rts @@ -13422,9 +13416,7 @@ check_button_all: MGTK_RELAY_CALL MGTK::InRect, desktop_aux::all_button_rect cmp #MGTK::inrect_inside bne maybe_check_button_cancel - jsr set_penmode_xor2 - MGTK_RELAY_CALL MGTK::PaintRect, desktop_aux::all_button_rect - jsr button_loop_all + yax_call button_event_loop, kAlertDialogID, desktop_aux::all_button_rect bmi :+ lda #PromptResult::all : rts @@ -13439,9 +13431,7 @@ check_button_cancel: cmp #MGTK::inrect_inside beq :+ jmp LA6ED -: jsr set_penmode_xor2 - MGTK_RELAY_CALL MGTK::PaintRect, desktop_aux::cancel_button_rect - jsr button_loop_cancel +: yax_call button_event_loop, kAlertDialogID, desktop_aux::cancel_button_rect bmi :+ lda #PromptResult::cancel : rts @@ -15160,121 +15150,49 @@ version_bytes: .endproc ;;; ============================================================ -;;; Event loop during button press - handle inverting -;;; the text as mouse is dragged in/out, report final -;;; click (A as passed) / cancel (A is negative) - -button_loop_ok: - lda #PromptResult::ok - jmp button_event_loop - -button_loop_cancel: - lda #PromptResult::cancel - jmp button_event_loop - -button_loop_yes: - lda #PromptResult::yes - jmp button_event_loop - -button_loop_no: - lda #PromptResult::no - jmp button_event_loop - -button_loop_all: - lda #PromptResult::all - jmp button_event_loop +;;; Event loop during button press - initial invert and +;;; inverting as mouse is dragged in/out. +;;; Input: A,X = rect address, Y = window_id +;;; Output: A=0/N=0/Z=1 = click, A=$FF/N=1/Z=0 = cancel .proc button_event_loop - ;; Configure test and fill procs - pha - asl a - asl a - tax - copy16 test_fill_button_proc_table,x, test_button_proc_addr - copy16 test_fill_button_proc_table+2,x, fill_button_proc_addr - pla - jmp event_loop - -test_fill_button_proc_table: - .addr test_ok_button,fill_ok_button - .addr test_cancel_button,fill_cancel_button - .addr test_yes_button,fill_yes_button - .addr test_no_button,fill_no_button - .addr test_all_button,fill_all_button - -test_ok_button: - MGTK_RELAY_CALL MGTK::InRect, desktop_aux::ok_button_rect - rts - -test_cancel_button: - MGTK_RELAY_CALL MGTK::InRect, desktop_aux::cancel_button_rect - rts - -test_yes_button: - MGTK_RELAY_CALL MGTK::InRect, desktop_aux::yes_button_rect - rts - -test_no_button: - MGTK_RELAY_CALL MGTK::InRect, desktop_aux::no_button_rect - rts - -test_all_button: - MGTK_RELAY_CALL MGTK::InRect, desktop_aux::all_button_rect - rts - -fill_ok_button: - MGTK_RELAY_CALL MGTK::PaintRect, desktop_aux::ok_button_rect - rts - -fill_cancel_button: - MGTK_RELAY_CALL MGTK::PaintRect, desktop_aux::cancel_button_rect - rts - -fill_yes_button: - MGTK_RELAY_CALL MGTK::PaintRect, desktop_aux::yes_button_rect - rts + stax rect_addr + sty window_id -fill_no_button: - MGTK_RELAY_CALL MGTK::PaintRect, desktop_aux::no_button_rect - rts - -fill_all_button: - MGTK_RELAY_CALL MGTK::PaintRect, desktop_aux::all_button_rect - rts - -test_proc: jmp (test_button_proc_addr) -fill_proc: jmp (fill_button_proc_addr) + ;; Initial state + copy #0, down_flag -test_button_proc_addr: .addr 0 -fill_button_proc_addr: .addr 0 + ;; Do initial inversion + jsr set_penmode_xor2 + jsr invert -event_loop: - sta click_result - copy #0, down_flag + ;; Event loop loop: MGTK_RELAY_CALL MGTK::GetEvent, event_params lda event_kind cmp #MGTK::EventKind::button_up beq exit - lda winfo_alert_dialog - sta event_params + lda window_id + sta screentowindow_window_id MGTK_RELAY_CALL MGTK::ScreenToWindow, screentowindow_params MGTK_RELAY_CALL MGTK::MoveTo, screentowindow_windowx - jsr test_proc + + ldax rect_addr + ldy #MGTK::InRect + jsr MGTK_RELAY + cmp #MGTK::inrect_inside beq inside lda down_flag ; outside but was inside? - beq invert + beq toggle jmp loop inside: lda down_flag ; already depressed? - bne invert + bne toggle jmp loop -invert: jsr set_penmode_xor2 - jsr fill_proc +toggle: jsr invert lda down_flag - clc - adc #$80 + eor #$80 sta down_flag jmp loop @@ -15283,17 +15201,29 @@ exit: lda down_flag ; was depressed? return #$FF ; hi bit = cancelled clicked: - jsr fill_proc ; invert one last time - return click_result ; grab expected result + jsr invert + return #0 + + ;; -------------------------------------------------- + +invert: ldax rect_addr + ldy #MGTK::PaintRect + jmp MGTK_RELAY + + ;; -------------------------------------------------- down_flag: .byte 0 -click_result: - .byte 0 +rect_addr: + .addr 0 +window_id: + .byte 0 .endproc +;;; ============================================================ + .proc noop rts .endproc diff --git a/desktop/desktop_res.s b/desktop/desktop_res.s index 425344a4..bcfedcd1 100644 --- a/desktop/desktop_res.s +++ b/desktop/desktop_res.s @@ -289,11 +289,13 @@ path_buf0: .res 65, 0 path_buf1: .res 65, 0 path_buf2: .res 65, 0 +kAlertDialogID = $0F + .params winfo_alert_dialog kWidth = 400 kHeight = 107 -window_id: .byte $0F +window_id: .byte kAlertDialogID options: .byte MGTK::Option::dialog_box title: .addr 0 hscroll: .byte MGTK::Scroll::option_none