Rev 4060 | Rev 4621 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4060 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
4143 | hidnplayr | 6 | ;; Written by hidnplayr@kolibrios.org ;; |
4060 | hidnplayr | 7 | ;; ;; |
8 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
9 | ;; Version 2, June 1991 ;; |
||
10 | ;; ;; |
||
11 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
12 | |||
13 | |||
4143 | hidnplayr | 14 | text_insert_newlines: ; esi = ASCIIZ string |
15 | |||
16 | xor edx, edx ; number of lines of text |
||
17 | cmp byte[esi], 0 |
||
18 | je .done |
||
19 | .next_line: |
||
20 | xor ebx, ebx |
||
21 | mov ecx, [textbox_width] |
||
22 | inc ecx |
||
23 | .more: |
||
24 | dec ecx |
||
25 | jz .end_of_line |
||
26 | lodsb ; get one character of the string |
||
27 | test al, al ; end of string? |
||
28 | jz .almost_done |
||
29 | cmp al, ' ' ; it's a space! remember its position |
||
30 | je .space |
||
31 | cmp al, 13 ; we already inserted a newline once, make it a space again |
||
32 | je .soft_nl |
||
33 | cmp al, 10 ; it's a newline, continue onto the next line |
||
34 | jne .more |
||
35 | inc edx |
||
36 | jmp .next_line |
||
37 | .soft_nl: |
||
38 | inc edx |
||
39 | mov byte[esi-1], ' ' |
||
40 | mov ebx, esi |
||
41 | jmp .more |
||
42 | .space: |
||
43 | mov ebx, esi ; last detected space |
||
44 | jmp .more |
||
45 | .end_of_line: |
||
46 | inc edx |
||
47 | test ebx, ebx ; did we detect any spaces on this line? |
||
48 | jz .next_line ; no: just continue onto the next line |
||
49 | mov byte[ebx-1], 13 ; yes: replace last space on line with a soft newline |
||
50 | mov esi, ebx ; and continue parsing just after last space |
||
51 | jmp .next_line ; |
||
52 | .almost_done: |
||
53 | dec esi |
||
54 | .done: |
||
55 | |||
56 | ret |
||
57 | |||
58 | ; When you set the direction flag before calling, you can also scan for previous line! |
||
59 | ; in: esi |
||
60 | ; out:esi |
||
61 | text_nextline: |
||
62 | |||
63 | mov ecx, [textbox_width] |
||
64 | .loop: |
||
65 | cmp byte[esi], 0 |
||
66 | je .done |
||
67 | lodsb |
||
68 | cmp al, 10 |
||
69 | je .done |
||
70 | cmp al, 13 |
||
71 | je .done |
||
72 | dec ecx |
||
73 | jnz .loop |
||
74 | .done: |
||
75 | |||
76 | ret |
||
77 | |||
78 | |||
4060 | hidnplayr | 79 | print_text: ; eax = start ptr |
80 | ; dl = end char |
||
81 | pusha |
||
82 | ptr2: |
||
83 | mov bl, [eax] |
||
84 | |||
85 | cmp bl, dl |
||
86 | je .done |
||
87 | test bl, bl |
||
88 | jz .done |
||
89 | call print_character |
||
90 | |||
91 | inc eax |
||
92 | jmp ptr2 |
||
93 | |||
94 | .done: |
||
95 | popa |
||
4143 | hidnplayr | 96 | |
4060 | hidnplayr | 97 | ret |
98 | |||
99 | |||
100 | |||
101 | print_text2: ; esi = ptr to ASCIIZ string |
||
102 | |||
103 | pusha |
||
104 | .loop: |
||
105 | lodsb |
||
106 | test al, al |
||
107 | jz .done |
||
108 | mov bl, al |
||
109 | call print_character |
||
110 | jmp .loop |
||
111 | |||
112 | .done: |
||
113 | popa |
||
4143 | hidnplayr | 114 | |
4060 | hidnplayr | 115 | ret |
116 | |||
117 | |||
118 | print_character: |
||
119 | |||
4143 | hidnplayr | 120 | push esi edi |
121 | mov esi, [window_print] |
||
122 | mov edi, [esi + window.text_write] |
||
123 | mov byte[edi], bl |
||
124 | inc edi |
||
125 | cmp edi, [esi + window.text_end] |
||
126 | jae .uh_ow |
||
127 | mov [esi + window.text_write], edi |
||
128 | .continue: |
||
129 | or [esi + window.flags], FLAG_UPDATED |
||
130 | pop edi esi |
||
131 | |||
132 | ret |
||
133 | |||
134 | .uh_ow: |
||
135 | |||
4060 | hidnplayr | 136 | pusha |
4143 | hidnplayr | 137 | mov edi, [esi + window.text_start] |
138 | mov [esi + window.text_print], edi |
||
139 | lea esi, [edi + TEXT_BUFFERSIZE/2] |
||
140 | call text_nextline |
||
141 | mov ecx, TEXT_BUFFERSIZE/8 |
||
142 | rep movsd |
||
143 | mov esi, edi |
||
144 | call text_insert_newlines |
||
4060 | hidnplayr | 145 | |
4143 | hidnplayr | 146 | mov ebx, [window_print] |
147 | mov [ebx + window.text_lines], edx |
||
148 | mov [ebx + window.text_scanned], esi |
||
149 | mov [ebx + window.text_write], esi |
||
150 | mov [ebx + window.text_line_print], 0 |
||
151 | popa |
||
4060 | hidnplayr | 152 | |
4143 | hidnplayr | 153 | jmp .continue |
4060 | hidnplayr | 154 | |
155 | |||
156 | |||
4143 | hidnplayr | 157 | draw_channel_text: |
4060 | hidnplayr | 158 | |
4143 | hidnplayr | 159 | mov edi, [window_active] |
160 | and [edi + window.flags], not FLAG_UPDATED ; clear the 'window is updated' flag |
||
4060 | hidnplayr | 161 | |
4143 | hidnplayr | 162 | ; Scan new text for newlines |
163 | mov esi, [edi + window.text_scanned] |
||
164 | call text_insert_newlines |
||
165 | add [edi + window.text_lines], edx |
||
166 | mov [edi + window.text_scanned], esi |
||
4060 | hidnplayr | 167 | |
4143 | hidnplayr | 168 | ; should we scroll up/down some lines ? ; TODO: only scroll down automatically when scrollbar is at lowest position ? |
169 | mov edx, [edi + window.text_lines] |
||
170 | sub edx, [textbox_height] |
||
171 | jle .noscroll ; There are less lines of text than fit into the window, dont scroll.. |
||
172 | sub edx, [edi + window.text_line_print] |
||
173 | je .noscroll ; We are already at the bottom pos, dont scroll.. |
||
4060 | hidnplayr | 174 | |
4143 | hidnplayr | 175 | .scroll_to_pos: ; edx = number of lines to go up/down (flags must indicate direction) |
176 | pushf |
||
177 | add [edi + window.text_line_print], edx |
||
178 | mov esi, [edi + window.text_print] |
||
179 | popf |
||
180 | ja .loop_forward |
||
181 | std ; set direction flag so we can scan backwards |
||
182 | dec esi ; move our cursor just in front of newline, for scanning backwards |
||
183 | dec edx ;;;;; FIXME: this seems to be needed, but why ??? |
||
184 | .loop_backward: |
||
185 | call text_nextline |
||
186 | inc edx |
||
187 | jnz .loop_backward |
||
188 | inc esi ; move the cursor just after last newline |
||
189 | cld |
||
190 | jmp .ok |
||
4060 | hidnplayr | 191 | |
4143 | hidnplayr | 192 | .loop_forward: |
193 | call text_nextline |
||
194 | dec edx |
||
195 | jnz .loop_forward |
||
196 | .ok: |
||
197 | mov [edi + window.text_print], esi |
||
198 | .noscroll: |
||
4060 | hidnplayr | 199 | |
4143 | hidnplayr | 200 | mov edx, [edi + window.text_print] |
201 | ; Calculate start coordinates (align text to bottom) |
||
202 | mov ebx, [textbox_height] |
||
203 | sub ebx, [edi + window.text_lines] |
||
204 | jae @f |
||
205 | xor ebx, ebx |
||
206 | @@: |
||
207 | imul ebx, FONT_HEIGHT |
||
208 | add ebx, TEXT_X shl 16 + TEXT_Y |
||
4060 | hidnplayr | 209 | |
4143 | hidnplayr | 210 | ; Prepare to actually draw some text |
211 | mov eax, [textbox_height] ; max number of lines to draw |
||
212 | mov ecx, [colors.work_text] ; default text color |
||
213 | .drawloop: |
||
214 | cmp byte[edx], 0 |
||
215 | je .end |
||
4060 | hidnplayr | 216 | |
4143 | hidnplayr | 217 | ; Clear one row of characters |
4060 | hidnplayr | 218 | pusha |
219 | mov cx, bx |
||
220 | shl ecx, 16 |
||
4143 | hidnplayr | 221 | mov cx, FONT_HEIGHT |
4060 | hidnplayr | 222 | mov ebx, TEXT_X shl 16 |
223 | mov bx, word[textbox_width] |
||
4143 | hidnplayr | 224 | imul bx, FONT_WIDTH |
4060 | hidnplayr | 225 | mov edx, [colors.work] |
226 | mcall 13 ; draw rectangle |
||
227 | popa |
||
228 | |||
4143 | hidnplayr | 229 | mov esi, edx |
230 | add esi, [textbox_width] |
||
231 | .line: |
||
232 | cmp byte[edx], 0 |
||
233 | je .end |
||
4060 | hidnplayr | 234 | |
4143 | hidnplayr | 235 | cmp byte[edx], 13 |
236 | je .newline_soft |
||
237 | |||
238 | cmp byte[edx], 10 |
||
239 | je .newline_hard |
||
240 | |||
241 | push esi eax |
||
242 | cmp byte[edx], 3 ; escape code for mIRC colors |
||
243 | jne .no_colors |
||
244 | inc edx |
||
245 | call dec_to_esi |
||
246 | jz .no_colors |
||
247 | mov ecx, [irc_colors + 4*esi] |
||
248 | |||
249 | cmp byte[edx], ',' ; background color? |
||
250 | jne .no_colors |
||
251 | inc edx |
||
252 | call dec_to_esi |
||
253 | jz .no_colors |
||
254 | mov edi, [irc_colors + 4*esi] |
||
255 | or ecx, 0x40000000 |
||
256 | .no_colors: |
||
257 | |||
4060 | hidnplayr | 258 | .draw: |
4143 | hidnplayr | 259 | mov esi, 1 |
4060 | hidnplayr | 260 | mcall 4 ; draw text |
4143 | hidnplayr | 261 | add ebx, FONT_WIDTH shl 16 |
262 | inc edx |
||
263 | pop eax esi |
||
264 | cmp edx, esi |
||
265 | jb .line |
||
266 | jmp .line_full |
||
4060 | hidnplayr | 267 | |
4143 | hidnplayr | 268 | .newline_hard: |
269 | mov ecx, [colors.work_text] |
||
270 | .newline_soft: |
||
271 | inc edx |
||
272 | .line_full: |
||
273 | and ebx, 0x0000ffff |
||
274 | add ebx, TEXT_X shl 16 + FONT_HEIGHT |
||
275 | dec eax |
||
276 | jnz .drawloop |
||
4060 | hidnplayr | 277 | |
4143 | hidnplayr | 278 | ; take care of the scrollbar |
279 | .scrollbar: |
||
280 | mov edi, [window_active] |
||
281 | mov edx, [edi + window.text_lines] |
||
282 | cmp edx, [textbox_height] |
||
283 | ja .draw_scroll |
||
284 | mov [scroll2.position], 0 ; disable scrollbar |
||
285 | jmp .scroll_done |
||
4060 | hidnplayr | 286 | |
4143 | hidnplayr | 287 | .draw_scroll: |
288 | mov [scroll2.max_area], edx |
||
289 | mov eax, [edi + window.text_line_print] |
||
290 | mov [scroll2.position], eax |
||
291 | |||
292 | push dword scroll2 ; redraw scrollbar |
||
293 | call [scrollbar_draw] |
||
294 | |||
295 | mov [scroll2.all_redraw], 0 ; next time, dont redraw it completely |
||
296 | .scroll_done: |
||
297 | .end: |
||
298 | ret |
||
299 | |||
300 | |||
301 | |||
302 | |||
303 | dec_to_esi: |
||
304 | |||
305 | xor esi, esi |
||
306 | .loop: |
||
307 | movzx eax, byte[edx] |
||
308 | sub al, '0' |
||
309 | jb .done |
||
310 | cmp al, 9 |
||
311 | ja .done |
||
312 | inc edx |
||
313 | shl esi, 1 ; esi * 2 |
||
314 | lea esi, [esi + 4*esi] ; esi * 5 |
||
315 | add esi, eax |
||
316 | jmp .loop |
||
317 | .done: |
||
318 | cmp esi, 16 |
||
319 | jae .fail |
||
320 | ret |
||
321 | |||
322 | .fail: |
||
323 | xor esi, esi |
||
324 | ret |
||
325 | |||
326 | |||
327 | |||
328 | if TIMESTAMP |
||
329 | print_timestamp: |
||
330 | |||
331 | pusha |
||
332 | mcall 3 ; get system time |
||
333 | |||
334 | mov bl, '[' |
||
335 | call print_character |
||
336 | mov ecx, TIMESTAMP |
||
337 | .loop: |
||
338 | mov bl, al |
||
339 | shr bl, 4 |
||
340 | add bl, '0' |
||
341 | call print_character |
||
342 | |||
343 | mov bl, al |
||
344 | and bl, 0x0f |
||
345 | add bl, '0' |
||
346 | call print_character |
||
347 | |||
348 | dec ecx |
||
349 | jz .done |
||
350 | |||
351 | mov bl, ':' |
||
352 | call print_character |
||
353 | shr eax, 8 |
||
354 | jmp .loop |
||
355 | .done: |
||
356 | mov bl, ']' |
||
357 | call print_character |
||
358 | mov bl, ' ' |
||
359 | call print_character |
||
360 | |||
4060 | hidnplayr | 361 | popa |
362 | ret |
||
4143 | hidnplayr | 363 | end if |