diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/EdgeView.cpp | 9 | ||||
-rw-r--r-- | src/gui/MachinaCanvas.cpp | 30 | ||||
-rw-r--r-- | src/gui/MachinaGUI.cpp | 6 | ||||
-rw-r--r-- | src/gui/MachinaGUI.hpp | 4 | ||||
-rw-r--r-- | src/gui/NodeView.cpp | 35 | ||||
-rw-r--r-- | src/gui/NodeView.hpp | 10 | ||||
-rw-r--r-- | src/gui/main.cpp | 9 |
7 files changed, 64 insertions, 39 deletions
diff --git a/src/gui/EdgeView.cpp b/src/gui/EdgeView.cpp index 5f57be6..877ecbb 100644 --- a/src/gui/EdgeView.cpp +++ b/src/gui/EdgeView.cpp @@ -73,6 +73,9 @@ EdgeView::EdgeView(Canvas& canvas, edge->signal_property.connect( sigc::mem_fun(this, &EdgeView::on_property)); + + signal_event().connect( + sigc::mem_fun(this, &EdgeView::on_event)); } float @@ -98,19 +101,21 @@ bool EdgeView::on_event(GdkEvent* ev) { MachinaCanvas* canvas = dynamic_cast<MachinaCanvas*>(this->canvas()); + Raul::Forge& forge = canvas->app()->forge(); + if (ev->type == GDK_BUTTON_PRESS) { if (ev->button.state & GDK_CONTROL_MASK) { if (ev->button.button == 1) { canvas->app()->controller()->set_property( _edge->id(), URIs::instance().machina_probability, - Raul::Atom(probability() - 0.1f)); + forge.make(float(probability() - 0.1f))); return true; } else if (ev->button.button == 3) { canvas->app()->controller()->set_property( _edge->id(), URIs::instance().machina_probability, - Raul::Atom(probability() + 0.1f)); + forge.make(float(probability() + 0.1f))); return true; } } diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp index da03cd9..57cffc9 100644 --- a/src/gui/MachinaCanvas.cpp +++ b/src/gui/MachinaCanvas.cpp @@ -17,7 +17,6 @@ #include <map> -#include "raul/log.hpp" #include "raul/SharedPtr.hpp" #include "raul/TimeStamp.hpp" @@ -40,6 +39,9 @@ MachinaCanvas::MachinaCanvas(MachinaGUI* app, int width, int height) , _app(app) { widget().grab_focus(); + + signal_event.connect( + sigc::mem_fun(this, &MachinaCanvas::on_event)); } bool @@ -56,7 +58,7 @@ MachinaCanvas::node_clicked(WeakPtr<NodeView> item, GdkEventButton* event) _app->controller()->learn(_app->maid(), node->node()->id()); return false; - } else if (event->button == 3) { // Right click: connect/disconnect + } else if (event->button == 1) { // Left click: connect/disconnect SharedPtr<NodeView> last = _last_clicked.lock(); if (last) { @@ -72,7 +74,6 @@ MachinaCanvas::node_clicked(WeakPtr<NodeView> item, GdkEventButton* event) } else { _last_clicked = node; - node->set_fill_color(0xFF0000FF); } return true; @@ -99,7 +100,7 @@ MachinaCanvas::on_new_object(SharedPtr<Client::ClientObject> object) { const Machina::URIs& uris = URIs::instance(); const Raul::Atom& type = object->get(uris.rdf_type); - if (type == "machina:Node") { + if (type.get<URIInt>() == uris.machina_Node) { SharedPtr<NodeView> view( new NodeView(_app->window(), *this, object, object->get(uris.machina_canvas_x).get_float(), @@ -108,13 +109,13 @@ MachinaCanvas::on_new_object(SharedPtr<Client::ClientObject> object) //if ( ! node->enter_action() && ! node->exit_action() ) // view->set_base_color(0x101010FF); - view->signal_click().connect( + view->signal_clicked().connect( sigc::bind<0>(sigc::mem_fun(this, &MachinaCanvas::node_clicked), WeakPtr<NodeView>(view))); object->set_view(view); - } else if (type == "machina:Edge") { + } else if (type.get<URIInt>() == uris.machina_Edge) { SharedPtr<Machina::Client::ClientObject> tail = _app->client_model()->find( object->get(uris.machina_tail_id).get_int32()); SharedPtr<Machina::Client::ClientObject> head = _app->client_model()->find( @@ -129,7 +130,7 @@ MachinaCanvas::on_new_object(SharedPtr<Client::ClientObject> object) object->set_view(view); } else { - Raul::error << "Unknown object type " << type << std::endl; + std::cerr << "Unknown object type" << std::endl; } } @@ -137,12 +138,12 @@ void MachinaCanvas::on_erase_object(SharedPtr<Client::ClientObject> object) { const Raul::Atom& type = object->get(URIs::instance().rdf_type); - if (type == "machina:Node") { + if (type.get<URIInt>() == URIs::instance().machina_Node) { // Destruction of the view will remove from the canvas - } else if (type == "machina:Edge") { + } else if (type.get<URIInt>() == URIs::instance().machina_Edge) { object->set_view(SharedPtr<Client::ClientObject::View>()); } else { - Raul::error << "Unknown object type " << type << std::endl; + std::cerr << "Unknown object type" << std::endl; } } @@ -150,10 +151,11 @@ void MachinaCanvas::action_create_node(double x, double y) { Machina::Client::ClientObject obj(0); - obj.set(URIs::instance().rdf_type, "machina:Node"); - obj.set(URIs::instance().machina_canvas_x, Raul::Atom((float)x)); - obj.set(URIs::instance().machina_canvas_y, Raul::Atom((float)y)); - obj.set(URIs::instance().machina_duration, Raul::Atom((float)1.0)); + obj.set(URIs::instance().rdf_type, + _app->forge().make_urid(URIs::instance().machina_Node)); + obj.set(URIs::instance().machina_canvas_x, _app->forge().make((float)x)); + obj.set(URIs::instance().machina_canvas_y, _app->forge().make((float)y)); + obj.set(URIs::instance().machina_duration, _app->forge().make(1.0f)); _app->controller()->create(obj); } diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp index 101622d..ee038de 100644 --- a/src/gui/MachinaGUI.cpp +++ b/src/gui/MachinaGUI.cpp @@ -47,7 +47,7 @@ MachinaGUI::MachinaGUI(SharedPtr<Machina::Engine> engine) , _engine(engine) , _client_model(new Machina::Client::ClientModel()) , _controller(new Machina::Controller(_engine, *_client_model.get())) - , _maid(new Raul::Maid(32)) + , _maid(new Raul::Maid()) { _canvas = boost::shared_ptr<MachinaCanvas>(new MachinaCanvas(this, 1600*2, 1200*2)); @@ -252,7 +252,7 @@ MachinaGUI::scrolled_window_event(GdkEvent* event) void MachinaGUI::arrange() { - _canvas->arrange(_menu_view_time_edges->get_active()); + _canvas->arrange(); } void @@ -581,7 +581,7 @@ MachinaGUI::menu_export_graphviz() const int result = dialog.run(); if (result == Gtk::RESPONSE_OK) - _canvas->render_to_dot(dialog.get_filename()); + _canvas->export_dot(dialog.get_filename().c_str()); } void diff --git a/src/gui/MachinaGUI.hpp b/src/gui/MachinaGUI.hpp index 4fd6dfc..27133e0 100644 --- a/src/gui/MachinaGUI.hpp +++ b/src/gui/MachinaGUI.hpp @@ -49,6 +49,8 @@ public: boost::shared_ptr<MachinaCanvas> canvas() { return _canvas; } boost::shared_ptr<Machina::Engine> engine() { return _engine; } + Raul::Forge& forge() { return _forge; } + SharedPtr<Raul::Maid> maid() { return _maid; } Gtk::Window* window() { return _main_window; } @@ -118,6 +120,8 @@ protected: SharedPtr<Raul::Maid> _maid; SharedPtr<Machina::Evolver> _evolver; + Raul::Forge _forge; + Gtk::Main* _gtk_main; Gtk::Window* _main_window; diff --git a/src/gui/NodeView.cpp b/src/gui/NodeView.cpp index 5e8ceb4..bf7c0b6 100644 --- a/src/gui/NodeView.cpp +++ b/src/gui/NodeView.cpp @@ -40,8 +40,8 @@ NodeView::NodeView(Gtk::Window* window, , _default_border_color(get_border_color()) , _default_fill_color(get_fill_color()) { - signal_click().connect( - sigc::mem_fun(this, &NodeView::on_click)); + signal_event().connect( + sigc::mem_fun(this, &NodeView::on_event)); node->signal_property.connect( sigc::mem_fun(this, &NodeView::on_property)); @@ -54,29 +54,34 @@ NodeView::on_double_click(GdkEventButton*) } bool -NodeView::node_is(Machina::URIInt key) +NodeView::node_is(Raul::Forge& forge, Machina::URIInt key) { const Raul::Atom& value = _node->get(key); - return value.type() == Raul::Atom::BOOL && value.get_bool(); + return value.type() == forge.Bool && value.get_bool(); } bool -NodeView::on_click(GdkEventButton* event) +NodeView::on_event(GdkEvent* event) { - if (event->state & GDK_CONTROL_MASK) { - MachinaCanvas* canvas = dynamic_cast<MachinaCanvas*>(this->canvas()); - if (event->button == 1) { - canvas->app()->controller()->set_property( + MachinaCanvas* canvas = dynamic_cast<MachinaCanvas*>(this->canvas()); + Raul::Forge& forge = canvas->app()->forge(); + if (event->type == GDK_BUTTON_PRESS) { + if (event->button.state & GDK_CONTROL_MASK) { + if (event->button.button == 1) { + canvas->app()->controller()->set_property( _node->id(), URIs::instance().machina_initial, - !node_is(URIs::instance().machina_initial)); - return true; - } else if (event->button == 3) { - canvas->app()->controller()->set_property( + forge.make(!node_is(forge, URIs::instance().machina_initial))); + return true; + } else if (event->button.button == 3) { + canvas->app()->controller()->set_property( _node->id(), URIs::instance().machina_selector, - !node_is(URIs::instance().machina_selector)); - return true; + forge.make(!node_is(forge, URIs::instance().machina_selector))); + return true; + } + } else { + _signal_clicked.emit(&event->button); } } return false; diff --git a/src/gui/NodeView.hpp b/src/gui/NodeView.hpp index ba87370..eb7a61f 100644 --- a/src/gui/NodeView.hpp +++ b/src/gui/NodeView.hpp @@ -42,14 +42,18 @@ public: void set_default_colors(); + sigc::signal<bool, GdkEventButton*>& signal_clicked() { + return _signal_clicked; + } + private: - bool on_click(GdkEventButton* ev); + bool on_event(GdkEvent* ev); void on_double_click(GdkEventButton* ev); void on_property(Machina::URIInt key, const Raul::Atom& value); void on_action_property(Machina::URIInt key, const Raul::Atom& value); void set_selected(gboolean selected); - bool node_is(Machina::URIInt key); + bool node_is(Raul::Forge& forge, Machina::URIInt key); Gtk::Window* _window; SharedPtr<Machina::Client::ClientObject> _node; @@ -58,6 +62,8 @@ private: SharedPtr<Machina::Client::ClientObject> _enter_action; sigc::connection _enter_action_connection; + + sigc::signal<bool, GdkEventButton*> _signal_clicked; }; #endif // MACHINA_NODEVIEW_HPP diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 6db973c..676e3b8 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -64,8 +64,11 @@ main(int argc, char** argv) } #endif + Raul::Forge forge; + if (!machine) - machine = SharedPtr<Machine>(new Machine(TimeUnit(TimeUnit::BEATS, 19200))); + machine = SharedPtr<Machine>( + new Machine(forge, TimeUnit(TimeUnit::BEATS, 19200))); std::string driver_name = "smf"; #ifdef HAVE_JACK @@ -73,8 +76,8 @@ main(int argc, char** argv) #endif // Build engine - SharedPtr<Driver> driver(Engine::new_driver(driver_name, machine)); - SharedPtr<Engine> engine(new Engine(driver, rdf_world)); + SharedPtr<Driver> driver(Engine::new_driver(forge, driver_name, machine)); + SharedPtr<Engine> engine(new Engine(forge, driver, rdf_world)); Gtk::Main app(argc, argv); |