Rev 4060 | Rev 4621 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4060 | Rev 4143 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
- | 6 | ;; Written by hidnplayr@kolibrios.org ;; |
|
6 | ;; ;; |
7 | ;; ;; |
7 | ;; GNU GENERAL PUBLIC LICENSE ;; |
8 | ;; GNU GENERAL PUBLIC LICENSE ;; |
8 | ;; Version 2, June 1991 ;; |
9 | ;; Version 2, June 1991 ;; |
9 | ;; ;; |
10 | ;; ;; |
10 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
11 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line -... | Line 12... | ||
- | 12 | ||
- | 13 | ||
- | 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 |
|
11 | 77 | ||
12 | 78 | ||
13 | print_text: ; eax = start ptr |
79 | print_text: ; eax = start ptr |
14 | ; dl = end char |
80 | ; dl = end char |
15 | pusha |
81 | pusha |
Line 25... | Line 91... | ||
25 | inc eax |
91 | inc eax |
26 | jmp ptr2 |
92 | jmp ptr2 |
Line 27... | Line 93... | ||
27 | 93 | ||
28 | .done: |
94 | .done: |
- | 95 | popa |
|
29 | popa |
96 | |
Line 30... | Line 97... | ||
30 | ret |
97 | ret |
Line 42... | Line 109... | ||
42 | call print_character |
109 | call print_character |
43 | jmp .loop |
110 | jmp .loop |
Line 44... | Line 111... | ||
44 | 111 | ||
45 | .done: |
112 | .done: |
46 | popa |
- | |
Line -... | Line 113... | ||
- | 113 | popa |
|
Line 47... | Line -... | ||
47 | ret |
- | |
48 | 114 | ||
Line 49... | Line 115... | ||
49 | 115 | ret |
|
50 | 116 | ||
51 | ; Character in bl |
117 | |
52 | print_character: |
118 | print_character: |
53 | - | ||
- | 119 | ||
54 | pusha |
120 | push esi edi |
55 | mov ecx, TEXTBOX_LINES |
121 | mov esi, [window_print] |
56 | imul ecx, [textbox_width] |
- | |
57 | mov esi, [text_start] |
122 | mov edi, [esi + window.text_write] |
- | 123 | mov byte[edi], bl |
|
58 | 124 | inc edi |
|
59 | cmp bl, 10 ; line down |
125 | cmp edi, [esi + window.text_end] |
Line 60... | Line -... | ||
60 | je .linefeed |
- | |
61 | - | ||
62 | mov eax, [text_pos] |
- | |
63 | mov byte[esi + eax], bl ; write the byte |
- | |
64 | inc [text_pos] |
- | |
65 | - | ||
66 | cmp [text_pos], ecx |
- | |
67 | jb .done |
126 | jae .uh_ow |
Line 68... | Line -... | ||
68 | - | ||
69 | .linefeed: |
- | |
70 | ; scroll all text one line to the top |
- | |
71 | mov edi, esi |
- | |
72 | add esi, [textbox_width] |
127 | mov [esi + window.text_write], edi |
73 | rep movsb |
- | |
Line -... | Line 128... | ||
- | 128 | .continue: |
|
- | 129 | or [esi + window.flags], FLAG_UPDATED |
|
- | 130 | pop edi esi |
|
- | 131 | ||
- | 132 | ret |
|
- | 133 | ||
- | 134 | .uh_ow: |
|
- | 135 | ||
- | 136 | pusha |
|
- | 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 |
|
74 | 143 | mov esi, edi |
|
75 | mov ecx, TEXTBOX_LINES - 1 |
- | |
Line -... | Line 144... | ||
- | 144 | call text_insert_newlines |
|
Line 76... | Line -... | ||
76 | imul ecx, [textbox_width] |
- | |
Line 77... | Line 145... | ||
77 | mov [text_pos], ecx |
145 | |
Line 78... | Line 146... | ||
78 | 146 | mov ebx, [window_print] |
|
79 | .done: |
147 | mov [ebx + window.text_lines], edx |
Line -... | Line 148... | ||
- | 148 | mov [ebx + window.text_scanned], esi |
|
- | 149 | mov [ebx + window.text_write], esi |
|
- | 150 | mov [ebx + window.text_line_print], 0 |
|
- | 151 | popa |
|
- | 152 | ||
- | 153 | jmp .continue |
|
- | 154 | ||
- | 155 | ||
- | 156 | ||
- | 157 | draw_channel_text: |
|
- | 158 | ||
- | 159 | mov edi, [window_active] |
|
- | 160 | and [edi + window.flags], not FLAG_UPDATED ; clear the 'window is updated' flag |
|
- | 161 | ||
- | 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 |
|
- | 167 | ||
- | 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.. |
|
- | 174 | ||
- | 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 |
|
- | 191 | ||
- | 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: |
|
80 | call window_is_updated |
199 | |
- | 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] |
|
81 | 204 | jae @f |
|
82 | popa |
205 | xor ebx, ebx |
83 | ret |
206 | @@: |
84 | 207 | imul ebx, FONT_HEIGHT |
|
85 | 208 | add ebx, TEXT_X shl 16 + TEXT_Y |
|
86 | 209 | ||
87 | draw_channel_text: ; edx = pointer to text |
210 | ; Prepare to actually draw some text |
88 | 211 | mov eax, [textbox_height] ; max number of lines to draw |
|
89 | pusha |
212 | mov ecx, [colors.work_text] ; default text color |
90 | 213 | .drawloop: |
|
Line -... | Line 214... | ||
- | 214 | cmp byte[edx], 0 |
|
- | 215 | je .end |
|
- | 216 | ||
- | 217 | ; Clear one row of characters |
|
- | 218 | pusha |
|
- | 219 | mov cx, bx |
|
- | 220 | shl ecx, 16 |
|
- | 221 | mov cx, FONT_HEIGHT |
|
- | 222 | mov ebx, TEXT_X shl 16 |
|
- | 223 | mov bx, word[textbox_width] |
|
- | 224 | imul bx, FONT_WIDTH |
|
- | 225 | mov edx, [colors.work] |
|
91 | mov ebx, TEXT_X shl 16 + TEXT_Y |
226 | mcall 13 ; draw rectangle |
- | 227 | popa |
|
- | 228 | ||
- | 229 | mov esi, edx |
|
- | 230 | add esi, [textbox_width] |
|
- | 231 | .line: |
|
92 | mov ecx, TEXTBOX_LINES |
232 | cmp byte[edx], 0 |
- | 233 | je .end |
|
- | 234 | ||
- | 235 | cmp byte[edx], 13 |
|
- | 236 | je .newline_soft |
|
- | 237 | ||
- | 238 | cmp byte[edx], 10 |
|
- | 239 | je .newline_hard |
|
- | 240 | ||
- | 241 | push esi eax |
|
Line 93... | Line 242... | ||
93 | 242 | cmp byte[edx], 3 ; escape code for mIRC colors |
|
94 | .drawloop: |
243 | jne .no_colors |
95 | pusha |
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 | ||
- | 258 | .draw: |
|
- | 259 | mov esi, 1 |
|
- | 260 | mcall 4 ; draw text |
|
- | 261 | add ebx, FONT_WIDTH shl 16 |
|
- | 262 | inc edx |
|
- | 263 | pop eax esi |
|
- | 264 | cmp edx, esi |
|
- | 265 | jb .line |
|
96 | mov cx, bx |
266 | jmp .line_full |
- | 267 | ||
- | 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 |
|
97 | shl ecx, 16 |
276 | jnz .drawloop |
- | 277 | ||
- | 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] |
|
Line 98... | Line -... | ||
98 | mov cx, 9 ; character height |
- | |
99 | mov ebx, TEXT_X shl 16 |
- | |
Line 100... | Line -... | ||
100 | mov bx, word[textbox_width] |
- | |
101 | imul bx, 6 ; character width |
- | |
Line -... | Line 283... | ||
- | 283 | ja .draw_scroll |
|
- | 284 | mov [scroll2.position], 0 ; disable scrollbar |
|
- | 285 | jmp .scroll_done |
|
- | 286 | ||
- | 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: |
|
102 | mov edx, [colors.work] |
297 | .end: |
- | 298 | ret |
|
- | 299 | ||
- | 300 | ||
103 | mcall 13 ; draw rectangle |
301 | |
Line -... | Line 302... | ||
- | 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 |
|
104 | popa |
344 | and bl, 0x0f |