diff options
author | David Robillard <d@drobilla.net> | 2013-01-13 07:49:49 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2013-01-13 07:49:49 +0000 |
commit | 67a8adbc93991acfb688f378f52392995a272fac (patch) | |
tree | a4e629bd9c0d7da4cc5c7cb644b3352ca6f0dc78 /src/gui/MachinaCanvas.cpp | |
parent | 33aa54fa98783d1da2a322ee136c17df7f9c98a5 (diff) | |
download | machina-67a8adbc93991acfb688f378f52392995a272fac.tar.gz machina-67a8adbc93991acfb688f378f52392995a272fac.tar.bz2 machina-67a8adbc93991acfb688f378f52392995a272fac.zip |
Change model to have a single initial node.
Merge multiple recording into branches off the same initial node.
Make transport state sane with 3 distinct states.
Handle announcing objects several times correctly.
Don't send useless zero coordinates for new nodes, position in visible area.
Rewrite and clean up Machine code.
Update help.
git-svn-id: http://svn.drobilla.net/lad/trunk/machina@4954 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/gui/MachinaCanvas.cpp')
-rw-r--r-- | src/gui/MachinaCanvas.cpp | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp index 627eb09..7a7efa9 100644 --- a/src/gui/MachinaCanvas.cpp +++ b/src/gui/MachinaCanvas.cpp @@ -39,6 +39,7 @@ namespace gui { MachinaCanvas::MachinaCanvas(MachinaGUI* app, int width, int height) : Canvas(width, height) , _app(app) + , _last_clicked(NULL) { widget().grab_focus(); @@ -47,13 +48,8 @@ MachinaCanvas::MachinaCanvas(MachinaGUI* app, int width, int height) } bool -MachinaCanvas::node_clicked(WPtr<NodeView> item, GdkEventButton* event) +MachinaCanvas::node_clicked(NodeView* node, GdkEventButton* event) { - SPtr<NodeView> node = dynamic_ptr_cast<NodeView>(item.lock()); - if (!node) { - return false; - } - if (event->state & GDK_CONTROL_MASK) { return false; } @@ -65,19 +61,17 @@ MachinaCanvas::node_clicked(WPtr<NodeView> item, GdkEventButton* event) } else if (event->button == 1) { // Left click: connect/disconnect - SPtr<NodeView> last = _last_clicked.lock(); - - if (last) { - if (node != last) { - if (get_edge(last.get(), node.get())) { - action_disconnect(last, node); + if (_last_clicked) { + if (node != _last_clicked) { + if (get_edge(_last_clicked, node)) { + action_disconnect(_last_clicked, node); } else { - action_connect(last, node); + action_connect(_last_clicked, node); } } - last->set_default_colors(); - _last_clicked.reset(); + _last_clicked->set_default_colors(); + _last_clicked = NULL; } else { _last_clicked = node; @@ -112,17 +106,28 @@ MachinaCanvas::on_new_object(SPtr<client::ClientObject> object) } if (type.get<URIInt>() == uris.machina_Node) { - SPtr<NodeView> view( - new NodeView(_app->window(), *this, object, - object->get(uris.machina_canvas_x).get_float(), - object->get(uris.machina_canvas_y).get_float())); + const Raul::Atom& node_x = object->get(uris.machina_canvas_x); + const Raul::Atom& node_y = object->get(uris.machina_canvas_y); + float x, y; + if (node_x.type() == _app->forge().Float && + node_y.type() == _app->forge().Float) { + x = node_x.get_float(); + y = node_y.get_float(); + } else { + int scroll_x, scroll_y; + get_scroll_offsets(scroll_x, scroll_y); + x = scroll_x + 64.0; + y = scroll_y + 64.0; + } + + NodeView* view = new NodeView(_app->window(), *this, object, x, y); //if ( ! node->enter_action() && ! node->exit_action() ) // view->set_base_color(0x101010FF); view->signal_clicked().connect( sigc::bind<0>(sigc::mem_fun(this, &MachinaCanvas::node_clicked), - WPtr<NodeView>(view))); + view)); object->set_view(view); @@ -141,12 +146,10 @@ MachinaCanvas::on_new_object(SPtr<client::ClientObject> object) return; } - SPtr<NodeView> tail_view = dynamic_ptr_cast<NodeView>(tail->view()); - SPtr<NodeView> head_view = dynamic_ptr_cast<NodeView>(head->view()); + NodeView* tail_view = dynamic_cast<NodeView*>(tail->view()); + NodeView* head_view = dynamic_cast<NodeView*>(head->view()); - SPtr<EdgeView> view(new EdgeView(*this, tail_view, head_view, object)); - - object->set_view(view); + object->set_view(new EdgeView(*this, tail_view, head_view, object)); } else { std::cerr << "Unknown object type " << type.get<URIInt>() << std::endl; @@ -160,7 +163,7 @@ MachinaCanvas::on_erase_object(SPtr<client::ClientObject> object) if (type.get<URIInt>() == URIs::instance().machina_Node) { // Destruction of the view will remove from the canvas } else if (type.get<URIInt>() == URIs::instance().machina_Edge) { - object->set_view(SPtr<client::ClientObject::View>()); + object->set_view(NULL); } else { std::cerr << "Unknown object type" << std::endl; } @@ -179,17 +182,15 @@ MachinaCanvas::action_create_node(double x, double y) } void -MachinaCanvas::action_connect(SPtr<NodeView> src, - SPtr<NodeView> head) +MachinaCanvas::action_connect(NodeView* tail, NodeView* head) { - _app->controller()->connect(src->node()->id(), head->node()->id()); + _app->controller()->connect(tail->node()->id(), head->node()->id()); } void -MachinaCanvas::action_disconnect(SPtr<NodeView> src, - SPtr<NodeView> head) +MachinaCanvas::action_disconnect(NodeView* tail, NodeView* head) { - _app->controller()->disconnect(src->node()->id(), head->node()->id()); + _app->controller()->disconnect(tail->node()->id(), head->node()->id()); } } // namespace machina |