Subversion Repositories Kolibri OS

Rev

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