Subversion Repositories Kolibri OS

Rev

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

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