Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2015. 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: 6031 $
  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. ;---------------------------------------------------------------
  25. syscall_button: ;////////////// system function 8 //////////////
  26. ;---------------------------------------------------------------
  27. ;? Define/undefine GUI button object
  28. ;---------------------------------------------------------------
  29. ;; Define button:
  30. ;> ebx = pack[16(x), 16(width)]
  31. ;> ecx = pack[16(y), 16(height)]
  32. ;> edx = pack[8(flags), 24(button identifier)]
  33. ;>       flags bits:
  34. ;>          7 (31) = 0
  35. ;>          6 (30) = don't draw button
  36. ;>          5 (29) = don't draw button frame when pressed
  37. ;> esi = button color
  38. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  39. ;; Undefine button:
  40. ;> edx = pack[8(flags), 24(button identifier)]
  41. ;>       flags bits:
  42. ;>          7 (31) = 1
  43. ;---------------------------------------------------------------
  44.         ; do we actually need to undefine the button?
  45.         test    edx, 0x80000000
  46.         jnz     .remove_button
  47.  
  48.         ; do we have free button slots available?
  49.         mov     edi, [BTN_ADDR]
  50.         mov     eax, [edi]
  51.         cmp     eax, button.MAX_BUTTONS
  52.         jge     .exit
  53.  
  54.         ; does it have positive size? (otherwise it doesn't have sense)
  55.         or      bx, bx
  56.         jle     .exit
  57.         or      cx, cx
  58.         jle     .exit
  59.  
  60.         ; make coordinates clientbox-relative
  61.         push    eax
  62.         mov     eax, [current_slot]
  63.         rol     ebx, 16
  64.         add     bx, word[eax + APPDATA.wnd_clientbox.left]
  65.         rol     ebx, 16
  66.         rol     ecx, 16
  67.         add     cx, word[eax + APPDATA.wnd_clientbox.top]
  68.         rol     ecx, 16
  69.         pop     eax
  70.  
  71.         ; basic checks passed, define the button
  72.         inc     eax
  73.         mov     [edi], ax
  74.         shl     eax, 4
  75.         add     edi, eax
  76. ; NOTE: this code doesn't rely on SYS_BUTTON struct,
  77. ; please revise it, if you change something.
  78.         mov     ax, [CURRENT_TASK]
  79.         stosw
  80.         mov     ax, dx
  81.         stosw               ; button id number: bits 0-15
  82.         mov     eax, ebx
  83.         rol     eax, 16
  84.         stosd               ; x start | x size
  85.         mov     eax, ecx
  86.         rol     eax, 16
  87.         stosd               ; y start | y size
  88.         mov     eax, edx
  89.         shr     eax, 16
  90.         stosw               ; button id number: bits 16-31
  91.  
  92.         ; do we also need to draw the button?
  93.         test    edx, 0x40000000
  94.         jnz     .exit
  95.  
  96.         xor     edi, edi
  97.         push    ebx ecx esi
  98.         cmp     [buttontype], 1
  99.         jnz     .draw
  100.         cmp     cx, 129
  101.         jnc     .draw
  102.  
  103.         ; calculate gradient data
  104.         mov     eax, esi
  105.         shl     eax, 8
  106.         mov     edx, 3
  107. .calculate:
  108.         rol     eax, 8
  109.         shl     al, 1
  110.         jnc     @f
  111.         neg     al
  112.         jnz     @f
  113.         mov     al, 128
  114. @@:
  115.         jns     @f
  116.         mov     al, 128
  117. @@:
  118.         div     cl
  119.         shl     ax, 8
  120.         dec     edx
  121.         jnz     .calculate
  122.         mov     dl, cl
  123.         dec     edx
  124.         shr     edx, 1
  125.         shr     eax, 8
  126.         mov     edi, eax
  127.         mul     edx
  128.         add     esi, eax
  129.  
  130. .draw:  ; calculate window-relative coordinates
  131.         movzx   ebp, cx
  132.         dec     ebp
  133.         shr     ebx, 16
  134.         shr     ecx, 16
  135.         mov     eax, [TASK_BASE]
  136.         add     ebx, [eax - twdw + WDATA.box.left]
  137.         add     ecx, [eax - twdw + WDATA.box.top]
  138.         mov     eax, ebx
  139.         inc     eax
  140.         mov     edx, ebx
  141.         add     dx, [esp+8]
  142.         dec     edx
  143.         mov     ebx, ecx
  144.         mov     ecx, esi
  145.         shr     ecx, 1
  146.         btr     ecx, 7
  147.         btr     ecx, 15
  148.         push    esi
  149.         mov     esi, edi
  150.         xor     edi, edi
  151.         call    hline   ; top border
  152.         inc     ebx
  153.         pop     ecx
  154. .next_line:
  155.         call    hline   ; button body
  156.         inc     ebx
  157.         sub     ecx, esi
  158.         dec     ebp
  159.         jnz     .next_line
  160.         shr     ecx, 1
  161.         btr     ecx, 7
  162.         btr     ecx, 15
  163.         call    hline   ; bottom border
  164.         pop     ecx
  165.         shr     ecx, 1
  166.         btr     ecx, 7
  167.         btr     ecx, 15
  168.         inc     edx
  169.         push    edx
  170.         mov     edx, ebx
  171.         sub     bx, [esp+4]
  172.         dec     eax
  173.         cmp     [buttontype], 1
  174.         jnz     @f
  175.         dec     edx
  176.         inc     ebx
  177. @@:
  178.         call    vline   ; left border
  179.         pop     eax
  180.         call    vline   ; right border
  181.         pop     ecx ebx
  182. .exit:
  183.         ret
  184.  
  185. ; FIXME: mutex needed
  186. .remove_button:
  187.         and     edx, 0x00ffffff
  188.         mov     edi, [BTN_ADDR]
  189.         mov     ebx, [edi]
  190.         inc     ebx
  191.         imul    esi, ebx, sizeof.SYS_BUTTON
  192.         add     esi, edi
  193.         xor     ecx, ecx
  194.         add     ecx, -sizeof.SYS_BUTTON
  195.         add     esi, sizeof.SYS_BUTTON
  196.  
  197. .next_button:
  198.         dec     ebx
  199.         jz      .exit
  200.  
  201.         add     ecx, sizeof.SYS_BUTTON
  202.         add     esi, -sizeof.SYS_BUTTON
  203.  
  204.         ; does it belong to our process?
  205.         mov     ax, [CURRENT_TASK]
  206.         cmp     ax, [esi + SYS_BUTTON.pslot]
  207.         jne     .next_button
  208.  
  209.         ; does the identifier match?
  210.         mov     eax, dword[esi + SYS_BUTTON.id_hi - 2]
  211.         mov     ax, [esi + SYS_BUTTON.id_lo]
  212.         and     eax, 0x00ffffff
  213.         cmp     edx, eax
  214.         jne     .next_button
  215.  
  216.         ; okay, undefine it
  217.         push    ebx
  218.         mov     ebx, esi
  219.         lea     eax, [esi + sizeof.SYS_BUTTON]
  220.         call    memmove
  221.         dec     dword[edi]
  222.         add     ecx, -sizeof.SYS_BUTTON
  223.         pop     ebx
  224.         jmp     .next_button
  225.  
  226. ;---------------------------------------------------------------
  227. sys_button_activate_handler:
  228. sys_button_deactivate_handler:
  229. ;---------------------------------------------------------------
  230. ;> eax = pack[8(process slot), 24(button id)]
  231. ;> ebx = pack[16(button x coord), 16(button y coord)]
  232. ;> cl = mouse button mask this system button was pressed with
  233. ;---------------------------------------------------------------
  234. ; find system button by specified process slot, id and coordinates
  235.         push    ecx edx esi edi
  236.         mov     edx, eax
  237.         shr     edx, 24
  238.         and     eax, 0x0ffffff
  239.         mov     edi, [BTN_ADDR]
  240.         mov     ecx, [edi]
  241.         imul    esi, ecx, sizeof.SYS_BUTTON
  242.         add     esi, edi
  243.         inc     ecx
  244.         add     esi, sizeof.SYS_BUTTON
  245. .next_button:
  246.         dec     ecx
  247.         jz      .popexit
  248.         add     esi, -sizeof.SYS_BUTTON
  249.  
  250.         ; does it belong to our process?
  251.         cmp     dx, [esi + SYS_BUTTON.pslot]
  252.         jne     .next_button
  253.  
  254.         ; does id match?
  255.         mov     edi, dword[esi + SYS_BUTTON.id_hi - 2]
  256.         mov     di, [esi + SYS_BUTTON.id_lo]
  257.         and     edi, 0x0ffffff
  258.         cmp     eax, edi
  259.         jne     .next_button
  260.  
  261.         ; does coordinates match?
  262.         mov     edi, dword[esi + SYS_BUTTON.left - 2]
  263.         mov     di, [esi + SYS_BUTTON.top]
  264.         cmp     ebx, edi
  265.         jne     .next_button
  266.  
  267.         mov     eax, esi
  268.         pop     edi esi edx ecx
  269.         mov     ebx, dword[eax + SYS_BUTTON.id_hi - 2]
  270.  
  271.         ; display button border on press?
  272.         test    ebx, 0x20000000
  273.         jnz     .exit
  274.  
  275.         ; invert system button border
  276.         pushad
  277.         mov     esi, eax
  278.         movzx   ecx, [esi + SYS_BUTTON.pslot]
  279.         shl     ecx, 5
  280.         add     ecx, window_data
  281.         mov     eax, dword[esi + SYS_BUTTON.left]
  282.         mov     ebx, dword[esi + SYS_BUTTON.top]
  283.         add     eax, [ecx + WDATA.box.left]
  284.         add     ebx, [ecx + WDATA.box.top]
  285.         rol     eax, 16
  286.         rol     ebx, 16
  287.         push    eax ebx
  288.         shr     eax, 16
  289.         shr     ebx, 16
  290.         mov     edx, eax
  291.         add     dx, [esp+4]
  292.         dec     edx
  293.         inc     eax
  294.         mov     ecx, 1000000h
  295.         xor     edi, edi
  296.         inc     edi
  297.         call    hline
  298.         add     bx, [esp]
  299.         call    hline
  300.         inc     edx
  301.         push    edx
  302.         mov     edx, ebx
  303.         sub     bx, [esp+4]
  304.         dec     eax
  305.         cmp     [buttontype], 1
  306.         jnz     @f
  307.         dec     edx
  308.         inc     ebx
  309. @@:
  310.         call    vline
  311.         pop     eax
  312.         call    vline
  313.         pop     eax eax
  314.         popad
  315. .exit:
  316.         ret
  317. .popexit:
  318.         pop     edi esi edx ecx
  319.         ret
  320.  
  321. ;---------------------------------------------------------------
  322. sys_button_perform_handler:
  323. ;---------------------------------------------------------------
  324. ;> eax = pack[8(process slot), 24(button id)]
  325. ;> ebx = pack[16(button x coord), 16(button y coord)]
  326. ;> cl = mouse button mask this system button was pressed with
  327. ;---------------------------------------------------------------
  328.         shl     eax, 8
  329.         mov     al, cl
  330.         movzx   ebx, byte[BTN_COUNT]
  331.         mov     [BTN_BUFF + ebx * 4], eax
  332.         inc     bl
  333.         mov     [BTN_COUNT], bl
  334.         ret
  335.