Переглянути джерело

More accurate line highlighting for UI text editor

Ivan Safrin 13 роки тому
батько
коміт
a9b190de02

+ 12 - 12
Core/Contents/Include/PolyPolygon.h

@@ -52,17 +52,8 @@ namespace Polycode {
 			* Returns the vertex at specified index.
 			* @return Vertex at specified index.
 			*/ 			
-			Vertex *getVertex(unsigned int index);
-			
-			/**
-			* Adds a new vertex with the specified position coordinates.
-			* @param x X coordinate of new vertex.
-			* @param y Y coordinate of new vertex.
-			* @param z Z coordinate of new vertex.						
-			* @return Newly added vertex.
-			*/ 
-			Vertex *addVertex(Number x, Number y, Number z);
-			
+			Vertex *getVertex(unsigned int index);			
+	
 			/**
 			* Adds a new vertex with the specified position coordinates and texture coordinates.
 			* @param x X coordinate of new vertex.
@@ -73,7 +64,16 @@ namespace Polycode {
 			* @return Newly added vertex.
 			*/ 			
 			Vertex *addVertex(Number x, Number y, Number z, Number u, Number v);
-			
+						
+			/**
+			* Adds a new vertex with the specified position coordinates.
+			* @param x X coordinate of new vertex.
+			* @param y Y coordinate of new vertex.
+			* @param z Z coordinate of new vertex.						
+			* @return Newly added vertex.
+			*/ 
+			Vertex *addVertex(Number x, Number y, Number z);
+		
 			
 			/**
 			* Adds a new vertex.

+ 1 - 1
IDE/Contents/Source/PolycodeConsole.cpp

@@ -234,7 +234,7 @@ void PolycodeConsole::_clearBacktraces() {
 
 void PolycodeConsole::_print(String msg) {
 	debugTextInput->setText(debugTextInput->getText()+msg);
-	debugTextInput->getScrollContainer()->setScrollValue(0, 1.1);
+	debugTextInput->getScrollContainer()->setScrollValue(0, 1.0);
 }
 
 void PolycodeConsole::Resize(Number width, Number height) {

+ 2 - 2
Modules/Contents/UI/Source/PolyUIScrollContainer.cpp

@@ -161,13 +161,13 @@ void UIScrollContainer::Update() {
 void UIScrollContainer::handleEvent(Event *event) {
 	if(event->getDispatcher() == vScrollBar) {
 		if(event->getEventCode() == Event::CHANGE_EVENT) {
-			scrollChild->setPositionY(floor(-((contentHeight-height) )*vScrollBar->getScrollValue()));
+			scrollChild->setPositionY(floor(((-contentHeight+height) )*vScrollBar->getScrollValue()));
 		}
 	}
 	
 	if(event->getDispatcher() == hScrollBar) {
 		if(event->getEventCode() == Event::CHANGE_EVENT) {
-			scrollChild->setPositionX(floor(-((contentWidth-width) )*hScrollBar->getScrollValue()));
+			scrollChild->setPositionX(floor(((-contentWidth+width) )*hScrollBar->getScrollValue()));
 		}
 	}
 	

+ 11 - 4
Modules/Contents/UI/Source/PolyUITextInput.cpp

@@ -443,7 +443,7 @@ void UITextInput::restructLines() {
 	}
 	
 	if(scrollContainer) {
-		scrollContainer->setContentSize(width,  (((lines.size()+1) * ((lineHeight+lineSpacing)))) - padding);
+		scrollContainer->setContentSize(width,  (((lines.size()) * ((lineHeight+lineSpacing)))) + padding);
 	}	
 	
 	if(multiLine) {
@@ -555,8 +555,11 @@ void UITextInput::dragSelectionTo(Number x, Number y) {
 	if(x > slen)
 		caretPosition = len;
 	
+	if(multiLine)
+		caretPosition++;
+		
 	if(caretPosition < 0)
-		caretPosition = 0;
+		caretPosition = 0;		
 
 	setSelection(this->lineOffset, lineOffset, this->caretPosition, caretPosition);
 }
@@ -634,6 +637,10 @@ void UITextInput::setCaretToMouse(Number x, Number y) {
 	}
 	if(x > slen)
 		caretPosition = len;
+		
+	if(multiLine)
+		caretPosition++;
+		
 	updateCaretPosition();	
 }
 
@@ -800,9 +807,9 @@ void UITextInput::Paste() {
 
 void UITextInput::showLine(unsigned int lineNumber, bool top) {
 	if(top) {
-		scrollContainer->setScrollValue(0.0, ((((lineNumber) * ((lineHeight+lineSpacing)))) + padding)/scrollContainer->getContentSize().y);
+		scrollContainer->setScrollValue(0.0, ((((lineNumber) * ((lineHeight+lineSpacing)))) + padding)/(scrollContainer->getContentSize().y-scrollContainer->getHeight()));
 	} else {
-		scrollContainer->setScrollValue(0.0, (((((lineNumber) * ((lineHeight+lineSpacing)))) + padding-(scrollContainer->getHeight()/2.0))/scrollContainer->getContentSize().y));	
+		scrollContainer->setScrollValue(0.0, (((((lineNumber) * ((lineHeight+lineSpacing)))) + padding-(scrollContainer->getHeight()/2.0))/(scrollContainer->getContentSize().y-scrollContainer->getHeight())));	
 	}
 }