mirror of
https://github.com/aseprite/aseprite.git
synced 2024-09-02 04:59:24 +00:00
Add Shift/Alt modifiers to selection tools to change Union/Subtract modes (fix #217)
This commit is contained in:
parent
6c571adbd4
commit
522e9a0337
@ -262,6 +262,10 @@
|
||||
<!-- When you scale the selection, pressing this
|
||||
keyboard shortcut you maintain aspect ratio -->
|
||||
<key action="MaintainAspectRatio" shortcut="Shift" />
|
||||
|
||||
<!-- Modifiers for selection tool -->
|
||||
<key action="AddSelection" shortcut="Shift" />
|
||||
<key action="SubtractSelection" shortcut="Alt" />
|
||||
</spriteeditor>
|
||||
|
||||
</keyboard>
|
||||
|
@ -71,6 +71,8 @@
|
||||
#define SPRITEDITOR_ACTION_ANGLESNAP "AngleSnap"
|
||||
#define SPRITEDITOR_ACTION_MAINTAINASPECTRATIO "MaintainAspectRatio"
|
||||
#define SPRITEDITOR_ACTION_LOCKAXIS "LockAxis"
|
||||
#define SPRITEDITOR_ACTION_ADDSEL "AddSelection"
|
||||
#define SPRITEDITOR_ACTION_SUBSEL "SubtractSelection"
|
||||
|
||||
namespace app {
|
||||
|
||||
@ -595,6 +597,24 @@ Accelerator* get_accel_to_lock_axis()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Accelerator* get_accel_to_add_selection()
|
||||
{
|
||||
Shortcut* shortcut = get_keyboard_shortcut_for_spriteeditor(SPRITEDITOR_ACTION_ADDSEL);
|
||||
if (shortcut)
|
||||
return shortcut->accel;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Accelerator* get_accel_to_subtract_selection()
|
||||
{
|
||||
Shortcut* shortcut = get_keyboard_shortcut_for_spriteeditor(SPRITEDITOR_ACTION_SUBSEL);
|
||||
if (shortcut)
|
||||
return shortcut->accel;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tools::Tool* get_selected_quicktool(tools::Tool* currentTool)
|
||||
{
|
||||
if (currentTool && currentTool->getInk(0)->isSelection()) {
|
||||
|
@ -88,6 +88,8 @@ namespace app {
|
||||
ui::Accelerator* get_accel_to_angle_snap();
|
||||
ui::Accelerator* get_accel_to_maintain_aspect_ratio();
|
||||
ui::Accelerator* get_accel_to_lock_axis();
|
||||
ui::Accelerator* get_accel_to_add_selection();
|
||||
ui::Accelerator* get_accel_to_subtract_selection();
|
||||
|
||||
tools::Tool* get_selected_quicktool(tools::Tool* currentTool);
|
||||
|
||||
|
@ -668,8 +668,13 @@ public:
|
||||
|
||||
void setupTooltips(TooltipManager* tooltipManager) {
|
||||
tooltipManager->addTooltipFor(getButtonAt(0), "Replace selection", JI_BOTTOM);
|
||||
tooltipManager->addTooltipFor(getButtonAt(1), "Add to selection", JI_BOTTOM);
|
||||
tooltipManager->addTooltipFor(getButtonAt(2), "Subtract from selection", JI_BOTTOM);
|
||||
tooltipManager->addTooltipFor(getButtonAt(1), "Add to selection (Shift key)", JI_BOTTOM);
|
||||
tooltipManager->addTooltipFor(getButtonAt(2), "Subtract from selection (Alt key)", JI_BOTTOM);
|
||||
}
|
||||
|
||||
void setSelectionMode(SelectionMode mode) {
|
||||
setSelectedItem((int)mode);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -948,4 +953,12 @@ void ContextBar::updateForMovingPixels()
|
||||
layout();
|
||||
}
|
||||
|
||||
void ContextBar::updateForSelectionMode(SelectionMode mode)
|
||||
{
|
||||
if (!m_selectionMode->isVisible())
|
||||
return;
|
||||
|
||||
m_selectionMode->setSelectionMode(mode);
|
||||
}
|
||||
|
||||
} // namespace app
|
||||
|
@ -47,6 +47,7 @@ namespace app {
|
||||
|
||||
void updateFromTool(tools::Tool* tool);
|
||||
void updateForMovingPixels();
|
||||
void updateForSelectionMode(SelectionMode mode);
|
||||
|
||||
protected:
|
||||
bool onProcessMessage(ui::Message* msg) override;
|
||||
|
@ -127,6 +127,23 @@ public:
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isAddSelectionPressed() override {
|
||||
Accelerator* accel = get_accel_to_add_selection();
|
||||
if (accel)
|
||||
return accel->checkFromAllegroKeyArray();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isSubtractSelectionPressed() override {
|
||||
Accelerator* accel = get_accel_to_subtract_selection();
|
||||
if (accel)
|
||||
return accel->checkFromAllegroKeyArray();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
DocumentView::DocumentView(Document* document, Type type)
|
||||
|
@ -140,6 +140,7 @@ Editor::Editor(Document* document, EditorFlags flags)
|
||||
, m_frame(FrameNumber(0))
|
||||
, m_zoom(0)
|
||||
, m_mask_timer(100, this)
|
||||
, m_selectionMode(kDefaultSelectionMode)
|
||||
, m_customizationDelegate(NULL)
|
||||
, m_docView(NULL)
|
||||
, m_flags(flags)
|
||||
@ -983,13 +984,21 @@ void Editor::updateStatusBar()
|
||||
m_state->onUpdateStatusBar(this);
|
||||
}
|
||||
|
||||
void Editor::editor_update_quicktool()
|
||||
void Editor::updateQuicktool()
|
||||
{
|
||||
if (m_customizationDelegate) {
|
||||
UIContext* context = UIContext::instance();
|
||||
tools::Tool* current_tool = context->settings()->getCurrentTool();
|
||||
tools::Tool* old_quicktool = m_quicktool;
|
||||
|
||||
// Don't change quicktools if we are in a selection tool and using
|
||||
// the selection modifiers.
|
||||
if (current_tool->getInk(0)->isSelection()) {
|
||||
if (m_customizationDelegate->isAddSelectionPressed() ||
|
||||
m_customizationDelegate->isSubtractSelectionPressed())
|
||||
return;
|
||||
}
|
||||
|
||||
tools::Tool* old_quicktool = m_quicktool;
|
||||
m_quicktool = m_customizationDelegate->getQuickTool(current_tool);
|
||||
|
||||
// If the tool has changed, we must to update the status bar because
|
||||
@ -1003,6 +1012,25 @@ void Editor::editor_update_quicktool()
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::updateSelectionMode()
|
||||
{
|
||||
SelectionMode mode = UIContext::instance()->settings()->selection()->getSelectionMode();
|
||||
|
||||
if (m_customizationDelegate && m_customizationDelegate->isAddSelectionPressed())
|
||||
mode = kAddSelectionMode;
|
||||
else if (m_customizationDelegate && m_customizationDelegate->isSubtractSelectionPressed())
|
||||
mode = kSubtractSelectionMode;
|
||||
else if (m_secondaryButton)
|
||||
mode = kSubtractSelectionMode;
|
||||
|
||||
if (mode != m_selectionMode) {
|
||||
m_selectionMode = mode;
|
||||
|
||||
App::instance()->getMainWindow()->getContextBar()
|
||||
->updateForSelectionMode(mode);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Message handler for the editor
|
||||
|
||||
@ -1028,7 +1056,8 @@ bool Editor::onProcessMessage(Message* msg)
|
||||
break;
|
||||
|
||||
case kMouseEnterMessage:
|
||||
editor_update_quicktool();
|
||||
updateQuicktool();
|
||||
updateSelectionMode();
|
||||
break;
|
||||
|
||||
case kMouseLeaveMessage:
|
||||
@ -1044,7 +1073,8 @@ bool Editor::onProcessMessage(Message* msg)
|
||||
if (!m_secondaryButton && mouseMsg->right()) {
|
||||
m_secondaryButton = mouseMsg->right();
|
||||
|
||||
editor_update_quicktool();
|
||||
updateQuicktool();
|
||||
updateSelectionMode();
|
||||
editor_setcursor();
|
||||
}
|
||||
|
||||
@ -1068,7 +1098,8 @@ bool Editor::onProcessMessage(Message* msg)
|
||||
if (!hasCapture() && m_secondaryButton) {
|
||||
m_secondaryButton = false;
|
||||
|
||||
editor_update_quicktool();
|
||||
updateQuicktool();
|
||||
updateSelectionMode();
|
||||
editor_setcursor();
|
||||
}
|
||||
|
||||
@ -1083,7 +1114,8 @@ bool Editor::onProcessMessage(Message* msg)
|
||||
bool used = m_state->onKeyDown(this, static_cast<KeyMessage*>(msg));
|
||||
|
||||
if (hasMouse()) {
|
||||
editor_update_quicktool();
|
||||
updateQuicktool();
|
||||
updateSelectionMode();
|
||||
editor_setcursor();
|
||||
}
|
||||
|
||||
@ -1098,7 +1130,8 @@ bool Editor::onProcessMessage(Message* msg)
|
||||
bool used = m_state->onKeyUp(this, static_cast<KeyMessage*>(msg));
|
||||
|
||||
if (hasMouse()) {
|
||||
editor_update_quicktool();
|
||||
updateQuicktool();
|
||||
updateSelectionMode();
|
||||
editor_setcursor();
|
||||
}
|
||||
|
||||
@ -1234,7 +1267,7 @@ bool Editor::isInsideSelection()
|
||||
int x, y;
|
||||
screenToEditor(jmouse_x(0), jmouse_y(0), &x, &y);
|
||||
return
|
||||
(UIContext::instance()->settings()->selection()->getSelectionMode() != kSubtractSelectionMode) &&
|
||||
(m_selectionMode != kSubtractSelectionMode) &&
|
||||
m_document != NULL &&
|
||||
m_document->isMaskVisible() &&
|
||||
m_document->mask()->containsPoint(x, y);
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "app/color.h"
|
||||
#include "app/document.h"
|
||||
#include "app/settings/selection_mode.h"
|
||||
#include "app/settings/settings_observers.h"
|
||||
#include "app/ui/editor/editor_observers.h"
|
||||
#include "app/ui/editor/editor_state.h"
|
||||
@ -170,6 +171,8 @@ namespace app {
|
||||
tools::Tool* getCurrentEditorTool();
|
||||
tools::Ink* getCurrentEditorInk();
|
||||
|
||||
SelectionMode getSelectionMode() const { return m_selectionMode; }
|
||||
|
||||
bool isSecondaryButton() const { return m_secondaryButton; }
|
||||
|
||||
// Returns true if we are able to draw in the current doc/sprite/layer/cel.
|
||||
@ -210,7 +213,8 @@ namespace app {
|
||||
|
||||
private:
|
||||
void setStateInternal(const EditorStatePtr& newState);
|
||||
void editor_update_quicktool();
|
||||
void updateQuicktool();
|
||||
void updateSelectionMode();
|
||||
void drawBrushPreview(int x, int y, bool refresh = true);
|
||||
void moveBrushPreview(int x, int y, bool refresh = true);
|
||||
void clearBrushPreview(bool refresh = true);
|
||||
@ -262,6 +266,8 @@ namespace app {
|
||||
// the user is not pressing any keyboard key).
|
||||
tools::Tool* m_quicktool;
|
||||
|
||||
SelectionMode m_selectionMode;
|
||||
|
||||
// Offset for the sprite
|
||||
int m_offset_x;
|
||||
int m_offset_y;
|
||||
|
@ -56,6 +56,10 @@ namespace app {
|
||||
// Returns true if the user wants to lock the X or Y axis when he is
|
||||
// dragging the selection.
|
||||
virtual bool isLockAxisKeyPressed() = 0;
|
||||
|
||||
virtual bool isAddSelectionPressed() = 0;
|
||||
|
||||
virtual bool isSubtractSelectionPressed() = 0;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
@ -81,7 +81,6 @@ class ToolLoopImpl : public tools::ToolLoop,
|
||||
tools::Ink* m_ink;
|
||||
int m_primary_color;
|
||||
int m_secondary_color;
|
||||
SelectionMode m_selectionMode;
|
||||
UndoTransaction m_undoTransaction;
|
||||
ExpandCelCanvas m_expandCelCanvas;
|
||||
gfx::Region m_dirtyArea;
|
||||
@ -112,7 +111,6 @@ public:
|
||||
, m_ink(ink)
|
||||
, m_primary_color(color_utils::color_for_layer(primary_color, m_layer))
|
||||
, m_secondary_color(color_utils::color_for_layer(secondary_color, m_layer))
|
||||
, m_selectionMode(m_settings->selection()->getSelectionMode())
|
||||
, m_undoTransaction(m_context,
|
||||
m_tool->getText().c_str(),
|
||||
((getInk()->isSelection() ||
|
||||
@ -137,10 +135,6 @@ public:
|
||||
break;
|
||||
}
|
||||
|
||||
// Right-click subtract selection always.
|
||||
if (m_button == 1)
|
||||
m_selectionMode = kSubtractSelectionMode;
|
||||
|
||||
m_previewFilled = m_toolSettings->getPreviewFilled();
|
||||
|
||||
m_sprayWidth = m_toolSettings->getSprayWidth();
|
||||
@ -160,7 +154,7 @@ public:
|
||||
// Selection ink
|
||||
if (getInk()->isSelection() &&
|
||||
(!m_document->isMaskVisible() ||
|
||||
m_selectionMode == kDefaultSelectionMode)) {
|
||||
getSelectionMode() == kDefaultSelectionMode)) {
|
||||
Mask emptyMask;
|
||||
m_document->setMask(&emptyMask);
|
||||
}
|
||||
@ -227,7 +221,7 @@ public:
|
||||
int getOpacity() override { return m_opacity; }
|
||||
int getTolerance() override { return m_tolerance; }
|
||||
bool getContiguous() override { return m_contiguous; }
|
||||
SelectionMode getSelectionMode() override { return m_selectionMode; }
|
||||
SelectionMode getSelectionMode() override { return m_editor->getSelectionMode(); }
|
||||
ISettings* settings() override { return m_settings; }
|
||||
IDocumentSettings* getDocumentSettings() override { return m_docSettings; }
|
||||
bool getFilled() override { return m_filled; }
|
||||
|
Loading…
Reference in New Issue
Block a user