// File: /workspace/github_c_makefile_star2_O2/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 0x86a32
movq %rdi, %rbx
callq 0x582b0
subq 0x5f0(%rbx), %rax
cmpq $0x63, %rax
ja 0x8672e
movq 0x5f8(%rbx), %rdi
movq (%rdi), %rax
movq 0x78(%rax), %rax
pushq $0x5
popq %rsi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax
movq 0x190(%rbx), %rdi
callq 0x56a50
movq %rax, %r12
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
movq %rax, %rdi
callq 0x59c60
cwtl
cvtsi2sd %eax, %xmm0
divsd 0x5cdb5(%rip), %xmm0    # 0xe3510
movsd %xmm0, 0x20(%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
movq %rax, %r13
movq %rax, %r15
shrq $0x20, %r15
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x50(%rax)
movq %rax, %rbp
movq %rax, %r14
shrq $0x20, %r14
cvtsi2sd %ebp, %xmm0
movsd 0x60145(%rip), %xmm1    # 0xe68d8
movsd 0x20(%rsp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movsd 0x5f80b(%rip), %xmm0    # 0xe5fb8
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %ecx
movq %r13, 0x10(%rsp)
addl %r13d, %eax
movl %eax, 0x48(%rsp)
movl %r15d, 0x4c(%rsp)
addl %eax, %ecx
movl %ecx, 0x50(%rsp)
leal (%r14,%r15), %eax
movl %eax, 0x54(%rsp)
leaq 0x478(%rbx), %rdi
callq 0x878c6
testl %eax, %eax
je 0x867f9
leaq 0x48(%rsp), %rsi
movq %r12, %rdi
callq 0x58ae0
testb %al, %al
je 0x86a32
movq %r12, 0x18(%rsp)
movq 0x5f8(%rbx), %rdi
movq (%rdi), %rax
callq *0x70(%rax)
callq 0x59120
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
movq 0x5b8(%rbx), %rdi
callq 0x5a250
movzwl 0xd0(%rbx), %r13d
movq 0x5b8(%rbx), %rax
cmpw $0x10, %r13w
movq %rbp, 0x30(%rsp)
jne 0x8684d
movl 0xb0(%rax), %ebp
pushq $-0x1
popq %r12
jmp 0x8686d
leal 0x1(%rbp), %ecx
cvtsi2sd %ecx, %xmm0
movl 0xb0(%rax), %ebp
cvtsi2sd %ebp, %xmm1
mulsd 0x20(%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, 0x2c(%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x160(%rax)
movq 0x18(%rsp), %rcx
movl 0xa8(%rcx), %ecx
cmpw $0x10, %r13w
jne 0x86903
testb %al, %al
movq 0x40(%rsp), %rdi
je 0x86920
movq 0x18(%rsp), %rsi
addl 0xb0(%rsi), %ecx
subl %r12d, %ecx
cvtsi2sd %ebp, %xmm0
mulsd 0x20(%rsp), %xmm0
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x5cecc(%rip), %rdx     # 0xe37b0
addsd (%rdx,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
movslq %ecx, %rcx
subq %rax, %rcx
movslq 0x38(%rsp), %rdx
cmpq %rdx, %rcx
jl 0x8695e
jmp 0x8698e
testb %al, %al
movq 0x40(%rsp), %rdi
je 0x86974
movq 0x18(%rsp), %rsi
addl 0xb0(%rsi), %ecx
subl %r12d, %ecx
cmpl %edi, %ecx
jge 0x86983
jmp 0x8698e
addl %ecx, %r12d
cvtsi2sd %ebp, %xmm0
mulsd 0x20(%rsp), %xmm0
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x5ce6f(%rip), %rcx     # 0xe37b0
addsd (%rcx,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
movslq %r12d, %rcx
addq %rax, %rcx
movslq %edi, %rdx
cmpq %rdx, %rcx
movq 0x18(%rsp), %rsi
jl 0x8698e
movq 0x10(%rsp), %rcx
movq 0x30(%rsp), %rdx
addl %edx, %ecx
subl %eax, %ecx
incl %ecx
movl %ecx, 0x8(%rsp)
jmp 0x8698e
addl %ecx, %r12d
cmpl 0x38(%rsp), %r12d
movq 0x18(%rsp), %rsi
jge 0x8698e
movq 0x10(%rsp), %rax
decl %eax
movl %eax, 0x8(%rsp)
movslq 0xac(%rsi), %rax
movslq %r14d, %rcx
addq %rax, %rcx
cvtsi2sdl 0x2c(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
mulsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
leaq 0x5cdf1(%rip), %rdx     # 0xe37b0
addsd (%rdx,%rax,8), %xmm1
cvttsd2si %xmm1, %rax
addq %rax, %rcx
sarq $0x20, %rdi
cmpq %rdi, %rcx
jl 0x869de
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 0xdb473(%rip), %rsi     # 0x161e80
xorl %edx, %edx
movq %rbx, %rcx
callq 0x876f2
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
nop