Subversion Repositories Kolibri OS

Rev

Rev 2703 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;                                          ;
  3. ;   Color Slider Control Demonstration     ;
  4. ;                                          ;
  5. ;   Compile with FASM for Kolibri          ;
  6. ;                                          ;
  7. ;   Author: Jason Delozier                 ;
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9.  
  10. use32
  11.  
  12.                org    0x0
  13.  
  14.                db     'MENUET01'              ; 8 byte id
  15.                dd     0x01                    ; header version
  16.                dd     START                   ; start of code
  17.                dd     I_END                   ; size of image
  18.                dd     0x1000                  ; memory for app
  19.                dd     0x1000                  ; esp
  20.                dd     0x0 , 0x0               ; I_Param , I_Icon
  21.  
  22. include 'lang.inc'
  23. include '..\..\..\macros.inc'
  24. include '..\..\..\KOSfuncs.inc'
  25. START:                          ; start of execution
  26.  
  27.     call draw_window            ; at first, draw the window
  28.  
  29. still:
  30.     call mouse_info
  31.  
  32.     mcall SF_WAIT_EVENT_TIMEOUT, 2
  33.  
  34.     cmp  eax,1                  ; redraw request ?
  35.     je   red
  36.     cmp  eax,2                  ; key in buffer ?
  37.     je   key
  38.     cmp  eax,3                  ; button in buffer ?
  39.     je   button
  40.  
  41.     jmp  still
  42.  
  43.   red:                          ; redraw
  44.     call draw_window
  45.     jmp  still
  46.  
  47.   key:                          ; key
  48.     mcall SF_GET_KEY            ; just read it and ignore
  49.     jmp  still
  50.  
  51.   button:                       ; button
  52.     mcall SF_GET_BUTTON         ; get id
  53.    
  54.     shr  eax,8
  55.  
  56.     cmp  eax,1                   ; button id=1 ?
  57.     jne  noclose
  58.     mcall SF_TERMINATE_PROCESS   ; close this program
  59.   noclose:
  60.  
  61.  
  62.   nofind:
  63.     jmp still
  64.  
  65.  
  66. ;   *********************************************
  67. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  68. ;   *********************************************
  69.  
  70.  
  71. draw_window:
  72.     mcall SF_REDRAW, SSF_BEGIN_DRAW
  73.     mcall SF_CREATE_WINDOW, <100,200>, <100,200>, 0x14ffffff, , title
  74.     mcall SF_REDRAW, SSF_END_DRAW
  75.        
  76.     call draw_slider_info
  77.  
  78.     xor  ecx,ecx
  79. Draw_Controls_Loop:
  80.     mov  ebp, [App_Controls+ecx]    ;get controls data location
  81.     or   ebp,ebp
  82.     jz   Draw_Controls_Done
  83.     call dword [App_Controls+ecx+4] ;call controls draw function
  84.     add  ecx, 12
  85.     jmp  Draw_Controls_Loop
  86. Draw_Controls_Done:
  87.  
  88.     ret
  89.  
  90.  
  91. ;***********************************************
  92. ;* Mouse Stuff
  93. ;***********************************************
  94. mousey dw 0
  95. mousex dw 0
  96. mouseb dd 0
  97.  
  98. mouse_info:
  99.    mcall SF_MOUSE_GET, SSF_WINDOW_POSITION
  100.    mov ecx, eax           ;
  101.    push ecx               ;
  102.    mcall SF_MOUSE_GET, SSF_BUTTON
  103.    cmp [mouseb], eax      ;compare old mouse states to new states
  104.    jne redraw_mouse_info  ;
  105.    cmp [mousey], cx       ;
  106.    jne redraw_mouse_info  ;
  107.    shr ecx, 16            ;
  108.    cmp [mousex], cx       ;
  109.    jne redraw_mouse_info  ;
  110.    pop ecx                ;
  111. ret                       ;return if no change in states
  112.  
  113.  
  114. redraw_mouse_info:
  115.    pop ecx
  116.    mov [mouseb], eax      ;save new mouse states
  117.    mov dword [mousey], ecx
  118.  
  119.    xor ecx, ecx
  120. Check_Mouse_Over_Controls_Loop:
  121.    mov ebp, [App_Controls+ecx]
  122.    or  ebp,ebp
  123.    jz Check_Mouse_Over_Controls_Loop_done
  124.    movzx eax,word [ebp+2]
  125.    cmp    ax, [mousex]
  126.    ja  mouse_not_on_control
  127.    movzx eax,word [ebp+6]
  128.    cmp    ax, [mousey]
  129.    ja  mouse_not_on_control
  130.    movzx eax,word [ebp]
  131.    add    ax, [ebp+2]
  132.    cmp    ax, [mousex]
  133.    jb  mouse_not_on_control
  134.    movzx eax,word [ebp+4]
  135.    add    ax, [ebp+6]
  136.    cmp    ax, [mousey]
  137.    jb  mouse_not_on_control
  138.    call dword [App_Controls+ecx+8]
  139. mouse_not_on_control:
  140.    add ecx, 12
  141.    jmp Check_Mouse_Over_Controls_Loop
  142. Check_Mouse_Over_Controls_Loop_done:
  143.  
  144. ret
  145.  
  146.  
  147.  
  148.  
  149. ;***********************************************
  150.  
  151.  
  152. draw_slider_info:
  153. ;Repaint value background
  154.    mcall SF_DRAW_RECT, 144*65536+36, 72*65536+9, 0x00ffffff
  155. ;Draw Color Box
  156.    xor edx, edx
  157.    movzx ecx,word [slider_1+12]
  158.    mov dh, cl
  159.    movzx ecx,word [slider_2+12]
  160.    mov dl, cl
  161.    shl edx, 8
  162.    movzx ecx,word [slider_3+12]
  163.    mov dl,cl
  164.    mov ebx, 0x00860035
  165.    mov ecx, 0x00590040
  166.    mov eax, SF_DRAW_RECT
  167.    mcall
  168. ;draw current value of slider
  169.    mov ecx, edx
  170.    mov eax, SF_DRAW_NUMBER
  171.    mov ebx, 0x00060100
  172.    mov esi, 0
  173.    mov edx, 144*65536+72
  174.    mcall
  175. ret
  176.  
  177.  
  178. ;**************************************
  179. ;*
  180. ;*   App Controls
  181. ;*
  182. ;**************************************
  183.  
  184. App_Controls:
  185.      dd slider_1 , draw_slider, slider_mouse_over   ;
  186.      dd slider_2 , draw_slider, slider_mouse_over   ;
  187.      dd slider_3 , draw_slider, slider_mouse_over   ;
  188.      dd 0 , 0          ; denotes last control do not delete
  189.  
  190. ;**************************************
  191. ;*
  192. ;*   Slider data
  193. ;*
  194. ;**************************************
  195.  
  196. slider_1:
  197.    dw  25  ;width         +0
  198.    dw  10  ;x             +2
  199.    dw  150 ;height        +4
  200.    dw  30  ;y             +6
  201.    dw  0   ;min           +8
  202.    dw  255 ;max           +10
  203.    dw  128 ;current       +12
  204.    dw  1   ;small change  +14
  205.    dw  5   ;big change    +16
  206.  
  207. slider_2:
  208.    dw  25  ;width         +0
  209.    dw  55  ;x             +2
  210.    dw  150 ;height        +4
  211.    dw  30  ;y             +6
  212.    dw  0   ;min           +8
  213.    dw  255 ;max           +10
  214.    dw  128  ;current       +12
  215.    dw  1   ;small change  +14
  216.    dw  5   ;big change    +16
  217.  
  218. slider_3:
  219.    dw  25  ;width         +0
  220.    dw  100 ;x             +2
  221.    dw  150 ;height        +4
  222.    dw  30  ;y             +6
  223.    dw  0   ;min           +8
  224.    dw  255 ;max           +10
  225.    dw  128 ;current       +12
  226.    dw  1   ;small change  +14
  227.    dw  5   ;big change    +16
  228.  
  229. ;**************************************
  230. ;*
  231. ;*   Slider Code
  232. ;*
  233. ;**************************************
  234.  
  235. box_h dw 10  ;static slider box height
  236.  
  237. draw_slider:
  238.    push eax ebx ecx edx
  239. ;Draw slider background
  240.    mov   eax, SF_DRAW_RECT ;slider background
  241.    mov   ebx, [ebp]      ;x start/width
  242.    mov   ecx, [ebp+4]    ;y start/height
  243.    mov   edx, 0x00EBEBEB ;color
  244.    mcall                 ;draw bar
  245. ;Draw line for slide rail
  246.    mov   eax, 38         ;draw vertical slide line
  247.    movzx ebx,word [ebp]  ;x
  248.    shr   ebx, 1          ;
  249.    add    bx,word [ebp+2];
  250.    push   bx             ;
  251.    shl   ebx, 16         ;
  252.    pop    bx             ;
  253.    mov   ecx, [ebp+4]    ;y start / height
  254.    add   ecx, 0x000A0000 ;
  255.    add   ecx, [ebp+6]    ;y start
  256.    sub   ecx, 10         ;
  257.    mov   edx, 0x00       ;color
  258.    mcall              ;
  259. ;Draw slider box
  260.    movzx eax,word [ebp+4]  ;height
  261.    sub   eax, 20           ;
  262.    movzx ebx,word [ebp+10] ;max value
  263.    sub    bx,word [ebp+8]  ;min value
  264.    movzx ecx,word [ebp+12] ;
  265.    call  slider_fpu_calc   ;EAX = ((EAX/EBX)*ECX)
  266.    mov   ebx, [ebp]        ;x start / width
  267.    movzx ecx,word [ebp+4]  ;height
  268.    add    cx, [ebp+6]      ;y
  269.    sub   ecx, 10           ;
  270.    movzx edx, [box_h]      ;
  271.    shr   edx, 1            ;
  272.    sub   ecx, edx          ;
  273.    sub   ecx, eax          ;*slide box y position
  274.    shl   ecx, 16           ;
  275.    mov    cx, [box_h]      ;height
  276.    mov   eax, SF_DRAW_RECT ;draw bar sys function
  277.    mov   edx, 0x00         ;color
  278.    mcall               ;draw slider box
  279.    pop edx ecx ebx eax
  280. ret
  281.  
  282. slider_mouse_over:
  283.    push eax ebx ecx edx
  284.    cmp [mouseb], 1
  285.    jne slider_mouse_over_done
  286.    movzx eax,word [ebp+4]
  287.    add    ax, [ebp+6]
  288.    sub   eax, 10
  289.    cmp [mousey], ax
  290.    ja slider_mouse_min
  291.    movzx eax,word [ebp+6]
  292.    add   eax, 10
  293.    cmp [mousey], ax
  294.    jb slider_mouse_max
  295. ;determine new current value
  296.    movzx eax,word  [ebp+10] ;slider max value
  297.    sub    ax,word  [ebp+8]  ;slider min value
  298.    movzx ebx,word [ebp+4]   ;slider height
  299.    sub   ebx,20             ;rail size
  300.    movzx ecx,word [mousey]  ;current mouse y pixel
  301.    sub   cx,word  [ebp+6]   ;minus y start of slider
  302.    sub   ecx, 10            ;minus pixels to top of rail
  303.    call  slider_fpu_calc    ;EAX = ((EAX/EBX)*ECX)
  304.    movzx ebx,word [ebp+10]  ;slider max
  305.    sub   ebx,eax            ;*current calculated position
  306.    jmp   slider_mouse_change;
  307. slider_mouse_max:           ;
  308.    movzx ebx,word [ebp+10]  ;get maximum value
  309.    jmp slider_mouse_change  ;
  310. slider_mouse_min:           ;
  311.    movzx ebx,word [ebp+8]   ;get minimum value
  312. slider_mouse_change:        ;
  313.    mov   [ebp+12],bx        ;new slider current position
  314.    call draw_slider         ;
  315.    call draw_slider_info    ;
  316. slider_mouse_over_done:     ;
  317.    pop edx ecx ebx eax
  318. ret
  319.  
  320.  
  321. temp  dd 0   ;temp varibles used in fpu computations
  322. temp2 dd 0
  323. temp3 dd 0
  324.  
  325. slider_fpu_calc:
  326.    mov   [temp],  eax
  327.    mov   [temp2], ebx
  328.    mov   [temp3], ecx
  329.    finit                   ;initilize FPU
  330.    fld   dword  [temp]     ;load value
  331.    fdiv  dword  [temp2]    ;divide
  332.    fmul  dword  [temp3]    ;multiply
  333.    fst   dword  [temp]     ;store computed value
  334.    mov   eax,   [temp]
  335. ret
  336.  
  337. ;**************************************************
  338. ;* End Slider Code
  339. ;**************************************************
  340.  
  341. ; DATA AREA
  342. title     db  'Color Slider',0
  343. I_END: