From 4e9a5bdaec0e6c04530710cb28e10ad5b8ebb2ad Mon Sep 17 00:00:00 2001 From: jacob1 Date: Fri, 17 Jan 2014 21:49:55 -0500 Subject: [PATCH] make sure comment box height and cursor position don't go too far when it's resizing, fixes #82 --- src/gui/interface/Textbox.cpp | 5 +++++ src/gui/interface/Textbox.h | 3 ++- src/gui/preview/PreviewView.cpp | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gui/interface/Textbox.cpp b/src/gui/interface/Textbox.cpp index ef07c67dc..0e854064e 100644 --- a/src/gui/interface/Textbox.cpp +++ b/src/gui/interface/Textbox.cpp @@ -122,6 +122,11 @@ void Textbox::OnContextMenuAction(int item) } } +void Textbox::resetCursorPosition() +{ + Graphics::PositionAtCharIndex(multiline?((char*)textLines.c_str()):((char*)text.c_str()), cursor, cursorPositionX, cursorPositionY); +} + void Textbox::cutSelection() { char * clipboardText; diff --git a/src/gui/interface/Textbox.h b/src/gui/interface/Textbox.h index 0d5140b0d..5e4c4f0b9 100644 --- a/src/gui/interface/Textbox.h +++ b/src/gui/interface/Textbox.h @@ -30,7 +30,7 @@ public: virtual void SetPlaceholder(std::string text); - void SetBorder(bool border) { this->border = border; }; + void SetBorder(bool border) { this->border = border; } void SetHidden(bool hidden); bool GetHidden() { return masked; } void SetActionCallback(TextboxAction * action) { actionCallback = action; } @@ -41,6 +41,7 @@ public: ValidInput GetInputType(); void SetInputType(ValidInput input); + void resetCursorPosition(); //Determines if the given character is valid given the input type bool CharacterValid(Uint16 character); diff --git a/src/gui/preview/PreviewView.cpp b/src/gui/preview/PreviewView.cpp index 1cd619b7c..0db033cde 100644 --- a/src/gui/preview/PreviewView.cpp +++ b/src/gui/preview/PreviewView.cpp @@ -351,6 +351,8 @@ void PreviewView::OnTick(float dt) xdiff = 1*isign(sizeDiff.X); addCommentBox->Size.X += xdiff; addCommentBox->Invalidate(); + commentBoxAutoHeight(); //make sure textbox height is correct after resizes + addCommentBox->resetCursorPosition(); //make sure cursor is in correct position after resizes } if(sizeDiff.Y!=0) {