Subversion Repositories Kolibri OS

Rev

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

  1. ;**************************************************************
  2. ; ScrollBar 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 scroll_bar_exit
  29. {
  30. popa
  31. ret 4
  32. }
  33. ;*****************************************************************************
  34. macro draw_up_arrow_vertical
  35. {
  36.         push  ebx
  37.        
  38.         xor   eax,eax
  39.         mov   ax,sb_size_x
  40.         shr   eax,1
  41.         shl   eax,16
  42.         add   ebx,eax
  43.        
  44.         xor   eax,eax
  45.         mov   ax,sb_btn_high
  46.         shr   eax,1
  47.         shl   eax,16
  48.         add   ecx,eax
  49.        
  50.         mov   edx,sb_line_col
  51.         sub   ebx,4 shl 16
  52.         mov   bx,7
  53.         mov   cx,1
  54.         mov   eax,13
  55.         int   0x40
  56.         sub   ecx,1 shl 16
  57.         add   ebx,1 shl 16
  58.         mov   bx,5
  59.         int   0x40
  60.         sub   ecx,1 shl 16
  61.         add   ebx,1 shl 16
  62.         mov   bx,3
  63.         int   0x40
  64.         sub   ecx,1 shl 16
  65.         add   ebx,1 shl 16
  66.         mov   bx,1
  67.         int   0x40
  68.         pop   ebx
  69. }
  70. ;*****************************************************************************
  71. macro draw_down_arrow_vertical
  72. {
  73.         push  ebx
  74.        
  75.         xor   eax,eax
  76.         mov   ax,sb_size_x
  77.         shr   eax,1
  78.         shl   eax,16
  79.         add   ebx,eax
  80.        
  81.         xor   eax,eax
  82.         mov   ax,sb_btn_high
  83.         shr   eax,1
  84.         shl   eax,16
  85.         add   ecx,eax
  86.        
  87.         mov   edx,sb_line_col
  88.         sub   ebx,4 shl 16
  89.         mov   bx,7
  90.         sub   ecx,2 shl 16
  91.         mov   cx,1
  92.         mov   eax,13
  93.         int   0x40
  94.         add   ecx,1 shl 16
  95.         add   ebx,1 shl 16
  96.         mov   bx,5
  97.         int   0x40
  98.         add   ecx,1 shl 16
  99.         add   ebx,1 shl 16
  100.         mov   bx,3
  101.         int   0x40
  102.         add   ecx,1 shl 16
  103.         add   ebx,1 shl 16
  104.         mov   bx,1
  105.         int   0x40
  106.         pop   ebx
  107. }
  108. ;*****************************************************************************
  109. macro draw_runner_center_vertical
  110. {
  111.         push  ebx
  112.         push  ecx
  113.        
  114.         xor   eax,eax
  115.         mov   ax,sb_size_x
  116.         shr   eax,1
  117.         shl   eax,16
  118.         add   ebx,eax
  119.        
  120.         mov   edx,sb_run_size
  121.         shr   edx,1
  122.         shl   edx,16
  123.         add   ecx,edx
  124.         mov   edx,sb_line_col
  125.         sub   ecx,8 shl 16
  126.         sub   ebx,5 shl 16
  127.         mov   bx,10
  128.         add   ecx,4 shl 16
  129.         mov   cx,1
  130.         mov   eax,13
  131.         int   0x40
  132.         add   ecx,3 shl 16
  133.         sub   ebx,1 shl 16
  134.         mov   bx,12
  135.         int   0x40
  136.         add   ebx,1 shl 16
  137.         mov   bx,10
  138.         add   ecx,3 shl 16
  139.         int   0x40
  140.         pop   ecx
  141.         pop   ebx
  142. }
  143. ;*****************************************************************************
  144. macro draw_up_arrow_horizontal
  145. {
  146.         push  ecx
  147.        
  148.         xor   eax,eax
  149.         mov   ax,sb_btn_high
  150.         shr   eax,1
  151.         shl   eax,16
  152.         add   ebx,eax
  153.        
  154.         xor   eax,eax
  155.         mov   ax,sb_size_y
  156.         shr   eax,1
  157.         shl   eax,16
  158.         add   ecx,eax
  159.        
  160.         mov   edx,sb_line_col
  161.         sub   ecx,4 shl 16
  162.         mov   cx,7
  163.         mov   bx,1
  164.        
  165.         mov   eax,13
  166.         int   0x40
  167.         sub   ebx,1 shl 16
  168.         add   ecx,1 shl 16
  169.         mov   cx,5
  170.         int   0x40
  171.         sub   ebx,1 shl 16
  172.         add   ecx,1 shl 16
  173.         mov   cx,3
  174.         int   0x40
  175.         sub   ebx,1 shl 16
  176.         add   ecx,1 shl 16
  177.         mov   cx,1
  178.         int   0x40
  179.         pop   ecx
  180. }
  181. ;*****************************************************************************
  182. macro draw_down_arrow_horizontal
  183. {
  184.         push  ecx
  185.        
  186.         xor   eax,eax
  187.         mov   ax,sb_btn_high
  188.         shr   eax,1
  189.         shl   eax,16
  190.         add   ebx,eax
  191.        
  192.         xor   eax,eax
  193.         mov   ax,sb_size_y
  194.         shr   eax,1
  195.         shl   eax,16
  196.         add   ecx,eax
  197.        
  198.         mov   edx,sb_line_col
  199.         sub   ecx,4 shl 16
  200.         mov   cx,7
  201.         sub   ebx,2 shl 16
  202.         mov   bx,1
  203.         mov   eax,13
  204.         int   0x40
  205.         add   ebx,1 shl 16
  206.         add   ecx,1 shl 16
  207.         mov   cx,5
  208.         int   0x40
  209.         add   ebx,1 shl 16
  210.         add   ecx,1 shl 16
  211.         mov   cx,3
  212.         int   0x40
  213.         add   ecx,1 shl 16
  214.         add   ebx,1 shl 16
  215.         mov   cx,1
  216.         int   0x40
  217.         pop   ecx
  218. }
  219. ;*****************************************************************************
  220. macro draw_runner_center_horizontal
  221. {
  222.         push  ebx
  223.         push  ecx
  224.        
  225.         xor   eax,eax
  226.         mov   ax,sb_size_y
  227.         shr   eax,1
  228.         shl   eax,16
  229.         add   ecx,eax
  230.        
  231.         mov   edx,sb_run_size
  232.         shr   edx,1
  233.         shl   edx,16
  234.         add   ebx,edx
  235.         mov   edx,sb_line_col
  236.         sub   ebx,8 shl 16
  237.         sub   ecx,5 shl 16
  238.         mov   cx,10
  239.         add   ebx,4 shl 16
  240.         mov   bx,1
  241.         mov   eax,13
  242.         int   0x40
  243.         add   ebx,3 shl 16
  244.         sub   ecx,1 shl 16
  245.         mov   cx,12
  246.         int   0x40
  247.         add   ecx,1 shl 16
  248.         mov   cx,10
  249.         add   ebx,3 shl 16
  250.         int   0x40
  251.         pop   ecx
  252.         pop   ebx
  253. }
  254. ;*****************************************************************************
  255. macro use_scroll_bar
  256. {
  257. scroll_bar:
  258. sb_size_x               equ [edi]
  259. sb_start_x              equ [edi+2]
  260. sb_size_y               equ [edi+4]
  261. sb_start_y              equ [edi+6]
  262. sb_btn_high             equ [edi+8]
  263. sb_type                 equ [edi+12]
  264. sb_max_area             equ [edi+16]
  265. sb_cur_area             equ [edi+20]
  266. sb_position             equ [edi+24]
  267. sb_bckg_col             equ [edi+28]
  268. sb_frnt_col             equ [edi+32]
  269. sb_line_col             equ [edi+36]
  270. sb_redraw               equ [edi+40]
  271. sb_delta                equ [edi+44]
  272. sb_delta2               equ [edi+46]
  273. sb_r_size_x             equ [edi+48]
  274. sb_r_start_x    equ [edi+50]
  275. sb_r_size_y             equ [edi+52]
  276. sb_r_start_y    equ [edi+54]
  277. sb_m_pos                equ [edi+56]
  278. sb_m_pos_2              equ [edi+60]
  279. sb_m_keys               equ [edi+64]
  280. sb_run_size             equ [edi+68]
  281. sb_position2    equ [edi+72]
  282. sb_work_size    equ [edi+76]
  283. sb_all_redraw   equ [edi+80]
  284. sb_ar_offset    equ [edi+84]
  285. }
  286. ;*****************************************************************************
  287. ;*****************************************************************************
  288. ; draw event
  289. ;*****************************************************************************
  290. ;*****************************************************************************
  291. macro use_scroll_bar_vertical
  292. {
  293. scroll_bar_vertical:
  294. .draw:
  295.         pusha
  296.         mov   edi,dword [esp+36]
  297. ;       mov   sb_all_redraw,dword 1
  298.         mov   sb_delta,word 0
  299.         call  .draw_1
  300.         mov   sb_all_redraw,dword 0
  301. scroll_bar_exit
  302. .draw_1:
  303.         pusha
  304. ;*********************************
  305.         xor   eax,eax
  306.         mov   ax,sb_size_y
  307.         mov   edx,sb_btn_high
  308.         shl   edx,1
  309.         sub   eax,edx
  310.         mov   sb_work_size,eax
  311. ;*********************************
  312.         mov   eax,sb_work_size   ;sb_max_area
  313.         mov   ebx,sb_max_area
  314.         cmp   ebx,sb_cur_area
  315.         ja      @f
  316.  
  317.         jmp   .no_size
  318.  
  319. @@:
  320.         imul  eax,sb_cur_area
  321.         xor   edx,edx
  322.         div   ebx
  323.         cmp   eax,10
  324.         jae   @f
  325.         mov   eax,10
  326. @@:
  327. .no_size:
  328.         mov   sb_run_size,eax
  329. ;*********************************
  330.         cmp   sb_delta,word 1
  331.         je      .@@_3
  332.         mov   eax,sb_work_size
  333.         sub   eax,sb_run_size
  334.         mov   ebx,sb_max_area
  335.         cmp   ebx,sb_cur_area
  336.         ja      @f
  337.         xor   eax,eax
  338.         jmp   .@@_1
  339. @@:
  340.         sub   ebx,sb_cur_area
  341.         imul  eax,sb_position
  342.         xor   edx,edx
  343.         div   ebx
  344. .@@_1:
  345.         mov   sb_position2,eax
  346.         xor   edx,edx
  347.         mov   dx,sb_size_y
  348.         sub   edx,sb_btn_high
  349.         sub   edx,sb_btn_high
  350.         sub   edx,sb_run_size
  351.         cmp   sb_position2,edx
  352.         jbe   .@@_3
  353.         mov   sb_position2,edx
  354. .@@_3:
  355. ;*********************************     
  356.         mov   ebx,sb_start_x
  357.         shl   ebx,16
  358.         inc   ebx
  359.         mov   ecx,sb_size_y
  360.         mov   edx,sb_line_col
  361.         mov   eax,13
  362.         cmp  sb_all_redraw,dword 0
  363.         je   @f
  364.         int   0x40   ; left extreme line
  365. @@:
  366.         push  ebx
  367.         ror   ebx,16
  368.         add   bx,sb_size_x
  369.         rol   ebx,16
  370.         cmp  sb_all_redraw,dword 0
  371.         je   @f
  372.         int   0x40   ; right extreme line
  373. @@:
  374.         pop   ebx
  375.  
  376.         push  ecx
  377.        
  378.         add   ebx,1 shl 16
  379.         mov   bx,sb_size_x
  380.         dec   ebx      
  381.         mov   cx,1
  382.         cmp  sb_all_redraw,dword 0
  383.         je   @f
  384.         int   0x40   ; top button - extreme line
  385. @@:
  386.         push  ecx
  387.         add   ecx,1 shl 16
  388.         add   ecx,sb_btn_high
  389.         sub   ecx,2
  390.         mov   edx,sb_frnt_col
  391.         cmp  sb_all_redraw,dword 0
  392.         je   @f
  393.         int   0x40   ; top button filling
  394. ;*********************************     
  395. draw_up_arrow_vertical
  396. ;*********************************
  397. @@:
  398.         pop   ecx
  399.        
  400.         ror   ecx,16
  401.         add   ecx,sb_btn_high  ;14 shl 16
  402.         rol   ecx,16
  403.         mov   edx,sb_line_col
  404.         cmp  sb_all_redraw,dword 0
  405.         je   @f
  406.         int   0x40   ;  top button - bottom line
  407. @@:
  408.         pop   ecx
  409. ;*********************************
  410.         ror   ecx,16   
  411.         add   ecx,sb_btn_high  ;15 shl 16
  412.         inc   ecx
  413.         rol   ecx,16
  414.         sub   ecx,sb_btn_high  ;30
  415.         sub   ecx,sb_btn_high
  416.         push  ecx
  417.         mov   cx,0
  418.         add   ecx,sb_position2
  419.         dec   cx
  420.         mov   eax,13
  421.         test  cx,0x8000
  422.         jnz   @f
  423.         mov   edx,sb_bckg_col
  424.         int   0x40      ; top interval
  425. @@:
  426. ;*********************************
  427.         shr   ecx,16
  428.         add   ecx,sb_position2
  429.         dec   ecx
  430.         shl   ecx,16
  431.         inc   ecx
  432.         mov   edx,sb_line_col
  433.         int   0x40      ; runner - top extreme line
  434.        
  435.         add   ecx,1 shl 16
  436.         mov   cx,0
  437.         add   ecx,sb_run_size
  438.         mov   sb_r_size_x,ebx
  439.         mov   sb_r_size_y,ecx
  440.         sub   ecx,2
  441.         mov   edx,sb_frnt_col
  442.         int   0x40   ; runner filling
  443. ;*********************************
  444. draw_runner_center_vertical
  445. ;*********************************
  446.         shr   ecx,16
  447.         add   ecx,sb_run_size
  448.         sub   ecx,2
  449.         shl   ecx,16  
  450.         inc   ecx
  451.         mov   edx,sb_line_col
  452.         int   0x40   ; runner - bottom extreme line
  453.        
  454.         add   ecx,1 shl 16
  455.         mov   cx,sb_start_y
  456.         add   cx,sb_size_y
  457.         sub   ecx,sb_btn_high
  458.         dec   ecx
  459.         mov   eax,ecx
  460.         shr   eax,16
  461.         sub   cx,ax
  462.         test  cx,0x8000
  463.         jnz       @f
  464.         mov   edx,sb_bckg_col
  465.         mov   eax,13
  466.         int   0x40   ; bottom interval
  467. @@:    
  468.         pop   ecx      
  469. ;*********************************     
  470.         mov   ax,cx
  471.         shr   ecx,16
  472.         add   cx,ax
  473.         sub   ecx,2
  474.         shl   ecx,16
  475.         inc   ecx
  476.         mov   edx,sb_line_col
  477.         mov   eax,13
  478.         cmp  sb_all_redraw,dword 0
  479.         je   @f
  480.         int   0x40   ; bottom button - top line
  481. @@:
  482.         push  ecx
  483.         add   ecx,1 shl 16
  484.         add   cx,sb_btn_high
  485.         sub   ecx,2
  486.         mov   edx,sb_frnt_col
  487.         cmp  sb_all_redraw,dword 0
  488.         je   @f
  489.         int   0x40   ; bottom button filling
  490. ;*********************************
  491. draw_down_arrow_vertical
  492. ;*********************************
  493. @@:
  494.         pop   ecx
  495.        
  496.         ror   ecx,16
  497.         add   ecx,sb_btn_high  ;14 shl 16
  498.         rol   ecx,16
  499.        
  500.         mov   edx,sb_line_col
  501.         mov   cx,1
  502.         cmp  sb_all_redraw,dword 0
  503.         je   @f
  504.         int   0x40   ; bottom button - extreme line
  505. @@:
  506.         popa
  507.         ret
  508. ;*****************************************************************************
  509. ;*****************************************************************************
  510. ; mouse event
  511. ;*****************************************************************************
  512. ;*****************************************************************************
  513. .mouse:
  514.         pusha
  515.         mov      edi,dword [esp+36]
  516.         mcall 37,1
  517.         mov   sb_m_pos,eax
  518.         cmp   sb_m_pos_2,dword 0
  519.         jne   @f
  520.        
  521.         mov   sb_m_pos_2,eax   
  522. @@:
  523.         mcall 37,2
  524.         mov   sb_m_keys,eax    
  525.  
  526.         cmp   sb_m_keys,eax
  527.         je        @f
  528.        
  529.         mov   sb_m_keys,eax
  530.  
  531.         mov   sb_delta,dword 0
  532.  
  533.         mov   eax,sb_m_pos
  534.         mov   sb_m_pos_2,eax
  535.         jmp   .continue_2
  536.        
  537. @@:
  538.         cmp   sb_m_keys,dword 0
  539.         jne      @f   ;.continue_2
  540.         mov   eax,sb_m_pos
  541.         mov   sb_m_pos_2,eax
  542.         jmp   .correct_1        ;.exit_sb      
  543. @@:
  544.         mov   sb_delta,word 1
  545.  
  546. .continue_2:
  547.         mov   eax,sb_m_pos
  548.         test  eax,0x80000000
  549.         jnz   .exit_sb
  550.        
  551.         test  eax,0x8000
  552.         jnz   .exit_sb
  553.        
  554.         mov   ebx,eax
  555.         shr   ebx,16   ; x position
  556.         shl   eax,16
  557.         shr   eax,16   ; y position
  558.  
  559.         mov   cx,sb_start_y
  560.         cmp   ax,cx
  561.         jb      .exit_sb
  562.        
  563.         cmp   sb_delta2,word 0
  564.         je      @f
  565.         push  ecx
  566.         add   cx,sb_btn_high
  567.         cmp   ax,cx
  568.         pop   ecx
  569.         jb      .exit_sb
  570.        
  571. @@:
  572.         add   cx,sb_size_y
  573.         cmp   ax,cx
  574.         ja      .exit_sb
  575.  
  576.         cmp   sb_delta2,word 0
  577.         je      @f
  578.         sub   cx,sb_btn_high
  579.         cmp   ax,cx
  580.         ja      .exit_sb
  581.        
  582. @@:
  583.         cmp   sb_delta2,word 1
  584.         je      @f
  585.        
  586.         cmp   sb_m_keys,dword 0
  587.         je      .exit_sb
  588.        
  589.         mov   cx,sb_start_x
  590.         cmp   bx,cx
  591.         jb      .exit_sb
  592.        
  593.         add   cx,sb_size_x
  594.         cmp   bx,cx
  595.         ja      .exit_sb
  596.  
  597.         mov   cx,sb_r_start_y
  598.         cmp   ax,cx
  599.         jb      .no_runner
  600.        
  601.         add   cx,sb_r_size_y
  602.         cmp   ax,cx
  603.         ja      .no_runner
  604.  
  605.         mov   sb_delta2,word 1 
  606. @@:
  607.         push  eax
  608.         mov   ax,sb_m_pos
  609.         cmp   ax,sb_m_pos_2
  610.         je      .correct  ;.exit_sb    
  611.        
  612.         shl   eax,16
  613.         shr   eax,16
  614.         mov   ebx,sb_m_pos_2
  615.         shl   ebx,16
  616.         shr   ebx,16
  617.         cmp   eax,ebx
  618.         jb   .sub
  619.        
  620.         sub   eax,ebx
  621.         mov   ebx,eax
  622.         add   sb_position2,ebx
  623.         xor   eax,eax
  624.         mov   ax,sb_size_y
  625.         sub   eax,sb_btn_high
  626.         sub   eax,sb_btn_high
  627.         sub   eax,sb_run_size
  628.         cmp   sb_position2,eax
  629.         jbe   @f
  630.        
  631.         mov   sb_position2,eax
  632. @@:
  633.         mov   eax,sb_m_pos
  634.         mov   sb_m_pos_2,eax
  635.         pop   eax
  636.         call  .draw_1
  637.         jmp   .no_runner_1
  638.        
  639. .correct:
  640.         pop   eax
  641.         jmp   .exit_sb
  642. .correct_1:
  643.         mov   sb_delta,dword 0
  644.         jmp   .exit_sb
  645.  
  646. .sub:
  647.         sub   ebx,eax
  648.         sub   sb_position2,ebx
  649.         test  sb_position2,dword 0x80000000
  650.         jz        @f
  651.        
  652.         mov   sb_position2,dword 0
  653. @@:
  654.         mov   eax,sb_m_pos
  655.         mov   sb_m_pos_2,eax
  656.         pop   eax
  657.         call  .draw_1
  658.         jmp   .no_runner_1
  659.  
  660. ;*****************************************************************************
  661. .no_runner:
  662.         mov   sb_delta,dword 0
  663. .no_runner_1:
  664.         xor   ecx,ecx
  665.         mov   cx,sb_start_y
  666.         add   cx,sb_btn_high   ;15
  667.         cmp   sb_delta,word 1
  668.         je      .scroll_sb
  669.        
  670.         cmp   ax,cx
  671.         ja      .scroll_sb
  672.        
  673.         cmp   sb_m_keys,dword 0
  674.         je   .exit_sb
  675.        
  676.         mov   eax,sb_ar_offset
  677.         cmp   sb_position,eax  ;dword 0
  678. ;       je      .exit_sb
  679.         jbe   @f
  680.        
  681. ;       dec   dword sb_position
  682.         sub   sb_position,eax
  683.         jmp   .all_sb
  684. @@:
  685.         xor   eax,eax
  686.         mov   sb_position,eax ;dword 0
  687.         mov   sb_position2,eax ;dword 0
  688.         jmp   .all_sb
  689. ;*****************************************************************************
  690. .scroll_sb:
  691.         add   cx,sb_size_y
  692.         sub   cx,sb_btn_high
  693.         sub   cx,sb_btn_high
  694.         cmp   sb_delta,word 1
  695.         je      @f
  696.        
  697.         cmp   ax,cx
  698.         ja      .down_sb
  699.        
  700. @@:
  701.         mov   ebx,sb_btn_high   ;16  ;15
  702. ;       inc   ebx
  703.         add   bx,sb_start_y
  704.         sub   cx,bx
  705.         sub   ax,bx
  706.        
  707. .scroll_sb_1:  
  708.         mov   ebx,sb_run_size
  709. ;***************************************************************************** 
  710.         cmp   sb_delta,word 1
  711.         je      .continue
  712.        
  713. @@:
  714.         mov   edx,eax
  715. ;       sub   edx,sb_btn_high
  716.         push  ebx
  717.         shr   ebx,1
  718.         sub   edx,ebx
  719.         pop   ebx
  720.         mov   sb_position2,edx
  721.         test  sb_position2,dword 0x80000000
  722.         jz       .test_1
  723.        
  724.         mov   sb_position2,dword 0
  725.         jmp   .continue
  726.        
  727. .test_1:
  728.         xor   edx,edx
  729.         mov   dx,sb_size_y
  730.         sub   edx,sb_btn_high
  731.         sub   edx,sb_btn_high
  732.         sub   edx,sb_run_size
  733.         cmp   sb_position2,edx
  734.         jbe   .continue
  735.        
  736.         mov   sb_position2,edx
  737. ;       jmp   .continue_1
  738.        
  739. .continue:  
  740.         mov   eax,sb_position2
  741.         sub   ecx,ebx
  742. .continue_1:
  743. ;*****************************************************************************  
  744.         mov   ebx,eax
  745.  
  746.         mov   eax,sb_max_area
  747.         cmp   eax,sb_cur_area
  748.         ja      @f
  749.  
  750.         xor   eax,eax
  751.         inc   eax
  752.         mov   sb_position2,eax
  753.         jmp   .all_sb   ;.store_position
  754. @@:
  755.         sub   eax,sb_cur_area
  756.         inc   eax
  757.         shl   eax,10
  758.         xor   edx,edx
  759.         div   ecx
  760.         shl   edx,1
  761.         cmp   edx,ecx
  762.         jb      @f
  763.        
  764.         inc   eax
  765.        
  766. @@:
  767.         imul  eax,ebx
  768.         shr   eax,10
  769.        
  770.         cmp   sb_position,eax
  771.         je      .exit_sb
  772.        
  773.         cmp   eax,0
  774.         ja      @f
  775.        
  776.         xor   eax,eax
  777.        
  778. @@:
  779. .store_position:
  780.         mov   sb_position,eax
  781. .all_sb:
  782.         mov   sb_redraw,dword 1
  783.         call  .draw_1
  784.         mov   eax,sb_m_pos
  785.         mov   sb_m_pos_2,eax
  786.         jmp   .exit_sb
  787. ;*****************************************************************************
  788. .down_sb:
  789.         cmp   sb_m_keys,dword 0
  790.         je   .exit_sb
  791.        
  792.         mov   eax,sb_max_area
  793.         mov   ebx,sb_ar_offset
  794.         sub   eax,sb_cur_area
  795.         push  eax
  796.         sub   eax,ebx
  797.         cmp   sb_position,eax
  798.         pop   eax
  799. ;       jae   .exit_sb
  800.         jae   @f
  801.        
  802. ;       inc   dword sb_position
  803.         add   sb_position,ebx
  804.         jmp   .all_sb
  805. @@:
  806.         mov   sb_position,eax
  807.         xor   eax,eax
  808.         mov   ax,sb_size_y
  809.         sub   eax,sb_btn_high
  810.         sub   eax,sb_btn_high
  811.         sub   eax,sb_run_size
  812.         mov   sb_position2,eax
  813.         jmp   .all_sb  
  814. .exit_sb:      
  815. scroll_bar_exit
  816. }
  817.  
  818. ;*****************************************************************************
  819. ;*****************************************************************************
  820. ;*****************************************************************************
  821. ;*****************************************************************************
  822. ;*****************************************************************************
  823. macro use_scroll_bar_horizontal
  824. {
  825. scroll_bar_horizontal:
  826. .draw:
  827.         pusha
  828.         mov   edi,dword [esp+36]
  829. ;       mov   sb_all_redraw,dword 1
  830.         mov   sb_delta,word 0
  831.         call  .draw_1
  832.         mov   sb_all_redraw,dword 0
  833. scroll_bar_exit
  834. .draw_1:
  835.         pusha
  836. ;*********************************
  837.         xor   eax,eax
  838.         mov   ax,sb_size_x      ;sb_size_y
  839.         mov   edx,sb_btn_high
  840.         shl   edx,1
  841.         sub   eax,edx
  842.         mov   sb_work_size,eax
  843. ;*********************************
  844.         mov   eax,sb_work_size   ;sb_max_area
  845.         mov   ebx,sb_max_area
  846.         cmp   ebx,sb_cur_area
  847.         ja      @f
  848.  
  849.         jmp   .no_size
  850.  
  851. @@:
  852.         imul  eax,sb_cur_area
  853.         xor   edx,edx
  854.         div   ebx
  855.         cmp   eax,10
  856.         jae   @f
  857.         mov   eax,10
  858. @@:
  859. .no_size:
  860.         mov   sb_run_size,eax
  861. ;*********************************
  862.         cmp   sb_delta,word 1
  863.         je      .@@_3
  864.         mov   eax,sb_work_size
  865.         sub   eax,sb_run_size
  866.         mov   ebx,sb_max_area
  867.         cmp   ebx,sb_cur_area
  868.         ja      @f
  869.         xor   eax,eax
  870.         jmp   .@@_1
  871. @@:
  872.         sub   ebx,sb_cur_area
  873.         imul  eax,sb_position
  874.         xor   edx,edx
  875.         div   ebx
  876. .@@_1:
  877.         mov   sb_position2,eax
  878.         xor   edx,edx
  879.         mov   dx,sb_size_x
  880.         sub   edx,sb_btn_high
  881.         sub   edx,sb_btn_high
  882.         sub   edx,sb_run_size
  883.         cmp   sb_position2,edx
  884.         jbe   .@@_3
  885.         mov   sb_position2,edx
  886. .@@_3:
  887. ;*********************************     
  888.         mov   ebx,sb_size_x
  889.         mov   ecx,sb_start_y
  890.         shl   ecx,16
  891.         inc   ecx      
  892.         mov   edx,sb_line_col
  893.         mov   eax,13
  894.         cmp  sb_all_redraw,dword 0
  895.         je   @f
  896.         int   0x40   ; top extreme line
  897. @@:
  898.         push  ecx
  899.         ror   ecx,16
  900.         add   cx,sb_size_y
  901.         rol   ecx,16
  902.         cmp  sb_all_redraw,dword 0
  903.         je   @f
  904.         int   0x40   ; bottom extreme line
  905. @@:
  906.         pop   ecx
  907.  
  908.         push  ebx
  909.        
  910.         add   ecx,1 shl 16
  911.         mov   cx,sb_size_y
  912.         dec   ecx      
  913.         mov   bx,1
  914.         cmp  sb_all_redraw,dword 0
  915.         je   @f
  916.         int   0x40   ; left button - extreme line
  917. @@:
  918.         push  ebx
  919.         add   ebx,1 shl 16
  920.         add   ebx,sb_btn_high
  921.         sub   ebx,2
  922.         mov   edx,sb_frnt_col
  923.         cmp  sb_all_redraw,dword 0
  924.         je   @f
  925.         int   0x40   ; left  button filling
  926. ;*********************************     
  927. draw_up_arrow_horizontal
  928. ;*********************************
  929. @@:
  930.         pop   ebx
  931.        
  932.         ror   ebx,16
  933.         add   ebx,sb_btn_high  ;14 shl 16
  934.         rol   ebx,16
  935.         mov   edx,sb_line_col
  936.         cmp  sb_all_redraw,dword 0
  937.         je   @f
  938.         int   0x40   ;  left  button - right line
  939. @@:
  940.         pop   ebx
  941. ;*********************************
  942.         ror   ebx,16   
  943.         add   ebx,sb_btn_high  ;15 shl 16
  944.           inc   ebx
  945.         rol   ebx,16
  946.         sub   ebx,sb_btn_high  ;30
  947.         sub   ebx,sb_btn_high
  948.         push  ebx
  949.         mov   bx,0
  950.         add   ebx,sb_position2
  951.           dec   bx
  952.         mov   eax,13
  953.         test  bx,0x8000
  954.         jnz   @f
  955.         mov   edx,sb_bckg_col
  956.         int   0x40      ; left interval
  957. @@:
  958. ;*********************************
  959.         shr   ebx,16
  960.         add   ebx,sb_position2
  961.         dec   ebx
  962.         shl   ebx,16
  963.         inc   ebx
  964.         mov   edx,sb_line_col
  965.         int   0x40      ; runner - left extreme line
  966.        
  967.         add   ebx,1 shl 16
  968.         mov   bx,0
  969.         add   ebx,sb_run_size
  970.         mov   sb_r_size_x,ebx
  971.         mov   sb_r_size_y,ecx
  972.         sub   ebx,2
  973.         mov   edx,sb_frnt_col
  974.         int   0x40   ; runner filling
  975. ;*********************************
  976. draw_runner_center_horizontal
  977. ;*********************************
  978.         shr   ebx,16
  979.         add   ebx,sb_run_size
  980.         sub   ebx,2
  981.         shl   ebx,16  
  982.         inc   ebx
  983.         mov   edx,sb_line_col
  984.         int   0x40   ; runner - bottom extreme line
  985.        
  986.         add   ebx,1 shl 16
  987.         mov   bx,sb_start_x
  988.         add   bx,sb_size_x
  989.         sub   ebx,sb_btn_high
  990.         dec   ebx
  991.         mov   eax,ebx
  992.         shr   eax,16
  993.         sub   bx,ax
  994.         test  bx,0x8000
  995.         jnz   @f
  996.         mov   edx,sb_bckg_col
  997.         mov   eax,13
  998.         int   0x40   ; bottom interval
  999. @@:
  1000.         pop   ebx      
  1001. ;*********************************     
  1002.         mov   ax,bx
  1003.         shr   ebx,16
  1004.         add   bx,ax
  1005.         sub   ebx,2
  1006.         shl   ebx,16
  1007.         inc   ebx
  1008.         mov   edx,sb_line_col
  1009.         mov   eax,13
  1010.         cmp  sb_all_redraw,dword 0
  1011.         je   @f
  1012.         int   0x40      ; bottom button - top line
  1013. @@:
  1014.         push  ebx
  1015.         add   ebx,1 shl 16
  1016.         add   bx,sb_btn_high
  1017.         sub   ebx,2
  1018.         mov   edx,sb_frnt_col
  1019.         cmp  sb_all_redraw,dword 0
  1020.         je   @f
  1021.         int   0x40   ; bottom button filling
  1022. ;*********************************
  1023. draw_down_arrow_horizontal
  1024. ;*********************************
  1025. @@:
  1026.         pop   ebx
  1027.        
  1028.         ror   ebx,16
  1029.         add   ebx,sb_btn_high  ;14 shl 16
  1030.         rol   ebx,16
  1031.        
  1032.         mov   edx,sb_line_col
  1033.         mov   bx,1
  1034.         cmp  sb_all_redraw,dword 0
  1035.         je   @f
  1036.         int   0x40   ; bottom button - extreme line
  1037. @@:
  1038.         popa
  1039.         ret
  1040. ;*****************************************************************************
  1041. ; mouse event
  1042. ;*****************************************************************************
  1043. .mouse:
  1044.         pusha
  1045.         mov      edi,dword [esp+36]
  1046.         mcall 37,1
  1047.         mov   sb_m_pos,eax
  1048.         cmp   sb_m_pos_2,dword 0
  1049.         jne   @f
  1050.        
  1051.         mov   sb_m_pos_2,eax   
  1052. @@:
  1053.         mcall 37,2
  1054.         mov   sb_m_keys,eax    
  1055.  
  1056.         cmp   sb_m_keys,eax
  1057.         je        @f
  1058.        
  1059.         mov   sb_m_keys,eax
  1060.  
  1061.         mov   sb_delta,dword 0
  1062.        
  1063.         mov   eax,sb_m_pos
  1064.         mov   sb_m_pos_2,eax
  1065.         jmp   .continue_2
  1066.        
  1067. @@:
  1068.         cmp   sb_m_keys,dword 0
  1069.         jne      @f   ;.continue_2
  1070.         mov   eax,sb_m_pos
  1071.         mov   sb_m_pos_2,eax
  1072.         jmp   .correct_1        ;.exit_sb
  1073. @@:
  1074.         mov   sb_delta,word 1
  1075.  
  1076. .continue_2:
  1077.         mov   eax,sb_m_pos
  1078.         test  eax,0x80000000
  1079.         jnz   .exit_sb
  1080.        
  1081.         test  eax,0x8000
  1082.         jnz   .exit_sb
  1083.        
  1084.         mov   ebx,eax
  1085.         shr   eax,16   ; x position
  1086.         shl   ebx,16
  1087.         shr   ebx,16   ; y position
  1088.  
  1089.         mov   cx,sb_start_x   ;y
  1090.         cmp   ax,cx
  1091.         jb      .exit_sb
  1092.        
  1093.         cmp   sb_delta2,word 0
  1094.         je      @f
  1095.         push  ecx
  1096.         add   cx,sb_btn_high
  1097.         cmp   ax,cx
  1098.         pop   ecx
  1099.         jb      .exit_sb
  1100.        
  1101. @@:
  1102.         add   cx,sb_size_x      ;y
  1103.         cmp   ax,cx
  1104.         ja      .exit_sb
  1105.  
  1106.         cmp   sb_delta2,word 0
  1107.         je      @f
  1108.         sub   cx,sb_btn_high
  1109.         cmp   ax,cx
  1110.         ja      .exit_sb
  1111.        
  1112. @@:
  1113.         cmp   sb_delta2,word 1
  1114.         je      @f
  1115.        
  1116.         cmp   sb_m_keys,dword 0
  1117.         je      .exit_sb
  1118.        
  1119.         mov   cx,sb_start_y   ;x
  1120.         cmp   bx,cx
  1121.         jb      .exit_sb
  1122.        
  1123.         add   cx,sb_size_y      ;x
  1124.         cmp   bx,cx
  1125.         ja      .exit_sb
  1126.        
  1127.         mov   cx,sb_r_start_x
  1128.         cmp   ax,cx
  1129.         jb      .no_runner
  1130.        
  1131.         add   cx,sb_r_size_x
  1132.         cmp   ax,cx
  1133.         ja      .no_runner
  1134.  
  1135.         mov   sb_delta2,word 1
  1136. @@:
  1137.         push  eax
  1138.         mov   eax,sb_m_pos
  1139.         mov   ebx,sb_m_pos_2
  1140.         shr   eax,16
  1141.         shr   ebx,16
  1142.         cmp   eax,ebx
  1143.         je      .correct  ;.exit_sb    
  1144.        
  1145. ;       shl   eax,16
  1146. ;       shr   eax,16
  1147. ;       mov   ebx,sb_m_pos_2
  1148. ;       shl   ebx,16
  1149. ;       shr   ebx,16
  1150. ;       cmp   eax,ebx
  1151.         jb   .sub
  1152.        
  1153.         sub   eax,ebx
  1154.         mov   ebx,eax
  1155.         add   sb_position2,ebx
  1156.         xor   eax,eax
  1157.         mov   ax,sb_size_x      ;y
  1158.         sub   eax,sb_btn_high
  1159.         sub   eax,sb_btn_high
  1160.         sub   eax,sb_run_size
  1161.         cmp   sb_position2,eax
  1162.         jbe   @f
  1163.        
  1164.         mov   sb_position2,eax
  1165. @@:
  1166.         mov   eax,sb_m_pos
  1167.         mov   sb_m_pos_2,eax
  1168.         pop   eax
  1169.         call  .draw_1
  1170.         jmp   .no_runner_1
  1171.        
  1172. .correct:
  1173.         pop   eax
  1174.         jmp   .exit_sb
  1175. .correct_1:
  1176.         mov   sb_delta,dword 0
  1177.         jmp   .exit_sb
  1178.  
  1179. .sub:
  1180.         sub   ebx,eax
  1181.         sub   sb_position2,ebx
  1182.         test  sb_position2,dword 0x80000000
  1183.         jz        @f
  1184.        
  1185.         mov   sb_position2,dword 0
  1186. @@:
  1187.         mov   eax,sb_m_pos
  1188.         mov   sb_m_pos_2,eax
  1189.         pop   eax
  1190.         call  .draw_1
  1191.         jmp   .no_runner_1
  1192.  
  1193. ;*****************************************************************************
  1194. .no_runner:
  1195.         mov   sb_delta,dword 0
  1196. .no_runner_1:
  1197.         xor   ecx,ecx
  1198.         mov   cx,sb_start_x   ;y
  1199.         add   cx,sb_btn_high   ;15
  1200.         cmp   sb_delta,word 1
  1201.         je      .scroll_sb
  1202.        
  1203.         cmp   ax,cx
  1204.         ja      .scroll_sb
  1205.        
  1206.         cmp   sb_m_keys,dword 0
  1207.         je   .exit_sb
  1208.        
  1209.         mov   eax,sb_ar_offset
  1210.         cmp   sb_position,eax  ;dword 0
  1211. ;       je      .exit_sb
  1212.         jbe   @f
  1213.        
  1214. ;       dec   dword sb_position
  1215.         sub   sb_position,eax
  1216.         jmp   .all_sb
  1217. @@:
  1218.         xor   eax,eax
  1219.         mov   sb_position,eax ;dword 0
  1220.         mov   sb_position2,eax  ;dword 0
  1221.         jmp   .all_sb
  1222. ;*****************************************************************************
  1223. .scroll_sb:
  1224.         add   cx,sb_size_x      ;y
  1225.         sub   cx,sb_btn_high
  1226.         sub   cx,sb_btn_high
  1227.         cmp   sb_delta,word 1
  1228.         je      @f
  1229.        
  1230.         cmp   ax,cx
  1231.         ja      .down_sb
  1232.        
  1233. @@:
  1234.         mov   ebx,sb_btn_high   ;16  ;15
  1235. ;       inc   ebx
  1236.         add   bx,sb_start_x     ;y
  1237.         sub   cx,bx
  1238.         sub   ax,bx
  1239.        
  1240. .scroll_sb_1:  
  1241.         mov   ebx,sb_run_size
  1242. ;***************************************************************************** 
  1243.         cmp   sb_delta,word 1
  1244.         je      .continue
  1245.        
  1246. @@:
  1247.         mov   edx,eax
  1248. ;       sub   edx,sb_btn_high
  1249.         push  ebx
  1250.         shr   ebx,1
  1251.         sub   edx,ebx
  1252.         pop   ebx
  1253.         mov   sb_position2,edx
  1254.         test  sb_position2,dword 0x80000000
  1255.         jz       .test_1
  1256.        
  1257.         mov   sb_position2,dword 0
  1258.         jmp   .continue
  1259.        
  1260. .test_1:
  1261.         xor   edx,edx
  1262.         mov   dx,sb_size_x       ;y
  1263.         sub   edx,sb_btn_high
  1264.         sub   edx,sb_btn_high
  1265.         sub   edx,sb_run_size
  1266.         cmp   sb_position2,edx
  1267.         jbe   .continue
  1268.        
  1269.         mov   sb_position2,edx
  1270. ;       jmp   .continue_1
  1271.        
  1272. .continue:  
  1273.         mov   eax,sb_position2
  1274.         sub   ecx,ebx
  1275. .continue_1:
  1276. ;*****************************************************************************  
  1277.         mov   ebx,eax
  1278.  
  1279.         mov   eax,sb_max_area
  1280.         cmp   eax,sb_cur_area
  1281.         ja      @f
  1282.  
  1283.         xor   eax,eax
  1284.         inc   eax
  1285.         mov   sb_position2,eax
  1286.         jmp   .all_sb   ;.store_position
  1287. @@:
  1288.         sub   eax,sb_cur_area
  1289.         inc   eax
  1290.         shl   eax,10
  1291.         xor   edx,edx
  1292.         div   ecx
  1293.         shl   edx,1
  1294.         cmp   edx,ecx
  1295.         jb      @f
  1296.        
  1297.         inc   eax
  1298.        
  1299. @@:
  1300.         imul  eax,ebx
  1301.         shr   eax,10
  1302.        
  1303.         cmp   sb_position,eax
  1304.         je      .exit_sb
  1305.        
  1306.         cmp   eax,0
  1307.         ja      @f
  1308.        
  1309.         xor   eax,eax
  1310.        
  1311. @@:
  1312. .store_position:
  1313.         mov   sb_position,eax
  1314. .all_sb:
  1315.         mov   sb_redraw,dword 1
  1316.         call  .draw_1
  1317.         mov   eax,sb_m_pos
  1318.         mov   sb_m_pos_2,eax
  1319.         jmp   .exit_sb
  1320. ;*****************************************************************************
  1321. .down_sb:
  1322.         cmp   sb_m_keys,dword 0
  1323.         je   .exit_sb
  1324.        
  1325.         mov   eax,sb_max_area
  1326.         mov   ebx,sb_ar_offset
  1327.         sub   eax,sb_cur_area
  1328.         push  eax
  1329.         sub   eax,ebx
  1330.         cmp   sb_position,eax
  1331.         pop   eax
  1332. ;       jae   .exit_sb
  1333.         jae   @f
  1334.        
  1335. ;       inc   dword sb_position
  1336.         add   sb_position,ebx
  1337.         jmp   .all_sb
  1338. @@:
  1339.         mov   sb_position,eax
  1340.         xor   eax,eax
  1341.         mov   ax,sb_size_x
  1342.         sub   eax,sb_btn_high
  1343.         sub   eax,sb_btn_high
  1344.         sub   eax,sb_run_size
  1345.         mov   sb_position2,eax
  1346.         jmp   .all_sb
  1347. .exit_sb:
  1348. scroll_bar_exit
  1349. }
  1350.