fix progressbar_draw, optimizations, formatting fixes

git-svn-id: svn://kolibrios.org@4116 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
0CodErr 2013-10-28 11:50:01 +00:00
parent 44d21dbf19
commit 8e9dbc453a

View File

@ -1,96 +1,84 @@
macro use_progressbar macro use_progressbar
{ {
pb equ [ebp + 4 + 8*4] pb equ [esp + 4 + 8*4]
align 16 align 16
progressbar_draw: progressbar_draw:
pushad pushad
mov ebp, esp
; draw frame ; draw frame
push ebp
mov [.last_esp], esp
mov eax, pb mov eax, pb
mov esi, [eax + PB_LEFT] mov edx, [eax + PB_FRAME_COLOR]
mov ebx, [eax + PB_LEFT]
mov edi, [eax + PB_TOP] mov edi, [eax + PB_TOP]
mov ebp, [eax + PB_WIDTH] mov ebp, [eax + PB_WIDTH]
add ebp, esi mov esi, [eax + PB_HEIGHT]
dec ebp add ebp, ebx
mov esp, [eax + PB_HEIGHT] add esi, edi
add esp, edi dec ebp
dec esp dec esi
mov edx, [eax + PB_FRAME_COLOR]
mov eax, 38 mov eax, 38
mov ebx, esi
shl ebx, 16 shl ebx, 16
add ebx, ebp mov bx, bp
mov ecx, edi shrd ecx, edi, 16
shl ecx, 16 mov cx, di
add ecx, edi
int 64 int 64
mov ecx, esp shrd ecx, esi, 16
shl ecx, 16 mov cx, si
add ecx, esp
int 64 int 64
shld esi, ebx, 16
mov bx, si mov bx, si
mov ecx, edi shrd ecx, edi, 16
shl ecx, 16
add ecx, esp
int 64 int 64
mov ebx, ebp shrd ebx, ebp, 16
shl ebx, 16 mov bx, bp
add ebx, ebp
int 64 int 64
mov esp, [.last_esp]
pop ebp
; if min > max then .skip ; if min > max then .skip
mov eax, pb mov eax, pb
mov edx, [eax + PB_MAX] mov edx, [eax + PB_MAX]
mov ecx, [eax + PB_MIN] mov ecx, [eax + PB_MIN]
cmp ecx, edx cmp ecx, edx
; jg .skip ; jg .skip
jne .min_no_eq_max jne .min_no_eq_max
dec edx dec edx
.min_no_eq_max: .min_no_eq_max:
; draw all progress rectangle ; draw all progress rectangle
call get_progress_width call get_progress_width
mov edi, eax mov edi, eax
mov eax, pb mov eax, pb
mov ebx, [eax + PB_LEFT] mov ebx, [eax + PB_LEFT]
inc ebx
shl ebx, 16
add ebx, edi
mov ecx, [eax + PB_TOP] mov ecx, [eax + PB_TOP]
inc ecx
shl ecx, 16
add ecx, [eax + PB_HEIGHT]
dec ecx
dec ecx
mov edx, [eax + PB_PROGRESS_COLOR] mov edx, [eax + PB_PROGRESS_COLOR]
mov eax, 13 inc ebx
inc ecx
shl ebx, 16
shl ecx, 16
add ebx, edi
add ecx, [eax + PB_HEIGHT]
dec ecx
mov eax, 13
dec ecx
int 64 int 64
; draw last part of non-progress rectangle ; draw last part of non-progress rectangle
; edi = pW, esi = W - 2 ; edi = pW, esi = W - 2
sub esi, edi ; width sub esi, edi ; width
shr ebx, 16 shr ebx, 16
add ebx, edi add ebx, edi
shl ebx, 16 shl ebx, 16
add ebx, esi add ebx, esi
mov esi, pb mov esi, pb
mov edx, [esi + PB_BACK_COLOR] mov edx, [esi + PB_BACK_COLOR]
int 64 int 64
; .skip: ; .skip:
popad popad
ret 4 ret 4
.last_esp dd 0
align 16 align 16
get_progress_width: get_progress_width:
; pW = (W-2)(value - min) / (max - min) ; pW = (W-2)(value - min) / (max - min)
mov esi, [eax + PB_WIDTH] mov esi, [eax + PB_WIDTH]
dec esi
dec esi
mov eax, [eax + PB_VALUE] mov eax, [eax + PB_VALUE]
dec esi
sub eax, ecx sub eax, ecx
dec esi
imul eax, esi imul eax, esi
neg ecx neg ecx
add ecx, edx add ecx, edx
@ -98,61 +86,59 @@ get_progress_width:
div ecx div ecx
ret ret
align 16 align 16
progressbar_progress: progressbar_progress:
pushad pushad
mov ebp, esp
; if min > max then .skip ; if min > max then .skip
mov eax, pb mov eax, pb
mov edx, [eax + PB_MAX] mov edx, [eax + PB_MAX]
mov ecx, [eax + PB_MIN] mov ecx, [eax + PB_MIN]
cmp ecx, edx cmp ecx, edx
; jg .skip ; jg .skip
jne .min_no_eq_max1 jne .min_no_eq_max1
dec edx dec edx
.min_no_eq_max1: .min_no_eq_max1:
call get_progress_width call get_progress_width
mov edi, eax mov edi, eax
; increase value ; increase value
mov eax, pb mov eax, pb
mov edx, [eax + PB_MAX] mov ecx, [eax + PB_VALUE]
mov ecx, [eax + PB_VALUE] mov edx, [eax + PB_MAX]
inc ecx inc ecx
; if value > max then value = max ; if value > max then value = max
cmp ecx, edx cmp ecx, edx
jng .next jng .next
mov ecx, edx mov ecx, edx
.next: .next:
mov [eax + PB_VALUE], ecx mov [eax + PB_VALUE], ecx
; draw new part of progress rectangle ; draw new part of progress rectangle
mov eax, pb mov eax, pb
mov ecx, [eax + PB_MIN] mov ecx, [eax + PB_MIN]
cmp ecx, edx cmp ecx, edx
jne .min_no_eq_max2 jne .min_no_eq_max2
dec edx dec edx
.min_no_eq_max2: .min_no_eq_max2:
call get_progress_width call get_progress_width
mov esi, eax mov esi, eax
; edi = last pW, esi = new pW ; edi = last pW, esi = new pW
mov eax, pb mov eax, pb
mov ebx, [eax + PB_LEFT] mov ebx, [eax + PB_LEFT]
inc ebx
add ebx, edi
shl ebx, 16
add ebx, esi
sub ebx, edi
mov ecx, [eax + PB_TOP] mov ecx, [eax + PB_TOP]
inc ecx
shl ecx, 16
add ecx, [eax + PB_HEIGHT]
dec ecx
dec ecx
mov edx, [eax + PB_PROGRESS_COLOR] mov edx, [eax + PB_PROGRESS_COLOR]
mov eax, 13 inc ebx
inc ecx
add ebx, edi
shl ecx, 16
shl ebx, 16
add ecx, [eax + PB_HEIGHT]
add ebx, esi
dec ecx
sub ebx, edi
mov eax, 13
dec ecx
int 64 int 64
; .skip: ; .skip:
popad popad
ret 4 ret 4
restore pb restore pb
} }