Subversion Repositories Kolibri OS

Rev

Rev 6054 | Rev 8288 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;*****************************************************************************
  2. ; Color Dialog - for Kolibri OS
  3. ; Copyright (c) 2013, 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. ;---------------------------------------------------------------------
  29. ;Some documentation for memory
  30. ;
  31. ;area name db 'FFFFFFFF_color_dialog',0 ; FFFFFFFF = PID
  32. ;
  33. ; communication area data
  34. ; flag  ; +0
  35. ; dw 0   ; 0 - empty, 1 - OK, color selected
  36. ;          2 - use another method/not found program, 3 - cancel
  37. ;
  38. ; type of dialog:  0-Palette&Tone
  39. ; dw 0 ; +2
  40. ;
  41. ; window X size ; +4
  42. ; dw 0
  43. ;
  44. ; window X position ; +6
  45. ; dw 0
  46. ;
  47. ; window y size ; +8
  48. ; dw 0
  49. ;
  50. ; window Y position ; +10
  51. ; dw 0
  52. ;
  53. ; ColorDialog WINDOW SLOT ; +12
  54. ; dd 0
  55. ;
  56. ; Color type ; +16
  57. ; dd 0
  58. ;
  59. ; Color value ; +20
  60. ; dd 0
  61.  
  62. ; First start flag ; +24
  63. ; dd 0 ; 0 - first start, 1 - subsequent starts
  64. ;
  65. ; Old colors ; +28
  66. ; rd 10
  67. ;
  68. ; Free area ; +68
  69. ;---------------------------------------------------------------------
  70.   use32
  71.   org    0x0
  72.  
  73.   db     'MENUET01'
  74.   dd     0x01
  75.   dd     START
  76.   dd     IM_END
  77.   dd     I_END
  78.   dd     stacktop
  79.   dd     param
  80.   dd     path
  81. ;---------------------------------------------------------------------
  82. include '../../macros.inc'
  83. include '../../KOSfuncs.inc'
  84. include '../../load_lib.mac'
  85. include '../../develop/libraries/box_lib/trunk/box_lib.mac'
  86. ;include 'lang.inc'
  87. ;include '../../debug.inc'
  88. @use_library
  89. ;---------------------------------------------------------------------
  90. p_start_x = 10
  91. p_start_y = 10
  92.  
  93. p_size_x = 20
  94. p_size_y = 256
  95. ;--------------------------------------
  96. t_start_x = 40
  97. t_start_y = 10
  98. ;--------------------------------------
  99. w_start_x = 200
  100. w_start_y = 200
  101.  
  102. w_size_x = 400
  103. w_size_y = 350
  104. ;--------------------------------------
  105. c_start_x = t_start_x + p_size_y + 10
  106. c_start_y = 10
  107.  
  108. c_size_x = 40
  109. c_size_y = 20
  110. ;---------------------------------------------------------------------
  111. x_minimal_size equ 350
  112. y_minimal_size equ 250
  113. ;---------------------------------------------------------------------
  114. START:
  115.         mcall   68,11
  116.         mcall   66,1,1
  117.         mcall   40,0x27
  118. ;       mcall   40,0x7
  119.         call    get_communication_area
  120.         call    get_active_pocess
  121.         call    clear_colors_history
  122. ;--------------------------------------
  123. load_libraries  l_libs_start,end_l_libs
  124.         test    eax,eax
  125.         jnz     button.exit_2
  126. ;--------------------------------------
  127.         xor     eax,eax
  128.         mov     al,p_size_x
  129.         mov     [palette_SIZE_X],eax
  130.         mov     ax,p_size_y
  131.         mov     [palette_SIZE_Y],eax
  132.         mov     [tone_SIZE_X],eax
  133.         mov     [tone_SIZE_Y],eax
  134.         mov     eax,0xff0000
  135.         mov     [tone_color],eax
  136.         mov     [selected_color],eax
  137.         call    prepare_scrollbars_position_from_color
  138. ;--------------------------------------
  139.         mov     ecx,[palette_SIZE_Y]
  140.         imul    ecx,[palette_SIZE_X]
  141.         lea     ecx,[ecx*3]
  142.         inc     ecx     ;reserve for stosd
  143.         mcall   68,12
  144.         mov     [palette_area],eax
  145. ;--------------------------------------
  146.         call    create_palette
  147. ;--------------------------------------
  148.         mov     ecx,[tone_SIZE_Y]
  149.         imul    ecx,[tone_SIZE_X]
  150.         lea     ecx,[ecx*3]
  151.         inc     ecx     ;reserve for stosd
  152.         mcall   68,12
  153.         mov     [tone_area],eax
  154. ;--------------------------------------
  155.         call    create_tone
  156. ;---------------------------------------------------------------------
  157. align 4
  158. red:
  159.         call    draw_window
  160. ;---------------------------------------------------------------------
  161. align 4
  162. still:
  163.         mcall   10
  164.  
  165.         cmp     eax,1
  166.         je      red
  167.  
  168.         cmp     eax,2
  169.         je      key
  170.  
  171.         cmp     eax,3
  172.         je      button
  173.  
  174.         cmp     eax,6
  175.         je      mouse
  176.  
  177.         jmp     still
  178. ;---------------------------------------------------------------------
  179. align 4
  180. button:
  181.         mcall   17
  182.  
  183.         cmp     ah, 2
  184.         je      palette_button
  185.  
  186.         cmp     ah, 3
  187.         je      tone_button
  188.  
  189.         cmp     ah, 4
  190.         je      color_button
  191.  
  192.         cmp     ah, 30
  193.         jb      @f
  194.  
  195.         cmp     ah, 39
  196.         ja      @f
  197.  
  198.         sub     ah,30
  199.         movzx   eax,ah
  200.         shl     eax,2
  201.         add     eax,[communication_area]
  202.         add     eax,28
  203.         mov     eax,[eax]
  204.         mov     [selected_color],eax
  205.         call    prepare_scrollbars_position_from_color
  206.         call    draw_selected_color
  207.         call    draw_scrollbars
  208.         jmp     still
  209. ;--------------------------------------
  210. align 4
  211. @@:
  212.         cmp     ah, 1
  213.         jne     still
  214. ;--------------------------------------
  215. align 4
  216. .exit:
  217.         mov     eax,[communication_area]
  218.         mov     [eax],word 3
  219.         jmp     @f
  220. ; dps "CD flag value: cancel "
  221. ;--------------------------------------
  222. align 4
  223. .exit_1:
  224. ;--------------------------------------
  225.         call    scroll_colors_history
  226. ;--------------------------------------
  227. align 4
  228. @@:
  229. ;       mov     ax,[eax]
  230. ;       and     eax,0xffff
  231. ; dps "CD flag value: "
  232. ; dpd eax
  233. ; newline
  234.  
  235.         call    get_window_param
  236.         mov     ebx,[communication_area]
  237.         mov     ecx,procinfo
  238. ;       mov     eax,[window_x]
  239.         mov     eax,[ecx+34]
  240.         shl     eax,16
  241.         add     eax,[ecx+42]
  242.         mov     [ebx+4],eax
  243. ;       mov     eax,[window_y]
  244.         mov     eax,[ecx+38]
  245.         shl     eax,16
  246.         add     eax,[ecx+46]
  247.         mov     [ebx+8],eax
  248. ;--------------------------------------
  249. align 4
  250. .exit_2:
  251.         mcall   -1
  252. ;---------------------------------------------------------------------
  253. align 4
  254. get_window_param:
  255.         mcall   9,procinfo,-1
  256.         mov     eax,[ebx+66]
  257.         inc     eax
  258. ;       mov     [window_high],eax
  259.         mov     eax,[ebx+62]
  260.         inc     eax
  261. ;       mov     [window_width],eax
  262.         mov     eax,[ebx+70]
  263. ;       mov     [window_status],eax
  264.         ret
  265. ;---------------------------------------------------------------------
  266. align 4
  267. get_communication_area:
  268.         xor     eax,eax
  269.         mov     al,[param]
  270.         test    eax,eax
  271.         jz      @f
  272.         mcall   68,22,param,,0x01
  273.         mov     [communication_area],eax
  274. ;       movzx   ebx,word [eax+2]
  275. ;       mov     [color_dialog_type],ebx
  276.  
  277.         mov     ebx,[eax+4]
  278. ;       cmp     bx,word x_minimal_size ;300
  279. ;       jb      @f
  280.         mov     bx,510
  281.         mov     [window_x],ebx
  282.         mov     ebx,[eax+8]
  283. ;       cmp     bx,word y_minimal_size ;200
  284. ;       jb      @f
  285.         mov     bx,340
  286.         mov     [window_y],ebx
  287. @@:
  288.         ret
  289. ;---------------------------------------------------------------------
  290. align 4
  291. get_active_pocess:
  292.         mcall   9,procinfo,-1
  293.         mov     ecx,[ebx+30]    ; PID
  294.         mcall   18,21
  295.         mov     [active_process],eax    ; WINDOW SLOT
  296.         mov     ebx,[communication_area]
  297.         test    ebx,ebx
  298.         jz      .1
  299.         mov     [ebx+12],eax    ; WINDOW SLOT to com. area
  300. .1:
  301.         ret
  302. ;---------------------------------------------------------------------
  303. align 4
  304. clear_colors_history:
  305.         mov     edi,[communication_area]
  306.         cmp     [edi+24],dword 1
  307.         je      @f
  308.         mov     [edi+24],dword 1
  309.         add     edi,28
  310.         mov     ecx,10
  311.         cld
  312.         mov     eax,0xffffff
  313.         rep     stosd
  314. @@:
  315.         ret
  316. ;---------------------------------------------------------------------
  317. align 4
  318. scroll_colors_history:
  319.         mov     edi,[communication_area]
  320.         add     edi,28
  321.         mov     eax,[selected_color]
  322.         cmp     [edi],eax
  323.         je      @f
  324.         mov     ecx,9
  325.         mov     esi,edi
  326.         add     esi,32
  327.         add     edi,36
  328.         std
  329.         rep     movsd
  330.         mov     edi,[communication_area]
  331.         mov     [edi+28],eax
  332. @@:
  333.         ret
  334. ;---------------------------------------------------------------------
  335. align 4
  336. palette_button:
  337.         mcall   37,1
  338.         and     eax,0xffff
  339.         sub     eax,p_start_y
  340.         imul    eax,p_size_x
  341.         lea     eax,[eax+eax*2]
  342.         add     eax,[palette_area]
  343.         mov     eax,[eax]
  344.         mov     [tone_color],eax
  345.         mov     [selected_color],eax
  346.         call    prepare_scrollbars_position_from_color
  347.         call    create_and_draw_tone
  348.         call    draw_selected_color
  349.         call    draw_scrollbars
  350.         jmp     still
  351. ;---------------------------------------------------------------------
  352. align 4
  353. tone_button:
  354.         mcall   37,1
  355.         mov     ebx,eax
  356.         and     eax,0xffff
  357.         shr     ebx,16
  358.         sub     eax,t_start_y
  359.         imul    eax,p_size_y
  360.         sub     ebx,t_start_x
  361.         add     eax,ebx
  362.         lea     eax,[eax+eax*2]
  363.         add     eax,[tone_area]
  364.         mov     eax,[eax]
  365.         mov     [selected_color],eax
  366.         call    prepare_scrollbars_position_from_color
  367.         call    draw_selected_color
  368.         call    draw_scrollbars
  369.         jmp     still
  370. ;---------------------------------------------------------------------
  371. align 4
  372. color_button:
  373.         mov     eax,[communication_area]
  374.         mov     [eax],word 1
  375.         mov     ebx,[selected_color]
  376.         and     ebx,0xffffff
  377.         mov     [eax+20],ebx
  378. ; dps "CD flag value: OK "
  379.         jmp     button.exit_1
  380. ;---------------------------------------------------------------------
  381. align 4
  382. prepare_scrollbars_position_from_color:
  383. ; in: eax = selected color
  384.         movzx   ebx,al
  385.         mov     [scroll_bar_data_blue.position],ebx
  386.         shr     eax,8
  387.         mov     bl,al
  388.         mov     [scroll_bar_data_green.position],ebx
  389.         shr     eax,8
  390.         mov     bl,al
  391.         mov     [scroll_bar_data_red.position],ebx
  392.         ret
  393. ;---------------------------------------------------------------------
  394. align 4
  395. prepare_color_from_scrollbars_position:
  396. ; out: ebx = selected color
  397.         mov     eax,[scroll_bar_data_red.position]
  398.         movzx   ebx,al
  399.         shl     ebx,8
  400.         mov     eax,[scroll_bar_data_green.position]
  401.         mov     bl,al
  402.         shl     ebx,8
  403.         mov     eax,[scroll_bar_data_blue.position]
  404.         mov     bl,al
  405.         ret
  406. ;---------------------------------------------------------------------
  407. align 4
  408. key:
  409.         mcall   2
  410.         jmp     still
  411. ;---------------------------------------------------------------------
  412. align 4
  413. mouse:
  414.         cmp     [scroll_bar_data_red.delta2],0
  415.         jne     .red
  416.         cmp     [scroll_bar_data_green.delta2],0
  417.         jne     .green
  418.         cmp     [scroll_bar_data_blue.delta2],0
  419.         jne     .blue
  420. ;--------------------------------------
  421. align 4
  422. .red:
  423.         push    dword scroll_bar_data_red
  424.         call    [scrollbar_ver_mouse]
  425.         cmp     [scroll_bar_data_red.delta2],0
  426.         jne     @f
  427. ;--------------------------------------
  428. align 4
  429. .green:
  430.         push    dword scroll_bar_data_green
  431.         call    [scrollbar_ver_mouse]
  432.         cmp     [scroll_bar_data_green.delta2],0
  433.         jne     @f
  434. ;--------------------------------------
  435. align 4
  436. .blue:
  437.         push    dword scroll_bar_data_blue
  438.         call    [scrollbar_ver_mouse]
  439. ;       cmp     [scroll_bar_data_blue.delta2],0
  440. ;       jne     @f
  441. ;--------------------------------------
  442. align 4
  443. @@:
  444.         call    prepare_color_from_scrollbars_position
  445.         cmp     [selected_color],ebx
  446.         je      still
  447.         mov     [selected_color],ebx
  448.         call    draw_selected_color
  449.         jmp     still
  450. ;---------------------------------------------------------------------
  451. align 4
  452. draw_selected_color:
  453.         mcall   13,<c_start_x,c_size_x>,<c_start_y,c_size_y>,[selected_color]
  454.         mcall   13,<c_start_x+c_size_x+10,c_size_x>,<c_start_y,c_size_y>,0xffffff
  455.         mov     ecx,[selected_color]
  456.         and     ecx,0xffffff
  457.         mcall   47,0x00060100,,<c_start_x+c_size_x+13,c_start_y+(c_size_y-6)/2>,0
  458.         ret
  459. ;---------------------------------------------------------------------
  460. align 4
  461. create_and_draw_tone:
  462.         call    create_tone
  463.         call    draw_tone
  464.         ret
  465. ;---------------------------------------------------------------------
  466. align 4
  467. draw_tone:
  468.         mcall   65,[tone_area],<[tone_SIZE_X],[tone_SIZE_Y]>,<t_start_x,t_start_y>,24
  469.         ret
  470. ;---------------------------------------------------------------------
  471. draw_scrollbars:
  472.         push    dword scroll_bar_data_red
  473.         call    [scrollbar_ver_draw]
  474.         push    dword scroll_bar_data_green
  475.         call    [scrollbar_ver_draw]
  476.         push    dword scroll_bar_data_blue
  477.         call    [scrollbar_ver_draw]
  478.         ret
  479. ;---------------------------------------------------------------------
  480. align 4
  481. draw_history_frame:
  482.         mov     [frame_data.x],dword (c_start_x+c_size_x*2+10*2)*65536+80
  483.         mov     [frame_data.y],dword (p_start_y+5)*65536+(p_size_y-5)
  484.  
  485.         mov     [frame_data.draw_text_flag],dword 1
  486.  
  487.         mov     [frame_data.text_pointer],dword history_text
  488.         push    dword frame_data
  489.         call    [Frame_draw]
  490.         ret
  491. ;---------------------------------------------------------------------
  492. align 4
  493. draw_button_row:
  494.         mov     edx,0x60000000 + 30             ; BUTTON ROW
  495. ;       mov     ebx,220*65536+14
  496.         mov     ebx,(c_start_x+c_size_x*2+10*3)*65536+14
  497.         mov     ecx,25*65536+14
  498.         mov     eax,8
  499. ;-----------------------------------
  500. align 4
  501. .newb:
  502.         mcall
  503.         add     ecx,24*65536
  504.         inc     edx
  505.         cmp     edx,0x60000000 + 39
  506.         jbe     .newb
  507.         ret
  508. ;---------------------------------------------------------------------
  509. align 4
  510. draw_color_value:
  511.         mov     ebx,(c_start_x+c_size_x*3+10)*65536+(c_size_x-1)
  512.         mov     ecx,28*65536+11
  513.         mov     edx,0xffffff
  514.         mov     eax,13
  515.         mov     edi,10
  516.         mov     esi,[communication_area]
  517.         add     esi,28
  518. ;-----------------------------------
  519. align 4
  520. @@:
  521.         mcall
  522.         pusha
  523.         mov     edx,ebx
  524.         add     edx,2 shl 16
  525.         shr     ecx,16
  526.         mov     dx,cx
  527.         add     dx,2
  528.         mov     ecx,[esi]
  529.         and     ecx,0xffffff
  530.         mcall   47,0x00060100,,,0
  531.         popa
  532.  
  533.         add     ecx,24*65536
  534.         add     esi,4
  535.         dec     edi
  536.         jnz     @b
  537.  
  538.         ret
  539. ;---------------------------------------------------------------------
  540. align 4
  541. draw_colours:
  542.         mov     edi,10
  543.         mov     esi,[communication_area]
  544.         add     esi,28
  545. ;       mov     ebx,220*65536+14
  546.         mov     ebx,(c_start_x+c_size_x*2+10*3)*65536+14
  547.         mov     ecx,27*65536+14
  548.         mov     eax,13
  549.         mov     [frame_data.draw_text_flag],dword 0
  550. ;--------------------------------------
  551. align 4
  552. newcol:
  553.         mov     edx,[esi]
  554.         mcall
  555.  
  556.         push    ebx ecx
  557.  
  558.         sub     ebx,2 shl 16
  559.         add     bx,4
  560.         sub     ecx,2 shl 16
  561.         add     cx,4
  562.  
  563.         mov     [frame_data.x],ebx
  564.         mov     [frame_data.y],ecx
  565.  
  566.         push    dword frame_data
  567.         call    [Frame_draw]
  568.  
  569.         pop     ecx ebx
  570.  
  571.         add     ecx,24*65536
  572.         add     esi,4
  573.  
  574.         dec     edi
  575.         jnz     newcol
  576.  
  577.         ret
  578. ;----------------------------------------------------------------------
  579. align 4
  580. draw_window:
  581.         mcall   12,1
  582. ;       mcall   0, <w_start_x,w_size_x>, <w_start_y,w_size_y>, 0x33AABBCC,,title
  583.         xor     esi,esi
  584.         mcall   0,[window_x],[window_y], 0x34EEEeee,,title
  585.         mcall   8,<p_start_x,[palette_SIZE_X]>,<p_start_y,[palette_SIZE_Y]>,0x60000002
  586.         mcall   ,<t_start_x,[tone_SIZE_X]>,<t_start_y,[tone_SIZE_Y]>,0x60000003
  587.         mcall   ,<296,80>,<280,22>,4,0x37A4D4
  588.         mcall   ,<402,80>,        ,1
  589.         mcall   4,<332,289>,0x802C7B9E,OK_Cancel
  590.         mcall   ,<331,288>,0x80FFFfff
  591.         xor     ebp,ebp
  592.         mcall   65,[palette_area],<[palette_SIZE_X],[palette_SIZE_Y]>,<p_start_x,p_start_y>,24
  593.         call    draw_tone
  594.         call    draw_selected_color
  595.         xor     eax,eax
  596.         inc     eax
  597.         mov     [scroll_bar_data_red.all_redraw],eax
  598.         mov     [scroll_bar_data_green.all_redraw],eax
  599.         mov     [scroll_bar_data_blue.all_redraw],eax
  600.         call    draw_scrollbars
  601.         call    draw_history_frame
  602.         call    draw_button_row
  603.         call    draw_colours
  604.         call    draw_color_value
  605.         mcall   12,2
  606.         ret
  607. ;---------------------------------------------------------------------
  608. include 'palette.inc'
  609. ;---------------------------------------------------------------------
  610. include 'tone.inc'
  611. ;---------------------------------------------------------------------
  612. include 'i_data.inc'
  613. ;---------------------------------------------------------------------
  614. IM_END:
  615. ;---------------------------------------------------------------------
  616. include 'u_data.inc'
  617. ;---------------------------------------------------------------------
  618. I_END:
  619. ;---------------------------------------------------------------------
  620.