diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/EdgeView.cpp | 10 | ||||
-rw-r--r-- | src/gui/MachinaCanvas.cpp | 91 | ||||
-rw-r--r-- | src/gui/MachinaCanvas.hpp | 2 | ||||
-rw-r--r-- | src/gui/MachinaGUI.cpp | 9 |
4 files changed, 66 insertions, 46 deletions
diff --git a/src/gui/EdgeView.cpp b/src/gui/EdgeView.cpp index 3b5b8ec..4817eca 100644 --- a/src/gui/EdgeView.cpp +++ b/src/gui/EdgeView.cpp @@ -31,17 +31,15 @@ EdgeView::EdgeView(SharedPtr<FlowCanvas> canvas, : LibFlowCanvas::Connection(canvas, src, dst, 0x9999AAff, true) , _edge(edge) { - update_label(); } void EdgeView::update_label() { - std::ostringstream label; - label << std::setw(4); - label << _edge->probability(); - set_label(label.str()); + char label[4]; + snprintf(label, 4, "%3f", _edge->probability()); + set_label(label); } @@ -64,3 +62,5 @@ EdgeView::on_event(GdkEvent* ev) return false; } + + diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp index 327b2b0..3c2c1e8 100644 --- a/src/gui/MachinaCanvas.cpp +++ b/src/gui/MachinaCanvas.cpp @@ -16,6 +16,7 @@ */ //#include "config.h" +#include <map> #include <raul/SharedPtr.h> #include "machina/Node.hpp" #include "machina/Machine.hpp" @@ -169,57 +170,73 @@ MachinaCanvas::disconnect_node(boost::shared_ptr<NodeView> src, } +SharedPtr<NodeView> +MachinaCanvas::create_node_view(SharedPtr<Machina::Node> node) +{ + SharedPtr<NodeView> view(new NodeView(node, shared_from_this(), + "", 10, 10)); + + view->signal_clicked.connect(sigc::bind<0>(sigc::mem_fun(this, + &MachinaCanvas::node_clicked), WeakPtr<NodeView>(view))); + + add_item(view); + //view->resize(); + + return view; +} + + void MachinaCanvas::build(SharedPtr<Machina::Machine> machine) { destroy(); + std::map<SharedPtr<Machina::Node>, SharedPtr<NodeView> > views; + for (Machina::Machine::Nodes::const_iterator i = machine->nodes().begin(); i != machine->nodes().end(); ++i) { - //const double x = 1600 + rand() % 300; - //const double y = 1200 + rand() % 300; - - SharedPtr<NodeView> view(new NodeView((*i), shared_from_this(), - "", 10, 10)); - - view->signal_clicked.connect(sigc::bind<0>(sigc::mem_fun(this, - &MachinaCanvas::node_clicked), WeakPtr<NodeView>(view))); - - add_item(view); - //view->resize(); + const SharedPtr<NodeView> view = create_node_view(*i); + views.insert(std::make_pair((*i), view)); } - - for (ItemMap::iterator n = _items.begin(); n != _items.end(); ++n) { - - SharedPtr<NodeView> src = PtrCast<NodeView>(n->second); - if (!src) - continue; - for (Machina::Node::Edges::const_iterator e = src->node()->outgoing_edges().begin(); - e != src->node()->outgoing_edges().end(); ++e) { - - SharedPtr<NodeView> dst; - for (ItemMap::iterator m = _items.begin(); m != _items.end(); ++m) { - SharedPtr<NodeView> nv = PtrCast<NodeView>((*m).second); - if (nv && nv->node() == (*e)->dst()) { - dst = nv; - break; - } - } - - if (dst) { - boost::shared_ptr<Connection> c(new EdgeView(shared_from_this(), - src, dst, (*e))); - src->add_connection(c); - dst->add_connection(c); - add_connection(c); - } + for (ItemList::iterator i = _items.begin(); i != _items.end(); ++i) { + const SharedPtr<NodeView> view = PtrCast<NodeView>(*i); + if (!view) + continue; + for (Machina::Node::Edges::const_iterator e = view->node()->outgoing_edges().begin(); + e != view->node()->outgoing_edges().end(); ++e) { + + SharedPtr<NodeView> dst_view = views[(*e)->dst()]; + assert(dst_view); + + boost::shared_ptr<Connection> c(new EdgeView(shared_from_this(), + view, dst_view, (*e))); + view->add_connection(c); + dst_view->add_connection(c); + add_connection(c); } + + while (Gtk::Main::events_pending()) + Gtk::Main::iteration(false); } - + arrange(); + /* + while (Gtk::Main::events_pending()) + Gtk::Main::iteration(false); + + for (list<boost::shared_ptr<Connection> >::iterator c = _connections.begin(); c != _connections.end(); ++c) { + const SharedPtr<EdgeView> view = PtrCast<EdgeView>(*c); + if (view) + view->update_label(); // very, very slow + + while (Gtk::Main::events_pending()) + Gtk::Main::iteration(false); + + } + */ } diff --git a/src/gui/MachinaCanvas.hpp b/src/gui/MachinaCanvas.hpp index feead3e..302ffa4 100644 --- a/src/gui/MachinaCanvas.hpp +++ b/src/gui/MachinaCanvas.hpp @@ -50,6 +50,8 @@ protected: void node_clicked(WeakPtr<NodeView> item, GdkEventButton* ev); private: + SharedPtr<NodeView> create_node_view(SharedPtr<Machina::Node> node); + MachinaGUI* _app; WeakPtr<NodeView> _last_clicked; diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp index db5e70c..592001f 100644 --- a/src/gui/MachinaGUI.cpp +++ b/src/gui/MachinaGUI.cpp @@ -242,8 +242,8 @@ MachinaGUI::attach() bool MachinaGUI::idle_callback() { - for (ItemMap::iterator i = _canvas->items().begin(); i != _canvas->items().end(); ++i) { - SharedPtr<NodeView> nv = PtrCast<NodeView>(i->second); + for (ItemList::iterator i = _canvas->items().begin(); i != _canvas->items().end(); ++i) { + const SharedPtr<NodeView> nv = PtrCast<NodeView>(*i); if (nv) nv->update_state(); } @@ -465,12 +465,13 @@ MachinaGUI::menu_import_midi() SharedPtr<Machina::Machine> machine = file_driver->learn(dialog.get_uri()); if (machine) { + dialog.hide(); machine->activate(); machine->reset(); - _engine->driver()->set_machine(machine); _canvas->build(machine); + _engine->driver()->set_machine(machine); } else { - Gtk::MessageDialog msg_dialog(*_main_window, "Error loading MIDI file", + Gtk::MessageDialog msg_dialog(dialog, "Error loading MIDI file", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); msg_dialog.run(); } |