| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  | /* ASE - Allegro Sprite Editor
 | 
					
						
							| 
									
										
										
										
											2010-02-02 05:25:40 +08:00
										 |  |  |  * Copyright (C) 2001-2010  David Capello | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-05 09:30:50 +08:00
										 |  |  | #include "jinete/jinete.h"
 | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-09 09:34:06 +08:00
										 |  |  | #include "commands/command.h"
 | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  | #include "modules/gui.h"
 | 
					
						
							|  |  |  | #include "raster/sprite.h"
 | 
					
						
							| 
									
										
										
										
											2009-06-11 23:11:11 +08:00
										 |  |  | #include "undoable.h"
 | 
					
						
							| 
									
										
										
										
											2009-10-09 09:34:06 +08:00
										 |  |  | #include "sprite_wrappers.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // frame_properties
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FramePropertiesCommand : public Command | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |   FramePropertiesCommand(); | 
					
						
							|  |  |  |   Command* clone() { return new FramePropertiesCommand(*this); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2010-07-31 23:23:45 +08:00
										 |  |  |   bool onEnabled(Context* context); | 
					
						
							|  |  |  |   void onExecute(Context* context); | 
					
						
							| 
									
										
										
										
											2009-10-09 09:34:06 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-11 23:11:11 +08:00
										 |  |  | class SpriteReader; | 
					
						
							|  |  |  | void dialogs_frame_length(const SpriteReader& sprite, int sprite_frame); | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-09 09:34:06 +08:00
										 |  |  | FramePropertiesCommand::FramePropertiesCommand() | 
					
						
							|  |  |  |   : Command("frame_properties", | 
					
						
							|  |  |  | 	    "Frame Properties", | 
					
						
							|  |  |  | 	    CmdUIOnlyFlag) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-31 23:23:45 +08:00
										 |  |  | bool FramePropertiesCommand::onEnabled(Context* context) | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-09 09:34:06 +08:00
										 |  |  |   const CurrentSpriteReader sprite(context); | 
					
						
							| 
									
										
										
										
											2009-06-11 23:11:11 +08:00
										 |  |  |   return | 
					
						
							|  |  |  |     sprite != NULL; | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-31 23:23:45 +08:00
										 |  |  | void FramePropertiesCommand::onExecute(Context* context) | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-09 09:34:06 +08:00
										 |  |  |   const CurrentSpriteReader sprite(context); | 
					
						
							| 
									
										
										
										
											2010-03-31 08:43:18 +08:00
										 |  |  |   dialogs_frame_length(sprite, sprite->getCurrentFrame()); | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* if sprite_frame < 0, set the frame length of all frames */ | 
					
						
							| 
									
										
										
										
											2009-06-11 23:11:11 +08:00
										 |  |  | void dialogs_frame_length(const SpriteReader& sprite, int sprite_frame) | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-11 23:11:11 +08:00
										 |  |  |   JWidget frame, frlen, ok; | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  |   char buf[64]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-07 09:14:33 +08:00
										 |  |  |   FramePtr window(load_widget("frame_duration.xml", "frame_duration")); | 
					
						
							| 
									
										
										
										
											2009-06-11 23:11:11 +08:00
										 |  |  |   get_widgets(window, | 
					
						
							|  |  |  | 	      "frame", &frame, | 
					
						
							|  |  |  | 	      "frlen", &frlen, | 
					
						
							|  |  |  | 	      "ok", &ok, NULL); | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (sprite_frame < 0) | 
					
						
							|  |  |  |     strcpy(buf, "All"); | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     sprintf(buf, "%d", sprite_frame+1); | 
					
						
							| 
									
										
										
										
											2010-01-26 08:38:05 +08:00
										 |  |  |   frame->setText(buf); | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-31 08:43:18 +08:00
										 |  |  |   frlen->setTextf("%d", sprite->getFrameDuration(sprite->getCurrentFrame())); | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-26 08:38:05 +08:00
										 |  |  |   window->open_window_fg(); | 
					
						
							|  |  |  |   if (window->get_killer() == ok) { | 
					
						
							|  |  |  |     int num = strtol(frlen->getText(), NULL, 10); | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (sprite_frame < 0) { | 
					
						
							|  |  |  |       if (jalert("Warning" | 
					
						
							| 
									
										
										
										
											2008-10-11 23:59:13 +08:00
										 |  |  | 		 "<<Do you want to change the duration of all frames?" | 
					
						
							|  |  |  | 		 "||&Yes||&No") == 1) { | 
					
						
							| 
									
										
										
										
											2009-06-11 23:11:11 +08:00
										 |  |  | 	SpriteWriter sprite_writer(sprite); | 
					
						
							|  |  |  | 	Undoable undoable(sprite_writer, "Constant Frame-Rate"); | 
					
						
							| 
									
										
										
										
											2010-09-19 21:33:07 +08:00
										 |  |  | 	undoable.setConstantFrameRate(num); | 
					
						
							| 
									
										
										
										
											2008-10-11 23:59:13 +08:00
										 |  |  | 	undoable.commit(); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2009-06-11 23:11:11 +08:00
										 |  |  |       SpriteWriter sprite_writer(sprite); | 
					
						
							|  |  |  |       Undoable undoable(sprite_writer, "Frame Duration"); | 
					
						
							| 
									
										
										
										
											2010-09-19 21:33:07 +08:00
										 |  |  |       undoable.setFrameDuration(sprite_frame, num); | 
					
						
							| 
									
										
										
										
											2008-10-11 23:59:13 +08:00
										 |  |  |       undoable.commit(); | 
					
						
							| 
									
										
										
										
											2007-11-19 22:29:24 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2007-12-05 09:30:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-09 09:34:06 +08:00
										 |  |  | //////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // CommandFactory
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Command* CommandFactory::create_frame_properties_command() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return new FramePropertiesCommand; | 
					
						
							|  |  |  | } |