Subversion Repositories Kolibri OS

Rev

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

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