// File: /workspace/github_c_makefile_star2_O3/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 0x81397
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x90(%rax)
xorl %r14d, %r14d
testb %al, %al
je 0x81397
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 0x58e20
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testl %ebp, %ebp
je 0x80fec
cmpl $0x1, %ebp
jne 0x8138d
movq %rbx, %rdi
callq 0x56c70
movl %eax, %r14d
movl 0xb0(%rbx), %eax
leal -0x4(%rax), %ecx
cmpl %ecx, %r14d
jle 0x80fb8
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
je 0x80fd9
movl 0xb0(%rbx), %eax
leal -0x4(%rax), %ecx
cmpl %ecx, %r14d
jg 0x8129b
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
je 0x81295
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
movl %eax, %r14d
jmp 0x8138d
leaq 0x10(%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 0x81099
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 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)
movl 0x6d0(%rbx), %r12d
jmp 0x810b4
movq (%rdi), %rax
callq *0x60(%rax)
movl $0x0, 0x6d0(%rbx)
xorl %r12d, %r12d
movl $0x0, 0xc(%rsp)
negl %r12d
movl $0x0, 0x8(%rsp)
movl %r12d, %r13d
xorl %r14d, %r14d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
cmpl %eax, %r14d
jge 0x811b1
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 %r12d, %ecx
js 0x811a3
movl 0xb0(%rbx), %edx
addl $-0x4, %edx
cmpl %edx, %r13d
jg 0x811a3
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), %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
movl %r12d, %ecx
addl %eax, %r13d
incl %r14d
movl %ecx, %r12d
jmp 0x810c5
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 0x81221
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 0xeada6(%rip), %rax     # 0x16bfa8
movl (%rax), %ecx
leaq 0x20(%rsp), %r8
movq $0x0, (%r8)
movq 0xea459(%rip), %rdx     # 0x16b670
movq %r15, %rdi
callq 0x57930
jmp 0x81269
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 0xead5c(%rip), %rax     # 0x16bfa8
movl (%rax), %ecx
leaq 0x20(%rsp), %r8
movq $0x0, (%r8)
movq 0xea26f(%rip), %rdx     # 0x16b4d0
movq %r15, %rdi
callq 0x57930
leaq 0x10(%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
jmp 0x8138d
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 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 0x81367
movq (%rbx), %rax
movq %rbx, %rdi
movl %r15d, %esi
callq *0x180(%rax)
movq %rax, %r12
movl 0xb0(%rax), %eax
movl %eax, %ecx
addl %r13d, %ecx
js 0x81359
movl 0xb0(%rbx), %edx
addl $-0x4, %edx
cmpl %edx, %r14d
jg 0x81359
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, %r13d
movl %r13d, %ecx
addl %eax, %r14d
incl %r15d
movl %ecx, %r13d
jmp 0x812cb
leaq 0x6d8(%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0x56fa0
xorl %r14d, %r14d
testb %al, %al
je 0x8138d
movq (%rbx), %rax
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
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 0x813b9
jmp 0x813b9
jmp 0x813b9
jmp 0x813b9
jmp 0x813b9
jmp 0x813b9
jmp 0x813b9
jmp 0x813b9
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x59200
movq %rbx, %rdi
callq 0x57090