aseprite/src/app/commands/set_playback_speed.cpp
David Capello 30a88c8e3d Put playback options into Frame > Playback submenu
This menu was accessible right-clicking the Play button in the
Timeline (and in the Preview window, with specific options for the
Preview).

This change includes some changes:

1. Now if a menu <item> in gui.xml doesn't specify a text field, the
   text of the command is used (to avoid double translation, the bad
   side is that we don't have a mnemonic specified).
2. Menu::showPopup() can be used with submenus from the root menu, to
   do this we have to remove the menu item owner temporarily before we
   show the menu as popup (see the change in Menu::showPopup())
3. We can specify a special active DocView for commands with
   UIContext::SetTargetView, this is used to set the Preview editor as
   active view for commands like TogglePlayOnce, etc.
2023-03-21 17:18:05 -03:00

67 lines
1.6 KiB
C++

// Aseprite
// Copyright (c) 2023 Igara Studio S.A.
//
// 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/commands/new_params.h"
#include "app/ui_context.h"
#include "app/ui/editor/editor.h"
#include "fmt/format.h"
namespace app {
struct SetPlaybackSpeedParams : public NewParams {
Param<double> multiplier { this, 1.0, "multiplier" };
};
class SetPlaybackSpeedCommand : public CommandWithNewParams<SetPlaybackSpeedParams> {
public:
SetPlaybackSpeedCommand();
protected:
bool onChecked(Context* ctx) override;
void onExecute(Context* ctx) override;
std::string onGetFriendlyName() const override;
};
SetPlaybackSpeedCommand::SetPlaybackSpeedCommand()
: CommandWithNewParams(CommandId::SetPlaybackSpeed(), CmdUIOnlyFlag)
{
}
bool SetPlaybackSpeedCommand::onChecked(Context* ctx)
{
Editor* editor = nullptr;
if (ctx->isUIAvailable())
editor = static_cast<UIContext*>(ctx)->activeEditor();
if (editor)
return (params().multiplier() == editor->getAnimationSpeedMultiplier());
else
return false;
}
void SetPlaybackSpeedCommand::onExecute(Context* ctx)
{
Editor* editor = nullptr;
if (ctx->isUIAvailable())
editor = static_cast<UIContext*>(ctx)->activeEditor();
if (editor)
editor->setAnimationSpeedMultiplier(params().multiplier());
}
std::string SetPlaybackSpeedCommand::onGetFriendlyName() const
{
return fmt::format(getBaseFriendlyName(), params().multiplier());
}
Command* CommandFactory::createSetPlaybackSpeedCommand()
{
return new SetPlaybackSpeedCommand;
}
} // namespace app