Subversion Repositories Kolibri OS

Rev

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

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