2008-01-05 18:32:12 +00:00
|
|
|
/* ASE - Allegro Sprite Editor
|
2011-01-20 18:32:31 -03:00
|
|
|
* Copyright (C) 2001-2011 David Capello
|
2008-01-05 18:32:12 +00: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"
|
|
|
|
|
|
|
|
#include <allegro.h>
|
|
|
|
|
2011-01-30 19:12:10 -03:00
|
|
|
#include "gui/gui.h"
|
2008-01-05 18:32:12 +00:00
|
|
|
|
2009-10-09 01:34:06 +00:00
|
|
|
#include "commands/command.h"
|
2008-01-05 18:32:12 +00:00
|
|
|
#include "modules/editors.h"
|
|
|
|
#include "modules/gui.h"
|
2008-03-22 18:43:56 +00:00
|
|
|
#include "modules/palettes.h"
|
2010-03-30 21:49:35 -03:00
|
|
|
#include "raster/image.h"
|
2008-03-22 18:43:56 +00:00
|
|
|
#include "raster/palette.h"
|
2008-01-05 18:32:12 +00:00
|
|
|
#include "raster/sprite.h"
|
2011-03-27 14:54:37 -03:00
|
|
|
#include "widgets/editor/editor.h"
|
2011-03-22 21:11:25 -03:00
|
|
|
#include "document_wrappers.h"
|
2009-10-09 01:34:06 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// play_animation
|
|
|
|
|
|
|
|
class PlayAnimationCommand : public Command
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PlayAnimationCommand();
|
|
|
|
Command* clone() { return new PlayAnimationCommand(*this); }
|
|
|
|
|
|
|
|
protected:
|
2010-07-31 12:23:45 -03:00
|
|
|
bool onEnabled(Context* context);
|
|
|
|
void onExecute(Context* context);
|
2009-10-09 01:34:06 +00:00
|
|
|
};
|
2008-01-05 18:32:12 +00:00
|
|
|
|
|
|
|
static int speed_timer;
|
|
|
|
|
2008-10-01 01:27:51 +00:00
|
|
|
static void speed_timer_callback()
|
2008-01-05 18:32:12 +00:00
|
|
|
{
|
|
|
|
speed_timer++;
|
|
|
|
}
|
|
|
|
|
|
|
|
END_OF_STATIC_FUNCTION(speed_timer_callback);
|
|
|
|
|
2009-10-09 01:34:06 +00:00
|
|
|
PlayAnimationCommand::PlayAnimationCommand()
|
2011-01-20 20:46:58 -03:00
|
|
|
: Command("PlayAnimation",
|
2009-10-09 01:34:06 +00:00
|
|
|
"Play Animation",
|
|
|
|
CmdUIOnlyFlag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-31 12:23:45 -03:00
|
|
|
bool PlayAnimationCommand::onEnabled(Context* context)
|
2008-01-05 18:32:12 +00:00
|
|
|
{
|
2011-03-27 14:51:02 -03:00
|
|
|
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
|
|
|
ContextFlags::HasActiveSprite);
|
2008-01-05 18:32:12 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 12:23:45 -03:00
|
|
|
void PlayAnimationCommand::onExecute(Context* context)
|
2008-01-05 18:32:12 +00:00
|
|
|
{
|
2011-03-22 21:11:25 -03:00
|
|
|
ActiveDocumentWriter document(context);
|
|
|
|
Sprite* sprite(document->getSprite());
|
2008-01-05 18:32:12 +00:00
|
|
|
int old_frame, msecs;
|
2010-01-30 16:43:13 +00:00
|
|
|
bool done = false;
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-07 17:47:45 -02:00
|
|
|
bool onionskin_state = context->getSettings()->getUseOnionskin();
|
2008-03-22 18:43:56 +00:00
|
|
|
Palette *oldpal, *newpal;
|
|
|
|
PALETTE rgbpal;
|
2008-01-05 18:32:12 +00:00
|
|
|
|
2010-03-30 21:43:18 -03:00
|
|
|
if (sprite->getTotalFrames() < 2)
|
2008-01-05 18:32:12 +00:00
|
|
|
return;
|
|
|
|
|
2010-02-28 22:09:46 -02:00
|
|
|
// desactivate the onionskin
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-07 17:47:45 -02:00
|
|
|
context->getSettings()->setUseOnionskin(false);
|
2008-02-29 19:29:49 +00:00
|
|
|
|
2008-01-05 18:32:12 +00:00
|
|
|
jmouse_hide();
|
|
|
|
|
2010-03-30 21:43:18 -03:00
|
|
|
old_frame = sprite->getCurrentFrame();
|
2008-01-05 18:32:12 +00:00
|
|
|
|
|
|
|
LOCK_VARIABLE(speed_timer);
|
|
|
|
LOCK_FUNCTION(speed_timer_callback);
|
|
|
|
|
|
|
|
clear_keybuf();
|
|
|
|
|
2010-03-30 21:49:35 -03:00
|
|
|
// Clear all the screen
|
2008-01-05 18:32:12 +00:00
|
|
|
clear_bitmap(ji_screen);
|
|
|
|
|
2010-03-30 21:49:35 -03:00
|
|
|
// Clear extras (e.g. pen preview)
|
2011-03-22 21:11:25 -03:00
|
|
|
document->destroyExtraCel();
|
2010-03-30 21:49:35 -03:00
|
|
|
|
2010-07-17 20:44:51 -03:00
|
|
|
// Do animation
|
2008-03-22 18:43:56 +00:00
|
|
|
oldpal = NULL;
|
2008-01-05 18:32:12 +00:00
|
|
|
speed_timer = 0;
|
|
|
|
while (!done) {
|
2010-03-30 21:43:18 -03:00
|
|
|
msecs = sprite->getFrameDuration(sprite->getCurrentFrame());
|
2008-01-05 18:32:12 +00:00
|
|
|
install_int_ex(speed_timer_callback, MSEC_TO_TIMER(msecs));
|
|
|
|
|
2010-03-30 21:43:18 -03:00
|
|
|
newpal = sprite->getPalette(sprite->getCurrentFrame());
|
2008-03-22 18:43:56 +00:00
|
|
|
if (oldpal != newpal) {
|
2010-03-28 12:15:32 -03:00
|
|
|
newpal->toAllegro(rgbpal);
|
|
|
|
set_palette(rgbpal);
|
2008-03-22 18:43:56 +00:00
|
|
|
oldpal = newpal;
|
|
|
|
}
|
|
|
|
|
2010-03-30 21:43:18 -03:00
|
|
|
current_editor->editor_draw_sprite_safe(0, 0, sprite->getWidth(), sprite->getHeight());
|
2008-01-05 18:32:12 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
poll_mouse();
|
|
|
|
poll_keyboard();
|
|
|
|
if (keypressed() || mouse_b)
|
2010-01-30 16:43:13 +00:00
|
|
|
done = true;
|
2008-01-05 18:32:12 +00:00
|
|
|
gui_feedback();
|
|
|
|
} while (!done && (speed_timer <= 0));
|
|
|
|
|
|
|
|
if (!done) {
|
2010-03-30 21:43:18 -03:00
|
|
|
int frame = sprite->getCurrentFrame()+1;
|
|
|
|
if (frame >= sprite->getTotalFrames())
|
|
|
|
frame = 0;
|
|
|
|
sprite->setCurrentFrame(frame);
|
2008-01-05 18:32:12 +00:00
|
|
|
|
|
|
|
speed_timer--;
|
|
|
|
}
|
|
|
|
gui_feedback();
|
|
|
|
}
|
|
|
|
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-07 17:47:45 -02:00
|
|
|
// restore onionskin flag
|
|
|
|
context->getSettings()->setUseOnionskin(onionskin_state);
|
2008-02-29 19:29:49 +00:00
|
|
|
|
2008-01-05 18:32:12 +00:00
|
|
|
/* if right-click or ESC */
|
|
|
|
if (mouse_b == 2 || (keypressed() && (readkey()>>8) == KEY_ESC))
|
|
|
|
/* return to the old frame position */
|
2010-03-30 21:43:18 -03:00
|
|
|
sprite->setCurrentFrame(old_frame);
|
2008-01-05 18:32:12 +00:00
|
|
|
|
|
|
|
/* refresh all */
|
2010-03-30 21:43:18 -03:00
|
|
|
newpal = sprite->getPalette(sprite->getCurrentFrame());
|
2010-01-30 16:43:13 +00:00
|
|
|
set_current_palette(newpal, true);
|
2008-01-05 18:32:12 +00:00
|
|
|
jmanager_refresh_screen();
|
|
|
|
gui_feedback();
|
|
|
|
|
|
|
|
while (mouse_b)
|
|
|
|
poll_mouse();
|
|
|
|
|
|
|
|
clear_keybuf();
|
|
|
|
remove_int(speed_timer_callback);
|
|
|
|
|
|
|
|
jmouse_show();
|
|
|
|
}
|
|
|
|
|
2009-10-09 01:34:06 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// CommandFactory
|
|
|
|
|
2011-01-20 20:46:58 -03:00
|
|
|
Command* CommandFactory::createPlayAnimationCommand()
|
2009-10-09 01:34:06 +00:00
|
|
|
{
|
|
|
|
return new PlayAnimationCommand;
|
|
|
|
}
|