diff options
author | David Robillard <d@drobilla.net> | 2011-12-07 02:25:31 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-12-07 02:25:31 +0000 |
commit | ab83f198624534342de6805df68dc85794421f9c (patch) | |
tree | 9975c94262eecc9527f27585e38c50b67aff9d18 /src | |
parent | a3b80d07bc180dfbf2679930b0137321ff0b477f (diff) | |
download | ganv-ab83f198624534342de6805df68dc85794421f9c.tar.gz ganv-ab83f198624534342de6805df68dc85794421f9c.tar.bz2 ganv-ab83f198624534342de6805df68dc85794421f9c.zip |
Add C test program.
git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@3824 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/Canvas.cpp | 16 | ||||
-rw-r--r-- | src/ganv_test.c | 55 | ||||
-rw-r--r-- | src/module.c | 21 |
3 files changed, 82 insertions, 10 deletions
diff --git a/src/Canvas.cpp b/src/Canvas.cpp index a410588..2faf2a5 100644 --- a/src/Canvas.cpp +++ b/src/Canvas.cpp @@ -125,7 +125,7 @@ struct HeadTailOrder { struct GanvCanvasImpl { GanvCanvasImpl(GanvCanvas* gobj) : _gcanvas(gobj) - , _layout(Glib::wrap(GTK_LAYOUT(_gcanvas))) + , _layout(GTK_LAYOUT(_gcanvas)) , _connect_port(NULL) , _last_selected_port(NULL) , _base_rect(gnome_canvas_item_new( @@ -231,8 +231,8 @@ struct GanvCanvasImpl { void move_contents_to_internal(double x, double y, double min_x, double min_y); - GanvCanvas* _gcanvas; - Gtk::Layout* _layout; + GanvCanvas* _gcanvas; + GtkLayout* _layout; Items _items; ///< Items on this canvas Edges _edges; ///< Edges ordered (src, dst) @@ -310,7 +310,7 @@ GanvCanvasImpl::selection_move_finished() { FOREACH_ITEM(_selected_items, i) { std::cerr << "FIXME: selection move finished" << std::endl; - Glib::wrap(*i)->signal_moved.emit(); + //Glib::wrap(*i)->signal_moved.emit(); } } @@ -398,8 +398,7 @@ GanvCanvasImpl::select_item(GanvNode* m) // Select any connections to or from this node if (GANV_IS_MODULE(m)) { - Ganv::Module* module = Glib::wrap(GANV_MODULE(m)); - module->for_each_port(select_edges, this); + ganv_module_for_each_port(GANV_MODULE(m), select_edges, this); } else { for_each_edge_on(m, ganv_edge_select); } @@ -425,8 +424,7 @@ GanvCanvasImpl::unselect_item(GanvNode* m) { // Unselect any connections to or from this node if (GANV_IS_MODULE(m)) { - Ganv::Module* module = Glib::wrap(GANV_MODULE(m)); - module->for_each_port(unselect_edges, this); + ganv_module_for_each_port(GANV_MODULE(m), unselect_edges, this); } else { for_each_edge_on(m, ganv_edge_unselect); } @@ -1707,7 +1705,7 @@ Canvas::root() Gtk::Layout& Canvas::widget() { - return *impl()->_layout; + return *Glib::wrap(impl()->_layout); } void diff --git a/src/ganv_test.c b/src/ganv_test.c new file mode 100644 index 0000000..a2df8af --- /dev/null +++ b/src/ganv_test.c @@ -0,0 +1,55 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <gtk/gtk.h> + +#include "ganv/ganv.h" + +static void +on_window_destroy(GtkWidget* widget, + gpointer data) +{ + gtk_main_quit(); +} + +int +main(int argc, char** argv) +{ + gtk_init(&argc, &argv); + + GtkWindow* win = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); + gtk_window_set_title(win, "Ganv Test"); + g_signal_connect(win, "destroy", + G_CALLBACK(on_window_destroy), NULL); + + GanvCanvas* canvas = ganv_canvas_new(1024, 768); + gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(canvas)); + + GanvModule* module = ganv_module_new(canvas, + "x", 10.0, + "y", 10.0, + "draggable", TRUE, + "label", "test", + NULL); + + gnome_canvas_item_show(GNOME_CANVAS_ITEM(module)); + gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(module)); + + gtk_widget_show_all(GTK_WIDGET(win)); + gtk_window_present(win); + gtk_main(); + + return 0; +} diff --git a/src/module.c b/src/module.c index 1a76787..acb0a6d 100644 --- a/src/module.c +++ b/src/module.c @@ -57,7 +57,7 @@ ganv_module_init(GanvModule* module) module->widest_input = 0.0; module->widest_output = 0.0; module->show_port_labels = FALSE; - module->must_resize = FALSE; + module->must_resize = TRUE; module->port_size_changed = FALSE; } @@ -550,6 +550,25 @@ ganv_module_class_init(GanvModuleClass* class) node_class->resize = ganv_module_resize; } +GanvModule* +ganv_module_new(GanvCanvas* canvas, + const char* first_prop_name, ...) +{ + GanvModule* module = GANV_MODULE( + g_object_new(ganv_module_get_type(), NULL)); + + GnomeCanvasItem* item = GNOME_CANVAS_ITEM(module); + va_list args; + va_start(args, first_prop_name); + gnome_canvas_item_construct(item, + gnome_canvas_root(GNOME_CANVAS(canvas)), + first_prop_name, args); + va_end(args); + + ganv_canvas_add_node(canvas, GANV_NODE(module)); + return module; +} + void ganv_module_add_port(GanvModule* module, GanvPort* port) |