Skip to content

Commit

Permalink
imp: use navigation buttons to switch layers
Browse files Browse the repository at this point in the history
  • Loading branch information
carrotIndustries committed Dec 10, 2020
1 parent 1080253 commit f871566
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/imp/imp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,11 @@ void ImpBase::create_context_menu(Gtk::Menu *parent, const std::set<SelectableRe

bool ImpBase::handle_click(GdkEventButton *button_event)
{
if (button_event->button > 3) {
handle_extra_button(button_event);
return false;
}

if (button_event->button != 2)
set_search_mode(false);

Expand Down
3 changes: 3 additions & 0 deletions src/imp/imp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class ImpBase {
bool handle_key_press(GdkEventKey *key_event);
void handle_cursor_move(const Coordi &pos);
bool handle_click(GdkEventButton *button_event);
virtual void handle_extra_button(const GdkEventButton *button_event)
{
}
bool handle_click_release(GdkEventButton *button_event);
bool handle_context_menu(GdkEventButton *button_event);
void tool_process(ToolResponse &resp);
Expand Down
20 changes: 20 additions & 0 deletions src/imp/imp_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ void ImpLayer::construct_layer_box(bool pack)
}
}

void ImpLayer::handle_extra_button(const GdkEventButton *button_event)
{
if (!preferences.mouse.switch_layers)
return;

switch (button_event->button) {
case 6:
case 8:
trigger_action(ActionID::LAYER_DOWN);
break;

case 7:
case 9:
trigger_action(ActionID::LAYER_UP);
break;

default:;
}
}

void ImpLayer::load_default_layers()
{
layer_box->load_from_json(
Expand Down
2 changes: 2 additions & 0 deletions src/imp/imp_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class ImpLayer : public ImpBase {
return &preferences.canvas_layer;
}

void handle_extra_button(const GdkEventButton *button_event) override;

~ImpLayer()
{
}
Expand Down
11 changes: 11 additions & 0 deletions src/pool-prj-mgr/preferences/preferences_window_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ MiscPreferencesEditor::MiscPreferencesEditor(Preferences &prefs) : preferences(p
gr->add_row(*r);
}
}
{
auto gr = Gtk::manage(new PreferencesGroup("Mouse"));
box->pack_start(*gr, false, false, 0);
gr->show();
{
auto r = Gtk::manage(new PreferencesRowBool("Switch layers with navigation buttons",
"Use back/forward buttons on mouse to move one layer down/up",
preferences, preferences.mouse.switch_layers));
gr->add_row(*r);
}
}
{
auto gr = Gtk::manage(new PreferencesGroup("Action Bar"));
box->pack_start(*gr, false, false, 0);
Expand Down
15 changes: 15 additions & 0 deletions src/preferences/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,18 @@ void ActionBarPreferences::load_from_json(const json &j)
show_in_tool = j.value("show_in_tool", true);
}

json MousePreferences::serialize() const
{
json j;
j["switch_layers"] = switch_layers;
return j;
}

void MousePreferences::load_from_json(const json &j)
{
switch_layers = j.value("switch_layers", true);
}

json Preferences::serialize() const
{
json j;
Expand All @@ -399,6 +411,7 @@ json Preferences::serialize() const
j["capture_output"] = capture_output;
j["partinfo"] = partinfo.serialize();
j["action_bar"] = action_bar.serialize();
j["mouse"] = mouse.serialize();
j["show_pull_request_tools"] = show_pull_request_tools;
return j;
}
Expand Down Expand Up @@ -428,6 +441,8 @@ void Preferences::load_from_json(const json &j)
in_tool_key_sequences.load_from_json(j.at("in_tool_key_sequences"));
if (j.count("action_bar"))
action_bar.load_from_json(j.at("action_bar"));
if (j.count("mouse"))
mouse.load_from_json(j.at("mouse"));
key_sequences.append_from_json(json_from_resource("/org/horizon-eda/horizon/imp/keys_default.json"));
in_tool_key_sequences.append_from_json(
json_from_resource("/org/horizon-eda/horizon/imp/in_tool_keys_default.json"));
Expand Down
9 changes: 9 additions & 0 deletions src/preferences/preferences.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ class ActionBarPreferences {
json serialize() const;
};

class MousePreferences {
public:
bool switch_layers = true;

void load_from_json(const json &j);
json serialize() const;
};

class Preferences {
public:
Preferences();
Expand All @@ -117,6 +125,7 @@ class Preferences {
PartInfoPreferences partinfo;
ActionBarPreferences action_bar;
InToolKeySequencesPreferences in_tool_key_sequences;
MousePreferences mouse;

bool show_pull_request_tools = false;

Expand Down

0 comments on commit f871566

Please sign in to comment.