summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-03-14 22:26:22 -0400
committerDavid Robillard <d@drobilla.net>2016-03-14 22:26:22 -0400
commit7fa32b8bf0223e9c83d4dbff13e93d98dc9b07ca (patch)
treefede87cc87664e0786b84a57598fefea2545a8b2 /src/gui
parent956bf7d64dc8e5e241174250e39098614faa59ea (diff)
downloadingen-7fa32b8bf0223e9c83d4dbff13e93d98dc9b07ca.tar.gz
ingen-7fa32b8bf0223e9c83d4dbff13e93d98dc9b07ca.tar.bz2
ingen-7fa32b8bf0223e9c83d4dbff13e93d98dc9b07ca.zip
Fix context menu position when using keyboard
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/GraphCanvas.cpp44
-rw-r--r--src/gui/GraphCanvas.hpp4
2 files changed, 31 insertions, 17 deletions
diff --git a/src/gui/GraphCanvas.cpp b/src/gui/GraphCanvas.cpp
index 85ab4855..7e237a1c 100644
--- a/src/gui/GraphCanvas.cpp
+++ b/src/gui/GraphCanvas.cpp
@@ -80,8 +80,8 @@ GraphCanvas::GraphCanvas(App& app,
, _app(app)
, _graph(graph)
, _auto_position_count(0)
- , _last_click_x(0)
- , _last_click_y(0)
+ , _menu_x(0)
+ , _menu_y(0)
, _paste_count(0)
, _menu(NULL)
, _internal_menu(NULL)
@@ -465,17 +465,31 @@ GraphCanvas::auto_menu_position(int& x, int& y, bool& push_in)
std::pair<int, int> scroll_offsets;
get_scroll_offsets(scroll_offsets.first, scroll_offsets.second);
- if (_auto_position_count > 0 && scroll_offsets != _auto_position_scroll_offsets)
- _auto_position_count = 0; // scrolling happened since last time, reset
+ if (_auto_position_count > 1 && scroll_offsets != _auto_position_scroll_offsets) {
+ // Scroll changed since last auto position, reset
+ _menu_x = 0;
+ _menu_y = 0;
+ _auto_position_count = 0;
+ }
- const int cascade = (_auto_position_count > 0) ? (_auto_position_count * 32) : 0;
+ if (_menu_x == 0 && _menu_y == 0) {
+ // No menu position set, start near top left of canvas
+ widget().translate_coordinates(
+ *_app.window_factory()->graph_window(_graph),
+ 64, 64, _menu_x, _menu_y);
- x = 64 + cascade;
- y = 64 + cascade;
- push_in = true;
+ int origin_x;
+ int origin_y;
+ widget().get_window()->get_origin(origin_x, origin_y);
+ _menu_x += origin_x;
+ _menu_y += origin_y;
+ }
- _last_click_x = scroll_offsets.first + x;
- _last_click_y = scroll_offsets.second + y;
+ const int cascade = _auto_position_count * 32;
+
+ x = _menu_x + cascade;
+ y = _menu_y + cascade;
+ push_in = true;
++_auto_position_count;
_auto_position_scroll_offsets = scroll_offsets;
@@ -491,9 +505,9 @@ GraphCanvas::on_event(GdkEvent* event)
switch (event->type) {
case GDK_BUTTON_PRESS:
if (event->button.button == 3) {
- _auto_position_count = 0;
- _last_click_x = (int)event->button.x;
- _last_click_y = (int)event->button.y;
+ _auto_position_count = 1;
+ _menu_x = (int)event->button.x_root;
+ _menu_y = (int)event->button.y_root;
show_menu(false, event->button.button, event->button.time);
ret = true;
}
@@ -832,11 +846,11 @@ GraphCanvas::get_initial_data(Resource::Graph ctx)
const URIs& uris = _app.uris();
result.insert(
make_pair(uris.ingen_canvasX,
- Resource::Property(_app.forge().make((float)_last_click_x),
+ Resource::Property(_app.forge().make((float)_menu_x),
ctx)));
result.insert(
make_pair(uris.ingen_canvasY,
- Resource::Property(_app.forge().make((float)_last_click_y),
+ Resource::Property(_app.forge().make((float)_menu_y),
ctx)));
return result;
}
diff --git a/src/gui/GraphCanvas.hpp b/src/gui/GraphCanvas.hpp
index b055d530..61c695c6 100644
--- a/src/gui/GraphCanvas.hpp
+++ b/src/gui/GraphCanvas.hpp
@@ -124,8 +124,8 @@ private:
int _auto_position_count;
std::pair<int, int> _auto_position_scroll_offsets;
- int _last_click_x;
- int _last_click_y;
+ int _menu_x;
+ int _menu_y;
int _paste_count;
// Track pasted objects so they can be selected when they arrive