Button style and code refactoring

git-svn-id: svn://kolibrios.org@6031 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
pathoswithin 2016-01-04 07:23:15 +00:00
parent 7c2f6e07b1
commit a060f178c9

View File

@ -8,10 +8,6 @@
$Revision$ $Revision$
;==============================================================================
;///// public functions ///////////////////////////////////////////////////////
;==============================================================================
button.MAX_BUTTONS = 4095 button.MAX_BUTTONS = 4095
struct SYS_BUTTON struct SYS_BUTTON
@ -25,12 +21,11 @@ struct SYS_BUTTON
dw ? dw ?
ends ends
align 4 ;---------------------------------------------------------------
;------------------------------------------------------------------------------ syscall_button: ;////////////// system function 8 //////////////
syscall_button: ;///// system function 8 ////////////////////////////////////// ;---------------------------------------------------------------
;------------------------------------------------------------------------------
;? Define/undefine GUI button object ;? Define/undefine GUI button object
;------------------------------------------------------------------------------ ;---------------------------------------------------------------
;; Define button: ;; Define button:
;> ebx = pack[16(x), 16(width)] ;> ebx = pack[16(x), 16(width)]
;> ecx = pack[16(y), 16(height)] ;> ecx = pack[16(y), 16(height)]
@ -40,12 +35,12 @@ syscall_button: ;///// system function 8 //////////////////////////////////////
;> 6 (30) = don't draw button ;> 6 (30) = don't draw button
;> 5 (29) = don't draw button frame when pressed ;> 5 (29) = don't draw button frame when pressed
;> esi = button color ;> esi = button color
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;; Undefine button: ;; Undefine button:
;> edx = pack[8(flags), 24(button identifier)] ;> edx = pack[8(flags), 24(button identifier)]
;> flags bits: ;> flags bits:
;> 7 (31) = 1 ;> 7 (31) = 1
;------------------------------------------------------------------------------ ;---------------------------------------------------------------
; do we actually need to undefine the button? ; do we actually need to undefine the button?
test edx, 0x80000000 test edx, 0x80000000
jnz .remove_button jnz .remove_button
@ -74,13 +69,12 @@ syscall_button: ;///// system function 8 //////////////////////////////////////
pop eax pop eax
; basic checks passed, define the button ; basic checks passed, define the button
push ebx ecx edx
inc eax inc eax
mov [edi], ax mov [edi], ax
shl eax, 4 shl eax, 4
add edi, eax add edi, eax
; NOTE: this code doesn't rely on SYS_BUTTON struct, please revise it ; NOTE: this code doesn't rely on SYS_BUTTON struct,
; if you change something ; please revise it, if you change something.
mov ax, [CURRENT_TASK] mov ax, [CURRENT_TASK]
stosw stosw
mov ax, dx mov ax, dx
@ -94,18 +88,48 @@ syscall_button: ;///// system function 8 //////////////////////////////////////
mov eax, edx mov eax, edx
shr eax, 16 shr eax, 16
stosw ; button id number: bits 16-31 stosw ; button id number: bits 16-31
pop edx ecx ebx
; do we also need to draw the button? ; do we also need to draw the button?
test edx, 0x40000000 test edx, 0x40000000
jnz .exit jnz .exit
; draw button body xor edi, edi
push ebx ecx esi
cmp [buttontype], 1
jnz .draw
cmp cx, 129
jnc .draw
pushad ; 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
mov al, 128
@@:
jns @f
mov al, 128
@@:
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
; calculate window-relative coordinates .draw: ; calculate window-relative coordinates
movzx edi, cx movzx ebp, cx
dec ebp
shr ebx, 16 shr ebx, 16
shr ecx, 16 shr ecx, 16
mov eax, [TASK_BASE] mov eax, [TASK_BASE]
@ -113,116 +137,53 @@ syscall_button: ;///// system function 8 //////////////////////////////////////
add ecx, [eax - twdw + WDATA.box.top] add ecx, [eax - twdw + WDATA.box.top]
mov eax, ebx mov eax, ebx
inc eax inc eax
shl eax, 16
mov ax, bx
add ax, word[esp + 16]
dec ax
mov ebx, ecx
shl ebx, 16
mov bx, cx
; calculate initial color
mov ecx, esi
cmp [buttontype], 0
je @f
call button._.incecx2
; set button height counter
@@:
mov edx, edi
add ebx, 0x00010001
dec edx
.next_line:
call button._.button_dececx
push edi
xor edi, edi
; call [draw_line]
call __sys_draw_line
pop edi
add ebx, 0x00010001
dec edx
jnz .next_line
popad
; draw button frame
push ebx ecx
; calculate window-relative coordinates
shr ebx, 16
shr ecx, 16
mov eax, [TASK_BASE]
add ebx, [eax - twdw + WDATA.box.left]
add ecx, [eax - twdw + WDATA.box.top]
; top border
mov eax, ebx
shl eax, 16
mov ax, bx
add ax, [esp + 4]
mov ebx, ecx
shl ebx, 16
mov bx, cx
push ebx
xor edi, edi
mov ecx, esi
; call button._.incecx
; call [draw_line]
call __sys_draw_line
; light line under top border
add ebx, 0x00010001
mov ecx, esi
call button._.incecx
call __sys_draw_line
sub ebx, 0x00010001
; bottom border
movzx edx, word[esp + 4 + 0]
add ebx, edx
shl edx, 16
add ebx, edx
mov ecx, esi
call button._.dececx
; call [draw_line]
call __sys_draw_line
; left border
pop ebx
push edx
mov edx, eax
shr edx, 16
mov ax, dx
mov edx, ebx mov edx, ebx
shr edx, 16 add dx, [esp+8]
mov bx, dx dec edx
add bx, [esp + 4 + 0] mov ebx, ecx
pop edx
mov ecx, esi mov ecx, esi
call button._.dececx ; button._.incecx shr ecx, 1
; call [draw_line] btr ecx, 7
dec ebx btr ecx, 15
call __sys_draw_line push esi
mov esi, edi
; right border xor edi, edi
mov dx, [esp + 4] call hline ; top border
add ax, dx inc ebx
shl edx, 16 pop ecx
add eax, edx .next_line:
add ebx, 0x00010000 call hline ; button body
mov ecx, esi inc ebx
call button._.dececx sub ecx, esi
; call [draw_line] dec ebp
call __sys_draw_line jnz .next_line
shr ecx, 1
btr ecx, 7
btr ecx, 15
call hline ; bottom border
pop ecx
shr ecx, 1
btr ecx, 7
btr ecx, 15
inc edx
push edx
mov edx, ebx
sub bx, [esp+4]
dec eax
cmp [buttontype], 1
jnz @f
dec edx
inc ebx
@@:
call vline ; left border
pop eax
call vline ; right border
pop ecx ebx pop ecx ebx
.exit: .exit:
ret ret
; FIXME: mutex needed ; FIXME: mutex needed
syscall_button.remove_button: .remove_button:
and edx, 0x00ffffff and edx, 0x00ffffff
mov edi, [BTN_ADDR] mov edi, [BTN_ADDR]
mov ebx, [edi] mov ebx, [edi]
@ -262,98 +223,28 @@ syscall_button.remove_button:
pop ebx pop ebx
jmp .next_button jmp .next_button
.exit: ;---------------------------------------------------------------
ret sys_button_activate_handler:
sys_button_deactivate_handler:
align 4 ;---------------------------------------------------------------
;------------------------------------------------------------------------------
sys_button_activate_handler: ;/////////////////////////////////////////////////
;------------------------------------------------------------------------------
;? <description>
;------------------------------------------------------------------------------
;> eax = pack[8(process slot), 24(button id)] ;> eax = pack[8(process slot), 24(button id)]
;> ebx = pack[16(button x coord), 16(button y coord)] ;> ebx = pack[16(button x coord), 16(button y coord)]
;> cl = mouse button mask this system button was pressed with ;> cl = mouse button mask this system button was pressed with
;------------------------------------------------------------------------------ ;---------------------------------------------------------------
call button._.find_button ; find system button by specified process slot, id and coordinates
or eax, eax
jz .exit
mov ebx, dword[eax + SYS_BUTTON.id_hi - 2]
call button._.negative_button
.exit:
ret
align 4
;------------------------------------------------------------------------------
sys_button_deactivate_handler: ;///////////////////////////////////////////////
;------------------------------------------------------------------------------
;? <description>
;------------------------------------------------------------------------------
;> 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
;------------------------------------------------------------------------------
call button._.find_button
or eax, eax
jz .exit
mov ebx, dword[eax + SYS_BUTTON.id_hi - 2]
call button._.negative_button
.exit:
ret
align 4
;------------------------------------------------------------------------------
sys_button_perform_handler: ;//////////////////////////////////////////////////
;------------------------------------------------------------------------------
;? <description>
;------------------------------------------------------------------------------
;> 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
ret
;==============================================================================
;///// private functions //////////////////////////////////////////////////////
;==============================================================================
;------------------------------------------------------------------------------
button._.find_button: ;////////////////////////////////////////////////////////
;------------------------------------------------------------------------------
;? Find system button by specified process slot, id and coordinates
;------------------------------------------------------------------------------
;> eax = pack[8(process slot), 24(button id)] or 0
;> ebx = pack[16(button x coord), 16(button y coord)]
;------------------------------------------------------------------------------
;< eax = pointer to SYS_BUTTON struct or 0
;------------------------------------------------------------------------------
push ecx edx esi edi push ecx edx esi edi
mov edx, eax mov edx, eax
shr edx, 24 shr edx, 24
and eax, 0x0ffffff and eax, 0x0ffffff
mov edi, [BTN_ADDR] mov edi, [BTN_ADDR]
mov ecx, [edi] mov ecx, [edi]
imul esi, ecx, sizeof.SYS_BUTTON imul esi, ecx, sizeof.SYS_BUTTON
add esi, edi add esi, edi
inc ecx inc ecx
add esi, sizeof.SYS_BUTTON add esi, sizeof.SYS_BUTTON
.next_button: .next_button:
dec ecx dec ecx
jz .not_found jz .popexit
add esi, -sizeof.SYS_BUTTON add esi, -sizeof.SYS_BUTTON
; does it belong to our process? ; does it belong to our process?
@ -373,147 +264,71 @@ button._.find_button: ;////////////////////////////////////////////////////////
cmp ebx, edi cmp ebx, edi
jne .next_button jne .next_button
; okay, return it
mov eax, esi mov eax, esi
jmp .exit
.not_found:
xor eax, eax
.exit:
pop edi esi edx ecx pop edi esi edx ecx
ret mov ebx, dword[eax + SYS_BUTTON.id_hi - 2]
;------------------------------------------------------------------------------ ; display button border on press?
button._.dececx: ;/////////////////////////////////////////////////////////////
;------------------------------------------------------------------------------
;? <description>
;------------------------------------------------------------------------------
sub cl, 0x20
jnc @f
xor cl, cl
@@:
sub ch, 0x20
jnc @f
xor ch, ch
@@:
rol ecx, 16
sub cl, 0x20
jnc @f
xor cl, cl
@@:
rol ecx, 16
ret
;------------------------------------------------------------------------------
button._.incecx: ;/////////////////////////////////////////////////////////////
;------------------------------------------------------------------------------
;? <description>
;------------------------------------------------------------------------------
add cl, 0x20
jnc @f
or cl, -1
@@:
add ch, 0x20
jnc @f
or ch, -1
@@:
rol ecx, 16
add cl, 0x20
jnc @f
or cl, -1
@@:
rol ecx, 16
ret
;------------------------------------------------------------------------------
button._.incecx2: ;////////////////////////////////////////////////////////////
;------------------------------------------------------------------------------
;? <description>
;------------------------------------------------------------------------------
add cl, 0x14
jnc @f
or cl, -1
@@:
add ch, 0x14
jnc @f
or ch, -1
@@:
rol ecx, 16
add cl, 0x14
jnc @f
or cl, -1
@@:
rol ecx, 16
ret
;------------------------------------------------------------------------------
button._.button_dececx: ;//////////////////////////////////////////////////////
;------------------------------------------------------------------------------
;? <description>
;------------------------------------------------------------------------------
cmp [buttontype], 1
jne .finish
push eax
mov al, 1
cmp edi, 20
jg @f
mov al, 2
@@:
sub cl, al
jnc @f
xor cl, cl
@@:
sub ch, al
jnc @f
xor ch, ch
@@:
rol ecx, 16
sub cl, al
jnc @f
xor cl, cl
@@:
rol ecx, 16
pop eax
.finish:
ret
;------------------------------------------------------------------------------
button._.negative_button: ;////////////////////////////////////////////////////
;------------------------------------------------------------------------------
;? Invert system button border
;------------------------------------------------------------------------------
; if requested, do not display button border on press.
test ebx, 0x20000000 test ebx, 0x20000000
jnz .exit jnz .exit
; invert system button border
pushad pushad
mov esi, eax
xchg esi, eax
movzx ecx, [esi + SYS_BUTTON.pslot] movzx ecx, [esi + SYS_BUTTON.pslot]
shl ecx, 5 shl ecx, 5
add ecx, window_data add ecx, window_data
mov eax, dword[esi + SYS_BUTTON.left] mov eax, dword[esi + SYS_BUTTON.left]
mov ebx, dword[esi + SYS_BUTTON.top] mov ebx, dword[esi + SYS_BUTTON.top]
add eax, [ecx + WDATA.box.left] add eax, [ecx + WDATA.box.left]
add ebx, [ecx + WDATA.box.top] add ebx, [ecx + WDATA.box.top]
push eax ebx
pop edx ecx
rol eax, 16 rol eax, 16
rol ebx, 16 rol ebx, 16
add ax, cx push eax ebx
add bx, dx shr eax, 16
shr ebx, 16
mov esi, 0x01000000 mov edx, eax
call draw_rectangle.forced add dx, [esp+4]
dec edx
inc eax
mov ecx, 1000000h
xor edi, edi
inc edi
call hline
add bx, [esp]
call hline
inc edx
push edx
mov edx, ebx
sub bx, [esp+4]
dec eax
cmp [buttontype], 1
jnz @f
dec edx
inc ebx
@@:
call vline
pop eax
call vline
pop eax eax
popad popad
.exit: .exit:
ret ret
.popexit:
pop edi esi edx ecx
ret
;---------------------------------------------------------------
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
ret