Subversion Repositories Kolibri OS

Rev

Rev 9930 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2023. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 9941 $
  9.  
  10.  
  11. ;   check mouse
  12. ;
  13. ;
  14. ;   FB00  ->   FB0F   mouse memory 00 chunk count - FB0A-B x - FB0C-D y
  15. ;   FB10  ->   FB17   mouse color mem
  16. ;   FB21              x move
  17. ;   FB22              y move
  18. ;   FB30              color temp
  19. ;   FB28              high bits temp
  20. ;   FB4A  ->   FB4D   FB4A-B x-under - FB4C-D y-under
  21. ;   FC00  ->   FCFE   com1/ps2 buffer
  22. ;   FCFF              com1/ps2 buffer count starting from FC00
  23.  
  24. uglobal
  25. ;--------------------------------------
  26. align 4
  27. mousecount                      dd ?
  28. mousedata                       dd ?
  29. Y_UNDER_sub_CUR_hot_y_add_curh  dw ?
  30. Y_UNDER_subtraction_CUR_hot_y   dw ?
  31. X_UNDER_sub_CUR_hot_x_add_curh  dw ?
  32. X_UNDER_subtraction_CUR_hot_x   dw ?
  33. endg
  34.  
  35. iglobal
  36. ;--------------------------------------
  37. align 4
  38. mouse_speed_factor      dw 4
  39. mouse_delay             db 3
  40. mouse_doubleclick_delay db 64
  41. endg
  42.  
  43. ;-----------------------------------------------------------------------------
  44.  
  45. align 4
  46. draw_mouse_under:
  47.  
  48.         ; return old picture
  49.         cmp     [_display.restore_cursor], 0
  50.         je      @F
  51.  
  52.         pushad
  53.         movzx   eax, word [X_UNDER]
  54.         movzx   ebx, word [Y_UNDER]
  55.         stdcall [_display.restore_cursor], eax, ebx
  56.         popad
  57. @@:
  58.         ret
  59.  
  60. ;-----------------------------------------------------------------------------
  61.  
  62. align 4
  63. save_draw_mouse:
  64.         cmp     [_display.move_cursor], 0
  65.         je      .exit
  66.         pushad
  67.  
  68.         mov     [X_UNDER], ax
  69.         mov     [Y_UNDER], bx
  70.         movzx   eax, word [MOUSE_Y]
  71.         movzx   ebx, word [MOUSE_X]
  72.         push    eax
  73.         push    ebx
  74.  
  75.         mov     eax, [d_width_calc_area + eax*4]
  76.  
  77.         add     eax, [_display.win_map]
  78.         movzx   edx, byte [ebx + eax]
  79.         shl     edx, BSF sizeof.WDATA
  80.         ; edx - thread slot of window under cursor
  81.         mov     esi, [window_data + edx + WDATA.cursor] ; cursor of window under cursor
  82.  
  83.         ; if cursor of window under cursor already equal to the
  84.         ; current_cursor then just draw it
  85.         cmp     esi, [current_cursor]
  86.         je      .draw
  87.  
  88.         ; eax = thread slot of current active window
  89.         mov     eax, [thread_count]
  90.         movzx   eax, word [WIN_POS + eax*2]
  91.         shl     eax, BSF sizeof.WDATA
  92.  
  93.         ; window under cursor == active window ?
  94.         cmp     eax, edx
  95.         je      @f
  96.  
  97.         ; check whether active window is being resized now:
  98.         mov     bl, [mouse.active_sys_window.action]
  99.         and     bl, mouse.WINDOW_RESIZE_S_FLAG or mouse.WINDOW_RESIZE_W_FLAG or mouse.WINDOW_RESIZE_E_FLAG
  100.         test    bl, bl
  101.         jz      .active_isnt_resizing
  102.         mov     esi, [window_data + eax + WDATA.cursor] ; esi = cursor of active window, it is resizing cursor
  103.         jmp     @f
  104.         .active_isnt_resizing:
  105.  
  106.         ; if cursor of window under the cursor is resizing cursor then draw it.
  107.         cmp     esi, [def_cursor_hresize]
  108.         je      @f
  109.         cmp     esi, [def_cursor_vresize]
  110.         je      @f
  111.         cmp     esi, [def_cursor_dresize1]
  112.         je      @f
  113.         cmp     esi, [def_cursor_dresize2]
  114.         je      @f
  115.  
  116.         ; set cursor of window under cursor
  117.         mov     esi, [window_data + edx + WDATA.cursor]
  118.         cmp     esi, [current_cursor]
  119.         je      .draw
  120.  
  121. @@:
  122.         cmp     [_display.select_cursor], 0
  123.         jz      .error
  124.  
  125.         stdcall [_display.select_cursor], esi
  126.         mov     [current_cursor], esi
  127. ;--------------------------------------
  128. align 4
  129. .draw:
  130.         stdcall [_display.move_cursor], esi
  131.         popad
  132.         ret
  133. ;--------------------------------------
  134. ;align 4
  135. ;.fail:
  136. ;        mov     ecx, [def_cursor]
  137. ;        mov     [window_data + edx + WDATA.cursor], ecx
  138. ;        stdcall [_display.move_cursor], ecx        ; stdcall: [esp]=ebx,eax
  139. ;        popad
  140. ;        ret
  141. ;--------------------------------------
  142. align 4
  143. .error:
  144.         popad
  145. .exit:
  146.         ret
  147.  
  148. ;-----------------------------------------------------------------------------
  149.  
  150. align 4
  151. __sys_draw_pointer:
  152.         pushad
  153.         movzx   ecx, word [X_UNDER]
  154.         movzx   edx, word [Y_UNDER]
  155.         movzx   ebx, word [MOUSE_Y]
  156.         movzx   eax, word [MOUSE_X]
  157.         cmp     [redrawmouse_unconditional], 0
  158.         je      @f
  159.         mov     [redrawmouse_unconditional], 0
  160.         jmp     .redrawmouse
  161.   @@:
  162.         cmp     eax, ecx
  163.         jne     .redrawmouse
  164.         cmp     ebx, edx
  165.         je      .nodmp
  166.  
  167. ;--------------------------------------
  168.  
  169. align 4
  170. .redrawmouse:
  171.         pushfd
  172.         cli
  173.         call    draw_mouse_under
  174.         call    save_draw_mouse
  175.  
  176.         cmp     [_display.select_cursor], select_cursor
  177.         jne     @f
  178.  
  179.         xor     eax, eax
  180.         mov     esi, [current_cursor]
  181.  
  182.         mov     ax, [Y_UNDER]
  183.         sub     eax, [esi + CURSOR.hot_y]
  184.         mov     [Y_UNDER_subtraction_CUR_hot_y], ax
  185.         add     eax, [cur.h]
  186.         mov     [Y_UNDER_sub_CUR_hot_y_add_curh], ax
  187.  
  188.         mov     ax, [X_UNDER]
  189.         sub     eax, [esi + CURSOR.hot_x]
  190.         mov     [X_UNDER_subtraction_CUR_hot_x], ax
  191.         add     eax, [cur.w]
  192.         mov     [X_UNDER_sub_CUR_hot_x_add_curh], ax
  193.   @@:
  194.         popfd
  195. .nodmp:
  196.         popad
  197.         ret
  198.  
  199. ;-----------------------------------------------------------------------------
  200.  
  201. align 4
  202. proc set_mouse_data stdcall uses ecx edx, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword
  203.  
  204.         mov     eax, [BtnState]
  205.         and     eax, 0x3FFFFFFF         ; Top 2 bits are used to flag absolute movements
  206.         mov     [BTN_DOWN], eax
  207. ;--------------------------------------
  208.         mov     eax, [XMoving]
  209.         test    [BtnState], 0x80000000
  210.         jnz     .absolute_x
  211.         test    eax, eax
  212.         jz      @f
  213.         call    mouse_acceleration
  214.         add     ax, [MOUSE_X]
  215.         jns     .check_x
  216.         xor     eax, eax
  217.         jmp     .set_x
  218.  .absolute_x:
  219.         mov     edx, [_display.width]
  220.         mul     edx
  221.         shr     eax, 15
  222.  .check_x:
  223.         cmp     ax, word[_display.width]
  224.         jl      .set_x
  225.         mov     ax, word[_display.width]
  226.         dec     ax
  227.  .set_x:
  228.         mov     [MOUSE_X], ax
  229. ;--------------------------------------
  230. @@:
  231.         mov     eax, [YMoving]
  232.         test    [BtnState], 0x40000000
  233.         jnz     .absolute_y
  234.         test    eax, eax
  235.         jz      @f
  236.         neg     eax
  237.         call    mouse_acceleration
  238.         add     ax, [MOUSE_Y]
  239.         jns     .check_y
  240.         xor     eax, eax
  241.         jmp     .set_y
  242.  .absolute_y:
  243.         mov     edx, [_display.height]
  244.         mul     edx
  245.         shr     eax, 15
  246.  .check_y:
  247.         cmp     ax, word[_display.height]
  248.         jl      .set_y
  249.         mov     ax, word[_display.height]
  250.         dec     ax
  251.  .set_y:
  252.         mov     [MOUSE_Y], ax
  253. ;--------------------------------------
  254. @@:
  255.         mov     eax, [VScroll]
  256.         test    eax, eax
  257.         jz      @f
  258.         add     [MOUSE_SCROLL_V], ax
  259.         bts     word [BTN_DOWN], 15
  260. @@:
  261.         mov     eax, [HScroll]
  262.         test    eax, eax
  263.         jz      @f
  264.         add     [MOUSE_SCROLL_H], ax
  265.         bts     dword [BTN_DOWN], 23
  266. @@:
  267.         mov     [mouse_active], 1
  268.         call    wakeup_osloop
  269.         ret
  270. endp
  271.  
  272. ;-----------------------------------------------------------------------------
  273. mouse_acceleration:
  274.         neg     ax
  275.         jl      mouse_acceleration
  276.         add     al, [mouse_delay]
  277.         mul     al
  278.         mov     cx, [mouse_speed_factor]
  279.         dec     ax
  280.         shr     ax, cl
  281.         inc     ax
  282.         test    eax, eax
  283.         jns     @f
  284.         neg     ax
  285. @@:
  286.         ret
  287.