aboutsummaryrefslogtreecommitdiffstats
path: root/src/gui/MachinaCanvas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/MachinaCanvas.cpp')
-rw-r--r--src/gui/MachinaCanvas.cpp52
1 files changed, 31 insertions, 21 deletions
diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp
index 1a95b1c..15aaf57 100644
--- a/src/gui/MachinaCanvas.cpp
+++ b/src/gui/MachinaCanvas.cpp
@@ -38,45 +38,55 @@ namespace gui {
MachinaCanvas::MachinaCanvas(MachinaGUI* app, int width, int height)
: Canvas(width, height)
, _app(app)
- , _last_clicked(NULL)
+ , _connect_node(NULL)
+ , _did_connect(false)
{
widget().grab_focus();
- signal_event.connect(
- sigc::mem_fun(this, &MachinaCanvas::on_event));
+ signal_event.connect(sigc::mem_fun(this, &MachinaCanvas::on_event));
+}
+
+void
+MachinaCanvas::connect_nodes(GanvNode* node, void* data)
+{
+ NodeView* view = dynamic_cast<NodeView*>(Glib::wrap(node));
+ if (!view) {
+ std::cerr << "error: Connect of node with no view" << std::endl;
+ return;
+ }
+ MachinaCanvas* canvas = (MachinaCanvas*)data;
+ if (canvas->get_edge(view, canvas->_connect_node)) {
+ canvas->action_disconnect(view, canvas->_connect_node);
+ canvas->_did_connect = true;
+ } else if (!canvas->get_edge(canvas->_connect_node, view)) {
+ canvas->action_connect(view, canvas->_connect_node);
+ canvas->_did_connect = true;
+ }
}
bool
MachinaCanvas::node_clicked(NodeView* node, GdkEventButton* event)
{
- if (event->state & GDK_CONTROL_MASK) {
+ if (event->state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK)) {
return false;
- }
- if (event->button == 2) {
+ } else if (event->button == 2) {
// Middle click: learn
_app->controller()->learn(_app->maid(), node->node()->id());
return false;
} else if (event->button == 1) {
// Left click: connect/disconnect
- if (_last_clicked) {
- if (node != _last_clicked) {
- if (get_edge(_last_clicked, node)) {
- action_disconnect(_last_clicked, node);
- } else {
- action_connect(_last_clicked, node);
- }
- }
-
- _last_clicked->set_default_colors();
- _last_clicked = NULL;
-
+ _connect_node = node;
+ for_each_selected_node(connect_nodes, this);
+ const bool handled = _did_connect;
+ _connect_node = NULL;
+ _did_connect = false;
+ if (_app->chain_mode()) {
+ return false; // Cause Ganv to select as usual
} else {
- _last_clicked = node;
+ return handled; // If we did something, stop event here
}
-
- return true;
}
return false;