Subversion Repositories Kolibri OS

Rev

Rev 4623 | Rev 4827 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;   Written by hidnplayr@kolibrios.org                            ;;
  7. ;;                                                                 ;;
  8. ;;         GNU GENERAL PUBLIC LICENSE                              ;;
  9. ;;          Version 2, June 1991                                   ;;
  10. ;;                                                                 ;;
  11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  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.         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. ;----------------------------------
  56. ; scan untill next line is reached
  57. ;
  58. ; When you set the direction flag before calling, you can also scan for previous line!
  59. ; IN:   esi
  60. ; OUT:  esi
  61. ;----------------------------------
  62. text_nextline:
  63.  
  64.         mov     ecx, [textbox_width]
  65.   .loop:
  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
  75.   .done:
  76.  
  77.         ret
  78.  
  79.  
  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:
  88.  
  89.         push    eax
  90.   .loop:
  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
  100.   .done:
  101.         pop     eax
  102.  
  103.         ret
  104.  
  105.  
  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:
  113.  
  114.         push    eax
  115.   .loop:
  116.         lodsb
  117.         test    al, al
  118.         jz      .done
  119.         call    print_char
  120.         jmp     .loop
  121.   .done:
  122.         pop     eax
  123.  
  124.         ret
  125.  
  126.  
  127. ;----------------------------------
  128. ; print character
  129. ;
  130. ; IN:   al = char to print
  131. ; OUT:  /
  132. ;----------------------------------
  133. print_char:
  134.  
  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
  142.   .continue:
  143.         or      [esi + window.flags], FLAG_UPDATED
  144.         pop     edi esi
  145.  
  146.         ret
  147.  
  148.   .uh_ow:
  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
  158.  
  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
  165.  
  166.         jmp     .continue
  167.  
  168.  
  169.  
  170. draw_channel_text:
  171.  
  172.         mov     edi, [window_active]
  173.         and     [edi + window.flags], not FLAG_UPDATED  ; clear the 'window is updated' flag
  174.  
  175. ; Scan new text for newlines
  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
  180.  
  181. ; Is scrollbar at lowest position?
  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.         sub     edx, [edi + window.text_line_print]
  188.         jg      .noscroll
  189.   .yesscroll:
  190. ; Scrollbar was at lowest position, scroll down automatically when new text arrived.
  191.         mov     edx, [edi + window.text_lines]
  192.         sub     edx, [textbox_height]
  193.         jle     .noscroll                               ; There are less lines of text than fit into the window, dont scroll..
  194.         sub     edx, [edi + window.text_line_print]
  195.         je      .noscroll                               ; We are already at the bottom pos, dont scroll..
  196.   .scroll_to_pos:               ; edx = number of lines to go up/down (flags must indicate direction)
  197.         pushf
  198.         add     [edi + window.text_line_print], edx
  199.         mov     esi, [edi + window.text_print]
  200.         popf
  201.         ja      .loop_forward
  202.         std                     ; set direction flag so we can scan backwards
  203.         dec     esi
  204.         dec     esi             ; move our cursor just in front of newline, for scanning backwards
  205.   .loop_backward:
  206.         call    text_nextline
  207.         inc     edx
  208.         jnz     .loop_backward
  209.         inc     esi
  210.         inc     esi             ; move the cursor just after last newline
  211.         cld
  212.         jmp     .ok
  213.  
  214.   .loop_forward:
  215.         call    text_nextline
  216.         dec     edx
  217.         jnz     .loop_forward
  218.   .ok:
  219.         mov     [edi + window.text_print], esi
  220.   .noscroll:
  221.  
  222. ; Update and draw scrollbar when nescessary
  223.         mov     edx, [edi + window.text_lines]
  224.         cmp     edx, [textbox_height]
  225.         jbe     .scroll_done
  226.  
  227.         mov     [scroll2.max_area], edx
  228.         mov     eax, [edi + window.text_line_print]
  229.         mov     [scroll2.position], eax
  230.  
  231.         push    dword scroll2                   ; redraw scrollbar
  232.         call    [scrollbar_draw]
  233.         mov     [scroll2.all_redraw], 0         ; next time, dont redraw it completely
  234.   .scroll_done:
  235.  
  236. ; Calculate start offset coordinates (align text to bottom)
  237.         mov     ebx, [textbox_height]
  238.         sub     ebx, [edi + window.text_lines]
  239.         jb      .no_offset
  240.         imul    ebx, FONT_HEIGHT
  241.         push    [edi + window.text_start]
  242.         pop     [edi + window.text_print]
  243.         jmp     .draw_text
  244.   .no_offset:
  245.         xor     ebx, ebx
  246.   .draw_text:
  247. ; Prepare to actually draw some text
  248.         mov     eax, [textbox_height]   ; max number of lines to draw
  249.         add     ebx, TEXT_X shl 16 + TEXT_Y
  250.         mov     ecx, [colors.work_text] ; default text color
  251.         mov     edx, [edi + window.text_print]
  252.   .drawloop:
  253.         cmp     byte[edx], 0
  254.         je      .end_of_text
  255.  
  256. ; Clear one row of characters
  257.         pusha
  258.         mov     cx, bx
  259.         shl     ecx, 16
  260.         mov     cx, FONT_HEIGHT
  261.         mov     ebx, TEXT_X shl 16
  262.         mov     bx, word[textbox_width]
  263.         imul    bx, FONT_WIDTH
  264.         mov     edx, [colors.work]
  265.         mcall   13                      ; draw rectangle
  266.         popa
  267.  
  268.         mov     esi, edx
  269.         add     esi, [textbox_width]
  270.   .line:
  271.         cmp     byte[edx], 0
  272.         je      .end_of_text
  273.  
  274.         cmp     byte[edx], 13
  275.         je      .newline_soft
  276.  
  277.         cmp     byte[edx], 10
  278.         je      .newline_hard
  279.  
  280.         push    esi eax
  281.         cmp     byte[edx], 3            ; escape code for mIRC colors
  282.         jne     .no_colors
  283.         inc     edx
  284.         call    dec_to_esi
  285.         jz      .no_colors
  286.         mov     ecx, [irc_colors + 4*esi]
  287.  
  288.         cmp     byte[edx], ','          ; background color?
  289.         jne     .no_colors
  290.         inc     edx
  291.         call    dec_to_esi
  292.         jz      .no_colors
  293.         mov     edi, [irc_colors + 4*esi]
  294.         or      ecx, 0x40000000
  295.   .no_colors:
  296.  
  297.         mov     esi, 1
  298.         mcall   4                       ; draw text
  299.         add     ebx, FONT_WIDTH shl 16
  300.         inc     edx
  301.         pop     eax esi
  302.         cmp     edx, esi
  303.         jb      .line
  304.         jmp     .line_full
  305.  
  306.   .newline_hard:
  307.         mov     ecx, [colors.work_text]
  308.   .newline_soft:
  309.         inc     edx
  310.   .line_full:
  311.         and     ebx, 0x0000ffff
  312.         add     ebx, TEXT_X shl 16 + FONT_HEIGHT
  313.         dec     eax
  314.         jnz     .drawloop
  315.   .end_of_text:
  316.  
  317.         ret
  318.  
  319.  
  320.  
  321.  
  322. dec_to_esi:
  323.  
  324.         xor     esi, esi
  325.   .loop:
  326.         movzx   eax, byte[edx]
  327.         sub     al, '0'
  328.         jb      .done
  329.         cmp     al, 9
  330.         ja      .done
  331.         inc     edx
  332.         lea     esi, [esi*4 + esi]      ; esi * 5
  333.         lea     esi, [esi*2 + eax]      ; esi * 2 + eax
  334.         jmp     .loop
  335.   .done:
  336.         cmp     esi, 16
  337.         jae     .fail
  338.         ret
  339.  
  340.   .fail:
  341.         xor     esi, esi
  342.         ret
  343.  
  344.  
  345.  
  346. if TIMESTAMP
  347. print_timestamp:
  348.  
  349.         pusha
  350.         mcall   3                       ; get system time
  351.         mov     ebx, eax
  352.  
  353.         mov     al, '['
  354.         call    print_char
  355.         mov     ecx, TIMESTAMP
  356.   .loop:
  357.         mov     al, bl
  358.         shr     al, 4
  359.         add     al, '0'
  360.         call    print_char
  361.  
  362.         mov     al, bl
  363.         and     al, 0x0f
  364.         add     al, '0'
  365.         call    print_char
  366.  
  367.         dec     ecx
  368.         jz      .done
  369.  
  370.         mov     al, ':'
  371.         call    print_char
  372.         shr     ebx, 8
  373.         jmp     .loop
  374.   .done:
  375.         mov     al, ']'
  376.         call    print_char
  377.         mov     al, ' '
  378.         call    print_char
  379.  
  380.         popa
  381.         ret
  382. end if