// File: /workspace/github_c_makefile_star2_O2/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 %r13d, %r13d
xorl %esi, %esi
callq 0x59ca0
andl $0x0, 0x5dc(%rbx)
movb $0x0, 0x5e0(%rbx)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
movq %rax, (%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x50(%rax)
movq %rax, %r12
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
movq %rax, %r15
shrq $0x20, %rax
movq %rax, 0x8(%rsp)
movl %ebp, 0x5c0(%rbx)
movl 0x30(%rbx), %edi
pushq $0x1
popq %rsi
callq 0x596b0
movl 0x5c0(%rbx), %ebp
testb %al, %al
je 0x8f262
leaq 0xf0(%rbx), %r14
xorl %r13d, %r13d
testl %ebp, %ebp
jle 0x8f25c
decl %ebp
movq %r14, %rdi
movl %ebp, %esi
callq 0x59cc0
xorl %ecx, %ecx
cmpl $0xa, (%rax)
sete %cl
addl %ecx, %r13d
jmp 0x8f23f
movl 0x5c0(%rbx), %ebp
movq (%rsp), %r14
addl %r14d, %r12d
movq %rbx, %rdi
movl %ebp, %esi
callq 0x59360
movq %r14, %rdi
movl %eax, %r14d
addl %r15d, %r14d
movl 0x5d0(%rbx), %eax
cmpl %r12d, %r14d
setg %dl
cmpl %edi, %r14d
setl %cl
orb %dl, %cl
testb %cl, %cl
je 0x8f2b8
je 0x8f290
leal -0x14(%rax), %ecx
addl $0x5, %eax
leal 0x14(%r14), %edx
cmpl %r12d, %r14d
leal -0x5(%r14), %esi
cmovlel %ecx, %eax
movl %eax, 0x5d0(%rbx)
cmovlel %edx, %esi
movl %esi, %r14d
jmp 0x8f282
testl %eax, %eax
jns 0x8f2c6
subl %eax, %r14d
andl $0x0, 0x5d0(%rbx)
leaq 0x140(%rbx), %r15
movq 0xd2ae4(%rip), %rsi     # 0x161db8
movq %r15, %rdi
callq 0x588a0
movl %eax, (%rsp)
movl %r13d, %ebp
subl 0x5d4(%rbx), %ebp
movl 0x30(%rbx), %edi
pushq $0x1
popq %rsi
callq 0x596b0
testb %al, %al
je 0x8f334
movl 0x5d4(%rbx), %ecx
cmpl %ecx, %r13d
jl 0x8f417
movq 0xd2aab(%rip), %rsi     # 0x161db8
movq %r15, %rdi
callq 0x59d90
addl $0x3, %eax
movl 0x5d4(%rbx), %ecx
movl %r13d, %edx
subl %ecx, %edx
incl %edx
imull %eax, %edx
cmpl 0xb4(%rbx), %edx
jg 0x8f417
movl 0x5d8(%rbx), %edx
testl %edx, %edx
jle 0x8f350
leaq 0x748(%rbx), %rdi
movl 0x5d4(%rbx), %esi
callq 0x7260e
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x98(%rax)
testb %al, %al
je 0x8f394
movl (%rsp), %eax
addl $0x3, %eax
imull %eax, %ebp
incl %r14d
movq 0x8(%rsp), %rax
addl %ebp, %eax
addl $0x2, %eax
shlq $0x20, %rax
orq %rax, %r14
leaq 0x10(%rsp), %rdx
movq %r14, (%rdx)
movq 0xd263c(%rip), %rdi     # 0x1619c8
movq %rbx, %rsi
callq 0x916bc
movq 0x5b8(%rbx), %rdi
testq %rdi, %rdi
je 0x8f3a5
callq 0x5a010
pushq $0x68
popq %rdi
callq 0x56700
movq %rax, %r14
movq %rax, %rdi
callq 0x56c00
movq %r14, 0x5b8(%rbx)
addq $0x48, %r14
movq 0xd21ae(%rip), %rsi     # 0x161578
movq %r14, %rdi
xorl %edx, %edx
movq %rbx, %rcx
callq 0x91462
movq 0x5b8(%rbx), %rdi
movl $0x1f4, %esi            # imm = 0x1F4
callq 0x56100
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x59ca0
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
decl %ecx
movl %ecx, 0x5d4(%rbx)
cmpl %ecx, %r13d
jl 0x8f40f
incl %r13d
movq 0xd2992(%rip), %r12     # 0x161db8
movq %r15, %rdi
movq %r12, %rsi
callq 0x59d90
addl $0x3, %eax
movl 0x5d4(%rbx), %ecx
movl %r13d, %edx
subl %ecx, %edx
imull %eax, %edx
cmpl 0xb4(%rbx), %edx
jle 0x8f334
incl %ecx
movl %ecx, 0x5d4(%rbx)
jmp 0x8f426
movq %rax, %rbx
pushq $0x68
popq %rsi
movq %r14, %rdi
callq 0x564c0
movq %rbx, %rdi
callq 0x58260