diff options
author | David Robillard <d@drobilla.net> | 2010-03-04 21:15:56 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-03-04 21:15:56 +0000 |
commit | 558083f6c0e9eda930f0a970836ebf2597840f39 (patch) | |
tree | 721dcaecc5bd4be8b115574f3282eb1d8bd56cfd /src/gui | |
parent | ef4179afb8e8c917c2fa355900fd30e24857c7db (diff) | |
download | ingen-558083f6c0e9eda930f0a970836ebf2597840f39.tar.gz ingen-558083f6c0e9eda930f0a970836ebf2597840f39.tar.bz2 ingen-558083f6c0e9eda930f0a970836ebf2597840f39.zip |
Pop up patch context menu on space or menu key press (i.e. ability to add stuff without mouse).
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2520 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/PatchCanvas.cpp | 32 | ||||
-rw-r--r-- | src/gui/PatchCanvas.hpp | 4 |
2 files changed, 32 insertions, 4 deletions
diff --git a/src/gui/PatchCanvas.cpp b/src/gui/PatchCanvas.cpp index 932b0ef9..d61137d6 100644 --- a/src/gui/PatchCanvas.cpp +++ b/src/gui/PatchCanvas.cpp @@ -126,12 +126,15 @@ PatchCanvas::PatchCanvas(SharedPtr<PatchModel> patch, int width, int height) void -PatchCanvas::show_menu(GdkEvent* event) +PatchCanvas::show_menu(bool position, unsigned button, uint32_t time) { if (!_internal_menu) build_menus(); - _menu->popup(event->button.button, event->button.time); + if (position) + _menu->popup(sigc::mem_fun(this, &PatchCanvas::auto_menu_position), button, time); + else + _menu->popup(button, time); } @@ -518,6 +521,25 @@ PatchCanvas::disconnect(boost::shared_ptr<FlowCanvas::Connectable> src_port, } +void +PatchCanvas::auto_menu_position(int& x, int& y, bool& push_in) +{ + int scroll_x, scroll_y; + get_scroll_offsets(scroll_x, scroll_y); + + Gtk::Container* parent = get_parent(); + const int win_width = parent->get_width(); + const int win_height = parent->get_height(); + + x = (win_width / 2.0); + y = (win_height / 2.0); + push_in = true; + + _last_click_x = scroll_x + x; + _last_click_y = scroll_y + y; +} + + bool PatchCanvas::canvas_event(GdkEvent* event) { @@ -530,7 +552,7 @@ PatchCanvas::canvas_event(GdkEvent* event) if (event->button.button == 3) { _last_click_x = (int)event->button.x; _last_click_y = (int)event->button.y; - show_menu(event); + show_menu(false, event->button.button, event->button.time); ret = true; } break; @@ -546,6 +568,10 @@ PatchCanvas::canvas_event(GdkEvent* event) _patch->set_editable(!_patch->get_editable()); ret = true; } + break; + case GDK_space: + case GDK_Menu: + show_menu(true, 3, event->key.time); default: break; } diff --git a/src/gui/PatchCanvas.hpp b/src/gui/PatchCanvas.hpp index a301f680..03018f5a 100644 --- a/src/gui/PatchCanvas.hpp +++ b/src/gui/PatchCanvas.hpp @@ -81,7 +81,7 @@ public: void paste(); void select_all(); - void show_menu(GdkEvent* event); + void show_menu(bool position, unsigned button, uint32_t time); bool canvas_event(GdkEvent* event); @@ -107,6 +107,8 @@ private: void build_internal_menu(); void build_classless_menu(); + void auto_menu_position(int& x, int& y, bool& push_in); + #ifdef HAVE_SLV2 typedef std::multimap<const std::string, SLV2PluginClass> LV2Children; void build_plugin_menu(); |