// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
cmpq $0x0, 0x5b8(%rdi)
je 0x893d5
movq %rdi, %rbx
callq 0x570e0
subq 0x5f0(%rbx), %rax
cmpq $0x63, %rax
ja 0x890b6
movq 0x5f8(%rbx), %rdi
movq (%rdi), %rax
movq 0x78(%rax), %rax
movl $0x5, %esi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax
movq 0x190(%rbx), %rdi
callq 0x559e0
movq %rax, 0x40(%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
movq %rax, %rdi
callq 0x58930
cwtl
cvtsi2sd %eax, %xmm0
divsd 0x6a5d3(%rip), %xmm0    # 0xf36b8
movsd %xmm0, 0x18(%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
movq %rax, %r12
movq %rax, %r15
shrq $0x20, %r15
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x50(%rax)
movq %rax, %rbp
movq %rax, %r14
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd 0x6d894(%rip), %xmm1    # 0xf69b0
movsd 0x18(%rsp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
shrq $0x20, %r14
movq %r12, 0x10(%rsp)
addl %r12d, %eax
movsd 0x6cece(%rip), %xmm0    # 0xf6010
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %ecx
movl %eax, 0x48(%rsp)
movl %r15d, 0x4c(%rsp)
addl %eax, %ecx
movl %ecx, 0x50(%rsp)
leal (%r14,%r15), %eax
movl %eax, 0x54(%rsp)
movq 0x488(%rbx), %rcx
movq 0x490(%rbx), %rax
movq %rcx, %rdx
orq %rax, %rdx
je 0x891a7
testq %rcx, %rcx
je 0x89189
movl 0x8(%rcx), %ecx
testq %rax, %rax
je 0x8918c
addl 0x8(%rax), %ecx
jmp 0x8918c
movl 0x8(%rax), %ecx
testl %ecx, %ecx
je 0x891a7
leaq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdi
callq 0x578a0
testb %al, %al
je 0x893d5
movq 0x5f8(%rbx), %rdi
movq (%rdi), %rax
callq *0x70(%rax)
callq 0x57e90
movq %rax, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
movq 0x5b8(%rbx), %rdi
callq 0x58ee0
movzwl 0xd0(%rbx), %r13d
movq 0x5b8(%rbx), %rax
cmpw $0x10, %r13w
movq %rbp, 0x28(%rsp)
jne 0x891f8
movl 0xb0(%rax), %ebp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x8921e
leal 0x1(%rbp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movl 0xb0(%rax), %ebp
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
mulsd 0x18(%rsp), %xmm1
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %r12d
addl 0x10(%rsp), %r12d
addq %r15, %r14
incq %r14
movq %r14, %rcx
shlq $0x20, %rcx
addq %r12, %rcx
movq %rcx, 0x8(%rsp)
movl 0xb4(%rax), %eax
movl %eax, 0x24(%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x160(%rax)
movq 0x40(%rsp), %rsi
movl 0xa8(%rsi), %ecx
cmpw $0x10, %r13w
jne 0x892af
testb %al, %al
movq 0x38(%rsp), %rdi
je 0x892c7
addl 0xb0(%rsi), %ecx
subl %r12d, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd 0x18(%rsp), %xmm0
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x6a55d(%rip), %rdx     # 0xf37f0
addsd (%rdx,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
movslq %ecx, %rcx
subq %rax, %rcx
movslq 0x30(%rsp), %rdx
cmpq %rdx, %rcx
jl 0x89303
jmp 0x8932e
testb %al, %al
movq 0x38(%rsp), %rdi
je 0x89319
addl 0xb0(%rsi), %ecx
subl %r12d, %ecx
cmpl %edi, %ecx
jge 0x89323
jmp 0x8932e
addl %ecx, %r12d
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd 0x18(%rsp), %xmm0
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x6a505(%rip), %rcx     # 0xf37f0
addsd (%rcx,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
movslq %r12d, %rcx
addq %rax, %rcx
movslq %edi, %rdx
cmpq %rdx, %rcx
jl 0x8932e
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %rdx
addl %edx, %ecx
subl %eax, %ecx
incl %ecx
movl %ecx, 0x8(%rsp)
jmp 0x8932e
addl %ecx, %r12d
cmpl 0x30(%rsp), %r12d
jge 0x8932e
movq 0x10(%rsp), %rax
decl %eax
movl %eax, 0x8(%rsp)
movslq 0xac(%rsi), %rax
movslq %r14d, %rcx
addq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2sdl 0x24(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
leaq 0x6a48e(%rip), %rdx     # 0xf37f0
addsd (%rdx,%rax,8), %xmm1
cvttsd2si %xmm1, %rax
addq %rax, %rcx
sarq $0x20, %rdi
cmpq %rdi, %rcx
jl 0x89381
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 0xe2ad0(%rip), %rsi     # 0x16be80
xorl %edx, %edx
movq %rbx, %rcx
callq 0x8a30a
movq 0x5b8(%rbx), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x30(%rax)
movq 0x190(%rbx), %rax
orl $0x2, 0x30(%rax)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq