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

Complete event sent out on RETURN in UITextInput, basic console for IDE

Ivan Safrin 13 лет назад
Родитель
Сommit
79c3dd8fd0

+ 6 - 0
IDE/Build/Mac OS X/Polycode.xcodeproj/project.pbxproj

@@ -14,6 +14,7 @@
 		6D2AC99B14B8500400BB63DA /* PolycodeProjectEditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D2AC99A14B8500400BB63DA /* PolycodeProjectEditor.cpp */; };
 		6D34143412B816BC0034FA9B /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D34143312B816BC0034FA9B /* IOKit.framework */; };
 		6D3B6C5B14B820A900727F17 /* ToolWindows.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D3B6C5A14B820A900727F17 /* ToolWindows.cpp */; };
+		6D3DC79D1622043A003ED2C9 /* PolycodeConsole.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D3DC79C1622043A003ED2C9 /* PolycodeConsole.cpp */; };
 		6D56156814C5430300FC8BD4 /* PolycodeScreenEditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D56156714C5430300FC8BD4 /* PolycodeScreenEditor.cpp */; };
 		6D6D3FA614B446A600219173 /* PolycodeToolLauncher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D6D3FA514B446A600219173 /* PolycodeToolLauncher.cpp */; };
 		6D70AB2A12B29BF200EB6D94 /* NewFileWindow.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D70AB2912B29BF200EB6D94 /* NewFileWindow.cpp */; };
@@ -76,6 +77,8 @@
 		6D34143312B816BC0034FA9B /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
 		6D3B6C5A14B820A900727F17 /* ToolWindows.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ToolWindows.cpp; sourceTree = "<group>"; };
 		6D3B6C5C14B820B000727F17 /* ToolWindows.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ToolWindows.h; sourceTree = "<group>"; };
+		6D3DC79C1622043A003ED2C9 /* PolycodeConsole.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolycodeConsole.cpp; sourceTree = "<group>"; };
+		6D3DC79F16220440003ED2C9 /* PolycodeConsole.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolycodeConsole.h; sourceTree = "<group>"; };
 		6D56156514C542FB00FC8BD4 /* PolycodeScreenEditor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolycodeScreenEditor.h; sourceTree = "<group>"; };
 		6D56156714C5430300FC8BD4 /* PolycodeScreenEditor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolycodeScreenEditor.cpp; sourceTree = "<group>"; };
 		6D6D3FA514B446A600219173 /* PolycodeToolLauncher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolycodeToolLauncher.cpp; sourceTree = "<group>"; };
@@ -244,6 +247,7 @@
 		6D80E91212AB53FB0037A708 /* Include */ = {
 			isa = PBXGroup;
 			children = (
+				6D3DC79F16220440003ED2C9 /* PolycodeConsole.h */,
 				6D56156514C542FB00FC8BD4 /* PolycodeScreenEditor.h */,
 				6D2AC99D14B8500A00BB63DA /* PolycodeProjectEditor.h */,
 				6D3B6C5C14B820B000727F17 /* ToolWindows.h */,
@@ -270,6 +274,7 @@
 		6D80E91812AB53FB0037A708 /* Source */ = {
 			isa = PBXGroup;
 			children = (
+				6D3DC79C1622043A003ED2C9 /* PolycodeConsole.cpp */,
 				6D56156714C5430300FC8BD4 /* PolycodeScreenEditor.cpp */,
 				6D2AC99A14B8500400BB63DA /* PolycodeProjectEditor.cpp */,
 				6D3B6C5A14B820A900727F17 /* ToolWindows.cpp */,
@@ -394,6 +399,7 @@
 				6D3B6C5B14B820A900727F17 /* ToolWindows.cpp in Sources */,
 				6D2AC99B14B8500400BB63DA /* PolycodeProjectEditor.cpp in Sources */,
 				6D56156814C5430300FC8BD4 /* PolycodeScreenEditor.cpp in Sources */,
+				6D3DC79D1622043A003ED2C9 /* PolycodeConsole.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 51 - 0
IDE/Contents/Include/PolycodeConsole.h

@@ -0,0 +1,51 @@
+/*
+ Copyright (C) 2012 by Ivan Safrin
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ */
+ 
+#pragma once
+
+#include "PolycodeUI.h"
+#include "Polycode.h"
+
+using namespace Polycode;
+
+class PolycodeConsole : public UIElement {
+	public:
+		PolycodeConsole();
+		~PolycodeConsole();
+		
+		void _print(String msg);
+		
+		void handleEvent(Event *event);
+		
+		static void print(String msg);
+		
+		void Resize(Number width, Number height);
+		
+		static void setInstance(PolycodeConsole *newInstance);
+		
+	protected:
+		
+		static PolycodeConsole *instance;
+		
+		UITextInput *debugTextInput;
+		UITextInput *consoleTextInput;		
+};

+ 4 - 1
IDE/Contents/Include/PolycodeFrame.h

@@ -24,6 +24,7 @@
 #include "Polycode.h"
 #include "PolycodeProjectBrowser.h"
 #include "PolycodeEditor.h"
+#include "PolycodeConsole.h"
 #include "NewProjectWindow.h"
 #include "ExampleBrowserWindow.h"
 #include "NewFileWindow.h"
@@ -70,6 +71,7 @@ public:
 	PolycodeProjectBrowser *projectBrowser;
 		
 	UIImageButton *playButton;
+	UIHSizer *mainSizer;	
 			
 private:
 	
@@ -87,6 +89,8 @@ private:
 	
 	ScreenImage *welcomeImage;	
 	
+	PolycodeConsole *console;
+	
 	EditorHolder *editorHolder;
 	
 
@@ -95,7 +99,6 @@ private:
 	ScreenShape *modalBlocker;
 	UIWindow *modalChild;		
 	
-	UIHSizer *mainSizer;
 	UIVSizer *consoleSizer;
 	
 	UIButton *newProjectButton;

+ 71 - 0
IDE/Contents/Source/PolycodeConsole.cpp

@@ -0,0 +1,71 @@
+/*
+ Copyright (C) 2012 by Ivan Safrin
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+
+#include "PolycodeConsole.h"
+
+PolycodeConsole* PolycodeConsole::instance = NULL;
+
+PolycodeConsole::PolycodeConsole() : UIElement() {
+	debugTextInput = new UITextInput(true, 100, 100);
+	addChild(debugTextInput);
+
+	consoleTextInput = new UITextInput(false, 100, 100);
+	addChild(consoleTextInput);	
+	
+	consoleTextInput->addEventListener(this, Event::COMPLETE_EVENT);
+
+	PolycodeConsole::setInstance(this);
+}
+
+PolycodeConsole::~PolycodeConsole() {
+
+}
+
+void PolycodeConsole::handleEvent(Event *event) {
+	if(event->getDispatcher() == consoleTextInput) {
+		if(event->getEventCode() == Event::COMPLETE_EVENT) {
+			_print(">"+consoleTextInput->getText());
+			_print("\n");
+			consoleTextInput->setText("");
+		}
+	}
+}
+
+void PolycodeConsole::setInstance(PolycodeConsole *newInstance) {
+	instance = newInstance;
+}
+
+void PolycodeConsole::print(String msg) {
+	instance->_print(msg);
+}
+
+void PolycodeConsole::_print(String msg) {
+	debugTextInput->setText(debugTextInput->getText()+msg);
+}
+
+void PolycodeConsole::Resize(Number width, Number height) {
+	debugTextInput->Resize(width, height-25);
+	debugTextInput->setPosition(0, 0);
+
+	consoleTextInput->Resize(width, 25);
+	consoleTextInput->setPosition(0, height-25);
+}

+ 2 - 3
IDE/Contents/Source/PolycodeFrame.cpp

@@ -72,9 +72,8 @@ PolycodeFrame::PolycodeFrame() : ScreenEntity() {
 	editorHolder = new EditorHolder();
 	consoleSizer->addTopChild(editorHolder);
 	
-	// REPLACE WITH CONSOLE CLASS
-	UITextInput *textInput = new UITextInput(true, 100, 100);
-	consoleSizer->addBottomChild(textInput);	
+	console = new PolycodeConsole();	
+	consoleSizer->addBottomChild(console);	
 	
 	
 	projectBrowser->treeContainer->getRootNode()->addEventListener(this, UITreeEvent::DRAG_START_EVENT);

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

@@ -340,9 +340,11 @@ bool PolycodeIDEApp::Update() {
 	if(projectManager->getProjectCount() > 0) {
 		frame->welcomeEntity->enabled =  false;
 		frame->projectBrowser->enabled =  true;		
+		frame->mainSizer->enabled = true;
 	} else {
 		frame->welcomeEntity->enabled =  true;
 		frame->projectBrowser->enabled =  false;			
+		frame->mainSizer->enabled = false;		
 	}
 
 	return core->Update();

+ 9 - 3
Modules/Contents/UI/Source/PolyUITextInput.cpp

@@ -351,6 +351,9 @@ void UITextInput::setText(String text) {
 		clearSelection();				
 		updateCaretPosition();		
 	} else {
+		selectAll();
+		insertText(text);
+		clearSelection();
 	}
 		
 //	this->text = text;
@@ -731,11 +734,14 @@ void UITextInput::onKeyDown(PolyKEY key, wchar_t charCode) {
 	
 	
 	if(key == KEY_RETURN) {
-		if(hasSelection)
-			deleteSelection();		
-		if(multiLine) {
+		if(multiLine) {	
+			if(hasSelection) {
+				deleteSelection();		
+			}			
 			insertLine(true);
 			updateCaretPosition();
+		} else {
+			dispatchEvent(new Event(), Event::COMPLETE_EVENT);
 		}
 		return;
 	}