/*
10 * 2020 Martin Owens <doctormo@geek-2.com>
12 * Copyright (C) 2018 Authors
13 * Released under GNU GPL v2+, read the file
'COPYING' for more information.
19#include <glibmm/i18n.h>
27using ModifierIdToTypeMap = std::map<std::string, Type>;
28ModifierIdToTypeMap
const &modifier_type_from_id()
30 static ModifierIdToTypeMap
const static_id_to_type_map {
55 return static_id_to_type_map;
58inline std::pair<Modifiers::Type, Modifier> make_modifier(
char const *
id,
65 return {modifier_type_from_id().at(
id),
Modifier(
id,
name, desc, and_mask, category, trigger)};
68std::map<int, int>
const &key_map()
70 static const std::map<int, int> static_key_map = {
71 {GDK_KEY_Alt_L, GDK_ALT_MASK},
72 {GDK_KEY_Alt_R, GDK_ALT_MASK},
73 {GDK_KEY_Control_L, GDK_CONTROL_MASK},
74 {GDK_KEY_Control_R, GDK_CONTROL_MASK},
75 {GDK_KEY_Shift_L, GDK_SHIFT_MASK},
76 {GDK_KEY_Shift_R, GDK_SHIFT_MASK},
77 {GDK_KEY_Meta_L, GDK_META_MASK},
78 {GDK_KEY_Meta_R, GDK_META_MASK},
80 return static_key_map;
89 make_modifier(
"canvas-pan-y", _(
"Vertical pan"), _(
"Pan/Scroll up and down"),
ALWAYS,
CANVAS,
SCROLL),
90 make_modifier(
"canvas-pan-x", _(
"Horizontal pan"), _(
"Pan/Scroll left and right"),
SHIFT,
CANVAS,
SCROLL),
91 make_modifier(
"canvas-zoom", _(
"Canvas zoom"), _(
"Zoom in and out with scroll wheel"),
CTRL,
CANVAS,
SCROLL),
92 make_modifier(
"canvas-rotate", _(
"Canvas rotate"), _(
"Rotate the canvas with scroll wheel"),
SHIFT |
CTRL,
CANVAS,
SCROLL),
95 make_modifier(
"select-add-to", _(
"Add to selection"), _(
"Add items to existing selection"),
SHIFT,
SELECT,
CLICK),
96 make_modifier(
"select-in-groups", _(
"Select inside groups"), _(
"Ignore groups when selecting items"),
CTRL,
SELECT,
CLICK),
97 make_modifier(
"select-touch-path", _(
"Select with touch-path"), _(
"Draw a band around items to select them"),
ALT,
SELECT,
DRAG),
98 make_modifier(
"select-always-box", _(
"Select with box"), _(
"Don't drag items, select more with a box"),
SHIFT,
SELECT,
DRAG),
99 make_modifier(
"select-remove-from", _(
"Remove from selection"), _(
"Remove items from existing selection"),
CTRL,
SELECT,
DRAG),
100 make_modifier(
"select-force-drag", _(
"Forced Drag"), _(
"Drag objects even if the mouse isn't over them"),
ALT,
SELECT,
DRAG),
101 make_modifier(
"select-cycle", _(
"Cycle through objects"), _(
"Scroll through objects under the cursor"),
ALT,
SELECT,
SCROLL),
104 make_modifier(
"move-confine", _(
"Move one axis only"), _(
"When dragging items, confine to either x or y axis"),
CTRL,
MOVE,
DRAG),
105 make_modifier(
"move-increment", _(
"Move in increments"), _(
"Move the objects by set increments when dragging"),
ALT,
MOVE,
DRAG),
106 make_modifier(
"move-snapping", _(
"No Move Snapping"), _(
"Disable snapping when moving objects"),
SHIFT,
MOVE,
DRAG),
107 make_modifier(
"trans-confine", _(
"Keep aspect ratio"), _(
"When resizing objects, confine the aspect ratio"),
CTRL,
TRANSFORM,
DRAG),
108 make_modifier(
"trans-increment", _(
"Transform in increments"), _(
"Scale, rotate or skew by set increments"),
ALT,
TRANSFORM,
DRAG),
109 make_modifier(
"trans-off-center", _(
"Transform around center"), _(
"When scaling, scale selection symmetrically around its rotation center. When rotating/skewing, transform relative to opposite corner/edge."),
SHIFT,
TRANSFORM,
DRAG),
110 make_modifier(
"trans-snapping", _(
"No Transform Snapping"), _(
"Disable snapping when transforming object."),
SHIFT,
TRANSFORM,
DRAG),
113 make_modifier(
"bool-shift", _(
"Switch mode"), _(
"Change shape builder mode temporarily by holding a modifier key."),
SHIFT,
BOOLEANS_TOOL,
DRAG),
115 make_modifier(
"node-grow-linear", _(
"Linear node selection"), _(
"Select the next nodes with scroll wheel or keyboard"),
CTRL,
NODE_TOOL,
SCROLL),
116 make_modifier(
"node-invert", _(
"Inverted node selection"), _(
"Select nodes outside the selection area"),
CTRL,
NODE_TOOL,
DRAG),
117 make_modifier(
"node-remove-from", _(
"Remove nodes from selection"), _(
"Remove selected nodes from the selection"),
SHIFT |
CTRL,
NODE_TOOL,
DRAG),
118 make_modifier(
"node-grow-spatial", _(
"Spatial node selection"), _(
"Select more nodes with scroll wheel or keyboard"),
ALWAYS,
NODE_TOOL,
SCROLL),
120 return static_modifiers;
129 {
MOVE, _(
"Movement")},
134 return static_category_names;
147 std::map<Type, unsigned long> scales;
149 if (val.get_trigger() == trigger && val.active(button_state)) {
154 using pair_type =
decltype(scales)::value_type;
155 auto sorted = std::max_element
157 std::begin(scales), std::end(scales),
158 [] (
const pair_type & p1,
const pair_type & p2) {
159 return p1.second < p2.second;
162 return sorted->first;
172 std::vector<Modifier const *> modifiers;
175 modifiers.push_back(&val);
183 auto const type_it = modifier_type_from_id().find(
id);
184 if (type_it == modifier_type_from_id().
end()) {
187 auto const modifier_it =
_modifiers().find(type_it->second);
191 return &(modifier_it->second);
235 auto ret = std::string();
240 ret.append(_(
"[NEVER]"));
243 if(mask &
CTRL) ret.append(_(
"Ctrl"));
245 if(!ret.empty()) ret.append(sep);
246 ret.append(_(
"Shift"));
249 if(!ret.empty()) ret.append(sep);
250 ret.append(_(
"Alt"));
253 if(!ret.empty()) ret.append(sep);
254 ret.append(_(
"Super"));
257 if(!ret.empty()) ret.append(sep);
258 ret.append(_(
"Hyper"));
261 if(!ret.empty()) ret.append(sep);
262 ret.append(_(
"Meta"));
278 std::bitset<
sizeof(mask)> bit_mask(mask);
279 return bit_mask.count();
292 std::string ctrl_msg =
"<b>Ctrl</b>: ";
293 std::string shift_msg =
"<b>Shift</b>: ";
294 std::string alt_msg =
"<b>Alt</b>: ";
299 for(
int i = 0; i < num_args; i++) {
301 auto name = std::string(_(modifier->get_name()));
302 switch (modifier->get_and_mask()) {
304 ctrl_msg +=
name +
", ";
307 shift_msg +=
name +
", ";
310 alt_msg +=
name +
", ";
313 g_warning(
"Unhandled responsivle tooltip: %s",
name.c_str());
317 ctrl_msg.erase(ctrl_msg.size() - 2);
318 shift_msg.erase(shift_msg.size() - 2);
319 alt_msg.erase(alt_msg.size() - 2);
322 ctrl_msg.c_str(), shift_msg.c_str(), alt_msg.c_str());
337 if (
auto it = key_map().find(keyval); it != key_map().end()) {
339 state &= ~it->second;
A convenience class for working with MessageStacks.
A class to represent ways functionality is driven by shift modifiers.
unsigned long get_weight() const
static CategoryNames const & _category_names()
bool active(int button_state) const
Test if this modifier is currently active.
KeyMask get_not_mask() const
static Type which(Trigger trigger, int button_state)
Given a Trigger, find which modifier is active (category lookup)
static Container & _modifiers()
A table of all the created modifiers and their ID lookups.
std::map< Trigger, std::string > CategoryNames
KeyMask get_and_mask() const
static Modifier * get(Type index)
A function to turn an enum index into a modifier object.
std::map< Type, Modifier > Container
An easy to use definition of the table of modifiers by Type and ID.
static std::vector< Modifier const * > getList()
List all the modifiers available.
Type
This anonymous enum is used to provide a list of the Shifts.
int add_keyval(int state, int keyval, bool release)
Add or remove the GDK keyval to the button state if it's one of the keys that define the key mask.
unsigned long calculate_weight(KeyMask mask)
Calculate the weight of this mask based on how many bits are set.
void responsive_tooltip(MessageContext *message_context, KeyEvent const &event, int num_args,...)
Set the responsive tooltip for this tool, given the selected types.
std::string generate_label(KeyMask mask, std::string sep)
Generate a label for any modifier keys based on the mask.
static cairo_user_data_key_t key
int const char va_start(args, fmt)