mirror of
https://github.com/aseprite/aseprite.git
synced 2024-07-19 03:17:28 +00:00
Add different selection modes to SelectTile command
Now we can add a tile using Shift+double click or substract one with Shift+Alt+double click.
This commit is contained in:
parent
e62f80842c
commit
417e431a32
|
@ -393,12 +393,18 @@
|
|||
<key command="SavePalette" />
|
||||
<key command="ColorQuantization" />
|
||||
<key command="AddColor">
|
||||
<param name="source" value="fg" />
|
||||
<param name="source" value="fg" />
|
||||
</key>
|
||||
<key command="AddColor">
|
||||
<param name="source" value="bg" />
|
||||
</key>
|
||||
<key command="SelectTile" />
|
||||
<key command="SelectTile">
|
||||
<param name="mode" value="add" />
|
||||
</key>
|
||||
<key command="SelectTile">
|
||||
<param name="mode" value="subtract" />
|
||||
</key>
|
||||
</commands>
|
||||
|
||||
<!-- Keyboard shortcuts to select tools -->
|
||||
|
|
|
@ -32,20 +32,37 @@ public:
|
|||
Command* clone() const override { return new SelectTileCommand(*this); }
|
||||
|
||||
protected:
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* ctx) override;
|
||||
void onExecute(Context* ctx) override;
|
||||
std::string onGetFriendlyName() const override;
|
||||
|
||||
private:
|
||||
tools::SelectionMode m_mode;
|
||||
};
|
||||
|
||||
SelectTileCommand::SelectTileCommand()
|
||||
: Command("SelectTile",
|
||||
"Select Tile",
|
||||
CmdRecordableFlag)
|
||||
, m_mode(tools::SelectionMode::DEFAULT)
|
||||
{
|
||||
}
|
||||
|
||||
bool SelectTileCommand::onEnabled(Context* context)
|
||||
void SelectTileCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable);
|
||||
std::string mode = params.get("mode");
|
||||
if (mode == "add")
|
||||
m_mode = tools::SelectionMode::ADD;
|
||||
else if (mode == "subtract")
|
||||
m_mode = tools::SelectionMode::SUBTRACT;
|
||||
else
|
||||
m_mode = tools::SelectionMode::DEFAULT;
|
||||
}
|
||||
|
||||
bool SelectTileCommand::onEnabled(Context* ctx)
|
||||
{
|
||||
return ctx->checkFlags(ContextFlags::ActiveDocumentIsWritable);
|
||||
}
|
||||
|
||||
void SelectTileCommand::onExecute(Context* ctx)
|
||||
|
@ -60,12 +77,20 @@ void SelectTileCommand::onExecute(Context* ctx)
|
|||
auto& docPref = Preferences::instance().document(doc);
|
||||
|
||||
base::UniquePtr<Mask> mask(new Mask());
|
||||
|
||||
if (m_mode != tools::SelectionMode::DEFAULT)
|
||||
mask->copyFrom(doc->mask());
|
||||
|
||||
{
|
||||
const gfx::Rect gridBounds = docPref.grid.bounds();
|
||||
gfx::Rect gridBounds = docPref.grid.bounds();
|
||||
gfx::Point pos = current_editor->screenToEditor(ui::get_mouse_position());
|
||||
pos = snap_to_grid(gridBounds, pos, PreferSnapTo::BoxOrigin);
|
||||
gridBounds.setOrigin(pos);
|
||||
|
||||
mask->add(gfx::Rect(pos, gridBounds.size()));
|
||||
if (m_mode != tools::SelectionMode::SUBTRACT)
|
||||
mask->add(gridBounds);
|
||||
else
|
||||
mask->subtract(gridBounds);
|
||||
}
|
||||
|
||||
// Set the new mask
|
||||
|
@ -79,6 +104,18 @@ void SelectTileCommand::onExecute(Context* ctx)
|
|||
update_screen_for_document(doc);
|
||||
}
|
||||
|
||||
std::string SelectTileCommand::onGetFriendlyName() const
|
||||
{
|
||||
std::string text = "Select Tile";
|
||||
|
||||
switch (m_mode) {
|
||||
case tools::SelectionMode::ADD: text += " (Add)"; break;
|
||||
case tools::SelectionMode::SUBTRACT: text += " (Subtract)"; break;
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
Command* CommandFactory::createSelectTileCommand()
|
||||
{
|
||||
return new SelectTileCommand;
|
||||
|
|
|
@ -349,7 +349,17 @@ bool StandbyState::onDoubleClick(Editor* editor, MouseMessage* msg)
|
|||
Command* selectTileCmd =
|
||||
CommandsModule::instance()->getCommandByName(CommandId::SelectTile);
|
||||
|
||||
UIContext::instance()->executeCommand(selectTileCmd);
|
||||
Params params;
|
||||
switch (editor->getSelectionMode()) {
|
||||
case tools::SelectionMode::ADD:
|
||||
params.set("mode", "add");
|
||||
break;
|
||||
case tools::SelectionMode::SUBTRACT:
|
||||
params.set("mode", "subtract");
|
||||
break;
|
||||
}
|
||||
|
||||
UIContext::instance()->executeCommand(selectTileCmd, params);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user