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

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 retVal = core->Update();
+
 	if(willRunProject) {
 		willRunProject = false;
 		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(!isLoading) {
+			lastFindString = "";
 			setHasChanges(true);
 		}
 	}
@@ -549,6 +550,7 @@ void PolycodeTextEditor::showFindBar() {
 	findBar->visible = true;
 	findBar->focusChild(findBar->findInput);
 	findBar->findInput->selectAll();
+	lastFindString = "";
 	Resize(editorSize.x, editorSize.y);
 }
 

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

@@ -62,21 +62,23 @@ namespace Polycode {
 	
 	class _PolyExport LineColorData {
 		public:
+			LineColorData() {}
 			LineColorData(Color color, unsigned int rangeStart, unsigned int rangeEnd) {
 				this->color = color;
 				this->rangeStart = rangeStart;
 				this->rangeEnd = rangeEnd;
 			}
 			Color color;
-			unsigned int rangeStart;
-			unsigned int rangeEnd;
+			int rangeStart;
+			int rangeEnd;
 	};
 	
 	class _PolyExport LineColorInfo {
 		public:
-			std::vector<LineColorData> colors;			
+			std::vector<LineColorData> colors;
+			LineColorInfo getColorInfoForRange(int start, int length);
 	};
-	
+		
 	class _PolyExport UITextInputSyntaxHighlighter {
 		public:		
 			virtual std::vector<SyntaxHighlightToken> parseText(String text) = 0;
@@ -88,6 +90,20 @@ namespace Polycode {
 			unsigned int caretStart;
 			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.
@@ -150,7 +166,7 @@ namespace Polycode {
 			void clearSelection();
 
 			/**
-			 * Set the current selection.
+			 * Set the currentselection.
 			 *
 			 * 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"
@@ -322,9 +338,13 @@ namespace Polycode {
 		protected:
 		
 			void readjustBuffer();
+			void updateWordWrap();
+			
+			Number resizeTimer;
+			void doMultilineResize();
 
 			std::vector<LineColorInfo> lineColors;
-					
+			std::vector<LineColorInfo> wordWrapColors;					
 			ScreenEntity *lineNumberAnchor;
 		
 			void renumberLines();
@@ -338,20 +358,33 @@ namespace Polycode {
 			void saveUndoState();
 		
 			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 caretSkipWordForward(int caretLine, int caretPosition);
 		
-			void selectLineFromOffset();
+			int lineOffsetToActualLineOffset(int lineOffset);
+			void setActualLineOffset();
 			void updateCaretPosition();
 			void setCaretToMouse(Number x, Number y);
-			void dragSelectionTo(Number x, Number y);		
+			void dragSelectionTo(Number x, Number y);
+			
+			void updateSelectionRects();
 		
 			void selectWordAtCaret();
 		
 			void restructLines();
 			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 *selectorRectMiddle;
 			ScreenShape *selectorRectBottom;		
@@ -391,6 +424,8 @@ namespace Polycode {
 			Number caretX,caretY;
 		
 			int caretPosition;
+			int actualCaretPosition;
+			
 			bool doSelectToCaret;
 			
 			UITextInputSyntaxHighlighter *syntaxHighliter;
@@ -415,16 +450,23 @@ namespace Polycode {
 			UIBox *inputRect;
 			ScreenShape *blinkerRect;
 			
+			Color selectionColor;
+			void _setSelectionColor(Color color);
+			
 			Number st;
 			Number sr;
 			Number sb;
 			Number sl;
+			
+			Vector2 selectionDragMouse;
 		
 			Number caretImagePosition;
 			
 			int currentBufferLines;
 			int neededBufferLines;
 			
+			int
+			
 			UIScrollContainer *scrollContainer;
 		
 			String fontName;
@@ -433,13 +475,19 @@ namespace Polycode {
 			Number lineHeight;
 		
 			int lineOffset;
+			int actualLineOffset;
 			
 			vector<String> lines;
-						
+			vector<WordWrapLine> wordWrapLines;
+									
 			vector<ScreenLabel*> bufferLines;
 			vector<ScreenLabel*> numberLines;
 			
 			Core *core;
+			
+			Number _newWidth;
+			Number _newHeight;
+			bool didMultilineResize;
         
 			enum indentTypes { INDENT_SPACE, INDENT_TAB } indentType;
 			int indentSpacing;

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


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