// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, 0x198(%rax)
je 0x89b0a
movq -0x58(%rbp), %rdi
callq 0x5de20
movq -0x58(%rbp), %rdi
addq $0x1d0, %rdi            # imm = 0x1D0
callq 0x8bb00
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x198(%rax)
cmpq $0x0, 0x198(%rax)
je 0x89d78
movq -0x58(%rbp), %rdi
addq $0x498, %rdi            # imm = 0x498
callq 0x8af60
movq -0x58(%rbp), %rax
movq 0x190(%rax), %rdi
callq 0x59bc0
movq -0x58(%rbp), %rdi
movq %rax, -0x10(%rbp)
movq (%rdi), %rax
callq *0x40(%rax)
movq %rax, -0x18(%rbp)
callq 0x5c790
movq %rax, -0x28(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x5d470
movw %ax, %cx
movq -0x58(%rbp), %rax
movswl %cx, %ecx
cvtsi2sd %ecx, %xmm0
movsd 0xfd92c(%rip), %xmm1    # 0x1874c0
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movq 0x198(%rax), %rdi
callq 0x5dbb0
movq -0x10(%rbp), %rdi
callq 0x5b090
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, -0x38(%rbp)
movq 0x198(%rax), %rdi
callq 0x5bf70
movq -0x58(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq (%rdi), %rax
callq *0x160(%rax)
testb $0x1, %al
jne 0x89c3b
movq -0x10(%rbp), %rdi
callq 0x5dab0
addl -0x38(%rbp), %eax
cltq
movq %rax, -0x60(%rbp)
cvtsi2sdl -0x40(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
callq 0x5a970
movq %rax, %rcx
movq -0x60(%rbp), %rax
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jl 0x89c39
movslq -0x38(%rbp), %rax
movq %rax, -0x68(%rbp)
cvtsi2sdl -0x40(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
callq 0x5a970
movq %rax, %rcx
movq -0x68(%rbp), %rax
subq %rcx, %rax
movl %eax, -0x38(%rbp)
jmp 0x89ca8
movq -0x10(%rbp), %rdi
callq 0x5dab0
movl %eax, -0x74(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5a210
movl %eax, %ecx
movl -0x74(%rbp), %eax
subl -0x38(%rbp), %ecx
addl %ecx, %eax
cltq
movq %rax, -0x70(%rbp)
cvtsi2sdl -0x40(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
callq 0x5a970
movq %rax, %rcx
movq -0x70(%rbp), %rax
subq %rcx, %rax
movslq -0x28(%rbp), %rcx
cmpq %rcx, %rax
jge 0x89ca6
movslq -0x38(%rbp), %rax
movq %rax, -0x80(%rbp)
cvtsi2sdl -0x40(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
callq 0x5a970
movq %rax, %rcx
movq -0x80(%rbp), %rax
subq %rcx, %rax
movl %eax, -0x38(%rbp)
jmp 0x89ca8
movq -0x10(%rbp), %rdi
callq 0x5ddb0
addl -0x34(%rbp), %eax
cltq
movq %rax, -0x88(%rbp)
cvtsi2sdl -0x3c(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
callq 0x5a970
movq %rax, %rcx
movq -0x88(%rbp), %rax
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jl 0x89d0c
movslq -0x34(%rbp), %rax
movq %rax, -0x90(%rbp)
cvtsi2sdl -0x3c(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
callq 0x5a970
movq %rax, %rcx
movq -0x90(%rbp), %rax
subq %rcx, %rax
movl %eax, -0x34(%rbp)
movq -0x58(%rbp), %rax
movq 0x198(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x5d8c0
movq -0x58(%rbp), %rax
movq 0x198(%rax), %rdi
movl $0x1, %esi
callq 0x5c4f0
movq -0x58(%rbp), %rcx
movq 0x198(%rcx), %rdi
addq $0x698, %rdi            # imm = 0x698
movq 0x17e7b2(%rip), %rax    # 0x208500
movq %rax, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x8b3e0
movq -0x58(%rbp), %rdi
movq 0x198(%rdi), %rsi
movq (%rdi), %rax
callq *0x30(%rax)
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)