Skip to content

Commit

Permalink
Option Picker: Expose MoveToOption for callers
Browse files Browse the repository at this point in the history
All callers - which need to paint the option strings - were computing
the text offsets from the option position. Take care of this in the
lib instead.

(This doesn't save bytes because the lib is instantiated for each
client, but it makes the code more maintainable.)

No functional changes.
  • Loading branch information
inexorabletash committed Oct 9, 2023
1 parent e57a313 commit 3dc1780
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
9 changes: 3 additions & 6 deletions desktop/ovl_format_erase.s
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ kOptionPickerRows = kVolPickerRows
kOptionPickerCols = kVolPickerCols
kOptionPickerItemWidth = kVolPickerItemWidth
kOptionPickerItemHeight = kVolPickerItemHeight
kOptionPickerTextHOffset = kVolPickerTextHOffset
kOptionPickerTextVOffset = kVolPickerTextVOffset
kOptionPickerLeft = kVolPickerLeft
kOptionPickerTop = kVolPickerTop
option_picker_item_rect := vol_picker_item_rect
Expand Down Expand Up @@ -398,12 +400,7 @@ loop: lda #SELF_MODIFIED_BYTE
beq :+
rts
:
jsr option_picker::GetOptionPos
addax #kVolPickerTextHOffset, vol_picker_item_rect::x1
tya
ldx #0
addax #kVolPickerTextVOffset, vol_picker_item_rect::y1
MGTK_CALL MGTK::MoveTo, vol_picker_item_rect::topleft
jsr option_picker::MoveToOption

;; Reverse order, so boot volume is first
lda DEVCNT
Expand Down
10 changes: 3 additions & 7 deletions desktop/ovl_selector_pick.s
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ kOptionPickerRows = kShortcutPickerRows
kOptionPickerCols = kShortcutPickerCols
kOptionPickerItemWidth = kShortcutPickerItemWidth
kOptionPickerItemHeight = kShortcutPickerItemHeight
kOptionPickerTextHOffset = kShortcutPickerTextHOffset
kOptionPickerTextVOffset = kShortcutPickerTextVOffset
kOptionPickerLeft = kShortcutPickerLeft
kOptionPickerTop = kShortcutPickerTop
option_picker_item_rect := entry_picker_item_rect
Expand All @@ -413,13 +415,7 @@ option_picker_item_rect := entry_picker_item_rect
stax $06

tya
jsr option_picker::GetOptionPos
addax #kShortcutPickerTextHOffset, entry_picker_item_rect::x1
tya
ldx #0
addax #kShortcutPickerTextYOffset, entry_picker_item_rect::y1

MGTK_CALL MGTK::MoveTo, entry_picker_item_rect::topleft
jsr option_picker::MoveToOption
ldax $06
jmp DrawString
.endproc ; DrawEntry
Expand Down
2 changes: 1 addition & 1 deletion desktop/res.s
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ pensize_frame: .byte kBorderDX, kBorderDY
kShortcutPickerItemWidth = 104
kShortcutPickerItemHeight = kListItemHeight
kShortcutPickerTextHOffset = 10
kShortcutPickerTextYOffset = kShortcutPickerItemHeight - 1
kShortcutPickerTextVOffset = kShortcutPickerItemHeight - 1

;; Line endpoints
DEFINE_POINT entry_picker_line1_start, kBorderDX*2, 22
Expand Down
26 changes: 21 additions & 5 deletions lib/option_picker.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
;;; Option Picker Control
;;;
;;; API:
;;; * `GetOptionPos` - call when drawing labels (caller responsible)
;;; * `MoveToOption` - call when drawing labels (caller responsible)
;;; * `IsOptionPickerKey` - call to see if key would be handled
;;; * `HandleOptionPickerKey` - call to handle key
;;; * `HandleOptionPickerClick` - `screentowindow_params` must be mapped
Expand All @@ -17,6 +17,8 @@
;;; * `kOptionPickerCols` - const
;;; * `kOptionPickerItemWidth` - const
;;; * `kOptionPickerItemHeight` - const
;;; * `kOptionPickerTextHOffset` - const
;;; * `kOptionPickerItemVOffset` - const
;;; * `kOptionPickerLeft` - const
;;; * `kOptionPickerTop` - const
;;; Required definitions:
Expand Down Expand Up @@ -73,7 +75,7 @@ handle_entry_click:
.proc _HighlightIndex
bmi ret

jsr GetOptionPos
jsr _GetOptionPos
stax option_picker_item_rect + MGTK::Rect::x1
addax #kOptionPickerItemWidth-1, option_picker_item_rect + MGTK::Rect::x2
tya ; y lo
Expand All @@ -92,7 +94,7 @@ ret: rts
;;; Get the coordinates of an option by index.
;;; Input: A = volume index
;;; Output: A,X = x coordinate, Y = y coordinate
.proc GetOptionPos
.proc _GetOptionPos
ldx #0 ; hi
ldy #option_picker::kOptionPickerRows
jsr Divide_16_8_16
Expand Down Expand Up @@ -121,7 +123,21 @@ ret: rts
pla ; X coord lo

rts
.endproc ; GetOptionPos
.endproc ; _GetOptionPos

;;; ============================================================

.proc MoveToOption
jsr _GetOptionPos

addax #kOptionPickerTextHOffset, option_picker_item_rect+MGTK::Rect::x1
tya
ldx #0
addax #kOptionPickerTextVOffset, option_picker_item_rect+MGTK::Rect::y1
MGTK_CALL MGTK::MoveTo, option_picker_item_rect+MGTK::Rect::topleft

rts
.endproc ; MoveToOption

;;; ============================================================
;;; Inputs: `screentowindow_params` has `windowx` and `windowy` mapped
Expand Down Expand Up @@ -300,7 +316,7 @@ loop: clc
.endscope ; option_picker_impl

;;; "Exports"
GetOptionPos := option_picker_impl::GetOptionPos
MoveToOption := option_picker_impl::MoveToOption
IsOptionPickerKey := option_picker_impl::IsOptionPickerKey
HandleOptionPickerKey := option_picker_impl::HandleOptionPickerKey
HandleOptionPickerClick := option_picker_impl::HandleOptionPickerClick
Expand Down
9 changes: 3 additions & 6 deletions selector/app.s
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,8 @@ kOptionPickerRows = kEntryPickerRows
kOptionPickerCols = kEntryPickerCols
kOptionPickerItemWidth = kEntryPickerItemWidth
kOptionPickerItemHeight = kEntryPickerItemHeight
kOptionPickerTextHOffset = kEntryPickerTextHOffset
kOptionPickerTextVOffset = kEntryPickerTextVOffset
kOptionPickerLeft = kEntryPickerLeft
kOptionPickerTop = kEntryPickerTop
option_picker_item_rect := entry_picker_item_rect
Expand Down Expand Up @@ -1476,12 +1478,7 @@ prefix: pla
common: lda #winfo::kDialogId
jsr GetWindowPort
pla
jsr option_picker::GetOptionPos
addax #kEntryPickerTextHOffset, entry_picker_item_rect::x1
tya
ldx #0
addax #kEntryPickerTextVOffset, entry_picker_item_rect::y1
MGTK_CALL MGTK::MoveTo, entry_picker_item_rect::topleft
jsr option_picker::MoveToOption
param_call DrawString, entry_string_buf
rts
.endproc ; DrawListEntry
Expand Down

0 comments on commit 3dc1780

Please sign in to comment.