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

Merge branch 'master' of https://github.com/ivansafrin/Polycode

Ivan Safrin 13 лет назад
Родитель
Сommit
b71cef3b2a
44 измененных файлов с 762 добавлено и 78 удалено
  1. 2 0
      .gitignore
  2. 4 0
      BUILD.md
  3. 8 3
      BUILD.txt
  4. 3 3
      Core/Contents/Include/PolySDLCore.h
  5. 8 2
      Core/Contents/Source/OSBasics.cpp
  6. 83 13
      Core/Contents/Source/PolySDLCore.cpp
  7. 4 1
      Core/Contents/Source/PolySocket.cpp
  8. 3 1
      Core/Contents/Source/PolyTween.cpp
  9. 13 0
      IDE/Build/Linux/Makefile
  10. 10 0
      IDE/Build/Linux/main.cpp
  11. 9 1
      IDE/Contents/Include/PolycodeFrame.h
  12. 2 2
      IDE/Contents/Include/PolycodeIDEApp.h
  13. 2 2
      IDE/Contents/Include/PolycodeProjectManager.h
  14. 3 0
      IDE/Contents/Resources/UIThemes/default/theme.xml
  15. 16 0
      IDE/Contents/Source/NewProjectWindow.cpp
  16. 41 2
      IDE/Contents/Source/PolycodeFrame.cpp
  17. 1 1
      IDE/Contents/Source/PolycodeIDEApp.cpp
  18. 1 1
      IDE/Contents/Source/PolycodeProjectManager.cpp
  19. 1 1
      IDE/Contents/Source/PolycodeScreenEditor.cpp
  20. 6 2
      IDE/Contents/Source/PolycodeToolLauncher.cpp
  21. 2 0
      Modules/Contents/UI/CMakeLists.txt
  22. 1 1
      Modules/Contents/UI/Include/PolyUIButton.h
  23. 2 0
      Modules/Contents/UI/Include/PolyUIColorBox.h
  24. 102 0
      Modules/Contents/UI/Include/PolyUIFileDialog.h
  25. 0 1
      Modules/Contents/UI/Include/PolyUIMenu.h
  26. 3 0
      Modules/Contents/UI/Include/PolyUIWindow.h
  27. 2 1
      Modules/Contents/UI/Include/PolycodeUI.h
  28. 3 1
      Modules/Contents/UI/Source/PolyUIButton.cpp
  29. 5 4
      Modules/Contents/UI/Source/PolyUICheckBox.cpp
  30. 22 1
      Modules/Contents/UI/Source/PolyUIColorBox.cpp
  31. 6 1
      Modules/Contents/UI/Source/PolyUIComboBox.cpp
  32. 311 0
      Modules/Contents/UI/Source/PolyUIFileDialog.cpp
  33. 2 1
      Modules/Contents/UI/Source/PolyUIHScrollBar.cpp
  34. 8 1
      Modules/Contents/UI/Source/PolyUIHSizer.cpp
  35. 3 1
      Modules/Contents/UI/Source/PolyUIHSlider.cpp
  36. 2 1
      Modules/Contents/UI/Source/PolyUIImageButton.cpp
  37. 7 3
      Modules/Contents/UI/Source/PolyUIMenu.cpp
  38. 2 1
      Modules/Contents/UI/Source/PolyUIScrollContainer.cpp
  39. 9 1
      Modules/Contents/UI/Source/PolyUITextInput.cpp
  40. 8 2
      Modules/Contents/UI/Source/PolyUITree.cpp
  41. 4 1
      Modules/Contents/UI/Source/PolyUITreeContainer.cpp
  42. 2 1
      Modules/Contents/UI/Source/PolyUIVScrollBar.cpp
  43. 8 1
      Modules/Contents/UI/Source/PolyUIVSizer.cpp
  44. 28 19
      Modules/Contents/UI/Source/PolyUIWindow.cpp

+ 2 - 0
.gitignore

@@ -77,6 +77,8 @@ Player/Build/Mac OS X/Polycode Player.xcodeproj/project.xcworkspace/xcuserdata/i
 
 /IDE/Contents/Resources/Standalone
 
+/IDE/Build/Linux/Build
+
 /Core/Build/Mac\ OS\ X/build
 /IDE/Build/Mac\ OS\ X/build
 /Modules/Build/Mac\ OS\ X/build

+ 4 - 0
BUILD.md

@@ -195,6 +195,10 @@ of variables to the cmake commands above. To build the bindings, you
 need a python installation with the PLY python module. You can get
 the PLY module at http://www.dabeaz.com/ply/
 
+Note: You will need python 2 for this step. If you have python 3 installed,
+pass -DPYTHON_EXECUTABLE=/usr/bin/python2 or whatever the full path to
+the python2 executable is on your system.
+
 To enable the bindings and the player, add the following options to the
 cmake command. Otherwise, the steps are exactly the same as the regular 
 Polycode build for your system.

+ 8 - 3
BUILD.txt

@@ -79,9 +79,10 @@ directory from a command prompt (for VS2010):
     cd Build
     cmake -G "Visual Studio 10" ..
     
-This generates a PolycodeDependencies.sln in the Build directory.
-Building the ALL_BUILD project in the solution in Visual Studio will download,
-build and install the dependencies. Note that you need to build both Debug and Release.
+This generates a PolycodeDependencies.sln in the Build directory. 
+Building the ALL_BUILD project in the solution in Visual Studio will download, build and 
+install the dependencies. Note that you need to build both Debug and
+Release.
 
 You will also need to manually build the "glext" and "wglext" projects.
 
@@ -194,6 +195,10 @@ of variables to the cmake commands above. To build the bindings, you
 need a python installation with the PLY python module. You can get
 the PLY module at http://www.dabeaz.com/ply/
 
+Note: You will need python 2 for this step. If you have python 3 installed,
+pass -DPYTHON_EXECUTABLE=/usr/bin/python2 or whatever the full path to
+the python2 executable is on your system.
+
 To enable the bindings and the player, add the following options to the
 cmake command. Otherwise, the steps are exactly the same as the regular 
 Polycode build for your system.

+ 3 - 3
Core/Contents/Include/PolySDLCore.h

@@ -41,7 +41,7 @@ namespace Polycode {
 		
 	public:
 		
-		SDLCore(PolycodeView *view, int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex=-1);
+		SDLCore(PolycodeView *view, int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex=-1, bool resizableWindow = false);
 		~SDLCore();
 
 		void enableMouse(bool newval);
@@ -70,8 +70,8 @@ namespace Polycode {
 		void openURL(String url);
 
 	private:
-		
-		
+		uint32_t flags;
+		bool resizableWindow;
 		
 	};
 }

+ 8 - 2
Core/Contents/Source/OSBasics.cpp

@@ -82,7 +82,12 @@ OSFileEntry::OSFileEntry(const String& path, const String& name, int type) {
 
 void OSFileEntry::init(const Polycode::String& path, const Polycode::String& name, int type) {
 	this->basePath = path;
-	this->fullPath = path + "/" + name;
+
+	if(path == "/") {
+		this->fullPath = "/" + name;
+	} else {
+		this->fullPath = path + "/" + name;
+	}
 	this->name = name;
 	this->type = type;
 
@@ -255,6 +260,7 @@ vector<OSFileEntry> OSBasics::parsePhysFSFolder(const String& pathString, bool s
 vector<OSFileEntry> OSBasics::parseFolder(const String& pathString, bool showHidden) {
 	vector<OSFileEntry> returnVector;
 	
+	if(pathString != "/") {
 	if(pathString.size() < 128) {
 		if(PHYSFS_exists(pathString.c_str())) {
 			if(PHYSFS_isDirectory(pathString.c_str())) {
@@ -262,7 +268,7 @@ vector<OSFileEntry> OSBasics::parseFolder(const String& pathString, bool showHid
 			}
 		}
 	}
-	
+	}
 	
 #ifdef _WINDOWS
 

+ 83 - 13
Core/Contents/Source/PolySDLCore.cpp

@@ -34,6 +34,12 @@
 #include <SDL/SDL.h>
 #include <iostream>
 
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <pwd.h>
+
 using namespace Polycode;
 using std::vector;
 
@@ -49,11 +55,25 @@ void Core::getScreenInfo(int *width, int *height, int *hz) {
 	if (hz) *hz = 0;
 }
 
-SDLCore::SDLCore(PolycodeView *view, int _xRes, int _yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex) : Core(_xRes, _yRes, fullScreen, vSync, aaLevel, anisotropyLevel, frameRate, monitorIndex) {
+SDLCore::SDLCore(PolycodeView *view, int _xRes, int _yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex, bool resizableWindow) : Core(_xRes, _yRes, fullScreen, vSync, aaLevel, anisotropyLevel, frameRate, monitorIndex) {
+
+	this->resizableWindow = resizableWindow;
+
+	char *buffer = getcwd(NULL, 0);
+	defaultWorkingDirectory = String(buffer);
+	free(buffer);
+
+	struct passwd *pw = getpwuid(getuid());
+	const char *homedir = pw->pw_dir;
+	userHomeDirectory = String(homedir);
 
 	String *windowTitle = (String*)view->windowData;
 
-	putenv("SDL_VIDEO_CENTERED=1");
+	if(resizableWindow) {
+		unsetenv("SDL_VIDEO_CENTERED");
+	} else {
+		setenv("SDL_VIDEO_CENTERED", "1", 1);
+	}
 
 	if(SDL_Init(SDL_INIT_VIDEO) < 0) {
 	}
@@ -95,16 +115,20 @@ void SDLCore::setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int
 	
 	SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);
 	
+	flags = SDL_OPENGL;
+
 	if(fullScreen) {
-		if( SDL_SetVideoMode(xRes, yRes, 0, SDL_OPENGL|SDL_FULLSCREEN) == NULL ) {
-		}	
-	} else {
-		if( SDL_SetVideoMode(xRes, yRes, 0, SDL_OPENGL) == NULL ) {
-		}
+		flags |= SDL_FULLSCREEN;
+	}
+
+	if(resizableWindow) {
+		flags |= SDL_RESIZABLE;
 	}
+	SDL_SetVideoMode(xRes, yRes, 0, flags);
 	
 	renderer->Resize(xRes, yRes);
-	CoreServices::getInstance()->getMaterialManager()->reloadProgramsAndTextures();
+	//CoreServices::getInstance()->getMaterialManager()->reloadProgramsAndTextures();
+	dispatchEvent(new Event(), EVENT_CORE_RESIZE);	
 }
 
 vector<Polycode::Rectangle> SDLCore::getVideoModes() {
@@ -130,7 +154,22 @@ void SDLCore::openURL(String url) {
 }
 
 String SDLCore::executeExternalCommand(String command) {
-	
+	FILE *fp = popen(command.c_str(), "r");
+	if(!fp) {
+		return "Unable to execute command";
+	}	
+
+	int fd = fileno(fp);
+
+	char path[2048];
+	String retString;
+
+	while (fgets(path, sizeof(path), fp) != NULL) {
+		retString = retString + String(path);
+	}
+
+	pclose(fp);
+	return retString;
 }
 
 int SDLThreadFunc(void *data) {
@@ -157,7 +196,7 @@ void SDLCore::enableMouse(bool newval) {
 	}
 	Core::enableMouse(newval);
 }
-	
+
 bool SDLCore::Update() {
 	if(!running)
 		return false;
@@ -173,6 +212,18 @@ bool SDLCore::Update() {
 				case SDL_QUIT:
 					running = false;
 				break;
+				case SDL_VIDEORESIZE:
+	if(resizableWindow) {
+		unsetenv("SDL_VIDEO_CENTERED");
+	} else {
+		setenv("SDL_VIDEO_CENTERED", "1", 1);
+	}
+					this->xRes = event.resize.w;
+					this->yRes = event.resize.h;
+					SDL_SetVideoMode(xRes, yRes, 0, flags);
+					renderer->Resize(xRes, yRes);	
+					dispatchEvent(new Event(), EVENT_CORE_RESIZE);	
+				break;
 				case SDL_JOYBUTTONDOWN:
 //					input->setKeyState((PolyKEY)(event.key.keysym.sym), true);
 				break;
@@ -243,18 +294,37 @@ String SDLCore::getClipboardString() {
 }
 
 void SDLCore::createFolder(const String& folderPath) {
-
+	mkdir(folderPath.c_str(), 0700);
 }
 
 void SDLCore::copyDiskItem(const String& itemPath, const String& destItemPath) {
-
+    int childExitStatus;
+    pid_t pid = fork();
+    if (pid == 0) {
+        execl("/bin/cp", "/bin/cp", itemPath.c_str(), destItemPath.c_str(), (char *)0);
+    } else {
+        pid_t ws = waitpid( pid, &childExitStatus, WNOHANG);
+    }
 }
 
 void SDLCore::moveDiskItem(const String& itemPath, const String& destItemPath) {
-
+    int childExitStatus;
+    pid_t pid = fork();
+    if (pid == 0) {
+        execl("/bin/mv", "/bin/mv", itemPath.c_str(), destItemPath.c_str(), (char *)0);
+    } else {
+        pid_t ws = waitpid( pid, &childExitStatus, WNOHANG);
+    }
 }
 
 void SDLCore::removeDiskItem(const String& itemPath) {
+    int childExitStatus;
+    pid_t pid = fork();
+    if (pid == 0) {
+        execl("/bin/rm", "/bin/rm", "-rf", itemPath.c_str(), (char *)0);
+    } else {
+        pid_t ws = waitpid( pid, &childExitStatus, WNOHANG);
+    }
 }
 
 String SDLCore::openFolderPicker() {

+ 4 - 1
Core/Contents/Source/PolySocket.cpp

@@ -22,7 +22,10 @@ THE SOFTWARE.
 
 #include "PolySocket.h"
 #include "PolyLogger.h"
-#include <unistd.h>
+
+#ifndef _WINDOWS
+	#include <unistd.h>
+#endif
 
 using namespace Polycode;
 using std::vector;

+ 3 - 1
Core/Contents/Source/PolyTween.cpp

@@ -67,7 +67,9 @@ void Tween::setSpeed(Number speed) {
 Tween::~Tween() {
 	tweenTimer->removeEventListener(this, 0);
 	delete tweenTimer;
-	CoreServices::getInstance()->getTweenManager()->removeTween(this);	
+	
+	deleteOnComplete = false; // Prevent loop when we removeTween in next line.
+	CoreServices::getInstance()->getTweenManager()->removeTween(this);
 }
 
 bool Tween::isComplete() {

+ 13 - 0
IDE/Build/Linux/Makefile

@@ -0,0 +1,13 @@
+CC=g++
+CFLAGS=-I../../Contents/Include -I../../../Release/Linux/Framework/Core/Dependencies/include -I../../../Release/Linux/Framework/Core/Dependencies/include/AL -I../../../Release/Linux/Framework/Core/include -I../../../Release/Linux/Framework/Modules/include -I../../../Release/Linux/Framework/Modules/Dependencies/include -I../../../Release/Linux/Framework/Modules/Dependencies/include/bullet -DUSE_POLYCODEUI_FILE_DIALOGS
+LDFLAGS=-lrt -ldl -lpthread ../../../Release/Linux/Framework/Core/lib/libPolycore.a ../../../Release/Linux/Framework/Core/Dependencies/lib/libfreetype.a ../../../Release/Linux/Framework/Core/Dependencies/lib/liblibvorbisfile.a ../../../Release/Linux/Framework/Core/Dependencies/lib/liblibvorbis.a ../../../Release/Linux/Framework/Core/Dependencies/lib/liblibogg.a ../../../Release/Linux/Framework/Core/Dependencies/lib/libopenal.so ../../../Release/Linux/Framework/Core/Dependencies/lib/libphysfs.a ../../../Release/Linux/Framework/Core/Dependencies/lib/libpng15.a ../../../Release/Linux/Framework/Core/Dependencies/lib/libz.a -lGL -lGLU -lSDL ../../../Release/Linux/Framework/Modules/lib/libPolycode2DPhysics.a ../../../Release/Linux/Framework/Modules/Dependencies/lib/libBox2D.a ../../../Release/Linux/Framework/Modules/lib/libPolycode3DPhysics.a ../../../Release/Linux/Framework/Modules/Dependencies/lib/libBulletDynamics.a ../../../Release/Linux/Framework/Modules/Dependencies/lib/libBulletCollision.a ../../../Release/Linux/Framework/Modules/Dependencies/lib/libLinearMath.a ../../../Release/Linux/Framework/Modules/lib/libPolycodeUI.a
+SRCS=../../Contents/Source/ExampleBrowserWindow.cpp ../../Contents/Source/PolycodeEditorManager.cpp  ../../Contents/Source/PolycodeProject.cpp        ../../Contents/Source/PolycodeScreenEditor.cpp ../../Contents/Source/ExportProjectWindow.cpp  ../../Contents/Source/PolycodeFontEditor.cpp     ../../Contents/Source/PolycodeProjectBrowser.cpp ../../Contents/Source/PolycodeSpriteEditor.cpp ../../Contents/Source/NewFileWindow.cpp        ../../Contents/Source/PolycodeFrame.cpp          ../../Contents/Source/PolycodeProjectEditor.cpp  ../../Contents/Source/PolycodeTextEditor.cpp ../../Contents/Source/NewProjectWindow.cpp     ../../Contents/Source/PolycodeIDEApp.cpp         ../../Contents/Source/PolycodeProjectManager.cpp ../../Contents/Source/PolycodeToolLauncher.cpp ../../Contents/Source/PolycodeConsole.cpp      ../../Contents/Source/PolycodeImageEditor.cpp    ../../Contents/Source/PolycodeProps.cpp          ../../Contents/Source/TextureBrowser.cpp ../../Contents/Source/PolycodeEditor.cpp       ../../Contents/Source/PolycodeMaterialEditor.cpp ../../Contents/Source/PolycodeRemoteDebugger.cpp ../../Contents/Source/ToolWindows.cpp
+
+default:
+	$(CC) $(CFLAGS) -g main.cpp $(SRCS) -o ./Build/Polycode $(LDFLAGS)
+	cp -R ../../Contents/Resources/* Build/
+	cp ../../../Release/Linux/Framework/Core/Assets/default.pak Build/
+	cp -R ../../../Release/Linux/Standalone Build
+clean:
+	rm ./Build/Polycode
+	

+ 10 - 0
IDE/Build/Linux/main.cpp

@@ -0,0 +1,10 @@
+#include "Polycode.h"
+#include "PolycodeView.h"
+#include "PolycodeIDEApp.h"
+
+int main(int argc, char *argv[]) {
+	PolycodeView *view = new PolycodeView("Hello Polycode!");
+	PolycodeIDEApp *app = new PolycodeIDEApp(view);
+	while(app->Update()) {}
+	return 0;
+}

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

@@ -160,6 +160,8 @@ public:
 	void showModal(UIWindow *modalChild);
 	void hideModal();
 	
+	void showFileBrowser(String baseDir, bool foldersOnly, std::vector<String> extensions, bool allowMultiple);
+
 	void handleEvent(Event *event);
 	
 	void addEditor(PolycodeEditor *editor);
@@ -195,11 +197,17 @@ public:
 		
 	CurveEditor *curveEditor;
 	
+	UIElement *modalRoot;
+	UIElement *fileBrowserRoot;
+	UIFileDialog *fileDialog;
+
 private:
 	
 	int frameSizeX;
 	int frameSizeY;
 	
+	ScreenShape *fileDialogBlocker;
+
 	ScreenShape *topBarBg;
 	ScreenImage *logo;	
 	ScreenImage *resizer;	
@@ -225,4 +233,4 @@ private:
 	UIButton *newProjectButton;
 	UIButton *examplesButton;
 	
-};
+};

+ 2 - 2
IDE/Contents/Include/PolycodeIDEApp.h

@@ -26,7 +26,7 @@
 #include "PolycodeProjectManager.h"
 #include "PolycodeEditorManager.h"
 #include "Polycode.h"
-#include "PolyCocoaCore.h"
+//#include "PolyCocoaCore.h"
 #include "PolycodeUI.h"
 #include "PolycodeFrame.h"
 
@@ -89,7 +89,7 @@ public:
 	
 	const static int EVENT_SHOW_MENU = 1;
 	
-	CocoaCore *core;	
+	Core *core;	
 protected:
 
 	bool willRunProject;

+ 2 - 2
IDE/Contents/Include/PolycodeProjectManager.h

@@ -48,7 +48,7 @@ class PolycodeProjectManager {
 	
 	PolycodeProject *getProjectByProjectFile(String projectFile);
 	
-	void exportProject(PolycodeProject *project, String exportPath, bool macOS, bool windows, bool linux);
+	void exportProject(PolycodeProject *project, String exportPath, bool macOS, bool windows, bool _linux);
 	
 	int removeProject(PolycodeProject *project);
 	
@@ -64,4 +64,4 @@ protected:
 	PolycodeProjectBrowser *projectBrowser;
 	vector<PolycodeProject*> projects;
 	
-};	
+};	

+ 3 - 0
IDE/Contents/Resources/UIThemes/default/theme.xml

@@ -157,4 +157,7 @@
 	<uiHSliderBgB>5</uiHSliderBgB>
 	<uiHSliderBgL>6</uiHSliderBgL>
 
+	<uiFileBrowserFileIcon>file.png</uiFileBrowserFileIcon>
+	<uiFileBrowserFolderIcon>folder.png</uiFileBrowserFolderIcon>
+	<uiFileBrowserPlaceIcon>boxIcon.png</uiFileBrowserPlaceIcon>
 </PolyConfig>

+ 16 - 0
IDE/Contents/Source/NewProjectWindow.cpp

@@ -21,6 +21,9 @@
 */
 
 #include "NewProjectWindow.h"
+#include "PolycodeFrame.h"
+
+extern PolycodeFrame *globalFrame;
 
 NewProjectWindow::NewProjectWindow() : UIWindow(L"Create New Project", 480, 280){
 	
@@ -122,6 +125,13 @@ void NewProjectWindow::ResetForm() {
 
 void NewProjectWindow::handleEvent(Event *event) {
 	if(event->getEventType() == "UIEvent") {
+		if(event->getEventCode() == UIEvent::OK_EVENT && event->getDispatcher() == globalFrame->fileDialog) {
+			String pathName = globalFrame->fileDialog->getSelection();
+			if(pathName != "")
+				projectLocationInput->setText(pathName);
+
+		}
+
 		if(event->getEventCode() == UIEvent::CLICK_EVENT) {
 			if(event->getDispatcher() == okButton) {
 				dispatchEvent(new UIEvent(), UIEvent::OK_EVENT);						
@@ -132,9 +142,15 @@ void NewProjectWindow::handleEvent(Event *event) {
 			}			
 			
 			if(event->getDispatcher() == locationSelectButton) {
+#ifdef USE_POLYCODEUI_FILE_DIALOGS
+				std::vector<String> exts;
+				globalFrame->showFileBrowser(CoreServices::getInstance()->getCore()->getUserHomeDirectory(),  true, exts, false);
+				globalFrame->fileDialog->addEventListener(this, UIEvent::OK_EVENT);
+#else
 				String pathName = CoreServices::getInstance()->getCore()->openFolderPicker();
 				if(pathName != "")
 					projectLocationInput->setText(pathName);
+#endif
 			}			
 			
 		}

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

@@ -610,6 +610,38 @@ PolycodeFrame::PolycodeFrame() : ScreenEntity() {
 	globalColorPicker = new UIColorPicker();
 	globalColorPicker->setPosition(300,300);
 	addChild(globalColorPicker);
+
+	modalRoot = new UIElement();
+	addChild(modalRoot);
+	
+	fileDialogBlocker = new ScreenShape(ScreenShape::SHAPE_RECT, 100, 100);
+	fileDialogBlocker->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
+	addChild(fileDialogBlocker);
+	fileDialogBlocker->setColor(0.0, 0.0, 0.0, 0.5);
+	fileDialogBlocker->processInputEvents = true;
+	fileDialogBlocker->blockMouseInput = true;
+	fileDialogBlocker->visible = false;
+	fileDialogBlocker->enabled = false;
+
+	fileBrowserRoot = new UIElement();
+	addChild(fileBrowserRoot);
+
+	fileDialog = NULL;
+}
+
+void PolycodeFrame::showFileBrowser(String baseDir, bool foldersOnly, std::vector<String> extensions, bool allowMultiple) {
+	
+	if(fileDialog)
+		delete fileDialog;
+
+	fileDialog = new UIFileDialog(baseDir, foldersOnly, extensions, allowMultiple);
+	fileDialog->addEventListener(this, UIEvent::CANCEL_EVENT);
+	fileDialog->addEventListener(this, UIEvent::OK_EVENT);
+	fileBrowserRoot->addChild(fileDialog);
+	fileDialog->setPosition(100,100);
+	
+	fileDialogBlocker->visible = true;
+	fileDialogBlocker->enabled = true;
 }
 
 void PolycodeFrame::showCurveEditor() {
@@ -621,7 +653,7 @@ void PolycodeFrame::showModal(UIWindow *modalChild) {
 	modalBlocker->enabled = true;
 	
 	this->modalChild = modalChild;
-	addChild(modalChild);
+	modalRoot->addChild(modalChild);
 	modalChild->showWindow();
 	modalChild->addEventListener(this, UIEvent::CLOSE_EVENT);
 	Resize(frameSizeX, frameSizeY);
@@ -652,7 +684,7 @@ void PolycodeFrame::showEditor(PolycodeEditor *editor) {
 
 void PolycodeFrame::hideModal() {
 	if(modalChild) {
-		removeChild(modalChild);
+		modalRoot->removeChild(modalChild);
 		modalChild->removeEventListener(this, UIEvent::CLOSE_EVENT);	
 		modalChild->hideWindow(); 
 		modalChild = NULL;
@@ -671,6 +703,12 @@ void PolycodeFrame::showAssetBrowser(std::vector<String> extensions) {
 
 void PolycodeFrame::handleEvent(Event *event) {
 	
+	if(event->getDispatcher() == fileDialog && event->getEventType() == "UIEvent") {
+		fileBrowserRoot->removeChild(fileDialog);
+		fileDialogBlocker->visible = false;
+		fileDialogBlocker->enabled = false;
+	}
+
 	if(event->getDispatcher() == CoreServices::getInstance()->getCore()->getInput()) {
 		switch(event->getEventCode()) {
 			case InputEvent::EVENT_MOUSEUP:
@@ -745,6 +783,7 @@ void PolycodeFrame::Resize(int x, int y) {
 	mainSizer->Resize(x,y-45);	
 	
 	modalBlocker->setShapeSize(x, y);
+	fileDialogBlocker->setShapeSize(x, y);
 		
 	
 	if(this->modalChild) {

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

@@ -29,7 +29,7 @@ UIGlobalMenu *globalMenu;
 SyntaxHighlightTheme *globalSyntaxTheme;
 
 PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
-	core = new CocoaCore(view, 900,700,false,true, 0, 0,30);	
+	core = new SDLCore(view, 900,700,false,true, 0, 0,30, -1, true);	
 	core->addEventListener(this, Core::EVENT_CORE_RESIZE);
 	
 	

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

@@ -136,7 +136,7 @@ void PolycodeProjectManager::createNewProject(String templateFolder, String proj
 	openProject(projectLocation+"/"+projectName+"/"+projectName+".polyproject");	
 }
 
-void PolycodeProjectManager::exportProject(PolycodeProject *project, String exportPath, bool macOS, bool windows, bool linux) {
+void PolycodeProjectManager::exportProject(PolycodeProject *project, String exportPath, bool macOS, bool windows, bool _linux) {
 
 	String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
 

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

@@ -788,7 +788,7 @@ void PolycodeScreenEditorMain::syncTransformToSelected() {
 		screenTransformShape->setShapeSize(selectedEntity->getWidth(),selectedEntity->getHeight());	
 		Matrix4 final = selectedEntity->getConcatenatedMatrixRelativeTo(baseEntity);
 		screenTransform->setPosition(final.getPosition());
-		screenTransformShape->matrixDirty = false;
+		screenTransformShape->dirtyMatrix(false);
 		screenTransformShape->setTransformByMatrixPure(final);
 		
 		screenTransform->rotation.roll = selectedEntity->getCombinedRoll();

+ 6 - 2
IDE/Contents/Source/PolycodeToolLauncher.cpp

@@ -33,11 +33,15 @@ PolycodeRunner::PolycodeRunner(String polyappPath) : Threaded() {
 void PolycodeRunner::runThread() {
 	String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
 
+#if defined(__APPLE__) && defined(__MACH__)
 	String command = "cd "+polycodeBasePath+"/Standalone/Player/PolycodePlayer.app/Contents/Resources && ../MacOS/PolycodePlayer "+polyappPath;
 		;		
+#else
+	String command = "cd "+polycodeBasePath+"/Standalone/Player && ./PolycodePlayer "+polyappPath;
 
+#endif
 	String ret = CoreServices::getInstance()->getCore()->executeExternalCommand(command);
-		core->removeDiskItem(polyappPath);	
+	core->removeDiskItem(polyappPath);	
 }
 
 PolycodeToolLauncher::PolycodeToolLauncher() {
@@ -92,4 +96,4 @@ void PolycodeToolLauncher::runPolyapp(String polyappPath) {
 
 #endif
 
-}
+}

+ 2 - 0
Modules/Contents/UI/CMakeLists.txt

@@ -21,6 +21,7 @@ SET(polycodeUI_SRCS
     Source/PolyUITreeEvent.cpp
     Source/PolyUIVScrollBar.cpp
     Source/PolyUIWindow.cpp
+    Source/PolyUIFileDialog.cpp
 )
 
 SET(polycodeUI_HDRS
@@ -45,6 +46,7 @@ SET(polycodeUI_HDRS
     Include/PolyUITreeEvent.h
     Include/PolyUIVScrollBar.h
     Include/PolyUIWindow.h
+    Include/PolyUIFileDialog.h
 )
 
 INCLUDE_DIRECTORIES(

+ 1 - 1
Modules/Contents/UI/Include/PolyUIButton.h

@@ -48,4 +48,4 @@ namespace Polycode {
 			ScreenLabel *buttonLabel;
 			bool pressedDown;
 	};
-}
+}

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

@@ -85,6 +85,8 @@ namespace Polycode {
 			UIHSlider *alphaSlider;
 			
 			ScreenShape *mainColorRect;
+			
+			vector<ScreenLabel *> junkLabels; // Kept only to delete
 	};
 
 	class _PolyExport UIColorBox : public UIElement {

+ 102 - 0
Modules/Contents/UI/Include/PolyUIFileDialog.h

@@ -0,0 +1,102 @@
+/*
+ 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 "PolyGlobals.h"
+#include "PolyUIWindow.h"
+#include "PolyUIButton.h"
+#include "PolyUIScrollContainer.h"
+#include "PolyUITextInput.h"
+#include "OSBasics.h"
+#include "PolyInputEvent.h"
+
+namespace Polycode {
+	
+	class CreateFolderWindow : public UIWindow {
+		public:
+			CreateFolderWindow();
+			~CreateFolderWindow();
+
+			UIButton *okButton;
+			UIButton *cancelButton;
+			UITextInput *nameInput;
+
+	};
+
+	class UIFileDialogEntry : public UIElement {
+		public:
+			UIFileDialogEntry(OSFileEntry entry, bool canSelect, int width=340, bool isPlace=false);
+			~UIFileDialogEntry();
+			void Select();
+			void Deselect();
+
+			bool canSelect;
+			ScreenShape *bg;
+			ScreenLabel *label;
+			OSFileEntry fileEntry;
+			ScreenImage *icon;
+	};
+
+	class UIFileDialog : public UIWindow {
+		public:
+			UIFileDialog(String baseDir, bool foldersOnly, std::vector<String> extensions, bool allowMultiple);
+			virtual ~UIFileDialog();
+
+			void onClose();
+			void handleEvent(Event *event);
+			void clearEntries();
+			void showFolder(String folderPath);
+	
+			void addToSidebar(String path, String name);
+
+			void Update();
+
+			String getSelection();
+		protected:
+
+			String selection;
+
+			String currentFolderPath;
+
+			UIFileDialogEntry *currentEntry;
+
+			bool foldersOnly;
+			bool allowMultiple;
+
+			bool doChangeFolder;
+			String newPath;
+
+			UIButton *okButton;
+			UIButton *cancelButton;
+			UIButton *newFolderButton;
+
+			CreateFolderWindow *createFolderWindow;
+
+			UIScrollContainer *scrollContainer;
+
+			std::vector<UIFileDialogEntry*> entries;
+			std::vector<UIFileDialogEntry*> sideBarEntries;
+			UIElement *entryHolder;		
+	};
+}
+

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

@@ -55,7 +55,6 @@ namespace Polycode {
 			
 		protected:
 		
-			ScreenImage *dropDownImage;
 			Number menuItemHeight;
 			Number menuWidth;
 			

+ 3 - 0
Modules/Contents/UI/Include/PolyUIWindow.h

@@ -71,5 +71,8 @@ namespace Polycode {
 			UIImageButton *closeBtn;
 			UIBox *windowRect;
 			ScreenShape *titlebarRect;
+		
+			bool tweenClosing;
+			void resetTween();
 	};
 }

+ 2 - 1
Modules/Contents/UI/Include/PolycodeUI.h

@@ -39,4 +39,5 @@
 #include "PolyUITreeEvent.h"
 #include "PolyUIVScrollBar.h"
 #include "PolyUIWindow.h"
-#include "PolyUIMenu.h"
+#include "PolyUIMenu.h"
+#include "PolyUIFileDialog.h"

+ 3 - 1
Modules/Contents/UI/Source/PolyUIButton.cpp

@@ -91,7 +91,9 @@ void UIButton::Update() {
 }
 
 UIButton::~UIButton() {
-
+	delete buttonRect;
+	delete buttonFocusedRect;
+	delete buttonLabel;
 }
 		
 void UIButton::handleEvent(Event *event) {

+ 5 - 4
Modules/Contents/UI/Source/PolyUICheckBox.cpp

@@ -38,9 +38,9 @@ UICheckBox::UICheckBox(String caption, bool checked) : UIElement() {
 	String uncheckImage = conf->getStringValue("Polycode", "uiCheckBoxUncheckedImage");
 	Number checkboxTextOffsetX = conf->getNumericValue("Polycode", "uiCheckBoxLabelOffsetX");
 	Number checkboxTextOffsetY = conf->getNumericValue("Polycode", "uiCheckBoxLabelOffsetY");
-		
+	
 	this->checked = checked;
-		
+	
 	buttonImageChecked = new ScreenImage(checkImage);
 	buttonImageChecked->visible = checked;
 
@@ -67,7 +67,6 @@ UICheckBox::UICheckBox(String caption, bool checked) : UIElement() {
 	
 	height = buttonImageUnchecked->getHeight();
 	width = buttonImageUnchecked->getWidth() + captionLabel->getWidth() + checkboxTextOffsetX;
-	
 }
 
 String UICheckBox::getCaptionLabel() {
@@ -75,7 +74,9 @@ String UICheckBox::getCaptionLabel() {
 }
 
 UICheckBox::~UICheckBox() {
-
+	delete buttonImageChecked;
+	delete buttonImageUnchecked;
+	delete captionLabel;
 }
 
 bool UICheckBox::isChecked() {

+ 22 - 1
Modules/Contents/UI/Source/PolyUIColorBox.cpp

@@ -95,6 +95,7 @@ UIColorPicker::UIColorPicker() : UIWindow(L"", 300, 240) {
 	ScreenLabel *label = new ScreenLabel(L"R:", fontSize, fontName);
 	label->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 15, topPadding+padding + 3);
 	addChild(label);
+	junkLabels.push_back(label);
 	
 	rTextInput = new UITextInput(false, 40, 12);
 	rTextInput->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 30, topPadding+padding);
@@ -104,6 +105,7 @@ UIColorPicker::UIColorPicker() : UIWindow(L"", 300, 240) {
 	label = new ScreenLabel(L"G:", fontSize, fontName);
 	label->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 15, topPadding+padding + 33);
 	addChild(label);
+	junkLabels.push_back(label);
 	
 	gTextInput = new UITextInput(false, 40, 12);
 	gTextInput->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 30, topPadding+padding + 30);
@@ -113,6 +115,7 @@ UIColorPicker::UIColorPicker() : UIWindow(L"", 300, 240) {
 	label = new ScreenLabel(L"B:", fontSize, fontName);
 	label->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 15, topPadding+padding + 63);
 	addChild(label);
+	junkLabels.push_back(label);
 	
 	bTextInput = new UITextInput(false, 40, 12);
 	bTextInput->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 30, topPadding+padding + 60);
@@ -122,6 +125,7 @@ UIColorPicker::UIColorPicker() : UIWindow(L"", 300, 240) {
 	label = new ScreenLabel(L"A:", fontSize, fontName);
 	label->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 15, topPadding+padding + 93);
 	addChild(label);
+	junkLabels.push_back(label);
 	
 	aTextInput = new UITextInput(false, 40, 12);
 	aTextInput->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 30, topPadding+padding + 90);
@@ -339,7 +343,20 @@ void UIColorPicker::setHue(Number hueNum) {
 }
 
 UIColorPicker::~UIColorPicker() {
-
+	delete mainBg;
+	delete mainFrame;
+	delete alphaSlider;
+	delete mainColorRect;
+	delete hueFrame;
+	delete hueSelector;
+	delete mainSelector;
+	delete rTextInput;
+	delete gTextInput;
+	delete bTextInput;
+	delete aTextInput;
+	
+	for(int c = 0; c < junkLabels.size(); c++)
+		delete junkLabels[c];
 }
 
 void UIColorPicker::Update() {
@@ -428,6 +445,10 @@ Color UIColorBox::getSelectedColor() {
 
 UIColorBox::~UIColorBox() {
 	colorPicker->removeAllHandlersForListener(this);
+	
+	delete bgImage;
+	delete colorShape;
+	delete frameImage;
 }
 
 void UIColorBox::setBoxColor(Color newColor) {

+ 6 - 1
Modules/Contents/UI/Source/PolyUIComboBox.cpp

@@ -101,7 +101,12 @@ UIComboBox::UIComboBox(UIGlobalMenu *globalMenu, Number comboWidth) : UIElement(
 }
 
 UIComboBox::~UIComboBox() {
-
+	for(int c = 0; c < items.size(); c++)
+		delete items[c];
+	
+	delete dropDownImage;
+	delete bgBox;
+	delete selectedLabel;
 }
 
 void UIComboBox::clearItems() {

+ 311 - 0
Modules/Contents/UI/Source/PolyUIFileDialog.cpp

@@ -0,0 +1,311 @@
+
+#include "PolyUIFileDialog.h"
+#include "PolyConfig.h"
+
+using namespace Polycode;
+
+UIFileDialogEntry::UIFileDialogEntry(OSFileEntry entry, bool canSelect, int width, bool isPlace) : UIElement() {
+	this->canSelect = canSelect;
+	ownsChildren = true;
+
+	Config *conf = CoreServices::getInstance()->getConfig();	
+	String fileIconName = conf->getStringValue("Polycode", "uiFileBrowserFileIcon");
+	String folderIconName = conf->getStringValue("Polycode", "uiFileBrowserFolderIcon");
+	String placeIconName = conf->getStringValue("Polycode", "uiFileBrowserPlaceIcon");
+
+	bg = new ScreenShape(ScreenShape::SHAPE_RECT, width, 18);
+	bg->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
+	addChild(bg);
+	bg->setColor(0.0, 0.0, 0.0, 0.1);
+	bg->processInputEvents = true;
+
+	this->fileEntry = entry;
+
+	if(isPlace) {
+		icon = new ScreenImage(placeIconName);
+	} else {
+		if(entry.type == OSFileEntry::TYPE_FILE) {
+			icon = new ScreenImage(fileIconName);
+		} else {
+			icon = new ScreenImage(folderIconName);
+		}
+	}
+
+	addChild(icon);
+	icon->setPosition(3,1);
+
+	label = new ScreenLabel(entry.name, 12, "sans");
+	addChild(label);
+	label->setPosition(25, 2);
+
+	if(!canSelect) {
+		label->color.a = 0.3;
+	}
+
+}
+
+void UIFileDialogEntry::Select() {
+	bg->setColor(0.0, 0.0, 0.0, 0.5);
+}
+
+void UIFileDialogEntry::Deselect() {
+	bg->setColor(0.0, 0.0, 0.0, 0.1);
+}
+
+UIFileDialogEntry::~UIFileDialogEntry() {
+
+}
+
+UIFileDialog::UIFileDialog(String baseDir, bool foldersOnly, std::vector<String> extensions, bool allowMultiple) : UIWindow("", 500, 400) {
+	this->foldersOnly = foldersOnly;
+	this->allowMultiple = allowMultiple;
+
+	ownsChildren = true;
+	
+	closeOnEscape = true;
+
+	if(foldersOnly) {
+		setWindowCaption("Select a folder");
+	} else {
+		if(allowMultiple) {
+			setWindowCaption("Select files");
+		} else {
+			setWindowCaption("Select a file");
+		}
+	}
+
+	cancelButton = new UIButton("Cancel", 100);
+	addChild(cancelButton);
+	cancelButton->setPosition(500-210, 400 - 20);
+
+	okButton = new UIButton("OK",  100);
+	addChild(okButton);
+	okButton->setPosition(500-100, 400 - 20);
+
+	newFolderButton = new UIButton("New Folder", 100);
+	addChild(newFolderButton);
+	newFolderButton->setPosition(25, 400-20);
+
+	newFolderButton->addEventListener(this, UIEvent::CLICK_EVENT);
+	okButton->addEventListener(this, UIEvent::CLICK_EVENT);
+	cancelButton->addEventListener(this, UIEvent::CLICK_EVENT);
+
+	entryHolder = new UIElement();
+	entryHolder->ownsChildren = true;
+
+	scrollContainer = new UIScrollContainer(entryHolder, false, true, 500-140, 320);
+	addChild(scrollContainer);
+
+	scrollContainer->setPosition(160, 40);
+	showFolder(baseDir);
+
+	createFolderWindow = new CreateFolderWindow();
+	createFolderWindow->visible = false;
+	createFolderWindow->enabled = false;
+
+	createFolderWindow->setPosition(100, 150);
+
+	createFolderWindow->okButton->addEventListener(this, UIEvent::CLICK_EVENT);
+	createFolderWindow->cancelButton->addEventListener(this, UIEvent::CLICK_EVENT);
+
+	addChild(createFolderWindow);
+
+	doChangeFolder = false;
+	addToSidebar("/", "Filesystem");
+	addToSidebar(CoreServices::getInstance()->getCore()->getUserHomeDirectory(), "Home");
+}
+
+void UIFileDialog::addToSidebar(String path, String name) {
+	OSFileEntry backEntry;
+	backEntry.type = OSFileEntry::TYPE_FOLDER;
+	backEntry.name = name;
+	backEntry.fullPath = path;
+
+	UIFileDialogEntry *newEntry = new UIFileDialogEntry(backEntry, true, 140, true);
+	addChild(newEntry);
+	newEntry->setPosition(10, 40 + (sideBarEntries.size() * 20));
+	sideBarEntries.push_back(newEntry);
+	newEntry->bg->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
+}
+
+void UIFileDialog::clearEntries() {
+	for(int i=0; i < entries.size(); i++) {
+		entryHolder->removeChild(entries[i]);
+		delete entries[i];	
+	}
+	entries.clear();
+}
+
+void UIFileDialog::onClose() {
+	dispatchEvent(new UIEvent(), UIEvent::CANCEL_EVENT);
+}
+
+String UIFileDialog::getSelection() {
+	return selection;
+}
+
+void UIFileDialog::showFolder(String folderPath) {
+	doChangeFolder = false;
+
+	currentFolderPath = folderPath;
+
+	if(foldersOnly) {
+		selection = folderPath;
+	}
+
+
+	for(int i=0; i < sideBarEntries.size(); i++) {
+		sideBarEntries[i]->Deselect();
+	}
+
+	currentEntry = NULL;
+	clearEntries();
+
+	std::vector<OSFileEntry> _entries = OSBasics::parseFolder(folderPath, false);
+	
+	int offset = 0;
+	if(folderPath != "/") {
+	offset = 1;
+	OSFileEntry backEntry;
+	backEntry.type = OSFileEntry::TYPE_FOLDER;
+	backEntry.name = "..";
+	backEntry.basePath = folderPath;
+	backEntry.fullPath = folderPath+"/..";
+
+	UIFileDialogEntry *newEntry = new UIFileDialogEntry(backEntry, true);
+	entryHolder->addChild(newEntry);
+	entries.push_back(newEntry);
+	newEntry->bg->addEventListener(this, InputEvent::EVENT_DOUBLECLICK);
+	newEntry->bg->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
+	}
+
+	int i;
+	for(i=0; i < _entries.size(); i++) {
+		bool canSelect = false;
+		if(foldersOnly) {
+			if(_entries[i].type == OSFileEntry::TYPE_FOLDER) {
+				canSelect = true;
+			}
+		} else {
+
+		}
+		UIFileDialogEntry *newEntry = new UIFileDialogEntry(_entries[i], canSelect);
+		entryHolder->addChild(newEntry);
+		newEntry->setPosition(0, (i+offset) * 20);
+		entries.push_back(newEntry);	
+		newEntry->bg->addEventListener(this, InputEvent::EVENT_DOUBLECLICK);
+		newEntry->bg->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
+	}
+	scrollContainer->setContentSize(500-160, (i+offset) * 20);
+}
+
+void UIFileDialog::Update() {
+	if(doChangeFolder) {
+		showFolder(newPath);
+		doChangeFolder = false;
+	}
+}
+
+void UIFileDialog::handleEvent(Event *event) {
+
+	for(int i=0; i < sideBarEntries.size(); i++) {
+		if(event->getDispatcher() == sideBarEntries[i]->bg) {
+			showFolder(sideBarEntries[i]->fileEntry.fullPath);
+			sideBarEntries[i]->Select();
+		}
+	}
+
+	for(int i=0; i < entries.size(); i++) {
+		if(event->getDispatcher() == entries[i]->bg) {
+			
+			switch(event->getEventCode()) {
+				case InputEvent::EVENT_DOUBLECLICK:
+					if(entries[i]->fileEntry.type == OSFileEntry::TYPE_FOLDER && entries[i]->canSelect) {
+						doChangeFolder = true;
+						if(entries[i]->fileEntry.name == "..") {
+							std::vector<String> bits = currentFolderPath.split("/");
+							newPath = "";
+							if(bits.size() > 2) {
+								for(int i=1; i < bits.size()-1; i++) {
+									newPath += "/"+bits[i];
+								}
+							} else {
+								newPath = "/";
+							}
+						} else{
+							newPath = entries[i]->fileEntry.fullPath;
+						}
+					}
+				break;
+				case InputEvent::EVENT_MOUSEDOWN:
+					if(entries[i]->canSelect) {
+						if(currentEntry)
+							currentEntry->Deselect();
+						entries[i]->Select();
+						currentEntry = entries[i];
+						if(foldersOnly) {
+							selection = entries[i]->fileEntry.fullPath;
+						}
+					}
+				break;
+			}
+		}
+	}
+
+	if(event->getDispatcher() == okButton) {
+		dispatchEvent(new UIEvent(), UIEvent::OK_EVENT);
+	}
+
+	if(event->getDispatcher() == cancelButton) {
+		dispatchEvent(new UIEvent(), UIEvent::CANCEL_EVENT);
+	}
+
+	if(event->getDispatcher() == createFolderWindow->okButton) {
+		CoreServices::getInstance()->getCore()->createFolder(currentFolderPath+"/"+createFolderWindow->nameInput->getText());
+		createFolderWindow->visible = false;
+		createFolderWindow->enabled = false;
+		showFolder(currentFolderPath);	
+	}
+
+	if(event->getDispatcher() == createFolderWindow->cancelButton) {
+		createFolderWindow->visible = false;
+		createFolderWindow->enabled = false;
+	}
+
+
+	if(event->getDispatcher() == newFolderButton) {
+		createFolderWindow->nameInput->setText("");
+		createFolderWindow->visible = true;
+		createFolderWindow->enabled = true;
+		
+	}
+
+	UIWindow::handleEvent(event);
+}
+
+UIFileDialog::~UIFileDialog() {
+
+}
+
+CreateFolderWindow::CreateFolderWindow() : UIWindow("New folder name", 290, 80) {
+	ownsChildren = true;
+	
+	closeBtn->visible = false;
+	closeBtn->enabled = false;
+
+	nameInput = new UITextInput(false, 270, 16);
+	addChild(nameInput);
+	nameInput->setPosition(20, 34);
+
+	cancelButton = new UIButton("Cancel", 100);
+	addChild(cancelButton);
+	cancelButton->setPosition(300-210, 80 - 12);
+
+	okButton = new UIButton("OK",  100);
+	addChild(okButton);
+	okButton->setPosition(300-100, 80 - 12);
+}
+
+CreateFolderWindow::~CreateFolderWindow() {
+	
+}

+ 2 - 1
Modules/Contents/UI/Source/PolyUIHScrollBar.cpp

@@ -172,5 +172,6 @@ void UIHScrollBar::handleEvent(Event *event) {
 
 
 UIHScrollBar::~UIHScrollBar() {
-	
+	delete bgBox;
+	delete handleBox;
 }

+ 8 - 1
Modules/Contents/UI/Source/PolyUIHSizer.cpp

@@ -74,7 +74,14 @@ UIHSizer::UIHSizer(Number width, Number height, Number mainWidth, bool leftSizer
 }
 
 UIHSizer::~UIHSizer() {
-
+	coreInput->removeAllHandlersForListener(this);
+	
+	if (ownsChildren)
+		childElements->ownsChildren = true;
+	delete childElements;
+	
+	delete separatorBgShape;
+	delete separatorHitShape;
 }
 
 void UIHSizer::handleEvent(Event *event) {

+ 3 - 1
Modules/Contents/UI/Source/PolyUIHSlider.cpp

@@ -78,7 +78,9 @@ UIHSlider::UIHSlider(Number start, Number end, Number width) : UIElement() {
 }
 
 UIHSlider::~UIHSlider() {
-
+	delete bgRect;
+	delete gripRect;
+	delete bgHitBox;
 }
 
 void UIHSlider::setSliderValue(Number val) {

+ 2 - 1
Modules/Contents/UI/Source/PolyUIImageButton.cpp

@@ -76,5 +76,6 @@ void UIImageButton::handleEvent(Event *event) {
 }
 
 UIImageButton::~UIImageButton() {
-
+	delete buttonImage;
+	delete buttonRect;
 }

+ 7 - 3
Modules/Contents/UI/Source/PolyUIMenu.cpp

@@ -47,12 +47,10 @@ UIMenuItem::UIMenuItem(String label, String _id, void *data, Number comboWidth,
 	
 	this->_id = _id;
 	this->data = data;
-
-
 }
 
 UIMenuItem::~UIMenuItem() {
-		
+	delete itemLabel;
 }
 
 UIMenu::UIMenu(Number menuWidth) : UIElement() {
@@ -178,6 +176,12 @@ void UIMenu::handleEvent(Event *event) {
 
 
 UIMenu::~UIMenu() {
+	for(int c = 0; c < items.size(); c++)
+		delete items[c];
+	
+	delete dropDownBox;
+	delete selectorBox;
+	
 	CoreServices::getInstance()->getCore()->getInput()->removeAllHandlersForListener(this);
 }
 

+ 2 - 1
Modules/Contents/UI/Source/PolyUIScrollContainer.cpp

@@ -191,5 +191,6 @@ void UIScrollContainer::handleEvent(Event *event) {
 }
 
 UIScrollContainer::~UIScrollContainer() {
-	
+	delete vScrollBar;
+	delete hScrollBar;
 }

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

@@ -1364,7 +1364,15 @@ void UITextInput::Update() {
 }
 
 UITextInput::~UITextInput() {
-
+	delete linesContainer;
+	delete inputRect;
+	delete lineNumberBg;
+	delete lineNumberAnchor;
+	delete selectorRectTop;
+	delete selectorRectMiddle;
+	delete selectorRectBottom;
+	delete blinkerRect;
+	delete blinkTimer;
 }
 
 void UITextInput::readjustBuffer() {

+ 8 - 2
Modules/Contents/UI/Source/PolyUITree.cpp

@@ -249,14 +249,14 @@ void UITree::clearSelection(UITree *selectedNode) {
 
 void UITree::refreshTree() {
 	if(collapsed) {
-		new Tween(&handleRotation, Tween::EASE_IN_QUAD, handleRotation, 0, 0.2f);
+		new Tween(&handleRotation, Tween::EASE_IN_QUAD, handleRotation, 0, 0.2f, false, true);
 		for(int i=0; i < treeChildren.size(); i++) {
 			treeChildren[i]->visible = false;
 			treeChildren[i]->enabled = false;			
 		}
 		treeHeight = 0;
 	} else {
-		new Tween(&handleRotation, Tween::EASE_IN_QUAD, handleRotation, 90, 0.2f);
+		new Tween(&handleRotation, Tween::EASE_IN_QUAD, handleRotation, 90, 0.2f, false, true);
 		int offset = cellHeight;
 		for(int i=0; i < treeChildren.size(); i++) {
 			treeChildren[i]->visible = true;
@@ -286,6 +286,12 @@ void UITree::toggleCollapsed() {
 
 UITree::~UITree() {
 	clearTree();
+	
+	delete textLabel;
+	delete bgBox;
+	delete selection;
+	delete arrowIconImage;
+	delete iconImage;
 }
 
 void UITree::clearTree() {

+ 4 - 1
Modules/Contents/UI/Source/PolyUITreeContainer.cpp

@@ -91,5 +91,8 @@ UITree *UITreeContainer::getRootNode() {
 }
 
 UITreeContainer::~UITreeContainer() {
-	
+	delete bgBox;
+	delete scrollChild;
+	delete rootNode;
+	delete mainContainer;
 }

+ 2 - 1
Modules/Contents/UI/Source/PolyUIVScrollBar.cpp

@@ -205,5 +205,6 @@ void UIVScrollBar::handleEvent(Event *event) {
 	
 
 UIVScrollBar::~UIVScrollBar() {
-	
+	delete bgBox;
+	delete handleBox;
 }

+ 8 - 1
Modules/Contents/UI/Source/PolyUIVSizer.cpp

@@ -74,7 +74,14 @@ UIVSizer::UIVSizer(Number width, Number height, Number mainHeight, bool topSizer
 }
 
 UIVSizer::~UIVSizer() {
-
+	coreInput->removeAllHandlersForListener(this);
+	
+	if (ownsChildren)
+		childElements->ownsChildren = true;
+	delete childElements;
+	
+	delete separatorBgShape;
+	delete separatorHitShape;
 }
 
 void UIVSizer::handleEvent(Event *event) {

+ 28 - 19
Modules/Contents/UI/Source/PolyUIWindow.cpp

@@ -30,8 +30,7 @@
 using namespace Polycode;
 
 
-UIWindow::UIWindow(String windowName, Number width, Number height) : ScreenEntity() {
-	
+UIWindow::UIWindow(String windowName, Number width, Number height) : ScreenEntity(), windowTween(NULL) {
 	closeOnEscape = false;
 	
 	snapToPixels = true;
@@ -112,11 +111,14 @@ void UIWindow::setWindowSize(Number w, Number h) {
 }
 
 UIWindow::~UIWindow() {
-
+	delete windowTween;
+	delete windowRect;
+	delete titlebarRect;
+	delete titleLabel;
+	delete closeBtn;
 }
 
 void UIWindow::onKeyDown(PolyKEY key, wchar_t charCode) {
-	
 	if(key == KEY_TAB) {
 		if(hasFocus) {
 			focusNextChild();
@@ -142,7 +144,7 @@ void UIWindow::onMouseDown(Number x, Number y) {
 	if(hasFocus)
 		return;
 	hasFocus = true;
-	dispatchEvent(new ScreenEvent(), ScreenEvent::ENTITY_MOVE_TOP);
+	//dispatchEvent(new ScreenEvent(), ScreenEvent::ENTITY_MOVE_TOP);
 	for(int i=0; i < children.size(); i++) {
 		if(((ScreenEntity*)children[i])->isFocusable()) {
 			focusChild(((ScreenEntity*)children[i]));
@@ -152,20 +154,24 @@ void UIWindow::onMouseDown(Number x, Number y) {
 }
 
 void UIWindow::showWindow() {
-//	if(!visible) {
-		enabled = true;
-		visible = true;
-		windowTween = new Tween(&color.a, Tween::EASE_IN_QUAD, 0.0f, 1.0f, 0.01f);
-//	}
+	if (windowTween)
+		delete windowTween;
+
+	enabled = true;
+	visible = true;
+	tweenClosing = false;
+	windowTween = new Tween(&color.a, Tween::EASE_IN_QUAD, 0.0f, 1.0f, 0.01f, false, true);
+	windowTween->addEventListener(this, Event::COMPLETE_EVENT);
 }
 
 void UIWindow::hideWindow() {
-//	if(visible) {
-		windowTween = new Tween(&color.a, Tween::EASE_IN_QUAD, 1.0f, 0.0f, 0.01f);
-		windowTween->addEventListener(this, Event::COMPLETE_EVENT);
-//	}
-}
+	if (windowTween)
+		delete windowTween;
 
+	tweenClosing = true;
+	windowTween = new Tween(&color.a, Tween::EASE_IN_QUAD, 1.0f, 0.0f, 0.01f, false, true);
+	windowTween->addEventListener(this, Event::COMPLETE_EVENT);
+}
 
 void UIWindow::handleEvent(Event *event) {
 	if(event->getDispatcher() == titlebarRect) {
@@ -185,8 +191,11 @@ void UIWindow::handleEvent(Event *event) {
 		dispatchEvent(new UIEvent(), UIEvent::CLOSE_EVENT);
 	}
 	if(event->getDispatcher() == windowTween) {
-		visible = false;
-		enabled = false;		
-		windowTween->removeEventListener(this, Event::COMPLETE_EVENT);
+		if (tweenClosing) {
+			visible = false;
+			enabled = false;
+		}
+		
+		windowTween = NULL;
 	}
-}
+}