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

Started work on fix for #238

Added a new container element that will only hold the actual lines, so that we can use scissors on that.
cib 12 лет назад
Родитель
Сommit
17c51168dd

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

@@ -31,7 +31,7 @@ PolycodeClipboard *globalClipboard;
 
 
 
 
 PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
-	core = new POLYCODE_CORE(view, 900,700,false,true, 0, 0,30, -1);	
+	core = new POLYCODE_CORE(view, 1100, 700,false,true, 0, 0,30, -1);	
 //	core->pauseOnLoseFocus = true;
 //	core->pauseOnLoseFocus = true;
 	
 	
 	CoreServices::getInstance()->getResourceManager()->reloadResourcesOnModify = true;
 	CoreServices::getInstance()->getResourceManager()->reloadResourcesOnModify = true;

+ 1 - 0
Modules/Contents/UI/Include/PolyUIElement.h

@@ -33,6 +33,7 @@ namespace Polycode {
 	class _PolyExport UIElement : public ScreenEntity {
 	class _PolyExport UIElement : public ScreenEntity {
 		public:
 		public:
 			UIElement();
 			UIElement();
+			UIElement(Number width, Number height);
 			~UIElement();
 			~UIElement();
 			
 			
 			virtual void Resize(Number width, Number height);
 			virtual void Resize(Number width, Number height);

+ 4 - 1
Modules/Contents/UI/Include/PolyUITextInput.h

@@ -383,6 +383,9 @@ namespace Polycode {
 			UITextInputSyntaxHighlighter *syntaxHighliter;
 			UITextInputSyntaxHighlighter *syntaxHighliter;
 		
 		
 			ScreenEntity *linesContainer;
 			ScreenEntity *linesContainer;
+
+			// container for the actual text contents
+			UIElement *textContainer; 
 			
 			
 			vector<ScreenLabel*> linesToDelete;	
 			vector<ScreenLabel*> linesToDelete;	
 			
 			
@@ -429,4 +432,4 @@ namespace Polycode {
 			int indentSpacing;
 			int indentSpacing;
 			
 			
 	};
 	};
-}
+}

+ 7 - 1
Modules/Contents/UI/Source/PolyUIElement.cpp

@@ -29,6 +29,12 @@ UIElement::UIElement() : ScreenEntity() {
 	processInputEvents = true;
 	processInputEvents = true;
 }
 }
 
 
+UIElement::UIElement(Number width, Number height) : ScreenEntity() {
+	setPositionMode(ScreenEntity::POSITION_TOPLEFT);
+	processInputEvents = true;
+	this->width = width; this->height = height;
+}
+
 UIElement::~UIElement() {
 UIElement::~UIElement() {
 
 
 }
 }
@@ -36,4 +42,4 @@ UIElement::~UIElement() {
 void UIElement::Resize(Number width, Number height) {
 void UIElement::Resize(Number width, Number height) {
 	setWidth(width);
 	setWidth(width);
 	setHeight(height);
 	setHeight(height);
-}
+}

+ 21 - 14
Modules/Contents/UI/Source/PolyUITextInput.cpp

@@ -30,7 +30,7 @@
 
 
 using namespace Polycode;
 using namespace Polycode;
 
 
-UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElement() {
+UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElement(width, height) {
 	this->multiLine = multiLine;
 	this->multiLine = multiLine;
 	processInputEvents = true;
 	processInputEvents = true;
 	isNumberOnly = false;
 	isNumberOnly = false;
@@ -74,7 +74,7 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElemen
 	if(!multiLine) {
 	if(!multiLine) {
 		rectHeight = fontSize+12;
 		rectHeight = fontSize+12;
 	} 
 	} 
-	
+
 	linesContainer = new ScreenEntity();	
 	linesContainer = new ScreenEntity();	
 	linesContainer->processInputEvents = true;
 	linesContainer->processInputEvents = true;
 	linesContainer->ownsChildren = true;
 	linesContainer->ownsChildren = true;
@@ -86,8 +86,13 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElemen
 	sl = conf->getNumericValue("Polycode", "textBgSkinL");
 	sl = conf->getNumericValue("Polycode", "textBgSkinL");
 
 
 	
 	
-	padding = conf->getNumericValue("Polycode", "textBgSkinPadding");	
+	padding = conf->getNumericValue("Polycode", "textBgSkinPadding");
 	
 	
+	textContainer = new UIElement();
+	textContainer->ownsChildren = true;
+	textContainer->enableScissor = true;
+
+	linesContainer->addChild(textContainer);	
 	if(multiLine) {
 	if(multiLine) {
 		inputRect = new UIBox(conf->getStringValue("Polycode", "textBgSkinMultiline"),
 		inputRect = new UIBox(conf->getStringValue("Polycode", "textBgSkinMultiline"),
 						  st,sr,sb,sl,
 						  st,sr,sb,sl,
@@ -116,6 +121,10 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElemen
 		decoratorOffset = sl/2.0;
 		decoratorOffset = sl/2.0;
 	}
 	}
 
 
+	textContainer->setWidth(this->getWidth() - textContainer->getPosition2D().x - padding);
+	textContainer->setHeight(this->getHeight() - textContainer->getPosition2D().y - padding);
+	textContainer->setPosition(padding + decoratorOffset, padding);
+	textContainer->scissorBox.setRect(textContainer->getScreenPosition().x, textContainer->getScreenPosition().y, 100, 100);
 	
 	
 	inputRect->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
 	inputRect->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
 	inputRect->addEventListener(this, InputEvent::EVENT_MOUSEUP);	
 	inputRect->addEventListener(this, InputEvent::EVENT_MOUSEUP);	
@@ -171,7 +180,6 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElemen
 		addChild(scrollContainer);
 		addChild(scrollContainer);
 	} else {
 	} else {
 		addChild(linesContainer);
 		addChild(linesContainer);
-		enableScissor = true;
 	}
 	}
 		
 		
 	undoStateIndex = 0;
 	undoStateIndex = 0;
@@ -194,7 +202,6 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElemen
 	core->addEventListener(this, Core::EVENT_UNDO);
 	core->addEventListener(this, Core::EVENT_UNDO);
 	core->addEventListener(this, Core::EVENT_REDO);
 	core->addEventListener(this, Core::EVENT_REDO);
 	core->addEventListener(this, Core::EVENT_SELECT_ALL);
 	core->addEventListener(this, Core::EVENT_SELECT_ALL);
-	
 	indentSpacing = 4;
 	indentSpacing = 4;
 	indentType = INDENT_TAB;
 	indentType = INDENT_TAB;
 }
 }
@@ -224,7 +231,7 @@ void UITextInput::checkBufferLines() {
 		ScreenLabel *newLine = new ScreenLabel(L"", fontSize, fontName, aaMode);
 		ScreenLabel *newLine = new ScreenLabel(L"", fontSize, fontName, aaMode);
 		newLine->color = textColor;
 		newLine->color = textColor;
 		lineHeight = newLine->getHeight();
 		lineHeight = newLine->getHeight();
-		linesContainer->addChild(newLine);
+		textContainer->addChild(newLine);
 		bufferLines.push_back(newLine);
 		bufferLines.push_back(newLine);
 	}
 	}
 	
 	
@@ -568,12 +575,17 @@ void UITextInput::renumberLines() {
 	}
 	}
 	
 	
 	lineNumberAnchor->setPositionX(padding+decoratorOffset - 10);
 	lineNumberAnchor->setPositionX(padding+decoratorOffset - 10);
+
+	// Update the position and width of the text accordingly.
+	textContainer->setPosition(decoratorOffset + padding, padding);
+	textContainer->setWidth(this->getWidth() - textContainer->getPosition2D().x - padding);
+	textContainer->scissorBox.setRect(textContainer->getPosition2D().x, textContainer->getPosition2D().y, textContainer->getWidth(), textContainer->getHeight());
 }
 }
 
 
 void UITextInput::restructLines() {
 void UITextInput::restructLines() {
 
 
 	for(int i=0; i < bufferLines.size(); i++) {
 	for(int i=0; i < bufferLines.size(); i++) {
-		bufferLines[i]->setPosition(decoratorOffset + padding,padding + (i*(lineHeight+lineSpacing)),0.0f);
+		bufferLines[i]->setPosition(0, (i*(lineHeight+lineSpacing)),0.0f);
 	}
 	}
 	
 	
 	if(multiLine && lineNumbersEnabled) {
 	if(multiLine && lineNumbersEnabled) {
@@ -1402,11 +1414,6 @@ void UITextInput::onKeyDown(PolyKEY key, wchar_t charCode) {
 
 
 void UITextInput::Update() {
 void UITextInput::Update() {
 
 
-	if(!multiLine) {
-		Vector2 pos = getScreenPosition();
-		scissorBox.setRect(pos.x,pos.y, width+sr+sl, height+sb+st);
-	}
-
 	if(hasSelection) {
 	if(hasSelection) {
 		blinkerRect->visible = false;
 		blinkerRect->visible = false;
 	}
 	}
@@ -1458,7 +1465,7 @@ void UITextInput::readjustBuffer() {
 		} else {
 		} else {
 			bufferLines[i]->setText("");
 			bufferLines[i]->setText("");
 		}
 		}
-		bufferLines[i]->setPosition(decoratorOffset + padding,padding + bufferLineOffset + (i*(lineHeight+lineSpacing)),0.0f);	
+		bufferLines[i]->setPosition(0, (i*(lineHeight+lineSpacing)),0.0f);	
 	}
 	}
 	
 	
 	for(int i=0; i < numberLines.size(); i++) {
 	for(int i=0; i < numberLines.size(); i++) {
@@ -1618,4 +1625,4 @@ void UITextInput::convertIndentToTabs() {
 		
 		
 		//TODO
 		//TODO
 	}
 	}
-}
+}