// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/classes/gui/window/window.cpp
// Function: smooth::GUI::Window::CalculateOffsets()
S::Void S::GUI::Window::CalculateOffsets()
{
	Widget	*lastTopWidget	= NIL;
	Int	 positions	= 0;

	innerOffset = Rect(Point(frameWidth, frameWidth), Size(0, 0));

	for (Int i = 0; i < GetNOfObjects(); i++)
	{
		Widget	*widget = GetNthObject(i);

		positions |= widget->GetOrientation();

		if (widget->GetOrientation() == OR_TOP)
		{
			lastTopWidget = widget;

			widget->SetMetrics(Point(innerOffset.left, innerOffset.top), Size(GetWidth() - innerOffset.left - innerOffset.right, widget->GetHeight()));

			innerOffset.top += widget->GetHeight();

			if (widget->subtype == WO_SEPARATOR) innerOffset.top += 3;
		}
		else if (widget->GetOrientation() == OR_BOTTOM)
		{
			widget->SetMetrics(Point(innerOffset.left, GetHeight() - innerOffset.bottom - widget->GetHeight()), Size(GetWidth() - innerOffset.left - innerOffset.right, widget->GetHeight()));

			innerOffset.bottom += widget->GetHeight();
		}
	}

	if (positions & OR_TOP)	   innerOffset.top    += 3;
	if (positions & OR_BOTTOM) innerOffset.bottom += 5;

	if (lastTopWidget != NIL)  innerOffset.top    += (lastTopWidget->subtype == WO_NOSEPARATOR ? 3 : 0);

	for (Int i = 0; i < GetNOfObjects(); i++)
	{
		Widget	*widget = GetNthObject(i);

		if (widget->GetOrientation() == OR_LEFT)
		{
			widget->SetMetrics(Point(innerOffset.left, innerOffset.top), Size(widget->GetWidth(), GetHeight() - innerOffset.top - innerOffset.bottom));

			innerOffset.left += widget->GetWidth();
		}
		else if (widget->GetOrientation() == OR_RIGHT)
		{
			widget->SetMetrics(Point(GetWidth() - innerOffset.right - widget->GetWidth(), innerOffset.top), Size(widget->GetWidth(), GetHeight() - innerOffset.top - innerOffset.bottom));

			innerOffset.right += widget->GetWidth();
		}
	}

	if (positions & OR_LEFT)  innerOffset.left  += 3;
	if (positions & OR_RIGHT) innerOffset.right += 3;

	for (Int i = 0; i < GetNOfObjects(); i++)
	{
		Widget	*widget = GetNthObject(i);

		if (widget->GetOrientation() == OR_CENTER)
		{
			widget->SetMetrics(Point(innerOffset.left, innerOffset.top), Size(GetWidth() - innerOffset.left - innerOffset.right, GetHeight() - innerOffset.top - innerOffset.bottom));
			widget->SetOrientation(OR_CENTER);
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movdqu 0x5e8(%rdi), %xmm0
leaq 0x5d8(%rdi), %rax
movq %rax, 0x20(%rsp)
leaq 0x5e0(%rdi), %rax
movq %rax, 0x18(%rsp)
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movdqu %xmm0, 0x5d8(%rdi)
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %r12d, %r12d
movl 0x40(%rbx), %eax
cmpl %eax, %r14d
jge 0x940ee
movq %rbx, %rdi
movl %r14d, %esi
callq 0x58c90
movq %rax, %r13
movq (%rax), %rax
movq %r13, %rdi
callq *0x128(%rax)
movl %eax, %ebp
movq (%r13), %rax
movq %r13, %rdi
callq *0x128(%rax)
cmpl $0x4, %eax
jne 0x9406c
movq 0x5d8(%rbx), %rax
movq %rax, 0x8(%rsp)
movl 0xb0(%rbx), %ecx
addl 0x5e0(%rbx), %eax
subl %eax, %ecx
movl 0xb4(%r13), %eax
movl %ecx, 0x10(%rsp)
movl %eax, 0x14(%rsp)
movq (%r13), %rax
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq *0x150(%rax)
movl 0x5dc(%rbx), %eax
addl 0xb4(%r13), %eax
movl %eax, 0x5dc(%rbx)
cmpw $0x1, 0x1a0(%r13)
jne 0x940e0
addl $0x3, %eax
movl %eax, 0x5dc(%rbx)
jmp 0x940e0
movq (%r13), %rax
movq %r13, %rdi
callq *0x128(%rax)
cmpl $0x8, %eax
jne 0x940dd
movl 0x5d8(%rbx), %eax
movl 0xb4(%rbx), %ecx
movl 0xb4(%r13), %edx
movl 0x5e4(%rbx), %esi
addl %edx, %esi
subl %esi, %ecx
movl %eax, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
movl 0xb0(%rbx), %ecx
addl 0x5e0(%rbx), %eax
subl %eax, %ecx
movl %ecx, 0x10(%rsp)
movl %edx, 0x14(%rsp)
movq (%r13), %rax
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq *0x150(%rax)
movl 0xb4(%r13), %eax
addl %eax, 0x5e4(%rbx)
movq %r12, %r13
orl %ebp, %r15d
incl %r14d
movq %r13, %r12
jmp 0x93fc9
testb $0x4, %r15b
je 0x940fb
addl $0x3, 0x5dc(%rbx)
testb $0x8, %r15b
je 0x94108
addl $0x5, 0x5e4(%rbx)
testq %r12, %r12
je 0x94125
xorl %ecx, %ecx
cmpw $0x2, 0x1a0(%r12)
sete %cl
leal (%rcx,%rcx,2), %ecx
addl %ecx, 0x5dc(%rbx)
xorl %ebp, %ebp
leaq 0x10(%rsp), %r13
cmpl %eax, %ebp
jge 0x9422b
movq %rbx, %rdi
movl %ebp, %esi
callq 0x58c90
movq %rax, %r12
movq (%rax), %rax
movq %r12, %rdi
callq *0x128(%rax)
cmpl $0x10, %eax
jne 0x941aa
movl 0x5d8(%rbx), %eax
movl 0x5dc(%rbx), %ecx
movl %eax, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
movq %r12, %r14
addq $0xb0, %r14
movl 0xb0(%r12), %eax
movl 0xb4(%rbx), %edx
addl 0x5e4(%rbx), %ecx
subl %ecx, %edx
movl %eax, 0x10(%rsp)
movl %edx, 0x14(%rsp)
movq (%r12), %rax
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
movq %r13, %rdx
callq *0x150(%rax)
movq 0x20(%rsp), %rax
jmp 0x9421c
movq (%r12), %rax
movq %r12, %rdi
callq *0x128(%rax)
cmpl $0x20, %eax
jne 0x94221
movl 0xb0(%rbx), %eax
movq %r12, %r14
addq $0xb0, %r14
movl 0xb0(%r12), %ecx
movl 0x5e0(%rbx), %edx
addl %ecx, %edx
subl %edx, %eax
movl 0x5dc(%rbx), %edx
movl %eax, 0x8(%rsp)
movl %edx, 0xc(%rsp)
movl 0xb4(%rbx), %eax
addl 0x5e4(%rbx), %edx
subl %edx, %eax
movl %ecx, 0x10(%rsp)
movl %eax, 0x14(%rsp)
movq (%r12), %rax
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
movq %r13, %rdx
callq *0x150(%rax)
movq 0x18(%rsp), %rax
movl (%r14), %ecx
addl %ecx, (%rax)
incl %ebp
movl 0x40(%rbx), %eax
jmp 0x9412c
testb $0x10, %r15b
je 0x94239
movq 0x20(%rsp), %rcx
addl $0x3, (%rcx)
testb $0x20, %r15b
je 0x94247
movq 0x18(%rsp), %rcx
addl $0x3, (%rcx)
xorl %ebp, %ebp
leaq 0x8(%rsp), %r14
leaq 0x10(%rsp), %r15
pushq $0x40
popq %r12
cmpl %eax, %ebp
jge 0x942e3
movq %rbx, %rdi
movl %ebp, %esi
callq 0x58c90
movq %rax, %r13
movq (%rax), %rax
movq %r13, %rdi
callq *0x128(%rax)
cmpl $0x40, %eax
jne 0x942d9
movq 0x5d8(%rbx), %rax
movq %rax, %xmm0
movl %eax, 0x8(%rsp)
pshufd $0x55, %xmm0, %xmm1     # xmm1 = xmm0[1,1,1,1]
movd %xmm1, 0xc(%rsp)
movq 0xb0(%rbx), %xmm1
movq 0x5e0(%rbx), %xmm2
paddd %xmm0, %xmm2
psubd %xmm2, %xmm1
movq %xmm1, 0x10(%rsp)
movq (%r13), %rax
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq *0x150(%rax)
movq (%r13), %rax
movq %r13, %rdi
movl %r12d, %esi
callq *0x120(%rax)
incl %ebp
movl 0x40(%rbx), %eax
jmp 0x94257
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq