Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2022. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 9850 $
  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.         ret
  58.  
  59.   @@:
  60.         pushad
  61.         xor     ecx, ecx
  62.         xor     edx, edx
  63.  
  64.   mres:
  65.         movzx   eax, word [X_UNDER]
  66.         movzx   ebx, word [Y_UNDER]
  67.         add     eax, ecx
  68.         add     ebx, edx
  69.         push    ecx
  70.         push    edx
  71.         push    eax
  72.         push    ebx
  73.         mov     eax, edx
  74.         shl     eax, 6
  75.         shl     ecx, 2
  76.         add     eax, ecx
  77.         add     eax, mouseunder
  78.         mov     ecx, [eax]
  79.         pop     ebx
  80.         pop     eax
  81.         mov     edi, 1 ; force
  82.         or      ecx, 0x04000000  ; don't save to mouseunder area
  83. ;        call    [putpixel]
  84.         call    __sys_putpixel
  85.         pop     edx
  86.         pop     ecx
  87.         inc     ecx
  88.         cmp     ecx, 16
  89.         jnz     mres
  90.         xor     ecx, ecx
  91.         inc     edx
  92.         cmp     edx, 24
  93.         jnz     mres
  94.         popad
  95.         ret
  96.  
  97. ;-----------------------------------------------------------------------------
  98.  
  99. align 4
  100. save_draw_mouse:
  101.         cmp     [_display.move_cursor], 0
  102.         je      .no_hw_cursor
  103.         pushad
  104.  
  105.         mov     [X_UNDER], ax
  106.         mov     [Y_UNDER], bx
  107.         movzx   eax, word [MOUSE_Y]
  108.         movzx   ebx, word [MOUSE_X]
  109.         push    eax
  110.         push    ebx
  111.  
  112.         mov     eax, [d_width_calc_area + eax*4]
  113.  
  114.         add     eax, [_display.win_map]
  115.         movzx   edx, byte [ebx + eax]
  116.         shl     edx, BSF sizeof.APPDATA
  117.         ; edx - thread slot of window under cursor
  118.         mov     esi, [SLOT_BASE + edx + APPDATA.cursor] ; cursor of window under cursor
  119.  
  120.         ; if cursor of window under cursor already equal to the
  121.         ; current_cursor then just draw it
  122.         cmp     esi, [current_cursor]
  123.         je      .draw
  124.  
  125.         ; eax = thread slot of current active window
  126.         mov     eax, [thread_count]
  127.         movzx   eax, word [WIN_POS + eax*2]
  128.         shl     eax, BSF sizeof.APPDATA
  129.  
  130.         ; window under cursor == active window ?
  131.         cmp     eax, edx
  132.         je      @f
  133.  
  134.         ; check whether active window is being resized now:
  135.         mov     bl, [mouse.active_sys_window.action]
  136.         and     bl, mouse.WINDOW_RESIZE_S_FLAG or mouse.WINDOW_RESIZE_W_FLAG or mouse.WINDOW_RESIZE_E_FLAG
  137.         test    bl, bl
  138.         jz      .active_isnt_resizing
  139.         mov     esi, [SLOT_BASE + eax + APPDATA.cursor] ; esi = cursor of active window, it is resizing cursor
  140.         jmp     @f
  141.         .active_isnt_resizing:
  142.  
  143.         ; if cursor of window under the cursor is resizing cursor then draw it.
  144.         cmp     esi, [def_cursor_hresize]
  145.         je      @f
  146.         cmp     esi, [def_cursor_vresize]
  147.         je      @f
  148.         cmp     esi, [def_cursor_dresize1]
  149.         je      @f
  150.         cmp     esi, [def_cursor_dresize2]
  151.         je      @f
  152.  
  153.         ; set cursor of window under cursor
  154.         mov     esi, [SLOT_BASE + edx + APPDATA.cursor]
  155.         cmp     esi, [current_cursor]
  156.         je      .draw
  157.  
  158. @@:
  159.         push    esi
  160.         call    [_display.select_cursor]
  161.         mov     [current_cursor], esi
  162. ;--------------------------------------
  163. align 4
  164. .draw:
  165.         stdcall [_display.move_cursor], esi
  166.         popad
  167.         ret
  168. ;--------------------------------------
  169. ;align 4
  170. ;.fail:
  171. ;        mov     ecx, [def_cursor]
  172. ;        mov     [edx+SLOT_BASE+APPDATA.cursor], ecx
  173. ;        stdcall [_display.move_cursor], ecx        ; stdcall: [esp]=ebx,eax
  174. ;        popad
  175. ;        ret
  176. ;--------------------------------------
  177. align 4
  178. .no_hw_cursor:
  179.         pushad
  180.         ; save & draw
  181.         mov     [X_UNDER], ax
  182.         mov     [Y_UNDER], bx
  183.         push    eax
  184.         push    ebx
  185.         mov     ecx, 0
  186.         mov     edx, 0
  187. ;--------------------------------------
  188. align 4
  189. drm:
  190.         push    eax
  191.         push    ebx
  192.         push    ecx
  193.         push    edx
  194.         ; helloworld
  195.         push    ecx
  196.         add     eax, ecx        ; save picture under mouse
  197.         add     ebx, edx
  198.         push    ecx
  199.         or      ecx, 0x04000000 ; don't load to mouseunder area
  200.         push    eax ebx edx edi
  201.         call    [GETPIXEL]
  202.         pop     edi edx ebx eax
  203.         mov     [COLOR_TEMP], ecx
  204.         pop     ecx
  205.         mov     eax, edx
  206.         shl     eax, 6
  207.         shl     ecx, 2
  208.         add     eax, ecx
  209.         add     eax, mouseunder
  210.         mov     ebx, [COLOR_TEMP]
  211.         and     ebx, 0xffffff
  212.         mov     [eax], ebx
  213.         pop     ecx
  214.         mov     edi, edx        ; y cycle
  215.         shl     edi, 4          ; *16 bytes per row
  216.         add     edi, ecx        ; x cycle
  217.         mov     esi, edi
  218.         add     edi, esi
  219.         add     edi, esi        ; *3
  220.         add     edi, [MOUSE_PICTURE]    ; we have our str address
  221.         mov     esi, edi
  222.         add     esi, 16*24*3
  223.         push    ecx
  224.         mov     ecx, [COLOR_TEMP]
  225.         call    combine_colors
  226.         and     ecx, 0xffffff
  227.         mov     [MOUSE_COLOR_MEM], ecx
  228.         pop     ecx
  229.         pop     edx
  230.         pop     ecx
  231.         pop     ebx
  232.         pop     eax
  233.         add     eax, ecx        ; we have x coord+cycle
  234.         add     ebx, edx        ; and y coord+cycle
  235.         push    ecx
  236.         mov     ecx, [MOUSE_COLOR_MEM]
  237.         mov     edi, 1 ; force
  238.         or      ecx, 0x04000000 ; don't save to mouseunder area
  239. ;        call    [putpixel]
  240.         call    __sys_putpixel
  241.         pop     ecx
  242.         mov     ebx, [esp+0]    ; pure y coord again
  243.         mov     eax, [esp+4]    ; and x
  244.         inc     ecx             ; +1 cycle
  245.         cmp     ecx, 16         ; if more than 16
  246.         jnz     drm
  247.         xor     ecx, ecx
  248.         inc     edx
  249.         cmp     edx, 24
  250.         jnz     drm
  251.         add     esp, 8
  252.         popad
  253.         ret
  254.  
  255. ;-----------------------------------------------------------------------------
  256.  
  257. align 4
  258. combine_colors:
  259.       ; in
  260.       ; ecx - color ( 00 RR GG BB )
  261.       ; edi - ref to new color byte
  262.       ; esi - ref to alpha byte
  263.       ;
  264.       ; out
  265.       ; ecx - new color ( roughly (ecx*[esi]>>8)+([edi]*[esi]>>8) )
  266.         push    eax
  267.         push    ebx
  268.         push    edx
  269.         push    ecx
  270.         xor     ecx, ecx
  271.          ; byte 0
  272.         mov     eax, 0xff
  273.         sub     al, [esi+0]
  274.         mov     ebx, [esp]
  275.         shr     ebx, 16
  276.         and     ebx, 0xff
  277.         mul     ebx
  278.         shr     eax, 8
  279.         add     ecx, eax
  280.         xor     eax, eax
  281.         xor     ebx, ebx
  282.         mov     al, [edi+0]
  283.         mov     bl, [esi+0]
  284.         mul     ebx
  285.         shr     eax, 8
  286.         add     ecx, eax
  287.         shl     ecx, 8
  288.          ; byte 1
  289.         mov     eax, 0xff
  290.         sub     al, [esi+1]
  291.         mov     ebx, [esp]
  292.         shr     ebx, 8
  293.         and     ebx, 0xff
  294.         mul     ebx
  295.         shr     eax, 8
  296.         add     ecx, eax
  297.         xor     eax, eax
  298.         xor     ebx, ebx
  299.         mov     al, [edi+1]
  300.         mov     bl, [esi+1]
  301.         mul     ebx
  302.         shr     eax, 8
  303.         add     ecx, eax
  304.         shl     ecx, 8
  305.          ; byte 2
  306.         mov     eax, 0xff
  307.         sub     al, [esi+2]
  308.         mov     ebx, [esp]
  309.         and     ebx, 0xff
  310.         mul     ebx
  311.         shr     eax, 8
  312.         add     ecx, eax
  313.         xor     eax, eax
  314.         xor     ebx, ebx
  315.         mov     al, [edi+2]
  316.         mov     bl, [esi+2]
  317.         mul     ebx
  318.         shr     eax, 8
  319.         add     ecx, eax
  320.         pop     eax
  321.         pop     edx
  322.         pop     ebx
  323.         pop     eax
  324.         ret
  325.  
  326. ;-----------------------------------------------------------------------------
  327.  
  328. align 4
  329. check_mouse_area_for_getpixel:
  330. ; in:
  331. ; eax = x
  332. ; ebx = y
  333. ; out:
  334. ; ecx = new color
  335.         push    eax ebx
  336. ; check for Y
  337.         xor     ecx, ecx
  338.         mov     cx, [Y_UNDER]   ; [MOUSE_Y]
  339.  
  340.         cmp     ebx, ecx
  341.         jb      .no_mouse_area
  342.         add     ecx, 23         ; mouse cursor Y size
  343.         cmp     ebx, ecx
  344.         ja      .no_mouse_area
  345. ; offset Y
  346.         sub     bx, [Y_UNDER]   ; [MOUSE_Y]
  347. ;--------------------------------------
  348. ; check for X
  349.         xor     ecx, ecx
  350.         mov     cx, [X_UNDER]   ; [MOUSE_X]
  351.         cmp     eax, ecx
  352.         jb      .no_mouse_area
  353.         add     ecx, 15         ; mouse cursor X size
  354.         cmp     eax, ecx
  355.         ja      .no_mouse_area
  356. ; offset X
  357.         sub     ax, [X_UNDER]   ; [MOUSE_X]
  358. ;--------------------------------------
  359. ; eax = offset x
  360. ; ebx = offset y
  361.         shl     ebx, 6  ;y
  362.         shl     eax, 2  ;x
  363.         add     eax, ebx
  364.         add     eax, mouseunder
  365.         mov     ecx, [eax]
  366.         and     ecx, 0xffffff
  367.         or      ecx, 0xff000000
  368.         pop     ebx eax
  369.         ret
  370.  
  371.   .no_mouse_area:
  372.         xor     ecx, ecx
  373.         pop     ebx eax
  374.         ret
  375.  
  376. ;-----------------------------------------------------------------------------
  377.  
  378. align 4
  379. check_mouse_area_for_putpixel:
  380. ; in:
  381. ; ecx = x shl 16 + y
  382. ; eax = color
  383. ; out:
  384. ; eax = new color
  385.         push    eax
  386. ; check for Y
  387.         mov     ax, [Y_UNDER]   ; [MOUSE_Y]
  388.         cmp     cx, ax
  389.         jb      .no_mouse_area
  390.         add     ax, 23          ; mouse cursor Y size
  391.         cmp     cx, ax
  392.         ja      .no_mouse_area
  393. ; offset Y
  394.         sub     cx, [Y_UNDER]   ; [MOUSE_Y]
  395.         mov     ax, cx
  396.         shl     eax, 16
  397.  
  398. ; check for X
  399.         mov     ax, [X_UNDER]   ; [MOUSE_X]
  400.         shr     ecx, 16
  401.         cmp     cx, ax
  402.         jb      .no_mouse_area
  403.         add     ax, 15          ; mouse cursor X size
  404.         cmp     cx, ax
  405.         ja      .no_mouse_area
  406. ; offset X
  407.         sub     cx, [X_UNDER]   ; [MOUSE_X]
  408.         mov     ax, cx
  409.  
  410. ; eax = (offset y) shl 16 + (offset x)
  411.  
  412.         pop     ecx
  413.  
  414.         push    eax ebx
  415.  
  416.         mov     ebx, eax
  417.         shr     ebx, 16         ; y
  418.         and     eax, 0xffff     ; x
  419.  
  420.         shl     ebx, 6
  421.         shl     eax, 2
  422.         add     eax, ebx
  423.         add     eax, mouseunder
  424.         and     ecx, 0xFFFFFF
  425.         mov     [eax], ecx
  426.  
  427.         pop     ebx eax
  428.  
  429.         push    esi edi
  430.         rol     eax, 16
  431.         movzx   edi, ax         ; y cycle
  432.         shl     edi, 4          ; *16 bytes per row
  433.         shr     eax, 16
  434.         add     edi, eax        ; x cycle
  435.         lea     edi, [edi*3]
  436.         add     edi, [MOUSE_PICTURE]    ; we have our str address
  437.         mov     esi, edi
  438.         add     esi, 16*24*3
  439.         call    combine_colors
  440.         pop     edi esi
  441.         mov     eax, ecx
  442.         ret
  443.  
  444.   .no_mouse_area:
  445.         pop     eax
  446.         ret
  447.  
  448. ;-----------------------------------------------------------------------------
  449.  
  450. align 4
  451. __sys_draw_pointer:
  452.         pushad
  453.         movzx   ecx, word [X_UNDER]
  454.         movzx   edx, word [Y_UNDER]
  455.         movzx   ebx, word [MOUSE_Y]
  456.         movzx   eax, word [MOUSE_X]
  457.         cmp     [redrawmouse_unconditional], 0
  458.         je      @f
  459.         mov     [redrawmouse_unconditional], 0
  460.         jmp     redrawmouse
  461.   @@:
  462.         cmp     eax, ecx
  463.         jne     redrawmouse
  464.         cmp     ebx, edx
  465.         je      nodmp
  466.  
  467. ;--------------------------------------
  468.  
  469. align 4
  470. redrawmouse:
  471.         pushfd
  472.         cli
  473.         call    draw_mouse_under
  474.         call    save_draw_mouse
  475.  
  476. ;        mov     eax, [_display.select_cursor]
  477. ;        test    eax, eax
  478. ;        jz      @f
  479.         cmp     [_display.select_cursor], select_cursor
  480.         jne     @f
  481.  
  482.         xor     eax, eax
  483.         mov     esi, [current_cursor]
  484.  
  485.         mov     ax, [Y_UNDER]
  486.         sub     eax, [esi + CURSOR.hot_y]
  487.         mov     [Y_UNDER_subtraction_CUR_hot_y], ax
  488.         add     eax, [cur.h]
  489.         mov     [Y_UNDER_sub_CUR_hot_y_add_curh], ax
  490.  
  491.         mov     ax, [X_UNDER]
  492.         sub     eax, [esi + CURSOR.hot_x]
  493.         mov     [X_UNDER_subtraction_CUR_hot_x], ax
  494.         add     eax, [cur.w]
  495.         mov     [X_UNDER_sub_CUR_hot_x_add_curh], ax
  496.   @@:
  497.         popfd
  498.   nodmp:
  499.         popad
  500.         ret
  501.  
  502. ;-----------------------------------------------------------------------------
  503.  
  504. align 4
  505. proc set_mouse_data stdcall uses ecx edx, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword
  506.  
  507.         mov     eax, [BtnState]
  508.         and     eax, 0x3FFFFFFF         ; Top 2 bits are used to flag absolute movements
  509.         mov     [BTN_DOWN], eax
  510. ;--------------------------------------
  511.         mov     eax, [XMoving]
  512.         test    [BtnState], 0x80000000
  513.         jnz     .absolute_x
  514.         test    eax, eax
  515.         jz      @f
  516.         call    mouse_acceleration
  517.         add     ax, [MOUSE_X]
  518.         jns     .check_x
  519.         xor     eax, eax
  520.         jmp     .set_x
  521.  .absolute_x:
  522.         mov     edx, [_display.width]
  523.         mul     edx
  524.         shr     eax, 15
  525.  .check_x:
  526.         cmp     ax, word[_display.width]
  527.         jl      .set_x
  528.         mov     ax, word[_display.width]
  529.         dec     ax
  530.  .set_x:
  531.         mov     [MOUSE_X], ax
  532. ;--------------------------------------
  533. @@:
  534.         mov     eax, [YMoving]
  535.         test    [BtnState], 0x40000000
  536.         jnz     .absolute_y
  537.         test    eax, eax
  538.         jz      @f
  539.         neg     eax
  540.         call    mouse_acceleration
  541.         add     ax, [MOUSE_Y]
  542.         jns     .check_y
  543.         xor     eax, eax
  544.         jmp     .set_y
  545.  .absolute_y:
  546.         mov     edx, [_display.height]
  547.         mul     edx
  548.         shr     eax, 15
  549.  .check_y:
  550.         cmp     ax, word[_display.height]
  551.         jl      .set_y
  552.         mov     ax, word[_display.height]
  553.         dec     ax
  554.  .set_y:
  555.         mov     [MOUSE_Y], ax
  556. ;--------------------------------------
  557. @@:
  558.         mov     eax, [VScroll]
  559.         test    eax, eax
  560.         jz      @f
  561.         add     [MOUSE_SCROLL_V], ax
  562.         bts     word [BTN_DOWN], 15
  563. @@:
  564.         mov     eax, [HScroll]
  565.         test    eax, eax
  566.         jz      @f
  567.         add     [MOUSE_SCROLL_H], ax
  568.         bts     dword [BTN_DOWN], 23
  569. @@:
  570.         mov     [mouse_active], 1
  571.         call    wakeup_osloop
  572.         ret
  573. endp
  574.  
  575. ;-----------------------------------------------------------------------------
  576. mouse_acceleration:
  577.         neg     ax
  578.         jl      mouse_acceleration
  579.         add     al, [mouse_delay]
  580.         mul     al
  581.         mov     cx, [mouse_speed_factor]
  582.         dec     ax
  583.         shr     ax, cl
  584.         inc     ax
  585.         test    eax, eax
  586.         jns     @f
  587.         neg     ax
  588. @@:
  589.         ret
  590.