Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
  4. ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
  5. ;; Distributed under terms of the GNU General Public License    ;;
  6. ;;                                                              ;;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8.  
  9. $Revision: 9941 $
  10.  
  11. button.MAX_BUTTONS = 4095
  12.  
  13. struct  SYS_BUTTON
  14.         pslot           dw ?
  15.         id_lo           dw ?
  16.         left            dw ?
  17.         width           dw ?
  18.         top             dw ?
  19.         height          dw ?
  20.         id_hi           dw ?
  21.                         dw ?
  22. ends
  23. ;---------------------------------------------------------------
  24. align 4
  25. ; @brief system function 17 - Get the identifier of the pressed button
  26. ; @param eax 17 - number function
  27. ; @return  eax = 1 - buffer empty,
  28. ;          eax = high 24 bits contain button identifier,
  29. ;          al = 0 - the button was pressed with left mouse button,
  30. ;          al = bit corresponding to used mouse button otherwise
  31. sys_getbutton:
  32.         mov     ebx, [current_slot_idx]    ; TOP OF WINDOW STACK
  33.         mov     [esp + SYSCALL_STACK.eax], dword 1
  34.         movzx   ecx, word [WIN_STACK + ebx * 2]
  35.         mov     edx, [thread_count] ; less than 256 processes
  36.         cmp     ecx, edx
  37.         jne     .exit
  38.         movzx   eax, byte [BTN_COUNT]
  39.         test    eax, eax
  40.         jz      .exit
  41.         mov     eax, [BTN_BUFF]
  42.         and     al, 0xFE                ; delete left button bit
  43.         mov     [BTN_COUNT], byte 0
  44.         mov     [esp + SYSCALL_STACK.eax], eax
  45. ;--------------------------------------
  46. align 4
  47. .exit:
  48.         ret
  49. ;---------------------------------------------------------------
  50. ; @brief system function 8 - define/delete the button
  51. ; @param eax = 8 - number function
  52. ; @param ebx = [offset_x]*65536 + [width]
  53. ; @param ecx = [offset_y]*65536 + [height]
  54. ; @param edx = 0xXYnnnnnn, where:
  55. ;        nnnnnn = identifier of the button
  56. ;        31 bit - delete button
  57. ;        30 bit - don't draw button
  58. ;        29 bit - don't draw button frame when pressed
  59. ; @param esi = 0x00RRGGBB - button color
  60. ; @return  function does not return value
  61. syscall_button:
  62. ;---------------------------------------------------------------
  63. ;? Define/undefine GUI button object
  64. ;---------------------------------------------------------------
  65. ;; Define button:
  66. ;> ebx = pack[16(x), 16(width)]
  67. ;> ecx = pack[16(y), 16(height)]
  68. ;> edx = pack[8(flags), 24(button identifier)]
  69. ;>       flags bits:
  70. ;>          7 (31) = 0
  71. ;>          6 (30) = don't draw button
  72. ;>          5 (29) = don't draw button frame when pressed
  73. ;> esi = button color
  74. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  75. ;; Undefine button:
  76. ;> edx = pack[8(flags), 24(button identifier)]
  77. ;>       flags bits:
  78. ;>          7 (31) = 1
  79. ;---------------------------------------------------------------
  80.         ; do we actually need to undefine the button?
  81.         test    edx, 0x80000000
  82.         jnz     .remove_button
  83.  
  84.         ; do we have free button slots available?
  85.         mov     edi, [BTN_ADDR]
  86.         mov     eax, [edi]
  87.         cmp     eax, button.MAX_BUTTONS
  88.         jge     .exit
  89.  
  90.         ; does it have positive size? (otherwise it doesn't have sense)
  91.         or      bx, bx
  92.         jle     .exit
  93.         or      cx, cx
  94.         jle     .exit
  95.  
  96.         ; make coordinates clientbox-relative
  97.         push    eax
  98.         mov     eax, [current_slot]
  99.         mov     eax, [eax + APPDATA.window]
  100.         rol     ebx, 16
  101.         add     bx, word[eax + WDATA.clientbox.left]
  102.         rol     ebx, 16
  103.         rol     ecx, 16
  104.         add     cx, word[eax + WDATA.clientbox.top]
  105.         rol     ecx, 16
  106.         pop     eax
  107.  
  108.         ; basic checks passed, define the button
  109.         inc     eax
  110.         mov     [edi], ax
  111.         shl     eax, 4
  112.         add     edi, eax
  113. ; NOTE: this code doesn't rely on SYS_BUTTON struct,
  114. ; please revise it, if you change something.
  115.         mov     ax, word [current_slot_idx]
  116.         stosw
  117.         mov     ax, dx
  118.         stosw               ; button id number: bits 0-15
  119.         mov     eax, ebx
  120.         rol     eax, 16
  121.         stosd               ; x start | x size
  122.         mov     eax, ecx
  123.         rol     eax, 16
  124.         stosd               ; y start | y size
  125.         mov     eax, edx
  126.         shr     eax, 16
  127.         stosw               ; button id number: bits 16-31
  128.  
  129.         ; do we also need to draw the button?
  130.         test    edx, 0x40000000
  131.         jnz     .exit
  132.  
  133.         and     esi, 0xFFFFFF
  134.         xor     edi, edi
  135.         push    ebx ecx esi
  136.         dec     cx
  137.         dec     cx
  138.         cmp     [buttontype], 1
  139.         jnz     .draw
  140.         cmp     cx, 65
  141.         jnc     .draw
  142.  
  143.         ; calculate gradient data
  144.         mov     eax, esi
  145.         shl     eax, 8
  146.         mov     edx, 3
  147. .calculate:
  148.         rol     eax, 8
  149.         shl     al, 1
  150.         jnc     @f
  151.         neg     al
  152.         jnz     @f
  153.         mov     al, 64
  154. @@:
  155.         cmp     al, 65
  156.         jc      @f
  157.         mov     al, 64
  158. @@:
  159.         div     cl
  160.         shl     ax, 8
  161.         dec     edx
  162.         jnz     .calculate
  163.         mov     dl, cl
  164.         dec     edx
  165.         shr     edx, 1
  166.         shr     eax, 8
  167.         mov     edi, eax
  168.         mul     edx
  169.         add     esi, eax
  170.  
  171. .draw:  ; calculate window-relative coordinates
  172.         movzx   ebp, cx
  173.         dec     ebp
  174.         shr     ebx, 16
  175.         shr     ecx, 16
  176.         mov     eax, [current_slot]
  177.         mov     eax, [eax + APPDATA.window]
  178.         add     ebx, [eax + WDATA.box.left]
  179.         add     ecx, [eax + WDATA.box.top]
  180.         mov     eax, ebx
  181.         inc     eax
  182.         mov     edx, ebx
  183.         add     dx, [esp+8]
  184.         dec     edx
  185.         mov     ebx, ecx
  186.         mov     ecx, esi
  187.         shr     ecx, 1
  188.         and     cx, 7F7Fh
  189.         push    esi
  190.         mov     esi, edi
  191.         xor     edi, edi
  192.         call    hline   ; top border
  193.         inc     ebx
  194.         or      ecx, 808080h
  195.         call    hline   ; top light line
  196.         pop     ecx
  197.         inc     ebx
  198. .next_line:
  199.         call    hline   ; button body
  200.         inc     ebx
  201.         sub     ecx, esi
  202.         dec     ebp
  203.         jnz     .next_line
  204.         shr     ecx, 2
  205.         and     cx, 3F3Fh
  206.         mov     ebp, ecx
  207.         shl     ecx, 1
  208.         add     ecx, ebp
  209.         call    hline   ; bottom dark line
  210.         inc     ebx
  211.         sub     ecx, ebp
  212.         call    hline   ; bottom border
  213.         pop     ecx
  214.         shr     ecx, 1
  215.         inc     edx
  216.         push    edx
  217.         mov     edx, ebx
  218.         sub     bx, [esp+4]
  219.         dec     edx
  220.         inc     ebx
  221.         cmp     [buttontype], 0
  222.         jnz     @f
  223.         dec     edx
  224.         or      ecx, 808080h
  225.         call    vline   ; left light line
  226.         inc     edx
  227. @@:
  228.         and     ecx, 7F7F7Fh
  229.         dec     eax
  230.         call    vline   ; left border
  231.         pop     eax
  232.         call    vline   ; right border
  233.         cmp     [buttontype], 0
  234.         jnz     @f
  235.         mov     ebp, ecx
  236.         shr     ecx, 1
  237.         and     cx, 7F7Fh
  238.         add     ecx, ebp
  239.         dec     eax
  240.         inc     ebx
  241.         dec     edx     ; avoid lines overflow
  242.         call    vline   ; right dark line
  243. @@:
  244.         pop     ecx ebx
  245. .exit:
  246.         ret
  247.  
  248. ; FIXME: mutex needed
  249. .remove_button:
  250.         and     edx, 0x00ffffff
  251.         mov     edi, [BTN_ADDR]
  252.         mov     ebx, [edi]
  253.         inc     ebx
  254.         imul    esi, ebx, sizeof.SYS_BUTTON
  255.         add     esi, edi
  256.         xor     ecx, ecx
  257.         add     ecx, -sizeof.SYS_BUTTON
  258.         add     esi, sizeof.SYS_BUTTON
  259.  
  260. .next_button:
  261.         dec     ebx
  262.         jz      .exit
  263.  
  264.         add     ecx, sizeof.SYS_BUTTON
  265.         add     esi, -sizeof.SYS_BUTTON
  266.  
  267.         ; does it belong to our process?
  268.         mov     ax, word [current_slot_idx]
  269.         cmp     ax, [esi + SYS_BUTTON.pslot]
  270.         jne     .next_button
  271.  
  272.         ; does the identifier match?
  273.         mov     eax, dword[esi + SYS_BUTTON.id_hi - 2]
  274.         mov     ax, [esi + SYS_BUTTON.id_lo]
  275.         and     eax, 0x00ffffff
  276.         cmp     edx, eax
  277.         jne     .next_button
  278.  
  279.         ; okay, undefine it
  280.         push    ebx
  281.         mov     ebx, esi
  282.         lea     eax, [esi + sizeof.SYS_BUTTON]
  283.         call    memmove
  284.         dec     dword[edi]
  285.         add     ecx, -sizeof.SYS_BUTTON
  286.         pop     ebx
  287.         jmp     .next_button
  288.  
  289. ;---------------------------------------------------------------
  290. sys_button_activate_handler:
  291. sys_button_deactivate_handler:
  292. ;---------------------------------------------------------------
  293. ;> eax = pack[8(process slot), 24(button id)]
  294. ;> ebx = pack[16(button x coord), 16(button y coord)]
  295. ;> cl = mouse button mask this system button was pressed with
  296. ;---------------------------------------------------------------
  297. ; find system button by specified process slot, id and coordinates
  298.         push    ecx edx esi edi
  299.         mov     edx, eax
  300.         shr     edx, 24
  301.         and     eax, 0x0ffffff
  302.         mov     edi, [BTN_ADDR]
  303.         mov     ecx, [edi]
  304.         imul    esi, ecx, sizeof.SYS_BUTTON
  305.         add     esi, edi
  306.         inc     ecx
  307.         add     esi, sizeof.SYS_BUTTON
  308. .next_button:
  309.         dec     ecx
  310.         jz      .popexit
  311.         add     esi, -sizeof.SYS_BUTTON
  312.  
  313.         ; does it belong to our process?
  314.         cmp     dx, [esi + SYS_BUTTON.pslot]
  315.         jne     .next_button
  316.  
  317.         ; does id match?
  318.         mov     edi, dword[esi + SYS_BUTTON.id_hi - 2]
  319.         mov     di, [esi + SYS_BUTTON.id_lo]
  320.         and     edi, 0x0ffffff
  321.         cmp     eax, edi
  322.         jne     .next_button
  323.  
  324.         ; does coordinates match?
  325.         mov     edi, dword[esi + SYS_BUTTON.left - 2]
  326.         mov     di, [esi + SYS_BUTTON.top]
  327.         cmp     ebx, edi
  328.         jne     .next_button
  329.  
  330.         mov     eax, esi
  331.         pop     edi esi edx ecx
  332.         mov     ebx, dword[eax + SYS_BUTTON.id_hi - 2]
  333.  
  334.         ; display button border on press?
  335.         bt      ebx, 29
  336.         jc      .exit
  337.  
  338.         ; invert system button border
  339.         pushad
  340.         mov     esi, eax
  341.         mov     edi, ebx
  342.         movzx   ecx, [esi + SYS_BUTTON.pslot]
  343.         shl     ecx, BSF sizeof.WDATA
  344.         mov     eax, dword[esi + SYS_BUTTON.left]
  345.         mov     ebx, dword[esi + SYS_BUTTON.top]
  346.         add     eax, [window_data + ecx + WDATA.box.left]
  347.         add     ebx, [window_data + ecx + WDATA.box.top]
  348.         mov     ecx, eax
  349.         mov     edx, ebx
  350.         bt      edi, 30
  351.         jc      @f
  352.         inc     ax
  353.         inc     bx
  354.         dec     cx
  355.         dec     dx
  356. @@:
  357.         rol     eax, 16
  358.         rol     ebx, 16
  359.         add     ax, cx
  360.         add     bx, dx
  361.         mov     esi, 1000000h
  362.         call    draw_rectangle.forced
  363.         popad
  364. .exit:
  365.         ret
  366. .popexit:
  367.         pop     edi esi edx ecx
  368.         ret
  369.  
  370. ;---------------------------------------------------------------
  371. sys_button_perform_handler:
  372. ;---------------------------------------------------------------
  373. ;> eax = pack[8(process slot), 24(button id)]
  374. ;> ebx = pack[16(button x coord), 16(button y coord)]
  375. ;> cl = mouse button mask this system button was pressed with
  376. ;---------------------------------------------------------------
  377.         shl     eax, 8
  378.         mov     al, cl
  379.         movzx   ebx, byte[BTN_COUNT]
  380.         mov     [BTN_BUFF + ebx * 4], eax
  381.         inc     bl
  382.         mov     [BTN_COUNT], bl
  383.         ret
  384.