diff --git a/ChangeLog b/ChangeLog index f642f83e7..5725d779f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-05-05 David A. Capello + + * src/script/functions.c (CropLayer): Rewritten (more simple). + (CropSprite): Fixed to crop the background layer right. + + * src/commands/cmd_merge_down_layer.c (cmd_merge_down_layer_execute): + Fixed to merge a transparent over the background. + + * src/raster/image.c (image_crop): Added the 'bgcolor' parameter. + + * src/script/functions.c (CropLayer): Fixed. + 2008-05-04 David A. Capello * src/util/celmove.c (move_cel, copy_cel): Fixed to handle diff --git a/data/gui-en.xml b/data/gui-en.xml index 4dec2444a..1d0b5cc56 100644 --- a/data/gui-en.xml +++ b/data/gui-en.xml @@ -133,8 +133,8 @@ - - + + @@ -145,16 +145,16 @@ - - + + - - - - - + + + + + - + diff --git a/docs/QuickHelp.html b/docs/QuickHelp.html deleted file mode 100644 index f35b2ac74..000000000 --- a/docs/QuickHelp.html +++ /dev/null @@ -1,184 +0,0 @@ - - - - -ASE Quick Help - - - -

ASE Quick Help

- -

Editor

- -

    -
  • Mouse cursor: is the icon (a little image) that you -displaces with the mouse movement (it moves pixel-by-pixel of the -screen).
  • -
  • Drawing cursor: is the cross that appears inside the editor -(it moves pixel-by-pixel of the image).
  • -
  • Left/Right: go to previous/next frame.
  • -
  • Down/Up: go to first/last frame.
  • -
  • 1 to 6: changes the editor's zoom.
  • -
  • Shift+Mouse movement: moves the editor's scroll
  • -
  • + or - from pad: changes the brush size
  • -
  • 9 or 0: picks primary or secondary color from the image
  • -
  • Ctrl+Mouse movement: moves the current layer
  • -

- -

In box-like tools (marker, line, rectangle, ellipse)

- -

    -
  • Shift: uses square aspect.
  • -
  • Ctrl: converges from center.
  • -

- -

In Move/Copy/Swap movement

- -

    -
  • M: changes between masked/copy method.
  • -

- -

Color bar

- -

    -
  • Double-click: opens the color selection dialog to change -the double-clicked color.
  • -
  • Ctrl+Click: opens a mini-palette window.
  • -

- -

Palette Editor (in color selection dialog)

- -

    -
  • Shift+Mouse click: selects a lineal range
  • -
  • Ctrl+Mouse click: selects a rectangular range
  • -
  • Left/Up/Right/Down: moves the selection to the used -direction (lineal selection can be only moved to left or right)
  • -

- -

Film Editor

- -

    -
  • ` (backquote): closes the film-editor
  • -

- -

Configure Tool Window

- -

    -
  • C: closes the window
  • -

- -

Tiled sprite view (F8)

- -

    -
  • Left/Right: go to previous/next frame.
  • -

- -

Normal sprite view (F7)

- -

    -
  • + or - from pad: changes the background color
  • -

- -

Hotkeys

- -

Default keyboard bindings (you can change it from the -"data/menus.en" file):

- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
System menu
F5 Refresh the screen
F12 Take a screen shot
File menu
Ctrl+N Creates a new sprite
Ctrl+O F3 Opens a sprite
Ctrl+S F2 Saves current sprite (ask for file name)
Ctrl+W Closes the current sprite
Ctrl+Q Esc Quits (ask about modified sprites)
Edit menu
Ctrl+Z Ctrl+U Undo
Ctrl+R Redo
Ctrl+X Shift+Del Cut
Ctrl+C Ctrl+Ins Copy
Ctrl+V Shift+Ins Paste
Ctrl+B Ctrl+Del Clear
Shift+M Moves the selected pixel region (mask) to other position
Shift+C Copies a pixel region in other position
Shift+H Flips the pixel region horizontally
Shift+V Flips the pixel region vertically
/ (slash) Replace colors
Ctrl+I Makes a negative of the image inside selected area
Sprite menu
Ctrl+P Shows the main sprite's properties
Layer menu
Shift+P Shows the properties of selected layer
Shift+N Inserts an image-layer
Frame menu
Ctrl+Shift+P Shows the properties of selected frame
Ctrl+Shift+N Creates a new frame
Mask (selection) menu
Ctrl+A Selects all
Ctrl+D Deselects the mask
Ctrl+Shift+D Reselects the mask
Ctrl+Shift+I Inverts the mask
? Shows the window to mask regions by image color
Ctrl+Shift+M Shows the masks' repository
Tool menu
Ctrl+0 Loads a script from file
F1 Shows tips
Ctrl+Shift+O Shows options
Drawing Tool menu
C Shows/hide Configure Tool window
M Marker: Select mask regions
D Dots: Draw pixel by pixel
P Pencil: Draw perfect trace
B Brush: Draw imperfect trace
F Floodfill: Fill areas
S Spray: Draw random pixels
L Line: Draw a line between two points
R Rectangle: Draw a rectangle between two points
E Ellipse: Draw a oval between two points
Filters menu
F9 Shows the Convolution Matrix window
F10 Ctrl+M Shows the Color Curve window
View menu
F8 Views the sprite like a mosaic (tiled)
F7 Views the sprite in a normal size
Ctrl+F1 Switch the menu-bar
Ctrl+F2 Switch the status-bar
Ctrl+F3 Switch the color-bar
Ctrl+F4 Switch the tool-bar
Ctrl+1 Makes the current editor the unique one
Ctrl+2 Splits the current editor vertically
Ctrl+3 Splits the current editor horizontally
Ctrl+4 Closes the current editor
Tab Shows/hide the Film Editor
F4 Shows the palette editor
X Shows the filters popup menu

- - - diff --git a/misc/dist.sh b/misc/dist.sh index 31b851ce2..70742aae3 100644 --- a/misc/dist.sh +++ b/misc/dist.sh @@ -1,7 +1,7 @@ #! /bin/sh dir="`pwd`" -version=0.6-beta2 +version=0.6b2 distdir=ase-$version freetype_files="third_party/freetype/ChangeLog \ @@ -90,7 +90,7 @@ ase_files="config.h \ data/tips/*.pcx \ data/tips/tips.en \ data/tips/tips.es \ - docs/*.html \ + docs/*.pdf \ docs/*.txt \ docs/files/*.txt \ docs/licenses/*.txt \ @@ -107,8 +107,8 @@ ase_files="config.h \ src/dialogs/*.[ch] \ src/effect/*.[ch] \ src/file/*.[ch] \ - src/file/fli/*.[ch] \ - src/file/fli/README \ + src/file/fli/*.[ch] \ + src/file/fli/README \ src/file/gif/*.[ch] \ src/intl/*.[ch] \ src/jinete/*.[ch] \ @@ -177,9 +177,7 @@ $1/data/jids/*.jid \ $1/data/gui-en.xml \ $1/data/tips/*.en \ $1/data/tips/*.es \ -$1/docs/*.html \ -$1/docs/*.info \ -$1/docs/*.texi \ +$1/docs/*.pdf \ $1/docs/*.txt \ $1/docs/files/*.txt \ $1/docs/licenses/*.txt" diff --git a/src/commands/cmd_background_from_layer.c b/src/commands/cmd_background_from_layer.c index 720dacfb0..3c3a5dce0 100644 --- a/src/commands/cmd_background_from_layer.c +++ b/src/commands/cmd_background_from_layer.c @@ -23,6 +23,7 @@ #include "modules/sprites.h" #include "raster/layer.h" #include "raster/sprite.h" +#include "raster/undo.h" #include "script/functions.h" static bool cmd_background_from_layer_enabled(const char *argument) @@ -38,8 +39,13 @@ static bool cmd_background_from_layer_enabled(const char *argument) static void cmd_background_from_layer_execute(const char *argument) { - BackgroundFromLayer(); - update_screen_for_sprite(current_sprite); + Sprite *sprite = current_sprite; + + if (undo_is_enabled(sprite->undo)) + undo_set_label(sprite->undo, "Background from Layer"); + + BackgroundFromLayer(sprite); + update_screen_for_sprite(sprite); } Command cmd_background_from_layer = { diff --git a/src/commands/cmd_crop.c b/src/commands/cmd_crop.c index 6fb0ebdcd..3ad9ec66e 100644 --- a/src/commands/cmd_crop.c +++ b/src/commands/cmd_crop.c @@ -19,11 +19,13 @@ #include "config.h" #include "commands/commands.h" +#include "modules/gui.h" #include "modules/sprites.h" #include "raster/image.h" -#include "raster/mask.h" #include "raster/layer.h" +#include "raster/mask.h" #include "raster/sprite.h" +#include "raster/undo.h" #include "script/functions.h" #include "util/autocrop.h" #include "util/misc.h" @@ -41,7 +43,13 @@ static bool cmd_crop_sprite_enabled(const char *argument) static void cmd_crop_sprite_execute(const char *argument) { - CropSprite(); + Sprite *sprite = current_sprite; + + if (undo_is_enabled(sprite->undo)) + undo_set_label(sprite->undo, "Sprite Crop"); + + CropSprite(sprite); + update_screen_for_sprite(sprite); } /* ======================== */ @@ -55,7 +63,13 @@ static bool cmd_autocrop_sprite_enabled(const char *argument) static void cmd_autocrop_sprite_execute(const char *argument) { - autocrop_sprite(); + Sprite *sprite = current_sprite; + + if (undo_is_enabled(sprite->undo)) + undo_set_label(sprite->undo, "Sprite Autocrop"); + + autocrop_sprite(sprite); + update_screen_for_sprite(sprite); } /**********************************************************************/ diff --git a/src/commands/cmd_flatten_layers.c b/src/commands/cmd_flatten_layers.c index 0856d3c1e..e5306a3f4 100644 --- a/src/commands/cmd_flatten_layers.c +++ b/src/commands/cmd_flatten_layers.c @@ -19,7 +19,10 @@ #include "config.h" #include "commands/commands.h" +#include "modules/gui.h" #include "modules/sprites.h" +#include "raster/undo.h" +#include "raster/sprite.h" #include "script/functions.h" static bool cmd_flatten_layers_enabled(const char *argument) @@ -29,7 +32,13 @@ static bool cmd_flatten_layers_enabled(const char *argument) static void cmd_flatten_layers_execute(const char *argument) { - FlattenLayers(); + Sprite *sprite = current_sprite; + + if (undo_is_enabled(sprite->undo)) + undo_set_label(sprite->undo, "Flatten Layers"); + + FlattenLayers(sprite); + update_screen_for_sprite(sprite); } Command cmd_flatten_layers = { diff --git a/src/commands/cmd_flip.c b/src/commands/cmd_flip.c index 7ff1a8f93..12a5e00b6 100644 --- a/src/commands/cmd_flip.c +++ b/src/commands/cmd_flip.c @@ -100,7 +100,7 @@ static void do_flip(int horz) } /* flip the portion of the bitmap */ - area = image_crop(image, x1, y1, x2-x1+1, y2-y1+1); + 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, diff --git a/src/commands/cmd_layer_from_background.c b/src/commands/cmd_layer_from_background.c index 8511de501..2252c5fa7 100644 --- a/src/commands/cmd_layer_from_background.c +++ b/src/commands/cmd_layer_from_background.c @@ -42,8 +42,13 @@ static bool cmd_layer_from_background_enabled(const char *argument) static void cmd_layer_from_background_execute(const char *argument) { - LayerFromBackground(); - update_screen_for_sprite(current_sprite); + Sprite *sprite = current_sprite; + + if (undo_is_enabled(sprite->undo)) + undo_set_label(sprite->undo, "Layer from Background"); + + LayerFromBackground(sprite); + update_screen_for_sprite(sprite); } Command cmd_layer_from_background = { diff --git a/src/commands/cmd_merge_down_layer.c b/src/commands/cmd_merge_down_layer.c index 748ba1a3c..73aaee784 100644 --- a/src/commands/cmd_merge_down_layer.c +++ b/src/commands/cmd_merge_down_layer.c @@ -86,7 +86,7 @@ static void cmd_merge_down_layer_execute(const char *argument) /* with source image? */ if (src_image != NULL) { /* no destination image */ - if (dst_image == NULL) { + if (dst_image == NULL) { /* only a transparent layer can have a null cel */ /* copy this cel to the destination layer... */ /* creating a copy of the image */ @@ -108,14 +108,30 @@ static void cmd_merge_down_layer_execute(const char *argument) } /* with destination */ else { - int x1 = MIN(src_cel->x, dst_cel->x); - int y1 = MIN(src_cel->y, dst_cel->y); - int x2 = MAX(src_cel->x+src_image->w-1, dst_cel->x+dst_image->w-1); - int y2 = MAX(src_cel->y+src_image->h-1, dst_cel->y+dst_image->h-1); - Image *new_image = image_crop(dst_image, - x1-dst_cel->x, - y1-dst_cel->y, - x2-x1+1, y2-y1+1); + int x1, y1, x2, y2, bgcolor; + Image *new_image; + + /* merge down in the background layer */ + if (layer_is_background(dst_layer)) { + x1 = 0; + y1 = 0; + x2 = sprite->w; + y2 = sprite->h; + bgcolor = app_get_color_to_clear_layer(dst_layer); + } + /* merge down in a transparent layer */ + else { + x1 = MIN(src_cel->x, dst_cel->x); + y1 = MIN(src_cel->y, dst_cel->y); + x2 = MAX(src_cel->x+src_image->w-1, dst_cel->x+dst_image->w-1); + y2 = MAX(src_cel->y+src_image->h-1, dst_cel->y+dst_image->h-1); + bgcolor = 0; + } + + new_image = image_crop(dst_image, + x1-dst_cel->x, + y1-dst_cel->y, + x2-x1+1, y2-y1+1, bgcolor); /* merge src_image in new_image */ image_merge(new_image, src_image, diff --git a/src/commands/cmd_new_file.c b/src/commands/cmd_new_file.c index 66c82493f..8695ac1b4 100644 --- a/src/commands/cmd_new_file.c +++ b/src/commands/cmd_new_file.c @@ -136,7 +136,7 @@ static void cmd_new_file_execute(const char *argument) /* if the background color isn't transparent, we have to convert the `Layer 1' in a `Background' */ if (color_type(color) != COLOR_TYPE_MASK) { - BackgroundFromLayer(); + BackgroundFromLayer(sprite); /* clear the image to */ image_clear(GetImage(sprite), diff --git a/src/commands/cmd_new_layer.c b/src/commands/cmd_new_layer.c index 6081ba1b9..b20c5b99f 100644 --- a/src/commands/cmd_new_layer.c +++ b/src/commands/cmd_new_layer.c @@ -26,6 +26,7 @@ #include "modules/sprites.h" #include "raster/layer.h" #include "raster/sprite.h" +#include "raster/undo.h" #include "script/functions.h" static bool cmd_new_layer_enabled(const char *argument) @@ -44,14 +45,19 @@ static void cmd_new_layer_execute(const char *argument) return; name_widget = jwidget_find_name(window, "name"); - jwidget_set_text(name_widget, GetUniqueLayerName()); + jwidget_set_text(name_widget, GetUniqueLayerName(sprite)); jwidget_set_min_size(name_widget, 128, 0); jwindow_open_fg(window); if (jwindow_get_killer(window) == jwidget_find_name(window, "ok")) { const char *name = jwidget_get_text(jwidget_find_name(window, "name")); - Layer *layer = NewLayer(); + Layer *layer; + + if (undo_is_enabled(sprite->undo)) + undo_set_label(sprite->undo, "New Layer"); + + layer = NewLayer(sprite); if (!layer) { jalert(_("Error<undo)) + undo_set_label(sprite->undo, "Remove Layer"); + + RemoveLayer(sprite); + update_screen_for_sprite(sprite); } Command cmd_remove_layer = { diff --git a/src/effect/effect.c b/src/effect/effect.c index d44421a41..d3f08d54b 100644 --- a/src/effect/effect.c +++ b/src/effect/effect.c @@ -386,7 +386,7 @@ static int effect_init(Effect *effect, Layer *layer, Image *image, } effect->src = image; - effect->dst = image_crop(image, 0, 0, image->w, image->h); + effect->dst = image_crop(image, 0, 0, image->w, image->h, 0); effect->row = -1; effect->mask = NULL; effect->preview_mask = NULL; diff --git a/src/file/gif_format.c b/src/file/gif_format.c index 6276b0506..1c6903aab 100644 --- a/src/file/gif_format.c +++ b/src/file/gif_format.c @@ -230,7 +230,7 @@ static bool load_GIF(FileOp *fop) gif->frames[i].xoff, gif->frames[i].yoff, gif->frames[i].w, - gif->frames[i].h); + gif->frames[i].h, 0); if (tmp) { image_copy(current_image, tmp, gif->frames[i].xoff, diff --git a/src/modules/tools.c b/src/modules/tools.c index 2083bad96..ed8bfe79f 100644 --- a/src/modules/tools.c +++ b/src/modules/tools.c @@ -959,7 +959,7 @@ void control_tool(JWidget widget, Tool *tool, tool_data.src_image = image_crop(cel_image, x1-cel->x, - y1-cel->y, x2-x1, y2-y1); + y1-cel->y, x2-x1, y2-y1, 0); tool_data.dst_image = image_new_copy(tool_data.src_image); tool_data.mask = (sprite->mask && diff --git a/src/raster/image.c b/src/raster/image.c index 94b4d95ee..340366bbc 100644 --- a/src/raster/image.c +++ b/src/raster/image.c @@ -78,7 +78,7 @@ Image *image_new(int imgtype, int w, int h) Image *image_new_copy(const Image *image) { assert(image != NULL); - return image_crop(image, 0, 0, image->w, image->h); + return image_crop(image, 0, 0, image->w, image->h, 0); } void image_free(Image *image) @@ -133,7 +133,7 @@ void image_merge(Image *dst, const Image *src, int x, int y, int opacity, int bl dst->method->merge(dst, src, x, y, opacity, blend_mode); } -Image *image_crop(const Image *image, int x, int y, int w, int h) +Image *image_crop(const Image *image, int x, int y, int w, int h, int bgcolor) { Image *trim; @@ -144,7 +144,7 @@ Image *image_crop(const Image *image, int x, int y, int w, int h) if (!trim) return NULL; - image_clear(trim, 0); + image_clear(trim, bgcolor); image_copy(trim, image, -x, -y); return trim; diff --git a/src/raster/image.h b/src/raster/image.h index e3a5bdebc..224911ff4 100644 --- a/src/raster/image.h +++ b/src/raster/image.h @@ -119,7 +119,7 @@ void image_copy(Image *dst, const Image *src, int x, int y); void image_merge(Image *dst, const Image *src, int x, int y, int opacity, int blend_mode); -Image *image_crop(const Image *image, int x, int y, int w, int h); +Image *image_crop(const Image *image, int x, int y, int w, int h, int bgcolor); void image_hline(Image *image, int x1, int y, int x2, int color); void image_vline(Image *image, int x, int y1, int y2, int color); diff --git a/src/raster/mask.c b/src/raster/mask.c index 2b135525e..3fb9507bf 100644 --- a/src/raster/mask.c +++ b/src/raster/mask.c @@ -169,7 +169,7 @@ void mask_union(Mask *mask, int x, int y, int w, int h) mask->w = x2 - mask->x + 1; mask->h = y2 - mask->y + 1; - image = image_crop(mask->bitmap, mask->x-x1, mask->y-y1, mask->w, mask->h); + image = image_crop(mask->bitmap, mask->x-x1, mask->y-y1, mask->w, mask->h, 0); image_free(mask->bitmap); mask->bitmap = image; } @@ -203,7 +203,7 @@ void mask_intersect(Mask *mask, int x, int y, int w, int h) mask->w = x2 - mask->x + 1; mask->h = y2 - mask->y + 1; - image = image_crop(mask->bitmap, mask->x-x1, mask->y-y1, mask->w, mask->h); + image = image_crop(mask->bitmap, mask->x-x1, mask->y-y1, mask->w, mask->h, 0); image_free(mask->bitmap); mask->bitmap = image; @@ -416,7 +416,7 @@ static void shrink_mask(Mask *mask) { \ for (u = u_begin; u u_op u_final; u u_add) { \ for (v = v_begin; v v_op v_final; v v_add) { \ - if (mask->bitmap->method->getpixel (mask->bitmap, U, V)) \ + if (mask->bitmap->method->getpixel(mask->bitmap, U, V)) \ break; \ } \ if (v == v_final) \ @@ -433,20 +433,20 @@ static void shrink_mask(Mask *mask) x2 = mask->x+mask->w-1; y2 = mask->y+mask->h-1; - SHRINK_SIDE (0, <, mask->w, ++, - 0, <, mask->h, ++, u, v, x1++); + SHRINK_SIDE(0, <, mask->w, ++, + 0, <, mask->h, ++, u, v, x1++); - SHRINK_SIDE (0, <, mask->h, ++, - 0, <, mask->w, ++, v, u, y1++); + SHRINK_SIDE(0, <, mask->h, ++, + 0, <, mask->w, ++, v, u, y1++); - SHRINK_SIDE (mask->w-1, >, 0, --, - 0, <, mask->h, ++, u, v, x2--); + SHRINK_SIDE(mask->w-1, >, 0, --, + 0, <, mask->h, ++, u, v, x2--); - SHRINK_SIDE (mask->h-1, >, 0, --, - 0, <, mask->w, ++, v, u, y2--); + SHRINK_SIDE(mask->h-1, >, 0, --, + 0, <, mask->w, ++, v, u, y2--); if ((x1 == x2) && (y1 == y2)) { - mask_none (mask); + mask_none(mask); } else if ((x1 != mask->x) || (x2 != mask->x+mask->w-1) || (y1 != mask->y) || (y2 != mask->y+mask->h-1)) { @@ -460,8 +460,8 @@ static void shrink_mask(Mask *mask) mask->w = x2 - x1 + 1; mask->h = y2 - y1 + 1; - image = image_crop (mask->bitmap, mask->x-u, mask->y-v, mask->w, mask->h); - image_free (mask->bitmap); + image = image_crop(mask->bitmap, mask->x-u, mask->y-v, mask->w, mask->h, 0); + image_free(mask->bitmap); mask->bitmap = image; } diff --git a/src/raster/undo.c b/src/raster/undo.c index d587d4238..41f9f49fa 100644 --- a/src/raster/undo.c +++ b/src/raster/undo.c @@ -711,7 +711,7 @@ static void chunk_flip_invert(UndoStream *stream, UndoChunkFlip *chunk, int stat chunk_flip_new(stream, image, x1, y1, x2, y2, horz); - area = image_crop(image, x1, y1, x2-x1+1, y2-y1+1); + 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, diff --git a/src/script/bindings.c b/src/script/bindings.c index bbf974ed4..5f445d359 100644 --- a/src/script/bindings.c +++ b/src/script/bindings.c @@ -521,4 +521,11 @@ static int bind_rand(lua_State *L) #define file_exists exists -#include "script/genbinds.c" +#if 0 /* TODO what we will do with this? */ + #include "script/genbinds.c" +#else + void register_bindings(lua_State *L) + { + /* do nothing */ + } +#endif diff --git a/src/script/functions.c b/src/script/functions.c index a31959566..b4f8b7139 100644 --- a/src/script/functions.c +++ b/src/script/functions.c @@ -142,14 +142,11 @@ void SetSprite(Sprite *sprite) set_current_sprite(sprite); } -void CropSprite(void) +void CropSprite(Sprite *sprite) { - Sprite *sprite = current_sprite; - - if ((sprite) && + if ((sprite != NULL) && (!mask_is_empty(sprite->mask))) { if (undo_is_enabled(sprite->undo)) { - undo_set_label(sprite->undo, "Sprite Crop"); undo_open(sprite->undo); undo_int(sprite->undo, (GfxObj *)sprite, &sprite->w); undo_int(sprite->undo, (GfxObj *)sprite, &sprite->h); @@ -160,6 +157,13 @@ void CropSprite(void) displace_layers(sprite->undo, sprite->set, -sprite->mask->x, -sprite->mask->y); + { + Layer *background_layer = sprite_get_background_layer(sprite); + if (background_layer != NULL) { + CropLayer(background_layer, 0, 0, sprite->w, sprite->h); + } + } + if (undo_is_enabled(sprite->undo)) { undo_int(sprite->undo, (GfxObj *)sprite->mask, &sprite->mask->x); undo_int(sprite->undo, (GfxObj *)sprite->mask, &sprite->mask->y); @@ -172,7 +176,6 @@ void CropSprite(void) undo_close(sprite->undo); sprite_generate_mask_boundaries(sprite); - update_screen_for_sprite(sprite); } } @@ -220,9 +223,8 @@ static int get_max_layer_num(Layer *layer); /** * Creates a new transparent layer. */ -Layer *NewLayer(void) +Layer *NewLayer(Sprite *sprite) { - Sprite *sprite = current_sprite; Layer *layer; #if 0 Image *image; @@ -275,7 +277,6 @@ Layer *NewLayer(void) /* undo stuff */ if (undo_is_enabled(sprite->undo)) { - undo_set_label(sprite->undo, "New Layer"); undo_open(sprite->undo); undo_add_layer(sprite->undo, sprite->set, layer); undo_set_layer(sprite->undo, sprite); @@ -294,9 +295,8 @@ Layer *NewLayer(void) /** * Creates a new layer set with the "name" in the current sprite */ -Layer *NewLayerSet(void) +Layer *NewLayerSet(Sprite *sprite) { - Sprite *sprite = current_sprite; Layer *layer = NULL; if (sprite == NULL) { @@ -330,10 +330,10 @@ Layer *NewLayerSet(void) /** * Removes the current selected layer */ -void RemoveLayer(void) +void RemoveLayer(Sprite *sprite) { - Sprite *sprite = current_sprite; - if (sprite && sprite->layer) { + if (sprite != NULL && + sprite->layer != NULL) { Layer *layer = sprite->layer; Layer *parent = layer->parent_layer; Layer *layer_select; @@ -350,10 +350,8 @@ void RemoveLayer(void) layer_select = NULL; /* undo stuff */ - if (undo_is_enabled(sprite->undo)) { - undo_set_label(sprite->undo, "Remove Layer"); + if (undo_is_enabled(sprite->undo)) undo_open(sprite->undo); - } /* select other layer */ if (undo_is_enabled(sprite->undo)) @@ -375,10 +373,9 @@ void RemoveLayer(void) } } -char *GetUniqueLayerName(void) +char *GetUniqueLayerName(Sprite *sprite) { - Sprite *sprite = current_sprite; - if (sprite) { + if (sprite != NULL) { char buf[1024]; sprintf(buf, "Layer %d", get_max_layer_num(sprite->set)+1); return jstrdup(buf); @@ -387,9 +384,8 @@ char *GetUniqueLayerName(void) return NULL; } -Layer *FlattenLayers(void) +Layer *FlattenLayers(Sprite *sprite) { - Sprite *sprite = current_sprite; bool is_new_background = FALSE; JLink link, next; Layer *background; @@ -433,10 +429,8 @@ Layer *FlattenLayers(void) bgcolor = 0; /* open undo */ - if (undo_is_enabled(sprite->undo)) { - undo_set_label(sprite->undo, "Flatten Layers"); + if (undo_is_enabled(sprite->undo)) undo_open(sprite->undo); - } /* add the new layer */ if (is_new_background) { @@ -515,122 +509,55 @@ Layer *FlattenLayers(void) /* close the undo */ if (undo_is_enabled(sprite->undo)) undo_close(sprite->undo); - -#if 0 /* TODO why? */ - /* update all editors that has this sprite */ - update_screen_for_sprite(sprite); -#endif return background; } -void CropLayer(void) +void CropLayer(Layer *layer, int x, int y, int w, int h) { - Sprite *sprite = current_sprite; + Sprite *sprite = layer->sprite; + Cel *cel; + Image *image; + Image *new_image; + JLink link; - if ((sprite != NULL) && - (!mask_is_empty(sprite->mask)) && - (sprite->layer != NULL) && - (layer_is_image(sprite->layer))) { - Layer *layer = sprite->layer; - Cel *cel; - Image *image; - Layer *new_layer; - Cel *new_cel; - Image *new_image; - Layer *set = layer->parent_layer; - JLink link; + JI_LIST_FOR_EACH(layer->cels, link) { + cel = link->data; + image = stock_get_image(sprite->stock, cel->image); + if (image == NULL) + continue; - new_layer = layer_new(sprite); - if (!new_layer) { + new_image = image_crop(image, x-cel->x, y-cel->y, w, h, + app_get_color_to_clear_layer(layer)); + if (new_image == NULL) { console_printf(_("Not enough memory\n")); return; } - layer_set_name(new_layer, layer->name); - layer_set_blend_mode(new_layer, layer->blend_mode); - - JI_LIST_FOR_EACH(layer->cels, link) { - cel = link->data; - image = stock_get_image(sprite->stock, cel->image); - if (!image) - continue; - - new_cel = cel_new_copy(cel); - if (!new_cel) { - layer_free(new_layer); - console_printf(_("Not enough memory\n")); - return; - } - - new_image = image_crop(image, - sprite->mask->x-cel->x, - sprite->mask->y-cel->y, - sprite->mask->w, - sprite->mask->h); - if (!new_image) { - layer_free(new_layer); - cel_free(new_cel); - console_printf(_("Not enough memory\n")); - return; - } - - new_cel->image = stock_add_image(sprite->stock, new_image); - new_cel->x = sprite->mask->x; - new_cel->y = sprite->mask->y; - - layer_add_cel(new_layer, new_cel); - } - - /* add the new layer */ if (undo_is_enabled(sprite->undo)) { - undo_set_label(sprite->undo, "Layer Crop"); - undo_open(sprite->undo); - undo_add_layer(sprite->undo, set, new_layer); + undo_replace_image(sprite->undo, sprite->stock, cel->image); + undo_int(sprite->undo, (GfxObj *)cel, &cel->x); + undo_int(sprite->undo, (GfxObj *)cel, &cel->y); } - layer_add_layer(set, new_layer); + cel->x = x; + cel->y = y; - /* move it after the old one */ - if (undo_is_enabled(sprite->undo)) - undo_move_layer(sprite->undo, new_layer); - - layer_move_layer(set, new_layer, layer); - - /* set the new one as the current one */ - if (undo_is_enabled(sprite->undo)) - undo_set_layer(sprite->undo, sprite); - - sprite_set_layer(sprite, new_layer); - - /* remove the old layer */ - if (undo_is_enabled(sprite->undo)) { - undo_remove_layer(sprite->undo, layer); - undo_close(sprite->undo); - } - - layer_remove_layer(set, layer); - - layer_free_images(layer); - layer_free(layer); - - /* refresh */ - update_screen_for_sprite(sprite); + stock_replace_image(sprite->stock, cel->image, new_image); + image_free(image); } } /** * Converts the selected layer in a `Background' layer. */ -void BackgroundFromLayer(void) +void BackgroundFromLayer(Sprite *sprite) { - Sprite *sprite; int bgcolor; JLink link; Image *bg_image; Image *cel_image; - sprite = current_sprite; if (sprite == NULL) { console_printf("BackgroundFromLayer: there is not a current sprite selected\n"); return; @@ -666,10 +593,8 @@ void BackgroundFromLayer(void) bgcolor = app_get_bg_color(sprite); bgcolor = fixup_color_for_background(sprite->imgtype, bgcolor); - if (undo_is_enabled(sprite->undo)) { - undo_set_label(sprite->undo, "Background from Layer"); + if (undo_is_enabled(sprite->undo)) undo_open(sprite->undo); - } /* create a temporary image to draw each frame of the new `Background' layer */ @@ -742,11 +667,8 @@ void BackgroundFromLayer(void) undo_close(sprite->undo); } -void LayerFromBackground(void) +void LayerFromBackground(Sprite *sprite) { - Sprite *sprite; - - sprite = current_sprite; if (sprite == NULL) { console_printf("LayerFromBackground: there is not a current sprite selected\n"); return; @@ -783,7 +705,6 @@ void LayerFromBackground(void) } if (undo_is_enabled(sprite->undo)) { - undo_set_label(sprite->undo, "Layer from Background"); undo_open(sprite->undo); undo_data(sprite->undo, (GfxObj *)sprite->layer, @@ -1170,7 +1091,6 @@ void CropCel(void) /* undo */ if (undo_is_enabled(sprite->undo)) { - undo_set_label(sprite->undo, "Cel Crop"); undo_open(sprite->undo); undo_int(sprite->undo, (GfxObj *)cel, &cel->x); undo_int(sprite->undo, (GfxObj *)cel, &cel->y); @@ -1184,7 +1104,7 @@ void CropCel(void) sprite->mask->x-cel->x, sprite->mask->y-cel->y, sprite->mask->w, - sprite->mask->h); + sprite->mask->h, 0); image_free(image); /* destroy the old image */ diff --git a/src/script/functions.h b/src/script/functions.h index bbff39303..40ae36ec0 100644 --- a/src/script/functions.h +++ b/src/script/functions.h @@ -33,24 +33,24 @@ void SaveSprite(const char *filename); void SetSprite(struct Sprite *sprite); -void CropSprite(void); +void CropSprite(struct Sprite *sprite); /*===================================================================*/ /* Layer */ /*===================================================================*/ -struct Layer *NewLayer(void); -struct Layer *NewLayerSet(void); -void RemoveLayer(void); +struct Layer *NewLayer(struct Sprite *sprite); +struct Layer *NewLayerSet(struct Sprite *sprite); +void RemoveLayer(struct Sprite *sprite); -char *GetUniqueLayerName(void); +char *GetUniqueLayerName(struct Sprite *sprite); -struct Layer *FlattenLayers(void); +struct Layer *FlattenLayers(struct Sprite *sprite); -void CropLayer(void); +void CropLayer(struct Layer *layer, int x, int y, int w, int h); -void BackgroundFromLayer(void); -void LayerFromBackground(void); +void BackgroundFromLayer(struct Sprite *sprite); +void LayerFromBackground(struct Sprite *sprite); void MoveLayerAfter(struct Layer *layer, struct Layer *after_this); diff --git a/src/util/autocrop.c b/src/util/autocrop.c index a0dc76958..dfee809a8 100644 --- a/src/util/autocrop.c +++ b/src/util/autocrop.c @@ -18,18 +18,15 @@ #include "config.h" -#include "modules/sprites.h" #include "raster/image.h" #include "raster/mask.h" #include "raster/sprite.h" #include "script/functions.h" #include "util/autocrop.h" -void autocrop_sprite(void) +void autocrop_sprite(Sprite *sprite) { - Sprite *sprite = current_sprite; - - if (sprite) { + if (sprite != NULL) { int old_frame = sprite->frame; Mask *old_mask = sprite->mask; Mask *mask; @@ -40,7 +37,7 @@ void autocrop_sprite(void) x1 = y1 = INT_MAX; x2 = y2 = INT_MIN; - image = image_new (sprite->imgtype, sprite->w, sprite->h); + image = image_new(sprite->imgtype, sprite->w, sprite->h); if (!image) return; @@ -70,7 +67,7 @@ void autocrop_sprite(void) mask_replace(mask, x1, y1, x2-x1+1, y2-y1+1); sprite->mask = mask; - CropSprite(); + CropSprite(sprite); sprite->mask = old_mask; sprite_generate_mask_boundaries(sprite); diff --git a/src/util/autocrop.h b/src/util/autocrop.h index b93d7c12a..c1adb63fc 100644 --- a/src/util/autocrop.h +++ b/src/util/autocrop.h @@ -19,7 +19,7 @@ #ifndef UTIL_AUTOCROP_H #define UTIL_AUTOCROP_H -void autocrop_sprite (void); +void autocrop_sprite(Sprite *sprite); bool get_shrink_rect(int *x1, int *y1, int *x2, int *y2, Image *image, int refpixel); diff --git a/src/util/celmove.c b/src/util/celmove.c index 4f0fe93fa..4af5c1393 100644 --- a/src/util/celmove.c +++ b/src/util/celmove.c @@ -115,7 +115,7 @@ void move_cel(void) -src_cel->x, -src_cel->y, sprite->w, - sprite->h); + sprite->h, 0); if (undo_is_enabled(sprite->undo)) { undo_replace_image(sprite->undo, sprite->stock, src_cel->image); @@ -194,7 +194,7 @@ void copy_cel(void) -src_cel->x, -src_cel->y, sprite->w, - sprite->h); + sprite->h, 0); image_clear(dst_image, app_get_color_to_clear_layer(dst_layer)); image_merge(dst_image, src_image, src_cel->x, src_cel->y, 255, BLEND_MODE_NORMAL); diff --git a/src/widgets/editor/editor.c b/src/widgets/editor/editor.c index 1beb640e0..cb4f5c64a 100644 --- a/src/widgets/editor/editor.c +++ b/src/widgets/editor/editor.c @@ -184,9 +184,11 @@ void editor_set_scroll(JWidget widget, int x, int y, int use_refresh_region) jview_get_scroll(view, &new_scroll_x, &new_scroll_y); /* move screen with blits */ + jmouse_hide(); jwidget_scroll(widget, region, old_scroll_x - new_scroll_x, old_scroll_y - new_scroll_y); + jmouse_show(); jregion_free(region); /* editor->widget->flags &= ~JI_DIRTY; */