Kaynağa Gözat

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

Ivan Safrin 12 yıl önce
ebeveyn
işleme
0aca9e2724

+ 85 - 3
Core/Contents/Source/PolySDLCore.cpp

@@ -53,6 +53,16 @@
 	void put_scrap(int type, int srclen, const char *src);
 	void get_scrap(int type, int *dstlen, char **dst);
 	// end SDL scrap
+
+// X11 cursor
+#include <X11/cursorfont.h>
+
+namespace {
+	void set_cursor(int cursorType);
+	void free_cursors();
+} // namespace
+// end X11 cursor
+
 #endif
 
 using namespace Polycode;
@@ -111,11 +121,13 @@ SDLCore::SDLCore(PolycodeView *view, int _xRes, int _yRes, bool fullScreen, bool
 		SDL_JoystickOpen(i);
 		input->addJoystick(i);
 	}
-	
+
+#ifdef USE_X11
 	// Start listening to clipboard events.
 	// (Yes on X11 you need to actively listen to
 	//  clipboard events and respond to them)
 	init_scrap();
+#endif // USE_X11
 
 	((OpenGLRenderer*)renderer)->Init();
 	CoreServices::getInstance()->installModule(new GLSLShaderModule());	
@@ -184,6 +196,9 @@ vector<Polycode::Rectangle> SDLCore::getVideoModes() {
 }
 
 SDLCore::~SDLCore() {
+#ifdef USE_X11
+	free_cursors();
+#endif // USE_X11
 	SDL_Quit();
 }
 
@@ -396,7 +411,9 @@ bool SDLCore::Update() {
 }
 
 void SDLCore::setCursor(int cursorType) {
-
+#ifdef USE_X11
+	set_cursor(cursorType);
+#endif // USE_X11
 }
 
 void SDLCore::warpCursor(int x, int y) {
@@ -446,7 +463,7 @@ void SDLCore::copyDiskItem(const String& itemPath, const String& destItemPath) {
     int childExitStatus;
     pid_t pid = fork();
     if (pid == 0) {
-        execl("/bin/cp", "/bin/cp", "-R", itemPath.c_str(), destItemPath.c_str(), (char *)0);
+        execl("/bin/cp", "/bin/cp", "-RT", itemPath.c_str(), destItemPath.c_str(), (char *)0);
     } else {
         pid_t ws = waitpid( pid, &childExitStatus, 0);
     }
@@ -860,4 +877,69 @@ PRIVATE int clipboard_filter(const SDL_Event *event)
   return(1);
 }
 
+// X11 cursor
+
+namespace {
+
+// WARNING: These functions rely on the SDL_Display and SDL_Window previously initialized by init_scrap
+
+const int CURSOR_COUNT = 7;
+Cursor defined_cursors[CURSOR_COUNT] = {0};
+
+void set_cursor(int cursorType) {
+	Cursor cursor = 0;
+	
+	if(cursorType >= 0 && cursorType < CURSOR_COUNT) {
+		cursor = defined_cursors[cursorType];
+		if(!cursor) {
+			switch(cursorType) {
+				case Polycode::Core::CURSOR_TEXT:
+					cursor = XCreateFontCursor (SDL_Display, XC_xterm);
+				break;
+				case Polycode::Core::CURSOR_POINTER:
+					cursor = XCreateFontCursor (SDL_Display, XC_hand1);
+				break;
+				case Polycode::Core::CURSOR_CROSSHAIR:
+					cursor = XCreateFontCursor (SDL_Display, XC_crosshair);
+				break;
+				case Polycode::Core::CURSOR_RESIZE_LEFT_RIGHT:
+					cursor = XCreateFontCursor (SDL_Display, XC_sb_h_double_arrow);
+				break;
+				case Polycode::Core::CURSOR_RESIZE_UP_DOWN:
+					cursor = XCreateFontCursor (SDL_Display, XC_sb_v_double_arrow);
+				break;
+				case Polycode::Core::CURSOR_OPEN_HAND:
+					cursor = XCreateFontCursor (SDL_Display, XC_fleur);
+				break;
+				case Polycode::Core::CURSOR_ARROW:
+					cursor = 0;
+				break;
+			}
+
+			defined_cursors[cursorType] = cursor;
+		}
+	}
+
+	if(!cursor) {
+		// Restore the normal cursor.
+		XUndefineCursor(SDL_Display, SDL_Window);
+	} else {
+		XDefineCursor(SDL_Display, SDL_Window, cursor);
+	}
+	
+	XFlush(SDL_Display);
+}
+
+void free_cursors() {
+	XUndefineCursor(SDL_Display, SDL_Window);
+	for(int i = 0; i < CURSOR_COUNT; i++) {
+		if(defined_cursors[i]) {
+			XFreeCursor(SDL_Display, defined_cursors[i]);
+			defined_cursors[i] = 0;
+		}
+	}
+}
+} // namespace
+// end X11 cursor
+
 #endif // USE_X11

+ 13 - 0
IDE/Contents/CMakeLists.txt

@@ -1,3 +1,16 @@
+# This CMakeLists.txt is a cross-platform alternative to the $Polycode/IDE/Build/$OS
+# build systems. 
+#
+# It also demonstrates how Polycode projects other than the IDE can be built.
+# First a few variables need to be set:
+# * POLYCODE_ROOT_DIR
+# * POLYCODE_RELEASE_DIR
+# * POLYCODE_CMAKE_DIR
+# * CMAKE_INSTALL_PREFIX
+# Then we can simply include ${POLYCODE_CMAKE_DIR}/PolycodeDependencies.cmake
+# After that, ${POLYCODE_DEPENDENCY_LIBS} will be set to the paths of our required
+# link libraries, which we can simply add to our IDE project with TARGET_LINK_LIBRARIES
+
 CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
 
 PROJECT(PolycodeIDE)

+ 20 - 8
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -357,6 +357,7 @@ void PolycodeIDEApp::openProject() {
 	exts.push_back("polyproject");
 	frame->showFileBrowser(CoreServices::getInstance()->getCore()->getUserHomeDirectory(),	false, exts, false);
 	frame->fileDialog->addEventListener(this, UIEvent::OK_EVENT);
+	frame->fileDialog->action = "openProject";
 #else
 	vector<CoreFileExtension> extensions;
 	CoreFileExtension ext;
@@ -453,7 +454,13 @@ void PolycodeIDEApp::runProject() {
 }
 
 void PolycodeIDEApp::addFiles() {
-	if(projectManager->getActiveProject()) {	
+	if(projectManager->getActiveProject()) {
+#ifdef USE_POLYCODEUI_FILE_DIALOGS
+		std::vector<String> exts;
+		frame->showFileBrowser(CoreServices::getInstance()->getCore()->getUserHomeDirectory(),	false, exts, false);
+		frame->fileDialog->addEventListener(this, UIEvent::OK_EVENT);
+		frame->fileDialog->action = "addFiles";
+#else	
 		vector<CoreFileExtension> extensions;		
 		std::vector<String> files = core->openFilePicker(extensions, true);				
 		
@@ -462,8 +469,9 @@ void PolycodeIDEApp::addFiles() {
 			core->copyDiskItem(files[i], projectManager->activeFolder + "/" + entry.name);
 		}
 		
-		frame->getProjectBrowser()->refreshProject(projectManager->getActiveProject());		
-	}			
+		frame->getProjectBrowser()->refreshProject(projectManager->getActiveProject());
+#endif
+	}		
 }
 
 void PolycodeIDEApp::findText() {
@@ -577,12 +585,16 @@ void PolycodeIDEApp::handleEvent(Event *event) {
 		if(event->getEventCode() == UIEvent::OK_EVENT && event->getEventType() == "UIEvent") {
 			String path = frame->fileDialog->getSelection();
 			if(path != "") {
-				PolycodeProject *project = projectManager->openProject(path);
-				if(project) {
-					projectManager->setActiveProject(project);
-					OSFileEntry projectEntry =	OSFileEntry(project->getProjectFile(), OSFileEntry::TYPE_FILE);
+				if(frame->fileDialog->action == "openProject") {
+					PolycodeProject *project = projectManager->openProject(path);
+					if(project) {
+						projectManager->setActiveProject(project);
+					}
+				} else if(frame->fileDialog->action == "addFiles") {
+					OSFileEntry entry = OSFileEntry(path, OSFileEntry::TYPE_FILE);
+					core->copyDiskItem(path, projectManager->activeFolder + "/" + entry.name);
+					frame->getProjectBrowser()->refreshProject(projectManager->getActiveProject());
 				}
-				
 			}
 		}
 	}

+ 40 - 6
Modules/Contents/UI/Include/PolyUIFileDialog.h

@@ -1,16 +1,16 @@
 /*
  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
@@ -31,7 +31,7 @@
 #include "PolyInputEvent.h"
 
 namespace Polycode {
-	
+
 	class CreateFolderWindow : public UIWindow {
 		public:
 			CreateFolderWindow();
@@ -57,23 +57,57 @@ namespace Polycode {
 			ScreenImage *icon;
 	};
 
+	/**
+	 * A dialog that allows the user to choose a file or directory from a
+	 * file system.
+	 */
 	class UIFileDialog : public UIWindow {
 		public:
+			/**
+			 * Create a new file dialog.
+			 *
+			 * @param baseDir The top-level directory, only entries in this directory and below can be selected.
+			 * @param foldersOnly If true, directories will be selected. If false, files will be selected.
+			 * @param extensions A list of accepted file extensions.
+			 * @param allowMultiple If true, multiple entries can be selected at once.
+			 */
 			UIFileDialog(String baseDir, bool foldersOnly, std::vector<String> extensions, bool allowMultiple);
 			virtual ~UIFileDialog();
 
 			void onClose();
 			void handleEvent(Event *event);
+
+			/**
+			 * Clears all entries in the file dialog.
+			 */
 			void clearEntries();
+
+			/**
+			 * Set a new top-level directory to display.
+			 */
 			void showFolder(String folderPath);
-	
+
+			/**
+			 * Returns whether a file with a specific file extension
+			 * can be selected.
+			 *
+			 * @param extension The file extension to be tested.
+			 */
 			bool canOpen(String extension);
 
 			void addToSidebar(String path, String name);
 
 			void Update();
 
+			/**
+			 * Get the selected entry.
+			 *
+			 * @return Full path of the selected entry
+			 * 		   (base path + relative path to top level directory)
+			 */
 			String getSelection();
+
+			String action;
 		protected:
 
 			String selection;
@@ -99,7 +133,7 @@ namespace Polycode {
 			std::vector<String> extensions;
 			std::vector<UIFileDialogEntry*> entries;
 			std::vector<UIFileDialogEntry*> sideBarEntries;
-			UIElement *entryHolder;		
+			UIElement *entryHolder;
 	};
 }
 

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

@@ -118,6 +118,10 @@ UIFileDialog::UIFileDialog(String baseDir, bool foldersOnly, std::vector<String>
 }
 
 bool UIFileDialog::canOpen(String extension) {
+	if(extensions.empty()) {
+		return true;
+	}
+	
 	for(int i=0; i < extensions.size(); i++) {
 		if(extensions[i] == extension) {
 			return true;

+ 2 - 2
Toolchain-mingw32.cmake

@@ -6,8 +6,8 @@ SET(CMAKE_C_COMPILER i486-mingw32-gcc)
 SET(CMAKE_CXX_COMPILER i486-mingw32-g++)
 SET(CMAKE_RC_COMPILER i486-mingw32-windres)
 
-# here is the target environment located
-SET(POLYCODE_DIRECTORY "/home/cib/projects/Polycode")
+# here is the target environment located, please replace /path/to/Polycode with the absolute path to your polycode installation
+SET(POLYCODE_DIRECTORY "/path/to/Polycode")
 SET(CMAKE_FIND_ROOT_PATH  /usr/i486-mingw32; ${POLYCODE_DIRECTORY}/Release/Windows/Framework/Core/Dependencies; ${POLYCODE_DIRECTORY}/Release/Windows/Framework/Tools/Dependencies; /home/cib/projects/Polycode/Release/Windows/Framework/Modules/Dependencies; )
 
 # adjust the default behaviour of the FIND_XXX() commands: