Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
8346 IgorA 1
;**************************************************************
2
; MenuBar Macro for Kolibri OS
3
; Copyright (c) 2009, Marat Zakiyanov aka Mario79, aka Mario
4
; All rights reserved.
5
;
6
; Redistribution and use in source and binary forms, with or without
7
; modification, are permitted provided that the following conditions are met:
8
;     * Redistributions of source code must retain the above copyright
9
;       notice, this list of conditions and the following disclaimer.
10
;     * Redistributions in binary form must reproduce the above copyright
11
;       notice, this list of conditions and the following disclaimer in the
12
;       documentation and/or other materials provided with the distribution.
13
;     * Neither the name of the  nor the
14
;       names of its contributors may be used to endorse or promote products
15
;       derived from this software without specific prior written permission.
16
;
17
; THIS SOFTWARE IS PROVIDED BY Marat Zakiyanov ''AS IS'' AND ANY
18
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
; DISCLAIMED. IN NO EVENT SHALL  BE LIABLE FOR ANY
21
; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
;*****************************************************************************
28
macro menu_bar_exit
29
{
30
popa
31
ret 4
32
}
33
;*****************************************************************************
34
align 16
35
menu_bar:
36
m_type			equ [edi]
37
m_size_x		equ [edi+4]
38
m_start_x		equ [edi+6]
39
m_size_y		equ [edi+8]
40
m_start_y		equ [edi+10]
41
m_text_pointer		equ [edi+12]
42
m_pos_pointer		equ [edi+16]
43
m_text_end		equ [edi+20]
44
m_ret_key		equ [edi+24]
45
m_mouse_keys		equ [edi+28]
46
m_size_x1		equ [edi+32]
47
m_start_x1		equ [edi+34]
48
m_size_y1		equ [edi+36]
49
m_start_y1		equ [edi+38]
50
m_bckg_col		equ [edi+40]
51
m_frnt_col		equ [edi+44]
52
m_menu_col		equ [edi+48]
53
m_select		equ [edi+52]
54
m_out_select		equ [edi+56]
55
m_buf_adress		equ [edi+60]
56
m_procinfo		equ [edi+64]
57
m_click			equ [edi+68]
58
m_cursor		equ [edi+72]
59
m_cursor_old		equ [edi+76]
60
m_interval		equ [edi+80]
61
m_cursor_max		equ [edi+84]
62
m_extended_key		equ [edi+88]
63
m_menu_sel_col		equ [edi+92]
64
m_bckg_text_col		equ [edi+96]
65
m_frnt_text_col		equ [edi+100]
66
m_mouse_keys_old	equ [edi+104]
67
m_font_height		equ [edi+108]
68
m_cursor_out		equ [edi+112]
69
m_get_mouse_flag	equ [edi+116]
70
;*****************************************************************************
71
;*****************************************************************************
72
; draw event
73
;*****************************************************************************
74
;*****************************************************************************
75
.draw:
76
	pusha
77
	mov	edi,dword [esp+36]
78
	call	.draw_1
79
	menu_bar_exit
80
.draw_1:
81
	call	.calc_m_cursor_max
82
	dec	dword m_cursor_max
83
	mov	eax,m_cursor_max
84
	imul	eax,m_interval
85
	mov	m_size_y1,ax
86
 
87
	mov	ebx,m_size_x
88
	mov	ecx,m_size_y
89
	cmp	dword m_select,1
90
	je	.active
91
	mov	edx,m_bckg_col
92
	jmp	@f
93
.active:
94
	mov	edx,m_frnt_col
95
@@:
96
	mcall	SF_DRAW_RECT
97
	shr	ecx,16
98
	mov	bx,cx
99
	movzx	eax,word m_size_y
100
	call	.calculate_font_offset
101
	cmp	dword m_select,1
102
	je	.active_1
103
	mov	ecx,m_bckg_text_col
104
	add	ecx,0x80000000
105
	jmp	@f
106
.active_1:
107
	mov	ecx,m_frnt_text_col
108
	add	ecx,0x80000000
109
@@:
110
	mov	edx,m_text_pointer
111
	mcall	SF_DRAW_TEXT
112
	ret
113
 
114
.draw_2:
115
	mcall	SF_DRAW_RECT,m_size_x1,m_size_y1,m_menu_col
116
	ret
117
 
118
.calculate_font_offset:
119
	sub	eax,m_font_height
120
	shr	eax,1
121
	add	ebx,eax
122
	add	ebx,4 shl 16
123
	ret
124
 
125
.draw_3:
126
	mov	ebx,m_size_x1
127
	mov	ecx,m_size_y1
128
 
129
	push	ebx ecx
130
	mov	eax,m_cursor_old
131
	imul	eax,m_interval
132
	shl	eax,16
133
	add	ecx,eax
134
	mov	cx,m_interval
135
	mcall	SF_DRAW_RECT,,,m_menu_col
136
	pop	ecx ebx
137
 
138
	push	ebx ecx
139
	mov	eax,m_cursor
140
	imul	eax,m_interval
141
	shl	eax,16
142
	add	ecx,eax
143
	mov	cx,m_interval
144
	mov	edx,m_menu_sel_col
145
	mcall	SF_DRAW_RECT
146
	pop	ecx ebx
147
 
148
	shr	ecx,16
149
	mov	bx,cx
150
	mov	eax,m_interval
151
	call	.calculate_font_offset
152
	mov	edx,m_pos_pointer
153
	xor	ebp,ebp
154
@@:
155
	cmp	ebp,m_cursor
156
	jne	.no_active_text
157
	mov	ecx,m_frnt_text_col
158
	mov	eax,m_menu_sel_col
159
	jmp	.active_text
160
.no_active_text:
161
	mov	ecx,m_bckg_text_col
162
	mov	eax,m_menu_col
163
.active_text:
164
	add	ecx,0xC0000000
165
	push	edi
166
	mov	edi,eax
167
	mcall	SF_DRAW_TEXT
168
	pop	edi
169
	call	.get_next_text
170
	inc	ebp
171
	add	ebx,m_interval
172
	jmp	@r
173
.draw_end:
174
	ret
175
 
176
.calc_m_cursor_max:
177
	mov	edx,m_pos_pointer
178
	mov	m_cursor_max,dword 0
179
@@:
180
	inc	dword m_cursor_max
181
	call	.get_next_text
182
	jmp	@r
183
;*****************************************************************************
184
.get_next_text:
185
	mov	esi,edx
186
@@:
187
	cmp	esi,m_text_end
188
	je	.get_next_text_end
189
	cld
190
	lodsb
191
	test	al,al
192
	jnz	@r
193
	mov	edx,esi
194
	ret
195
.get_next_text_end:
196
	add	esp,4
197
	ret
198
;*****************************************************************************
199
;*****************************************************************************
200
; mouse event
201
;*****************************************************************************
202
;*****************************************************************************
203
.activate:
204
	pusha
205
	mov	edi,dword [esp+36]
206
	jmp	.start_loop
207
.mouse:
208
	pusha
209
	mov	edi,dword [esp+36]
210
 
211
	call	.processing_real_mouse
212
 
213
	test	eax,0x80000000
214
	jnz	.exit_menu
215
	test	eax,0x8000
216
	jnz	.exit_menu
217
 
218
	mov	ebx,eax
219
	shr	ebx,16   ; x position
220
	shl	eax,16
221
	shr	eax,16   ; y position
222
 
223
	mov	cx,m_start_x
224
	cmp	bx,cx
225
	jb	.exit_menu
226
 
227
	add	cx,m_size_x
228
	dec	cx
229
	cmp	bx,cx
230
	ja	.exit_menu
231
 
232
	mov	cx,m_start_y
233
	cmp	ax,cx
234
	jb	.exit_menu
235
 
236
	add	cx,m_size_y
237
	cmp	ax,cx
238
	ja	.exit_menu
239
 
240
	test	dword m_mouse_keys,1b
241
	jnz	@f
242
	cmp	dword m_select,1
243
	je	.exit_menu_1
244
	mov	dword m_select,1
245
	call	.draw_1
246
	jmp	.exit_menu_1
247
@@:
248
	cmp	dword m_get_mouse_flag,1
249
	mov	m_get_mouse_flag,dword 0
250
	je	@f
251
 
252
	mov	eax,m_mouse_keys
253
	cmp	eax,m_mouse_keys_old
254
	je	.exit_menu_1
255
@@:
256
	cmp	dword m_type,1
257
	jne	.start_loop
258
 
259
	xor	eax,eax
260
	inc	eax
261
	mov	m_cursor_out,eax
262
	mov	m_click,eax
263
	menu_bar_exit
264
 
265
.start_loop:
266
	mov	m_select,dword 1
267
	call	.draw_1
268
	call	.allocate_menu_area
269
	call	.get_menu_area
270
 
271
	call	.draw_2
272
.red:
273
	call	.draw_3
274
.still:
275
	mcall	SF_WAIT_EVENT
276
	cmp	eax,1
277
	je	.exit_menu_3
278
	cmp	eax,2
279
	je	.key_menu
280
	cmp	eax,3
281
	je	.exit_menu_3
282
	cmp	eax,6
283
	je	.mouse_menu
284
	jmp	.still
285
 
286
.key_menu:
287
	mcall	SF_GET_KEY
288
 
289
	cmp	dword m_extended_key,1
290
	je	.extended_key
291
	test	al,al
292
	jnz	.key_menu_end
293
	cmp	ah, 0xE0
294
	jne	@f
295
	mov	m_extended_key,dword 1
296
.key_menu_end:
297
	jmp	.still
298
@@:
299
	cmp	ah,72  ;Arrow Up
300
	je	.menu_key_72_1
301
	cmp	ah,80 ; Arrow Down
302
	je	.menu_key_80_1
303
	cmp	ah,28  ; Enter
304
	je	.menu_key_28_1
305
	cmp	ah,1  ; Esc
306
	je	.menu_key_1_1
307
	cmp	ah,75  ; L-Arrow down
308
	je	.menu_key_75_1
309
	cmp	ah,77  ; R-Arrow down
310
	je	.menu_key_77_1
311
 
312
.key_menu_end_1:
313
	cmp	ah,208 ; Arrow Down
314
	je	.key_menu_end
315
	cmp	ah,200 ; Arrow Up
316
	je	.key_menu_end
317
	cmp	ah,156 ; Enter
318
	je	.key_menu_end
319
	cmp	ah,129 ; Esc
320
	je	.key_menu_end
321
	cmp	ah,199  ;Home
322
	je	.key_menu_end
323
	cmp	ah,207  ;End
324
	je	.key_menu_end
325
	cmp	ah,201  ;Page UP
326
	je	.key_menu_end
327
	cmp	ah,209  ;Page Down
328
	je	.key_menu_end
329
	cmp	ah,42	; NumLock ON
330
	je	.key_menu_end
331
	cmp	ah,170  ; NumLock ON
332
	je	.key_menu_end
333
	cmp	ah,210  ; Insert
334
	je	.key_menu_end
335
	cmp	ah,211  ; Delete
336
	je	.key_menu_end
337
	cmp	ah,157  ; Ctrl up
338
	je	.key_menu_end
339
	cmp	ah,184  ; Alt up
340
	je	.key_menu_end
341
	cmp	ah,170  ; L-Shift up
342
	je	.key_menu_end
343
	cmp	ah,182  ; R-Shift up
344
	je	.key_menu_end
345
	cmp	ah,203  ; L-Arrow up
346
	je	.key_menu_end
347
	cmp	ah,205  ; R-Arrow up
348
	je	.key_menu_end
349
 
350
	jmp	.exit_menu_3
351
 
352
;---------------------------------------------------------------------
353
.extended_key:
354
	mov	m_extended_key, dword 0
355
.menu_key_80:
356
	cmp	ah,80	; arrow down
357
	jne	.menu_key_72
358
.menu_key_80_1:
359
	mov	eax,m_cursor_max
360
	dec	eax
361
	cmp	eax,m_cursor
362
	je	.still ;@f
363
	mov	ebx,m_cursor
364
	mov	m_cursor_old,ebx
365
	inc	dword m_cursor
366
;@@:
367
	jmp	.red
368
;---------------------------------------------------------------------
369
.menu_key_72:
370
	cmp	ah,72	;arrow up
371
	jne	.menu_key_71
372
.menu_key_72_1:
373
	cmp	m_cursor,dword 0
374
	je	.still  ;@f
375
	mov	ebx,m_cursor
376
	mov	m_cursor_old,ebx
377
	dec	dword m_cursor
378
;@@:
379
	jmp	.red
380
;---------------------------------------------------------------------
381
.menu_key_71:
382
	cmp	ah,71    ;Home
383
	je	@f
384
	cmp	ah,73    ;PageUp
385
	jne	.menu_key_79
386
@@:
387
	cmp	dword m_cursor,0
388
	je	.still
389
	mov	ebx,m_cursor
390
	mov	m_cursor_old,ebx
391
	mov	m_cursor,dword 0
392
	jmp	.red
393
;---------------------------------------------------------------------
394
.menu_key_79:
395
	cmp	ah,79    ; End
396
	je	@f
397
	cmp	ah,81    ; PageDown
398
	jne	.menu_key_1
399
@@:
400
	mov	ecx,m_cursor_max
401
	dec	ecx
402
	cmp	m_cursor,ecx
403
	je	.still
404
	mov	ebx,m_cursor
405
	mov	m_cursor_old,ebx
406
	mov	m_cursor,ecx
407
	jmp	.red
408
;---------------------------------------------------------------------
409
.menu_key_1:
410
	cmp	ah,1 ; Esc
411
	jne	.menu_key_28
412
.menu_key_1_1:
413
	jmp	.exit_menu_3
414
;---------------------------------------------------------------------
415
.menu_key_28:
416
	cmp	ah,28 ; Enter
417
	jne	.menu_key_75
418
.menu_key_28_1:
419
	xor	eax,eax
420
	mov	m_mouse_keys_old,eax
421
	inc	eax
422
	mov	m_mouse_keys,eax
423
	jmp	.exit_menu_2
424
;---------------------------------------------------------------------
425
.menu_key_75:
426
	cmp	ah,75  ; L-Arrow down
427
	jne	.menu_key_77
428
.menu_key_75_1:
429
	mov	m_ret_key,dword 1
430
	jmp	.exit_menu_3
431
;---------------------------------------------------------------------
432
.menu_key_77:
433
	cmp	ah,77  ; R-Arrow down
434
	jne	.key_menu_end_1
435
.menu_key_77_1:
436
	mov	m_ret_key,dword 2
437
	jmp	.exit_menu_3
438
;---------------------------------------------------------------------
439
.processing_real_mouse:
440
	mcall	SF_MOUSE_GET,SSF_BUTTON
441
	mov	ebx,m_mouse_keys
442
	mov	m_mouse_keys_old,ebx
443
	mov	m_mouse_keys,eax
444
 
445
	mcall	SF_MOUSE_GET,SSF_WINDOW_POSITION
446
	ret
447
;---------------------------------------------------------------------
448
.allocate_menu_area:
449
	call	.free_menu_area
450
	movzx	ecx,word m_size_x1
451
	movzx	eax,word m_size_y1
452
	imul	ecx,eax
453
	lea	ecx,[ecx*3]
454
	mcall	SF_SYS_MISC,SSF_MEM_ALLOC
455
	mov	m_buf_adress,eax
456
	ret
457
;---------------------------------------------------------------------
458
.free_menu_area:
459
	cmp	dword m_buf_adress,0
460
	je	@f
461
	mcall	SF_SYS_MISC,SSF_MEM_FREE,m_buf_adress
462
	xor	eax,eax
463
	mov	m_buf_adress,eax
464
@@:
465
	ret
466
;---------------------------------------------------------------------
467
.get_menu_area:
468
	mcall	SF_THREAD_INFO, m_procinfo,-1
469
 
470
	mov	cx,m_size_x1
471
	shl	ecx,16
472
	mov	cx,m_size_y1
473
 
474
	mov	dx,m_start_x1
475
	mov	eax,m_procinfo
476
	add	dx,[eax+34]
477
	add	dx,[eax+54]
478
	shl	edx,16
479
	mov	dx,m_start_y1
480
	add	dx,[eax+38]
481
	add	dx,[eax+58]
482
 
483
	mcall	SF_GET_IMAGE, m_buf_adress
484
	ret
485
;---------------------------------------------------------------------
486
.put_menu_area:
487
	mov	cx,m_size_x1
488
	shl	ecx,16
489
	mov	cx,m_size_y1
490
 
491
	mov	dx,m_start_x1
492
	shl	edx,16
493
	mov	dx,m_start_y1
494
 
495
	mcall	SF_PUT_IMAGE, m_buf_adress
496
	call	.free_menu_area
497
	ret
498
;---------------------------------------------------------------------
499
.mouse_menu:
500
	call	.processing_real_mouse
501
 
502
	test	eax,0x80000000
503
	jnz	.still
504
	test	eax,0x8000
505
	jnz	.still
506
 
507
	mov	ebx,eax
508
	shr	ebx,16
509
	shl	eax,16
510
	shr	eax,16
511
 
512
	xor	ecx,ecx
513
	mov	cx,m_start_y1
514
	cmp	ax,cx
515
	jbe	.close
516
	add	cx,m_size_y1
517
	cmp	ax,cx
518
	jae	.close
519
	mov	cx,m_start_x1
520
	cmp	bx,cx
521
	jbe	.close
522
	add	cx,m_size_x1
523
	cmp	bx,cx
524
	jae	.close
525
	sub	ax,m_start_y1
526
	mov	ebx,m_interval
527
	xor	edx,edx
528
	div	ebx
529
	mov	ebx,m_cursor
530
	cmp	eax,ebx
531
	je	.no_red
532
	mov	m_cursor_old,ebx
533
	cmp	eax,m_cursor_max
534
	jb	@f
535
	mov	eax,m_cursor_max
536
@@:
537
	mov	m_cursor,eax
538
	test	m_mouse_keys,dword 1b
539
	jz	.red
540
	jmp	.exit_menu_2
541
.no_red:
542
	test	m_mouse_keys,dword 1b
543
	jz	.still
544
	jmp	.exit_menu_2
545
.close:
546
	test	m_mouse_keys,dword 1b
547
	jz	.still
548
	jmp	.exit_menu_3
549
 
550
.exit_menu:
551
	cmp	dword m_select,0
552
	je	.exit_menu_1
553
	mov	m_select,dword 0
554
 
555
	call	.draw_1
556
 
557
	test	m_mouse_keys,dword 1b
558
	jz	.exit_menu_1
559
 
560
.exit_menu_3:
561
	mov	m_select,dword 0
562
	call	.put_menu_area
563
	xor	eax,eax
564
	mov	m_cursor_out,eax
565
	jmp	.exit
566
 
567
.exit_menu_2:
568
	mov	m_select,dword 0
569
	call	.put_menu_area
570
	mov	edx,m_pos_pointer
571
 
572
	mov	ebx,m_cursor
573
@@:
574
	cmp	ebx,0
575
	jz	@f
576
	dec	ebx
577
	call	.get_next_text
578
	jmp	@r
579
 
580
@@:
581
	mov	m_out_select,edx
582
	mov	eax,m_cursor
583
	inc	eax
584
	mov	m_cursor_out,eax
585
 
586
	mov	eax,m_mouse_keys
587
	cmp	eax,m_mouse_keys_old
588
	jne	.exit
589
	xor	eax,eax
590
	mov	m_cursor_out,eax
591
.exit:
592
	call	.draw_1
593
	mov	m_click,dword 1
594
	jmp	@f
595
.exit_menu_1:
596
	mov	m_click,dword 0
597
@@:
598
menu_bar_exit