// File: /workspace/github_c_makefile_star2_O2/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 0x6f7f9
movq %rbx, %rdi
callq 0x5a4a8
leaq 0x1d0(%rbx), %rdi
callq 0x710a8
movq %rax, 0x198(%rbx)
testq %rax, %rax
je 0x6f99c
leaq 0x498(%rbx), %rdi
callq 0x70196
movq 0x190(%rbx), %rdi
callq 0x56a50
movq %rax, %r15
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
movq %rax, %r12
callq 0x59120
movq %rax, 0x10(%rsp)
movq %rdx, %r14
movq %r12, %rdi
callq 0x59c60
cwtl
cvtsi2sd %eax, %xmm0
divsd 0x73cb2(%rip), %xmm0    # 0xe3510
movsd %xmm0, 0x8(%rsp)
movq 0x198(%rbx), %rdi
callq 0x5a250
movq %r15, %rdi
callq 0x57cc0
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 0x6f9ab
movl 0xb0(%r15), %edx
addl 0xa8(%r15), %edx
subl %r12d, %edx
cvtsi2sd %r13d, %xmm0
movsd 0x8(%rsp), %xmm2
mulsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x73ece(%rip), %rsi     # 0xe37b0
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 0x6f907
subl %eax, %r12d
movl %r12d, (%rsp)
movslq 0xac(%r15), %rax
movslq %ecx, %rdx
addq %rax, %rdx
cvtsi2sd %ebp, %xmm0
mulsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
leaq 0x73e80(%rip), %rsi     # 0xe37b0
addsd (%rsi,%rax,8), %xmm1
cvttsd2si %xmm1, %rax
addq %rax, %rdx
sarq $0x20, %r14
cmpq %r14, %rdx
jl 0x6f94c
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 0xf1ba6(%rip), %rsi     # 0x161528
xorl %edx, %edx
movq %rbx, %rcx
callq 0x702aa
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(%r15), %rax
movslq %r12d, %rdx
addq %rax, %rdx
cvtsi2sd %r13d, %xmm0
movsd 0x8(%rsp), %xmm2
mulsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x73dd5(%rip), %rsi     # 0xe37b0
addsd (%rsi,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
addq %rax, %rdx
movslq %r14d, %rsi
cmpq %rsi, %rdx
movapd %xmm2, %xmm1
jge 0x6f900
jmp 0x6f907
nop