// File: /workspace/github_c_makefile_star2_O1/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 0x6fac1
movq %rbx, %rdi
callq 0x59128
leaq 0x1d0(%rbx), %rdi
callq 0x71642
movq %rax, 0x198(%rbx)
testq %rax, %rax
je 0x6fcd5
leaq 0x498(%rbx), %rdi
callq 0x70488
movq 0x190(%rbx), %r14
movq 0xfcd31(%rip), %rax     # 0x16c828
movswl (%rax), %ebp
leaq 0x20(%r14), %rdi
movl %ebp, %esi
callq 0x57520
testb %al, %al
jne 0x6fb18
movq 0x190(%r14), %r14
testq %r14, %r14
jne 0x6fafa
xorl %r14d, %r14d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
movq %rax, %r13
callq 0x57e90
movq %rax, %r12
movq %rdx, %r15
movq %r13, %rdi
callq 0x58930
cwtl
cvtsi2sd %eax, %xmm0
divsd 0x849ac(%rip), %xmm0    # 0xf44f0
movsd %xmm0, 0x10(%rsp)
movq 0x198(%rbx), %rdi
callq 0x58ee0
movq %r14, %rdi
callq 0x56b50
movq %rax, 0x8(%rsp)
movq (%rbx), %rax
movq 0x198(%rbx), %rcx
movl 0xb0(%rcx), %r13d
movl 0xb4(%rcx), %ebp
movq %rbx, %rdi
callq *0x160(%rax)
testb %al, %al
je 0x6fbe5
movl 0xb0(%r14), %edx
movl 0x8(%rsp), %eax
addl 0xa8(%r14), %edx
subl %eax, %edx
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd 0x10(%rsp), %xmm2
mulsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
ucomisd %xmm0, %xmm1
seta %cl
leaq 0x84cff(%rip), %rsi     # 0xf48c0
addsd (%rsi,%rcx,8), %xmm0
cvttsd2si %xmm0, %rcx
movslq %edx, %rdx
subq %rcx, %rdx
movslq %r12d, %rsi
cmpq %rsi, %rdx
movapd %xmm2, %xmm1
jge 0x6fc39
subl %ecx, %eax
movl %eax, 0x8(%rsp)
jmp 0x6fc39
movslq 0xa8(%r14), %rdx
movslq 0x8(%rsp), %rax
addq %rax, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd 0x10(%rsp), %xmm2
mulsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
ucomisd %xmm0, %xmm1
seta %cl
leaq 0x84ca6(%rip), %rsi     # 0xf48c0
addsd (%rsi,%rcx,8), %xmm0
cvttsd2si %xmm0, %rcx
addq %rcx, %rdx
movslq %r15d, %rsi
cmpq %rsi, %rdx
movapd %xmm2, %xmm1
jl 0x6fc39
subl %ecx, %eax
movl %eax, 0x8(%rsp)
movslq 0xac(%r14), %rdx
movslq 0xc(%rsp), %rax
addq %rax, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
ucomisd %xmm1, %xmm0
seta %cl
leaq 0x84c59(%rip), %rsi     # 0xf48c0
addsd (%rsi,%rcx,8), %xmm1
cvttsd2si %xmm1, %rcx
addq %rcx, %rdx
sarq $0x20, %r15
cmpq %r15, %rdx
jl 0x6fc83
subl %ecx, %eax
movl %eax, 0xc(%rsp)
movq 0x198(%rbx), %rdi
leaq 0xb0(%rdi), %rdx
movq (%rdi), %rax
leaq 0x8(%rsp), %rsi
callq *0x150(%rax)
movq 0x198(%rbx), %rdi
movb $0x1, 0xce(%rdi)
addq $0x698, %rdi            # imm = 0x698
movq 0xfc86d(%rip), %rsi     # 0x16c528
xorl %edx, %edx
movq %rbx, %rcx
callq 0x705b8
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