From 59ae779fca21ce0e9f03cd42442496800daae369 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 2 Jun 2009 14:08:56 +0000 Subject: [PATCH] + Added Context parameter to CurrentSprite. + Now CurrentSprite is defined in current_sprite.h. + Modified several routines to get the current sprite as parameter. --- ChangeLog | 4 ++ config.h | 6 +++ makefile.lst | 1 + src/ase/current_sprite.cpp | 60 +++++++++++++++++++++++++++ src/ase/current_sprite.h | 57 +++++++++++++++++++++++++ src/commands/cmd_copy_cel.cpp | 3 +- src/commands/cmd_mask_by_color.cpp | 3 +- src/commands/cmd_move_cel.cpp | 3 +- src/commands/commands.h | 1 + src/dialogs/aniedit.cpp | 2 +- src/dialogs/canvasze.cpp | 3 +- src/dialogs/canvasze.h | 4 +- src/dialogs/drawtext.cpp | 14 +++---- src/dialogs/drawtext.h | 5 ++- src/dialogs/maskcol.cpp | 40 +++++++++--------- src/dialogs/maskcol.h | 4 +- src/dialogs/vectmap.cpp | 3 +- src/dialogs/vectmap.h | 4 +- src/jinete/jwidget.cpp | 1 - src/jinete/themes/jstandard_theme.cpp | 6 +-- src/modules/editors.cpp | 1 + src/modules/sprites.cpp | 32 -------------- src/modules/sprites.h | 27 +----------- src/util/celmove.cpp | 12 +++--- src/util/celmove.h | 5 ++- src/util/functions.cpp | 1 + src/util/misc.cpp | 47 ++++++++++----------- src/util/misc.h | 2 +- 28 files changed, 214 insertions(+), 137 deletions(-) create mode 100644 src/ase/current_sprite.cpp create mode 100644 src/ase/current_sprite.h diff --git a/ChangeLog b/ChangeLog index 08c4fa41f..0c0f23fad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-06-01 David A. Capello + + * src/ase/current_sprite.h (CurrentSprite): Added. + 2009-05-31 David A. Capello * src/file/file.cpp (fop_free): Fixed a mutex-handle leak. diff --git a/config.h b/config.h index 7eb8de03b..21751b36d 100644 --- a/config.h +++ b/config.h @@ -38,6 +38,9 @@ const char *msgids_get(const char *id); /* src/intl/msgids.[ch] */ #define _(msgid) (msgids_get(msgid)) +// asserts +#include + #include #undef PI #define PI 3.14159265358979323846 @@ -48,6 +51,9 @@ typedef uint8_t ase_uint8; typedef uint16_t ase_uint16; typedef uint32_t ase_uint32; +////////////////////////////////////////////////////////////////////// +// Overloaded new/delete operators to detect memory-leaks + #if defined __cplusplus && defined MEMLEAK #include diff --git a/makefile.lst b/makefile.lst index 5ee87d3b7..ff459e639 100644 --- a/makefile.lst +++ b/makefile.lst @@ -7,6 +7,7 @@ ASE = aseprite$(EXE) COMMON_SOURCES = \ src/ase/context.cpp \ + src/ase/current_sprite.cpp \ src/ase/ui_context.cpp \ src/commands/cmd_about.cpp \ src/commands/cmd_advanced_mode.cpp \ diff --git a/src/ase/current_sprite.cpp b/src/ase/current_sprite.cpp new file mode 100644 index 000000000..855124af2 --- /dev/null +++ b/src/ase/current_sprite.cpp @@ -0,0 +1,60 @@ +/* ASE - Allegro Sprite Editor + * Copyright (C) 2001-2009 David Capello + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "config.h" + +#include "ase/context.h" +#include "ase/current_sprite.h" +#include "ase/ui_context.h" // TODO remove this line +#include "raster/sprite.h" + +CurrentSprite::CurrentSprite() +{ + m_context = UIContext::instance(); + m_sprite = m_context->get_current_sprite(); + if (m_sprite) + m_writeable = m_sprite->lock(); +} + +CurrentSprite::CurrentSprite(Context* context) +{ + assert(context != NULL); + + m_context = context; + m_sprite = m_context->get_current_sprite(); + if (m_sprite) + m_writeable = m_sprite->lock(); +} + +CurrentSprite::~CurrentSprite() +{ + if (m_sprite) + m_sprite->unlock(); +} + +void CurrentSprite::destroy() +{ + if (m_sprite) { + m_context->remove_sprite(m_sprite); + m_sprite->unlock(); + + delete m_sprite; + m_sprite = NULL; + m_writeable = false; + } +} diff --git a/src/ase/current_sprite.h b/src/ase/current_sprite.h new file mode 100644 index 000000000..6cddac178 --- /dev/null +++ b/src/ase/current_sprite.h @@ -0,0 +1,57 @@ +/* ASE - Allegro Sprite Editor + * Copyright (C) 2001-2009 David Capello + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef ASE_CURRENT_SPRITE_H +#define ASE_CURRENT_SPRITE_H + +#include + +class Context; +class Sprite; + +class CurrentSprite +{ + Context* m_context; + Sprite* m_sprite; + bool m_writeable; + + // // No-default constructor (undefined) + // CurrentSprite(); + + // Non-copyable + CurrentSprite(const CurrentSprite&); + CurrentSprite& operator=(const CurrentSprite&); + +public: + CurrentSprite(); + CurrentSprite(Context* context); + ~CurrentSprite(); + + bool writeable() const { return m_writeable; } + void destroy(); + + operator Sprite* () { return m_sprite; } + + Sprite* operator->() { + assert(m_sprite != NULL); + return m_sprite; + } + +}; + +#endif // ASE_CURRENT_SPRITE_H diff --git a/src/commands/cmd_copy_cel.cpp b/src/commands/cmd_copy_cel.cpp index 707203524..255c36b1d 100644 --- a/src/commands/cmd_copy_cel.cpp +++ b/src/commands/cmd_copy_cel.cpp @@ -31,7 +31,8 @@ static bool cmd_copy_cel_enabled(const char *argument) static void cmd_copy_cel_execute(const char *argument) { - copy_cel(); + CurrentSprite sprite; + copy_cel(sprite); } Command cmd_copy_cel = { diff --git a/src/commands/cmd_mask_by_color.cpp b/src/commands/cmd_mask_by_color.cpp index 70e329a99..2e5de7d5b 100644 --- a/src/commands/cmd_mask_by_color.cpp +++ b/src/commands/cmd_mask_by_color.cpp @@ -32,7 +32,8 @@ static bool cmd_mask_by_color_enabled(const char *argument) static void cmd_mask_by_color_execute(const char *argument) { - dialogs_mask_color(); + CurrentSprite sprite; + dialogs_mask_color(sprite); } Command cmd_mask_by_color = { diff --git a/src/commands/cmd_move_cel.cpp b/src/commands/cmd_move_cel.cpp index 96ed1be78..1372935f6 100644 --- a/src/commands/cmd_move_cel.cpp +++ b/src/commands/cmd_move_cel.cpp @@ -31,7 +31,8 @@ static bool cmd_move_cel_enabled(const char *argument) static void cmd_move_cel_execute(const char *argument) { - move_cel(); + CurrentSprite sprite; + move_cel(sprite); } Command cmd_move_cel = { diff --git a/src/commands/commands.h b/src/commands/commands.h index 1f39063f5..0693b967d 100644 --- a/src/commands/commands.h +++ b/src/commands/commands.h @@ -20,6 +20,7 @@ #define COMMANDS_COMMANDS_H #include "jinete/jbase.h" +#include "ase/current_sprite.h" #define CMD_ABOUT "about" #define CMD_ADVANCED_MODE "advanced_mode" diff --git a/src/dialogs/aniedit.cpp b/src/dialogs/aniedit.cpp index 97d4ef923..228dd0a82 100644 --- a/src/dialogs/aniedit.cpp +++ b/src/dialogs/aniedit.cpp @@ -639,7 +639,7 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg) /* move the cel */ else if (msg->mouse.left) { if (movement) { - move_cel(); + move_cel(anieditor->sprite); destroy_thumbnails(); anieditor_regenerate_layers(widget); diff --git a/src/dialogs/canvasze.cpp b/src/dialogs/canvasze.cpp index bb81f9c99..df810df1d 100644 --- a/src/dialogs/canvasze.cpp +++ b/src/dialogs/canvasze.cpp @@ -39,7 +39,7 @@ #include "widgets/colbut.h" #include "widgets/groupbut.h" -void canvas_resize() +void canvas_resize(Sprite* sprite) { JWidget window, box1, box2, box3, box4, box5, box6; JWidget label_w, label_h; @@ -47,7 +47,6 @@ void canvas_resize() JWidget check_w, check_h; JWidget button_offset; JWidget button_ok, button_cancel; - CurrentSprite sprite; if (!is_interactive () || !sprite) return; diff --git a/src/dialogs/canvasze.h b/src/dialogs/canvasze.h index fa5b228c6..95be34706 100644 --- a/src/dialogs/canvasze.h +++ b/src/dialogs/canvasze.h @@ -19,7 +19,9 @@ #ifndef DIALOGS_CANVASZE_H #define DIALOGS_CANVASZE_H -void canvas_resize(); +class Sprite; + +void canvas_resize(Sprite* sprite); #endif /* DIALOGS_CANVASZE_H */ diff --git a/src/dialogs/drawtext.cpp b/src/dialogs/drawtext.cpp index f122895df..910b61883 100644 --- a/src/dialogs/drawtext.cpp +++ b/src/dialogs/drawtext.cpp @@ -42,18 +42,17 @@ static JWidget font_button; -static Image *render_text(FONT *f, const char *text, int color); +static Image *render_text(Sprite* sprite, FONT *f, const char *text, int color); static FONT *my_load_font(const char *filename); static void button_font_command(JWidget widget); static void update_button_text(); -void dialogs_draw_text() +void dialogs_draw_text(Sprite* sprite) { Image *image, *dest_image; JWidget window, button_ok, color_box, color_but; JWidget entry_size, entry_text; - CurrentSprite sprite; char buf[256]; if (!is_interactive() || !sprite) @@ -136,7 +135,7 @@ void dialogs_draw_text() set_config_int("DrawText", "Size", size); /* render text */ - image = render_text(f, text, color); + image = render_text(sprite, f, text, color); if (image) { clipboard::copy_image(image, sprite_get_palette(sprite, sprite->frame)); clipboard::paste(sprite); @@ -152,7 +151,7 @@ void dialogs_draw_text() jwidget_free(window); } -Image *RenderText(const char *fontname, int size, int color, const char *text) +Image *RenderText(Sprite* sprite, const char *fontname, int size, int color, const char *text) { Image *render; FONT *f; @@ -163,14 +162,14 @@ Image *RenderText(const char *fontname, int size, int color, const char *text) ji_font_set_size(f, size); - render = render_text(f, text, color); + render = render_text(sprite, f, text, color); destroy_font(f); return render; } -static Image *render_text(FONT *f, const char *text, int color) +static Image *render_text(Sprite* sprite, FONT *f, const char *text, int color) { /* TODO warning this uses Image->dat and not Image->line */ #define DO(type, colfunc) \ @@ -186,7 +185,6 @@ static Image *render_text(FONT *f, const char *text, int color) } \ } - CurrentSprite sprite; int i, pixels, w, h; Image *image; BITMAP *bmp; diff --git a/src/dialogs/drawtext.h b/src/dialogs/drawtext.h index 49bae6664..774edc2b5 100644 --- a/src/dialogs/drawtext.h +++ b/src/dialogs/drawtext.h @@ -20,10 +20,11 @@ #define DIALOGS_DRAWTEXT_H class Image; +class Sprite; -void dialogs_draw_text(); +void dialogs_draw_text(Sprite* sprite); -Image* RenderText(const char* fontname, int size, int color, const char* text); +Image* RenderText(Sprite* sprite, const char* fontname, int size, int color, const char* text); #endif /* DIALOGS_DRAWTEXT_H */ diff --git a/src/dialogs/maskcol.cpp b/src/dialogs/maskcol.cpp index 6e46c2f41..2162f1a72 100644 --- a/src/dialogs/maskcol.cpp +++ b/src/dialogs/maskcol.cpp @@ -49,16 +49,15 @@ static bool color_change_hook(JWidget widget, void *data); static bool slider_change_hook(JWidget widget, void *data); static bool preview_change_hook(JWidget widget, void *data); -static Mask *gen_mask(); -static void mask_preview(); +static Mask *gen_mask(Sprite* sprite); +static void mask_preview(Sprite* sprite); -void dialogs_mask_color() +void dialogs_mask_color(Sprite* sprite) { JWidget window, box1, box2, box3, box4; JWidget label_color, button_1, button_2; JWidget label_fuzziness; JWidget button_ok, button_cancel; - CurrentSprite sprite; Image *image; if (!is_interactive () || !sprite) @@ -90,12 +89,15 @@ void dialogs_mask_color() if (get_config_bool("MaskColor", "Preview", TRUE)) jwidget_select(check_preview); + button_1->user_data[1] = sprite; + button_2->user_data[1] = sprite; + jbutton_add_command(button_1, button_1_command); jbutton_add_command(button_2, button_2_command); - HOOK(button_color, SIGNAL_COLORBUTTON_CHANGE, color_change_hook, 0); - HOOK(slider_fuzziness, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); - HOOK(check_preview, JI_SIGNAL_CHECK_CHANGE, preview_change_hook, 0); + HOOK(button_color, SIGNAL_COLORBUTTON_CHANGE, color_change_hook, sprite); + HOOK(slider_fuzziness, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, sprite); + HOOK(check_preview, JI_SIGNAL_CHECK_CHANGE, preview_change_hook, sprite); jwidget_magnetic(button_ok, TRUE); jwidget_expansive(button_color, TRUE); @@ -113,7 +115,7 @@ void dialogs_mask_color() jwindow_center(window); /* mask first preview */ - mask_preview(); + mask_preview(sprite); /* load window configuration */ load_window_pos(window, "MaskColor"); @@ -131,7 +133,7 @@ void dialogs_mask_color() } /* change the mask */ - mask = gen_mask(); + mask = gen_mask(sprite); sprite_set_mask(sprite, mask); mask_free(mask); @@ -159,38 +161,37 @@ static void button_1_command(JWidget widget) { colorbutton_set_color(button_color, colorbar_get_fg_color(app_get_colorbar())); - mask_preview(); + mask_preview((Sprite*)widget->user_data[1]); } static void button_2_command(JWidget widget) { colorbutton_set_color(button_color, colorbar_get_bg_color(app_get_colorbar())); - mask_preview(); + mask_preview((Sprite*)widget->user_data[1]); } static bool color_change_hook(JWidget widget, void *data) { - mask_preview(); + mask_preview((Sprite*)data); return FALSE; } static bool slider_change_hook(JWidget widget, void *data) { - mask_preview(); + mask_preview((Sprite*)data); return FALSE; } static bool preview_change_hook(JWidget widget, void *data) { - mask_preview(); + mask_preview((Sprite*)data); return FALSE; } -static Mask *gen_mask() +static Mask *gen_mask(Sprite* sprite) { int xpos, ypos, color, fuzziness; - CurrentSprite sprite; Image* image = GetImage2(sprite, &xpos, &ypos, NULL); @@ -205,11 +206,10 @@ static Mask *gen_mask() return mask; } -static void mask_preview() +static void mask_preview(Sprite* sprite) { - if (jwidget_is_selected (check_preview)) { - CurrentSprite sprite; - Mask *mask = gen_mask(); + if (jwidget_is_selected(check_preview)) { + Mask *mask = gen_mask(sprite); Mask *old_mask = sprite->mask; sprite->mask = mask; diff --git a/src/dialogs/maskcol.h b/src/dialogs/maskcol.h index 6fe74bf50..beb365949 100644 --- a/src/dialogs/maskcol.h +++ b/src/dialogs/maskcol.h @@ -19,6 +19,8 @@ #ifndef DIALOGS_MASKCOL_H #define DIALOGS_MASKCOL_H -void dialogs_mask_color(); +class Sprite; + +void dialogs_mask_color(Sprite* sprite); #endif /* DIALOGS_MASKCOL_H */ diff --git a/src/dialogs/vectmap.cpp b/src/dialogs/vectmap.cpp index dd7891ce6..542d16007 100644 --- a/src/dialogs/vectmap.cpp +++ b/src/dialogs/vectmap.cpp @@ -123,11 +123,10 @@ static int image_getpixel4 (Image *image, double x, double y) return bilinear4(a, b, c, d, ftofix(x), ftofix(y)); } -void dialogs_vector_map() +void dialogs_vector_map(Sprite* sprite) { #define PROJECT() project(image, x, y, dmax, &u, &v) - CurrentSprite sprite; Image *image, *image_copy; double u, v, dmax; int c, x, y; diff --git a/src/dialogs/vectmap.h b/src/dialogs/vectmap.h index 7610568e2..8e0b813ac 100644 --- a/src/dialogs/vectmap.h +++ b/src/dialogs/vectmap.h @@ -19,6 +19,8 @@ #ifndef DIALOGS_VECTMAP_H #define DIALOGS_VECTMAP_H -void dialogs_vector_map(); +class Sprite; + +void dialogs_vector_map(Sprite* sprite); #endif /* DIALOGS_VECTMAP_H */ diff --git a/src/jinete/jwidget.cpp b/src/jinete/jwidget.cpp index 4384e1c24..715166830 100644 --- a/src/jinete/jwidget.cpp +++ b/src/jinete/jwidget.cpp @@ -351,7 +351,6 @@ void jwidget::set_text_quiet(const char *text) void jwidget::align(int align) { m_align = align; - dirty(); } FONT *jwidget::font() diff --git a/src/jinete/themes/jstandard_theme.cpp b/src/jinete/themes/jstandard_theme.cpp index bc4dbd216..e41ba828d 100644 --- a/src/jinete/themes/jstandard_theme.cpp +++ b/src/jinete/themes/jstandard_theme.cpp @@ -398,6 +398,7 @@ static void theme_init_widget(JWidget widget) case JI_SLIDER: BORDER(4); widget->child_spacing = jwidget_get_text_height(widget); + widget->align(JI_CENTER | JI_MIDDLE); break; case JI_TEXTBOX: @@ -1146,8 +1147,7 @@ static void theme_draw_slider(JWidget widget, JRect clip) usprintf(buf, "%d", value); - widget->align(JI_CENTER | JI_MIDDLE); - widget->text(buf); + widget->set_text_quiet(buf); r = jrect_new(x1, y1, x2+1, y2+1); @@ -1172,7 +1172,7 @@ static void theme_draw_slider(JWidget widget, JRect clip) set_clip(ji_screen, cx1, cy1, cx2, cy2); - widget->text(old_text.c_str()); + widget->set_text_quiet(old_text.c_str()); jrect_free(r); } } diff --git a/src/modules/editors.cpp b/src/modules/editors.cpp index 57fbe40ca..c40832796 100644 --- a/src/modules/editors.cpp +++ b/src/modules/editors.cpp @@ -20,6 +20,7 @@ #include "jinete/jinete.h" +#include "ase/current_sprite.h" #include "ase/ui_context.h" #include "core/app.h" #include "modules/editors.h" diff --git a/src/modules/sprites.cpp b/src/modules/sprites.cpp index e9fd2e5fa..1e593ca67 100644 --- a/src/modules/sprites.cpp +++ b/src/modules/sprites.cpp @@ -38,38 +38,6 @@ static void layer_get_pos(Sprite* sprite, Layer *layer, int target, bool write, ////////////////////////////////////////////////////////////////////// -CurrentSprite::CurrentSprite() -{ - UIContext* context = UIContext::instance(); - - m_sprite = context->get_current_sprite(); - if (m_sprite) - m_writeable = m_sprite->lock(); -} - -CurrentSprite::~CurrentSprite() -{ - if (m_sprite) - m_sprite->unlock(); -} - -void CurrentSprite::destroy() -{ - if (m_sprite) { - UIContext* context = UIContext::instance(); - - context->remove_sprite(m_sprite); - - m_sprite->unlock(); - - delete m_sprite; - m_sprite = NULL; - m_writeable = false; - } -} - -////////////////////////////////////////////////////////////////////// - ImageRef *images_ref_get_from_sprite(Sprite* sprite, int target, bool write) { Layer *layer = target & TARGET_ALL_LAYERS ? sprite->set: diff --git a/src/modules/sprites.h b/src/modules/sprites.h index 4186758fa..dba01ce81 100644 --- a/src/modules/sprites.h +++ b/src/modules/sprites.h @@ -19,11 +19,7 @@ #ifndef MODULES_SPRITES_H #define MODULES_SPRITES_H -#include - -#include "jinete/jbase.h" -#include "raster/sprite.h" - +class Sprite; class Image; class Layer; class Cel; @@ -36,27 +32,6 @@ struct ImageRef ImageRef* next; }; -class CurrentSprite -{ - Sprite* m_sprite; - bool m_writeable; - -public: - CurrentSprite(); - ~CurrentSprite(); - - bool writeable() const { return m_writeable; } - void destroy(); - - operator Sprite* () { return m_sprite; } - - Sprite* operator->() { - assert(m_sprite != NULL); - return m_sprite; - } - -}; - ImageRef* images_ref_get_from_sprite(Sprite* sprite, int target, bool write); void images_ref_free(ImageRef* image_ref); diff --git a/src/util/celmove.cpp b/src/util/celmove.cpp index d5ae7ac31..a94fbb894 100644 --- a/src/util/celmove.cpp +++ b/src/util/celmove.cpp @@ -37,8 +37,8 @@ #include "util/celmove.h" #include "util/functions.h" -/* these variables indicate what cel to move (and the current_sprite - frame indicates to where move it) */ +/* these variables indicate what cel to move (and the sprite's + frame indicates where to move it) */ static Layer *src_layer = NULL; /* TODO warning not thread safe */ static Layer *dst_layer = NULL; static int src_frame = 0; @@ -53,9 +53,8 @@ void set_frame_to_handle(Layer *_src_layer, int _src_frame, dst_frame = _dst_frame; } -void move_cel() +void move_cel(Sprite* sprite) { - CurrentSprite sprite; Cel *src_cel, *dst_cel; assert(src_layer != NULL); @@ -64,7 +63,7 @@ void move_cel() assert(dst_frame >= 0 && dst_frame < sprite->frames); if (layer_is_background(src_layer)) { - copy_cel(); + copy_cel(sprite); return; } @@ -145,9 +144,8 @@ void move_cel() set_frame_to_handle(NULL, 0, NULL, 0); } -void copy_cel() +void copy_cel(Sprite* sprite) { - CurrentSprite sprite; Cel *src_cel, *dst_cel; assert(src_layer != NULL); diff --git a/src/util/celmove.h b/src/util/celmove.h index c42fdb4bc..1f7b18253 100644 --- a/src/util/celmove.h +++ b/src/util/celmove.h @@ -21,12 +21,13 @@ class Cel; class Layer; +class Sprite; void set_frame_to_handle(Layer* src_layer, int src_frame, Layer* dst_layer, int dst_frame); -void move_cel(); -void copy_cel(); +void move_cel(Sprite* sprite); +void copy_cel(Sprite* sprite); #endif /* UTIL_CELMOVE_H */ diff --git a/src/util/functions.cpp b/src/util/functions.cpp index 070d04594..ff6e79b72 100644 --- a/src/util/functions.cpp +++ b/src/util/functions.cpp @@ -21,6 +21,7 @@ #include #include "jinete/jinete.h" +#include "ase/current_sprite.h" #include "ase/ui_context.h" #include "console/console.h" #include "core/app.h" diff --git a/src/util/misc.cpp b/src/util/misc.cpp index 4c93de594..f5ec392df 100644 --- a/src/util/misc.cpp +++ b/src/util/misc.cpp @@ -81,39 +81,38 @@ Image* GetImage2(Sprite* sprite, int* x, int* y, int* opacity) return image; } -void LoadPalette(const char *filename) +void LoadPalette(Sprite* sprite, const char *filename) { - CurrentSprite sprite; - if (sprite) { - DIRS *dir, *dirs; - char buf[512]; + assert(sprite != NULL); - dirs = dirs_new(); - dirs_add_path(dirs, filename); + DIRS *dir, *dirs; + char buf[512]; - usprintf(buf, "palettes/%s", filename); - dirs_cat_dirs(dirs, filename_in_datadir (buf)); + dirs = dirs_new(); + dirs_add_path(dirs, filename); - for (dir=dirs; dir; dir=dir->next) { - if (exists(dir->path)) { - Palette *pal = palette_load(dir->path); - if (pal != NULL) { - /* set the palette calling the hooks */ - set_current_palette(pal, FALSE); + usprintf(buf, "palettes/%s", filename); + dirs_cat_dirs(dirs, filename_in_datadir (buf)); - /* just one palette */ - sprite_reset_palettes(sprite); - sprite_set_palette(sprite, pal, 0); + for (dir=dirs; dir; dir=dir->next) { + if (exists(dir->path)) { + Palette *pal = palette_load(dir->path); + if (pal != NULL) { + /* set the palette calling the hooks */ + set_current_palette(pal, FALSE); - /* redraw the entire screen */ - jmanager_refresh_screen(); - } - break; + /* just one palette */ + sprite_reset_palettes(sprite); + sprite_set_palette(sprite, pal, 0); + + /* redraw the entire screen */ + jmanager_refresh_screen(); } + break; } - - dirs_free(dirs); } + + dirs_free(dirs); } /* returns a new layer created from the current mask in the current diff --git a/src/util/misc.h b/src/util/misc.h index 69b080e2e..1695f0680 100644 --- a/src/util/misc.h +++ b/src/util/misc.h @@ -31,7 +31,7 @@ class Undo; Image* GetImage(Sprite* sprite); Image* GetImage2(Sprite* sprite, int *x, int *y, int *opacity); -void LoadPalette(const char* filename); +void LoadPalette(Sprite* sprite, const char* filename); Layer* NewLayerFromMask(Sprite* src, Sprite* dst); Image* NewImageFromMask(Sprite* src);