// File: /workspace/github_c_makefile_star2_O1/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
testb %al, %al
je 0x92f7c
movl 0x5c0(%rbx), %ebp
testl %ebp, %ebp
jle 0x92f7c
leaq 0xf0(%rbx), %r15
incl %ebp
xorl %r14d, %r14d
leal -0x2(%rbp), %esi
movq %r15, %rdi
callq 0x58990
xorl %ecx, %ecx
cmpl $0xa, (%rax)
sete %cl
addl %ecx, %r14d
decl %ebp
cmpl $0x1, %ebp
jg 0x92f5f
movl 0x5c0(%rbx), %esi
movq %rbx, %rdi
callq 0x580d0
movl %eax, %r15d
addl 0x8(%rsp), %r15d
cmpl %r12d, %r15d
setl %sil
cmpl %r13d, %r15d
setg %dl
jg 0x92fa6
cmpl %r12d, %r15d
jge 0x92ff3
leaq 0x5d0(%rbx), %rax
movl 0x5d0(%rbx), %ecx
testb $0x1, %dl
jne 0x92fbe
testb $0x1, %sil
je 0x92fdf
leal -0x14(%rcx), %esi
addl $0x5, %ecx
leal 0x14(%r15), %edi
addl $-0x5, %r15d
testb $0x1, %dl
movq %rax, %rdx
cmovneq %rax, %rdx
cmovel %esi, %ecx
movl %ecx, (%rdx)
cmovel %edi, %r15d
cmpl %r12d, %r15d
setl %sil
cmpl %r13d, %r15d
setg %dl
jg 0x92fb3
cmpl %r12d, %r15d
jl 0x92fb3
movl 0x5d0(%rbx), %eax
testl %eax, %eax
jns 0x9300a
subl %eax, %r15d
movl $0x0, 0x5d0(%rbx)
leaq 0x140(%rbx), %r12
movq 0xd9da0(%rip), %rsi     # 0x16cdb8
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 0x930e1
cmpl 0x5d4(%rbx), %r14d
jl 0x93073
movq 0xd9d66(%rip), %rsi     # 0x16cdb8
movq %r12, %rdi
callq 0x58a50
addl $0x3, %eax
movl %r14d, %ecx
subl 0x5d4(%rbx), %ecx
incl %ecx
imull %eax, %ecx
cmpl 0xb4(%rbx), %ecx
jle 0x930e1
cmpl 0x5d4(%rbx), %r14d
jge 0x93083
movl %r14d, 0x5d4(%rbx)
movq 0xd9d2e(%rip), %rsi     # 0x16cdb8
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 0x930e1
movq 0xd9d03(%rip), %r13     # 0x16cdb8
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 0x930b5
movl 0x5d8(%rbx), %edx
testl %edx, %edx
jle 0x930fd
leaq 0x748(%rbx), %rdi
movl 0x5d4(%rbx), %esi
callq 0x72e5c
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x98(%rax)
testb %al, %al
je 0x93146
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 0xd988a(%rip), %rdi     # 0x16c9c8
movq %rbx, %rsi
callq 0x95674
movq 0x5b8(%rbx), %rdi
testq %rdi, %rdi
je 0x93157
callq 0x58cc0
movl $0x68, %edi
callq 0x556b0
movq %rax, %r14
movq %rax, %rdi
callq 0x55b80
movq %r14, 0x5b8(%rbx)
addq $0x48, %r14
movq 0xd93fa(%rip), %rsi     # 0x16c578
movq %r14, %rdi
xorl %edx, %edx
movq %rbx, %rcx
callq 0x953e4
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