// File: /workspace/github_c_makefile_star2_O2/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)
testb %al, %al
je 0x7f10a
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x90(%rax)
xorl %r14d, %r14d
testb %al, %al
je 0x7f475
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, 0x10(%rsp)
movl %r15d, 0x14(%rsp)
movl %ecx, 0x18(%rsp)
addl %r15d, %eax
movl %eax, 0x1c(%rsp)
leaq 0x38(%rsp), %rdi
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x5a180
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testl %ebp, %ebp
je 0x7f113
cmpl $0x1, %ebp
jne 0x7f46b
movq %rbx, %rdi
callq 0x57df0
movl %eax, %r14d
movl 0xb0(%rbx), %eax
leal -0x4(%rax), %ecx
cmpl %ecx, %r14d
jle 0x7f0d6
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
je 0x7f0f7
movl 0xb0(%rbx), %eax
leal -0x4(%rax), %ecx
cmpl %ecx, %r14d
jg 0x7f397
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
je 0x7f391
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
movl %eax, %r14d
jmp 0x7f46b
pushq $-0x1
popq %r14
jmp 0x7f475
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x56160
movq %rbx, %rdi
callq 0x57df0
movl %eax, %ebp
movl 0xb0(%rbx), %eax
leal -0x4(%rax), %ecx
movq 0x6c8(%rbx), %rdi
cmpl %ecx, %ebp
movq %r12, 0x50(%rsp)
jle 0x7f1bf
movabsq $0x1200000001, %rcx     # imm = 0x1200000001
leaq 0x28(%rsp), %rsi
movq %rcx, (%rsi)
addl $-0x2, %eax
movl 0xb4(%rdi), %ecx
leaq 0x20(%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 0x56840
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)
movl 0x6d0(%rbx), %ebp
jmp 0x7f1d6
movq (%rdi), %rax
callq *0x60(%rax)
andl $0x0, 0x6d0(%rbx)
xorl %ebp, %ebp
movl $0x0, 0xc(%rsp)
negl %ebp
movl $0x0, 0x8(%rsp)
movl %ebp, %r13d
xorl %r14d, %r14d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
cmpl %eax, %r14d
jge 0x7f2b5
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 %ebp, %ecx
js 0x7f2a8
movl 0xb0(%rbx), %edx
addl $-0x4, %edx
cmpl %edx, %r13d
jg 0x7f2a8
leal 0x2(%r13), %ecx
movl %ecx, 0x28(%rsp)
movl $0x2, 0x2c(%rsp)
movl 0xb4(%rbx), %ecx
subl 0xc(%rsp), %ecx
addl $-0x4, %ecx
movl %eax, 0x20(%rsp)
movl %ecx, 0x24(%rsp)
movq (%r15), %rax
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq *0x150(%rax)
movb $0x1, 0xcb(%r15)
movl 0x8(%r15), %r12d
leaq 0x38(%rsp), %rdi
movl 0x8(%rsp), %esi
callq 0x59cc0
movq %rax, %rcx
incl 0x8(%rsp)
movl %r12d, %eax
cltd
movl $0x7fff, %esi           # imm = 0x7FFF
idivl %esi
incl %edx
movl %edx, (%rcx)
movl 0xb0(%r15), %eax
addl %eax, %ebp
movl %ebp, %ecx
addl %eax, %r13d
incl %r14d
movl %ecx, %ebp
jmp 0x7f1e6
leaq 0x6d8(%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0x56630
movq 0x50(%rsp), %r15
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x98(%rax)
testb %al, %al
je 0x7f322
movq 0x10(%rsp), %rax
movl 0x18(%rsp), %ecx
movl 0x1c(%rsp), %edx
subl 0xc(%rsp), %edx
shlq $0x20, %rdx
orq %rcx, %rdx
leaq 0x28(%rsp), %rsi
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
movq 0xe2ca2(%rip), %rax     # 0x161fa8
movl (%rax), %ecx
leaq 0x20(%rsp), %r8
andq $0x0, (%r8)
movq 0xe2358(%rip), %rdx     # 0x161670
movq %r15, %rdi
callq 0x58b80
jmp 0x7f367
movq 0x10(%rsp), %rax
movl 0x18(%rsp), %ecx
movl 0x1c(%rsp), %edx
subl 0xc(%rsp), %edx
shlq $0x20, %rdx
orq %rcx, %rdx
leaq 0x28(%rsp), %rsi
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
movq 0xe2c5b(%rip), %rax     # 0x161fa8
movl (%rax), %ecx
leaq 0x20(%rsp), %r8
andq $0x0, (%r8)
movq 0xe2171(%rip), %rdx     # 0x1614d0
movq %r15, %rdi
callq 0x58b80
leaq 0x10(%rsp), %rsi
pushq $0x1
popq %rdx
movq %r15, %rdi
callq 0x58ad0
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x57910
movq %r15, %rdi
callq 0x59a80
jmp 0x7f46b
movl 0xb0(%rbx), %eax
movq 0x6c8(%rbx), %rdi
subl %eax, %r14d
addl $0x4, %r14d
movl $0x0, 0x8(%rsp)
xorl %esi, %esi
movl %r14d, %edx
callq 0x56840
xorl %r14d, %r14d
subl 0x6d0(%rbx), %r14d
movl %r14d, %ebp
xorl %r15d, %r15d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
cmpl %eax, %r15d
jge 0x7f445
movq (%rbx), %rax
movq %rbx, %rdi
movl %r15d, %esi
callq *0x180(%rax)
movq %rax, %r12
movl 0xb0(%rax), %eax
movl %eax, %ecx
addl %r14d, %ecx
js 0x7f43b
movl 0xb0(%rbx), %edx
addl $-0x4, %edx
cmpl %edx, %ebp
jg 0x7f43b
movl 0x8(%r12), %r13d
leaq 0x38(%rsp), %rdi
movl 0x8(%rsp), %esi
callq 0x59cc0
movq %rax, %rcx
incl 0x8(%rsp)
movl %r13d, %eax
cltd
movl $0x7fff, %esi           # imm = 0x7FFF
idivl %esi
incl %edx
movl %edx, (%rcx)
movl 0xb0(%r12), %eax
addl %eax, %r14d
movl %r14d, %ecx
addl %eax, %ebp
incl %r15d
movl %ecx, %r14d
jmp 0x7f3c7
leaq 0x6d8(%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0x58150
xorl %r14d, %r14d
testb %al, %al
je 0x7f46b
movq (%rbx), %rax
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
leaq 0x38(%rsp), %rdi
callq 0x5a588
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7f497
jmp 0x7f497
jmp 0x7f497
jmp 0x7f497
jmp 0x7f497
jmp 0x7f497
jmp 0x7f497
jmp 0x7f497
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x5a588
movq %rbx, %rdi
callq 0x58260