2008-01-05 18:32:12 +00:00
|
|
|
/* ASE - Allegro Sprite Editor
|
2009-01-24 00:41:01 +00:00
|
|
|
* Copyright (C) 2008-2009 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>
|
|
|
|
|
|
|
|
#include "jinete/jinete.h"
|
|
|
|
|
|
|
|
#include "commands/commands.h"
|
|
|
|
#include "modules/editors.h"
|
|
|
|
#include "modules/gui.h"
|
2008-03-22 18:43:56 +00:00
|
|
|
#include "modules/palettes.h"
|
2008-02-29 19:29:49 +00:00
|
|
|
#include "modules/tools.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"
|
|
|
|
#include "widgets/editor.h"
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
static bool cmd_play_animation_enabled(const char *argument)
|
|
|
|
{
|
2009-06-11 15:11:11 +00:00
|
|
|
const CurrentSpriteReader sprite;
|
|
|
|
return
|
|
|
|
sprite != NULL;
|
2008-01-05 18:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cmd_play_animation_execute(const char *argument)
|
|
|
|
{
|
2009-06-11 15:11:11 +00:00
|
|
|
CurrentSpriteWriter sprite;
|
2008-01-05 18:32:12 +00:00
|
|
|
int old_frame, msecs;
|
|
|
|
bool done = FALSE;
|
2008-02-29 19:29:49 +00:00
|
|
|
bool onionskin = get_onionskin();
|
2008-03-22 18:43:56 +00:00
|
|
|
Palette *oldpal, *newpal;
|
|
|
|
PALETTE rgbpal;
|
2008-01-05 18:32:12 +00:00
|
|
|
|
|
|
|
if (sprite->frames < 2)
|
|
|
|
return;
|
|
|
|
|
2008-02-29 19:29:49 +00:00
|
|
|
/* desactivate the onion-skin */
|
|
|
|
set_onionskin(FALSE);
|
|
|
|
|
2008-01-05 18:32:12 +00:00
|
|
|
jmouse_hide();
|
|
|
|
|
|
|
|
old_frame = sprite->frame;
|
|
|
|
|
|
|
|
LOCK_VARIABLE(speed_timer);
|
|
|
|
LOCK_FUNCTION(speed_timer_callback);
|
|
|
|
|
|
|
|
clear_keybuf();
|
|
|
|
|
|
|
|
/* clear all the screen */
|
|
|
|
clear_bitmap(ji_screen);
|
|
|
|
|
|
|
|
/* 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) {
|
|
|
|
msecs = sprite_get_frlen(sprite, sprite->frame);
|
|
|
|
install_int_ex(speed_timer_callback, MSEC_TO_TIMER(msecs));
|
|
|
|
|
2008-03-22 18:43:56 +00:00
|
|
|
newpal = sprite_get_palette(sprite, sprite->frame);
|
|
|
|
if (oldpal != newpal) {
|
|
|
|
set_palette(palette_to_allegro(newpal, rgbpal));
|
|
|
|
oldpal = newpal;
|
|
|
|
}
|
|
|
|
|
2008-01-05 18:32:12 +00:00
|
|
|
editor_draw_sprite_safe(current_editor, 0, 0, sprite->w, sprite->h);
|
|
|
|
|
|
|
|
do {
|
|
|
|
poll_mouse();
|
|
|
|
poll_keyboard();
|
|
|
|
if (keypressed() || mouse_b)
|
|
|
|
done = TRUE;
|
|
|
|
gui_feedback();
|
|
|
|
} while (!done && (speed_timer <= 0));
|
|
|
|
|
|
|
|
if (!done) {
|
|
|
|
sprite->frame++;
|
|
|
|
if (sprite->frame >= sprite->frames)
|
|
|
|
sprite->frame = 0;
|
|
|
|
|
|
|
|
speed_timer--;
|
|
|
|
}
|
|
|
|
gui_feedback();
|
|
|
|
}
|
|
|
|
|
2008-02-29 19:29:49 +00:00
|
|
|
set_onionskin(onionskin);
|
|
|
|
|
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 */
|
|
|
|
sprite->frame = old_frame;
|
|
|
|
|
|
|
|
/* refresh all */
|
2008-03-22 18:43:56 +00:00
|
|
|
newpal = sprite_get_palette(sprite, sprite->frame);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
Command cmd_play_animation = {
|
|
|
|
CMD_PLAY_ANIMATION,
|
|
|
|
cmd_play_animation_enabled,
|
|
|
|
NULL,
|
|
|
|
cmd_play_animation_execute,
|
|
|
|
};
|