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