Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1391 mikedld 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
10051 ace_dent 3
;; Copyright (C) KolibriOS team 2010-2024. All rights reserved. ;;
1391 mikedld 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
 
5851 pathoswith 9
;================================
10
;/////// public functions ///////
11
;================================
1391 mikedld 12
 
13
mouse.LEFT_BUTTON_FLAG   = 0001b
14
mouse.RIGHT_BUTTON_FLAG  = 0010b
15
mouse.MIDDLE_BUTTON_FLAG = 0100b
16
 
17
mouse.BUTTONS_MASK = \
18
  mouse.LEFT_BUTTON_FLAG or \
19
  mouse.RIGHT_BUTTON_FLAG or \
20
  mouse.MIDDLE_BUTTON_FLAG
21
 
22
mouse.WINDOW_RESIZE_N_FLAG = 000001b
23
mouse.WINDOW_RESIZE_W_FLAG = 000010b
24
mouse.WINDOW_RESIZE_S_FLAG = 000100b
25
mouse.WINDOW_RESIZE_E_FLAG = 001000b
26
mouse.WINDOW_MOVE_FLAG     = 010000b
27
 
28
mouse.WINDOW_RESIZE_SW_FLAG = \
29
  mouse.WINDOW_RESIZE_S_FLAG or \
30
  mouse.WINDOW_RESIZE_W_FLAG
31
mouse.WINDOW_RESIZE_SE_FLAG = \
32
  mouse.WINDOW_RESIZE_S_FLAG or \
33
  mouse.WINDOW_RESIZE_E_FLAG
34
 
35
align 4
5851 pathoswith 36
;-----------------------------------------------------------------
37
mouse_check_events:
38
; Check if mouse buttons state or cursor position has changed
1391 mikedld 39
        push    eax ebx
40
        mov     al, [BTN_DOWN]
41
        mov     bl, [mouse.state.buttons]
42
        and     al, mouse.BUTTONS_MASK
43
        mov     cl, al
44
        xchg    cl, [mouse.state.buttons]
45
        xor     bl, al
46
        push    eax ebx
47
 
48
        ; did any mouse button changed its state?
49
        or      bl, bl
50
        jz      .check_position
51
 
52
        ; yes it did, is that the first button of all pressed down?
53
        or      cl, cl
54
        jnz     .check_buttons_released
55
 
56
        ; yes it is, activate window user is pointing at, if needed
57
        call    mouse._.activate_sys_window_under_cursor
58
 
59
        ; is there any system button under cursor?
2288 clevermous 60
        call    mouse._.find_sys_button_under_cursor
1391 mikedld 61
        or      eax, eax
62
        jz      .check_buttons_released
63
 
64
        ; yes there is, activate it and exit
65
        mov     [mouse.active_sys_button.pbid], eax
66
        mov     [mouse.active_sys_button.coord], ebx
67
        mov     cl, [mouse.state.buttons]
68
        mov     [mouse.active_sys_button.buttons], cl
69
        call    sys_button_activate_handler
70
        jmp     .exit
71
 
72
  .check_buttons_released:
73
        cmp     [mouse.state.buttons], 0
74
        jnz     .buttons_changed
75
 
76
        ; did we press some button earlier?
77
        cmp     [mouse.active_sys_button.pbid], 0
78
        je      .buttons_changed
79
 
80
        ; yes we did, deactivate it
81
        xor     eax, eax
82
        xchg    eax, [mouse.active_sys_button.pbid]
83
        mov     ebx, [mouse.active_sys_button.coord]
84
        mov     cl, [mouse.active_sys_button.buttons]
85
        push    eax ebx
86
        call    sys_button_deactivate_handler
87
        pop     edx ecx
88
 
89
        ; is the button under cursor the one we deactivated?
90
        call    mouse._.find_sys_button_under_cursor
91
        cmp     eax, ecx
92
        jne     .exit
93
        cmp     ebx, edx
94
        jne     .exit
95
 
96
        ; yes it is, perform associated action
97
        mov     cl, [mouse.active_sys_button.buttons]
98
        call    sys_button_perform_handler
99
        jmp     .exit
100
 
101
  .buttons_changed:
102
        test    byte[esp], mouse.LEFT_BUTTON_FLAG
103
        jz      @f
104
        mov     eax, [esp + 4]
105
        call    .call_left_button_handler
106
 
2288 clevermous 107
    @@:
108
        test    byte[esp], mouse.RIGHT_BUTTON_FLAG
1391 mikedld 109
        jz      @f
110
        mov     eax, [esp + 4]
111
        call    .call_right_button_handler
112
 
2288 clevermous 113
    @@:
114
        test    byte[esp], mouse.MIDDLE_BUTTON_FLAG
1391 mikedld 115
        jz      .check_position
116
        mov     eax, [esp + 4]
117
        call    .call_middle_button_handler
118
 
119
  .check_position:
120
        movzx   eax, word[MOUSE_X]
121
        movzx   ebx, word[MOUSE_Y]
122
        cmp     eax, [mouse.state.pos.x]
123
        jne     .position_changed
124
        cmp     ebx, [mouse.state.pos.y]
125
        je      .exit
126
 
127
  .position_changed:
128
        xchg    eax, [mouse.state.pos.x]
129
        xchg    ebx, [mouse.state.pos.y]
130
 
131
        call    mouse._.move_handler
132
 
133
  .exit:
134
        add     esp, 8
135
        pop     ebx eax
136
        ret
137
 
138
  .call_left_button_handler:
139
        test    eax, mouse.LEFT_BUTTON_FLAG
140
        jnz     mouse._.left_button_press_handler
141
        jmp     mouse._.left_button_release_handler
142
 
143
  .call_right_button_handler:
144
        test    eax, mouse.RIGHT_BUTTON_FLAG
145
        jnz     mouse._.right_button_press_handler
146
        jmp     mouse._.right_button_release_handler
147
 
148
  .call_middle_button_handler:
149
        test    eax, mouse.MIDDLE_BUTTON_FLAG
150
        jnz     mouse._.middle_button_press_handler
151
        jmp     mouse._.middle_button_release_handler
152
 
5851 pathoswith 153
;===============================
154
;////// private functions //////
155
;===============================
1391 mikedld 156
 
157
uglobal
158
  mouse.state:
159
    .pos     POINT
160
    .buttons db ?
161
 
5851 pathoswith 162
; NOTE: since there's no unique and lifetime-constant button identifiers,
163
; we are using two dwords to identify each of them:
164
;   * pbid - process slot (high 8 bits) and button id (low 24 bits) pack
165
;   * coord - left (high 16 bits) and top (low 16 bits) coordinates pack
1391 mikedld 166
  align 4
167
  mouse.active_sys_button:
168
    .pbid    dd ?
169
    .coord   dd ?
170
    .buttons db ?
171
 
172
  align 4
173
  mouse.active_sys_window:
174
    .pslot      dd ?
175
    .old_box    BOX
176
    .new_box    BOX
177
    .delta      POINT
178
    .last_ticks dd ?
179
    .action     db ?
180
endg
181
 
5870 GerdtR 182
iglobal
183
        fl_moving db 0
184
        rb 3
185
endg
186
 
1391 mikedld 187
align 4
5851 pathoswith 188
;-----------------------------------------------------------------
189
mouse._.left_button_press_handler:
190
; Called when left mouse button has been pressed down
191
        bts     word [BTN_DOWN], 8
192
        mov     eax, [timer_ticks]
193
        mov     ebx, eax
194
        xchg    ebx, [mouse.active_sys_window.last_ticks]
195
        sub     eax, ebx
196
        movzx   ebx, [mouse_doubleclick_delay]
197
        cmp     eax, ebx
198
        jg      @f
199
        bts     dword [BTN_DOWN], 24
200
@@:
1391 mikedld 201
        test    [mouse.state.buttons], not mouse.LEFT_BUTTON_FLAG
202
        jnz     .exit
203
 
204
        call    mouse._.find_sys_window_under_cursor
205
        call    mouse._.check_sys_window_actions
206
        mov     [mouse.active_sys_window.action], al
207
        or      eax, eax
208
        jz      .exit
209
 
210
        xchg    eax, edx
211
        test    dl, mouse.WINDOW_MOVE_FLAG
212
        jz      @f
213
 
5851 pathoswith 214
        bt      dword [BTN_DOWN], 24
215
        jnc     @f
1391 mikedld 216
 
217
        mov     [mouse.active_sys_window.last_ticks], 0
218
        call    sys_window_maximize_handler
219
        jmp     .exit
220
 
2288 clevermous 221
    @@:
222
        test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED
1391 mikedld 223
        jnz     .exit
224
        mov     [mouse.active_sys_window.pslot], esi
225
        lea     eax, [edi + WDATA.box]
226
        mov     ebx, mouse.active_sys_window.old_box
2381 hidnplayr 227
        mov     ecx, sizeof.BOX
1391 mikedld 228
        call    memmove
229
        mov     ebx, mouse.active_sys_window.new_box
230
        call    memmove
231
        test    edx, mouse.WINDOW_MOVE_FLAG
232
        jz      @f
233
 
234
        call    .calculate_n_delta
235
        call    .calculate_w_delta
236
        jmp     .call_window_handler
237
 
2288 clevermous 238
    @@:
239
        test    dl, mouse.WINDOW_RESIZE_W_FLAG
1391 mikedld 240
        jz      @f
241
        call    .calculate_w_delta
242
 
2288 clevermous 243
    @@:
244
        test    dl, mouse.WINDOW_RESIZE_S_FLAG
1391 mikedld 245
        jz      @f
246
        call    .calculate_s_delta
247
 
2288 clevermous 248
    @@:
249
        test    dl, mouse.WINDOW_RESIZE_E_FLAG
1391 mikedld 250
        jz      .call_window_handler
251
        call    .calculate_e_delta
252
 
253
  .call_window_handler:
254
  .exit:
255
        ret
256
 
257
  .calculate_n_delta:
258
        mov     eax, [mouse.state.pos.y]
259
        sub     eax, [mouse.active_sys_window.old_box.top]
260
        mov     [mouse.active_sys_window.delta.y], eax
261
        ret
262
 
263
  .calculate_w_delta:
264
        mov     eax, [mouse.state.pos.x]
265
        sub     eax, [mouse.active_sys_window.old_box.left]
266
        mov     [mouse.active_sys_window.delta.x], eax
267
        ret
268
 
269
  .calculate_s_delta:
270
        mov     eax, [mouse.active_sys_window.old_box.top]
271
        add     eax, [mouse.active_sys_window.old_box.height]
272
        sub     eax, [mouse.state.pos.y]
273
        mov     [mouse.active_sys_window.delta.y], eax
274
        ret
275
 
276
  .calculate_e_delta:
277
        mov     eax, [mouse.active_sys_window.old_box.left]
278
        add     eax, [mouse.active_sys_window.old_box.width]
279
        sub     eax, [mouse.state.pos.x]
280
        mov     [mouse.active_sys_window.delta.x], eax
281
        ret
282
 
283
align 4
5851 pathoswith 284
;-----------------------------------------------------------------
285
mouse._.left_button_release_handler:
286
; Called when left mouse button has been released
287
        bts     dword [BTN_DOWN], 16
1391 mikedld 288
        xor     esi, esi
289
        xchg    esi, [mouse.active_sys_window.pslot]
290
        or      esi, esi
291
        jz      .exit
292
 
293
        mov     eax, esi
9926 Doczom 294
        shl     eax, BSF sizeof.WDATA
1391 mikedld 295
        add     eax, window_data + WDATA.box
296
        mov     ebx, mouse.active_sys_window.old_box
2381 hidnplayr 297
        mov     ecx, sizeof.BOX
1391 mikedld 298
        call    memmove
299
 
300
        mov     eax, mouse.active_sys_window.old_box
301
        mov     ebx, mouse.active_sys_window.new_box
302
        call    sys_window_end_moving_handler
303
 
304
  .exit:
2011 mikedld 305
        and     [mouse.active_sys_window.action], 0
5870 GerdtR 306
        mov     [fl_moving], 0
1391 mikedld 307
        ret
308
 
5851 pathoswith 309
mouse._.right_button_press_handler:
310
        bts     word [BTN_DOWN], 9
1391 mikedld 311
        test    [mouse.state.buttons], not mouse.RIGHT_BUTTON_FLAG
5851 pathoswith 312
        jnz     @f
1391 mikedld 313
        call    mouse._.find_sys_window_under_cursor
314
        call    mouse._.check_sys_window_actions
315
        test    al, mouse.WINDOW_MOVE_FLAG
5851 pathoswith 316
        jz      @f
317
        jmp     sys_window_rollup_handler
1391 mikedld 318
 
5851 pathoswith 319
mouse._.right_button_release_handler:
320
        bts     dword [BTN_DOWN], 17
321
@@:
1391 mikedld 322
        ret
323
 
5851 pathoswith 324
mouse._.middle_button_press_handler:
325
        bts     word [BTN_DOWN], 10
1391 mikedld 326
        ret
327
 
5851 pathoswith 328
mouse._.middle_button_release_handler:
329
        bts     dword [BTN_DOWN], 18
1391 mikedld 330
        ret
331
 
332
align 4
5851 pathoswith 333
;-----------------------------------------------------------------
334
mouse._.move_handler:
335
; Called when cursor has been moved
1391 mikedld 336
;> eax = old x coord
337
;> ebx = old y coord
9848 rgimad 338
        push    eax ebx
339
 
340
        call    mouse._.find_sys_window_under_cursor
341
        call    mouse._.check_sys_window_actions
342
 
9850 rgimad 343
        ; if now we are resizing the window, dont change the cursor
344
        mov     bl, [mouse.active_sys_window.action]
345
        and     bl, mouse.WINDOW_RESIZE_S_FLAG or mouse.WINDOW_RESIZE_W_FLAG or mouse.WINDOW_RESIZE_E_FLAG
346
        test    bl, bl
347
        jnz     .end1
348
 
9848 rgimad 349
        cmp     al, mouse.WINDOW_RESIZE_SW_FLAG
350
        jne     .not_sw
351
        ; DEBUGF  1, "RESIZE SOUTH-WEST\n"
352
 
353
        mov     eax, [def_cursor_dresize2]
354
 
355
        jmp     .set_resizing_cursor
356
.not_sw:
357
        cmp     al, mouse.WINDOW_RESIZE_SE_FLAG
358
        jne     .not_se
359
        ; DEBUGF  1, "RESIZE SOUTH-EAST\n"
360
 
361
        mov     eax, [def_cursor_dresize1]
362
 
363
        jmp     .set_resizing_cursor
364
.not_se:
365
        cmp     al, mouse.WINDOW_RESIZE_W_FLAG
366
        jne     .not_w
367
        ; DEBUGF  1, "RESIZE WEST\n"
368
 
369
        mov     eax, [def_cursor_hresize]
370
 
371
        jmp     .set_resizing_cursor
372
.not_w:
373
        cmp     al, mouse.WINDOW_RESIZE_S_FLAG
374
        jne     .not_s
375
        ; DEBUGF  1, "RESIZE SOUTH\n"
376
 
377
        mov     eax, [def_cursor_vresize]
378
 
379
        jmp     .set_resizing_cursor
380
.not_s:
381
        cmp     al, mouse.WINDOW_RESIZE_E_FLAG
382
        jne     .not_in_resize_area
383
        ; DEBUGF  1, "RESIZE EAST\n"
384
 
385
        mov     eax, [def_cursor_hresize]
386
 
387
.set_resizing_cursor:
9850 rgimad 388
        ; DEBUGF  1, ".set_resizing_cursor eax = %x\n", eax
9848 rgimad 389
        ; change cursor to resizing cursor
9930 Doczom 390
        shl     esi, BSF sizeof.WDATA
391
        add     esi, window_data
10051 ace_dent 392
 
9848 rgimad 393
        ; if resizing cursor we need (eax) isnt set already, set it
9930 Doczom 394
        cmp     eax, [esi + WDATA.cursor]
9848 rgimad 395
        je      @f
10051 ace_dent 396
 
9850 rgimad 397
        ; DEBUGF  1, "changing cursor to resizing\n"
9930 Doczom 398
        xchg    eax, [esi + WDATA.cursor] ; set resizing cursor, prev cursor goes to eax
9848 rgimad 399
        ; save previous cursor (will be restored when we'll get out of the resizing area)
400
        ; if we change resizing cursor to resizing cursor then dont update previous cursor
401
        cmp     eax, [def_cursor_hresize]
402
        je      @f
403
        cmp     eax, [def_cursor_vresize]
404
        je      @f
405
        cmp     eax, [def_cursor_dresize1]
406
        je      @f
407
        cmp     eax, [def_cursor_dresize2]
408
        je      @f
409
 
9930 Doczom 410
        mov     [esi + WDATA.temp_cursor], eax ; save prev cursor
9848 rgimad 411
 
412
@@:
413
        jmp     .end1
414
.not_in_resize_area:
9850 rgimad 415
        ; DEBUGF  1, ".not_in_resize_area\n"
416
 
9930 Doczom 417
        shl     esi, BSF sizeof.WDATA
418
        add     esi, window_data
419
        mov     eax, [esi + WDATA.temp_cursor]
9848 rgimad 420
 
421
        test    eax, eax
422
        jz      .end1
10051 ace_dent 423
 
9848 rgimad 424
        ; restore prev cursor
9930 Doczom 425
        mov     [esi + WDATA.temp_cursor], 0
426
        mov     [esi + WDATA.cursor], eax
9848 rgimad 427
 
428
.end1:
429
        pop     ebx eax
430
 
1391 mikedld 431
        cmp     [mouse.active_sys_button.pbid], 0
432
        jnz     .exit
433
 
434
        mov     esi, [mouse.active_sys_window.pslot]
435
        or      esi, esi
436
        jz      .exit
437
 
438
        mov     eax, mouse.active_sys_window.new_box
439
        mov     ebx, mouse.active_sys_window.old_box
2381 hidnplayr 440
        mov     ecx, sizeof.BOX
1391 mikedld 441
        call    memmove
442
 
443
        mov     dl, [mouse.active_sys_window.action]
444
        test    dl, mouse.WINDOW_MOVE_FLAG
445
        jz      .check_resize_w
446
 
447
        mov     eax, [mouse.state.pos.x]
448
        sub     eax, [mouse.active_sys_window.delta.x]
449
        mov     [mouse.active_sys_window.new_box.left], eax
450
        mov     eax, [mouse.state.pos.y]
451
        sub     eax, [mouse.active_sys_window.delta.y]
452
        mov     [mouse.active_sys_window.new_box.top], eax
453
 
454
        mov     eax, [mouse.active_sys_window.new_box.left]
455
        or      eax, eax
456
        jge     @f
457
        xor     eax, eax
458
        mov     [mouse.active_sys_window.new_box.left], eax
2288 clevermous 459
    @@:
460
        add     eax, [mouse.active_sys_window.new_box.width]
5350 serge 461
        cmp     eax, [_display.width]
1391 mikedld 462
        jl      @f
5350 serge 463
        sub     eax, [_display.width]
8928 dunkaist 464
        inc     eax
1391 mikedld 465
        sub     [mouse.active_sys_window.new_box.left], eax
2288 clevermous 466
    @@:
467
        mov     eax, [mouse.active_sys_window.new_box.top]
1391 mikedld 468
        or      eax, eax
469
        jge     @f
470
        xor     eax, eax
471
        mov     [mouse.active_sys_window.new_box.top], eax
2288 clevermous 472
    @@:
473
        add     eax, [mouse.active_sys_window.new_box.height]
5350 serge 474
        cmp     eax, [_display.height]
475
        jl      .call_window_handler
476
        sub     eax, [_display.height]
8928 dunkaist 477
        inc     eax
1391 mikedld 478
        sub     [mouse.active_sys_window.new_box.top], eax
479
        jmp     .call_window_handler
480
 
481
  .check_resize_w:
482
        test    dl, mouse.WINDOW_RESIZE_W_FLAG
483
        jz      .check_resize_s
484
 
485
        mov     eax, [mouse.state.pos.x]
486
        sub     eax, [mouse.active_sys_window.delta.x]
487
        mov     [mouse.active_sys_window.new_box.left], eax
488
        sub     eax, [mouse.active_sys_window.old_box.left]
489
        sub     [mouse.active_sys_window.new_box.width], eax
490
 
491
        mov     eax, [mouse.active_sys_window.new_box.width]
492
        sub     eax, 127
493
        jge     @f
494
        add     [mouse.active_sys_window.new_box.left], eax
495
        mov     [mouse.active_sys_window.new_box.width], 127
2288 clevermous 496
    @@:
497
        mov     eax, [mouse.active_sys_window.new_box.left]
1391 mikedld 498
        or      eax, eax
499
        jge     .check_resize_s
500
        add     [mouse.active_sys_window.new_box.width], eax
501
        xor     eax, eax
502
        mov     [mouse.active_sys_window.new_box.left], eax
503
 
504
  .check_resize_s:
505
        test    dl, mouse.WINDOW_RESIZE_S_FLAG
506
        jz      .check_resize_e
507
 
508
        mov     eax, [mouse.state.pos.y]
509
        add     eax, [mouse.active_sys_window.delta.y]
510
        sub     eax, [mouse.active_sys_window.old_box.top]
511
        mov     [mouse.active_sys_window.new_box.height], eax
512
 
513
        push    eax
514
        mov     edi, esi
9926 Doczom 515
        shl     edi, BSF sizeof.WDATA
1391 mikedld 516
        add     edi, window_data
517
        call    window._.get_rolledup_height
518
        mov     ecx, eax
519
        pop     eax
520
        mov     eax, [mouse.active_sys_window.new_box.height]
521
        cmp     eax, ecx
522
        jge     @f
523
        mov     eax, ecx
524
        mov     [mouse.active_sys_window.new_box.height], eax
2288 clevermous 525
    @@:
526
        add     eax, [mouse.active_sys_window.new_box.top]
5350 serge 527
        cmp     eax, [_display.height]
528
        jl      .check_resize_e
529
        sub     eax, [_display.height]
1391 mikedld 530
        neg     eax
531
        add     [mouse.active_sys_window.new_box.height], eax
5350 serge 532
        mov     ecx, [_display.height]
1391 mikedld 533
        cmp     ecx, eax
5350 serge 534
        jg      .check_resize_e
1391 mikedld 535
        mov     [mouse.active_sys_window.new_box.height], ecx
536
 
537
  .check_resize_e:
538
        test    dl, mouse.WINDOW_RESIZE_E_FLAG
539
        jz      .call_window_handler
540
 
541
        mov     eax, [mouse.state.pos.x]
542
        add     eax, [mouse.active_sys_window.delta.x]
543
        sub     eax, [mouse.active_sys_window.old_box.left]
544
        mov     [mouse.active_sys_window.new_box.width], eax
545
 
546
        mov     eax, [mouse.active_sys_window.new_box.width]
547
        cmp     eax, 127
548
        jge     @f
549
        mov     eax, 127
550
        mov     [mouse.active_sys_window.new_box.width], eax
2288 clevermous 551
    @@:
552
        add     eax, [mouse.active_sys_window.new_box.left]
5350 serge 553
        cmp     eax, [_display.width]
554
        jl      .call_window_handler
555
        sub     eax, [_display.width]
1391 mikedld 556
        neg     eax
557
        add     [mouse.active_sys_window.new_box.width], eax
5350 serge 558
        mov     ecx, [_display.width]
1391 mikedld 559
        cmp     ecx, eax
5350 serge 560
        jg      .call_window_handler
1391 mikedld 561
        mov     [mouse.active_sys_window.new_box.width], ecx
562
 
563
  .call_window_handler:
564
        mov     eax, mouse.active_sys_window.old_box
565
        mov     ebx, mouse.active_sys_window.new_box
566
 
567
        push    esi
568
        mov     esi, mouse.active_sys_window.old_box
569
        mov     edi, mouse.active_sys_window.new_box
2381 hidnplayr 570
        mov     ecx, sizeof.BOX / 4
1391 mikedld 571
        repe
572
        cmpsd
573
        pop     esi
574
        je      .exit
575
 
5870 GerdtR 576
        test    [fl_moving], 1
577
        jnz     @f
578
 
579
        mov     [fl_moving], 1
580
        push    edi
581
        mov     edi, esi
9926 Doczom 582
        shl     edi, BSF sizeof.WDATA
5870 GerdtR 583
        add     edi, WDATA.box + window_data
584
        call    window._.draw_negative_box
585
        pop     edi
586
     @@:
587
 
588
 
1391 mikedld 589
        mov     [mouse.active_sys_window.last_ticks], 0
590
        call    sys_window_moving_handler
591
 
592
  .exit:
593
        ret
594
 
595
align 4
5851 pathoswith 596
;-----------------------------------------------------------------
597
mouse._.find_sys_window_under_cursor:
598
; Find system window object which is currently visible on screen
599
; and has mouse cursor within its bounds
1391 mikedld 600
;< esi = process slot
601
;< edi = pointer to WDATA struct
2446 mario79 602
        mov     esi, [mouse.state.pos.y]
603
        mov     esi, [d_width_calc_area + esi*4]
604
 
5351 serge 605
        add     esi, [_display.win_map]
1391 mikedld 606
        add     esi, [mouse.state.pos.x]
607
        movzx   esi, byte[esi]
608
        mov     edi, esi
9926 Doczom 609
        shl     edi, BSF sizeof.WDATA
1391 mikedld 610
        add     edi, window_data
611
        ret
612
 
613
align 4
5851 pathoswith 614
;-----------------------------------------------------------------
615
mouse._.activate_sys_window_under_cursor:
616
; activate and redraw window under cursor (if necessary)
1391 mikedld 617
        call    mouse._.find_sys_window_under_cursor
618
        movzx   esi, word[WIN_STACK + esi * 2]
619
        lea     esi, [WIN_POS + esi * 2]
620
        jmp     waredraw
621
 
622
align 4
5851 pathoswith 623
;-----------------------------------------------------------------
624
mouse._.find_sys_button_under_cursor:
625
; Find system button object which is currently visible on screen
626
; and has mouse cursor within its bounds
1391 mikedld 627
;< eax = pack[8(process slot), 24(button id)] or 0
628
;< ebx = pack[16(button x coord), 16(button y coord)]
629
        push    ecx edx esi edi
630
 
631
        call    mouse._.find_sys_window_under_cursor
632
        mov     edx, esi
633
 
634
        ; check if any process button contains cursor
635
        mov     eax, [BTN_ADDR]
636
        mov     ecx, [eax]
2384 hidnplayr 637
        imul    esi, ecx, sizeof.SYS_BUTTON
1391 mikedld 638
        add     esi, eax
639
        inc     ecx
2384 hidnplayr 640
        add     esi, sizeof.SYS_BUTTON
1391 mikedld 641
 
642
  .next_button:
643
        dec     ecx
644
        jz      .not_found
645
 
2384 hidnplayr 646
        add     esi, -sizeof.SYS_BUTTON
1391 mikedld 647
 
648
        ; does it belong to our process?
649
        cmp     dx, [esi + SYS_BUTTON.pslot]
650
        jne     .next_button
651
 
652
        ; does it contain cursor coordinates?
653
        mov     eax, [mouse.state.pos.x]
654
        sub     eax, [edi + WDATA.box.left]
655
        sub     ax, [esi + SYS_BUTTON.left]
656
        jl      .next_button
657
        sub     ax, [esi + SYS_BUTTON.width]
658
        jge     .next_button
659
        mov     eax, [mouse.state.pos.y]
660
        sub     eax, [edi + WDATA.box.top]
661
        sub     ax, [esi + SYS_BUTTON.top]
662
        jl      .next_button
663
        sub     ax, [esi + SYS_BUTTON.height]
664
        jge     .next_button
665
 
666
        ; okay, return it
667
        shl     edx, 24
668
        mov     eax, dword[esi + SYS_BUTTON.id_hi - 2]
669
        mov     ax, [esi + SYS_BUTTON.id_lo]
670
        and     eax, 0x0ffffff
671
        or      eax, edx
672
        mov     ebx, dword[esi + SYS_BUTTON.left - 2]
673
        mov     bx, [esi + SYS_BUTTON.top]
674
        jmp     .exit
675
 
676
  .not_found:
677
        xor     eax, eax
678
        xor     ebx, ebx
679
 
680
  .exit:
681
        pop     edi esi edx ecx
682
        ret
683
 
684
align 4
5851 pathoswith 685
;-----------------------------------------------------------------
686
mouse._.check_sys_window_actions:
1391 mikedld 687
;< eax = action flags or 0
688
        ; is window movable?
689
        test    byte[edi + WDATA.cl_titlebar + 3], 0x01
690
        jnz     .no_action
691
 
692
        mov     eax, [mouse.state.pos.x]
693
        mov     ebx, [mouse.state.pos.y]
694
        sub     eax, [edi + WDATA.box.left]
695
        sub     ebx, [edi + WDATA.box.top]
696
 
697
        ; is there a window titlebar under cursor?
698
        push    eax
699
        call    window._.get_titlebar_height
700
        cmp     ebx, eax
701
        pop     eax
702
        jl      .move_action
703
 
704
        ; no there isn't, can it be resized then?
705
        mov     dl, [edi + WDATA.fl_wstyle]
706
        and     dl, 0x0f
5851 pathoswith 707
; NOTE: dangerous optimization, revise if window types changed
708
; this currently implies only types 2 and 3 could be resized
1391 mikedld 709
        test    dl, 2
710
        jz      .no_action
711
 
712
        mov     ecx, [edi + WDATA.box.width]
713
        add     ecx, -window.BORDER_SIZE
714
        mov     edx, [edi + WDATA.box.height]
715
        add     edx, -window.BORDER_SIZE
716
 
717
        ; is it rolled up?
718
        test    [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP
719
        jnz     .resize_w_or_e_action
720
 
721
        cmp     eax, window.BORDER_SIZE
722
        jl      .resize_w_action
723
        cmp     eax, ecx
724
        jg      .resize_e_action
725
        cmp     ebx, edx
726
        jle     .no_action
727
 
728
  .resize_s_action:
729
        cmp     eax, window.BORDER_SIZE + 10
730
        jl      .resize_sw_action
731
        add     ecx, -10
732
        cmp     eax, ecx
733
        jge     .resize_se_action
734
        mov     eax, mouse.WINDOW_RESIZE_S_FLAG
735
        jmp     .exit
736
 
737
  .resize_w_or_e_action:
738
        cmp     eax, window.BORDER_SIZE + 10
739
        jl      .resize_w_action.direct
740
        add     ecx, -10
741
        cmp     eax, ecx
742
        jg      .resize_e_action.direct
743
        jmp     .no_action
744
 
745
  .resize_w_action:
746
        add     edx, -10
747
        cmp     ebx, edx
748
        jge     .resize_sw_action
749
  .resize_w_action.direct:
750
        mov     eax, mouse.WINDOW_RESIZE_W_FLAG
751
        jmp     .exit
752
 
753
  .resize_e_action:
754
        add     edx, -10
755
        cmp     ebx, edx
756
        jge     .resize_se_action
757
  .resize_e_action.direct:
758
        mov     eax, mouse.WINDOW_RESIZE_E_FLAG
759
        jmp     .exit
760
 
761
  .resize_sw_action:
762
        mov     eax, mouse.WINDOW_RESIZE_SW_FLAG
763
        jmp     .exit
764
 
765
  .resize_se_action:
766
        mov     eax, mouse.WINDOW_RESIZE_SE_FLAG
767
        jmp     .exit
768
 
769
  .move_action:
770
        mov     eax, mouse.WINDOW_MOVE_FLAG
771
        jmp     .exit
772
 
773
  .no_action:
774
        xor     eax, eax
775
 
776
  .exit:
777
        ret
9514 rgimad 778
;-----------------------------------------------------------------------------
779
 
780
align 4
781
readmousepos:
782
; eax=0 screen relative
783
; eax=1 window relative
784
; eax=2 buttons pressed
785
; eax=3 buttons pressed ext
786
; eax=4 load cursor
787
; eax=5 set cursor
788
; eax=6 delete cursor
789
; eax=7 get mouse_z
790
; eax=8 load cursor unicode
791
        cmp     ebx, 8
792
        ja      @f
793
        jmp     dword[.mousefn+ebx*4]
794
 
795
align 4
796
.mousefn:
797
dd  .msscreen
798
dd  .mswin
799
dd  .msbutton
800
dd  .msbuttonExt
801
dd  .app_load_cursor
802
dd  .app_set_cursor
803
dd  .app_delete_cursor
804
dd  .msz
805
dd  .loadCursorUni
806
 
807
.msscreen:
808
        mov     eax, [MOUSE_X]
809
        shl     eax, 16
810
        mov     ax, [MOUSE_Y]
9831 dunkaist 811
        mov     [esp + SYSCALL_STACK.eax], eax
9514 rgimad 812
@@:
813
        ret
814
 
815
.mswin:
816
        mov     eax, [MOUSE_X]
817
        shl     eax, 16
818
        mov     ax, [MOUSE_Y]
9930 Doczom 819
        mov     esi, [current_slot]
820
        mov     esi, [esi + APPDATA.window]
821
        mov     bx, word[esi + WDATA.box.left]
9514 rgimad 822
        shl     ebx, 16
9930 Doczom 823
        mov     bx, word[esi + WDATA.box.top]
9514 rgimad 824
        sub     eax, ebx
9930 Doczom 825
        sub     ax, word[esi + WDATA.clientbox.top]
9514 rgimad 826
        rol     eax, 16
9930 Doczom 827
        sub     ax, word[esi + WDATA.clientbox.left]
9514 rgimad 828
        rol     eax, 16
9831 dunkaist 829
        mov     [esp + SYSCALL_STACK.eax], eax
9514 rgimad 830
        ret
831
 
832
.msbutton:
833
        movzx   eax, byte [BTN_DOWN]
9831 dunkaist 834
        mov     [esp + SYSCALL_STACK.eax], eax
9514 rgimad 835
        ret
836
 
837
.msbuttonExt:
838
        mov     eax, [BTN_DOWN]
9831 dunkaist 839
        mov     [esp + SYSCALL_STACK.eax], eax
9514 rgimad 840
        ret
841
 
842
.app_load_cursor:
843
        cmp     ecx, OS_BASE
844
        jae     @f
845
        stdcall load_cursor, ecx, edx
9831 dunkaist 846
        mov     [esp + SYSCALL_STACK.eax], eax
9514 rgimad 847
@@:
848
        ret
849
 
850
.loadCursorUni:
851
        cmp     ecx, OS_BASE
852
        jae     @b
853
        push    ecx edx
854
        stdcall kernel_alloc, maxPathLength
855
        mov     edi, eax
856
        pop     eax esi
857
        push    edi
858
        call    getFullPath
859
        pop     ebp
860
        test    eax, eax
861
        jz      @f
862
        stdcall load_cursor, ebp, LOAD_FROM_FILE
9831 dunkaist 863
        mov     [esp + SYSCALL_STACK.eax], eax
9514 rgimad 864
@@:
865
        stdcall kernel_free, ebp
866
        ret
867
 
868
.app_set_cursor:
869
        stdcall set_cursor, ecx
9831 dunkaist 870
        mov     [esp + SYSCALL_STACK.eax], eax
9514 rgimad 871
        ret
872
 
873
.app_delete_cursor:
874
        stdcall delete_cursor, ecx
9831 dunkaist 875
        mov     [esp + SYSCALL_STACK.eax], eax
9514 rgimad 876
        ret
877
 
878
.msz:
879
        mov     edi, [thread_count]
880
        movzx   edi, word [WIN_POS + edi*2]
881
        cmp     edi, [current_slot_idx]
882
        jne     @f
883
        mov     ax, [MOUSE_SCROLL_H]
884
        shl     eax, 16
885
        mov     ax, [MOUSE_SCROLL_V]
9831 dunkaist 886
        mov     [esp + SYSCALL_STACK.eax], eax
9514 rgimad 887
        and     [MOUSE_SCROLL_H], word 0
888
        and     [MOUSE_SCROLL_V], word 0
889
        ret
890
@@:
9831 dunkaist 891
        and     [esp + SYSCALL_STACK.eax], dword 0
892
        ret