Subversion Repositories Kolibri OS

Rev

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