Skip to content

Commit

Permalink
DeskTop: Refactor button event loop, more flexible proc, save a bunch…
Browse files Browse the repository at this point in the history
… of bytes
  • Loading branch information
inexorabletash committed Mar 1, 2020
1 parent 20c15cd commit 7f4be7f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 115 deletions.
158 changes: 44 additions & 114 deletions desktop/desktop_main.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion desktop/desktop_res.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7f4be7f

Please sign in to comment.