diff --git a/data/gui-en.xml b/data/gui-en.xml
index 6e9e6cb53..82c19b195 100644
--- a/data/gui-en.xml
+++ b/data/gui-en.xml
@@ -22,8 +22,8 @@
-
-
+
+
@@ -118,8 +118,8 @@
-
-
+
+
@@ -142,8 +142,8 @@
-
-
+
+
diff --git a/src/commands/cmd_about.cpp b/src/commands/cmd_about.cpp
index 728fd18cc..b1cd471ed 100644
--- a/src/commands/cmd_about.cpp
+++ b/src/commands/cmd_about.cpp
@@ -133,5 +133,4 @@ Command cmd_about = {
NULL,
NULL,
cmd_about_execute,
- NULL
};
diff --git a/src/commands/cmd_advanced_mode.cpp b/src/commands/cmd_advanced_mode.cpp
index e27dab391..9c2f4b110 100644
--- a/src/commands/cmd_advanced_mode.cpp
+++ b/src/commands/cmd_advanced_mode.cpp
@@ -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);
-
- set_config_bool("AdvancedMode", "Warning",
- !jwidget_is_selected(donot_show));
+ jwindow_open_fg(window);
+
+ 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
};
diff --git a/src/commands/cmd_background_from_layer.cpp b/src/commands/cmd_background_from_layer.cpp
index 7d2c657b3..bc7850385 100644
--- a/src/commands/cmd_background_from_layer.cpp
+++ b/src/commands/cmd_background_from_layer.cpp
@@ -61,5 +61,4 @@ Command cmd_background_from_layer = {
cmd_background_from_layer_enabled,
NULL,
cmd_background_from_layer_execute,
- NULL
};
diff --git a/src/commands/cmd_canvas_size.cpp b/src/commands/cmd_canvas_size.cpp
index e66700d04..4f87766db 100644
--- a/src/commands/cmd_canvas_size.cpp
+++ b/src/commands/cmd_canvas_size.cpp
@@ -86,5 +86,4 @@ Command cmd_canvas_size = {
cmd_canvas_size_enabled,
NULL,
cmd_canvas_size_execute,
- NULL
};
diff --git a/src/commands/cmd_cel_properties.cpp b/src/commands/cmd_cel_properties.cpp
index 2e99874ec..34141aee0 100644
--- a/src/commands/cmd_cel_properties.cpp
+++ b/src/commands/cmd_cel_properties.cpp
@@ -141,5 +141,4 @@ Command cmd_cel_properties = {
cmd_cel_properties_enabled,
NULL,
cmd_cel_properties_execute,
- NULL
};
diff --git a/src/commands/cmd_change_image_type.cpp b/src/commands/cmd_change_image_type.cpp
index a4a795d0d..a5567df1e 100644
--- a/src/commands/cmd_change_image_type.cpp
+++ b/src/commands/cmd_change_image_type.cpp
@@ -76,5 +76,4 @@ Command cmd_change_image_type = {
cmd_change_image_type_enabled,
NULL,
cmd_change_image_type_execute,
- NULL
};
diff --git a/src/commands/cmd_clear.cpp b/src/commands/cmd_clear.cpp
index 0327b17f8..73c9af1c4 100644
--- a/src/commands/cmd_clear.cpp
+++ b/src/commands/cmd_clear.cpp
@@ -55,5 +55,4 @@ Command cmd_clear = {
cmd_clear_enabled,
NULL,
cmd_clear_execute,
- NULL
};
diff --git a/src/commands/cmd_close_file.cpp b/src/commands/cmd_close_file.cpp
index e02a70d21..311d5bf1c 100644
--- a/src/commands/cmd_close_file.cpp
+++ b/src/commands/cmd_close_file.cpp
@@ -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
};
diff --git a/src/commands/cmd_configure_screen.cpp b/src/commands/cmd_configure_screen.cpp
index dac8e7268..b2401503a 100644
--- a/src/commands/cmd_configure_screen.cpp
+++ b/src/commands/cmd_configure_screen.cpp
@@ -253,5 +253,4 @@ Command cmd_configure_screen = {
NULL,
NULL,
cmd_configure_screen_execute,
- NULL
};
diff --git a/src/commands/cmd_configure_tools.cpp b/src/commands/cmd_configure_tools.cpp
index ec6ac4417..a24a7969b 100644
--- a/src/commands/cmd_configure_tools.cpp
+++ b/src/commands/cmd_configure_tools.cpp
@@ -371,5 +371,4 @@ Command cmd_configure_tools = {
NULL,
NULL,
cmd_configure_tools_execute,
- NULL
};
diff --git a/src/commands/cmd_copy.cpp b/src/commands/cmd_copy.cpp
index e90007486..66fbad37b 100644
--- a/src/commands/cmd_copy.cpp
+++ b/src/commands/cmd_copy.cpp
@@ -54,5 +54,4 @@ Command cmd_copy = {
cmd_copy_enabled,
NULL,
cmd_copy_execute,
- NULL
};
diff --git a/src/commands/cmd_copy_cel.cpp b/src/commands/cmd_copy_cel.cpp
index b4647d47e..8666259fe 100644
--- a/src/commands/cmd_copy_cel.cpp
+++ b/src/commands/cmd_copy_cel.cpp
@@ -40,5 +40,4 @@ Command cmd_copy_cel = {
cmd_copy_cel_enabled,
NULL,
cmd_copy_cel_execute,
- NULL
};
diff --git a/src/commands/cmd_crop.cpp b/src/commands/cmd_crop.cpp
index 13623f011..d9fb69c56 100644
--- a/src/commands/cmd_crop.cpp
+++ b/src/commands/cmd_crop.cpp
@@ -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
};
diff --git a/src/commands/cmd_cut.cpp b/src/commands/cmd_cut.cpp
index f3a304888..1efa43436 100644
--- a/src/commands/cmd_cut.cpp
+++ b/src/commands/cmd_cut.cpp
@@ -53,5 +53,4 @@ Command cmd_cut = {
cmd_cut_enabled,
NULL,
cmd_cut_execute,
- NULL
};
diff --git a/src/commands/cmd_deselect_mask.cpp b/src/commands/cmd_deselect_mask.cpp
index 17d76481f..da0fa7285 100644
--- a/src/commands/cmd_deselect_mask.cpp
+++ b/src/commands/cmd_deselect_mask.cpp
@@ -66,5 +66,4 @@ Command cmd_deselect_mask = {
cmd_deselect_mask_enabled,
NULL,
cmd_deselect_mask_execute,
- NULL
};
diff --git a/src/commands/cmd_drawing_tools.cpp b/src/commands/cmd_drawing_tools.cpp
index 0dff7d744..9c10591d6 100644
--- a/src/commands/cmd_drawing_tools.cpp
+++ b/src/commands/cmd_drawing_tools.cpp
@@ -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
};
diff --git a/src/commands/cmd_duplicate_layer.cpp b/src/commands/cmd_duplicate_layer.cpp
index 88f03a76f..c75add5c6 100644
--- a/src/commands/cmd_duplicate_layer.cpp
+++ b/src/commands/cmd_duplicate_layer.cpp
@@ -96,5 +96,4 @@ Command cmd_duplicate_layer = {
cmd_duplicate_layer_enabled,
NULL,
cmd_duplicate_layer_execute,
- NULL
};
diff --git a/src/commands/cmd_duplicate_sprite.cpp b/src/commands/cmd_duplicate_sprite.cpp
index 63da877c1..02594309b 100644
--- a/src/commands/cmd_duplicate_sprite.cpp
+++ b/src/commands/cmd_duplicate_sprite.cpp
@@ -88,5 +88,4 @@ Command cmd_duplicate_sprite = {
cmd_duplicate_sprite_enabled,
NULL,
cmd_duplicate_sprite_execute,
- NULL
};
diff --git a/src/commands/cmd_exit.cpp b/src/commands/cmd_exit.cpp
index 2b87ef53d..9443bb323 100644
--- a/src/commands/cmd_exit.cpp
+++ b/src/commands/cmd_exit.cpp
@@ -51,5 +51,4 @@ Command cmd_exit = {
NULL,
NULL,
cmd_exit_execute,
- NULL
};
diff --git a/src/commands/cmd_eyedropper_tool.cpp b/src/commands/cmd_eyedropper_tool.cpp
index c25a02f3c..18422019e 100644
--- a/src/commands/cmd_eyedropper_tool.cpp
+++ b/src/commands/cmd_eyedropper_tool.cpp
@@ -67,5 +67,4 @@ Command cmd_eyedropper_tool = {
NULL,
NULL,
cmd_eyedropper_tool_execute,
- NULL
};
diff --git a/src/commands/cmd_film_editor.cpp b/src/commands/cmd_film_editor.cpp
index 6087d17eb..6e3b3c67d 100644
--- a/src/commands/cmd_film_editor.cpp
+++ b/src/commands/cmd_film_editor.cpp
@@ -40,5 +40,4 @@ Command cmd_film_editor = {
cmd_film_editor_enabled,
NULL,
cmd_film_editor_execute,
- NULL
};
diff --git a/src/commands/cmd_flatten_layers.cpp b/src/commands/cmd_flatten_layers.cpp
index 188da4641..90fc94255 100644
--- a/src/commands/cmd_flatten_layers.cpp
+++ b/src/commands/cmd_flatten_layers.cpp
@@ -49,5 +49,4 @@ Command cmd_flatten_layers = {
cmd_flatten_layers_enabled,
NULL,
cmd_flatten_layers_execute,
- NULL
};
diff --git a/src/commands/cmd_flip.cpp b/src/commands/cmd_flip.cpp
index 86efbb73a..5c709797d 100644
--- a/src/commands/cmd_flip.cpp
+++ b/src/commands/cmd_flip.cpp
@@ -18,116 +18,108 @@
#include "config.h"
+#include
+
+#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,
};
diff --git a/src/commands/cmd_frame_properties.cpp b/src/commands/cmd_frame_properties.cpp
index d91f19f7f..e664c096b 100644
--- a/src/commands/cmd_frame_properties.cpp
+++ b/src/commands/cmd_frame_properties.cpp
@@ -91,5 +91,4 @@ Command cmd_frame_properties = {
cmd_frame_properties_enabled,
NULL,
cmd_frame_properties_execute,
- NULL
};
diff --git a/src/commands/cmd_grid.cpp b/src/commands/cmd_grid.cpp
index a918cfd2c..3c3c4b319 100644
--- a/src/commands/cmd_grid.cpp
+++ b/src/commands/cmd_grid.cpp
@@ -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
};
diff --git a/src/commands/cmd_invert_mask.cpp b/src/commands/cmd_invert_mask.cpp
index 7cc653d80..8bfa2dd95 100644
--- a/src/commands/cmd_invert_mask.cpp
+++ b/src/commands/cmd_invert_mask.cpp
@@ -85,5 +85,4 @@ Command cmd_invert_mask = {
cmd_invert_mask_enabled,
NULL,
cmd_invert_mask_execute,
- NULL
};
diff --git a/src/commands/cmd_layer_from_background.cpp b/src/commands/cmd_layer_from_background.cpp
index 7d63e5276..9e3368db3 100644
--- a/src/commands/cmd_layer_from_background.cpp
+++ b/src/commands/cmd_layer_from_background.cpp
@@ -53,5 +53,4 @@ Command cmd_layer_from_background = {
cmd_layer_from_background_enabled,
NULL,
cmd_layer_from_background_execute,
- NULL
};
diff --git a/src/commands/cmd_layer_properties.cpp b/src/commands/cmd_layer_properties.cpp
index 80a57023b..1da01b292 100644
--- a/src/commands/cmd_layer_properties.cpp
+++ b/src/commands/cmd_layer_properties.cpp
@@ -113,5 +113,4 @@ Command cmd_layer_properties = {
cmd_layer_properties_enabled,
NULL,
cmd_layer_properties_execute,
- NULL
};
diff --git a/src/commands/cmd_load_mask.cpp b/src/commands/cmd_load_mask.cpp
index e381d6999..b863b212e 100644
--- a/src/commands/cmd_load_mask.cpp
+++ b/src/commands/cmd_load_mask.cpp
@@ -67,5 +67,4 @@ Command cmd_load_mask = {
cmd_load_mask_enabled,
NULL,
cmd_load_mask_execute,
- NULL
};
diff --git a/src/commands/cmd_mask_all.cpp b/src/commands/cmd_mask_all.cpp
index dd8567855..d32672775 100644
--- a/src/commands/cmd_mask_all.cpp
+++ b/src/commands/cmd_mask_all.cpp
@@ -53,5 +53,4 @@ Command cmd_mask_all = {
cmd_mask_all_enabled,
NULL,
cmd_mask_all_execute,
- NULL
};
diff --git a/src/commands/cmd_mask_by_color.cpp b/src/commands/cmd_mask_by_color.cpp
index b8a98e199..eddeb99fc 100644
--- a/src/commands/cmd_mask_by_color.cpp
+++ b/src/commands/cmd_mask_by_color.cpp
@@ -42,5 +42,4 @@ Command cmd_mask_by_color = {
cmd_mask_by_color_enabled,
NULL,
cmd_mask_by_color_execute,
- NULL
};
diff --git a/src/commands/cmd_merge_down_layer.cpp b/src/commands/cmd_merge_down_layer.cpp
index fe51ae32e..738cc61c4 100644
--- a/src/commands/cmd_merge_down_layer.cpp
+++ b/src/commands/cmd_merge_down_layer.cpp
@@ -173,5 +173,4 @@ Command cmd_merge_down_layer = {
cmd_merge_down_layer_enabled,
NULL,
cmd_merge_down_layer_execute,
- NULL
};
diff --git a/src/commands/cmd_move_cel.cpp b/src/commands/cmd_move_cel.cpp
index 2c282b6d7..9e72173cc 100644
--- a/src/commands/cmd_move_cel.cpp
+++ b/src/commands/cmd_move_cel.cpp
@@ -40,5 +40,4 @@ Command cmd_move_cel = {
cmd_move_cel_enabled,
NULL,
cmd_move_cel_execute,
- NULL
};
diff --git a/src/commands/cmd_new_file.cpp b/src/commands/cmd_new_file.cpp
index bd5b6d8f2..341ee58bc 100644
--- a/src/commands/cmd_new_file.cpp
+++ b/src/commands/cmd_new_file.cpp
@@ -180,5 +180,4 @@ Command cmd_new_file = {
NULL,
NULL,
cmd_new_file_execute,
- NULL
};
diff --git a/src/commands/cmd_new_frame.cpp b/src/commands/cmd_new_frame.cpp
index fa76e3404..3a93b7ac3 100644
--- a/src/commands/cmd_new_frame.cpp
+++ b/src/commands/cmd_new_frame.cpp
@@ -67,5 +67,4 @@ Command cmd_new_frame = {
cmd_new_frame_enabled,
NULL,
cmd_new_frame_execute,
- NULL
};
diff --git a/src/commands/cmd_new_layer.cpp b/src/commands/cmd_new_layer.cpp
index 7e8dfb186..692ec1876 100644
--- a/src/commands/cmd_new_layer.cpp
+++ b/src/commands/cmd_new_layer.cpp
@@ -99,5 +99,4 @@ Command cmd_new_layer = {
cmd_new_layer_enabled,
NULL,
cmd_new_layer_execute,
- NULL
};
diff --git a/src/commands/cmd_new_layer_set.cpp b/src/commands/cmd_new_layer_set.cpp
index 28eea4ef3..681401fa5 100644
--- a/src/commands/cmd_new_layer_set.cpp
+++ b/src/commands/cmd_new_layer_set.cpp
@@ -60,5 +60,4 @@ Command cmd_new_layer_set = {
cmd_new_layer_set_enabled,
NULL,
cmd_new_layer_set_execute,
- NULL
};
diff --git a/src/commands/cmd_open_file.cpp b/src/commands/cmd_open_file.cpp
index 0ef6f4e7c..545693c9a 100644
--- a/src/commands/cmd_open_file.cpp
+++ b/src/commands/cmd_open_file.cpp
@@ -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
};
diff --git a/src/commands/cmd_options.cpp b/src/commands/cmd_options.cpp
index e304b4b35..aeb9fa7e6 100644
--- a/src/commands/cmd_options.cpp
+++ b/src/commands/cmd_options.cpp
@@ -33,5 +33,4 @@ Command cmd_options = {
NULL,
NULL,
cmd_options_execute,
- NULL
};
diff --git a/src/commands/cmd_palette_editor.cpp b/src/commands/cmd_palette_editor.cpp
index 21216863a..ca829f6b2 100644
--- a/src/commands/cmd_palette_editor.cpp
+++ b/src/commands/cmd_palette_editor.cpp
@@ -538,5 +538,4 @@ Command cmd_palette_editor = {
NULL,
NULL,
cmd_palette_editor_execute,
- NULL
};
diff --git a/src/commands/cmd_paste.cpp b/src/commands/cmd_paste.cpp
index 1ee8faef9..e233d5507 100644
--- a/src/commands/cmd_paste.cpp
+++ b/src/commands/cmd_paste.cpp
@@ -47,5 +47,4 @@ Command cmd_paste = {
cmd_paste_enabled,
NULL,
cmd_paste_execute,
- NULL
};
diff --git a/src/commands/cmd_preview.cpp b/src/commands/cmd_preview.cpp
index fb4a51054..36cea94a9 100644
--- a/src/commands/cmd_preview.cpp
+++ b/src/commands/cmd_preview.cpp
@@ -210,6 +210,9 @@ static void preview_sprite(int flags)
for (u=x-w; uw, 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
};
diff --git a/src/commands/cmd_record_screen.cpp b/src/commands/cmd_record_screen.cpp
index 18481c829..33eee04e5 100644
--- a/src/commands/cmd_record_screen.cpp
+++ b/src/commands/cmd_record_screen.cpp
@@ -51,5 +51,4 @@ Command cmd_record_screen = {
NULL,
cmd_record_screen_checked,
cmd_record_screen_execute,
- NULL
};
diff --git a/src/commands/cmd_redo.cpp b/src/commands/cmd_redo.cpp
index bf4526fde..65ac86ec1 100644
--- a/src/commands/cmd_redo.cpp
+++ b/src/commands/cmd_redo.cpp
@@ -52,5 +52,4 @@ Command cmd_redo = {
cmd_redo_enabled,
NULL,
cmd_redo_execute,
- NULL
};
diff --git a/src/commands/cmd_refresh.cpp b/src/commands/cmd_refresh.cpp
index fa1c44190..4c5ee66ad 100644
--- a/src/commands/cmd_refresh.cpp
+++ b/src/commands/cmd_refresh.cpp
@@ -62,5 +62,4 @@ Command cmd_refresh = {
NULL,
NULL,
cmd_refresh_execute,
- NULL
};
diff --git a/src/commands/cmd_remove_cel.cpp b/src/commands/cmd_remove_cel.cpp
index 31e34d966..83ffbac22 100644
--- a/src/commands/cmd_remove_cel.cpp
+++ b/src/commands/cmd_remove_cel.cpp
@@ -55,5 +55,4 @@ Command cmd_remove_cel = {
cmd_remove_cel_enabled,
NULL,
cmd_remove_cel_execute,
- NULL
};
diff --git a/src/commands/cmd_remove_frame.cpp b/src/commands/cmd_remove_frame.cpp
index 4d00d46d2..5083a2e6e 100644
--- a/src/commands/cmd_remove_frame.cpp
+++ b/src/commands/cmd_remove_frame.cpp
@@ -50,5 +50,4 @@ Command cmd_remove_frame = {
cmd_remove_frame_enabled,
NULL,
cmd_remove_frame_execute,
- NULL
};
diff --git a/src/commands/cmd_remove_layer.cpp b/src/commands/cmd_remove_layer.cpp
index 32c688699..940da94d0 100644
--- a/src/commands/cmd_remove_layer.cpp
+++ b/src/commands/cmd_remove_layer.cpp
@@ -49,5 +49,4 @@ Command cmd_remove_layer = {
cmd_remove_layer_enabled,
NULL,
cmd_remove_layer_execute,
- NULL
};
diff --git a/src/commands/cmd_reselect_mask.cpp b/src/commands/cmd_reselect_mask.cpp
index 725194e08..bc82aaaf7 100644
--- a/src/commands/cmd_reselect_mask.cpp
+++ b/src/commands/cmd_reselect_mask.cpp
@@ -63,5 +63,4 @@ Command cmd_reselect_mask = {
cmd_reselect_mask_enabled,
NULL,
cmd_reselect_mask_execute,
- NULL
};
diff --git a/src/commands/cmd_save_file.cpp b/src/commands/cmd_save_file.cpp
index fce6f3aa4..cdd85b69e 100644
--- a/src/commands/cmd_save_file.cpp
+++ b/src/commands/cmd_save_file.cpp
@@ -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
};
diff --git a/src/commands/cmd_save_mask.cpp b/src/commands/cmd_save_mask.cpp
index 63a4ac515..d16fa1871 100644
--- a/src/commands/cmd_save_mask.cpp
+++ b/src/commands/cmd_save_mask.cpp
@@ -82,5 +82,4 @@ Command cmd_save_mask = {
cmd_save_mask_enabled,
NULL,
cmd_save_mask_execute,
- NULL
};
diff --git a/src/commands/cmd_screen_shot.cpp b/src/commands/cmd_screen_shot.cpp
index ec1fffeba..e5ab10d13 100644
--- a/src/commands/cmd_screen_shot.cpp
+++ b/src/commands/cmd_screen_shot.cpp
@@ -115,5 +115,4 @@ Command cmd_screen_shot = {
NULL,
NULL,
cmd_screen_shot_execute,
- NULL
};
diff --git a/src/commands/cmd_select_file.cpp b/src/commands/cmd_select_file.cpp
index f6bf6d044..67e3630d8 100644
--- a/src/commands/cmd_select_file.cpp
+++ b/src/commands/cmd_select_file.cpp
@@ -79,5 +79,4 @@ Command cmd_select_file = {
cmd_select_file_enabled,
cmd_select_file_checked,
cmd_select_file_execute,
- NULL
};
diff --git a/src/commands/cmd_sprite_editor.cpp b/src/commands/cmd_sprite_editor.cpp
index 0349f4c71..66239bce6 100644
--- a/src/commands/cmd_sprite_editor.cpp
+++ b/src/commands/cmd_sprite_editor.cpp
@@ -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
};
diff --git a/src/commands/cmd_sprite_properties.cpp b/src/commands/cmd_sprite_properties.cpp
index 55ccd9982..ae3c66be6 100644
--- a/src/commands/cmd_sprite_properties.cpp
+++ b/src/commands/cmd_sprite_properties.cpp
@@ -117,5 +117,4 @@ Command cmd_sprite_properties = {
cmd_sprite_properties_enabled,
NULL,
cmd_sprite_properties_execute,
- NULL
};
diff --git a/src/commands/cmd_sprite_size.cpp b/src/commands/cmd_sprite_size.cpp
index fc32c8aef..a05d87df8 100644
--- a/src/commands/cmd_sprite_size.cpp
+++ b/src/commands/cmd_sprite_size.cpp
@@ -291,5 +291,4 @@ Command cmd_sprite_size = {
cmd_sprite_size_enabled,
NULL,
cmd_sprite_size_execute,
- NULL
};
diff --git a/src/commands/cmd_switch_colors.cpp b/src/commands/cmd_switch_colors.cpp
index 8b8689da5..6a76674ff 100644
--- a/src/commands/cmd_switch_colors.cpp
+++ b/src/commands/cmd_switch_colors.cpp
@@ -41,5 +41,4 @@ Command cmd_switch_colors = {
NULL,
NULL,
cmd_switch_colors_execute,
- NULL
};
diff --git a/src/commands/cmd_tips.cpp b/src/commands/cmd_tips.cpp
index 64c12b08e..a8d7e43a9 100644
--- a/src/commands/cmd_tips.cpp
+++ b/src/commands/cmd_tips.cpp
@@ -33,5 +33,4 @@ Command cmd_tips = {
NULL,
NULL,
cmd_tips_execute,
- NULL
};
diff --git a/src/commands/cmd_undo.cpp b/src/commands/cmd_undo.cpp
index b44b13857..8c73153bf 100644
--- a/src/commands/cmd_undo.cpp
+++ b/src/commands/cmd_undo.cpp
@@ -52,5 +52,4 @@ Command cmd_undo = {
cmd_undo_enabled,
NULL,
cmd_undo_execute,
- NULL
};
diff --git a/src/commands/commands.cpp b/src/commands/commands.cpp
index 68f503943..99d7d0d1e 100644
--- a/src/commands/commands.cpp
+++ b/src/commands/commands.cpp
@@ -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;
- }
- }
-}
diff --git a/src/commands/commands.h b/src/commands/commands.h
index f95a1a0a6..cb34fbffa 100644
--- a/src/commands/commands.h
+++ b/src/commands/commands.h
@@ -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 */
diff --git a/src/commands/fx/cmd_color_curve.cpp b/src/commands/fx/cmd_color_curve.cpp
index aef1226b2..7abe63362 100644
--- a/src/commands/fx/cmd_color_curve.cpp
+++ b/src/commands/fx/cmd_color_curve.cpp
@@ -160,5 +160,4 @@ Command cmd_color_curve = {
cmd_color_curve_enabled,
NULL,
cmd_color_curve_execute,
- NULL
};
diff --git a/src/commands/fx/cmd_convolution_matrix.cpp b/src/commands/fx/cmd_convolution_matrix.cpp
index a344e0201..3a9d9bde4 100644
--- a/src/commands/fx/cmd_convolution_matrix.cpp
+++ b/src/commands/fx/cmd_convolution_matrix.cpp
@@ -318,5 +318,4 @@ Command cmd_convolution_matrix = {
cmd_convolution_matrix_enabled,
NULL,
cmd_convolution_matrix_execute,
- NULL
};
diff --git a/src/commands/fx/cmd_despeckle.cpp b/src/commands/fx/cmd_despeckle.cpp
index 96e9445ad..2749b1be3 100644
--- a/src/commands/fx/cmd_despeckle.cpp
+++ b/src/commands/fx/cmd_despeckle.cpp
@@ -185,5 +185,4 @@ Command cmd_despeckle = {
cmd_despeckle_enabled,
NULL,
cmd_despeckle_execute,
- NULL
};
diff --git a/src/commands/fx/cmd_invert_color.cpp b/src/commands/fx/cmd_invert_color.cpp
index 17c3f2b27..96db51fbd 100644
--- a/src/commands/fx/cmd_invert_color.cpp
+++ b/src/commands/fx/cmd_invert_color.cpp
@@ -134,5 +134,4 @@ Command cmd_invert_color = {
cmd_invert_color_enabled,
NULL,
cmd_invert_color_execute,
- NULL
};
diff --git a/src/commands/fx/cmd_replace_color.cpp b/src/commands/fx/cmd_replace_color.cpp
index 9f498b8a1..e11a2a5dd 100644
--- a/src/commands/fx/cmd_replace_color.cpp
+++ b/src/commands/fx/cmd_replace_color.cpp
@@ -189,5 +189,4 @@ Command cmd_replace_color = {
cmd_replace_color_enabled,
NULL,
cmd_replace_color_execute,
- NULL
};
diff --git a/src/dialogs/aniedit.cpp b/src/dialogs/aniedit.cpp
index 27d8dfd86..9e6b926b1 100644
--- a/src/dialogs/aniedit.cpp
+++ b/src/dialogs/aniedit.cpp
@@ -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) {
diff --git a/src/modules/gui.cpp b/src/modules/gui.cpp
index e99996464..c87faf6ba 100644
--- a/src/modules/gui.cpp
+++ b/src/modules/gui.cpp
@@ -18,7 +18,10 @@
#include "config.h"
-#include
+#include
+#include
+#include
+#include
#include
#include
@@ -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 monitors;
+static std::vector 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(link->data));
+ // destroy shortcuts
+ for (std::vector::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::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::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::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::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::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(link->data);
+ for (std::list::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::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(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; iis_key_pressed(msg))
+ group[j++] = tools_list[i];
+ }
+
+ if (j >= 2) {
+ for (i=0; icommand;
+
+ // 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(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;
}
/**********************************************************************/
diff --git a/src/modules/gui.h b/src/modules/gui.h
index 29fb7df74..31ce46ee8 100644
--- a/src/modules/gui.h
+++ b/src/modules/gui.h
@@ -23,8 +23,12 @@
#include
#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);
diff --git a/src/modules/rootmenu.cpp b/src/modules/rootmenu.cpp
index 3adf4d0a2..3d3d4f339 100644
--- a/src/modules/rootmenu.cpp
+++ b/src/modules/rootmenu.cpp
@@ -20,6 +20,7 @@
#include
#include
+#include
#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 */
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);
}
}
diff --git a/src/modules/tools.cpp b/src/modules/tools.cpp
index 4059eaa31..a4ad03817 100644
--- a/src/modules/tools.cpp
+++ b/src/modules/tools.cpp
@@ -23,7 +23,6 @@
#include
#include
-#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; caccel) {
- 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; iundo_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);
}
}
diff --git a/src/raster/undo.h b/src/raster/undo.h
index 4f43eea39..b3d0283e6 100644
--- a/src/raster/undo.h
+++ b/src/raster/undo.h
@@ -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);
diff --git a/src/undoable.cpp b/src/undoable.cpp
index 8bb6a7421..66b0b9ce2 100644
--- a/src/undoable.cpp
+++ b/src/undoable.cpp
@@ -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);
diff --git a/src/undoable.h b/src/undoable.h
index 93d1468c6..24e9e1692 100644
--- a/src/undoable.h
+++ b/src/undoable.h
@@ -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);
diff --git a/src/widgets/colbar.cpp b/src/widgets/colbar.cpp
index b34e10cc8..844b5d973 100644
--- a/src/widgets/colbar.cpp
+++ b/src/widgets/colbar.cpp
@@ -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;
diff --git a/src/widgets/menuitem.cpp b/src/widgets/menuitem.cpp
index 90ea0c855..b53a2675c 100644
--- a/src/widgets/menuitem.cpp
+++ b/src/widgets/menuitem.cpp
@@ -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