Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2012. 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: 2465 $
  10.  
  11. ;==============================================================================
  12. ;///// public functions ///////////////////////////////////////////////////////
  13. ;==============================================================================
  14.  
  15. button.MAX_BUTTONS = 4095
  16.  
  17. struct  SYS_BUTTON
  18.         pslot           dw ?
  19.         id_lo           dw ?
  20.         left            dw ?
  21.         width           dw ?
  22.         top             dw ?
  23.         height          dw ?
  24.         id_hi           dw ?
  25.                         dw ?
  26. ends
  27.  
  28. align 4
  29. ;------------------------------------------------------------------------------
  30. syscall_button: ;///// system function 8 //////////////////////////////////////
  31. ;------------------------------------------------------------------------------
  32. ;? Define/undefine GUI button object
  33. ;------------------------------------------------------------------------------
  34. ;; Define button:
  35. ;> ebx = pack[16(x), 16(width)]
  36. ;> ecx = pack[16(y), 16(height)]
  37. ;> edx = pack[8(flags), 24(button identifier)]
  38. ;>       flags bits:
  39. ;>          7 (31) = 0
  40. ;>          6 (30) = don't draw button
  41. ;>          5 (29) = don't draw button frame when pressed
  42. ;> esi = button color
  43. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  44. ;; Undefine button:
  45. ;> edx = pack[8(flags), 24(button identifier)]
  46. ;>       flags bits:
  47. ;>          7 (31) = 1
  48. ;------------------------------------------------------------------------------
  49.         ; do we actually need to undefine the button?
  50.         test    edx, 0x80000000
  51.         jnz     .remove_button
  52.  
  53.         ; do we have free button slots available?
  54.         mov     edi, [BTN_ADDR]
  55.         mov     eax, [edi]
  56.         cmp     eax, button.MAX_BUTTONS
  57.         jge     .exit
  58.  
  59.         ; does it have positive size? (otherwise it doesn't have sense)
  60.         or      bx, bx
  61.         jle     .exit
  62.         or      cx, cx
  63.         jle     .exit
  64.  
  65.         ; make coordinates clientbox-relative
  66.         push    eax
  67.         mov     eax, [current_slot]
  68.         rol     ebx, 16
  69.         add     bx, word[eax + APPDATA.wnd_clientbox.left]
  70.         rol     ebx, 16
  71.         rol     ecx, 16
  72.         add     cx, word[eax + APPDATA.wnd_clientbox.top]
  73.         rol     ecx, 16
  74.         pop     eax
  75.  
  76.         ; basic checks passed, define the button
  77.         push    ebx ecx edx
  78.         inc     eax
  79.         mov     [edi], ax
  80.         shl     eax, 4
  81.         add     edi, eax
  82.         ; NOTE: this code doesn't rely on SYS_BUTTON struct, please revise it
  83.         ;       if you change something
  84.         mov     ax, [CURRENT_TASK]
  85.         stosw
  86.         mov     ax, dx
  87.         stosw               ; button id number: bits 0-15
  88.         mov     eax, ebx
  89.         rol     eax, 16
  90.         stosd               ; x start | x size
  91.         mov     eax, ecx
  92.         rol     eax, 16
  93.         stosd               ; y start | y size
  94.         mov     eax, edx
  95.         shr     eax, 16
  96.         stosw               ; button id number: bits 16-31
  97.         pop     edx ecx ebx
  98.  
  99.         ; do we also need to draw the button?
  100.         test    edx, 0x40000000
  101.         jnz     .exit
  102.  
  103.         ; draw button body
  104.  
  105.         pushad
  106.  
  107.         ; calculate window-relative coordinates
  108.         movzx   edi, cx
  109.         shr     ebx, 16
  110.         shr     ecx, 16
  111.         mov     eax, [TASK_BASE]
  112.         add     ebx, [eax - twdw + WDATA.box.left]
  113.         add     ecx, [eax - twdw + WDATA.box.top]
  114.         mov     eax, ebx
  115.         shl     eax, 16
  116.         mov     ax, bx
  117.         add     ax, word[esp + 16]
  118.         mov     ebx, ecx
  119.         shl     ebx, 16
  120.         mov     bx, cx
  121.  
  122.         ; calculate initial color
  123.         mov     ecx, esi
  124.         cmp     [buttontype], 0
  125.         je      @f
  126.         call    button._.incecx2
  127.  
  128.         ; set button height counter
  129.     @@:
  130.         mov     edx, edi
  131.  
  132.   .next_line:
  133.         call    button._.button_dececx
  134.         push    edi
  135.         xor     edi, edi
  136. ;        call    [draw_line]
  137.         call    __sys_draw_line
  138.         pop     edi
  139.         add     ebx, 0x00010001
  140.         dec     edx
  141.         jnz     .next_line
  142.  
  143.         popad
  144.  
  145.         ; draw button frame
  146.  
  147.         push    ebx ecx
  148.  
  149.         ; calculate window-relative coordinates
  150.         shr     ebx, 16
  151.         shr     ecx, 16
  152.         mov     eax, [TASK_BASE]
  153.         add     ebx, [eax - twdw + WDATA.box.left]
  154.         add     ecx, [eax - twdw + WDATA.box.top]
  155.  
  156.         ; top border
  157.         mov     eax, ebx
  158.         shl     eax, 16
  159.         mov     ax, bx
  160.         add     ax, [esp + 4]
  161.         mov     ebx, ecx
  162.         shl     ebx, 16
  163.         mov     bx, cx
  164.         push    ebx
  165.         xor     edi, edi
  166.         mov     ecx, esi
  167.         call    button._.incecx
  168. ;        call    [draw_line]
  169.         call    __sys_draw_line
  170.  
  171.         ; bottom border
  172.         movzx   edx, word[esp + 4 + 0]
  173.         add     ebx, edx
  174.         shl     edx, 16
  175.         add     ebx, edx
  176.         mov     ecx, esi
  177.         call    button._.dececx
  178. ;        call    [draw_line]
  179.         call    __sys_draw_line
  180.  
  181.         ; left border
  182.         pop     ebx
  183.         push    edx
  184.         mov     edx, eax
  185.         shr     edx, 16
  186.         mov     ax, dx
  187.         mov     edx, ebx
  188.         shr     edx, 16
  189.         mov     bx, dx
  190.         add     bx, [esp + 4 + 0]
  191.         pop     edx
  192.         mov     ecx, esi
  193.         call    button._.incecx
  194. ;        call    [draw_line]
  195.         call    __sys_draw_line
  196.  
  197.         ; right border
  198.         mov     dx, [esp + 4]
  199.         add     ax, dx
  200.         shl     edx, 16
  201.         add     eax, edx
  202.         add     ebx, 0x00010000
  203.         mov     ecx, esi
  204.         call    button._.dececx
  205. ;        call    [draw_line]
  206.         call    __sys_draw_line
  207.  
  208.         pop     ecx ebx
  209.  
  210.   .exit:
  211.         ret
  212.  
  213. ; FIXME: mutex needed
  214. syscall_button.remove_button:
  215.         and     edx, 0x00ffffff
  216.         mov     edi, [BTN_ADDR]
  217.         mov     ebx, [edi]
  218.         inc     ebx
  219.         imul    esi, ebx, sizeof.SYS_BUTTON
  220.         add     esi, edi
  221.         xor     ecx, ecx
  222.         add     ecx, -sizeof.SYS_BUTTON
  223.         add     esi, sizeof.SYS_BUTTON
  224.  
  225.   .next_button:
  226.         dec     ebx
  227.         jz      .exit
  228.  
  229.         add     ecx, sizeof.SYS_BUTTON
  230.         add     esi, -sizeof.SYS_BUTTON
  231.  
  232.         ; does it belong to our process?
  233.         mov     ax, [CURRENT_TASK]
  234.         cmp     ax, [esi + SYS_BUTTON.pslot]
  235.         jne     .next_button
  236.  
  237.         ; does the identifier match?
  238.         mov     eax, dword[esi + SYS_BUTTON.id_hi - 2]
  239.         mov     ax, [esi + SYS_BUTTON.id_lo]
  240.         and     eax, 0x00ffffff
  241.         cmp     edx, eax
  242.         jne     .next_button
  243.  
  244.         ; okay, undefine it
  245.         push    ebx
  246.         mov     ebx, esi
  247.         lea     eax, [esi + sizeof.SYS_BUTTON]
  248.         call    memmove
  249.         dec     dword[edi]
  250.         add     ecx, -sizeof.SYS_BUTTON
  251.         pop     ebx
  252.         jmp     .next_button
  253.  
  254.   .exit:
  255.         ret
  256.  
  257. align 4
  258. ;------------------------------------------------------------------------------
  259. sys_button_activate_handler: ;/////////////////////////////////////////////////
  260. ;------------------------------------------------------------------------------
  261. ;? <description>
  262. ;------------------------------------------------------------------------------
  263. ;> eax = pack[8(process slot), 24(button id)]
  264. ;> ebx = pack[16(button x coord), 16(button y coord)]
  265. ;> cl = mouse button mask this system button was pressed with
  266. ;------------------------------------------------------------------------------
  267.         call    button._.find_button
  268.         or      eax, eax
  269.         jz      .exit
  270.  
  271.         mov     ebx, dword[eax + SYS_BUTTON.id_hi - 2]
  272.         call    button._.negative_button
  273.  
  274.   .exit:
  275.         ret
  276.  
  277. align 4
  278. ;------------------------------------------------------------------------------
  279. sys_button_deactivate_handler: ;///////////////////////////////////////////////
  280. ;------------------------------------------------------------------------------
  281. ;? <description>
  282. ;------------------------------------------------------------------------------
  283. ;> eax = pack[8(process slot), 24(button id)]
  284. ;> ebx = pack[16(button x coord), 16(button y coord)]
  285. ;> cl = mouse button mask this system button was pressed with
  286. ;------------------------------------------------------------------------------
  287.         call    button._.find_button
  288.         or      eax, eax
  289.         jz      .exit
  290.  
  291.         mov     ebx, dword[eax + SYS_BUTTON.id_hi - 2]
  292.         call    button._.negative_button
  293.  
  294.   .exit:
  295.         ret
  296.  
  297. align 4
  298. ;------------------------------------------------------------------------------
  299. sys_button_perform_handler: ;//////////////////////////////////////////////////
  300. ;------------------------------------------------------------------------------
  301. ;? <description>
  302. ;------------------------------------------------------------------------------
  303. ;> eax = pack[8(process slot), 24(button id)]
  304. ;> ebx = pack[16(button x coord), 16(button y coord)]
  305. ;> cl = mouse button mask this system button was pressed with
  306. ;------------------------------------------------------------------------------
  307.         shl     eax, 8
  308.         mov     al, cl
  309.         movzx   ebx, byte[BTN_COUNT]
  310.         mov     [BTN_BUFF + ebx * 4], eax
  311.         inc     bl
  312.         mov     [BTN_COUNT], bl
  313.         ret
  314.  
  315. ;==============================================================================
  316. ;///// private functions //////////////////////////////////////////////////////
  317. ;==============================================================================
  318.  
  319. ;------------------------------------------------------------------------------
  320. button._.find_button: ;////////////////////////////////////////////////////////
  321. ;------------------------------------------------------------------------------
  322. ;? Find system button by specified process slot, id and coordinates
  323. ;------------------------------------------------------------------------------
  324. ;> eax = pack[8(process slot), 24(button id)] or 0
  325. ;> ebx = pack[16(button x coord), 16(button y coord)]
  326. ;------------------------------------------------------------------------------
  327. ;< eax = pointer to SYS_BUTTON struct or 0
  328. ;------------------------------------------------------------------------------
  329.         push    ecx edx esi edi
  330.  
  331.         mov     edx, eax
  332.         shr     edx, 24
  333.         and     eax, 0x0ffffff
  334.  
  335.         mov     edi, [BTN_ADDR]
  336.         mov     ecx, [edi]
  337.         imul    esi, ecx, sizeof.SYS_BUTTON
  338.         add     esi, edi
  339.         inc     ecx
  340.         add     esi, sizeof.SYS_BUTTON
  341.  
  342.   .next_button:
  343.         dec     ecx
  344.         jz      .not_found
  345.  
  346.         add     esi, -sizeof.SYS_BUTTON
  347.  
  348.         ; does it belong to our process?
  349.         cmp     dx, [esi + SYS_BUTTON.pslot]
  350.         jne     .next_button
  351.  
  352.         ; does id match?
  353.         mov     edi, dword[esi + SYS_BUTTON.id_hi - 2]
  354.         mov     di, [esi + SYS_BUTTON.id_lo]
  355.         and     edi, 0x0ffffff
  356.         cmp     eax, edi
  357.         jne     .next_button
  358.  
  359.         ; does coordinates match?
  360.         mov     edi, dword[esi + SYS_BUTTON.left - 2]
  361.         mov     di, [esi + SYS_BUTTON.top]
  362.         cmp     ebx, edi
  363.         jne     .next_button
  364.  
  365.         ; okay, return it
  366.         mov     eax, esi
  367.         jmp     .exit
  368.  
  369.   .not_found:
  370.         xor     eax, eax
  371.  
  372.   .exit:
  373.         pop     edi esi edx ecx
  374.         ret
  375.  
  376. ;------------------------------------------------------------------------------
  377. button._.dececx: ;/////////////////////////////////////////////////////////////
  378. ;------------------------------------------------------------------------------
  379. ;? <description>
  380. ;------------------------------------------------------------------------------
  381.         sub     cl, 0x20
  382.         jnc     @f
  383.         xor     cl, cl
  384.     @@:
  385.         sub     ch, 0x20
  386.         jnc     @f
  387.         xor     ch, ch
  388.     @@:
  389.         rol     ecx, 16
  390.         sub     cl, 0x20
  391.         jnc     @f
  392.         xor     cl, cl
  393.     @@:
  394.         rol     ecx, 16
  395.         ret
  396.  
  397. ;------------------------------------------------------------------------------
  398. button._.incecx: ;/////////////////////////////////////////////////////////////
  399. ;------------------------------------------------------------------------------
  400. ;? <description>
  401. ;------------------------------------------------------------------------------
  402.         add     cl, 0x20
  403.         jnc     @f
  404.         or      cl, -1
  405.     @@:
  406.         add     ch, 0x20
  407.         jnc     @f
  408.         or      ch, -1
  409.     @@:
  410.         rol     ecx, 16
  411.         add     cl, 0x20
  412.         jnc     @f
  413.         or      cl, -1
  414.     @@:
  415.         rol     ecx, 16
  416.         ret
  417.  
  418. ;------------------------------------------------------------------------------
  419. button._.incecx2: ;////////////////////////////////////////////////////////////
  420. ;------------------------------------------------------------------------------
  421. ;? <description>
  422. ;------------------------------------------------------------------------------
  423.         add     cl, 0x14
  424.         jnc     @f
  425.         or      cl, -1
  426.     @@:
  427.         add     ch, 0x14
  428.         jnc     @f
  429.         or      ch, -1
  430.     @@:
  431.         rol     ecx, 16
  432.         add     cl, 0x14
  433.         jnc     @f
  434.         or      cl, -1
  435.     @@:
  436.         rol     ecx, 16
  437.         ret
  438.  
  439. ;------------------------------------------------------------------------------
  440. button._.button_dececx: ;//////////////////////////////////////////////////////
  441. ;------------------------------------------------------------------------------
  442. ;? <description>
  443. ;------------------------------------------------------------------------------
  444.         cmp     [buttontype], 1
  445.         jne     .finish
  446.  
  447.         push    eax
  448.         mov     al, 1
  449.         cmp     edi, 20
  450.         jg      @f
  451.         mov     al, 2
  452.  
  453.     @@:
  454.         sub     cl, al
  455.         jnc     @f
  456.         xor     cl, cl
  457.     @@:
  458.         sub     ch, al
  459.         jnc     @f
  460.         xor     ch, ch
  461.     @@:
  462.         rol     ecx, 16
  463.         sub     cl, al
  464.         jnc     @f
  465.         xor     cl, cl
  466.     @@:
  467.         rol     ecx, 16
  468.  
  469.         pop     eax
  470.  
  471.   .finish:
  472.         ret
  473.  
  474. ;------------------------------------------------------------------------------
  475. button._.negative_button: ;////////////////////////////////////////////////////
  476. ;------------------------------------------------------------------------------
  477. ;? Invert system button border
  478. ;------------------------------------------------------------------------------
  479.         ; if requested, do not display button border on press.
  480.         test    ebx, 0x20000000
  481.         jnz     .exit
  482.  
  483.         pushad
  484.  
  485.         xchg    esi, eax
  486.  
  487.         movzx   ecx, [esi + SYS_BUTTON.pslot]
  488.         shl     ecx, 5
  489.         add     ecx, window_data
  490.  
  491.         mov     eax, dword[esi + SYS_BUTTON.left]
  492.         mov     ebx, dword[esi + SYS_BUTTON.top]
  493.         add     eax, [ecx + WDATA.box.left]
  494.         add     ebx, [ecx + WDATA.box.top]
  495.         push    eax ebx
  496.         pop     edx ecx
  497.         rol     eax, 16
  498.         rol     ebx, 16
  499.         add     ax, cx
  500.         add     bx, dx
  501.  
  502.         mov     esi, 0x01000000
  503.         call    draw_rectangle.forced
  504.  
  505.         popad
  506.  
  507.   .exit:
  508.         ret
  509.