Subversion Repositories Kolibri OS

Rev

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

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