// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/classes/gui/widgets/multi/menu/menubarentry.cpp
// Function: smooth::GUI::MenubarEntry::OpenPopupMenu()
S::Void S::GUI::MenubarEntry::OpenPopupMenu()
{
	if (popup == NIL) return;

	if (S::System::System::Clock() - popupMenuClosed < 100)
	{
		hotspot->Paint(SP_MOUSEUP);

		return;
	}

	Window	*window	     = container->GetContainerWindow();
	Surface	*surface     = GetDrawSurface();
	Float	 scaleFactor = surface->GetSurfaceDPI() / 96.0;

	Point	 realPos     = GetRealPosition();
	Size	 realSize    = GetRealSize();

	Rect	 popupFrame  = Rect(realPos + Point(realSize.cx - 11 * scaleFactor, 0), Size(11 * scaleFactor, realSize.cy));

	if (onAction.GetNOfConnectedSlots() == 0 || window->IsMouseOn(popupFrame))
	{
		hotspot->Deactivate();

		Rect	 monitor   = System::Screen::GetActiveScreenWorkArea();

		popup->CalculateSize();

		Point	 popupPos  = realPos + Point(orientation == OR_LEFT ? -1 : realSize.cx + 1 - popup->GetWidth() * scaleFactor, realSize.cy + 1);
		Size	 popupSize = popup->GetSize();

		if (orientation == OR_LEFT)
		{
			if (!IsRightToLeft()) { if (window->GetX() + popupPos.x			       + Math::Round(popupSize.cx * scaleFactor) >= monitor.right) popupPos.x = realPos.x + realSize.cx + 1 - Math::Round(popupSize.cx * scaleFactor); }
			else		      { if (window->GetX() + (window->GetWidth() - popupPos.x) - Math::Round(popupSize.cx * scaleFactor) <  monitor.left)  popupPos.x = realPos.x + realSize.cx + 1 - Math::Round(popupSize.cx * scaleFactor); }
		}
		else
		{
			if (!IsRightToLeft()) { if (window->GetX() + popupPos.x			       <  monitor.left)  popupPos.x = realPos.x - 1; }
			else		      { if (window->GetX() + (window->GetWidth() - popupPos.x) >= monitor.right) popupPos.x = realPos.x - 1; }
		}

		if (window->GetY() + popupPos.y + Math::Round(popupSize.cy * scaleFactor) >= monitor.bottom) popupPos.y = realPos.y - Math::Round(popupSize.cy * scaleFactor) - 1;

		popup->SetPosition(popupPos);
		popup->internalRequestClose.Connect(&MenubarEntry::ClosePopupMenu, this);

		Add(popup);

		container->SetFlags(container->GetFlags() | MB_POPUPOPEN);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
cmpq $0x0, 0x5b8(%rdi)
je 0x898ed
movq %rdi, %rbx
callq 0x570e0
subq 0x5f0(%rbx), %rax
cmpq $0x63, %rax
ja 0x895d6
movq 0x5f8(%rbx), %rdi
movq (%rdi), %rax
movq 0x78(%rax), %rax
movl $0x5, %esi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax
movq 0x190(%rbx), %rdi
callq 0x559e0
movq %rax, %r13
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
movq %rax, %rdi
callq 0x58930
cwtl
cvtsi2sd %eax, %xmm0
divsd 0x6aeed(%rip), %xmm0    # 0xf44f0
movsd %xmm0, 0x18(%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
movq %rax, %rbp
movq %rax, %r15
shrq $0x20, %r15
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x50(%rax)
movq %rax, %r12
shrq $0x20, %r12
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x6e208(%rip), %xmm1    # 0xf7848
movsd 0x18(%rsp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movsd 0x6d916(%rip), %xmm0    # 0xf6f70
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %ecx
movq %rbp, 0x10(%rsp)
addl %ebp, %eax
movl %eax, 0x38(%rsp)
movl %r15d, 0x3c(%rsp)
addl %eax, %ecx
movl %ecx, 0x40(%rsp)
leal (%r12,%r15), %eax
movl %eax, 0x44(%rsp)
movq 0x488(%rbx), %rdx
movq 0x490(%rbx), %rcx
xorl %eax, %eax
movq %rdx, %rsi
orq %rcx, %rsi
je 0x896ad
testq %rdx, %rdx
je 0x896aa
movl 0x8(%rdx), %eax
testq %rcx, %rcx
je 0x896ad
addl 0x8(%rcx), %eax
jmp 0x896ad
movl 0x8(%rcx), %eax
testl %eax, %eax
je 0x896c6
leaq 0x38(%rsp), %rsi
movq %r13, %rdi
callq 0x578a0
testb %al, %al
je 0x898ed
movq %r13, %rbp
movq 0x5f8(%rbx), %rdi
movq (%rdi), %rax
callq *0x70(%rax)
callq 0x57e90
movq %rax, 0x30(%rsp)
movq %rdx, %r14
movq 0x5b8(%rbx), %rdi
callq 0x58ee0
movzwl 0xd0(%rbx), %r13d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpw $0x10, %r13w
je 0x89731
movq 0x20(%rsp), %rax
incl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq 0x5b8(%rbx), %rax
xorps %xmm1, %xmm1
cvtsi2sdl 0xb0(%rax), %xmm1
mulsd 0x18(%rsp), %xmm1
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
addl 0x10(%rsp), %eax
leal (%r15,%r12), %ecx
incl %ecx
shlq $0x20, %rcx
orq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x5b8(%rbx), %rax
movl 0xb0(%rax), %r12d
movl 0xb4(%rax), %eax
movl %eax, 0x2c(%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x160(%rax)
movslq 0xa8(%rbp), %rcx
cmpw $0x10, %r13w
jne 0x897c5
testb %al, %al
je 0x897da
addl 0xb0(%rbp), %ecx
subl 0x8(%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
mulsd 0x18(%rsp), %xmm0
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x6b117(%rip), %rdx     # 0xf48c0
addsd (%rdx,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
movslq %ecx, %rcx
subq %rax, %rcx
movslq 0x30(%rsp), %rdx
cmpq %rdx, %rcx
jl 0x89819
jmp 0x89844
testb %al, %al
je 0x8982f
addl 0xb0(%rbp), %ecx
subl 0x8(%rsp), %ecx
cmpl %r14d, %ecx
jge 0x89839
jmp 0x89844
movslq 0x8(%rsp), %rdx
addq %rcx, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
mulsd 0x18(%rsp), %xmm0
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x6b0bc(%rip), %rcx     # 0xf48c0
addsd (%rcx,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
addq %rax, %rdx
movslq %r14d, %rcx
cmpq %rcx, %rdx
jl 0x89844
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rdx
addl %edx, %ecx
subl %eax, %ecx
incl %ecx
movl %ecx, 0x8(%rsp)
jmp 0x89844
addl 0x8(%rsp), %ecx
cmpl 0x30(%rsp), %ecx
jge 0x89844
movq 0x10(%rsp), %rax
decl %eax
movl %eax, 0x8(%rsp)
movslq 0xac(%rbp), %rax
movslq 0xc(%rsp), %rcx
addq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2sdl 0x2c(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
leaq 0x6b046(%rip), %rdx     # 0xf48c0
addsd (%rdx,%rax,8), %xmm1
cvttsd2si %xmm1, %rax
addq %rax, %rcx
sarq $0x20, %r14
cmpq %r14, %rcx
jl 0x89899
notl %eax
addl %r15d, %eax
movl %eax, 0xc(%rsp)
movq 0x5b8(%rbx), %rdi
leaq 0xb0(%rdi), %rdx
movq (%rdi), %rax
leaq 0x8(%rsp), %rsi
callq *0x150(%rax)
movl $0x698, %edi            # imm = 0x698
addq 0x5b8(%rbx), %rdi
movq 0xe35b8(%rip), %rsi     # 0x16ce80
xorl %edx, %edx
movq %rbx, %rcx
callq 0x8a890
movq 0x5b8(%rbx), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x30(%rax)
movq 0x190(%rbx), %rax
orl $0x2, 0x30(%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq