mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +00:00
Fix flip commands behavior when the user is moving the selection.
This commit is contained in:
parent
e89d8a6231
commit
516834a80a
@ -18,13 +18,12 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "commands/cmd_flip.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "commands/command.h"
|
||||
#include "commands/params.h"
|
||||
#include "document_wrappers.h"
|
||||
#include "gfx/size.h"
|
||||
#include "gui/list.h"
|
||||
#include "modules/editors.h"
|
||||
#include "modules/gui.h"
|
||||
#include "raster/algorithm/flip_image.h"
|
||||
#include "raster/cel.h"
|
||||
@ -32,29 +31,7 @@
|
||||
#include "raster/mask.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/stock.h"
|
||||
#include "undo/undo_history.h"
|
||||
#include "undo_transaction.h"
|
||||
#include "util/misc.h"
|
||||
|
||||
#include <allegro/unicode.h>
|
||||
|
||||
class FlipCommand : public Command
|
||||
{
|
||||
public:
|
||||
FlipCommand();
|
||||
Command* clone() const { return new FlipCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
bool onEnabled(Context* context);
|
||||
void onExecute(Context* context);
|
||||
|
||||
private:
|
||||
static char* read_authors_txt(const char *filename);
|
||||
|
||||
bool m_flipMask;
|
||||
raster::algorithm::FlipType m_flipType;
|
||||
};
|
||||
|
||||
FlipCommand::FlipCommand()
|
||||
: Command("Flip",
|
||||
|
43
src/commands/cmd_flip.h
Normal file
43
src/commands/cmd_flip.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* ASEPRITE
|
||||
* Copyright (C) 2001-2012 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 COMMANDS_CMD_FLIP_H_INCLUDED
|
||||
#define COMMANDS_CMD_FLIP_H_INCLUDED
|
||||
|
||||
#include "commands/command.h"
|
||||
#include "raster/algorithm/flip_type.h"
|
||||
|
||||
class FlipCommand : public Command
|
||||
{
|
||||
public:
|
||||
FlipCommand();
|
||||
Command* clone() const { return new FlipCommand(*this); }
|
||||
|
||||
raster::algorithm::FlipType getFlipType() const { return m_flipType; }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
bool onEnabled(Context* context);
|
||||
void onExecute(Context* context);
|
||||
|
||||
private:
|
||||
bool m_flipMask;
|
||||
raster::algorithm::FlipType m_flipType;
|
||||
};
|
||||
|
||||
#endif // COMMANDS_CMD_FLIP_H_INCLUDED
|
@ -23,6 +23,7 @@
|
||||
#include "app.h"
|
||||
#include "app/color_utils.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "commands/cmd_flip.h"
|
||||
#include "commands/command.h"
|
||||
#include "commands/commands.h"
|
||||
#include "gfx/rect.h"
|
||||
@ -32,6 +33,7 @@
|
||||
#include "gui/view.h"
|
||||
#include "modules/editors.h"
|
||||
#include "modules/gui.h"
|
||||
#include "raster/algorithm/flip_image.h"
|
||||
#include "raster/mask.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "tools/ink.h"
|
||||
@ -336,6 +338,14 @@ bool MovingPixelsState::onKeyDown(Editor* editor, Message* msg)
|
||||
// Return true because we've used the keyboard shortcut.
|
||||
return true;
|
||||
}
|
||||
// Flip Horizontally/Vertically commands are handled manually to
|
||||
// avoid dropping the floating region of pixels.
|
||||
else if (strcmp(cmd->short_name(), CommandId::Flip) == 0) {
|
||||
if (FlipCommand* flipCommand = dynamic_cast<FlipCommand*>(cmd)) {
|
||||
m_pixelsMovement->flipImage(flipCommand->getFlipType());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "document.h"
|
||||
#include "la/vector2d.h"
|
||||
#include "modules/gui.h"
|
||||
#include "raster/algorithm/flip_image.h"
|
||||
#include "raster/cel.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/mask.h"
|
||||
@ -69,6 +70,37 @@ PixelsMovement::~PixelsMovement()
|
||||
delete m_currentMask;
|
||||
}
|
||||
|
||||
void PixelsMovement::flipImage(raster::algorithm::FlipType flipType)
|
||||
{
|
||||
// Flip the image.
|
||||
raster::algorithm::flip_image(m_originalImage,
|
||||
gfx::Rect(gfx::Point(0, 0),
|
||||
gfx::Size(m_originalImage->w,
|
||||
m_originalImage->h)),
|
||||
flipType);
|
||||
|
||||
// Flip the mask.
|
||||
raster::algorithm::flip_image(m_initialMask->getBitmap(),
|
||||
gfx::Rect(gfx::Point(0, 0),
|
||||
gfx::Size(m_initialMask->getBounds().w,
|
||||
m_initialMask->getBounds().h)),
|
||||
flipType);
|
||||
|
||||
{
|
||||
DocumentWriter documentWriter(m_documentReader);
|
||||
|
||||
// Regenerate the transformed (rotated, scaled, etc.) image and
|
||||
// mask.
|
||||
redrawExtraImage(documentWriter);
|
||||
redrawCurrentMask();
|
||||
|
||||
documentWriter->setMask(m_currentMask);
|
||||
documentWriter->generateMaskBoundaries(m_currentMask);
|
||||
}
|
||||
|
||||
update_screen_for_document(m_documentReader);
|
||||
}
|
||||
|
||||
void PixelsMovement::cutMask()
|
||||
{
|
||||
{
|
||||
|
@ -20,9 +20,10 @@
|
||||
#define WIDGETS_EDITOR_PIXELS_MOVEMENT_H_INCLUDED
|
||||
|
||||
#include "document_wrappers.h"
|
||||
#include "gfx/size.h"
|
||||
#include "raster/algorithm/flip_type.h"
|
||||
#include "undo_transaction.h"
|
||||
#include "widgets/editor/handle_type.h"
|
||||
#include "gfx/size.h"
|
||||
|
||||
class Document;
|
||||
class Image;
|
||||
@ -80,6 +81,12 @@ public:
|
||||
|
||||
void setMaskColor(uint32_t mask_color);
|
||||
|
||||
// Flips the image and mask in the given direction in "flipType".
|
||||
// Flip Horizontally/Vertically commands are replaced calling this
|
||||
// function, so they work more as the user would expect (flip the
|
||||
// current selection instead of dropping and flipping it).
|
||||
void flipImage(raster::algorithm::FlipType flipType);
|
||||
|
||||
const gfx::Transformation& getTransformation() const { return m_currentData; }
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user