2007-11-16 18:25:45 +00:00
|
|
|
/* ASE - Allegro Sprite Editor
|
2010-02-01 21:25:40 +00:00
|
|
|
* Copyright (C) 2001-2010 David Capello
|
2007-11-08 00:54:31 +00:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2009-07-10 02:08:41 +00:00
|
|
|
#include <allegro/unicode.h>
|
|
|
|
|
|
|
|
#include "jinete/jlist.h"
|
|
|
|
|
2009-10-09 01:34:06 +00:00
|
|
|
#include "commands/command.h"
|
|
|
|
#include "commands/params.h"
|
2007-11-08 00:54:31 +00:00
|
|
|
#include "modules/editors.h"
|
|
|
|
#include "modules/gui.h"
|
2009-07-10 02:08:41 +00:00
|
|
|
#include "raster/cel.h"
|
2007-11-08 00:54:31 +00:00
|
|
|
#include "raster/image.h"
|
|
|
|
#include "raster/mask.h"
|
|
|
|
#include "raster/sprite.h"
|
2009-07-10 02:08:41 +00:00
|
|
|
#include "raster/stock.h"
|
2007-11-08 00:54:31 +00:00
|
|
|
#include "raster/undo.h"
|
|
|
|
#include "util/misc.h"
|
2009-07-10 02:08:41 +00:00
|
|
|
#include "undoable.h"
|
2009-10-09 01:34:06 +00:00
|
|
|
#include "sprite_wrappers.h"
|
2007-11-08 00:54:31 +00:00
|
|
|
|
2009-10-09 01:34:06 +00:00
|
|
|
class FlipCommand : public Command
|
2007-11-08 00:54:31 +00:00
|
|
|
{
|
2009-10-09 01:34:06 +00:00
|
|
|
bool m_flip_mask;
|
|
|
|
bool m_flip_horizontal;
|
|
|
|
bool m_flip_vertical;
|
|
|
|
|
|
|
|
public:
|
|
|
|
FlipCommand();
|
|
|
|
Command* clone() const { return new FlipCommand(*this); }
|
|
|
|
|
|
|
|
protected:
|
2010-07-31 15:23:45 +00:00
|
|
|
void onLoadParams(Params* params);
|
|
|
|
bool onEnabled(Context* context);
|
|
|
|
void onExecute(Context* context);
|
2009-10-09 01:34:06 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static char* read_authors_txt(const char *filename);
|
|
|
|
};
|
|
|
|
|
|
|
|
FlipCommand::FlipCommand()
|
|
|
|
: Command("flip",
|
|
|
|
"Flip",
|
|
|
|
CmdRecordableFlag)
|
|
|
|
{
|
|
|
|
m_flip_mask = false;
|
|
|
|
m_flip_horizontal = false;
|
|
|
|
m_flip_vertical = false;
|
|
|
|
}
|
|
|
|
|
2010-07-31 15:23:45 +00:00
|
|
|
void FlipCommand::onLoadParams(Params* params)
|
2009-10-09 01:34:06 +00:00
|
|
|
{
|
|
|
|
std::string target = params->get("target");
|
|
|
|
m_flip_mask = (target == "mask");
|
|
|
|
|
|
|
|
std::string orientation = params->get("orientation");
|
|
|
|
m_flip_horizontal = (orientation == "horizontal");
|
|
|
|
m_flip_vertical = (orientation == "vertical");
|
|
|
|
}
|
|
|
|
|
2010-07-31 15:23:45 +00:00
|
|
|
bool FlipCommand::onEnabled(Context* context)
|
2009-10-09 01:34:06 +00:00
|
|
|
{
|
|
|
|
const CurrentSpriteReader sprite(context);
|
2009-06-11 15:11:11 +00:00
|
|
|
return
|
2009-07-27 03:03:19 +00:00
|
|
|
sprite != NULL;
|
2007-11-08 00:54:31 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 15:23:45 +00:00
|
|
|
void FlipCommand::onExecute(Context* context)
|
2007-11-08 00:54:31 +00:00
|
|
|
{
|
2009-10-09 01:34:06 +00:00
|
|
|
CurrentSpriteWriter sprite(context);
|
2009-07-10 02:08:41 +00:00
|
|
|
|
|
|
|
{
|
2009-10-09 01:34:06 +00:00
|
|
|
Undoable undoable(sprite, m_flip_mask ?
|
|
|
|
(m_flip_horizontal ? "Flip Horizontal":
|
|
|
|
"Flip Vertical"):
|
|
|
|
(m_flip_horizontal ? "Flip Canvas Horizontal":
|
|
|
|
"Flip Canvas Vertical"));
|
2009-07-10 02:08:41 +00:00
|
|
|
|
2009-10-09 01:34:06 +00:00
|
|
|
if (m_flip_mask) {
|
2009-08-17 18:00:38 +00:00
|
|
|
Image* image;
|
2009-07-10 02:08:41 +00:00
|
|
|
int x1, y1, x2, y2;
|
|
|
|
int x, y;
|
|
|
|
|
2010-03-31 00:43:18 +00:00
|
|
|
image = sprite->getCurrentImage(&x, &y);
|
2009-07-10 02:08:41 +00:00
|
|
|
if (!image)
|
2010-03-07 18:39:58 +00:00
|
|
|
return;
|
|
|
|
// mask is empty?
|
2010-03-31 00:43:18 +00:00
|
|
|
if (sprite->getMask()->is_empty()) {
|
2010-03-07 18:39:58 +00:00
|
|
|
// so we flip the entire image
|
|
|
|
x1 = 0;
|
|
|
|
y1 = 0;
|
2009-07-10 02:08:41 +00:00
|
|
|
x2 = image->w-1;
|
|
|
|
y2 = image->h-1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// apply the cel offset
|
2010-03-31 00:43:18 +00:00
|
|
|
x1 = sprite->getMask()->x - x;
|
|
|
|
y1 = sprite->getMask()->y - y;
|
|
|
|
x2 = sprite->getMask()->x + sprite->getMask()->w - 1 - x;
|
|
|
|
y2 = sprite->getMask()->y + sprite->getMask()->h - 1 - y;
|
2009-07-10 02:08:41 +00:00
|
|
|
|
|
|
|
// clip
|
|
|
|
x1 = MID(0, x1, image->w-1);
|
|
|
|
y1 = MID(0, y1, image->h-1);
|
|
|
|
x2 = MID(0, x2, image->w-1);
|
|
|
|
y2 = MID(0, y2, image->h-1);
|
|
|
|
}
|
|
|
|
|
2010-09-19 13:33:07 +00:00
|
|
|
undoable.flipImage(image, x1, y1, x2, y2,
|
|
|
|
m_flip_horizontal, m_flip_vertical);
|
2009-07-10 02:08:41 +00:00
|
|
|
}
|
2009-10-09 01:34:06 +00:00
|
|
|
else {
|
2009-07-10 02:08:41 +00:00
|
|
|
// get all sprite cels
|
2009-11-17 13:12:26 +00:00
|
|
|
CelList cels;
|
2010-03-31 00:43:18 +00:00
|
|
|
sprite->getCels(cels);
|
2009-07-10 02:08:41 +00:00
|
|
|
|
|
|
|
// for each cel...
|
2009-11-17 13:12:26 +00:00
|
|
|
for (CelIterator it = cels.begin(); it != cels.end(); ++it) {
|
|
|
|
Cel* cel = *it;
|
2010-03-31 00:43:18 +00:00
|
|
|
Image* image = stock_get_image(sprite->getStock(), cel->image);
|
2009-07-10 02:08:41 +00:00
|
|
|
|
2010-09-19 13:33:07 +00:00
|
|
|
undoable.setCelPosition(cel,
|
|
|
|
m_flip_horizontal ? sprite->getWidth() - image->w - cel->x: cel->x,
|
|
|
|
m_flip_vertical ? sprite->getHeight() - image->h - cel->y: cel->y);
|
2009-07-10 02:08:41 +00:00
|
|
|
|
2010-09-19 13:33:07 +00:00
|
|
|
undoable.flipImage(image, 0, 0, image->w-1, image->h-1,
|
|
|
|
m_flip_horizontal, m_flip_vertical);
|
2009-07-10 02:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
undoable.commit();
|
2007-11-08 00:54:31 +00:00
|
|
|
}
|
2009-10-09 01:34:06 +00:00
|
|
|
|
2009-06-01 02:59:15 +00:00
|
|
|
update_screen_for_sprite(sprite);
|
2007-11-08 00:54:31 +00:00
|
|
|
}
|
2007-12-05 01:30:50 +00:00
|
|
|
|
2009-10-09 01:34:06 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// CommandFactory
|
|
|
|
|
|
|
|
Command* CommandFactory::create_flip_command()
|
|
|
|
{
|
|
|
|
return new FlipCommand;
|
|
|
|
}
|