Subversion Repositories Kolibri OS

Rev

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