Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;
  2. ; Example for Box_lib: scrollbar, menubar, dinamic_button
  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. ; import_boxlib procedure written by <Lrz>
  29. ;---------------------------------------------------------------------
  30.  
  31.         use32
  32.         org     0x0
  33.  
  34.         db      'MENUET01'
  35.         dd      0x01
  36.         dd      START
  37.         dd      IM_END
  38.         dd      I_END
  39.         dd      stacktop
  40.         dd      0x0
  41.         dd      path
  42.  
  43. include 'MACROS.INC'
  44. ;---------------------------------------------------------------------
  45. ;---    Start of program        ----------------------------------------------
  46. ;---------------------------------------------------------------------
  47.  
  48. START:
  49.         mcall 68, 11
  50.         mcall 66, 1, 1
  51.         mcall 40, 0x27
  52. ;--------------------------------------------------------------------- 
  53. ; Procinfo area for function 9 in MenuBar
  54.         mcall   68,12,1024
  55.         mov     [menu_data_1.procinfo],eax
  56.         mov     [menu_data_2.procinfo],eax
  57. ;--------------------------------------------------------------------- 
  58. ; loading Box_Lib library
  59.         mov     ebx,boxlib_name
  60.         mov     esi,path
  61.         mov     edi,file_name
  62.         call    copy_path
  63.  
  64.         mcall 68,19,file_name ; load of alternative
  65.         test    eax,eax
  66.         jnz @f
  67.        
  68.         mcall 68,19,system_dir ; load of sys directory
  69.         test    eax,eax
  70.         jz      button.exit
  71. @@:
  72.         call    import_boxlib
  73. ;---------------------------------------------------------------------
  74. ; Load and convert BMP file for DinamicButton
  75. ; This procedures use cnv_bmp.obj and this module used only for
  76. ; demonstration of use DinamicButton
  77. ;
  78.  
  79.         mov     ebx,plugin_BMP_name
  80.         mov     esi,path
  81.         mov     edi,file_name
  82.         call    copy_path
  83.  
  84.         mcall 68,19,file_name
  85.         test    eax,eax
  86.         jz  button.exit
  87.        
  88.         mov     eax,[eax+4]
  89.         mov     [plugin],eax
  90.        
  91.         mov     ebx,icons_file_name
  92.         mov     esi,path
  93.         mov     edi,file_name
  94.         call    copy_path
  95.        
  96.         mcall 70, fileinfo
  97.  
  98.         mov     [fileinfo+0],dword 0
  99.  
  100.         mov     ecx,[file_info+32]
  101.         mov     [fileinfo+12],ecx
  102.         mov [img_size],ecx
  103.        
  104.  
  105.         mcall 68, 12
  106.  
  107.  
  108.         mov     [fileinfo+16],eax
  109.         mov     [image_file],eax
  110.  
  111.  
  112.         mcall 70, fileinfo
  113.        
  114.         xor     eax,eax
  115.         mov     [return_code],eax
  116.         mov     eax,image_file
  117.         call    [plugin]
  118.        
  119.         mov     ecx,[image_file]
  120.         mcall 68, 13,
  121.        
  122.         cmp     [return_code],dword 0
  123.         jne     button.exit
  124.        
  125.         mov     ebx,[raw_pointer]
  126.         mov     eax,[ebx+4]
  127.         ; set of button size
  128.         mov     [dinamic_button_data_1.size_x],ax
  129.         mov     [dinamic_button_data_1.size_y],ax
  130.         mov     [dinamic_button_data_2.size_x],ax
  131.         mov     [dinamic_button_data_2.size_y],ax
  132.         mov     eax,[ebx+12]
  133.         ; set of RAW resolution to pixel
  134.         mov     [dinamic_button_data_1.resolution_raw],eax
  135.         mov     [dinamic_button_data_2.resolution_raw],eax
  136.         mov     eax,[ebx+20]
  137.         add     eax,ebx
  138.         ; set RAW palette, use else resolution 8bit or less
  139.         mov     [dinamic_button_data_1.palette_raw],eax
  140.         mov     [dinamic_button_data_2.palette_raw],eax
  141.         mov     eax,[ebx+28]
  142.         add     eax,ebx
  143.         ; set RAW area for passive button
  144.         mov     [dinamic_button_data_1.passive_raw],eax
  145.         mov     [dinamic_button_data_2.passive_raw],eax
  146.         mov     ecx,[ebx+4]
  147.         imul ecx,[ebx+4]
  148.         imul ecx,[ebx+12]
  149.         shr     ecx,3
  150.         add     eax,ecx
  151.         ; set  RAW area for active button
  152.         mov     [dinamic_button_data_1.active_raw],eax
  153.         mov     [dinamic_button_data_2.active_raw],eax
  154.         add     eax,ecx
  155.         ; RAW area for click button
  156.         mov     [dinamic_button_data_1.click_raw],eax
  157.         mov     [dinamic_button_data_2.click_raw],eax
  158. ;--------------------------------------------------------------------- 
  159. red:
  160.         call draw_window
  161. still:
  162.         mcall 10
  163.  
  164.         cmp     eax,1
  165.         je      red
  166.         cmp     eax,2
  167.         je      key
  168.         cmp     eax,3
  169.         je      button
  170.         cmp     eax,6
  171.         je      mouse
  172.         jmp     still
  173.  
  174.  
  175. ;---------------------------------------------------------------------
  176.         key:
  177.         mcall 2
  178.         jmp     still
  179. ;---------------------------------------------------------------------
  180.         button:
  181.         mcall 17
  182.         cmp     ah, 1
  183.         jne     still
  184.         .exit:
  185.         mcall -1
  186. ;---------------------------------------------------------------------
  187. mouse:
  188. ;-----------------------------------------------
  189.         cmp     [scroll_bar_data_horizontal.delta2],0
  190.         jne     .horizontal
  191. .vertical:
  192.     mov   eax,[scroll_bar_data_vertical.max_area]
  193.     cmp   eax,[scroll_bar_data_vertical.cur_area]
  194.     jbe   .horizontal
  195. ; mouse event for Vertical ScrollBar
  196.         push dword scroll_bar_data_vertical
  197.         call [scrollbar_ver_mouse]
  198.         mov  eax,scroll_bar_data_vertical.redraw
  199.         xor  ebx,ebx
  200.         cmp     [eax],ebx
  201.         je      @f
  202.         mov     [eax],ebx
  203.         jmp     .draw_cube
  204. @@:
  205.         cmp     [scroll_bar_data_vertical.delta2],0
  206.         jne     still
  207. .horizontal:
  208.     mov   eax,[scroll_bar_data_horizontal.max_area]
  209.     cmp   eax,[scroll_bar_data_horizontal.cur_area]
  210.     jbe   .other
  211. ; mouse event for Horizontal ScrollBar
  212.         push dword scroll_bar_data_horizontal
  213.         call [scrollbar_hor_mouse]
  214.         mov  eax,scroll_bar_data_horizontal.redraw
  215.         xor  ebx,ebx
  216.         cmp     [eax],ebx      
  217.         je      .other
  218.         mov     [eax],ebx
  219. .draw_cube:
  220.         call draw_cube
  221.         jmp     still
  222. .other:
  223.         cmp  [scroll_bar_data_vertical.delta2],0
  224.         jne   still
  225.         cmp  [scroll_bar_data_horizontal.delta2],0
  226.         jne   still
  227. ;-----------------------------------------------
  228. .menu_bar_1:
  229.         call   .set_mouse_flag
  230. @@:
  231. ; mouse event for Menu 1
  232.         push    dword menu_data_1
  233.         call    [menu_bar_mouse]
  234.     cmp   [menu_data_1.click],dword 1
  235.         jne   .menu_bar_2
  236.         cmp   [menu_data_1.cursor_out],dword 0
  237.         jne    analyse_out_menu_1
  238.         jmp    .menu_bar_1
  239. ;--------------------------------------------
  240. .menu_bar_2:
  241. ; mouse event for Menu 2
  242.         push    dword menu_data_2
  243.         call    [menu_bar_mouse]
  244.     cmp   [menu_data_2.click],dword 1
  245.         jne   .mouse_dinamic_button
  246.         cmp   [menu_data_2.cursor_out],dword 0
  247.         jne    analyse_out_menu_2
  248.     jmp    .menu_bar_1
  249. ;--------------------------------------------
  250. .mouse_dinamic_button:
  251. ; mouse event for Dinamic Button 1
  252.         push    dword dinamic_button_data_1
  253.         call    [dinamic_button_mouse]
  254.         mov   eax,dinamic_button_data_1.click
  255.     cmp   [eax],dword 1
  256.         jne   @f
  257.     mov   [eax],dword 0
  258.         jmp   about
  259. @@:
  260. ; mouse event for Dinamic Button 2
  261.         push    dword dinamic_button_data_2
  262.         call    [dinamic_button_mouse]
  263.         mov   eax,dinamic_button_data_2.click
  264.     cmp   [eax],dword 1
  265.         jne   still  ;@f
  266.     mov   [eax],dword 0
  267.         jmp   button.exit
  268. ;---------------------------------------------------------------------
  269. .set_mouse_flag:       
  270.         xor   eax,eax
  271.         inc   eax
  272.         mov   [menu_data_1.get_mouse_flag],eax
  273.         mov   [menu_data_2.get_mouse_flag],eax
  274.         ret
  275. ;---------------------------------------------------------------------
  276. analyse_out_menu_1:
  277. ; analyse result of Menu 1
  278.         cmp [menu_data_1.cursor_out],dword 3
  279.         je      button.exit    
  280.         jmp     still
  281.        
  282. analyse_out_menu_2:
  283. ; analyse result of Menu 2
  284.         cmp [menu_data_2.cursor_out],dword 2
  285.         je      about
  286.         jmp     still
  287. ;---------------------------------------------------------------------
  288.         about:
  289.         mcall 51,1,thread3,thread
  290.         jmp     still
  291. ;---------------------------------------------------------------------
  292. draw_window:
  293.         mcall 12, 1
  294.         mcall 0, <0,400>, <0,400>, 0x03AABBCC, 0x805080D0, 0x005080D0
  295.         mcall 71, 1, header_1
  296. ;---------------------------------------------
  297. ; draw for Menu 1
  298.         push    dword menu_data_1
  299.         call    [menu_bar_draw]
  300. ; draw for Menu 2
  301.         push    dword menu_data_2
  302.         call    [menu_bar_draw]
  303. ;---------------------------------------------
  304. ; draw for Dinamic Button 1
  305.         push    dword dinamic_button_data_1
  306.         call    [dinamic_button_draw]
  307. ; draw for Dinamic Button 2
  308.         push    dword dinamic_button_data_2
  309.         call    [dinamic_button_draw]
  310. ;---------------------------------------------
  311. ; set all_redraw flag for draw all ScrollBar
  312. ; In some cases it is necessity to draw only the area
  313. ; of moving of a "runner", for acceleration of output -
  314. ; in this case the flag needs to be reset to 0 (zero).
  315.         xor     eax,eax
  316.         inc     eax
  317.         mov     [scroll_bar_data_vertical.all_redraw],eax
  318.         mov     [scroll_bar_data_horizontal.all_redraw],eax
  319.        
  320. ; draw for Vertical ScrollBar
  321.         push     dword scroll_bar_data_vertical
  322.         call     [scrollbar_ver_draw]
  323. ; draw for Horizontal ScrollBar
  324.         push     dword scroll_bar_data_horizontal
  325.         call     [scrollbar_hor_draw]
  326. ; reset all_redraw flag
  327.         xor     eax,eax
  328.         mov     [scroll_bar_data_vertical.all_redraw],eax
  329.         mov     [scroll_bar_data_horizontal.all_redraw],eax
  330. ;---------------------------------------------
  331.         call draw_cube
  332.         mcall 12, 2
  333.         ret
  334. ;---------------------------------------------------------------------
  335. draw_cube:
  336.         mcall 13,<30,301>,<50,301>,0xafafaf
  337.         mov     ecx,[scroll_bar_data_vertical.position]
  338.         add     ecx,50
  339.         shl     ecx,16
  340.         mov     cx,30
  341.         mov     ebx,[scroll_bar_data_horizontal.position]
  342.         add     ebx,30
  343.         shl     ebx,16
  344.         mov     bx,30
  345.         mcall 13, , , 0x0
  346.         ret
  347. ;---------------------------------------------------------------------
  348. copy_path:
  349.         xor     eax,eax
  350. @@:
  351.         cld
  352.         lodsb
  353.         stosb
  354.         test    eax,eax
  355.         jnz     @b
  356.         mov     esi,edi
  357. @@:
  358.         std
  359.         lodsb
  360.         cmp     al,'/'
  361.         jnz     @b
  362.         mov     edi,esi
  363.         add     edi,2
  364.         mov     esi,ebx
  365. @@:
  366.         cld
  367.         lodsb
  368.         stosb
  369.         test    eax,eax
  370.         jnz     @b
  371.         ret
  372. ;---------------------------------------------------------------------
  373. ; Import procedure written by <Lrz>
  374. ; Copyright (c) 2008, 2009,  <Lrz>
  375. ; All rights reserved.
  376. ; importing Box_lib entry
  377.  
  378. import_boxlib:
  379. ; initialize import
  380.         mov             edx, eax
  381.         mov             esi,myimport
  382. .import_loop:
  383.         lodsd
  384.         test     eax, eax
  385.         jz              .import_done
  386.         push     edx
  387. .import_find:
  388.         mov             ebx, [edx]
  389.         test     ebx, ebx
  390.         jz              .exit   ;import_not_found
  391.         push     eax
  392. @@:
  393.         mov             cl, [eax]
  394.         cmp             cl, [ebx]
  395.         jnz             .import_find_next
  396.         test     cl, cl
  397.         jz              .import_found
  398.         inc             eax
  399.         inc             ebx
  400.         jmp             @b
  401. .import_find_next:
  402.         pop             eax
  403.         add             edx, 8
  404.         jmp             .import_find
  405. .import_found:
  406.         pop             eax
  407.         mov             eax, [edx+4]
  408.         mov             [esi-4], eax
  409.         pop             edx
  410.         jmp             .import_loop
  411. .import_done:
  412.         ret
  413. .exit:
  414.         add     esp,4
  415.         jmp      button.exit
  416. ;---------------------------------------------------------------------
  417. include 'data.inc'
  418. include 'w_about.inc'
  419. IM_END:
  420.         rb 1024
  421. thread:
  422.         rb 1024
  423. stacktop:
  424. path:
  425.         rb      4096
  426. file_name:
  427.         rb 4096
  428. file_info:
  429.         rb 40
  430. I_END:
  431.  
  432.