mirror of https://github.com/aseprite/aseprite.git
				
				
				
			Merge branch 'dev' of git@github.com:aseprite/aseprite.git into gfx
This commit is contained in:
		
						commit
						f9612eb666
					
				|  | @ -0,0 +1,21 @@ | |||
| GIMP Palette | ||||
| # | ||||
| # by Arne Niklas Jansson | ||||
| # http://androidarts.com/ | ||||
| # | ||||
|   0   0   0	Untitled | ||||
| 157 157 157	Untitled | ||||
| 255 255 255	Untitled | ||||
| 190  38  51	Untitled | ||||
| 224 111 139	Untitled | ||||
|  73  60  43	Untitled | ||||
| 164 100  34	Untitled | ||||
| 235 137  49	Untitled | ||||
| 247 226 107	Untitled | ||||
|  47  72  78	Untitled | ||||
|  68 137  26	Untitled | ||||
| 163 206  39	Untitled | ||||
|  27  38  50	Untitled | ||||
|   0  87 132	Untitled | ||||
|  49 162 242	Untitled | ||||
| 178 220 239	Untitled | ||||
|  | @ -0,0 +1,36 @@ | |||
| GIMP Palette | ||||
| # | ||||
| # by Arne Niklas Jansson | ||||
| # http://androidarts.com/ | ||||
| # | ||||
| 190  38  51	Untitled | ||||
| 115  41  48	Untitled | ||||
| 203  92 207	Untitled | ||||
| 224 111 139	Untitled | ||||
| 150  75 168	Untitled | ||||
| 158 115 235	Untitled | ||||
|  52  42 151	Untitled | ||||
|  36  90 239	Untitled | ||||
|  27  38  50	Untitled | ||||
|  49 162 242	Untitled | ||||
|   0  87 132	Untitled | ||||
| 105 113 117	Untitled | ||||
| 178 220 239	Untitled | ||||
|  47  72  78	Untitled | ||||
|  20 128 126	Untitled | ||||
|  39 193 167	Untitled | ||||
|  33  92  46	Untitled | ||||
|  68 137  26	Untitled | ||||
| 163 206  39	Untitled | ||||
|  71  81  32	Untitled | ||||
| 188 179  48	Untitled | ||||
| 247 226 107	Untitled | ||||
| 238 182  47	Untitled | ||||
|  73  60  43	Untitled | ||||
| 164 100  34	Untitled | ||||
| 235 137  49	Untitled | ||||
| 247 176 128	Untitled | ||||
| 218  66   0	Untitled | ||||
| 255 255 255	Untitled | ||||
| 204 204 204	Untitled | ||||
| 157 157 157	Untitled | ||||
|  | @ -0,0 +1,21 @@ | |||
| GIMP Palette | ||||
| # | ||||
| # by Richard "DawnBringer" Fhager | ||||
| # http://www.pixeljoint.com/p/23821.htm | ||||
| # | ||||
|  20  12  28	Untitled | ||||
|  68  36  52	Untitled | ||||
|  48  52 109	Untitled | ||||
|  78  74  78	Untitled | ||||
| 133  76  48	Untitled | ||||
|  52 101  36	Untitled | ||||
| 208  70  72	Untitled | ||||
| 117 113  97	Untitled | ||||
|  89 125 206	Untitled | ||||
| 210 125  44	Untitled | ||||
| 133 149 161	Untitled | ||||
| 109 170  44	Untitled | ||||
| 210 170 153	Untitled | ||||
| 109 194 202	Untitled | ||||
| 218 212  94	Untitled | ||||
| 222 238 214	Untitled | ||||
|  | @ -0,0 +1,37 @@ | |||
| GIMP Palette | ||||
| # | ||||
| # by Richard "DawnBringer" Fhager | ||||
| # http://www.pixeljoint.com/p/23821.htm | ||||
| # | ||||
|   0   0   0	Untitled | ||||
|  34  32  52	Untitled | ||||
|  69  40  60	Untitled | ||||
| 102  57  49	Untitled | ||||
| 143  86  59	Untitled | ||||
| 223 113  38	Untitled | ||||
| 217 160 102	Untitled | ||||
| 238 195 154	Untitled | ||||
| 251 242  54	Untitled | ||||
| 153 229  80	Untitled | ||||
| 106 190  48	Untitled | ||||
|  55 148 110	Untitled | ||||
|  75 105  47	Untitled | ||||
|  82  75  36	Untitled | ||||
|  50  60  57	Untitled | ||||
|  63  63 116	Untitled | ||||
|  48  96 130	Untitled | ||||
|  91 110 225	Untitled | ||||
|  99 155 255	Untitled | ||||
|  95 205 228	Untitled | ||||
| 203 219 252	Untitled | ||||
| 255 255 255	Untitled | ||||
| 155 173 183	Untitled | ||||
| 132 126 135	Untitled | ||||
| 105 106 106	Untitled | ||||
|  89  86  82	Untitled | ||||
| 118  66 138	Untitled | ||||
| 172  50  50	Untitled | ||||
| 217  87  99	Untitled | ||||
| 215 123 186	Untitled | ||||
| 143 151  74	Untitled | ||||
| 138 111  48	Untitled | ||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							|  | @ -0,0 +1,13 @@ | |||
| <!-- ASEPRITE --> | ||||
| <!-- Copyright (C) 2014 by David Capello --> | ||||
| <gui> | ||||
|   <vbox id="mainbox"> | ||||
|     <label text="Available Palettes:" /> | ||||
|     <view id="view" expansive="true" /> | ||||
|     <hbox> | ||||
|       <hbox expansive="true" /> | ||||
|       <button id="load" text="Load" width="60" /> | ||||
|       <button id="openfolder" text="Open Folder" width="60" /> | ||||
|     </hbox> | ||||
|   </vbox> | ||||
| </gui> | ||||
|  | @ -75,6 +75,7 @@ add_library(app-lib | |||
|   commands/cmd_save_mask.cpp | ||||
|   commands/cmd_save_palette.cpp | ||||
|   commands/cmd_scroll.cpp | ||||
|   commands/cmd_set_palette.cpp | ||||
|   commands/cmd_sprite_editor.cpp | ||||
|   commands/cmd_sprite_properties.cpp | ||||
|   commands/cmd_sprite_size.cpp | ||||
|  | @ -134,6 +135,7 @@ add_library(app-lib | |||
|   modules/gui.cpp | ||||
|   modules/palettes.cpp | ||||
|   objects_container_impl.cpp | ||||
|   palettes_loader.cpp | ||||
|   project.cpp | ||||
|   recent_files.cpp | ||||
|   resource_finder.cpp | ||||
|  | @ -176,6 +178,8 @@ add_library(app-lib | |||
|   ui/main_menu_bar.cpp | ||||
|   ui/main_window.cpp | ||||
|   ui/mini_editor.cpp | ||||
|   ui/palette_listbox.cpp | ||||
|   ui/palette_popup.cpp | ||||
|   ui/palette_view.cpp | ||||
|   ui/popup_window_pin.cpp | ||||
|   ui/skin/button_icon_impl.cpp | ||||
|  |  | |||
|  | @ -151,11 +151,13 @@ App::App(int argc, const char* argv[]) | |||
|     PRINTF("Loading custom palette file: %s\n", palFile.c_str()); | ||||
| 
 | ||||
|     base::UniquePtr<Palette> pal(Palette::load(palFile.c_str())); | ||||
|     if (pal.get() == NULL) | ||||
|       throw base::Exception("Error loading default palette from: %s", palFile.c_str()); | ||||
| 
 | ||||
|     if (pal.get() != NULL) { | ||||
|       set_default_palette(pal.get()); | ||||
|     } | ||||
|     else { | ||||
|       PRINTF("Error loading custom palette file\n"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   // Set system palette to the default one.
 | ||||
|   set_current_palette(NULL, true); | ||||
|  |  | |||
|  | @ -20,18 +20,15 @@ | |||
| #include "config.h" | ||||
| #endif | ||||
| 
 | ||||
| #include "app/commands/cmd_set_palette.h" | ||||
| #include "app/commands/command.h" | ||||
| #include "app/context_access.h" | ||||
| #include "app/document_api.h" | ||||
| #include "app/commands/commands.h" | ||||
| #include "app/context.h" | ||||
| #include "app/file_selector.h" | ||||
| #include "app/ini_file.h" | ||||
| #include "app/modules/palettes.h" | ||||
| #include "app/undo_transaction.h" | ||||
| #include "base/compiler_specific.h" | ||||
| #include "base/unique_ptr.h" | ||||
| #include "raster/palette.h" | ||||
| #include "ui/alert.h" | ||||
| #include "ui/manager.h" | ||||
| 
 | ||||
| namespace app { | ||||
| 
 | ||||
|  | @ -55,30 +52,18 @@ LoadPaletteCommand::LoadPaletteCommand() | |||
| 
 | ||||
| void LoadPaletteCommand::onExecute(Context* context) | ||||
| { | ||||
|   ContextWriter writer(context); | ||||
| 
 | ||||
|   base::string filename = app::show_file_selector("Load Palette", "", "png,pcx,bmp,tga,lbm,col,gpl"); | ||||
|   if (!filename.empty()) { | ||||
|     base::UniquePtr<raster::Palette> palette(raster::Palette::load(filename.c_str())); | ||||
|     if (!palette) { | ||||
|       Alert::show("Error<<Loading palette file||&Close"); | ||||
|     } | ||||
|     else if (writer.document()) { | ||||
|       UndoTransaction undoTransaction(writer.context(), "Load Palette"); | ||||
|       writer.document()->getApi() | ||||
|         .setPalette(writer.sprite(), writer.frame(), palette); | ||||
|       undoTransaction.commit(); | ||||
|     } | ||||
|     else { | ||||
|       set_default_palette(palette); | ||||
|       set_config_string("GfxMode", "Palette", filename.c_str()); | ||||
|       SetPaletteCommand* cmd = static_cast<SetPaletteCommand*>( | ||||
|         CommandsModule::instance()->getCommandByName(CommandId::SetPalette)); | ||||
|       cmd->setPalette(palette); | ||||
|       context->executeCommand(cmd); | ||||
|     } | ||||
| 
 | ||||
|     // Set the palette calling the hooks
 | ||||
|     set_current_palette(palette, false); | ||||
| 
 | ||||
|     // Redraw the entire screen
 | ||||
|     ui::Manager::getDefault()->invalidate(); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -51,8 +51,8 @@ public: | |||
|   Command* clone() const OVERRIDE { return new OpenFileCommand(*this); } | ||||
| 
 | ||||
| protected: | ||||
|   void onLoadParams(Params* params); | ||||
|   void onExecute(Context* context); | ||||
|   void onLoadParams(Params* params) OVERRIDE; | ||||
|   void onExecute(Context* context) OVERRIDE; | ||||
| 
 | ||||
| private: | ||||
|   std::string m_filename; | ||||
|  |  | |||
|  | @ -0,0 +1,80 @@ | |||
| /* Aseprite
 | ||||
|  * Copyright (C) 2001-2014  David Capello | ||||
|  * | ||||
|  * This program is free software; you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation; either version 2 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU General Public License | ||||
|  * along with this program; if not, write to the Free Software | ||||
|  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||
|  */ | ||||
| 
 | ||||
| #ifdef HAVE_CONFIG_H | ||||
| #include "config.h" | ||||
| #endif | ||||
| 
 | ||||
| #include "app/commands/cmd_set_palette.h" | ||||
| #include "app/context_access.h" | ||||
| #include "app/document_api.h" | ||||
| #include "app/file_selector.h" | ||||
| #include "app/ini_file.h" | ||||
| #include "app/modules/palettes.h" | ||||
| #include "app/undo_transaction.h" | ||||
| #include "base/compiler_specific.h" | ||||
| #include "base/unique_ptr.h" | ||||
| #include "raster/palette.h" | ||||
| #include "ui/alert.h" | ||||
| #include "ui/manager.h" | ||||
| 
 | ||||
| namespace app { | ||||
| 
 | ||||
| using namespace ui; | ||||
| 
 | ||||
| SetPaletteCommand::SetPaletteCommand() | ||||
|   : Command("SetPalette", | ||||
|             "Set Palette", | ||||
|             CmdRecordableFlag) | ||||
|   , m_palette(NULL) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| void SetPaletteCommand::onExecute(Context* context) | ||||
| { | ||||
|   ASSERT(m_palette); | ||||
|   if (!m_palette) | ||||
|     return; | ||||
| 
 | ||||
|   ContextWriter writer(context); | ||||
| 
 | ||||
|   if (writer.document()) { | ||||
|     UndoTransaction undoTransaction(writer.context(), "Set Palette"); | ||||
|     writer.document()->getApi() | ||||
|       .setPalette(writer.sprite(), writer.frame(), m_palette); | ||||
|     undoTransaction.commit(); | ||||
|   } | ||||
|   // Set default palette
 | ||||
|   else { | ||||
|     set_default_palette(m_palette); | ||||
|     set_config_string("GfxMode", "Palette", m_palette->getFilename().c_str()); | ||||
|   } | ||||
| 
 | ||||
|   // Set the palette calling the hooks
 | ||||
|   set_current_palette(m_palette, false); | ||||
| 
 | ||||
|   // Redraw the entire screen
 | ||||
|   ui::Manager::getDefault()->invalidate(); | ||||
| } | ||||
| 
 | ||||
| Command* CommandFactory::createSetPaletteCommand() | ||||
| { | ||||
|   return new SetPaletteCommand; | ||||
| } | ||||
| 
 | ||||
| } // namespace app
 | ||||
|  | @ -0,0 +1,48 @@ | |||
| /* Aseprite
 | ||||
|  * Copyright (C) 2001-2014  David Capello | ||||
|  * | ||||
|  * This program is free software; you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation; either version 2 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU General Public License | ||||
|  * along with this program; if not, write to the Free Software | ||||
|  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||
|  */ | ||||
| 
 | ||||
| #ifndef APP_COMMANDS_CMD_SET_PALETTE_H_INCLUDED | ||||
| #define APP_COMMANDS_CMD_SET_PALETTE_H_INCLUDED | ||||
| #pragma once | ||||
| 
 | ||||
| #include "app/commands/command.h" | ||||
| #include "base/compiler_specific.h" | ||||
| 
 | ||||
| namespace raster { | ||||
|   class Palette; | ||||
| } | ||||
| 
 | ||||
| namespace app { | ||||
| 
 | ||||
|   class SetPaletteCommand : public Command { | ||||
|   public: | ||||
|     SetPaletteCommand(); | ||||
|     Command* clone() const OVERRIDE { return new SetPaletteCommand(*this); } | ||||
| 
 | ||||
|     void setPalette(raster::Palette* palette) { m_palette = palette; } | ||||
| 
 | ||||
|   protected: | ||||
|     virtual void onExecute(Context* context) OVERRIDE; | ||||
| 
 | ||||
|   private: | ||||
|     raster::Palette* m_palette; | ||||
|   }; | ||||
| 
 | ||||
| } // namespace app
 | ||||
| 
 | ||||
| #endif | ||||
|  | @ -97,6 +97,7 @@ FOR_EACH_COMMAND(SaveFileCopyAs) | |||
| FOR_EACH_COMMAND(SaveMask) | ||||
| FOR_EACH_COMMAND(SavePalette) | ||||
| FOR_EACH_COMMAND(Scroll) | ||||
| FOR_EACH_COMMAND(SetPalette) | ||||
| FOR_EACH_COMMAND(ShowGrid) | ||||
| FOR_EACH_COMMAND(SnapToGrid) | ||||
| FOR_EACH_COMMAND(SplitEditorHorizontally) | ||||
|  |  | |||
|  | @ -0,0 +1,117 @@ | |||
| /* Aseprite
 | ||||
|  * Copyright (C) 2001-2014  David Capello | ||||
|  * | ||||
|  * This program is free software; you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation; either version 2 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU General Public License | ||||
|  * along with this program; if not, write to the Free Software | ||||
|  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||
|  */ | ||||
| 
 | ||||
| #ifdef HAVE_CONFIG_H | ||||
| #include "config.h" | ||||
| #endif | ||||
| 
 | ||||
| #include "app/palettes_loader.h" | ||||
| 
 | ||||
| #include "app/file_system.h" | ||||
| #include "app/resource_finder.h" | ||||
| #include "base/bind.h" | ||||
| #include "base/fs.h" | ||||
| #include "base/path.h" | ||||
| #include "base/scoped_value.h" | ||||
| #include "raster/palette.h" | ||||
| 
 | ||||
| namespace app { | ||||
| 
 | ||||
| PalettesLoader::PalettesLoader() | ||||
|   : m_done(false) | ||||
|   , m_cancel(false) | ||||
|   , m_thread(Bind<void>(&PalettesLoader::threadLoadPalettes, this)) | ||||
| { | ||||
|   PRINTF("PalettesLoader::PalettesLoader()\n"); | ||||
| } | ||||
| 
 | ||||
| PalettesLoader::~PalettesLoader() | ||||
| { | ||||
|   m_thread.join(); | ||||
| 
 | ||||
|   PRINTF("PalettesLoader::~PalettesLoader()\n"); | ||||
| } | ||||
| 
 | ||||
| void PalettesLoader::cancel() | ||||
| { | ||||
|   m_cancel = true; | ||||
| } | ||||
| 
 | ||||
| bool PalettesLoader::done() | ||||
| { | ||||
|   return m_done; | ||||
| } | ||||
| 
 | ||||
| bool PalettesLoader::next(base::UniquePtr<raster::Palette>& palette, std::string& name) | ||||
| { | ||||
|   Item item; | ||||
|   if (m_queue.try_pop(item)) { | ||||
|     palette.reset(item.palette); | ||||
|     name = item.name; | ||||
|     return true; | ||||
|   } | ||||
|   else | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| // static
 | ||||
| std::string PalettesLoader::palettesLocation() | ||||
| { | ||||
|   std::string path; | ||||
|   ResourceFinder rf; | ||||
|   rf.includeDataDir("palettes"); | ||||
|   while (rf.next()) { | ||||
|     if (base::directory_exists(rf.filename())) { | ||||
|       path = rf.filename(); | ||||
|       break; | ||||
|     } | ||||
|   } | ||||
|   return base::fix_path_separators(path); | ||||
| } | ||||
| 
 | ||||
| void PalettesLoader::threadLoadPalettes() | ||||
| { | ||||
|   PRINTF("threadLoadPalettes()\n"); | ||||
| 
 | ||||
|   base::ScopedValue<bool> scoped(m_done, false, true); | ||||
| 
 | ||||
|   std::string path = palettesLocation(); | ||||
|   PRINTF("Loading palettes from %s...\n", path.c_str()); | ||||
|   if (path.empty()) | ||||
|     return; | ||||
| 
 | ||||
|   IFileItem* item = FileSystemModule::instance()->getFileItemFromPath(path); | ||||
|   if (!item) | ||||
|     return; | ||||
| 
 | ||||
|   FileItemList list = item->getChildren(); | ||||
|   for (FileItemList::iterator it=list.begin(), end=list.end(); | ||||
|        it != end; ++it) { | ||||
|     if (m_cancel) | ||||
|       break; | ||||
| 
 | ||||
|     raster::Palette* palette = | ||||
|       raster::Palette::load((*it)->getFileName().c_str()); | ||||
|      | ||||
|     if (palette) { | ||||
|       m_queue.push(Item(palette, base::get_file_title((*it)->getFileName()))); | ||||
|     } | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| } // namespace app
 | ||||
|  | @ -0,0 +1,69 @@ | |||
| /* Aseprite
 | ||||
|  * Copyright (C) 2001-2014  David Capello | ||||
|  * | ||||
|  * This program is free software; you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation; either version 2 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU General Public License | ||||
|  * along with this program; if not, write to the Free Software | ||||
|  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||
|  */ | ||||
| 
 | ||||
| #ifndef APP_PALETTES_LOADER_H_INCLUDED | ||||
| #define APP_PALETTES_LOADER_H_INCLUDED | ||||
| #pragma once | ||||
| 
 | ||||
| #include "base/concurrent_queue.h" | ||||
| #include "base/thread.h" | ||||
| #include "base/unique_ptr.h" | ||||
| 
 | ||||
| namespace raster { | ||||
|   class Palette; | ||||
| } | ||||
| 
 | ||||
| namespace app { | ||||
| 
 | ||||
|   class PalettesLoader { | ||||
|   public: | ||||
|     PalettesLoader(); | ||||
|     ~PalettesLoader(); | ||||
| 
 | ||||
|     void cancel(); | ||||
|     bool done(); | ||||
|     bool isDone() const { return m_done; } | ||||
| 
 | ||||
|     bool next(base::UniquePtr<raster::Palette>& palette, std::string& name); | ||||
| 
 | ||||
|     static std::string palettesLocation(); | ||||
| 
 | ||||
|   private: | ||||
|     void threadLoadPalettes(); | ||||
| 
 | ||||
|     struct Item { | ||||
|       raster::Palette* palette; | ||||
|       std::string name; | ||||
|       Item() : palette(NULL) { | ||||
|       } | ||||
|       Item(raster::Palette* palette, const std::string& name) | ||||
|         : palette(palette), name(name) { | ||||
|       } | ||||
|     }; | ||||
| 
 | ||||
|     typedef base::concurrent_queue<Item> Queue; | ||||
| 
 | ||||
|     bool m_done; | ||||
|     bool m_cancel; | ||||
|     Queue m_queue; | ||||
|     base::thread m_thread; | ||||
|   }; | ||||
| 
 | ||||
| } // namespace app
 | ||||
| 
 | ||||
| #endif | ||||
|  | @ -34,9 +34,12 @@ | |||
| #include "app/ui_context.h" | ||||
| #include "base/bind.h" | ||||
| #include "raster/image.h" | ||||
| #include "raster/palette.h" | ||||
| #include "ui/graphics.h" | ||||
| #include "ui/paint_event.h" | ||||
| 
 | ||||
| #include "ui/menu.h" | ||||
| 
 | ||||
| namespace app { | ||||
| 
 | ||||
| using namespace app::skin; | ||||
|  | @ -74,7 +77,7 @@ ColorBar* ColorBar::m_instance = NULL; | |||
| 
 | ||||
| ColorBar::ColorBar(int align) | ||||
|   : Box(align) | ||||
|   , m_paletteButton("Edit Palette", kButtonWidget) | ||||
|   , m_paletteButton("Edit Palette") | ||||
|   , m_paletteView(false) | ||||
|   , m_fgColor(app::Color::fromIndex(15), IMAGE_INDEXED) | ||||
|   , m_bgColor(app::Color::fromIndex(0), IMAGE_INDEXED) | ||||
|  | @ -123,8 +126,9 @@ ColorBar::ColorBar(int align) | |||
|   m_paletteView.setBgColor(((SkinTheme*)getTheme())->getColor(ThemeColor::TabSelectedFace)); | ||||
| 
 | ||||
|   // Change labels foreground color
 | ||||
|   setup_mini_font(setup_mini_look(&m_paletteButton)); | ||||
|   setup_mini_font(m_paletteButton.mainButton()); | ||||
|   m_paletteButton.Click.connect(Bind<void>(&ColorBar::onPaletteButtonClick, this)); | ||||
|   m_paletteButton.DropDownClick.connect(Bind<void>(&ColorBar::onPaletteButtonDropDownClick, this)); | ||||
| 
 | ||||
|   onColorButtonChange(getFgColor()); | ||||
| } | ||||
|  | @ -183,6 +187,15 @@ void ColorBar::onPaletteButtonClick() | |||
|   UIContext::instance()->executeCommand(cmd_show_palette_editor, ¶ms); | ||||
| } | ||||
| 
 | ||||
| void ColorBar::onPaletteButtonDropDownClick() | ||||
| { | ||||
|   gfx::Rect bounds = m_paletteButton.getBounds(); | ||||
| 
 | ||||
|   m_palettePopup.showPopup( | ||||
|     gfx::Rect(bounds.x+bounds.w, bounds.y, | ||||
|       JI_SCREEN_W/2, JI_SCREEN_H/2)); | ||||
| } | ||||
| 
 | ||||
| void ColorBar::onPaletteIndexChange(int index) | ||||
| { | ||||
|   m_lock = true; | ||||
|  |  | |||
|  | @ -22,17 +22,20 @@ | |||
| 
 | ||||
| #include "app/color.h" | ||||
| #include "app/ui/color_button.h" | ||||
| #include "app/ui/drop_down_button.h" | ||||
| #include "app/ui/palette_popup.h" | ||||
| #include "app/ui/palette_view.h" | ||||
| #include "base/compiler_specific.h" | ||||
| #include "base/signal.h" | ||||
| #include "base/unique_ptr.h" | ||||
| #include "raster/pixel_format.h" | ||||
| #include "ui/box.h" | ||||
| #include "ui/button.h" | ||||
| #include "ui/view.h" | ||||
| 
 | ||||
| namespace app { | ||||
|   class PaletteView; | ||||
|   class ColorButton; | ||||
|   class PalettesLoader; | ||||
| 
 | ||||
|   class ColorBar : public ui::Box { | ||||
|     static ColorBar* m_instance; | ||||
|  | @ -61,21 +64,22 @@ namespace app { | |||
| 
 | ||||
|   protected: | ||||
|     void onPaletteButtonClick(); | ||||
|     void onPaletteButtonDropDownClick(); | ||||
|     void onPaletteIndexChange(int index); | ||||
|     void onFgColorButtonChange(const app::Color& color); | ||||
|     void onBgColorButtonChange(const app::Color& color); | ||||
|     void onColorButtonChange(const app::Color& color); | ||||
| 
 | ||||
|   private: | ||||
|     class ScrollableView : public ui::View | ||||
|     { | ||||
|     class ScrollableView : public ui::View { | ||||
|     public: | ||||
|       ScrollableView(); | ||||
|     protected: | ||||
|       void onPaint(ui::PaintEvent& ev) OVERRIDE; | ||||
|     }; | ||||
| 
 | ||||
|     ui::CheckBox m_paletteButton; | ||||
|     DropDownButton m_paletteButton; | ||||
|     PalettePopup m_palettePopup; | ||||
|     ScrollableView m_scrollableView; | ||||
|     PaletteView m_paletteView; | ||||
|     ColorButton m_fgColor; | ||||
|  |  | |||
|  | @ -34,6 +34,9 @@ namespace app { | |||
|   public: | ||||
|     DropDownButton(const char* text); | ||||
| 
 | ||||
|     ui::Button* mainButton() { return m_button; } | ||||
|     ui::Button* dropDown() { return m_dropDown; } | ||||
| 
 | ||||
|     Signal0<void> Click; | ||||
|     Signal0<void> DropDownClick; | ||||
| 
 | ||||
|  |  | |||
|  | @ -0,0 +1,217 @@ | |||
| /* Aseprite
 | ||||
|  * Copyright (C) 2001-2014  David Capello | ||||
|  * | ||||
|  * This program is free software; you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation; either version 2 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU General Public License | ||||
|  * along with this program; if not, write to the Free Software | ||||
|  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||
|  */ | ||||
| 
 | ||||
| #ifdef HAVE_CONFIG_H | ||||
| #include "config.h" | ||||
| #endif | ||||
| 
 | ||||
| #include "app/ui/palette_listbox.h" | ||||
| 
 | ||||
| #include "app/modules/palettes.h" | ||||
| #include "app/palettes_loader.h" | ||||
| #include "app/ui/skin/skin_theme.h" | ||||
| #include "base/bind.h" | ||||
| #include "raster/palette.h" | ||||
| #include "ui/graphics.h" | ||||
| #include "ui/listitem.h" | ||||
| #include "ui/message.h" | ||||
| #include "ui/paint_event.h" | ||||
| #include "ui/preferred_size_event.h" | ||||
| 
 | ||||
| namespace app { | ||||
| 
 | ||||
| using namespace ui; | ||||
| using namespace skin; | ||||
| 
 | ||||
| class PaletteListItem : public ListItem { | ||||
| public: | ||||
|   PaletteListItem(raster::Palette* palette, const std::string& name) | ||||
|     : ListItem(name), m_palette(palette) { | ||||
|   } | ||||
| 
 | ||||
|   raster::Palette* palette() const { | ||||
|     return m_palette; | ||||
|   } | ||||
| 
 | ||||
| protected: | ||||
|   bool onProcessMessage(ui::Message* msg) OVERRIDE { | ||||
|     switch (msg->type()) { | ||||
|       case kMouseLeaveMessage: | ||||
|       case kMouseEnterMessage: | ||||
|         invalidate(); | ||||
|         break; | ||||
|     } | ||||
|     return ListItem::onProcessMessage(msg); | ||||
|   } | ||||
| 
 | ||||
|   void onPaint(PaintEvent& ev) OVERRIDE { | ||||
|     SkinTheme* theme = static_cast<SkinTheme*>(getTheme()); | ||||
|     Graphics* g = ev.getGraphics(); | ||||
|     gfx::Rect bounds = getClientBounds(); | ||||
|     ui::Color bgcolor, fgcolor; | ||||
| 
 | ||||
|     if (isSelected()) { | ||||
|       bgcolor = theme->getColor(ThemeColor::ListItemSelectedFace); | ||||
|       fgcolor = theme->getColor(ThemeColor::ListItemSelectedText); | ||||
|     } | ||||
|     else { | ||||
|       bgcolor = theme->getColor(ThemeColor::ListItemNormalFace); | ||||
|       fgcolor = theme->getColor(ThemeColor::ListItemNormalText); | ||||
|     } | ||||
| 
 | ||||
|     g->fillRect(bgcolor, bounds); | ||||
| 
 | ||||
|     gfx::Rect box( | ||||
|       bounds.x, bounds.y+bounds.h-6*jguiscale(), | ||||
|       4*jguiscale(), 4*jguiscale()); | ||||
| 
 | ||||
|     for (int i=0; i<m_palette->size(); ++i) { | ||||
|       raster::color_t c = m_palette->getEntry(i); | ||||
| 
 | ||||
|       g->fillRect(ui::rgba( | ||||
|           raster::rgba_getr(c), | ||||
|           raster::rgba_getg(c), | ||||
|           raster::rgba_getb(c)), box); | ||||
| 
 | ||||
|       box.x += box.w; | ||||
|     } | ||||
| 
 | ||||
|     g->drawString(getText(), fgcolor, ui::ColorNone, false, | ||||
|       gfx::Point( | ||||
|         bounds.x + jguiscale()*2, | ||||
|         bounds.y + bounds.h/2 - g->measureString(getText()).h/2)); | ||||
|   } | ||||
| 
 | ||||
|   void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE { | ||||
|     ev.setPreferredSize( | ||||
|       gfx::Size(0, (2+16+2)*jguiscale())); | ||||
|   } | ||||
| 
 | ||||
| private: | ||||
|   base::UniquePtr<raster::Palette> m_palette; | ||||
| }; | ||||
| 
 | ||||
| class PaletteListBox::LoadingItem : public ListItem { | ||||
| public: | ||||
|   LoadingItem() | ||||
|     : ListItem("Loading") | ||||
|     , m_state(0) { | ||||
|   } | ||||
| 
 | ||||
|   void makeProgress() { | ||||
|     std::string text = "Loading "; | ||||
| 
 | ||||
|     switch ((++m_state) % 4) { | ||||
|       case 0: text += "/"; break; | ||||
|       case 1: text += "-"; break; | ||||
|       case 2: text += "\\"; break; | ||||
|       case 3: text += "|"; break; | ||||
|     } | ||||
| 
 | ||||
|     setText(text); | ||||
|   } | ||||
| 
 | ||||
| private: | ||||
|   int m_state; | ||||
| }; | ||||
| 
 | ||||
| PaletteListBox::PaletteListBox() | ||||
|   : m_palettesTimer(100) | ||||
|   , m_loadingItem(NULL) | ||||
| { | ||||
|   m_palettesTimer.Tick.connect(Bind<void>(&PaletteListBox::onTick, this)); | ||||
| } | ||||
| 
 | ||||
| raster::Palette* PaletteListBox::selectedPalette() | ||||
| { | ||||
|   if (PaletteListItem* item = dynamic_cast<PaletteListItem*>(getSelectedChild())) | ||||
|     return item->palette(); | ||||
|   else | ||||
|     return NULL; | ||||
| } | ||||
| 
 | ||||
| bool PaletteListBox::onProcessMessage(ui::Message* msg) | ||||
| { | ||||
|   switch (msg->type()) { | ||||
| 
 | ||||
|     case kOpenMessage: { | ||||
|       if (m_palettesLoader == NULL) { | ||||
|         m_palettesLoader.reset(new PalettesLoader()); | ||||
|         m_palettesTimer.start(); | ||||
|       } | ||||
|       break; | ||||
|     } | ||||
| 
 | ||||
|   } | ||||
|   return ListBox::onProcessMessage(msg); | ||||
| } | ||||
| 
 | ||||
| void PaletteListBox::onChangeSelectedItem() | ||||
| { | ||||
|   raster::Palette* palette = selectedPalette(); | ||||
|   if (palette) | ||||
|     PalChange(palette); | ||||
| } | ||||
| 
 | ||||
| void PaletteListBox::onTick() | ||||
| { | ||||
|   if (m_palettesLoader == NULL) { | ||||
|     stop(); | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if (!m_loadingItem) { | ||||
|     m_loadingItem = new LoadingItem; | ||||
|     addChild(m_loadingItem); | ||||
|   } | ||||
|   m_loadingItem->makeProgress(); | ||||
|      | ||||
|   base::UniquePtr<raster::Palette> palette; | ||||
|   std::string name; | ||||
| 
 | ||||
|   if (!m_palettesLoader->next(palette, name)) { | ||||
|     if (m_palettesLoader->isDone()) { | ||||
|       stop(); | ||||
| 
 | ||||
|       PRINTF("Done\n"); | ||||
|     } | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   base::UniquePtr<PaletteListItem> item(new PaletteListItem(palette, name)); | ||||
|   insertChild(getItemsCount()-1, item); | ||||
|   layout(); | ||||
| 
 | ||||
|   palette.release(); | ||||
|   item.release(); | ||||
| } | ||||
| 
 | ||||
| void PaletteListBox::stop() | ||||
| { | ||||
|   if (m_loadingItem) { | ||||
|     removeChild(m_loadingItem); | ||||
|     delete m_loadingItem; | ||||
|     m_loadingItem = NULL; | ||||
| 
 | ||||
|     invalidate(); | ||||
|   } | ||||
| 
 | ||||
|   m_palettesTimer.stop(); | ||||
| } | ||||
| 
 | ||||
| } // namespace app
 | ||||
|  | @ -0,0 +1,55 @@ | |||
| /* Aseprite
 | ||||
|  * Copyright (C) 2001-2014  David Capello | ||||
|  * | ||||
|  * This program is free software; you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation; either version 2 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU General Public License | ||||
|  * along with this program; if not, write to the Free Software | ||||
|  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||
|  */ | ||||
| 
 | ||||
| #ifndef APP_UI_PALETTE_LISTBOX_H_INCLUDED | ||||
| #define APP_UI_PALETTE_LISTBOX_H_INCLUDED | ||||
| #pragma once | ||||
| 
 | ||||
| #include "app/palettes_loader.h" | ||||
| #include "base/compiler_specific.h" | ||||
| #include "base/unique_ptr.h" | ||||
| #include "ui/listbox.h" | ||||
| #include "ui/timer.h" | ||||
| 
 | ||||
| namespace app { | ||||
| 
 | ||||
|   class PaletteListBox : public ui::ListBox { | ||||
|   public: | ||||
|     PaletteListBox(); | ||||
| 
 | ||||
|     raster::Palette* selectedPalette(); | ||||
| 
 | ||||
|     Signal1<void, raster::Palette*> PalChange; | ||||
| 
 | ||||
|   protected: | ||||
|     bool onProcessMessage(ui::Message* msg) OVERRIDE; | ||||
|     void onChangeSelectedItem() OVERRIDE; | ||||
|     void onTick(); | ||||
|     void stop(); | ||||
| 
 | ||||
|   private: | ||||
|     base::UniquePtr<PalettesLoader> m_palettesLoader; | ||||
|     ui::Timer m_palettesTimer; | ||||
| 
 | ||||
|     class LoadingItem; | ||||
|     LoadingItem* m_loadingItem; | ||||
|   }; | ||||
| 
 | ||||
| } // namespace app
 | ||||
| 
 | ||||
| #endif | ||||
|  | @ -0,0 +1,92 @@ | |||
| /* Aseprite
 | ||||
|  * Copyright (C) 2001-2014  David Capello | ||||
|  * | ||||
|  * This program is free software; you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation; either version 2 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU General Public License | ||||
|  * along with this program; if not, write to the Free Software | ||||
|  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||
|  */ | ||||
| 
 | ||||
| #ifdef HAVE_CONFIG_H | ||||
| #include "config.h" | ||||
| #endif | ||||
| 
 | ||||
| #include "app/ui/palette_popup.h" | ||||
| 
 | ||||
| #include "app/commands/cmd_set_palette.h" | ||||
| #include "app/commands/commands.h" | ||||
| #include "app/launcher.h" | ||||
| #include "app/load_widget.h" | ||||
| #include "app/palettes_loader.h" | ||||
| #include "app/ui/palette_listbox.h" | ||||
| #include "app/ui_context.h" | ||||
| #include "base/bind.h" | ||||
| #include "ui/box.h" | ||||
| #include "ui/button.h" | ||||
| #include "ui/theme.h" | ||||
| #include "ui/view.h" | ||||
| 
 | ||||
| namespace app { | ||||
| 
 | ||||
| using namespace ui; | ||||
| 
 | ||||
| PalettePopup::PalettePopup() | ||||
|   : PopupWindow("Palettes", kCloseOnClickInOtherWindow) | ||||
| { | ||||
|   setAutoRemap(false); | ||||
|   setBorder(gfx::Border(4*jguiscale())); | ||||
| 
 | ||||
|   addChild(app::load_widget<Box>("palette_popup.xml", "mainbox")); | ||||
| 
 | ||||
|   m_load = findChildT<Button>("load"); | ||||
|   m_load->Click.connect(Bind<void>(&PalettePopup::onLoad, this)); | ||||
|   findChildT<Button>("openfolder")->Click.connect(Bind<void>(&PalettePopup::onOpenFolder, this)); | ||||
| 
 | ||||
|   m_view = findChildT<View>("view"); | ||||
|   m_view->attachToView(&m_paletteListBox); | ||||
| 
 | ||||
|   m_paletteListBox.PalChange.connect(&PalettePopup::onPalChange, this); | ||||
| } | ||||
| 
 | ||||
| void PalettePopup::showPopup(gfx::Rect& bounds) | ||||
| { | ||||
|   m_load->setEnabled(false); | ||||
|   m_paletteListBox.selectChild(NULL); | ||||
| 
 | ||||
|   moveWindow(bounds); | ||||
|   openWindow(); | ||||
| } | ||||
| 
 | ||||
| void PalettePopup::onPalChange(raster::Palette* palette) | ||||
| { | ||||
|   m_load->setEnabled(palette != NULL); | ||||
| } | ||||
| 
 | ||||
| void PalettePopup::onLoad() | ||||
| { | ||||
|   raster::Palette* palette = m_paletteListBox.selectedPalette(); | ||||
|   if (!palette) | ||||
|     return; | ||||
| 
 | ||||
|   SetPaletteCommand* cmd = static_cast<SetPaletteCommand*>( | ||||
|     CommandsModule::instance()->getCommandByName(CommandId::SetPalette)); | ||||
|   cmd->setPalette(palette); | ||||
| 
 | ||||
|   UIContext::instance()->executeCommand(cmd); | ||||
| } | ||||
| 
 | ||||
| void PalettePopup::onOpenFolder() | ||||
| { | ||||
|   launcher::open_folder(PalettesLoader::palettesLocation()); | ||||
| } | ||||
| 
 | ||||
| } // namespace app
 | ||||
|  | @ -0,0 +1,53 @@ | |||
| /* Aseprite
 | ||||
|  * Copyright (C) 2001-2014  David Capello | ||||
|  * | ||||
|  * This program is free software; you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation; either version 2 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU General Public License | ||||
|  * along with this program; if not, write to the Free Software | ||||
|  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||
|  */ | ||||
| 
 | ||||
| #ifndef APP_UI_PALETTE_POPUP_H_INCLUDED | ||||
| #define APP_UI_PALETTE_POPUP_H_INCLUDED | ||||
| #pragma once | ||||
| 
 | ||||
| #include "app/ui/palette_listbox.h" | ||||
| #include "base/compiler_specific.h" | ||||
| #include "ui/popup_window.h" | ||||
| 
 | ||||
| namespace ui { | ||||
|   class Button; | ||||
|   class View; | ||||
| } | ||||
| 
 | ||||
| namespace app { | ||||
| 
 | ||||
|   class PalettePopup : public ui::PopupWindow { | ||||
|   public: | ||||
|     PalettePopup(); | ||||
| 
 | ||||
|     void showPopup(gfx::Rect& bounds); | ||||
| 
 | ||||
|   protected: | ||||
|     void onPalChange(raster::Palette* palette); | ||||
|     void onLoad(); | ||||
|     void onOpenFolder(); | ||||
| 
 | ||||
|   private: | ||||
|     ui::View* m_view; | ||||
|     ui::Button* m_load; | ||||
|     PaletteListBox m_paletteListBox; | ||||
|   }; | ||||
| 
 | ||||
| } // namespace app
 | ||||
| 
 | ||||
| #endif | ||||
|  | @ -0,0 +1,55 @@ | |||
| // Aseprite Base Library
 | ||||
| // Copyright (c) 2001-2014 David Capello
 | ||||
| //
 | ||||
| // This file is released under the terms of the MIT license.
 | ||||
| // Read LICENSE.txt for more information.
 | ||||
| 
 | ||||
| #ifndef BASE_CONCURRENT_QUEUE_H_INCLUDED | ||||
| #define BASE_CONCURRENT_QUEUE_H_INCLUDED | ||||
| #pragma once | ||||
| 
 | ||||
| #include "base/disable_copying.h" | ||||
| #include "base/mutex.h" | ||||
| #include "base/scoped_lock.h" | ||||
| 
 | ||||
| #include <queue> | ||||
| 
 | ||||
| namespace base { | ||||
| 
 | ||||
|   template<typename T> | ||||
|   class concurrent_queue { | ||||
|   public: | ||||
|     concurrent_queue() { | ||||
|     } | ||||
| 
 | ||||
|     ~concurrent_queue() { | ||||
|     } | ||||
| 
 | ||||
|     void push(const T& value) { | ||||
|       scoped_lock hold(m_mutex); | ||||
|       m_queue.push(value); | ||||
|     } | ||||
| 
 | ||||
|     bool try_pop(T& value) { | ||||
|       if (!m_mutex.try_lock()) | ||||
|         return false; | ||||
| 
 | ||||
|       scoped_unlock unlock(m_mutex); | ||||
|       if (m_queue.empty()) | ||||
|         return false; | ||||
| 
 | ||||
|       value = m_queue.front(); | ||||
|       m_queue.pop(); | ||||
|       return true; | ||||
|     } | ||||
| 
 | ||||
|   private: | ||||
|     std::queue<T> m_queue; | ||||
|     mutex m_mutex; | ||||
| 
 | ||||
|     DISABLE_COPYING(concurrent_queue); | ||||
|   }; | ||||
| 
 | ||||
| } // namespace base
 | ||||
| 
 | ||||
| #endif | ||||
|  | @ -8,8 +8,9 @@ | |||
| #include "config.h" | ||||
| #endif | ||||
| 
 | ||||
| #include "base/launcher.h" | ||||
| #include "base/exception.h" | ||||
| #include "base/fs.h" | ||||
| #include "base/launcher.h" | ||||
| #include "base/string.h" | ||||
| 
 | ||||
| #ifdef WIN32 | ||||
|  | @ -90,10 +91,15 @@ bool open_file(const std::string& file) | |||
| bool open_folder(const std::string& file) | ||||
| { | ||||
| #ifdef WIN32 | ||||
|   int ret = win32_shell_execute(NULL, | ||||
|                                 L"explorer", | ||||
|   int ret; | ||||
|   if (base::directory_exists(file)) { | ||||
|     ret = win32_shell_execute(NULL, L"explorer", | ||||
|       (L"/n,/e,\"" + base::from_utf8(file) + L"\"").c_str()); | ||||
|   } | ||||
|   else { | ||||
|     ret = win32_shell_execute(NULL, L"explorer", | ||||
|       (L"/e,/select,\"" + base::from_utf8(file) + L"\"").c_str()); | ||||
| 
 | ||||
|   } | ||||
|   return (ret == 0); | ||||
| #else | ||||
|   return false; | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| // Aseprite Base Library
 | ||||
| // Copyright (c) 2001-2013 David Capello
 | ||||
| // Copyright (c) 2001-2014 David Capello
 | ||||
| //
 | ||||
| // This file is released under the terms of the MIT license.
 | ||||
| // Read LICENSE.txt for more information.
 | ||||
|  | @ -12,20 +12,12 @@ | |||
| 
 | ||||
| namespace base { | ||||
| 
 | ||||
|   // An object to safely lock and unlock mutexes.
 | ||||
|   //
 | ||||
|   // The constructor of scoped_lock locks the mutex, and the destructor
 | ||||
|   // unlocks the mutex. In this way you can safely use scoped_lock inside
 | ||||
|   // a try/catch block without worrying about the lock state of the
 | ||||
|   // mutex if some exception is thrown.
 | ||||
|   class scoped_lock { | ||||
|   class scoped_unlock { | ||||
|   public: | ||||
| 
 | ||||
|     scoped_lock(mutex& m) : m_mutex(m) { | ||||
|       m_mutex.lock(); | ||||
|     scoped_unlock(mutex& m) : m_mutex(m) { | ||||
|     } | ||||
| 
 | ||||
|     ~scoped_lock() { | ||||
|     ~scoped_unlock() { | ||||
|       m_mutex.unlock(); | ||||
|     } | ||||
| 
 | ||||
|  | @ -36,10 +28,27 @@ namespace base { | |||
|   private: | ||||
|     mutex& m_mutex; | ||||
| 
 | ||||
|     // Undefined constructors.
 | ||||
|     scoped_unlock(); | ||||
|     DISABLE_COPYING(scoped_unlock); | ||||
|   }; | ||||
| 
 | ||||
|   // An object to safely lock and unlock mutexes.
 | ||||
|   //
 | ||||
|   // The constructor of scoped_lock locks the mutex, and the destructor
 | ||||
|   // unlocks the mutex. In this way you can safely use scoped_lock inside
 | ||||
|   // a try/catch block without worrying about the lock state of the
 | ||||
|   // mutex if some exception is thrown.
 | ||||
|   class scoped_lock : public scoped_unlock { | ||||
|   public: | ||||
|     scoped_lock(mutex& m) : scoped_unlock(m) { | ||||
|       get_mutex().lock(); | ||||
|     } | ||||
| 
 | ||||
|   private: | ||||
|     // Undefined constructors.
 | ||||
|     scoped_lock(); | ||||
|     DISABLE_COPYING(scoped_lock); | ||||
| 
 | ||||
|   }; | ||||
| 
 | ||||
| } // namespace base
 | ||||
|  |  | |||
|  | @ -46,8 +46,7 @@ Palette* load_gpl_file(const char *filename) | |||
|   base::trim_string(line, line); | ||||
|   if (line != "GIMP Palette") return NULL; | ||||
| 
 | ||||
|   base::UniquePtr<Palette> pal(new Palette(FrameNumber(0), 256)); | ||||
|   int entryCounter = 0; | ||||
|   base::UniquePtr<Palette> pal(new Palette(FrameNumber(0), 0)); | ||||
| 
 | ||||
|   while (std::getline(f, line)) { | ||||
|     // Trim line.
 | ||||
|  | @ -66,13 +65,16 @@ Palette* load_gpl_file(const char *filename) | |||
|     // TODO add support to read the color name
 | ||||
|     lineIn >> r >> g >> b; | ||||
|     if (lineIn.good()) { | ||||
|       pal->setEntry(entryCounter, rgba(r, g, b, 255)); | ||||
|       ++entryCounter; | ||||
|       if (entryCounter >= Palette::MaxColors) | ||||
|       pal->addEntry(rgba(r, g, b, 255)); | ||||
|       if (pal->size() == Palette::MaxColors) | ||||
|         break; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   // TODO remove this when Aseprite supports palettes with less than 256 colors
 | ||||
|   if (pal->size() != Palette::MaxColors) | ||||
|       pal->resize(Palette::MaxColors); | ||||
| 
 | ||||
|   return pal.release(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -41,7 +41,7 @@ using namespace gfx; | |||
| Palette::Palette(FrameNumber frame, int ncolors) | ||||
|   : Object(OBJECT_PALETTE) | ||||
| { | ||||
|   ASSERT(ncolors >= 1 && ncolors <= MaxColors); | ||||
|   ASSERT(ncolors >= 0 && ncolors <= MaxColors); | ||||
| 
 | ||||
|   m_frame = frame; | ||||
|   m_colors.resize(ncolors); | ||||
|  | @ -72,7 +72,7 @@ Palette* Palette::createGrayscale() | |||
| 
 | ||||
| void Palette::resize(int ncolors) | ||||
| { | ||||
|   ASSERT(ncolors >= 1 && ncolors <= MaxColors); | ||||
|   ASSERT(ncolors >= 0 && ncolors <= MaxColors); | ||||
| 
 | ||||
|   int old_size = m_colors.size(); | ||||
|   m_colors.resize(ncolors); | ||||
|  | @ -87,6 +87,12 @@ void Palette::resize(int ncolors) | |||
|   ++m_modifications; | ||||
| } | ||||
| 
 | ||||
| void Palette::addEntry(color_t color) | ||||
| { | ||||
|   resize(size()+1); | ||||
|   setEntry(size()-1, color); | ||||
| } | ||||
| 
 | ||||
| void Palette::setFrame(FrameNumber frame) | ||||
| { | ||||
|   ASSERT(frame >= 0); | ||||
|  | @ -426,6 +432,9 @@ Palette* Palette::load(const char *filename) | |||
|     pal = raster::file::load_gpl_file(filename); | ||||
|   } | ||||
| 
 | ||||
|   if (pal) | ||||
|     pal->setFilename(filename); | ||||
| 
 | ||||
|   return pal; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -67,6 +67,11 @@ namespace raster { | |||
|     int size() const { return m_colors.size(); } | ||||
|     void resize(int ncolors); | ||||
| 
 | ||||
|     std::string getFilename() const { return m_filename; } | ||||
|     void setFilename(const std::string& filename) { | ||||
|       m_filename = filename; | ||||
|     } | ||||
| 
 | ||||
|     int getModifications() const { return m_modifications; } | ||||
| 
 | ||||
|     FrameNumber getFrame() const { return m_frame; } | ||||
|  | @ -76,8 +81,8 @@ namespace raster { | |||
|       ASSERT(i >= 0 && i < size()); | ||||
|       return m_colors[i]; | ||||
|     } | ||||
| 
 | ||||
|     void setEntry(int i, color_t color); | ||||
|     void addEntry(color_t color); | ||||
| 
 | ||||
|     void copyColorsTo(Palette* dst) const; | ||||
| 
 | ||||
|  | @ -101,6 +106,7 @@ namespace raster { | |||
|     FrameNumber m_frame; | ||||
|     std::vector<color_t> m_colors; | ||||
|     int m_modifications; | ||||
|     std::string m_filename; // If the palette is associated with a file.
 | ||||
|   }; | ||||
| 
 | ||||
| } // namespace raster
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue