Subversion Repositories Kolibri OS

Rev

Rev 8926 | Rev 9911 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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