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

	if (S::System::System::Clock() - popupMenuClosed < 100) return;

	Widget	*window	     = container->GetContainerWindow();
	Surface	*surface     = GetDrawSurface();

	if (window == NIL) return;

	if (timer != NIL)
	{
		DeleteObject(timer);

		timer = NIL;
	}

	hotspot->Deactivate();

	Rect	 monitor     = System::Screen::GetActiveScreenWorkArea();
	Float	 scaleFactor = surface->GetSurfaceDPI() / 96.0;

	popup->CalculateSize();

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

	Point	 popupPos    = realPos + Point(realSize.cx, Math::Round(-3 * scaleFactor));
	Size	 popupSize   = popup->GetSize();

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

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

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

	owner->SetFlags(owner->GetFlags() | MB_POPUPOPEN);

	Add(popup);

	/* Set the MB_POPUPOPEN flag again as it may have been unset by a
	 * closing sibling popup during PopupMenu::Show in the above Add call.
	 */
	owner->SetFlags(owner->GetFlags() | MB_POPUPOPEN);
}

// Assembly:
cmpq $0x0, 0x5b8(%rdi)
je 0x8ce7c
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
callq 0x570e0
subq 0x5f0(%rbx), %rax
cmpq $0x64, %rax
jb 0x8ce6e
movq 0x190(%rbx), %rdi
callq 0x559e0
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
testq %r14, %r14
je 0x8ce6e
movq %rax, %r12
movq 0x608(%rbx), %rdi
testq %rdi, %rdi
je 0x8cc7d
callq 0x58cc0
movq $0x0, 0x608(%rbx)
movq 0x5f8(%rbx), %rdi
movq (%rdi), %rax
callq *0x70(%rax)
callq 0x57e90
movq %rax, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %r12, %rdi
callq 0x58930
cwtl
cvtsi2sd %eax, %xmm0
divsd 0x67842(%rip), %xmm0    # 0xf44f0
movsd %xmm0, 0x8(%rsp)
movq 0x5b8(%rbx), %rdi
callq 0x58ee0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
movq %rax, %r13
movq %rax, %rbp
shrq $0x20, %rbp
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x50(%rax)
movsd 0x6ad04(%rip), %xmm0    # 0xf79e8
mulsd 0x8(%rsp), %xmm0
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
ucomisd %xmm0, %xmm1
seta %cl
leaq 0x67a92(%rip), %rdx     # 0xf4790
addsd (%rdx,%rcx,8), %xmm0
movq %rax, %r12
cvttsd2si %xmm0, %rax
leal (%r12,%r13), %ecx
addl %ebp, %eax
shlq $0x20, %rax
orq %rax, %rcx
movq %rcx, (%rsp)
movq 0x5b8(%rbx), %rax
movl 0xb0(%rax), %r15d
movl 0xb4(%rax), %eax
movl %eax, 0x14(%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x160(%rax)
testb %al, %al
je 0x8ce7d
movl 0xb0(%r14), %ecx
addl 0xa8(%r14), %ecx
subl (%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd 0x8(%rsp), %xmm2
mulsd %xmm2, %xmm0
xorl %eax, %eax
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
seta %al
leaq 0x67a11(%rip), %rsi     # 0xf4790
addsd (%rsi,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
movslq %ecx, %rcx
subq %rax, %rcx
movslq 0x20(%rsp), %rdx
cmpq %rdx, %rcx
movq 0x18(%rsp), %rdx
jge 0x8cda5
subl %eax, %r13d
movl %r13d, (%rsp)
movslq 0xac(%r14), %rax
movslq 0x4(%rsp), %rcx
xorps %xmm1, %xmm1
cvtsi2sdl 0x14(%rsp), %xmm1
addq %rax, %rcx
mulsd %xmm2, %xmm1
xorpd %xmm0, %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
addsd (%rsi,%rax,8), %xmm1
cvttsd2si %xmm1, %rax
addq %rax, %rcx
sarq $0x20, %rdx
cmpq %rdx, %rcx
jl 0x8ce11
shrq $0x20, %r12
mulsd 0x67770(%rip), %xmm2    # 0xf4560
xorl %ecx, %ecx
ucomisd %xmm2, %xmm0
seta %cl
addsd (%rsi,%rcx,8), %xmm2
cvttsd2si %xmm2, %rcx
addl %ebp, %r12d
addl %ecx, %r12d
subl %eax, %r12d
movl %r12d, 0x4(%rsp)
movq 0x5b8(%rbx), %rdi
leaq 0xb0(%rdi), %rdx
movq (%rdi), %rax
movq %rsp, %rsi
callq *0x150(%rax)
movl $0x698, %edi            # imm = 0x698
addq 0x5b8(%rbx), %rdi
movq 0xdfc1a(%rip), %rsi     # 0x16ca58
xorl %edx, %edx
movq %rbx, %rcx
callq 0x8dd40
movq 0x600(%rbx), %rax
orl $0x2, 0x30(%rax)
movq 0x5b8(%rbx), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x30(%rax)
movq 0x600(%rbx), %rax
orl $0x2, 0x30(%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq 0xa8(%r14), %rax
movslq (%rsp), %rcx
addq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd 0x8(%rsp), %xmm2
mulsd %xmm2, %xmm0
xorl %eax, %eax
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
seta %al
leaq 0x678df(%rip), %rdi     # 0xf4790
addsd (%rdi,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
addq %rax, %rcx
movq 0x18(%rsp), %rsi
movslq %esi, %rdx
cmpq %rdx, %rcx
movq %rsi, %rdx
movq %rdi, %rsi
jge 0x8cd9e
jmp 0x8cda5