2009-12-27 19:37:14 +01:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2024-05-22 17:15:14 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
|
2009-12-27 19:37:14 +01:00
|
|
|
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;;
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
2010-02-06 20:08:19 +01:00
|
|
|
button.MAX_BUTTONS = 4095
|
|
|
|
|
2012-02-23 19:52:13 +01:00
|
|
|
struct SYS_BUTTON
|
|
|
|
pslot dw ?
|
|
|
|
id_lo dw ?
|
|
|
|
left dw ?
|
|
|
|
width dw ?
|
|
|
|
top dw ?
|
|
|
|
height dw ?
|
|
|
|
id_hi dw ?
|
|
|
|
dw ?
|
|
|
|
ends
|
2016-01-04 08:23:15 +01:00
|
|
|
;---------------------------------------------------------------
|
2023-04-09 20:19:13 +02:00
|
|
|
align 4
|
|
|
|
; @brief system function 17 - Get the identifier of the pressed button
|
|
|
|
; @param eax 17 - number function
|
|
|
|
; @return eax = 1 - buffer empty,
|
|
|
|
; eax = high 24 bits contain button identifier,
|
|
|
|
; al = 0 - the button was pressed with left mouse button,
|
|
|
|
; al = bit corresponding to used mouse button otherwise
|
|
|
|
sys_getbutton:
|
|
|
|
mov ebx, [current_slot_idx] ; TOP OF WINDOW STACK
|
|
|
|
mov [esp + SYSCALL_STACK.eax], dword 1
|
|
|
|
movzx ecx, word [WIN_STACK + ebx * 2]
|
|
|
|
mov edx, [thread_count] ; less than 256 processes
|
|
|
|
cmp ecx, edx
|
|
|
|
jne .exit
|
|
|
|
movzx eax, byte [BTN_COUNT]
|
|
|
|
test eax, eax
|
|
|
|
jz .exit
|
|
|
|
mov eax, [BTN_BUFF]
|
|
|
|
and al, 0xFE ; delete left button bit
|
|
|
|
mov [BTN_COUNT], byte 0
|
|
|
|
mov [esp + SYSCALL_STACK.eax], eax
|
|
|
|
;--------------------------------------
|
|
|
|
align 4
|
|
|
|
.exit:
|
|
|
|
ret
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
; @brief system function 8 - define/delete the button
|
|
|
|
; @param eax = 8 - number function
|
|
|
|
; @param ebx = [offset_x]*65536 + [width]
|
|
|
|
; @param ecx = [offset_y]*65536 + [height]
|
|
|
|
; @param edx = 0xXYnnnnnn, where:
|
|
|
|
; nnnnnn = identifier of the button
|
|
|
|
; 31 bit - delete button
|
|
|
|
; 30 bit - don't draw button
|
|
|
|
; 29 bit - don't draw button frame when pressed
|
|
|
|
; @param esi = 0x00RRGGBB - button color
|
|
|
|
; @return function does not return value
|
|
|
|
syscall_button:
|
2016-01-04 08:23:15 +01:00
|
|
|
;---------------------------------------------------------------
|
2010-01-05 02:28:11 +01:00
|
|
|
;? Define/undefine GUI button object
|
2016-01-04 08:23:15 +01:00
|
|
|
;---------------------------------------------------------------
|
2010-01-05 02:28:11 +01:00
|
|
|
;; Define button:
|
|
|
|
;> ebx = pack[16(x), 16(width)]
|
|
|
|
;> ecx = pack[16(y), 16(height)]
|
|
|
|
;> edx = pack[8(flags), 24(button identifier)]
|
|
|
|
;> flags bits:
|
|
|
|
;> 7 (31) = 0
|
|
|
|
;> 6 (30) = don't draw button
|
|
|
|
;> 5 (29) = don't draw button frame when pressed
|
|
|
|
;> esi = button color
|
2024-05-22 17:15:14 +02:00
|
|
|
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-01-05 02:28:11 +01:00
|
|
|
;; Undefine button:
|
|
|
|
;> edx = pack[8(flags), 24(button identifier)]
|
|
|
|
;> flags bits:
|
|
|
|
;> 7 (31) = 1
|
2016-01-04 08:23:15 +01:00
|
|
|
;---------------------------------------------------------------
|
2009-12-27 19:37:14 +01:00
|
|
|
; do we actually need to undefine the button?
|
|
|
|
test edx, 0x80000000
|
|
|
|
jnz .remove_button
|
|
|
|
|
|
|
|
; do we have free button slots available?
|
|
|
|
mov edi, [BTN_ADDR]
|
|
|
|
mov eax, [edi]
|
2010-02-06 20:08:19 +01:00
|
|
|
cmp eax, button.MAX_BUTTONS
|
2009-12-27 19:37:14 +01:00
|
|
|
jge .exit
|
|
|
|
|
|
|
|
; does it have positive size? (otherwise it doesn't have sense)
|
|
|
|
or bx, bx
|
|
|
|
jle .exit
|
|
|
|
or cx, cx
|
|
|
|
jle .exit
|
|
|
|
|
|
|
|
; make coordinates clientbox-relative
|
|
|
|
push eax
|
2023-09-22 18:31:40 +02:00
|
|
|
mov eax, [current_slot]
|
|
|
|
mov eax, [eax + APPDATA.window]
|
2009-12-27 19:37:14 +01:00
|
|
|
rol ebx, 16
|
2023-09-22 18:31:40 +02:00
|
|
|
add bx, word[eax + WDATA.clientbox.left]
|
2009-12-27 19:37:14 +01:00
|
|
|
rol ebx, 16
|
|
|
|
rol ecx, 16
|
2023-09-22 18:31:40 +02:00
|
|
|
add cx, word[eax + WDATA.clientbox.top]
|
2009-12-27 19:37:14 +01:00
|
|
|
rol ecx, 16
|
|
|
|
pop eax
|
|
|
|
|
|
|
|
; basic checks passed, define the button
|
|
|
|
inc eax
|
|
|
|
mov [edi], ax
|
|
|
|
shl eax, 4
|
|
|
|
add edi, eax
|
2016-01-04 08:23:15 +01:00
|
|
|
; NOTE: this code doesn't rely on SYS_BUTTON struct,
|
|
|
|
; please revise it, if you change something.
|
2021-06-17 11:41:16 +02:00
|
|
|
mov ax, word [current_slot_idx]
|
2009-12-27 19:37:14 +01:00
|
|
|
stosw
|
|
|
|
mov ax, dx
|
|
|
|
stosw ; button id number: bits 0-15
|
|
|
|
mov eax, ebx
|
|
|
|
rol eax, 16
|
|
|
|
stosd ; x start | x size
|
|
|
|
mov eax, ecx
|
|
|
|
rol eax, 16
|
|
|
|
stosd ; y start | y size
|
|
|
|
mov eax, edx
|
|
|
|
shr eax, 16
|
|
|
|
stosw ; button id number: bits 16-31
|
|
|
|
|
|
|
|
; do we also need to draw the button?
|
|
|
|
test edx, 0x40000000
|
|
|
|
jnz .exit
|
|
|
|
|
2016-01-05 04:18:00 +01:00
|
|
|
and esi, 0xFFFFFF
|
2016-01-04 08:23:15 +01:00
|
|
|
xor edi, edi
|
|
|
|
push ebx ecx esi
|
2016-01-05 04:18:00 +01:00
|
|
|
dec cx
|
|
|
|
dec cx
|
2016-01-04 08:23:15 +01:00
|
|
|
cmp [buttontype], 1
|
|
|
|
jnz .draw
|
2016-01-05 04:18:00 +01:00
|
|
|
cmp cx, 65
|
2016-01-04 08:23:15 +01:00
|
|
|
jnc .draw
|
2014-11-22 00:27:14 +01:00
|
|
|
|
2016-01-04 08:23:15 +01:00
|
|
|
; calculate gradient data
|
|
|
|
mov eax, esi
|
|
|
|
shl eax, 8
|
|
|
|
mov edx, 3
|
|
|
|
.calculate:
|
|
|
|
rol eax, 8
|
|
|
|
shl al, 1
|
|
|
|
jnc @f
|
|
|
|
neg al
|
|
|
|
jnz @f
|
2016-01-05 04:18:00 +01:00
|
|
|
mov al, 64
|
2016-01-04 08:23:15 +01:00
|
|
|
@@:
|
2016-01-05 04:18:00 +01:00
|
|
|
cmp al, 65
|
|
|
|
jc @f
|
|
|
|
mov al, 64
|
2016-01-04 08:23:15 +01:00
|
|
|
@@:
|
|
|
|
div cl
|
|
|
|
shl ax, 8
|
|
|
|
dec edx
|
|
|
|
jnz .calculate
|
|
|
|
mov dl, cl
|
|
|
|
dec edx
|
|
|
|
shr edx, 1
|
|
|
|
shr eax, 8
|
|
|
|
mov edi, eax
|
|
|
|
mul edx
|
|
|
|
add esi, eax
|
|
|
|
|
|
|
|
.draw: ; calculate window-relative coordinates
|
|
|
|
movzx ebp, cx
|
|
|
|
dec ebp
|
2014-11-22 00:27:14 +01:00
|
|
|
shr ebx, 16
|
|
|
|
shr ecx, 16
|
2023-09-22 18:31:40 +02:00
|
|
|
mov eax, [current_slot]
|
|
|
|
mov eax, [eax + APPDATA.window]
|
|
|
|
add ebx, [eax + WDATA.box.left]
|
|
|
|
add ecx, [eax + WDATA.box.top]
|
2014-11-22 00:27:14 +01:00
|
|
|
mov eax, ebx
|
2015-07-19 17:56:04 +02:00
|
|
|
inc eax
|
2016-01-04 08:23:15 +01:00
|
|
|
mov edx, ebx
|
|
|
|
add dx, [esp+8]
|
|
|
|
dec edx
|
2014-11-22 00:27:14 +01:00
|
|
|
mov ebx, ecx
|
2009-12-27 19:37:14 +01:00
|
|
|
mov ecx, esi
|
2016-01-04 08:23:15 +01:00
|
|
|
shr ecx, 1
|
2016-01-05 04:18:00 +01:00
|
|
|
and cx, 7F7Fh
|
2016-01-04 08:23:15 +01:00
|
|
|
push esi
|
|
|
|
mov esi, edi
|
2014-11-22 00:27:14 +01:00
|
|
|
xor edi, edi
|
2016-01-04 08:23:15 +01:00
|
|
|
call hline ; top border
|
|
|
|
inc ebx
|
2016-01-05 04:18:00 +01:00
|
|
|
or ecx, 808080h
|
|
|
|
call hline ; top light line
|
2016-01-04 08:23:15 +01:00
|
|
|
pop ecx
|
2016-01-05 04:18:00 +01:00
|
|
|
inc ebx
|
2016-01-04 08:23:15 +01:00
|
|
|
.next_line:
|
|
|
|
call hline ; button body
|
|
|
|
inc ebx
|
|
|
|
sub ecx, esi
|
|
|
|
dec ebp
|
2009-12-27 19:37:14 +01:00
|
|
|
jnz .next_line
|
2016-01-05 04:18:00 +01:00
|
|
|
shr ecx, 2
|
|
|
|
and cx, 3F3Fh
|
|
|
|
mov ebp, ecx
|
|
|
|
shl ecx, 1
|
|
|
|
add ecx, ebp
|
|
|
|
call hline ; bottom dark line
|
|
|
|
inc ebx
|
|
|
|
sub ecx, ebp
|
2016-01-04 08:23:15 +01:00
|
|
|
call hline ; bottom border
|
|
|
|
pop ecx
|
|
|
|
shr ecx, 1
|
|
|
|
inc edx
|
2014-11-22 00:27:14 +01:00
|
|
|
push edx
|
|
|
|
mov edx, ebx
|
2016-01-04 08:23:15 +01:00
|
|
|
sub bx, [esp+4]
|
|
|
|
dec edx
|
|
|
|
inc ebx
|
2016-01-05 04:18:00 +01:00
|
|
|
cmp [buttontype], 0
|
|
|
|
jnz @f
|
|
|
|
dec edx
|
|
|
|
or ecx, 808080h
|
|
|
|
call vline ; left light line
|
|
|
|
inc edx
|
2016-01-04 08:23:15 +01:00
|
|
|
@@:
|
2016-01-05 04:18:00 +01:00
|
|
|
and ecx, 7F7F7Fh
|
|
|
|
dec eax
|
2016-01-04 08:23:15 +01:00
|
|
|
call vline ; left border
|
|
|
|
pop eax
|
|
|
|
call vline ; right border
|
2016-01-05 04:18:00 +01:00
|
|
|
cmp [buttontype], 0
|
|
|
|
jnz @f
|
|
|
|
mov ebp, ecx
|
|
|
|
shr ecx, 1
|
|
|
|
and cx, 7F7Fh
|
|
|
|
add ecx, ebp
|
|
|
|
dec eax
|
|
|
|
inc ebx
|
2021-06-22 21:41:46 +02:00
|
|
|
dec edx ; avoid lines overflow
|
2016-01-05 04:18:00 +01:00
|
|
|
call vline ; right dark line
|
|
|
|
@@:
|
2014-11-22 00:27:14 +01:00
|
|
|
pop ecx ebx
|
2016-01-04 08:23:15 +01:00
|
|
|
.exit:
|
2009-12-27 19:37:14 +01:00
|
|
|
ret
|
|
|
|
|
|
|
|
; FIXME: mutex needed
|
2016-01-04 08:23:15 +01:00
|
|
|
.remove_button:
|
2009-12-27 19:37:14 +01:00
|
|
|
and edx, 0x00ffffff
|
|
|
|
mov edi, [BTN_ADDR]
|
|
|
|
mov ebx, [edi]
|
|
|
|
inc ebx
|
2012-02-23 19:52:13 +01:00
|
|
|
imul esi, ebx, sizeof.SYS_BUTTON
|
2009-12-27 19:37:14 +01:00
|
|
|
add esi, edi
|
|
|
|
xor ecx, ecx
|
2012-02-23 19:52:13 +01:00
|
|
|
add ecx, -sizeof.SYS_BUTTON
|
|
|
|
add esi, sizeof.SYS_BUTTON
|
2009-12-27 19:37:14 +01:00
|
|
|
|
2016-01-04 08:23:15 +01:00
|
|
|
.next_button:
|
2009-12-27 19:37:14 +01:00
|
|
|
dec ebx
|
|
|
|
jz .exit
|
|
|
|
|
2012-02-23 19:52:13 +01:00
|
|
|
add ecx, sizeof.SYS_BUTTON
|
|
|
|
add esi, -sizeof.SYS_BUTTON
|
2009-12-27 19:37:14 +01:00
|
|
|
|
|
|
|
; does it belong to our process?
|
2021-06-17 11:41:16 +02:00
|
|
|
mov ax, word [current_slot_idx]
|
2009-12-27 19:37:14 +01:00
|
|
|
cmp ax, [esi + SYS_BUTTON.pslot]
|
|
|
|
jne .next_button
|
|
|
|
|
|
|
|
; does the identifier match?
|
|
|
|
mov eax, dword[esi + SYS_BUTTON.id_hi - 2]
|
|
|
|
mov ax, [esi + SYS_BUTTON.id_lo]
|
|
|
|
and eax, 0x00ffffff
|
|
|
|
cmp edx, eax
|
|
|
|
jne .next_button
|
|
|
|
|
|
|
|
; okay, undefine it
|
2009-12-29 22:29:30 +01:00
|
|
|
push ebx
|
2009-12-27 19:37:14 +01:00
|
|
|
mov ebx, esi
|
2012-02-23 19:52:13 +01:00
|
|
|
lea eax, [esi + sizeof.SYS_BUTTON]
|
2009-12-27 19:37:14 +01:00
|
|
|
call memmove
|
|
|
|
dec dword[edi]
|
2012-02-23 19:52:13 +01:00
|
|
|
add ecx, -sizeof.SYS_BUTTON
|
2009-12-29 22:29:30 +01:00
|
|
|
pop ebx
|
2009-12-27 19:37:14 +01:00
|
|
|
jmp .next_button
|
|
|
|
|
2016-01-04 08:23:15 +01:00
|
|
|
;---------------------------------------------------------------
|
|
|
|
sys_button_activate_handler:
|
|
|
|
sys_button_deactivate_handler:
|
|
|
|
;---------------------------------------------------------------
|
2010-02-06 20:08:19 +01:00
|
|
|
;> eax = pack[8(process slot), 24(button id)]
|
|
|
|
;> ebx = pack[16(button x coord), 16(button y coord)]
|
|
|
|
;> cl = mouse button mask this system button was pressed with
|
2016-01-04 08:23:15 +01:00
|
|
|
;---------------------------------------------------------------
|
|
|
|
; find system button by specified process slot, id and coordinates
|
2010-02-06 20:08:19 +01:00
|
|
|
push ecx edx esi edi
|
|
|
|
mov edx, eax
|
|
|
|
shr edx, 24
|
|
|
|
and eax, 0x0ffffff
|
|
|
|
mov edi, [BTN_ADDR]
|
|
|
|
mov ecx, [edi]
|
2012-02-23 19:52:13 +01:00
|
|
|
imul esi, ecx, sizeof.SYS_BUTTON
|
2010-02-06 20:08:19 +01:00
|
|
|
add esi, edi
|
|
|
|
inc ecx
|
2012-02-23 19:52:13 +01:00
|
|
|
add esi, sizeof.SYS_BUTTON
|
2016-01-04 08:23:15 +01:00
|
|
|
.next_button:
|
2010-02-06 20:08:19 +01:00
|
|
|
dec ecx
|
2016-01-04 08:23:15 +01:00
|
|
|
jz .popexit
|
2012-02-23 19:52:13 +01:00
|
|
|
add esi, -sizeof.SYS_BUTTON
|
2009-12-27 19:37:14 +01:00
|
|
|
|
2010-02-06 20:08:19 +01:00
|
|
|
; does it belong to our process?
|
|
|
|
cmp dx, [esi + SYS_BUTTON.pslot]
|
|
|
|
jne .next_button
|
2009-12-27 19:37:14 +01:00
|
|
|
|
2010-02-06 20:08:19 +01:00
|
|
|
; does id match?
|
|
|
|
mov edi, dword[esi + SYS_BUTTON.id_hi - 2]
|
|
|
|
mov di, [esi + SYS_BUTTON.id_lo]
|
|
|
|
and edi, 0x0ffffff
|
|
|
|
cmp eax, edi
|
|
|
|
jne .next_button
|
2009-12-27 19:37:14 +01:00
|
|
|
|
2010-02-06 20:08:19 +01:00
|
|
|
; does coordinates match?
|
|
|
|
mov edi, dword[esi + SYS_BUTTON.left - 2]
|
|
|
|
mov di, [esi + SYS_BUTTON.top]
|
|
|
|
cmp ebx, edi
|
|
|
|
jne .next_button
|
2009-12-27 19:37:14 +01:00
|
|
|
|
2010-02-06 20:08:19 +01:00
|
|
|
mov eax, esi
|
|
|
|
pop edi esi edx ecx
|
2016-01-04 08:23:15 +01:00
|
|
|
mov ebx, dword[eax + SYS_BUTTON.id_hi - 2]
|
2009-12-27 19:37:14 +01:00
|
|
|
|
2016-01-04 08:23:15 +01:00
|
|
|
; display button border on press?
|
2016-01-07 17:29:25 +01:00
|
|
|
bt ebx, 29
|
|
|
|
jc .exit
|
2009-12-27 19:37:14 +01:00
|
|
|
|
2016-01-04 08:23:15 +01:00
|
|
|
; invert system button border
|
2009-12-27 19:37:14 +01:00
|
|
|
pushad
|
2016-01-04 08:23:15 +01:00
|
|
|
mov esi, eax
|
2016-01-07 17:29:25 +01:00
|
|
|
mov edi, ebx
|
2010-01-05 02:28:11 +01:00
|
|
|
movzx ecx, [esi + SYS_BUTTON.pslot]
|
2023-06-25 18:42:10 +02:00
|
|
|
shl ecx, BSF sizeof.WDATA
|
2010-01-05 02:28:11 +01:00
|
|
|
mov eax, dword[esi + SYS_BUTTON.left]
|
|
|
|
mov ebx, dword[esi + SYS_BUTTON.top]
|
2023-06-25 18:42:10 +02:00
|
|
|
add eax, [window_data + ecx + WDATA.box.left]
|
|
|
|
add ebx, [window_data + ecx + WDATA.box.top]
|
2016-01-07 09:45:03 +01:00
|
|
|
mov ecx, eax
|
|
|
|
mov edx, ebx
|
2016-01-07 17:29:25 +01:00
|
|
|
bt edi, 30
|
|
|
|
jc @f
|
2016-01-07 09:45:03 +01:00
|
|
|
inc ax
|
|
|
|
inc bx
|
2016-01-07 17:29:25 +01:00
|
|
|
dec cx
|
|
|
|
dec dx
|
|
|
|
@@:
|
2010-01-05 02:28:11 +01:00
|
|
|
rol eax, 16
|
|
|
|
rol ebx, 16
|
2016-01-07 09:45:03 +01:00
|
|
|
add ax, cx
|
|
|
|
add bx, dx
|
|
|
|
mov esi, 1000000h
|
|
|
|
call draw_rectangle.forced
|
2014-06-10 22:02:53 +02:00
|
|
|
popad
|
2016-01-04 08:23:15 +01:00
|
|
|
.exit:
|
|
|
|
ret
|
|
|
|
.popexit:
|
|
|
|
pop edi esi edx ecx
|
|
|
|
ret
|
2014-11-22 00:27:14 +01:00
|
|
|
|
2016-01-04 08:23:15 +01:00
|
|
|
;---------------------------------------------------------------
|
|
|
|
sys_button_perform_handler:
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
;> eax = pack[8(process slot), 24(button id)]
|
|
|
|
;> ebx = pack[16(button x coord), 16(button y coord)]
|
|
|
|
;> cl = mouse button mask this system button was pressed with
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
shl eax, 8
|
|
|
|
mov al, cl
|
|
|
|
movzx ebx, byte[BTN_COUNT]
|
|
|
|
mov [BTN_BUFF + ebx * 4], eax
|
|
|
|
inc bl
|
|
|
|
mov [BTN_COUNT], bl
|
2009-12-27 19:37:14 +01:00
|
|
|
ret
|