Skip to content

Commit

Permalink
Introduce LineEdit ToolKit (LETK)
Browse files Browse the repository at this point in the history
This reworks the line edit (text field) control logic from requiring
one instance of the code per control to a re-usable toolkit with an
MLI-style calling interface that operates on LineEditRecord instances.

The code gets somewhat more complicated, but this means that DAs don't
need their own copy of the library, and all instances inside DeskTop
-- rename (etc) dialog plus two in the file dialog -- can all share
the code.

The API itself could use some improvement (e.g. Activate should set
the blink_ip_flag) but this was intended to be a drop-in replacement
at first.

Related to #81.

No (intentional) behavior changes.
  • Loading branch information
inexorabletash committed Jul 11, 2022
1 parent 60b3513 commit 79bdae0
Show file tree
Hide file tree
Showing 23 changed files with 1,149 additions and 669 deletions.
88 changes: 44 additions & 44 deletions desk.acc/find.files.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
.include "../inc/macros.inc"
.include "../inc/prodos.inc"
.include "../mgtk/mgtk.inc"
.include "../letk/letk.inc"
.include "../common.inc"
.include "../desktop/desktop.inc"

MGTKEntry := MGTKAuxEntry
LETKEntry := LETKAuxEntry

;;; ============================================================
;;; Memory map
Expand Down Expand Up @@ -927,8 +929,6 @@ grafport_win: .tag MGTK::GrafPort

;; Left edges are adjusted dynamically based on label width
DEFINE_RECT input_rect, kFindLeft + kLabelHOffset, kControlsTop, kDAWidth-250, kControlsTop + kTextBoxHeight
DEFINE_RECT input_clear_rect, kFindLeft + kLabelHOffset+1, kControlsTop+1, kDAWidth-250-1, kControlsTop + kTextBoxHeight-1
DEFINE_POINT input_textpos, kTextBoxTextHOffset, kControlsTop + kTextBoxTextVOffset

DEFINE_BUTTON search, res_string_button_search, kDAWidth-235, kControlsTop
DEFINE_BUTTON cancel, res_string_button_cancel, kDAWidth-120, kControlsTop
Expand All @@ -941,41 +941,66 @@ pensize_frame: .byte kBorderDX, kBorderDY

cursor_ibeam_flag: .byte 0

kBufSize = 16 ; max length = 15, length
kBufSize = kMaxFilenameLength+1 ; max length = 15, length
buf_search: .res kBufSize, 0 ; search term

.include "../lib/line_edit_res.s"

top_row: .byte 0

;;; ============================================================
;;; Search field

.params line_edit_rec
window_id: .byte kDAWindowID
a_buf: .addr buf_search
;; NOTE: Left edges are adjusted dynamically based on label width
DEFINE_RECT rect, kFindLeft + kLabelHOffset+1, kControlsTop+1, kDAWidth-250-1, kControlsTop + kTextBoxHeight-1
DEFINE_POINT pos, kTextBoxTextHOffset, kControlsTop + kTextBoxTextVOffset
max_length: .byte kMaxFilenameLength
blink_ip_flag: .byte 0
dirty_flag: .byte 0
.res .sizeof(LETK::LineEditRecord) - (*-::line_edit_rec)
.endparams
.assert .sizeof(line_edit_rec) = .sizeof(LETK::LineEditRecord), error, "struct size"

.params le_params
record: .addr line_edit_rec
;;; For `LETK::Key` calls:
key := * + 0
modifiers := * + 1
;;; For `LETK::Click` calls:
coords := * + 0
xcoord := * + 0
ycoord := * + 2
.res 4
.endparams

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

.proc Init
;; Prep input string
copy #0, buf_search

jsr line_edit__Init
copy #$80, line_edit_res::blink_ip_flag
copy #kMaxFilenameLength, line_edit_res::max_length
LETK_CALL LETK::Init, le_params
copy #$80, line_edit_rec::blink_ip_flag

param_call MeasureString, find_label_str
addax input_rect::x1
add16 input_rect::x1, input_textpos::xcoord, input_textpos::xcoord
add16_8 input_rect::x1, #1, input_clear_rect::x1
add16 input_rect::x1, line_edit_rec::pos::xcoord, line_edit_rec::pos::xcoord
add16_8 input_rect::x1, #1, line_edit_rec::rect::x1

MGTK_CALL MGTK::OpenWindow, winfo
MGTK_CALL MGTK::OpenWindow, winfo_results
MGTK_CALL MGTK::HideCursor
jsr DrawWindow
jsr line_edit__Activate
LETK_CALL LETK::Activate, le_params
jsr DrawResults
MGTK_CALL MGTK::ShowCursor
MGTK_CALL MGTK::FlushEvents
FALL_THROUGH_TO InputLoop
.endproc

.proc InputLoop
jsr line_edit__Idle
LETK_CALL LETK::Idle, le_params
param_call JTRelay, JUMP_TABLE_YIELD_LOOP
MGTK_CALL MGTK::GetEvent, event_params
lda event_params::kind
Expand All @@ -999,41 +1024,14 @@ top_row: .byte 0
rts
.endproc

;;; ============================================================
;;; Line Edit

.scope line_edit
buf_text := buf_search
textpos := input_textpos
clear_rect := input_clear_rect
frame_rect := input_rect
NotifyTextChanged := NoOp
click_coords := screentowindow_params::window

.proc SetPort
copy #kDAWindowID, getwinport_params::window_id
MGTK_CALL MGTK::GetWinPort, getwinport_params
MGTK_CALL MGTK::SetPort, grafport_win
rts
.endproc

.proc NoOp
rts
.endproc

.include "../lib/line_edit.s"

.endscope ; line_edit
line_edit__Init := line_edit::Init
line_edit__Idle := line_edit::Idle
line_edit__Activate := line_edit::Activate

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

.proc HandleKey
lda event_params::key
sta le_params::key

ldx event_params::modifiers
stx le_params::modifiers
IF_NOT_ZERO
cpx #3 ; both?
IF_EQ
Expand Down Expand Up @@ -1064,7 +1062,7 @@ line_edit__Activate := line_edit::Activate
END_IF
END_IF

jsr line_edit::Key
LETK_CALL LETK::Key, le_params
ELSE
;; Not modified
cmp #CHAR_ESCAPE
Expand Down Expand Up @@ -1095,7 +1093,7 @@ line_edit__Activate := line_edit::Activate
bcc allow
jsr IsSearchChar
bcs ignore
allow: jsr line_edit::Key
allow: LETK_CALL LETK::Key, le_params
ignore:
END_IF

Expand Down Expand Up @@ -1234,7 +1232,9 @@ finish: jmp InputLoop
MGTK_CALL MGTK::InRect, input_rect
cmp #MGTK::inrect_inside
bne done
jsr line_edit::Click

COPY_STRUCT MGTK::Point, screentowindow_params::window, le_params::coords
LETK_CALL LETK::Click, le_params

done: jmp InputLoop

Expand Down
70 changes: 34 additions & 36 deletions desk.acc/map.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
.include "../inc/apple2.inc"
.include "../inc/macros.inc"
.include "../mgtk/mgtk.inc"
.include "../letk/letk.inc"
.include "../common.inc"
.include "../desktop/desktop.inc"

MGTKEntry := MGTKAuxEntry
LETKEntry := LETKAuxEntry

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

Expand Down Expand Up @@ -68,9 +70,6 @@ kTextBoxLeft = kControlsLeft
kTextBoxTop = kRow1
kTextBoxWidth = 7 * 15 + 2 * kTextBoxTextHOffset
DEFINE_RECT_SZ input_rect, kTextBoxLeft, kTextBoxTop, kTextBoxWidth, kTextBoxHeight
DEFINE_RECT_SZ input_clear_rect, kTextBoxLeft+1, kTextBoxTop+1, kTextBoxWidth-2, kTextBoxHeight-2
DEFINE_POINT input_textpos, kTextBoxLeft + kTextBoxTextHOffset, kTextBoxTop + kTextBoxTextVOffset

DEFINE_BUTTON find, res_string_button_find, kTextBoxLeft + kTextBoxWidth + 5, kTextBoxTop, 62

kLabelLeft = kControlsLeft + kTextBoxTextHOffset
Expand Down Expand Up @@ -245,40 +244,36 @@ cursor_ibeam_flag: .byte 0
kBufSize = 16 ; max length = 15, length
buf_search: .res kBufSize, 0 ; search term

.include "../lib/line_edit_res.s"

.scope line_edit
buf_text := buf_search
textpos := input_textpos
clear_rect := input_clear_rect
frame_rect := input_rect
NotifyTextChanged := NoOp
click_coords := screentowindow_params::window

.proc SetPort
copy #kDAWindowId, getwinport_params::window_id
MGTK_CALL MGTK::GetWinPort, getwinport_params
;; ASSERT: Result is not MGTK::Error::window_obscured
;; (HandleDrag forces window to be onscreen)
MGTK_CALL MGTK::SetPort, grafport_win
rts
.endproc

.proc NoOp
rts
.endproc

.include "../lib/line_edit.s"

.endscope ; line_edit
.params line_edit_rec
window_id: .byte kDAWindowId
a_buf: .addr buf_search
DEFINE_RECT_SZ rect, kTextBoxLeft+1, kTextBoxTop+1, kTextBoxWidth-2, kTextBoxHeight-2
DEFINE_POINT pos, kTextBoxLeft + kTextBoxTextHOffset, kTextBoxTop + kTextBoxTextVOffset
max_length: .byte kBufSize - 1
blink_ip_flag: .byte 0
dirty_flag: .byte 0
.res .sizeof(LETK::LineEditRecord) - (*-::line_edit_rec)
.endparams
.assert .sizeof(line_edit_rec) = .sizeof(LETK::LineEditRecord), error, "struct size"

.params le_params
record: .addr line_edit_rec
;;; For `LETK::Key` calls:
key := * + 0
modifiers := * + 1
;;; For `LETK::Click` calls:
coords := * + 0
xcoord := * + 0
ycoord := * + 2
.res 4
.endparams

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

.proc Init
copy #0, buf_search
jsr line_edit::Init
copy #$80, line_edit_res::blink_ip_flag
copy #kBufSize-1, line_edit_res::max_length
LETK_CALL LETK::Init, le_params
copy #$80, line_edit_rec::blink_ip_flag

MGTK_CALL MGTK::OpenWindow, winfo
jsr UpdateCoordsFromLatLong
Expand All @@ -288,7 +283,7 @@ buf_search: .res kBufSize, 0 ; search term
.endproc

.proc InputLoop
jsr line_edit::Idle
LETK_CALL LETK::Idle, le_params
param_call JTRelay, JUMP_TABLE_YIELD_LOOP
MGTK_CALL MGTK::GetEvent, event_params
lda event_params::kind
Expand Down Expand Up @@ -322,7 +317,9 @@ buf_search: .res kBufSize, 0 ; search term
jmp InputLoop
END_IF

jsr line_edit::Key
copy event_params::key, le_params::key
copy event_params::modifiers, le_params::modifiers
LETK_CALL LETK::Key, le_params
jmp InputLoop
.endproc

Expand Down Expand Up @@ -499,7 +496,8 @@ ret: rts
;; Click in line edit?
MGTK_CALL MGTK::InRect, input_rect
IF_NE
jsr line_edit::Click
COPY_STRUCT MGTK::Point, screentowindow_params::window, le_params::coords
LETK_CALL LETK::Click, le_params
jmp done
END_IF

Expand Down Expand Up @@ -641,7 +639,7 @@ done: jmp InputLoop

MGTK_CALL MGTK::SetPenMode, notpencopy
MGTK_CALL MGTK::FrameRect, input_rect
jsr line_edit::Activate
LETK_CALL LETK::Activate, le_params

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

Expand Down
3 changes: 2 additions & 1 deletion desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ When running, memory use includes:
* $8600-$BFFF - Resources and tookits, with floating memory layout
* Resources, including icons, font, menu definitions, etc.
* [Icon ToolKit](APIs.md)
* [LineEdit ToolKit](../letk/LETK.md)
* Alert dialog resources/code

...and in the Aux language card area (accessible from both aux and
Expand Down Expand Up @@ -195,10 +196,10 @@ $BF00 +-------------+ | Utilities & |
| DeskTop | | Resources |
| App Code | | |
| | | * Icon TK |
| | | * LE TK |
| | | * Alerts |
| | | |
| | | |
| | | |
$A000 | +------+ | |
| | Ovl | | |
| | | | |
Expand Down
12 changes: 12 additions & 0 deletions desktop/auxmem.s
Original file line number Diff line number Diff line change
Expand Up @@ -2969,6 +2969,11 @@ case2:

.endscope ; icon_toolkit

;;; ============================================================
;;; Line Edit ToolKit
;;; ============================================================

.include "../letk/letk.s"

;;; ============================================================
;;; Menus
Expand Down Expand Up @@ -3661,6 +3666,13 @@ app_mask:
.byte PX(%0000000),PX(%0000000),PX(%1111110),PX(%0000000),PX(%0000000)
.byte PX(%0000000),PX(%0000000),PX(%0011000),PX(%0000000),PX(%0000000)

;;; ============================================================
;;; Relay table at fixed memory location (see desktop.s)
;;; These are used by DAs calling directly from aux.

PAD_TO ::LETKAuxEntry
jmp letk::LETKEntry

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

PAD_TO ::kSegmentDeskTopAuxAddress + ::kSegmentDeskTopAuxLength
Expand Down
3 changes: 3 additions & 0 deletions desktop/desktop.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
;;; MGTK loaded into AUX; to call from MAIN use JUMP_TABLE_MGTK_CALL
MGTKAuxEntry := $4000

;;; LETK loaded into AUX; to call from MAIN use JUMP_TABLE_LETK_CALL
LETKAuxEntry := $BFFD

;;; Desk Accessories are loaded in Main ($800-$1BFF) using
;;; an I/O buffer (Main $1C00-1FFF). DAs often copy themselves
;;; into Aux but can only use $800-$1AFF due to entry tables.
Expand Down
1 change: 1 addition & 0 deletions desktop/desktop.s
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.include "../inc/prodos.inc"
.include "../inc/smartport.inc"
.include "../mgtk/mgtk.inc"
.include "../letk/letk.inc"
.include "../common.inc"
.include "../desktop/desktop.inc"
.include "../desktop/icontk.inc"
Expand Down
2 changes: 1 addition & 1 deletion desktop/internal.inc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ _segoffset .set 0
;;; Dynamically loaded overlays
DEFSEG OverlayFormatErase, $0800, $1100
DEFSEG OverlayShortcutPick, $9000, $0C00
DEFSEG OverlayFileDialog, $5000, $1700
DEFSEG OverlayFileDialog, $5000, $1300
DEFSEG OverlayFileCopy, $7000, $0200
DEFSEG OverlayFileDelete, $7000, $0100
DEFSEG OverlayShortcutEdit, $7000, $0500
Expand Down
8 changes: 8 additions & 0 deletions desktop/lc.s
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ params: .res 3
jmp ParamsRelayImpl
.endproc

;;; ============================================================
;;; LineEditTK call from main>aux, MLI-style params

.proc LETKRelayImpl
ldax #aux::letk::LETKEntry
jmp ParamsRelayImpl
.endproc


;;; ============================================================
;;; Used/Free icon map (Aux $1F80 - $1FFF)
Expand Down
Loading

0 comments on commit 79bdae0

Please sign in to comment.