Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1334 mikedld 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2455 mario79 3
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
1334 mikedld 4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
 
9
$Revision: 4970 $
10
 
11
;==============================================================================
12
;///// public functions ///////////////////////////////////////////////////////
13
;==============================================================================
14
 
1391 mikedld 15
button.MAX_BUTTONS = 4095
16
 
2384 hidnplayr 17
struct  SYS_BUTTON
18
        pslot           dw ?
19
        id_lo           dw ?
20
        left            dw ?
21
        width           dw ?
22
        top             dw ?
23
        height          dw ?
24
        id_hi           dw ?
25
                        dw ?
26
ends
1334 mikedld 27
 
28
align 4
29
;------------------------------------------------------------------------------
30
syscall_button: ;///// system function 8 //////////////////////////////////////
31
;------------------------------------------------------------------------------
1362 mikedld 32
;? Define/undefine GUI button object
1334 mikedld 33
;------------------------------------------------------------------------------
1362 mikedld 34
;; Define button:
35
;> ebx = pack[16(x), 16(width)]
36
;> ecx = pack[16(y), 16(height)]
37
;> edx = pack[8(flags), 24(button identifier)]
38
;>       flags bits:
39
;>          7 (31) = 0
40
;>          6 (30) = don't draw button
41
;>          5 (29) = don't draw button frame when pressed
4970 Akyltist 42
;>          4 (28) = don't draw button 3d frame
1362 mikedld 43
;> esi = button color
1334 mikedld 44
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1362 mikedld 45
;; Undefine button:
46
;> edx = pack[8(flags), 24(button identifier)]
47
;>       flags bits:
48
;>          7 (31) = 1
1334 mikedld 49
;------------------------------------------------------------------------------
50
        ; do we actually need to undefine the button?
51
        test    edx, 0x80000000
52
        jnz     .remove_button
53
 
54
        ; do we have free button slots available?
55
        mov     edi, [BTN_ADDR]
56
        mov     eax, [edi]
1391 mikedld 57
        cmp     eax, button.MAX_BUTTONS
1334 mikedld 58
        jge     .exit
59
 
60
        ; does it have positive size? (otherwise it doesn't have sense)
61
        or      bx, bx
62
        jle     .exit
63
        or      cx, cx
64
        jle     .exit
65
 
66
        ; make coordinates clientbox-relative
67
        push    eax
68
        mov     eax, [current_slot]
69
        rol     ebx, 16
70
        add     bx, word[eax + APPDATA.wnd_clientbox.left]
71
        rol     ebx, 16
72
        rol     ecx, 16
73
        add     cx, word[eax + APPDATA.wnd_clientbox.top]
74
        rol     ecx, 16
75
        pop     eax
76
 
77
        ; basic checks passed, define the button
78
        push    ebx ecx edx
79
        inc     eax
80
        mov     [edi], ax
81
        shl     eax, 4
82
        add     edi, eax
83
        ; NOTE: this code doesn't rely on SYS_BUTTON struct, please revise it
84
        ;       if you change something
85
        mov     ax, [CURRENT_TASK]
86
        stosw
87
        mov     ax, dx
88
        stosw               ; button id number: bits 0-15
89
        mov     eax, ebx
4970 Akyltist 90
        dec     eax
1334 mikedld 91
        rol     eax, 16
92
        stosd               ; x start | x size
93
        mov     eax, ecx
4970 Akyltist 94
        dec     eax
1334 mikedld 95
        rol     eax, 16
96
        stosd               ; y start | y size
97
        mov     eax, edx
98
        shr     eax, 16
99
        stosw               ; button id number: bits 16-31
100
        pop     edx ecx ebx
101
 
102
        ; do we also need to draw the button?
103
        test    edx, 0x40000000
104
        jnz     .exit
105
 
4970 Akyltist 106
        ; DRAW BODY -----------------------------
1334 mikedld 107
        pushad
4970 Akyltist 108
        call    button._.button_calc_relativ
109
        xor     edi, edi ; for __sys_draw_line
110
        ; set color
1334 mikedld 111
        mov     ecx, esi
4970 Akyltist 112
        ; set coordinate
113
        inc     edx
114
        ; if gradient
1334 mikedld 115
        cmp     [buttontype], 0
4970 Akyltist 116
        je      .next_line
117
        call    button._.incecx
118
align 4
119
.next_line:
1334 mikedld 120
        call    button._.button_dececx
2453 mario79 121
        call    __sys_draw_line
1334 mikedld 122
        add     ebx, 0x00010001
123
        dec     edx
124
        jnz     .next_line
4970 Akyltist 125
        popad
1334 mikedld 126
 
4970 Akyltist 127
        ; DRAW FRAME ----------------------------
128
        pushad
129
        call    button._.button_calc_relativ
130
        mov     esi, common_colours
131
 
132
        mov     edi, dword [esi+104]
133
        call    .top_border
134
        mov     edi, dword [esi+104]
135
        call    .bottom_border
136
        mov     edi, dword [esi+104]
137
        call    .right_border
138
        mov     edi, dword [esi+104]
139
        call    .left_border
1334 mikedld 140
        popad
141
 
4970 Akyltist 142
        ; DRAW 3D SHADOW ------------------------
143
        test    edx, 0x10000000
144
        jnz     .exit
1334 mikedld 145
 
4970 Akyltist 146
        pushad
147
        mov     edi, edx
148
        call    button._.button_calc_relativ
149
        ; get color address
150
        mov     esi, common_colours
151
        test    edi, 0x10000000
152
        jnz     @f
153
        add     eax, 0x10000
154
        dec     eax
155
        inc     ecx
156
        dec     edx
157
        dec     edx
158
align 4
159
@@:
160
        mov     edi, dword [esi+12]
161
        call    .top_border
162
        mov     edi, dword [esi+8]
163
        call    .bottom_border
164
        mov     edi, dword [esi+8]
165
        call    .right_border
166
        mov     edi, dword [esi+12]
167
        call    .left_border
168
        popad
169
        ret
1334 mikedld 170
 
4970 Akyltist 171
align 4
172
.top_border:
1334 mikedld 173
        mov     ebx, ecx
174
        shl     ebx, 16
4970 Akyltist 175
        mov     bx , cx
176
        mov     ecx, edi
1334 mikedld 177
        xor     edi, edi
2453 mario79 178
        call    __sys_draw_line
4970 Akyltist 179
        ret
1334 mikedld 180
 
4970 Akyltist 181
align 4
182
.bottom_border:
183
        add     bx , dx
184
        rol     ebx, 16
185
        add     bx , dx
186
        mov     ecx, edi
187
        xor     edi, edi
2453 mario79 188
        call    __sys_draw_line
4970 Akyltist 189
        ret
1334 mikedld 190
 
4970 Akyltist 191
align 4
192
.right_border:
193
        push    eax
194
        sub     bx, dx
195
        mov     cx, ax
196
        shl     eax, 16
197
        mov     ax, cx
198
        mov     ecx, edi
199
        xor     edi, edi
2453 mario79 200
        call    __sys_draw_line
4970 Akyltist 201
        pop     eax
202
        ret
1334 mikedld 203
 
4970 Akyltist 204
align 4
205
.left_border:
206
        shr     eax, 16
207
        mov     cx, ax
208
        shl     eax, 16
209
        mov     ax, cx
210
        mov     ecx, edi
211
        xor     edi, edi
2453 mario79 212
        call    __sys_draw_line
1334 mikedld 213
        ret
4970 Akyltist 214
align 4
215
.exit:
216
        ret
1334 mikedld 217
 
218
; FIXME: mutex needed
219
syscall_button.remove_button:
220
        and     edx, 0x00ffffff
221
        mov     edi, [BTN_ADDR]
222
        mov     ebx, [edi]
223
        inc     ebx
2384 hidnplayr 224
        imul    esi, ebx, sizeof.SYS_BUTTON
1334 mikedld 225
        add     esi, edi
226
        xor     ecx, ecx
2384 hidnplayr 227
        add     ecx, -sizeof.SYS_BUTTON
228
        add     esi, sizeof.SYS_BUTTON
1334 mikedld 229
 
230
  .next_button:
231
        dec     ebx
232
        jz      .exit
233
 
2384 hidnplayr 234
        add     ecx, sizeof.SYS_BUTTON
235
        add     esi, -sizeof.SYS_BUTTON
1334 mikedld 236
 
237
        ; does it belong to our process?
238
        mov     ax, [CURRENT_TASK]
239
        cmp     ax, [esi + SYS_BUTTON.pslot]
240
        jne     .next_button
241
 
242
        ; does the identifier match?
243
        mov     eax, dword[esi + SYS_BUTTON.id_hi - 2]
244
        mov     ax, [esi + SYS_BUTTON.id_lo]
245
        and     eax, 0x00ffffff
246
        cmp     edx, eax
247
        jne     .next_button
248
 
249
        ; okay, undefine it
1341 mikedld 250
        push    ebx
1334 mikedld 251
        mov     ebx, esi
2384 hidnplayr 252
        lea     eax, [esi + sizeof.SYS_BUTTON]
1334 mikedld 253
        call    memmove
254
        dec     dword[edi]
2384 hidnplayr 255
        add     ecx, -sizeof.SYS_BUTTON
1341 mikedld 256
        pop     ebx
1334 mikedld 257
        jmp     .next_button
258
 
259
  .exit:
260
        ret
261
 
262
align 4
263
;------------------------------------------------------------------------------
1391 mikedld 264
sys_button_activate_handler: ;/////////////////////////////////////////////////
1334 mikedld 265
;------------------------------------------------------------------------------
1362 mikedld 266
;? 
1334 mikedld 267
;------------------------------------------------------------------------------
1391 mikedld 268
;> eax = pack[8(process slot), 24(button id)]
269
;> ebx = pack[16(button x coord), 16(button y coord)]
270
;> cl = mouse button mask this system button was pressed with
271
;------------------------------------------------------------------------------
272
        call    button._.find_button
273
        or      eax, eax
274
        jz      .exit
1334 mikedld 275
 
1391 mikedld 276
        mov     ebx, dword[eax + SYS_BUTTON.id_hi - 2]
4970 Akyltist 277
        push    edi ; spam
278
        xor     edi, edi
1391 mikedld 279
        call    button._.negative_button
4970 Akyltist 280
        pop     edi
1391 mikedld 281
  .exit:
1334 mikedld 282
        ret
283
 
1391 mikedld 284
align 4
285
;------------------------------------------------------------------------------
286
sys_button_deactivate_handler: ;///////////////////////////////////////////////
287
;------------------------------------------------------------------------------
288
;? 
289
;------------------------------------------------------------------------------
290
;> eax = pack[8(process slot), 24(button id)]
291
;> ebx = pack[16(button x coord), 16(button y coord)]
292
;> cl = mouse button mask this system button was pressed with
293
;------------------------------------------------------------------------------
294
        call    button._.find_button
295
        or      eax, eax
296
        jz      .exit
1334 mikedld 297
 
1391 mikedld 298
        mov     ebx, dword[eax + SYS_BUTTON.id_hi - 2]
4970 Akyltist 299
        push    edi ; spam
300
        xor     edi, edi
301
        inc     edi
1334 mikedld 302
        call    button._.negative_button
4970 Akyltist 303
        pop     edi
1391 mikedld 304
  .exit:
305
        ret
1334 mikedld 306
 
1391 mikedld 307
align 4
308
;------------------------------------------------------------------------------
309
sys_button_perform_handler: ;//////////////////////////////////////////////////
310
;------------------------------------------------------------------------------
311
;? 
312
;------------------------------------------------------------------------------
313
;> eax = pack[8(process slot), 24(button id)]
314
;> ebx = pack[16(button x coord), 16(button y coord)]
315
;> cl = mouse button mask this system button was pressed with
316
;------------------------------------------------------------------------------
317
        shl     eax, 8
318
        mov     al, cl
319
        movzx   ebx, byte[BTN_COUNT]
320
        mov     [BTN_BUFF + ebx * 4], eax
321
        inc     bl
322
        mov     [BTN_COUNT], bl
323
        ret
1334 mikedld 324
 
1391 mikedld 325
;==============================================================================
326
;///// private functions //////////////////////////////////////////////////////
327
;==============================================================================
1334 mikedld 328
 
1391 mikedld 329
;------------------------------------------------------------------------------
330
button._.find_button: ;////////////////////////////////////////////////////////
331
;------------------------------------------------------------------------------
332
;? Find system button by specified process slot, id and coordinates
333
;------------------------------------------------------------------------------
334
;> eax = pack[8(process slot), 24(button id)] or 0
335
;> ebx = pack[16(button x coord), 16(button y coord)]
336
;------------------------------------------------------------------------------
337
;< eax = pointer to SYS_BUTTON struct or 0
338
;------------------------------------------------------------------------------
339
        push    ecx edx esi edi
1334 mikedld 340
 
1391 mikedld 341
        mov     edx, eax
342
        shr     edx, 24
343
        and     eax, 0x0ffffff
1334 mikedld 344
 
1391 mikedld 345
        mov     edi, [BTN_ADDR]
346
        mov     ecx, [edi]
2384 hidnplayr 347
        imul    esi, ecx, sizeof.SYS_BUTTON
1391 mikedld 348
        add     esi, edi
349
        inc     ecx
2384 hidnplayr 350
        add     esi, sizeof.SYS_BUTTON
1334 mikedld 351
 
1391 mikedld 352
  .next_button:
353
        dec     ecx
354
        jz      .not_found
1334 mikedld 355
 
2384 hidnplayr 356
        add     esi, -sizeof.SYS_BUTTON
1334 mikedld 357
 
1391 mikedld 358
        ; does it belong to our process?
359
        cmp     dx, [esi + SYS_BUTTON.pslot]
360
        jne     .next_button
1334 mikedld 361
 
1391 mikedld 362
        ; does id match?
363
        mov     edi, dword[esi + SYS_BUTTON.id_hi - 2]
364
        mov     di, [esi + SYS_BUTTON.id_lo]
365
        and     edi, 0x0ffffff
366
        cmp     eax, edi
367
        jne     .next_button
1334 mikedld 368
 
1391 mikedld 369
        ; does coordinates match?
370
        mov     edi, dword[esi + SYS_BUTTON.left - 2]
371
        mov     di, [esi + SYS_BUTTON.top]
372
        cmp     ebx, edi
373
        jne     .next_button
1334 mikedld 374
 
1391 mikedld 375
        ; okay, return it
376
        mov     eax, esi
377
        jmp     .exit
1334 mikedld 378
 
1391 mikedld 379
  .not_found:
380
        xor     eax, eax
1334 mikedld 381
 
1391 mikedld 382
  .exit:
383
        pop     edi esi edx ecx
1334 mikedld 384
        ret
385
 
386
;------------------------------------------------------------------------------
4970 Akyltist 387
button._.button_dececx: ;//////////////////////////////////////////////////////
1334 mikedld 388
;------------------------------------------------------------------------------
1362 mikedld 389
;? 
1334 mikedld 390
;------------------------------------------------------------------------------
4970 Akyltist 391
        cmp     [buttontype], 1
392
        jne     .finish
393
 
394
        push    eax
395
        mov     al, 1
396
        ;cmp     edi, 20
397
        ;jg      @f
398
        ;mov     al, 2
399
 
400
    @@:
401
        sub     cl, al
1334 mikedld 402
        jnc     @f
403
        xor     cl, cl
2288 clevermous 404
    @@:
4970 Akyltist 405
        sub     ch, al
1334 mikedld 406
        jnc     @f
407
        xor     ch, ch
2288 clevermous 408
    @@:
409
        rol     ecx, 16
4970 Akyltist 410
        sub     cl, al
1334 mikedld 411
        jnc     @f
412
        xor     cl, cl
2288 clevermous 413
    @@:
414
        rol     ecx, 16
1334 mikedld 415
 
4970 Akyltist 416
        pop     eax
417
 
418
  .finish:
1334 mikedld 419
        ret
420
;------------------------------------------------------------------------------
4970 Akyltist 421
button._.incecx: ;////////////////////////////////////////////////////////////
1334 mikedld 422
;------------------------------------------------------------------------------
1362 mikedld 423
;? 
1334 mikedld 424
;------------------------------------------------------------------------------
425
        add     cl, 0x14
426
        jnc     @f
427
        or      cl, -1
2288 clevermous 428
    @@:
429
        add     ch, 0x14
1334 mikedld 430
        jnc     @f
431
        or      ch, -1
2288 clevermous 432
    @@:
433
        rol     ecx, 16
1334 mikedld 434
        add     cl, 0x14
435
        jnc     @f
436
        or      cl, -1
2288 clevermous 437
    @@:
438
        rol     ecx, 16
1334 mikedld 439
        ret
440
;------------------------------------------------------------------------------
4970 Akyltist 441
button._.button_calc_relativ: ;
1334 mikedld 442
;------------------------------------------------------------------------------
1362 mikedld 443
;? 
1334 mikedld 444
;------------------------------------------------------------------------------
4970 Akyltist 445
        movzx   edx, cx
446
        dec     edx        ; get height
447
        shr     ebx, 16
448
        shr     ecx, 16
449
        mov     eax, [TASK_BASE]
450
        add     ebx, [eax - twdw + WDATA.box.left]
451
        add     ecx, [eax - twdw + WDATA.box.top]
452
        mov     eax, ebx
453
        shl     eax, 16
454
        mov     ax, bx
455
        add     ax, word[esp + 20]
456
        dec     eax
457
        mov     bx, cx
458
        shl     ebx, 16
459
        mov     bx, cx
1334 mikedld 460
        ret
461
 
462
;------------------------------------------------------------------------------
463
button._.negative_button: ;////////////////////////////////////////////////////
464
;------------------------------------------------------------------------------
1391 mikedld 465
;? Invert system button border
4970 Akyltist 466
; edi - 0 activate, 1 - deactivate
1334 mikedld 467
;------------------------------------------------------------------------------
1362 mikedld 468
        ; if requested, do not display button border on press.
1334 mikedld 469
        test    ebx, 0x20000000
1362 mikedld 470
        jnz     .exit
1334 mikedld 471
 
472
        pushad
4970 Akyltist 473
        push    ebx
1362 mikedld 474
        xchg    esi, eax
1334 mikedld 475
 
1362 mikedld 476
        movzx   ecx, [esi + SYS_BUTTON.pslot]
477
        shl     ecx, 5
478
        add     ecx, window_data
1334 mikedld 479
 
1362 mikedld 480
        mov     eax, dword[esi + SYS_BUTTON.left]
481
        mov     ebx, dword[esi + SYS_BUTTON.top]
482
        add     eax, [ecx + WDATA.box.left]
483
        add     ebx, [ecx + WDATA.box.top]
484
        push    eax ebx
485
        pop     edx ecx
486
        rol     eax, 16
487
        rol     ebx, 16
488
        add     ax, cx
489
        add     bx, dx
1334 mikedld 490
 
4970 Akyltist 491
        xor     edx, edx
492
        mov     dx, [esi + SYS_BUTTON.id_lo]
493
 
494
        cmp     dx, 1
495
        jne     .no_close
496
        sub     eax, 0x00010001
497
        dec     ebx
1362 mikedld 498
        mov     esi, 0x01000000
499
        call    draw_rectangle.forced
4970 Akyltist 500
        jmp     .fade
501
align 4
502
.no_close:
503
        cmp     dx, 65535
504
        jne     .no_mini
505
        sub     eax, 0x00010001
506
        dec     ebx
507
        mov     esi, 0x01000000
508
        call    draw_rectangle.forced
509
        jmp     .fade
510
align 4
511
.no_mini:
512
        add     eax, 0x00010000
513
        add     ebx, 0x00010000
514
        pop     edx
515
        test    edx, 0x10000000
516
        jnz     .only_frame
517
        mov     edx, common_colours
518
        mov     esi, dword [edx+12]
519
        cmp     edi, 0
520
        jne     .shadow
521
        mov     esi, dword [edx+8]
522
align 4
523
.shadow:
524
        call    draw_rectangle.forced
525
align 4
526
.only_frame:
527
        mov     edx, common_colours
528
        sub     eax, 0x00010000
529
        sub     ebx, 0x00010000
530
        mov     esi, dword [edx+104]
531
        cmp     edi, 0
532
        jne     .draw
533
        mov     esi, dword [edx+112]
534
align 4
535
.draw:
536
        call    draw_rectangle.forced
1362 mikedld 537
        popad
1334 mikedld 538
        ret
4970 Akyltist 539
align 4
540
.fade:
541
        pop     ebx
542
        popad
543
align 4
544
.exit:
545
        ret