mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +00:00
Convert ink menu into a popup menu specified in gui.xml
This commit is contained in:
parent
aaf49be654
commit
e8dd1526f6
21
data/gui.xml
21
data/gui.xml
@ -373,6 +373,7 @@
|
||||
<key command="SetInkType"><param name="type" value="copy-color" /></key>
|
||||
<key command="SetInkType"><param name="type" value="lock-alpha" /></key>
|
||||
<key command="SetInkType"><param name="type" value="shading" /></key>
|
||||
<key command="SetSameInk" />
|
||||
</commands>
|
||||
|
||||
<!-- Keyboard shortcuts to select tools -->
|
||||
@ -846,6 +847,26 @@
|
||||
<item command="ColorQuantization" text="Create Palette from Current Sprite" />
|
||||
</menu>
|
||||
|
||||
<menu id="ink_popup">
|
||||
<item command="SetInkType" text="Simple Ink">
|
||||
<param name="type" value="simple" />
|
||||
</item>
|
||||
<item command="SetInkType" text="Alpha Compositing">
|
||||
<param name="type" value="alpha-compositing" />
|
||||
</item>
|
||||
<item command="SetInkType" text="Copy Alpha+Color">
|
||||
<param name="type" value="copy-color" />
|
||||
</item>
|
||||
<item command="SetInkType" text="Lock Alpha">
|
||||
<param name="type" value="lock-alpha" />
|
||||
</item>
|
||||
<item command="SetInkType" text="Shading">
|
||||
<param name="type" value="shading" />
|
||||
</item>
|
||||
<separator />
|
||||
<item command="SetSameInk" text="Same in all Tools" />
|
||||
</menu>
|
||||
|
||||
</menus>
|
||||
|
||||
<!-- tools -->
|
||||
|
@ -247,6 +247,7 @@ add_library(app-lib
|
||||
commands/cmd_set_loop_section.cpp
|
||||
commands/cmd_set_palette.cpp
|
||||
commands/cmd_set_palette_entry_size.cpp
|
||||
commands/cmd_set_same_ink.cpp
|
||||
commands/cmd_sprite_properties.cpp
|
||||
commands/cmd_sprite_size.cpp
|
||||
commands/cmd_switch_colors.cpp
|
||||
|
@ -89,6 +89,7 @@ void AppMenus::reload()
|
||||
m_celMovementPopupMenu.reset(loadMenuById(handle, "cel_movement_popup"));
|
||||
m_frameTagPopupMenu.reset(loadMenuById(handle, "frame_tag_popup"));
|
||||
m_palettePopupMenu.reset(loadMenuById(handle, "palette_popup"));
|
||||
m_inkPopupMenu.reset(loadMenuById(handle, "ink_popup"));
|
||||
|
||||
////////////////////////////////////////
|
||||
// Load keyboard shortcuts for commands
|
||||
|
@ -47,6 +47,7 @@ namespace app {
|
||||
Menu* getCelMovementPopupMenu() { return m_celMovementPopupMenu; }
|
||||
Menu* getFrameTagPopupMenu() { return m_frameTagPopupMenu; }
|
||||
Menu* getPalettePopupMenu() { return m_palettePopupMenu; }
|
||||
Menu* getInkPopupMenu() { return m_inkPopupMenu; }
|
||||
|
||||
void applyShortcutToMenuitemsWithCommand(Command* command, const Params& params, Key* key);
|
||||
|
||||
@ -67,6 +68,7 @@ namespace app {
|
||||
base::UniquePtr<Menu> m_celMovementPopupMenu;
|
||||
base::UniquePtr<Menu> m_frameTagPopupMenu;
|
||||
base::UniquePtr<Menu> m_palettePopupMenu;
|
||||
base::UniquePtr<Menu> m_inkPopupMenu;
|
||||
ScopedConnection m_recentFilesConn;
|
||||
};
|
||||
|
||||
|
@ -26,6 +26,7 @@ public:
|
||||
|
||||
protected:
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onChecked(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
std::string onGetFriendlyName() const override;
|
||||
|
||||
@ -58,6 +59,12 @@ void SetInkTypeCommand::onLoadParams(const Params& params)
|
||||
m_type = tools::InkType::DEFAULT;
|
||||
}
|
||||
|
||||
bool SetInkTypeCommand::onChecked(Context* context)
|
||||
{
|
||||
tools::Tool* tool = App::instance()->activeTool();
|
||||
return (Preferences::instance().tool(tool).ink() == m_type);
|
||||
}
|
||||
|
||||
void SetInkTypeCommand::onExecute(Context* context)
|
||||
{
|
||||
App::instance()
|
||||
|
69
src/app/commands/cmd_set_same_ink.cpp
Normal file
69
src/app/commands/cmd_set_same_ink.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/commands/command.h"
|
||||
#include "app/commands/commands.h"
|
||||
#include "app/commands/params.h"
|
||||
#include "app/pref/preferences.h"
|
||||
#include "app/tools/tool.h"
|
||||
#include "app/tools/tool_box.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
class SetSameInkCommand : public Command {
|
||||
public:
|
||||
SetSameInkCommand();
|
||||
Command* clone() const override { return new SetSameInkCommand(*this); }
|
||||
|
||||
protected:
|
||||
bool onChecked(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
};
|
||||
|
||||
SetSameInkCommand::SetSameInkCommand()
|
||||
: Command("SetSameInk",
|
||||
"Same Ink in All Tools",
|
||||
CmdUIOnlyFlag)
|
||||
{
|
||||
}
|
||||
|
||||
bool SetSameInkCommand::onChecked(Context* context)
|
||||
{
|
||||
return Preferences::instance().shared.shareInk();
|
||||
}
|
||||
|
||||
void SetSameInkCommand::onExecute(Context* context)
|
||||
{
|
||||
Preferences& pref = Preferences::instance();
|
||||
bool newState = !pref.shared.shareInk();
|
||||
pref.shared.shareInk(newState);
|
||||
|
||||
if (newState) {
|
||||
tools::Tool* activeTool = App::instance()->activeTool();
|
||||
tools::InkType inkType = pref.tool(activeTool).ink();
|
||||
int opacity = pref.tool(activeTool).opacity();
|
||||
|
||||
for (tools::Tool* tool : *App::instance()->getToolBox()) {
|
||||
if (tool != activeTool) {
|
||||
pref.tool(tool).ink(inkType);
|
||||
pref.tool(tool).opacity(opacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Command* CommandFactory::createSetSameInkCommand()
|
||||
{
|
||||
return new SetSameInkCommand;
|
||||
}
|
||||
|
||||
} // namespace app
|
@ -109,6 +109,7 @@ FOR_EACH_COMMAND(SetInkType)
|
||||
FOR_EACH_COMMAND(SetLoopSection)
|
||||
FOR_EACH_COMMAND(SetPalette)
|
||||
FOR_EACH_COMMAND(SetPaletteEntrySize)
|
||||
FOR_EACH_COMMAND(SetSameInk)
|
||||
FOR_EACH_COMMAND(ShowGrid)
|
||||
FOR_EACH_COMMAND(ShowOnionSkin)
|
||||
FOR_EACH_COMMAND(ShowPixelGrid)
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "app/ui/context_bar.h"
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/app_menus.h"
|
||||
#include "app/color_utils.h"
|
||||
#include "app/commands/commands.h"
|
||||
#include "app/document.h"
|
||||
@ -376,63 +377,13 @@ protected:
|
||||
|
||||
gfx::Rect bounds = getBounds();
|
||||
|
||||
Menu menu;
|
||||
MenuItem
|
||||
simple(tools::ink_type_to_string(tools::InkType::SIMPLE)),
|
||||
alphacompo(tools::ink_type_to_string(tools::InkType::ALPHA_COMPOSITING)),
|
||||
copycolor(tools::ink_type_to_string(tools::InkType::COPY_COLOR)),
|
||||
lockalpha(tools::ink_type_to_string(tools::InkType::LOCK_ALPHA)),
|
||||
shading(tools::ink_type_to_string(tools::InkType::SHADING)),
|
||||
alltools("Same in all Tools");
|
||||
menu.addChild(&simple);
|
||||
menu.addChild(&alphacompo);
|
||||
menu.addChild(©color);
|
||||
menu.addChild(&lockalpha);
|
||||
menu.addChild(&shading);
|
||||
menu.addChild(new MenuSeparator);
|
||||
menu.addChild(&alltools);
|
||||
|
||||
Tool* tool = App::instance()->activeTool();
|
||||
switch (Preferences::instance().tool(tool).ink()) {
|
||||
case tools::InkType::SIMPLE: simple.setSelected(true); break;
|
||||
case tools::InkType::ALPHA_COMPOSITING: alphacompo.setSelected(true); break;
|
||||
case tools::InkType::COPY_COLOR: copycolor.setSelected(true); break;
|
||||
case tools::InkType::LOCK_ALPHA: lockalpha.setSelected(true); break;
|
||||
case tools::InkType::SHADING: shading.setSelected(true); break;
|
||||
}
|
||||
alltools.setSelected(Preferences::instance().shared.shareInk());
|
||||
|
||||
simple.Click.connect(Bind<void>(&InkTypeField::setInkType, this, InkType::SIMPLE));
|
||||
alphacompo.Click.connect(Bind<void>(&InkTypeField::setInkType, this, InkType::ALPHA_COMPOSITING));
|
||||
copycolor.Click.connect(Bind<void>(&InkTypeField::setInkType, this, InkType::COPY_COLOR));
|
||||
lockalpha.Click.connect(Bind<void>(&InkTypeField::setInkType, this, InkType::LOCK_ALPHA));
|
||||
shading.Click.connect(Bind<void>(&InkTypeField::setInkType, this, InkType::SHADING));
|
||||
alltools.Click.connect(Bind<void>(&InkTypeField::onSameInAllTools, this));
|
||||
|
||||
menu.showPopup(gfx::Point(bounds.x, bounds.y+bounds.h));
|
||||
AppMenus::instance()
|
||||
->getInkPopupMenu()
|
||||
->showPopup(gfx::Point(bounds.x, bounds.y+bounds.h));
|
||||
|
||||
deselectItems();
|
||||
}
|
||||
|
||||
void onSameInAllTools() {
|
||||
Preferences& pref = Preferences::instance();
|
||||
bool newState = !pref.shared.shareInk();
|
||||
pref.shared.shareInk(newState);
|
||||
|
||||
if (newState) {
|
||||
Tool* activeTool = App::instance()->activeTool();
|
||||
InkType inkType = pref.tool(activeTool).ink();
|
||||
int opacity = pref.tool(activeTool).opacity();
|
||||
|
||||
for (Tool* tool : *App::instance()->getToolBox()) {
|
||||
if (tool != activeTool) {
|
||||
pref.tool(tool).ink(inkType);
|
||||
pref.tool(tool).opacity(opacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ContextBar* m_owner;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user