Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
111 heavyiron 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                    ;
3
;;  Scroll.inc                                                        ;
4
;;                                                                    ;
5
;;  Vertical Scroll Bar Example for MenuetOS                          ;
6
;;                                                                    ;
7
;;  Version 0.2  27 February 2005                                     ;
8
;;                                                                    ;
9
;;                                                                    ;
10
;;          GNU GENERAL PUBLIC LICENSE                                ;
11
;;             Version 2, June 1991                                   ;
12
;;                                                                    ;
13
;;  Copyright 2005 Jason Delozier,                                    ;
14
;;   cordata51@hotmail.com                                            ;
15
;;                                                                    ;
16
;;  See file COPYING for details                                      ;
17
;;                                                                    ;
18
;;  Updates:                                                          ;
19
;;     - FPU not longer used for calculations -Feb 27, 2005           ;
20
;;                                                                    ;
21
;;                                                                    ;
22
;;   TODO:                                                            ;
23
;;     - Create Message Handler and only allow runtime arguments      ;
24
;;       to be processed through the message handler                  ;
25
;;     - Remove all local varibles and only allow working varible to  ;
26
;;       reside in scroll bar structure.                              ;
27
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28
 
29
 
30
 
31
 
32
 
33
;*****************************************************************************
34
;*
35
;*   VScroll Structure Equates
36
;*
37
;*****************************************************************************
38
 
39
VScroll_width	      equ 0
40
VScroll_x	      equ 2
41
VScroll_height	      equ 4
42
VScroll_y	      equ 6
43
VScroll_min	      equ 8
44
VScroll_max	      equ 12
45
VScroll_current       equ 16
46
VScroll_s_change      equ 20
47
VScroll_b_change      equ 24
48
 
49
;Example VScroll Structure
50
;VScroll_1:
51
;   dw  16  ;width         +0
52
;   dw  100 ;x             +2
53
;   dw  200 ;height        +4
54
;   dw  40  ;y             +6
55
;   dd  0   ;min           +8
56
;   dd  1000;max           +12
57
;   dd  1   ;current       +16
58
;   dd  1   ;small change  +20
59
;   dd  10  ;big change    +24
60
 
61
VScroll_Min_Height dw 16     ;scroll box
62
Vscroll_Fixed_Height dw 16   ;height of scroll buttons (up and down)
63
 
64
;**************************************
65
;*
66
;*   Mouse Over VScroll
67
;*
68
;**************************************
69
vsm1 dd 0
70
vstoff dd 0
71
 
72
VScroll_mouse_over:
73
   cmp	 [mouseb], 1
74
   je	 VScroll_Mouse_Has_Mouse
75
   cmp	 [mouseb], 0
76
   jne	 VScroll_mouse_over_done2
77
   mov	 [vsm1], 0
78
   jmp	 VScroll_mouse_over_done2
79
VScroll_Mouse_Has_Mouse:
80
   push ecx
81
   mov	ecx, [vsm1]
82
   shl	ecx,2
83
   call dword [VScroll_Mouse_Jumptable+ecx]
84
VScroll_mouse_over_done:
85
   pop ecx
86
VScroll_mouse_over_done2:
87
   ret
88
 
89
VScroll_Mouse_Jumptable:
90
   dd	   VScroll_Mouse_Find
91
   dd	   VScroll_Mouse_On_Up
92
   dd	   VScroll_Mouse_On_Down
93
   dd	   VScroll_Mouse_Above_Thumb
94
   dd	   VScroll_Mouse_Below_Thumb
95
   dd	   VScroll_Mouse_On_Thumb
96
 
97
VScroll_Mouse_Find:
98
   inc	 ecx
99
   call  dword [VScroll_Mouse_Jumptable+ecx*4]
100
   cmp	 [vsm1], 0
101
   jne	 VScroll_mouse_over_done2
102
   cmp	 ecx, 5
103
   je	 VScroll_mouse_over_done2
104
   jmp	 VScroll_Mouse_Find
105
 
106
 
107
;**************************************
108
;Is Mouse at Up button
109
VScroll_Mouse_On_Up:
110
   push  eax
111
   movzx eax, word [ebp+VScroll_y]
112
   add	  ax, word [Vscroll_Fixed_Height]
113
   cmp	 [mousey], ax
114
   pop	 eax
115
   ja	 VScroll_Mouse_On_Up2
116
   mov	 [vsm1], 1
117
   call   VScroll_Small_Up
118
VScroll_Mouse_On_Up2:
119
   ret
120
 
121
;**************************************
122
;Is Mouse at Down button
123
VScroll_Mouse_On_Down:
124
   push  eax
125
   movzx eax,word [ebp+VScroll_y]
126
   add	  ax, word [ebp+VScroll_height]
127
   sub	  ax, word [Vscroll_Fixed_Height]
128
   cmp	 [mousey], ax
129
   pop	 eax
130
   jb	 VScroll_Mouse_On_Down2
131
   mov	 [vsm1], 2
132
   call  VScroll_Small_Down
133
VScroll_Mouse_On_Down2:
134
   ret
135
 
136
;**************************************
137
;Is Mouse above Scroll Thumb
138
VScroll_Mouse_Above_Thumb:
139
    push  eax
140
    push  ecx
141
    push  edx
142
    call  Vscroll_SBox_Area
143
    add    cx, word [ebp+VScroll_y]
144
    add    cx, word [Vscroll_Fixed_Height] ;plus height of scroll button
145
    cmp    cx, [mousey]
146
    pop   edx
147
    pop   ecx
148
    pop   eax
149
    jb	  VScroll_Mouse_Above_Thumb2
150
    mov   [vsm1], 3
151
    call  VScroll_Big_Up
152
VScroll_Mouse_Above_Thumb2:
153
    ret
154
 
155
;**************************************
156
;Is Mouse below scroll thumb
157
VScroll_Mouse_Below_Thumb:
158
    push  eax
159
    push  ecx
160
    push  edx
161
    call  Vscroll_SBox_Area
162
    add   cx, word [ebp+VScroll_y]
163
    add   cx, word [Vscroll_Fixed_Height] ;plus height of scroll button
164
    add   cx, ax
165
    cmp   cx, [mousey]
166
    pop   edx
167
    pop   ecx
168
    pop   eax
169
    ja	  VScroll_Mouse_Below_Thumb2
170
    mov   [vsm1], 4
171
    call  VScroll_Big_Down
172
VScroll_Mouse_Below_Thumb2:
173
    ret
174
 
175
;**************************************
176
;Mouse is on Scroll Thumb
177
VScroll_Mouse_On_Thumb:
178
 
179
    pusha
180
    cmp [vsm1], 5		       ;first time moving since we clicked?
181
    je	VScroll_Mouse_On_Thumb1        ;if not jump.. we already have offset
182
    mov   [vsm1], 5  ;determine offset between mouse pointer and top of thumb
183
    call  Vscroll_SBox_Area	       ;get top of thumb coordinate
184
    add   cx, word [ebp+VScroll_y]     ;make screen coordinate
185
    add   cx, word [Vscroll_Fixed_Height] ;plus height of scroll button and top
186
    movzx esi,word  [mousey]	       ;get mouse position
187
    sub   esi, ecx		       ;make offset between top of thumb
188
    mov   [vstoff], esi 	       ;and mouse pointer then save it
189
VScroll_Mouse_On_Thumb1:	       ;
190
    movzx esi, [mousey] 	       ;get mouse y value
191
    sub    si, word [ebp+VScroll_y]    ;get y starting value of scroll bar
192
    sub    si, [Vscroll_Fixed_Height]
193
    sub   esi, [vstoff] 	   ;
194
    call  Vscroll_SBox_Area	       ;
195
VScroll_Mouse_On_Thumb2:	       ;
196
    cmp   [ebp+VScroll_current], edx   ;only redraw if change occured
197
    je	  VScroll_Mouse_On_Thumb3      ;
198
    mov   [ebp+VScroll_current], edx   ;new current value
199
    call  drawvscrolla		       ;redraw scroll background and thumb
200
VScroll_Mouse_On_Thumb3:	       ;
201
    popa			       ;
202
    ret
203
;**************************************
204
 
205
 
206
 
207
 
208
;*****************************************************************************
209
;*
210
;*   Vscroll_SBox_Area
211
;*
212
;*   Purpose: To determine the area of the Scroll Bar Thumb and the current
213
;*            value of scroll based on top pixel of thumb.
214
;*
215
;*   Inputs:
216
;*           EBP - Structure of scroll bar
217
;*           ESI - Top of Thumb - optional
218
;*
219
;*   Outputs:
220
;*           EAX - Thumb Height
221
;*           ECX - Top of thumb
222
;*           EDX - Current Value based on top pixel of thumb. Valid when ESI
223
;*                 is given as input.
224
;*
225
;*   This procedure is divided up into 5 specific functions.
226
;*     1.  ((Vmax-VMin)/Small Change)= Total Changes
227
;*     2.  Height - (2* Fixed Button Height) = Total Pixels
228
;*     3.  Total Pixels - Total Changes = Thumb Height (must be >= 16)
229
;*             Minimum Height of 16 is varible [VScroll_Min_Height]
230
;*     4.   (((Tot Pixels - Thumb Height)* Current)/Max-min)=Top Pixel of Thumb
231
;*     5.   ((Mouse Top * (max-Min))/(Total Pix - Thumb Height)) = Current
232
;*          Step 5 is only valid if ESI is supplied as an input.
233
;*
234
;*
235
;*****************************************************************************
236
 
237
Vscroll_SBox_Area:
238
    push  ebx
239
    push  esi
240
    push  edi
241
    ;Step 1. Determine Total Changes
242
    mov   eax, dword [ebp+VScroll_max]	    ;get max scroll
243
    sub   eax, dword [ebp+VScroll_min]	    ;sub minmum scroll for total scro
244
    xor   edx,edx
245
    push  eax
246
    div   dword [ebp+VScroll_s_change] ;
247
    ;eax = total changes ((max-min)/Small Change)
248
 
249
    ;Step 2. Determine Total Pixels
250
    movzx ecx,	word [ebp+VScroll_height]   ;height of entire scroll bar
251
    mov    bx,	word [Vscroll_Fixed_Height] ;minus height of both scroll button
252
    shl    bx, 1
253
    sub    cx, bx
254
    push  ecx
255
    ;ecx = total pixels (Total Height - (2*Fixed Button Height)
256
 
257
    ;Step 3. Determine Thumb Height
258
    cmp   ecx, eax
259
    jbe   vs1
260
    sub   ecx, eax
261
    cmp   cx, word [VScroll_Min_Height]
262
    jb	  vs1
263
    jmp   vs2
264
vs1:
265
    movzx ecx,	word [VScroll_Min_Height]
266
vs2:
267
    ;ecx = Thumb Height  (Total Pixels - Total Changes) >=16
268
 
269
    ;Step 4. Determine Top Pixel of Thumb
270
    pop   edi			       ;Total Pixels
271
    sub   edi, ecx		       ;
272
    ;edi = Total Pixels - thumb Height
273
    mov   eax, edi		       ;
274
    mul   dword [ebp+VScroll_current]  ;get current scroll value
275
    pop   ebx			       ;max scroll
276
    push  ecx			       ;
277
    div   ebx			       ;
278
    mov   ecx, eax		       ;
279
    ;ecx = top pixel of thumb
280
 
281
    ;Step 5. Determine Current Value based on Mouse Position
282
    cmp si,0
283
    jge vss4
284
    mov eax, dword [ebp+VScroll_min]
285
    jmp vsdone1
286
vss4:
287
    cmp esi, edi
288
    jbe vss3
289
    mov eax, dword [ebp+VScroll_max]
290
    jmp vsdone1
291
vss3:
292
    mov   eax,ebx		       ;max scroll
293
    mul   esi			       ;Top Pixel of mouse
294
    div   edi			       ;Total Pixels - Thumb Height
295
    ;eax = Current Value
296
 
297
vsdone1:
298
    mov   edx, eax		       ;Current Value
299
    pop   eax			       ;Thumb Height
300
    pop   edi
301
    pop   esi
302
    pop   ebx
303
ret
304
 
305
;*****************************************************************************
306
;*
307
;*****************************************************************************
308
;ebp is structure
309
drawvscroll:
310
pusha
311
    ;up button
312
    mov eax, 13 		       ;button system function
313
    mov edx,0x00777777  ;0x6677cc		      ;color
314
    mov ebx, [ebp+VScroll_width]      ;x-start/width
315
    mov  cx, word [ebp+VScroll_y]      ;get bottom of scroll bar
316
    shl ecx, 16
317
    mov  cx, [Vscroll_Fixed_Height]    ;fixed height
318
    int 0x40
319
 
320
    ;down button
321
    mov ebx, [ebp+VScroll_width]      ;x-start/width
322
    mov  cx, word [ebp+VScroll_y]      ;get bottom of scroll bar
323
    add  cx, word [ebp+VScroll_height] ;
324
    sub  cx, [Vscroll_Fixed_Height]    ;y-start is 12 pixel from bottom
325
    shl ecx, 16 		      ;
326
    mov  cx, [Vscroll_Fixed_Height]    ;fixed height
327
    int 0x40
328
;------- 'ASCL.INC' needs to be included to use this --
329
    putlabel 493,46,'',cl_Black
330
    putlabel 493,372,'',cl_Black
331
;------------------------------------------------------
332
 
333
popa
334
drawvscrolla:
335
pusha
336
 
337
    mov   eax, 13			 ;Draw Scroll Box Background
338
    mov   edx, 0x00999999;0			 ;color
339
    push  edx
340
    movzx edx, word [Vscroll_Fixed_Height]
341
    mov   ebx, [ebp+VScroll_width]    ;x-start/width
342
    movzx ecx,word [ebp+VScroll_y]    ;y-start
343
    add   ecx, edx		      ;add fixed height button
344
    shl   ecx, 16		      ;do height next
345
    mov    cx,word [ebp+VScroll_height]    ;y-start
346
    sub    cx, dx		      ;subtract fixed height of up button
347
    sub    cx, dx		      ;subtract fixed height of down button
348
    pop   edx
349
    int   0x40				 ;tell system to draw it
350
 
351
;determine height of scroll box (thumb)
352
 
353
    call  Vscroll_SBox_Area
354
    add    cx, [ebp+VScroll_y]
355
    add    cx, 16
356
    shl   ecx, 16
357
    mov    cx, ax
358
 
359
    mov   eax, 13		      ;draw scroll box
360
    mov   ebx, [ebp+VScroll_width]	 ;x-start/width
361
    mov   edx, 0x00bbbbbb ;0x999999
362
    int   0x40
363
;call Draw_Scroll_info
364
popa
365
ret
366
;*****************************************************************************
367
 
368
;*****************************************************************************
369
;* VScroll_Big_Up
370
;* VScroll_Small_Up
371
;*****************************************************************************
372
;need to update for signed values
373
VScroll_Big_Up:
374
   push   eax
375
   push   ebx
376
   mov	  eax, dword [ebp+VScroll_b_change]
377
   jmp	  VScroll_Up
378
VScroll_Small_Up:
379
   push   eax
380
   push   ebx
381
   mov	  eax, dword [ebp+VScroll_s_change]
382
VScroll_Up:
383
   mov	  ebx, dword [ebp+VScroll_min]	  ;get minimum value
384
   cmp	  [ebp+VScroll_current], ebx	  ;are we at minimum already?
385
   je	  VScroll_Up_exit		  ;if so leave
386
   sub	  [ebp+VScroll_current], eax	  ;
387
   jnc	  VScroll_Up_done
388
   mov	  [ebp+VScroll_current], ebx
389
VScroll_Up_done:
390
   cmp	  [ebp+VScroll_current], ebx	   ;if current is greater then max
391
   jae	  VScroll_Up_done2
392
   mov	  [ebp+VScroll_current], ebx
393
VScroll_Up_done2:
394
;redraw
395
   call   drawvscroll ;temp?
396
VScroll_Up_exit:
397
   pop	  ebx
398
   pop	  eax
399
 
400
ret
401
;*****************************************************************************
402
 
403
 
404
;*****************************************************************************
405
;* VScroll_Big_Down
406
;* VScroll_Small_Down
407
;*****************************************************************************
408
;need to update for signed values
409
VScroll_Big_Down:
410
   push   eax
411
   push   ebx
412
   mov	  eax, dword [ebp+VScroll_b_change];get big change value
413
   jmp	  VScroll_Down
414
VScroll_Small_Down:
415
   push   eax
416
   push   ebx
417
   mov	  eax, dword [ebp+VScroll_s_change];get small change value
418
VScroll_Down:
419
   mov	  ebx, dword [ebp+VScroll_max]	   ;get maximum scroll value
420
   cmp	  [ebp+VScroll_current], ebx	   ;are we at max already?
421
   je	  VScroll_Down_exit		   ;if so leave
422
   add	  [ebp+VScroll_current], eax	   ;add change to current
423
   jno	  VScroll_Down_done		   ;dont go beyond bounds of register
424
   mov	  [ebp+VScroll_current], ebx	   ;if we did then we at max
425
VScroll_Down_done:			   ;
426
   cmp	  [ebp+VScroll_current], ebx	   ;if current is greater then max
427
   jbe	  VScroll_Down_done2		   ;
428
   mov	  [ebp+VScroll_current], ebx	   ;then we at max
429
VScroll_Down_done2:			   ;
430
;redraw
431
   call   drawvscroll	    ;temp?
432
VScroll_Down_exit:
433
   pop	  ebx
434
   pop	  eax
435
ret
436
;*****************************************************************************
437