[graph-gtk] graph-gtk: port to gtk3



commit b344f39b3bbde2c8faf9c716cf4e3ed1c1600134
Author: Clayton Walker <clayton m walker gmail com>
Date:   Sun Oct 20 01:40:03 2013 -0600

    graph-gtk: port to gtk3

 configure.ac                     |    2 +-
 graph-gtk.pc.in                  |    2 +-
 graph-gtk/Makefile.am            |    3 ++-
 graph-gtk/graph-gtk-connection.c |    4 ++--
 graph-gtk/graph-gtk-connection.h |    6 ------
 graph-gtk/graph-gtk-node.c       |   18 ++++++++++++------
 graph-gtk/graph-gtk-node.h       |    8 +-------
 graph-gtk/graph-gtk-pad.c        |    6 +++---
 graph-gtk/graph-gtk-pad.h        |    7 +------
 graph-gtk/graph-gtk-types.h      |   16 ++++++++++++++++
 graph-gtk/graph-gtk-view.c       |    6 ++++--
 graph-gtk/graph-gtk-view.h       |   10 +---------
 tests/simple_container.c         |   25 +++++++++++++++++--------
 13 files changed, 61 insertions(+), 52 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 32ebf23..6da392d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,6 +20,6 @@ AC_CONFIG_SRCDIR([graph-gtk/graph-gtk-view.c])
 AC_PROG_CC
 AC_PROG_INSTALL
 AC_PROG_LIBTOOL
-PKG_CHECK_MODULES(GTK, gtk+-2.0)
+PKG_CHECK_MODULES(GTK, gtk+-3.0)
 
 AC_OUTPUT
diff --git a/graph-gtk.pc.in b/graph-gtk.pc.in
index 605e3d8..e75d886 100644
--- a/graph-gtk.pc.in
+++ b/graph-gtk.pc.in
@@ -7,6 +7,6 @@ includedir= includedir@
 Name: GRAPH-GTK
 Description: GRAPH MANIPULATION WIDGET 
 Version: @VERSION@
-Requires: gtk+-2.0
+Requires: gtk+-3.0
 Libs: -L${libdir} -l PACKAGE_NAME@
 Cflags: -I${includedir}/@PACKAGE_NAME@/
diff --git a/graph-gtk/Makefile.am b/graph-gtk/Makefile.am
index 8f0575e..3358c5c 100644
--- a/graph-gtk/Makefile.am
+++ b/graph-gtk/Makefile.am
@@ -6,7 +6,8 @@ lib_LTLIBRARIES = libgraph-gtk.la
 pkginclude_HEADERS =           graph-gtk-view.h        \
                                graph-gtk-node.h        \
                                graph-gtk-pad.h         \
-                               graph-gtk-connection.h
+                               graph-gtk-connection.h  \
+                               graph-gtk-types.h
 
 libgraph_gtk_la_SOURCES =      graph-gtk-view.c        \
                                graph-gtk-node.c        \
diff --git a/graph-gtk/graph-gtk-connection.c b/graph-gtk/graph-gtk-connection.c
index f52ecaa..c4c1c84 100644
--- a/graph-gtk/graph-gtk-connection.c
+++ b/graph-gtk/graph-gtk-connection.c
@@ -1,6 +1,6 @@
 #include "graph-gtk-connection.h"
 
-#include <math.h>
+#include <glib.h>
 
 static void graph_gtk_connection_dispose (GObject *object);
 static void graph_gtk_connection_finalize (GObject *object);
@@ -56,7 +56,7 @@ graph_gtk_connection_default_render(GraphGtkConnection* self, cairo_t* cr)
 
   gdouble offset = 
     ((to_x > from_x) ? ((to_x-from_x)/2) : ((from_x-to_x)/2))
-    + abs(from_y-to_y)/6;
+    + ABS(from_y-to_y)/6;
 
   /*  if(to_x - from_x > 100)
     cairo_curve_to(cr, (from_x+to_x)/2, from_y,
diff --git a/graph-gtk/graph-gtk-connection.h b/graph-gtk/graph-gtk-connection.h
index 2249fc3..9a9dc55 100644
--- a/graph-gtk/graph-gtk-connection.h
+++ b/graph-gtk/graph-gtk-connection.h
@@ -27,12 +27,6 @@ G_BEGIN_DECLS
                                GRAPH_TYPE_GTK_CONNECTION,               \
                                GraphGtkConnectionClass))
 
-struct _GraphGtkPad;
-typedef struct _GraphGtkPad GraphGtkPad;
-
-typedef struct _GraphGtkConnection      GraphGtkConnection;
-typedef struct _GraphGtkConnectionClass GraphGtkConnectionClass;
-
 struct _GraphGtkConnectionClass
 {
   GObjectClass parent_class;
diff --git a/graph-gtk/graph-gtk-node.c b/graph-gtk/graph-gtk-node.c
index 200f48b..f304e62 100644
--- a/graph-gtk/graph-gtk-node.c
+++ b/graph-gtk/graph-gtk-node.c
@@ -21,7 +21,7 @@ void cairo_image_surface_blur( cairo_surface_t* surface, double radius )
     
   // The number of times to perform the averaging. According to wikipedia,
   // three iterations is good enough to pass for a gaussian.
-  const MAX_ITERATIONS = 3; 
+  const int MAX_ITERATIONS = 3; 
   int iteration;
 
   memcpy( dst, src, width*height*4 );
@@ -168,7 +168,9 @@ graph_gtk_node_render_default(GraphGtkNode* self, cairo_t* cr)
       cairo_surface_flush(shadow);
       cairo_image_surface_blur(shadow, 2);
 
-      int offset = 3.5;
+      // FIXME: Original code
+      // int offset = 3.5;
+      int offset = 3;
       cairo_set_source_surface(cr, shadow, (self->x+self->offset_x)-25+offset, 
(self->y+self->offset_y)-25+offset);
       //cairo_rectangle(cr, (self->x+self->offset_x)-10, (self->y+self->offset_y)-10, 
(self->x+self->offset_x)+20, (self->y+self->offset_y)+20);
       cairo_paint(cr);
@@ -252,7 +254,7 @@ graph_gtk_node_render_default(GraphGtkNode* self, cairo_t* cr)
   cairo_set_line_width(cr, 0.5);
   cairo_stroke(cr);
 
-  cairo_select_font_face (cr, "FreeSerif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+  cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
   cairo_set_font_size(cr, 14);
   cairo_set_source_rgb(cr, 200.0/256.0, 200.0/256.0, 200.0/256.0);
   cairo_move_to(cr, (self->x+self->offset_x)+4, (self->y+self->offset_y)+13);
@@ -384,7 +386,9 @@ graph_gtk_node_connect_to(GraphGtkNode* source, const gchar* output_pad, GraphGt
 gboolean
 graph_gtk_node_recalculate_size(GraphGtkNode* self)
 {
-  g_return_if_fail(IS_GRAPH_GTK_NODE(self));
+  // FIXME: According to glib docs, cannot use macro
+  // on functions that return a value
+  // g_return_if_fail(IS_GRAPH_GTK_NODE(self));
 
   return GRAPH_GTK_NODE_GET_CLASS(self)->recalculate_size(self);
 }
@@ -417,7 +421,7 @@ graph_gtk_node_recalculate_size_default(GraphGtkNode* self)
   GtkWidget *widget = GTK_WIDGET(view);
   cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget));
 
-  cairo_select_font_face (cr, "FreeSerif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+  cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
   cairo_set_font_size(cr, 13);
       
   cairo_text_extents(cr, self->name, &extents);
@@ -475,7 +479,9 @@ graph_gtk_node_recalculate_size_default(GraphGtkNode* self)
   for(list = self->input_pads, count = 0; list != NULL; list = list->next, count++) {
     GraphGtkPad *pad = (GraphGtkPad*)list->data;
 
-    pad->rel_x = 5.5;
+    // FIXME: Original code below
+    // pad->rel_x = 5.5;
+    pad->rel_x = 5;
     pad->rel_y = 30+count*25;
     if(self->show_image && image_h > 0)
       pad->rel_y += image_h+6;
diff --git a/graph-gtk/graph-gtk-node.h b/graph-gtk/graph-gtk-node.h
index c557c01..27b202e 100644
--- a/graph-gtk/graph-gtk-node.h
+++ b/graph-gtk/graph-gtk-node.h
@@ -4,7 +4,7 @@
 #include <glib-object.h>
 #include <gtk/gtk.h>
 
-#include "graph-gtk-pad.h"
+#include "graph-gtk-types.h"
 
 G_BEGIN_DECLS
 
@@ -29,12 +29,6 @@ G_BEGIN_DECLS
                                GRAPH_TYPE_GTK_NODE,                     \
                                GraphGtkNodeClass))
 
-struct _GraphGtkView;
-typedef struct _GraphGtkView GraphGtkView;
-
-typedef struct _GraphGtkNode      GraphGtkNode;
-typedef struct _GraphGtkNodeClass GraphGtkNodeClass;
-
 struct _GraphGtkNodeClass
 {
   GObjectClass parent_class;
diff --git a/graph-gtk/graph-gtk-pad.c b/graph-gtk/graph-gtk-pad.c
index 553232c..ef556f4 100644
--- a/graph-gtk/graph-gtk-pad.c
+++ b/graph-gtk/graph-gtk-pad.c
@@ -74,7 +74,7 @@ graph_gtk_pad_default_render(GraphGtkPad* self, cairo_t* cr)
       cairo_set_source_rgb(cr, 132.0/256.0, 132.0/256.0, 132.0/256.0);
       cairo_stroke(cr);
 
-      cairo_select_font_face (cr, "FreeSerif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+      cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
       cairo_set_font_size(cr, 13);
       
       cairo_text_extents_t extents;
@@ -106,7 +106,7 @@ graph_gtk_pad_default_render(GraphGtkPad* self, cairo_t* cr)
       cairo_set_source_rgb(cr, 132.0/256.0, 132.0/256.0, 132.0/256.0);
       cairo_stroke(cr);
 
-      cairo_select_font_face (cr, "FreeSerif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+      cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
       cairo_set_font_size(cr, 13);
       
       cairo_text_extents_t extents;
@@ -180,7 +180,7 @@ graph_gtk_pad_get_width(GraphGtkPad* self)
       GtkWidget *widget = GTK_WIDGET(view);
       cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget));
 
-      cairo_select_font_face (cr, "FreeSerif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+      cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
       cairo_set_font_size(cr, 13);
       
       cairo_text_extents_t extents;
diff --git a/graph-gtk/graph-gtk-pad.h b/graph-gtk/graph-gtk-pad.h
index 2ab34ea..1ddcddd 100644
--- a/graph-gtk/graph-gtk-pad.h
+++ b/graph-gtk/graph-gtk-pad.h
@@ -3,6 +3,7 @@
 
 #include <glib-object.h>
 #include <gtk/gtk.h>
+#include "graph-gtk-types.h"
 
 G_BEGIN_DECLS
 
@@ -27,12 +28,6 @@ G_BEGIN_DECLS
                                GRAPH_TYPE_GTK_PAD,                      \
                                GraphGtkPadClass))
 
-struct _GraphGtkNode;
-typedef struct _GraphGtkNode GraphGtkNode;
-
-typedef struct _GraphGtkPad      GraphGtkPad;
-typedef struct _GraphGtkPadClass GraphGtkPadClass;
-
 struct _GraphGtkPadClass
 {
   GObjectClass parent_class;
diff --git a/graph-gtk/graph-gtk-types.h b/graph-gtk/graph-gtk-types.h
new file mode 100644
index 0000000..6d9d190
--- /dev/null
+++ b/graph-gtk/graph-gtk-types.h
@@ -0,0 +1,16 @@
+#ifndef __GRAPH_GTK_TYPES_H__
+#define __GRAPH_GTK_TYPES_H__
+
+typedef struct _GraphGtkPad             GraphGtkPad;
+typedef struct _GraphGtkPadClass        GraphGtkPadClass;
+
+typedef struct _GraphGtkView            GraphGtkView;
+typedef struct _GraphGtkViewClass       GraphGtkViewClass;
+
+typedef struct _GraphGtkConnection      GraphGtkConnection;
+typedef struct _GraphGtkConnectionClass GraphGtkConnectionClass;
+
+typedef struct _GraphGtkNode            GraphGtkNode;
+typedef struct _GraphGtkNodeClass       GraphGtkNodeClass;
+
+#endif /* __GRAPH_GTK_TYPES_H__ */
diff --git a/graph-gtk/graph-gtk-view.c b/graph-gtk/graph-gtk-view.c
index 92806d7..6a6ba29 100644
--- a/graph-gtk/graph-gtk-view.c
+++ b/graph-gtk/graph-gtk-view.c
@@ -295,8 +295,9 @@ graph_gtk_view_button_pressed(GtkWidget* widget, GdkEventButton* event)
        {
          GraphGtkNode *node = (GraphGtkNode*)nodes->data;
          GraphGtkPad *pad;
+         pad = graph_gtk_node_is_on_pad(node, event->x+self->pan_x, event->y+self->pan_y);
 
-         if(pad = graph_gtk_node_is_on_pad(node, event->x+self->pan_x, event->y+self->pan_y))
+         if(pad)
            {
              self->is_mouse_connecting = TRUE;
              self->pad_connecting_from = pad;
@@ -411,8 +412,9 @@ graph_gtk_view_button_released(GtkWidget* widget, GdkEventButton* event)
            {
              GraphGtkNode *node = (GraphGtkNode*)nodes->data;
              GraphGtkPad *pad;
+             pad = graph_gtk_node_is_on_pad(node, event->x+self->pan_x, event->y+self->pan_y);
 
-             if(pad = graph_gtk_node_is_on_pad(node, event->x+self->pan_x, event->y+self->pan_y))
+             if(pad)
                {
                  REDRAW();
                  self->is_mouse_connecting = FALSE;
diff --git a/graph-gtk/graph-gtk-view.h b/graph-gtk/graph-gtk-view.h
index 6d57791..43af1e5 100644
--- a/graph-gtk/graph-gtk-view.h
+++ b/graph-gtk/graph-gtk-view.h
@@ -2,6 +2,7 @@
 #define __GRAPH_GTK_VIEW_H__
 
 #include <gtk/gtk.h>
+#include "graph-gtk-types.h"
 
 /**
    GraphGtkView:
@@ -35,15 +36,6 @@ G_BEGIN_DECLS
                                GRAPH_TYPE_GTK_VIEW,                     \
                                GraphGtkViewClass))
 
-struct _GraphGtkPad;
-typedef struct _GraphGtkPad GraphGtkPad;
-
-struct _GraphGtkNode;
-typedef struct _GraphGtkNode GraphGtkNode;
-
-typedef struct _GraphGtkView      GraphGtkView;
-typedef struct _GraphGtkViewClass GraphGtkViewClass;
-
 struct _GraphGtkViewClass
 {
   GtkDrawingAreaClass parent_class;
diff --git a/tests/simple_container.c b/tests/simple_container.c
index 2babbc1..7e738fd 100644
--- a/tests/simple_container.c
+++ b/tests/simple_container.c
@@ -2,6 +2,9 @@
 #include <graph-gtk-view.h>
 #include <graph-gtk-node.h>
 
+#include <glib.h>
+#include <glib/gi18n.h>
+
 static void menu_item_activated (GtkMenuItem*, gpointer);
 static void button_clicked(GtkButton*, gpointer);
 static void node_selected(GraphGtkView *view, GraphGtkNode *node, gpointer user_data);
@@ -25,7 +28,8 @@ main(gint argc,
   g_signal_connect(graphView, "nodes-connected", G_CALLBACK(nodes_connected), NULL);
   g_signal_connect(graphView, "nodes-disconnected", G_CALLBACK(nodes_disconnected), NULL);
 
-  GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
+  GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+  gtk_box_set_homogeneous(GTK_BOX (vbox), FALSE);
   gtk_container_add(GTK_CONTAINER(window), vbox);
 
   //Build the menu
@@ -75,8 +79,8 @@ static void menu_item_activated (GtkMenuItem* menu_item, gpointer data)
       GtkWidget* dialog = gtk_dialog_new_with_buttons ("Add Node",
                                                       GTK_WINDOW(gtk_widget_get_ancestor 
(GTK_WIDGET(menu_item), GTK_TYPE_WINDOW)),
                                                       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                      GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
-                                                      GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+                                                      _("_OK"), GTK_RESPONSE_ACCEPT,
+                                                      _("_CANCEL"), GTK_RESPONSE_REJECT,
                                                       NULL);
 
       gtk_window_set_default_size(GTK_WINDOW(dialog), 350, 80);
@@ -88,21 +92,26 @@ static void menu_item_activated (GtkMenuItem* menu_item, gpointer data)
       gtk_box_pack_start(GTK_BOX(vbox), name_label, FALSE, FALSE, 0);
       gtk_box_pack_start(GTK_BOX(vbox), name_entry, FALSE, FALSE, 0);
 
-      GtkWidget* columns = gtk_hbox_new(TRUE, 0);
+      GtkWidget *columns = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+      gtk_box_set_homogeneous(GTK_BOX (columns), FALSE);
       gtk_box_pack_start(GTK_BOX(vbox), columns, TRUE, TRUE, 0);
 
-      GtkWidget* left_column = gtk_vbox_new(FALSE, 0);
+      GtkWidget *left_column = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+      gtk_box_set_homogeneous(GTK_BOX (left_column), FALSE);
       gtk_box_pack_start(GTK_BOX(columns), left_column, TRUE, TRUE, 0);
       gtk_box_pack_start(GTK_BOX(left_column), gtk_label_new("Inputs"), FALSE, FALSE, 0);
 
-      GtkWidget* right_column = gtk_vbox_new(FALSE, 0);
+      GtkWidget *right_column = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+      gtk_box_set_homogeneous(GTK_BOX (right_column), FALSE);
       gtk_box_pack_start(GTK_BOX(columns), right_column, TRUE, TRUE, 0);
       gtk_box_pack_start(GTK_BOX(right_column), gtk_label_new("Outputs"), FALSE, FALSE, 0);
 
-      GtkWidget* inputs = gtk_vbox_new(FALSE, 0);
+      GtkWidget *inputs = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+      gtk_box_set_homogeneous(GTK_BOX (inputs), FALSE);
       gtk_box_pack_start(GTK_BOX(left_column), inputs, TRUE, TRUE, 0);
 
-      GtkWidget* outputs = gtk_vbox_new(FALSE, 0);
+      GtkWidget *outputs = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+      gtk_box_set_homogeneous(GTK_BOX (outputs), FALSE);
       gtk_box_pack_start(GTK_BOX(right_column), outputs, TRUE, TRUE, 0);
 
       GtkWidget* add_input = gtk_button_new_with_label("Add");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]