-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathletk.inc
140 lines (109 loc) · 3.59 KB
/
letk.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
;;; ============================================================
;;; LineEdit ToolKit
;;; ============================================================
.scope LETK
.struct LineEditRecord
;;; --------------------------------------------------
;;; These fields are:
;;; * static for the life of the control
;;; * don't change within calls
;;; * are adjacent
;;; * order matters
;;; Window containing the control
window_id .byte
;;; Address of the text buffer
a_buf .addr
;;; Bounding rect of the control
rect .tag MGTK::Rect
;;; Set to the maximum length
max_length .byte
;;; Options. bit7 = centered
options .byte
;;; --------------------------------------------------
;;; Internal: Set when the caret in the control should blink.
active_flag .byte
;;; Internal: Position of the caret.
caret_pos .byte
;;; Internal: Set during the caret blink cycle while the caret is visible.
caret_flag .byte
;;; Internal: counter for the caret blink cycle.
caret_counter .word
.endstruct
kLineEditOptionsNormal = %00000000
kLineEditOptionsCentered = %10000000
.macro DEFINE_LINE_EDIT name, winid, buf, left, top, width, maxlen, options_param
.params name
window_id: .byte winid
a_buf: .addr buf
DEFINE_RECT_SZ rect, left+1, top+1, width-2, kTextBoxHeight-2
max_length: .byte maxlen
.if .paramcount > 7
options: .byte options_param
.else
options: .byte 0
.endif
dirty_flag: .byte 0
.res .sizeof(LETK::LineEditRecord) - (*-window_id)
.refto window_id
.refto a_buf
.refto rect
.refto max_length
.refto options
.refto dirty_flag
.endparams
.assert .sizeof(name) = .sizeof(LETK::LineEditRecord), error, "struct size"
.endmacro
;;; ============================================================
Init = $00 ; Initialize LineEditRecord members
;;; .addr record
Idle = $01 ; Call from event loop; blinks caret
;;; .addr record
Activate = $02 ; Move caret to the end and shows it
;;; .addr record
Deactivate = $03 ; Hide caret
;;; .addr record
Click = $04 ; Handle click within control bounds
;;; .addr record
;;; .word xcoord Click x location
;;; .word ycoord Click y location
;;; NOTE: Coordinates should be mapped from screen to window
Key = $05 ; Handle key press
;;; .addr record
;;; .byte key From MGTK::Event::key
;;; .byte modifiers From MGTK::Event::modifiers
;;; NOTE: Caller is responsible for filtering out undesired printables ($20-$7E)
Update = $06 ; Redraw control, e.g. after control moves or text changes
;;; .addr record
.endscope ; LETK
;;; ============================================================
.macro DEFINE_LINE_EDIT_PARAMS name, rec
.params name
record: .addr rec
;;; For `LETK::Key` calls:
key := * + 0
modifiers := * + 1
;;; For `LETK::Click` calls:
coords := * + 0
xcoord := * + 0
ycoord := * + 2
.res 4
.refto record
.refto key
.refto modifiers
.refto coords
.refto xcoord
.refto ycoord
.endparams
.endmacro
;;; ============================================================
;;; Scopes define their own LETKEntry identifiers
;;; This allows for helpers that e.g. bank switch before calling.
.macro LETK_CALL call, addr
jsr LETKEntry
.byte call
.if .paramcount > 1
.addr addr
.else
.addr 0
.endif
.endmacro