Added goto_*_frame & play_animation commands. With this the 'Preview'

uses the same keys to move through frames that are specified in gui.xml
This commit is contained in:
David Capello 2008-01-05 18:32:12 +00:00
parent d2be70c242
commit cbcc6953b4
16 changed files with 352 additions and 109 deletions

View File

@ -1,5 +1,9 @@
2008-01-05 David A. Capello <dacap@users.sourceforge.net>
* src/commands/cmd_play_animation.c: Added.
* src/commands/cmd_goto_frame.c: Added goto_*_frame commands.
* src/jinete/jmenu.c (Base): Added 'is_processing' to avoid
sending menu-messages when there're menu-messages in the queue.

View File

@ -6,7 +6,6 @@ High priority work
- 100% CPU
- test UNDO in 64bits plataforms (reported by Jon Rafkind);
- Add menus for play animation, a menu for all animation stuff
- add support for PNG files.
- ver por el nuevo load_font de Allegro.
- complete palette operations, and palette editor (it needs a slider
or something to move between palette changes);
@ -56,7 +55,6 @@ Wish-list
+ "middle mouse button" for the film editor.
+ don't use LINKs when load a sequence of bitmaps.
- manuq wish-list:
+ sprite/layer/frame/cel (distintion between "frame" and "cel")
+ layer-with-constant-cel
+ onion skin for all layers in a frame
- add menu customization through UI (Tools/Customize).

View File

@ -43,11 +43,11 @@
<key command="new_layer" shortcut="Shift+N" />
<!-- frame -->
<key command="new_frame" shortcut="N" />
<!-- <item command="goto_first_frame" shortcut="Up" /> -->
<!-- <item command="goto_previous_frame" name="Left" /> -->
<!-- <item command="goto_next_frame" name="Right" /> -->
<!-- <item command="goto_last_frame" name="Down" /> -->
<!-- <item command="play_animation" name="Enter" /> -->
<key command="goto_first_frame" shortcut="Down" />
<key command="goto_previous_frame" shortcut="Left" />
<key command="goto_next_frame" shortcut="Right" />
<key command="goto_last_frame" shortcut="Up" />
<key command="play_animation" shortcut="Enter" />
<!-- cel -->
<key command="cel_properties" shortcut="Shift+Ctrl+P" />
<key command="new_cel" shortcut="Shift+Ctrl+N" />
@ -158,14 +158,14 @@
<separator />
<item command="new_frame" name="&New" />
<item command="remove_frame" name="&Remove" />
<!-- <separator /> -->
<!-- <menu name="&Go to"> -->
<!-- <item command="goto_first_frame" name="&First" /> -->
<!-- <item command="goto_previous_frame" name="&Previous" /> -->
<!-- <item command="goto_next_frame" name="&Next" /> -->
<!-- <item command="goto_last_frame" name="&Last" /> -->
<!-- </menu> -->
<!-- <item command="play_animation" name="&Play" /> -->
<separator />
<menu name="&Go to">
<item command="goto_first_frame" name="&First" />
<item command="goto_previous_frame" name="&Previous" />
<item command="goto_next_frame" name="&Next" />
<item command="goto_last_frame" name="&Last" />
</menu>
<item command="play_animation" name="&Play" />
</menu>
<menu name="&Cel" id="cel_popup">
<item command="cel_properties" name="&Properties" />

View File

@ -1,4 +1,4 @@
# Copyright (C) 2001-2005, 2007 by David A. Capello -*-Makefile-*-
# Copyright (C) 2001-2005, 2007, 2008 by David A. Capello -*-Makefile-*-
######################################################################
# ASE
@ -28,6 +28,7 @@ COMMON_SOURCES = \
src/commands/cmd_flatten_layers.c \
src/commands/cmd_flip.c \
src/commands/cmd_frame_properties.c \
src/commands/cmd_goto_frame.c \
src/commands/cmd_invert_mask.c \
src/commands/cmd_layer_properties.c \
src/commands/cmd_link_cel.c \
@ -46,6 +47,7 @@ COMMON_SOURCES = \
src/commands/cmd_options.c \
src/commands/cmd_palette_editor.c \
src/commands/cmd_paste.c \
src/commands/cmd_play_animation.c \
src/commands/cmd_play_flic.c \
src/commands/cmd_preview.c \
src/commands/cmd_record_screen.c \

View File

@ -0,0 +1,132 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2008 David A. 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"
#ifndef USE_PRECOMPILED_HEADER
#include "commands/commands.h"
#include "modules/gui.h"
#include "modules/editors.h"
#include "modules/sprites.h"
#include "raster/sprite.h"
#include "widgets/editor.h"
#endif
/* ======================== */
/* goto_first_frame */
/* ======================== */
static bool cmd_goto_first_frame_enabled(const char *argument)
{
return current_sprite != NULL;
}
static void cmd_goto_first_frame_execute(const char *argument)
{
current_sprite->frame = 0;
update_screen_for_sprite(current_sprite);
editor_update_status_bar_for_standby(current_editor);
}
/* ======================== */
/* goto_previous_frame */
/* ======================== */
static bool cmd_goto_previous_frame_enabled(const char *argument)
{
return current_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;
update_screen_for_sprite(current_sprite);
editor_update_status_bar_for_standby(current_editor);
}
/* ======================== */
/* goto_next_frame */
/* ======================== */
static bool cmd_goto_next_frame_enabled(const char *argument)
{
return current_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;
update_screen_for_sprite(current_sprite);
editor_update_status_bar_for_standby(current_editor);
}
/* ======================== */
/* goto_last_frame */
/* ======================== */
static bool cmd_goto_last_frame_enabled(const char *argument)
{
return current_sprite != NULL;
}
static void cmd_goto_last_frame_execute(const char *argument)
{
current_sprite->frame = current_sprite->frames-1;
update_screen_for_sprite(current_sprite);
editor_update_status_bar_for_standby(current_editor);
}
Command cmd_goto_first_frame = {
CMD_GOTO_FIRST_FRAME,
cmd_goto_first_frame_enabled,
NULL,
cmd_goto_first_frame_execute,
};
Command cmd_goto_previous_frame = {
CMD_GOTO_PREVIOUS_FRAME,
cmd_goto_previous_frame_enabled,
NULL,
cmd_goto_previous_frame_execute,
};
Command cmd_goto_next_frame = {
CMD_GOTO_NEXT_FRAME,
cmd_goto_next_frame_enabled,
NULL,
cmd_goto_next_frame_execute,
};
Command cmd_goto_last_frame = {
CMD_GOTO_LAST_FRAME,
cmd_goto_last_frame_enabled,
NULL,
cmd_goto_last_frame_execute,
};

View File

@ -0,0 +1,123 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2008 David A. 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"
#ifndef USE_PRECOMPILED_HEADER
#include <allegro.h>
#include "jinete/jinete.h"
#include "commands/commands.h"
#include "modules/editors.h"
#include "modules/gui.h"
#include "modules/palette.h"
#include "modules/sprites.h"
#include "raster/sprite.h"
#include "widgets/editor.h"
#endif
static int speed_timer;
static void speed_timer_callback(void)
{
speed_timer++;
}
END_OF_STATIC_FUNCTION(speed_timer_callback);
static bool cmd_play_animation_enabled(const char *argument)
{
return current_sprite != NULL;
}
static void cmd_play_animation_execute(const char *argument)
{
Sprite *sprite = current_sprite;
int old_frame, msecs;
bool done = FALSE;
if (sprite->frames < 2)
return;
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 */
speed_timer = 0;
while (!done) {
msecs = sprite_get_frlen(sprite, sprite->frame);
install_int_ex(speed_timer_callback, MSEC_TO_TIMER(msecs));
set_palette(sprite_get_palette(sprite, sprite->frame));
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();
}
/* 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 */
set_current_palette(sprite_get_palette(sprite, sprite->frame), TRUE);
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,
};

View File

@ -1,5 +1,5 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2007 David A. Capello
* Copyright (C) 2007, 2008 David A. 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
@ -207,10 +207,23 @@ static void preview_sprite(int flags)
gui_feedback();
if (keypressed()) {
int c = readkey()>>8;
int readkey_value = readkey();
Command *command;
JMessage msg;
msg = jmessage_new_key_related(JM_CHAR, readkey_value);
command = command_get_by_key(msg);
jmessage_free(msg);
/* change frame */
if (editor_keys_toset_frame(widget, c)) {
if (command &&
(strcmp(command->name, CMD_GOTO_FIRST_FRAME) == 0 ||
strcmp(command->name, CMD_GOTO_PREVIOUS_FRAME) == 0 ||
strcmp(command->name, CMD_GOTO_NEXT_FRAME) == 0 ||
strcmp(command->name, CMD_GOTO_LAST_FRAME) == 0)) {
/* execute the command */
command_execute(command, NULL);
/* redraw */
redraw = TRUE;
@ -222,14 +235,19 @@ static void preview_sprite(int flags)
image_free(image);
}
}
/* play the animation */
else if (command &&
strcmp(command->name, CMD_PLAY_ANIMATION) == 0) {
/* TODO */
}
/* change background color */
else if (c == KEY_PLUS_PAD) {
else if ((readkey_value>>8) == KEY_PLUS_PAD) {
if (index_bg_color < 255) {
bg_color = palette_color[++index_bg_color];
redraw = TRUE;
}
}
else if (c == KEY_MINUS_PAD) {
else if ((readkey_value>>8) == KEY_MINUS_PAD) {
if (index_bg_color > 0) {
bg_color = palette_color[--index_bg_color];
redraw = TRUE;

View File

@ -1,5 +1,5 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2007 David A. Capello
* Copyright (C) 2007, 2008 David A. 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
@ -83,6 +83,11 @@ extern Command cmd_crop_layer;
extern Command cmd_frame_properties;
extern Command cmd_remove_frame;
extern Command cmd_new_frame;
extern Command cmd_goto_first_frame;
extern Command cmd_goto_previous_frame;
extern Command cmd_goto_next_frame;
extern Command cmd_goto_last_frame;
extern Command cmd_play_animation;
/* cel */
extern Command cmd_cel_properties;
extern Command cmd_remove_cel;
@ -174,6 +179,11 @@ static Command *commands[] = {
&cmd_frame_properties,
&cmd_remove_frame,
&cmd_new_frame,
&cmd_goto_first_frame,
&cmd_goto_previous_frame,
&cmd_goto_next_frame,
&cmd_goto_last_frame,
&cmd_play_animation,
/* cel */
&cmd_cel_properties,
&cmd_remove_cel,

View File

@ -1,5 +1,5 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2007 David A. Capello
* Copyright (C) 2007, 2008 David A. 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
@ -73,6 +73,11 @@
#define CMD_FRAME_PROPERTIES "frame_properties"
#define CMD_NEW_FRAME "new_frame"
#define CMD_REMOVE_FRAME "remove_frame"
#define CMD_GOTO_FIRST_FRAME "goto_first_frame"
#define CMD_GOTO_PREVIOUS_FRAME "goto_previous_frame"
#define CMD_GOTO_NEXT_FRAME "goto_next_frame"
#define CMD_GOTO_LAST_FRAME "goto_last_frame"
#define CMD_PLAY_ANIMATION "play_animation"
/* cel */
#define CMD_CEL_PROPERTIES "cel_properties"
#define CMD_REMOVE_CEL "remove_cel"

View File

@ -125,7 +125,6 @@ static void generate_proc_windows_list2(JWidget manager);
static int some_parent_is_focusrest(JWidget widget);
static JWidget find_magnetic_widget(JWidget widget);
static JMessage new_mouse_msg(int type);
static JMessage new_key_msg(int type, int readkey_value);
static void broadcast_key_msg(JWidget manager, JMessage msg);
static Filter *filter_new(int message, JWidget widget);
static void filter_free(Filter *filter);
@ -489,14 +488,15 @@ bool jmanager_poll(JWidget manager, bool all_windows)
int readkey_value = readkey();
/* char message first */
msg = new_key_msg(JM_CHAR, readkey_value);
msg = jmessage_new_key_related(JM_CHAR, readkey_value);
broadcast_key_msg(manager, msg);
/* key-pressed message is dependent from char message (if char
message isn't used, we send the key-pressed message) */
c = readkey_value >> 8;
if (old_readed_key[c] != key[c] && !old_readed_key[c]) {
JMessage sub_msg = new_key_msg(JM_KEYPRESSED, readkey_value);
JMessage sub_msg = jmessage_new_key_related(JM_KEYPRESSED,
readkey_value);
old_readed_key[c] = key[c];
/* same addressee */
@ -513,7 +513,8 @@ bool jmanager_poll(JWidget manager, bool all_windows)
for (c=0; c<KEY_MAX; c++) {
if (old_readed_key[c] != key[c] && old_readed_key[c]) {
/* press/release key interface */
msg = new_key_msg (JM_KEYRELEASED, (c << 8) | scancode_to_ascii(c));
msg = jmessage_new_key_related(JM_KEYRELEASED,
(c << 8) | scancode_to_ascii(c));
old_readed_key[c] = key[c];
broadcast_key_msg(manager, msg);
jmanager_enqueue_message(msg);
@ -1419,19 +1420,6 @@ static JMessage new_mouse_msg(int type)
return msg;
}
static JMessage new_key_msg(int type, int readkey_value)
{
JMessage msg = jmessage_new(type);
msg->key.scancode = (readkey_value >> 8) & 0xff;
msg->key.ascii = readkey_value & 0xff;
#if 0
printf("%i: %i %i [%c]\n", type, msg->key.scancode,
msg->key.ascii, msg->key.ascii);
#endif
return msg;
}
static void broadcast_key_msg(JWidget manager, JMessage msg)
{
JWidget window;

View File

@ -70,6 +70,19 @@ JMessage jmessage_new(int type)
return msg;
}
JMessage jmessage_new_key_related(int type, int readkey_value)
{
JMessage msg = jmessage_new(type);
msg->key.scancode = (readkey_value >> 8) & 0xff;
msg->key.ascii = readkey_value & 0xff;
#if 0
printf("%i: %i %i [%c]\n", type, msg->key.scancode,
msg->key.ascii, msg->key.ascii);
#endif
return msg;
}
JMessage jmessage_new_copy(const JMessage msg)
{
JMessage copy;

View File

@ -136,6 +136,7 @@ union jmessage
int ji_register_message_type(void);
JMessage jmessage_new(int type);
JMessage jmessage_new_key_related(int type, int readkey_value);
JMessage jmessage_new_copy(const JMessage msg);
void jmessage_free(JMessage msg);

View File

@ -430,9 +430,9 @@ void reload_default_font(void)
/* directories */
dirs = dirs_new ();
default_font = get_config_string ("Options", "DefaultFont", "");
default_font = get_config_string("Options", "DefaultFont", "");
if ((default_font) && (*default_font))
dirs_add_path (dirs, default_font);
dirs_add_path(dirs, default_font);
/* big font */
/* if (JI_SCREEN_W > 320) */
@ -446,7 +446,7 @@ void reload_default_font(void)
theme->default_font = ji_font_load (dir->path);
if (theme->default_font) {
if (ji_font_is_scalable (theme->default_font)) {
ji_font_set_size (theme->default_font,
ji_font_set_size(theme->default_font,
(JI_SCREEN_W > 320) ? 14: 8);
}
break;
@ -461,7 +461,7 @@ void reload_default_font(void)
theme->default_font = font;
/* set all widgets fonts */
_ji_set_font_of_all_widgets (theme->default_font);
_ji_set_font_of_all_widgets(theme->default_font);
}
void load_window_pos(JWidget window, const char *section)
@ -469,28 +469,28 @@ void load_window_pos(JWidget window, const char *section)
JRect pos, orig_pos;
/* default position */
orig_pos = jwidget_get_rect (window);
pos = jrect_new_copy (orig_pos);
orig_pos = jwidget_get_rect(window);
pos = jrect_new_copy(orig_pos);
/* load configurated position */
get_config_rect (section, "WindowPos", pos);
get_config_rect(section, "WindowPos", pos);
pos->x2 = pos->x1 + MID(jrect_w(orig_pos), jrect_w(pos), JI_SCREEN_W);
pos->y2 = pos->y1 + MID(jrect_h(orig_pos), jrect_h(pos), JI_SCREEN_H);
jrect_moveto (pos,
jrect_moveto(pos,
MID(0, pos->x1, JI_SCREEN_W-jrect_w(pos)),
MID(0, pos->y1, JI_SCREEN_H-jrect_h(pos)));
jwidget_set_rect (window, pos);
jwidget_set_rect(window, pos);
jrect_free (pos);
jrect_free (orig_pos);
jrect_free(pos);
jrect_free(orig_pos);
}
void save_window_pos(JWidget window, const char *section)
{
set_config_rect (section, "WindowPos", window->rc);
set_config_rect(section, "WindowPos", window->rc);
}
JWidget load_widget(const char *filename, const char *name)

View File

@ -1,5 +1,5 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001-2005, 2007, 2008 David A. 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
@ -112,7 +112,6 @@ bool editor_cursor_is_subpixel(JWidget editor);
/* src/gui/editor/keys.c */
int editor_keys_toset_zoom(JWidget editor, int scancode);
int editor_keys_toset_frame(JWidget editor, int scancode);
int editor_keys_toset_brushsize(JWidget editor, int scancode);
int editor_keys_toget_pixels(JWidget editor, int scancode);

View File

@ -838,9 +838,9 @@ void editor_update_status_bar_for_standby(JWidget widget)
Editor *editor = editor_data(widget);
int x, y;
screen_to_editor (widget, jmouse_x(0), jmouse_y(0), &x, &y);
screen_to_editor(widget, jmouse_x(0), jmouse_y(0), &x, &y);
status_bar_set_text(app_get_status_bar (), 0,
status_bar_set_text(app_get_status_bar(), 0,
"%s %3d %3d (%s %3d %3d) [%s %d]",
_("Pos"), x, y,
_("Size"),
@ -1234,7 +1234,6 @@ static bool editor_msg_proc (JWidget widget, JMessage msg)
case JM_CHAR:
if (!editor_keys_toset_zoom(widget, msg->key.scancode) &&
!editor_keys_toset_frame(widget, msg->key.scancode) &&
!editor_keys_toset_brushsize(widget, msg->key.scancode) &&
!editor_keys_toget_pixels(widget, msg->key.scancode))
return FALSE;

View File

@ -94,55 +94,6 @@ int editor_keys_toset_zoom(JWidget widget, int scancode)
return FALSE;
}
int editor_keys_toset_frame(JWidget widget, int scancode)
{
Editor *editor = editor_data(widget);
if ((editor->sprite) &&
/* (jwidget_has_mouse (widget)) && */
!(key_shifts & (KB_SHIFT_FLAG | KB_CTRL_FLAG | KB_ALT_FLAG))) {
int old_frame = editor->sprite->frame;
switch (scancode) {
/* previous frame */
case KEY_LEFT:
editor->sprite->frame--;
if (editor->sprite->frame < 0)
editor->sprite->frame = editor->sprite->frames-1;
break;
/* last frame */
case KEY_UP:
editor->sprite->frame = editor->sprite->frames-1;
break;
/* next frame */
case KEY_RIGHT:
editor->sprite->frame++;
if (editor->sprite->frame >= editor->sprite->frames)
editor->sprite->frame = 0;
break;
/* first frame */
case KEY_DOWN:
editor->sprite->frame = 0;
break;
/* nothing */
default:
return FALSE;
}
if (editor->sprite->frame != old_frame)
update_screen_for_sprite(editor->sprite);
editor_update_status_bar_for_standby(widget);
return TRUE;
}
return FALSE;
}
int editor_keys_toset_brushsize(JWidget widget, int scancode)
{
Editor *editor = editor_data(widget);