Subversion Repositories Kolibri OS

Rev

Rev 3733 | Blame | Last modification | View Log | Download | RSS feed

  1. ;**************************************************************
  2. ; MenuBar Macro for Kolibri OS
  3. ; Copyright (c) 2009, Marat Zakiyanov aka Mario79, aka Mario
  4. ; All rights reserved.
  5. ;
  6. ; Redistribution and use in source and binary forms, with or without
  7. ; modification, are permitted provided that the following conditions are met:
  8. ;     * Redistributions of source code must retain the above copyright
  9. ;       notice, this list of conditions and the following disclaimer.
  10. ;     * Redistributions in binary form must reproduce the above copyright
  11. ;       notice, this list of conditions and the following disclaimer in the
  12. ;       documentation and/or other materials provided with the distribution.
  13. ;     * Neither the name of the <organization> nor the
  14. ;       names of its contributors may be used to endorse or promote products
  15. ;       derived from this software without specific prior written permission.
  16. ;
  17. ; THIS SOFTWARE IS PROVIDED BY Marat Zakiyanov ''AS IS'' AND ANY
  18. ; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. ; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. ; DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  21. ; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. ; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. ; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. ;*****************************************************************************
  28. macro menu_bar_exit
  29. {
  30. popa        
  31. ret 4
  32. }
  33. ;*****************************************************************************
  34. macro use_menu_bar
  35. {
  36. menu_bar:
  37. m_type                  equ [edi]
  38. m_size_x                equ [edi+4]
  39. m_start_x               equ [edi+6]
  40. m_size_y                equ [edi+8]
  41. m_start_y               equ [edi+10]
  42. m_text_pointer          equ [edi+12]
  43. m_pos_pointer           equ [edi+16]
  44. m_text_end              equ [edi+20]
  45. m_ret_key               equ [edi+24]
  46. m_mouse_keys            equ [edi+28]
  47. m_size_x1               equ [edi+32]
  48. m_start_x1              equ [edi+34]
  49. m_size_y1               equ [edi+36]
  50. m_start_y1              equ [edi+38]
  51. m_bckg_col              equ [edi+40]
  52. m_frnt_col              equ [edi+44]
  53. m_menu_col              equ [edi+48]
  54. m_select                equ [edi+52]
  55. m_out_select            equ [edi+56]
  56. m_buf_adress            equ [edi+60]
  57. m_procinfo              equ [edi+64]
  58. m_click                 equ [edi+68]
  59. m_cursor                equ [edi+72]
  60. m_cursor_old            equ [edi+76]
  61. m_interval              equ [edi+80]
  62. m_cursor_max            equ [edi+84]
  63. m_extended_key          equ [edi+88]
  64. m_menu_sel_col          equ [edi+92]
  65. m_bckg_text_col         equ [edi+96]
  66. m_frnt_text_col         equ [edi+100]
  67. m_mouse_keys_old        equ [edi+104]
  68. m_font_height           equ [edi+108]
  69. m_cursor_out            equ [edi+112]
  70. m_get_mouse_flag        equ [edi+116]
  71. ;*****************************************************************************
  72. ;*****************************************************************************
  73. ; draw event
  74. ;*****************************************************************************
  75. ;*****************************************************************************
  76. .draw:
  77.         pusha
  78.         mov     edi,dword [esp+36]
  79.         call    .draw_1
  80.         menu_bar_exit
  81. .draw_1:
  82.         call    .calc_m_cursor_max
  83.         dec     dword m_cursor_max
  84.         mov     eax,m_cursor_max
  85.         imul    eax,m_interval
  86.         mov     m_size_y1,ax
  87.        
  88.         mov     ebx,m_size_x
  89.         mov     ecx,m_size_y
  90.         cmp     dword m_select,1
  91.         je      .active
  92.         mov     edx,m_bckg_col
  93.         jmp     @f
  94. .active:
  95.         mov     edx,m_frnt_col
  96. @@:
  97.         mcall   13
  98.         shr     ecx,16
  99.         mov     bx,cx
  100.         movzx   eax,word m_size_y
  101.         call    .calculate_font_offset
  102.         cmp     dword m_select,1
  103.         je      .active_1
  104.         mov     ecx,m_bckg_text_col
  105.         add     ecx,0x80000000
  106.         jmp     @f
  107. .active_1:
  108.         mov     ecx,m_frnt_text_col
  109.         add     ecx,0x80000000
  110. @@:
  111.         mov     edx,m_text_pointer
  112.         mcall   4
  113.         ret
  114.  
  115. .draw_2:
  116.         mov     ebx,m_size_x1
  117.         mov     ecx,m_size_y1
  118.         mov     edx,m_menu_col
  119.         mcall   13
  120.         ret
  121.  
  122. .calculate_font_offset:
  123.         sub     eax,m_font_height
  124.         shr     eax,1
  125.         add     ebx,eax
  126.         add     ebx,4 shl 16
  127.         ret
  128.        
  129. .draw_3:
  130.         mov     ebx,m_size_x1
  131.         mov     ecx,m_size_y1
  132.  
  133.         push    ebx ecx
  134.         mov     eax,m_cursor_old
  135.         imul    eax,m_interval
  136.         shl     eax,16
  137.         add     ecx,eax
  138.         mov     cx,m_interval
  139.         mov     edx,m_menu_col
  140.         mcall   13
  141.         pop     ecx ebx
  142.    
  143.         push    ebx ecx
  144.         mov     eax,m_cursor
  145.         imul    eax,m_interval
  146.         shl     eax,16
  147.         add     ecx,eax
  148.         mov     cx,m_interval
  149.         mov     edx,m_menu_sel_col
  150.         mcall   13
  151.         pop     ecx ebx
  152.        
  153.         shr     ecx,16
  154.         mov     bx,cx
  155.         mov     eax,m_interval
  156.         call    .calculate_font_offset
  157.         mov     edx,m_pos_pointer
  158.         xor     ebp,ebp
  159. @@:
  160.         cmp     ebp,m_cursor
  161.         jne     .no_active_text
  162.         mov     ecx,m_frnt_text_col
  163.         mov     eax,m_menu_sel_col
  164.         jmp     .active_text
  165. .no_active_text:
  166.         mov     ecx,m_bckg_text_col
  167.         mov     eax,m_menu_col
  168. .active_text:
  169.         add     ecx,0xC0000000
  170.         push    edi
  171.         mov     edi,eax
  172.         mcall   4
  173.         pop     edi
  174.         call    .get_next_text
  175.         inc     ebp
  176.         add     ebx,m_interval
  177.         jmp     @r
  178. .draw_end:
  179.         ret
  180.        
  181. .calc_m_cursor_max:
  182.         mov     edx,m_pos_pointer
  183.         mov     m_cursor_max,dword 0
  184. @@:
  185.         inc     dword m_cursor_max
  186.         call    .get_next_text
  187.         jmp     @r
  188. ;*****************************************************************************
  189. .get_next_text:
  190.         mov     esi,edx
  191. @@:
  192.         cmp     esi,m_text_end
  193.         je      .get_next_text_end
  194.         cld
  195.         lodsb
  196.         test    al,al
  197.         jnz     @r
  198.         mov     edx,esi
  199.         ret
  200. .get_next_text_end:
  201.         add     esp,4
  202.         ret
  203. ;*****************************************************************************
  204. ;*****************************************************************************
  205. ; mouse event
  206. ;*****************************************************************************
  207. ;*****************************************************************************
  208. .activate:
  209.         pusha
  210.         mov     edi,dword [esp+36]
  211.         jmp     .start_loop
  212. .mouse:
  213.         pusha
  214.         mov     edi,dword [esp+36]
  215.  
  216.         call    .processing_real_mouse
  217.  
  218.         test    eax,0x80000000
  219.         jnz     .exit_menu
  220.         test    eax,0x8000
  221.         jnz     .exit_menu
  222.  
  223.         mov     ebx,eax
  224.         shr     ebx,16   ; x position
  225.         shl     eax,16
  226.         shr     eax,16   ; y position
  227.          
  228.         mov     cx,m_start_x
  229.         cmp     bx,cx
  230.         jb      .exit_menu
  231.      
  232.         add     cx,m_size_x
  233.         dec     cx
  234.         cmp     bx,cx
  235.         ja      .exit_menu
  236.  
  237.         mov     cx,m_start_y
  238.         cmp     ax,cx
  239.         jb      .exit_menu
  240.      
  241.         add     cx,m_size_y
  242.         cmp     ax,cx
  243.         ja      .exit_menu
  244.  
  245.         test    dword m_mouse_keys,1b
  246.         jnz     @f
  247.         cmp     dword m_select,1
  248.         je      .exit_menu_1
  249.         mov     dword m_select,1
  250.         call    .draw_1
  251.         jmp     .exit_menu_1
  252. @@:
  253.         cmp     dword m_get_mouse_flag,1
  254.         mov     m_get_mouse_flag,dword 0
  255.         je      @f
  256.        
  257.         mov     eax,m_mouse_keys
  258.         cmp     eax,m_mouse_keys_old
  259.         je      .exit_menu_1
  260. @@:
  261.         cmp     dword m_type,1
  262.         jne     .start_loop
  263.  
  264.         xor     eax,eax
  265.         inc     eax
  266.         mov     m_cursor_out,eax
  267.         mov     m_click,eax
  268.         menu_bar_exit
  269.  
  270. .start_loop:
  271.         mov     m_select,dword 1
  272.         call    .draw_1
  273.         call    .allocate_menu_area
  274.         call    .get_menu_area
  275.          
  276.         call    .draw_2
  277. .red:
  278.         call    .draw_3
  279. .still:
  280.         mcall   10
  281.         cmp     eax,1
  282.         je      .exit_menu_3
  283.         cmp     eax,2
  284.         je      .key_menu
  285.         cmp     eax,3
  286.         je      .exit_menu_3
  287.         cmp     eax,6
  288.         je      .mouse_menu
  289.         jmp     .still
  290.        
  291. .key_menu:
  292.         mcall   2
  293.  
  294.         cmp     dword m_extended_key,1
  295.         je      .extended_key
  296.         test    al,al
  297.         jnz     .key_menu_end
  298.         cmp     ah, 0xE0
  299.         jne     @f
  300.         mov     m_extended_key,dword 1
  301. .key_menu_end:
  302.         jmp     .still
  303. @@:
  304.         cmp     ah,72  ;Arrow Up
  305.         je      .menu_key_72_1
  306.         cmp     ah,80 ; Arrow Down
  307.         je      .menu_key_80_1
  308.         cmp     ah,28  ; Enter
  309.         je      .menu_key_28_1
  310.         cmp     ah,1  ; Esc
  311.         je      .menu_key_1_1
  312.         cmp     ah,75  ; L-Arrow down
  313.         je      .menu_key_75_1
  314.         cmp     ah,77  ; R-Arrow down
  315.         je      .menu_key_77_1
  316.        
  317. .key_menu_end_1:
  318.         cmp     ah,208 ; Arrow Down
  319.         je      .key_menu_end
  320.         cmp     ah,200 ; Arrow Up
  321.         je      .key_menu_end
  322.         cmp     ah,156 ; Enter
  323.         je      .key_menu_end
  324.         cmp     ah,129 ; Esc
  325.         je      .key_menu_end
  326.         cmp     ah,199  ;Home
  327.         je      .key_menu_end
  328.         cmp     ah,207  ;End
  329.         je      .key_menu_end
  330.         cmp     ah,201  ;Page UP
  331.         je      .key_menu_end
  332.         cmp     ah,209  ;Page Down
  333.         je      .key_menu_end
  334.         cmp     ah,42   ; NumLock ON
  335.         je      .key_menu_end
  336.         cmp     ah,170  ; NumLock ON
  337.         je      .key_menu_end
  338.         cmp     ah,210  ; Insert
  339.         je      .key_menu_end
  340.         cmp     ah,211  ; Delete
  341.         je      .key_menu_end
  342.         cmp     ah,157  ; Ctrl up
  343.         je      .key_menu_end
  344.         cmp     ah,184  ; Alt up
  345.         je      .key_menu_end
  346.         cmp     ah,170  ; L-Shift up
  347.         je      .key_menu_end
  348.         cmp     ah,182  ; R-Shift up
  349.         je      .key_menu_end
  350.         cmp     ah,203  ; L-Arrow up
  351.         je      .key_menu_end
  352.         cmp     ah,205  ; R-Arrow up
  353.         je      .key_menu_end
  354.  
  355.         jmp     .exit_menu_3
  356.  
  357. ;---------------------------------------------------------------------
  358. .extended_key:
  359.         mov     m_extended_key, dword 0
  360. .menu_key_80:
  361.         cmp     ah,80   ; arrow down
  362.         jne     .menu_key_72
  363. .menu_key_80_1:
  364.         mov     eax,m_cursor_max
  365.         dec     eax
  366.         cmp     eax,m_cursor
  367.         je      .still ;@f
  368.         mov     ebx,m_cursor
  369.         mov     m_cursor_old,ebx
  370.         inc     dword m_cursor
  371. ;@@:
  372.         jmp     .red
  373. ;---------------------------------------------------------------------
  374. .menu_key_72:
  375.         cmp     ah,72   ;arrow up
  376.         jne     .menu_key_71
  377. .menu_key_72_1:
  378.         cmp     m_cursor,dword 0
  379.         je      .still  ;@f
  380.         mov     ebx,m_cursor
  381.         mov     m_cursor_old,ebx
  382.         dec     dword m_cursor
  383. ;@@:
  384.         jmp     .red
  385. ;---------------------------------------------------------------------
  386. .menu_key_71:
  387.         cmp     ah,71    ;Home
  388.         je      @f
  389.         cmp     ah,73    ;PageUp
  390.         jne     .menu_key_79
  391. @@:
  392.         cmp     dword m_cursor,0
  393.         je      .still
  394.         mov     ebx,m_cursor
  395.         mov     m_cursor_old,ebx
  396.         mov     m_cursor,dword 0
  397.         jmp     .red
  398. ;---------------------------------------------------------------------
  399. .menu_key_79:
  400.         cmp     ah,79    ; End
  401.         je      @f
  402.         cmp     ah,81    ; PageDown
  403.         jne     .menu_key_1
  404. @@:
  405.         mov     ecx,m_cursor_max
  406.         dec     ecx
  407.         cmp     m_cursor,ecx
  408.         je      .still
  409.         mov     ebx,m_cursor
  410.         mov     m_cursor_old,ebx
  411.         mov     m_cursor,ecx
  412.         jmp     .red
  413. ;---------------------------------------------------------------------
  414. .menu_key_1:
  415.         cmp     ah,1 ; Esc
  416.         jne     .menu_key_28
  417. .menu_key_1_1:
  418.         jmp     .exit_menu_3
  419. ;---------------------------------------------------------------------
  420. .menu_key_28:
  421.         cmp     ah,28 ; Enter
  422.         jne     .menu_key_75
  423. .menu_key_28_1:
  424.         xor     eax,eax
  425.         mov     m_mouse_keys_old,eax
  426.         inc     eax
  427.         mov     m_mouse_keys,eax
  428.         jmp     .exit_menu_2
  429. ;---------------------------------------------------------------------
  430. .menu_key_75:
  431.         cmp     ah,75  ; L-Arrow down
  432.         jne     .menu_key_77
  433. .menu_key_75_1:
  434.         mov     m_ret_key,dword 1
  435.         jmp     .exit_menu_3
  436. ;---------------------------------------------------------------------
  437. .menu_key_77:
  438.         cmp     ah,77  ; R-Arrow down
  439.         jne     .key_menu_end_1
  440. .menu_key_77_1:
  441.         mov     m_ret_key,dword 2
  442.         jmp     .exit_menu_3
  443. ;---------------------------------------------------------------------
  444. .processing_real_mouse:
  445.         mcall   37,2
  446.         mov     ebx,m_mouse_keys
  447.         mov     m_mouse_keys_old,ebx
  448.         mov     m_mouse_keys,eax
  449.          
  450.         mcall 37,1
  451.         ret
  452. ;---------------------------------------------------------------------
  453. .allocate_menu_area:
  454.         call    .free_menu_area
  455.         movzx   ecx,word m_size_x1
  456.         movzx   eax,word m_size_y1
  457.         imul    ecx,eax
  458.         lea     ecx,[ecx*3]
  459.         mcall   68, 12
  460.         mov     m_buf_adress,eax
  461.         ret
  462. ;---------------------------------------------------------------------
  463. .free_menu_area:
  464.         cmp     dword m_buf_adress,0
  465.         je      @f
  466.         mcall   68,13,m_buf_adress
  467.         xor     eax,eax
  468.         mov     m_buf_adress,eax
  469. @@:
  470.         ret
  471. ;---------------------------------------------------------------------
  472. .get_menu_area:
  473.         mcall   9, m_procinfo,-1
  474.          
  475.         mov     cx,m_size_x1
  476.         shl     ecx,16
  477.         mov     cx,m_size_y1
  478.          
  479.         mov     dx,m_start_x1
  480.         mov     eax,m_procinfo
  481.         add     dx,[eax+34]
  482.         add     dx,[eax+54]
  483.         shl     edx,16
  484.         mov     dx,m_start_y1
  485.         add     dx,[eax+38]
  486.         add     dx,[eax+58]
  487.          
  488.         mcall   36, m_buf_adress
  489.         ret
  490. ;---------------------------------------------------------------------
  491. .put_menu_area:
  492.         mov     cx,m_size_x1
  493.         shl     ecx,16
  494.         mov     cx,m_size_y1
  495.          
  496.         mov     dx,m_start_x1
  497.         shl     edx,16
  498.         mov     dx,m_start_y1
  499.          
  500.         mcall   7, m_buf_adress
  501.         call    .free_menu_area
  502.         ret
  503. ;---------------------------------------------------------------------
  504. .mouse_menu:
  505.         call    .processing_real_mouse
  506.  
  507.         test    eax,0x80000000
  508.         jnz     .still
  509.         test    eax,0x8000
  510.         jnz     .still
  511.          
  512.         mov     ebx,eax
  513.         shr     ebx,16
  514.         shl     eax,16
  515.         shr     eax,16
  516.          
  517.         xor     ecx,ecx
  518.         mov     cx,m_start_y1
  519.         cmp     ax,cx
  520.         jbe     .close
  521.         add     cx,m_size_y1
  522.         cmp     ax,cx
  523.         jae     .close
  524.         mov     cx,m_start_x1
  525.         cmp     bx,cx
  526.         jbe     .close
  527.         add     cx,m_size_x1
  528.         cmp     bx,cx
  529.         jae     .close
  530.         sub     ax,m_start_y1
  531.         mov     ebx,m_interval
  532.         xor     edx,edx
  533.         div     ebx
  534.         mov     ebx,m_cursor
  535.         cmp     eax,ebx
  536.         je      .no_red
  537.         mov     m_cursor_old,ebx
  538.         cmp     eax,m_cursor_max
  539.         jb      @f
  540.         mov     eax,m_cursor_max
  541. @@:
  542.         mov     m_cursor,eax
  543.         test    m_mouse_keys,dword 1b
  544.         jz      .red
  545.         jmp     .exit_menu_2
  546. .no_red:
  547.         test    m_mouse_keys,dword 1b
  548.         jz      .still
  549.         jmp     .exit_menu_2
  550. .close:
  551.         test    m_mouse_keys,dword 1b
  552.         jz      .still
  553.         jmp     .exit_menu_3
  554.          
  555. .exit_menu:
  556.         cmp     dword m_select,0
  557.         je      .exit_menu_1
  558.         mov     m_select,dword 0
  559.          
  560.         call    .draw_1
  561.  
  562.         test    m_mouse_keys,dword 1b
  563.         jz      .exit_menu_1
  564.          
  565. .exit_menu_3:
  566.         mov     m_select,dword 0
  567.         call    .put_menu_area
  568.         xor     eax,eax
  569.         mov     m_cursor_out,eax
  570.         jmp     .exit
  571.        
  572. .exit_menu_2:
  573.         mov     m_select,dword 0
  574.         call    .put_menu_area
  575.         mov     edx,m_pos_pointer
  576.        
  577.         mov     ebx,m_cursor
  578. @@:
  579.         cmp     ebx,0
  580.         jz      @f
  581.         dec     ebx
  582.         call    .get_next_text
  583.         jmp     @r
  584.        
  585. @@:
  586.         mov     m_out_select,edx
  587.         mov     eax,m_cursor
  588.         inc     eax
  589.         mov     m_cursor_out,eax
  590.        
  591.         mov     eax,m_mouse_keys
  592.         cmp     eax,m_mouse_keys_old
  593.         jne     .exit
  594.         xor     eax,eax
  595.         mov     m_cursor_out,eax
  596. .exit:
  597.         call    .draw_1
  598.         mov     m_click,dword 1
  599.         jmp     @f
  600. .exit_menu_1:
  601.         mov     m_click,dword 0
  602. @@:
  603. menu_bar_exit
  604. }
  605.  
  606.