mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-30 04:20:23 +00:00
+ CurrentSprite class was split in SpriteWrapper/Reader/Writer, and CurrentSpriteReader/Writer wrappers.
+ More routines are using exceptions for error handling. + Added JWidgetPtr class. + Added Undoable::set_imgtype/layer_from_background/flatten_layers.
This commit is contained in:
parent
d157131d4a
commit
3885f37f45
21
ChangeLog
21
ChangeLog
@ -1,7 +1,28 @@
|
||||
2009-06-11 David A. Capello <davidcapello@gmail.com>
|
||||
|
||||
* src/modules/gui.h (JWidgetPtr): Added to automatically delete
|
||||
the widget in the destructor.
|
||||
|
||||
* src/modules/gui.cpp (load_widget/get_widgets): In case of error
|
||||
now they throw an exception.
|
||||
|
||||
* src/sprite_wrappers.h: CurrentSprite class was split in
|
||||
SpriteWrapper/Reader/Writer, and CurrentSpriteReader/Writer
|
||||
wrappers.
|
||||
|
||||
* src/console/console.h (Console): Added the class to
|
||||
automatically open/close the console (with RAII idiom).
|
||||
|
||||
2009-06-10 David A. Capello <davidcapello@gmail.com>
|
||||
|
||||
* src/modules/palettes.h: Added CurrentSpriteRgbMap class.
|
||||
|
||||
2009-06-04 David A. Capello <davidcapello@gmail.com>
|
||||
|
||||
* src/raster/sprite.h (Sprite): Added m_write_lock and
|
||||
m_read_locks members. Added lock(bool) and lock_to_write()
|
||||
methods.
|
||||
|
||||
2009-06-01 David A. Capello <davidcapello@gmail.com>
|
||||
|
||||
* src/ase/current_sprite.h (CurrentSprite): Added.
|
||||
|
@ -126,7 +126,12 @@
|
||||
</menu>
|
||||
<menu name="&Sprite">
|
||||
<item command="sprite_properties" name="&Properties..." />
|
||||
<item command="change_image_type" name="Color &Mode..." />
|
||||
<menu name name="Color &Mode">
|
||||
<item command="change_image_type" name="&RGB Color" argument="rgb" />
|
||||
<item command="change_image_type" name="&Grayscale" argument="grayscale" />
|
||||
<item command="change_image_type" name="&Indexed (No Dithering)" argument="indexed" />
|
||||
<item command="change_image_type" name="Indexed (Ordered &Dither)" argument="indexed-dither" />
|
||||
</menu>
|
||||
<separator />
|
||||
<item command="duplicate_sprite" name="&Duplicate..." />
|
||||
<separator />
|
||||
|
@ -1,25 +0,0 @@
|
||||
<!-- ASE - Allegro Sprite Editor -->
|
||||
<!-- Copyright (C) 2001-2009 by David Capello -->
|
||||
<jinete>
|
||||
<window text="Convert Color" name="image_type">
|
||||
<box vertical>
|
||||
<box vertical expansive>
|
||||
<box horizontal>
|
||||
<label text="From:" />
|
||||
<label text="" name="from" />
|
||||
</box>
|
||||
<label text="To:" />
|
||||
<radio name="imgtype1" text="&RGB Color" group=1 />
|
||||
<radio name="imgtype2" text="&Grayscale" group=1 />
|
||||
<radio name="imgtype3" text="&Indexed" group=1 />
|
||||
<separator horizontal />
|
||||
<radio name="dither1" text="&No Dithering" group=2 />
|
||||
<radio name="dither2" text="&Ordered Dither" group=2 />
|
||||
</box>
|
||||
<box horizontal expansive homogeneous>
|
||||
<button text="&OK" name="ok" magnetic />
|
||||
<button text="&Cancel" />
|
||||
</box>
|
||||
</box>
|
||||
</window>
|
||||
</jinete>
|
@ -190,14 +190,12 @@ COMMON_SOURCES = \
|
||||
src/raster/sprite.cpp \
|
||||
src/raster/stock.cpp \
|
||||
src/raster/undo.cpp \
|
||||
src/raster/undoable.cpp \
|
||||
src/util/autocrop.cpp \
|
||||
src/util/boundary.cpp \
|
||||
src/util/celmove.cpp \
|
||||
src/util/clipboard.cpp \
|
||||
src/util/col_file.cpp \
|
||||
src/util/filetoks.cpp \
|
||||
src/util/functions.cpp \
|
||||
src/util/hash.cpp \
|
||||
src/util/misc.cpp \
|
||||
src/util/msk_file.cpp \
|
||||
@ -235,7 +233,10 @@ COMMON_OBJS = $(addprefix $(OBJ_DIR)/, \
|
||||
$(addsuffix $(OBJ), \
|
||||
$(notdir $(basename $(COMMON_SOURCES)))))
|
||||
|
||||
ASE_SOURCES = src/main.cpp $(COMMON_SOURCES)
|
||||
ASE_SOURCES = \
|
||||
src/main.cpp \
|
||||
src/undoable.cpp \
|
||||
$(COMMON_SOURCES)
|
||||
|
||||
ASE_OBJS = $(addprefix $(OBJ_DIR)/, \
|
||||
$(addsuffix $(OBJ), \
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <list>
|
||||
|
||||
class Sprite;
|
||||
class SpriteReader;
|
||||
|
||||
typedef std::list<Sprite*> SpriteList;
|
||||
|
||||
@ -42,6 +43,11 @@ public:
|
||||
Context();
|
||||
virtual ~Context();
|
||||
|
||||
virtual bool is_ui_available() const { return false; }
|
||||
virtual bool is_recording_macro() const { return false; }
|
||||
virtual bool is_executing_macro() const { return false; }
|
||||
virtual bool is_executing_script() const { return false; }
|
||||
|
||||
const SpriteList& get_sprite_list() const;
|
||||
Sprite* get_first_sprite() const;
|
||||
Sprite* get_next_sprite(Sprite* sprite) const;
|
||||
|
@ -1,60 +0,0 @@
|
||||
/* 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;
|
||||
}
|
||||
}
|
@ -31,6 +31,8 @@ public:
|
||||
UIContext();
|
||||
virtual ~UIContext();
|
||||
|
||||
virtual bool is_ui_available() const { return true; }
|
||||
|
||||
void show_sprite(Sprite* sprite) const;
|
||||
|
||||
protected:
|
||||
|
@ -16,42 +16,40 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef ASE_CURRENT_SPRITE_H
|
||||
#define ASE_CURRENT_SPRITE_H
|
||||
#ifndef ASE_EXCEPTION_H
|
||||
#define ASE_EXCEPTION_H
|
||||
|
||||
#include <list>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include "console/console.h"
|
||||
|
||||
class Context;
|
||||
class Sprite;
|
||||
|
||||
class CurrentSprite
|
||||
class ase_exception : public std::exception
|
||||
{
|
||||
Context* m_context;
|
||||
Sprite* m_sprite;
|
||||
bool m_writeable;
|
||||
|
||||
// // No-default constructor (undefined)
|
||||
// CurrentSprite();
|
||||
|
||||
// Non-copyable
|
||||
CurrentSprite(const CurrentSprite&);
|
||||
CurrentSprite& operator=(const CurrentSprite&);
|
||||
std::string m_msg;
|
||||
|
||||
public:
|
||||
CurrentSprite();
|
||||
CurrentSprite(Context* context);
|
||||
~CurrentSprite();
|
||||
|
||||
bool writeable() const { return m_writeable; }
|
||||
void destroy();
|
||||
ase_exception(const char* msg) throw()
|
||||
: m_msg(msg)
|
||||
{
|
||||
}
|
||||
|
||||
operator Sprite* () { return m_sprite; }
|
||||
ase_exception(const std::string& msg) throw()
|
||||
: m_msg(msg)
|
||||
{
|
||||
}
|
||||
|
||||
Sprite* operator->() {
|
||||
assert(m_sprite != NULL);
|
||||
return m_sprite;
|
||||
void show()
|
||||
{
|
||||
Console console;
|
||||
console.printf("An error ocurred executing the command.\n\nDetails:\n%s", what());
|
||||
}
|
||||
|
||||
const char* what() const throw()
|
||||
{
|
||||
return m_msg.c_str();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // ASE_CURRENT_SPRITE_H
|
||||
#endif // ASE_EXCEPTION_H
|
@ -25,16 +25,18 @@
|
||||
#include "commands/commands.h"
|
||||
#include "core/core.h"
|
||||
#include "core/dirs.h"
|
||||
#include "modules/gui.h"
|
||||
|
||||
static char *read_authors_txt(const char *filename);
|
||||
|
||||
static void cmd_about_execute(const char *argument)
|
||||
{
|
||||
JWidget window, box1, label1, label2, separator1;
|
||||
JWidget box1, label1, label2, separator1;
|
||||
JWidget textbox, view, separator2;
|
||||
JWidget label3, label4, box2, box3, box4, button1;
|
||||
char *authors_txt = read_authors_txt("AUTHORS.txt");
|
||||
|
||||
JWidgetPtr window;
|
||||
if (authors_txt)
|
||||
window = jwindow_new_desktop();
|
||||
else
|
||||
@ -86,7 +88,6 @@ static void cmd_about_execute(const char *argument)
|
||||
button1->border_width.b);
|
||||
|
||||
jwindow_open_fg(window);
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
static char *read_authors_txt(const char *filename)
|
||||
|
@ -52,18 +52,13 @@ static void cmd_advanced_mode_execute(const char *argument)
|
||||
if (advanced_mode &&
|
||||
get_config_bool("AdvancedMode", "Warning", TRUE)) {
|
||||
Command *cmd_advanced_mode = command_get_by_name(CMD_ADVANCED_MODE);
|
||||
JWidget window, warning_label, donot_show;
|
||||
char warning[1024];
|
||||
char key[1024];
|
||||
char buf[1024];
|
||||
|
||||
/* load the window widget */
|
||||
window = load_widget("advanced.jid", "advanced_mode_warning");
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
warning_label = jwidget_find_name(window, "warning_label");
|
||||
donot_show = jwidget_find_name(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);
|
||||
@ -75,8 +70,6 @@ static void cmd_advanced_mode_execute(const char *argument)
|
||||
|
||||
set_config_bool("AdvancedMode", "Warning",
|
||||
!jwidget_is_selected(donot_show));
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,12 +24,12 @@
|
||||
#include "modules/sprites.h"
|
||||
#include "raster/layer.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/undoable.h"
|
||||
#include "undoable.h"
|
||||
#include "widgets/colbar.h"
|
||||
|
||||
static bool cmd_background_from_layer_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL &&
|
||||
sprite->layer != NULL &&
|
||||
@ -41,7 +41,7 @@ static bool cmd_background_from_layer_enabled(const char *argument)
|
||||
|
||||
static void cmd_background_from_layer_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
|
||||
// each frame of the layer to be converted as `Background' must be
|
||||
// cleared using the selected background color in the color-bar
|
||||
|
@ -29,34 +29,28 @@
|
||||
#include "raster/image.h"
|
||||
#include "raster/mask.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/undoable.h"
|
||||
#include "undoable.h"
|
||||
#include "widgets/colbar.h"
|
||||
|
||||
static bool cmd_canvas_size_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_canvas_size_execute(const char *argument)
|
||||
{
|
||||
JWidget window, left, top, right, bottom, ok;
|
||||
CurrentSprite sprite;
|
||||
JWidget left, top, right, bottom, ok;
|
||||
CurrentSpriteWriter sprite;
|
||||
|
||||
// load the window widget
|
||||
window = load_widget("canvas.jid", "canvas_size");
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
if (!get_widgets(window,
|
||||
"left", &left,
|
||||
"top", &top,
|
||||
"right", &right,
|
||||
"bottom", &bottom,
|
||||
"ok", &ok, NULL)) {
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
JWidgetPtr window = load_widget("canvas.jid", "canvas_size");
|
||||
get_widgets(window,
|
||||
"left", &left,
|
||||
"top", &top,
|
||||
"right", &right,
|
||||
"bottom", &bottom,
|
||||
"ok", &ok, NULL);
|
||||
|
||||
jwindow_remap(window);
|
||||
jwindow_center(window);
|
||||
@ -85,8 +79,6 @@ static void cmd_canvas_size_execute(const char *argument)
|
||||
sprite_generate_mask_boundaries(sprite);
|
||||
update_screen_for_sprite(sprite);
|
||||
}
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
Command cmd_canvas_size = {
|
||||
|
@ -36,13 +36,12 @@
|
||||
|
||||
static bool cmd_cel_properties_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite && sprite->layer;
|
||||
}
|
||||
|
||||
static void cmd_cel_properties_execute(const char *argument)
|
||||
{
|
||||
JWidget window = NULL;
|
||||
JWidget label_frame, label_pos, label_size;
|
||||
JWidget slider_opacity, button_ok;
|
||||
Layer *layer;
|
||||
@ -51,31 +50,25 @@ static void cmd_cel_properties_execute(const char *argument)
|
||||
int memsize;
|
||||
|
||||
/* get current sprite */
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
if (!sprite)
|
||||
return;
|
||||
|
||||
/* get selected layer */
|
||||
layer = sprite->layer;
|
||||
if (!layer)
|
||||
goto done;
|
||||
return;
|
||||
|
||||
/* get current cel (can be NULL) */
|
||||
cel = layer_get_cel(layer, sprite->frame);
|
||||
|
||||
window = load_widget("celprop.jid", "cel_properties");
|
||||
if (!window)
|
||||
goto done;
|
||||
|
||||
if (!get_widgets(window,
|
||||
"frame", &label_frame,
|
||||
"pos", &label_pos,
|
||||
"size", &label_size,
|
||||
"opacity", &slider_opacity,
|
||||
"ok", &button_ok, NULL)) {
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
JWidgetPtr window = load_widget("celprop.jid", "cel_properties");
|
||||
get_widgets(window,
|
||||
"frame", &label_frame,
|
||||
"pos", &label_pos,
|
||||
"size", &label_size,
|
||||
"opacity", &slider_opacity,
|
||||
"ok", &button_ok, NULL);
|
||||
|
||||
/* if the layer isn't writable */
|
||||
if (!layer_is_writable(layer)) {
|
||||
@ -141,10 +134,6 @@ static void cmd_cel_properties_execute(const char *argument)
|
||||
update_screen_for_sprite(sprite);
|
||||
}
|
||||
}
|
||||
|
||||
done:;
|
||||
if (window)
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
Command cmd_cel_properties = {
|
||||
|
@ -18,89 +18,57 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "jinete/jinete.h"
|
||||
#include <allegro/unicode.h>
|
||||
|
||||
#include "commands/commands.h"
|
||||
#include "core/app.h"
|
||||
#include "core/cfg.h"
|
||||
#include "modules/gui.h"
|
||||
#include "modules/palettes.h"
|
||||
#include "modules/sprites.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/quant.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "undoable.h"
|
||||
|
||||
static bool cmd_change_image_type_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL &&
|
||||
argument != NULL &&
|
||||
((ustrcmp(argument, "rgb") == 0 && sprite->imgtype != IMAGE_RGB) ||
|
||||
(ustrcmp(argument, "grayscale") == 0 && sprite->imgtype != IMAGE_GRAYSCALE) ||
|
||||
(ustrncmp(argument, "indexed", 7) == 0 && sprite->imgtype != IMAGE_INDEXED));
|
||||
}
|
||||
|
||||
static void cmd_change_image_type_execute(const char *argument)
|
||||
{
|
||||
JWidget window, from, radio1, radio2, radio3, dither1, dither2;
|
||||
CurrentSprite current_sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
int destimgtype = sprite->imgtype;
|
||||
int dithermethod = DITHERING_NONE;
|
||||
|
||||
/* load the window widget */
|
||||
window = load_widget("imgtype.jid", "image_type");
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
from = jwidget_find_name(window, "from");
|
||||
radio1 = jwidget_find_name(window, "imgtype1");
|
||||
radio2 = jwidget_find_name(window, "imgtype2");
|
||||
radio3 = jwidget_find_name(window, "imgtype3");
|
||||
dither1 = jwidget_find_name(window, "dither1");
|
||||
dither2 = jwidget_find_name(window, "dither2");
|
||||
|
||||
if (current_sprite->imgtype == IMAGE_RGB) {
|
||||
jwidget_set_text(from, _("RGB"));
|
||||
jwidget_disable(radio1);
|
||||
jwidget_select(radio3); /* to Indexed by default */
|
||||
if (ustrcmp(argument, "rgb") == 0) {
|
||||
destimgtype = IMAGE_RGB;
|
||||
}
|
||||
else if (current_sprite->imgtype == IMAGE_GRAYSCALE) {
|
||||
jwidget_set_text(from, _("Grayscale"));
|
||||
jwidget_disable(radio2);
|
||||
jwidget_select(radio1); /* to RGB by default */
|
||||
else if (ustrcmp(argument, "grayscale") == 0) {
|
||||
destimgtype = IMAGE_GRAYSCALE;
|
||||
}
|
||||
else if (current_sprite->imgtype == IMAGE_INDEXED) {
|
||||
jwidget_set_text(from, _("Indexed"));
|
||||
jwidget_disable(radio3);
|
||||
jwidget_select(radio1); /* to RGB by default */
|
||||
else if (ustrcmp(argument, "indexed") == 0) {
|
||||
destimgtype = IMAGE_INDEXED;
|
||||
}
|
||||
else if (ustrcmp(argument, "indexed-dither") == 0) {
|
||||
destimgtype = IMAGE_INDEXED;
|
||||
dithermethod = DITHERING_ORDERED;
|
||||
}
|
||||
|
||||
if (get_config_bool("Options", "Dither", FALSE))
|
||||
jwidget_select(dither2);
|
||||
else
|
||||
jwidget_select(dither1);
|
||||
|
||||
/* open the window */
|
||||
jwindow_open_fg(window);
|
||||
|
||||
if (jwindow_get_killer(window) == jwidget_find_name(window, "ok")) {
|
||||
int destimgtype, dithermethod;
|
||||
|
||||
if (jwidget_is_selected(radio1))
|
||||
destimgtype = IMAGE_RGB;
|
||||
else if (jwidget_is_selected(radio2))
|
||||
destimgtype = IMAGE_GRAYSCALE;
|
||||
else
|
||||
destimgtype = IMAGE_INDEXED;
|
||||
|
||||
if (jwidget_is_selected(dither1))
|
||||
dithermethod = DITHERING_NONE;
|
||||
else
|
||||
dithermethod = DITHERING_ORDERED;
|
||||
|
||||
{
|
||||
CurrentSpriteRgbMap rgbmap;
|
||||
sprite_set_imgtype(current_sprite, destimgtype, dithermethod);
|
||||
}
|
||||
|
||||
app_refresh_screen();
|
||||
{
|
||||
CurrentSpriteRgbMap rgbmap;
|
||||
Undoable undoable(sprite, "Color Mode Change");
|
||||
undoable.set_imgtype(destimgtype, dithermethod);
|
||||
undoable.commit();
|
||||
}
|
||||
|
||||
jwidget_free(window);
|
||||
app_refresh_screen(sprite);
|
||||
}
|
||||
|
||||
Command cmd_change_image_type = {
|
||||
|
@ -25,12 +25,12 @@
|
||||
#include "raster/layer.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/undo.h"
|
||||
#include "raster/undoable.h"
|
||||
#include "undoable.h"
|
||||
#include "widgets/colbar.h"
|
||||
|
||||
static bool cmd_clear_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL &&
|
||||
sprite->layer != NULL &&
|
||||
@ -41,16 +41,12 @@ static bool cmd_clear_enabled(const char *argument)
|
||||
|
||||
static void cmd_clear_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
if (!sprite)
|
||||
return;
|
||||
|
||||
CurrentSpriteWriter sprite;
|
||||
{
|
||||
Undoable undoable(sprite, "Clear");
|
||||
undoable.clear_mask(app_get_color_to_clear_layer(sprite->layer));
|
||||
undoable.commit();
|
||||
}
|
||||
|
||||
update_screen_for_sprite(sprite);
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ static bool close_current_sprite();
|
||||
|
||||
static bool cmd_close_file_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite != NULL;
|
||||
}
|
||||
|
||||
@ -75,9 +75,7 @@ static void cmd_close_all_files_execute(const char *argument)
|
||||
*/
|
||||
static bool close_current_sprite()
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
if (!sprite.writeable())
|
||||
return false;
|
||||
CurrentSpriteWriter sprite;
|
||||
|
||||
/* see if the sprite has changes */
|
||||
while (sprite_is_modified(sprite)) {
|
||||
@ -89,6 +87,7 @@ static bool close_current_sprite()
|
||||
|
||||
if (ret == 1) {
|
||||
/* "save": save the changes */
|
||||
// TODO we have to pass the sprite to the save file command
|
||||
command_execute(command_get_by_name(CMD_SAVE_FILE), NULL);
|
||||
}
|
||||
else if (ret != 2) {
|
||||
|
@ -74,21 +74,15 @@ static void cmd_configure_screen_execute(const char *argument)
|
||||
|
||||
static void show_dialog()
|
||||
{
|
||||
JWidget window, resolution, color_depth, pixel_scale, fullscreen;
|
||||
JWidget resolution, color_depth, pixel_scale, fullscreen;
|
||||
char buf[512];
|
||||
|
||||
window = load_widget("confscr.jid", "configure_screen");
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
if (!get_widgets(window,
|
||||
"resolution", &resolution,
|
||||
"color_depth", &color_depth,
|
||||
"pixel_scale", &pixel_scale,
|
||||
"fullscreen", &fullscreen, NULL)) {
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
JWidgetPtr window = load_widget("confscr.jid", "configure_screen");
|
||||
get_widgets(window,
|
||||
"resolution", &resolution,
|
||||
"color_depth", &color_depth,
|
||||
"pixel_scale", &pixel_scale,
|
||||
"fullscreen", &fullscreen, NULL);
|
||||
|
||||
jcombobox_add_string(resolution, "320x200", NULL);
|
||||
jcombobox_add_string(resolution, "320x240", NULL);
|
||||
@ -139,10 +133,10 @@ static void show_dialog()
|
||||
|
||||
/* setup graphics mode */
|
||||
if (try_new_gfx_mode()) {
|
||||
JWidget alert_window = jalert_new("Confirm Screen"
|
||||
"<<Do you want to keep this screen resolution?"
|
||||
"<<In 10 seconds the screen will be restored."
|
||||
"||&Yes||&No");
|
||||
JWidgetPtr alert_window = jalert_new("Confirm Screen"
|
||||
"<<Do you want to keep this screen resolution?"
|
||||
"<<In 10 seconds the screen will be restored."
|
||||
"||&Yes||&No");
|
||||
jwidget_add_hook(alert_window, -1, alert_msg_proc, NULL);
|
||||
|
||||
seconds_to_accept = 10;
|
||||
@ -165,12 +159,8 @@ static void show_dialog()
|
||||
|
||||
try_new_gfx_mode();
|
||||
}
|
||||
|
||||
jwidget_free(alert_window);
|
||||
}
|
||||
}
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
static bool try_new_gfx_mode()
|
||||
@ -185,7 +175,7 @@ static bool try_new_gfx_mode()
|
||||
if (set_gfx_mode(old_card, old_w, old_h, 0, 0) < 0) {
|
||||
/* oh no! more errors!, we can't restore the old graphics mode! */
|
||||
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
|
||||
console_printf(_("FATAL ERROR: Unable to restore the old graphics mode!\n"));
|
||||
user_printf(_("FATAL ERROR: Unable to restore the old graphics mode!\n"));
|
||||
app_exit();
|
||||
exit(1);
|
||||
}
|
||||
@ -197,12 +187,16 @@ static bool try_new_gfx_mode()
|
||||
set_black_palette();
|
||||
|
||||
/* restore palette all screen stuff */
|
||||
app_refresh_screen();
|
||||
{
|
||||
const CurrentSpriteReader sprite;
|
||||
app_refresh_screen(sprite);
|
||||
}
|
||||
|
||||
console_printf(_("Error setting graphics mode: %dx%d %d bpp\n"),
|
||||
Console console;
|
||||
console.printf(_("Error setting graphics mode: %dx%d %d bpp\n"),
|
||||
new_w, new_h, new_depth);
|
||||
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/* the new graphics mode is working */
|
||||
@ -212,8 +206,11 @@ static bool try_new_gfx_mode()
|
||||
/* set to a black palette */
|
||||
set_black_palette();
|
||||
|
||||
/* restore palette all screen stuff */
|
||||
app_refresh_screen();
|
||||
// restore palette all screen stuff
|
||||
{
|
||||
const CurrentSpriteReader sprite;
|
||||
app_refresh_screen(sprite);
|
||||
}
|
||||
}
|
||||
|
||||
/* setup mouse */
|
||||
@ -225,7 +222,7 @@ static bool try_new_gfx_mode()
|
||||
jmanager_refresh_screen();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool alert_msg_proc(JWidget widget, JMessage msg)
|
||||
|
@ -84,26 +84,29 @@ static void cmd_configure_tools_execute(const char *argument)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!get_widgets(window,
|
||||
"filled", &filled,
|
||||
"tiled", &tiled,
|
||||
"tiled_x", &tiled_x,
|
||||
"tiled_y", &tiled_y,
|
||||
"use_grid", &use_grid,
|
||||
"view_grid", &view_grid,
|
||||
"set_grid", &set_grid,
|
||||
"brush_size", &brush_size,
|
||||
"brush_angle", &brush_angle,
|
||||
"glass_dirty", &glass_dirty,
|
||||
"spray_width", &spray_width,
|
||||
"air_speed", &air_speed,
|
||||
"cursor_color_box", &cursor_color_box,
|
||||
"brush_preview_box", &brush_preview_box,
|
||||
"brush_type_box", &brush_type_box,
|
||||
"onionskin", &check_onionskin, NULL)) {
|
||||
try {
|
||||
get_widgets(window,
|
||||
"filled", &filled,
|
||||
"tiled", &tiled,
|
||||
"tiled_x", &tiled_x,
|
||||
"tiled_y", &tiled_y,
|
||||
"use_grid", &use_grid,
|
||||
"view_grid", &view_grid,
|
||||
"set_grid", &set_grid,
|
||||
"brush_size", &brush_size,
|
||||
"brush_angle", &brush_angle,
|
||||
"glass_dirty", &glass_dirty,
|
||||
"spray_width", &spray_width,
|
||||
"air_speed", &air_speed,
|
||||
"cursor_color_box", &cursor_color_box,
|
||||
"brush_preview_box", &brush_preview_box,
|
||||
"brush_type_box", &brush_type_box,
|
||||
"onionskin", &check_onionskin, NULL);
|
||||
}
|
||||
catch (...) {
|
||||
jwidget_free(window);
|
||||
window = NULL;
|
||||
return;
|
||||
throw;
|
||||
}
|
||||
|
||||
/* cursor-color */
|
||||
@ -325,24 +328,29 @@ static bool view_grid_check_change_hook(JWidget widget, void *data)
|
||||
|
||||
static bool set_grid_button_select_hook(JWidget widget, void *data)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
try {
|
||||
const CurrentSpriteReader sprite;
|
||||
|
||||
if (sprite && sprite->mask && sprite->mask->bitmap) {
|
||||
JRect rect = jrect_new(sprite->mask->x,
|
||||
sprite->mask->y,
|
||||
sprite->mask->x+sprite->mask->w,
|
||||
sprite->mask->y+sprite->mask->h);
|
||||
set_grid(rect);
|
||||
jrect_free(rect);
|
||||
if (sprite && sprite->mask && sprite->mask->bitmap) {
|
||||
JRect rect = jrect_new(sprite->mask->x,
|
||||
sprite->mask->y,
|
||||
sprite->mask->x+sprite->mask->w,
|
||||
sprite->mask->y+sprite->mask->h);
|
||||
set_grid(rect);
|
||||
jrect_free(rect);
|
||||
|
||||
if (get_view_grid())
|
||||
refresh_all_editors();
|
||||
if (get_view_grid())
|
||||
refresh_all_editors();
|
||||
}
|
||||
else {
|
||||
jalert(_("Error"
|
||||
"<<You have to select a sprite with mask."
|
||||
"<<The boundaries of the mask will be used"
|
||||
"<<to specify the grid area.||&OK"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
jalert(_("Error"
|
||||
"<<You must select a sprite with mask."
|
||||
"<<The boundaries of the mask will be used"
|
||||
"<<to specify the grid area.||&OK"));
|
||||
catch (locked_sprite_exception& e) {
|
||||
e.show();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
static bool cmd_copy_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
|
||||
if ((!sprite) ||
|
||||
(!sprite->layer) ||
|
||||
@ -45,7 +45,7 @@ static bool cmd_copy_enabled(const char *argument)
|
||||
|
||||
static void cmd_copy_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
clipboard::copy(sprite);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ static bool cmd_copy_cel_enabled(const char *argument)
|
||||
|
||||
static void cmd_copy_cel_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
copy_cel(sprite);
|
||||
}
|
||||
|
||||
|
@ -26,10 +26,9 @@
|
||||
#include "raster/layer.h"
|
||||
#include "raster/mask.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/undoable.h"
|
||||
#include "undoable.h"
|
||||
#include "widgets/colbar.h"
|
||||
#include "util/autocrop.h"
|
||||
#include "util/functions.h"
|
||||
#include "util/misc.h"
|
||||
|
||||
/* ======================== */
|
||||
@ -38,7 +37,7 @@
|
||||
|
||||
static bool cmd_crop_sprite_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL &&
|
||||
sprite->mask != NULL &&
|
||||
@ -47,7 +46,7 @@ static bool cmd_crop_sprite_enabled(const char *argument)
|
||||
|
||||
static void cmd_crop_sprite_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
{
|
||||
Undoable undoable(sprite, "Sprite Crop");
|
||||
int bgcolor = get_color_for_image(sprite->imgtype,
|
||||
@ -69,13 +68,13 @@ static void cmd_crop_sprite_execute(const char *argument)
|
||||
|
||||
static bool cmd_autocrop_sprite_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_autocrop_sprite_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
{
|
||||
Undoable undoable(sprite, "Sprite Autocrop");
|
||||
undoable.autocrop_sprite(colorbar_get_bg_color(app_get_colorbar()));
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
static bool cmd_cut_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
if ((!sprite) ||
|
||||
(!sprite->layer) ||
|
||||
(!layer_is_readable(sprite->layer)) ||
|
||||
@ -44,7 +44,7 @@ static bool cmd_cut_enabled(const char *argument)
|
||||
|
||||
static void cmd_cut_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
clipboard::cut(sprite);
|
||||
}
|
||||
|
||||
|
@ -27,13 +27,13 @@
|
||||
|
||||
static bool cmd_deselect_mask_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite && !mask_is_empty(sprite->mask);
|
||||
}
|
||||
|
||||
static void cmd_deselect_mask_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
Mask *mask;
|
||||
|
||||
/* destroy the *deselected* mask */
|
||||
|
@ -29,24 +29,23 @@
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/undo.h"
|
||||
|
||||
static Layer *duplicate_layer();
|
||||
static Layer *duplicate_layer(Sprite* sprite);
|
||||
|
||||
static bool cmd_duplicate_layer_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite && sprite->layer;
|
||||
}
|
||||
|
||||
static void cmd_duplicate_layer_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
if (duplicate_layer() != NULL)
|
||||
CurrentSpriteWriter sprite;
|
||||
if (duplicate_layer(sprite) != NULL)
|
||||
update_screen_for_sprite(sprite);
|
||||
}
|
||||
|
||||
static Layer *duplicate_layer()
|
||||
static Layer *duplicate_layer(Sprite* sprite)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
Layer *layer_copy;
|
||||
char buf[1024];
|
||||
|
||||
@ -64,7 +63,8 @@ static Layer *duplicate_layer()
|
||||
if (undo_is_enabled(sprite->undo))
|
||||
undo_close(sprite->undo);
|
||||
|
||||
console_printf("Not enough memory");
|
||||
Console console;
|
||||
console.printf("Not enough memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -32,20 +32,18 @@
|
||||
|
||||
static bool cmd_duplicate_sprite_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite;
|
||||
}
|
||||
|
||||
static void cmd_duplicate_sprite_execute(const char *argument)
|
||||
{
|
||||
JWidget window, src_name, dst_name, flatten;
|
||||
CurrentSprite sprite;
|
||||
JWidget src_name, dst_name, flatten;
|
||||
const CurrentSpriteReader sprite;
|
||||
char buf[1024];
|
||||
|
||||
/* load the window widget */
|
||||
window = load_widget("dupspr.jid", "duplicate_sprite");
|
||||
if (!window)
|
||||
return;
|
||||
JWidgetPtr window = load_widget("dupspr.jid", "duplicate_sprite");
|
||||
|
||||
src_name = jwidget_find_name(window, "src_name");
|
||||
dst_name = jwidget_find_name(window, "dst_name");
|
||||
@ -83,8 +81,6 @@ static void cmd_duplicate_sprite_execute(const char *argument)
|
||||
context->show_sprite(sprite_copy);
|
||||
}
|
||||
}
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
Command cmd_duplicate_sprite = {
|
||||
|
@ -26,8 +26,8 @@
|
||||
|
||||
static bool cmd_film_editor_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_film_editor_execute(const char *argument)
|
||||
|
@ -19,26 +19,28 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "commands/commands.h"
|
||||
#include "core/app.h"
|
||||
#include "modules/gui.h"
|
||||
#include "modules/sprites.h"
|
||||
#include "raster/undo.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "util/functions.h"
|
||||
#include "undoable.h"
|
||||
#include "widgets/colbar.h"
|
||||
|
||||
static bool cmd_flatten_layers_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_flatten_layers_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
|
||||
if (undo_is_enabled(sprite->undo))
|
||||
undo_set_label(sprite->undo, "Flatten Layers");
|
||||
|
||||
FlattenLayers(sprite);
|
||||
CurrentSpriteWriter sprite;
|
||||
int bgcolor = get_color_for_image(sprite->imgtype,
|
||||
colorbar_get_bg_color(app_get_colorbar()));
|
||||
{
|
||||
Undoable undoable(sprite, "Flatten Layers");
|
||||
undoable.flatten_layers(bgcolor);
|
||||
undoable.commit();
|
||||
}
|
||||
update_screen_for_sprite(sprite);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "raster/undo.h"
|
||||
#include "util/misc.h"
|
||||
|
||||
static void do_flip(int horz);
|
||||
static void do_flip(Sprite* sprite, bool horz);
|
||||
|
||||
/* ======================== */
|
||||
/* flip_horizontal */
|
||||
@ -36,13 +36,15 @@ static void do_flip(int horz);
|
||||
|
||||
static bool cmd_flip_horizontal_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_flip_horizontal_execute(const char *argument)
|
||||
{
|
||||
do_flip(TRUE);
|
||||
CurrentSpriteWriter sprite;
|
||||
do_flip(sprite, true);
|
||||
}
|
||||
|
||||
/* ======================== */
|
||||
@ -51,21 +53,22 @@ static void cmd_flip_horizontal_execute(const char *argument)
|
||||
|
||||
static bool cmd_flip_vertical_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_flip_vertical_execute(const char *argument)
|
||||
{
|
||||
do_flip(FALSE);
|
||||
CurrentSpriteWriter sprite;
|
||||
do_flip(sprite, false);
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
/* do_flip */
|
||||
|
||||
static void do_flip(int horz)
|
||||
static void do_flip(Sprite* sprite, bool horz)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
Image *image, *area;
|
||||
int x1, y1, x2, y2;
|
||||
int x, y;
|
||||
|
@ -24,40 +24,35 @@
|
||||
#include "modules/gui.h"
|
||||
#include "modules/sprites.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/undoable.h"
|
||||
#include "undoable.h"
|
||||
|
||||
void dialogs_frame_length(int sprite_frame);
|
||||
class SpriteReader;
|
||||
void dialogs_frame_length(const SpriteReader& sprite, int sprite_frame);
|
||||
|
||||
static bool cmd_frame_properties_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_frame_properties_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
dialogs_frame_length(sprite->frame);
|
||||
const CurrentSpriteReader sprite;
|
||||
dialogs_frame_length(sprite, sprite->frame);
|
||||
}
|
||||
|
||||
/* if sprite_frame < 0, set the frame length of all frames */
|
||||
void dialogs_frame_length(int sprite_frame)
|
||||
void dialogs_frame_length(const SpriteReader& sprite, int sprite_frame)
|
||||
{
|
||||
JWidget window, frame, frlen, ok;
|
||||
CurrentSprite sprite;
|
||||
JWidget frame, frlen, ok;
|
||||
char buf[64];
|
||||
|
||||
window = load_widget("frlen.jid", "frame_duration");
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
if (!get_widgets(window,
|
||||
"frame", &frame,
|
||||
"frlen", &frlen,
|
||||
"ok", &ok, NULL)) {
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
JWidgetPtr window = load_widget("frlen.jid", "frame_duration");
|
||||
get_widgets(window,
|
||||
"frame", &frame,
|
||||
"frlen", &frlen,
|
||||
"ok", &ok, NULL);
|
||||
|
||||
if (sprite_frame < 0)
|
||||
strcpy(buf, "All");
|
||||
@ -76,18 +71,19 @@ void dialogs_frame_length(int sprite_frame)
|
||||
if (jalert("Warning"
|
||||
"<<Do you want to change the duration of all frames?"
|
||||
"||&Yes||&No") == 1) {
|
||||
Undoable undoable(sprite, "Constant Frame-Rate");
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
Undoable undoable(sprite_writer, "Constant Frame-Rate");
|
||||
undoable.set_constant_frame_rate(num);
|
||||
undoable.commit();
|
||||
}
|
||||
}
|
||||
else {
|
||||
Undoable undoable(sprite, "Frame Duration");
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
Undoable undoable(sprite_writer, "Frame Duration");
|
||||
undoable.set_frame_duration(sprite_frame, num);
|
||||
undoable.commit();
|
||||
}
|
||||
}
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
Command cmd_frame_properties = {
|
||||
|
@ -31,13 +31,13 @@
|
||||
|
||||
static bool cmd_goto_first_frame_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_goto_first_frame_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
sprite->frame = 0;
|
||||
|
||||
update_screen_for_sprite(sprite);
|
||||
@ -50,13 +50,14 @@ static void cmd_goto_first_frame_execute(const char *argument)
|
||||
|
||||
static bool cmd_goto_previous_frame_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite != NULL;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_goto_previous_frame_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
|
||||
if (sprite->frame > 0)
|
||||
sprite->frame--;
|
||||
@ -73,13 +74,14 @@ static void cmd_goto_previous_frame_execute(const char *argument)
|
||||
|
||||
static bool cmd_goto_next_frame_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite != NULL;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_goto_next_frame_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
|
||||
if (sprite->frame < sprite->frames-1)
|
||||
sprite->frame++;
|
||||
@ -96,13 +98,14 @@ static void cmd_goto_next_frame_execute(const char *argument)
|
||||
|
||||
static bool cmd_goto_last_frame_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite != NULL;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_goto_last_frame_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
sprite->frame = sprite->frames-1;
|
||||
|
||||
update_screen_for_sprite(sprite);
|
||||
|
@ -34,13 +34,14 @@
|
||||
|
||||
static bool cmd_goto_previous_layer_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite != NULL;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_goto_previous_layer_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
int i = sprite_layer2index(sprite, sprite->layer);
|
||||
|
||||
if (i > 0)
|
||||
@ -64,13 +65,14 @@ static void cmd_goto_previous_layer_execute(const char *argument)
|
||||
|
||||
static bool cmd_goto_next_layer_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite != NULL;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_goto_next_layer_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
int i = sprite_layer2index(sprite, sprite->layer);
|
||||
|
||||
if (i < sprite_count_layers(sprite)-1)
|
||||
|
@ -28,13 +28,13 @@
|
||||
|
||||
static bool cmd_invert_mask_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_invert_mask_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
Mask *mask;
|
||||
|
||||
/* change the selection */
|
||||
|
@ -22,19 +22,15 @@
|
||||
|
||||
#include "commands/commands.h"
|
||||
#include "modules/gui.h"
|
||||
#include "modules/sprites.h"
|
||||
#include "raster/cel.h"
|
||||
#include "raster/layer.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/undo.h"
|
||||
#include "util/functions.h"
|
||||
#include "undoable.h"
|
||||
|
||||
static bool cmd_layer_from_background_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite &&
|
||||
sprite->layer &&
|
||||
sprite != NULL &&
|
||||
sprite->layer != NULL &&
|
||||
layer_is_image(sprite->layer) &&
|
||||
layer_is_readable(sprite->layer) &&
|
||||
layer_is_writable(sprite->layer) &&
|
||||
@ -43,12 +39,12 @@ static bool cmd_layer_from_background_enabled(const char *argument)
|
||||
|
||||
static void cmd_layer_from_background_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
|
||||
if (undo_is_enabled(sprite->undo))
|
||||
undo_set_label(sprite->undo, "Layer from Background");
|
||||
|
||||
LayerFromBackground(sprite);
|
||||
CurrentSpriteWriter sprite;
|
||||
{
|
||||
Undoable undoable(sprite, "Layer from Background");
|
||||
undoable.layer_from_background();
|
||||
undoable.commit();
|
||||
}
|
||||
update_screen_for_sprite(sprite);
|
||||
}
|
||||
|
||||
|
@ -29,18 +29,20 @@
|
||||
|
||||
static bool cmd_layer_properties_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite && sprite->layer;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL &&
|
||||
sprite->layer != NULL;
|
||||
}
|
||||
|
||||
static void cmd_layer_properties_execute(const char *argument)
|
||||
{
|
||||
JWidget window, box1, box2, box3, label_name, entry_name;
|
||||
JWidget box1, box2, box3, label_name, entry_name;
|
||||
JWidget button_ok, button_cancel, label_bm, view_bm, list_bm;
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
Layer *layer = sprite->layer;
|
||||
|
||||
window = jwindow_new(_("Layer Properties"));
|
||||
JWidgetPtr window = jwindow_new(_("Layer Properties"));
|
||||
box1 = jbox_new(JI_VERTICAL);
|
||||
box2 = jbox_new(JI_HORIZONTAL);
|
||||
box3 = jbox_new(JI_HORIZONTAL + JI_HOMOGENEOUS);
|
||||
@ -104,8 +106,6 @@ static void cmd_layer_properties_execute(const char *argument)
|
||||
|
||||
update_screen_for_sprite(sprite);
|
||||
}
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
Command cmd_layer_properties = {
|
||||
|
@ -31,13 +31,13 @@
|
||||
|
||||
static bool cmd_load_mask_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_load_mask_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
jstring filename = ase_file_selector(_("Load .msk File"), "", "msk");
|
||||
if (!filename.empty()) {
|
||||
Mask *mask = load_msk_file(filename.c_str());
|
||||
|
@ -27,13 +27,13 @@
|
||||
|
||||
static bool cmd_mask_all_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_mask_all_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
|
||||
/* undo */
|
||||
if (undo_is_enabled(sprite->undo)) {
|
||||
|
@ -26,13 +26,14 @@
|
||||
|
||||
static bool cmd_mask_by_color_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_mask_by_color_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
dialogs_mask_color(sprite);
|
||||
}
|
||||
|
||||
|
@ -33,24 +33,24 @@
|
||||
|
||||
static bool cmd_merge_down_layer_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
if (!sprite)
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
Layer *src_layer = sprite->layer;
|
||||
if (!src_layer || !layer_is_image(src_layer))
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
Layer* dst_layer = layer_get_prev(sprite->layer);
|
||||
if (!dst_layer || !layer_is_image(dst_layer))
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void cmd_merge_down_layer_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
Layer *src_layer, *dst_layer;
|
||||
Cel *src_cel, *dst_cel;
|
||||
Image *src_image, *dst_image;
|
||||
|
@ -31,7 +31,7 @@ static bool cmd_move_cel_enabled(const char *argument)
|
||||
|
||||
static void cmd_move_cel_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
move_cel(sprite);
|
||||
}
|
||||
|
||||
|
@ -36,18 +36,19 @@
|
||||
#include "raster/layer.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/undo.h"
|
||||
#include "util/functions.h"
|
||||
#include "util/misc.h"
|
||||
#include "widgets/colbar.h"
|
||||
|
||||
static int _sprite_counter = 0;
|
||||
|
||||
static Sprite *new_sprite(Context* context, int imgtype, int w, int h);
|
||||
|
||||
/**
|
||||
* Shows the "New Sprite" dialog.
|
||||
*/
|
||||
static void cmd_new_file_execute(const char *argument)
|
||||
{
|
||||
JWidget window, width, height, radio1, radio2, radio3, ok, bg_box;
|
||||
JWidget width, height, radio1, radio2, radio3, ok, bg_box;
|
||||
int imgtype, w, h, bg;
|
||||
char buf[1024];
|
||||
Sprite *sprite;
|
||||
@ -61,9 +62,7 @@ static void cmd_new_file_execute(const char *argument)
|
||||
};
|
||||
|
||||
/* load the window widget */
|
||||
window = load_widget("newspr.jid", "new_sprite");
|
||||
if (!window)
|
||||
return;
|
||||
JWidgetPtr window = load_widget("newspr.jid", "new_sprite");
|
||||
|
||||
width = jwidget_find_name(window, "width");
|
||||
height = jwidget_find_name(window, "height");
|
||||
@ -127,9 +126,10 @@ static void cmd_new_file_execute(const char *argument)
|
||||
set_config_int("NewSprite", "Background", bg);
|
||||
|
||||
/* create the new sprite */
|
||||
sprite = NewSprite(imgtype, w, h);
|
||||
sprite = new_sprite(UIContext::instance(), imgtype, w, h);
|
||||
if (!sprite) {
|
||||
console_printf("Not enough memory to allocate the sprite\n");
|
||||
Console console;
|
||||
console.printf("Not enough memory to allocate the sprite\n");
|
||||
}
|
||||
else {
|
||||
usprintf(buf, "Sprite-%04d", ++_sprite_counter);
|
||||
@ -143,21 +143,36 @@ static void cmd_new_file_execute(const char *argument)
|
||||
get_color_for_image(imgtype, color));
|
||||
}
|
||||
|
||||
/* the undo should be disabled because we use NewSprite to
|
||||
create it (a function for scripts) */
|
||||
assert(undo_is_disabled(sprite->undo));
|
||||
|
||||
/* enable undo */
|
||||
undo_enable(sprite->undo);
|
||||
|
||||
/* show the sprite to the user */
|
||||
UIContext* context = UIContext::instance();
|
||||
context->show_sprite(sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jwidget_free(window);
|
||||
/**
|
||||
* Creates a new sprite with the given dimension with one transparent
|
||||
* layer called "Layer 1".
|
||||
*
|
||||
* @param imgtype Color mode, one of the following values: IMAGE_RGB, IMAGE_GRAYSCALE, IMAGE_INDEXED
|
||||
* @param w Width of the sprite
|
||||
* @param h Height of the sprite
|
||||
*/
|
||||
static Sprite *new_sprite(Context* context, int imgtype, int w, int h)
|
||||
{
|
||||
assert(imgtype == IMAGE_RGB || imgtype == IMAGE_GRAYSCALE || imgtype == IMAGE_INDEXED);
|
||||
assert(w >= 1 && w <= 9999);
|
||||
assert(h >= 1 && h <= 9999);
|
||||
|
||||
Sprite *sprite = sprite_new_with_layer(imgtype, w, h);
|
||||
if (!sprite)
|
||||
return NULL;
|
||||
|
||||
context->add_sprite(sprite);
|
||||
context->set_current_sprite(sprite);
|
||||
|
||||
return sprite;
|
||||
}
|
||||
|
||||
Command cmd_new_file = {
|
||||
|
@ -31,17 +31,17 @@
|
||||
#include "raster/image.h"
|
||||
#include "raster/layer.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/undoable.h"
|
||||
#include "undoable.h"
|
||||
#include "widgets/statebar.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
static bool cmd_new_frame_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite &&
|
||||
sprite->layer &&
|
||||
sprite != NULL &&
|
||||
sprite->layer != NULL &&
|
||||
layer_is_readable(sprite->layer) &&
|
||||
layer_is_writable(sprite->layer) &&
|
||||
layer_is_image(sprite->layer);
|
||||
@ -49,7 +49,7 @@ static bool cmd_new_frame_enabled(const char *argument)
|
||||
|
||||
static void cmd_new_frame_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
{
|
||||
Undoable undoable(sprite, "New Frame");
|
||||
undoable.new_frame();
|
||||
|
@ -26,28 +26,25 @@
|
||||
#include "modules/sprites.h"
|
||||
#include "raster/layer.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/undoable.h"
|
||||
#include "util/functions.h"
|
||||
#include "undoable.h"
|
||||
|
||||
static bool cmd_new_layer_enabled(const char *argument)
|
||||
static char* get_unique_layer_name(Sprite* sprite);
|
||||
static int get_max_layer_num(Layer* layer);
|
||||
|
||||
static bool cmd_new_layer_enabled(const char* argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite;
|
||||
}
|
||||
|
||||
static void cmd_new_layer_execute(const char *argument)
|
||||
static void cmd_new_layer_execute(const char* argument)
|
||||
{
|
||||
JWidget window, name_widget;
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
|
||||
/* load the window widget */
|
||||
window = load_widget("newlay.jid", "new_layer");
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
name_widget = jwidget_find_name(window, "name");
|
||||
JWidgetPtr window = load_widget("newlay.jid", "new_layer");
|
||||
JWidget name_widget = find_widget(window, "name");
|
||||
{
|
||||
char *name = GetUniqueLayerName(sprite);
|
||||
char* name = get_unique_layer_name(sprite);
|
||||
jwidget_set_text(name_widget, name);
|
||||
jfree(name);
|
||||
}
|
||||
@ -66,8 +63,35 @@ static void cmd_new_layer_execute(const char *argument)
|
||||
layer_set_name(layer, name);
|
||||
update_screen_for_sprite(sprite);
|
||||
}
|
||||
}
|
||||
|
||||
jwidget_free(window);
|
||||
static char* get_unique_layer_name(Sprite* sprite)
|
||||
{
|
||||
if (sprite != NULL) {
|
||||
char buf[1024];
|
||||
sprintf(buf, "Layer %d", get_max_layer_num(sprite->set)+1);
|
||||
return jstrdup(buf);
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int get_max_layer_num(Layer* layer)
|
||||
{
|
||||
int max = 0;
|
||||
|
||||
if (strncmp(layer->name, "Layer ", 6) == 0)
|
||||
max = strtol(layer->name+6, NULL, 10);
|
||||
|
||||
if (layer_is_set(layer)) {
|
||||
JLink link;
|
||||
JI_LIST_FOR_EACH(layer->layers, link) {
|
||||
int tmp = get_max_layer_num(reinterpret_cast<Layer*>(link->data));
|
||||
max = MAX(tmp, max);
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
Command cmd_new_layer = {
|
||||
|
@ -26,38 +26,33 @@
|
||||
#include "modules/sprites.h"
|
||||
#include "raster/layer.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "util/functions.h"
|
||||
|
||||
static bool cmd_new_layer_set_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_new_layer_set_execute(const char *argument)
|
||||
{
|
||||
JWidget window;
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
|
||||
// load the window widget
|
||||
window = load_widget("newlay.jid", "new_layer_set");
|
||||
if (!window)
|
||||
return;
|
||||
JWidgetPtr window = load_widget("newlay.jid", "new_layer_set");
|
||||
|
||||
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 = NewLayerSet(sprite);
|
||||
if (!layer) {
|
||||
jalert(_("Error<<Not enough memory||&Close"));
|
||||
return;
|
||||
}
|
||||
Layer *layer = layer_set_new(sprite);
|
||||
|
||||
layer_set_name(layer, name);
|
||||
layer_add_layer(sprite->set, layer);
|
||||
sprite_set_layer(sprite, layer);
|
||||
|
||||
update_screen_for_sprite(sprite);
|
||||
}
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
Command cmd_new_layer_set = {
|
||||
|
@ -99,9 +99,8 @@ static void monitor_openfile_bg(void *_data)
|
||||
progress_free(data->progress);
|
||||
|
||||
if (fop->error) {
|
||||
console_open();
|
||||
console_printf(fop->error);
|
||||
console_close();
|
||||
Console console;
|
||||
console.printf(fop->error);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -143,6 +142,7 @@ static void monitor_free(void *_data)
|
||||
*/
|
||||
static void cmd_open_file_execute(const char *argument)
|
||||
{
|
||||
Console console;
|
||||
jstring filename;
|
||||
|
||||
/* interactive */
|
||||
@ -161,13 +161,13 @@ static void cmd_open_file_execute(const char *argument)
|
||||
|
||||
if (fop) {
|
||||
if (fop->error) {
|
||||
console_printf(fop->error);
|
||||
console.printf(fop->error);
|
||||
fop_free(fop);
|
||||
}
|
||||
else {
|
||||
JThread thread = jthread_new(openfile_bg, fop);
|
||||
if (thread) {
|
||||
OpenFileData *data = jnew(OpenFileData, 1);
|
||||
OpenFileData* data = new OpenFileData;
|
||||
|
||||
data->fop = fop;
|
||||
data->progress = progress_new(app_get_statusbar());
|
||||
@ -191,9 +191,7 @@ static void cmd_open_file_execute(const char *argument)
|
||||
|
||||
/* show any error */
|
||||
if (fop->error) {
|
||||
console_open();
|
||||
console_printf(fop->error);
|
||||
console_close();
|
||||
console.printf(fop->error);
|
||||
}
|
||||
else {
|
||||
Sprite *sprite = fop->sprite;
|
||||
@ -216,10 +214,10 @@ static void cmd_open_file_execute(const char *argument)
|
||||
progress_free(data->progress);
|
||||
jwidget_free(data->alert_window);
|
||||
fop_free(fop);
|
||||
jfree(data);
|
||||
delete data;
|
||||
}
|
||||
else {
|
||||
console_printf(_("Error creating thread to load the sprite"));
|
||||
console.printf(_("Error creating thread to load the sprite"));
|
||||
fop_free(fop);
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,8 @@
|
||||
#include "widgets/colview.h"
|
||||
#include "widgets/paledit.h"
|
||||
|
||||
#define get_sprite(wgt) (*(const SpriteReader*)(jwidget_get_window(wgt))->user_data[0])
|
||||
|
||||
static Palette **palettes;
|
||||
|
||||
static JWidget slider_R, slider_G, slider_B;
|
||||
@ -66,7 +68,7 @@ static void set_new_palette(Palette *palette);
|
||||
|
||||
static void cmd_palette_editor_execute(const char *argument)
|
||||
{
|
||||
JWidget window, colorviewer_box, palette_editor_view;
|
||||
JWidget colorviewer_box, palette_editor_view;
|
||||
JWidget slider_columns, button_ok;
|
||||
JWidget button_select_all;
|
||||
JWidget button_undo, button_redo;
|
||||
@ -74,7 +76,7 @@ static void cmd_palette_editor_execute(const char *argument)
|
||||
JWidget button_ramp, button_quantize;
|
||||
int frame, columns;
|
||||
Palette *palette = NULL;
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
int imgtype = sprite ? sprite->imgtype: IMAGE_INDEXED;
|
||||
int frame_bak = sprite ? sprite->frame : 0;
|
||||
bool all_frames_same_palette = TRUE;
|
||||
@ -85,33 +87,29 @@ static void cmd_palette_editor_execute(const char *argument)
|
||||
}
|
||||
|
||||
/* load widgets */
|
||||
window = load_widget("paledit.jid", "palette_editor");
|
||||
if (!window)
|
||||
return;
|
||||
JWidgetPtr window = load_widget("paledit.jid", "palette_editor");
|
||||
get_widgets(window,
|
||||
"red", &slider_R,
|
||||
"green", &slider_G,
|
||||
"blue", &slider_B,
|
||||
"hue", &slider_H,
|
||||
"saturation", &slider_S,
|
||||
"value", &slider_V,
|
||||
"columns", &slider_columns,
|
||||
"frame", &slider_frame,
|
||||
"select_all", &button_select_all,
|
||||
"undo", &button_undo,
|
||||
"redo", &button_redo,
|
||||
"load", &button_load,
|
||||
"save", &button_save,
|
||||
"ramp", &button_ramp,
|
||||
"quantize", &button_quantize,
|
||||
"button_ok", &button_ok,
|
||||
"colorviewer", &colorviewer_box,
|
||||
"palette_editor", &palette_editor_view,
|
||||
"all_frames", &check_all_frames, NULL);
|
||||
|
||||
if (!get_widgets(window,
|
||||
"red", &slider_R,
|
||||
"green", &slider_G,
|
||||
"blue", &slider_B,
|
||||
"hue", &slider_H,
|
||||
"saturation", &slider_S,
|
||||
"value", &slider_V,
|
||||
"columns", &slider_columns,
|
||||
"frame", &slider_frame,
|
||||
"select_all", &button_select_all,
|
||||
"undo", &button_undo,
|
||||
"redo", &button_redo,
|
||||
"load", &button_load,
|
||||
"save", &button_save,
|
||||
"ramp", &button_ramp,
|
||||
"quantize", &button_quantize,
|
||||
"button_ok", &button_ok,
|
||||
"colorviewer", &colorviewer_box,
|
||||
"palette_editor", &palette_editor_view,
|
||||
"all_frames", &check_all_frames, NULL)) {
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
window->user_data[0] = (void*)&sprite;
|
||||
|
||||
/* create current_sprite->frames palettes */
|
||||
if (sprite) {
|
||||
@ -174,8 +172,10 @@ static void cmd_palette_editor_execute(const char *argument)
|
||||
if (jwidget_is_selected(check_all_frames))
|
||||
jwidget_disable(slider_frame);
|
||||
}
|
||||
else
|
||||
else {
|
||||
jwidget_disable(slider_frame);
|
||||
jwidget_disable(button_quantize);
|
||||
}
|
||||
|
||||
/* hook signals */
|
||||
HOOK(slider_R, JI_SIGNAL_SLIDER_CHANGE, sliderRGB_change_hook, 0);
|
||||
@ -208,7 +208,8 @@ static void cmd_palette_editor_execute(const char *argument)
|
||||
/* check the killer widget */
|
||||
if (jwindow_get_killer(window) == button_ok) {
|
||||
if (sprite) {
|
||||
sprite_reset_palettes(sprite);
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
sprite_reset_palettes(sprite_writer);
|
||||
|
||||
/* one palette */
|
||||
if (jwidget_is_selected(check_all_frames)) {
|
||||
@ -216,7 +217,7 @@ static void cmd_palette_editor_execute(const char *argument)
|
||||
palette_copy_colors(palettes[0],
|
||||
get_current_palette());
|
||||
|
||||
sprite_set_palette(sprite, palettes[0], TRUE);
|
||||
sprite_set_palette(sprite_writer, palettes[0], TRUE);
|
||||
}
|
||||
/* various palettes */
|
||||
else {
|
||||
@ -224,11 +225,11 @@ static void cmd_palette_editor_execute(const char *argument)
|
||||
palette_copy_colors(palettes[frame],
|
||||
get_current_palette());
|
||||
|
||||
for (frame=0; frame<sprite->frames; ++frame) {
|
||||
for (frame=0; frame<sprite_writer->frames; ++frame) {
|
||||
if (frame == 0 ||
|
||||
palette_count_diff(palettes[frame],
|
||||
palettes[frame-1], NULL, NULL) > 0) {
|
||||
sprite_set_palette(sprite, palettes[frame], TRUE);
|
||||
sprite_set_palette(sprite_writer, palettes[frame], TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -243,7 +244,9 @@ static void cmd_palette_editor_execute(const char *argument)
|
||||
else {
|
||||
/* restore the system palette */
|
||||
if (sprite) {
|
||||
sprite->frame = frame_bak;
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
sprite_writer->frame = frame_bak;
|
||||
|
||||
set_current_palette(sprite_get_palette(sprite, frame_bak), TRUE);
|
||||
}
|
||||
else {
|
||||
@ -261,8 +264,6 @@ static void cmd_palette_editor_execute(const char *argument)
|
||||
/* save window configuration */
|
||||
save_window_pos(window, "PaletteEditor");
|
||||
|
||||
jwidget_free(window);
|
||||
|
||||
if (palettes) {
|
||||
assert(sprite);
|
||||
|
||||
@ -354,16 +355,19 @@ static void ramp_command(JWidget widget)
|
||||
|
||||
static void quantize_command(JWidget widget)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
Palette *palette = palette_new(0, MAX_PALETTE_COLORS);
|
||||
const SpriteReader& sprite = get_sprite(widget);
|
||||
assert(sprite != NULL);
|
||||
|
||||
Palette* palette = palette_new(0, MAX_PALETTE_COLORS);
|
||||
bool array[256];
|
||||
|
||||
paledit_get_selected_entries(palette_editor, array);
|
||||
palette_copy_colors(palette,
|
||||
paledit_get_palette(palette_editor));
|
||||
|
||||
if (sprite && sprite->imgtype == IMAGE_RGB) {
|
||||
sprite_quantize_ex(sprite, palette);
|
||||
if (sprite->imgtype == IMAGE_RGB) {
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
sprite_quantize_ex(sprite_writer, palette);
|
||||
}
|
||||
else {
|
||||
jalert(_("Error<<You can use this command only for RGB sprites||&OK"));
|
||||
@ -437,13 +441,18 @@ static bool slider_columns_change_hook(JWidget widget, void *data)
|
||||
|
||||
static bool slider_frame_change_hook(JWidget widget, void *data)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const SpriteReader& sprite = get_sprite(widget);
|
||||
assert(sprite != NULL);
|
||||
|
||||
int old_frame = sprite->frame;
|
||||
int new_frame = jslider_get_value(slider_frame);
|
||||
|
||||
palette_copy_colors(palettes[old_frame],
|
||||
get_current_palette());
|
||||
sprite->frame = new_frame;
|
||||
{
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
sprite_writer->frame = new_frame;
|
||||
}
|
||||
set_new_palette(palettes[new_frame]);
|
||||
|
||||
return FALSE;
|
||||
@ -451,7 +460,9 @@ static bool slider_frame_change_hook(JWidget widget, void *data)
|
||||
|
||||
static bool check_all_frames_change_hook(JWidget widget, void *data)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const SpriteReader& sprite = get_sprite(widget);
|
||||
assert(sprite != NULL);
|
||||
|
||||
int frame = jslider_get_value(slider_frame);
|
||||
|
||||
palette_copy_colors(palettes[frame],
|
||||
|
@ -26,14 +26,15 @@
|
||||
|
||||
static bool cmd_paste_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
|
||||
return (sprite && clipboard::can_paste());
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL &&
|
||||
clipboard::can_paste();
|
||||
}
|
||||
|
||||
static void cmd_paste_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
|
||||
if (undo_is_enabled(sprite->undo))
|
||||
undo_set_label(sprite->undo, "Paste");
|
||||
|
@ -43,13 +43,14 @@ END_OF_STATIC_FUNCTION(speed_timer_callback);
|
||||
|
||||
static bool cmd_play_animation_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_play_animation_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
int old_frame, msecs;
|
||||
bool done = FALSE;
|
||||
bool onionskin = get_onionskin();
|
||||
|
@ -43,8 +43,9 @@ static void preview_sprite(int flags);
|
||||
|
||||
static bool cmd_preview_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
/* ======================== */
|
||||
|
@ -28,13 +28,15 @@
|
||||
|
||||
static bool cmd_redo_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite != NULL && undo_can_redo(sprite->undo);
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL &&
|
||||
undo_can_redo(sprite->undo);
|
||||
}
|
||||
|
||||
static void cmd_redo_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
|
||||
statusbar_show_tip(app_get_statusbar(), 1000,
|
||||
_("Redid %s"),
|
||||
|
@ -37,7 +37,10 @@ static void cmd_refresh_execute(const char *argument)
|
||||
clear_to_color(screen, makecol(0, 0, 0));
|
||||
jmouse_show();
|
||||
|
||||
app_refresh_screen();
|
||||
{
|
||||
const CurrentSpriteReader sprite;
|
||||
app_refresh_screen(sprite);
|
||||
}
|
||||
|
||||
/* print memory information */
|
||||
#if defined ALLEGRO_WINDOWS && defined DEBUGMODE
|
||||
|
@ -24,14 +24,14 @@
|
||||
#include "raster/cel.h"
|
||||
#include "raster/layer.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/undoable.h"
|
||||
#include "undoable.h"
|
||||
|
||||
static bool cmd_remove_cel_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite &&
|
||||
sprite->layer &&
|
||||
sprite != NULL &&
|
||||
sprite->layer != NULL &&
|
||||
layer_is_readable(sprite->layer) &&
|
||||
layer_is_writable(sprite->layer) &&
|
||||
layer_is_image(sprite->layer) &&
|
||||
@ -40,7 +40,7 @@ static bool cmd_remove_cel_enabled(const char *argument)
|
||||
|
||||
static void cmd_remove_cel_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
Cel* cel = layer_get_cel(sprite->layer, sprite->frame);
|
||||
{
|
||||
Undoable undoable(sprite, "Remove Cel");
|
||||
|
@ -24,11 +24,11 @@
|
||||
#include "modules/gui.h"
|
||||
#include "modules/sprites.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/undoable.h"
|
||||
#include "undoable.h"
|
||||
|
||||
static bool cmd_remove_frame_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL &&
|
||||
sprite->frames > 1;
|
||||
@ -36,7 +36,7 @@ static bool cmd_remove_frame_enabled(const char *argument)
|
||||
|
||||
static void cmd_remove_frame_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
{
|
||||
Undoable undoable(sprite, "Remove Frame");
|
||||
undoable.remove_frame(sprite->frame);
|
||||
|
@ -23,11 +23,11 @@
|
||||
#include "modules/sprites.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/undo.h"
|
||||
#include "raster/undoable.h"
|
||||
#include "undoable.h"
|
||||
|
||||
static bool cmd_remove_layer_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL &&
|
||||
sprite->layer != NULL;
|
||||
@ -35,7 +35,7 @@ static bool cmd_remove_layer_enabled(const char *argument)
|
||||
|
||||
static void cmd_remove_layer_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
{
|
||||
Undoable undoable(sprite, "Remove Layer");
|
||||
undoable.remove_layer(sprite->layer);
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
static bool cmd_reselect_mask_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL &&
|
||||
sprite_request_mask(sprite, "*deselected*") != NULL;
|
||||
@ -35,7 +35,7 @@ static bool cmd_reselect_mask_enabled(const char *argument)
|
||||
|
||||
static void cmd_reselect_mask_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
Mask *mask;
|
||||
|
||||
/* request *deselected* mask */
|
||||
|
@ -93,7 +93,7 @@ static void save_sprite_in_background(Sprite* sprite, bool mark_as_saved)
|
||||
if (fop) {
|
||||
JThread thread = jthread_new(savefile_bg, fop);
|
||||
if (thread) {
|
||||
SaveFileData *data = jnew(SaveFileData, 1);
|
||||
SaveFileData* data = new SaveFileData;
|
||||
|
||||
data->fop = fop;
|
||||
data->progress = progress_new(app_get_statusbar());
|
||||
@ -118,9 +118,8 @@ static void save_sprite_in_background(Sprite* sprite, bool mark_as_saved)
|
||||
|
||||
/* show any error */
|
||||
if (fop->error) {
|
||||
console_open();
|
||||
console_printf(fop->error);
|
||||
console_close();
|
||||
Console console;
|
||||
console.printf(fop->error);
|
||||
}
|
||||
/* no error? */
|
||||
else {
|
||||
@ -136,16 +135,15 @@ static void save_sprite_in_background(Sprite* sprite, bool mark_as_saved)
|
||||
progress_free(data->progress);
|
||||
jwidget_free(data->alert_window);
|
||||
fop_free(fop);
|
||||
jfree(data);
|
||||
delete data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
static void save_as_dialog(const char* dlg_title, bool mark_as_saved)
|
||||
static void save_as_dialog(Sprite* sprite, const char* dlg_title, bool mark_as_saved)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
char exts[4096];
|
||||
jstring filename;
|
||||
jstring newfilename;
|
||||
@ -200,7 +198,7 @@ static void save_as_dialog(const char* dlg_title, bool mark_as_saved)
|
||||
*/
|
||||
static bool cmd_save_file_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return sprite;
|
||||
}
|
||||
|
||||
@ -211,7 +209,7 @@ static bool cmd_save_file_enabled(const char *argument)
|
||||
*/
|
||||
static void cmd_save_file_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
|
||||
/* if the sprite is associated to a file in the file-system, we can
|
||||
save it directly without user interaction */
|
||||
@ -222,7 +220,7 @@ static void cmd_save_file_execute(const char *argument)
|
||||
save-as dialog to the user to select for first time the file-name
|
||||
for this sprite */
|
||||
else {
|
||||
save_as_dialog(_("Save Sprite"), true);
|
||||
save_as_dialog(sprite, _("Save Sprite"), true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,13 +230,15 @@ static void cmd_save_file_execute(const char *argument)
|
||||
|
||||
static bool cmd_save_file_as_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_save_file_as_execute(const char *argument)
|
||||
{
|
||||
save_as_dialog(_("Save Sprite As"), true);
|
||||
CurrentSpriteWriter sprite;
|
||||
save_as_dialog(sprite, _("Save Sprite As"), true);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
@ -247,17 +247,18 @@ static void cmd_save_file_as_execute(const char *argument)
|
||||
|
||||
static bool cmd_save_file_copy_as_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_save_file_copy_as_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
jstring old_filename = sprite->filename;
|
||||
|
||||
// show "Save As" dialog
|
||||
save_as_dialog(_("Save Sprite Copy As"), false);
|
||||
save_as_dialog(sprite, _("Save Sprite Copy As"), false);
|
||||
|
||||
// restore the file name
|
||||
sprite_set_filename(sprite, old_filename.c_str());
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
static bool cmd_save_mask_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
if (!sprite)
|
||||
return false;
|
||||
else
|
||||
@ -41,7 +41,7 @@ static bool cmd_save_mask_enabled(const char *argument)
|
||||
|
||||
static void cmd_save_mask_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
jstring filename = "default.msk";
|
||||
int ret;
|
||||
|
||||
|
@ -45,17 +45,17 @@ static bool cmd_select_file_enabled(const char *argument)
|
||||
|
||||
static bool cmd_select_file_checked(const char *argument)
|
||||
{
|
||||
CurrentSprite current_sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
|
||||
if (argument) {
|
||||
int sprite_id = ustrtol(argument, NULL, 10);
|
||||
GfxObj *gfxobj = gfxobj_find(sprite_id);
|
||||
return
|
||||
gfxobj && gfxobj->type == GFXOBJ_SPRITE &&
|
||||
current_sprite == (Sprite *)gfxobj;
|
||||
sprite == (Sprite *)gfxobj;
|
||||
}
|
||||
else
|
||||
return current_sprite == NULL;
|
||||
return sprite == NULL;
|
||||
}
|
||||
|
||||
static void cmd_select_file_execute(const char *argument)
|
||||
|
@ -32,36 +32,31 @@
|
||||
#include "widgets/colbut.h"
|
||||
|
||||
/* TODO remove this */
|
||||
void dialogs_frame_length(int sprite_frpos);
|
||||
void dialogs_frame_length(const SpriteReader& sprite, int sprite_frpos);
|
||||
|
||||
static bool cmd_sprite_properties_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_sprite_properties_execute(const char *argument)
|
||||
{
|
||||
JWidget window, killer, name, type, size, frames, speed, ok;
|
||||
CurrentSprite sprite;
|
||||
JWidget killer, name, type, size, frames, speed, ok;
|
||||
const CurrentSpriteReader sprite;
|
||||
jstring imgtype_text;
|
||||
char buf[256];
|
||||
|
||||
/* load the window widget */
|
||||
window = load_widget("sprprop.jid", "sprite_properties");
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
if (!get_widgets(window,
|
||||
"name", &name,
|
||||
"type", &type,
|
||||
"size", &size,
|
||||
"frames", &frames,
|
||||
"speed", &speed,
|
||||
"ok", &ok, NULL)) {
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
JWidgetPtr window = load_widget("sprprop.jid", "sprite_properties");
|
||||
get_widgets(window,
|
||||
"name", &name,
|
||||
"type", &type,
|
||||
"size", &size,
|
||||
"frames", &frames,
|
||||
"speed", &speed,
|
||||
"ok", &ok, NULL);
|
||||
|
||||
/* update widgets values */
|
||||
switch (sprite->imgtype) {
|
||||
@ -110,13 +105,11 @@ static void cmd_sprite_properties_execute(const char *argument)
|
||||
if (killer == ok)
|
||||
break;
|
||||
else if (killer == speed) {
|
||||
dialogs_frame_length(-1);
|
||||
dialogs_frame_length(sprite, -1);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
Command cmd_sprite_properties = {
|
||||
|
@ -32,23 +32,23 @@
|
||||
#include "raster/image.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/stock.h"
|
||||
#include "raster/undoable.h"
|
||||
#include "undoable.h"
|
||||
|
||||
#define PERC_FORMAT "%.1f%%"
|
||||
|
||||
class SpriteSizeJob : public Job
|
||||
{
|
||||
Sprite* m_sprite;
|
||||
SpriteWriter m_sprite;
|
||||
int m_new_width;
|
||||
int m_new_height;
|
||||
ResizeMethod m_resize_method;
|
||||
|
||||
public:
|
||||
|
||||
SpriteSizeJob(Sprite* sprite, int new_width, int new_height, ResizeMethod resize_method)
|
||||
SpriteSizeJob(const SpriteReader& sprite, int new_width, int new_height, ResizeMethod resize_method)
|
||||
: Job("Sprite Size")
|
||||
, m_sprite(sprite)
|
||||
{
|
||||
m_sprite = sprite;
|
||||
m_new_width = new_width;
|
||||
m_new_height = new_height;
|
||||
m_resize_method = resize_method;
|
||||
@ -109,6 +109,9 @@ protected:
|
||||
|
||||
// TODO resize mask
|
||||
|
||||
// regenerate mask
|
||||
sprite_generate_mask_boundaries(m_sprite);
|
||||
|
||||
// commit changes
|
||||
undoable.commit();
|
||||
}
|
||||
@ -123,33 +126,26 @@ static bool height_perc_change_hook(JWidget widget, void *data);
|
||||
|
||||
static bool cmd_sprite_size_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_sprite_size_execute(const char *argument)
|
||||
{
|
||||
JWidget window, width_px, height_px, width_perc, height_perc, lock_ratio, method, ok;
|
||||
CurrentSprite sprite;
|
||||
if (!sprite)
|
||||
return;
|
||||
JWidget width_px, height_px, width_perc, height_perc, lock_ratio, method, ok;
|
||||
const CurrentSpriteReader sprite;
|
||||
|
||||
// load the window widget
|
||||
window = load_widget("sprsize.jid", "sprite_size");
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
if (!get_widgets(window,
|
||||
"width_px", &width_px,
|
||||
"height_px", &height_px,
|
||||
"width_perc", &width_perc,
|
||||
"height_perc", &height_perc,
|
||||
"lock_ratio", &lock_ratio,
|
||||
"method", &method,
|
||||
"ok", &ok, NULL)) {
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
JWidgetPtr window = load_widget("sprsize.jid", "sprite_size");
|
||||
get_widgets(window,
|
||||
"width_px", &width_px,
|
||||
"height_px", &height_px,
|
||||
"width_perc", &width_perc,
|
||||
"height_perc", &height_perc,
|
||||
"lock_ratio", &lock_ratio,
|
||||
"method", &method,
|
||||
"ok", &ok, NULL);
|
||||
|
||||
width_px->textf("%d", sprite->w);
|
||||
height_px->textf("%d", sprite->h);
|
||||
@ -185,16 +181,13 @@ static void cmd_sprite_size_execute(const char *argument)
|
||||
job.do_job();
|
||||
}
|
||||
|
||||
sprite_generate_mask_boundaries(sprite);
|
||||
update_screen_for_sprite(sprite);
|
||||
}
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
static bool lock_ratio_change_hook(JWidget widget, void *data)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
|
||||
if (widget->selected())
|
||||
width_px_change_hook(widget->find_sibling("width_px"), NULL);
|
||||
@ -204,7 +197,7 @@ static bool lock_ratio_change_hook(JWidget widget, void *data)
|
||||
|
||||
static bool width_px_change_hook(JWidget widget, void *data)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
int width = widget->text_int();
|
||||
double perc = 100.0 * width / sprite->w;
|
||||
|
||||
@ -220,7 +213,7 @@ static bool width_px_change_hook(JWidget widget, void *data)
|
||||
|
||||
static bool height_px_change_hook(JWidget widget, void *data)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
int height = widget->text_int();
|
||||
double perc = 100.0 * height / sprite->h;
|
||||
|
||||
@ -236,7 +229,7 @@ static bool height_px_change_hook(JWidget widget, void *data)
|
||||
|
||||
static bool width_perc_change_hook(JWidget widget, void *data)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
double width = widget->text_double();
|
||||
|
||||
widget->find_sibling("width_px")->textf("%d", (int)(sprite->w * width / 100));
|
||||
@ -251,7 +244,7 @@ static bool width_perc_change_hook(JWidget widget, void *data)
|
||||
|
||||
static bool height_perc_change_hook(JWidget widget, void *data)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
double height = widget->text_double();
|
||||
|
||||
widget->find_sibling("height_px")->textf("%d", (int)(sprite->h * height / 100));
|
||||
|
@ -28,13 +28,15 @@
|
||||
|
||||
static bool cmd_undo_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite != NULL && undo_can_undo(sprite->undo);
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL &&
|
||||
undo_can_undo(sprite->undo);
|
||||
}
|
||||
|
||||
static void cmd_undo_execute(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
CurrentSpriteWriter sprite;
|
||||
|
||||
statusbar_show_tip(app_get_statusbar(), 1000,
|
||||
_("Undid %s"),
|
||||
|
@ -250,18 +250,28 @@ Command *command_get_by_key(JMessage msg)
|
||||
*/
|
||||
bool command_is_enabled(Command *command, const char *argument)
|
||||
{
|
||||
if (command && command->enabled)
|
||||
return (*command->enabled)(argument);
|
||||
else
|
||||
return TRUE;
|
||||
try {
|
||||
if (command && command->enabled)
|
||||
return (*command->enabled)(argument);
|
||||
else
|
||||
return true;
|
||||
}
|
||||
catch (...) {
|
||||
// did the "is_enabled" throw an exception? disabled this command so...
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool command_is_checked(Command *command, const char *argument)
|
||||
{
|
||||
if (command && command->checked)
|
||||
return (*command->checked)(argument);
|
||||
else
|
||||
return FALSE;
|
||||
try {
|
||||
if (command && command->checked)
|
||||
return (*command->checked)(argument);
|
||||
}
|
||||
catch (...) {
|
||||
// do nothing
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -270,7 +280,7 @@ bool command_is_checked(Command *command, const char *argument)
|
||||
*/
|
||||
void command_execute(Command *command, const char *argument)
|
||||
{
|
||||
console_open();
|
||||
Console console;
|
||||
|
||||
try {
|
||||
if (command && command->execute &&
|
||||
@ -278,14 +288,17 @@ void command_execute(Command *command, const char *argument)
|
||||
(*command->execute)(argument);
|
||||
}
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
jalert("Error"
|
||||
"<<Uncaught exception:"
|
||||
"<<%s"
|
||||
"||&OK", e.what());
|
||||
catch (ase_exception& e) {
|
||||
e.show();
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
console.printf("An error ocurred executing the command.\n\nDetails:\n%s", e.what());
|
||||
}
|
||||
catch (...) {
|
||||
console.printf("An unknown error ocurred executing the command.\n"
|
||||
"Please try again or report this bug.\n\n"
|
||||
"Details: Unknown exception caught.");
|
||||
}
|
||||
|
||||
console_close();
|
||||
}
|
||||
|
||||
bool command_is_key_pressed(Command *command, JMessage msg)
|
||||
|
@ -20,7 +20,7 @@
|
||||
#define COMMANDS_COMMANDS_H
|
||||
|
||||
#include "jinete/jbase.h"
|
||||
#include "ase/current_sprite.h"
|
||||
#include "sprite_wrappers.h"
|
||||
|
||||
#define CMD_ABOUT "about"
|
||||
#define CMD_ADVANCED_MODE "advanced_mode"
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "effect/effect.h"
|
||||
#include "modules/gui.h"
|
||||
#include "modules/sprites.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/mask.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "util/misc.h"
|
||||
@ -48,18 +47,17 @@ static void make_preview();
|
||||
|
||||
static bool cmd_color_curve_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite != NULL;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_color_curve_execute(const char *argument)
|
||||
{
|
||||
JWidget window, button_ok;
|
||||
const CurrentSpriteReader sprite;
|
||||
JWidget button_ok;
|
||||
JWidget view_curve, curve_editor;
|
||||
JWidget box_target, target_button;
|
||||
CurrentSprite sprite;
|
||||
Image *image;
|
||||
Effect *effect;
|
||||
|
||||
if (!the_curve) {
|
||||
/* default curve */
|
||||
@ -72,39 +70,24 @@ static void cmd_color_curve_execute(const char *argument)
|
||||
the_curve);
|
||||
}
|
||||
|
||||
image = GetImage(sprite);
|
||||
if (!image)
|
||||
return;
|
||||
JWidgetPtr window = load_widget("colcurv.jid", "color_curve");
|
||||
get_widgets(window,
|
||||
"preview", &check_preview,
|
||||
"button_ok", &button_ok,
|
||||
"curve", &view_curve,
|
||||
"target", &box_target, NULL);
|
||||
|
||||
window = load_widget("colcurv.jid", "color_curve");
|
||||
if (!window)
|
||||
return;
|
||||
Effect effect(sprite, "color_curve");
|
||||
effect_set_target(&effect, TARGET_RED_CHANNEL | TARGET_GREEN_CHANNEL |
|
||||
TARGET_BLUE_CHANNEL | TARGET_ALPHA_CHANNEL);
|
||||
|
||||
if (!get_widgets(window,
|
||||
"preview", &check_preview,
|
||||
"button_ok", &button_ok,
|
||||
"curve", &view_curve,
|
||||
"target", &box_target, NULL)) {
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
|
||||
effect = effect_new(sprite, "color_curve");
|
||||
if (!effect) {
|
||||
console_printf(_("Error creating the effect applicator for this sprite\n"));
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
effect_set_target(effect, TARGET_RED_CHANNEL | TARGET_GREEN_CHANNEL |
|
||||
TARGET_BLUE_CHANNEL | TARGET_ALPHA_CHANNEL);
|
||||
|
||||
preview = preview_new(effect);
|
||||
preview = preview_new(&effect);
|
||||
|
||||
set_color_curve(the_curve);
|
||||
|
||||
curve_editor = curve_editor_new(the_curve, 0, 0, 255, 255);
|
||||
target_button = target_button_new(sprite->imgtype, TRUE);
|
||||
target_button_set_target(target_button, effect->target);
|
||||
target_button_set_target(target_button, effect.target);
|
||||
|
||||
if (get_config_bool("ColorCurve", "Preview", TRUE))
|
||||
jwidget_select(check_preview);
|
||||
@ -130,19 +113,14 @@ static void cmd_color_curve_execute(const char *argument)
|
||||
/* open the window */
|
||||
jwindow_open_fg(window);
|
||||
|
||||
if (jwindow_get_killer(window) == button_ok) {
|
||||
effect_apply_to_target_with_progressbar(effect);
|
||||
}
|
||||
|
||||
effect_free(effect);
|
||||
if (jwindow_get_killer(window) == button_ok)
|
||||
effect_apply_to_target_with_progressbar(&effect);
|
||||
|
||||
/* update editors */
|
||||
update_screen_for_sprite(sprite);
|
||||
|
||||
/* save window configuration */
|
||||
save_window_pos(window, "ColorCurve");
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
static bool window_msg_proc(JWidget widget, JMessage msg)
|
||||
|
@ -43,7 +43,6 @@
|
||||
#include "modules/gui.h"
|
||||
#include "modules/sprites.h"
|
||||
#include "modules/tools.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/mask.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "util/misc.h"
|
||||
@ -70,54 +69,37 @@ static void make_preview();
|
||||
|
||||
static bool cmd_convolution_matrix_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite != NULL;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_convolution_matrix_execute(const char *argument)
|
||||
{
|
||||
JWidget window, button_ok;
|
||||
const CurrentSpriteReader sprite;
|
||||
JWidget button_ok;
|
||||
JWidget view_convmatr, list_convmatr;
|
||||
JWidget box_target;
|
||||
JWidget reload, generate;
|
||||
CurrentSprite sprite;
|
||||
Image *image;
|
||||
Effect *effect;
|
||||
|
||||
image = GetImage(sprite);
|
||||
if (!image)
|
||||
return;
|
||||
JWidgetPtr window = load_widget("convmatr.jid", "convolution_matrix");
|
||||
get_widgets(window,
|
||||
"preview", &check_preview,
|
||||
"tiled", &check_tiled,
|
||||
"button_ok", &button_ok,
|
||||
"view", &view_convmatr,
|
||||
"target", &box_target,
|
||||
"reload", &reload,
|
||||
"generate", &generate, NULL);
|
||||
|
||||
window = load_widget("convmatr.jid", "convolution_matrix");
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
if (!get_widgets(window,
|
||||
"preview", &check_preview,
|
||||
"tiled", &check_tiled,
|
||||
"button_ok", &button_ok,
|
||||
"view", &view_convmatr,
|
||||
"target", &box_target,
|
||||
"reload", &reload,
|
||||
"generate", &generate, NULL)) {
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
|
||||
effect = effect_new(sprite, "convolution_matrix");
|
||||
if (!effect) {
|
||||
console_printf(_("Error creating the effect applicator for this sprite\n"));
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
|
||||
preview = preview_new(effect);
|
||||
Effect effect(sprite, "convolution_matrix");
|
||||
preview = preview_new(&effect);
|
||||
|
||||
list_convmatr = jlistbox_new();
|
||||
listbox_fill_convmatg(list_convmatr);
|
||||
|
||||
target_button = target_button_new(sprite->imgtype, TRUE);
|
||||
target_button_set_target(target_button, effect->target);
|
||||
target_button_set_target(target_button, effect.target);
|
||||
|
||||
if (get_config_bool("ConvolutionMatrix", "Preview", TRUE))
|
||||
jwidget_select(check_preview);
|
||||
@ -154,19 +136,14 @@ static void cmd_convolution_matrix_execute(const char *argument)
|
||||
/* open the window */
|
||||
jwindow_open_fg(window);
|
||||
|
||||
if (jwindow_get_killer(window) == button_ok) {
|
||||
effect_apply_to_target_with_progressbar(effect);
|
||||
}
|
||||
|
||||
effect_free(effect);
|
||||
if (jwindow_get_killer(window) == button_ok)
|
||||
effect_apply_to_target_with_progressbar(&effect);
|
||||
|
||||
/* update editors */
|
||||
update_screen_for_sprite(sprite);
|
||||
|
||||
/* save window configuration */
|
||||
save_window_pos(window, "ConvolutionMatrix");
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
static void listbox_fill_convmatg(JWidget listbox)
|
||||
@ -235,7 +212,6 @@ static bool reload_select_hook(JWidget widget, void *data)
|
||||
static bool generate_select_hook(JWidget widget, void *data)
|
||||
{
|
||||
#if 0
|
||||
JWidget window;
|
||||
JWidget view_x;
|
||||
JWidget view_y;
|
||||
JWidget curvedit_x;
|
||||
@ -245,20 +221,14 @@ static bool generate_select_hook(JWidget widget, void *data)
|
||||
JWidget div, div_auto;
|
||||
JWidget bias, bias_auto;
|
||||
|
||||
window = load_widget("convmatr.jid", "generate_convolution_matrix");
|
||||
if (!window)
|
||||
return TRUE; /* don't close */
|
||||
|
||||
if (!get_widgets(window,
|
||||
"view_x", &view_x,
|
||||
"view_y", &view_y,
|
||||
"div", &div,
|
||||
"bias", &bias,
|
||||
"div_auto", &div_auto,
|
||||
"bias_auto", &bias_auto, NULL)) {
|
||||
jwidget_free(window);
|
||||
return TRUE; /* don't close */
|
||||
}
|
||||
JWidgetPtr window = load_widget("convmatr.jid", "generate_convolution_matrix");
|
||||
get_widgets(window,
|
||||
"view_x", &view_x,
|
||||
"view_y", &view_y,
|
||||
"div", &div,
|
||||
"bias", &bias,
|
||||
"div_auto", &div_auto,
|
||||
"bias_auto", &bias_auto, NULL);
|
||||
|
||||
/* curve_x = curve_new(CURVE_SPLINE); */
|
||||
/* curve_y = curve_new(CURVE_SPLINE); */
|
||||
@ -291,12 +261,10 @@ static bool generate_select_hook(JWidget widget, void *data)
|
||||
|
||||
/* TODO do something */
|
||||
|
||||
jwidget_free(window);
|
||||
|
||||
curve_free(curve_x);
|
||||
curve_free(curve_y);
|
||||
#endif
|
||||
return TRUE; /* do not close */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static bool list_change_hook(JWidget widget, void *data)
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include "modules/gui.h"
|
||||
#include "modules/sprites.h"
|
||||
#include "modules/tools.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/mask.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "util/misc.h"
|
||||
@ -57,51 +56,35 @@ static void make_preview();
|
||||
|
||||
static bool cmd_despeckle_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_despeckle_execute(const char *argument)
|
||||
{
|
||||
JWidget window, box_target, target_button, button_ok;
|
||||
CurrentSprite sprite;
|
||||
Image *image;
|
||||
Effect *effect;
|
||||
const CurrentSpriteReader sprite;
|
||||
JWidget box_target, target_button, button_ok;
|
||||
char buf[32];
|
||||
|
||||
image = GetImage(sprite);
|
||||
if (!image)
|
||||
return;
|
||||
JWidgetPtr window = load_widget("median.jid", "median");
|
||||
get_widgets(window,
|
||||
"width", &entry_width,
|
||||
"height", &entry_height,
|
||||
"preview", &check_preview,
|
||||
"tiled", &check_tiled,
|
||||
"target", &box_target,
|
||||
"button_ok", &button_ok, NULL);
|
||||
|
||||
window = load_widget("median.jid", "median");
|
||||
if (!window)
|
||||
return;
|
||||
Effect effect(sprite, "median");
|
||||
effect_set_target(&effect, TARGET_RED_CHANNEL |
|
||||
TARGET_GREEN_CHANNEL |
|
||||
TARGET_BLUE_CHANNEL);
|
||||
|
||||
if (!get_widgets(window,
|
||||
"width", &entry_width,
|
||||
"height", &entry_height,
|
||||
"preview", &check_preview,
|
||||
"tiled", &check_tiled,
|
||||
"target", &box_target,
|
||||
"button_ok", &button_ok, NULL)) {
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
|
||||
effect = effect_new(sprite, "median");
|
||||
if (!effect) {
|
||||
console_printf(_("Error creating the effect applicator for this sprite\n"));
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
effect_set_target(effect, TARGET_RED_CHANNEL |
|
||||
TARGET_GREEN_CHANNEL |
|
||||
TARGET_BLUE_CHANNEL);
|
||||
|
||||
preview = preview_new(effect);
|
||||
preview = preview_new(&effect);
|
||||
|
||||
target_button = target_button_new(sprite->imgtype, TRUE);
|
||||
target_button_set_target(target_button, effect->target);
|
||||
target_button_set_target(target_button, effect.target);
|
||||
|
||||
sprintf(buf, "%d", get_config_int("Median", "Width", 3));
|
||||
jwidget_set_text(entry_width, buf);
|
||||
@ -136,19 +119,14 @@ static void cmd_despeckle_execute(const char *argument)
|
||||
/* open the window */
|
||||
jwindow_open_fg(window);
|
||||
|
||||
if (jwindow_get_killer(window) == button_ok) {
|
||||
effect_apply_to_target_with_progressbar(effect);
|
||||
}
|
||||
|
||||
effect_free(effect);
|
||||
if (jwindow_get_killer(window) == button_ok)
|
||||
effect_apply_to_target_with_progressbar(&effect);
|
||||
|
||||
/* update editors */
|
||||
update_screen_for_sprite(sprite);
|
||||
|
||||
/* save window configuration */
|
||||
save_window_pos(window, "Median");
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
static bool width_change_hook(JWidget widget, void *data)
|
||||
|
@ -51,46 +51,30 @@ static void make_preview();
|
||||
|
||||
static bool cmd_invert_color_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_invert_color_execute(const char *argument)
|
||||
{
|
||||
JWidget window, box_target, target_button, button_ok;
|
||||
CurrentSprite sprite;
|
||||
Image *image;
|
||||
Effect *effect;
|
||||
JWidget box_target, target_button, button_ok;
|
||||
const CurrentSpriteReader sprite;
|
||||
|
||||
image = GetImage(sprite);
|
||||
if (!image)
|
||||
return;
|
||||
JWidgetPtr window = load_widget("invrtcol.jid", "invert_color");
|
||||
get_widgets(window,
|
||||
"target", &box_target,
|
||||
"preview", &check_preview,
|
||||
"button_ok", &button_ok, NULL);
|
||||
|
||||
window = load_widget("invrtcol.jid", "invert_color");
|
||||
if (!window)
|
||||
return;
|
||||
Effect effect(sprite, "invert_color");
|
||||
effect_set_target(&effect, TARGET_RED_CHANNEL |
|
||||
TARGET_GREEN_CHANNEL |
|
||||
TARGET_BLUE_CHANNEL);
|
||||
|
||||
if (!get_widgets(window,
|
||||
"target", &box_target,
|
||||
"preview", &check_preview,
|
||||
"button_ok", &button_ok, NULL)) {
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
|
||||
effect = effect_new(sprite, "invert_color");
|
||||
if (!effect) {
|
||||
console_printf(_("Error creating the effect applicator for this sprite\n"));
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
effect_set_target(effect, TARGET_RED_CHANNEL |
|
||||
TARGET_GREEN_CHANNEL |
|
||||
TARGET_BLUE_CHANNEL);
|
||||
|
||||
preview = preview_new(effect);
|
||||
preview = preview_new(&effect);
|
||||
target_button = target_button_new(sprite->imgtype, TRUE);
|
||||
target_button_set_target(target_button, effect->target);
|
||||
target_button_set_target(target_button, effect.target);
|
||||
|
||||
if (get_config_bool("InvertColor", "Preview", TRUE))
|
||||
jwidget_select(check_preview);
|
||||
@ -114,19 +98,14 @@ static void cmd_invert_color_execute(const char *argument)
|
||||
/* open the window */
|
||||
jwindow_open_fg(window);
|
||||
|
||||
if (jwindow_get_killer(window) == button_ok) {
|
||||
effect_apply_to_target_with_progressbar(effect);
|
||||
}
|
||||
|
||||
effect_free(effect);
|
||||
if (jwindow_get_killer(window) == button_ok)
|
||||
effect_apply_to_target_with_progressbar(&effect);
|
||||
|
||||
/* update editors */
|
||||
update_screen_for_sprite(sprite);
|
||||
|
||||
/* save window configuration */
|
||||
save_window_pos(window, "InvertColor");
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
static bool target_change_hook(JWidget widget, void *data)
|
||||
|
@ -54,51 +54,32 @@ static void make_preview();
|
||||
|
||||
static bool cmd_replace_color_enabled(const char *argument)
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
return sprite;
|
||||
const CurrentSpriteReader sprite;
|
||||
return
|
||||
sprite != NULL;
|
||||
}
|
||||
|
||||
static void cmd_replace_color_execute(const char *argument)
|
||||
{
|
||||
JWidget window = NULL;
|
||||
const CurrentSpriteReader sprite;
|
||||
JWidget color_buttons_box;
|
||||
JWidget box_target, target_button;
|
||||
JWidget button_ok;
|
||||
Image *image;
|
||||
Effect *effect;
|
||||
|
||||
CurrentSprite sprite;
|
||||
if (!sprite)
|
||||
return;
|
||||
JWidgetPtr window = load_widget("replcol.jid", "replace_color");
|
||||
get_widgets(window,
|
||||
"color_buttons_box", &color_buttons_box,
|
||||
"preview", &check_preview,
|
||||
"fuzziness", &slider_fuzziness,
|
||||
"target", &box_target,
|
||||
"button_ok", &button_ok, NULL);
|
||||
|
||||
image = GetImage(sprite);
|
||||
if (!image)
|
||||
goto done;
|
||||
|
||||
window = load_widget("replcol.jid", "replace_color");
|
||||
if (!window)
|
||||
goto done;
|
||||
|
||||
if (!get_widgets(window,
|
||||
"color_buttons_box", &color_buttons_box,
|
||||
"preview", &check_preview,
|
||||
"fuzziness", &slider_fuzziness,
|
||||
"target", &box_target,
|
||||
"button_ok", &button_ok, NULL)) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
effect = effect_new(sprite, "replace_color");
|
||||
if (!effect) {
|
||||
console_printf(_("Error creating the effect applicator for this sprite\n"));
|
||||
goto done;
|
||||
}
|
||||
effect_set_target(effect, TARGET_RED_CHANNEL |
|
||||
TARGET_GREEN_CHANNEL |
|
||||
TARGET_BLUE_CHANNEL |
|
||||
TARGET_ALPHA_CHANNEL);
|
||||
|
||||
preview = preview_new(effect);
|
||||
Effect effect(sprite, "replace_color");
|
||||
effect_set_target(&effect, TARGET_RED_CHANNEL |
|
||||
TARGET_GREEN_CHANNEL |
|
||||
TARGET_BLUE_CHANNEL |
|
||||
TARGET_ALPHA_CHANNEL);
|
||||
preview = preview_new(&effect);
|
||||
|
||||
button_color1 = colorbutton_new
|
||||
(get_config_color("ReplaceColor", "Color1",
|
||||
@ -111,7 +92,7 @@ static void cmd_replace_color_execute(const char *argument)
|
||||
sprite->imgtype);
|
||||
|
||||
target_button = target_button_new(sprite->imgtype, FALSE);
|
||||
target_button_set_target(target_button, effect->target);
|
||||
target_button_set_target(target_button, effect.target);
|
||||
|
||||
jslider_set_value(slider_fuzziness,
|
||||
get_config_int("ReplaceColor", "Fuzziness", 0));
|
||||
@ -142,21 +123,14 @@ static void cmd_replace_color_execute(const char *argument)
|
||||
/* open the window */
|
||||
jwindow_open_fg(window);
|
||||
|
||||
if (jwindow_get_killer(window) == button_ok) {
|
||||
effect_apply_to_target_with_progressbar(effect);
|
||||
}
|
||||
|
||||
effect_free(effect);
|
||||
if (jwindow_get_killer(window) == button_ok)
|
||||
effect_apply_to_target_with_progressbar(&effect);
|
||||
|
||||
/* update editors */
|
||||
update_screen_for_sprite(sprite);
|
||||
|
||||
/* save window configuration */
|
||||
save_window_pos(window, "ReplaceColor");
|
||||
|
||||
done:;
|
||||
if (window)
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
static bool color_change_hook(JWidget widget, void *data)
|
||||
@ -194,7 +168,7 @@ static bool preview_change_hook(JWidget widget, void *data)
|
||||
|
||||
static void make_preview()
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
Sprite* sprite = preview_get_effect(preview)->sprite;
|
||||
color_t from, to;
|
||||
int fuzziness;
|
||||
|
||||
|
@ -148,15 +148,9 @@ static void monitor_free(void *_data)
|
||||
*
|
||||
* [main thread]
|
||||
*/
|
||||
void effect_apply_to_target_with_progressbar(Effect *effect)
|
||||
void effect_apply_to_target_with_progressbar(Effect* effect)
|
||||
{
|
||||
ThreadData *data;
|
||||
|
||||
data = jnew(ThreadData, 1);
|
||||
if (data == NULL) {
|
||||
jalert("Error<<Not enough memory||&OK");
|
||||
return;
|
||||
}
|
||||
ThreadData *data = new ThreadData;
|
||||
|
||||
effect->progress_data = data;
|
||||
effect->progress = effect_progress_hook;
|
||||
@ -190,5 +184,5 @@ void effect_apply_to_target_with_progressbar(Effect *effect)
|
||||
|
||||
progress_free(data->progress);
|
||||
jwidget_free(data->alert_window);
|
||||
jfree(data);
|
||||
delete data;
|
||||
}
|
||||
|
@ -37,12 +37,10 @@ static int console_counter = 0;
|
||||
static bool console_locked;
|
||||
static bool want_close_flag = FALSE;
|
||||
|
||||
void console_open()
|
||||
Console::Console()
|
||||
{
|
||||
console_counter++;
|
||||
|
||||
/* TODO verify if the ji_screen works */
|
||||
/* if (!screen || */
|
||||
if (!ji_screen ||
|
||||
!is_interactive() ||
|
||||
wid_console ||
|
||||
@ -51,7 +49,7 @@ void console_open()
|
||||
else {
|
||||
JWidget window, grid, view, textbox, button;
|
||||
|
||||
window = jwindow_new(_("Processing..."));
|
||||
window = jwindow_new(_("Errors Console"));
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
@ -87,7 +85,7 @@ void console_open()
|
||||
}
|
||||
}
|
||||
|
||||
void console_close()
|
||||
Console::~Console()
|
||||
{
|
||||
console_counter--;
|
||||
|
||||
@ -105,7 +103,7 @@ void console_close()
|
||||
}
|
||||
}
|
||||
|
||||
void console_printf(const char *format, ...)
|
||||
void Console::printf(const char *format, ...)
|
||||
{
|
||||
char buf[1024];
|
||||
va_list ap;
|
||||
@ -154,6 +152,9 @@ void console_printf(const char *format, ...)
|
||||
else {
|
||||
fputs(buf, stdout);
|
||||
fflush(stdout);
|
||||
|
||||
if (ji_screen)
|
||||
jalert("Error<<%s||OK", buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,10 +19,15 @@
|
||||
#ifndef CONSOLE_H
|
||||
#define CONSOLE_H
|
||||
|
||||
void console_open();
|
||||
void console_close();
|
||||
class Console
|
||||
{
|
||||
public:
|
||||
Console();
|
||||
~Console();
|
||||
|
||||
void printf(const char *format, ...);
|
||||
};
|
||||
|
||||
void console_printf(const char *format, ...);
|
||||
void user_printf(const char *format, ...);
|
||||
|
||||
#endif /* CONSOLE_H */
|
||||
|
100
src/core/app.cpp
100
src/core/app.cpp
@ -72,17 +72,22 @@ enum {
|
||||
OPEN_GFX_FILE,
|
||||
};
|
||||
|
||||
typedef struct Option
|
||||
struct Option
|
||||
{
|
||||
int type;
|
||||
char *data;
|
||||
} Option;
|
||||
};
|
||||
|
||||
typedef struct AppHook
|
||||
struct AppHook
|
||||
{
|
||||
void (*proc)(void *);
|
||||
void *data;
|
||||
} AppHook;
|
||||
|
||||
AppHook(void (*proc)(void *), void *data) {
|
||||
this->proc = proc;
|
||||
this->data = data;
|
||||
}
|
||||
};
|
||||
|
||||
static char *exe_name; /* name of the program */
|
||||
|
||||
@ -111,9 +116,6 @@ static void usage(int status);
|
||||
static Option *option_new(int type, const char *data);
|
||||
static void option_free(Option *option);
|
||||
|
||||
static AppHook *apphook_new(void (*proc)(void *), void *data);
|
||||
static void apphook_free(AppHook *apphook);
|
||||
|
||||
/**
|
||||
* Initializes the application loading the modules, setting the
|
||||
* graphics mode, loading the configuration and resources, etc.
|
||||
@ -175,7 +177,8 @@ bool app_init(int argc, char *argv[])
|
||||
pal = palette_load(palette_filename);
|
||||
if (pal == NULL) {
|
||||
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
|
||||
console_printf(_("Error loading default palette from `%s'\n"),
|
||||
Console console;
|
||||
console.printf(_("Error loading default palette from `%s'\n"),
|
||||
palette_filename);
|
||||
return FALSE;
|
||||
}
|
||||
@ -332,12 +335,9 @@ void app_loop()
|
||||
/* select language */
|
||||
dialogs_select_language(FALSE);
|
||||
|
||||
/* show tips? */
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
if (!sprite)
|
||||
dialogs_tips(FALSE);
|
||||
}
|
||||
// show tips only if there are not a current sprite
|
||||
if (!UIContext::instance()->get_current_sprite())
|
||||
dialogs_tips(FALSE);
|
||||
|
||||
// support to drop files from Windows explorer
|
||||
install_drop_files();
|
||||
@ -377,7 +377,8 @@ void app_exit()
|
||||
for (c=0; c<APP_EVENTS; ++c) {
|
||||
if (apphooks[c] != NULL) {
|
||||
JI_LIST_FOR_EACH(apphooks[c], link) {
|
||||
apphook_free(reinterpret_cast<AppHook*>(link->data));
|
||||
AppHook* apphook = reinterpret_cast<AppHook*>(link->data);
|
||||
delete apphook;
|
||||
}
|
||||
jlist_free(apphooks[c]);
|
||||
apphooks[c] = NULL;
|
||||
@ -406,7 +407,7 @@ void app_add_hook(int app_event, void (*proc)(void *data), void *data)
|
||||
if (apphooks[app_event] == NULL)
|
||||
apphooks[app_event] = jlist_new();
|
||||
|
||||
jlist_append(apphooks[app_event], apphook_new(proc, data));
|
||||
jlist_append(apphooks[app_event], new AppHook(proc, data));
|
||||
}
|
||||
|
||||
void app_trigger_event(int app_event)
|
||||
@ -427,19 +428,17 @@ void app_trigger_event(int app_event)
|
||||
/**
|
||||
* Updates palette and redraw the screen.
|
||||
*/
|
||||
void app_refresh_screen()
|
||||
void app_refresh_screen(const Sprite* sprite)
|
||||
{
|
||||
if (ase_mode & MODE_GUI) {
|
||||
CurrentSprite sprite;
|
||||
assert(screen != NULL);
|
||||
|
||||
/* update the color palette */
|
||||
set_current_palette(sprite != NULL ?
|
||||
sprite_get_palette(sprite, sprite->frame): NULL,
|
||||
FALSE);
|
||||
if (sprite)
|
||||
set_current_palette(sprite_get_palette(sprite, sprite->frame), false);
|
||||
else
|
||||
set_current_palette(NULL, false);
|
||||
|
||||
/* redraw the screen */
|
||||
jmanager_refresh_screen();
|
||||
}
|
||||
// redraw the screen
|
||||
jmanager_refresh_screen();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -514,8 +513,11 @@ bool app_realloc_recent_list()
|
||||
|
||||
int app_get_current_image_type()
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
if (sprite)
|
||||
Context* context = UIContext::instance();
|
||||
assert(context != NULL);
|
||||
|
||||
Sprite* sprite = context->get_current_sprite();
|
||||
if (sprite != NULL)
|
||||
return sprite->imgtype;
|
||||
else if (screen != NULL && bitmap_color_depth(screen) == 8)
|
||||
return IMAGE_INDEXED;
|
||||
@ -589,6 +591,7 @@ static void tabsbar_select_callback(JWidget tabs, void *data, int button)
|
||||
*/
|
||||
static int check_args(int argc, char *argv[])
|
||||
{
|
||||
Console console;
|
||||
int i, n, len;
|
||||
char *arg;
|
||||
|
||||
@ -643,7 +646,7 @@ static int check_args(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
else {
|
||||
console_printf(_("%s: option \"res\" requires an argument\n"), exe_name);
|
||||
console.printf(_("%s: option \"res\" requires an argument\n"), exe_name);
|
||||
usage(1);
|
||||
}
|
||||
}
|
||||
@ -659,7 +662,7 @@ static int check_args(int argc, char *argv[])
|
||||
else if (strncmp(arg+n, "version", len) == 0) {
|
||||
ase_mode |= MODE_BATCH;
|
||||
|
||||
console_printf("ase %s\n", VERSION);
|
||||
console.printf("ase %s\n", VERSION);
|
||||
}
|
||||
/* invalid argument */
|
||||
else {
|
||||
@ -679,21 +682,23 @@ static int check_args(int argc, char *argv[])
|
||||
*/
|
||||
static void usage(int status)
|
||||
{
|
||||
Console console;
|
||||
|
||||
/* show options */
|
||||
if (!status) {
|
||||
/* copyright */
|
||||
console_printf
|
||||
console.printf
|
||||
("ase %s -- allegro-sprite-editor, %s\n"
|
||||
COPYRIGHT "\n\n",
|
||||
VERSION, _("The Ultimate Sprites Factory"));
|
||||
|
||||
/* usage */
|
||||
console_printf
|
||||
console.printf
|
||||
("%s\n %s [%s] [%s]...\n\n",
|
||||
_("Usage:"), exe_name, _("OPTION"), _("FILE"));
|
||||
|
||||
/* options */
|
||||
console_printf
|
||||
console.printf
|
||||
("%s:\n"
|
||||
" -palette GFX-FILE %s\n"
|
||||
" -resolution WxH[xBPP] %s\n"
|
||||
@ -709,24 +714,20 @@ static void usage(int status)
|
||||
_("Output version information and exit"));
|
||||
|
||||
/* web-site */
|
||||
console_printf
|
||||
console.printf
|
||||
("%s: %s\n%s\n\n %s\n\n",
|
||||
_("Find more information in the ASE's official web site at:"), WEBSITE);
|
||||
}
|
||||
/* how to show options */
|
||||
else {
|
||||
console_printf(_("Try \"%s --help\" for more information.\n"), exe_name);
|
||||
console.printf(_("Try \"%s --help\" for more information.\n"), exe_name);
|
||||
}
|
||||
exit(status);
|
||||
}
|
||||
|
||||
static Option *option_new(int type, const char *data)
|
||||
{
|
||||
Option *option;
|
||||
|
||||
option = jnew(Option, 1);
|
||||
if (!option)
|
||||
return NULL;
|
||||
Option *option = new Option;
|
||||
|
||||
option->type = type;
|
||||
option->data = jstrdup(data);
|
||||
@ -737,22 +738,5 @@ static Option *option_new(int type, const char *data)
|
||||
static void option_free(Option* option)
|
||||
{
|
||||
jfree(option->data);
|
||||
jfree(option);
|
||||
}
|
||||
|
||||
static AppHook *apphook_new(void (*proc)(void*), void* data)
|
||||
{
|
||||
AppHook* apphook = jnew(AppHook, 1);
|
||||
if (!apphook)
|
||||
return NULL;
|
||||
|
||||
apphook->proc = proc;
|
||||
apphook->data = data;
|
||||
|
||||
return apphook;
|
||||
}
|
||||
|
||||
static void apphook_free(AppHook *apphook)
|
||||
{
|
||||
jfree(apphook);
|
||||
delete option;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ void app_exit();
|
||||
void app_add_hook(int app_event, void (*proc)(void *data), void *data);
|
||||
void app_trigger_event(int app_event);
|
||||
|
||||
void app_refresh_screen();
|
||||
void app_refresh_screen(const Sprite* sprite);
|
||||
|
||||
void app_realloc_sprite_list();
|
||||
bool app_realloc_recent_list();
|
||||
|
@ -34,9 +34,8 @@
|
||||
#include "modules/rootmenu.h"
|
||||
#include "modules/sprites.h"
|
||||
#include "raster/raster.h"
|
||||
#include "raster/undoable.h"
|
||||
#include "undoable.h"
|
||||
#include "util/celmove.h"
|
||||
#include "util/functions.h"
|
||||
#include "util/thmbnail.h"
|
||||
|
||||
/*
|
||||
@ -98,9 +97,8 @@ enum {
|
||||
|
||||
typedef struct AniEditor
|
||||
{
|
||||
Sprite* sprite;
|
||||
const Sprite* sprite;
|
||||
int state;
|
||||
Layer* selected_layer;
|
||||
Layer** layers;
|
||||
int nlayers;
|
||||
int scroll_x;
|
||||
@ -122,7 +120,7 @@ typedef struct AniEditor
|
||||
|
||||
static JWidget current_anieditor = NULL;
|
||||
|
||||
static JWidget anieditor_new(Sprite* sprite);
|
||||
static JWidget anieditor_new(const Sprite* sprite);
|
||||
static int anieditor_type();
|
||||
static AniEditor* anieditor_data(JWidget widget);
|
||||
static bool anieditor_msg_proc(JWidget widget, JMessage msg);
|
||||
@ -163,7 +161,7 @@ bool animation_editor_is_movingcel()
|
||||
*/
|
||||
void switch_between_animation_and_sprite_editor()
|
||||
{
|
||||
CurrentSprite sprite;
|
||||
const Sprite* sprite = UIContext::instance()->get_current_sprite();
|
||||
JWidget window;
|
||||
JWidget anieditor;
|
||||
int layer;
|
||||
@ -198,10 +196,10 @@ void switch_between_animation_and_sprite_editor()
|
||||
The Animation Editor
|
||||
*********************************************************************/
|
||||
|
||||
static JWidget anieditor_new(Sprite* sprite)
|
||||
static JWidget anieditor_new(const Sprite* sprite)
|
||||
{
|
||||
JWidget widget = jwidget_new(anieditor_type());
|
||||
AniEditor* anieditor = jnew0(AniEditor, 1);
|
||||
AniEditor* anieditor = new AniEditor;
|
||||
|
||||
anieditor->sprite = sprite;
|
||||
anieditor->state = STATE_STANDBY;
|
||||
@ -245,7 +243,7 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
|
||||
case JM_DESTROY:
|
||||
if (anieditor->layers)
|
||||
jfree(anieditor->layers);
|
||||
jfree(anieditor);
|
||||
delete anieditor;
|
||||
break;
|
||||
|
||||
case JM_REQSIZE:
|
||||
@ -325,18 +323,26 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
|
||||
/* do nothing */
|
||||
break;
|
||||
case PART_HEADER_FRAME:
|
||||
anieditor->sprite->frame = anieditor->clk_frame;
|
||||
{
|
||||
const SpriteReader sprite((Sprite*)anieditor->sprite);
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
sprite_writer->frame = anieditor->clk_frame;
|
||||
}
|
||||
jwidget_dirty(widget); /* TODO replace this by redrawing old current frame and new current frame */
|
||||
jwidget_hard_capture_mouse(widget);
|
||||
anieditor->state = STATE_MOVING_FRAME;
|
||||
break;
|
||||
case PART_LAYER: {
|
||||
int old_layer = anieditor_get_layer_index(widget, anieditor->sprite->layer);
|
||||
const SpriteReader sprite((Sprite*)anieditor->sprite);
|
||||
int old_layer = anieditor_get_layer_index(widget, sprite->layer);
|
||||
int frame = anieditor->sprite->frame;
|
||||
|
||||
/* did the user select another layer? */
|
||||
if (old_layer != anieditor->clk_layer) {
|
||||
anieditor->sprite->layer = anieditor->layers[anieditor->clk_layer];
|
||||
{
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
sprite_writer->layer = anieditor->layers[anieditor->clk_layer];
|
||||
}
|
||||
|
||||
jmouse_hide();
|
||||
/* redraw the old & new selected cel */
|
||||
@ -348,9 +354,7 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
|
||||
}
|
||||
|
||||
/* change the scroll to show the new selected cel */
|
||||
anieditor_show_cel(widget,
|
||||
anieditor->clk_layer,
|
||||
anieditor->sprite->frame);
|
||||
anieditor_show_cel(widget, anieditor->clk_layer, sprite->frame);
|
||||
jwidget_hard_capture_mouse(widget);
|
||||
anieditor->state = STATE_MOVING_LAYER;
|
||||
break;
|
||||
@ -362,14 +366,18 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
|
||||
jwidget_hard_capture_mouse(widget);
|
||||
break;
|
||||
case PART_CEL: {
|
||||
int old_layer = anieditor_get_layer_index(widget, anieditor->sprite->layer);
|
||||
int old_frame = anieditor->sprite->frame;
|
||||
const SpriteReader sprite((Sprite*)anieditor->sprite);
|
||||
int old_layer = anieditor_get_layer_index(widget, sprite->layer);
|
||||
int old_frame = sprite->frame;
|
||||
|
||||
/* select the new clicked-part */
|
||||
if (old_layer != anieditor->clk_layer ||
|
||||
old_frame != anieditor->clk_frame) {
|
||||
anieditor->sprite->layer = anieditor->layers[anieditor->clk_layer];
|
||||
anieditor->sprite->frame = anieditor->clk_frame;
|
||||
{
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
sprite_writer->layer = anieditor->layers[anieditor->clk_layer];
|
||||
sprite_writer->frame = anieditor->clk_frame;
|
||||
}
|
||||
|
||||
jmouse_hide();
|
||||
/* redraw the old & new selected layer */
|
||||
@ -385,9 +393,7 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
|
||||
}
|
||||
|
||||
/* change the scroll to show the new selected cel */
|
||||
anieditor_show_cel(widget,
|
||||
anieditor->clk_layer,
|
||||
anieditor->sprite->frame);
|
||||
anieditor_show_cel(widget, anieditor->clk_layer, sprite->frame);
|
||||
|
||||
/* capture the mouse (to move the cel) */
|
||||
jwidget_hard_capture_mouse(widget);
|
||||
@ -533,11 +539,14 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
|
||||
if (anieditor->clk_frame == anieditor->hot_frame)
|
||||
command_execute(command_get_by_name(CMD_FRAME_PROPERTIES), NULL);
|
||||
else {
|
||||
const SpriteReader sprite((Sprite*)anieditor->sprite);
|
||||
|
||||
if (anieditor->hot_frame >= 0 &&
|
||||
anieditor->hot_frame < anieditor->sprite->frames &&
|
||||
anieditor->hot_frame < sprite->frames &&
|
||||
anieditor->hot_frame != anieditor->clk_frame+1) {
|
||||
{
|
||||
Undoable undoable(anieditor->sprite, "Move Frame");
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
Undoable undoable(sprite_writer, "Move Frame");
|
||||
undoable.move_frame_before(anieditor->clk_frame, anieditor->hot_frame);
|
||||
undoable.commit();
|
||||
}
|
||||
@ -568,15 +577,20 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
|
||||
anieditor->hot_layer != anieditor->clk_layer+1) {
|
||||
if (!layer_is_background(anieditor->layers[anieditor->clk_layer])) {
|
||||
// move the clicked-layer after the hot-layer
|
||||
{
|
||||
Undoable undoable(anieditor->sprite, "Move Layer");
|
||||
try {
|
||||
const SpriteReader sprite((Sprite*)anieditor->sprite);
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
Undoable undoable(sprite_writer, "Move Layer");
|
||||
undoable.move_layer_after(anieditor->layers[anieditor->clk_layer],
|
||||
anieditor->layers[anieditor->hot_layer]);
|
||||
undoable.commit();
|
||||
}
|
||||
|
||||
/* select the new layer */
|
||||
anieditor->sprite->layer = anieditor->layers[anieditor->clk_layer];
|
||||
/* select the new layer */
|
||||
sprite_writer->layer = anieditor->layers[anieditor->clk_layer];
|
||||
}
|
||||
catch (locked_sprite_exception& e) {
|
||||
e.show();
|
||||
}
|
||||
|
||||
jwidget_dirty(widget);
|
||||
anieditor_regenerate_layers(widget);
|
||||
@ -639,7 +653,11 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
|
||||
/* move the cel */
|
||||
else if (msg->mouse.left) {
|
||||
if (movement) {
|
||||
move_cel(anieditor->sprite);
|
||||
{
|
||||
const SpriteReader sprite((Sprite*)anieditor->sprite);
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
move_cel(sprite_writer);
|
||||
}
|
||||
|
||||
destroy_thumbnails();
|
||||
anieditor_regenerate_layers(widget);
|
||||
@ -668,7 +686,6 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
|
||||
|
||||
case JM_KEYPRESSED: {
|
||||
Command *command = command_get_by_key(msg);
|
||||
Sprite *sprite = anieditor->sprite;
|
||||
|
||||
/* close animation editor */
|
||||
if ((command && (strcmp(command->name, CMD_FILM_EDITOR) == 0)) ||
|
||||
@ -679,8 +696,10 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
|
||||
|
||||
/* undo */
|
||||
if (command && strcmp(command->name, CMD_UNDO) == 0) {
|
||||
const SpriteReader sprite((Sprite*)anieditor->sprite);
|
||||
if (undo_can_undo(sprite->undo)) {
|
||||
undo_do_undo(sprite->undo);
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
undo_do_undo(sprite_writer->undo);
|
||||
|
||||
destroy_thumbnails();
|
||||
anieditor_regenerate_layers(widget);
|
||||
@ -692,8 +711,10 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg)
|
||||
|
||||
/* redo */
|
||||
if (command && strcmp(command->name, CMD_REDO) == 0) {
|
||||
const SpriteReader sprite((Sprite*)anieditor->sprite);
|
||||
if (undo_can_redo(sprite->undo)) {
|
||||
undo_do_redo(sprite->undo);
|
||||
SpriteWriter sprite_writer(sprite);
|
||||
undo_do_redo(sprite_writer->undo);
|
||||
|
||||
destroy_thumbnails();
|
||||
anieditor_regenerate_layers(widget);
|
||||
|
@ -50,8 +50,9 @@ static void update_button_text();
|
||||
|
||||
void dialogs_draw_text(Sprite* sprite)
|
||||
{
|
||||
#if 0
|
||||
Image *image, *dest_image;
|
||||
JWidget window, button_ok, color_box, color_but;
|
||||
JWidget button_ok, color_box, color_but;
|
||||
JWidget entry_size, entry_text;
|
||||
char buf[256];
|
||||
|
||||
@ -62,9 +63,7 @@ void dialogs_draw_text(Sprite* sprite)
|
||||
if (!dest_image)
|
||||
return;
|
||||
|
||||
window = load_widget("drawtext.jid", "drawtext_window");
|
||||
if (!window)
|
||||
return;
|
||||
JWidgetPtr window = load_widget("drawtext.jid", "drawtext_window");
|
||||
|
||||
if (!get_widgets(window,
|
||||
"font", &font_button,
|
||||
@ -72,7 +71,6 @@ void dialogs_draw_text(Sprite* sprite)
|
||||
"size", &entry_size,
|
||||
"color_box", &color_box,
|
||||
"ok", &button_ok, NULL)) {
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -147,8 +145,7 @@ void dialogs_draw_text(Sprite* sprite)
|
||||
destroy_font(f);
|
||||
}
|
||||
}
|
||||
|
||||
jwidget_free(window);
|
||||
#endif
|
||||
}
|
||||
|
||||
Image *RenderText(Sprite* sprite, const char *fontname, int size, int color, const char *text)
|
||||
@ -270,8 +267,10 @@ static FONT *my_load_font(const char *filename)
|
||||
dirs_free(dirs);
|
||||
|
||||
/* error loading font */
|
||||
if (!f)
|
||||
console_printf(_("Error loading font.\n"));
|
||||
if (!f) {
|
||||
Console console;
|
||||
console.printf(_("Error loading font.\n"));
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ static bool slider_mouse_hook(JWidget widget, void *data);
|
||||
/* shows option dialog */
|
||||
void dialogs_options()
|
||||
{
|
||||
JWidget window, check_smooth, check_dither;
|
||||
JWidget check_smooth, check_dither;
|
||||
JWidget button_ok;
|
||||
JWidget move_click2, draw_click2, killer;
|
||||
JWidget undo_size_limit;
|
||||
@ -60,23 +60,17 @@ void dialogs_options()
|
||||
old_y = y;
|
||||
|
||||
/* load the window widget */
|
||||
window = load_widget("options.jid", "options");
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
if (!get_widgets(window,
|
||||
"mouse_x", &slider_x,
|
||||
"mouse_y", &slider_y,
|
||||
"lock_axis", &check_lockmouse,
|
||||
"smooth", &check_smooth,
|
||||
"dither", &check_dither,
|
||||
"move_click2", &move_click2,
|
||||
"draw_click2", &draw_click2,
|
||||
"undo_size_limit", &undo_size_limit,
|
||||
"button_ok", &button_ok, NULL)) {
|
||||
jwidget_free(window);
|
||||
return;
|
||||
}
|
||||
JWidgetPtr window = load_widget("options.jid", "options");
|
||||
get_widgets(window,
|
||||
"mouse_x", &slider_x,
|
||||
"mouse_y", &slider_y,
|
||||
"lock_axis", &check_lockmouse,
|
||||
"smooth", &check_smooth,
|
||||
"dither", &check_dither,
|
||||
"move_click2", &move_click2,
|
||||
"draw_click2", &draw_click2,
|
||||
"undo_size_limit", &undo_size_limit,
|
||||
"button_ok", &button_ok, NULL);
|
||||
|
||||
jslider_set_value(slider_x, x);
|
||||
jslider_set_value(slider_y, y);
|
||||
@ -129,8 +123,6 @@ void dialogs_options()
|
||||
|
||||
set_mouse_speed(8-old_x, 8-old_y);
|
||||
}
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
static bool slider_mouse_hook(JWidget widget, void *data)
|
||||
|
@ -272,7 +272,8 @@ static int tips_count_pages()
|
||||
|
||||
f = tips_open_file();
|
||||
if (!f) {
|
||||
console_printf("Error loading tips files\n");
|
||||
Console console;
|
||||
console.printf("Error loading tips files\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -283,8 +284,10 @@ static int tips_count_pages()
|
||||
|
||||
fclose(f);
|
||||
|
||||
if (!page)
|
||||
console_printf("No pages tips file\n");
|
||||
if (!page) {
|
||||
Console console;
|
||||
console.printf("No pages tips file\n");
|
||||
}
|
||||
|
||||
return page;
|
||||
}
|
||||
|
@ -69,9 +69,9 @@ static EffectData effects_data[] = {
|
||||
};
|
||||
|
||||
static EffectData *get_effect_data(const char *name);
|
||||
static int effect_init(Effect *effect, Layer *layer, Image *image, int offset_x, int offset_y);
|
||||
static void effect_init(Effect *effect, Layer *layer, Image *image, int offset_x, int offset_y);
|
||||
static void effect_apply_to_image(Effect *effect, ImageRef *p, int x, int y);
|
||||
static int effect_update_mask(Effect *effect, Mask *mask, Image *image);
|
||||
static bool effect_update_mask(Effect *effect, Mask *mask, Image *image);
|
||||
|
||||
int init_module_effect()
|
||||
{
|
||||
@ -84,68 +84,55 @@ void exit_module_effect()
|
||||
exit_convolution_matrix();
|
||||
}
|
||||
|
||||
Effect *effect_new(Sprite *sprite, const char *name)
|
||||
Effect::Effect(const SpriteReader& sprite, const char* name)
|
||||
{
|
||||
int offset_x, offset_y;
|
||||
EffectData *effect_data;
|
||||
Effect *effect;
|
||||
Image *image;
|
||||
EffectData* effect_data;
|
||||
Image* image;
|
||||
void (*apply)(Effect*);
|
||||
|
||||
effect_data = get_effect_data(name);
|
||||
if (!effect_data)
|
||||
return NULL;
|
||||
|
||||
apply = NULL;
|
||||
switch (sprite->imgtype) {
|
||||
case IMAGE_RGB: apply = effect_data->apply_4; break;
|
||||
case IMAGE_GRAYSCALE: apply = effect_data->apply_2; break;
|
||||
case IMAGE_INDEXED: apply = effect_data->apply_1; break;
|
||||
default:
|
||||
throw invalid_imgtype_exception();
|
||||
}
|
||||
if (!apply)
|
||||
return NULL;
|
||||
|
||||
effect = jnew(Effect, 1);
|
||||
if (!effect)
|
||||
return NULL;
|
||||
|
||||
effect->sprite = sprite;
|
||||
effect->src = NULL;
|
||||
effect->dst = NULL;
|
||||
effect->row = 0;
|
||||
effect->offset_x = 0;
|
||||
effect->offset_y = 0;
|
||||
effect->mask = NULL;
|
||||
effect->preview_mask = NULL;
|
||||
effect->mask_address = NULL;
|
||||
effect->effect_data = effect_data;
|
||||
effect->apply = apply;
|
||||
effect->_target = TARGET_ALL_CHANNELS;
|
||||
effect->target = TARGET_ALL_CHANNELS;
|
||||
effect->progress_data = NULL;
|
||||
effect->progress = NULL;
|
||||
effect->is_cancelled = NULL;
|
||||
this->sprite = sprite;
|
||||
this->src = NULL;
|
||||
this->dst = NULL;
|
||||
this->row = 0;
|
||||
this->offset_x = 0;
|
||||
this->offset_y = 0;
|
||||
this->mask = NULL;
|
||||
this->preview_mask = NULL;
|
||||
this->mask_address = NULL;
|
||||
this->effect_data = effect_data;
|
||||
this->apply = apply;
|
||||
this->_target = TARGET_ALL_CHANNELS;
|
||||
this->target = TARGET_ALL_CHANNELS;
|
||||
this->progress_data = NULL;
|
||||
this->progress = NULL;
|
||||
this->is_cancelled = NULL;
|
||||
|
||||
image = GetImage2(sprite, &offset_x, &offset_y, NULL);
|
||||
if (image) {
|
||||
if (!effect_init(effect, sprite->layer, image, offset_x, offset_y)) {
|
||||
effect_free(effect);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (image == NULL)
|
||||
throw no_image_exception();
|
||||
|
||||
return effect;
|
||||
effect_init(this, sprite->layer, image, offset_x, offset_y);
|
||||
}
|
||||
|
||||
void effect_free(Effect *effect)
|
||||
Effect::~Effect()
|
||||
{
|
||||
if (effect->preview_mask)
|
||||
mask_free(effect->preview_mask);
|
||||
if (this->preview_mask)
|
||||
mask_free(this->preview_mask);
|
||||
|
||||
if (effect->dst)
|
||||
image_free(effect->dst);
|
||||
|
||||
jfree(effect);
|
||||
if (this->dst)
|
||||
image_free(this->dst);
|
||||
}
|
||||
|
||||
void effect_set_target(Effect *effect, int target)
|
||||
@ -363,17 +350,17 @@ static EffectData *get_effect_data(const char *name)
|
||||
return effects_data+c;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
throw invalid_effect_exception(name);
|
||||
}
|
||||
|
||||
static int effect_init(Effect *effect, Layer *layer, Image *image,
|
||||
int offset_x, int offset_y)
|
||||
static void effect_init(Effect *effect, Layer *layer, Image *image,
|
||||
int offset_x, int offset_y)
|
||||
{
|
||||
effect->offset_x = offset_x;
|
||||
effect->offset_y = offset_y;
|
||||
|
||||
if (!effect_update_mask(effect, effect->sprite->mask, image))
|
||||
return FALSE;
|
||||
throw invalid_area_exception();
|
||||
|
||||
if (effect->preview_mask) {
|
||||
mask_free(effect->preview_mask);
|
||||
@ -397,17 +384,15 @@ static int effect_init(Effect *effect, Layer *layer, Image *image,
|
||||
/* the alpha channel of the background layer can't be modified */
|
||||
if (layer_is_background(layer))
|
||||
effect->target &= ~TARGET_ALPHA_CHANNEL;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void effect_apply_to_image(Effect *effect, ImageRef *p, int x, int y)
|
||||
{
|
||||
if (effect_init(effect, p->layer, p->image, x, y))
|
||||
effect_apply(effect);
|
||||
effect_init(effect, p->layer, p->image, x, y);
|
||||
effect_apply(effect);
|
||||
}
|
||||
|
||||
static int effect_update_mask(Effect *effect, Mask *mask, Image *image)
|
||||
static bool effect_update_mask(Effect *effect, Mask *mask, Image *image)
|
||||
{
|
||||
int x, y, w, h;
|
||||
|
||||
@ -445,13 +430,13 @@ static int effect_update_mask(Effect *effect, Mask *mask, Image *image)
|
||||
effect->y = 0;
|
||||
effect->w = 0;
|
||||
effect->h = 0;
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
effect->x = x;
|
||||
effect->y = y;
|
||||
effect->w = w;
|
||||
effect->h = h;
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@
|
||||
#define EFFECT_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cstring>
|
||||
#include "sprite_wrappers.h"
|
||||
#include "jinete/jbase.h"
|
||||
|
||||
class Image;
|
||||
@ -42,14 +44,41 @@ class Sprite;
|
||||
TARGET_ALPHA_CHANNEL | \
|
||||
TARGET_GRAY_CHANNEL )
|
||||
|
||||
int init_module_effect();
|
||||
void exit_module_effect();
|
||||
|
||||
class invalid_effect_exception : public ase_exception
|
||||
{
|
||||
public:
|
||||
invalid_effect_exception(const char* effect_name) throw()
|
||||
: ase_exception(std::string("Invalid effect specified: ") + effect_name) { }
|
||||
};
|
||||
|
||||
class invalid_imgtype_exception : public ase_exception
|
||||
{
|
||||
public:
|
||||
invalid_imgtype_exception() throw()
|
||||
: ase_exception("Invalid image type specified.") { }
|
||||
};
|
||||
|
||||
class invalid_area_exception : public ase_exception
|
||||
{
|
||||
public:
|
||||
invalid_area_exception() throw()
|
||||
: ase_exception("The current mask/area to apply the effect is completelly invalid.") { }
|
||||
};
|
||||
|
||||
class no_image_exception : public ase_exception
|
||||
{
|
||||
public:
|
||||
no_image_exception() throw()
|
||||
: ase_exception("There are not an active image to apply the effect.\n"
|
||||
"Please select a layer/cel with an image and try again.") { }
|
||||
};
|
||||
|
||||
struct EffectData;
|
||||
|
||||
struct Effect
|
||||
{
|
||||
Sprite* sprite;
|
||||
SpriteWriter sprite;
|
||||
Image* src;
|
||||
Image* dst;
|
||||
int row;
|
||||
@ -68,10 +97,13 @@ struct Effect
|
||||
void *progress_data;
|
||||
void (*progress)(void *data, float progress);
|
||||
bool (*is_cancelled)(void *data);
|
||||
|
||||
Effect(const SpriteReader& sprite, const char* name);
|
||||
~Effect();
|
||||
};
|
||||
|
||||
Effect* effect_new(Sprite* sprite, const char* name);
|
||||
void effect_free(Effect* effect);
|
||||
int init_module_effect();
|
||||
void exit_module_effect();
|
||||
|
||||
void effect_set_target(Effect* effect, int target);
|
||||
|
||||
|
@ -112,8 +112,10 @@ Sprite *sprite_load(const char *filename)
|
||||
fop_operate(fop);
|
||||
fop_done(fop);
|
||||
|
||||
if (fop->error)
|
||||
console_printf(fop->error);
|
||||
if (fop->error) {
|
||||
Console console;
|
||||
console.printf(fop->error);
|
||||
}
|
||||
|
||||
sprite = fop->sprite;
|
||||
fop_free(fop);
|
||||
@ -132,8 +134,10 @@ int sprite_save(Sprite *sprite)
|
||||
fop_operate(fop);
|
||||
fop_done(fop);
|
||||
|
||||
if (fop->error)
|
||||
console_printf(fop->error);
|
||||
if (fop->error) {
|
||||
Console console;
|
||||
console.printf(fop->error);
|
||||
}
|
||||
|
||||
ret = (fop->error == NULL) ? 0: -1;
|
||||
fop_free(fop);
|
||||
|
@ -350,44 +350,41 @@ static bool save_JPEG(FileOp *fop)
|
||||
*/
|
||||
static FormatOptions *get_options_JPEG(FileOp *fop)
|
||||
{
|
||||
JWidget window, slider_quality, ok;
|
||||
JpegOptions *jpeg_options = jpeg_options_new();
|
||||
try {
|
||||
/* configuration parameters */
|
||||
jpeg_options->quality = get_config_float("JPEG", "Quality", 1.0f);
|
||||
|
||||
/* configuration parameters */
|
||||
jpeg_options->quality = get_config_float("JPEG", "Quality", 1.0f);
|
||||
/* interactive mode */
|
||||
if (!is_interactive())
|
||||
return (FormatOptions*)jpeg_options;
|
||||
|
||||
/* widgets */
|
||||
JWidgetPtr window = load_widget("jpeg_options.jid", "jpeg_options");
|
||||
JWidget slider_quality, ok;
|
||||
get_widgets(window,
|
||||
"quality", &slider_quality,
|
||||
"ok", &ok, NULL);
|
||||
|
||||
jslider_set_value(slider_quality, jpeg_options->quality * 10.0f);
|
||||
|
||||
jwindow_open_fg(window);
|
||||
|
||||
if (jwindow_get_killer(window) == ok) {
|
||||
jpeg_options->quality = jslider_get_value(slider_quality) / 10.0f;
|
||||
set_config_float("JPEG", "Quality", jpeg_options->quality);
|
||||
}
|
||||
else {
|
||||
format_options_free((FormatOptions *)jpeg_options);
|
||||
jpeg_options = NULL;
|
||||
}
|
||||
|
||||
/* interactive mode */
|
||||
if (!is_interactive())
|
||||
return (FormatOptions *)jpeg_options;
|
||||
|
||||
/* widgets */
|
||||
window = load_widget("jpeg_options.jid", "jpeg_options");
|
||||
if (!window) {
|
||||
}
|
||||
catch (ase_exception& e) {
|
||||
format_options_free((FormatOptions *)jpeg_options);
|
||||
|
||||
e.show();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!get_widgets(window,
|
||||
"quality", &slider_quality,
|
||||
"ok", &ok, NULL)) {
|
||||
jwidget_free(window);
|
||||
format_options_free((FormatOptions *)jpeg_options);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jslider_set_value(slider_quality, jpeg_options->quality * 10.0f);
|
||||
|
||||
jwindow_open_fg(window);
|
||||
|
||||
if (jwindow_get_killer(window) == ok) {
|
||||
jpeg_options->quality = jslider_get_value(slider_quality) / 10.0f;
|
||||
set_config_float("JPEG", "Quality", jpeg_options->quality);
|
||||
}
|
||||
else {
|
||||
format_options_free((FormatOptions *)jpeg_options);
|
||||
jpeg_options = NULL;
|
||||
}
|
||||
|
||||
jwidget_free(window);
|
||||
return (FormatOptions *)jpeg_options;
|
||||
}
|
||||
|
37
src/main.cpp
37
src/main.cpp
@ -28,18 +28,33 @@ const char ase_ident[] =
|
||||
"$ASE: " VERSION " " COPYRIGHT " $\n"
|
||||
"$Website: " WEBSITE " $\n";
|
||||
|
||||
/***********************************************************************
|
||||
Main Routine
|
||||
***********************************************************************/
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Basic classes for some RAII
|
||||
|
||||
class Allegro {
|
||||
public:
|
||||
Allegro() { allegro_init(); }
|
||||
~Allegro() { allegro_exit(); }
|
||||
};
|
||||
|
||||
class MemLeaks {
|
||||
public:
|
||||
#if defined MEMLEAK
|
||||
MemLeaks() { jmemleak_init(); }
|
||||
~MemLeaks() { jmemleak_exit(); }
|
||||
#endif
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Main Routine
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
allegro_init();
|
||||
set_uformat(U_ASCII);
|
||||
Allegro allegro;
|
||||
MemLeaks memleaks;
|
||||
|
||||
#if defined MEMLEAK
|
||||
jmemleak_init();
|
||||
#endif
|
||||
set_uformat(U_ASCII);
|
||||
|
||||
// initialises the application
|
||||
if (!app_init(argc, argv))
|
||||
@ -47,12 +62,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
app_loop();
|
||||
app_exit();
|
||||
|
||||
#if defined MEMLEAK
|
||||
jmemleak_exit();
|
||||
#endif
|
||||
|
||||
allegro_exit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#include "jinete/jinete.h"
|
||||
|
||||
#include "ase/current_sprite.h"
|
||||
#include "sprite_wrappers.h"
|
||||
#include "ase/ui_context.h"
|
||||
#include "core/app.h"
|
||||
#include "modules/editors.h"
|
||||
@ -82,7 +82,7 @@ void refresh_all_editors()
|
||||
jwidget_dirty(reinterpret_cast<JWidget>(link->data));
|
||||
}
|
||||
|
||||
void update_editors_with_sprite(Sprite *sprite)
|
||||
void update_editors_with_sprite(const Sprite *sprite)
|
||||
{
|
||||
JWidget widget;
|
||||
JLink link;
|
||||
@ -95,7 +95,7 @@ void update_editors_with_sprite(Sprite *sprite)
|
||||
}
|
||||
}
|
||||
|
||||
void editors_draw_sprite(Sprite *sprite, int x1, int y1, int x2, int y2)
|
||||
void editors_draw_sprite(const Sprite *sprite, int x1, int y1, int x2, int y2)
|
||||
{
|
||||
JWidget widget;
|
||||
JLink link;
|
||||
@ -110,7 +110,7 @@ void editors_draw_sprite(Sprite *sprite, int x1, int y1, int x2, int y2)
|
||||
|
||||
/* TODO improve this (with JRegion or something, and without
|
||||
recursivity) */
|
||||
void editors_draw_sprite_tiled(Sprite *sprite, int x1, int y1, int x2, int y2)
|
||||
void editors_draw_sprite_tiled(const Sprite *sprite, int x1, int y1, int x2, int y2)
|
||||
{
|
||||
int cx1, cy1, cx2, cy2; /* cel rectangle */
|
||||
int lx1, ly1, lx2, ly2; /* limited rectangle to the cel rectangle */
|
||||
@ -174,45 +174,27 @@ void editors_draw_sprite_tiled(Sprite *sprite, int x1, int y1, int x2, int y2)
|
||||
}
|
||||
}
|
||||
|
||||
void editors_hide_sprite(Sprite *sprite)
|
||||
void editors_hide_sprite(const Sprite *sprite)
|
||||
{
|
||||
CurrentSprite current_sprite;
|
||||
JWidget widget;
|
||||
int refresh;
|
||||
UIContext* context = UIContext::instance();
|
||||
bool refresh = (context->get_current_sprite() == sprite) ? true: false;
|
||||
|
||||
JLink link;
|
||||
|
||||
refresh = (current_sprite == sprite) ? TRUE: FALSE;
|
||||
|
||||
JI_LIST_FOR_EACH(editors, link) {
|
||||
widget = reinterpret_cast<JWidget>(link->data);
|
||||
JWidget widget = reinterpret_cast<JWidget>(link->data);
|
||||
|
||||
if (sprite == editor_get_sprite(widget))
|
||||
editor_set_sprite(widget, get_more_reliable_sprite());
|
||||
}
|
||||
|
||||
if (refresh) {
|
||||
UIContext* context = UIContext::instance();
|
||||
context->set_current_sprite(editor_get_sprite(current_editor));
|
||||
Sprite* sprite = editor_get_sprite(current_editor);
|
||||
|
||||
app_refresh_screen();
|
||||
context->set_current_sprite(sprite);
|
||||
app_refresh_screen(sprite);
|
||||
}
|
||||
}
|
||||
|
||||
void replace_sprite_in_editors(Sprite *old_sprite, Sprite *new_sprite)
|
||||
{
|
||||
JWidget widget;
|
||||
JLink link;
|
||||
|
||||
JI_LIST_FOR_EACH(editors, link) {
|
||||
widget = reinterpret_cast<JWidget>(link->data);
|
||||
|
||||
if (old_sprite == editor_get_sprite(widget))
|
||||
editor_set_sprite(widget, new_sprite);
|
||||
}
|
||||
|
||||
app_refresh_screen();
|
||||
}
|
||||
|
||||
void set_current_editor(JWidget editor)
|
||||
{
|
||||
if (current_editor != editor) {
|
||||
@ -224,9 +206,10 @@ void set_current_editor(JWidget editor)
|
||||
jwidget_dirty(jwidget_get_view(current_editor));
|
||||
|
||||
UIContext* context = UIContext::instance();
|
||||
context->set_current_sprite(editor_get_sprite(current_editor));
|
||||
Sprite* sprite = editor_get_sprite(current_editor);
|
||||
context->set_current_sprite(sprite);
|
||||
|
||||
app_refresh_screen();
|
||||
app_refresh_screen(sprite);
|
||||
app_realloc_sprite_list();
|
||||
}
|
||||
}
|
||||
@ -244,7 +227,7 @@ void set_sprite_in_current_editor(Sprite *sprite)
|
||||
|
||||
jwidget_dirty(jwidget_get_view(current_editor));
|
||||
|
||||
app_refresh_screen();
|
||||
app_refresh_screen(sprite);
|
||||
app_realloc_sprite_list();
|
||||
}
|
||||
}
|
||||
|
@ -35,11 +35,10 @@ void remove_editor(JWidget editor);
|
||||
void set_current_editor(JWidget editor);
|
||||
|
||||
void refresh_all_editors();
|
||||
void update_editors_with_sprite(Sprite* sprite);
|
||||
void editors_draw_sprite(Sprite* sprite, int x1, int y1, int x2, int y2);
|
||||
void editors_draw_sprite_tiled(Sprite* sprite, int x1, int y1, int x2, int y2);
|
||||
void editors_hide_sprite(Sprite* sprite);
|
||||
void replace_sprite_in_editors(Sprite* old_sprite, Sprite* new_sprite);
|
||||
void update_editors_with_sprite(const Sprite* sprite);
|
||||
void editors_draw_sprite(const Sprite* sprite, int x1, int y1, int x2, int y2);
|
||||
void editors_draw_sprite_tiled(const Sprite* sprite, int x1, int y1, int x2, int y2);
|
||||
void editors_hide_sprite(const Sprite* sprite);
|
||||
|
||||
void set_sprite_in_current_editor(Sprite* sprite);
|
||||
void set_sprite_in_more_reliable_editor(Sprite* sprite);
|
||||
|
@ -368,7 +368,7 @@ void set_screen_scaling(int scaling)
|
||||
screen_scaling = scaling;
|
||||
}
|
||||
|
||||
void update_screen_for_sprite(Sprite *sprite)
|
||||
void update_screen_for_sprite(const Sprite* sprite)
|
||||
{
|
||||
if (!(ase_mode & MODE_GUI))
|
||||
return;
|
||||
@ -412,7 +412,9 @@ void gui_feedback()
|
||||
|
||||
if (next_idle_flags & REFRESH_FULL_SCREEN) {
|
||||
next_idle_flags ^= REFRESH_FULL_SCREEN;
|
||||
update_screen_for_sprite(UIContext::instance()->get_current_sprite());
|
||||
|
||||
const CurrentSpriteReader sprite;
|
||||
update_screen_for_sprite(sprite);
|
||||
}
|
||||
|
||||
/* record file if is necessary */
|
||||
@ -549,7 +551,7 @@ JWidget load_widget(const char *filename, const char *name)
|
||||
JWidget widget;
|
||||
DIRS *it, *dirs;
|
||||
char buf[512];
|
||||
bool found = FALSE;
|
||||
bool found = false;
|
||||
|
||||
dirs = dirs_new();
|
||||
|
||||
@ -561,25 +563,32 @@ JWidget load_widget(const char *filename, const char *name)
|
||||
for (it=dirs; it; it=it->next) {
|
||||
if (exists(it->path)) {
|
||||
ustrcpy(buf, it->path);
|
||||
found = TRUE;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dirs_free(dirs);
|
||||
|
||||
if (!found) {
|
||||
console_printf(_("File not found: \"%s\"\n"), filename);
|
||||
return NULL;
|
||||
}
|
||||
if (!found)
|
||||
throw widget_file_not_found(filename);
|
||||
|
||||
widget = ji_load_widget(buf, name);
|
||||
if (!widget)
|
||||
console_printf(_("Error loading widget: \"%s\"\n"), name);
|
||||
throw widget_not_found(name);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
JWidget find_widget(JWidget widget, const char *name)
|
||||
{
|
||||
JWidget child = jwidget_find_name(widget, name);
|
||||
if (!child)
|
||||
throw widget_not_found(name);
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
void schedule_rebuild_recent_list()
|
||||
{
|
||||
next_idle_flags |= REBUILD_RECENT_LIST;
|
||||
@ -653,7 +662,7 @@ void hook_signal(JWidget widget,
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
bool get_widgets(JWidget window, ...)
|
||||
void get_widgets(JWidget window, ...)
|
||||
{
|
||||
JWidget *widget;
|
||||
char *name;
|
||||
@ -666,14 +675,10 @@ bool get_widgets(JWidget window, ...)
|
||||
break;
|
||||
|
||||
*widget = jwidget_find_name(window, name);
|
||||
if (!*widget) {
|
||||
console_printf(_("Widget %s not found.\n"), name);
|
||||
return FALSE;
|
||||
}
|
||||
if (!*widget)
|
||||
throw widget_not_found(name);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
@ -19,8 +19,34 @@
|
||||
#ifndef MODULES_GUI_H
|
||||
#define MODULES_GUI_H
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include "ase_exception.h"
|
||||
#include "jinete/jbase.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
class widget_file_not_found : public ase_exception
|
||||
{
|
||||
public:
|
||||
widget_file_not_found(const char* file_name) throw()
|
||||
: ase_exception(std::string("Cannot load file: ") + file_name
|
||||
+ "\nPlease reinstall " PACKAGE) { }
|
||||
};
|
||||
|
||||
/**
|
||||
* Exception thrown by find_widget() if a widget is not found.
|
||||
*/
|
||||
class widget_not_found : public ase_exception
|
||||
{
|
||||
public:
|
||||
widget_not_found(const char* widget_name) throw()
|
||||
: ase_exception("A data file is corrupted.\nPlease reinstall " PACKAGE
|
||||
"\n\nDetails: Widget not found: " + std::string(widget_name)) { }
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define HOOK(widget, signal, signal_handler, data) \
|
||||
hook_signal((widget), (signal), (signal_handler), (void *)(data))
|
||||
|
||||
@ -35,7 +61,7 @@ int guiscale();
|
||||
int get_screen_scaling();
|
||||
void set_screen_scaling(int scaling);
|
||||
|
||||
void update_screen_for_sprite(Sprite* sprite);
|
||||
void update_screen_for_sprite(const Sprite* sprite);
|
||||
|
||||
void gui_run();
|
||||
void gui_feedback();
|
||||
@ -47,6 +73,7 @@ void load_window_pos(JWidget window, const char *section);
|
||||
void save_window_pos(JWidget window, const char *section);
|
||||
|
||||
JWidget load_widget(const char *filename, const char *name);
|
||||
JWidget find_widget(JWidget widget, const char *name);
|
||||
|
||||
void schedule_rebuild_recent_list();
|
||||
|
||||
@ -55,7 +82,7 @@ void hook_signal(JWidget widget,
|
||||
bool (*signal_handler)(JWidget widget, void *data),
|
||||
void *data);
|
||||
|
||||
bool get_widgets(JWidget window, ...);
|
||||
void get_widgets(JWidget window, ...);
|
||||
|
||||
void add_gfxicon_to_button(JWidget button, int gfx_id, int icon_align);
|
||||
void set_gfxicon_in_button(JWidget button, int gfx_id);
|
||||
@ -71,4 +98,49 @@ Monitor* add_gui_monitor(void (*proc)(void*),
|
||||
void (*free)(void*), void* data);
|
||||
void remove_gui_monitor(Monitor* monitor);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Smart JWidget pointer
|
||||
|
||||
class JWidgetPtr
|
||||
{
|
||||
JWidget m_widget;
|
||||
|
||||
// TODO make this class copyable and count references (so this is
|
||||
// really "smart" pointer)...
|
||||
JWidgetPtr(const JWidgetPtr&);
|
||||
JWidgetPtr& operator=(const JWidgetPtr&);
|
||||
|
||||
public:
|
||||
JWidgetPtr() {
|
||||
m_widget = NULL;
|
||||
}
|
||||
|
||||
JWidgetPtr(JWidget widget) {
|
||||
m_widget = widget;
|
||||
}
|
||||
|
||||
~JWidgetPtr() {
|
||||
delete m_widget;
|
||||
}
|
||||
|
||||
JWidgetPtr& operator=(JWidget widget) {
|
||||
if (m_widget)
|
||||
delete m_widget;
|
||||
|
||||
m_widget = widget;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator JWidget() {
|
||||
return m_widget;
|
||||
}
|
||||
|
||||
JWidget operator->() {
|
||||
assert(m_widget != NULL);
|
||||
return m_widget;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* MODULES_GUI_H */
|
||||
|
@ -120,10 +120,10 @@ void set_default_palette(Palette *palette)
|
||||
* @param palette If "palette" is NULL will be used the default one
|
||||
* (ase_default_palette)
|
||||
*/
|
||||
bool set_current_palette(Palette *_palette, int forced)
|
||||
bool set_current_palette(Palette *_palette, bool forced)
|
||||
{
|
||||
Palette *palette = _palette ? _palette: ase_default_palette;
|
||||
bool ret = FALSE;
|
||||
bool ret = false;
|
||||
|
||||
/* have changes */
|
||||
if (forced ||
|
||||
@ -245,7 +245,7 @@ void set_current_color(int index, int r, int g, int b)
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CurrentSpriteRgbMap::CurrentSpriteRgbMap()
|
||||
{
|
||||
@ -257,7 +257,7 @@ CurrentSpriteRgbMap::~CurrentSpriteRgbMap()
|
||||
rgb_map = my_rgb_map;
|
||||
|
||||
if (regen_my_rgb_map) {
|
||||
regen_my_rgb_map = FALSE;
|
||||
regen_my_rgb_map = false;
|
||||
create_rgb_table(my_rgb_map, _current_palette, NULL);
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ Palette* get_default_palette();
|
||||
Palette* get_current_palette();
|
||||
|
||||
void set_default_palette(Palette* palette);
|
||||
bool set_current_palette(Palette* palette, int forced);
|
||||
bool set_current_palette(Palette* palette, bool forced);
|
||||
void set_black_palette();
|
||||
void set_current_color(int index, int r, int g, int b);
|
||||
|
||||
|
@ -318,7 +318,7 @@ static JWidget convert_xmlelem_to_menuitem(JXmlElem elem)
|
||||
menuitem = menuitem_new(jxmlelem_get_attr(elem, "name"),
|
||||
command_get_by_name(jxmlelem_get_attr(elem,
|
||||
"command")),
|
||||
NULL);
|
||||
jxmlelem_get_attr(elem, "argument"));
|
||||
if (!menuitem)
|
||||
return 0;
|
||||
|
||||
|
@ -710,14 +710,8 @@ static void tool_rectangle_draw_trace(int x1, int y1, int x2, int y2, ToolData *
|
||||
}
|
||||
|
||||
if (filled_mode) {
|
||||
int bak_color;
|
||||
bak_color = data->color;
|
||||
data->color = data->other_color;
|
||||
|
||||
for (c=y1; c<=y2; c++)
|
||||
do_ink_hline(x1, c, x2, data);
|
||||
|
||||
data->color = bak_color;
|
||||
}
|
||||
|
||||
for (c=x1; c<=x2; c++) do_ink_brush(c, y1, data);
|
||||
@ -746,14 +740,8 @@ static Tool tool_rectangle =
|
||||
static void tool_ellipse_draw_trace(int x1, int y1, int x2, int y2, ToolData *data)
|
||||
{
|
||||
if (filled_mode) {
|
||||
int bak_color;
|
||||
bak_color = data->color;
|
||||
data->color = data->other_color;
|
||||
|
||||
algo_ellipsefill(x1, y1, x2, y2, data,
|
||||
(AlgoHLine)do_ink_hline);
|
||||
|
||||
data->color = bak_color;
|
||||
}
|
||||
|
||||
algo_ellipse(x1, y1, x2, y2, data,
|
||||
|
@ -71,7 +71,9 @@ GfxObj::~GfxObj()
|
||||
{
|
||||
// we have to remove this object from the map
|
||||
jmutex_lock(objects_mutex);
|
||||
erase_gfxobj(this);
|
||||
{
|
||||
erase_gfxobj(this);
|
||||
}
|
||||
jmutex_unlock(objects_mutex);
|
||||
}
|
||||
|
||||
@ -114,9 +116,11 @@ void _gfxobj_set_id(GfxObj* gfxobj, gfxobj_id id)
|
||||
assert(gfxobj_find(id) == NULL);
|
||||
|
||||
jmutex_lock(objects_mutex);
|
||||
erase_gfxobj(gfxobj); // remove the object
|
||||
gfxobj->id = id; // change the ID
|
||||
insert_gfxobj(gfxobj); // insert the object again in the map
|
||||
{
|
||||
erase_gfxobj(gfxobj); // remove the object
|
||||
gfxobj->id = id; // change the ID
|
||||
insert_gfxobj(gfxobj); // insert the object again in the map
|
||||
}
|
||||
jmutex_unlock(objects_mutex);
|
||||
}
|
||||
|
||||
|
@ -327,135 +327,6 @@ void image_to_allegro(const Image* image, BITMAP *bmp, int x, int y)
|
||||
image->to_allegro(bmp, x, y);
|
||||
}
|
||||
|
||||
void image_convert(const Image* src, Image* dst)
|
||||
{
|
||||
int c, x, y, w, h;
|
||||
float hue, s, v;
|
||||
|
||||
if ((src->w != dst->w) || (src->h != dst->h))
|
||||
return;
|
||||
else if (src->imgtype == dst->imgtype) {
|
||||
image_copy(dst, src, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
w = dst->w;
|
||||
h = dst->h;
|
||||
|
||||
switch (src->imgtype) {
|
||||
|
||||
case IMAGE_RGB:
|
||||
switch (dst->imgtype) {
|
||||
|
||||
/* RGB -> Grayscale */
|
||||
case IMAGE_GRAYSCALE:
|
||||
for (y=0; y<h; y++) {
|
||||
for (x=0; x<w; x++) {
|
||||
c = image_getpixel_fast<RgbTraits>(src, x, y);
|
||||
rgb_to_hsv(_rgba_getr(c),
|
||||
_rgba_getg(c),
|
||||
_rgba_getb(c), &hue, &s, &v);
|
||||
v = v * 255.0f;
|
||||
image_putpixel_fast<GrayscaleTraits>(dst, x, y,
|
||||
_graya((int)MID(0, v, 255),
|
||||
_rgba_geta(c)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* RGB -> Indexed */
|
||||
case IMAGE_INDEXED:
|
||||
for (y=0; y<h; y++) {
|
||||
for (x=0; x<w; x++) {
|
||||
c = image_getpixel_fast<RgbTraits>(src, x, y);
|
||||
if (!_rgba_geta (c))
|
||||
image_putpixel_fast<IndexedTraits>(dst, x, y, 0);
|
||||
else
|
||||
image_putpixel_fast<IndexedTraits>(dst, x, y,
|
||||
makecol8(_rgba_getr(c),
|
||||
_rgba_getg(c),
|
||||
_rgba_getb(c)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case IMAGE_GRAYSCALE:
|
||||
switch (dst->imgtype) {
|
||||
|
||||
/* Grayscale -> RGB */
|
||||
case IMAGE_RGB:
|
||||
for (y=0; y<h; y++) {
|
||||
for (x=0; x<w; x++) {
|
||||
c = image_getpixel_fast<GrayscaleTraits>(src, x, y);
|
||||
image_putpixel_fast<RgbTraits>(dst, x, y,
|
||||
_rgba(_graya_getv(c),
|
||||
_graya_getv(c),
|
||||
_graya_getv(c),
|
||||
_graya_geta(c)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* Grayscale -> Indexed */
|
||||
case IMAGE_INDEXED:
|
||||
for (y=0; y<h; y++) {
|
||||
for (x=0; x<w; x++) {
|
||||
c = image_getpixel_fast<GrayscaleTraits>(src, x, y);
|
||||
if (!_graya_geta(c))
|
||||
image_putpixel_fast<IndexedTraits>(dst, x, y, 0);
|
||||
else
|
||||
image_putpixel_fast<IndexedTraits>(dst, x, y,
|
||||
makecol8(_graya_getv(c),
|
||||
_graya_getv(c),
|
||||
_graya_getv(c)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case IMAGE_INDEXED:
|
||||
switch (dst->imgtype) {
|
||||
|
||||
/* Indexed -> RGB */
|
||||
case IMAGE_RGB:
|
||||
for (y=0; y<h; y++) {
|
||||
for (x=0; x<w; x++) {
|
||||
c = image_getpixel_fast<IndexedTraits>(src, x, y);
|
||||
if (!c)
|
||||
image_putpixel_fast<RgbTraits>(dst, x, y, 0);
|
||||
else
|
||||
image_putpixel_fast<RgbTraits>(dst, x, y,
|
||||
_rgba(getr8(c),
|
||||
getg8(c),
|
||||
getb8(c), 255));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* Indexed -> Grayscale */
|
||||
case IMAGE_GRAYSCALE:
|
||||
for (y=0; y<h; y++) {
|
||||
for (x=0; x<w; x++) {
|
||||
c = image_getpixel_fast<GrayscaleTraits>(src, x, y);
|
||||
if (!c)
|
||||
image_putpixel_fast<GrayscaleTraits>(dst, x, y, 0);
|
||||
else {
|
||||
rgb_to_hsv(getr8(c), getg8(c), getb8(c), &hue, &s, &v);
|
||||
v = v * 255.0f;
|
||||
image_putpixel_fast<GrayscaleTraits>(dst, x, y,
|
||||
_graya((int)MID(0, v, 255), 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void image_resize(const Image* src, Image* dst, ResizeMethod method, Palette* pal, RGB_MAP* rgb_map)
|
||||
{
|
||||
switch (method) {
|
||||
|
@ -88,7 +88,6 @@ void image_ellipsefill(Image* image, int x1, int y1, int x2, int y2, int color);
|
||||
|
||||
void image_to_allegro(const Image* image, BITMAP* bmp, int x, int y);
|
||||
|
||||
void image_convert(const Image* src, Image* dst);
|
||||
void image_resize(const Image* src, Image* dst, ResizeMethod method, Palette* palette, RGB_MAP* rgb_map);
|
||||
int image_count_diff(const Image* i1, const Image* i2);
|
||||
bool image_shrink_rect(Image *image, int *x1, int *y1, int *x2, int *y2, int refpixel);
|
||||
|
@ -28,20 +28,22 @@ Image *image_set_imgtype(Image *image, int imgtype,
|
||||
RGB_MAP *rgb_map,
|
||||
Palette *palette)
|
||||
{
|
||||
ase_uint32 *rgb_address;
|
||||
ase_uint16 *gray_address;
|
||||
ase_uint8 *idx_address;
|
||||
int i, c, r, g, b, size;
|
||||
ase_uint32* rgb_address;
|
||||
ase_uint16* gray_address;
|
||||
ase_uint8* idx_address;
|
||||
ase_uint32 c;
|
||||
int i, r, g, b, size;
|
||||
Image *new_image;
|
||||
|
||||
/* no convertion */
|
||||
// no convertion
|
||||
if (image->imgtype == imgtype)
|
||||
return NULL;
|
||||
/* RGB -> Indexed with ordered dithering */
|
||||
// RGB -> Indexed with ordered dithering
|
||||
else if (image->imgtype == IMAGE_RGB &&
|
||||
imgtype == IMAGE_INDEXED &&
|
||||
dithering_method == DITHERING_ORDERED)
|
||||
dithering_method == DITHERING_ORDERED) {
|
||||
return image_rgb_to_indexed(image, 0, 0, rgb_map, palette);
|
||||
}
|
||||
|
||||
new_image = image_new(imgtype, image->w, image->h);
|
||||
if (!new_image)
|
||||
@ -52,24 +54,24 @@ Image *image_set_imgtype(Image *image, int imgtype,
|
||||
switch (image->imgtype) {
|
||||
|
||||
case IMAGE_RGB:
|
||||
rgb_address = (ase_uint32 *)image->dat;
|
||||
rgb_address = (ase_uint32*)image->dat;
|
||||
|
||||
switch (new_image->imgtype) {
|
||||
/* RGB -> Grayscale */
|
||||
// RGB -> Grayscale
|
||||
case IMAGE_GRAYSCALE:
|
||||
gray_address = (ase_uint16 *)new_image->dat;
|
||||
gray_address = (ase_uint16*)new_image->dat;
|
||||
for (i=0; i<size; i++) {
|
||||
c = *rgb_address;
|
||||
r = _rgba_getr (c);
|
||||
g = _rgba_getg (c);
|
||||
b = _rgba_getb (c);
|
||||
rgb_to_hsv_int (&r, &g, &b);
|
||||
*gray_address = _graya (b, _rgba_geta (c));
|
||||
r = _rgba_getr(c);
|
||||
g = _rgba_getg(c);
|
||||
b = _rgba_getb(c);
|
||||
rgb_to_hsv_int(&r, &g, &b);
|
||||
*gray_address = _graya(b, _rgba_geta(c));
|
||||
rgb_address++;
|
||||
gray_address++;
|
||||
}
|
||||
break;
|
||||
/* RGB -> Indexed */
|
||||
// RGB -> Indexed
|
||||
case IMAGE_INDEXED:
|
||||
idx_address = new_image->dat;
|
||||
for (i=0; i<size; i++) {
|
||||
@ -89,12 +91,12 @@ Image *image_set_imgtype(Image *image, int imgtype,
|
||||
break;
|
||||
|
||||
case IMAGE_GRAYSCALE:
|
||||
gray_address = (ase_uint16 *)image->dat;
|
||||
gray_address = (ase_uint16*)image->dat;
|
||||
|
||||
switch (new_image->imgtype) {
|
||||
/* Grayscale -> RGB */
|
||||
// Grayscale -> RGB
|
||||
case IMAGE_RGB:
|
||||
rgb_address = (ase_uint32 *)new_image->dat;
|
||||
rgb_address = (ase_uint32*)new_image->dat;
|
||||
for (i=0; i<size; i++) {
|
||||
c = *gray_address;
|
||||
g = _graya_getv(c);
|
||||
@ -103,7 +105,7 @@ Image *image_set_imgtype(Image *image, int imgtype,
|
||||
rgb_address++;
|
||||
}
|
||||
break;
|
||||
/* Grayscale -> Indexed */
|
||||
// Grayscale -> Indexed
|
||||
case IMAGE_INDEXED:
|
||||
idx_address = new_image->dat;
|
||||
for (i=0; i<size; i++) {
|
||||
@ -123,9 +125,9 @@ Image *image_set_imgtype(Image *image, int imgtype,
|
||||
idx_address = image->dat;
|
||||
|
||||
switch (new_image->imgtype) {
|
||||
/* Indexed -> RGB */
|
||||
// Indexed -> RGB
|
||||
case IMAGE_RGB:
|
||||
rgb_address = (ase_uint32 *)new_image->dat;
|
||||
rgb_address = (ase_uint32*)new_image->dat;
|
||||
for (i=0; i<size; i++) {
|
||||
c = *idx_address;
|
||||
if (c == 0)
|
||||
@ -138,9 +140,9 @@ Image *image_set_imgtype(Image *image, int imgtype,
|
||||
rgb_address++;
|
||||
}
|
||||
break;
|
||||
/* Indexed -> Grayscale */
|
||||
// Indexed -> Grayscale
|
||||
case IMAGE_GRAYSCALE:
|
||||
gray_address = (ase_uint16 *)new_image->dat;
|
||||
gray_address = (ase_uint16*)new_image->dat;
|
||||
for (i=0; i<size; i++) {
|
||||
c = *idx_address;
|
||||
if (c == 0)
|
||||
|
@ -91,7 +91,8 @@ Sprite::Sprite(int imgtype, int w, int h)
|
||||
sprite_set_speed(this, 100);
|
||||
|
||||
/* multiple access */
|
||||
m_locked = 0;
|
||||
m_write_lock = false;
|
||||
m_read_locks = 0;
|
||||
m_mutex = jmutex_new();
|
||||
|
||||
/* file format options */
|
||||
@ -314,26 +315,82 @@ bool sprite_need_alpha(const Sprite* sprite)
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock the sprite to write or read it.
|
||||
* Lock the sprite to read or write it.
|
||||
*
|
||||
* @return true if the sprite can be written (because this is the first lock).
|
||||
* @return true if the sprite can be accessed in the desired mode.
|
||||
*/
|
||||
bool Sprite::lock()
|
||||
bool Sprite::lock(bool write)
|
||||
{
|
||||
ScopedLock hold(m_mutex);
|
||||
|
||||
if (++m_locked == 1)
|
||||
// read-only
|
||||
if (!write) {
|
||||
// If no body is writting the sprite...
|
||||
if (!m_write_lock) {
|
||||
// We can read it
|
||||
++m_read_locks;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// read and write
|
||||
else {
|
||||
// If no body is reading and writting...
|
||||
if (m_read_locks == 0 && !m_write_lock) {
|
||||
// We can start writting the sprite...
|
||||
m_write_lock = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you have locked the sprite to read, using this method
|
||||
* you can raise your access level to write it.
|
||||
*/
|
||||
bool Sprite::lock_to_write()
|
||||
{
|
||||
ScopedLock hold(m_mutex);
|
||||
|
||||
// this only is possible if there are just one reader
|
||||
if (m_read_locks == 1) {
|
||||
assert(!m_write_lock);
|
||||
m_read_locks = 0;
|
||||
m_write_lock = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you have locked the sprite to write, using this method
|
||||
* you can your access level to only read it.
|
||||
*/
|
||||
void Sprite::unlock_to_read()
|
||||
{
|
||||
ScopedLock hold(m_mutex);
|
||||
assert(m_read_locks == 0);
|
||||
assert(m_write_lock);
|
||||
|
||||
m_write_lock = false;
|
||||
m_read_locks = 1;
|
||||
}
|
||||
|
||||
void Sprite::unlock()
|
||||
{
|
||||
ScopedLock hold(m_mutex);
|
||||
|
||||
--m_locked;
|
||||
assert(m_locked >= 0);
|
||||
if (m_write_lock) {
|
||||
m_write_lock = false;
|
||||
}
|
||||
else if (m_read_locks > 0) {
|
||||
--m_read_locks;
|
||||
}
|
||||
else {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
Palette* sprite_get_palette(const Sprite* sprite, int frame)
|
||||
@ -362,9 +419,10 @@ Palette* sprite_get_palette(const Sprite* sprite, int frame)
|
||||
void sprite_set_palette(Sprite* sprite, Palette* pal, bool truncate)
|
||||
{
|
||||
assert(sprite != NULL);
|
||||
assert(pal != NULL);
|
||||
|
||||
if (!truncate) {
|
||||
Palette* sprite_pal = sprite_get_palette(sprite, sprite->frame);
|
||||
Palette* sprite_pal = sprite_get_palette(sprite, pal->frame);
|
||||
palette_copy_colors(sprite_pal, pal);
|
||||
}
|
||||
else {
|
||||
@ -402,6 +460,18 @@ void sprite_reset_palettes(Sprite* sprite)
|
||||
}
|
||||
}
|
||||
|
||||
void sprite_delete_palette(Sprite* sprite, Palette* pal)
|
||||
{
|
||||
assert(sprite != NULL);
|
||||
assert(pal != NULL);
|
||||
|
||||
JLink link = jlist_find(sprite->palettes, pal);
|
||||
assert(link != NULL);
|
||||
|
||||
palette_free(pal);
|
||||
jlist_delete_link(sprite->palettes, link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the sprite's filename
|
||||
*/
|
||||
@ -504,76 +574,6 @@ void sprite_set_frame(Sprite* sprite, int frame)
|
||||
sprite->frame = frame;
|
||||
}
|
||||
|
||||
/**
|
||||
* @warning: it uses the current Allegro "rgb_map"
|
||||
*/
|
||||
void sprite_set_imgtype(Sprite* sprite, int imgtype, int dithering_method)
|
||||
{
|
||||
Image *old_image;
|
||||
Image *new_image;
|
||||
int c;
|
||||
|
||||
/* nothing to do */
|
||||
if (sprite->imgtype == imgtype)
|
||||
return;
|
||||
|
||||
/* if the undo is enabled, open a "big" group */
|
||||
if (undo_is_enabled(sprite->undo)) {
|
||||
undo_set_label(sprite->undo, "Color Mode Change");
|
||||
undo_open(sprite->undo);
|
||||
}
|
||||
|
||||
/* change imgtype of the stock of images */
|
||||
if (undo_is_enabled(sprite->undo))
|
||||
undo_int(sprite->undo, (GfxObj *)sprite->stock, &sprite->stock->imgtype);
|
||||
|
||||
sprite->stock->imgtype = imgtype;
|
||||
|
||||
for (c=0; c<sprite->stock->nimage; c++) {
|
||||
old_image = stock_get_image(sprite->stock, c);
|
||||
if (!old_image)
|
||||
continue;
|
||||
|
||||
new_image = image_set_imgtype(old_image, imgtype, dithering_method,
|
||||
rgb_map,
|
||||
/* TODO check this out */
|
||||
sprite_get_palette(sprite,
|
||||
sprite->frame));
|
||||
if (!new_image)
|
||||
return; /* TODO error handling: not enough memory!
|
||||
we should undo all work done */
|
||||
|
||||
if (undo_is_enabled(sprite->undo))
|
||||
undo_replace_image(sprite->undo, sprite->stock, c);
|
||||
|
||||
image_free(old_image);
|
||||
stock_replace_image(sprite->stock, c, new_image);
|
||||
}
|
||||
|
||||
/* change "sprite.imgtype" field */
|
||||
if (undo_is_enabled(sprite->undo))
|
||||
undo_int(sprite->undo, (GfxObj *)sprite, &sprite->imgtype);
|
||||
|
||||
sprite->imgtype = imgtype;
|
||||
|
||||
#if 0 /* TODO */
|
||||
/* change "sprite.palette" */
|
||||
if (imgtype == IMAGE_GRAYSCALE) {
|
||||
int c;
|
||||
undo_data(sprite->undo, (GfxObj *)sprite,
|
||||
&sprite->palette, sizeof(PALETTE));
|
||||
for (c=0; c<256; c++) {
|
||||
sprite->palette[c].r = c >> 2;
|
||||
sprite->palette[c].g = c >> 2;
|
||||
sprite->palette[c].b = c >> 2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (undo_is_enabled(sprite->undo))
|
||||
undo_close(sprite->undo);
|
||||
}
|
||||
|
||||
Layer *sprite_get_background_layer(const Sprite* sprite)
|
||||
{
|
||||
assert(sprite != NULL);
|
||||
@ -676,7 +676,7 @@ void sprite_generate_mask_boundaries(Sprite* sprite)
|
||||
}
|
||||
}
|
||||
|
||||
Layer *sprite_index2layer(const Sprite* sprite, int index)
|
||||
Layer* sprite_index2layer(const Sprite* sprite, int index)
|
||||
{
|
||||
int index_count = -1;
|
||||
assert(sprite != NULL);
|
||||
|
@ -78,9 +78,14 @@ private:
|
||||
JMutex m_mutex;
|
||||
|
||||
/**
|
||||
* Greater than zero when a thread is reading/writing the sprite.
|
||||
* True if some thread is writing the sprite.
|
||||
*/
|
||||
int m_locked;
|
||||
bool m_write_lock;
|
||||
|
||||
/**
|
||||
* Greater than zero when one or more threads are reading the sprite.
|
||||
*/
|
||||
int m_read_locks;
|
||||
|
||||
public:
|
||||
|
||||
@ -92,7 +97,9 @@ public:
|
||||
Sprite(int imgtype, int w, int h);
|
||||
virtual ~Sprite();
|
||||
|
||||
bool lock();
|
||||
bool lock(bool write);
|
||||
bool lock_to_write();
|
||||
void unlock_to_read();
|
||||
void unlock();
|
||||
};
|
||||
|
||||
@ -110,6 +117,7 @@ bool sprite_need_alpha(const Sprite* sprite);
|
||||
Palette* sprite_get_palette(const Sprite* sprite, int frame);
|
||||
void sprite_set_palette(Sprite* sprite, Palette* pal, bool truncate);
|
||||
void sprite_reset_palettes(Sprite* sprite);
|
||||
void sprite_delete_palette(Sprite* sprite, Palette* pal);
|
||||
|
||||
void sprite_set_filename(Sprite* sprite, const char* filename);
|
||||
void sprite_set_format_options(Sprite* sprite, FormatOptions* format_options);
|
||||
@ -122,7 +130,6 @@ void sprite_set_path(Sprite* sprite, const Path* path);
|
||||
void sprite_set_mask(Sprite* sprite, const Mask* mask);
|
||||
void sprite_set_layer(Sprite* sprite, Layer* layer);
|
||||
void sprite_set_frame(Sprite* sprite, int frame);
|
||||
void sprite_set_imgtype(Sprite* sprite, int imgtype, int dithering_method);
|
||||
|
||||
Layer* sprite_get_background_layer(const Sprite* sprite);
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "raster/image.h"
|
||||
#include "raster/layer.h"
|
||||
#include "raster/mask.h"
|
||||
#include "raster/palette.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/stock.h"
|
||||
#include "raster/undo.h"
|
||||
@ -41,35 +42,39 @@ enum {
|
||||
DO_REDO,
|
||||
};
|
||||
|
||||
/* undo types */
|
||||
// undo types
|
||||
enum {
|
||||
/* group */
|
||||
// group
|
||||
UNDO_TYPE_OPEN,
|
||||
UNDO_TYPE_CLOSE,
|
||||
|
||||
/* data management */
|
||||
// data management
|
||||
UNDO_TYPE_DATA,
|
||||
|
||||
/* image management */
|
||||
// image management
|
||||
UNDO_TYPE_IMAGE,
|
||||
UNDO_TYPE_FLIP,
|
||||
UNDO_TYPE_DIRTY,
|
||||
|
||||
/* stock management */
|
||||
// stock management
|
||||
UNDO_TYPE_ADD_IMAGE,
|
||||
UNDO_TYPE_REMOVE_IMAGE,
|
||||
UNDO_TYPE_REPLACE_IMAGE,
|
||||
|
||||
/* cel management */
|
||||
// cel management
|
||||
UNDO_TYPE_ADD_CEL,
|
||||
UNDO_TYPE_REMOVE_CEL,
|
||||
|
||||
/* layer management */
|
||||
// layer management
|
||||
UNDO_TYPE_ADD_LAYER,
|
||||
UNDO_TYPE_REMOVE_LAYER,
|
||||
UNDO_TYPE_MOVE_LAYER,
|
||||
UNDO_TYPE_SET_LAYER,
|
||||
|
||||
// palette management
|
||||
UNDO_TYPE_ADD_PALETTE,
|
||||
UNDO_TYPE_REMOVE_PALETTE,
|
||||
|
||||
/* misc */
|
||||
UNDO_TYPE_SET_MASK,
|
||||
UNDO_TYPE_SET_FRAMES,
|
||||
@ -89,6 +94,8 @@ typedef struct UndoChunkAddLayer UndoChunkAddLayer;
|
||||
typedef struct UndoChunkRemoveLayer UndoChunkRemoveLayer;
|
||||
typedef struct UndoChunkMoveLayer UndoChunkMoveLayer;
|
||||
typedef struct UndoChunkSetLayer UndoChunkSetLayer;
|
||||
typedef struct UndoChunkAddPalette UndoChunkAddPalette;
|
||||
typedef struct UndoChunkRemovePalette UndoChunkRemovePalette;
|
||||
typedef struct UndoChunkSetMask UndoChunkSetMask;
|
||||
typedef struct UndoChunkSetFrames UndoChunkSetFrames;
|
||||
typedef struct UndoChunkSetFrlen UndoChunkSetFrlen;
|
||||
@ -166,6 +173,12 @@ static void chunk_move_layer_invert(UndoStream* stream, UndoChunkMoveLayer* chun
|
||||
static void chunk_set_layer_new(UndoStream* stream, Sprite *sprite);
|
||||
static void chunk_set_layer_invert(UndoStream* stream, UndoChunkSetLayer* chunk, int state);
|
||||
|
||||
static void chunk_add_palette_new(UndoStream* stream, Sprite *sprite, Palette* palette);
|
||||
static void chunk_add_palette_invert(UndoStream* stream, UndoChunkAddPalette *chunk, int state);
|
||||
|
||||
static void chunk_remove_palette_new(UndoStream* stream, Sprite *sprite, Palette* palette);
|
||||
static void chunk_remove_palette_invert(UndoStream* stream, UndoChunkRemovePalette *chunk, int state);
|
||||
|
||||
static void chunk_set_mask_new(UndoStream* stream, Sprite *sprite);
|
||||
static void chunk_set_mask_invert(UndoStream* stream, UndoChunkSetMask* chunk, int state);
|
||||
|
||||
@ -195,9 +208,11 @@ static UndoAction undo_actions[] = {
|
||||
DECL_UNDO_ACTION(remove_layer),
|
||||
DECL_UNDO_ACTION(move_layer),
|
||||
DECL_UNDO_ACTION(set_layer),
|
||||
DECL_UNDO_ACTION(add_palette),
|
||||
DECL_UNDO_ACTION(remove_palette),
|
||||
DECL_UNDO_ACTION(set_mask),
|
||||
DECL_UNDO_ACTION(set_frames),
|
||||
DECL_UNDO_ACTION(set_frlen)
|
||||
DECL_UNDO_ACTION(set_frlen),
|
||||
};
|
||||
|
||||
/* UndoChunk */
|
||||
@ -223,6 +238,10 @@ static Layer* read_raw_layer(ase_uint8* raw_data);
|
||||
static ase_uint8* write_raw_layer(ase_uint8* raw_data, Layer* layer);
|
||||
static int get_raw_layer_size(Layer* layer);
|
||||
|
||||
static Palette* read_raw_palette(ase_uint8* raw_data);
|
||||
static ase_uint8* write_raw_palette(ase_uint8* raw_data, Palette* palette);
|
||||
static int get_raw_palette_size(Palette* palette);
|
||||
|
||||
static Mask* read_raw_mask(ase_uint8* raw_data);
|
||||
static ase_uint8* write_raw_mask(ase_uint8* raw_data, Mask* mask);
|
||||
static int get_raw_mask_size(Mask* mask);
|
||||
@ -1216,10 +1235,11 @@ static void chunk_move_layer_invert(UndoStream* stream, UndoChunkMoveLayer* chun
|
||||
Layer* layer = (Layer* )gfxobj_find(chunk->layer_id);
|
||||
Layer* after = (Layer* )gfxobj_find(chunk->after_id);
|
||||
|
||||
if (set && layer) {
|
||||
chunk_move_layer_new(stream, layer);
|
||||
layer_move_layer(set, layer, after);
|
||||
}
|
||||
if (set == NULL || layer == NULL)
|
||||
throw undo_exception("chunk_move_layer_invert");
|
||||
|
||||
chunk_move_layer_new(stream, layer);
|
||||
layer_move_layer(set, layer, after);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
@ -1260,11 +1280,104 @@ static void chunk_set_layer_invert(UndoStream* stream, UndoChunkSetLayer* chunk,
|
||||
Sprite *sprite = (Sprite *)gfxobj_find(chunk->sprite_id);
|
||||
Layer* layer = (Layer* )gfxobj_find(chunk->layer_id);
|
||||
|
||||
if (sprite) {
|
||||
chunk_set_layer_new(stream, sprite);
|
||||
if (sprite == NULL)
|
||||
throw undo_exception("chunk_set_layer_invert");
|
||||
|
||||
sprite->layer = layer;
|
||||
}
|
||||
chunk_set_layer_new(stream, sprite);
|
||||
|
||||
sprite->layer = layer;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
||||
"add_palette"
|
||||
|
||||
DWORD sprite ID
|
||||
DWORD palette ID
|
||||
|
||||
***********************************************************************/
|
||||
|
||||
struct UndoChunkAddPalette
|
||||
{
|
||||
UndoChunk head;
|
||||
ase_uint32 sprite_id;
|
||||
ase_uint32 palette_id;
|
||||
};
|
||||
|
||||
void undo_add_palette(Undo* undo, Sprite *sprite, Palette* palette)
|
||||
{
|
||||
chunk_add_palette_new(undo->undo_stream, sprite, palette);
|
||||
update_undo(undo);
|
||||
}
|
||||
|
||||
static void chunk_add_palette_new(UndoStream* stream, Sprite *sprite, Palette* palette)
|
||||
{
|
||||
UndoChunkAddPalette* chunk = (UndoChunkAddPalette*)
|
||||
undo_chunk_new(stream,
|
||||
UNDO_TYPE_ADD_PALETTE,
|
||||
sizeof(UndoChunkAddPalette));
|
||||
|
||||
chunk->sprite_id = sprite->id;
|
||||
chunk->palette_id = palette->id;
|
||||
}
|
||||
|
||||
static void chunk_add_palette_invert(UndoStream* stream, UndoChunkAddPalette *chunk, int state)
|
||||
{
|
||||
Sprite* sprite = (Sprite*)gfxobj_find(chunk->sprite_id);
|
||||
Palette* palette = (Palette*)gfxobj_find(chunk->palette_id);
|
||||
|
||||
if (sprite == NULL || palette == NULL)
|
||||
throw undo_exception("chunk_add_palette_invert");
|
||||
|
||||
chunk_remove_palette_new(stream, sprite, palette);
|
||||
sprite_delete_palette(sprite, palette);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
||||
"remove_palette"
|
||||
|
||||
DWORD sprite ID
|
||||
PALETTE_DATA see read/write_raw_palette
|
||||
|
||||
***********************************************************************/
|
||||
|
||||
struct UndoChunkRemovePalette
|
||||
{
|
||||
UndoChunk head;
|
||||
ase_uint32 sprite_id;
|
||||
ase_uint8 data[0];
|
||||
};
|
||||
|
||||
void undo_remove_palette(Undo* undo, Sprite *sprite, Palette* palette)
|
||||
{
|
||||
chunk_remove_palette_new(undo->undo_stream, sprite, palette);
|
||||
update_undo(undo);
|
||||
}
|
||||
|
||||
static void chunk_remove_palette_new(UndoStream* stream, Sprite *sprite, Palette* palette)
|
||||
{
|
||||
UndoChunkRemovePalette* chunk = (UndoChunkRemovePalette*)
|
||||
undo_chunk_new(stream,
|
||||
UNDO_TYPE_REMOVE_PALETTE,
|
||||
sizeof(UndoChunkRemovePalette)+get_raw_palette_size(palette));
|
||||
|
||||
chunk->sprite_id = sprite->id;
|
||||
write_raw_palette(chunk->data, palette);
|
||||
}
|
||||
|
||||
static void chunk_remove_palette_invert(UndoStream* stream, UndoChunkRemovePalette *chunk, int state)
|
||||
{
|
||||
Sprite *sprite = (Sprite *)gfxobj_find(chunk->sprite_id);
|
||||
if (sprite == NULL)
|
||||
throw undo_exception("chunk_remove_palette_invert");
|
||||
|
||||
Palette* palette = read_raw_palette(chunk->data);
|
||||
|
||||
chunk_add_palette_new(stream, sprite, palette);
|
||||
sprite_set_palette(sprite, palette, true);
|
||||
|
||||
palette_free(palette);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
@ -1383,13 +1496,13 @@ void undo_set_frlen(Undo* undo, Sprite *sprite, int frame)
|
||||
|
||||
static void chunk_set_frlen_new(UndoStream* stream, Sprite *sprite, int frame)
|
||||
{
|
||||
assert(frame >= 0 && frame < sprite->frames);
|
||||
|
||||
UndoChunkSetFrlen *chunk = (UndoChunkSetFrlen *)
|
||||
undo_chunk_new(stream,
|
||||
UNDO_TYPE_SET_FRLEN,
|
||||
sizeof(UndoChunkSetFrlen));
|
||||
|
||||
assert(frame >= 0 && frame < sprite->frames);
|
||||
|
||||
chunk->sprite_id = sprite->id;
|
||||
chunk->frame = frame;
|
||||
chunk->frlen = sprite->frlens[frame];
|
||||
@ -1930,6 +2043,64 @@ static int get_raw_layer_size(Layer* layer)
|
||||
return size;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
||||
Raw palette data
|
||||
|
||||
WORD frame
|
||||
WORD ncolors
|
||||
for each color ("ncolors" times)
|
||||
DWORD _rgba color
|
||||
|
||||
***********************************************************************/
|
||||
|
||||
static Palette* read_raw_palette(ase_uint8* raw_data)
|
||||
{
|
||||
ase_uint32 dword;
|
||||
ase_uint16 word;
|
||||
ase_uint32 color;
|
||||
int frame, ncolors;
|
||||
Palette* palette;
|
||||
|
||||
read_raw_uint16(frame); /* frame */
|
||||
read_raw_uint16(ncolors); /* ncolors */
|
||||
|
||||
palette = palette_new(frame, ncolors);
|
||||
if (!palette)
|
||||
return NULL;
|
||||
|
||||
for (int c=0; c<ncolors; c++) {
|
||||
read_raw_uint32(color);
|
||||
palette_set_entry(palette, c, color);
|
||||
}
|
||||
|
||||
return palette;
|
||||
}
|
||||
|
||||
static ase_uint8* write_raw_palette(ase_uint8* raw_data, Palette* palette)
|
||||
{
|
||||
ase_uint32 dword;
|
||||
ase_uint16 word;
|
||||
ase_uint32 color;
|
||||
|
||||
write_raw_uint16(palette->frame); /* frame */
|
||||
write_raw_uint16(palette->ncolors); /* ncolors*/
|
||||
|
||||
for (int c=0; c<palette->ncolors; c++) {
|
||||
color = palette_get_entry(palette, c);
|
||||
write_raw_uint32(color);
|
||||
}
|
||||
|
||||
return raw_data;
|
||||
}
|
||||
|
||||
static int get_raw_palette_size(Palette* palette)
|
||||
{
|
||||
// 2 WORD + 4 BYTES*ncolors
|
||||
return 2*2 + 4*palette->ncolors;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
|
||||
Raw mask data
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <string.h> /* for strlen */
|
||||
|
||||
#include "raster/gfxobj.h"
|
||||
#include "ase_exception.h"
|
||||
|
||||
class Cel;
|
||||
class Image;
|
||||
@ -33,6 +34,12 @@ class Stock;
|
||||
struct Dirty;
|
||||
struct UndoStream;
|
||||
|
||||
class undo_exception : public ase_exception
|
||||
{
|
||||
public:
|
||||
undo_exception(const char* msg) throw() : ase_exception(msg) { }
|
||||
};
|
||||
|
||||
class Undo : public GfxObj
|
||||
{
|
||||
public:
|
||||
@ -87,6 +94,8 @@ void undo_add_layer(Undo* undo, Layer *set, Layer *layer);
|
||||
void undo_remove_layer(Undo* undo, Layer *layer);
|
||||
void undo_move_layer(Undo* undo, Layer *layer);
|
||||
void undo_set_layer(Undo* undo, Sprite* sprite);
|
||||
void undo_add_palette(Undo* undo, Sprite* sprite, Palette* palette);
|
||||
void undo_remove_palette(Undo* undo, Sprite* sprite, Palette* palette);
|
||||
void undo_set_mask(Undo* undo, Sprite* sprite);
|
||||
void undo_set_frames(Undo* undo, Sprite* sprite);
|
||||
void undo_set_frlen(Undo* undo, Sprite* sprite, int frame);
|
||||
|
248
src/sprite_wrappers.h
Normal file
248
src/sprite_wrappers.h
Normal file
@ -0,0 +1,248 @@
|
||||
/* 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 SPRITE_WRAPPERS_H
|
||||
#define SPRITE_WRAPPERS_H
|
||||
|
||||
#include <list>
|
||||
#include <exception>
|
||||
#include "ase_exception.h"
|
||||
#include "ase/ui_context.h"
|
||||
#include "raster/sprite.h"
|
||||
|
||||
class Context;
|
||||
|
||||
class locked_sprite_exception : public ase_exception
|
||||
{
|
||||
public:
|
||||
locked_sprite_exception() throw()
|
||||
: ase_exception("Cannot read/write the sprite.\n"
|
||||
"The sprite is locked by a background task.\n"
|
||||
"Try again later.") { }
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Wraps a sprite.
|
||||
*/
|
||||
class SpriteWrapper
|
||||
{
|
||||
protected:
|
||||
Sprite* m_sprite;
|
||||
|
||||
public:
|
||||
SpriteWrapper() : m_sprite(NULL) { }
|
||||
SpriteWrapper(const SpriteWrapper& copy) : m_sprite(copy.m_sprite) { }
|
||||
explicit SpriteWrapper(Sprite* sprite) : m_sprite(sprite) { }
|
||||
~SpriteWrapper() { }
|
||||
|
||||
SpriteWrapper& operator=(const SpriteWrapper& copy) {
|
||||
m_sprite = copy.m_sprite;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator Sprite* () { return m_sprite; }
|
||||
operator const Sprite* () const { return m_sprite; }
|
||||
|
||||
Sprite* operator->() {
|
||||
assert(m_sprite != NULL);
|
||||
return m_sprite;
|
||||
}
|
||||
|
||||
const Sprite* operator->() const {
|
||||
assert(m_sprite != NULL);
|
||||
return m_sprite;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Class to view the sprite's state.
|
||||
*/
|
||||
class SpriteReader : public SpriteWrapper
|
||||
{
|
||||
public:
|
||||
|
||||
SpriteReader()
|
||||
{
|
||||
}
|
||||
|
||||
explicit SpriteReader(Sprite* sprite)
|
||||
: SpriteWrapper(sprite)
|
||||
{
|
||||
if (m_sprite && !m_sprite->lock(false))
|
||||
throw locked_sprite_exception();
|
||||
}
|
||||
|
||||
explicit SpriteReader(const SpriteReader& copy)
|
||||
: SpriteWrapper(copy)
|
||||
{
|
||||
if (m_sprite && !m_sprite->lock(false))
|
||||
throw locked_sprite_exception();
|
||||
}
|
||||
|
||||
SpriteReader& operator=(const SpriteReader& copy)
|
||||
{
|
||||
// unlock old sprite
|
||||
if (m_sprite)
|
||||
m_sprite->unlock();
|
||||
|
||||
SpriteWrapper::operator=(copy);
|
||||
|
||||
// relock the sprite
|
||||
if (m_sprite && !m_sprite->lock(false))
|
||||
throw locked_sprite_exception();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
~SpriteReader() {
|
||||
// unlock the sprite
|
||||
if (m_sprite)
|
||||
m_sprite->unlock();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Class to modify the sprite's state.
|
||||
*/
|
||||
class SpriteWriter : public SpriteWrapper
|
||||
{
|
||||
bool m_from_reader;
|
||||
bool m_locked;
|
||||
|
||||
// Non-copyable
|
||||
SpriteWriter(const SpriteWriter&);
|
||||
SpriteWriter& operator=(const SpriteWriter&);
|
||||
|
||||
public:
|
||||
|
||||
SpriteWriter()
|
||||
: m_from_reader(false)
|
||||
, m_locked(false)
|
||||
{
|
||||
}
|
||||
|
||||
explicit SpriteWriter(Sprite* sprite)
|
||||
: SpriteWrapper(sprite)
|
||||
, m_from_reader(false)
|
||||
, m_locked(false)
|
||||
{
|
||||
if (m_sprite) {
|
||||
if (!m_sprite->lock(true))
|
||||
throw locked_sprite_exception();
|
||||
|
||||
m_locked = true;
|
||||
}
|
||||
}
|
||||
|
||||
explicit SpriteWriter(const SpriteReader& sprite)
|
||||
: SpriteWrapper(sprite)
|
||||
, m_from_reader(true)
|
||||
, m_locked(false)
|
||||
{
|
||||
if (m_sprite) {
|
||||
if (!m_sprite->lock_to_write())
|
||||
throw locked_sprite_exception();
|
||||
|
||||
m_locked = true;
|
||||
}
|
||||
}
|
||||
|
||||
~SpriteWriter() {
|
||||
unlock_writer();
|
||||
}
|
||||
|
||||
SpriteWriter& operator=(const SpriteReader& copy)
|
||||
{
|
||||
unlock_writer();
|
||||
|
||||
SpriteWrapper::operator=(copy);
|
||||
|
||||
m_locked = false;
|
||||
if (m_sprite) {
|
||||
m_from_reader = true;
|
||||
|
||||
if (!m_sprite->lock_to_write())
|
||||
throw locked_sprite_exception();
|
||||
|
||||
m_locked = true;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void unlock_writer()
|
||||
{
|
||||
if (m_sprite && m_locked) {
|
||||
if (m_from_reader)
|
||||
m_sprite->unlock_to_read();
|
||||
else
|
||||
m_sprite->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class CurrentSpriteReader : public SpriteReader
|
||||
{
|
||||
public:
|
||||
|
||||
CurrentSpriteReader(Context* context = UIContext::instance())
|
||||
: SpriteReader(context->get_current_sprite())
|
||||
{
|
||||
}
|
||||
|
||||
~CurrentSpriteReader() {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class CurrentSpriteWriter : public SpriteWriter
|
||||
{
|
||||
Context* m_context;
|
||||
|
||||
public:
|
||||
|
||||
CurrentSpriteWriter(Context* context = UIContext::instance())
|
||||
: SpriteWriter(context->get_current_sprite())
|
||||
, m_context(context)
|
||||
{
|
||||
}
|
||||
|
||||
~CurrentSpriteWriter() {
|
||||
}
|
||||
|
||||
void destroy()
|
||||
{
|
||||
assert(m_sprite != NULL);
|
||||
|
||||
m_context->remove_sprite(m_sprite);
|
||||
unlock_writer();
|
||||
|
||||
delete m_sprite;
|
||||
m_sprite = NULL;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // SPRITE_WRAPPERS_H
|
@ -23,15 +23,19 @@
|
||||
|
||||
#include "jinete/jlist.h"
|
||||
|
||||
#include "sprite_wrappers.h"
|
||||
#include "raster/blend.h"
|
||||
#include "raster/cel.h"
|
||||
#include "raster/dirty.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/layer.h"
|
||||
#include "raster/mask.h"
|
||||
#include "raster/palette.h"
|
||||
#include "raster/quant.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/stock.h"
|
||||
#include "raster/undo.h"
|
||||
#include "raster/undoable.h"
|
||||
#include "undoable.h"
|
||||
|
||||
/**
|
||||
* Starts a undoable sequence of operations.
|
||||
@ -39,18 +43,17 @@
|
||||
* All the operations will be grouped in the sprite's undo as an
|
||||
* atomic operation.
|
||||
*/
|
||||
Undoable::Undoable(Sprite* sprite, const char* label)
|
||||
Undoable::Undoable(SpriteWriter& sprite, const char* label)
|
||||
{
|
||||
assert(sprite);
|
||||
assert(label);
|
||||
assert(label != NULL);
|
||||
|
||||
this->sprite = sprite;
|
||||
committed = false;
|
||||
enabled_flag = undo_is_enabled(sprite->undo);
|
||||
m_sprite = sprite;
|
||||
m_committed = false;
|
||||
m_enabled_flag = undo_is_enabled(m_sprite->undo);
|
||||
|
||||
if (is_enabled()) {
|
||||
undo_set_label(sprite->undo, label);
|
||||
undo_open(sprite->undo);
|
||||
undo_set_label(m_sprite->undo, label);
|
||||
undo_open(m_sprite->undo);
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,16 +61,16 @@ Undoable::~Undoable()
|
||||
{
|
||||
if (is_enabled()) {
|
||||
// close the undo information
|
||||
undo_close(sprite->undo);
|
||||
undo_close(m_sprite->undo);
|
||||
|
||||
// if it isn't committed, we have to rollback all changes
|
||||
if (!committed) {
|
||||
if (!m_committed) {
|
||||
// undo the group of operations
|
||||
undo_do_undo(sprite->undo);
|
||||
undo_do_undo(m_sprite->undo);
|
||||
|
||||
// clear the redo (sorry to the user, here we lost the old redo
|
||||
// information)
|
||||
undo_clear_redo(sprite->undo);
|
||||
undo_clear_redo(m_sprite->undo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -81,7 +84,7 @@ Undoable::~Undoable()
|
||||
*/
|
||||
void Undoable::commit()
|
||||
{
|
||||
committed = true;
|
||||
m_committed = true;
|
||||
}
|
||||
|
||||
void Undoable::set_number_of_frames(int frames)
|
||||
@ -90,9 +93,9 @@ void Undoable::set_number_of_frames(int frames)
|
||||
|
||||
// increment frames counter in the sprite
|
||||
if (is_enabled())
|
||||
undo_set_frames(sprite->undo, sprite);
|
||||
undo_set_frames(m_sprite->undo, m_sprite);
|
||||
|
||||
sprite_set_frames(sprite, frames);
|
||||
sprite_set_frames(m_sprite, frames);
|
||||
}
|
||||
|
||||
void Undoable::set_current_frame(int frame)
|
||||
@ -100,9 +103,9 @@ void Undoable::set_current_frame(int frame)
|
||||
assert(frame >= 0);
|
||||
|
||||
if (is_enabled())
|
||||
undo_int(sprite->undo, sprite, &sprite->frame);
|
||||
undo_int(m_sprite->undo, m_sprite, &m_sprite->frame);
|
||||
|
||||
sprite_set_frame(sprite, frame);
|
||||
sprite_set_frame(m_sprite, frame);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,9 +117,9 @@ void Undoable::set_current_frame(int frame)
|
||||
void Undoable::set_current_layer(Layer* layer)
|
||||
{
|
||||
if (is_enabled())
|
||||
undo_set_layer(sprite->undo, sprite);
|
||||
undo_set_layer(m_sprite->undo, m_sprite);
|
||||
|
||||
sprite_set_layer(sprite, layer);
|
||||
sprite_set_layer(m_sprite, layer);
|
||||
}
|
||||
|
||||
void Undoable::set_sprite_size(int w, int h)
|
||||
@ -125,41 +128,41 @@ void Undoable::set_sprite_size(int w, int h)
|
||||
assert(h > 0);
|
||||
|
||||
if (is_enabled()) {
|
||||
undo_int(sprite->undo, sprite, &sprite->w);
|
||||
undo_int(sprite->undo, sprite, &sprite->h);
|
||||
undo_int(m_sprite->undo, m_sprite, &m_sprite->w);
|
||||
undo_int(m_sprite->undo, m_sprite, &m_sprite->h);
|
||||
}
|
||||
|
||||
sprite_set_size(sprite, w, h);
|
||||
sprite_set_size(m_sprite, w, h);
|
||||
}
|
||||
|
||||
void Undoable::crop_sprite(int x, int y, int w, int h, int bgcolor)
|
||||
{
|
||||
set_sprite_size(w, h);
|
||||
|
||||
displace_layers(sprite->set, -x, -y);
|
||||
displace_layers(m_sprite->set, -x, -y);
|
||||
|
||||
Layer *background_layer = sprite_get_background_layer(sprite);
|
||||
Layer *background_layer = sprite_get_background_layer(m_sprite);
|
||||
if (background_layer)
|
||||
crop_layer(background_layer, 0, 0, sprite->w, sprite->h, bgcolor);
|
||||
crop_layer(background_layer, 0, 0, m_sprite->w, m_sprite->h, bgcolor);
|
||||
|
||||
if (!mask_is_empty(sprite->mask))
|
||||
set_mask_position(sprite->mask->x-x, sprite->mask->y-y);
|
||||
if (!mask_is_empty(m_sprite->mask))
|
||||
set_mask_position(m_sprite->mask->x-x, m_sprite->mask->y-y);
|
||||
}
|
||||
|
||||
void Undoable::autocrop_sprite(int bgcolor)
|
||||
{
|
||||
int old_frame = sprite->frame;
|
||||
int old_frame = m_sprite->frame;
|
||||
int x1, y1, x2, y2;
|
||||
int u1, v1, u2, v2;
|
||||
|
||||
x1 = y1 = INT_MAX;
|
||||
x2 = y2 = INT_MIN;
|
||||
|
||||
Image* image = image_new(sprite->imgtype, sprite->w, sprite->h);
|
||||
Image* image = image_new(m_sprite->imgtype, m_sprite->w, m_sprite->h);
|
||||
|
||||
for (sprite->frame=0; sprite->frame<sprite->frames; sprite->frame++) {
|
||||
for (m_sprite->frame=0; m_sprite->frame<m_sprite->frames; m_sprite->frame++) {
|
||||
image_clear(image, 0);
|
||||
sprite_render(sprite, image, 0, 0);
|
||||
sprite_render(m_sprite, image, 0, 0);
|
||||
|
||||
// TODO configurable (what color pixel to use as "refpixel",
|
||||
// here we are using the top-left pixel by default)
|
||||
@ -171,7 +174,7 @@ void Undoable::autocrop_sprite(int bgcolor)
|
||||
y2 = MAX(y2, v2);
|
||||
}
|
||||
}
|
||||
sprite->frame = old_frame;
|
||||
m_sprite->frame = old_frame;
|
||||
|
||||
image_free(image);
|
||||
|
||||
@ -182,6 +185,79 @@ void Undoable::autocrop_sprite(int bgcolor)
|
||||
crop_sprite(x1, y1, x2-x1+1, y2-y1+1, bgcolor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @warning: it uses the current Allegro "rgb_map"
|
||||
*/
|
||||
void Undoable::set_imgtype(int new_imgtype, int dithering_method)
|
||||
{
|
||||
Image *old_image;
|
||||
Image *new_image;
|
||||
int c;
|
||||
|
||||
if (m_sprite->imgtype == new_imgtype)
|
||||
return;
|
||||
|
||||
/* change imgtype of the stock of images */
|
||||
if (is_enabled())
|
||||
undo_int(m_sprite->undo, (GfxObj *)m_sprite->stock, &m_sprite->stock->imgtype);
|
||||
|
||||
m_sprite->stock->imgtype = new_imgtype;
|
||||
|
||||
for (c=0; c<m_sprite->stock->nimage; c++) {
|
||||
old_image = stock_get_image(m_sprite->stock, c);
|
||||
if (!old_image)
|
||||
continue;
|
||||
|
||||
new_image = image_set_imgtype(old_image, new_imgtype, dithering_method,
|
||||
rgb_map,
|
||||
/* TODO check this out */
|
||||
sprite_get_palette(m_sprite,
|
||||
m_sprite->frame));
|
||||
if (!new_image)
|
||||
return; /* TODO error handling: not enough memory!
|
||||
we should undo all work done */
|
||||
|
||||
if (is_enabled())
|
||||
undo_replace_image(m_sprite->undo, m_sprite->stock, c);
|
||||
|
||||
image_free(old_image);
|
||||
stock_replace_image(m_sprite->stock, c, new_image);
|
||||
}
|
||||
|
||||
/* change "sprite.imgtype" field */
|
||||
if (is_enabled())
|
||||
undo_int(m_sprite->undo, m_sprite, &m_sprite->imgtype);
|
||||
|
||||
m_sprite->imgtype = new_imgtype;
|
||||
|
||||
// change "sprite.palette"
|
||||
if (new_imgtype == IMAGE_GRAYSCALE) {
|
||||
if (is_enabled()) {
|
||||
Palette* palette;
|
||||
JLink link;
|
||||
|
||||
JI_LIST_FOR_EACH(m_sprite->palettes, link) {
|
||||
if (jlist_first(m_sprite->palettes) != link) {
|
||||
palette = reinterpret_cast<Palette*>(link->data);
|
||||
undo_remove_palette(m_sprite->undo, m_sprite, palette);
|
||||
}
|
||||
}
|
||||
|
||||
palette = sprite_get_palette(m_sprite, 0);
|
||||
undo_data(m_sprite->undo, palette, palette->color, sizeof(palette->color));
|
||||
}
|
||||
|
||||
Palette* graypal = palette_new(0, MAX_PALETTE_COLORS);
|
||||
for (int c=0; c<256; c++)
|
||||
palette_set_entry(graypal, c, _rgba(c, c, c, 255));
|
||||
|
||||
sprite_reset_palettes(m_sprite);
|
||||
sprite_set_palette(m_sprite, graypal, false);
|
||||
|
||||
palette_free(graypal);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new image in the stock.
|
||||
*
|
||||
@ -193,10 +269,10 @@ int Undoable::add_image_in_stock(Image* image)
|
||||
assert(image);
|
||||
|
||||
// add the image in the stock
|
||||
int image_index = stock_add_image(sprite->stock, image);
|
||||
int image_index = stock_add_image(m_sprite->stock, image);
|
||||
|
||||
if (is_enabled())
|
||||
undo_add_image(sprite->undo, sprite->stock, image_index);
|
||||
undo_add_image(m_sprite->undo, m_sprite->stock, image_index);
|
||||
|
||||
return image_index;
|
||||
}
|
||||
@ -208,27 +284,27 @@ void Undoable::remove_image_from_stock(int image_index)
|
||||
{
|
||||
assert(image_index >= 0);
|
||||
|
||||
Image* image = stock_get_image(sprite->stock, image_index);
|
||||
Image* image = stock_get_image(m_sprite->stock, image_index);
|
||||
assert(image);
|
||||
|
||||
if (is_enabled())
|
||||
undo_remove_image(sprite->undo, sprite->stock, image_index);
|
||||
undo_remove_image(m_sprite->undo, m_sprite->stock, image_index);
|
||||
|
||||
stock_remove_image(sprite->stock, image);
|
||||
stock_remove_image(m_sprite->stock, image);
|
||||
image_free(image);
|
||||
}
|
||||
|
||||
void Undoable::replace_stock_image(int image_index, Image* new_image)
|
||||
{
|
||||
// get the current image in the 'image_index' position
|
||||
Image* old_image = stock_get_image(sprite->stock, image_index);
|
||||
Image* old_image = stock_get_image(m_sprite->stock, image_index);
|
||||
assert(old_image);
|
||||
|
||||
// replace the image in the stock
|
||||
if (is_enabled())
|
||||
undo_replace_image(sprite->undo, sprite->stock, image_index);
|
||||
undo_replace_image(m_sprite->undo, m_sprite->stock, image_index);
|
||||
|
||||
stock_replace_image(sprite->stock, image_index, new_image);
|
||||
stock_replace_image(m_sprite->stock, image_index, new_image);
|
||||
|
||||
// destroy the old image
|
||||
image_free(old_image);
|
||||
@ -240,15 +316,15 @@ void Undoable::replace_stock_image(int image_index, Image* new_image)
|
||||
Layer* Undoable::new_layer()
|
||||
{
|
||||
// new layer
|
||||
Layer* layer = layer_new(sprite);
|
||||
Layer* layer = layer_new(m_sprite);
|
||||
|
||||
// configure layer name and blend mode
|
||||
layer_set_blend_mode(layer, BLEND_MODE_NORMAL);
|
||||
|
||||
// add the layer in the sprite set
|
||||
if (is_enabled())
|
||||
undo_add_layer(sprite->undo, sprite->set, layer);
|
||||
layer_add_layer(sprite->set, layer);
|
||||
undo_add_layer(m_sprite->undo, m_sprite->set, layer);
|
||||
layer_add_layer(m_sprite->set, layer);
|
||||
|
||||
// select the new layer
|
||||
set_current_layer(layer);
|
||||
@ -266,7 +342,7 @@ void Undoable::remove_layer(Layer* layer)
|
||||
Layer* parent = layer->parent_layer;
|
||||
|
||||
// if the layer to be removed is the selected layer
|
||||
if (layer == sprite->layer) {
|
||||
if (layer == m_sprite->layer) {
|
||||
Layer* layer_select = NULL;
|
||||
|
||||
// select: previous layer, or next layer, or parent(if it is not the
|
||||
@ -275,7 +351,7 @@ void Undoable::remove_layer(Layer* layer)
|
||||
layer_select = layer_get_prev(layer);
|
||||
else if (layer_get_next(layer))
|
||||
layer_select = layer_get_next(layer);
|
||||
else if (parent != sprite->set)
|
||||
else if (parent != m_sprite->set)
|
||||
layer_select = parent;
|
||||
|
||||
// select other layer
|
||||
@ -284,7 +360,7 @@ void Undoable::remove_layer(Layer* layer)
|
||||
|
||||
// remove the layer
|
||||
if (is_enabled())
|
||||
undo_remove_layer(sprite->undo, layer);
|
||||
undo_remove_layer(m_sprite->undo, layer);
|
||||
|
||||
layer_remove_layer(parent, layer);
|
||||
|
||||
@ -296,7 +372,7 @@ void Undoable::remove_layer(Layer* layer)
|
||||
void Undoable::move_layer_after(Layer* layer, Layer* after_this)
|
||||
{
|
||||
if (is_enabled())
|
||||
undo_move_layer(sprite->undo, layer);
|
||||
undo_move_layer(m_sprite->undo, layer);
|
||||
|
||||
layer_move_layer(layer->parent_layer, layer, after_this);
|
||||
}
|
||||
@ -348,25 +424,26 @@ void Undoable::background_from_layer(Layer* layer, int bgcolor)
|
||||
assert(layer_is_image(layer));
|
||||
assert(layer_is_readable(layer));
|
||||
assert(layer_is_writable(layer));
|
||||
assert(layer->sprite == sprite);
|
||||
assert(sprite_get_background_layer(sprite) == NULL);
|
||||
assert(layer->sprite == m_sprite);
|
||||
assert(sprite_get_background_layer(m_sprite) == NULL);
|
||||
|
||||
// create a temporary image to draw each frame of the new
|
||||
// `Background' layer
|
||||
std::auto_ptr<Image> bg_image(image_new(sprite->imgtype, sprite->w, sprite->h));
|
||||
std::auto_ptr<Image> bg_image_wrap(image_new(m_sprite->imgtype, m_sprite->w, m_sprite->h));
|
||||
Image* bg_image = bg_image_wrap.get();
|
||||
|
||||
JLink link;
|
||||
JI_LIST_FOR_EACH(layer->cels, link) {
|
||||
Cel* cel = reinterpret_cast<Cel*>(link->data);
|
||||
assert((cel->image > 0) &&
|
||||
(cel->image < sprite->stock->nimage));
|
||||
(cel->image < m_sprite->stock->nimage));
|
||||
|
||||
// get the image from the sprite's stock of images
|
||||
Image* cel_image = stock_get_image(sprite->stock, cel->image);
|
||||
Image* cel_image = stock_get_image(m_sprite->stock, cel->image);
|
||||
assert(cel_image);
|
||||
|
||||
image_clear(bg_image.get(), bgcolor);
|
||||
image_merge(bg_image.get(), cel_image,
|
||||
image_clear(bg_image, bgcolor);
|
||||
image_merge(bg_image, cel_image,
|
||||
cel->x,
|
||||
cel->y,
|
||||
MID(0, cel->opacity, 255),
|
||||
@ -379,24 +456,139 @@ void Undoable::background_from_layer(Layer* layer, int bgcolor)
|
||||
if (bg_image->w == cel_image->w &&
|
||||
bg_image->h == cel_image->h) {
|
||||
if (is_enabled())
|
||||
undo_image(sprite->undo, cel_image, 0, 0, cel_image->w, cel_image->h);
|
||||
undo_image(m_sprite->undo, cel_image, 0, 0, cel_image->w, cel_image->h);
|
||||
|
||||
image_copy(cel_image, bg_image.get(), 0, 0);
|
||||
image_copy(cel_image, bg_image, 0, 0);
|
||||
}
|
||||
else {
|
||||
replace_stock_image(cel->image, image_new_copy(bg_image.get()));
|
||||
replace_stock_image(cel->image, image_new_copy(bg_image));
|
||||
}
|
||||
}
|
||||
|
||||
configure_layer_as_background(layer);
|
||||
}
|
||||
|
||||
void Undoable::layer_from_background()
|
||||
{
|
||||
assert(sprite_get_background_layer(m_sprite) != NULL);
|
||||
assert(m_sprite->layer != NULL);
|
||||
assert(layer_is_image(m_sprite->layer));
|
||||
assert(layer_is_readable(m_sprite->layer));
|
||||
assert(layer_is_writable(m_sprite->layer));
|
||||
assert(layer_is_background(m_sprite->layer));
|
||||
|
||||
if (is_enabled()) {
|
||||
undo_data(m_sprite->undo,
|
||||
m_sprite->layer,
|
||||
&m_sprite->layer->flags,
|
||||
sizeof(m_sprite->layer->flags));
|
||||
|
||||
undo_data(m_sprite->undo,
|
||||
m_sprite->layer,
|
||||
&m_sprite->layer->name,
|
||||
LAYER_NAME_SIZE);
|
||||
}
|
||||
|
||||
m_sprite->layer->flags &= ~(LAYER_IS_LOCKMOVE | LAYER_IS_BACKGROUND);
|
||||
layer_set_name(m_sprite->layer, "Layer 0");
|
||||
}
|
||||
|
||||
void Undoable::flatten_layers(int bgcolor)
|
||||
{
|
||||
JLink link, next;
|
||||
Layer *background;
|
||||
Image *cel_image;
|
||||
Cel *cel;
|
||||
int frame;
|
||||
|
||||
// create a temporary image
|
||||
std::auto_ptr<Image> image_wrap(image_new(m_sprite->imgtype, m_sprite->w, m_sprite->h));
|
||||
Image* image = image_wrap.get();
|
||||
|
||||
/* get the background layer from the sprite */
|
||||
background = sprite_get_background_layer(m_sprite);
|
||||
if (!background) {
|
||||
/* if there aren't a background layer we must to create the background */
|
||||
background = layer_new(m_sprite);
|
||||
|
||||
if (is_enabled())
|
||||
undo_add_layer(m_sprite->undo, m_sprite->set, background);
|
||||
|
||||
layer_add_layer(m_sprite->set, background);
|
||||
|
||||
if (is_enabled())
|
||||
undo_move_layer(m_sprite->undo, background);
|
||||
|
||||
layer_configure_as_background(background);
|
||||
}
|
||||
|
||||
/* copy all frames to the background */
|
||||
for (frame=0; frame<m_sprite->frames; frame++) {
|
||||
/* clear the image and render this frame */
|
||||
image_clear(image, bgcolor);
|
||||
layer_render(m_sprite->set, image, 0, 0, frame);
|
||||
|
||||
cel = layer_get_cel(background, frame);
|
||||
if (cel) {
|
||||
cel_image = m_sprite->stock->image[cel->image];
|
||||
assert(cel_image != NULL);
|
||||
|
||||
/* we have to save the current state of `cel_image' in the undo */
|
||||
if (is_enabled()) {
|
||||
Dirty* dirty = dirty_new_from_differences(cel_image, image);
|
||||
dirty_save_image_data(dirty);
|
||||
undo_dirty(m_sprite->undo, dirty);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* if there aren't a cel in this frame in the background, we
|
||||
have to create a copy of the image for the new cel */
|
||||
cel_image = image_new_copy(image);
|
||||
/* TODO error handling: if (!cel_image) { ... } */
|
||||
|
||||
/* here we create the new cel (with the new image `cel_image') */
|
||||
cel = cel_new(frame, stock_add_image(m_sprite->stock, cel_image));
|
||||
/* TODO error handling: if (!cel) { ... } */
|
||||
|
||||
/* and finally we add the cel in the background */
|
||||
layer_add_cel(background, cel);
|
||||
}
|
||||
|
||||
image_copy(cel_image, image, 0, 0);
|
||||
}
|
||||
|
||||
/* select the background */
|
||||
if (m_sprite->layer != background) {
|
||||
if (is_enabled())
|
||||
undo_set_layer(m_sprite->undo, m_sprite);
|
||||
|
||||
sprite_set_layer(m_sprite, background);
|
||||
}
|
||||
|
||||
/* remove old layers */
|
||||
JI_LIST_FOR_EACH_SAFE(m_sprite->set->layers, link, next) {
|
||||
if (link->data != background) {
|
||||
Layer* old_layer = reinterpret_cast<Layer*>(link->data);
|
||||
|
||||
/* remove the layer */
|
||||
if (is_enabled())
|
||||
undo_remove_layer(m_sprite->undo, old_layer);
|
||||
|
||||
layer_remove_layer(m_sprite->set, old_layer);
|
||||
|
||||
/* destroy the layer */
|
||||
layer_free_images(old_layer);
|
||||
layer_free(old_layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Undoable::configure_layer_as_background(Layer* layer)
|
||||
{
|
||||
if (is_enabled()) {
|
||||
undo_data(sprite->undo, (GfxObj *)layer, &layer->flags, sizeof(layer->flags));
|
||||
undo_data(sprite->undo, (GfxObj *)layer, &layer->name, LAYER_NAME_SIZE);
|
||||
undo_move_layer(sprite->undo, layer);
|
||||
undo_data(m_sprite->undo, (GfxObj *)layer, &layer->flags, sizeof(layer->flags));
|
||||
undo_data(m_sprite->undo, (GfxObj *)layer, &layer->name, LAYER_NAME_SIZE);
|
||||
undo_move_layer(m_sprite->undo, layer);
|
||||
}
|
||||
|
||||
layer_configure_as_background(layer);
|
||||
@ -405,14 +597,14 @@ void Undoable::configure_layer_as_background(Layer* layer)
|
||||
void Undoable::new_frame()
|
||||
{
|
||||
// add a new cel to every layer
|
||||
new_frame_for_layer(sprite->set,
|
||||
sprite->frame+1);
|
||||
new_frame_for_layer(m_sprite->set,
|
||||
m_sprite->frame+1);
|
||||
|
||||
// increment frames counter in the sprite
|
||||
set_number_of_frames(sprite->frames+1);
|
||||
set_number_of_frames(m_sprite->frames+1);
|
||||
|
||||
// go to next frame (the new one)
|
||||
set_current_frame(sprite->frame+1);
|
||||
set_current_frame(m_sprite->frame+1);
|
||||
}
|
||||
|
||||
void Undoable::new_frame_for_layer(Layer* layer, int frame)
|
||||
@ -424,7 +616,7 @@ void Undoable::new_frame_for_layer(Layer* layer, int frame)
|
||||
|
||||
case GFXOBJ_LAYER_IMAGE:
|
||||
// displace all cels in '>=frame' to the next frame
|
||||
for (int c=sprite->frames-1; c>=frame; --c) {
|
||||
for (int c=m_sprite->frames-1; c>=frame; --c) {
|
||||
Cel* cel = layer_get_cel(layer, c);
|
||||
if (cel)
|
||||
set_cel_frame_position(cel, cel->frame+1);
|
||||
@ -449,20 +641,20 @@ void Undoable::remove_frame(int frame)
|
||||
|
||||
// remove cels from this frame (and displace one position backward
|
||||
// all next frames)
|
||||
remove_frame_of_layer(sprite->set, frame);
|
||||
remove_frame_of_layer(m_sprite->set, frame);
|
||||
|
||||
/* decrement frames counter in the sprite */
|
||||
if (is_enabled())
|
||||
undo_set_frames(sprite->undo, sprite);
|
||||
undo_set_frames(m_sprite->undo, m_sprite);
|
||||
|
||||
sprite_set_frames(sprite, sprite->frames-1);
|
||||
sprite_set_frames(m_sprite, m_sprite->frames-1);
|
||||
|
||||
/* move backward if we are outside the range of frames */
|
||||
if (sprite->frame >= sprite->frames) {
|
||||
if (m_sprite->frame >= m_sprite->frames) {
|
||||
if (is_enabled())
|
||||
undo_int(sprite->undo, sprite, &sprite->frame);
|
||||
undo_int(m_sprite->undo, m_sprite, &m_sprite->frame);
|
||||
|
||||
sprite_set_frame(sprite, sprite->frames-1);
|
||||
sprite_set_frame(m_sprite, m_sprite->frames-1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -477,7 +669,7 @@ void Undoable::remove_frame_of_layer(Layer* layer, int frame)
|
||||
if (Cel* cel = layer_get_cel(layer, frame))
|
||||
remove_cel(layer, cel);
|
||||
|
||||
for (++frame; frame<sprite->frames; ++frame)
|
||||
for (++frame; frame<m_sprite->frames; ++frame)
|
||||
if (Cel* cel = layer_get_cel(layer, frame))
|
||||
set_cel_frame_position(cel, cel->frame-1);
|
||||
break;
|
||||
@ -502,7 +694,7 @@ void Undoable::copy_previous_frame(Layer* layer, int frame)
|
||||
|
||||
// create a copy of the previous cel
|
||||
Cel* src_cel = layer_get_cel(layer, frame-1);
|
||||
Image* src_image = src_cel ? stock_get_image(sprite->stock,
|
||||
Image* src_image = src_cel ? stock_get_image(m_sprite->stock,
|
||||
src_cel->image):
|
||||
NULL;
|
||||
|
||||
@ -532,7 +724,7 @@ void Undoable::add_cel(Layer* layer, Cel* cel)
|
||||
assert(layer_is_image(layer));
|
||||
|
||||
if (is_enabled())
|
||||
undo_add_cel(sprite->undo, layer, cel);
|
||||
undo_add_cel(m_sprite->undo, layer, cel);
|
||||
|
||||
layer_add_cel(layer, cel);
|
||||
}
|
||||
@ -546,7 +738,7 @@ void Undoable::remove_cel(Layer* layer, Cel* cel)
|
||||
// find if the image that use the cel to remove, is used by
|
||||
// another cels
|
||||
bool used = false;
|
||||
for (int frame=0; frame<sprite->frames; ++frame) {
|
||||
for (int frame=0; frame<m_sprite->frames; ++frame) {
|
||||
Cel* it = layer_get_cel(layer, frame);
|
||||
if (it && it != cel && it->image == cel->image) {
|
||||
used = true;
|
||||
@ -560,7 +752,7 @@ void Undoable::remove_cel(Layer* layer, Cel* cel)
|
||||
remove_image_from_stock(cel->image);
|
||||
|
||||
if (is_enabled())
|
||||
undo_remove_cel(sprite->undo, layer, cel);
|
||||
undo_remove_cel(m_sprite->undo, layer, cel);
|
||||
|
||||
// remove the cel from the layer
|
||||
layer_remove_cel(layer, cel);
|
||||
@ -575,7 +767,7 @@ void Undoable::set_cel_frame_position(Cel* cel, int frame)
|
||||
assert(frame >= 0);
|
||||
|
||||
if (is_enabled())
|
||||
undo_int(sprite->undo, cel, &cel->frame);
|
||||
undo_int(m_sprite->undo, cel, &cel->frame);
|
||||
|
||||
cel->frame = frame;
|
||||
}
|
||||
@ -585,8 +777,8 @@ void Undoable::set_cel_position(Cel* cel, int x, int y)
|
||||
assert(cel);
|
||||
|
||||
if (is_enabled()) {
|
||||
undo_int(sprite->undo, cel, &cel->x);
|
||||
undo_int(sprite->undo, cel, &cel->y);
|
||||
undo_int(m_sprite->undo, cel, &cel->x);
|
||||
undo_int(m_sprite->undo, cel, &cel->y);
|
||||
}
|
||||
|
||||
cel->x = x;
|
||||
@ -596,53 +788,53 @@ void Undoable::set_cel_position(Cel* cel, int x, int y)
|
||||
void Undoable::set_frame_duration(int frame, int msecs)
|
||||
{
|
||||
if (is_enabled())
|
||||
undo_set_frlen(sprite->undo, sprite, frame);
|
||||
undo_set_frlen(m_sprite->undo, m_sprite, frame);
|
||||
|
||||
sprite_set_frlen(sprite, frame, msecs);
|
||||
sprite_set_frlen(m_sprite, frame, msecs);
|
||||
}
|
||||
|
||||
void Undoable::set_constant_frame_rate(int msecs)
|
||||
{
|
||||
if (is_enabled()) {
|
||||
for (int fr=0; fr<sprite->frames; ++fr)
|
||||
undo_set_frlen(sprite->undo, sprite, fr);
|
||||
for (int fr=0; fr<m_sprite->frames; ++fr)
|
||||
undo_set_frlen(m_sprite->undo, m_sprite, fr);
|
||||
}
|
||||
|
||||
sprite_set_speed(sprite, msecs);
|
||||
sprite_set_speed(m_sprite, msecs);
|
||||
}
|
||||
|
||||
void Undoable::move_frame_before(int frame, int before_frame)
|
||||
{
|
||||
if (frame != before_frame &&
|
||||
frame >= 0 &&
|
||||
frame < sprite->frames &&
|
||||
frame < m_sprite->frames &&
|
||||
before_frame >= 0 &&
|
||||
before_frame < sprite->frames) {
|
||||
before_frame < m_sprite->frames) {
|
||||
// change the frame-lengths...
|
||||
|
||||
int frlen_aux = sprite->frlens[frame];
|
||||
int frlen_aux = m_sprite->frlens[frame];
|
||||
|
||||
// moving the frame to the future
|
||||
if (frame < before_frame) {
|
||||
frlen_aux = sprite->frlens[frame];
|
||||
frlen_aux = m_sprite->frlens[frame];
|
||||
|
||||
for (int c=frame; c<before_frame-1; c++)
|
||||
set_frame_duration(c, sprite->frlens[c+1]);
|
||||
set_frame_duration(c, m_sprite->frlens[c+1]);
|
||||
|
||||
set_frame_duration(before_frame-1, frlen_aux);
|
||||
}
|
||||
// moving the frame to the past
|
||||
else if (before_frame < frame) {
|
||||
frlen_aux = sprite->frlens[frame];
|
||||
frlen_aux = m_sprite->frlens[frame];
|
||||
|
||||
for (int c=frame; c>before_frame; c--)
|
||||
set_frame_duration(c, sprite->frlens[c-1]);
|
||||
set_frame_duration(c, m_sprite->frlens[c-1]);
|
||||
|
||||
set_frame_duration(before_frame, frlen_aux);
|
||||
}
|
||||
|
||||
// change the cels of position...
|
||||
move_frame_before_layer(sprite->set, frame, before_frame);
|
||||
move_frame_before_layer(m_sprite->set, frame, before_frame);
|
||||
}
|
||||
}
|
||||
|
||||
@ -697,15 +889,15 @@ void Undoable::move_frame_before_layer(Layer* layer, int frame, int before_frame
|
||||
|
||||
Cel* Undoable::get_current_cel()
|
||||
{
|
||||
if (sprite->layer && layer_is_image(sprite->layer))
|
||||
return layer_get_cel(sprite->layer, sprite->frame);
|
||||
if (m_sprite->layer && layer_is_image(m_sprite->layer))
|
||||
return layer_get_cel(m_sprite->layer, m_sprite->frame);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Undoable::crop_cel(Cel* cel, int x, int y, int w, int h, int bgcolor)
|
||||
{
|
||||
Image* cel_image = stock_get_image(sprite->stock, cel->image);
|
||||
Image* cel_image = stock_get_image(m_sprite->stock, cel->image);
|
||||
assert(cel_image);
|
||||
|
||||
// create the new image through a crop
|
||||
@ -720,8 +912,8 @@ void Undoable::crop_cel(Cel* cel, int x, int y, int w, int h, int bgcolor)
|
||||
|
||||
Image* Undoable::get_cel_image(Cel* cel)
|
||||
{
|
||||
if (cel && cel->image >= 0 && cel->image < sprite->stock->nimage)
|
||||
return sprite->stock->image[cel->image];
|
||||
if (cel && cel->image >= 0 && cel->image < m_sprite->stock->nimage)
|
||||
return m_sprite->stock->image[cel->image];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
@ -739,11 +931,11 @@ void Undoable::clear_mask(int bgcolor)
|
||||
|
||||
// if the mask is empty then we have to clear the entire image
|
||||
// in the cel
|
||||
if (mask_is_empty(sprite->mask)) {
|
||||
if (mask_is_empty(m_sprite->mask)) {
|
||||
// if the layer is the background then we clear the image
|
||||
if (layer_is_background(sprite->layer)) {
|
||||
if (layer_is_background(m_sprite->layer)) {
|
||||
if (is_enabled())
|
||||
undo_image(sprite->undo, image, 0, 0, image->w, image->h);
|
||||
undo_image(m_sprite->undo, image, 0, 0, image->w, image->h);
|
||||
|
||||
// clear all
|
||||
image_clear(image, bgcolor);
|
||||
@ -751,32 +943,32 @@ void Undoable::clear_mask(int bgcolor)
|
||||
// if the layer is transparent we can remove the cel (and its
|
||||
// associated image)
|
||||
else {
|
||||
remove_cel(sprite->layer, cel);
|
||||
remove_cel(m_sprite->layer, cel);
|
||||
}
|
||||
}
|
||||
else {
|
||||
int u, v, putx, puty;
|
||||
int x1 = MAX(0, sprite->mask->x);
|
||||
int y1 = MAX(0, sprite->mask->y);
|
||||
int x2 = MIN(image->w-1, sprite->mask->x+sprite->mask->w-1);
|
||||
int y2 = MIN(image->h-1, sprite->mask->y+sprite->mask->h-1);
|
||||
int x1 = MAX(0, m_sprite->mask->x);
|
||||
int y1 = MAX(0, m_sprite->mask->y);
|
||||
int x2 = MIN(image->w-1, m_sprite->mask->x+m_sprite->mask->w-1);
|
||||
int y2 = MIN(image->h-1, m_sprite->mask->y+m_sprite->mask->h-1);
|
||||
|
||||
// do nothing
|
||||
if (x1 > x2 || y1 > y2)
|
||||
return;
|
||||
|
||||
if (is_enabled())
|
||||
undo_image(sprite->undo, image, x1, y1, x2-x1+1, y2-y1+1);
|
||||
undo_image(m_sprite->undo, image, x1, y1, x2-x1+1, y2-y1+1);
|
||||
|
||||
// clear the masked zones
|
||||
for (v=0; v<sprite->mask->h; v++) {
|
||||
for (v=0; v<m_sprite->mask->h; v++) {
|
||||
div_t d = div(0, 8);
|
||||
ase_uint8* address = ((ase_uint8 **)sprite->mask->bitmap->line)[v]+d.quot;
|
||||
ase_uint8* address = ((ase_uint8 **)m_sprite->mask->bitmap->line)[v]+d.quot;
|
||||
|
||||
for (u=0; u<sprite->mask->w; u++) {
|
||||
for (u=0; u<m_sprite->mask->w; u++) {
|
||||
if ((*address & (1<<d.rem))) {
|
||||
putx = u + sprite->mask->x - cel->x;
|
||||
puty = v + sprite->mask->y - cel->y;
|
||||
putx = u + m_sprite->mask->x - cel->x;
|
||||
puty = v + m_sprite->mask->y - cel->y;
|
||||
image_putpixel(image, putx, puty, bgcolor);
|
||||
}
|
||||
|
||||
@ -788,25 +980,24 @@ void Undoable::clear_mask(int bgcolor)
|
||||
|
||||
void Undoable::copy_to_current_mask(Mask* mask)
|
||||
{
|
||||
assert(sprite->mask);
|
||||
assert(m_sprite->mask);
|
||||
assert(mask);
|
||||
|
||||
if (is_enabled())
|
||||
undo_set_mask(sprite->undo, sprite);
|
||||
undo_set_mask(m_sprite->undo, m_sprite);
|
||||
|
||||
mask_copy(sprite->mask, mask);
|
||||
mask_copy(m_sprite->mask, mask);
|
||||
}
|
||||
|
||||
void Undoable::set_mask_position(int x, int y)
|
||||
{
|
||||
assert(sprite->mask);
|
||||
assert(m_sprite->mask);
|
||||
|
||||
if (is_enabled()) {
|
||||
undo_int(sprite->undo, sprite->mask, &sprite->mask->x);
|
||||
undo_int(sprite->undo, sprite->mask, &sprite->mask->y);
|
||||
undo_int(m_sprite->undo, m_sprite->mask, &m_sprite->mask->x);
|
||||
undo_int(m_sprite->undo, m_sprite->mask, &m_sprite->mask->y);
|
||||
}
|
||||
|
||||
sprite->mask->x = x;
|
||||
sprite->mask->y = y;
|
||||
m_sprite->mask->x = x;
|
||||
m_sprite->mask->y = y;
|
||||
}
|
||||
|
@ -16,11 +16,13 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef RASTER_UNDOABLE_H
|
||||
#define RASTER_UNDOABLE_H
|
||||
#ifndef UNDOABLE_H
|
||||
#define UNDOABLE_H
|
||||
|
||||
class Cel;
|
||||
class Layer;
|
||||
class Sprite;
|
||||
class SpriteWriter;
|
||||
|
||||
/**
|
||||
* Class with high-level set of routines to modify a sprite.
|
||||
@ -30,16 +32,16 @@ class Sprite;
|
||||
*/
|
||||
class Undoable
|
||||
{
|
||||
Sprite* sprite;
|
||||
bool committed;
|
||||
bool enabled_flag;
|
||||
Sprite* m_sprite;
|
||||
bool m_committed;
|
||||
bool m_enabled_flag;
|
||||
|
||||
public:
|
||||
Undoable(Sprite* sprite, const char* label);
|
||||
Undoable(SpriteWriter& sprite, const char* label);
|
||||
virtual ~Undoable();
|
||||
|
||||
inline Sprite* get_sprite() const { return sprite; }
|
||||
inline bool is_enabled() const { return enabled_flag; }
|
||||
inline Sprite* get_sprite() const { return m_sprite; }
|
||||
inline bool is_enabled() const { return m_enabled_flag; }
|
||||
|
||||
void commit();
|
||||
|
||||
@ -50,6 +52,7 @@ public:
|
||||
void set_sprite_size(int w, int h);
|
||||
void crop_sprite(int x, int y, int w, int h, int bgcolor);
|
||||
void autocrop_sprite(int bgcolor);
|
||||
void set_imgtype(int new_imgtype, int dithering_method);
|
||||
|
||||
// for images in stock
|
||||
int add_image_in_stock(Image* image);
|
||||
@ -63,6 +66,8 @@ public:
|
||||
void crop_layer(Layer* layer, int x, int y, int w, int h, int bgcolor);
|
||||
void displace_layers(Layer* layer, int dx, int dy);
|
||||
void background_from_layer(Layer* layer, int bgcolor);
|
||||
void layer_from_background();
|
||||
void flatten_layers(int bgcolor);
|
||||
private:
|
||||
void configure_layer_as_background(Layer* layer);
|
||||
|
||||
@ -96,4 +101,4 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#endif /* RASTER_UNDOABLE_H */
|
||||
#endif // UNDOABLE_H
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user