Subversion Repositories Kolibri OS

Rev

Rev 4621 | Rev 4623 | 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
 
4622 hidnplayr 204
; Update and draw scrollbar when nescessary
205
        mov     edx, [edi + window.text_lines]
206
        cmp     edx, [textbox_height]
207
        jbe     .scroll_done
208
 
209
        mov     [scroll2.max_area], edx
210
        mov     eax, [edi + window.text_line_print]
211
        mov     [scroll2.position], eax
212
 
213
        push    dword scroll2                   ; redraw scrollbar
214
        call    [scrollbar_draw]
215
        mov     [scroll2.all_redraw], 0         ; next time, dont redraw it completely
216
  .scroll_done:
217
 
4621 hidnplayr 218
; Calculate start offset coordinates (align text to bottom)
4143 hidnplayr 219
        mov     ebx, [textbox_height]
220
        sub     ebx, [edi + window.text_lines]
4621 hidnplayr 221
        jb      .no_offset
222
        imul    ebx, FONT_HEIGHT
223
        push    [edi + window.text_start]
224
        pop     [edi + window.text_print]
225
        jmp     .draw_text
226
  .no_offset:
4143 hidnplayr 227
        xor     ebx, ebx
4621 hidnplayr 228
  .draw_text:
4143 hidnplayr 229
; Prepare to actually draw some text
230
        mov     eax, [textbox_height]   ; max number of lines to draw
4621 hidnplayr 231
        add     ebx, TEXT_X shl 16 + TEXT_Y
4143 hidnplayr 232
        mov     ecx, [colors.work_text] ; default text color
4621 hidnplayr 233
        mov     edx, [edi + window.text_print]
4143 hidnplayr 234
  .drawloop:
235
        cmp     byte[edx], 0
4621 hidnplayr 236
        je      .end_of_text
4060 hidnplayr 237
 
4143 hidnplayr 238
; Clear one row of characters
4060 hidnplayr 239
        pusha
240
        mov     cx, bx
241
        shl     ecx, 16
4143 hidnplayr 242
        mov     cx, FONT_HEIGHT
4060 hidnplayr 243
        mov     ebx, TEXT_X shl 16
244
        mov     bx, word[textbox_width]
4143 hidnplayr 245
        imul    bx, FONT_WIDTH
4060 hidnplayr 246
        mov     edx, [colors.work]
247
        mcall   13                      ; draw rectangle
248
        popa
249
 
4143 hidnplayr 250
        mov     esi, edx
251
        add     esi, [textbox_width]
252
  .line:
253
        cmp     byte[edx], 0
4621 hidnplayr 254
        je      .end_of_text
4060 hidnplayr 255
 
4143 hidnplayr 256
        cmp     byte[edx], 13
257
        je      .newline_soft
258
 
259
        cmp     byte[edx], 10
260
        je      .newline_hard
261
 
262
        push    esi eax
263
        cmp     byte[edx], 3            ; escape code for mIRC colors
264
        jne     .no_colors
265
        inc     edx
266
        call    dec_to_esi
267
        jz      .no_colors
268
        mov     ecx, [irc_colors + 4*esi]
269
 
270
        cmp     byte[edx], ','          ; background color?
271
        jne     .no_colors
272
        inc     edx
273
        call    dec_to_esi
274
        jz      .no_colors
275
        mov     edi, [irc_colors + 4*esi]
276
        or      ecx, 0x40000000
277
  .no_colors:
278
 
279
        mov     esi, 1
4060 hidnplayr 280
        mcall   4                       ; draw text
4143 hidnplayr 281
        add     ebx, FONT_WIDTH shl 16
282
        inc     edx
283
        pop     eax esi
284
        cmp     edx, esi
285
        jb      .line
286
        jmp     .line_full
4060 hidnplayr 287
 
4143 hidnplayr 288
  .newline_hard:
289
        mov     ecx, [colors.work_text]
290
  .newline_soft:
291
        inc     edx
292
  .line_full:
293
        and     ebx, 0x0000ffff
294
        add     ebx, TEXT_X shl 16 + FONT_HEIGHT
295
        dec     eax
296
        jnz     .drawloop
4621 hidnplayr 297
  .end_of_text:
4060 hidnplayr 298
 
4143 hidnplayr 299
        ret
300
 
301
 
302
 
303
 
304
dec_to_esi:
305
 
306
        xor     esi, esi
307
  .loop:
308
        movzx   eax, byte[edx]
309
        sub     al, '0'
310
        jb      .done
311
        cmp     al, 9
312
        ja      .done
313
        inc     edx
4621 hidnplayr 314
        lea     esi, [esi*4 + esi]      ; esi * 5
315
        lea     esi, [esi*2 + eax]      ; esi * 2 + eax
4143 hidnplayr 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