// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x88(%rbp)
movb $0x1, 0xcd(%rdi)
xorl %esi, %esi
callq 0x5d4c0
movq -0x88(%rbp), %rdi
movl $0x0, 0x5dc(%rdi)
movb $0x0, 0x5e0(%rdi)
movq (%rdi), %rax
callq *0x48(%rax)
movq -0x88(%rbp), %rdi
movq %rax, -0x24(%rbp)
movq (%rdi), %rax
callq *0x50(%rax)
movq %rax, -0x2c(%rbp)
leaq -0x1c(%rbp), %rdi
leaq -0x24(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x59ff0
movq -0x88(%rbp), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movq -0x88(%rbp), %rdi
movq %rax, -0x34(%rbp)
movl -0xc(%rbp), %eax
movl %eax, 0x5c0(%rdi)
movl $0x0, -0x38(%rbp)
callq 0x5a120
movl %eax, %edi
movl $0x1, %esi
callq 0x5ce30
testb $0x1, %al
jne 0xcd43e
jmp 0xcd48a
movq -0x88(%rbp), %rax
movl 0x5c0(%rax), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0xcd488
movq -0x88(%rbp), %rdi
addq $0xf0, %rdi
movl -0x3c(%rbp), %esi
callq 0x5d4e0
cmpl $0xa, (%rax)
jne 0xcd47b
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xcd47d
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xcd451
jmp 0xcd48a
movq -0x88(%rbp), %rdi
movl 0x5c0(%rdi), %esi
callq 0x5ca60
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %ecx
movb $0x1, %al
cmpl -0x14(%rbp), %ecx
movb %al, -0x89(%rbp)
jg 0xcd4c1
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
setl %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0xcd4cd
jmp 0xcd521
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jle 0xcd4f6
movq -0x88(%rbp), %rax
movl 0x5d0(%rax), %ecx
addl $0x5, %ecx
movl %ecx, 0x5d0(%rax)
movl -0x34(%rbp), %eax
subl $0x5, %eax
movl %eax, -0x34(%rbp)
jmp 0xcd51f
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xcd51d
movq -0x88(%rbp), %rax
movl 0x5d0(%rax), %ecx
subl $0x14, %ecx
movl %ecx, 0x5d0(%rax)
movl -0x34(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x34(%rbp)
jmp 0xcd51f
jmp 0xcd4a2
movq -0x88(%rbp), %rax
cmpl $0x0, 0x5d0(%rax)
jge 0xcd550
movq -0x88(%rbp), %rax
movl 0x5d0(%rax), %edx
movl -0x34(%rbp), %ecx
subl %edx, %ecx
movl %ecx, -0x34(%rbp)
movl $0x0, 0x5d0(%rax)
movq -0x88(%rbp), %rdi
addq $0x140, %rdi            # imm = 0x140
movq 0x13b843(%rip), %rsi    # 0x208da8
callq 0x5bde0
movq -0x88(%rbp), %rdi
addl $0x3, %eax
movl -0x38(%rbp), %ecx
subl 0x5d4(%rdi), %ecx
imull %ecx, %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
callq 0x5a120
movl %eax, %edi
movl $0x1, %esi
callq 0x5ce30
testb $0x1, %al
jne 0xcd5a0
jmp 0xcd698
movq -0x88(%rbp), %rcx
movl -0x38(%rbp), %eax
subl 0x5d4(%rcx), %eax
cmpl $0x0, %eax
jl 0xcd603
movq -0x88(%rbp), %rdi
addq $0x140, %rdi            # imm = 0x140
movq 0x13b7de(%rip), %rsi    # 0x208da8
callq 0x5d5e0
movq -0x88(%rbp), %rdi
addl $0x3, %eax
movl -0x38(%rbp), %ecx
subl 0x5d4(%rdi), %ecx
addl $0x1, %ecx
imull %ecx, %eax
movl %eax, -0x90(%rbp)
callq 0x5b860
movl %eax, %ecx
movl -0x90(%rbp), %eax
cmpl %ecx, %eax
jle 0xcd698
jmp 0xcd605
movq -0x88(%rbp), %rcx
movl -0x38(%rbp), %eax
subl 0x5d4(%rcx), %eax
cmpl $0x0, %eax
jge 0xcd632
movq -0x88(%rbp), %rax
movl 0x5d4(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x5d4(%rax)
jmp 0xcd605
jmp 0xcd634
movq -0x88(%rbp), %rdi
addq $0x140, %rdi            # imm = 0x140
movq 0x13b75f(%rip), %rsi    # 0x208da8
callq 0x5d5e0
movq -0x88(%rbp), %rdi
addl $0x3, %eax
movl -0x38(%rbp), %ecx
subl 0x5d4(%rdi), %ecx
addl $0x1, %ecx
imull %ecx, %eax
movl %eax, -0x94(%rbp)
callq 0x5b860
movl %eax, %ecx
movl -0x94(%rbp), %eax
cmpl %ecx, %eax
jle 0xcd696
movq -0x88(%rbp), %rax
movl 0x5d4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x5d4(%rax)
jmp 0xcd634
jmp 0xcd698
movq -0x88(%rbp), %rax
cmpl $0x0, 0x5d8(%rax)
jle 0xcd6ca
movq -0x88(%rbp), %rax
movq %rax, %rdi
addq $0x748, %rdi            # imm = 0x748
movl 0x5d4(%rax), %esi
movl 0x5d8(%rax), %edx
callq 0x908f0
movq -0x88(%rbp), %rdi
movq (%rdi), %rax
callq *0x98(%rax)
testb $0x1, %al
jne 0xcd6e0
jmp 0xcd71b
leaq -0x4c(%rbp), %rdi
movl $0x1, %esi
movl $0x2, %edx
callq 0x5c2c0
leaq -0x34(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x5ca20
movq -0x88(%rbp), %rsi
movq %rax, -0x44(%rbp)
movq 0x13b296(%rip), %rdi    # 0x2089a8
leaq -0x44(%rbp), %rdx
callq 0xd10f0
movq -0x88(%rbp), %rax
cmpq $0x0, 0x5b8(%rax)
je 0xcd73f
movq -0x88(%rbp), %rax
movq 0x5b8(%rax), %rdi
callq 0x5d8d0
movl $0x68, %edi
callq 0x59820
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xa0(%rbp)
callq 0x59db0
jmp 0xcd75d
movq -0x88(%rbp), %rcx
movq -0xa0(%rbp), %rax
movq %rax, 0x5b8(%rcx)
movq 0x5b8(%rcx), %rdi
addq $0x48, %rdi
movq 0x13adcc(%rip), %rax    # 0x208550
movq %rax, -0x70(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
callq 0xd0c10
movq -0x88(%rbp), %rax
movq 0x5b8(%rax), %rdi
movl $0x1f4, %esi            # imm = 0x1F4
callq 0x59120
movq -0x88(%rbp), %rdi
movq (%rdi), %rax
movq 0x78(%rax), %rax
xorl %esi, %esi
callq *%rax
movq -0x88(%rbp), %rdi
movl $0x1, %esi
callq 0x5d4c0
leaq -0x80(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x5ca80
movq -0xb0(%rbp), %rdi
callq 0x59680
movl %eax, -0xa4(%rbp)
jmp 0xcd7fc
leaq -0x80(%rbp), %rdi
callq 0x5a410
movl -0xa4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
movq -0xa0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
movl $0x68, %esi
callq 0x595b0
jmp 0xcd848
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x5a410
movq -0x58(%rbp), %rdi
callq 0x5b6b0
nopw %cs:(%rax,%rax)