Subversion Repositories Kolibri OS

Rev

Rev 1597 | 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
@@:
248
 
1666 mario79 249
	cmp	dword m_get_mouse_flag,1
1199 mario79 250
	mov	m_get_mouse_flag,dword 0
251
	je	@f
1037 mario79 252
 
1199 mario79 253
	mov	eax,m_mouse_keys
254
	cmp	eax,m_mouse_keys_old
255
	je	.exit_menu_1
1037 mario79 256
@@:
1199 mario79 257
.start_loop:
258
	mov	m_select,dword 1
259
	call	.draw_1
260
	call	.allocate_menu_area
261
	call	.get_menu_area
1037 mario79 262
 
1199 mario79 263
	call	.draw_2
1037 mario79 264
.red:
1199 mario79 265
	call	.draw_3
1037 mario79 266
.still:
1199 mario79 267
	mcall	10
268
	cmp	eax,1
269
	je	.exit_menu_3
270
	cmp	eax,2
271
	je	.key_menu
272
	cmp	eax,3
273
	je	.exit_menu_3
274
	cmp	eax,6
275
	je	.mouse_menu
276
	jmp	.still
1037 mario79 277
 
278
.key_menu:
1199 mario79 279
	mcall	2
280
 
1666 mario79 281
	cmp	dword m_extended_key,1
1199 mario79 282
	je	.extended_key
283
	test	al,al
284
	jnz	.key_menu_end
285
	cmp	ah, 0xE0
286
	jne	@f
287
	mov	m_extended_key,dword 1
1037 mario79 288
.key_menu_end:
1199 mario79 289
	jmp	.still
1037 mario79 290
@@:
1199 mario79 291
	cmp	ah,72  ;Arrow Up
292
	je	.menu_key_72_1
293
	cmp	ah,80 ; Arrow Down
294
	je	.menu_key_80_1
295
	cmp	ah,28  ; Enter
296
	je	.menu_key_28_1
297
	cmp	ah,1  ; Esc
298
	je	.menu_key_1_1
299
	cmp	ah,75  ; L-Arrow down
300
	je	.menu_key_75_1
301
	cmp	ah,77  ; R-Arrow down
302
	je	.menu_key_77_1
303
 
1037 mario79 304
.key_menu_end_1:
1199 mario79 305
	cmp	ah,208 ; Arrow Down
306
	je	.key_menu_end
307
	cmp	ah,200 ; Arrow Up
308
	je	.key_menu_end
309
	cmp	ah,156 ; Enter
310
	je	.key_menu_end
311
	cmp	ah,129 ; Esc
312
	je	.key_menu_end
313
	cmp	ah,199  ;Home
314
	je	.key_menu_end
315
	cmp	ah,207  ;End
316
	je	.key_menu_end
317
	cmp	ah,201  ;Page UP
318
	je	.key_menu_end
319
	cmp	ah,209  ;Page Down
320
	je	.key_menu_end
321
	cmp	ah,42	; NumLock ON
322
	je	.key_menu_end
323
	cmp	ah,170  ; NumLock ON
324
	je	.key_menu_end
325
	cmp	ah,210  ; Insert
326
	je	.key_menu_end
327
	cmp	ah,211  ; Delete
328
	je	.key_menu_end
329
	cmp	ah,157  ; Ctrl up
330
	je	.key_menu_end
331
	cmp	ah,184  ; Alt up
332
	je	.key_menu_end
333
	cmp	ah,170  ; L-Shift up
334
	je	.key_menu_end
335
	cmp	ah,182  ; R-Shift up
336
	je	.key_menu_end
337
	cmp	ah,203  ; L-Arrow up
338
	je	.key_menu_end
339
	cmp	ah,205  ; R-Arrow up
340
	je	.key_menu_end
1037 mario79 341
 
1199 mario79 342
	jmp	.exit_menu_3
1037 mario79 343
 
344
;---------------------------------------------------------------------
345
.extended_key:
1199 mario79 346
	mov	m_extended_key, dword 0
1037 mario79 347
.menu_key_80:
1199 mario79 348
	cmp	ah,80	; arrow down
349
	jne	.menu_key_72
1037 mario79 350
.menu_key_80_1:
1199 mario79 351
	mov	eax,m_cursor_max
352
	dec	eax
353
	cmp	eax,m_cursor
354
	je	.still ;@f
355
	mov	ebx,m_cursor
356
	mov	m_cursor_old,ebx
357
	inc	dword m_cursor
1037 mario79 358
;@@:
1199 mario79 359
	jmp	.red
1037 mario79 360
;---------------------------------------------------------------------
361
.menu_key_72:
1199 mario79 362
	cmp	ah,72	;arrow up
363
	jne	.menu_key_71
1037 mario79 364
.menu_key_72_1:
1199 mario79 365
	cmp	m_cursor,dword 0
366
	je	.still  ;@f
367
	mov	ebx,m_cursor
368
	mov	m_cursor_old,ebx
369
	dec	dword m_cursor
1037 mario79 370
;@@:
1199 mario79 371
	jmp	.red
1037 mario79 372
;---------------------------------------------------------------------
373
.menu_key_71:
1199 mario79 374
	cmp	ah,71    ;Home
375
	je	@f
376
	cmp	ah,73    ;PageUp
377
	jne	.menu_key_79
1037 mario79 378
@@:
1666 mario79 379
	cmp	dword m_cursor,0
1199 mario79 380
	je	.still
381
	mov	ebx,m_cursor
382
	mov	m_cursor_old,ebx
383
	mov	m_cursor,dword 0
384
	jmp	.red
1037 mario79 385
;---------------------------------------------------------------------
386
.menu_key_79:
1199 mario79 387
	cmp	ah,79    ; End
388
	je	@f
389
	cmp	ah,81    ; PageDown
390
	jne	.menu_key_1
1037 mario79 391
@@:
1199 mario79 392
	mov	ecx,m_cursor_max
393
	dec	ecx
394
	cmp	m_cursor,ecx
395
	je	.still
396
	mov	ebx,m_cursor
397
	mov	m_cursor_old,ebx
398
	mov	m_cursor,ecx
399
	jmp	.red
1037 mario79 400
;---------------------------------------------------------------------
401
.menu_key_1:
1199 mario79 402
	cmp	ah,1 ; Esc
403
	jne	.menu_key_28
1037 mario79 404
.menu_key_1_1:
1199 mario79 405
	jmp	.exit_menu_3
1037 mario79 406
;---------------------------------------------------------------------
407
.menu_key_28:
1199 mario79 408
	cmp	ah,28 ; Enter
409
	jne	.menu_key_75
1037 mario79 410
.menu_key_28_1:
1199 mario79 411
	xor	eax,eax
412
	mov	m_mouse_keys_old,eax
413
	inc	eax
414
	mov	m_mouse_keys,eax
415
	jmp	.exit_menu_2
1037 mario79 416
;---------------------------------------------------------------------
1199 mario79 417
.menu_key_75:
418
	cmp	ah,75  ; L-Arrow down
419
	jne	.menu_key_77
420
.menu_key_75_1:
421
	mov	m_ret_key,dword 1
422
	jmp	.exit_menu_3
423
;---------------------------------------------------------------------
424
.menu_key_77:
425
	cmp	ah,77  ; R-Arrow down
426
	jne	.key_menu_end_1
427
.menu_key_77_1:
428
	mov	m_ret_key,dword 2
429
	jmp	.exit_menu_3
430
;---------------------------------------------------------------------
1037 mario79 431
.processing_real_mouse:
1199 mario79 432
	mcall	37,2
433
	mov	ebx,m_mouse_keys
434
	mov	m_mouse_keys_old,ebx
435
	mov	m_mouse_keys,eax
1037 mario79 436
 
1199 mario79 437
	mcall 37,1
438
	ret
1037 mario79 439
;---------------------------------------------------------------------
440
.allocate_menu_area:
1199 mario79 441
	call	.free_menu_area
442
	movzx	ecx,word m_size_x1
443
	movzx	eax,word m_size_y1
444
	imul	ecx,eax
445
	lea	ecx,[ecx*3]
446
	mcall	68, 12
447
	mov	m_buf_adress,eax
448
	ret
1037 mario79 449
;---------------------------------------------------------------------
450
.free_menu_area:
1666 mario79 451
	cmp	dword m_buf_adress,0
1597 mario79 452
	je	@f
1199 mario79 453
	mcall	68,13,m_buf_adress
454
	xor	eax,eax
455
	mov	m_buf_adress,eax
1597 mario79 456
@@:
1199 mario79 457
	ret
1037 mario79 458
;---------------------------------------------------------------------
459
.get_menu_area:
1199 mario79 460
	mcall	9, m_procinfo,-1
1037 mario79 461
 
1199 mario79 462
	mov	cx,m_size_x1
463
	shl	ecx,16
464
	mov	cx,m_size_y1
1037 mario79 465
 
1199 mario79 466
	mov	dx,m_start_x1
467
	mov	eax,m_procinfo
468
	add	dx,[eax+34]
469
	add	dx,[eax+54]
470
	shl	edx,16
471
	mov	dx,m_start_y1
472
	add	dx,[eax+38]
473
	add	dx,[eax+58]
1037 mario79 474
 
1199 mario79 475
	mcall	36, m_buf_adress
476
	ret
1037 mario79 477
;---------------------------------------------------------------------
478
.put_menu_area:
1199 mario79 479
	mov	cx,m_size_x1
480
	shl	ecx,16
481
	mov	cx,m_size_y1
1037 mario79 482
 
1199 mario79 483
	mov	dx,m_start_x1
484
	shl	edx,16
485
	mov	dx,m_start_y1
1037 mario79 486
 
1199 mario79 487
	mcall	7, m_buf_adress
1597 mario79 488
	call	.free_menu_area
1199 mario79 489
	ret
1037 mario79 490
;---------------------------------------------------------------------
491
.mouse_menu:
1199 mario79 492
	call	.processing_real_mouse
1037 mario79 493
 
1199 mario79 494
	test	eax,0x80000000
495
	jnz	.still
496
	test	eax,0x8000
497
	jnz	.still
1037 mario79 498
 
1199 mario79 499
	mov	ebx,eax
500
	shr	ebx,16
501
	shl	eax,16
502
	shr	eax,16
1037 mario79 503
 
1199 mario79 504
	xor	ecx,ecx
505
	mov	cx,m_start_y1
506
	cmp	ax,cx
507
	jbe	.close
508
	add	cx,m_size_y1
509
	cmp	ax,cx
510
	jae	.close
511
	mov	cx,m_start_x1
512
	cmp	bx,cx
513
	jbe	.close
514
	add	cx,m_size_x1
515
	cmp	bx,cx
516
	jae	.close
517
	sub	ax,m_start_y1
518
	mov	ebx,m_interval
519
	xor	edx,edx
520
	div	ebx
521
	mov	ebx,m_cursor
522
	cmp	eax,ebx
523
	je	.no_red
524
	mov	m_cursor_old,ebx
525
	cmp	eax,m_cursor_max
526
	jb	@f
527
	mov	eax,m_cursor_max
1037 mario79 528
@@:
1199 mario79 529
	mov	m_cursor,eax
530
	test	m_mouse_keys,dword 1b
531
	jz	.red
532
	jmp	.exit_menu_2
1037 mario79 533
.no_red:
1199 mario79 534
	test	m_mouse_keys,dword 1b
535
	jz	.still
536
	jmp	.exit_menu_2
1037 mario79 537
.close:
1199 mario79 538
	test	m_mouse_keys,dword 1b
539
	jz	.still
540
	jmp	.exit_menu_3
1037 mario79 541
 
542
.exit_menu:
1666 mario79 543
	cmp	dword m_select,0
1199 mario79 544
	je	.exit_menu_1
545
	mov	m_select,dword 0
1037 mario79 546
 
1199 mario79 547
	call	.draw_1
548
 
549
	test	m_mouse_keys,dword 1b
550
	jz	.exit_menu_1
1037 mario79 551
 
552
.exit_menu_3:
1199 mario79 553
	mov	m_select,dword 0
554
	call	.put_menu_area
555
	xor	eax,eax
556
	mov	m_cursor_out,eax
557
	jmp	.exit
1037 mario79 558
 
559
.exit_menu_2:
1199 mario79 560
	mov	m_select,dword 0
561
	call	.put_menu_area
562
	mov	edx,m_pos_pointer
1037 mario79 563
 
1199 mario79 564
	mov	ebx,m_cursor
1037 mario79 565
@@:
1199 mario79 566
	cmp	ebx,0
567
	jz	@f
568
	dec	ebx
569
	call	.get_next_text
570
	jmp	@r
1037 mario79 571
 
572
@@:
1199 mario79 573
	mov	m_out_select,edx
574
	mov	eax,m_cursor
575
	inc	eax
576
	mov	m_cursor_out,eax
1037 mario79 577
 
1199 mario79 578
	mov	eax,m_mouse_keys
579
	cmp	eax,m_mouse_keys_old
580
	jne	.exit
581
	xor	eax,eax
582
	mov	m_cursor_out,eax
1037 mario79 583
.exit:
1199 mario79 584
	call	.draw_1
585
	mov	m_click,dword 1
586
	jmp	@f
1037 mario79 587
.exit_menu_1:
1199 mario79 588
	mov	m_click,dword 0
1037 mario79 589
@@:
590
menu_bar_exit
591
}
592