Subversion Repositories Kolibri OS

Rev

Rev 551 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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