mirror of https://github.com/aseprite/aseprite.git
				
				
				
			Added Context and UIContext classes.
Added CurrentSprite class. Removed current_sprite global. Moved all functions of 'sprites' module to Context/UIContext.
This commit is contained in:
		
							parent
							
								
									8f92f78702
								
							
						
					
					
						commit
						c4be9fe5b4
					
				
							
								
								
									
										9
									
								
								TODO.txt
								
								
								
								
							
							
						
						
									
										9
									
								
								TODO.txt
								
								
								
								
							|  | @ -43,10 +43,7 @@ Wish-list | |||
| - dacap wish-list: | ||||
|   + added starred file-items in the file-selector. | ||||
|   + add AseContext structure to handle the current state of the | ||||
|     application (and hook changes in the context/options): | ||||
|   + src/ase/ directory | ||||
|   + src/ase/context.[ch] | ||||
|   + the current sprite should be in the AseContext | ||||
|     application (and hook changes in the context/options). | ||||
|   + the commands should be enabled/disabled/checked by the current | ||||
|     context state | ||||
|   + the commands should use a new ase/ API and not the raster/ low-level | ||||
|  | @ -54,10 +51,6 @@ Wish-list | |||
|     - All "functions.c" should be in Undoable | ||||
|   + the dependencies should be: | ||||
|     commands/ -> ase/ -> raster/ -> jinete/ | ||||
|   + the list of 'sprites' should be in the context (maybe a | ||||
|     AseSharedContext). | ||||
|   + the scripts should start with a new default AseContext (but | ||||
|     with the AseSharedContext visible) | ||||
| - manuq wish-list: | ||||
|   + layer-with-constant-cel | ||||
| - Mateusz Czaplinski ideas: | ||||
|  |  | |||
|  | @ -80,6 +80,7 @@ $(ZLIB_LIB): $(ZLIB_OBJS) | |||
| # Rules to build objects and the application | ||||
| 
 | ||||
| VPATH = src					\ | ||||
| 	src/ase					\ | ||||
| 	src/commands				\ | ||||
| 	src/commands/fx				\ | ||||
| 	src/console				\ | ||||
|  |  | |||
|  | @ -6,6 +6,8 @@ | |||
| ASE = aseprite$(EXE) | ||||
| 
 | ||||
| COMMON_SOURCES =					\ | ||||
| 	src/ase/context.cpp				\ | ||||
| 	src/ase/ui_context.cpp				\ | ||||
| 	src/commands/cmd_about.cpp			\ | ||||
| 	src/commands/cmd_advanced_mode.cpp		\ | ||||
| 	src/commands/cmd_background_from_layer.cpp	\ | ||||
|  |  | |||
|  | @ -94,6 +94,7 @@ $(ZLIB_LIB): $(ZLIB_OBJS) | |||
| # Rules to build objects and the application | ||||
| 
 | ||||
| VPATH = src					\ | ||||
| 	src/ase					\ | ||||
| 	src/commands				\ | ||||
| 	src/commands/fx				\ | ||||
| 	src/console				\ | ||||
|  |  | |||
|  | @ -0,0 +1,138 @@ | |||
| /* ASE - Allegro Sprite Editor
 | ||||
|  * Copyright (C) 2001-2009  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 | ||||
|  */ | ||||
| 
 | ||||
| #include "config.h" | ||||
| 
 | ||||
| #include <cassert> | ||||
| #include <algorithm> | ||||
| 
 | ||||
| #include "ase/context.h" | ||||
| 
 | ||||
| Context::Context() | ||||
| { | ||||
|   m_current_sprite = NULL; | ||||
| } | ||||
| 
 | ||||
| Context::~Context() | ||||
| { | ||||
|   for (SpriteList::iterator | ||||
| 	 it = m_sprites.begin(); it != m_sprites.end(); ++it) { | ||||
|     Sprite* sprite = *it; | ||||
|     delete sprite; | ||||
|   } | ||||
|   m_sprites.clear(); | ||||
| } | ||||
| 
 | ||||
| const SpriteList& Context::get_sprite_list() const | ||||
| { | ||||
|   return m_sprites; | ||||
| } | ||||
| 
 | ||||
| Sprite* Context::get_first_sprite() const | ||||
| { | ||||
|   if (!m_sprites.empty()) | ||||
|     return m_sprites.front(); | ||||
|   else | ||||
|     return NULL; | ||||
| } | ||||
| 
 | ||||
| Sprite* Context::get_next_sprite(Sprite* sprite) const | ||||
| { | ||||
|   assert(sprite != NULL); | ||||
| 
 | ||||
|   SpriteList::const_iterator it = std::find(m_sprites.begin(), m_sprites.end(), sprite); | ||||
| 
 | ||||
|   if (it != m_sprites.end()) { | ||||
|     ++it; | ||||
|     if (it != m_sprites.end()) | ||||
|       return *it; | ||||
|   } | ||||
|   return NULL; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * Append the sprite to the context's sprites' list. | ||||
|  */ | ||||
| void Context::add_sprite(Sprite* sprite) | ||||
| { | ||||
|   assert(sprite != NULL); | ||||
| 
 | ||||
|   m_sprites.push_front(sprite); | ||||
| 
 | ||||
|   // generate on_add_sprite event
 | ||||
|   on_add_sprite(sprite); | ||||
| } | ||||
| 
 | ||||
| void Context::remove_sprite(Sprite* sprite) | ||||
| { | ||||
|   assert(sprite != NULL); | ||||
| 
 | ||||
|   SpriteList::iterator it = std::find(m_sprites.begin(), m_sprites.end(), sprite); | ||||
|   assert(it != m_sprites.end()); | ||||
| 
 | ||||
|   // remove the item from the sprites list
 | ||||
|   m_sprites.erase(it); | ||||
| 
 | ||||
|   // generate on_remove_sprite event
 | ||||
|   on_remove_sprite(sprite); | ||||
| 
 | ||||
|   // the current sprite cannot be the removed sprite anymore
 | ||||
|   if (m_current_sprite == sprite) | ||||
|     set_current_sprite(NULL); | ||||
| } | ||||
| 
 | ||||
| void Context::send_sprite_to_top(Sprite* sprite) | ||||
| { | ||||
|   assert(sprite); | ||||
| 
 | ||||
|   SpriteList::iterator it = std::find(m_sprites.begin(), m_sprites.end(), sprite); | ||||
|   assert(it != m_sprites.end()); | ||||
| 
 | ||||
|   // remove the item from the sprites list
 | ||||
|   m_sprites.erase(it); | ||||
| 
 | ||||
|   // add it again
 | ||||
|   m_sprites.push_front(sprite); | ||||
| } | ||||
| 
 | ||||
| Sprite* Context::get_current_sprite() const | ||||
| { | ||||
|   return m_current_sprite; | ||||
| } | ||||
| 
 | ||||
| void Context::set_current_sprite(Sprite* sprite) | ||||
| { | ||||
|   m_current_sprite = sprite; | ||||
| 
 | ||||
|   on_set_current_sprite(sprite); | ||||
| } | ||||
| 
 | ||||
| void Context::on_add_sprite(Sprite* sprite) | ||||
| { | ||||
|   // do nothing
 | ||||
| } | ||||
| 
 | ||||
| void Context::on_remove_sprite(Sprite* sprite) | ||||
| { | ||||
|   // do nothing
 | ||||
| } | ||||
| 
 | ||||
| void Context::on_set_current_sprite(Sprite* sprite) | ||||
| { | ||||
|   // do nothing
 | ||||
| } | ||||
|  | @ -0,0 +1,65 @@ | |||
| /* ASE - Allegro Sprite Editor
 | ||||
|  * Copyright (C) 2001-2009  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 ASE_CONTEXT_H | ||||
| #define ASE_CONTEXT_H | ||||
| 
 | ||||
| #include <list> | ||||
| 
 | ||||
| class Sprite; | ||||
| 
 | ||||
| typedef std::list<Sprite*> SpriteList; | ||||
| 
 | ||||
| class Context | ||||
| { | ||||
|   /**
 | ||||
|    * List of all sprites. | ||||
|    */ | ||||
|   SpriteList m_sprites; | ||||
| 
 | ||||
|   /**
 | ||||
|    * Current selected sprite to operate. | ||||
|    */ | ||||
|   Sprite* m_current_sprite; | ||||
| 
 | ||||
| public: | ||||
| 
 | ||||
|   Context(); | ||||
|   virtual ~Context(); | ||||
| 
 | ||||
|   const SpriteList& get_sprite_list() const; | ||||
|   Sprite* get_first_sprite() const; | ||||
|   Sprite* get_next_sprite(Sprite* sprite) const; | ||||
| 
 | ||||
|   void add_sprite(Sprite* sprite); | ||||
|   void remove_sprite(Sprite* sprite); | ||||
|   void send_sprite_to_top(Sprite* sprite); | ||||
| 
 | ||||
|   Sprite* get_current_sprite() const; | ||||
|   void set_current_sprite(Sprite* sprite); | ||||
| 
 | ||||
| protected: | ||||
| 
 | ||||
|   virtual void on_add_sprite(Sprite* sprite); | ||||
|   virtual void on_remove_sprite(Sprite* sprite); | ||||
|   virtual void on_set_current_sprite(Sprite* sprite); | ||||
| 
 | ||||
| }; | ||||
| 
 | ||||
| #endif // ASE_CONTEXT_H
 | ||||
| 
 | ||||
|  | @ -0,0 +1,98 @@ | |||
| /* ASE - Allegro Sprite Editor
 | ||||
|  * Copyright (C) 2001-2009  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 | ||||
|  */ | ||||
| 
 | ||||
| #include "config.h" | ||||
| 
 | ||||
| #include <cassert> | ||||
| #include <allegro/file.h> | ||||
| 
 | ||||
| #include "ase/ui_context.h" | ||||
| #include "core/app.h" | ||||
| #include "modules/editors.h" | ||||
| #include "raster/sprite.h" | ||||
| #include "widgets/tabs.h" | ||||
| 
 | ||||
| //////////////////////////////////////////////////////////////////////
 | ||||
| // UIContext singleton
 | ||||
| 
 | ||||
| static UIContext* g_instance = NULL; | ||||
| 
 | ||||
| UIContext* UIContext::instance() | ||||
| { | ||||
|   if (!g_instance) | ||||
|     g_instance = new UIContext; | ||||
|   return g_instance; | ||||
| } | ||||
| 
 | ||||
| void UIContext::destroy_instance() | ||||
| { | ||||
|   delete g_instance; | ||||
|   g_instance = NULL; | ||||
| } | ||||
| 
 | ||||
| //////////////////////////////////////////////////////////////////////
 | ||||
| 
 | ||||
| UIContext::UIContext() | ||||
| { | ||||
| } | ||||
| 
 | ||||
| UIContext::~UIContext() | ||||
| { | ||||
| } | ||||
| 
 | ||||
| void UIContext::show_sprite(Sprite* sprite) const | ||||
| { | ||||
|   set_sprite_in_more_reliable_editor(sprite); | ||||
| } | ||||
| 
 | ||||
| void UIContext::on_add_sprite(Sprite* sprite) | ||||
| { | ||||
|   // base method
 | ||||
|   Context::on_add_sprite(sprite); | ||||
| 
 | ||||
|   // add the tab for this sprite
 | ||||
|   tabs_append_tab(app_get_tabsbar(), | ||||
| 		  get_filename(sprite->filename), sprite); | ||||
| 
 | ||||
|   // rebuild the menu list of sprites
 | ||||
|   app_realloc_sprite_list(); | ||||
| } | ||||
| 
 | ||||
| void UIContext::on_remove_sprite(Sprite* sprite) | ||||
| { | ||||
|   // base method
 | ||||
|   Context::on_remove_sprite(sprite); | ||||
| 
 | ||||
|   // remove this sprite from tabs
 | ||||
|   tabs_remove_tab(app_get_tabsbar(), sprite); | ||||
| 
 | ||||
|   // rebuild the menu list of sprites
 | ||||
|   app_realloc_sprite_list(); | ||||
| 
 | ||||
|   // select other sprites in the editors where are this sprite
 | ||||
|   editors_hide_sprite(sprite); | ||||
| } | ||||
| 
 | ||||
| void UIContext::on_set_current_sprite(Sprite* sprite) | ||||
| { | ||||
|   // base method
 | ||||
|   Context::on_set_current_sprite(sprite); | ||||
| 
 | ||||
|   // select the sprite in the tabs
 | ||||
|   tabs_select_tab(app_get_tabsbar(), sprite); | ||||
| } | ||||
|  | @ -0,0 +1,44 @@ | |||
| /* ASE - Allegro Sprite Editor
 | ||||
|  * Copyright (C) 2001-2009  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 ASE_UI_CONTEXT_H | ||||
| #define ASE_UI_CONTEXT_H | ||||
| 
 | ||||
| #include "ase/context.h" | ||||
| 
 | ||||
| class UIContext : public Context | ||||
| { | ||||
| public: | ||||
| 
 | ||||
|   static UIContext* instance(); | ||||
|   static void destroy_instance(); | ||||
| 
 | ||||
|   UIContext(); | ||||
|   virtual ~UIContext(); | ||||
| 
 | ||||
|   void show_sprite(Sprite* sprite) const; | ||||
| 
 | ||||
| protected: | ||||
| 
 | ||||
|   virtual void on_add_sprite(Sprite* sprite); | ||||
|   virtual void on_remove_sprite(Sprite* sprite); | ||||
|   virtual void on_set_current_sprite(Sprite* sprite); | ||||
| 
 | ||||
| }; | ||||
| 
 | ||||
| #endif // ASE_UI_CONTEXT_H
 | ||||
|  | @ -29,18 +29,19 @@ | |||
| 
 | ||||
| static bool cmd_background_from_layer_enabled(const char *argument) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   return | ||||
|     current_sprite != NULL && | ||||
|     current_sprite->layer != NULL && | ||||
|     sprite_get_background_layer(current_sprite) == NULL && | ||||
|     layer_is_image(current_sprite->layer) && | ||||
|     layer_is_readable(current_sprite->layer) && | ||||
|     layer_is_writable(current_sprite->layer); | ||||
|     sprite != NULL && | ||||
|     sprite->layer != NULL && | ||||
|     sprite_get_background_layer(sprite) == NULL && | ||||
|     layer_is_image(sprite->layer) && | ||||
|     layer_is_readable(sprite->layer) && | ||||
|     layer_is_writable(sprite->layer); | ||||
| } | ||||
| 
 | ||||
| static void cmd_background_from_layer_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   // each frame of the layer to be converted as `Background' must be
 | ||||
|   // cleared using the selected background color in the color-bar
 | ||||
|  |  | |||
|  | @ -34,13 +34,14 @@ | |||
| 
 | ||||
| static bool cmd_canvas_size_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite != NULL; | ||||
| } | ||||
| 
 | ||||
| static void cmd_canvas_size_execute(const char *argument) | ||||
| { | ||||
|   JWidget window, left, top, right, bottom, ok; | ||||
|   Sprite* sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   // load the window widget
 | ||||
|   window = load_widget("canvas.jid", "canvas_size"); | ||||
|  |  | |||
|  | @ -36,9 +36,8 @@ | |||
| 
 | ||||
| static bool cmd_cel_properties_enabled(const char *argument) | ||||
| { | ||||
|   return | ||||
|     is_current_sprite_not_locked() | ||||
|     && current_sprite->layer; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite && sprite->layer; | ||||
| } | ||||
| 
 | ||||
| static void cmd_cel_properties_execute(const char *argument) | ||||
|  | @ -46,14 +45,13 @@ static void cmd_cel_properties_execute(const char *argument) | |||
|   JWidget window = NULL; | ||||
|   JWidget label_frame, label_pos, label_size; | ||||
|   JWidget slider_opacity, button_ok; | ||||
|   Sprite *sprite; | ||||
|   Layer *layer; | ||||
|   Cel *cel; | ||||
|   char buf[1024]; | ||||
|   int memsize; | ||||
| 
 | ||||
|   /* get current sprite */ | ||||
|   sprite = lock_current_sprite(); | ||||
|   CurrentSprite sprite; | ||||
|   if (!sprite) | ||||
|     return; | ||||
| 
 | ||||
|  | @ -147,8 +145,6 @@ static void cmd_cel_properties_execute(const char *argument) | |||
| done:; | ||||
|   if (window) | ||||
|     jwidget_free(window); | ||||
| 
 | ||||
|   sprite_unlock(sprite); | ||||
| } | ||||
| 
 | ||||
| Command cmd_cel_properties = { | ||||
|  |  | |||
|  | @ -32,12 +32,14 @@ | |||
| 
 | ||||
| static bool cmd_change_image_type_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_change_image_type_execute(const char *argument) | ||||
| { | ||||
|   JWidget window, from, radio1, radio2, radio3, dither1, dither2; | ||||
|   CurrentSprite current_sprite; | ||||
| 
 | ||||
|   /* load the window widget */ | ||||
|   window = load_widget("imgtype.jid", "image_type"); | ||||
|  |  | |||
|  | @ -30,22 +30,27 @@ | |||
| 
 | ||||
| static bool cmd_clear_enabled(const char *argument) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   return | ||||
|     current_sprite != NULL && | ||||
|     current_sprite->layer != NULL && | ||||
|     layer_is_image(current_sprite->layer) && | ||||
|     layer_is_readable(current_sprite->layer) && | ||||
|     layer_is_writable(current_sprite->layer); | ||||
|     sprite != NULL && | ||||
|     sprite->layer != NULL && | ||||
|     layer_is_image(sprite->layer) && | ||||
|     layer_is_readable(sprite->layer) && | ||||
|     layer_is_writable(sprite->layer); | ||||
| } | ||||
| 
 | ||||
| static void cmd_clear_execute(const char *argument) | ||||
| { | ||||
|   Sprite* sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   if (!sprite) | ||||
|     return; | ||||
| 
 | ||||
|   { | ||||
|     Undoable undoable(sprite, "Clear"); | ||||
|     undoable.clear_mask(app_get_color_to_clear_layer(sprite->layer)); | ||||
|     undoable.commit(); | ||||
|   } | ||||
| 
 | ||||
|   update_screen_for_sprite(sprite); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -21,6 +21,7 @@ | |||
| #include <allegro.h> | ||||
| #include "jinete/jinete.h" | ||||
| 
 | ||||
| #include "ase/ui_context.h" | ||||
| #include "commands/commands.h" | ||||
| #include "core/app.h" | ||||
| #include "modules/sprites.h" | ||||
|  | @ -34,7 +35,8 @@ static bool close_current_sprite(); | |||
| 
 | ||||
| static bool cmd_close_file_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite != NULL; | ||||
| } | ||||
| 
 | ||||
| static void cmd_close_file_execute(const char *argument) | ||||
|  | @ -48,17 +50,23 @@ static void cmd_close_file_execute(const char *argument) | |||
| 
 | ||||
| static bool cmd_close_all_files_enabled(const char *argument) | ||||
| { | ||||
|   return !jlist_empty(get_sprite_list()); | ||||
|   return !UIContext::instance()->get_sprite_list().empty(); | ||||
| } | ||||
| 
 | ||||
| static void cmd_close_all_files_execute(const char *argument) | ||||
| { | ||||
|   if (!current_sprite) | ||||
|     sprite_show(get_first_sprite()); | ||||
|   UIContext* context = UIContext::instance(); | ||||
|   if (!context->get_current_sprite()) | ||||
|     context->show_sprite(context->get_first_sprite()); | ||||
| 
 | ||||
|   while (current_sprite != NULL && | ||||
| 	 close_current_sprite()) | ||||
|     ; | ||||
|   while (true) { | ||||
|     if (context->get_current_sprite() != NULL) { | ||||
|       if (!close_current_sprite()) | ||||
| 	break; | ||||
|     } | ||||
|     else | ||||
|       break; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  | @ -67,7 +75,9 @@ static void cmd_close_all_files_execute(const char *argument) | |||
|  */ | ||||
| static bool close_current_sprite() | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   if (!sprite.writeable()) | ||||
|     return false; | ||||
| 
 | ||||
|   /* see if the sprite has changes */ | ||||
|   while (sprite_is_modified(sprite)) { | ||||
|  | @ -83,7 +93,7 @@ static bool close_current_sprite() | |||
|     } | ||||
|     else if (ret != 2) { | ||||
|       /* "cancel" or "ESC" */ | ||||
|       return FALSE; /* we back doing nothing */ | ||||
|       return false; /* we back doing nothing */ | ||||
|     } | ||||
|     else { | ||||
|       /* "discard" */ | ||||
|  | @ -92,9 +102,8 @@ static bool close_current_sprite() | |||
|   } | ||||
| 
 | ||||
|   /* closes the sprite */ | ||||
|   sprite_unmount(sprite); | ||||
|   sprite_free(sprite); | ||||
|   return TRUE; | ||||
|   sprite.destroy(); | ||||
|   return true; | ||||
| } | ||||
| 
 | ||||
| Command cmd_close_file = { | ||||
|  |  | |||
|  | @ -325,7 +325,7 @@ static bool view_grid_check_change_hook(JWidget widget, void *data) | |||
| 
 | ||||
| static bool set_grid_button_select_hook(JWidget widget, void *data) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   if (sprite && sprite->mask && sprite->mask->bitmap) { | ||||
|     JRect rect = jrect_new(sprite->mask->x, | ||||
|  |  | |||
|  | @ -30,20 +30,23 @@ | |||
| 
 | ||||
| static bool cmd_copy_enabled(const char *argument) | ||||
| { | ||||
|   if ((!current_sprite) || | ||||
|       (!current_sprite->layer) || | ||||
|       (!layer_is_readable(current_sprite->layer)) || | ||||
|       (!layer_is_writable(current_sprite->layer)) || | ||||
|       (!current_sprite->mask) || | ||||
|       (!current_sprite->mask->bitmap)) | ||||
|     return FALSE; | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   if ((!sprite) || | ||||
|       (!sprite->layer) || | ||||
|       (!layer_is_readable(sprite->layer)) || | ||||
|       (!layer_is_writable(sprite->layer)) || | ||||
|       (!sprite->mask) || | ||||
|       (!sprite->mask->bitmap)) | ||||
|     return false; | ||||
|   else | ||||
|     return GetImage(current_sprite) ? TRUE: FALSE; | ||||
|     return GetImage(sprite) ? true: false; | ||||
| } | ||||
| 
 | ||||
| static void cmd_copy_execute(const char *argument) | ||||
| { | ||||
|   clipboard::copy(current_sprite); | ||||
|   CurrentSprite sprite; | ||||
|   clipboard::copy(sprite); | ||||
| } | ||||
| 
 | ||||
| Command cmd_copy = { | ||||
|  |  | |||
|  | @ -38,15 +38,16 @@ | |||
| 
 | ||||
| static bool cmd_crop_sprite_enabled(const char *argument) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   return | ||||
|     current_sprite != NULL && | ||||
|     current_sprite->mask != NULL && | ||||
|     current_sprite->mask->bitmap != NULL; | ||||
|     sprite != NULL && | ||||
|     sprite->mask != NULL && | ||||
|     sprite->mask->bitmap != NULL; | ||||
| } | ||||
| 
 | ||||
| static void cmd_crop_sprite_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   { | ||||
|     Undoable undoable(sprite, "Sprite Crop"); | ||||
|     int bgcolor = get_color_for_image(sprite->imgtype, | ||||
|  | @ -68,12 +69,13 @@ static void cmd_crop_sprite_execute(const char *argument) | |||
| 
 | ||||
| static bool cmd_autocrop_sprite_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite != NULL; | ||||
| } | ||||
| 
 | ||||
| static void cmd_autocrop_sprite_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   { | ||||
|     Undoable undoable(sprite, "Sprite Autocrop"); | ||||
|     undoable.autocrop_sprite(colorbar_get_bg_color(app_get_colorbar())); | ||||
|  |  | |||
|  | @ -30,20 +30,22 @@ | |||
| 
 | ||||
| static bool cmd_cut_enabled(const char *argument) | ||||
| { | ||||
|   if ((!current_sprite) || | ||||
|       (!current_sprite->layer) || | ||||
|       (!layer_is_readable(current_sprite->layer)) || | ||||
|       (!layer_is_writable(current_sprite->layer)) || | ||||
|       (!current_sprite->mask) || | ||||
|       (!current_sprite->mask->bitmap)) | ||||
|     return FALSE; | ||||
|   CurrentSprite sprite; | ||||
|   if ((!sprite) || | ||||
|       (!sprite->layer) || | ||||
|       (!layer_is_readable(sprite->layer)) || | ||||
|       (!layer_is_writable(sprite->layer)) || | ||||
|       (!sprite->mask) || | ||||
|       (!sprite->mask->bitmap)) | ||||
|     return false; | ||||
|   else | ||||
|     return GetImage(current_sprite) ? TRUE: FALSE; | ||||
|     return GetImage(sprite) ? true: false; | ||||
| } | ||||
| 
 | ||||
| static void cmd_cut_execute(const char *argument) | ||||
| { | ||||
|   clipboard::cut(current_sprite); | ||||
|   CurrentSprite sprite; | ||||
|   clipboard::cut(sprite); | ||||
| } | ||||
| 
 | ||||
| Command cmd_cut = { | ||||
|  |  | |||
|  | @ -27,14 +27,13 @@ | |||
| 
 | ||||
| static bool cmd_deselect_mask_enabled(const char *argument) | ||||
| { | ||||
|   return | ||||
|     current_sprite != NULL && | ||||
|     !mask_is_empty(current_sprite->mask); | ||||
|   CurrentSprite sprite; | ||||
|   return sprite && !mask_is_empty(sprite->mask); | ||||
| } | ||||
| 
 | ||||
| static void cmd_deselect_mask_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Mask *mask; | ||||
| 
 | ||||
|   /* destroy the *deselected* mask */ | ||||
|  |  | |||
|  | @ -33,20 +33,20 @@ static Layer *duplicate_layer(); | |||
| 
 | ||||
| static bool cmd_duplicate_layer_enabled(const char *argument) | ||||
| { | ||||
|   return | ||||
|     current_sprite != NULL && | ||||
|     current_sprite->layer != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite && sprite->layer; | ||||
| } | ||||
| 
 | ||||
| static void cmd_duplicate_layer_execute(const char *argument) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   if (duplicate_layer() != NULL) | ||||
|     update_screen_for_sprite(current_sprite); | ||||
|     update_screen_for_sprite(sprite); | ||||
| } | ||||
| 
 | ||||
| static Layer *duplicate_layer() | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Layer *layer_copy; | ||||
|   char buf[1024]; | ||||
| 
 | ||||
|  |  | |||
|  | @ -22,6 +22,7 @@ | |||
| 
 | ||||
| #include "jinete/jinete.h" | ||||
| 
 | ||||
| #include "ase/ui_context.h" | ||||
| #include "commands/commands.h" | ||||
| #include "core/app.h" | ||||
| #include "core/cfg.h" | ||||
|  | @ -31,13 +32,14 @@ | |||
| 
 | ||||
| static bool cmd_duplicate_sprite_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_duplicate_sprite_execute(const char *argument) | ||||
| { | ||||
|   JWidget window, src_name, dst_name, flatten; | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   char buf[1024]; | ||||
| 
 | ||||
|   /* load the window widget */ | ||||
|  | @ -74,9 +76,11 @@ static void cmd_duplicate_sprite_execute(const char *argument) | |||
|     if (sprite_copy != NULL) { | ||||
|       sprite_set_filename(sprite_copy, jwidget_get_text(dst_name)); | ||||
| 
 | ||||
|       sprite_mount(sprite_copy); | ||||
|       set_current_sprite(sprite_copy); | ||||
|       sprite_show(sprite_copy); | ||||
|       UIContext* context = UIContext::instance(); | ||||
| 
 | ||||
|       context->add_sprite(sprite_copy); | ||||
|       context->set_current_sprite(sprite_copy); | ||||
|       context->show_sprite(sprite_copy); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -20,6 +20,7 @@ | |||
| 
 | ||||
| #include "jinete/jinete.h" | ||||
| 
 | ||||
| #include "ase/ui_context.h" | ||||
| #include "commands/commands.h" | ||||
| #include "core/app.h" | ||||
| #include "modules/sprites.h" | ||||
|  | @ -27,7 +28,8 @@ | |||
| 
 | ||||
| static void cmd_exit_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = get_first_sprite(); | ||||
|   UIContext* context = UIContext::instance(); | ||||
|   Sprite *sprite = context->get_first_sprite(); | ||||
| 
 | ||||
|   while (sprite) { | ||||
|     // check if this sprite is modified
 | ||||
|  | @ -37,7 +39,7 @@ static void cmd_exit_execute(const char *argument) | |||
|       } | ||||
|       break; | ||||
|     } | ||||
|     sprite = get_next_sprite(sprite); | ||||
|     sprite = context->get_next_sprite(sprite); | ||||
|   } | ||||
| 
 | ||||
|   /* close the window */ | ||||
|  |  | |||
|  | @ -26,7 +26,8 @@ | |||
| 
 | ||||
| static bool cmd_film_editor_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_film_editor_execute(const char *argument) | ||||
|  |  | |||
|  | @ -27,12 +27,13 @@ | |||
| 
 | ||||
| static bool cmd_flatten_layers_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_flatten_layers_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   if (undo_is_enabled(sprite->undo)) | ||||
|     undo_set_label(sprite->undo, "Flatten Layers"); | ||||
|  |  | |||
|  | @ -36,7 +36,8 @@ static void do_flip(int horz); | |||
| 
 | ||||
| static bool cmd_flip_horizontal_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_flip_horizontal_execute(const char *argument) | ||||
|  | @ -50,7 +51,8 @@ static void cmd_flip_horizontal_execute(const char *argument) | |||
| 
 | ||||
| static bool cmd_flip_vertical_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_flip_vertical_execute(const char *argument) | ||||
|  | @ -63,7 +65,7 @@ static void cmd_flip_vertical_execute(const char *argument) | |||
| 
 | ||||
| static void do_flip(int horz) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Image *image, *area; | ||||
|   int x1, y1, x2, y2; | ||||
|   int x, y; | ||||
|  | @ -108,7 +110,7 @@ static void do_flip(int horz) | |||
| 		     !horz? y2-y: y1+y, | ||||
| 		     image_getpixel(area, x, y)); | ||||
|   image_free(area); | ||||
|   update_screen_for_sprite(current_sprite); | ||||
|   update_screen_for_sprite(sprite); | ||||
| } | ||||
| 
 | ||||
| Command cmd_flip_horizontal = { | ||||
|  |  | |||
|  | @ -30,19 +30,21 @@ void dialogs_frame_length(int sprite_frame); | |||
| 
 | ||||
| static bool cmd_frame_properties_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_frame_properties_execute(const char *argument) | ||||
| { | ||||
|   dialogs_frame_length(current_sprite->frame); | ||||
|   CurrentSprite sprite; | ||||
|   dialogs_frame_length(sprite->frame); | ||||
| } | ||||
| 
 | ||||
| /* if sprite_frame < 0, set the frame length of all frames */ | ||||
| void dialogs_frame_length(int sprite_frame) | ||||
| { | ||||
|   JWidget window, frame, frlen, ok; | ||||
|   Sprite* sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   char buf[64]; | ||||
| 
 | ||||
|   window = load_widget("frlen.jid", "frame_duration"); | ||||
|  |  | |||
|  | @ -31,14 +31,16 @@ | |||
| 
 | ||||
| static bool cmd_goto_first_frame_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite != NULL; | ||||
| } | ||||
| 
 | ||||
| static void cmd_goto_first_frame_execute(const char *argument) | ||||
| { | ||||
|   current_sprite->frame = 0; | ||||
|   CurrentSprite sprite; | ||||
|   sprite->frame = 0; | ||||
| 
 | ||||
|   update_screen_for_sprite(current_sprite); | ||||
|   update_screen_for_sprite(sprite); | ||||
|   editor_update_statusbar_for_standby(current_editor); | ||||
| } | ||||
| 
 | ||||
|  | @ -48,17 +50,20 @@ static void cmd_goto_first_frame_execute(const char *argument) | |||
| 
 | ||||
| static bool cmd_goto_previous_frame_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite != NULL; | ||||
| } | ||||
| 
 | ||||
| static void cmd_goto_previous_frame_execute(const char *argument) | ||||
| { | ||||
|   if (current_sprite->frame > 0) | ||||
|     current_sprite->frame--; | ||||
|   else | ||||
|     current_sprite->frame = current_sprite->frames-1; | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   update_screen_for_sprite(current_sprite); | ||||
|   if (sprite->frame > 0) | ||||
|     sprite->frame--; | ||||
|   else | ||||
|     sprite->frame = sprite->frames-1; | ||||
| 
 | ||||
|   update_screen_for_sprite(sprite); | ||||
|   editor_update_statusbar_for_standby(current_editor); | ||||
| } | ||||
| 
 | ||||
|  | @ -68,17 +73,20 @@ static void cmd_goto_previous_frame_execute(const char *argument) | |||
| 
 | ||||
| static bool cmd_goto_next_frame_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite != NULL; | ||||
| } | ||||
| 
 | ||||
| static void cmd_goto_next_frame_execute(const char *argument) | ||||
| { | ||||
|   if (current_sprite->frame < current_sprite->frames-1) | ||||
|     current_sprite->frame++; | ||||
|   else | ||||
|     current_sprite->frame = 0; | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   update_screen_for_sprite(current_sprite); | ||||
|   if (sprite->frame < sprite->frames-1) | ||||
|     sprite->frame++; | ||||
|   else | ||||
|     sprite->frame = 0; | ||||
| 
 | ||||
|   update_screen_for_sprite(sprite); | ||||
|   editor_update_statusbar_for_standby(current_editor); | ||||
| } | ||||
| 
 | ||||
|  | @ -88,14 +96,16 @@ static void cmd_goto_next_frame_execute(const char *argument) | |||
| 
 | ||||
| static bool cmd_goto_last_frame_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite != NULL; | ||||
| } | ||||
| 
 | ||||
| static void cmd_goto_last_frame_execute(const char *argument) | ||||
| { | ||||
|   current_sprite->frame = current_sprite->frames-1; | ||||
|   CurrentSprite sprite; | ||||
|   sprite->frame = sprite->frames-1; | ||||
| 
 | ||||
|   update_screen_for_sprite(current_sprite); | ||||
|   update_screen_for_sprite(sprite); | ||||
|   editor_update_statusbar_for_standby(current_editor); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -34,26 +34,28 @@ | |||
| 
 | ||||
| static bool cmd_goto_previous_layer_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite != NULL; | ||||
| } | ||||
| 
 | ||||
| static void cmd_goto_previous_layer_execute(const char *argument) | ||||
| { | ||||
|   int i = sprite_layer2index(current_sprite, current_sprite->layer); | ||||
|   CurrentSprite sprite; | ||||
|   int i = sprite_layer2index(sprite, sprite->layer); | ||||
|    | ||||
|   if (i > 0) | ||||
|     i--; | ||||
|   else | ||||
|     i = sprite_count_layers(current_sprite)-1; | ||||
|     i = sprite_count_layers(sprite)-1; | ||||
| 
 | ||||
|   current_sprite->layer = sprite_index2layer(current_sprite, i); | ||||
|   sprite->layer = sprite_index2layer(sprite, i); | ||||
| 
 | ||||
|   update_screen_for_sprite(current_sprite); | ||||
|   update_screen_for_sprite(sprite); | ||||
|   editor_update_statusbar_for_standby(current_editor); | ||||
| 
 | ||||
|   statusbar_show_tip(app_get_statusbar(), 1000, | ||||
| 		     _("Layer `%s' selected"), | ||||
| 		     current_sprite->layer->name); | ||||
| 		     sprite->layer->name); | ||||
| } | ||||
| 
 | ||||
| /* ======================== */ | ||||
|  | @ -62,26 +64,28 @@ static void cmd_goto_previous_layer_execute(const char *argument) | |||
| 
 | ||||
| static bool cmd_goto_next_layer_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite != NULL; | ||||
| } | ||||
| 
 | ||||
| static void cmd_goto_next_layer_execute(const char *argument) | ||||
| { | ||||
|   int i = sprite_layer2index(current_sprite, current_sprite->layer); | ||||
|   CurrentSprite sprite; | ||||
|   int i = sprite_layer2index(sprite, sprite->layer); | ||||
| 
 | ||||
|   if (i < sprite_count_layers(current_sprite)-1) | ||||
|   if (i < sprite_count_layers(sprite)-1) | ||||
|     i++; | ||||
|   else | ||||
|     i = 0; | ||||
| 
 | ||||
|   current_sprite->layer = sprite_index2layer(current_sprite, i); | ||||
|   sprite->layer = sprite_index2layer(sprite, i); | ||||
| 
 | ||||
|   update_screen_for_sprite(current_sprite); | ||||
|   update_screen_for_sprite(sprite); | ||||
|   editor_update_statusbar_for_standby(current_editor); | ||||
| 
 | ||||
|   statusbar_show_tip(app_get_statusbar(), 1000, | ||||
| 		     _("Layer `%s' selected"), | ||||
| 		     current_sprite->layer->name); | ||||
| 		     sprite->layer->name); | ||||
| } | ||||
| 
 | ||||
| Command cmd_goto_previous_layer = { | ||||
|  |  | |||
|  | @ -28,12 +28,13 @@ | |||
| 
 | ||||
| static bool cmd_invert_mask_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_invert_mask_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Mask *mask; | ||||
| 
 | ||||
|   /* change the selection */ | ||||
|  |  | |||
|  | @ -31,18 +31,19 @@ | |||
| 
 | ||||
| static bool cmd_layer_from_background_enabled(const char *argument) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   return | ||||
|     current_sprite != NULL && | ||||
|     current_sprite->layer != NULL && | ||||
|     layer_is_image(current_sprite->layer) && | ||||
|     layer_is_readable(current_sprite->layer) && | ||||
|     layer_is_writable(current_sprite->layer) && | ||||
|     layer_is_background(current_sprite->layer); | ||||
|     sprite && | ||||
|     sprite->layer && | ||||
|     layer_is_image(sprite->layer) && | ||||
|     layer_is_readable(sprite->layer) && | ||||
|     layer_is_writable(sprite->layer) && | ||||
|     layer_is_background(sprite->layer); | ||||
| } | ||||
| 
 | ||||
| static void cmd_layer_from_background_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   if (undo_is_enabled(sprite->undo)) | ||||
|     undo_set_label(sprite->undo, "Layer from Background"); | ||||
|  |  | |||
|  | @ -29,16 +29,15 @@ | |||
| 
 | ||||
| static bool cmd_layer_properties_enabled(const char *argument) | ||||
| { | ||||
|   return | ||||
|     current_sprite != NULL && | ||||
|     current_sprite->layer != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite && sprite->layer; | ||||
| } | ||||
| 
 | ||||
| static void cmd_layer_properties_execute(const char *argument) | ||||
| { | ||||
|   JWidget window, box1, box2, box3, label_name, entry_name; | ||||
|   JWidget button_ok, button_cancel, label_bm, view_bm, list_bm; | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Layer *layer = sprite->layer; | ||||
| 
 | ||||
|   window = jwindow_new(_("Layer Properties")); | ||||
|  |  | |||
|  | @ -31,13 +31,13 @@ | |||
| 
 | ||||
| static bool cmd_load_mask_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_load_mask_execute(const char *argument) | ||||
| { | ||||
|   /* get current sprite */ | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   jstring filename = ase_file_selector(_("Load .msk File"), "", "msk"); | ||||
|   if (!filename.empty()) { | ||||
|     Mask *mask = load_msk_file(filename.c_str()); | ||||
|  |  | |||
|  | @ -27,12 +27,13 @@ | |||
| 
 | ||||
| static bool cmd_mask_all_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
|    | ||||
| static void cmd_mask_all_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   /* undo */ | ||||
|   if (undo_is_enabled(sprite->undo)) { | ||||
|  |  | |||
|  | @ -26,7 +26,8 @@ | |||
| 
 | ||||
| static bool cmd_mask_by_color_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_mask_by_color_execute(const char *argument) | ||||
|  |  | |||
|  | @ -33,18 +33,15 @@ | |||
| 
 | ||||
| static bool cmd_merge_down_layer_enabled(const char *argument) | ||||
| { | ||||
|   Layer *src_layer, *dst_layer; | ||||
|   Sprite *sprite; | ||||
| 
 | ||||
|   sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   if (!sprite) | ||||
|     return FALSE; | ||||
| 
 | ||||
|   src_layer = sprite->layer; | ||||
|   Layer *src_layer = sprite->layer; | ||||
|   if (!src_layer || !layer_is_image(src_layer)) | ||||
|     return FALSE; | ||||
| 
 | ||||
|   dst_layer = layer_get_prev(sprite->layer); | ||||
|   Layer* dst_layer = layer_get_prev(sprite->layer); | ||||
|   if (!dst_layer || !layer_is_image(dst_layer)) | ||||
|     return FALSE; | ||||
| 
 | ||||
|  | @ -53,7 +50,7 @@ static bool cmd_merge_down_layer_enabled(const char *argument) | |||
| 
 | ||||
| static void cmd_merge_down_layer_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Layer *src_layer, *dst_layer; | ||||
|   Cel *src_cel, *dst_cel; | ||||
|   Image *src_image, *dst_image; | ||||
|  |  | |||
|  | @ -24,6 +24,7 @@ | |||
| 
 | ||||
| #include "jinete/jinete.h" | ||||
| 
 | ||||
| #include "ase/ui_context.h" | ||||
| #include "commands/commands.h" | ||||
| #include "console/console.h" | ||||
| #include "core/app.h" | ||||
|  | @ -150,7 +151,8 @@ static void cmd_new_file_execute(const char *argument) | |||
| 	undo_enable(sprite->undo); | ||||
| 
 | ||||
| 	/* show the sprite to the user */ | ||||
| 	sprite_show(sprite); | ||||
| 	UIContext* context = UIContext::instance(); | ||||
| 	context->show_sprite(sprite); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  |  | |||
|  | @ -38,17 +38,18 @@ | |||
| 
 | ||||
| static bool cmd_new_frame_enabled(const char *argument) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   return | ||||
|     current_sprite && | ||||
|     current_sprite->layer && | ||||
|     layer_is_readable(current_sprite->layer) && | ||||
|     layer_is_writable(current_sprite->layer) && | ||||
|     layer_is_image(current_sprite->layer); | ||||
|     sprite && | ||||
|     sprite->layer && | ||||
|     layer_is_readable(sprite->layer) && | ||||
|     layer_is_writable(sprite->layer) && | ||||
|     layer_is_image(sprite->layer); | ||||
| } | ||||
| 
 | ||||
| static void cmd_new_frame_execute(const char *argument) | ||||
| { | ||||
|   Sprite* sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   { | ||||
|     Undoable undoable(sprite, "New Frame"); | ||||
|     undoable.new_frame(); | ||||
|  |  | |||
|  | @ -31,13 +31,14 @@ | |||
| 
 | ||||
| static bool cmd_new_layer_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_new_layer_execute(const char *argument) | ||||
| { | ||||
|   JWidget window, name_widget; | ||||
|   Sprite* sprite = current_sprite; /* get current sprite */ | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   /* load the window widget */ | ||||
|   window = load_widget("newlay.jid", "new_layer"); | ||||
|  |  | |||
|  | @ -30,15 +30,16 @@ | |||
| 
 | ||||
| static bool cmd_new_layer_set_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_new_layer_set_execute(const char *argument) | ||||
| { | ||||
|   JWidget window; | ||||
|   Sprite *sprite = current_sprite; /* get current sprite */ | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   /* load the window widget */ | ||||
|   // load the window widget
 | ||||
|   window = load_widget("newlay.jid", "new_layer_set"); | ||||
|   if (!window) | ||||
|     return; | ||||
|  |  | |||
|  | @ -23,6 +23,7 @@ | |||
| 
 | ||||
| #include "jinete/jinete.h" | ||||
| 
 | ||||
| #include "ase/ui_context.h" | ||||
| #include "commands/commands.h" | ||||
| #include "console/console.h" | ||||
| #include "core/app.h" | ||||
|  | @ -56,7 +57,7 @@ static void openfile_bg(void *fop_data) | |||
|   fop_operate(fop); | ||||
| 
 | ||||
|   if (fop_is_stop(fop) && fop->sprite) { | ||||
|     sprite_free(fop->sprite); | ||||
|     delete fop->sprite; | ||||
|     fop->sprite = NULL; | ||||
|   } | ||||
| 
 | ||||
|  | @ -197,9 +198,11 @@ static void cmd_open_file_execute(const char *argument) | |||
| 	  else { | ||||
| 	    Sprite *sprite = fop->sprite; | ||||
| 	    if (sprite) { | ||||
| 	      UIContext* context = UIContext::instance(); | ||||
| 
 | ||||
| 	      recent_file(fop->filename); | ||||
| 	      sprite_mount(sprite); | ||||
| 	      sprite_show(sprite); | ||||
| 	      context->add_sprite(sprite); | ||||
| 	      context->show_sprite(sprite); | ||||
| 	    } | ||||
| 	    /* if the sprite isn't NULL and the file-operation wasn't
 | ||||
| 	       stopped by the user...  */ | ||||
|  |  | |||
|  | @ -32,7 +32,6 @@ | |||
| #include "modules/gui.h" | ||||
| #include "modules/palettes.h" | ||||
| #include "modules/sprites.h" | ||||
| #include "modules/sprites.h" | ||||
| #include "raster/image.h" | ||||
| #include "raster/palette.h" | ||||
| #include "raster/sprite.h" | ||||
|  | @ -75,8 +74,9 @@ static void cmd_palette_editor_execute(const char *argument) | |||
|   JWidget button_ramp, button_quantize; | ||||
|   int frame, columns; | ||||
|   Palette *palette = NULL; | ||||
|   int imgtype = current_sprite ? current_sprite->imgtype: IMAGE_INDEXED; | ||||
|   int frame_bak = current_sprite ? current_sprite->frame : 0; | ||||
|   CurrentSprite sprite; | ||||
|   int imgtype = sprite ? sprite->imgtype: IMAGE_INDEXED; | ||||
|   int frame_bak = sprite ? sprite->frame : 0; | ||||
|   bool all_frames_same_palette = TRUE; | ||||
| 
 | ||||
|   if (imgtype == IMAGE_GRAYSCALE) { | ||||
|  | @ -114,16 +114,16 @@ static void cmd_palette_editor_execute(const char *argument) | |||
|   } | ||||
| 
 | ||||
|   /* create current_sprite->frames palettes */ | ||||
|   if (current_sprite) { | ||||
|     palettes = (Palette **)jmalloc(sizeof(Palette *) * current_sprite->frames); | ||||
|   if (sprite) { | ||||
|     palettes = (Palette **)jmalloc(sizeof(Palette *) * sprite->frames); | ||||
|     if (!palettes) { | ||||
|       jalert(_("Error<<Not enough memory||&OK")); | ||||
|       return; | ||||
|     } | ||||
|     for (frame=0; frame<current_sprite->frames; ++frame) { | ||||
|     for (frame=0; frame<sprite->frames; ++frame) { | ||||
|       palettes[frame] = palette_new(frame, MAX_PALETTE_COLORS); | ||||
|       palette_copy_colors(palettes[frame], | ||||
| 			  sprite_get_palette(current_sprite, frame)); | ||||
| 			  sprite_get_palette(sprite, frame)); | ||||
| 
 | ||||
|       if (frame > 0 && | ||||
| 	  palette_count_diff(palettes[frame-1], palettes[frame], NULL, NULL) > 0) { | ||||
|  | @ -167,9 +167,9 @@ static void cmd_palette_editor_execute(const char *argument) | |||
|     jwidget_deselect(check_all_frames); | ||||
|    | ||||
|   /* frame */ | ||||
|   if (current_sprite) { | ||||
|     jslider_set_range(slider_frame, 0, current_sprite->frames-1); | ||||
|     jslider_set_value(slider_frame, current_sprite->frame); | ||||
|   if (sprite) { | ||||
|     jslider_set_range(slider_frame, 0, sprite->frames-1); | ||||
|     jslider_set_value(slider_frame, sprite->frame); | ||||
|      | ||||
|     if (jwidget_is_selected(check_all_frames)) | ||||
|       jwidget_disable(slider_frame); | ||||
|  | @ -207,8 +207,8 @@ static void cmd_palette_editor_execute(const char *argument) | |||
| 
 | ||||
|   /* check the killer widget */ | ||||
|   if (jwindow_get_killer(window) == button_ok) { | ||||
|     if (current_sprite) { | ||||
|       sprite_reset_palettes(current_sprite); | ||||
|     if (sprite) { | ||||
|       sprite_reset_palettes(sprite); | ||||
| 
 | ||||
|       /* one palette */ | ||||
|       if (jwidget_is_selected(check_all_frames)) { | ||||
|  | @ -216,7 +216,7 @@ static void cmd_palette_editor_execute(const char *argument) | |||
| 	palette_copy_colors(palettes[0], | ||||
| 			    get_current_palette()); | ||||
| 
 | ||||
| 	sprite_set_palette(current_sprite, palettes[0], TRUE); | ||||
| 	sprite_set_palette(sprite, palettes[0], TRUE); | ||||
|       } | ||||
|       /* various palettes */ | ||||
|       else { | ||||
|  | @ -224,11 +224,11 @@ static void cmd_palette_editor_execute(const char *argument) | |||
| 	palette_copy_colors(palettes[frame], | ||||
| 			    get_current_palette()); | ||||
| 
 | ||||
| 	for (frame=0; frame<current_sprite->frames; ++frame) { | ||||
| 	for (frame=0; frame<sprite->frames; ++frame) { | ||||
| 	  if (frame == 0 || | ||||
| 	      palette_count_diff(palettes[frame], | ||||
| 				 palettes[frame-1], NULL, NULL) > 0) { | ||||
| 	    sprite_set_palette(current_sprite, palettes[frame], TRUE); | ||||
| 	    sprite_set_palette(sprite, palettes[frame], TRUE); | ||||
| 	  } | ||||
| 	} | ||||
|       } | ||||
|  | @ -242,9 +242,9 @@ static void cmd_palette_editor_execute(const char *argument) | |||
|   /* cancel or ESC */ | ||||
|   else { | ||||
|     /* restore the system palette */ | ||||
|     if (current_sprite) { | ||||
|       current_sprite->frame = frame_bak; | ||||
|       set_current_palette(sprite_get_palette(current_sprite, frame_bak), TRUE); | ||||
|     if (sprite) { | ||||
|       sprite->frame = frame_bak; | ||||
|       set_current_palette(sprite_get_palette(sprite, frame_bak), TRUE); | ||||
|     } | ||||
|     else { | ||||
|       set_current_palette(NULL, TRUE); | ||||
|  | @ -264,9 +264,9 @@ static void cmd_palette_editor_execute(const char *argument) | |||
|   jwidget_free(window); | ||||
| 
 | ||||
|   if (palettes) { | ||||
|     assert(current_sprite); | ||||
|     assert(sprite); | ||||
| 
 | ||||
|     for (frame=0; frame<current_sprite->frames; ++frame) | ||||
|     for (frame=0; frame<sprite->frames; ++frame) | ||||
|       palette_free(palettes[frame]); | ||||
| 
 | ||||
|     jfree(palettes); | ||||
|  | @ -354,6 +354,7 @@ static void ramp_command(JWidget widget) | |||
| 
 | ||||
| static void quantize_command(JWidget widget) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   Palette *palette = palette_new(0, MAX_PALETTE_COLORS); | ||||
|   bool array[256]; | ||||
| 
 | ||||
|  | @ -361,8 +362,8 @@ static void quantize_command(JWidget widget) | |||
|   palette_copy_colors(palette, | ||||
| 		      paledit_get_palette(palette_editor)); | ||||
| 
 | ||||
|   if (current_sprite && current_sprite->imgtype == IMAGE_RGB) { | ||||
|     sprite_quantize_ex(current_sprite, palette); | ||||
|   if (sprite && sprite->imgtype == IMAGE_RGB) { | ||||
|     sprite_quantize_ex(sprite, palette); | ||||
|   } | ||||
|   else { | ||||
|     jalert(_("Error<<You can use this command only for RGB sprites||&OK")); | ||||
|  | @ -436,12 +437,13 @@ static bool slider_columns_change_hook(JWidget widget, void *data) | |||
| 
 | ||||
| static bool slider_frame_change_hook(JWidget widget, void *data) | ||||
| { | ||||
|   int old_frame = current_sprite->frame; | ||||
|   CurrentSprite sprite; | ||||
|   int old_frame = sprite->frame; | ||||
|   int new_frame = jslider_get_value(slider_frame); | ||||
| 
 | ||||
|   palette_copy_colors(palettes[old_frame], | ||||
| 		      get_current_palette()); | ||||
|   current_sprite->frame = new_frame; | ||||
|   sprite->frame = new_frame; | ||||
|   set_new_palette(palettes[new_frame]); | ||||
| 
 | ||||
|   return FALSE; | ||||
|  | @ -449,6 +451,7 @@ static bool slider_frame_change_hook(JWidget widget, void *data) | |||
| 
 | ||||
| static bool check_all_frames_change_hook(JWidget widget, void *data) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   int frame = jslider_get_value(slider_frame); | ||||
| 
 | ||||
|   palette_copy_colors(palettes[frame], | ||||
|  | @ -458,7 +461,7 @@ static bool check_all_frames_change_hook(JWidget widget, void *data) | |||
|     bool has_two_or_more_palettes = FALSE; | ||||
|     int c; | ||||
| 
 | ||||
|     for (c=1; c<current_sprite->frames; c++) { | ||||
|     for (c=1; c<sprite->frames; c++) { | ||||
|       if (palette_count_diff(palettes[c-1], palettes[c], NULL, NULL) > 0) { | ||||
| 	has_two_or_more_palettes = TRUE; | ||||
| 	break; | ||||
|  |  | |||
|  | @ -26,17 +26,19 @@ | |||
| 
 | ||||
| static bool cmd_paste_enabled(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   return (sprite && clipboard::can_paste()); | ||||
| } | ||||
| 
 | ||||
| static void cmd_paste_execute(const char *argument) | ||||
| { | ||||
|   if (undo_is_enabled(current_sprite->undo)) | ||||
|     undo_set_label(current_sprite->undo, "Paste"); | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   clipboard::paste(current_sprite); | ||||
|   if (undo_is_enabled(sprite->undo)) | ||||
|     undo_set_label(sprite->undo, "Paste"); | ||||
| 
 | ||||
|   clipboard::paste(sprite); | ||||
| } | ||||
| 
 | ||||
| Command cmd_paste = { | ||||
|  |  | |||
|  | @ -43,12 +43,13 @@ END_OF_STATIC_FUNCTION(speed_timer_callback); | |||
| 
 | ||||
| static bool cmd_play_animation_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_play_animation_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   int old_frame, msecs; | ||||
|   bool done = FALSE; | ||||
|   bool onionskin = get_onionskin(); | ||||
|  |  | |||
|  | @ -43,7 +43,8 @@ static void preview_sprite(int flags); | |||
| 
 | ||||
| static bool cmd_preview_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| /* ======================== */ | ||||
|  |  | |||
|  | @ -28,18 +28,21 @@ | |||
| 
 | ||||
| static bool cmd_redo_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL && undo_can_redo(current_sprite->undo); | ||||
|   CurrentSprite sprite; | ||||
|   return sprite != NULL && undo_can_redo(sprite->undo); | ||||
| } | ||||
| 
 | ||||
| static void cmd_redo_execute(const char *argument) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   statusbar_show_tip(app_get_statusbar(), 1000, | ||||
| 		     _("Redid %s"), | ||||
| 		     undo_get_next_redo_label(current_sprite->undo)); | ||||
| 		     undo_get_next_redo_label(sprite->undo)); | ||||
| 
 | ||||
|   undo_do_redo(current_sprite->undo); | ||||
|   sprite_generate_mask_boundaries(current_sprite); | ||||
|   update_screen_for_sprite(current_sprite); | ||||
|   undo_do_redo(sprite->undo); | ||||
|   sprite_generate_mask_boundaries(sprite); | ||||
|   update_screen_for_sprite(sprite); | ||||
| } | ||||
| 
 | ||||
| Command cmd_redo = { | ||||
|  |  | |||
|  | @ -28,18 +28,19 @@ | |||
| 
 | ||||
| static bool cmd_remove_cel_enabled(const char *argument) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   return | ||||
|     current_sprite && | ||||
|     current_sprite->layer && | ||||
|     layer_is_readable(current_sprite->layer) && | ||||
|     layer_is_writable(current_sprite->layer) && | ||||
|     layer_is_image(current_sprite->layer) && | ||||
|     layer_get_cel(current_sprite->layer, current_sprite->frame); | ||||
|     sprite && | ||||
|     sprite->layer && | ||||
|     layer_is_readable(sprite->layer) && | ||||
|     layer_is_writable(sprite->layer) && | ||||
|     layer_is_image(sprite->layer) && | ||||
|     layer_get_cel(sprite->layer, sprite->frame); | ||||
| } | ||||
| 
 | ||||
| static void cmd_remove_cel_execute(const char *argument) | ||||
| { | ||||
|   Sprite* sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Cel* cel = layer_get_cel(sprite->layer, sprite->frame); | ||||
|   { | ||||
|     Undoable undoable(sprite, "Remove Cel"); | ||||
|  |  | |||
|  | @ -28,14 +28,15 @@ | |||
| 
 | ||||
| static bool cmd_remove_frame_enabled(const char *argument) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   return | ||||
|     current_sprite != NULL && | ||||
|     current_sprite->frames > 1; | ||||
|     sprite != NULL && | ||||
|     sprite->frames > 1; | ||||
| } | ||||
| 
 | ||||
| static void cmd_remove_frame_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   { | ||||
|     Undoable undoable(sprite, "Remove Frame"); | ||||
|     undoable.remove_frame(sprite->frame); | ||||
|  |  | |||
|  | @ -27,14 +27,15 @@ | |||
| 
 | ||||
| static bool cmd_remove_layer_enabled(const char *argument) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   return | ||||
|     current_sprite != NULL && | ||||
|     current_sprite->layer != NULL; | ||||
|     sprite != NULL && | ||||
|     sprite->layer != NULL; | ||||
| } | ||||
| 
 | ||||
| static void cmd_remove_layer_execute(const char *argument) | ||||
| { | ||||
|   Sprite* sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   { | ||||
|     Undoable undoable(sprite, "Remove Layer"); | ||||
|     undoable.remove_layer(sprite->layer); | ||||
|  |  | |||
|  | @ -27,14 +27,15 @@ | |||
| 
 | ||||
| static bool cmd_reselect_mask_enabled(const char *argument) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   return | ||||
|     current_sprite != NULL && | ||||
|     sprite_request_mask(current_sprite, "*deselected*") != NULL; | ||||
|     sprite != NULL && | ||||
|     sprite_request_mask(sprite, "*deselected*") != NULL; | ||||
| } | ||||
| 
 | ||||
| static void cmd_reselect_mask_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Mask *mask; | ||||
| 
 | ||||
|   /* request *deselected* mask */ | ||||
|  |  | |||
|  | @ -145,7 +145,7 @@ static void save_sprite_in_background(Sprite* sprite, bool mark_as_saved) | |||
| 
 | ||||
| static void save_as_dialog(const char* dlg_title, bool mark_as_saved) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   char exts[4096]; | ||||
|   jstring filename; | ||||
|   jstring newfilename; | ||||
|  | @ -200,7 +200,8 @@ static void save_as_dialog(const char* dlg_title, bool mark_as_saved) | |||
|  */ | ||||
| static bool cmd_save_file_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  | @ -210,7 +211,7 @@ static bool cmd_save_file_enabled(const char *argument) | |||
|  */ | ||||
| static void cmd_save_file_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   /* if the sprite is associated to a file in the file-system, we can
 | ||||
|      save it directly without user interaction */ | ||||
|  | @ -231,7 +232,8 @@ static void cmd_save_file_execute(const char *argument) | |||
| 
 | ||||
| static bool cmd_save_file_as_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_save_file_as_execute(const char *argument) | ||||
|  | @ -245,12 +247,13 @@ static void cmd_save_file_as_execute(const char *argument) | |||
| 
 | ||||
| static bool cmd_save_file_copy_as_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_save_file_copy_as_execute(const char *argument) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   jstring old_filename = sprite->filename; | ||||
| 
 | ||||
|   // show "Save As" dialog
 | ||||
|  |  | |||
|  | @ -31,17 +31,17 @@ | |||
| 
 | ||||
| static bool cmd_save_mask_enabled(const char *argument) | ||||
| { | ||||
|   if (!current_sprite) | ||||
|     return FALSE; | ||||
|   CurrentSprite sprite; | ||||
|   if (!sprite) | ||||
|     return false; | ||||
|   else | ||||
|     return (current_sprite->mask && | ||||
| 	    current_sprite->mask->bitmap) ? TRUE: FALSE; | ||||
|     return (sprite->mask && | ||||
| 	    sprite->mask->bitmap) ? true: false; | ||||
| } | ||||
| 
 | ||||
| static void cmd_save_mask_execute(const char *argument) | ||||
| { | ||||
|   /* get current sprite */ | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   jstring filename = "default.msk"; | ||||
|   int ret; | ||||
| 
 | ||||
|  |  | |||
|  | @ -100,7 +100,7 @@ static void cmd_screen_shot_execute(const char *argument) | |||
|     sprite_save(sprite); | ||||
| 
 | ||||
|     /* destroy the sprite */ | ||||
|     sprite_free(sprite); | ||||
|     delete sprite; | ||||
|   } | ||||
| 
 | ||||
|   /* destroy the bitmap */ | ||||
|  |  | |||
|  | @ -24,6 +24,7 @@ | |||
| 
 | ||||
| #include "jinete/jinete.h" | ||||
| 
 | ||||
| #include "ase/ui_context.h" | ||||
| #include "commands/commands.h" | ||||
| #include "core/app.h" | ||||
| #include "modules/sprites.h" | ||||
|  | @ -44,6 +45,8 @@ static bool cmd_select_file_enabled(const char *argument) | |||
| 
 | ||||
| static bool cmd_select_file_checked(const char *argument) | ||||
| { | ||||
|   CurrentSprite current_sprite; | ||||
| 
 | ||||
|   if (argument) { | ||||
|     int sprite_id = ustrtol(argument, NULL, 10); | ||||
|     GfxObj *gfxobj = gfxobj_find(sprite_id); | ||||
|  | @ -57,15 +60,17 @@ static bool cmd_select_file_checked(const char *argument) | |||
| 
 | ||||
| static void cmd_select_file_execute(const char *argument) | ||||
| { | ||||
|   UIContext* context = UIContext::instance(); | ||||
| 
 | ||||
|   if (argument) { | ||||
|     int sprite_id = ustrtol(argument, NULL, 10); | ||||
|     GfxObj* gfxobj = gfxobj_find(sprite_id); | ||||
|     assert(gfxobj != NULL); | ||||
| 
 | ||||
|     sprite_show((Sprite *)gfxobj); | ||||
|     context->show_sprite((Sprite*)gfxobj); | ||||
|   } | ||||
|   else { | ||||
|     sprite_show(NULL); | ||||
|     context->show_sprite(NULL); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -36,13 +36,14 @@ void dialogs_frame_length(int sprite_frpos); | |||
| 
 | ||||
| static bool cmd_sprite_properties_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_sprite_properties_execute(const char *argument) | ||||
| { | ||||
|   JWidget window, killer, name, type, size, frames, speed, ok; | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   jstring imgtype_text; | ||||
|   char buf[256]; | ||||
| 
 | ||||
|  |  | |||
|  | @ -46,6 +46,7 @@ class SpriteSizeJob : public Job | |||
| public: | ||||
| 
 | ||||
|   SpriteSizeJob(Sprite* sprite, int new_width, int new_height, ResizeMethod resize_method) | ||||
|     : Job("Sprite Size") | ||||
|   { | ||||
|     m_sprite = sprite; | ||||
|     m_new_width = new_width; | ||||
|  | @ -122,13 +123,16 @@ static bool height_perc_change_hook(JWidget widget, void *data); | |||
| 
 | ||||
| static bool cmd_sprite_size_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_sprite_size_execute(const char *argument) | ||||
| { | ||||
|   JWidget window, width_px, height_px, width_perc, height_perc, lock_ratio, method, ok; | ||||
|   Sprite* sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   if (!sprite) | ||||
|     return; | ||||
| 
 | ||||
|   // load the window widget
 | ||||
|   window = load_widget("sprsize.jid", "sprite_size"); | ||||
|  | @ -190,6 +194,8 @@ static void cmd_sprite_size_execute(const char *argument) | |||
| 
 | ||||
| static bool lock_ratio_change_hook(JWidget widget, void *data) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   if (widget->selected()) | ||||
|     width_px_change_hook(widget->find_sibling("width_px"), NULL); | ||||
| 
 | ||||
|  | @ -198,14 +204,15 @@ static bool lock_ratio_change_hook(JWidget widget, void *data) | |||
| 
 | ||||
| static bool width_px_change_hook(JWidget widget, void *data) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   int width = widget->text_int(); | ||||
|   double perc = 100.0 * width / current_sprite->w; | ||||
|   double perc = 100.0 * width / sprite->w; | ||||
| 
 | ||||
|   widget->find_sibling("width_perc")->textf(PERC_FORMAT, perc); | ||||
| 
 | ||||
|   if (widget->find_sibling("lock_ratio")->selected()) { | ||||
|     widget->find_sibling("height_perc")->textf(PERC_FORMAT, perc); | ||||
|     widget->find_sibling("height_px")->textf("%d", current_sprite->h * width / current_sprite->w); | ||||
|     widget->find_sibling("height_px")->textf("%d", sprite->h * width / sprite->w); | ||||
|   } | ||||
| 
 | ||||
|   return true; | ||||
|  | @ -213,14 +220,15 @@ static bool width_px_change_hook(JWidget widget, void *data) | |||
| 
 | ||||
| static bool height_px_change_hook(JWidget widget, void *data) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   int height = widget->text_int(); | ||||
|   double perc = 100.0 * height / current_sprite->h; | ||||
|   double perc = 100.0 * height / sprite->h; | ||||
| 
 | ||||
|   widget->find_sibling("height_perc")->textf(PERC_FORMAT, perc); | ||||
| 
 | ||||
|   if (widget->find_sibling("lock_ratio")->selected()) { | ||||
|     widget->find_sibling("width_perc")->textf(PERC_FORMAT, perc); | ||||
|     widget->find_sibling("width_px")->textf("%d", current_sprite->w * height / current_sprite->h); | ||||
|     widget->find_sibling("width_px")->textf("%d", sprite->w * height / sprite->h); | ||||
|   } | ||||
| 
 | ||||
|   return true; | ||||
|  | @ -228,12 +236,13 @@ static bool height_px_change_hook(JWidget widget, void *data) | |||
| 
 | ||||
| static bool width_perc_change_hook(JWidget widget, void *data) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   double width = widget->text_double(); | ||||
| 
 | ||||
|   widget->find_sibling("width_px")->textf("%d", (int)(current_sprite->w * width / 100)); | ||||
|   widget->find_sibling("width_px")->textf("%d", (int)(sprite->w * width / 100)); | ||||
| 
 | ||||
|   if (widget->find_sibling("lock_ratio")->selected()) { | ||||
|     widget->find_sibling("height_px")->textf("%d", (int)(current_sprite->h * width / 100)); | ||||
|     widget->find_sibling("height_px")->textf("%d", (int)(sprite->h * width / 100)); | ||||
|     widget->find_sibling("height_perc")->text(widget->text()); | ||||
|   } | ||||
| 
 | ||||
|  | @ -242,12 +251,13 @@ static bool width_perc_change_hook(JWidget widget, void *data) | |||
| 
 | ||||
| static bool height_perc_change_hook(JWidget widget, void *data) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   double height = widget->text_double(); | ||||
| 
 | ||||
|   widget->find_sibling("height_px")->textf("%d", (int)(current_sprite->h * height / 100)); | ||||
|   widget->find_sibling("height_px")->textf("%d", (int)(sprite->h * height / 100)); | ||||
| 
 | ||||
|   if (widget->find_sibling("lock_ratio")->selected()) { | ||||
|     widget->find_sibling("width_px")->textf("%d", (int)(current_sprite->w * height / 100)); | ||||
|     widget->find_sibling("width_px")->textf("%d", (int)(sprite->w * height / 100)); | ||||
|     widget->find_sibling("width_perc")->text(widget->text()); | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -28,18 +28,21 @@ | |||
| 
 | ||||
| static bool cmd_undo_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL && undo_can_undo(current_sprite->undo); | ||||
|   CurrentSprite sprite; | ||||
|   return sprite != NULL && undo_can_undo(sprite->undo); | ||||
| } | ||||
| 
 | ||||
| static void cmd_undo_execute(const char *argument) | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   statusbar_show_tip(app_get_statusbar(), 1000, | ||||
| 		     _("Undid %s"), | ||||
| 		     undo_get_next_undo_label(current_sprite->undo)); | ||||
| 		     undo_get_next_undo_label(sprite->undo)); | ||||
| 
 | ||||
|   undo_do_undo(current_sprite->undo); | ||||
|   sprite_generate_mask_boundaries(current_sprite); | ||||
|   update_screen_for_sprite(current_sprite); | ||||
|   undo_do_undo(sprite->undo); | ||||
|   sprite_generate_mask_boundaries(sprite); | ||||
|   update_screen_for_sprite(sprite); | ||||
| } | ||||
| 
 | ||||
| Command cmd_undo = { | ||||
|  |  | |||
|  | @ -48,7 +48,8 @@ static void make_preview(); | |||
| 
 | ||||
| static bool cmd_color_curve_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite != NULL; | ||||
| } | ||||
| 
 | ||||
| static void cmd_color_curve_execute(const char *argument) | ||||
|  | @ -56,7 +57,7 @@ static void cmd_color_curve_execute(const char *argument) | |||
|   JWidget window, button_ok; | ||||
|   JWidget view_curve, curve_editor; | ||||
|   JWidget box_target, target_button; | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Image *image; | ||||
|   Effect *effect; | ||||
| 
 | ||||
|  | @ -71,7 +72,7 @@ static void cmd_color_curve_execute(const char *argument) | |||
| 		 the_curve); | ||||
|   } | ||||
| 
 | ||||
|   image = GetImage(current_sprite); | ||||
|   image = GetImage(sprite); | ||||
|   if (!image) | ||||
|     return; | ||||
| 
 | ||||
|  |  | |||
|  | @ -70,7 +70,8 @@ static void make_preview(); | |||
| 
 | ||||
| static bool cmd_convolution_matrix_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite != NULL; | ||||
| } | ||||
| 
 | ||||
| static void cmd_convolution_matrix_execute(const char *argument) | ||||
|  | @ -79,11 +80,11 @@ static void cmd_convolution_matrix_execute(const char *argument) | |||
|   JWidget view_convmatr, list_convmatr; | ||||
|   JWidget box_target; | ||||
|   JWidget reload, generate; | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Image *image; | ||||
|   Effect *effect; | ||||
| 
 | ||||
|   image = GetImage(current_sprite); | ||||
|   image = GetImage(sprite); | ||||
|   if (!image) | ||||
|     return; | ||||
| 
 | ||||
|  |  | |||
|  | @ -57,17 +57,19 @@ static void make_preview(); | |||
| 
 | ||||
| static bool cmd_despeckle_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_despeckle_execute(const char *argument) | ||||
| { | ||||
|   JWidget window, box_target, target_button, button_ok; | ||||
|   CurrentSprite sprite; | ||||
|   Image *image; | ||||
|   Effect *effect; | ||||
|   char buf[32]; | ||||
| 
 | ||||
|   image = GetImage(current_sprite); | ||||
|   image = GetImage(sprite); | ||||
|   if (!image) | ||||
|     return; | ||||
| 
 | ||||
|  | @ -86,7 +88,7 @@ static void cmd_despeckle_execute(const char *argument) | |||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   effect = effect_new(current_sprite, "median"); | ||||
|   effect = effect_new(sprite, "median"); | ||||
|   if (!effect) { | ||||
|     console_printf(_("Error creating the effect applicator for this sprite\n")); | ||||
|     jwidget_free(window); | ||||
|  | @ -98,7 +100,7 @@ static void cmd_despeckle_execute(const char *argument) | |||
| 
 | ||||
|   preview = preview_new(effect); | ||||
| 
 | ||||
|   target_button = target_button_new(current_sprite->imgtype, TRUE); | ||||
|   target_button = target_button_new(sprite->imgtype, TRUE); | ||||
|   target_button_set_target(target_button, effect->target); | ||||
| 
 | ||||
|   sprintf(buf, "%d", get_config_int("Median", "Width", 3)); | ||||
|  | @ -141,7 +143,7 @@ static void cmd_despeckle_execute(const char *argument) | |||
|   effect_free(effect); | ||||
| 
 | ||||
|   /* update editors */ | ||||
|   update_screen_for_sprite(current_sprite); | ||||
|   update_screen_for_sprite(sprite); | ||||
| 
 | ||||
|   /* save window configuration */ | ||||
|   save_window_pos(window, "Median"); | ||||
|  |  | |||
|  | @ -51,17 +51,18 @@ static void make_preview(); | |||
| 
 | ||||
| static bool cmd_invert_color_enabled(const char *argument) | ||||
| { | ||||
|   return current_sprite != NULL; | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_invert_color_execute(const char *argument) | ||||
| { | ||||
|   JWidget window, box_target, target_button, button_ok; | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Image *image; | ||||
|   Effect *effect; | ||||
| 
 | ||||
|   image = GetImage(current_sprite); | ||||
|   image = GetImage(sprite); | ||||
|   if (!image) | ||||
|     return; | ||||
| 
 | ||||
|  |  | |||
|  | @ -54,7 +54,8 @@ static void make_preview(); | |||
| 
 | ||||
| static bool cmd_replace_color_enabled(const char *argument) | ||||
| { | ||||
|   return is_current_sprite_not_locked(); | ||||
|   CurrentSprite sprite; | ||||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| static void cmd_replace_color_execute(const char *argument) | ||||
|  | @ -65,13 +66,12 @@ static void cmd_replace_color_execute(const char *argument) | |||
|   JWidget button_ok; | ||||
|   Image *image; | ||||
|   Effect *effect; | ||||
|   Sprite *sprite; | ||||
| 
 | ||||
|   sprite = lock_current_sprite(); | ||||
|   CurrentSprite sprite; | ||||
|   if (!sprite) | ||||
|     return; | ||||
| 
 | ||||
|   image = GetImage(current_sprite); | ||||
|   image = GetImage(sprite); | ||||
|   if (!image) | ||||
|     goto done; | ||||
| 
 | ||||
|  | @ -103,14 +103,14 @@ static void cmd_replace_color_execute(const char *argument) | |||
|   button_color1 = colorbutton_new | ||||
|     (get_config_color("ReplaceColor", "Color1", | ||||
| 		      colorbar_get_fg_color(app_get_colorbar())), | ||||
|      current_sprite->imgtype); | ||||
|      sprite->imgtype); | ||||
| 
 | ||||
|   button_color2 = colorbutton_new | ||||
|     (get_config_color("ReplaceColor", "Color2", | ||||
| 		      colorbar_get_bg_color(app_get_colorbar())), | ||||
|      current_sprite->imgtype); | ||||
|      sprite->imgtype); | ||||
| 
 | ||||
|   target_button = target_button_new(current_sprite->imgtype, FALSE); | ||||
|   target_button = target_button_new(sprite->imgtype, FALSE); | ||||
|   target_button_set_target(target_button, effect->target); | ||||
| 
 | ||||
|   jslider_set_value(slider_fuzziness, | ||||
|  | @ -149,7 +149,7 @@ static void cmd_replace_color_execute(const char *argument) | |||
|   effect_free(effect); | ||||
| 
 | ||||
|   /* update editors */ | ||||
|   update_screen_for_sprite(current_sprite); | ||||
|   update_screen_for_sprite(sprite); | ||||
| 
 | ||||
|   /* save window configuration */ | ||||
|   save_window_pos(window, "ReplaceColor"); | ||||
|  | @ -157,8 +157,6 @@ static void cmd_replace_color_execute(const char *argument) | |||
| done:; | ||||
|   if (window) | ||||
|     jwidget_free(window); | ||||
| 
 | ||||
|   sprite_unlock(sprite); | ||||
| } | ||||
| 
 | ||||
| static bool color_change_hook(JWidget widget, void *data) | ||||
|  | @ -196,6 +194,7 @@ static bool preview_change_hook(JWidget widget, void *data) | |||
| 
 | ||||
| static void make_preview() | ||||
| { | ||||
|   CurrentSprite sprite; | ||||
|   color_t from, to; | ||||
|   int fuzziness; | ||||
| 
 | ||||
|  | @ -203,8 +202,8 @@ static void make_preview() | |||
|   to = get_config_color("ReplaceColor", "Color2", color_mask()); | ||||
|   fuzziness = get_config_int("ReplaceColor", "Fuzziness", 0); | ||||
| 
 | ||||
|   set_replace_colors(get_color_for_layer(current_sprite->layer, from), | ||||
| 		     get_color_for_layer(current_sprite->layer, to), | ||||
|   set_replace_colors(get_color_for_layer(sprite->layer, from), | ||||
| 		     get_color_for_layer(sprite->layer, to), | ||||
| 		     MID(0, fuzziness, 255)); | ||||
| 
 | ||||
|   if (jwidget_is_selected(check_preview)) | ||||
|  |  | |||
|  | @ -30,6 +30,7 @@ | |||
| #include "jinete/jinete.h" | ||||
| #include "jinete/jintern.h" | ||||
| 
 | ||||
| #include "ase/ui_context.h" | ||||
| #include "commands/commands.h" | ||||
| #include "console/console.h" | ||||
| #include "core/app.h" | ||||
|  | @ -291,10 +292,8 @@ void app_loop() | |||
|     switch (option->type) { | ||||
| 
 | ||||
|       case OPEN_GFX_FILE: { | ||||
| 	Sprite *sprite; | ||||
| 
 | ||||
| 	/* load the sprite */ | ||||
| 	sprite = sprite_load(option->data); | ||||
| 	Sprite *sprite = sprite_load(option->data); | ||||
| 	if (!sprite) { | ||||
| 	  /* error */ | ||||
| 	  if (ase_mode & MODE_GUI) | ||||
|  | @ -304,12 +303,13 @@ void app_loop() | |||
| 	} | ||||
| 	else { | ||||
| 	  /* mount and select the sprite */ | ||||
| 	  sprite_mount(sprite); | ||||
| 	  set_current_sprite(sprite); | ||||
| 	  UIContext* context = UIContext::instance(); | ||||
| 	  context->add_sprite(sprite); | ||||
| 	  context->set_current_sprite(sprite); | ||||
| 
 | ||||
| 	  if (ase_mode & MODE_GUI) { | ||||
| 	    /* show it */ | ||||
| 	    set_sprite_in_more_reliable_editor(get_first_sprite()); | ||||
| 	    set_sprite_in_more_reliable_editor(context->get_first_sprite()); | ||||
| 
 | ||||
| 	    /* recent file */ | ||||
| 	    recent_file(option->data); | ||||
|  | @ -333,8 +333,11 @@ void app_loop() | |||
|     dialogs_select_language(FALSE); | ||||
| 
 | ||||
|     /* show tips? */ | ||||
|     if (!current_sprite) | ||||
|     { | ||||
|       CurrentSprite sprite; | ||||
|       if (!sprite) | ||||
| 	dialogs_tips(FALSE); | ||||
|     } | ||||
| 
 | ||||
|     // support to drop files from Windows explorer
 | ||||
|     install_drop_files(); | ||||
|  | @ -383,6 +386,7 @@ void app_exit() | |||
| 
 | ||||
|   /* finalize modules, configuration and core */ | ||||
|   modules_exit(); | ||||
|   UIContext::destroy_instance(); | ||||
|   editor_cursor_exit(); | ||||
|   boundary_exit(); | ||||
| 
 | ||||
|  | @ -426,10 +430,11 @@ void app_trigger_event(int app_event) | |||
| void app_refresh_screen() | ||||
| { | ||||
|   if (ase_mode & MODE_GUI) { | ||||
|     CurrentSprite sprite; | ||||
| 
 | ||||
|     /* update the color palette */ | ||||
|     set_current_palette(current_sprite != NULL ? | ||||
| 			sprite_get_palette(current_sprite, | ||||
| 					   current_sprite->frame): NULL, | ||||
|     set_current_palette(sprite != NULL ? | ||||
| 			sprite_get_palette(sprite, sprite->frame): NULL, | ||||
| 			FALSE); | ||||
| 
 | ||||
|     /* redraw the screen */ | ||||
|  | @ -442,15 +447,14 @@ void app_refresh_screen() | |||
|  */ | ||||
| void app_realloc_sprite_list() | ||||
| { | ||||
|   Sprite* sprite; | ||||
|   JLink link; | ||||
|   UIContext* context = UIContext::instance(); | ||||
|   const SpriteList& list = context->get_sprite_list(); | ||||
| 
 | ||||
|   /* insert all other sprites */ | ||||
|   JI_LIST_FOR_EACH(get_sprite_list(), link) { | ||||
|     sprite = reinterpret_cast<Sprite*>(link->data); | ||||
|     tabs_set_text_for_tab(tabsbar, | ||||
| 			  get_filename(sprite->filename), | ||||
| 			  sprite); | ||||
|   for (SpriteList::const_iterator | ||||
| 	 it = list.begin(); it != list.end(); ++it) { | ||||
|     Sprite* sprite = *it; | ||||
|     tabs_set_text_for_tab(tabsbar, get_filename(sprite->filename), sprite); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  | @ -510,8 +514,9 @@ bool app_realloc_recent_list() | |||
| 
 | ||||
| int app_get_current_image_type() | ||||
| { | ||||
|   if (current_sprite) | ||||
|     return current_sprite->imgtype; | ||||
|   CurrentSprite sprite; | ||||
|   if (sprite) | ||||
|     return sprite->imgtype; | ||||
|   else if (screen != NULL && bitmap_color_depth(screen) == 8) | ||||
|     return IMAGE_INDEXED; | ||||
|   else | ||||
|  | @ -568,9 +573,11 @@ int app_get_color_to_clear_layer(Layer *layer) | |||
| static void tabsbar_select_callback(JWidget tabs, void *data, int button) | ||||
| { | ||||
|   // Note: data can be NULL (the "Nothing" tab)
 | ||||
|   Sprite* sprite = (Sprite*)data; | ||||
| 
 | ||||
|   // put as current sprite
 | ||||
|   sprite_show((Sprite *)data); | ||||
|   UIContext* context = UIContext::instance(); | ||||
|   context->show_sprite(sprite); | ||||
| 
 | ||||
|   // middle button: close the sprite
 | ||||
|   if (data && (button & 4)) | ||||
|  |  | |||
|  | @ -29,7 +29,7 @@ | |||
| #include "modules/gui.h" | ||||
| #include "widgets/statebar.h" | ||||
| 
 | ||||
| Job::Job() | ||||
| Job::Job(const char* job_name) | ||||
| { | ||||
|   m_mutex = NULL; | ||||
|   m_thread = NULL; | ||||
|  | @ -45,7 +45,7 @@ Job::Job() | |||
|   m_monitor = add_gui_monitor(&Job::monitor_proc, | ||||
| 			      &Job::monitor_free, | ||||
| 			      (void*)this); | ||||
|   m_alert_window = jalert_new(PACKAGE "<<Working...||&Cancel"); | ||||
|   m_alert_window = jalert_new("%s<<Working...||&Cancel", job_name); | ||||
| } | ||||
| 
 | ||||
| Job::~Job() | ||||
|  |  | |||
|  | @ -35,9 +35,14 @@ class Job | |||
|   bool m_done_flag; | ||||
|   bool m_canceled_flag; | ||||
| 
 | ||||
|   // these methods are privated and not defined
 | ||||
|   Job(); | ||||
|   Job(const Job&); | ||||
|   Job& operator==(const Job&); | ||||
|    | ||||
| public: | ||||
| 
 | ||||
|   Job(); | ||||
|   Job(const char* job_name); | ||||
|   virtual ~Job(); | ||||
| 
 | ||||
|   void do_job(); | ||||
|  |  | |||
|  | @ -27,7 +27,6 @@ | |||
| #include "modules/palettes.h" | ||||
| #include "modules/recent.h" | ||||
| #include "modules/rootmenu.h" | ||||
| #include "modules/sprites.h" | ||||
| #include "modules/tools.h" | ||||
| 
 | ||||
| #define DEF_MODULE(name, reqs) \ | ||||
|  | @ -48,7 +47,6 @@ static Module module[] = | |||
|      first ones.  */ | ||||
| 
 | ||||
|   DEF_MODULE(palette,		REQUIRE_INTERFACE), | ||||
|   DEF_MODULE(sprites,		REQUIRE_INTERFACE), | ||||
|   DEF_MODULE(effect,		REQUIRE_INTERFACE), | ||||
|   DEF_MODULE(tools,		REQUIRE_INTERFACE), | ||||
|   DEF_MODULE(graphics,		REQUIRE_INTERFACE), | ||||
|  |  | |||
|  | @ -163,7 +163,7 @@ bool animation_editor_is_movingcel() | |||
|  */ | ||||
| void switch_between_animation_and_sprite_editor() | ||||
| { | ||||
|   Sprite* sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   JWidget window; | ||||
|   JWidget anieditor; | ||||
|   int layer; | ||||
|  |  | |||
|  | @ -47,7 +47,7 @@ void canvas_resize() | |||
|   JWidget check_w, check_h; | ||||
|   JWidget button_offset; | ||||
|   JWidget button_ok, button_cancel; | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   if (!is_interactive () || !sprite) | ||||
|     return; | ||||
|  |  | |||
|  | @ -53,12 +53,13 @@ void dialogs_draw_text() | |||
|   Image *image, *dest_image; | ||||
|   JWidget window, button_ok, color_box, color_but; | ||||
|   JWidget entry_size, entry_text; | ||||
|   CurrentSprite sprite; | ||||
|   char buf[256]; | ||||
| 
 | ||||
|   if (!is_interactive() || !current_sprite) | ||||
|   if (!is_interactive() || !sprite) | ||||
|     return; | ||||
| 
 | ||||
|   dest_image = GetImage(current_sprite); | ||||
|   dest_image = GetImage(sprite); | ||||
|   if (!dest_image) | ||||
|     return; | ||||
| 
 | ||||
|  | @ -84,7 +85,7 @@ void dialogs_draw_text() | |||
|   color_but = colorbutton_new | ||||
|     (get_config_color("DrawText", "Color", | ||||
| 		      colorbar_get_fg_color(app_get_colorbar())), | ||||
|      current_sprite->imgtype); | ||||
|      sprite->imgtype); | ||||
| 
 | ||||
|   jwidget_add_child(color_box, color_but); | ||||
| 
 | ||||
|  | @ -126,7 +127,7 @@ void dialogs_draw_text() | |||
|       ji_font_set_size(f, size); | ||||
| 
 | ||||
|       /* setup color */ | ||||
|       color = get_color_for_image(current_sprite->imgtype, | ||||
|       color = get_color_for_image(sprite->imgtype, | ||||
| 				  color_with_type); | ||||
| 
 | ||||
|       /* update configuration */ | ||||
|  | @ -137,9 +138,8 @@ void dialogs_draw_text() | |||
|       /* render text */ | ||||
|       image = render_text(f, text, color); | ||||
|       if (image) { | ||||
| 	clipboard::copy_image(image, sprite_get_palette(current_sprite, | ||||
| 							current_sprite->frame)); | ||||
| 	clipboard::paste(current_sprite); | ||||
| 	clipboard::copy_image(image, sprite_get_palette(sprite, sprite->frame)); | ||||
| 	clipboard::paste(sprite); | ||||
|       } | ||||
|       else | ||||
| 	console_printf(_("Error rendering text.\n")); | ||||
|  | @ -186,6 +186,7 @@ static Image *render_text(FONT *f, const char *text, int color) | |||
|     }							\ | ||||
|   } | ||||
| 
 | ||||
|   CurrentSprite sprite; | ||||
|   int i, pixels, w, h; | ||||
|   Image *image; | ||||
|   BITMAP *bmp; | ||||
|  | @ -206,7 +207,7 @@ static Image *render_text(FONT *f, const char *text, int color) | |||
|   clear_to_color(bmp, makecol32 (255, 0, 255)); | ||||
|   textout(bmp, f, text, 0, 0, makecol32 (255, 255, 255)); | ||||
| 
 | ||||
|   image = image_new(current_sprite->imgtype, w, h); | ||||
|   image = image_new(sprite->imgtype, w, h); | ||||
|   if (!image) { | ||||
|     destroy_bitmap(bmp); | ||||
|     return NULL; | ||||
|  |  | |||
|  | @ -58,13 +58,13 @@ void dialogs_mask_color() | |||
|   JWidget label_color, button_1, button_2; | ||||
|   JWidget label_fuzziness; | ||||
|   JWidget button_ok, button_cancel; | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Image *image; | ||||
| 
 | ||||
|   if (!is_interactive () || !sprite) | ||||
|     return; | ||||
| 
 | ||||
|   image = GetImage(current_sprite); | ||||
|   image = GetImage(sprite); | ||||
|   if (!image) | ||||
|     return; | ||||
| 
 | ||||
|  | @ -190,18 +190,15 @@ static bool preview_change_hook(JWidget widget, void *data) | |||
| static Mask *gen_mask() | ||||
| { | ||||
|   int xpos, ypos, color, fuzziness; | ||||
|   Sprite *sprite; | ||||
|   Image *image; | ||||
|   Mask *mask; | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   sprite = current_sprite; | ||||
|   image = GetImage2(sprite, &xpos, &ypos, NULL); | ||||
|   Image* image = GetImage2(sprite, &xpos, &ypos, NULL); | ||||
| 
 | ||||
|   color = get_color_for_image(sprite->imgtype, | ||||
| 			      colorbutton_get_color(button_color)); | ||||
|   fuzziness = jslider_get_value(slider_fuzziness); | ||||
| 
 | ||||
|   mask = mask_new(); | ||||
|   Mask* mask = mask_new(); | ||||
|   mask_by_color(mask, image, color, fuzziness); | ||||
|   mask_move(mask, xpos, ypos); | ||||
| 
 | ||||
|  | @ -211,7 +208,7 @@ static Mask *gen_mask() | |||
| static void mask_preview() | ||||
| { | ||||
|   if (jwidget_is_selected (check_preview)) { | ||||
|     Sprite *sprite = current_sprite; | ||||
|     CurrentSprite sprite; | ||||
|     Mask *mask = gen_mask(); | ||||
|     Mask *old_mask = sprite->mask; | ||||
| 
 | ||||
|  |  | |||
|  | @ -127,7 +127,7 @@ void dialogs_vector_map() | |||
| { | ||||
| #define PROJECT()	project(image, x, y, dmax, &u, &v) | ||||
| 
 | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Image *image, *image_copy; | ||||
|   double u, v, dmax; | ||||
|   int c, x, y; | ||||
|  | @ -135,7 +135,7 @@ void dialogs_vector_map() | |||
|   if (!is_interactive () || !sprite) | ||||
|     return; | ||||
| 
 | ||||
|   image = GetImage(current_sprite); | ||||
|   image = GetImage(sprite); | ||||
|   if (!image) | ||||
|     return; | ||||
| 
 | ||||
|  |  | |||
|  | @ -506,7 +506,7 @@ void fop_operate(FileOp *fop) | |||
| 	    if (fop->seq.image) image_free(fop->seq.image); | ||||
| 	    if (fop->seq.last_cel) cel_free(fop->seq.last_cel); | ||||
| 	    if (fop->sprite) { | ||||
| 	      sprite_free(fop->sprite); | ||||
| 	      delete fop->sprite; | ||||
| 	      fop->sprite = NULL; | ||||
| 	    } | ||||
| 	    break; | ||||
|  | @ -744,7 +744,7 @@ Image *fop_sequence_image(FileOp *fop, int imgtype, int w, int h) | |||
| 
 | ||||
|     layer = layer_new(sprite); | ||||
|     if (!layer) { | ||||
|       sprite_free(sprite); | ||||
|       delete sprite; | ||||
|       return NULL; | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -254,7 +254,7 @@ error:; | |||
|   if (current_image_old) image_free(current_image_old); | ||||
|   if (npal) palette_free(npal); | ||||
|   if (opal) palette_free(opal); | ||||
|   if (sprite) sprite_free(sprite); | ||||
|   delete sprite; | ||||
|   return ret; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -20,6 +20,7 @@ | |||
| 
 | ||||
| #include "jinete/jinete.h" | ||||
| 
 | ||||
| #include "ase/ui_context.h" | ||||
| #include "core/app.h" | ||||
| #include "modules/editors.h" | ||||
| #include "modules/gui.h" | ||||
|  | @ -174,6 +175,7 @@ void editors_draw_sprite_tiled(Sprite *sprite, int x1, int y1, int x2, int y2) | |||
| 
 | ||||
| void editors_hide_sprite(Sprite *sprite) | ||||
| { | ||||
|   CurrentSprite current_sprite; | ||||
|   JWidget widget; | ||||
|   int refresh; | ||||
|   JLink link; | ||||
|  | @ -188,7 +190,9 @@ void editors_hide_sprite(Sprite *sprite) | |||
|   } | ||||
| 
 | ||||
|   if (refresh) { | ||||
|     set_current_sprite(editor_get_sprite(current_editor)); | ||||
|     UIContext* context = UIContext::instance(); | ||||
|     context->set_current_sprite(editor_get_sprite(current_editor)); | ||||
| 
 | ||||
|     app_refresh_screen(); | ||||
|   } | ||||
| } | ||||
|  | @ -218,7 +222,9 @@ void set_current_editor(JWidget editor) | |||
| 
 | ||||
|     jwidget_dirty(jwidget_get_view(current_editor)); | ||||
| 
 | ||||
|     set_current_sprite(editor_get_sprite(current_editor)); | ||||
|     UIContext* context = UIContext::instance(); | ||||
|     context->set_current_sprite(editor_get_sprite(current_editor)); | ||||
| 
 | ||||
|     app_refresh_screen(); | ||||
|     app_realloc_sprite_list(); | ||||
|   } | ||||
|  | @ -227,8 +233,11 @@ void set_current_editor(JWidget editor) | |||
| void set_sprite_in_current_editor(Sprite *sprite) | ||||
| { | ||||
|   if (current_editor) { | ||||
|     set_current_sprite(sprite); | ||||
|     send_sprite_to_top(sprite); | ||||
|     UIContext* context = UIContext::instance(); | ||||
|      | ||||
|     context->set_current_sprite(sprite); | ||||
|     if (sprite != NULL) | ||||
|       context->send_sprite_to_top(sprite); | ||||
| 
 | ||||
|     editor_set_sprite(current_editor, sprite); | ||||
| 
 | ||||
|  | @ -420,12 +429,12 @@ static int is_sprite_in_some_editor(Sprite *sprite) | |||
|  */ | ||||
| static Sprite *get_more_reliable_sprite() | ||||
| { | ||||
|   Sprite *sprite; | ||||
|   JLink link; | ||||
| 
 | ||||
|   JI_LIST_FOR_EACH(get_sprite_list(), link) { | ||||
|     sprite = reinterpret_cast<Sprite*>(link->data); | ||||
|   UIContext* context = UIContext::instance(); | ||||
|   const SpriteList& list = context->get_sprite_list(); | ||||
| 
 | ||||
|   for (SpriteList::const_iterator | ||||
| 	 it = list.begin(); it != list.end(); ++it) { | ||||
|     Sprite* sprite = *it; | ||||
|     if (!(is_sprite_in_some_editor(sprite))) | ||||
|       return sprite; | ||||
|   } | ||||
|  |  | |||
|  | @ -29,6 +29,7 @@ | |||
| #include "jinete/jinete.h" | ||||
| #include "jinete/jintern.h" | ||||
| 
 | ||||
| #include "ase/ui_context.h" | ||||
| #include "commands/commands.h" | ||||
| #include "console/console.h" | ||||
| #include "core/app.h" | ||||
|  | @ -411,7 +412,7 @@ void gui_feedback() | |||
| 
 | ||||
|   if (next_idle_flags & REFRESH_FULL_SCREEN) { | ||||
|     next_idle_flags ^= REFRESH_FULL_SCREEN; | ||||
|     update_screen_for_sprite(current_sprite); | ||||
|     update_screen_for_sprite(UIContext::instance()->get_current_sprite()); | ||||
|   } | ||||
| 
 | ||||
|   /* record file if is necessary */ | ||||
|  |  | |||
|  | @ -18,17 +18,12 @@ | |||
| 
 | ||||
| #include "config.h" | ||||
| 
 | ||||
| #include <assert.h> | ||||
| #include <allegro/file.h> | ||||
| #include <cassert> | ||||
| 
 | ||||
| #include "jinete/jlist.h" | ||||
| 
 | ||||
| #include "core/app.h" | ||||
| #include "core/core.h" | ||||
| #include "file/file.h" | ||||
| #include "ase/ui_context.h" | ||||
| #include "effect/effect.h" | ||||
| #include "modules/editors.h" | ||||
| #include "modules/gui.h" | ||||
| #include "modules/sprites.h" | ||||
| #include "raster/cel.h" | ||||
| #include "raster/image.h" | ||||
|  | @ -37,151 +32,43 @@ | |||
| #include "raster/sprite.h" | ||||
| #include "raster/stock.h" | ||||
| #include "util/misc.h" | ||||
| #include "widgets/editor.h" | ||||
| #include "widgets/tabs.h" | ||||
| 
 | ||||
| /* Current selected sprite to operate, it could be not the same of
 | ||||
|    editor_get_sprite(current_editor).  */ | ||||
| 
 | ||||
| Sprite* current_sprite = NULL; | ||||
| 
 | ||||
| static JList sprites_list; | ||||
| 
 | ||||
| static ImageRef *images_ref_get_from_layer(Sprite* sprite, Layer *layer, int target, bool write); | ||||
| static void layer_get_pos(Sprite* sprite, Layer *layer, int target, bool write, int **x, int **y, int *count); | ||||
| 
 | ||||
| int init_module_sprites() | ||||
| //////////////////////////////////////////////////////////////////////
 | ||||
| 
 | ||||
| CurrentSprite::CurrentSprite() | ||||
| { | ||||
|   sprites_list = jlist_new(); | ||||
|   current_sprite = NULL; | ||||
|   return 0; | ||||
|   UIContext* context = UIContext::instance(); | ||||
| 
 | ||||
|   m_sprite = context->get_current_sprite(); | ||||
|   if (m_sprite) | ||||
|     m_writeable = m_sprite->lock(); | ||||
| } | ||||
| 
 | ||||
| void exit_module_sprites() | ||||
| CurrentSprite::~CurrentSprite() | ||||
| { | ||||
|   JLink link; | ||||
| 
 | ||||
|   JI_LIST_FOR_EACH(sprites_list, link) { | ||||
|     sprite_free(reinterpret_cast<Sprite*>(link->data)); | ||||
|   } | ||||
|   jlist_free(sprites_list); | ||||
|   sprites_list = NULL; | ||||
| 
 | ||||
|   current_sprite = NULL; | ||||
|   if (m_sprite) | ||||
|     m_sprite->unlock(); | ||||
| } | ||||
| 
 | ||||
| JList get_sprite_list() | ||||
| void CurrentSprite::destroy() | ||||
| { | ||||
|   return sprites_list; | ||||
| } | ||||
|   if (m_sprite) { | ||||
|     UIContext* context = UIContext::instance(); | ||||
| 
 | ||||
| Sprite* get_first_sprite() | ||||
| { | ||||
|   return reinterpret_cast<Sprite*>(jlist_first_data(sprites_list)); | ||||
| } | ||||
|     context->remove_sprite(m_sprite); | ||||
| 
 | ||||
| Sprite* get_next_sprite(Sprite* sprite) | ||||
| { | ||||
|   JLink link = jlist_find(sprites_list, sprite); | ||||
|     m_sprite->unlock(); | ||||
| 
 | ||||
|   if (sprites_list->end != link && | ||||
|       sprites_list->end != link->next) | ||||
|     return reinterpret_cast<Sprite*>(link->next->data); | ||||
|   else | ||||
|     return NULL; | ||||
| } | ||||
| 
 | ||||
| /* adds the "sprite" in the list of sprites */ | ||||
| void sprite_mount(Sprite* sprite) | ||||
| { | ||||
|   /* append the sprite to the list */ | ||||
|   jlist_prepend(sprites_list, sprite); | ||||
| 
 | ||||
|   if (is_interactive()) { | ||||
|     /* add the tab for this sprite */ | ||||
|     tabs_append_tab(app_get_tabsbar(), | ||||
| 		    get_filename(sprite->filename), sprite); | ||||
| 
 | ||||
|     /* rebuild the menu list of sprites */ | ||||
|     app_realloc_sprite_list(); | ||||
|     delete m_sprite; | ||||
|     m_sprite = NULL; | ||||
|     m_writeable = false; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| /* removes the "sprite" from the list of sprites */ | ||||
| void sprite_unmount(Sprite* sprite) | ||||
| { | ||||
|   /* remove from the sprite's list */ | ||||
|   jlist_remove(sprites_list, sprite); | ||||
| 
 | ||||
|   if (is_interactive()) { | ||||
|     /* remove this sprite from tabs */ | ||||
|     tabs_remove_tab(app_get_tabsbar(), sprite); | ||||
| 
 | ||||
|     /* rebuild the menu list of sprites */ | ||||
|     app_realloc_sprite_list(); | ||||
| 
 | ||||
|     /* select other sprites in the editors where are this sprite */ | ||||
|     editors_hide_sprite(sprite); | ||||
|   } | ||||
|   else { | ||||
|     if (current_sprite == sprite) | ||||
|       set_current_sprite(NULL); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| /* sets current sprite (doesn't show it, only sets the
 | ||||
|    "current_sprite" pointer).  */ | ||||
| void set_current_sprite(Sprite* sprite) | ||||
| { | ||||
|   current_sprite = sprite; | ||||
| 
 | ||||
|   /* select the sprite in the tabs */ | ||||
|   tabs_select_tab(app_get_tabsbar(), sprite); | ||||
| } | ||||
| 
 | ||||
| void send_sprite_to_top(Sprite* sprite) | ||||
| { | ||||
|   if (sprite && jlist_find(sprites_list, sprite) != sprites_list->end) { | ||||
|     jlist_remove(sprites_list, sprite); | ||||
|     jlist_prepend(sprites_list, sprite); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| /* puts the sprite in some editor */ | ||||
| void sprite_show(Sprite* sprite) | ||||
| { | ||||
|   if (is_interactive()) | ||||
|     set_sprite_in_more_reliable_editor(sprite); | ||||
| } | ||||
| 
 | ||||
| bool is_current_sprite_not_locked() | ||||
| { | ||||
|   return | ||||
|     current_sprite != NULL && | ||||
|     !sprite_is_locked(current_sprite); | ||||
| } | ||||
| 
 | ||||
| bool is_current_sprite_writable() | ||||
| { | ||||
|   return | ||||
|     current_sprite != NULL | ||||
|     && !sprite_is_locked(current_sprite) | ||||
|     && current_sprite->layer != NULL | ||||
|     && layer_is_readable(current_sprite->layer) | ||||
|     && layer_is_writable(current_sprite->layer) | ||||
|     && layer_is_image(current_sprite->layer) | ||||
|     && layer_get_cel(current_sprite->layer, | ||||
| 		     current_sprite->frame) != NULL; | ||||
| } | ||||
| 
 | ||||
| Sprite* lock_current_sprite() | ||||
| { | ||||
|   if (current_sprite != NULL && | ||||
|       sprite_lock(current_sprite)) | ||||
|     return current_sprite; | ||||
|   else | ||||
|     return NULL; | ||||
| } | ||||
| //////////////////////////////////////////////////////////////////////
 | ||||
| 
 | ||||
| ImageRef *images_ref_get_from_sprite(Sprite* sprite, int target, bool write) | ||||
| { | ||||
|  |  | |||
|  | @ -19,12 +19,14 @@ | |||
| #ifndef MODULES_SPRITES_H | ||||
| #define MODULES_SPRITES_H | ||||
| 
 | ||||
| #include <cassert> | ||||
| 
 | ||||
| #include "jinete/jbase.h" | ||||
| #include "raster/sprite.h" | ||||
| 
 | ||||
| class Image; | ||||
| class Layer; | ||||
| class Cel; | ||||
| class Sprite; | ||||
| 
 | ||||
| struct ImageRef | ||||
| { | ||||
|  | @ -34,26 +36,26 @@ struct ImageRef | |||
|   ImageRef* next; | ||||
| }; | ||||
| 
 | ||||
| extern Sprite* current_sprite; | ||||
| class CurrentSprite | ||||
| { | ||||
|   Sprite* m_sprite; | ||||
|   bool m_writeable; | ||||
| 
 | ||||
| int init_module_sprites(); | ||||
| void exit_module_sprites(); | ||||
| public: | ||||
|   CurrentSprite(); | ||||
|   ~CurrentSprite(); | ||||
| 
 | ||||
| JList get_sprite_list(); | ||||
| Sprite* get_first_sprite(); | ||||
| Sprite* get_next_sprite(Sprite* sprite); | ||||
|   bool writeable() const { return m_writeable; } | ||||
|   void destroy(); | ||||
| 
 | ||||
| void sprite_mount(Sprite* sprite); | ||||
| void sprite_unmount(Sprite* sprite); | ||||
|   operator Sprite* () { return m_sprite; } | ||||
| 
 | ||||
| void set_current_sprite(Sprite* sprite); | ||||
| void send_sprite_to_top(Sprite* sprite); | ||||
| void sprite_show(Sprite* sprite); | ||||
|   Sprite* operator->() { | ||||
|     assert(m_sprite != NULL); | ||||
|     return m_sprite; | ||||
|   } | ||||
| 
 | ||||
| bool is_current_sprite_not_locked(); | ||||
| bool is_current_sprite_writable(); | ||||
| 
 | ||||
| Sprite* lock_current_sprite(); | ||||
| }; | ||||
| 
 | ||||
| ImageRef* images_ref_get_from_sprite(Sprite* sprite, int target, bool write); | ||||
| void images_ref_free(ImageRef* image_ref); | ||||
|  |  | |||
|  | @ -91,8 +91,8 @@ Sprite::Sprite(int imgtype, int w, int h) | |||
|   sprite_set_speed(this, 100); | ||||
| 
 | ||||
|   /* multiple access */ | ||||
|   this->locked = FALSE; | ||||
|   this->mutex = jmutex_new(); | ||||
|   m_locked = 0; | ||||
|   m_mutex = jmutex_new(); | ||||
| 
 | ||||
|   /* file format options */ | ||||
|   this->format_options = NULL; | ||||
|  | @ -105,7 +105,7 @@ Sprite::~Sprite() | |||
| { | ||||
|   JLink link; | ||||
| 
 | ||||
|   assert(!this->locked); | ||||
|   // assert(m_locked == 1);
 | ||||
| 
 | ||||
|   /* destroy images' stock */ | ||||
|   if (this->stock) | ||||
|  | @ -143,7 +143,7 @@ Sprite::~Sprite() | |||
|   if (this->bound.seg) jfree(this->bound.seg); | ||||
| 
 | ||||
|   /* destroy mutex */ | ||||
|   jmutex_free(this->mutex); | ||||
|   jmutex_free(this->m_mutex); | ||||
| 
 | ||||
|   /* destroy file format options */ | ||||
|   if (this->format_options) | ||||
|  | @ -178,7 +178,7 @@ Sprite* sprite_new_copy(const Sprite* src_sprite) | |||
|   undo_enable(dst_sprite->undo); | ||||
| 
 | ||||
|   if (dst_sprite->set == NULL) { | ||||
|     sprite_free(dst_sprite); | ||||
|     delete dst_sprite; | ||||
|     return NULL; | ||||
|   } | ||||
| 
 | ||||
|  | @ -211,7 +211,7 @@ Sprite* sprite_new_flatten_copy(const Sprite* src_sprite) | |||
| 				      0, 0, src_sprite->w, src_sprite->h, | ||||
| 				      0, src_sprite->frames-1); | ||||
|   if (flat_layer == NULL) { | ||||
|     sprite_free(dst_sprite); | ||||
|     delete dst_sprite; | ||||
|     return NULL; | ||||
|   } | ||||
| 
 | ||||
|  | @ -237,7 +237,7 @@ Sprite* sprite_new_with_layer(int imgtype, int w, int h) | |||
|   /* new image */ | ||||
|   image = image_new(imgtype, w, h); | ||||
|   if (!image) { | ||||
|     sprite_free(sprite); | ||||
|     delete sprite; | ||||
|     return NULL; | ||||
|   } | ||||
| 
 | ||||
|  | @ -245,7 +245,7 @@ Sprite* sprite_new_with_layer(int imgtype, int w, int h) | |||
|   layer = layer_new(sprite); | ||||
|   if (!layer) { | ||||
|     image_free(image); | ||||
|     sprite_free(sprite); | ||||
|     delete sprite; | ||||
|     return NULL; | ||||
|   } | ||||
| 
 | ||||
|  | @ -276,16 +276,6 @@ Sprite* sprite_new_with_layer(int imgtype, int w, int h) | |||
|   return sprite; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * Destroys the sprite | ||||
|  */ | ||||
| void sprite_free(Sprite* sprite) | ||||
| { | ||||
|   assert(sprite); | ||||
|   delete sprite; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| bool sprite_is_modified(Sprite* sprite) | ||||
| { | ||||
|   assert(sprite != NULL); | ||||
|  | @ -301,19 +291,6 @@ bool sprite_is_associated_to_file(Sprite* sprite) | |||
|   return sprite->associated_to_file; | ||||
| } | ||||
| 
 | ||||
| bool sprite_is_locked(Sprite* sprite) | ||||
| { | ||||
|   bool locked; | ||||
| 
 | ||||
|   assert(sprite != NULL); | ||||
| 
 | ||||
|   jmutex_lock(sprite->mutex); | ||||
|   locked = sprite->locked; | ||||
|   jmutex_unlock(sprite->mutex); | ||||
|      | ||||
|   return locked; | ||||
| } | ||||
| 
 | ||||
| void sprite_mark_as_saved(Sprite* sprite) | ||||
| { | ||||
|   assert(sprite != NULL); | ||||
|  | @ -336,30 +313,27 @@ bool sprite_need_alpha(Sprite* sprite) | |||
|   return FALSE; | ||||
| } | ||||
| 
 | ||||
| bool sprite_lock(Sprite* sprite) | ||||
| /**
 | ||||
|  * Lock the sprite to write or read it. | ||||
|  * | ||||
|  * @return true if the sprite can be written (because this is the first lock). | ||||
|  */ | ||||
| bool Sprite::lock() | ||||
| { | ||||
|   bool res = FALSE; | ||||
|   ScopedLock hold(m_mutex); | ||||
| 
 | ||||
|   assert(sprite != NULL); | ||||
| 
 | ||||
|   jmutex_lock(sprite->mutex); | ||||
|   if (!sprite->locked) { | ||||
|     sprite->locked = TRUE; | ||||
|     res = TRUE; | ||||
|   } | ||||
|   jmutex_unlock(sprite->mutex); | ||||
| 
 | ||||
|   return res; | ||||
|   if (++m_locked == 1) | ||||
|     return true; | ||||
|   else | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| void sprite_unlock(Sprite* sprite) | ||||
| void Sprite::unlock() | ||||
| { | ||||
|   assert(sprite != NULL); | ||||
|   ScopedLock hold(m_mutex); | ||||
| 
 | ||||
|   jmutex_lock(sprite->mutex); | ||||
|   assert(sprite->locked); | ||||
|   sprite->locked = FALSE; | ||||
|   jmutex_unlock(sprite->mutex); | ||||
|   --m_locked; | ||||
|   assert(m_locked >= 0); | ||||
| } | ||||
| 
 | ||||
| Palette* sprite_get_palette(Sprite* sprite, int frame) | ||||
|  | @ -838,7 +812,7 @@ static Sprite* general_copy(const Sprite* src_sprite) | |||
|   stock_free(dst_sprite->stock); | ||||
|   dst_sprite->stock = stock_new_copy(src_sprite->stock); | ||||
|   if (!dst_sprite->stock) { | ||||
|     sprite_free(dst_sprite); | ||||
|     delete dst_sprite; | ||||
|     return NULL; | ||||
|   } | ||||
| 
 | ||||
|  | @ -862,7 +836,7 @@ static Sprite* general_copy(const Sprite* src_sprite) | |||
|   if (src_sprite->path) { | ||||
|     dst_sprite->path = path_new_copy(src_sprite->path); | ||||
|     if (!dst_sprite->path) { | ||||
|       sprite_free(dst_sprite); | ||||
|       delete dst_sprite; | ||||
|       return NULL; | ||||
|     } | ||||
|   } | ||||
|  | @ -876,7 +850,7 @@ static Sprite* general_copy(const Sprite* src_sprite) | |||
|   if (src_sprite->mask) { | ||||
|     dst_sprite->mask = mask_new_copy(src_sprite->mask); | ||||
|     if (!dst_sprite->mask) { | ||||
|       sprite_free(dst_sprite); | ||||
|       delete dst_sprite; | ||||
|       return NULL; | ||||
|     } | ||||
|   } | ||||
|  |  | |||
|  | @ -70,15 +70,19 @@ public: | |||
|     int zoom; | ||||
|   } preferred; | ||||
| 
 | ||||
| private: | ||||
| 
 | ||||
|   /**
 | ||||
|    * Mutex to modify the 'locked' flag. | ||||
|    */ | ||||
|   JMutex mutex; | ||||
|   JMutex m_mutex; | ||||
| 
 | ||||
|   /**
 | ||||
|    * True when a thread is reading/writing the sprite. | ||||
|    * Greater than zero when a thread is reading/writing the sprite. | ||||
|    */ | ||||
|   bool locked; | ||||
|   int m_locked; | ||||
| 
 | ||||
| public: | ||||
| 
 | ||||
|   /**
 | ||||
|    * Data to save the file in the same format that it was loaded | ||||
|  | @ -87,24 +91,22 @@ public: | |||
| 
 | ||||
|   Sprite(int imgtype, int w, int h); | ||||
|   virtual ~Sprite(); | ||||
| 
 | ||||
|   bool lock(); | ||||
|   void unlock(); | ||||
| }; | ||||
| 
 | ||||
| Sprite* sprite_new(int imgtype, int w, int h); | ||||
| Sprite* sprite_new_copy(const Sprite* src_sprite); | ||||
| Sprite* sprite_new_flatten_copy(const Sprite* src_sprite); | ||||
| Sprite* sprite_new_with_layer(int imgtype, int w, int h); | ||||
| void sprite_free(Sprite* sprite); | ||||
| 
 | ||||
| bool sprite_is_modified(Sprite* sprite); | ||||
| bool sprite_is_associated_to_file(Sprite* sprite); | ||||
| bool sprite_is_locked(Sprite* sprite); | ||||
| void sprite_mark_as_saved(Sprite* sprite); | ||||
| 
 | ||||
| bool sprite_need_alpha(Sprite* sprite); | ||||
| 
 | ||||
| bool sprite_lock(Sprite* sprite); | ||||
| void sprite_unlock(Sprite* sprite); | ||||
| 
 | ||||
| struct Palette* sprite_get_palette(Sprite* sprite, int frame); | ||||
| void sprite_set_palette(Sprite* sprite, struct Palette* pal, bool truncate); | ||||
| void sprite_reset_palettes(Sprite* sprite); | ||||
|  |  | |||
|  | @ -112,7 +112,7 @@ void test () | |||
| 
 | ||||
|   image_free(image_screen); | ||||
|   image_free(image_bg); | ||||
|   sprite_free(sprite); | ||||
|   delete sprite; | ||||
|   destroy_bitmap(bmp); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -55,7 +55,7 @@ void set_frame_to_handle(Layer *_src_layer, int _src_frame, | |||
| 
 | ||||
| void move_cel() | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Cel *src_cel, *dst_cel; | ||||
| 
 | ||||
|   assert(src_layer != NULL); | ||||
|  | @ -147,7 +147,7 @@ void move_cel() | |||
| 
 | ||||
| void copy_cel() | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Cel *src_cel, *dst_cel; | ||||
| 
 | ||||
|   assert(src_layer != NULL); | ||||
|  |  | |||
|  | @ -21,6 +21,7 @@ | |||
| #include <assert.h> | ||||
| #include "jinete/jinete.h" | ||||
| 
 | ||||
| #include "ase/ui_context.h" | ||||
| #include "console/console.h" | ||||
| #include "core/app.h" | ||||
| #include "file/file.h" | ||||
|  | @ -69,8 +70,10 @@ Sprite *NewSprite(int imgtype, int w, int h) | |||
|     return NULL; | ||||
| 
 | ||||
|   undo_disable(sprite->undo); | ||||
|   sprite_mount(sprite); | ||||
|   set_current_sprite(sprite); | ||||
| 
 | ||||
|   UIContext* context = UIContext::instance(); | ||||
|   context->add_sprite(sprite); | ||||
|   context->set_current_sprite(sprite); | ||||
| 
 | ||||
|   assert(undo_is_disabled(sprite->undo)); | ||||
|   return sprite; | ||||
|  | @ -99,8 +102,10 @@ Sprite *LoadSprite(const char *filename) | |||
|   sprite = sprite_load(filename); | ||||
|   if (sprite) { | ||||
|     undo_disable(sprite->undo); | ||||
|     sprite_mount(sprite); | ||||
|     set_current_sprite(sprite); | ||||
| 
 | ||||
|     UIContext* context = UIContext::instance(); | ||||
|     context->add_sprite(sprite); | ||||
|     context->set_current_sprite(sprite); | ||||
|   } | ||||
| 
 | ||||
|   assert(undo_is_disabled(sprite->undo)); | ||||
|  | @ -112,7 +117,9 @@ Sprite *LoadSprite(const char *filename) | |||
|  */ | ||||
| void SaveSprite(const char *filename) | ||||
| { | ||||
|   if (current_sprite == NULL) { | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   if (sprite == NULL) { | ||||
|     console_printf("SaveSprite: No current sprite\n"); | ||||
|     return; | ||||
|   } | ||||
|  | @ -122,11 +129,11 @@ void SaveSprite(const char *filename) | |||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   sprite_set_filename(current_sprite, filename); | ||||
|   sprite_set_filename(sprite, filename); | ||||
|   app_realloc_sprite_list(); | ||||
| 
 | ||||
|   if (sprite_save(current_sprite) == 0) | ||||
|     sprite_mark_as_saved(current_sprite); | ||||
|   if (sprite_save(sprite) == 0) | ||||
|     sprite_mark_as_saved(sprite); | ||||
|   else | ||||
|     console_printf("SaveSprite: Error saving sprite file %s\n", filename); | ||||
| } | ||||
|  | @ -137,7 +144,8 @@ void SaveSprite(const char *filename) | |||
|  */ | ||||
| void SetSprite(Sprite *sprite) | ||||
| { | ||||
|   set_current_sprite(sprite); | ||||
|   UIContext* context = UIContext::instance(); | ||||
|   context->set_current_sprite(sprite); | ||||
| } | ||||
| 
 | ||||
| /*===================================================================*/ | ||||
|  | @ -396,7 +404,7 @@ static int get_max_layer_num(Layer *layer) | |||
| 
 | ||||
| void RemoveCel(Layer *layer, Cel *cel) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Image *image; | ||||
|   Cel *it; | ||||
|   int frame; | ||||
|  |  | |||
|  | @ -83,7 +83,8 @@ Image* GetImage2(Sprite* sprite, int* x, int* y, int* opacity) | |||
| 
 | ||||
| void LoadPalette(const char *filename) | ||||
| { | ||||
|   if (current_sprite) { | ||||
|   CurrentSprite sprite; | ||||
|   if (sprite) { | ||||
|     DIRS *dir, *dirs; | ||||
|     char buf[512]; | ||||
| 
 | ||||
|  | @ -101,8 +102,8 @@ void LoadPalette(const char *filename) | |||
| 	  set_current_palette(pal, FALSE); | ||||
| 
 | ||||
| 	  /* just one palette */ | ||||
| 	  sprite_reset_palettes(current_sprite); | ||||
| 	  sprite_set_palette(current_sprite, pal, 0); | ||||
| 	  sprite_reset_palettes(sprite); | ||||
| 	  sprite_set_palette(sprite, pal, 0); | ||||
| 
 | ||||
| 	  /* redraw the entire screen */ | ||||
| 	  jmanager_refresh_screen(); | ||||
|  |  | |||
|  | @ -477,11 +477,9 @@ static bool colorbar_msg_proc(JWidget widget, JMessage msg) | |||
|       /* time to refresh all the editors which have the current
 | ||||
| 	 sprite selected? */ | ||||
|       if (msg->timer.timer_id == colorbar->refresh_timer_id) { | ||||
| 	Sprite *sprite = current_sprite; | ||||
| 
 | ||||
| 	if (sprite != NULL) { | ||||
| 	CurrentSprite sprite; | ||||
| 	if (sprite != NULL) | ||||
| 	  update_editors_with_sprite(sprite); | ||||
| 	} | ||||
| 
 | ||||
| 	jmanager_stop_timer(colorbar->refresh_timer_id); | ||||
|       } | ||||
|  | @ -653,8 +651,8 @@ static bool tooltip_window_msg_proc(JWidget widget, JMessage msg) | |||
|   switch (msg->type) { | ||||
| 
 | ||||
|     case JM_CLOSE: { | ||||
|       /* change the sprite palette */ | ||||
|       Sprite *sprite = current_sprite; | ||||
|       // change the sprite palette
 | ||||
|       CurrentSprite sprite; | ||||
| 
 | ||||
|       if (sprite != NULL) { | ||||
| 	Palette *pal = sprite_get_palette(sprite, sprite->frame); | ||||
|  | @ -726,8 +724,8 @@ static bool tooltip_window_msg_proc(JWidget widget, JMessage msg) | |||
| 	   different from the current sprite's palette, then we have | ||||
| 	   to start the "refresh_timer" to refresh all the editors | ||||
| 	   with that sprite */ | ||||
| 	if (current_sprite != NULL && bitmap_color_depth(screen) != 8) { | ||||
| 	  Sprite *sprite = current_sprite; | ||||
| 	CurrentSprite sprite; | ||||
| 	if (sprite != NULL && bitmap_color_depth(screen) != 8) { | ||||
| 	  Palette *pal = sprite_get_palette(sprite, sprite->frame); | ||||
| 	   | ||||
| 	  if (palette_count_diff(pal, get_current_palette(), NULL, NULL) > 0) { | ||||
|  |  | |||
|  | @ -26,6 +26,7 @@ | |||
| 
 | ||||
| #include "jinete/jinete.h" | ||||
| 
 | ||||
| #include "ase/ui_context.h" | ||||
| #include "commands/commands.h" | ||||
| #include "core/app.h" | ||||
| #include "core/cfg.h" | ||||
|  | @ -1026,8 +1027,10 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) | |||
|       break; | ||||
| 
 | ||||
|     case JM_BUTTONPRESSED: { | ||||
|       UIContext* context = UIContext::instance(); | ||||
| 
 | ||||
|       set_current_editor(widget); | ||||
|       set_current_sprite(editor->sprite); | ||||
|       context->set_current_sprite(editor->sprite); | ||||
| 
 | ||||
|       if (!editor->sprite) | ||||
| 	break; | ||||
|  | @ -1396,7 +1399,6 @@ static void editor_update_candraw(JWidget widget) | |||
| 
 | ||||
|   editor->cursor_candraw = | ||||
|     (editor->sprite != NULL && | ||||
|      !sprite_is_locked(editor->sprite) && | ||||
|      editor->sprite->layer != NULL && | ||||
|      layer_is_image(editor->sprite->layer) && | ||||
|      layer_is_readable(editor->sprite->layer) && | ||||
|  |  | |||
|  | @ -751,7 +751,7 @@ static void openfile_bg(void *_data) | |||
|   sprite = fop->sprite; | ||||
|   if (sprite) { | ||||
|     if (fop_is_stop(fop)) | ||||
|       sprite_free(fop->sprite); | ||||
|       delete fop->sprite; | ||||
|     else { | ||||
|       /* the palette to convert the Image to a BITMAP */ | ||||
|       palette_to_allegro(sprite_get_palette(sprite, 0), data->rgbpal); | ||||
|  | @ -760,7 +760,7 @@ static void openfile_bg(void *_data) | |||
|       image = image_new(sprite->imgtype, sprite->w, sprite->h); | ||||
|       image_clear(image, 0); | ||||
|       sprite_render(sprite, image, 0, 0); | ||||
|       sprite_free(sprite); | ||||
|       delete sprite; | ||||
| 
 | ||||
|       /* calculate the thumbnail size */ | ||||
|       thumb_w = MAX_THUMBNAIL_SIZE * image->w / MAX(image->w, image->h); | ||||
|  |  | |||
|  | @ -316,24 +316,32 @@ static bool statusbar_msg_proc(JWidget widget, JMessage msg) | |||
| 	} | ||||
|       } | ||||
|       /* draw current sprite size in memory */ | ||||
|       else if (current_sprite != NULL) { | ||||
|       else { | ||||
| 	CurrentSprite sprite; | ||||
| 	if (sprite != NULL) { | ||||
| 	  char buf[1024]; | ||||
| 
 | ||||
| 	  if (sprite.writeable()) { | ||||
| 	    ustrcpy(buf, "Sprite:"); | ||||
| 	get_pretty_memsize(sprite_get_memsize(current_sprite), | ||||
| 	    get_pretty_memsize(sprite_get_memsize(sprite), | ||||
| 			       buf+ustrsize(buf), | ||||
| 			       sizeof(buf)-ustrsize(buf)); | ||||
| 
 | ||||
| 	    ustrcat(buf, " Undo:"); | ||||
| 	get_pretty_memsize(undo_get_memsize(current_sprite->undo), | ||||
| 	    get_pretty_memsize(undo_get_memsize(sprite->undo), | ||||
| 			       buf+ustrsize(buf), | ||||
| 			       sizeof(buf)-ustrsize(buf)); | ||||
| 	  } | ||||
| 	  else { | ||||
| 	    ustrcpy(buf, "Sprite is Locked"); | ||||
| 	  } | ||||
| 
 | ||||
| 	  textout_right_ex(ji_screen, widget->font(), buf, | ||||
| 			   rc->x2-2, | ||||
| 			   (widget->rc->y1+widget->rc->y2)/2-text_height(widget->font())/2, | ||||
| 			   ji_color_foreground(), -1); | ||||
| 	} | ||||
|       } | ||||
| 
 | ||||
|       jrect_free(rc); | ||||
|       return TRUE; | ||||
|  | @ -341,7 +349,7 @@ static bool statusbar_msg_proc(JWidget widget, JMessage msg) | |||
| 
 | ||||
|     case JM_MOUSEENTER: | ||||
|       if (!jwidget_has_child(widget, statusbar->commands_box)) { | ||||
| 	Sprite *sprite = current_sprite; | ||||
| 	CurrentSprite sprite; | ||||
| 
 | ||||
| 	if (!sprite) { | ||||
| 	  jwidget_disable(statusbar->b_first); | ||||
|  | @ -401,8 +409,7 @@ static bool tipwindow_msg_proc(JWidget widget, JMessage msg) | |||
| 
 | ||||
| static bool slider_change_hook(JWidget widget, void *data) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
| 
 | ||||
|   CurrentSprite sprite; | ||||
|   if (sprite) { | ||||
|     if ((sprite->layer) && | ||||
| 	(sprite->layer->type == GFXOBJ_LAYER_IMAGE)) { | ||||
|  | @ -423,7 +430,7 @@ static bool slider_change_hook(JWidget widget, void *data) | |||
| 
 | ||||
| static void button_command(JWidget widget, void *data) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
| 
 | ||||
|   if (sprite) { | ||||
|     const char *cmd = NULL; | ||||
|  | @ -462,7 +469,7 @@ static void button_command(JWidget widget, void *data) | |||
| 
 | ||||
| static void update_from_layer(StatusBar *statusbar) | ||||
| { | ||||
|   Sprite *sprite = current_sprite; | ||||
|   CurrentSprite sprite; | ||||
|   Cel *cel; | ||||
| 
 | ||||
|   /* layer button */ | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue