Subversion Repositories Kolibri OS

Rev

Rev 9709 | Rev 9926 | Go to most recent revision | 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: 9911 $
  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.         rol     ebx, 16
  100.         add     bx, word[eax + APPDATA.wnd_clientbox.left]
  101.         rol     ebx, 16
  102.         rol     ecx, 16
  103.         add     cx, word[eax + APPDATA.wnd_clientbox.top]
  104.         rol     ecx, 16
  105.         pop     eax
  106.  
  107.         ; basic checks passed, define the button
  108.         inc     eax
  109.         mov     [edi], ax
  110.         shl     eax, 4
  111.         add     edi, eax
  112. ; NOTE: this code doesn't rely on SYS_BUTTON struct,
  113. ; please revise it, if you change something.
  114.         mov     ax, word [current_slot_idx]
  115.         stosw
  116.         mov     ax, dx
  117.         stosw               ; button id number: bits 0-15
  118.         mov     eax, ebx
  119.         rol     eax, 16
  120.         stosd               ; x start | x size
  121.         mov     eax, ecx
  122.         rol     eax, 16
  123.         stosd               ; y start | y size
  124.         mov     eax, edx
  125.         shr     eax, 16
  126.         stosw               ; button id number: bits 16-31
  127.  
  128.         ; do we also need to draw the button?
  129.         test    edx, 0x40000000
  130.         jnz     .exit
  131.  
  132.         and     esi, 0xFFFFFF
  133.         xor     edi, edi
  134.         push    ebx ecx esi
  135.         dec     cx
  136.         dec     cx
  137.         cmp     [buttontype], 1
  138.         jnz     .draw
  139.         cmp     cx, 65
  140.         jnc     .draw
  141.  
  142.         ; calculate gradient data
  143.         mov     eax, esi
  144.         shl     eax, 8
  145.         mov     edx, 3
  146. .calculate:
  147.         rol     eax, 8
  148.         shl     al, 1
  149.         jnc     @f
  150.         neg     al
  151.         jnz     @f
  152.         mov     al, 64
  153. @@:
  154.         cmp     al, 65
  155.         jc      @f
  156.         mov     al, 64
  157. @@:
  158.         div     cl
  159.         shl     ax, 8
  160.         dec     edx
  161.         jnz     .calculate
  162.         mov     dl, cl
  163.         dec     edx
  164.         shr     edx, 1
  165.         shr     eax, 8
  166.         mov     edi, eax
  167.         mul     edx
  168.         add     esi, eax
  169.  
  170. .draw:  ; calculate window-relative coordinates
  171.         movzx   ebp, cx
  172.         dec     ebp
  173.         shr     ebx, 16
  174.         shr     ecx, 16
  175.         mov     eax, [current_slot_idx]
  176.         shl     eax, BSF sizeof.WDATA
  177.         add     ebx, [eax + window_data + WDATA.box.left]
  178.         add     ecx, [eax + window_data + WDATA.box.top]
  179.         mov     eax, ebx
  180.         inc     eax
  181.         mov     edx, ebx
  182.         add     dx, [esp+8]
  183.         dec     edx
  184.         mov     ebx, ecx
  185.         mov     ecx, esi
  186.         shr     ecx, 1
  187.         and     cx, 7F7Fh
  188.         push    esi
  189.         mov     esi, edi
  190.         xor     edi, edi
  191.         call    hline   ; top border
  192.         inc     ebx
  193.         or      ecx, 808080h
  194.         call    hline   ; top light line
  195.         pop     ecx
  196.         inc     ebx
  197. .next_line:
  198.         call    hline   ; button body
  199.         inc     ebx
  200.         sub     ecx, esi
  201.         dec     ebp
  202.         jnz     .next_line
  203.         shr     ecx, 2
  204.         and     cx, 3F3Fh
  205.         mov     ebp, ecx
  206.         shl     ecx, 1
  207.         add     ecx, ebp
  208.         call    hline   ; bottom dark line
  209.         inc     ebx
  210.         sub     ecx, ebp
  211.         call    hline   ; bottom border
  212.         pop     ecx
  213.         shr     ecx, 1
  214.         inc     edx
  215.         push    edx
  216.         mov     edx, ebx
  217.         sub     bx, [esp+4]
  218.         dec     edx
  219.         inc     ebx
  220.         cmp     [buttontype], 0
  221.         jnz     @f
  222.         dec     edx
  223.         or      ecx, 808080h
  224.         call    vline   ; left light line
  225.         inc     edx
  226. @@:
  227.         and     ecx, 7F7F7Fh
  228.         dec     eax
  229.         call    vline   ; left border
  230.         pop     eax
  231.         call    vline   ; right border
  232.         cmp     [buttontype], 0
  233.         jnz     @f
  234.         mov     ebp, ecx
  235.         shr     ecx, 1
  236.         and     cx, 7F7Fh
  237.         add     ecx, ebp
  238.         dec     eax
  239.         inc     ebx
  240.         dec     edx     ; avoid lines overflow
  241.         call    vline   ; right dark line
  242. @@:
  243.         pop     ecx ebx
  244. .exit:
  245.         ret
  246.  
  247. ; FIXME: mutex needed
  248. .remove_button:
  249.         and     edx, 0x00ffffff
  250.         mov     edi, [BTN_ADDR]
  251.         mov     ebx, [edi]
  252.         inc     ebx
  253.         imul    esi, ebx, sizeof.SYS_BUTTON
  254.         add     esi, edi
  255.         xor     ecx, ecx
  256.         add     ecx, -sizeof.SYS_BUTTON
  257.         add     esi, sizeof.SYS_BUTTON
  258.  
  259. .next_button:
  260.         dec     ebx
  261.         jz      .exit
  262.  
  263.         add     ecx, sizeof.SYS_BUTTON
  264.         add     esi, -sizeof.SYS_BUTTON
  265.  
  266.         ; does it belong to our process?
  267.         mov     ax, word [current_slot_idx]
  268.         cmp     ax, [esi + SYS_BUTTON.pslot]
  269.         jne     .next_button
  270.  
  271.         ; does the identifier match?
  272.         mov     eax, dword[esi + SYS_BUTTON.id_hi - 2]
  273.         mov     ax, [esi + SYS_BUTTON.id_lo]
  274.         and     eax, 0x00ffffff
  275.         cmp     edx, eax
  276.         jne     .next_button
  277.  
  278.         ; okay, undefine it
  279.         push    ebx
  280.         mov     ebx, esi
  281.         lea     eax, [esi + sizeof.SYS_BUTTON]
  282.         call    memmove
  283.         dec     dword[edi]
  284.         add     ecx, -sizeof.SYS_BUTTON
  285.         pop     ebx
  286.         jmp     .next_button
  287.  
  288. ;---------------------------------------------------------------
  289. sys_button_activate_handler:
  290. sys_button_deactivate_handler:
  291. ;---------------------------------------------------------------
  292. ;> eax = pack[8(process slot), 24(button id)]
  293. ;> ebx = pack[16(button x coord), 16(button y coord)]
  294. ;> cl = mouse button mask this system button was pressed with
  295. ;---------------------------------------------------------------
  296. ; find system button by specified process slot, id and coordinates
  297.         push    ecx edx esi edi
  298.         mov     edx, eax
  299.         shr     edx, 24
  300.         and     eax, 0x0ffffff
  301.         mov     edi, [BTN_ADDR]
  302.         mov     ecx, [edi]
  303.         imul    esi, ecx, sizeof.SYS_BUTTON
  304.         add     esi, edi
  305.         inc     ecx
  306.         add     esi, sizeof.SYS_BUTTON
  307. .next_button:
  308.         dec     ecx
  309.         jz      .popexit
  310.         add     esi, -sizeof.SYS_BUTTON
  311.  
  312.         ; does it belong to our process?
  313.         cmp     dx, [esi + SYS_BUTTON.pslot]
  314.         jne     .next_button
  315.  
  316.         ; does id match?
  317.         mov     edi, dword[esi + SYS_BUTTON.id_hi - 2]
  318.         mov     di, [esi + SYS_BUTTON.id_lo]
  319.         and     edi, 0x0ffffff
  320.         cmp     eax, edi
  321.         jne     .next_button
  322.  
  323.         ; does coordinates match?
  324.         mov     edi, dword[esi + SYS_BUTTON.left - 2]
  325.         mov     di, [esi + SYS_BUTTON.top]
  326.         cmp     ebx, edi
  327.         jne     .next_button
  328.  
  329.         mov     eax, esi
  330.         pop     edi esi edx ecx
  331.         mov     ebx, dword[eax + SYS_BUTTON.id_hi - 2]
  332.  
  333.         ; display button border on press?
  334.         bt      ebx, 29
  335.         jc      .exit
  336.  
  337.         ; invert system button border
  338.         pushad
  339.         mov     esi, eax
  340.         mov     edi, ebx
  341.         movzx   ecx, [esi + SYS_BUTTON.pslot]
  342.         shl     ecx, 5
  343.         add     ecx, window_data
  344.         mov     eax, dword[esi + SYS_BUTTON.left]
  345.         mov     ebx, dword[esi + SYS_BUTTON.top]
  346.         add     eax, [ecx + WDATA.box.left]
  347.         add     ebx, [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.