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

	Surface		*surface	   = GetDrawSurface();
	Rect		 frame		   = Rect(GetRealPosition(), GetRealSize());
	Rect		 entryRect	   = frame;

	String		 visibleEntries;
	Int		 visibleEntryCount = 0;

	Int		 entriesWidth	   = 0;
	Int		 scrollbarHeight   = (scrollbar->IsVisible() ? scrollbar->GetHeight() : 0);

	switch (message)
	{
		case SP_PAINT:
			surface->StartPaint(frame);

			/* Update scrollbar if necessary.
			 */
			entriesWidth = GetEntriesWidth();

			if (entriesWidth > GetWidth() - 4)
			{
				scrollbar->SetMetrics(Point(1, 18), Size(GetWidth() - 2, scrollbar->GetHeight()));
				scrollbar->SetRange(0, entriesWidth - (GetWidth() - 4));

				scrollbar->SetPageSize(GetWidth() - 4);

				scrollbar->Show();

				scrollbarHeight = scrollbar->GetHeight();
			}
			else
			{
				scrollbar->Hide();

				scrollbarPos	= 0;
				scrollbarHeight = 0;
			}

			/* Set visibility of image entries first.
			 */
			entryRect.left	= -scrollbarPos;
			entryRect.right = -scrollbarPos;

			for (Int i = 0; i < Length(); i++)
			{
				ListEntry	*entry = GetNthEntry(i);

				entry->SetVisibleDirect(False);

				if (entryRect.right + entry->GetWidth() >= 0 && entryRect.left <= GetWidth() - 4)
				{
					entry->SetMetrics(Point(entryRect.left + 2, 2), Size(entry->GetWidth(), GetHeight() - 4 - scrollbarHeight));
					entry->SetVisibleDirect(True);

					visibleEntries[visibleEntryCount++] = entry->GetHandle() % 32767 + 1;
				}

				entryRect.left	+= entry->GetWidth();
				entryRect.right += entry->GetWidth();
			}

			visibleEntriesString = visibleEntries;

			/* Now paint the imagebox and all entries.
			 */
			if (IsActive())	surface->Box(frame - Size(0, scrollbarHeight), Setup::ClientColor, Rect::Filled);
			else		surface->Box(frame - Size(0, scrollbarHeight), Setup::BackgroundColor, Rect::Filled);

			surface->Frame(frame, FRAME_DOWN);

			Widget::Paint(message);

			surface->EndPaint();

			break;
		case SP_UPDATE:
			/* Update scrollbar if necessary.
			 */
			entriesWidth = GetEntriesWidth();

			if ((entriesWidth >  GetWidth() - 4 && !scrollbar->IsVisible()) ||
			    (entriesWidth <= GetWidth() - 4 &&  scrollbar->IsVisible())) return Paint(SP_PAINT);

			scrollbar->SetRange(0, entriesWidth - (GetWidth() - 4));

			/* Find visible entries.
			 */
			entryRect.left	= -scrollbarPos;
			entryRect.right = -scrollbarPos;

			for (Int i = 0; i < Length(); i++)
			{
				ListEntry	*entry = GetNthEntry(i);

				if (entryRect.right + entry->GetWidth() >= 0 && entryRect.left <= GetWidth() - 4)
				{
					visibleEntries[visibleEntryCount++] = entry->GetHandle() % 32767 + 1;
				}

				entryRect.left	+= entry->GetWidth();
				entryRect.right += entry->GetWidth();
			}

			/* Check for changes.
			 */
			if (visibleEntriesString != visibleEntries) Paint(SP_PAINT);

			break;
	}

	return Success();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movq (%rdi), %rax
callq *0x88(%rax)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testb %al, %al
je 0x81854
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x90(%rax)
xorl %r14d, %r14d
testb %al, %al
je 0x81854
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
movq %rax, %r12
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
movq %rax, %r14
movq %rax, %r15
shrq $0x20, %r15
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x50(%rax)
leal (%rax,%r14), %ecx
shrq $0x20, %rax
movl %r14d, 0x18(%rsp)
movl %r15d, 0x1c(%rsp)
movl %ecx, 0x20(%rsp)
addl %r15d, %eax
movl %eax, 0x24(%rsp)
leaq 0x38(%rsp), %rdi
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x58e20
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testl %ebp, %ebp
je 0x814b4
cmpl $0x1, %ebp
jne 0x8184a
movq %rbx, %rdi
callq 0x56c70
movl %eax, %r14d
movl 0xb0(%rbx), %eax
addl $-0x4, %eax
cmpl %eax, %r14d
jle 0x81477
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
je 0x814a1
movl 0xb0(%rbx), %eax
addl $-0x4, %eax
cmpl %eax, %r14d
jg 0x81561
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
je 0x81561
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
movl %eax, %r14d
jmp 0x8184a
leaq 0x18(%rsp), %rsi
movq %r12, %rdi
callq 0x55160
movq %rbx, %rdi
callq 0x56c70
movl %eax, %ebp
movl 0xb0(%rbx), %eax
leal -0x4(%rax), %ecx
movq 0x6c8(%rbx), %rdi
cmpl %ecx, %ebp
movq %r12, 0x50(%rsp)
jle 0x81654
movabsq $0x1200000001, %rcx     # imm = 0x1200000001
leaq 0x28(%rsp), %rsi
movq %rcx, (%rsi)
addl $-0x2, %eax
movl 0xb4(%rdi), %ecx
leaq 0x10(%rsp), %rdx
movl %eax, (%rdx)
movl %ecx, 0x4(%rdx)
movq (%rdi), %rax
callq *0x150(%rax)
movq 0x6c8(%rbx), %rdi
subl 0xb0(%rbx), %ebp
addl $0x4, %ebp
xorl %esi, %esi
movl %ebp, %edx
callq 0x557e0
movq 0x6c8(%rbx), %rdi
movl 0xb0(%rbx), %eax
addl $-0x4, %eax
movl %eax, 0x654(%rdi)
movq (%rdi), %rax
callq *0x58(%rax)
movq 0x6c8(%rbx), %rax
movl 0xb4(%rax), %eax
movl %eax, 0xc(%rsp)
jmp 0x8166c
movq 0x6c8(%rbx), %rdi
subl 0xb0(%rbx), %r14d
addl $0x4, %r14d
movl $0x0, 0x8(%rsp)
xorl %esi, %esi
movl %r14d, %edx
callq 0x557e0
xorl %r13d, %r13d
subl 0x6d0(%rbx), %r13d
movl %r13d, %r14d
xorl %r15d, %r15d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
cmpl %eax, %r15d
jge 0x81625
movq (%rbx), %rax
movq %rbx, %rdi
movl %r15d, %esi
callq *0x180(%rax)
movq %rax, %r12
movl 0xb0(%rax), %eax
addl %r13d, %eax
js 0x8160f
movl 0xb0(%rbx), %eax
addl $-0x4, %eax
cmpl %eax, %r14d
jg 0x8160f
movl 0x8(%r12), %ebp
leaq 0x38(%rsp), %rdi
movl 0x8(%rsp), %esi
callq 0x58990
incl 0x8(%rsp)
movslq %ebp, %rcx
imulq $-0x7ffefffd, %rcx, %rdx # imm = 0x80010003
shrq $0x20, %rdx
addl %ecx, %edx
movl %edx, %esi
shrl $0x1f, %esi
sarl $0xe, %edx
addl %esi, %edx
movl %edx, %esi
shll $0xf, %esi
subl %esi, %edx
addl %edx, %ecx
incl %ecx
movl %ecx, (%rax)
movl 0xb0(%r12), %eax
addl %eax, %r14d
addl %eax, %r13d
incl %r15d
jmp 0x81595
leaq 0x6d8(%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0x56fa0
xorl %r14d, %r14d
testb %al, %al
je 0x8184a
movq (%rbx), %rax
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
jmp 0x8184a
movq (%rdi), %rax
callq *0x60(%rax)
movl $0x0, 0x6d0(%rbx)
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
xorl %r13d, %r13d
subl 0x6d0(%rbx), %r13d
movl %r13d, %r12d
xorl %r14d, %r14d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
cmpl %eax, %r14d
jge 0x8176b
movq (%rbx), %rax
movq %rbx, %rdi
movl %r14d, %esi
callq *0x180(%rax)
movq %rax, %r15
movb $0x0, 0xcb(%rax)
movl 0xb0(%rax), %eax
movl %eax, %ecx
addl %r13d, %ecx
js 0x81756
movl 0xb0(%rbx), %ecx
addl $-0x4, %ecx
cmpl %ecx, %r12d
jg 0x81756
leal 0x2(%r12), %ecx
movl %ecx, 0x28(%rsp)
movl $0x2, 0x2c(%rsp)
movl 0xb4(%rbx), %ecx
subl 0xc(%rsp), %ecx
addl $-0x4, %ecx
movl %eax, 0x10(%rsp)
movl %ecx, 0x14(%rsp)
movq (%r15), %rax
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq *0x150(%rax)
movb $0x1, 0xcb(%r15)
movl 0x8(%r15), %ebp
leaq 0x38(%rsp), %rdi
movl 0x8(%rsp), %esi
callq 0x58990
incl 0x8(%rsp)
movslq %ebp, %rcx
imulq $-0x7ffefffd, %rcx, %rdx # imm = 0x80010003
shrq $0x20, %rdx
addl %ecx, %edx
movl %edx, %esi
shrl $0x1f, %esi
sarl $0xe, %edx
addl %esi, %edx
movl %edx, %esi
shll $0xf, %esi
subl %esi, %edx
addl %edx, %ecx
incl %ecx
movl %ecx, (%rax)
movl 0xb0(%r15), %eax
addl %eax, %r12d
addl %eax, %r13d
incl %r14d
jmp 0x81684
leaq 0x6d8(%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0x555f0
movq 0x50(%rsp), %r15
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x98(%rax)
testb %al, %al
je 0x817db
movl 0x20(%rsp), %eax
movl 0x24(%rsp), %ecx
subl 0xc(%rsp), %ecx
movq 0x18(%rsp), %rdx
shlq $0x20, %rcx
orq %rax, %rcx
leaq 0x28(%rsp), %rsi
movq %rdx, (%rsi)
movq %rcx, 0x8(%rsi)
movq 0xeb7ec(%rip), %rax     # 0x16cfa8
movl (%rax), %ecx
leaq 0x10(%rsp), %r8
movq $0x0, (%r8)
movq 0xeae9f(%rip), %rdx     # 0x16c670
movq %r15, %rdi
callq 0x57930
jmp 0x81823
movl 0x20(%rsp), %eax
movl 0x24(%rsp), %ecx
subl 0xc(%rsp), %ecx
movq 0x18(%rsp), %rdx
shlq $0x20, %rcx
orq %rax, %rcx
leaq 0x28(%rsp), %rsi
movq %rdx, (%rsi)
movq %rcx, 0x8(%rsi)
movq 0xeb7a2(%rip), %rax     # 0x16cfa8
movl (%rax), %ecx
leaq 0x10(%rsp), %r8
movq $0x0, (%r8)
movq 0xeacb5(%rip), %rdx     # 0x16c4d0
movq %r15, %rdi
callq 0x57930
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
movl $0x1, %edx
callq 0x57890
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x567d0
movq %r15, %rdi
callq 0x58780
leaq 0x38(%rsp), %rdi
callq 0x59200
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x81876
jmp 0x81876
jmp 0x81876
jmp 0x81876
jmp 0x81876
jmp 0x81876
jmp 0x81876
jmp 0x81876
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x59200
movq %rbx, %rdi
callq 0x57090
nop