Subversion Repositories Kolibri OS

Rev

Rev 6009 | Rev 6032 | 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: 6031 $
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
1334 mikedld 23
 
6031 pathoswith 24
;---------------------------------------------------------------
25
syscall_button: ;////////////// system function 8 //////////////
26
;---------------------------------------------------------------
1362 mikedld 27
;? Define/undefine GUI button object
6031 pathoswith 28
;---------------------------------------------------------------
1362 mikedld 29
;; Define button:
30
;> ebx = pack[16(x), 16(width)]
31
;> ecx = pack[16(y), 16(height)]
32
;> edx = pack[8(flags), 24(button identifier)]
33
;>       flags bits:
34
;>          7 (31) = 0
35
;>          6 (30) = don't draw button
36
;>          5 (29) = don't draw button frame when pressed
37
;> esi = button color
6031 pathoswith 38
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1362 mikedld 39
;; Undefine button:
40
;> edx = pack[8(flags), 24(button identifier)]
41
;>       flags bits:
42
;>          7 (31) = 1
6031 pathoswith 43
;---------------------------------------------------------------
1334 mikedld 44
        ; do we actually need to undefine the button?
45
        test    edx, 0x80000000
46
        jnz     .remove_button
47
 
48
        ; do we have free button slots available?
49
        mov     edi, [BTN_ADDR]
50
        mov     eax, [edi]
1391 mikedld 51
        cmp     eax, button.MAX_BUTTONS
1334 mikedld 52
        jge     .exit
53
 
54
        ; does it have positive size? (otherwise it doesn't have sense)
55
        or      bx, bx
56
        jle     .exit
57
        or      cx, cx
58
        jle     .exit
59
 
60
        ; make coordinates clientbox-relative
61
        push    eax
62
        mov     eax, [current_slot]
63
        rol     ebx, 16
64
        add     bx, word[eax + APPDATA.wnd_clientbox.left]
65
        rol     ebx, 16
66
        rol     ecx, 16
67
        add     cx, word[eax + APPDATA.wnd_clientbox.top]
68
        rol     ecx, 16
69
        pop     eax
70
 
71
        ; basic checks passed, define the button
72
        inc     eax
73
        mov     [edi], ax
74
        shl     eax, 4
75
        add     edi, eax
6031 pathoswith 76
; NOTE: this code doesn't rely on SYS_BUTTON struct,
77
; please revise it, if you change something.
1334 mikedld 78
        mov     ax, [CURRENT_TASK]
79
        stosw
80
        mov     ax, dx
81
        stosw               ; button id number: bits 0-15
82
        mov     eax, ebx
83
        rol     eax, 16
84
        stosd               ; x start | x size
85
        mov     eax, ecx
86
        rol     eax, 16
87
        stosd               ; y start | y size
88
        mov     eax, edx
89
        shr     eax, 16
90
        stosw               ; button id number: bits 16-31
91
 
92
        ; do we also need to draw the button?
93
        test    edx, 0x40000000
94
        jnz     .exit
95
 
6031 pathoswith 96
        xor     edi, edi
97
        push    ebx ecx esi
98
        cmp     [buttontype], 1
99
        jnz     .draw
100
        cmp     cx, 129
101
        jnc     .draw
5185 mario79 102
 
6031 pathoswith 103
        ; calculate gradient data
104
        mov     eax, esi
105
        shl     eax, 8
106
        mov     edx, 3
107
.calculate:
108
        rol     eax, 8
109
        shl     al, 1
110
        jnc     @f
111
        neg     al
112
        jnz     @f
113
        mov     al, 128
114
@@:
115
        jns     @f
116
        mov     al, 128
117
@@:
118
        div     cl
119
        shl     ax, 8
120
        dec     edx
121
        jnz     .calculate
122
        mov     dl, cl
123
        dec     edx
124
        shr     edx, 1
125
        shr     eax, 8
126
        mov     edi, eax
127
        mul     edx
128
        add     esi, eax
5185 mario79 129
 
6031 pathoswith 130
.draw:  ; calculate window-relative coordinates
131
        movzx   ebp, cx
132
        dec     ebp
5185 mario79 133
        shr     ebx, 16
134
        shr     ecx, 16
135
        mov     eax, [TASK_BASE]
136
        add     ebx, [eax - twdw + WDATA.box.left]
137
        add     ecx, [eax - twdw + WDATA.box.top]
138
        mov     eax, ebx
5580 leency 139
        inc     eax
6031 pathoswith 140
        mov     edx, ebx
141
        add     dx, [esp+8]
142
        dec     edx
5185 mario79 143
        mov     ebx, ecx
1334 mikedld 144
        mov     ecx, esi
6031 pathoswith 145
        shr     ecx, 1
146
        btr     ecx, 7
147
        btr     ecx, 15
148
        push    esi
149
        mov     esi, edi
5185 mario79 150
        xor     edi, edi
6031 pathoswith 151
        call    hline   ; top border
152
        inc     ebx
153
        pop     ecx
154
.next_line:
155
        call    hline   ; button body
156
        inc     ebx
157
        sub     ecx, esi
158
        dec     ebp
1334 mikedld 159
        jnz     .next_line
6031 pathoswith 160
        shr     ecx, 1
161
        btr     ecx, 7
162
        btr     ecx, 15
163
        call    hline   ; bottom border
164
        pop     ecx
165
        shr     ecx, 1
166
        btr     ecx, 7
167
        btr     ecx, 15
168
        inc     edx
5185 mario79 169
        push    edx
170
        mov     edx, ebx
6031 pathoswith 171
        sub     bx, [esp+4]
172
        dec     eax
173
        cmp     [buttontype], 1
174
        jnz     @f
175
        dec     edx
176
        inc     ebx
177
@@:
178
        call    vline   ; left border
179
        pop     eax
180
        call    vline   ; right border
5185 mario79 181
        pop     ecx ebx
6031 pathoswith 182
.exit:
1334 mikedld 183
        ret
184
 
185
; FIXME: mutex needed
6031 pathoswith 186
.remove_button:
1334 mikedld 187
        and     edx, 0x00ffffff
188
        mov     edi, [BTN_ADDR]
189
        mov     ebx, [edi]
190
        inc     ebx
2384 hidnplayr 191
        imul    esi, ebx, sizeof.SYS_BUTTON
1334 mikedld 192
        add     esi, edi
193
        xor     ecx, ecx
2384 hidnplayr 194
        add     ecx, -sizeof.SYS_BUTTON
195
        add     esi, sizeof.SYS_BUTTON
1334 mikedld 196
 
6031 pathoswith 197
.next_button:
1334 mikedld 198
        dec     ebx
199
        jz      .exit
200
 
2384 hidnplayr 201
        add     ecx, sizeof.SYS_BUTTON
202
        add     esi, -sizeof.SYS_BUTTON
1334 mikedld 203
 
204
        ; does it belong to our process?
205
        mov     ax, [CURRENT_TASK]
206
        cmp     ax, [esi + SYS_BUTTON.pslot]
207
        jne     .next_button
208
 
209
        ; does the identifier match?
210
        mov     eax, dword[esi + SYS_BUTTON.id_hi - 2]
211
        mov     ax, [esi + SYS_BUTTON.id_lo]
212
        and     eax, 0x00ffffff
213
        cmp     edx, eax
214
        jne     .next_button
215
 
216
        ; okay, undefine it
1341 mikedld 217
        push    ebx
1334 mikedld 218
        mov     ebx, esi
2384 hidnplayr 219
        lea     eax, [esi + sizeof.SYS_BUTTON]
1334 mikedld 220
        call    memmove
221
        dec     dword[edi]
2384 hidnplayr 222
        add     ecx, -sizeof.SYS_BUTTON
1341 mikedld 223
        pop     ebx
1334 mikedld 224
        jmp     .next_button
225
 
6031 pathoswith 226
;---------------------------------------------------------------
227
sys_button_activate_handler:
228
sys_button_deactivate_handler:
229
;---------------------------------------------------------------
1391 mikedld 230
;> eax = pack[8(process slot), 24(button id)]
231
;> ebx = pack[16(button x coord), 16(button y coord)]
232
;> cl = mouse button mask this system button was pressed with
6031 pathoswith 233
;---------------------------------------------------------------
234
; find system button by specified process slot, id and coordinates
1391 mikedld 235
        push    ecx edx esi edi
236
        mov     edx, eax
237
        shr     edx, 24
238
        and     eax, 0x0ffffff
239
        mov     edi, [BTN_ADDR]
240
        mov     ecx, [edi]
2384 hidnplayr 241
        imul    esi, ecx, sizeof.SYS_BUTTON
1391 mikedld 242
        add     esi, edi
243
        inc     ecx
2384 hidnplayr 244
        add     esi, sizeof.SYS_BUTTON
6031 pathoswith 245
.next_button:
1391 mikedld 246
        dec     ecx
6031 pathoswith 247
        jz      .popexit
2384 hidnplayr 248
        add     esi, -sizeof.SYS_BUTTON
1334 mikedld 249
 
1391 mikedld 250
        ; does it belong to our process?
251
        cmp     dx, [esi + SYS_BUTTON.pslot]
252
        jne     .next_button
1334 mikedld 253
 
1391 mikedld 254
        ; does id match?
255
        mov     edi, dword[esi + SYS_BUTTON.id_hi - 2]
256
        mov     di, [esi + SYS_BUTTON.id_lo]
257
        and     edi, 0x0ffffff
258
        cmp     eax, edi
259
        jne     .next_button
1334 mikedld 260
 
1391 mikedld 261
        ; does coordinates match?
262
        mov     edi, dword[esi + SYS_BUTTON.left - 2]
263
        mov     di, [esi + SYS_BUTTON.top]
264
        cmp     ebx, edi
265
        jne     .next_button
1334 mikedld 266
 
1391 mikedld 267
        mov     eax, esi
268
        pop     edi esi edx ecx
6031 pathoswith 269
        mov     ebx, dword[eax + SYS_BUTTON.id_hi - 2]
1334 mikedld 270
 
6031 pathoswith 271
        ; display button border on press?
1334 mikedld 272
        test    ebx, 0x20000000
1362 mikedld 273
        jnz     .exit
1334 mikedld 274
 
6031 pathoswith 275
        ; invert system button border
1334 mikedld 276
        pushad
6031 pathoswith 277
        mov     esi, eax
1362 mikedld 278
        movzx   ecx, [esi + SYS_BUTTON.pslot]
279
        shl     ecx, 5
280
        add     ecx, window_data
281
        mov     eax, dword[esi + SYS_BUTTON.left]
282
        mov     ebx, dword[esi + SYS_BUTTON.top]
283
        add     eax, [ecx + WDATA.box.left]
284
        add     ebx, [ecx + WDATA.box.top]
285
        rol     eax, 16
286
        rol     ebx, 16
6031 pathoswith 287
        push    eax ebx
288
        shr     eax, 16
289
        shr     ebx, 16
290
        mov     edx, eax
291
        add     dx, [esp+4]
292
        dec     edx
293
        inc     eax
294
        mov     ecx, 1000000h
295
        xor     edi, edi
296
        inc     edi
297
        call    hline
298
        add     bx, [esp]
299
        call    hline
300
        inc     edx
301
        push    edx
302
        mov     edx, ebx
303
        sub     bx, [esp+4]
304
        dec     eax
305
        cmp     [buttontype], 1
306
        jnz     @f
307
        dec     edx
308
        inc     ebx
309
@@:
310
        call    vline
311
        pop     eax
312
        call    vline
313
        pop     eax eax
1362 mikedld 314
        popad
6031 pathoswith 315
.exit:
316
        ret
317
.popexit:
318
        pop     edi esi edx ecx
319
        ret
5185 mario79 320
 
6031 pathoswith 321
;---------------------------------------------------------------
322
sys_button_perform_handler:
323
;---------------------------------------------------------------
324
;> eax = pack[8(process slot), 24(button id)]
325
;> ebx = pack[16(button x coord), 16(button y coord)]
326
;> cl = mouse button mask this system button was pressed with
327
;---------------------------------------------------------------
328
        shl     eax, 8
329
        mov     al, cl
330
        movzx   ebx, byte[BTN_COUNT]
331
        mov     [BTN_BUFF + ebx * 4], eax
332
        inc     bl
333
        mov     [BTN_COUNT], bl
1334 mikedld 334
        ret