mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-22 15:39:52 +00:00
Add command to change the layer opacity
This commit is contained in:
parent
b2281636d6
commit
7a0d6c7f9e
11
data/gui.xml
11
data/gui.xml
@ -223,6 +223,17 @@
|
|||||||
<param name="action" value="in" />
|
<param name="action" value="in" />
|
||||||
</key>
|
</key>
|
||||||
|
|
||||||
|
<!-- Layer opacity -->
|
||||||
|
<key command="LayerOpacity"><param name="opacity" value="0" /></key>
|
||||||
|
<key command="LayerOpacity"><param name="opacity" value="32" /></key>
|
||||||
|
<key command="LayerOpacity" shortcut="Shift+1"><param name="opacity" value="64" /></key>
|
||||||
|
<key command="LayerOpacity"><param name="opacity" value="96" /></key>
|
||||||
|
<key command="LayerOpacity" shortcut="Shift+2"><param name="opacity" value="128" /></key>
|
||||||
|
<key command="LayerOpacity"><param name="opacity" value="160" /></key>
|
||||||
|
<key command="LayerOpacity" shortcut="Shift+3"><param name="opacity" value="192" /></key>
|
||||||
|
<key command="LayerOpacity"><param name="opacity" value="224" /></key>
|
||||||
|
<key command="LayerOpacity" shortcut="Shift+4"><param name="opacity" value="255" /></key>
|
||||||
|
|
||||||
<!-- Scroll to center -->
|
<!-- Scroll to center -->
|
||||||
<key command="ScrollCenter" shortcut="Shift+C" />
|
<key command="ScrollCenter" shortcut="Shift+C" />
|
||||||
<key command="FitScreen" shortcut="Ctrl+0" mac="Cmd+0" />
|
<key command="FitScreen" shortcut="Ctrl+0" mac="Cmd+0" />
|
||||||
|
@ -225,6 +225,7 @@ add_library(app-lib
|
|||||||
commands/cmd_keyboard_shortcuts.cpp
|
commands/cmd_keyboard_shortcuts.cpp
|
||||||
commands/cmd_launch.cpp
|
commands/cmd_launch.cpp
|
||||||
commands/cmd_layer_from_background.cpp
|
commands/cmd_layer_from_background.cpp
|
||||||
|
commands/cmd_layer_opacity.cpp
|
||||||
commands/cmd_layer_properties.cpp
|
commands/cmd_layer_properties.cpp
|
||||||
commands/cmd_layer_visibility.cpp
|
commands/cmd_layer_visibility.cpp
|
||||||
commands/cmd_link_cels.cpp
|
commands/cmd_link_cels.cpp
|
||||||
|
111
src/app/commands/cmd_layer_opacity.cpp
Normal file
111
src/app/commands/cmd_layer_opacity.cpp
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2016 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/app.h"
|
||||||
|
#include "app/cmd/set_layer_opacity.h"
|
||||||
|
#include "app/commands/command.h"
|
||||||
|
#include "app/commands/params.h"
|
||||||
|
#include "app/context.h"
|
||||||
|
#include "app/context_access.h"
|
||||||
|
#include "app/modules/gui.h"
|
||||||
|
#include "app/transaction.h"
|
||||||
|
#include "app/ui/timeline.h"
|
||||||
|
#include "base/convert_to.h"
|
||||||
|
#include "doc/layer.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
|
||||||
|
class LayerOpacityCommand : public Command {
|
||||||
|
public:
|
||||||
|
LayerOpacityCommand();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void onLoadParams(const Params& params) override;
|
||||||
|
bool onEnabled(Context* context) override;
|
||||||
|
void onExecute(Context* context) override;
|
||||||
|
std::string onGetFriendlyName() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_opacity;
|
||||||
|
};
|
||||||
|
|
||||||
|
LayerOpacityCommand::LayerOpacityCommand()
|
||||||
|
: Command("LayerOpacity",
|
||||||
|
"Layer Opacity",
|
||||||
|
CmdUIOnlyFlag)
|
||||||
|
{
|
||||||
|
m_opacity = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LayerOpacityCommand::onLoadParams(const Params& params)
|
||||||
|
{
|
||||||
|
m_opacity = params.get_as<int>("opacity");
|
||||||
|
m_opacity = MID(0, m_opacity, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LayerOpacityCommand::onEnabled(Context* context)
|
||||||
|
{
|
||||||
|
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
||||||
|
ContextFlags::HasActiveLayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LayerOpacityCommand::onExecute(Context* context)
|
||||||
|
{
|
||||||
|
ContextWriter writer(context);
|
||||||
|
Layer* layer = writer.layer();
|
||||||
|
if (!layer ||
|
||||||
|
!layer->isImage() ||
|
||||||
|
static_cast<LayerImage*>(layer)->opacity() == m_opacity)
|
||||||
|
return;
|
||||||
|
|
||||||
|
{
|
||||||
|
Transaction transaction(writer.context(), "Set Layer Opacity");
|
||||||
|
|
||||||
|
// TODO the range of selected frames should be in doc::Site.
|
||||||
|
auto range = App::instance()->timeline()->range();
|
||||||
|
if (range.enabled()) {
|
||||||
|
for (LayerIndex layerIdx = range.layerBegin(); layerIdx <= range.layerEnd(); ++layerIdx) {
|
||||||
|
Layer* layer = writer.sprite()->indexToLayer(layerIdx);
|
||||||
|
if (!layer->isImage())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
transaction.execute(
|
||||||
|
new cmd::SetLayerOpacity(static_cast<LayerImage*>(layer), m_opacity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
transaction.execute(
|
||||||
|
new cmd::SetLayerOpacity(static_cast<LayerImage*>(writer.layer()), m_opacity));
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
update_screen_for_document(writer.document());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string LayerOpacityCommand::onGetFriendlyName() const
|
||||||
|
{
|
||||||
|
std::string text = "Set Layer Opacity to ";
|
||||||
|
text += base::convert_to<std::string>(m_opacity);
|
||||||
|
text += " (";
|
||||||
|
text += base::convert_to<std::string>(int(100.0 * m_opacity / 255.0));
|
||||||
|
text += "%)";
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
Command* CommandFactory::createLayerOpacityCommand()
|
||||||
|
{
|
||||||
|
return new LayerOpacityCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace app
|
@ -61,6 +61,7 @@ FOR_EACH_COMMAND(InvertMask)
|
|||||||
FOR_EACH_COMMAND(KeyboardShortcuts)
|
FOR_EACH_COMMAND(KeyboardShortcuts)
|
||||||
FOR_EACH_COMMAND(Launch)
|
FOR_EACH_COMMAND(Launch)
|
||||||
FOR_EACH_COMMAND(LayerFromBackground)
|
FOR_EACH_COMMAND(LayerFromBackground)
|
||||||
|
FOR_EACH_COMMAND(LayerOpacity)
|
||||||
FOR_EACH_COMMAND(LayerProperties)
|
FOR_EACH_COMMAND(LayerProperties)
|
||||||
FOR_EACH_COMMAND(LayerVisibility)
|
FOR_EACH_COMMAND(LayerVisibility)
|
||||||
FOR_EACH_COMMAND(LinkCels)
|
FOR_EACH_COMMAND(LinkCels)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user