mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-28 16:11:35 +00:00
+ Added Flip Canvas Horizontal/Vertical commands.
+ Fixed problems with keyboard shortcuts for commands with arguments.
This commit is contained in:
parent
7280eba09e
commit
f8f45dc0e5
@ -22,8 +22,8 @@
|
||||
<key command="copy" shortcut="Ctrl+C" /> <key command="copy" shortcut="Ctrl+Ins" />
|
||||
<key command="paste" shortcut="Ctrl+V" /> <key command="paste" shortcut="Shift+Ins" />
|
||||
<key command="clear" shortcut="Ctrl+B" /> <key command="clear" shortcut="Ctrl+Del" />
|
||||
<key command="flip_horizontal" shortcut="Shift+H" />
|
||||
<key command="flip_vertical" shortcut="Shift+V" />
|
||||
<key command="flip" shortcut="Shift+H" argument="mask horizontal" />
|
||||
<key command="flip" shortcut="Shift+V" argument="mask vertical" />
|
||||
<key command="replace_color" shortcut="Shift+R" />
|
||||
<key command="invert_color" shortcut="Ctrl+I" />
|
||||
<!-- sprite -->
|
||||
@ -118,8 +118,8 @@
|
||||
<item command="paste" name="&Paste" />
|
||||
<item command="clear" name="C&lear" />
|
||||
<separator />
|
||||
<item command="flip_horizontal" name="Flip &Horizontal" />
|
||||
<item command="flip_vertical" name="Flip &Vertical" />
|
||||
<item command="flip" name="Flip &Horizontal" argument="mask horizontal" />
|
||||
<item command="flip" name="Flip &Vertical" argument="mask vertical" />
|
||||
<separator />
|
||||
<item command="replace_color" name="R&eplace Color..." />
|
||||
<item command="invert_color" name="&Invert" />
|
||||
@ -142,8 +142,8 @@
|
||||
<item command="rotate_canvas" name="90 CW" argument="90" />
|
||||
<item command="rotate_canvas" name="90 CCW" argument="-90" />
|
||||
<separator />
|
||||
<item command="flip_canvas_horizontal" name="Flip Canvas &Horizontal" />
|
||||
<item command="flip_canvas_vertical" name="Flip Canvas &Vertical" />
|
||||
<item command="flip" name="Flip Canvas &Horizontal" argument="canvas horizontal" />
|
||||
<item command="flip" name="Flip Canvas &Vertical" argument="canvas vertical" />
|
||||
</menu>
|
||||
<separator />
|
||||
<item command="crop_sprite" name="Cr&op" />
|
||||
|
@ -133,5 +133,4 @@ Command cmd_about = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_about_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -50,26 +50,29 @@ static void cmd_advanced_mode_execute(const char *argument)
|
||||
jwidget_dirty(app_get_top_window());
|
||||
|
||||
if (advanced_mode &&
|
||||
get_config_bool("AdvancedMode", "Warning", TRUE)) {
|
||||
Command *cmd_advanced_mode = command_get_by_name(CMD_ADVANCED_MODE);
|
||||
char warning[1024];
|
||||
char key[1024];
|
||||
char buf[1024];
|
||||
get_config_bool("AdvancedMode", "Warning", true)) {
|
||||
Command* cmd_advanced_mode = command_get_by_name(CMD_ADVANCED_MODE);
|
||||
JAccel accel = get_accel_to_execute_command(cmd_advanced_mode, NULL);
|
||||
if (accel != NULL) {
|
||||
char warning[1024];
|
||||
char key[1024];
|
||||
char buf[1024];
|
||||
|
||||
JWidgetPtr window(load_widget("advanced.jid", "advanced_mode_warning"));
|
||||
JWidget warning_label = find_widget(window, "warning_label");
|
||||
JWidget donot_show = find_widget(window, "donot_show");
|
||||
JWidgetPtr window(load_widget("advanced.jid", "advanced_mode_warning"));
|
||||
JWidget warning_label = find_widget(window, "warning_label");
|
||||
JWidget donot_show = find_widget(window, "donot_show");
|
||||
|
||||
strcpy(warning, _("You can back pressing the \"%s\" key."));
|
||||
jaccel_to_string(cmd_advanced_mode->accel, key);
|
||||
sprintf(buf, warning, key);
|
||||
strcpy(warning, _("You can back pressing the \"%s\" key."));
|
||||
jaccel_to_string(accel, key);
|
||||
sprintf(buf, warning, key);
|
||||
|
||||
jwidget_set_text(warning_label, buf);
|
||||
jwidget_set_text(warning_label, buf);
|
||||
|
||||
jwindow_open_fg(window);
|
||||
jwindow_open_fg(window);
|
||||
|
||||
set_config_bool("AdvancedMode", "Warning",
|
||||
!jwidget_is_selected(donot_show));
|
||||
set_config_bool("AdvancedMode", "Warning",
|
||||
!jwidget_is_selected(donot_show));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,5 +81,4 @@ Command cmd_advanced_mode = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_advanced_mode_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -61,5 +61,4 @@ Command cmd_background_from_layer = {
|
||||
cmd_background_from_layer_enabled,
|
||||
NULL,
|
||||
cmd_background_from_layer_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -86,5 +86,4 @@ Command cmd_canvas_size = {
|
||||
cmd_canvas_size_enabled,
|
||||
NULL,
|
||||
cmd_canvas_size_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -141,5 +141,4 @@ Command cmd_cel_properties = {
|
||||
cmd_cel_properties_enabled,
|
||||
NULL,
|
||||
cmd_cel_properties_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -76,5 +76,4 @@ Command cmd_change_image_type = {
|
||||
cmd_change_image_type_enabled,
|
||||
NULL,
|
||||
cmd_change_image_type_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -55,5 +55,4 @@ Command cmd_clear = {
|
||||
cmd_clear_enabled,
|
||||
NULL,
|
||||
cmd_clear_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -110,7 +110,6 @@ Command cmd_close_file = {
|
||||
cmd_close_file_enabled,
|
||||
NULL,
|
||||
cmd_close_file_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_close_all_files = {
|
||||
@ -118,5 +117,4 @@ Command cmd_close_all_files = {
|
||||
cmd_close_all_files_enabled,
|
||||
NULL,
|
||||
cmd_close_all_files_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -253,5 +253,4 @@ Command cmd_configure_screen = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_configure_screen_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -371,5 +371,4 @@ Command cmd_configure_tools = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_configure_tools_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -54,5 +54,4 @@ Command cmd_copy = {
|
||||
cmd_copy_enabled,
|
||||
NULL,
|
||||
cmd_copy_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -40,5 +40,4 @@ Command cmd_copy_cel = {
|
||||
cmd_copy_cel_enabled,
|
||||
NULL,
|
||||
cmd_copy_cel_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -92,7 +92,6 @@ Command cmd_crop_sprite = {
|
||||
cmd_crop_sprite_enabled,
|
||||
NULL,
|
||||
cmd_crop_sprite_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_autocrop_sprite = {
|
||||
@ -100,5 +99,4 @@ Command cmd_autocrop_sprite = {
|
||||
cmd_autocrop_sprite_enabled,
|
||||
NULL,
|
||||
cmd_autocrop_sprite_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -53,5 +53,4 @@ Command cmd_cut = {
|
||||
cmd_cut_enabled,
|
||||
NULL,
|
||||
cmd_cut_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -66,5 +66,4 @@ Command cmd_deselect_mask = {
|
||||
cmd_deselect_mask_enabled,
|
||||
NULL,
|
||||
cmd_deselect_mask_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -173,7 +173,6 @@ Command cmd_blur_tool = {
|
||||
NULL,
|
||||
cmd_blur_tool_checked,
|
||||
cmd_blur_tool_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_brush_tool = {
|
||||
@ -181,7 +180,6 @@ Command cmd_brush_tool = {
|
||||
NULL,
|
||||
cmd_brush_tool_checked,
|
||||
cmd_brush_tool_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_ellipse_tool = {
|
||||
@ -189,7 +187,6 @@ Command cmd_ellipse_tool = {
|
||||
NULL,
|
||||
cmd_ellipse_tool_checked,
|
||||
cmd_ellipse_tool_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_eraser_tool = {
|
||||
@ -197,7 +194,6 @@ Command cmd_eraser_tool = {
|
||||
NULL,
|
||||
cmd_eraser_tool_checked,
|
||||
cmd_eraser_tool_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_floodfill_tool = {
|
||||
@ -205,7 +201,6 @@ Command cmd_floodfill_tool = {
|
||||
NULL,
|
||||
cmd_floodfill_tool_checked,
|
||||
cmd_floodfill_tool_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_line_tool = {
|
||||
@ -213,7 +208,6 @@ Command cmd_line_tool = {
|
||||
NULL,
|
||||
cmd_line_tool_checked,
|
||||
cmd_line_tool_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_marker_tool = {
|
||||
@ -221,7 +215,6 @@ Command cmd_marker_tool = {
|
||||
NULL,
|
||||
cmd_marker_tool_checked,
|
||||
cmd_marker_tool_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_pencil_tool = {
|
||||
@ -229,7 +222,6 @@ Command cmd_pencil_tool = {
|
||||
NULL,
|
||||
cmd_pencil_tool_checked,
|
||||
cmd_pencil_tool_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_rectangle_tool = {
|
||||
@ -237,7 +229,6 @@ Command cmd_rectangle_tool = {
|
||||
NULL,
|
||||
cmd_rectangle_tool_checked,
|
||||
cmd_rectangle_tool_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_spray_tool = {
|
||||
@ -245,5 +236,4 @@ Command cmd_spray_tool = {
|
||||
NULL,
|
||||
cmd_spray_tool_checked,
|
||||
cmd_spray_tool_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -96,5 +96,4 @@ Command cmd_duplicate_layer = {
|
||||
cmd_duplicate_layer_enabled,
|
||||
NULL,
|
||||
cmd_duplicate_layer_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -88,5 +88,4 @@ Command cmd_duplicate_sprite = {
|
||||
cmd_duplicate_sprite_enabled,
|
||||
NULL,
|
||||
cmd_duplicate_sprite_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -51,5 +51,4 @@ Command cmd_exit = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_exit_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -67,5 +67,4 @@ Command cmd_eyedropper_tool = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_eyedropper_tool_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -40,5 +40,4 @@ Command cmd_film_editor = {
|
||||
cmd_film_editor_enabled,
|
||||
NULL,
|
||||
cmd_film_editor_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -49,5 +49,4 @@ Command cmd_flatten_layers = {
|
||||
cmd_flatten_layers_enabled,
|
||||
NULL,
|
||||
cmd_flatten_layers_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -18,116 +18,108 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro/unicode.h>
|
||||
|
||||
#include "jinete/jlist.h"
|
||||
|
||||
#include "commands/commands.h"
|
||||
#include "modules/editors.h"
|
||||
#include "modules/gui.h"
|
||||
#include "modules/sprites.h"
|
||||
#include "raster/cel.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/mask.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/stock.h"
|
||||
#include "raster/undo.h"
|
||||
#include "util/misc.h"
|
||||
#include "undoable.h"
|
||||
|
||||
static void do_flip(Sprite* sprite, bool horz);
|
||||
|
||||
/* ======================== */
|
||||
/* flip_horizontal */
|
||||
/* ======================== */
|
||||
|
||||
static bool cmd_flip_horizontal_enabled(const char *argument)
|
||||
static bool cmd_flip_enabled(const char *argument)
|
||||
{
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
sprite != NULL &&
|
||||
argument != NULL;
|
||||
}
|
||||
|
||||
static void cmd_flip_horizontal_execute(const char *argument)
|
||||
static void cmd_flip_execute(const char *argument)
|
||||
{
|
||||
CurrentSpriteWriter sprite;
|
||||
do_flip(sprite, true);
|
||||
}
|
||||
bool flip_mask = ustrstr(argument, "mask") != NULL;
|
||||
bool flip_canvas = ustrstr(argument, "canvas") != NULL;
|
||||
bool flip_horizontal = ustrstr(argument, "horizontal") != NULL;
|
||||
bool flip_vertical = ustrstr(argument, "vertical") != NULL;
|
||||
|
||||
/* ======================== */
|
||||
/* flip_vertical */
|
||||
/* ======================== */
|
||||
{
|
||||
Undoable undoable(sprite,
|
||||
flip_mask ? (flip_horizontal ? "Flip Horizontal":
|
||||
"Flip Vertical"):
|
||||
(flip_horizontal ? "Flip Canvas Horizontal":
|
||||
"Flip Canvas Vertical"));
|
||||
|
||||
static bool cmd_flip_vertical_enabled(const char *argument)
|
||||
{
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
if (flip_mask) {
|
||||
Image *image, *area;
|
||||
int x1, y1, x2, y2;
|
||||
int x, y;
|
||||
|
||||
static void cmd_flip_vertical_execute(const char *argument)
|
||||
{
|
||||
CurrentSpriteWriter sprite;
|
||||
do_flip(sprite, false);
|
||||
}
|
||||
image = GetImage2(sprite, &x, &y, NULL);
|
||||
if (!image)
|
||||
return;
|
||||
|
||||
/************************************************************/
|
||||
/* do_flip */
|
||||
// mask is empty?
|
||||
if (mask_is_empty(sprite->mask)) {
|
||||
// so we flip the entire image
|
||||
x1 = 0;
|
||||
y1 = 0;
|
||||
x2 = image->w-1;
|
||||
y2 = image->h-1;
|
||||
}
|
||||
else {
|
||||
// apply the cel offset
|
||||
x1 = sprite->mask->x - x;
|
||||
y1 = sprite->mask->y - y;
|
||||
x2 = sprite->mask->x + sprite->mask->w - 1 - x;
|
||||
y2 = sprite->mask->y + sprite->mask->h - 1 - y;
|
||||
|
||||
static void do_flip(Sprite* sprite, bool horz)
|
||||
{
|
||||
Image *image, *area;
|
||||
int x1, y1, x2, y2;
|
||||
int x, y;
|
||||
// clip
|
||||
x1 = MID(0, x1, image->w-1);
|
||||
y1 = MID(0, y1, image->h-1);
|
||||
x2 = MID(0, x2, image->w-1);
|
||||
y2 = MID(0, y2, image->h-1);
|
||||
}
|
||||
|
||||
image = GetImage2(sprite, &x, &y, NULL);
|
||||
if (!image)
|
||||
return;
|
||||
undoable.flip_image(image, x1, y1, x2, y2, flip_horizontal, flip_vertical);
|
||||
}
|
||||
else if (flip_canvas) {
|
||||
// get all sprite cels
|
||||
JList cels = jlist_new();
|
||||
sprite_get_cels(sprite, cels);
|
||||
|
||||
if (mask_is_empty(sprite->mask)) {
|
||||
x1 = 0;
|
||||
y1 = 0;
|
||||
x2 = image->w-1;
|
||||
y2 = image->h-1;
|
||||
// for each cel...
|
||||
JLink link;
|
||||
JI_LIST_FOR_EACH(cels, link) {
|
||||
Cel* cel = (Cel*)link->data;
|
||||
Image* image = stock_get_image(sprite->stock, cel->image);
|
||||
|
||||
undoable.set_cel_position(cel,
|
||||
flip_horizontal ? sprite->w - image->w - cel->x: cel->x,
|
||||
flip_vertical ? sprite->h - image->h - cel->y: cel->y);
|
||||
|
||||
undoable.flip_image(image, 0, 0, image->w-1, image->h-1,
|
||||
flip_horizontal, flip_vertical);
|
||||
}
|
||||
jlist_free(cels);
|
||||
}
|
||||
|
||||
undoable.commit();
|
||||
}
|
||||
else {
|
||||
/* apply the cel offset */
|
||||
x1 = sprite->mask->x - x;
|
||||
y1 = sprite->mask->y - y;
|
||||
x2 = sprite->mask->x + sprite->mask->w - 1 - x;
|
||||
y2 = sprite->mask->y + sprite->mask->h - 1 - y;
|
||||
|
||||
/* clip */
|
||||
x1 = MID(0, x1, image->w-1);
|
||||
y1 = MID(0, y1, image->h-1);
|
||||
x2 = MID(0, x2, image->w-1);
|
||||
y2 = MID(0, y2, image->h-1);
|
||||
}
|
||||
|
||||
/* insert the undo operation */
|
||||
if (undo_is_enabled(sprite->undo)) {
|
||||
undo_set_label(sprite->undo, horz ? "Horizontal Flip":
|
||||
"Vertical Flip");
|
||||
undo_flip(sprite->undo, image, x1, y1, x2, y2, horz);
|
||||
}
|
||||
|
||||
/* flip the portion of the bitmap */
|
||||
area = image_crop(image, x1, y1, x2-x1+1, y2-y1+1, 0);
|
||||
for (y=0; y<(y2-y1+1); y++)
|
||||
for (x=0; x<(x2-x1+1); x++)
|
||||
image_putpixel(image,
|
||||
horz ? x2-x: x1+x,
|
||||
!horz? y2-y: y1+y,
|
||||
image_getpixel(area, x, y));
|
||||
image_free(area);
|
||||
update_screen_for_sprite(sprite);
|
||||
}
|
||||
|
||||
Command cmd_flip_horizontal = {
|
||||
CMD_FLIP_HORIZONTAL,
|
||||
cmd_flip_horizontal_enabled,
|
||||
Command cmd_flip = {
|
||||
CMD_FLIP,
|
||||
cmd_flip_enabled,
|
||||
NULL,
|
||||
cmd_flip_horizontal_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_flip_vertical = {
|
||||
CMD_FLIP_VERTICAL,
|
||||
cmd_flip_vertical_enabled,
|
||||
NULL,
|
||||
cmd_flip_vertical_execute,
|
||||
NULL
|
||||
cmd_flip_execute,
|
||||
};
|
||||
|
@ -91,5 +91,4 @@ Command cmd_frame_properties = {
|
||||
cmd_frame_properties_enabled,
|
||||
NULL,
|
||||
cmd_frame_properties_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -69,7 +69,6 @@ Command cmd_show_grid = {
|
||||
NULL,
|
||||
cmd_show_grid_checked,
|
||||
cmd_show_grid_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_snap_to_grid = {
|
||||
@ -77,5 +76,4 @@ Command cmd_snap_to_grid = {
|
||||
NULL,
|
||||
cmd_snap_to_grid_checked,
|
||||
cmd_snap_to_grid_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -85,5 +85,4 @@ Command cmd_invert_mask = {
|
||||
cmd_invert_mask_enabled,
|
||||
NULL,
|
||||
cmd_invert_mask_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -53,5 +53,4 @@ Command cmd_layer_from_background = {
|
||||
cmd_layer_from_background_enabled,
|
||||
NULL,
|
||||
cmd_layer_from_background_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -113,5 +113,4 @@ Command cmd_layer_properties = {
|
||||
cmd_layer_properties_enabled,
|
||||
NULL,
|
||||
cmd_layer_properties_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -67,5 +67,4 @@ Command cmd_load_mask = {
|
||||
cmd_load_mask_enabled,
|
||||
NULL,
|
||||
cmd_load_mask_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -53,5 +53,4 @@ Command cmd_mask_all = {
|
||||
cmd_mask_all_enabled,
|
||||
NULL,
|
||||
cmd_mask_all_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -42,5 +42,4 @@ Command cmd_mask_by_color = {
|
||||
cmd_mask_by_color_enabled,
|
||||
NULL,
|
||||
cmd_mask_by_color_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -173,5 +173,4 @@ Command cmd_merge_down_layer = {
|
||||
cmd_merge_down_layer_enabled,
|
||||
NULL,
|
||||
cmd_merge_down_layer_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -40,5 +40,4 @@ Command cmd_move_cel = {
|
||||
cmd_move_cel_enabled,
|
||||
NULL,
|
||||
cmd_move_cel_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -180,5 +180,4 @@ Command cmd_new_file = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_new_file_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -67,5 +67,4 @@ Command cmd_new_frame = {
|
||||
cmd_new_frame_enabled,
|
||||
NULL,
|
||||
cmd_new_frame_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -99,5 +99,4 @@ Command cmd_new_layer = {
|
||||
cmd_new_layer_enabled,
|
||||
NULL,
|
||||
cmd_new_layer_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -60,5 +60,4 @@ Command cmd_new_layer_set = {
|
||||
cmd_new_layer_set_enabled,
|
||||
NULL,
|
||||
cmd_new_layer_set_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -113,13 +113,13 @@ static void monitor_openfile_bg(void *_data)
|
||||
*
|
||||
* [main thread]
|
||||
*/
|
||||
static void monitor_free(void *_data)
|
||||
static void monitor_free(void* _data)
|
||||
{
|
||||
OpenFileData *data = (OpenFileData *)_data;
|
||||
FileOp *fop = (FileOp *)data->fop;
|
||||
OpenFileData* data = (OpenFileData*)_data;
|
||||
|
||||
#if 0
|
||||
/* stop the file-operation and wait the thread to exit */
|
||||
FileOp* fop = (FileOp*)data->fop;
|
||||
fop_stop(fop);
|
||||
jthread_join(data->thread);
|
||||
#endif
|
||||
@ -233,5 +233,4 @@ Command cmd_open_file = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_open_file_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -33,5 +33,4 @@ Command cmd_options = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_options_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -538,5 +538,4 @@ Command cmd_palette_editor = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_palette_editor_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -47,5 +47,4 @@ Command cmd_paste = {
|
||||
cmd_paste_enabled,
|
||||
NULL,
|
||||
cmd_paste_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -210,6 +210,9 @@ static void preview_sprite(int flags)
|
||||
for (u=x-w; u<JI_SCREEN_W+w; u+=w)
|
||||
blit(bmp, ji_screen, 0, 0, u, v, w, h);
|
||||
break;
|
||||
case TILED_NONE:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -233,6 +236,9 @@ static void preview_sprite(int flags)
|
||||
for (u=x-w; u<JI_SCREEN_W+w; u+=w)
|
||||
stretch_blit(bmp, ji_screen, 0, 0, bmp->w, bmp->h, u, v, w, h);
|
||||
break;
|
||||
case TILED_NONE:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -243,11 +249,8 @@ static void preview_sprite(int flags)
|
||||
|
||||
if (keypressed()) {
|
||||
int readkey_value = readkey();
|
||||
Command *command;
|
||||
JMessage msg;
|
||||
|
||||
msg = jmessage_new_key_related(JM_KEYPRESSED, readkey_value);
|
||||
command = command_get_by_key(msg);
|
||||
JMessage msg = jmessage_new_key_related(JM_KEYPRESSED, readkey_value);
|
||||
Command* command = get_command_from_key_message(msg);
|
||||
jmessage_free(msg);
|
||||
|
||||
/* change frame */
|
||||
@ -315,7 +318,6 @@ Command cmd_preview_fit_to_screen = {
|
||||
cmd_preview_enabled,
|
||||
NULL,
|
||||
cmd_preview_fit_to_screen_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_preview_normal = {
|
||||
@ -323,7 +325,6 @@ Command cmd_preview_normal = {
|
||||
cmd_preview_enabled,
|
||||
NULL,
|
||||
cmd_preview_normal_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_preview_tiled = {
|
||||
@ -331,5 +332,4 @@ Command cmd_preview_tiled = {
|
||||
cmd_preview_enabled,
|
||||
NULL,
|
||||
cmd_preview_tiled_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -51,5 +51,4 @@ Command cmd_record_screen = {
|
||||
NULL,
|
||||
cmd_record_screen_checked,
|
||||
cmd_record_screen_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -52,5 +52,4 @@ Command cmd_redo = {
|
||||
cmd_redo_enabled,
|
||||
NULL,
|
||||
cmd_redo_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -62,5 +62,4 @@ Command cmd_refresh = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_refresh_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -55,5 +55,4 @@ Command cmd_remove_cel = {
|
||||
cmd_remove_cel_enabled,
|
||||
NULL,
|
||||
cmd_remove_cel_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -50,5 +50,4 @@ Command cmd_remove_frame = {
|
||||
cmd_remove_frame_enabled,
|
||||
NULL,
|
||||
cmd_remove_frame_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -49,5 +49,4 @@ Command cmd_remove_layer = {
|
||||
cmd_remove_layer_enabled,
|
||||
NULL,
|
||||
cmd_remove_layer_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -63,5 +63,4 @@ Command cmd_reselect_mask = {
|
||||
cmd_reselect_mask_enabled,
|
||||
NULL,
|
||||
cmd_reselect_mask_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -273,7 +273,6 @@ Command cmd_save_file = {
|
||||
cmd_save_file_enabled,
|
||||
NULL,
|
||||
cmd_save_file_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
/**
|
||||
@ -284,7 +283,6 @@ Command cmd_save_file_as = {
|
||||
cmd_save_file_as_enabled,
|
||||
NULL,
|
||||
cmd_save_file_as_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
/**
|
||||
@ -295,5 +293,4 @@ Command cmd_save_file_copy_as = {
|
||||
cmd_save_file_copy_as_enabled,
|
||||
NULL,
|
||||
cmd_save_file_copy_as_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -82,5 +82,4 @@ Command cmd_save_mask = {
|
||||
cmd_save_mask_enabled,
|
||||
NULL,
|
||||
cmd_save_mask_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -115,5 +115,4 @@ Command cmd_screen_shot = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_screen_shot_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -79,5 +79,4 @@ Command cmd_select_file = {
|
||||
cmd_select_file_enabled,
|
||||
cmd_select_file_checked,
|
||||
cmd_select_file_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -46,7 +46,6 @@ Command cmd_close_editor = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_close_editor_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_make_unique_editor = {
|
||||
@ -54,7 +53,6 @@ Command cmd_make_unique_editor = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_make_unique_editor_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_split_editor_horizontally = {
|
||||
@ -62,7 +60,6 @@ Command cmd_split_editor_horizontally = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_split_editor_horizontally_execute,
|
||||
NULL
|
||||
};
|
||||
|
||||
Command cmd_split_editor_vertically = {
|
||||
@ -70,5 +67,4 @@ Command cmd_split_editor_vertically = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_split_editor_vertically_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -117,5 +117,4 @@ Command cmd_sprite_properties = {
|
||||
cmd_sprite_properties_enabled,
|
||||
NULL,
|
||||
cmd_sprite_properties_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -291,5 +291,4 @@ Command cmd_sprite_size = {
|
||||
cmd_sprite_size_enabled,
|
||||
NULL,
|
||||
cmd_sprite_size_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -41,5 +41,4 @@ Command cmd_switch_colors = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_switch_colors_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -33,5 +33,4 @@ Command cmd_tips = {
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_tips_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -52,5 +52,4 @@ Command cmd_undo = {
|
||||
cmd_undo_enabled,
|
||||
NULL,
|
||||
cmd_undo_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -59,8 +59,7 @@ extern Command cmd_exit;
|
||||
extern Command cmd_eyedropper_tool;
|
||||
extern Command cmd_film_editor;
|
||||
extern Command cmd_flatten_layers;
|
||||
extern Command cmd_flip_horizontal;
|
||||
extern Command cmd_flip_vertical;
|
||||
extern Command cmd_flip;
|
||||
extern Command cmd_floodfill_tool;
|
||||
extern Command cmd_frame_properties;
|
||||
extern Command cmd_goto_first_frame;
|
||||
@ -154,8 +153,7 @@ static Command *commands[] = {
|
||||
&cmd_eyedropper_tool,
|
||||
&cmd_film_editor,
|
||||
&cmd_flatten_layers,
|
||||
&cmd_flip_horizontal,
|
||||
&cmd_flip_vertical,
|
||||
&cmd_flip,
|
||||
&cmd_floodfill_tool,
|
||||
&cmd_frame_properties,
|
||||
&cmd_goto_first_frame,
|
||||
@ -234,18 +232,6 @@ Command *command_get_by_name(const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Command *command_get_by_key(JMessage msg)
|
||||
{
|
||||
Command **cmd;
|
||||
|
||||
for (cmd=commands; *cmd; cmd++) {
|
||||
if (command_is_key_pressed(*cmd, msg))
|
||||
return *cmd;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current state of the program fulfills the
|
||||
* preconditions to execute this command.
|
||||
@ -302,37 +288,3 @@ void command_execute(Command *command, const char *argument)
|
||||
"Details: Unknown exception caught.");
|
||||
}
|
||||
}
|
||||
|
||||
bool command_is_key_pressed(Command *command, JMessage msg)
|
||||
{
|
||||
if (command->accel) {
|
||||
return jaccel_check(command->accel,
|
||||
msg->any.shifts,
|
||||
msg->key.ascii,
|
||||
msg->key.scancode);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void command_add_key(Command *command, const char *string)
|
||||
{
|
||||
char buf[256];
|
||||
|
||||
if (!command->accel)
|
||||
command->accel = jaccel_new();
|
||||
|
||||
usprintf(buf, "<%s>", string);
|
||||
jaccel_add_keys_from_string(command->accel, buf);
|
||||
}
|
||||
|
||||
void command_reset_keys()
|
||||
{
|
||||
Command **cmd;
|
||||
|
||||
for (cmd=commands; *cmd; cmd++) {
|
||||
if ((*cmd)->accel) {
|
||||
jaccel_free((*cmd)->accel);
|
||||
(*cmd)->accel = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,8 +53,7 @@
|
||||
#define CMD_EYEDROPPER_TOOL "eyedropper_tool"
|
||||
#define CMD_FILM_EDITOR "film_editor"
|
||||
#define CMD_FLATTEN_LAYERS "flatten_layers"
|
||||
#define CMD_FLIP_HORIZONTAL "flip_horizontal"
|
||||
#define CMD_FLIP_VERTICAL "flip_vertical"
|
||||
#define CMD_FLIP "flip"
|
||||
#define CMD_FLOODFILL_TOOL "floodfill_tool"
|
||||
#define CMD_FRAME_PROPERTIES "frame_properties"
|
||||
#define CMD_GOTO_FIRST_FRAME "goto_first_frame"
|
||||
@ -123,18 +122,12 @@ struct Command
|
||||
bool (*enabled)(const char *argument); /* preconditions to execute the command */
|
||||
bool (*checked)(const char *argument); /* should the menu-item be checked? */
|
||||
void (*execute)(const char *argument); /* execute the command (after check the preconditions) */
|
||||
JAccel accel;
|
||||
};
|
||||
|
||||
Command *command_get_by_name(const char *name);
|
||||
Command *command_get_by_key(JMessage msg);
|
||||
|
||||
bool command_is_enabled(Command *command, const char *argument);
|
||||
bool command_is_checked(Command *command, const char *argument);
|
||||
void command_execute(Command *command, const char *argument);
|
||||
|
||||
bool command_is_key_pressed(Command *command, JMessage msg);
|
||||
void command_add_key(Command *command, const char *string);
|
||||
void command_reset_keys();
|
||||
|
||||
#endif /* COMMANDS_COMMANDS_H */
|
||||
|
@ -160,5 +160,4 @@ Command cmd_color_curve = {
|
||||
cmd_color_curve_enabled,
|
||||
NULL,
|
||||
cmd_color_curve_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -318,5 +318,4 @@ Command cmd_convolution_matrix = {
|
||||
cmd_convolution_matrix_enabled,
|
||||
NULL,
|
||||
cmd_convolution_matrix_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -185,5 +185,4 @@ Command cmd_despeckle = {
|
||||
cmd_despeckle_enabled,
|
||||
NULL,
|
||||
cmd_despeckle_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -134,5 +134,4 @@ Command cmd_invert_color = {
|
||||
cmd_invert_color_enabled,
|
||||
NULL,
|
||||
cmd_invert_color_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -189,5 +189,4 @@ Command cmd_replace_color = {
|
||||
cmd_replace_color_enabled,
|
||||
NULL,
|
||||
cmd_replace_color_execute,
|
||||
NULL
|
||||
};
|
||||
|
@ -685,7 +685,7 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
|
||||
break;
|
||||
|
||||
case JM_KEYPRESSED: {
|
||||
Command *command = command_get_by_key(msg);
|
||||
Command *command = get_command_from_key_message(msg);
|
||||
|
||||
/* close animation editor */
|
||||
if ((command && (strcmp(command->name, CMD_FILM_EDITOR) == 0)) ||
|
||||
@ -813,7 +813,7 @@ static void anieditor_setcursor(JWidget widget, int x, int y)
|
||||
{
|
||||
AniEditor* anieditor = anieditor_data(widget);
|
||||
int mx = x - widget->rc->x1;
|
||||
int my = y - widget->rc->y1;
|
||||
//int my = y - widget->rc->y1;
|
||||
|
||||
/* is the mouse in the separator */
|
||||
if (mx > anieditor->separator_x-2 && mx < anieditor->separator_x+2) {
|
||||
|
@ -18,7 +18,10 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <allegro.h>
|
||||
#include <allegro/internal/aintern.h>
|
||||
|
||||
@ -56,7 +59,7 @@
|
||||
|
||||
#define MONITOR_TIMER_MSECS 100
|
||||
|
||||
/**************************************************************/
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef ALLEGRO_WINDOWS
|
||||
# define DEF_SCALE 2
|
||||
@ -78,22 +81,55 @@ static struct
|
||||
|
||||
static int try_depths[] = { 32, 24, 16, 15, 8 };
|
||||
|
||||
/**************************************************************/
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum ShortcutType { Shortcut_ExecuteCommand,
|
||||
Shortcut_ChangeTool };
|
||||
|
||||
struct Shortcut
|
||||
{
|
||||
JAccel accel;
|
||||
ShortcutType type;
|
||||
union {
|
||||
Command* command;
|
||||
Tool* tool;
|
||||
};
|
||||
std::string argument;
|
||||
|
||||
Shortcut(ShortcutType type);
|
||||
~Shortcut();
|
||||
|
||||
void add_shortcut(const char* shortcut_string);
|
||||
bool is_key_pressed(JMessage msg);
|
||||
|
||||
};
|
||||
|
||||
static Shortcut* get_keyboard_shortcut_for_command(Command* command, const char* argument);
|
||||
static Shortcut* get_keyboard_shortcut_for_tool(Tool* tool);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Monitor
|
||||
{
|
||||
/* returns true when the job is done and the monitor can be removed */
|
||||
// returns true when the job is done and the monitor can be removed
|
||||
void (*proc)(void *);
|
||||
void (*free)(void *);
|
||||
void *data;
|
||||
bool lock : 1;
|
||||
bool deleted : 1;
|
||||
bool lock;
|
||||
bool deleted;
|
||||
|
||||
Monitor(void (*proc)(void *),
|
||||
void (*free)(void *), void *data);
|
||||
~Monitor();
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
static JWidget manager = NULL;
|
||||
|
||||
static int monitor_timer = -1;
|
||||
static JList monitors;
|
||||
static std::list<Monitor*> monitors;
|
||||
static std::vector<Shortcut*> shortcuts;
|
||||
|
||||
static bool ji_screen_created = FALSE;
|
||||
|
||||
@ -104,10 +140,6 @@ static JList icon_buttons;
|
||||
static bool double_buffering;
|
||||
static int screen_scaling;
|
||||
|
||||
static Monitor *monitor_new(void (*proc)(void *),
|
||||
void (*free)(void *), void *data);
|
||||
static void monitor_free(Monitor *monitor);
|
||||
|
||||
/* load & save graphics configuration */
|
||||
static void load_gui_config(int *w, int *h, int *bpp, bool *fullscreen);
|
||||
static void save_gui_config();
|
||||
@ -238,8 +270,6 @@ int init_module_gui()
|
||||
}
|
||||
gfx_done:;
|
||||
|
||||
monitors = jlist_new();
|
||||
|
||||
/* window title */
|
||||
set_window_title("Allegro Sprite Editor v" VERSION);
|
||||
|
||||
@ -282,14 +312,21 @@ int init_module_gui()
|
||||
|
||||
void exit_module_gui()
|
||||
{
|
||||
JLink link;
|
||||
|
||||
/* destroy monitors */
|
||||
JI_LIST_FOR_EACH(monitors, link) {
|
||||
monitor_free(reinterpret_cast<Monitor*>(link->data));
|
||||
// destroy shortcuts
|
||||
for (std::vector<Shortcut*>::iterator
|
||||
it = shortcuts.begin(); it != shortcuts.end(); ++it) {
|
||||
Shortcut* shortcut = *it;
|
||||
delete shortcut;
|
||||
}
|
||||
jlist_free(monitors);
|
||||
monitors = NULL;
|
||||
shortcuts.clear();
|
||||
|
||||
// destroy monitors
|
||||
for (std::list<Monitor*>::iterator
|
||||
it2 = monitors.begin(); it2 != monitors.end(); ++it2) {
|
||||
Monitor* monitor = *it2;
|
||||
delete monitor;
|
||||
}
|
||||
monitors.clear();
|
||||
|
||||
if (double_buffering) {
|
||||
BITMAP *old_bmp = ji_screen;
|
||||
@ -315,28 +352,20 @@ int guiscale()
|
||||
return (JI_SCREEN_W > 512 ? 2: 1);
|
||||
}
|
||||
|
||||
static Monitor *monitor_new(void (*proc)(void *),
|
||||
void (*free)(void *), void *data)
|
||||
Monitor::Monitor(void (*proc)(void *),
|
||||
void (*free)(void *), void *data)
|
||||
{
|
||||
Monitor *monitor = jnew(Monitor, 1);
|
||||
if (!monitor)
|
||||
return NULL;
|
||||
|
||||
monitor->proc = proc;
|
||||
monitor->free = free;
|
||||
monitor->data = data;
|
||||
monitor->lock = FALSE;
|
||||
monitor->deleted = FALSE;
|
||||
|
||||
return monitor;
|
||||
this->proc = proc;
|
||||
this->free = free;
|
||||
this->data = data;
|
||||
this->lock = false;
|
||||
this->deleted = false;
|
||||
}
|
||||
|
||||
static void monitor_free(Monitor *monitor)
|
||||
Monitor::~Monitor()
|
||||
{
|
||||
if (monitor->free)
|
||||
(*monitor->free)(monitor->data);
|
||||
|
||||
jfree(monitor);
|
||||
if (this->free)
|
||||
(*this->free)(this->data);
|
||||
}
|
||||
|
||||
static void load_gui_config(int *w, int *h, int *bpp, bool *fullscreen)
|
||||
@ -741,17 +770,148 @@ JWidget check_button_new(const char *text, int b1, int b2, int b3, int b4)
|
||||
return widget;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Keyboard shortcuts
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
JAccel add_keyboard_shortcut_to_execute_command(const char* shortcut_string, Command* command, const char* argument)
|
||||
{
|
||||
Shortcut* shortcut = get_keyboard_shortcut_for_command(command, argument);
|
||||
|
||||
if (!shortcut) {
|
||||
shortcut = new Shortcut(Shortcut_ExecuteCommand);
|
||||
shortcut->command = command;
|
||||
shortcut->argument = argument ? argument: "";
|
||||
|
||||
shortcuts.push_back(shortcut);
|
||||
}
|
||||
|
||||
shortcut->add_shortcut(shortcut_string);
|
||||
return shortcut->accel;
|
||||
}
|
||||
|
||||
JAccel add_keyboard_shortcut_to_change_tool(const char* shortcut_string, Tool* tool)
|
||||
{
|
||||
Shortcut* shortcut = get_keyboard_shortcut_for_tool(tool);
|
||||
|
||||
if (!shortcut) {
|
||||
shortcut = new Shortcut(Shortcut_ChangeTool);
|
||||
shortcut->tool = tool;
|
||||
|
||||
shortcuts.push_back(shortcut);
|
||||
}
|
||||
|
||||
shortcut->add_shortcut(shortcut_string);
|
||||
return shortcut->accel;
|
||||
}
|
||||
|
||||
Command* get_command_from_key_message(JMessage msg)
|
||||
{
|
||||
for (std::vector<Shortcut*>::iterator
|
||||
it = shortcuts.begin(); it != shortcuts.end(); ++it) {
|
||||
Shortcut* shortcut = *it;
|
||||
|
||||
if (shortcut->type == Shortcut_ExecuteCommand &&
|
||||
shortcut->argument.empty() &&
|
||||
shortcut->is_key_pressed(msg)) {
|
||||
return shortcut->command;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JAccel get_accel_to_execute_command(Command* command, const char* argument)
|
||||
{
|
||||
Shortcut* shortcut = get_keyboard_shortcut_for_command(command, argument);
|
||||
if (shortcut)
|
||||
return shortcut->accel;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JAccel get_accel_to_change_tool(Tool* tool)
|
||||
{
|
||||
Shortcut* shortcut = get_keyboard_shortcut_for_tool(tool);
|
||||
if (shortcut)
|
||||
return shortcut->accel;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Shortcut::Shortcut(ShortcutType type)
|
||||
{
|
||||
this->type = type;
|
||||
this->accel = jaccel_new();
|
||||
}
|
||||
|
||||
Shortcut::~Shortcut()
|
||||
{
|
||||
jaccel_free(accel);
|
||||
}
|
||||
|
||||
void Shortcut::add_shortcut(const char* shortcut_string)
|
||||
{
|
||||
char buf[256];
|
||||
usprintf(buf, "<%s>", shortcut_string);
|
||||
jaccel_add_keys_from_string(this->accel, buf);
|
||||
}
|
||||
|
||||
bool Shortcut::is_key_pressed(JMessage msg)
|
||||
{
|
||||
if (accel) {
|
||||
return jaccel_check(accel,
|
||||
msg->any.shifts,
|
||||
msg->key.ascii,
|
||||
msg->key.scancode);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static Shortcut* get_keyboard_shortcut_for_command(Command* command, const char* argument)
|
||||
{
|
||||
if (!argument)
|
||||
argument = "";
|
||||
|
||||
for (std::vector<Shortcut*>::iterator
|
||||
it = shortcuts.begin(); it != shortcuts.end(); ++it) {
|
||||
Shortcut* shortcut = *it;
|
||||
|
||||
if (shortcut->type == Shortcut_ExecuteCommand &&
|
||||
shortcut->command == command &&
|
||||
shortcut->argument == argument) {
|
||||
return shortcut;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static Shortcut* get_keyboard_shortcut_for_tool(Tool* tool)
|
||||
{
|
||||
for (std::vector<Shortcut*>::iterator
|
||||
it = shortcuts.begin(); it != shortcuts.end(); ++it) {
|
||||
Shortcut* shortcut = *it;
|
||||
|
||||
if (shortcut->type == Shortcut_ChangeTool &&
|
||||
shortcut->tool == tool) {
|
||||
return shortcut;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a routine to be called each 100 milliseconds to monitor
|
||||
* whatever you want. It's mainly used to monitor the progress of a
|
||||
* file-operation (see @ref fop_operate)
|
||||
*/
|
||||
Monitor *add_gui_monitor(void (*proc)(void *),
|
||||
Monitor* add_gui_monitor(void (*proc)(void *),
|
||||
void (*free)(void *), void *data)
|
||||
{
|
||||
Monitor *monitor = monitor_new(proc, free, data);
|
||||
Monitor* monitor = new Monitor(proc, free, data);
|
||||
|
||||
jlist_append(monitors, monitor);
|
||||
monitors.push_back(monitor);
|
||||
|
||||
if (monitor_timer < 0)
|
||||
monitor_timer = jmanager_add_timer(manager, MONITOR_TIMER_MSECS);
|
||||
@ -766,16 +926,18 @@ Monitor *add_gui_monitor(void (*proc)(void *),
|
||||
*/
|
||||
void remove_gui_monitor(Monitor* monitor)
|
||||
{
|
||||
JLink link = jlist_find(monitors, monitor);
|
||||
assert(link != NULL);
|
||||
std::list<Monitor*>::iterator it =
|
||||
std::find(monitors.begin(), monitors.end(), monitor);
|
||||
|
||||
assert(it != monitors.end());
|
||||
|
||||
if (!monitor->lock)
|
||||
monitor_free(monitor);
|
||||
delete monitor;
|
||||
else
|
||||
monitor->deleted = TRUE;
|
||||
monitor->deleted = true;
|
||||
|
||||
jlist_delete_link(monitors, link);
|
||||
if (jlist_empty(monitors))
|
||||
monitors.erase(it);
|
||||
if (monitors.empty())
|
||||
jmanager_stop_timer(monitor_timer);
|
||||
}
|
||||
|
||||
@ -795,77 +957,108 @@ static bool manager_msg_proc(JWidget widget, JMessage msg)
|
||||
|
||||
case JM_TIMER:
|
||||
if (msg->timer.timer_id == monitor_timer) {
|
||||
JLink link, next;
|
||||
JI_LIST_FOR_EACH_SAFE(monitors, link, next) {
|
||||
Monitor* monitor = reinterpret_cast<Monitor*>(link->data);
|
||||
for (std::list<Monitor*>::iterator
|
||||
it = monitors.begin(), next; it != monitors.end(); it = next) {
|
||||
Monitor* monitor = *it;
|
||||
next = it;
|
||||
++next;
|
||||
|
||||
/* is the monitor not lock? */
|
||||
// is the monitor not lock?
|
||||
if (!monitor->lock) {
|
||||
/* call the monitor procedure */
|
||||
monitor->lock = TRUE;
|
||||
// call the monitor procedure
|
||||
monitor->lock = true;
|
||||
(*monitor->proc)(monitor->data);
|
||||
monitor->lock = FALSE;
|
||||
monitor->lock = false;
|
||||
|
||||
if (monitor->deleted)
|
||||
monitor_free(monitor);
|
||||
delete monitor;
|
||||
}
|
||||
}
|
||||
|
||||
/* is monitors empty? we can stop the timer so */
|
||||
if (jlist_empty(monitors))
|
||||
// is monitors empty? we can stop the timer so
|
||||
if (monitors.empty())
|
||||
jmanager_stop_timer(monitor_timer);
|
||||
}
|
||||
break;
|
||||
|
||||
case JM_KEYPRESSED: {
|
||||
/* check for commands */
|
||||
Command *command = command_get_by_key(msg);
|
||||
if (!command) {
|
||||
/* check for tools */
|
||||
Tool *tool = get_tool_by_key(msg);
|
||||
if (tool != NULL)
|
||||
select_tool(tool);
|
||||
break;
|
||||
}
|
||||
case JM_KEYPRESSED:
|
||||
for (std::vector<Shortcut*>::iterator
|
||||
it = shortcuts.begin(); it != shortcuts.end(); ++it) {
|
||||
Shortcut* shortcut = *it;
|
||||
|
||||
/* the screen shot is available in everywhere */
|
||||
if (strcmp(command->name, CMD_SCREEN_SHOT) == 0) {
|
||||
if (command_is_enabled(command, NULL)) {
|
||||
command_execute(command, NULL);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
/* all other keys are only available in the main-window */
|
||||
else {
|
||||
JWidget child;
|
||||
JLink link;
|
||||
if (shortcut->is_key_pressed(msg)) {
|
||||
switch (shortcut->type) {
|
||||
|
||||
JI_LIST_FOR_EACH(widget->children, link) {
|
||||
child = reinterpret_cast<JWidget>(link->data);
|
||||
case Shortcut_ChangeTool: {
|
||||
Tool* select_this_tool = shortcut->tool;
|
||||
Tool* group[MAX_TOOLS];
|
||||
int i, j;
|
||||
|
||||
/* there are a foreground window executing? */
|
||||
if (jwindow_is_foreground(child)) {
|
||||
break;
|
||||
}
|
||||
/* is it the desktop and the top-window= */
|
||||
else if (jwindow_is_desktop(child) && child == app_get_top_window()) {
|
||||
/* ok, so we can execute the command represented by the
|
||||
pressed-key in the message... */
|
||||
if (command_is_enabled(command, NULL)) {
|
||||
// if a menu is open, close everything
|
||||
command_execute(command, NULL);
|
||||
return TRUE;
|
||||
for (i=j=0; i<MAX_TOOLS; i++) {
|
||||
if (get_keyboard_shortcut_for_tool(tools_list[i])->is_key_pressed(msg))
|
||||
group[j++] = tools_list[i];
|
||||
}
|
||||
|
||||
if (j >= 2) {
|
||||
for (i=0; i<j; i++) {
|
||||
if (group[i] == current_tool && i+1 < j) {
|
||||
select_this_tool = group[i+1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
select_tool(select_this_tool);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case Shortcut_ExecuteCommand: {
|
||||
Command* command = shortcut->command;
|
||||
|
||||
// the screen shot is available in everywhere
|
||||
if (strcmp(command->name, CMD_SCREEN_SHOT) == 0) {
|
||||
if (command_is_enabled(command, NULL)) {
|
||||
command_execute(command, shortcut->argument.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// all other keys are only available in the main-window
|
||||
else {
|
||||
JWidget child;
|
||||
JLink link;
|
||||
|
||||
JI_LIST_FOR_EACH(widget->children, link) {
|
||||
child = reinterpret_cast<JWidget>(link->data);
|
||||
|
||||
/* there are a foreground window executing? */
|
||||
if (jwindow_is_foreground(child)) {
|
||||
break;
|
||||
}
|
||||
/* is it the desktop and the top-window= */
|
||||
else if (jwindow_is_desktop(child) && child == app_get_top_window()) {
|
||||
/* ok, so we can execute the command represented by the
|
||||
pressed-key in the message... */
|
||||
if (command_is_enabled(command, shortcut->argument.c_str())) {
|
||||
// if a menu is open, close everything
|
||||
command_execute(command, shortcut->argument.c_str());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
@ -23,8 +23,12 @@
|
||||
#include <string>
|
||||
#include "ase_exception.h"
|
||||
#include "jinete/jbase.h"
|
||||
#include "jinete/jaccel.h"
|
||||
#include "jinete/jwidget.h"
|
||||
|
||||
struct Command;
|
||||
struct Tool;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
class widget_file_not_found : public ase_exception
|
||||
@ -92,8 +96,18 @@ JWidget radio_button_new(int radio_group, int b1, int b2, int b3, int b4);
|
||||
JWidget check_button_new(const char *text, int b1, int b2, int b3, int b4);
|
||||
/* void change_to_button_style(JWidget widget, int b1, int b2, int b3, int b4); */
|
||||
|
||||
/********************************************************************/
|
||||
/* monitors */
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Keyboard shortcuts
|
||||
|
||||
JAccel add_keyboard_shortcut_to_execute_command(const char* shortcut, Command* command, const char* argument);
|
||||
JAccel add_keyboard_shortcut_to_change_tool(const char* shortcut, Tool* tool);
|
||||
|
||||
Command* get_command_from_key_message(JMessage msg);
|
||||
JAccel get_accel_to_execute_command(Command* command, const char* argument);
|
||||
JAccel get_accel_to_change_tool(Tool* tool);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Monitors
|
||||
|
||||
Monitor* add_gui_monitor(void (*proc)(void*),
|
||||
void (*free)(void*), void* data);
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <allegro/unicode.h>
|
||||
|
||||
#include "jinete/jinete.h"
|
||||
|
||||
@ -31,6 +32,7 @@
|
||||
#include "intl/intl.h"
|
||||
#include "modules/rootmenu.h"
|
||||
#include "modules/tools.h"
|
||||
#include "modules/gui.h"
|
||||
#include "util/filetoks.h"
|
||||
#include "widgets/menuitem.h"
|
||||
|
||||
@ -47,7 +49,7 @@ static int load_root_menu();
|
||||
static JWidget load_menu_by_id(JXml xml, const char *id, const char *filename);
|
||||
static JWidget convert_xmlelem_to_menu(JXmlElem elem);
|
||||
static JWidget convert_xmlelem_to_menuitem(JXmlElem elem);
|
||||
static void apply_shortcut_to_menuitems_with_command(JWidget menu, Command *command);
|
||||
static void apply_shortcut_to_menuitems_with_command(JWidget menu, Command* command, const char* argument, JAccel accel);
|
||||
|
||||
int init_module_rootmenu()
|
||||
{
|
||||
@ -64,7 +66,6 @@ int init_module_rootmenu()
|
||||
|
||||
void exit_module_rootmenu()
|
||||
{
|
||||
command_reset_keys();
|
||||
jwidget_free(root_menu);
|
||||
|
||||
if (layer_popup_menu) jwidget_free(layer_popup_menu);
|
||||
@ -103,10 +104,8 @@ static int load_root_menu()
|
||||
jmenubar_set_menu(app_get_menubar(), NULL);
|
||||
|
||||
/* destroy `root-menu' if it exists */
|
||||
if (root_menu) {
|
||||
command_reset_keys();
|
||||
if (root_menu)
|
||||
jwidget_free(root_menu);
|
||||
}
|
||||
|
||||
/* create a new empty-menu */
|
||||
root_menu = NULL;
|
||||
@ -171,21 +170,29 @@ static int load_root_menu()
|
||||
/* finally, we can read the <key /> */
|
||||
const char *command_name = jxmlelem_get_attr((JXmlElem)child2, "command");
|
||||
const char *command_key = jxmlelem_get_attr((JXmlElem)child2, "shortcut");
|
||||
const char *argument = jxmlelem_get_attr((JXmlElem)child2, "argument");
|
||||
|
||||
if (command_name && command_key) {
|
||||
Command *command = command_get_by_name(command_name);
|
||||
if (command) {
|
||||
bool first_shortcut = !command->accel;
|
||||
if (!argument)
|
||||
argument = "";
|
||||
|
||||
/* add the keyboard shortcut to the command */
|
||||
PRINTF("- Shortcut for command `%s': <%s>\n", command_name, command_key);
|
||||
command_add_key(command, command_key);
|
||||
bool first_shortcut =
|
||||
(get_accel_to_execute_command(command, argument) == NULL);
|
||||
|
||||
/* add the shortcut to the menuitems with this
|
||||
command (this is only visual, the
|
||||
"manager_msg_proc" is the only one that process
|
||||
keyboard shortcuts) */
|
||||
PRINTF("- Shortcut for command `%s' with argument `%s': <%s>\n",
|
||||
command_name, argument, command_key);
|
||||
|
||||
// add the keyboard shortcut to the command
|
||||
JAccel accel =
|
||||
add_keyboard_shortcut_to_execute_command(command_key, command, argument);
|
||||
|
||||
// add the shortcut to the menuitems with this
|
||||
// command (this is only visual, the "manager_msg_proc"
|
||||
// is the only one that process keyboard shortcuts)
|
||||
if (first_shortcut)
|
||||
apply_shortcut_to_menuitems_with_command(root_menu, command);
|
||||
apply_shortcut_to_menuitems_with_command(root_menu, command, argument, accel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -220,7 +227,7 @@ static int load_root_menu()
|
||||
if (tool) {
|
||||
/* add the keyboard shortcut to the tool */
|
||||
PRINTF("- Shortcut for tool `%s': <%s>\n", tool_name, tool_key);
|
||||
tool_add_key(tool, tool_key);
|
||||
add_keyboard_shortcut_to_change_tool(tool_key, tool);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -348,7 +355,7 @@ static JWidget convert_xmlelem_to_menuitem(JXmlElem elem)
|
||||
return menuitem;
|
||||
}
|
||||
|
||||
static void apply_shortcut_to_menuitems_with_command(JWidget menu, Command *command)
|
||||
static void apply_shortcut_to_menuitems_with_command(JWidget menu, Command *command, const char* argument, JAccel accel)
|
||||
{
|
||||
JList children = jwidget_get_children(menu);
|
||||
JWidget menuitem, submenu;
|
||||
@ -358,14 +365,13 @@ static void apply_shortcut_to_menuitems_with_command(JWidget menu, Command *comm
|
||||
menuitem = (JWidget)link->data;
|
||||
|
||||
if (jwidget_get_type(menuitem) == JI_MENUITEM) {
|
||||
if (menuitem_get_command(menuitem) == command) {
|
||||
jmenuitem_set_accel(menuitem, jaccel_new_copy(command->accel));
|
||||
}
|
||||
if (menuitem_get_command(menuitem) == command &&
|
||||
ustrcmp(menuitem_get_argument(menuitem), argument) == 0)
|
||||
jmenuitem_set_accel(menuitem, jaccel_new_copy(accel));
|
||||
|
||||
submenu = jmenuitem_get_submenu(menuitem);
|
||||
if (submenu) {
|
||||
apply_shortcut_to_menuitems_with_command(submenu, command);
|
||||
}
|
||||
if (submenu)
|
||||
apply_shortcut_to_menuitems_with_command(submenu, command, argument, accel);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include <limits.h>
|
||||
#include <cmath>
|
||||
|
||||
#include "jinete/jaccel.h"
|
||||
#include "jinete/jalert.h"
|
||||
#include "jinete/jlist.h"
|
||||
#include "jinete/jmanager.h"
|
||||
@ -201,8 +200,6 @@ int init_module_tools()
|
||||
|
||||
void exit_module_tools()
|
||||
{
|
||||
int c;
|
||||
|
||||
set_config_color("Tools", "CursorColor", cursor_color);
|
||||
set_config_int("Tools", "GlassDirty", glass_dirty);
|
||||
set_config_int("Tools", "SprayWidth", spray_width);
|
||||
@ -220,35 +217,6 @@ void exit_module_tools()
|
||||
|
||||
jrect_free(grid);
|
||||
brush_free(brush);
|
||||
|
||||
for (c=0; c<MAX_TOOLS; c++) {
|
||||
if (tools_list[c]->accel) {
|
||||
jaccel_free(tools_list[c]->accel);
|
||||
tools_list[c]->accel = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tool_add_key(Tool *tool, const char *string)
|
||||
{
|
||||
char buf[256];
|
||||
|
||||
if (!tool->accel)
|
||||
tool->accel = jaccel_new();
|
||||
|
||||
usprintf(buf, "<%s>", string);
|
||||
jaccel_add_keys_from_string(tool->accel, buf);
|
||||
}
|
||||
|
||||
bool tool_is_key_pressed(Tool *tool, JMessage msg)
|
||||
{
|
||||
if (tool->accel) {
|
||||
return jaccel_check(tool->accel,
|
||||
msg->any.shifts,
|
||||
msg->key.ascii,
|
||||
msg->key.scancode);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Tool *get_tool_by_name(const char *name)
|
||||
@ -262,27 +230,6 @@ Tool *get_tool_by_name(const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Tool *get_tool_by_key(JMessage msg)
|
||||
{
|
||||
Tool *group[MAX_TOOLS];
|
||||
int i, j;
|
||||
|
||||
for (i=j=0; i<MAX_TOOLS; i++) {
|
||||
if (tool_is_key_pressed(tools_list[i], msg))
|
||||
group[j++] = tools_list[i];
|
||||
}
|
||||
|
||||
if (j == 0)
|
||||
return NULL;
|
||||
|
||||
for (i=0; i<j; i++)
|
||||
if (group[i] == current_tool)
|
||||
if (i+1 < j)
|
||||
return group[i+1];
|
||||
|
||||
return group[0];
|
||||
}
|
||||
|
||||
void select_tool(Tool *tool)
|
||||
{
|
||||
assert(tool != NULL);
|
||||
@ -495,7 +442,8 @@ static Tool tool_marker =
|
||||
"Rectangular Marquee Tool",
|
||||
"Rectangular Marquee Tool",
|
||||
TOOL_FIRST2LAST | TOOL_UPDATE_BOX,
|
||||
NULL
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
/***********************************************************/
|
||||
@ -518,7 +466,6 @@ static Tool tool_pencil =
|
||||
TOOL_OLD2LAST | TOOL_UPDATE_TRACE,
|
||||
NULL,
|
||||
tool_pencil_draw_trace,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***********************************************************/
|
||||
@ -532,7 +479,7 @@ static Tool tool_brush =
|
||||
"Brush Tool",
|
||||
TOOL_4OLD2LAST | TOOL_UPDATE_4PTS,
|
||||
NULL,
|
||||
NULL
|
||||
NULL,
|
||||
};
|
||||
|
||||
/***********************************************************/
|
||||
@ -574,7 +521,6 @@ static Tool tool_eraser =
|
||||
TOOL_OLD2LAST | TOOL_UPDATE_TRACE,
|
||||
tool_eraser_preprocess_data,
|
||||
tool_eraser_draw_trace,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***********************************************************/
|
||||
@ -597,7 +543,6 @@ static Tool tool_floodfill =
|
||||
TOOL_OLD2LAST | TOOL_UPDATE_ALL,
|
||||
NULL,
|
||||
tool_floodfill_draw_trace,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***********************************************************/
|
||||
@ -640,7 +585,6 @@ static Tool tool_spray =
|
||||
TOOL_COPY_DST2SRC | TOOL_OLD2LAST | TOOL_UPDATE_SPRAY,
|
||||
NULL,
|
||||
tool_spray_draw_trace,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***********************************************************/
|
||||
@ -663,7 +607,6 @@ static Tool tool_line =
|
||||
TOOL_COPY_SRC2DST | TOOL_FIRST2LAST | TOOL_UPDATE_BOX | TOOL_SNAP_ANGLES,
|
||||
NULL,
|
||||
tool_line_draw_trace,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***********************************************************/
|
||||
@ -686,7 +629,6 @@ static Tool tool_curve =
|
||||
TOOL_COPY_SRC2DST | TOOL_4FIRST2LAST | TOOL_UPDATE_4PTS | TOOL_SNAP_ANGLES,
|
||||
NULL,
|
||||
tool_curve_draw_trace,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***********************************************************/
|
||||
@ -730,7 +672,6 @@ static Tool tool_rectangle =
|
||||
TOOL_COPY_SRC2DST | TOOL_FIRST2LAST | TOOL_UPDATE_BOX | TOOL_ACCEPT_FILL,
|
||||
NULL,
|
||||
tool_rectangle_draw_trace,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***********************************************************/
|
||||
@ -756,7 +697,6 @@ static Tool tool_ellipse =
|
||||
TOOL_COPY_SRC2DST | TOOL_FIRST2LAST | TOOL_UPDATE_BOX | TOOL_ACCEPT_FILL,
|
||||
NULL,
|
||||
tool_ellipse_draw_trace,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***********************************************************/
|
||||
@ -785,7 +725,6 @@ static Tool tool_blur =
|
||||
TOOL_COPY_DST2SRC | TOOL_OLD2LAST | TOOL_UPDATE_TRACE,
|
||||
tool_blur_preprocess_data,
|
||||
tool_blur_draw_trace,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***********************************************************/
|
||||
@ -814,7 +753,6 @@ static Tool tool_jumble =
|
||||
TOOL_COPY_DST2SRC | TOOL_OLD2LAST | TOOL_UPDATE_TRACE,
|
||||
tool_jumble_preprocess_data,
|
||||
tool_jumble_draw_trace,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***********************************************************/
|
||||
|
@ -65,7 +65,6 @@ struct Tool
|
||||
int flags;
|
||||
void (*preprocess_data)(ToolData *data);
|
||||
void (*draw_trace)(int x1, int y1, int x2, int y2, ToolData *data);
|
||||
JAccel accel;
|
||||
};
|
||||
|
||||
struct ToolData
|
||||
@ -95,11 +94,7 @@ extern Tool *tools_list[MAX_TOOLS];
|
||||
int init_module_tools();
|
||||
void exit_module_tools();
|
||||
|
||||
void tool_add_key(Tool *tool, const char *string);
|
||||
bool tool_is_key_pressed(Tool *tool, JMessage msg);
|
||||
|
||||
Tool *get_tool_by_name(const char *name);
|
||||
Tool *get_tool_by_key(JMessage msg);
|
||||
|
||||
void select_tool(Tool *tool);
|
||||
|
||||
|
@ -140,7 +140,7 @@ static void chunk_data_invert(UndoStream* stream, UndoChunkData *chunk, int stat
|
||||
static void chunk_image_new(UndoStream* stream, Image* image, int x, int y, int w, int h);
|
||||
static void chunk_image_invert(UndoStream* stream, UndoChunkImage* chunk, int state);
|
||||
|
||||
static void chunk_flip_new(UndoStream* stream, Image* image, int x1, int y1, int x2, int y2, int horz);
|
||||
static void chunk_flip_new(UndoStream* stream, Image* image, int x1, int y1, int x2, int y2, bool horz);
|
||||
static void chunk_flip_invert(UndoStream* stream, UndoChunkFlip *chunk, int state);
|
||||
|
||||
static void chunk_dirty_new(UndoStream* stream, Dirty *dirty);
|
||||
@ -739,13 +739,13 @@ struct UndoChunkFlip
|
||||
ase_uint8 horz;
|
||||
};
|
||||
|
||||
void undo_flip(Undo* undo, Image* image, int x1, int y1, int x2, int y2, int horz)
|
||||
void undo_flip(Undo* undo, Image* image, int x1, int y1, int x2, int y2, bool horz)
|
||||
{
|
||||
chunk_flip_new(undo->undo_stream, image, x1, y1, x2, y2, horz);
|
||||
update_undo(undo);
|
||||
}
|
||||
|
||||
static void chunk_flip_new(UndoStream* stream, Image* image, int x1, int y1, int x2, int y2, int horz)
|
||||
static void chunk_flip_new(UndoStream* stream, Image* image, int x1, int y1, int x2, int y2, bool horz)
|
||||
{
|
||||
UndoChunkFlip *chunk = (UndoChunkFlip *)
|
||||
undo_chunk_new(stream,
|
||||
@ -761,32 +761,31 @@ static void chunk_flip_new(UndoStream* stream, Image* image, int x1, int y1, int
|
||||
chunk->horz = horz;
|
||||
}
|
||||
|
||||
static void chunk_flip_invert(UndoStream* stream, UndoChunkFlip *chunk, int state)
|
||||
static void chunk_flip_invert(UndoStream* stream, UndoChunkFlip* chunk, int state)
|
||||
{
|
||||
Image* image = (Image* )gfxobj_find(chunk->image_id);
|
||||
Image* image = (Image*)gfxobj_find(chunk->image_id);
|
||||
|
||||
if ((image) &&
|
||||
(image->type == GFXOBJ_IMAGE) &&
|
||||
(image->imgtype == chunk->imgtype)) {
|
||||
int x1, y1, x2, y2;
|
||||
int x, y, horz;
|
||||
Image* area;
|
||||
|
||||
x1 = chunk->x1;
|
||||
y1 = chunk->y1;
|
||||
x2 = chunk->x2;
|
||||
y2 = chunk->y2;
|
||||
horz = chunk->horz;
|
||||
int x1 = chunk->x1;
|
||||
int y1 = chunk->y1;
|
||||
int x2 = chunk->x2;
|
||||
int y2 = chunk->y2;
|
||||
bool horz = chunk->horz;
|
||||
|
||||
chunk_flip_new(stream, image, x1, y1, x2, y2, horz);
|
||||
|
||||
area = image_crop(image, x1, y1, x2-x1+1, y2-y1+1, 0);
|
||||
Image* area = image_crop(image, x1, y1, x2-x1+1, y2-y1+1, 0);
|
||||
int x, y;
|
||||
|
||||
for (y=0; y<(y2-y1+1); y++)
|
||||
for (x=0; x<(x2-x1+1); x++)
|
||||
image_putpixel(image,
|
||||
horz ? x2-x: x1+x,
|
||||
!horz? y2-y: y1+y,
|
||||
image_getpixel(area, x, y));
|
||||
|
||||
image_free(area);
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ void undo_open(Undo* undo);
|
||||
void undo_close(Undo* undo);
|
||||
void undo_data(Undo* undo, GfxObj *gfxobj, void *data, int size);
|
||||
void undo_image(Undo* undo, Image *image, int x, int y, int w, int h);
|
||||
void undo_flip(Undo* undo, Image *image, int x1, int y1, int x2, int y2, int horz);
|
||||
void undo_flip(Undo* undo, Image *image, int x1, int y1, int x2, int y2, bool horz);
|
||||
void undo_dirty(Undo* undo, Dirty *dirty);
|
||||
void undo_add_image(Undo* undo, Stock *stock, int image_index);
|
||||
void undo_remove_image(Undo* undo, Stock *stock, int image_index);
|
||||
|
@ -978,6 +978,32 @@ void Undoable::clear_mask(int bgcolor)
|
||||
}
|
||||
}
|
||||
|
||||
void Undoable::flip_image(Image* image, int x1, int y1, int x2, int y2,
|
||||
bool flip_horizontal, bool flip_vertical)
|
||||
{
|
||||
// insert the undo operation
|
||||
if (is_enabled()) {
|
||||
if (flip_horizontal)
|
||||
undo_flip(m_sprite->undo, image, x1, y1, x2, y2, true);
|
||||
|
||||
if (flip_vertical)
|
||||
undo_flip(m_sprite->undo, image, x1, y1, x2, y2, false);
|
||||
}
|
||||
|
||||
// flip the portion of the bitmap
|
||||
Image* area = image_crop(image, x1, y1, x2-x1+1, y2-y1+1, 0);
|
||||
int x, y;
|
||||
|
||||
for (y=0; y<(y2-y1+1); y++)
|
||||
for (x=0; x<(x2-x1+1); x++)
|
||||
image_putpixel(image,
|
||||
flip_horizontal ? x2-x: x1+x,
|
||||
flip_vertical ? y2-y: y1+y,
|
||||
image_getpixel(area, x, y));
|
||||
|
||||
image_free(area);
|
||||
}
|
||||
|
||||
void Undoable::copy_to_current_mask(Mask* mask)
|
||||
{
|
||||
assert(m_sprite->mask);
|
||||
|
@ -94,6 +94,8 @@ public:
|
||||
// for image
|
||||
Image* get_cel_image(Cel* cel);
|
||||
void clear_mask(int bgcolor);
|
||||
void flip_image(Image* image, int x1, int y1, int x2, int y2,
|
||||
bool flip_horizontal, bool flip_vertical);
|
||||
|
||||
// for mask
|
||||
void copy_to_current_mask(Mask* mask);
|
||||
|
@ -581,9 +581,10 @@ static void colorbar_open_tooltip(JWidget widget, int x1, int x2, int y1, int y2
|
||||
cmd = command_get_by_name(CMD_SWITCH_COLORS);
|
||||
assert(cmd != NULL);
|
||||
|
||||
if (cmd->accel != NULL) {
|
||||
JAccel accel = get_accel_to_execute_command(cmd, NULL);
|
||||
if (accel != NULL) {
|
||||
ustrcat(buf, _(" - "));
|
||||
jaccel_to_string(cmd->accel, buf+ustrsize(buf));
|
||||
jaccel_to_string(accel, buf+ustrsize(buf));
|
||||
ustrcat(buf, _(" key switches colors"));
|
||||
}
|
||||
break;
|
||||
|
@ -49,15 +49,15 @@ static bool menuitem_msg_proc(JWidget widget, JMessage msg);
|
||||
*
|
||||
* @see jmenuitem_new
|
||||
*/
|
||||
JWidget menuitem_new(const char *text,
|
||||
Command *command,
|
||||
const char *argument)
|
||||
JWidget menuitem_new(const char* text,
|
||||
Command* command,
|
||||
const char* argument)
|
||||
{
|
||||
JWidget widget = jmenuitem_new(text);
|
||||
MenuItem *menuitem = jnew0(MenuItem, 1);
|
||||
|
||||
menuitem->command = command;
|
||||
menuitem->argument = argument ? jstrdup(argument): NULL;
|
||||
menuitem->argument = jstrdup(argument ? argument: "");
|
||||
|
||||
jwidget_add_hook(widget,
|
||||
menuitem_type(),
|
||||
@ -67,12 +67,18 @@ JWidget menuitem_new(const char *text,
|
||||
return widget;
|
||||
}
|
||||
|
||||
Command *menuitem_get_command(JWidget widget)
|
||||
Command* menuitem_get_command(JWidget widget)
|
||||
{
|
||||
MenuItem* menuitem = reinterpret_cast<MenuItem*>(jwidget_get_data(widget, menuitem_type()));
|
||||
return menuitem->command;
|
||||
}
|
||||
|
||||
const char* menuitem_get_argument(JWidget widget)
|
||||
{
|
||||
MenuItem* menuitem = reinterpret_cast<MenuItem*>(jwidget_get_data(widget, menuitem_type()));
|
||||
return menuitem->argument;
|
||||
}
|
||||
|
||||
static int menuitem_type()
|
||||
{
|
||||
static int type = 0;
|
||||
@ -87,8 +93,7 @@ static bool menuitem_msg_proc(JWidget widget, JMessage msg)
|
||||
|
||||
case JM_DESTROY: {
|
||||
MenuItem* menuitem = reinterpret_cast<MenuItem*>(jwidget_get_data(widget, menuitem_type()));
|
||||
if (menuitem->argument)
|
||||
jfree(menuitem->argument);
|
||||
jfree(menuitem->argument);
|
||||
jfree(menuitem);
|
||||
break;
|
||||
}
|
||||
|
@ -23,10 +23,11 @@
|
||||
|
||||
struct Command;
|
||||
|
||||
JWidget menuitem_new(const char *text,
|
||||
struct Command *command,
|
||||
const char *argument);
|
||||
JWidget menuitem_new(const char* text,
|
||||
struct Command* command,
|
||||
const char* argument);
|
||||
|
||||
Command *menuitem_get_command(JWidget menuitem);
|
||||
Command* menuitem_get_command(JWidget menuitem);
|
||||
const char* menuitem_get_argument(JWidget menuitem);
|
||||
|
||||
#endif /* WIDGETS_MENUITEM_H */
|
||||
|
@ -73,9 +73,11 @@ JWidget toolbar_new()
|
||||
child = jwidget_find_name(tools, buf);
|
||||
|
||||
usprintf(buf, "%s", _(tools_list[c]->tips));
|
||||
if (tools_list[c]->accel) {
|
||||
|
||||
JAccel accel = get_accel_to_change_tool(tools_list[c]);
|
||||
if (accel) {
|
||||
ustrcat(buf, "\n(");
|
||||
jaccel_to_string(tools_list[c]->accel, buf+ustrsize(buf));
|
||||
jaccel_to_string(accel, buf+ustrsize(buf));
|
||||
ustrcat(buf, ")");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user