// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/classes/gui/widgets/basic/image.cpp
// Function: smooth::GUI::Image::Paint(int)
S::Int S::GUI::Image::Paint(Int message)
{
	if (!IsRegistered()) return Error();
	if (!IsVisible())    return Success();

	switch (message)
	{
		case SP_PAINT:
			{
				Surface	*surface = GetDrawSurface();

				/* Scale image if necessary.
				 */
				Size	 size	  = GetSize();
				Size	 bmpSize  = bitmap.GetSize();
				Size	 newSize  = bmpSize;

				if	(Float(bmpSize.cx) / size.cx >= Float(bmpSize.cy) / size.cy && bmpSize.cx > size.cx) newSize = newSize * (Float(size.cx) / bmpSize.cx);
				else if (Float(bmpSize.cy) / size.cy >= Float(bmpSize.cx) / size.cx && bmpSize.cy > size.cy) newSize = newSize * (Float(size.cy) / bmpSize.cy);

				newSize = newSize * surface->GetSurfaceDPI() / 96.0;

				/* Draw image centered.
				 */
				Size	 realSize = GetRealSize();
				Rect	 bmpRect  = Rect(GetRealPosition() + Point(realSize.cx - newSize.cx, realSize.cy - newSize.cy) / 2, newSize);

				surface->StartPaint(GetVisibleArea());

				if (bmpSize != newSize && bitmapScaled.GetSize() != newSize) bitmapScaled = bitmap.Scale(newSize);

				if (bmpSize == newSize) surface->BlitFromBitmap(bitmap,	      Rect(Point(0, 0), bmpSize), bmpRect);
				else			surface->BlitFromBitmap(bitmapScaled, Rect(Point(0, 0), newSize), bmpRect);

				surface->EndPaint();
			}

			break;
	}

	return Success();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, %ebp
movq %rdi, %r14
movq (%rdi), %rax
callq *0x88(%rax)
testb %al, %al
je 0x76fb8
movq (%r14), %rax
movq %r14, %rdi
callq *0x90(%rax)
xorl %ebx, %ebx
testl %ebp, %ebp
jne 0x7717f
testb %al, %al
je 0x7717f
movq (%r14), %rax
movq %r14, %rdi
callq *0x40(%rax)
movq %rax, %r15
movl 0xb0(%r14), %ebp
movl 0xb4(%r14), %ebx
leaq 0x5b8(%r14), %rdi
movq %rdi, 0x18(%rsp)
callq 0x596e0
movq (%rax), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
cvtsi2sd %edx, %xmm3
cvtsi2sd %ebp, %xmm1
movq %rdx, (%rsp)
movapd %xmm3, %xmm4
cvtsi2sd %esi, %xmm2
divsd %xmm1, %xmm4
cvtsi2sd %ebx, %xmm0
movapd %xmm2, %xmm5
divsd %xmm0, %xmm5
ucomisd %xmm5, %xmm4
setae %al
cmpl %edx, %ebp
setl %cl
andb %al, %cl
cmpb $0x1, %cl
movq %rdx, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
jne 0x76fc0
divsd %xmm3, %xmm1
movq %rsp, %r12
movq %r12, %rdi
movapd %xmm1, %xmm0
jmp 0x76fdd
pushq $-0x1
popq %rbx
jmp 0x7717f
ucomisd %xmm4, %xmm5
setae %al
cmpl %esi, %ebx
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x76fe6
divsd %xmm2, %xmm0
movq %rsp, %r12
movq %r12, %rdi
callq 0x57480
movq %rax, (%r12)
movq %r15, %rdi
callq 0x59c60
cwtl
cvtsi2sd %eax, %xmm0
movq %rsp, %r12
movq %r12, %rdi
callq 0x57480
leaq 0x38(%rsp), %rdi
movq %rax, (%rdi)
movsd 0x6c502(%rip), %xmm0    # 0xe3510
callq 0x59050
movq %rax, (%r12)
movq (%r14), %rax
movq %r14, %rdi
callq *0x50(%rax)
movq %rax, %r13
movq %r15, 0x30(%rsp)
movq %rax, %r15
shrq $0x20, %r15
movq (%r14), %rax
movq %r14, %rdi
callq *0x48(%rax)
movq %rax, %rbp
movq %rax, %rbx
shrq $0x20, %rbx
movl (%r12), %eax
subl 0x4(%r12), %r15d
subl %eax, %r13d
leaq 0x8(%rsp), %r12
movl %r13d, (%r12)
movl %r15d, 0x4(%r12)
movq 0x30(%rsp), %r15
movsd 0x6c327(%rip), %xmm0    # 0xe3390
movq %r12, %rdi
callq 0x59600
movq %rax, %rcx
shrq $0x20, %rcx
addl %ebp, %eax
addl %ebx, %ecx
leaq 0x38(%rsp), %rsi
movl %eax, (%rsi)
movl %ecx, 0x4(%rsi)
movq %rsp, %rdx
addl (%rdx), %eax
movl %eax, 0x8(%rsi)
addl 0x4(%rdx), %ecx
movq %rdx, %rbx
movl %ecx, 0xc(%rsi)
movq (%r14), %rax
movq %r14, %rdi
callq *0x130(%rax)
movq %rax, (%r12)
movq %rdx, 0x8(%r12)
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x56160
movq 0x28(%rsp), %r13
cmpl %r13d, (%rbx)
movq 0x20(%rsp), %rbp
jne 0x770d3
movl %ebp, %eax
movl %r13d, %ecx
cmpl %ebp, 0x4(%rsp)
je 0x77123
leaq 0x5c0(%r14), %r12
movq %r12, %rdi
callq 0x596e0
movl (%rax), %ecx
cmpl (%rsp), %ecx
jne 0x770f2
movl 0x4(%rax), %eax
cmpl 0x4(%rsp), %eax
je 0x77123
leaq 0x8(%rsp), %rbx
movq %rsp, %rdx
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0x56500
movq %r12, %rdi
movq %rbx, %rsi
callq 0x59570
leaq 0x8(%rsp), %rdi
callq 0x5a4c8
movl (%rsp), %ecx
movl 0x4(%rsp), %eax
movl %ecx, %edx
xorl %r13d, %edx
movl %eax, %esi
xorl %ebp, %esi
orl %edx, %esi
jne 0x7714f
leaq 0x8(%rsp), %rdx
andq $0x0, (%rdx)
movl %r13d, 0x8(%rdx)
movl %ebp, 0xc(%rdx)
leaq 0x38(%rsp), %rcx
movq %r15, %rdi
movq 0x18(%rsp), %rsi
jmp 0x77170
leaq 0x8(%rsp), %rdx
andq $0x0, (%rdx)
addq $0x5c0, %r14            # imm = 0x5C0
movl %ecx, 0x8(%rdx)
movl %eax, 0xc(%rdx)
leaq 0x38(%rsp), %rcx
movq %r15, %rdi
movq %r14, %rsi
callq 0x56c20
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x59a80
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x5a4c8
movq %rbx, %rdi
callq 0x58260
nopl (%rax)