// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/classes/gui/widgets/widget.cpp
// Function: smooth::GUI::Widget::OpenContextMenu()
S::Void S::GUI::Widget::OpenContextMenu()
{
	if (contextMenu != NIL) CloseContextMenu();

	contextMenu = getContextMenu.Call();

	if (contextMenu != NIL)
	{
		onOpenContextMenu.Emit();

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

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

		contextMenu->CalculateSize();

		Point	 popupPos  = window->GetMousePosition();
		Size	 popupSize = contextMenu->GetSize();

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

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

		contextMenu->SetPosition(popupPos);
		contextMenu->SetAlwaysActive(True);
		contextMenu->internalRequestClose.Connect(&Widget::CloseContextMenu, this);

		Add(contextMenu);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
cmpq $0x0, 0x198(%rdi)
je 0x6f82f
movq %rbx, %rdi
callq 0x59128
leaq 0x1d0(%rbx), %rdi
callq 0x7133c
movq %rax, 0x198(%rbx)
testq %rax, %rax
je 0x6f9f8
leaq 0x498(%rbx), %rdi
callq 0x701aa
movq 0x190(%rbx), %r14
movq 0xfbfc3(%rip), %rax     # 0x16b828
movswl (%rax), %ebp
leaq 0x20(%r14), %rdi
movl %ebp, %esi
callq 0x57520
testb %al, %al
jne 0x6f886
movq 0x190(%r14), %r14
testq %r14, %r14
jne 0x6f868
xorl %r14d, %r14d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
movq %rax, %r12
callq 0x57e90
movq %rax, 0x10(%rsp)
movq %rdx, %r15
movq %r12, %rdi
callq 0x58930
cwtl
cvtsi2sd %eax, %xmm0
divsd 0x83e04(%rip), %xmm0    # 0xf36b8
movsd %xmm0, 0x8(%rsp)
movq 0x198(%rbx), %rdi
callq 0x58ee0
movq %r14, %rdi
callq 0x56b50
movq %rax, %r12
movq %rax, (%rsp)
movq (%rbx), %rax
movq 0x198(%rbx), %rcx
movl 0xb0(%rcx), %r13d
movl 0xb4(%rcx), %ebp
movq %rbx, %rdi
callq *0x160(%rax)
movq %r12, %rcx
shrq $0x20, %rcx
testb %al, %al
je 0x6fa07
movl 0xb0(%r14), %edx
addl 0xa8(%r14), %edx
subl %r12d, %edx
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd 0x8(%rsp), %xmm2
mulsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x83eb5(%rip), %rsi     # 0xf37f0
addsd (%rsi,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
movslq %edx, %rdx
subq %rax, %rdx
movslq 0x10(%rsp), %rsi
cmpq %rsi, %rdx
movapd %xmm2, %xmm1
jge 0x6f960
subl %eax, %r12d
movl %r12d, (%rsp)
movslq 0xac(%r14), %rax
movslq %ecx, %rdx
addq %rax, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
leaq 0x83e64(%rip), %rsi     # 0xf37f0
addsd (%rsi,%rax,8), %xmm1
cvttsd2si %xmm1, %rax
addq %rax, %rdx
sarq $0x20, %r15
cmpq %r15, %rdx
jl 0x6f9a8
subl %eax, %ecx
movl %ecx, 0x4(%rsp)
movq 0x198(%rbx), %rdi
leaq 0xb0(%rdi), %rdx
movq (%rdi), %rax
movq %rsp, %rsi
callq *0x150(%rax)
movq 0x198(%rbx), %rdi
movb $0x1, 0xce(%rdi)
addq $0x698, %rdi            # imm = 0x698
movq 0xfbb4a(%rip), %rsi     # 0x16b528
xorl %edx, %edx
movq %rbx, %rcx
callq 0x702f0
movq (%rbx), %rax
movq 0x198(%rbx), %rsi
movq %rbx, %rdi
callq *0x30(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq 0xa8(%r14), %rax
movslq %r12d, %rdx
addq %rax, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd 0x8(%rsp), %xmm2
mulsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x83db6(%rip), %rsi     # 0xf37f0
addsd (%rsi,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
addq %rax, %rdx
movslq %r15d, %rsi
cmpq %rsi, %rdx
movapd %xmm2, %xmm1
jge 0x6f959
jmp 0x6f960