Subversion Repositories Kolibri OS

Rev

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