From 6e9aa3be4ae85f5a9bc4924b381962ac4a5760ac Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 4 Mar 2010 22:03:06 +0000 Subject: Cascade when several objects are added via keyboard in sequence. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2522 a436a847-0d15-0410-975c-d299462d15a1 --- src/gui/PatchCanvas.cpp | 24 +++++++++++++++--------- src/gui/PatchCanvas.hpp | 3 +++ 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/gui/PatchCanvas.cpp b/src/gui/PatchCanvas.cpp index d61137d6..758172ab 100644 --- a/src/gui/PatchCanvas.cpp +++ b/src/gui/PatchCanvas.cpp @@ -61,6 +61,7 @@ namespace GUI { PatchCanvas::PatchCanvas(SharedPtr patch, int width, int height) : Canvas(width, height) , _patch(patch) + , _auto_position_count(0) , _last_click_x(0) , _last_click_y(0) , _paste_count(0) @@ -524,19 +525,23 @@ PatchCanvas::disconnect(boost::shared_ptr 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); + std::pair 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 - Gtk::Container* parent = get_parent(); - const int win_width = parent->get_width(); - const int win_height = parent->get_height(); + const int cascade = (_auto_position_count > 0) ? (_auto_position_count * 32) : 0; - x = (win_width / 2.0); - y = (win_height / 2.0); + x = 64 + cascade; + y = 64 + cascade; push_in = true; - _last_click_x = scroll_x + x; - _last_click_y = scroll_y + y; + _last_click_x = scroll_offsets.first + x; + _last_click_y = scroll_offsets.second + y; + + ++_auto_position_count; + _auto_position_scroll_offsets = scroll_offsets; } @@ -550,6 +555,7 @@ PatchCanvas::canvas_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; show_menu(false, event->button.button, event->button.time); diff --git a/src/gui/PatchCanvas.hpp b/src/gui/PatchCanvas.hpp index 03018f5a..cf723081 100644 --- a/src/gui/PatchCanvas.hpp +++ b/src/gui/PatchCanvas.hpp @@ -134,6 +134,9 @@ private: typedef std::map, SharedPtr > Views; Views _views; + int _auto_position_count; + std::pair _auto_position_scroll_offsets; + int _last_click_x; int _last_click_y; int _paste_count; -- cgit v1.2.1