Add support to call Flip command without UI

This commit is contained in:
David Capello 2020-04-17 12:29:48 -03:00
parent c0d4264789
commit fb68407e04
4 changed files with 31 additions and 18 deletions

View File

@ -222,7 +222,6 @@ if(ENABLE_UI)
commands/cmd_eyedropper.cpp
commands/cmd_fill_and_stroke.cpp
commands/cmd_fit_screen.cpp
commands/cmd_flip.cpp
commands/cmd_frame_properties.cpp
commands/cmd_frame_tag_properties.cpp
commands/cmd_fullscreen_preview.cpp
@ -500,6 +499,7 @@ add_library(app-lib
commands/cmd_crop.cpp
commands/cmd_export_sprite_sheet.cpp
commands/cmd_flatten_layers.cpp
commands/cmd_flip.cpp
commands/cmd_layer_from_background.cpp
commands/cmd_load_palette.cpp
commands/cmd_merge_down_layer.cpp

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -63,23 +63,23 @@ void FlipCommand::onLoadParams(const Params& params)
doc::algorithm::FlipHorizontal);
}
bool FlipCommand::onEnabled(Context* context)
bool FlipCommand::onEnabled(Context* ctx)
{
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable);
return ctx->checkFlags(ContextFlags::ActiveDocumentIsWritable);
}
void FlipCommand::onExecute(Context* context)
void FlipCommand::onExecute(Context* ctx)
{
Site site = context->activeSite();
Timeline* timeline = App::instance()->timeline();
LockTimelineRange lockRange(timeline);
Site site = ctx->activeSite();
LockTimelineRange lockRange(App::instance()->timeline());
CelList cels;
if (m_flipMask) {
// If we want to flip the visible mask we can go to
// MovingPixelsState (even when the range is enabled, because now
// PixelsMovement support ranges).
if (site.document()->isMaskVisible()) {
if (site.document()->isMaskVisible() &&
ctx->isUIAvailable()) {
// Select marquee tool
if (tools::Tool* tool = App::instance()->toolBox()
->getToolById(tools::WellKnownTools::RectangularMarquee)) {
@ -89,7 +89,7 @@ void FlipCommand::onExecute(Context* context)
}
}
auto range = timeline->range();
auto range = site.range();
if (range.enabled()) {
cels = get_unlocked_unique_cels(site.sprite(), range);
}
@ -111,10 +111,10 @@ void FlipCommand::onExecute(Context* context)
cels.push_back(cel);
}
ContextWriter writer(context);
ContextWriter writer(ctx);
Doc* document = writer.document();
Sprite* sprite = writer.sprite();
Tx tx(writer.context(), friendlyName());
Tx tx(ctx, friendlyName());
DocApi api = document->getApi(tx);
Mask* mask = document->mask();
@ -228,7 +228,11 @@ void FlipCommand::onExecute(Context* context)
}
tx.commit();
update_screen_for_document(document);
#ifdef ENABLE_UI
if (ctx->isUIAvailable())
update_screen_for_document(document);
#endif
}
std::string FlipCommand::onGetFriendlyName() const

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -20,6 +20,7 @@ FOR_EACH_COMMAND(CropSprite)
FOR_EACH_COMMAND(Despeckle)
FOR_EACH_COMMAND(ExportSpriteSheet)
FOR_EACH_COMMAND(FlattenLayers)
FOR_EACH_COMMAND(Flip)
FOR_EACH_COMMAND(HueSaturation)
FOR_EACH_COMMAND(InvertColor)
FOR_EACH_COMMAND(LayerFromBackground)
@ -67,7 +68,6 @@ FOR_EACH_COMMAND(Exit)
FOR_EACH_COMMAND(Eyedropper)
FOR_EACH_COMMAND(Fill)
FOR_EACH_COMMAND(FitScreen)
FOR_EACH_COMMAND(Flip)
FOR_EACH_COMMAND(FrameProperties)
FOR_EACH_COMMAND(FrameTagProperties)
FOR_EACH_COMMAND(FullscreenPreview)

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -420,18 +420,27 @@ namespace app {
} m_moveRangeData;
};
#ifdef ENABLE_UI
class LockTimelineRange {
public:
LockTimelineRange(Timeline* timeline)
: m_timeline(timeline) {
m_timeline->lockRange();
if (m_timeline)
m_timeline->lockRange();
}
~LockTimelineRange() {
m_timeline->unlockRange();
if (m_timeline)
m_timeline->unlockRange();
}
private:
Timeline* m_timeline;
};
#else // !ENABLE_UI
class LockTimelineRange {
public:
LockTimelineRange(Timeline* timeline) { }
};
#endif
} // namespace app