summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-03-04 22:03:06 +0000
committerDavid Robillard <d@drobilla.net>2010-03-04 22:03:06 +0000
commit6e9aa3be4ae85f5a9bc4924b381962ac4a5760ac (patch)
treee6dd2958b3611c8ca60b000043c148d2e39cf8ce /src/gui
parent4e15488ea9089fb112d5afa7203bb090bf6a7502 (diff)
downloadingen-6e9aa3be4ae85f5a9bc4924b381962ac4a5760ac.tar.gz
ingen-6e9aa3be4ae85f5a9bc4924b381962ac4a5760ac.tar.bz2
ingen-6e9aa3be4ae85f5a9bc4924b381962ac4a5760ac.zip
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
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/PatchCanvas.cpp24
-rw-r--r--src/gui/PatchCanvas.hpp3
2 files changed, 18 insertions, 9 deletions
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<PatchModel> 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<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);
+ 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
- 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<ObjectModel>, SharedPtr<FlowCanvas::Module> > Views;
Views _views;
+ int _auto_position_count;
+ std::pair<int,int> _auto_position_scroll_offsets;
+
int _last_click_x;
int _last_click_y;
int _paste_count;