// File: /workspace/github_c_makefile_star2_O2/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 0x899fc
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
callq 0x582b0
subq 0x5f0(%rbx), %rax
cmpq $0x64, %rax
jb 0x899ee
movq 0x190(%rbx), %rdi
callq 0x56a50
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
movq %r14, 0x10(%rsp)
testq %r14, %r14
je 0x899ee
movq %rax, %r12
movq 0x608(%rbx), %rdi
testq %rdi, %rdi
je 0x897ef
callq 0x5a010
andq $0x0, 0x608(%rbx)
movq 0x5f8(%rbx), %rdi
movq (%rdi), %rax
callq *0x70(%rax)
callq 0x59120
movq %rax, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movq %r12, %rdi
callq 0x59c60
cwtl
cvtsi2sd %eax, %xmm0
divsd 0x59cf0(%rip), %xmm0    # 0xe3510
movsd %xmm0, 0x8(%rsp)
movq 0x5b8(%rbx), %rdi
callq 0x5a250
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
movq %rax, %rbp
movq %rax, %r14
shrq $0x20, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x50(%rax)
movsd 0x5d222(%rip), %xmm0    # 0xe6a78
mulsd 0x8(%rsp), %xmm0
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
ucomisd %xmm0, %xmm1
movq %rax, %r12
seta %cl
leaq 0x59f3d(%rip), %rax     # 0xe37b0
addsd (%rax,%rcx,8), %xmm0
cvttsd2si %xmm0, %r15
movq %rbp, %r13
addq %r12, %r13
movq %r14, 0x30(%rsp)
addq %r14, %r15
movq %r15, %rax
shlq $0x20, %rax
movl %r13d, %ecx
orq %rax, %rcx
movq %rcx, (%rsp)
movq 0x5b8(%rbx), %rax
movl 0xb0(%rax), %r14d
movl 0xb4(%rax), %eax
movl %eax, 0x1c(%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x160(%rax)
testb %al, %al
je 0x899fd
movq 0x10(%rsp), %rax
movl 0xb0(%rax), %ecx
addl 0xa8(%rax), %ecx
subl %r13d, %ecx
cvtsi2sd %r14d, %xmm0
movsd 0x8(%rsp), %xmm2
mulsd %xmm2, %xmm0
xorl %eax, %eax
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
seta %al
leaq 0x59eb1(%rip), %rdi     # 0xe37b0
addsd (%rdi,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
movslq %ecx, %rcx
subq %rax, %rcx
movslq 0x28(%rsp), %rdx
cmpq %rdx, %rcx
movq 0x20(%rsp), %rsi
jge 0x89923
subl %eax, %ebp
movl %ebp, (%rsp)
movq 0x10(%rsp), %rax
movslq 0xac(%rax), %rcx
cvtsi2sdl 0x1c(%rsp), %xmm1
movslq %r15d, %rdx
mulsd %xmm2, %xmm1
xorpd %xmm0, %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
addsd (%rdi,%rax,8), %xmm1
cvttsd2si %xmm1, %rax
addq %rax, %rcx
addq %rdx, %rcx
sarq $0x20, %rsi
cmpq %rsi, %rcx
jl 0x89991
shrq $0x20, %r12
mulsd 0x59c12(%rip), %xmm2    # 0xe3580
xorl %ecx, %ecx
ucomisd %xmm2, %xmm0
seta %cl
addsd (%rdi,%rcx,8), %xmm2
cvttsd2si %xmm2, %rcx
addl 0x30(%rsp), %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 0xd809a(%rip), %rsi     # 0x161a58
xorl %edx, %edx
movq %rbx, %rcx
callq 0x8a80e
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 $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rax
movslq 0xa8(%rax), %rax
movslq %r13d, %rcx
addq %rax, %rcx
cvtsi2sd %r14d, %xmm0
movsd 0x8(%rsp), %xmm2
mulsd %xmm2, %xmm0
xorl %eax, %eax
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
seta %al
leaq 0x59d7e(%rip), %rdi     # 0xe37b0
addsd (%rdi,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
addq %rax, %rcx
movq 0x20(%rsp), %rsi
movslq %esi, %rdx
cmpq %rdx, %rcx
jge 0x8991e
jmp 0x89923
nop