-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplitScreen.INC
318 lines (284 loc) · 11.2 KB
/
SplitScreen.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
'SPLIT SCREEN library
'JirSoft 2021
CONST VERSION.SPLIT = "0.05"
'can be used for spltting the screen into areas, where can be either printed-out text or loaded image
'area is defined in control string, so you can define many areas...
'overlapping of areas is not checked
'SUBs are used because every needs CONTROL STRING as pasrameter and it's also updated
'CONTROL STRING DESCRIPTION (cs$, 22 bytes)
' dx% = STR2BIN(UINT16, LEFT$(cs$, 2)) x-coordinate of Left upper corner of the screen part
' dy% = STR2BIN(UINT16, MID$(cs$, 3, 2)) y-coordinate of Left upper corner of the screen part
'
' w% = STR2BIN(UINT16, MID$(cs$, 5, 2)) width of the screen part
' h% = STR2BIN(UINT16, MID$(cs$, 7, 2)) height of the screen part
'
' x% = STR2BIN(UINT16, MID$(cs$, 9, 2)) x-coordinate of the cursor (left upper)
' y% = STR2BIN(UINT16, MID$(cs$, 11, 2)) y-coordinate of the cursor (left upper)
'
' t% = STR2BIN(UINT8, MID$(cs$, 13, 1)) TAB width in pixels
'
' f% = STR2BIN(UINT8, MID$(cs$, 14, 1)) FONT
'
' fc% = STR2BIN(UINT32, MID$(cs$, 15, 4)) foreground color
' bc% = STR2BIN(UINT32, MID$(cs$, 19, 4)) background color
'SUB init.SPLIT(cs$, dx%, dy%, w%, h%)
'creates new screen part X/Y/WIDTH/HEIGHT and sets control string cs$
'SUB setStyle.SPLIT(cs$, t%, f%, fc%, bc%)
'sets TAB, FONT, FOREGROUND and BACKGROUND
'for not changing default, set the value to -1
'SIB cls.SPLIT(cs$)
'clears the screen, sets X/Y to 0
'SUB print.SPLIT(cs$, txt$)
'main FUNCTION for string output, parameteres are control string and txt$ to output
'CHR$(8) is TAB character, used to go to the next TAB position
'CHR$(10) is line feed character, uset to go to begin of the next line (screen can be scrolled up)
'other ASCII codes bellow CHR$(32) are ignored
'FUNCTION loadImage.SPLIT(cs$, fn$, iw%, ih%)
'load image into full part of the screen
'when we know image width/height (iw%/ih%) is used (need to be smaller than MM.XRES/MM.YRES)
'returns TRUE (=1) when OK
'FUNCTION input.SPLIT(cs$, allowedChars$, maxLen%) AS STRING
'allows to input string in any split area, use any charaters from allowedChar$ (or any, if this string is empty)
'you can delete last character with BACKSPACE, finish the input with ENTER or RETURN (this will be not part of the returned string)
'with maxLen% you can limit length of the input, if it's <=0 or >255 then the limit will be 255 characters
SUB init.SPLIT(cs$, dx%, dy%, w%, h%)
'creates new screen part X/Y/WIDTH/HEIGHT and sets control string cs$
cs$ = BIN2STR$(UINT16, dx%) + BIN2STR$(UINT16, dy%) 'x/y position of the LEFT upper screen corner
CAT cs$, BIN2STR$(UINT16, w%) + BIN2STR$(UINT16, h%) 'width/height of the screen
CAT cs$, BIN2STR$(UINT16, 0) + BIN2STR$(UINT16, 0) 'x/y position of the cursor relative to dx%/dy%
CAT cs$, BIN2STR$(UINT8, 20) 'default TAB in pixels
CAT cs$, BIN2STR$(UINT8, 1) 'default FONT
CAT cs$, BIN2STR$(UINT32, RGB(WHITE)) + BIN2STR$(UINT32, RGB(NOTBLACK)) 'default FOREGROUND and BACKGROUND colors
END SUB
SUB setStyle.SPLIT(cs$, t%, f%, fc%, bc%)
'sets TAB, FONT, FOREGROUND and BACKGROUND
'for not changing default, set the value to -1
IF t%>0 THEN 'TAB in pixels
MID$(cs$, 13, 1) = BIN2STR$(UINT8, t% AND 255)
ENDIF
IF f%>0 AND f%<9 THEN 'FONT
MID$(cs$, 14, 1) = BIN2STR$(UINT8, f%)
ENDIF
IF fc%>=0 THEN 'FOREGROUND color
MID$(cs$, 15, 4) = BIN2STR$(UINT32, fc% AND &hFFFFFF)
ENDIF
IF bc%>=0 THEN 'BACKGROUND color
MID$(cs$, 19, 4) = BIN2STR$(UINT32, bc% AND &hFFFFFF))
ENDIF
END SUB
SUB cls.SPLIT(cs$)
'clears the screen, sets X/Y to 0
MID$(cs$, 9, 4) = BIN2STR$(UINT16, 0) + BIN2STR$(UINT16, 0)
BOX STR2BIN(UINT16, LEFT$(cs$, 2)), STR2BIN(UINT16, MID$(cs$, 3, 2)), STR2BIN(UINT16, MID$(cs$, 5, 2)), STR2BIN(UINT16, MID$(cs$, 7, 2)), 0, STR2BIN(UINT32, MID$(cs$, 19, 4)), STR2BIN(UINT32, MID$(cs$, 19, 4))
END SUB
SUB print.SPLIT(cs$, txt$)
'main SUB for string output, parameteres are control string and txt$ to output
'CHR$(8) is TAB character, used to go to the next TAB position
'CHR$(10) is line feed character, uset to go to begin of the next line (screen can be scrolled up)
'other ASCII codes bellow CHR$(32) are ignored
LOCAL INTEGER dx = STR2BIN(UINT16, LEFT$(cs$, 2))
LOCAL INTEGER dy = STR2BIN(UINT16, MID$(cs$, 3, 2))
LOCAL INTEGER w = STR2BIN(UINT16, MID$(cs$, 5, 2))
LOCAL INTEGER h = STR2BIN(UINT16, MID$(cs$, 7, 2))
LOCAL INTEGER x = STR2BIN(UINT16, MID$(cs$, 9, 2))
LOCAL INTEGER y = STR2BIN(UINT16, MID$(cs$, 11, 2))
LOCAL INTEGER t = STR2BIN(UINT8, MID$(cs$, 13, 1))
LOCAL INTEGER f = STR2BIN(UINT8, MID$(cs$, 14, 1))
LOCAL INTEGER fc = STR2BIN(UINT32, MID$(cs$, 15, 4))
LOCAL INTEGER bc = STR2BIN(UINT32, MID$(cs$, 19, 4))
FONT f, 1
LOCAL INTEGER fh = MM.INFO(FONTHEIGHT)
LOCAL INTEGER fw = MM.INFO(FONTWIDTH)
LOCAL INTEGER i
LOCAL STRING ch
FOR i = 1 TO LEN(txt$)
ch = MID$(txt$, i, 1)
IF ch<" " THEN
IF ch=CHR$(10) THEN 'line feed
x = 0
IF (y+fh)<h THEN
INC y, fh
ELSE
'scrolling, repeated because of saving SUB/FUNCTION slot
BLIT dx, dy+fh, dx, dy, w, h-fh
BOX dx, dy+y, w, h-y, 0, bc, bc
ENDIF
ELSEIF ch=CHR$(9) THEN 'TAB
nx = t*INT(x\t)
IF nx<=x THEN INC nx, t
IF (nx+fw)<=w THEN
x = nx
ELSE
x = 0
IF (y+fh)<h THEN
INC y, fh
ELSE
'scrolling, repeated because of saving SUB/FUNCTION slot
BLIT dx, dy+fh, dx, dy, w, h-fh
BOX dx, dy+y, w, h-y, 0, bc, bc
ENDIF
ENDIF
ENDIF
ELSE
'normal char to output
IF (x+fw)>w THEN 'char can't be placed into current line
x = 0
IF (y+fh)<h THEN
INC y, fh
ELSE
'scrolling, repeated because of saving SUB/FUNCTION slot
BLIT dx, dy+fh, dx, dy, w, h-fh
BOX dx, dy+y, w, h-y, 0, bc, bc
ENDIF
ENDIF
TEXT dx+x, dy+y, ch, "LT", f, 1, fc, bc
INC x, fw
ENDIF
NEXT i
MID$(cs$, 9, 4) = BIN2STR$(UINT16, x) + BIN2STR$(UINT16, y)
END SUB
FUNCTION loadImage.SPLIT(cs$, fn$, iw%, ih%) AS INTEGER
'load image into full part of the screen
'when we know image width/height (iw%/ih%) is used (need to be smaller than MM.XRES/MM.YRES)
'returns TRUE (=1) when OK
LOCAL STRING ext = UCASE$(RIGHT$(fn$, 4))
LOCAL INTEGER dx = STR2BIN(UINT16, LEFT$(cs$, 2))
LOCAL INTEGER dy = STR2BIN(UINT16, MID$(cs$, 3, 2))
LOCAL INTEGER w = STR2BIN(UINT16, MID$(cs$, 5, 2))
LOCAL INTEGER h = STR2BIN(UINT16, MID$(cs$, 7, 2))
loadImage.SPLIT = 0 'ERROR
PAGE WRITE 1
SELECT CASE ext
CASE ".GIF"
ON ERROR SKIP
LOAD GIF fn$
IF NOT MM.ERRNO THEN loadImage.SPLIT = 1
CASE ".BMP"
ON ERROR SKIP
LOAD BMP fn$
IF NOT MM.ERRNO THEN loadImage.SPLIT = 1
CASE ".JPG"
ON ERROR SKIP
LOAD JPG fn$
IF NOT MM.ERRNO THEN loadImage.SPLIT = 1
CASE ".PNG"
ON ERROR SKIP
LOAD PNG fn$
IF NOT MM.ERRNO THEN loadImage.SPLIT = 1
END SELECT
PAGE WRITE 0
IF loadImage.SPLIT THEN
IF iw%>0 AND ih%>0 THEN 'image width and height is known and used
IMAGE RESIZE 0, 0, iw%, ih%, dx, dy, w, h, 1
ELSE 'resize whole page to selected area
IMAGE RESIZE 0, 0, MM.HRES, MM.VRES, dx, dy, w, h, 1
ENDIF
ENDIF
END FUNCTION
FUNCTION input.SPLIT(cs$, allowedChars$, maxLen%) AS STRING
'allows to input string in any split area, use any charaters from allowedChar$ (or any, if this string is empty)
'you can delete last character with BACKSPACE, finish the input with ENTER or RETURN (this will be not part of the returned string)
'with maxLen% you can limit length of the input, if it's <=0 or >255 then the limit will be 255 characters
LOCAL STRING k, lf = CHR$(10), cr = CHR$(13), bs = CHR$(8), lineEndMem = ""
LOCAL INTEGER dx = STR2BIN(UINT16, LEFT$(cs$, 2))
LOCAL INTEGER dy = STR2BIN(UINT16, MID$(cs$, 3, 2))
LOCAL INTEGER w = STR2BIN(UINT16, MID$(cs$, 5, 2))
LOCAL INTEGER h = STR2BIN(UINT16, MID$(cs$, 7, 2))
LOCAL INTEGER x = STR2BIN(UINT16, MID$(cs$, 9, 2))
LOCAL INTEGER y = STR2BIN(UINT16, MID$(cs$, 11, 2))
LOCAL INTEGER t = STR2BIN(UINT8, MID$(cs$, 13, 1))
LOCAL INTEGER f = STR2BIN(UINT8, MID$(cs$, 14, 1))
LOCAL INTEGER fc = STR2BIN(UINT32, MID$(cs$, 15, 4))
LOCAL INTEGER bc = STR2BIN(UINT32, MID$(cs$, 19, 4))
FONT f, 1
LOCAL INTEGER fh = MM.INFO(FONTHEIGHT)
LOCAL INTEGER fw = MM.INFO(FONTWIDTH)
CONST cspd = 300 'cursorblink speed in ms
CONST cst = 1 'cursor thickness
LOCAL INTEGER cx = x, cy = y, con, ct = TIMER + cspd
input.SPLIT = ""
IF maxLen%<1 THEN maxLen% = 255
'prepare cursor
IF (cx+fw)>w then
'cursof is on next line
cx = 0
IF (cy+fh)<=h THEN
INC cy, fh
ELSE
INC cy, -fh
BLIT dx, dy+fh, dx, dy, w, h-fh
BOX dx, dy+cy, w, h-cy, 0, bc, bc
ENDIF
ENDIF
con = 1
LINE dx+cx, dy+cy+fh-cst, dx+cx+fw-1, dy+cy+fh-cst, cst, fc
DO
k = ""
DO WHILE k=""
k = INKEY$
IF TIMER>ct THEN
IF con THEN 'blink cursor
LINE dx+cx, dy+cy+fh-cst, dx+cx+fw-1, dy+cy+fh-cst, cst, bc
ELSE
LINE dx+cx, dy+cy+fh-cst, dx+cx+fw-1, dy+cy+fh-cst, cst, fc
ENDIF
con = 1 - con
ct = TIMER + cspd
ENDIF
LOOP
IF k=bs THEN 'BACKSPACE
IF input.SPLIT<>"" THEN
input.SPLIT = LEFT$(input.SPLIT, LEN(input.SPLIT)-1)
'delete char, move cursor left
IF con THEN 'delete cursor
LINE dx+cx, dy+cy+fh-cst, dx+cx+fw-1, dy+cy+fh-cst, cst, bc
ENDIF
IF cx>=fw THEN 'still on current line
INC cx, -fw
ELSE 'deleted char on previous line
IF cy>=fh THEN 'we can't redraw already missed lines out of window
INC cy, -fh
cx = STR2BIN(UINT16, RIGHT$(lineEndMem, 2))
lineEndMem = LEFT$(lineEndMem, LEN(lineEndMem)-2)
ENDIF
ENDIF
TEXT dx+cx, dy+cy, " ", "LT", f, 1, fc, bc
con = 1
LINE dx+cx, dy+cy+fh-cst, dx+cx+fw-1, dy+cy+fh-cst, cst, fc
ct = TIMER + cspd
ENDIF
ELSEIF k=cr OR k=lf THEN 'ENTER/RETURN
IF con THEN 'delete cursor
LINE dx+cx, dy+cy+fh-cst, dx+cx+fw-1, dy+cy+fh-cst, cst, bc
ENDIF
x = cx
y = cy
ELSEIF k>=" " THEN 'normal character
IF LEN(input.SPLIT)<maxLen% THEN
IF INSTR(allowedChars$, k)>0 OR allowedChars$="" THEN
CAT input.SPLIT, k
'print char, move X, prepare cursor
TEXT dx+cx, dy+cy, k, "LT", f, 1, fc, bc
INC cx, fw
ENDIF
IF (cx+fw)>w then
'cursof is on next line
CAT lineEndMem, BIN2STR$(UINT16, cx-fw)
cx = 0
IF (cy+fh)<=h THEN
INC cy, fh
ELSE
INC cy, -fh
BLIT dx, dy+fh, dx, dy, w, h-fh
BOX dx, dy+cy, w, h-cy, 0, bc, bc
ENDIF
ENDIF
con = 1
LINE dx+cx, dy+cy+fh-cst, dx+cx+fw-1, dy+cy+fh-cst, cst, fc
ct = TIMER + cspd
ENDIF
ENDIF
LOOP UNTIL k=cr OR k=lf
DO WHILE INKEY$<>"":LOOP
MID$(cs$, 9, 4) = BIN2STR$(UINT16, x) + BIN2STR$(UINT16, y)
END FUNCTION