Merge branch 'master'

This commit is contained in:
David Capello 2018-07-07 12:20:25 -03:00
commit a360c4fcc4
7 changed files with 168 additions and 126 deletions

View File

@ -21,10 +21,15 @@
#include "app/doc_api.h"
#include "app/doc_range.h"
#include "app/i18n/strings.h"
#include "app/modules/editors.h"
#include "app/modules/gui.h"
#include "app/tools/tool_box.h"
#include "app/transaction.h"
#include "app/ui/editor/editor.h"
#include "app/ui/editor/moving_pixels_state.h"
#include "app/ui/status_bar.h"
#include "app/ui/timeline/timeline.h"
#include "app/ui/toolbar.h"
#include "app/util/expand_cel_canvas.h"
#include "app/util/range_utils.h"
#include "doc/algorithm/flip_image.h"
@ -37,6 +42,7 @@
#include "fmt/format.h"
#include "gfx/size.h"
namespace app {
FlipCommand::FlipCommand()
@ -63,14 +69,7 @@ bool FlipCommand::onEnabled(Context* context)
void FlipCommand::onExecute(Context* context)
{
ContextWriter writer(context);
Doc* document = writer.document();
Sprite* sprite = writer.sprite();
{
Transaction transaction(writer.context(), friendlyName());
DocApi api = document->getApi(transaction);
Site site = context->activeSite();
Timeline* timeline = App::instance()->timeline();
LockTimelineRange lockRange(timeline);
@ -78,12 +77,23 @@ void FlipCommand::onExecute(Context* context)
if (m_flipMask) {
auto range = timeline->range();
if (range.enabled()) {
cels = get_unlocked_unique_cels(sprite, range);
cels = get_unlocked_unique_cels(site.sprite(), range);
}
else if (writer.cel() &&
writer.layer() &&
writer.layer()->isEditable()) {
cels.push_back(writer.cel());
else if (site.cel() &&
site.layer() &&
site.layer()->isEditable()) {
// If we want to flip the visible mask for the current cel,
// we can go to MovingPixelsState.
if (site.document()->isMaskVisible()) {
// Select marquee tool
if (tools::Tool* tool = App::instance()->toolBox()
->getToolById(tools::WellKnownTools::RectangularMarquee)) {
ToolBar::instance()->selectTool(tool);
current_editor->startFlipTransformation(m_flipType);
return;
}
}
cels.push_back(site.cel());
}
if (cels.empty()) {
@ -94,10 +104,16 @@ void FlipCommand::onExecute(Context* context)
}
// Flip the whole sprite (even locked layers)
else {
for (Cel* cel : sprite->uniqueCels())
for (Cel* cel : site.sprite()->uniqueCels())
cels.push_back(cel);
}
ContextWriter writer(context);
Doc* document = writer.document();
Sprite* sprite = writer.sprite();
Transaction transaction(writer.context(), friendlyName());
DocApi api = document->getApi(transaction);
Mask* mask = document->mask();
if (m_flipMask && document->isMaskVisible()) {
Site site = *writer.site();
@ -211,8 +227,6 @@ void FlipCommand::onExecute(Context* context)
}
transaction.commit();
}
update_screen_for_document(document);
}

View File

@ -2238,6 +2238,14 @@ void Editor::startSelectionTransformation(const gfx::Point& move, double angle)
}
}
void Editor::startFlipTransformation(doc::algorithm::FlipType flipType)
{
if (MovingPixelsState* movingPixels = dynamic_cast<MovingPixelsState*>(m_state.get()))
movingPixels->flip(flipType);
else if (StandbyState* standby = dynamic_cast<StandbyState*>(m_state.get()))
standby->startFlipTransformation(this, flipType);
}
void Editor::notifyScrollChanged()
{
m_observers.notifyScrollChanged(this);

View File

@ -20,6 +20,7 @@
#include "app/ui/editor/editor_observers.h"
#include "app/ui/editor/editor_state.h"
#include "app/ui/editor/editor_states_history.h"
#include "doc/algorithm/flip_type.h"
#include "doc/frame.h"
#include "doc/image_buffer.h"
#include "filters/tiled_mode.h"
@ -219,6 +220,8 @@ namespace app {
void startSelectionTransformation(const gfx::Point& move, double angle);
void startFlipTransformation(doc::algorithm::FlipType flipType);
// Used by EditorView to notify changes in the view's scroll
// position.
void notifyScrollChanged();

View File

@ -134,6 +134,11 @@ void MovingPixelsState::rotate(double angle)
m_pixelsMovement->rotate(angle);
}
void MovingPixelsState::flip(doc::algorithm::FlipType flipType)
{
m_pixelsMovement->flipImage(flipType);
}
void MovingPixelsState::onEnterState(Editor* editor)
{
StandbyState::onEnterState(editor);

View File

@ -34,6 +34,7 @@ namespace app {
void translate(const gfx::Point& delta);
void rotate(double angle);
void flip(doc::algorithm::FlipType flipType);
// EditorState
virtual void onEnterState(Editor* editor) override;

View File

@ -673,6 +673,14 @@ void StandbyState::startSelectionTransformation(Editor* editor,
}
}
void StandbyState::startFlipTransformation(Editor* editor, doc::algorithm::FlipType flipType)
{
transformSelection(editor, NULL, NoHandle);
if (MovingPixelsState* movingPixels = dynamic_cast<MovingPixelsState*>(editor->getState().get()))
movingPixels->flip(flipType);
}
void StandbyState::transformSelection(Editor* editor, MouseMessage* msg, HandleType handle)
{
Doc* document = editor->document();

View File

@ -12,6 +12,7 @@
#include "app/ui/editor/editor_decorator.h"
#include "app/ui/editor/handle_type.h"
#include "app/ui/editor/state_with_wheel_behavior.h"
#include "doc/algorithm/flip_type.h"
#include "obs/connection.h"
namespace app {
@ -48,6 +49,8 @@ namespace app {
void startSelectionTransformation(Editor* editor, const gfx::Point& move, double angle);
void startFlipTransformation(Editor* editor, doc::algorithm::FlipType flipType);
protected:
void callEyedropper(Editor* editor, const ui::MouseMessage* msg);
bool checkStartDrawingStraightLine(Editor* editor, const ui::MouseMessage* msg);