// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/classes/gui/widgets/special/cursor.cpp
// Function: smooth::GUI::Cursor::SetCursorPos(int)
S::Int S::GUI::Cursor::SetCursorPos(Int newPos)
{
	focussed = True;

	ShowCursor(False);

	imeAdvance = 0;
	imeCursor  = False;

	Rect	 frame	 = Rect(GetRealPosition(), GetRealSize());
	Point	 p1	 = GetRealPosition();

	promptPos = newPos;

	/* Compute line number.
	 */
	Int	 line = 0;

	if (Binary::IsFlagSet(GetFlags(), CF_MULTILINE))
	{
		for (Int j = promptPos - 1; j >= 0; j--)
		{
			if (text[j] == '\n') line++;
		}
	}

	/* Compute cursor position on screen.
	 */
	p1.x += GetDisplayCursorPositionFromLogical(promptPos);

	while (p1.x > frame.right || p1.x < frame.left)
	{
		if	(p1.x > frame.right) { visibleOffset +=  5; p1.x -=  5; }
		else if (p1.x < frame.left)  { visibleOffset -= 20; p1.x += 20; }
	}

	if (visibleOffset < 0) { p1.x -= visibleOffset; visibleOffset = 0; }

	p1.y += (font.GetScaledTextSizeY() + 3) * (line - scrollPos);

	if (Binary::IsFlagSet(GetFlags(), CF_MULTILINE) && (line - scrollPos < 0 || (font.GetUnscaledTextSizeY() + 3) * (line - scrollPos + 1) > GetHeight()))
	{
		while (line - scrollPos < 0)							 scrollPos--;
		while ((font.GetUnscaledTextSizeY() + 3) * (line - scrollPos + 1) > GetHeight()) scrollPos++;
	}

	if (maxScrollPos > 0) onScroll.Emit(scrollPos, maxScrollPos);

	/* Notify listeners of new cursor position.
	 */
	if (IsActive()) internalSetCursor.Emit(this, p1 + Point(1, 2));

	/* Start blinking cursor timer.
	 */
	if (timer != NIL) DeleteObject(timer);

	timer = new System::Timer();

	timer->onInterval.Connect(&Cursor::OnTimer, this);
	timer->Start(500);

	/* Redraw and show cursor.
	 */
	Paint(SP_PAINT);

	ShowCursor(True);

	return Success();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movb $0x1, 0xcd(%rdi)
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x58970
movl $0x0, 0x5dc(%rbx)
movb $0x0, 0x5e0(%rbx)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
movq %rax, %r12
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x50(%rax)
movq %rax, %r13
addl %r12d, %r13d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
movq %rax, 0x8(%rsp)
movl %ebp, 0x5c0(%rbx)
movl 0x30(%rbx), %edi
movl $0x1, %esi
callq 0x583f0
movl 0x5c0(%rbx), %r15d
testl %r15d, %r15d
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x929c1
leaq 0xf0(%rbx), %rbp
incl %r15d
xorl %r14d, %r14d
leal -0x2(%r15), %esi
movq %rbp, %rdi
callq 0x58990
xorl %ecx, %ecx
cmpl $0xa, (%rax)
sete %cl
addl %ecx, %r14d
decl %r15d
cmpl $0x1, %r15d
ja 0x9299a
movl 0x5c0(%rbx), %r15d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x580d0
movl %eax, %r15d
addl 0x8(%rsp), %r15d
cmpl %r12d, %r15d
setl %dl
movl 0x5d0(%rbx), %eax
cmpl %r13d, %r15d
setg %cl
jg 0x929ed
cmpl %r12d, %r15d
jge 0x92a1d
testb $0x1, %cl
jne 0x929f7
testb $0x1, %dl
je 0x92a15
leal -0x14(%rax), %edx
addl $0x5, %eax
leal 0x14(%r15), %esi
addl $-0x5, %r15d
testb $0x1, %cl
cmovel %edx, %eax
movl %eax, 0x5d0(%rbx)
cmovel %esi, %r15d
cmpl %r12d, %r15d
setl %dl
jmp 0x929e0
testl %eax, %eax
jns 0x92a2e
subl %eax, %r15d
movl $0x0, 0x5d0(%rbx)
leaq 0x140(%rbx), %r12
movq 0xd937c(%rip), %rsi     # 0x16bdb8
movq %r12, %rdi
callq 0x57680
movl %eax, 0x4(%rsp)
movl %r14d, %ebp
subl 0x5d4(%rbx), %ebp
movl 0x30(%rbx), %edi
movl $0x1, %esi
callq 0x583f0
testb %al, %al
je 0x92b05
movl 0x5d4(%rbx), %ecx
cmpl %ecx, %r14d
jl 0x92a9b
movq 0xd9340(%rip), %rsi     # 0x16bdb8
movq %r12, %rdi
callq 0x58a50
addl $0x3, %eax
movl 0x5d4(%rbx), %ecx
movl %r14d, %edx
subl %ecx, %edx
incl %edx
imull %eax, %edx
cmpl 0xb4(%rbx), %edx
jle 0x92b05
cmpl %ecx, %r14d
jge 0x92aa7
movl %r14d, 0x5d4(%rbx)
movq 0xd930a(%rip), %rsi     # 0x16bdb8
movq %r12, %rdi
callq 0x58a50
addl $0x3, %eax
movl 0x5d4(%rbx), %ecx
incl %r14d
movl %r14d, %edx
subl %ecx, %edx
imull %eax, %edx
cmpl 0xb4(%rbx), %edx
jle 0x92b05
movq 0xd92df(%rip), %r13     # 0x16bdb8
incl %ecx
movl %ecx, 0x5d4(%rbx)
movq %r12, %rdi
movq %r13, %rsi
callq 0x58a50
addl $0x3, %eax
movl 0x5d4(%rbx), %ecx
movl %r14d, %edx
subl %ecx, %edx
imull %eax, %edx
cmpl 0xb4(%rbx), %edx
jg 0x92ad9
movl 0x5d8(%rbx), %edx
testl %edx, %edx
jle 0x92b21
leaq 0x748(%rbx), %rdi
movl 0x5d4(%rbx), %esi
callq 0x72b08
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x98(%rax)
testb %al, %al
je 0x92b6a
movq 0x8(%rsp), %rax
shrq $0x20, %rax
movl 0x4(%rsp), %ecx
addl $0x3, %ecx
imull %ecx, %ebp
incl %r15d
addl %ebp, %eax
addl $0x2, %eax
shlq $0x20, %rax
orq %rax, %r15
leaq 0x10(%rsp), %rdx
movq %r15, (%rdx)
movq 0xd8e66(%rip), %rdi     # 0x16b9c8
movq %rbx, %rsi
callq 0x9501c
movq 0x5b8(%rbx), %rdi
testq %rdi, %rdi
je 0x92b7b
callq 0x58cc0
movl $0x68, %edi
callq 0x556b0
movq %rax, %r14
movq %rax, %rdi
callq 0x55b80
movq %r14, 0x5b8(%rbx)
addq $0x48, %r14
movq 0xd89d6(%rip), %rsi     # 0x16b578
movq %r14, %rdi
xorl %edx, %edx
movq %rbx, %rcx
callq 0x94d7e
movq 0x5b8(%rbx), %rdi
movl $0x1f4, %esi            # imm = 0x1F4
callq 0x55100
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x58970
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x68, %esi
movq %r14, %rdi
callq 0x55480
movq %rbx, %rdi
callq 0x57090
nop