Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
593 mikedld 8
$Revision: 928 $
9
 
10
 
33 mario79 11
;   check mouse
12
;
13
;
14
;   FB00  ->   FB0F   mouse memory 00 chunk count - FB0A-B x - FB0C-D y
15
;   FB10  ->   FB17   mouse color mem
16
;   FB21              x move
17
;   FB22              y move
18
;   FB30              color temp
19
;   FB28              high bits temp
20
 
21
uglobal
22
  mousecount  dd  0x0
23
  mousedata   dd  0x0
24
endg
25
 
473 diamond 26
iglobal
928 serge 27
mouse_delay         dd 10
479 kastigar 28
mouse_speed_factor: dd 3
928 serge 29
mouse_timer_ticks   dd 0
473 diamond 30
endg
120 mario79 31
 
928 serge 32
align 4
33 mario79 33
draw_mouse_under:
769 Rus 34
	; return old picture
214 serge 35
 
769 Rus 36
	cmp [set_hw_cursor], 0
37
	jz @F
38
	pushad
928 serge 39
    mov  eax, [x_under]
40
    mov  ebx, [y_under]
769 Rus 41
	stdcall [hw_restore], eax, ebx
42
	popad
43
	ret
214 serge 44
@@:
769 Rus 45
	pushad
46
	xor    ecx,ecx
47
	xor    edx,edx
48
	align  4
119 mario79 49
mres:
928 serge 50
    mov eax, [x_under]
51
    mov ebx, [y_under]
769 Rus 52
	add    eax,ecx
53
	add    ebx,edx
54
	push   ecx
55
	push   edx
56
	push   eax
57
	push   ebx
58
	mov    eax,edx
59
	shl    eax,6
60
	shl    ecx,2
61
	add    eax,ecx
62
	add    eax,mouseunder
63
	mov    ecx,[eax]
64
	pop    ebx
65
	pop    eax
66
	mov    edi, 1 ;force
67
	call   [putpixel]
68
	pop    edx
69
	pop    ecx
70
	inc    ecx
71
	cmp    ecx, 16
72
	jnz    mres
73
	xor    ecx, ecx
74
	inc    edx
75
	cmp    edx, 24
76
	jnz    mres
77
	popad
78
	ret
33 mario79 79
 
80
save_draw_mouse:
214 serge 81
 
769 Rus 82
	cmp [set_hw_cursor], 0
83
	je .no_hw_cursor
84
	pushad
221 serge 85
 
928 serge 86
    mov    [x_under], eax
87
    mov    [y_under], ebx
769 Rus 88
	movzx  eax,word [MOUSE_Y]
89
	movzx  ebx,word [MOUSE_X]
90
	push eax
91
	push ebx
221 serge 92
 
769 Rus 93
	mov ecx, [Screen_Max_X]
94
	inc ecx
95
	mul ecx
840 serge 96
        add eax, [_display_data]
97
        movzx edx, byte [ebx+eax]
769 Rus 98
	shl edx, 8
802 serge 99
        mov esi, [edx+SLOT_BASE+APPDATA.cursor]
230 serge 100
 
802 serge 101
        cmp esi, [current_cursor]
769 Rus 102
	je .draw
630 serge 103
 
802 serge 104
       ; cmp [esi+CURSOR.magic], 'CURS'
105
       ; jne .fail
630 serge 106
 
802 serge 107
        push esi
769 Rus 108
	call [select_hw_cursor]
802 serge 109
        mov [current_cursor], esi
630 serge 110
.draw:
802 serge 111
        stdcall [set_hw_cursor], esi
769 Rus 112
	popad
113
	ret
230 serge 114
.fail:
769 Rus 115
	mov ecx, [def_cursor]
116
	mov [edx+SLOT_BASE+APPDATA.cursor], ecx
802 serge 117
        stdcall [set_hw_cursor], ecx            ; stdcall: [esp]=ebx,eax
769 Rus 118
	popad
119
	ret
230 serge 120
 
630 serge 121
.no_hw_cursor:
769 Rus 122
	pushad
123
	; save & draw
928 serge 124
    mov    [x_under], eax
125
    mov    [y_under], ebx
769 Rus 126
	push   eax
127
	push   ebx
128
	mov    ecx,0
129
	mov    edx,0
130
	align  4
119 mario79 131
drm:
769 Rus 132
	push   eax
133
	push   ebx
134
	push   ecx
135
	push   edx
136
	; helloworld
137
	push  ecx
138
	add    eax,ecx	; save picture under mouse
139
	add    ebx,edx
140
	push   ecx
141
	call   getpixel
928 serge 142
    mov    [color_temp],ecx
769 Rus 143
	pop    ecx
144
	mov    eax,edx
145
	shl    eax,6
146
	shl    ecx,2
147
	add    eax,ecx
148
	add    eax,mouseunder
928 serge 149
    mov    ebx,[color_temp]
769 Rus 150
	mov    [eax],ebx
151
	pop  ecx
928 serge 152
    mov    edi,edx            ; y cycle
153
    shl    edi,4              ; *16 bytes per row
154
    add    edi,ecx            ; x cycle
155
    lea edi, [mousepointer+edi+edi*2]  ; we have our str address
769 Rus 156
	mov    esi, edi
157
	add    esi, 16*24*3
158
	push   ecx
928 serge 159
    mov    ecx, [color_temp]
769 Rus 160
	call   combine_colors
928 serge 161
    mov    [mouse_color_mem], ecx
769 Rus 162
	pop    ecx
163
	pop    edx
164
	pop    ecx
165
	pop    ebx
166
	pop    eax
167
	add    eax,ecx	     ; we have x coord+cycle
168
	add    ebx,edx	     ; and y coord+cycle
169
	push   ecx
928 serge 170
    mov    ecx, [mouse_color_mem]
769 Rus 171
	mov    edi, 1
172
	call   [putpixel]
173
	pop    ecx
174
	mov    ebx,[esp+0]	; pure y coord again
175
	mov    eax,[esp+4]	; and x
928 serge 176
    inc    ecx          ; +1 cycle
769 Rus 177
	cmp    ecx,16	    ; if more than 16
178
	jnz    drm
179
	xor    ecx, ecx
180
	inc    edx
181
	cmp    edx,24
182
	jnz    drm
183
	add   esp,8
184
	popad
185
	ret
33 mario79 186
 
187
 
188
combine_colors:
189
      ; in
190
      ; ecx - color ( 00 RR GG BB )
191
      ; edi - ref to new color byte
192
      ; esi - ref to alpha byte
193
      ;
194
      ; out
195
      ; ecx - new color ( roughly (ecx*[esi]>>8)+([edi]*[esi]>>8) )
196
      push eax
197
      push ebx
198
      push edx
199
      push ecx
200
      xor ecx, ecx
769 Rus 201
	 ; byte 2
33 mario79 202
      mov eax, 0xff
203
      sub al, [esi+0]
204
      mov ebx, [esp]
205
      shr ebx, 16
206
      and ebx, 0xff
207
      mul ebx
208
      shr eax, 8
209
      add ecx, eax
119 mario79 210
      xor eax, eax
211
      xor ebx, ebx
212
      mov al, [edi+0]
213
      mov bl, [esi+0]
33 mario79 214
      mul ebx
215
      shr eax, 8
216
      add ecx, eax
217
      shl ecx, 8
769 Rus 218
	 ; byte 1
33 mario79 219
      mov eax, 0xff
220
      sub al, [esi+1]
221
      mov ebx, [esp]
222
      shr ebx, 8
223
      and ebx, 0xff
224
      mul ebx
225
      shr eax, 8
226
      add ecx, eax
119 mario79 227
      xor eax, eax
228
      xor ebx, ebx
229
      mov al, [edi+1]
230
      mov bl, [esi+1]
33 mario79 231
      mul ebx
232
      shr eax, 8
233
      add ecx, eax
234
      shl ecx, 8
769 Rus 235
	 ; byte 2
33 mario79 236
      mov eax, 0xff
237
      sub al, [esi+2]
238
      mov ebx, [esp]
239
      and ebx, 0xff
240
      mul ebx
241
      shr eax, 8
242
      add ecx, eax
119 mario79 243
      xor eax, eax
244
      xor ebx, ebx
245
      mov al, [edi+2]
246
      mov bl, [esi+2]
33 mario79 247
      mul ebx
248
      shr eax, 8
249
      add ecx, eax
250
      pop eax
251
      pop edx
252
      pop ebx
253
      pop eax
254
      ret
255
 
256
 
257
__sys_disable_mouse:
928 serge 258
      cmp  [MOUSE_VISIBLE], 0
36 mario79 259
      je    @f
260
      ret
214 serge 261
@@:
33 mario79 262
      pushad
379 serge 263
      cmp  [CURRENT_TASK],dword 1
33 mario79 264
      je   disable_m
379 serge 265
      mov  edx,[CURRENT_TASK]
33 mario79 266
      shl  edx,5
267
      add  edx,window_data
381 serge 268
      movzx  eax, word [MOUSE_X]
269
      movzx  ebx, word [MOUSE_Y]
753 serge 270
      mov  ecx,[Screen_Max_X]
33 mario79 271
      inc  ecx
272
      imul  ecx,ebx
273
      add  ecx,eax
840 serge 274
      add  ecx, [_display_data]
379 serge 275
      mov   eax, [CURRENT_TASK]
33 mario79 276
      movzx ebx, byte [ecx]
277
      cmp   eax,ebx
278
      je    yes_mouse_disable
279
      movzx ebx, byte [ecx+16]
280
      cmp   eax,ebx
281
      je    yes_mouse_disable
753 serge 282
      mov   ebx,[Screen_Max_X]
33 mario79 283
      inc   ebx
284
      imul  ebx,10
285
      add   ecx,ebx
286
      movzx ebx, byte [ecx]
287
      cmp   eax,ebx
288
      je    yes_mouse_disable
289
      movzx ebx, byte [ecx+16]
290
      cmp   eax,ebx
291
      je    yes_mouse_disable
292
      jmp   no_mouse_disable
119 mario79 293
yes_mouse_disable:
379 serge 294
      mov  edx,[CURRENT_TASK]
33 mario79 295
      shl  edx,5
296
      add  edx,window_data
381 serge 297
      movzx  eax, word [MOUSE_X]
298
      movzx  ebx, word [MOUSE_Y]
769 Rus 299
      mov  ecx,[edx+0]	 ; mouse inside the area ?
739 heavyiron 300
      add  eax,10
33 mario79 301
      cmp  eax,ecx
302
      jb   no_mouse_disable
739 heavyiron 303
      sub  eax,10
33 mario79 304
      add  ecx,[edx+8]
305
      cmp  eax,ecx
306
      jg   no_mouse_disable
307
      mov  ecx,[edx+4]
739 heavyiron 308
      add  ebx,14
33 mario79 309
      cmp  ebx,ecx
310
      jb   no_mouse_disable
739 heavyiron 311
      sub  ebx,14
33 mario79 312
      add  ecx,[edx+12]
313
      cmp  ebx,ecx
314
      jg   no_mouse_disable
119 mario79 315
disable_m:
928 serge 316
      cmp  [MOUSE_VISIBLE], 0
119 mario79 317
      jne  no_mouse_disable
389 serge 318
      pushf
36 mario79 319
      cli
119 mario79 320
      call draw_mouse_under
389 serge 321
      popf
928 serge 322
      mov  [MOUSE_VISIBLE], 1
119 mario79 323
no_mouse_disable:
33 mario79 324
      popad
325
      ret
326
 
327
__sys_draw_pointer:
769 Rus 328
	cmp   [mouse_pause],0
329
	je    @f
330
	ret
119 mario79 331
@@:
769 Rus 332
	push   eax
333
	mov	eax,[timer_ticks]
334
	sub	eax,[MouseTickCounter]
335
	cmp	eax,1
336
	ja	@f
337
	pop    eax
338
	ret
119 mario79 339
@@:
769 Rus 340
	mov	eax,[timer_ticks]
341
	mov	[MouseTickCounter],eax
342
	pop	eax
343
	pushad
928 serge 344
    cmp    [MOUSE_VISIBLE], 0  ; mouse visible ?
769 Rus 345
	je     chms00
928 serge 346
    mov [MOUSE_VISIBLE], 0
769 Rus 347
	movzx  ebx,word [MOUSE_Y]
348
	movzx  eax,word [MOUSE_X]
349
	pushfd
350
	cli
351
	call   save_draw_mouse
352
	popfd
119 mario79 353
nodmu2:
769 Rus 354
	popad
355
	ret
119 mario79 356
chms00:
928 serge 357
    mov  ecx, [x_under]
358
    mov  edx, [y_under]
769 Rus 359
	movzx  ebx,word [MOUSE_Y]
360
	movzx  eax,word [MOUSE_X]
361
	cmp    eax,ecx
362
	jne    redrawmouse
363
	cmp    ebx,edx
364
	jne    redrawmouse
365
	jmp    nodmp
119 mario79 366
redrawmouse:
769 Rus 367
	pushfd
368
	cli
369
	call   draw_mouse_under
370
	call   save_draw_mouse
371
	popfd
119 mario79 372
nodmp:
769 Rus 373
	popad
374
	ret
119 mario79 375
 
479 kastigar 376
proc set_mouse_data stdcall, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword
630 serge 377
 
479 kastigar 378
    mov  eax,[BtnState]
928 serge 379
    mov  [btn_down],eax
479 kastigar 380
 
381
    mov  eax,[XMoving]
382
    call mouse_acceleration
769 Rus 383
    add  ax,[MOUSE_X]	 ;[XCoordinate]
479 kastigar 384
    cmp  ax,0
385
    jge  @@M1
386
    mov  eax,0
387
    jmp  @@M2
388
@@M1:
928 serge 389
    cmp  ax, word [Screen_Max_X]   ;ScreenLength
769 Rus 390
    jl	 @@M2
928 serge 391
    mov  ax, word [Screen_Max_X]   ;ScreenLength-1
479 kastigar 392
 
393
@@M2:
769 Rus 394
    mov  [MOUSE_X],ax	  ;[XCoordinate]
479 kastigar 395
 
396
    mov  eax,[YMoving]
397
    neg  eax
398
    call mouse_acceleration
399
 
769 Rus 400
    add  ax,[MOUSE_Y]	;[YCoordinate]
479 kastigar 401
    cmp  ax,0
402
    jge  @@M3
403
    mov  ax,0
404
    jmp  @@M4
405
@@M3:
928 serge 406
    cmp  ax, word [Screen_Max_Y]  ;ScreenHeigth
769 Rus 407
    jl	 @@M4
928 serge 408
    mov  ax, word [Screen_Max_Y] ;ScreenHeigth-1
479 kastigar 409
 
410
@@M4:
769 Rus 411
    mov  [MOUSE_Y],ax	  ;[YCoordinate]
479 kastigar 412
 
413
    mov  eax,[VScroll]
928 serge 414
    add  [mouse_scroll_v], eax
630 serge 415
 
479 kastigar 416
    mov  eax,[HScroll]
928 serge 417
    add  [mouse_scroll_h], eax
479 kastigar 418
 
419
    mov  [mouse_active],1
420
    mov  eax,[timer_ticks]
421
    mov  [mouse_timer_ticks],eax
422
    ret
423
endp
424
 
425
mouse_acceleration:
769 Rus 426
	push  eax
427
	mov   eax,[timer_ticks]
428
	sub   eax,[mouse_timer_ticks]
429
	cmp   eax,[mouse_delay]
430
	pop   eax
431
	ja    @f
432
	;push  edx
433
	imul  eax,[mouse_speed_factor]
434
	;pop   edx
479 kastigar 435
@@:
769 Rus 436
	ret
479 kastigar 437