Subversion Repositories Kolibri OS

Rev

Rev 1666 | 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
163
	jmp	.active_text
1037 mario79 164
.no_active_text:
1199 mario79 165
	mov	ecx,m_bckg_text_col
1037 mario79 166
.active_text:
1199 mario79 167
	add	ecx,0x80000000
168
	mcall	4
169
	call	.get_next_text
170
	inc	ebp
171
	add	ebx,m_interval
172
	jmp	@r
1037 mario79 173
.draw_end:
1199 mario79 174
	ret
1037 mario79 175
 
176
.calc_m_cursor_max:
1199 mario79 177
	mov	edx,m_pos_pointer
178
	mov	m_cursor_max,dword 0
1037 mario79 179
@@:
1199 mario79 180
	inc	dword m_cursor_max
181
	call	.get_next_text
182
	jmp	@r
1037 mario79 183
;*****************************************************************************
184
.get_next_text:
1199 mario79 185
	mov	esi,edx
1037 mario79 186
@@:
1199 mario79 187
	cmp	esi,m_text_end
188
	je	.get_next_text_end
1037 mario79 189
	cld
190
	lodsb
1199 mario79 191
	test	al,al
192
	jnz	@r
193
	mov	edx,esi
194
	ret
1037 mario79 195
.get_next_text_end:
1199 mario79 196
	add	esp,4
1037 mario79 197
	ret
198
;*****************************************************************************
199
;*****************************************************************************
200
; mouse event
201
;*****************************************************************************
202
;*****************************************************************************
1199 mario79 203
.activate:
204
	pusha
205
	mov	edi,dword [esp+36]
206
	jmp	.start_loop
1037 mario79 207
.mouse:
208
	pusha
1199 mario79 209
	mov	edi,dword [esp+36]
1037 mario79 210
 
1199 mario79 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
1037 mario79 222
 
1199 mario79 223
	mov	cx,m_start_x
224
	cmp	bx,cx
225
	jb	.exit_menu
1037 mario79 226
 
1199 mario79 227
	add	cx,m_size_x
228
	dec	cx
229
	cmp	bx,cx
230
	ja	.exit_menu
1037 mario79 231
 
1199 mario79 232
	mov	cx,m_start_y
233
	cmp	ax,cx
234
	jb	.exit_menu
1037 mario79 235
 
1199 mario79 236
	add	cx,m_size_y
237
	cmp	ax,cx
238
	ja	.exit_menu
1037 mario79 239
 
1666 mario79 240
	test	dword m_mouse_keys,1b
1199 mario79 241
	jnz	@f
1666 mario79 242
	cmp	dword m_select,1
1199 mario79 243
	je	.exit_menu_1
1666 mario79 244
	mov	dword m_select,1
1199 mario79 245
	call	.draw_1
246
	jmp	.exit_menu_1
1037 mario79 247
@@:
1666 mario79 248
	cmp	dword m_get_mouse_flag,1
1199 mario79 249
	mov	m_get_mouse_flag,dword 0
250
	je	@f
1037 mario79 251
 
1199 mario79 252
	mov	eax,m_mouse_keys
253
	cmp	eax,m_mouse_keys_old
254
	je	.exit_menu_1
1037 mario79 255
@@:
3733 mario79 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
 
1199 mario79 265
.start_loop:
266
	mov	m_select,dword 1
267
	call	.draw_1
268
	call	.allocate_menu_area
269
	call	.get_menu_area
1037 mario79 270
 
1199 mario79 271
	call	.draw_2
1037 mario79 272
.red:
1199 mario79 273
	call	.draw_3
1037 mario79 274
.still:
1199 mario79 275
	mcall	10
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
1037 mario79 285
 
286
.key_menu:
1199 mario79 287
	mcall	2
288
 
1666 mario79 289
	cmp	dword m_extended_key,1
1199 mario79 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
1037 mario79 296
.key_menu_end:
1199 mario79 297
	jmp	.still
1037 mario79 298
@@:
1199 mario79 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
 
1037 mario79 312
.key_menu_end_1:
1199 mario79 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
1037 mario79 349
 
1199 mario79 350
	jmp	.exit_menu_3
1037 mario79 351
 
352
;---------------------------------------------------------------------
353
.extended_key:
1199 mario79 354
	mov	m_extended_key, dword 0
1037 mario79 355
.menu_key_80:
1199 mario79 356
	cmp	ah,80	; arrow down
357
	jne	.menu_key_72
1037 mario79 358
.menu_key_80_1:
1199 mario79 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
1037 mario79 366
;@@:
1199 mario79 367
	jmp	.red
1037 mario79 368
;---------------------------------------------------------------------
369
.menu_key_72:
1199 mario79 370
	cmp	ah,72	;arrow up
371
	jne	.menu_key_71
1037 mario79 372
.menu_key_72_1:
1199 mario79 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
1037 mario79 378
;@@:
1199 mario79 379
	jmp	.red
1037 mario79 380
;---------------------------------------------------------------------
381
.menu_key_71:
1199 mario79 382
	cmp	ah,71    ;Home
383
	je	@f
384
	cmp	ah,73    ;PageUp
385
	jne	.menu_key_79
1037 mario79 386
@@:
1666 mario79 387
	cmp	dword m_cursor,0
1199 mario79 388
	je	.still
389
	mov	ebx,m_cursor
390
	mov	m_cursor_old,ebx
391
	mov	m_cursor,dword 0
392
	jmp	.red
1037 mario79 393
;---------------------------------------------------------------------
394
.menu_key_79:
1199 mario79 395
	cmp	ah,79    ; End
396
	je	@f
397
	cmp	ah,81    ; PageDown
398
	jne	.menu_key_1
1037 mario79 399
@@:
1199 mario79 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
1037 mario79 408
;---------------------------------------------------------------------
409
.menu_key_1:
1199 mario79 410
	cmp	ah,1 ; Esc
411
	jne	.menu_key_28
1037 mario79 412
.menu_key_1_1:
1199 mario79 413
	jmp	.exit_menu_3
1037 mario79 414
;---------------------------------------------------------------------
415
.menu_key_28:
1199 mario79 416
	cmp	ah,28 ; Enter
417
	jne	.menu_key_75
1037 mario79 418
.menu_key_28_1:
1199 mario79 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
1037 mario79 424
;---------------------------------------------------------------------
1199 mario79 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
;---------------------------------------------------------------------
1037 mario79 439
.processing_real_mouse:
1199 mario79 440
	mcall	37,2
441
	mov	ebx,m_mouse_keys
442
	mov	m_mouse_keys_old,ebx
443
	mov	m_mouse_keys,eax
1037 mario79 444
 
1199 mario79 445
	mcall 37,1
446
	ret
1037 mario79 447
;---------------------------------------------------------------------
448
.allocate_menu_area:
1199 mario79 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	68, 12
455
	mov	m_buf_adress,eax
456
	ret
1037 mario79 457
;---------------------------------------------------------------------
458
.free_menu_area:
1666 mario79 459
	cmp	dword m_buf_adress,0
1597 mario79 460
	je	@f
1199 mario79 461
	mcall	68,13,m_buf_adress
462
	xor	eax,eax
463
	mov	m_buf_adress,eax
1597 mario79 464
@@:
1199 mario79 465
	ret
1037 mario79 466
;---------------------------------------------------------------------
467
.get_menu_area:
1199 mario79 468
	mcall	9, m_procinfo,-1
1037 mario79 469
 
1199 mario79 470
	mov	cx,m_size_x1
471
	shl	ecx,16
472
	mov	cx,m_size_y1
1037 mario79 473
 
1199 mario79 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]
1037 mario79 482
 
1199 mario79 483
	mcall	36, m_buf_adress
484
	ret
1037 mario79 485
;---------------------------------------------------------------------
486
.put_menu_area:
1199 mario79 487
	mov	cx,m_size_x1
488
	shl	ecx,16
489
	mov	cx,m_size_y1
1037 mario79 490
 
1199 mario79 491
	mov	dx,m_start_x1
492
	shl	edx,16
493
	mov	dx,m_start_y1
1037 mario79 494
 
1199 mario79 495
	mcall	7, m_buf_adress
1597 mario79 496
	call	.free_menu_area
1199 mario79 497
	ret
1037 mario79 498
;---------------------------------------------------------------------
499
.mouse_menu:
1199 mario79 500
	call	.processing_real_mouse
1037 mario79 501
 
1199 mario79 502
	test	eax,0x80000000
503
	jnz	.still
504
	test	eax,0x8000
505
	jnz	.still
1037 mario79 506
 
1199 mario79 507
	mov	ebx,eax
508
	shr	ebx,16
509
	shl	eax,16
510
	shr	eax,16
1037 mario79 511
 
1199 mario79 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
1037 mario79 536
@@:
1199 mario79 537
	mov	m_cursor,eax
538
	test	m_mouse_keys,dword 1b
539
	jz	.red
540
	jmp	.exit_menu_2
1037 mario79 541
.no_red:
1199 mario79 542
	test	m_mouse_keys,dword 1b
543
	jz	.still
544
	jmp	.exit_menu_2
1037 mario79 545
.close:
1199 mario79 546
	test	m_mouse_keys,dword 1b
547
	jz	.still
548
	jmp	.exit_menu_3
1037 mario79 549
 
550
.exit_menu:
1666 mario79 551
	cmp	dword m_select,0
1199 mario79 552
	je	.exit_menu_1
553
	mov	m_select,dword 0
1037 mario79 554
 
1199 mario79 555
	call	.draw_1
556
 
557
	test	m_mouse_keys,dword 1b
558
	jz	.exit_menu_1
1037 mario79 559
 
560
.exit_menu_3:
1199 mario79 561
	mov	m_select,dword 0
562
	call	.put_menu_area
563
	xor	eax,eax
564
	mov	m_cursor_out,eax
565
	jmp	.exit
1037 mario79 566
 
567
.exit_menu_2:
1199 mario79 568
	mov	m_select,dword 0
569
	call	.put_menu_area
570
	mov	edx,m_pos_pointer
1037 mario79 571
 
1199 mario79 572
	mov	ebx,m_cursor
1037 mario79 573
@@:
1199 mario79 574
	cmp	ebx,0
575
	jz	@f
576
	dec	ebx
577
	call	.get_next_text
578
	jmp	@r
1037 mario79 579
 
580
@@:
1199 mario79 581
	mov	m_out_select,edx
582
	mov	eax,m_cursor
583
	inc	eax
584
	mov	m_cursor_out,eax
1037 mario79 585
 
1199 mario79 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
1037 mario79 591
.exit:
1199 mario79 592
	call	.draw_1
593
	mov	m_click,dword 1
594
	jmp	@f
1037 mario79 595
.exit_menu_1:
1199 mario79 596
	mov	m_click,dword 0
1037 mario79 597
@@:
598
menu_bar_exit
599
}
600