Subversion Repositories Kolibri OS

Rev

Rev 1049 | 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     m_select,dword 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     m_select,dword 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.         jmp     .active_text
  164. .no_active_text:
  165.         mov     ecx,m_bckg_text_col
  166. .active_text:
  167.         add     ecx,0x80000000
  168.         mcall   4
  169.         call    .get_next_text
  170.         inc     ebp
  171.         add     ebx,m_interval
  172.         jmp     @r
  173. .draw_end:
  174.         ret
  175.        
  176. .calc_m_cursor_max:
  177.         mov     edx,m_pos_pointer
  178.         mov     m_cursor_max,dword 0
  179. @@:
  180.         inc     dword m_cursor_max
  181.         call    .get_next_text
  182.         jmp     @r
  183. ;*****************************************************************************
  184. .get_next_text:
  185.         mov     esi,edx
  186. @@:
  187.         cmp     esi,m_text_end
  188.         je      .get_next_text_end
  189.         cld
  190.         lodsb
  191.         test    al,al
  192.         jnz     @r
  193.         mov     edx,esi
  194.         ret
  195. .get_next_text_end:
  196.         add     esp,4
  197.         ret
  198. ;*****************************************************************************
  199. ;*****************************************************************************
  200. ; mouse event
  201. ;*****************************************************************************
  202. ;*****************************************************************************
  203. .activate:
  204.         pusha
  205.         mov     edi,dword [esp+36]
  206.         jmp     .start_loop
  207. .mouse:
  208.         pusha
  209.         mov     edi,dword [esp+36]
  210.  
  211.         call    .processing_real_mouse
  212.  
  213.         test    eax,0x80000000
  214.         jnz     .exit_menu
  215.         test    eax,0x8000
  216.         jnz     .exit_menu
  217.  
  218.         mov     ebx,eax
  219.         shr     ebx,16   ; x position
  220.         shl     eax,16
  221.         shr     eax,16   ; y position
  222.          
  223.         mov     cx,m_start_x
  224.         cmp     bx,cx
  225.         jb      .exit_menu
  226.      
  227.         add     cx,m_size_x
  228.         dec     cx
  229.         cmp     bx,cx
  230.         ja      .exit_menu
  231.  
  232.         mov     cx,m_start_y
  233.         cmp     ax,cx
  234.         jb      .exit_menu
  235.      
  236.         add     cx,m_size_y
  237.         cmp     ax,cx
  238.         ja      .exit_menu
  239.  
  240.         test    m_mouse_keys,dword 1b
  241.         jnz     @f
  242.         cmp     m_select,dword 1
  243.         je      .exit_menu_1
  244.         mov     m_select,dword 1
  245.         call    .draw_1
  246.         jmp     .exit_menu_1
  247. @@:
  248.  
  249.         cmp     m_get_mouse_flag,dword 1
  250.         mov     m_get_mouse_flag,dword 0
  251.         je      @f
  252.        
  253.         mov     eax,m_mouse_keys
  254.         cmp     eax,m_mouse_keys_old
  255.         je      .exit_menu_1
  256. @@:
  257. .start_loop:
  258.         mov     m_select,dword 1
  259.         call    .draw_1
  260.         call    .allocate_menu_area
  261.         call    .get_menu_area
  262.          
  263.         call    .draw_2
  264. .red:
  265.         call    .draw_3
  266. .still:
  267.         mcall   10
  268.         cmp     eax,1
  269.         je      .exit_menu_3
  270.         cmp     eax,2
  271.         je      .key_menu
  272.         cmp     eax,3
  273.         je      .exit_menu_3
  274.         cmp     eax,6
  275.         je      .mouse_menu
  276.         jmp     .still
  277.        
  278. .key_menu:
  279.         mcall   2
  280.  
  281.         cmp     m_extended_key,dword 1
  282.         je      .extended_key
  283.         test    al,al
  284.         jnz     .key_menu_end
  285.         cmp     ah, 0xE0
  286.         jne     @f
  287.         mov     m_extended_key,dword 1
  288. .key_menu_end:
  289.         jmp     .still
  290. @@:
  291.         cmp     ah,72  ;Arrow Up
  292.         je      .menu_key_72_1
  293.         cmp     ah,80 ; Arrow Down
  294.         je      .menu_key_80_1
  295.         cmp     ah,28  ; Enter
  296.         je      .menu_key_28_1
  297.         cmp     ah,1  ; Esc
  298.         je      .menu_key_1_1
  299.         cmp     ah,75  ; L-Arrow down
  300.         je      .menu_key_75_1
  301.         cmp     ah,77  ; R-Arrow down
  302.         je      .menu_key_77_1
  303.        
  304. .key_menu_end_1:
  305.         cmp     ah,208 ; Arrow Down
  306.         je      .key_menu_end
  307.         cmp     ah,200 ; Arrow Up
  308.         je      .key_menu_end
  309.         cmp     ah,156 ; Enter
  310.         je      .key_menu_end
  311.         cmp     ah,129 ; Esc
  312.         je      .key_menu_end
  313.         cmp     ah,199  ;Home
  314.         je      .key_menu_end
  315.         cmp     ah,207  ;End
  316.         je      .key_menu_end
  317.         cmp     ah,201  ;Page UP
  318.         je      .key_menu_end
  319.         cmp     ah,209  ;Page Down
  320.         je      .key_menu_end
  321.         cmp     ah,42   ; NumLock ON
  322.         je      .key_menu_end
  323.         cmp     ah,170  ; NumLock ON
  324.         je      .key_menu_end
  325.         cmp     ah,210  ; Insert
  326.         je      .key_menu_end
  327.         cmp     ah,211  ; Delete
  328.         je      .key_menu_end
  329.         cmp     ah,157  ; Ctrl up
  330.         je      .key_menu_end
  331.         cmp     ah,184  ; Alt up
  332.         je      .key_menu_end
  333.         cmp     ah,170  ; L-Shift up
  334.         je      .key_menu_end
  335.         cmp     ah,182  ; R-Shift up
  336.         je      .key_menu_end
  337.         cmp     ah,203  ; L-Arrow up
  338.         je      .key_menu_end
  339.         cmp     ah,205  ; R-Arrow up
  340.         je      .key_menu_end
  341.  
  342.         jmp     .exit_menu_3
  343.  
  344. ;---------------------------------------------------------------------
  345. .extended_key:
  346.         mov     m_extended_key, dword 0
  347. .menu_key_80:
  348.         cmp     ah,80   ; arrow down
  349.         jne     .menu_key_72
  350. .menu_key_80_1:
  351.         mov     eax,m_cursor_max
  352.         dec     eax
  353.         cmp     eax,m_cursor
  354.         je      .still ;@f
  355.         mov     ebx,m_cursor
  356.         mov     m_cursor_old,ebx
  357.         inc     dword m_cursor
  358. ;@@:
  359.         jmp     .red
  360. ;---------------------------------------------------------------------
  361. .menu_key_72:
  362.         cmp     ah,72   ;arrow up
  363.         jne     .menu_key_71
  364. .menu_key_72_1:
  365.         cmp     m_cursor,dword 0
  366.         je      .still  ;@f
  367.         mov     ebx,m_cursor
  368.         mov     m_cursor_old,ebx
  369.         dec     dword m_cursor
  370. ;@@:
  371.         jmp     .red
  372. ;---------------------------------------------------------------------
  373. .menu_key_71:
  374.         cmp     ah,71    ;Home
  375.         je      @f
  376.         cmp     ah,73    ;PageUp
  377.         jne     .menu_key_79
  378. @@:
  379.         cmp     m_cursor,dword 0
  380.         je      .still
  381.         mov     ebx,m_cursor
  382.         mov     m_cursor_old,ebx
  383.         mov     m_cursor,dword 0
  384.         jmp     .red
  385. ;---------------------------------------------------------------------
  386. .menu_key_79:
  387.         cmp     ah,79    ; End
  388.         je      @f
  389.         cmp     ah,81    ; PageDown
  390.         jne     .menu_key_1
  391. @@:
  392.         mov     ecx,m_cursor_max
  393.         dec     ecx
  394.         cmp     m_cursor,ecx
  395.         je      .still
  396.         mov     ebx,m_cursor
  397.         mov     m_cursor_old,ebx
  398.         mov     m_cursor,ecx
  399.         jmp     .red
  400. ;---------------------------------------------------------------------
  401. .menu_key_1:
  402.         cmp     ah,1 ; Esc
  403.         jne     .menu_key_28
  404. .menu_key_1_1:
  405.         jmp     .exit_menu_3
  406. ;---------------------------------------------------------------------
  407. .menu_key_28:
  408.         cmp     ah,28 ; Enter
  409.         jne     .menu_key_75
  410. .menu_key_28_1:
  411.         xor     eax,eax
  412.         mov     m_mouse_keys_old,eax
  413.         inc     eax
  414.         mov     m_mouse_keys,eax
  415.         jmp     .exit_menu_2
  416. ;---------------------------------------------------------------------
  417. .menu_key_75:
  418.         cmp     ah,75  ; L-Arrow down
  419.         jne     .menu_key_77
  420. .menu_key_75_1:
  421.         mov     m_ret_key,dword 1
  422.         jmp     .exit_menu_3
  423. ;---------------------------------------------------------------------
  424. .menu_key_77:
  425.         cmp     ah,77  ; R-Arrow down
  426.         jne     .key_menu_end_1
  427. .menu_key_77_1:
  428.         mov     m_ret_key,dword 2
  429.         jmp     .exit_menu_3
  430. ;---------------------------------------------------------------------
  431. .processing_real_mouse:
  432.         mcall   37,2
  433.         mov     ebx,m_mouse_keys
  434.         mov     m_mouse_keys_old,ebx
  435.         mov     m_mouse_keys,eax
  436.          
  437.         mcall 37,1
  438.         ret
  439. ;---------------------------------------------------------------------
  440. .allocate_menu_area:
  441.         cmp     m_buf_adress,dword 0
  442.         je      @f
  443.         call    .free_menu_area
  444. @@:
  445.         movzx   ecx,word m_size_x1
  446.         movzx   eax,word m_size_y1
  447.         imul    ecx,eax
  448.         lea     ecx,[ecx*3]
  449.         mcall   68, 12
  450.         mov     m_buf_adress,eax
  451.         ret
  452. ;---------------------------------------------------------------------
  453. .free_menu_area:
  454.         mcall   68,13,m_buf_adress
  455.         xor     eax,eax
  456.         mov     m_buf_adress,eax
  457.         ret
  458. ;---------------------------------------------------------------------
  459. .get_menu_area:
  460.         mcall   9, m_procinfo,-1
  461.          
  462.         mov     cx,m_size_x1
  463.         shl     ecx,16
  464.         mov     cx,m_size_y1
  465.          
  466.         mov     dx,m_start_x1
  467.         mov     eax,m_procinfo
  468.         add     dx,[eax+34]
  469.         add     dx,[eax+54]
  470.         shl     edx,16
  471.         mov     dx,m_start_y1
  472.         add     dx,[eax+38]
  473.         add     dx,[eax+58]
  474.          
  475.         mcall   36, m_buf_adress
  476.         ret
  477. ;---------------------------------------------------------------------
  478. .put_menu_area:
  479.         mov     cx,m_size_x1
  480.         shl     ecx,16
  481.         mov     cx,m_size_y1
  482.          
  483.         mov     dx,m_start_x1
  484.         shl     edx,16
  485.         mov     dx,m_start_y1
  486.          
  487.         mcall   7, m_buf_adress
  488.         ret
  489. ;---------------------------------------------------------------------
  490. .mouse_menu:
  491.         call    .processing_real_mouse
  492.  
  493.         test    eax,0x80000000
  494.         jnz     .still
  495.         test    eax,0x8000
  496.         jnz     .still
  497.          
  498.         mov     ebx,eax
  499.         shr     ebx,16
  500.         shl     eax,16
  501.         shr     eax,16
  502.          
  503.         xor     ecx,ecx
  504.         mov     cx,m_start_y1
  505.         cmp     ax,cx
  506.         jbe     .close
  507.         add     cx,m_size_y1
  508.         cmp     ax,cx
  509.         jae     .close
  510.         mov     cx,m_start_x1
  511.         cmp     bx,cx
  512.         jbe     .close
  513.         add     cx,m_size_x1
  514.         cmp     bx,cx
  515.         jae     .close
  516.         sub     ax,m_start_y1
  517.         mov     ebx,m_interval
  518.         xor     edx,edx
  519.         div     ebx
  520.         mov     ebx,m_cursor
  521.         cmp     eax,ebx
  522.         je      .no_red
  523.         mov     m_cursor_old,ebx
  524.         cmp     eax,m_cursor_max
  525.         jb      @f
  526.         mov     eax,m_cursor_max
  527. @@:
  528.         mov     m_cursor,eax
  529.         test    m_mouse_keys,dword 1b
  530.         jz      .red
  531.         jmp     .exit_menu_2
  532. .no_red:
  533.         test    m_mouse_keys,dword 1b
  534.         jz      .still
  535.         jmp     .exit_menu_2
  536. .close:
  537.         test    m_mouse_keys,dword 1b
  538.         jz      .still
  539.         jmp     .exit_menu_3
  540.          
  541. .exit_menu:
  542.         cmp     m_select,dword 0
  543.         je      .exit_menu_1
  544.         mov     m_select,dword 0
  545.          
  546.         call    .draw_1
  547.  
  548.         test    m_mouse_keys,dword 1b
  549.         jz      .exit_menu_1
  550.          
  551. .exit_menu_3:
  552.         mov     m_select,dword 0
  553.         call    .put_menu_area
  554.         xor     eax,eax
  555.         mov     m_cursor_out,eax
  556.         jmp     .exit
  557.        
  558. .exit_menu_2:
  559.         mov     m_select,dword 0
  560.         call    .put_menu_area
  561.         mov     edx,m_pos_pointer
  562.        
  563.         mov     ebx,m_cursor
  564. @@:
  565.         cmp     ebx,0
  566.         jz      @f
  567.         dec     ebx
  568.         call    .get_next_text
  569.         jmp     @r
  570.        
  571. @@:
  572.         mov     m_out_select,edx
  573.         mov     eax,m_cursor
  574.         inc     eax
  575.         mov     m_cursor_out,eax
  576.        
  577.         mov     eax,m_mouse_keys
  578.         cmp     eax,m_mouse_keys_old
  579.         jne     .exit
  580.         xor     eax,eax
  581.         mov     m_cursor_out,eax
  582. .exit:
  583.         call    .draw_1
  584.         mov     m_click,dword 1
  585.         jmp     @f
  586. .exit_menu_1:
  587.         mov     m_click,dword 0
  588. @@:
  589. menu_bar_exit
  590. }
  591.  
  592.