Subversion Repositories Kolibri OS

Rev

Rev 9926 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1334 mikedld 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
6035 pathoswith 3
;; Copyright (C) KolibriOS team 2004-2016. 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: 9941 $
10
 
1391 mikedld 11
button.MAX_BUTTONS = 4095
12
 
2384 hidnplayr 13
struct  SYS_BUTTON
14
        pslot           dw ?
15
        id_lo           dw ?
16
        left            dw ?
17
        width           dw ?
18
        top             dw ?
19
        height          dw ?
20
        id_hi           dw ?
21
                        dw ?
22
ends
6031 pathoswith 23
;---------------------------------------------------------------
9911 Doczom 24
align 4
25
; @brief system function 17 - Get the identifier of the pressed button
26
; @param eax 17 - number function
27
; @return  eax = 1 - buffer empty,
28
;          eax = high 24 bits contain button identifier,
29
;          al = 0 - the button was pressed with left mouse button,
30
;          al = bit corresponding to used mouse button otherwise
31
sys_getbutton:
32
        mov     ebx, [current_slot_idx]    ; TOP OF WINDOW STACK
33
        mov     [esp + SYSCALL_STACK.eax], dword 1
34
        movzx   ecx, word [WIN_STACK + ebx * 2]
35
        mov     edx, [thread_count] ; less than 256 processes
36
        cmp     ecx, edx
37
        jne     .exit
38
        movzx   eax, byte [BTN_COUNT]
39
        test    eax, eax
40
        jz      .exit
41
        mov     eax, [BTN_BUFF]
42
        and     al, 0xFE                ; delete left button bit
43
        mov     [BTN_COUNT], byte 0
44
        mov     [esp + SYSCALL_STACK.eax], eax
45
;--------------------------------------
46
align 4
47
.exit:
48
        ret
6031 pathoswith 49
;---------------------------------------------------------------
9911 Doczom 50
; @brief system function 8 - define/delete the button
51
; @param eax = 8 - number function
52
; @param ebx = [offset_x]*65536 + [width]
53
; @param ecx = [offset_y]*65536 + [height]
54
; @param edx = 0xXYnnnnnn, where:
55
;        nnnnnn = identifier of the button
56
;        31 bit - delete button
57
;        30 bit - don't draw button
58
;        29 bit - don't draw button frame when pressed
59
; @param esi = 0x00RRGGBB - button color
60
; @return  function does not return value
61
syscall_button:
62
;---------------------------------------------------------------
1362 mikedld 63
;? Define/undefine GUI button object
6031 pathoswith 64
;---------------------------------------------------------------
1362 mikedld 65
;; Define button:
66
;> ebx = pack[16(x), 16(width)]
67
;> ecx = pack[16(y), 16(height)]
68
;> edx = pack[8(flags), 24(button identifier)]
69
;>       flags bits:
70
;>          7 (31) = 0
71
;>          6 (30) = don't draw button
72
;>          5 (29) = don't draw button frame when pressed
73
;> esi = button color
6031 pathoswith 74
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1362 mikedld 75
;; Undefine button:
76
;> edx = pack[8(flags), 24(button identifier)]
77
;>       flags bits:
78
;>          7 (31) = 1
6031 pathoswith 79
;---------------------------------------------------------------
1334 mikedld 80
        ; do we actually need to undefine the button?
81
        test    edx, 0x80000000
82
        jnz     .remove_button
83
 
84
        ; do we have free button slots available?
85
        mov     edi, [BTN_ADDR]
86
        mov     eax, [edi]
1391 mikedld 87
        cmp     eax, button.MAX_BUTTONS
1334 mikedld 88
        jge     .exit
89
 
90
        ; does it have positive size? (otherwise it doesn't have sense)
91
        or      bx, bx
92
        jle     .exit
93
        or      cx, cx
94
        jle     .exit
95
 
96
        ; make coordinates clientbox-relative
97
        push    eax
9941 Doczom 98
        mov     eax, [current_slot]
99
        mov     eax, [eax + APPDATA.window]
1334 mikedld 100
        rol     ebx, 16
9941 Doczom 101
        add     bx, word[eax + WDATA.clientbox.left]
1334 mikedld 102
        rol     ebx, 16
103
        rol     ecx, 16
9941 Doczom 104
        add     cx, word[eax + WDATA.clientbox.top]
1334 mikedld 105
        rol     ecx, 16
106
        pop     eax
107
 
108
        ; basic checks passed, define the button
109
        inc     eax
110
        mov     [edi], ax
111
        shl     eax, 4
112
        add     edi, eax
6031 pathoswith 113
; NOTE: this code doesn't rely on SYS_BUTTON struct,
114
; please revise it, if you change something.
8869 rgimad 115
        mov     ax, word [current_slot_idx]
1334 mikedld 116
        stosw
117
        mov     ax, dx
118
        stosw               ; button id number: bits 0-15
119
        mov     eax, ebx
120
        rol     eax, 16
121
        stosd               ; x start | x size
122
        mov     eax, ecx
123
        rol     eax, 16
124
        stosd               ; y start | y size
125
        mov     eax, edx
126
        shr     eax, 16
127
        stosw               ; button id number: bits 16-31
128
 
129
        ; do we also need to draw the button?
130
        test    edx, 0x40000000
131
        jnz     .exit
132
 
6032 pathoswith 133
        and     esi, 0xFFFFFF
6031 pathoswith 134
        xor     edi, edi
135
        push    ebx ecx esi
6032 pathoswith 136
        dec     cx
137
        dec     cx
6031 pathoswith 138
        cmp     [buttontype], 1
139
        jnz     .draw
6032 pathoswith 140
        cmp     cx, 65
6031 pathoswith 141
        jnc     .draw
5185 mario79 142
 
6031 pathoswith 143
        ; calculate gradient data
144
        mov     eax, esi
145
        shl     eax, 8
146
        mov     edx, 3
147
.calculate:
148
        rol     eax, 8
149
        shl     al, 1
150
        jnc     @f
151
        neg     al
152
        jnz     @f
6032 pathoswith 153
        mov     al, 64
6031 pathoswith 154
@@:
6032 pathoswith 155
        cmp     al, 65
156
        jc      @f
157
        mov     al, 64
6031 pathoswith 158
@@:
159
        div     cl
160
        shl     ax, 8
161
        dec     edx
162
        jnz     .calculate
163
        mov     dl, cl
164
        dec     edx
165
        shr     edx, 1
166
        shr     eax, 8
167
        mov     edi, eax
168
        mul     edx
169
        add     esi, eax
5185 mario79 170
 
6031 pathoswith 171
.draw:  ; calculate window-relative coordinates
172
        movzx   ebp, cx
173
        dec     ebp
5185 mario79 174
        shr     ebx, 16
175
        shr     ecx, 16
9941 Doczom 176
        mov     eax, [current_slot]
177
        mov     eax, [eax + APPDATA.window]
178
        add     ebx, [eax + WDATA.box.left]
179
        add     ecx, [eax + WDATA.box.top]
5185 mario79 180
        mov     eax, ebx
5580 leency 181
        inc     eax
6031 pathoswith 182
        mov     edx, ebx
183
        add     dx, [esp+8]
184
        dec     edx
5185 mario79 185
        mov     ebx, ecx
1334 mikedld 186
        mov     ecx, esi
6031 pathoswith 187
        shr     ecx, 1
6032 pathoswith 188
        and     cx, 7F7Fh
6031 pathoswith 189
        push    esi
190
        mov     esi, edi
5185 mario79 191
        xor     edi, edi
6031 pathoswith 192
        call    hline   ; top border
193
        inc     ebx
6032 pathoswith 194
        or      ecx, 808080h
195
        call    hline   ; top light line
6031 pathoswith 196
        pop     ecx
6032 pathoswith 197
        inc     ebx
6031 pathoswith 198
.next_line:
199
        call    hline   ; button body
200
        inc     ebx
201
        sub     ecx, esi
202
        dec     ebp
1334 mikedld 203
        jnz     .next_line
6032 pathoswith 204
        shr     ecx, 2
205
        and     cx, 3F3Fh
206
        mov     ebp, ecx
207
        shl     ecx, 1
208
        add     ecx, ebp
209
        call    hline   ; bottom dark line
210
        inc     ebx
211
        sub     ecx, ebp
6031 pathoswith 212
        call    hline   ; bottom border
213
        pop     ecx
214
        shr     ecx, 1
215
        inc     edx
5185 mario79 216
        push    edx
217
        mov     edx, ebx
6031 pathoswith 218
        sub     bx, [esp+4]
6032 pathoswith 219
        dec     edx
220
        inc     ebx
221
        cmp     [buttontype], 0
6031 pathoswith 222
        jnz     @f
223
        dec     edx
6032 pathoswith 224
        or      ecx, 808080h
225
        call    vline   ; left light line
226
        inc     edx
6031 pathoswith 227
@@:
6032 pathoswith 228
        and     ecx, 7F7F7Fh
229
        dec     eax
6031 pathoswith 230
        call    vline   ; left border
231
        pop     eax
232
        call    vline   ; right border
6032 pathoswith 233
        cmp     [buttontype], 0
234
        jnz     @f
235
        mov     ebp, ecx
236
        shr     ecx, 1
237
        and     cx, 7F7Fh
238
        add     ecx, ebp
239
        dec     eax
240
        inc     ebx
8926 leency 241
        dec     edx     ; avoid lines overflow
6032 pathoswith 242
        call    vline   ; right dark line
243
@@:
5185 mario79 244
        pop     ecx ebx
6031 pathoswith 245
.exit:
1334 mikedld 246
        ret
247
 
248
; FIXME: mutex needed
6031 pathoswith 249
.remove_button:
1334 mikedld 250
        and     edx, 0x00ffffff
251
        mov     edi, [BTN_ADDR]
252
        mov     ebx, [edi]
253
        inc     ebx
2384 hidnplayr 254
        imul    esi, ebx, sizeof.SYS_BUTTON
1334 mikedld 255
        add     esi, edi
256
        xor     ecx, ecx
2384 hidnplayr 257
        add     ecx, -sizeof.SYS_BUTTON
258
        add     esi, sizeof.SYS_BUTTON
1334 mikedld 259
 
6031 pathoswith 260
.next_button:
1334 mikedld 261
        dec     ebx
262
        jz      .exit
263
 
2384 hidnplayr 264
        add     ecx, sizeof.SYS_BUTTON
265
        add     esi, -sizeof.SYS_BUTTON
1334 mikedld 266
 
267
        ; does it belong to our process?
8869 rgimad 268
        mov     ax, word [current_slot_idx]
1334 mikedld 269
        cmp     ax, [esi + SYS_BUTTON.pslot]
270
        jne     .next_button
271
 
272
        ; does the identifier match?
273
        mov     eax, dword[esi + SYS_BUTTON.id_hi - 2]
274
        mov     ax, [esi + SYS_BUTTON.id_lo]
275
        and     eax, 0x00ffffff
276
        cmp     edx, eax
277
        jne     .next_button
278
 
279
        ; okay, undefine it
1341 mikedld 280
        push    ebx
1334 mikedld 281
        mov     ebx, esi
2384 hidnplayr 282
        lea     eax, [esi + sizeof.SYS_BUTTON]
1334 mikedld 283
        call    memmove
284
        dec     dword[edi]
2384 hidnplayr 285
        add     ecx, -sizeof.SYS_BUTTON
1341 mikedld 286
        pop     ebx
1334 mikedld 287
        jmp     .next_button
288
 
6031 pathoswith 289
;---------------------------------------------------------------
290
sys_button_activate_handler:
291
sys_button_deactivate_handler:
292
;---------------------------------------------------------------
1391 mikedld 293
;> eax = pack[8(process slot), 24(button id)]
294
;> ebx = pack[16(button x coord), 16(button y coord)]
295
;> cl = mouse button mask this system button was pressed with
6031 pathoswith 296
;---------------------------------------------------------------
297
; find system button by specified process slot, id and coordinates
1391 mikedld 298
        push    ecx edx esi edi
299
        mov     edx, eax
300
        shr     edx, 24
301
        and     eax, 0x0ffffff
302
        mov     edi, [BTN_ADDR]
303
        mov     ecx, [edi]
2384 hidnplayr 304
        imul    esi, ecx, sizeof.SYS_BUTTON
1391 mikedld 305
        add     esi, edi
306
        inc     ecx
2384 hidnplayr 307
        add     esi, sizeof.SYS_BUTTON
6031 pathoswith 308
.next_button:
1391 mikedld 309
        dec     ecx
6031 pathoswith 310
        jz      .popexit
2384 hidnplayr 311
        add     esi, -sizeof.SYS_BUTTON
1334 mikedld 312
 
1391 mikedld 313
        ; does it belong to our process?
314
        cmp     dx, [esi + SYS_BUTTON.pslot]
315
        jne     .next_button
1334 mikedld 316
 
1391 mikedld 317
        ; does id match?
318
        mov     edi, dword[esi + SYS_BUTTON.id_hi - 2]
319
        mov     di, [esi + SYS_BUTTON.id_lo]
320
        and     edi, 0x0ffffff
321
        cmp     eax, edi
322
        jne     .next_button
1334 mikedld 323
 
1391 mikedld 324
        ; does coordinates match?
325
        mov     edi, dword[esi + SYS_BUTTON.left - 2]
326
        mov     di, [esi + SYS_BUTTON.top]
327
        cmp     ebx, edi
328
        jne     .next_button
1334 mikedld 329
 
1391 mikedld 330
        mov     eax, esi
331
        pop     edi esi edx ecx
6031 pathoswith 332
        mov     ebx, dword[eax + SYS_BUTTON.id_hi - 2]
1334 mikedld 333
 
6031 pathoswith 334
        ; display button border on press?
6044 pathoswith 335
        bt      ebx, 29
336
        jc      .exit
1334 mikedld 337
 
6031 pathoswith 338
        ; invert system button border
1334 mikedld 339
        pushad
6031 pathoswith 340
        mov     esi, eax
6044 pathoswith 341
        mov     edi, ebx
1362 mikedld 342
        movzx   ecx, [esi + SYS_BUTTON.pslot]
9926 Doczom 343
        shl     ecx, BSF sizeof.WDATA
1362 mikedld 344
        mov     eax, dword[esi + SYS_BUTTON.left]
345
        mov     ebx, dword[esi + SYS_BUTTON.top]
9926 Doczom 346
        add     eax, [window_data + ecx + WDATA.box.left]
347
        add     ebx, [window_data + ecx + WDATA.box.top]
6035 pathoswith 348
        mov     ecx, eax
349
        mov     edx, ebx
6044 pathoswith 350
        bt      edi, 30
351
        jc      @f
6035 pathoswith 352
        inc     ax
353
        inc     bx
6044 pathoswith 354
        dec     cx
355
        dec     dx
356
@@:
1362 mikedld 357
        rol     eax, 16
358
        rol     ebx, 16
6035 pathoswith 359
        add     ax, cx
360
        add     bx, dx
361
        mov     esi, 1000000h
362
        call    draw_rectangle.forced
1362 mikedld 363
        popad
6031 pathoswith 364
.exit:
365
        ret
366
.popexit:
367
        pop     edi esi edx ecx
368
        ret
5185 mario79 369
 
6031 pathoswith 370
;---------------------------------------------------------------
371
sys_button_perform_handler:
372
;---------------------------------------------------------------
373
;> eax = pack[8(process slot), 24(button id)]
374
;> ebx = pack[16(button x coord), 16(button y coord)]
375
;> cl = mouse button mask this system button was pressed with
376
;---------------------------------------------------------------
377
        shl     eax, 8
378
        mov     al, cl
379
        movzx   ebx, byte[BTN_COUNT]
380
        mov     [BTN_BUFF + ebx * 4], eax
381
        inc     bl
382
        mov     [BTN_COUNT], bl
1334 mikedld 383
        ret