2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2017-05-30 01:20:42 +08:00
|
|
|
// Copyright (C) 2001-2017 David Capello
|
2015-02-12 23:16:25 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/commands/command.h"
|
|
|
|
|
#include "app/commands/params.h"
|
|
|
|
|
#include "app/ui/color_bar.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
|
|
|
|
|
class PaletteEditorCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
|
PaletteEditorCommand();
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new PaletteEditorCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
|
protected:
|
2015-03-12 02:40:22 +08:00
|
|
|
void onLoadParams(const Params& params) override;
|
2015-05-04 13:02:58 +08:00
|
|
|
bool onChecked(Context* context) override;
|
2017-06-23 04:44:34 +08:00
|
|
|
void onExecute(Context* context) override;
|
2017-07-04 04:41:10 +08:00
|
|
|
std::string onGetFriendlyName() const override;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
|
private:
|
2017-07-04 04:41:10 +08:00
|
|
|
bool m_edit;
|
|
|
|
|
bool m_popup;
|
2012-01-06 06:45:03 +08:00
|
|
|
bool m_background;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PaletteEditorCommand::PaletteEditorCommand()
|
|
|
|
|
: Command("PaletteEditor",
|
2017-06-23 04:44:34 +08:00
|
|
|
"Edit Palette",
|
2012-01-06 06:45:03 +08:00
|
|
|
CmdRecordableFlag)
|
|
|
|
|
{
|
2017-07-04 04:41:10 +08:00
|
|
|
m_edit = true;
|
|
|
|
|
m_popup = false;
|
2012-01-06 06:45:03 +08:00
|
|
|
m_background = false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-12 02:40:22 +08:00
|
|
|
void PaletteEditorCommand::onLoadParams(const Params& params)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
2017-07-04 04:41:10 +08:00
|
|
|
m_edit =
|
|
|
|
|
(params.empty() ||
|
|
|
|
|
params.get("edit") == "switch" ||
|
|
|
|
|
params.get("switch") == "true"); // "switch" for backward compatibility
|
|
|
|
|
m_popup = (!params.get("popup").empty());
|
|
|
|
|
m_background = (params.get("popup") == "background");
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
2015-05-04 13:02:58 +08:00
|
|
|
bool PaletteEditorCommand::onChecked(Context* context)
|
|
|
|
|
{
|
2017-06-23 04:44:34 +08:00
|
|
|
return ColorBar::instance()->inEditMode();
|
2015-05-11 09:53:36 +08:00
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2017-06-23 04:44:34 +08:00
|
|
|
void PaletteEditorCommand::onExecute(Context* context)
|
2015-09-14 19:53:31 +08:00
|
|
|
{
|
2017-07-04 04:41:10 +08:00
|
|
|
auto colorBar = ColorBar::instance();
|
|
|
|
|
bool editMode = colorBar->inEditMode();
|
|
|
|
|
ColorButton* button =
|
|
|
|
|
(m_background ?
|
|
|
|
|
colorBar->bgColorButton():
|
|
|
|
|
colorBar->fgColorButton());
|
|
|
|
|
|
|
|
|
|
// Switch edit mode
|
|
|
|
|
if (m_edit && !m_popup) {
|
|
|
|
|
colorBar->setEditMode(!editMode);
|
|
|
|
|
}
|
|
|
|
|
// Switch popup
|
|
|
|
|
else if (!m_edit && m_popup) {
|
|
|
|
|
if (button->isPopupVisible())
|
|
|
|
|
button->closePopup();
|
|
|
|
|
else
|
|
|
|
|
button->openPopup(true);
|
|
|
|
|
}
|
2017-07-05 01:09:50 +08:00
|
|
|
// Switch both (the popup visibility is used to switch both states)
|
2017-07-04 04:41:10 +08:00
|
|
|
else if (m_edit && m_popup) {
|
2017-07-05 01:09:50 +08:00
|
|
|
if (button->isPopupVisible()) {
|
2017-07-04 04:41:10 +08:00
|
|
|
colorBar->setEditMode(false);
|
|
|
|
|
button->closePopup();
|
|
|
|
|
}
|
|
|
|
|
else {
|
2017-07-05 01:09:50 +08:00
|
|
|
colorBar->setEditMode(true);
|
|
|
|
|
button->openPopup(true);
|
2017-07-04 04:41:10 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-11 09:53:36 +08:00
|
|
|
|
2017-07-04 04:41:10 +08:00
|
|
|
std::string PaletteEditorCommand::onGetFriendlyName() const
|
|
|
|
|
{
|
|
|
|
|
std::string text = "Switch";
|
|
|
|
|
if (m_edit) {
|
|
|
|
|
text += " Edit Palette Mode";
|
|
|
|
|
}
|
|
|
|
|
if (m_edit && m_popup) {
|
|
|
|
|
text += " and";
|
|
|
|
|
}
|
|
|
|
|
if (m_popup) {
|
|
|
|
|
if (m_background)
|
|
|
|
|
text += " Background";
|
|
|
|
|
else
|
|
|
|
|
text += " Foreground";
|
|
|
|
|
text += " Color Popup";
|
|
|
|
|
}
|
|
|
|
|
return text;
|
2015-05-11 20:51:10 +08:00
|
|
|
}
|
|
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
Command* CommandFactory::createPaletteEditorCommand()
|
|
|
|
|
{
|
|
|
|
|
return new PaletteEditorCommand;
|
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
|
} // namespace app
|