Просмотр исходного кода

Added word wrap support to UITextInput. UITextInput now scrolls with mouse selection. Fixed find functionality in the IDE text editor. UITextInput selection now updates on resize. Fixed various minor bugs in UITextInput.

Ivan Safrin 12 лет назад
Родитель
Сommit
2d769810e5

+ 4 - 1
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -1054,6 +1054,8 @@ PolycodeIDEApp::~PolycodeIDEApp() {
 
 
 bool PolycodeIDEApp::Update() {
 bool PolycodeIDEApp::Update() {
 
 
+	bool retVal = core->Update();
+
 	if(willRunProject) {
 	if(willRunProject) {
 		willRunProject = false;
 		willRunProject = false;
 		runProject();
 		runProject();
@@ -1100,6 +1102,7 @@ bool PolycodeIDEApp::Update() {
 	}
 	}
 
 
 
 
-	return core->updateAndRender();
+	core->Render();
+	return retVal;
 }
 }
 
 

+ 2 - 0
IDE/Contents/Source/PolycodeTextEditor.cpp

@@ -490,6 +490,7 @@ void PolycodeTextEditor::handleEvent(Event *event) {
 
 
 	if(event->getDispatcher() == textInput && event->getEventType() == "UIEvent") {
 	if(event->getDispatcher() == textInput && event->getEventType() == "UIEvent") {
 		if(!isLoading) {
 		if(!isLoading) {
+			lastFindString = "";
 			setHasChanges(true);
 			setHasChanges(true);
 		}
 		}
 	}
 	}
@@ -549,6 +550,7 @@ void PolycodeTextEditor::showFindBar() {
 	findBar->visible = true;
 	findBar->visible = true;
 	findBar->focusChild(findBar->findInput);
 	findBar->focusChild(findBar->findInput);
 	findBar->findInput->selectAll();
 	findBar->findInput->selectAll();
+	lastFindString = "";
 	Resize(editorSize.x, editorSize.y);
 	Resize(editorSize.x, editorSize.y);
 }
 }
 
 

+ 59 - 11
Modules/Contents/UI/Include/PolyUITextInput.h

@@ -62,21 +62,23 @@ namespace Polycode {
 	
 	
 	class _PolyExport LineColorData {
 	class _PolyExport LineColorData {
 		public:
 		public:
+			LineColorData() {}
 			LineColorData(Color color, unsigned int rangeStart, unsigned int rangeEnd) {
 			LineColorData(Color color, unsigned int rangeStart, unsigned int rangeEnd) {
 				this->color = color;
 				this->color = color;
 				this->rangeStart = rangeStart;
 				this->rangeStart = rangeStart;
 				this->rangeEnd = rangeEnd;
 				this->rangeEnd = rangeEnd;
 			}
 			}
 			Color color;
 			Color color;
-			unsigned int rangeStart;
-			unsigned int rangeEnd;
+			int rangeStart;
+			int rangeEnd;
 	};
 	};
 	
 	
 	class _PolyExport LineColorInfo {
 	class _PolyExport LineColorInfo {
 		public:
 		public:
-			std::vector<LineColorData> colors;			
+			std::vector<LineColorData> colors;
+			LineColorInfo getColorInfoForRange(int start, int length);
 	};
 	};
-	
+		
 	class _PolyExport UITextInputSyntaxHighlighter {
 	class _PolyExport UITextInputSyntaxHighlighter {
 		public:		
 		public:		
 			virtual std::vector<SyntaxHighlightToken> parseText(String text) = 0;
 			virtual std::vector<SyntaxHighlightToken> parseText(String text) = 0;
@@ -88,6 +90,20 @@ namespace Polycode {
 			unsigned int caretStart;
 			unsigned int caretStart;
 			unsigned int caretEnd;							
 			unsigned int caretEnd;							
 	};
 	};
+	
+	class WordWrapLine {
+		public:
+			String text;
+			bool isWordWrap;
+			int actualLineNumber;
+			int lineStart;
+	};
+	
+	class TextColorPair {
+		public:
+			LineColorInfo colorInfo;
+			String text;
+	};
 
 
 	/**
 	/**
 	 * A text input element. Can be single- or multiline.
 	 * A text input element. Can be single- or multiline.
@@ -150,7 +166,7 @@ namespace Polycode {
 			void clearSelection();
 			void clearSelection();
 
 
 			/**
 			/**
-			 * Set the current selection.
+			 * Set the currentselection.
 			 *
 			 *
 			 * If (lineStart, colStart) is further "right" or "down" than (lineEnd, colEnd),
 			 * If (lineStart, colStart) is further "right" or "down" than (lineEnd, colEnd),
 			 * the two will automatically be swapped. It's thus enough to specify the two "edges"
 			 * the two will automatically be swapped. It's thus enough to specify the two "edges"
@@ -322,9 +338,13 @@ namespace Polycode {
 		protected:
 		protected:
 		
 		
 			void readjustBuffer();
 			void readjustBuffer();
+			void updateWordWrap();
+			
+			Number resizeTimer;
+			void doMultilineResize();
 
 
 			std::vector<LineColorInfo> lineColors;
 			std::vector<LineColorInfo> lineColors;
-					
+			std::vector<LineColorInfo> wordWrapColors;					
 			ScreenEntity *lineNumberAnchor;
 			ScreenEntity *lineNumberAnchor;
 		
 		
 			void renumberLines();
 			void renumberLines();
@@ -338,20 +358,33 @@ namespace Polycode {
 			void saveUndoState();
 			void saveUndoState();
 		
 		
 			bool isNumberOnly;
 			bool isNumberOnly;
-		
+			
+			void setActualToCaret();
+			void setOffsetToActual();
+			
+			void convertOffsetToActual(int lineOffset, int caretPosition, int *actualCaretPosition);
+			
+			void convertActualToOffset(int actualLineOffset, int actualCaretPosition, int *lineOffset, int *caretPosition);
+					
 			int caretSkipWordBack(int caretLine, int caretPosition);
 			int caretSkipWordBack(int caretLine, int caretPosition);
 			int caretSkipWordForward(int caretLine, int caretPosition);
 			int caretSkipWordForward(int caretLine, int caretPosition);
 		
 		
-			void selectLineFromOffset();
+			int lineOffsetToActualLineOffset(int lineOffset);
+			void setActualLineOffset();
 			void updateCaretPosition();
 			void updateCaretPosition();
 			void setCaretToMouse(Number x, Number y);
 			void setCaretToMouse(Number x, Number y);
-			void dragSelectionTo(Number x, Number y);		
+			void dragSelectionTo(Number x, Number y);
+			
+			void updateSelectionRects();
 		
 		
 			void selectWordAtCaret();
 			void selectWordAtCaret();
 		
 		
 			void restructLines();
 			void restructLines();
 			void removeLines(unsigned int startIndex, unsigned int endIndex);
 			void removeLines(unsigned int startIndex, unsigned int endIndex);
-		
+			
+			std::vector<TextColorPair> makeWordWrapBuffer(int wrapLineOffset, String indentPrefix);
+			std::vector<TextColorPair> splitTokens(String stringToSplit, LineColorInfo *stringColorInfo);
+			
 			ScreenShape *selectorRectTop;
 			ScreenShape *selectorRectTop;
 			ScreenShape *selectorRectMiddle;
 			ScreenShape *selectorRectMiddle;
 			ScreenShape *selectorRectBottom;		
 			ScreenShape *selectorRectBottom;		
@@ -391,6 +424,8 @@ namespace Polycode {
 			Number caretX,caretY;
 			Number caretX,caretY;
 		
 		
 			int caretPosition;
 			int caretPosition;
+			int actualCaretPosition;
+			
 			bool doSelectToCaret;
 			bool doSelectToCaret;
 			
 			
 			UITextInputSyntaxHighlighter *syntaxHighliter;
 			UITextInputSyntaxHighlighter *syntaxHighliter;
@@ -415,16 +450,23 @@ namespace Polycode {
 			UIBox *inputRect;
 			UIBox *inputRect;
 			ScreenShape *blinkerRect;
 			ScreenShape *blinkerRect;
 			
 			
+			Color selectionColor;
+			void _setSelectionColor(Color color);
+			
 			Number st;
 			Number st;
 			Number sr;
 			Number sr;
 			Number sb;
 			Number sb;
 			Number sl;
 			Number sl;
+			
+			Vector2 selectionDragMouse;
 		
 		
 			Number caretImagePosition;
 			Number caretImagePosition;
 			
 			
 			int currentBufferLines;
 			int currentBufferLines;
 			int neededBufferLines;
 			int neededBufferLines;
 			
 			
+			int
+			
 			UIScrollContainer *scrollContainer;
 			UIScrollContainer *scrollContainer;
 		
 		
 			String fontName;
 			String fontName;
@@ -433,13 +475,19 @@ namespace Polycode {
 			Number lineHeight;
 			Number lineHeight;
 		
 		
 			int lineOffset;
 			int lineOffset;
+			int actualLineOffset;
 			
 			
 			vector<String> lines;
 			vector<String> lines;
-						
+			vector<WordWrapLine> wordWrapLines;
+									
 			vector<ScreenLabel*> bufferLines;
 			vector<ScreenLabel*> bufferLines;
 			vector<ScreenLabel*> numberLines;
 			vector<ScreenLabel*> numberLines;
 			
 			
 			Core *core;
 			Core *core;
+			
+			Number _newWidth;
+			Number _newHeight;
+			bool didMultilineResize;
         
         
 			enum indentTypes { INDENT_SPACE, INDENT_TAB } indentType;
 			enum indentTypes { INDENT_SPACE, INDENT_TAB } indentType;
 			int indentSpacing;
 			int indentSpacing;

Разница между файлами не показана из-за своего большого размера
+ 377 - 161
Modules/Contents/UI/Source/PolyUITextInput.cpp


Некоторые файлы не были показаны из-за большого количества измененных файлов