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

Scrolling setters for scrollbars and scroll container, execute command for Core, app launcher for Cocoa core, misc IDE changes

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

+ 4 - 0
Core/Contents/Include/PolyCocoaCore.h

@@ -116,6 +116,10 @@ namespace Polycode {
 		String openFolderPicker();
 		vector<String> openFilePicker(vector<CoreFileExtension> extensions, bool allowMultiple);
 		
+		String executeExternalCommand(String command);
+		
+		void launchApplicationWithFile(String application, String file);
+		
 		void setCursor(int cursorType);
 		void warpCursor(int x, int y);
 		

+ 2 - 0
Core/Contents/Include/PolyCore.h

@@ -310,6 +310,8 @@ namespace Polycode {
 		static const int EVENT_LOST_FOCUS = 1;
 		static const int EVENT_GAINED_FOCUS = 2;
 		
+		virtual String executeExternalCommand(String command) = 0;
+		
 		/**
 		* Returns the default working path of the application.
 		*/

+ 30 - 0
Core/Contents/Source/PolyCocoaCore.mm

@@ -248,6 +248,36 @@ void CocoaCore::setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, in
 	*/
 }
 
+void CocoaCore::launchApplicationWithFile(String application, String file) {
+	NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
+	NSURL *url = [NSURL fileURLWithPath: [NSString stringWithCString:application.c_str()]];
+
+	NSError *error = nil;
+	NSArray *arguments = [NSArray arrayWithObjects: [NSString stringWithCString:file.c_str()], nil];
+	[workspace launchApplicationAtURL:url options:0 configuration:[NSDictionary dictionaryWithObject:arguments forKey:NSWorkspaceLaunchConfigurationArguments] error:&error];
+//Handle error
+}
+
+String CocoaCore::executeExternalCommand(String command) {
+	FILE *fp = popen(command.c_str(), "r");
+	if(!fp) {
+		return "Unable to execute command";
+	}	
+	
+	int fd = fileno(fp);
+	
+	char path[1024];
+	String retString;
+	
+	while (fgets(path, sizeof(path), fp) != NULL) {
+		retString = retString + String(path);
+	}
+
+	fclose(fp);
+	pclose(fp);
+	return retString;
+}
+
 void CocoaCore::resizeTo(int xRes, int yRes) {
 	this->xRes = xRes;
 	this->yRes = yRes;

+ 3 - 0
Core/Contents/Source/PolyCore.cpp

@@ -70,6 +70,9 @@ namespace Polycode {
 		
 		this->monitorIndex = monitorIndex;
 		
+		if(frameRate == 0)
+			frameRate = 60;
+		
 		refreshInterval = 1000 / frameRate;		
 		threadedEventMutex = NULL;
 	}

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

@@ -81,7 +81,7 @@
 		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>"; };
+		6D6D3FA514B446A600219173 /* PolycodeToolLauncher.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp.preprocessed; fileEncoding = 4; path = PolycodeToolLauncher.cpp; sourceTree = "<group>"; };
 		6D6D3FA814B446AF00219173 /* PolycodeToolLauncher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolycodeToolLauncher.h; sourceTree = "<group>"; };
 		6D70AB2812B29BEC00EB6D94 /* NewFileWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NewFileWindow.h; sourceTree = "<group>"; };
 		6D70AB2912B29BF200EB6D94 /* NewFileWindow.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFileWindow.cpp; sourceTree = "<group>"; };

+ 10 - 1
IDE/Contents/Include/PolycodeToolLauncher.h

@@ -23,13 +23,22 @@
 #pragma once
 
 #include "PolycodeProject.h"
+#include "PolycodeConsole.h"
+
+class PolycodeRunner : public Threaded {
+	public:
+		PolycodeRunner(String polyappPath);
+		
+		void runThread();
+		
+		String polyappPath;
+};
 
 class PolycodeToolLauncher {
 	public: 
 		PolycodeToolLauncher();
 		~PolycodeToolLauncher();		
 		
-		static void execLocalBinCommand(String command);		
 		static String generateTempPath();
 		static void buildProject(PolycodeProject *project, String destinationPath);
 

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

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

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

@@ -162,12 +162,13 @@ void PolycodeIDEApp::runProject() {
 		String outPath = PolycodeToolLauncher::generateTempPath() + ".polyapp";
 		PolycodeToolLauncher::buildProject(projectManager->getActiveProject(), outPath);
 		PolycodeToolLauncher::runPolyapp(outPath);
-		core->removeDiskItem(outPath);
 	}
 }
 
 void PolycodeIDEApp::saveFile() {
-	editorManager->getCurrentEditor()->saveFile();
+	if(editorManager->getCurrentEditor()) {
+		editorManager->getCurrentEditor()->saveFile();
+	}
 }
 
 void PolycodeIDEApp::handleEvent(Event *event) {

+ 1 - 0
IDE/Contents/Source/PolycodeProjectBrowser.cpp

@@ -27,6 +27,7 @@ PolycodeProjectBrowser::PolycodeProjectBrowser() : UIElement() {
 	treeContainer->getRootNode()->toggleCollapsed();
 	treeContainer->getRootNode()->addEventListener(this, UITreeEvent::SELECTED_EVENT);
 	treeContainer->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
+	treeContainer->processInputEvents = true;
 	
 	BrowserUserData *data = new BrowserUserData();
 	data->type = 0;

+ 9 - 1
IDE/Contents/Source/PolycodeProjectEditor.cpp

@@ -250,9 +250,17 @@ void PolycodeProjectEditor::saveFile() {
 	(*color)["blue"]->NumberVal = bgColorBox->getSelectedColor().b;
 
 
-	configFile.root["modules"]->Clear();
+	if(configFile.root["modules"]) {
+		configFile.root["modules"]->Clear();
+	}
+	
 	for(int j=0; j < moduleCheckboxes.size(); j++) {
 		if(moduleCheckboxes[j]->isChecked()) {
+			
+			if(!configFile.root["modules"]) {
+				configFile.root.addChild("modules");	
+			}
+		
 			configFile.root["modules"]->addChild("module", moduleCheckboxes[j]->getCaptionLabel());
 		}
 	}

+ 34 - 9
IDE/Contents/Source/PolycodeToolLauncher.cpp

@@ -20,20 +20,32 @@
  THE SOFTWARE.
  */
  
-#pragma once
-
 #include "PolycodeToolLauncher.h"
 
-PolycodeToolLauncher::PolycodeToolLauncher() {
+#if defined(__APPLE__) && defined(__MACH__)
+	#include "PolyCocoaCore.h"
+#endif
 
+PolycodeRunner::PolycodeRunner(String polyappPath) : Threaded() {
+	this->polyappPath = polyappPath;
 }
 
-PolycodeToolLauncher::~PolycodeToolLauncher() {
+void PolycodeRunner::runThread() {
+	String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
 
+	String command = "cd "+polycodeBasePath+"/Standalone/Player/PolycodePlayer.app/Contents/Resources && ../MacOS/PolycodePlayer "+polyappPath;
+		;		
+
+	String ret = CoreServices::getInstance()->getCore()->executeExternalCommand(command);
+		core->removeDiskItem(polyappPath);	
 }
 
-void PolycodeToolLauncher::execLocalBinCommand(String command) {
-	system(command.c_str());
+PolycodeToolLauncher::PolycodeToolLauncher() {
+
+}
+
+PolycodeToolLauncher::~PolycodeToolLauncher() {
+
 }
 
 String PolycodeToolLauncher::generateTempPath() {
@@ -46,12 +58,25 @@ void PolycodeToolLauncher::buildProject(PolycodeProject *project, String destina
 	
 	String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
 	
-	execLocalBinCommand("cd "+projectBasePath+" && "+polycodeBasePath+"/Standalone/Bin/polybuild  --config="+projectPath+" --out="+destinationPath);
+	String command = "cd "+projectBasePath+" && "+polycodeBasePath+"/Standalone/Bin/polybuild  --config="+projectPath+" --out="+destinationPath;	
+	String ret = CoreServices::getInstance()->getCore()->executeExternalCommand(command);
+	PolycodeConsole::print(ret);	
 
 }
 
-void PolycodeToolLauncher::runPolyapp(String polyappPath) {
+void PolycodeToolLauncher::runPolyapp(String polyappPath) {		
+//	PolycodeRunner *runner = new PolycodeRunner(polyappPath);
+//	CoreServices::getInstance()->getCore()->createThread(runner);
+
+#if defined(__APPLE__) && defined(__MACH__)
+	CocoaCore *cocoaCore = (CocoaCore*) CoreServices::getInstance()->getCore();
+
 	String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
+	String command = polycodeBasePath+"/Standalone/Player/PolycodePlayer.app";
+	
+	cocoaCore->launchApplicationWithFile(command, polyappPath);
+#else
+
+#endif
 
-	execLocalBinCommand("cd "+polycodeBasePath+"/Standalone/Player/PolycodePlayer.app/Contents/Resources && ../MacOS/PolycodePlayer "+polyappPath);	
 }

+ 2 - 0
Modules/Contents/UI/Include/PolyUIHScrollBar.h

@@ -35,6 +35,8 @@ namespace Polycode {
 		Number getScrollValue();
 		void handleEvent(Event *event);
 		
+		void scrollTo(Number scrollValue);
+		
 		Number minHandleSize;
 		
 		void setHandleRatio(Number newRatio);

+ 2 - 0
Modules/Contents/UI/Include/PolyUIScrollContainer.h

@@ -37,6 +37,8 @@ namespace Polycode {
 		
 		void Resize(Number width, Number height);
 		
+		void setScrollValue(Number xScroll, Number yScroll);
+		
 		void Update();
 		
 		void onMouseWheelDown(Number x, Number y);

+ 2 - 0
Modules/Contents/UI/Include/PolyUITextInput.h

@@ -69,6 +69,8 @@ namespace Polycode {
 		
 			String getSelectionText();
 			void insertText(String text);
+			
+			UIScrollContainer *getScrollContainer();
 		
 		protected:
 		

+ 2 - 0
Modules/Contents/UI/Include/PolyUIVScrollBar.h

@@ -37,6 +37,8 @@ namespace Polycode {
 		
 		void Resize(int newHeight);
 		
+		void scrollTo(Number scrollValue);
+		
 		void onMouseWheelDown(Number x, Number y);
 		void onMouseWheelUp(Number x, Number y);
 		

+ 4 - 0
Modules/Contents/UI/Source/PolyUIHScrollBar.cpp

@@ -112,6 +112,10 @@ Number UIHScrollBar::getScrollValue() {
 	return scrollValue;
 }
 
+void UIHScrollBar::scrollTo(Number scrollValue) {
+	handleBox->setPositionX((scrollValue * dragRectWidth) + padding);	
+}
+
 void UIHScrollBar::handleEvent(Event *event) {
 	if(event->getDispatcher() == bgBox) {
 		InputEvent *inputEvent = (InputEvent*)event;

+ 7 - 0
Modules/Contents/UI/Source/PolyUIScrollContainer.cpp

@@ -70,6 +70,8 @@ UIScrollContainer::UIScrollContainer(ScreenEntity *scrolledEntity, bool hScroll,
 			
 	setContentSize(scrollChild->getWidth()*scrollChild->getScale().x, scrollChild->getHeight()*scrollChild->getScale().y);
 	Resize(width, height);	
+	
+	processInputEvents = true;
 }
 
 void UIScrollContainer::Resize(Number width, Number height) {
@@ -122,6 +124,11 @@ void UIScrollContainer::setContentSize(Number newContentWidth, Number newContent
 	}	
 }
 
+void UIScrollContainer::setScrollValue(Number xScroll, Number yScroll) {
+	hScrollBar->scrollTo(xScroll);
+	vScrollBar->scrollTo(yScroll);	
+}
+
 void UIScrollContainer::Update() {
 	Vector2 pos = getScreenPosition();
 	scrollChild->scissorBox.setRect(pos.x,pos.y, width, height);	

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

@@ -592,6 +592,10 @@ String UITextInput::getSelectionText() {
 	return totalText;
 }
 
+UIScrollContainer *UITextInput::getScrollContainer() {
+	return scrollContainer;
+}
+
 void UITextInput::onKeyDown(PolyKEY key, wchar_t charCode) {
 	
 	if(!hasFocus)

+ 4 - 0
Modules/Contents/UI/Source/PolyUIVScrollBar.cpp

@@ -105,6 +105,10 @@ void UIVScrollBar::Update() {
 	}
 }
 
+void UIVScrollBar::scrollTo(Number scrollValue) {
+	handleBox->setPositionY((scrollValue * dragRectHeight) + padding);	
+}
+
 void UIVScrollBar::setHandleRatio(Number newRatio) {
 	scrollHandleHeight = height*newRatio;	
 	

+ 2 - 0
Player/Contents/Include/PolycodePlayer.h

@@ -40,6 +40,8 @@ extern "C" {
 
 using namespace Polycode;
 
+//class PolycodeRemoteDebuggerClient : public
+
 class PolycodeDebugEvent : public Event {
 public:
 	PolycodeDebugEvent();