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