[graph-gtk] Replaced instances of GSList with GList
- From: Isaac Wagner <isaacbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [graph-gtk] Replaced instances of GSList with GList
- Date: Tue, 31 Jul 2012 11:22:19 +0000 (UTC)
commit 2abd705ea4af2bc30b36fcb0d20b11ae6fcc7cdb
Author: Isaac Wagner <isaacbw src gnome org>
Date: Tue Jul 31 07:16:16 2012 -0400
Replaced instances of GSList with GList
graph-gtk/graph-gtk-node.c | 28 +++++++-------
graph-gtk/graph-gtk-node.h | 10 +++---
graph-gtk/graph-gtk-pad.c | 14 ++++----
graph-gtk/graph-gtk-pad.h | 2 +-
graph-gtk/graph-gtk-view.c | 83 +++++++++++++++++++++++++++++--------------
graph-gtk/graph-gtk-view.h | 9 +++--
6 files changed, 89 insertions(+), 57 deletions(-)
---
diff --git a/graph-gtk/graph-gtk-node.c b/graph-gtk/graph-gtk-node.c
index 5c9ff54..0644680 100644
--- a/graph-gtk/graph-gtk-node.c
+++ b/graph-gtk/graph-gtk-node.c
@@ -244,7 +244,7 @@ graph_gtk_node_render_default(GraphGtkNode* self, cairo_t* cr)
cairo_move_to(cr, (self->x+self->offset_x)+4, (self->y+self->offset_y)+13);
cairo_show_text(cr, self->name);
- GSList *pad;
+ GList *pad;
for(pad = graph_gtk_node_get_input_pads(self); pad != NULL; pad = pad->next)
{
graph_gtk_pad_render((GraphGtkPad*)pad->data, cr);
@@ -308,22 +308,22 @@ graph_gtk_node_render(GraphGtkNode* self, cairo_t* cairo)
GRAPH_GTK_NODE_GET_CLASS(self)->render_node(self, cairo);
}
-GSList*
+GList*
graph_gtk_node_get_pads(GraphGtkNode* self)
{
- return g_slist_concat(self->input_pads, self->output_pads);
+ return g_list_concat(self->input_pads, self->output_pads);
}
-GSList*
+GList*
graph_gtk_node_get_input_pads(GraphGtkNode* self)
{
- return g_slist_copy(self->input_pads);
+ return g_list_copy(self->input_pads);
}
-GSList*
+GList*
graph_gtk_node_get_output_pads(GraphGtkNode* self)
{
- return g_slist_copy(self->output_pads);
+ return g_list_copy(self->output_pads);
}
void
@@ -331,7 +331,7 @@ graph_gtk_node_connect_to(GraphGtkNode* source, const gchar* output_pad, GraphGt
{
GraphGtkPad *source_pad = NULL, *sink_pad = NULL;
- GSList* list;
+ GList* list;
for(list = graph_gtk_node_get_pads(source); list != NULL; list++)
{
GraphGtkPad *pad = (GraphGtkPad*)list->data;
@@ -372,7 +372,7 @@ graph_gtk_node_recalculate_size(GraphGtkNode* self)
//Calculate width
gdouble longest_in = 0.0, longest_out = 0.0;
- GSList* list;
+ GList* list;
for(list = self->output_pads; list != NULL; list = list->next) {
GraphGtkPad *pad = (GraphGtkPad*)list->data;
longest_in = MAX(longest_in, graph_gtk_pad_get_width(pad));
@@ -470,22 +470,22 @@ graph_gtk_node_add_pad(GraphGtkNode* self, const gchar* pad_name, gboolean outpu
{
if(output)
{
- GSList* list;
+ GList* list;
for(list = self->output_pads; list != NULL && g_strcmp0(((GraphGtkPad*)list->data)->name, pad_name); list = list->next);
if(!list) {
GraphGtkPad* pad = graph_gtk_pad_new(pad_name, TRUE);
pad->node = self;
- self->output_pads = g_slist_append(self->output_pads, pad);
+ self->output_pads = g_list_append(self->output_pads, pad);
}
}
else
{
- GSList* list;
+ GList* list;
for(list = self->input_pads; list != NULL && g_strcmp0(((GraphGtkPad*)list->data)->name, pad_name); list = list->next);
if(!list) {
GraphGtkPad* pad = graph_gtk_pad_new(pad_name, FALSE);
pad->node = self;
- self->input_pads = g_slist_append(self->input_pads, pad);
+ self->input_pads = g_list_append(self->input_pads, pad);
}
}
@@ -507,7 +507,7 @@ graph_gtk_node_is_within(GraphGtkNode* self, int x, int y)
GraphGtkPad*
graph_gtk_node_is_on_pad(GraphGtkNode* self, int x, int y)
{
- GSList *list;
+ GList *list;
int px, py;
for(list = graph_gtk_node_get_input_pads(self); list != NULL; list = list->next)
diff --git a/graph-gtk/graph-gtk-node.h b/graph-gtk/graph-gtk-node.h
index e095ec9..e02d066 100644
--- a/graph-gtk/graph-gtk-node.h
+++ b/graph-gtk/graph-gtk-node.h
@@ -47,8 +47,8 @@ struct _GraphGtkNode
GraphGtkView *view;
- GSList *input_pads;
- GSList *output_pads;
+ GList *input_pads;
+ GList *output_pads;
const gchar *name;
@@ -74,9 +74,9 @@ void graph_gtk_node_set_name(GraphGtkNode* self, const gchar* name);
const gchar* graph_gtk_node_get_name(GraphGtkNode* self);
void graph_gtk_node_render(GraphGtkNode* self, cairo_t* cairo);
void graph_gtk_node_add_pad(GraphGtkNode* self, const gchar* pad_name, gboolean output);
-GSList* graph_gtk_node_get_pads(GraphGtkNode* self);
-GSList* graph_gtk_node_get_input_pads(GraphGtkNode* self);
-GSList* graph_gtk_node_get_output_pads(GraphGtkNode* self);
+GList* graph_gtk_node_get_pads(GraphGtkNode* self);
+GList* graph_gtk_node_get_input_pads(GraphGtkNode* self);
+GList* graph_gtk_node_get_output_pads(GraphGtkNode* self);
void graph_gtk_node_connect_to(GraphGtkNode* source, const gchar* output_pad, GraphGtkNode* sink, const gchar* input_pad);
gboolean graph_gtk_node_recalculate_size(GraphGtkNode* self);
gboolean graph_gtk_node_is_within(GraphGtkNode* self, int x, int y); //check whether this position is within the node
diff --git a/graph-gtk/graph-gtk-pad.c b/graph-gtk/graph-gtk-pad.c
index a4720a6..553232c 100644
--- a/graph-gtk/graph-gtk-pad.c
+++ b/graph-gtk/graph-gtk-pad.c
@@ -48,7 +48,7 @@ graph_gtk_pad_finalize (GObject *object)
static void
graph_gtk_pad_default_render(GraphGtkPad* self, cairo_t* cr)
{
- gboolean connected = (g_slist_length(self->connections) > 0);
+ gboolean connected = (g_list_length(self->connections) > 0);
int x, y;
graph_gtk_pad_get_position(self, &x, &y);
@@ -151,7 +151,7 @@ graph_gtk_pad_is_connected_to(GraphGtkPad* self, GraphGtkPad* other)
if((self->is_output && other->is_output) || (!self->is_output && !other->is_output))
return FALSE;
- GSList* list;
+ GList* list;
for(list = self->connections; list != NULL; list = list->next)
{
GraphGtkConnection *connection = (GraphGtkConnection*)list->data;
@@ -209,10 +209,10 @@ graph_gtk_pad_connect_to(GraphGtkPad* source, GraphGtkPad* sink)
{
GraphGtkConnection *connection = graph_gtk_connection_new(source, sink);
- source->connections = g_slist_append(source->connections, connection);
+ source->connections = g_list_append(source->connections, connection);
graph_gtk_pad_disconnect(sink);
- sink->connections = g_slist_append(sink->connections, connection);
+ sink->connections = g_list_append(sink->connections, connection);
}
}
@@ -220,7 +220,7 @@ graph_gtk_pad_connect_to(GraphGtkPad* source, GraphGtkPad* sink)
void
graph_gtk_pad_disconnect(GraphGtkPad* self)
{
- GSList* list;
+ GList* list;
for(list = self->connections; list != NULL; list = list->next)
{
GraphGtkConnection *connection = (GraphGtkConnection*)list->data;
@@ -242,11 +242,11 @@ graph_gtk_pad_disconnect(GraphGtkPad* self)
self->node, self->name);
}
- other->connections = g_slist_remove(other->connections, connection);
+ other->connections = g_list_remove(other->connections, connection);
g_object_unref(connection);
}
- g_slist_free(self->connections);
+ g_list_free(self->connections);
self->connections = NULL;
}
diff --git a/graph-gtk/graph-gtk-pad.h b/graph-gtk/graph-gtk-pad.h
index 8d902c4..2ab34ea 100644
--- a/graph-gtk/graph-gtk-pad.h
+++ b/graph-gtk/graph-gtk-pad.h
@@ -49,7 +49,7 @@ struct _GraphGtkPad
gint rel_x, rel_y; //coordinates of the center this pad relative to the containing node's coordinates. These values are set by the containing node when the node is constructed and if/when the node is resized. It is up to the containing node to made sure these coordinates are up to date
gboolean is_output; //input pads can only have one connection. New connections replace old connections
- GSList* connections; //each GraphGtkConnection* is referenced twice, once each by the GraphGtkPads at either end
+ GList* connections; //each GraphGtkConnection* is referenced twice, once each by the GraphGtkPads at either end
};
GType graph_gtk_pad_get_type (void) G_GNUC_CONST;
diff --git a/graph-gtk/graph-gtk-view.c b/graph-gtk/graph-gtk-view.c
index 33f4dc5..5efb6cb 100644
--- a/graph-gtk/graph-gtk-view.c
+++ b/graph-gtk/graph-gtk-view.c
@@ -119,6 +119,7 @@ graph_gtk_view_init (GraphGtkView *self)
gtk_widget_set_can_focus(GTK_WIDGET(self), TRUE);
self->pan_x = 0;
self->pan_y = 0;
+ self->bg = NULL;
}
static void
@@ -160,6 +161,27 @@ graph_gtk_view_draw(GtkWidget *widget, cairo_t* cr)
cairo_set_source_rgb(cr, 124.0/256.0, 124.0/256.0, 124.0/256.0);
cairo_paint(cr);
+ if(view->bg)
+ {
+ gdouble bg_w = cairo_image_surface_get_width(view->bg);
+ gdouble bg_h = cairo_image_surface_get_height(view->bg);
+
+
+ gint width = gdk_window_get_width(widget->window);
+ gint height = gdk_window_get_height(widget->window);
+
+ cairo_pattern_t *pattern = cairo_pattern_create_for_surface(view->bg);
+ cairo_matrix_t transform;
+ cairo_matrix_init_translate(&transform, -(width/2-bg_w/2), -(height/2-bg_h/2));
+ cairo_pattern_set_matrix(pattern, &transform);
+
+ cairo_set_source(cr, pattern);
+ cairo_rectangle(cr, width/2-bg_w/2, height/2-bg_h/2, bg_w, bg_h);
+ cairo_fill(cr);
+
+ cairo_pattern_destroy(pattern);
+ }
+
cairo_translate(cr, -view->pan_x, -view->pan_y);
if(view->is_mouse_panning)
{
@@ -167,16 +189,16 @@ graph_gtk_view_draw(GtkWidget *widget, cairo_t* cr)
}
//render the graph_gtk_view
- GSList* nodes;
+ GList* nodes;
for(nodes = view->nodes; nodes != NULL; nodes = nodes->next)
{
GraphGtkNode *node = (GraphGtkNode*)nodes->data;
- GSList *pads;
+ GList *pads;
for(pads = graph_gtk_node_get_input_pads(node); pads != NULL; pads = pads->next)
{
GraphGtkPad *pad = (GraphGtkPad*)pads->data;
- GSList *connections;
+ GList *connections;
for(connections = pad->connections; connections != NULL; connections = connections->next)
{
GraphGtkConnection *connection = (GraphGtkConnection*)connections->data;
@@ -187,7 +209,7 @@ graph_gtk_view_draw(GtkWidget *widget, cairo_t* cr)
for(pads = graph_gtk_node_get_output_pads(node); pads != NULL; pads = pads->next)
{
GraphGtkPad *pad = (GraphGtkPad*)pads->data;
- GSList *connections;
+ GList *connections;
for(connections = pad->connections; connections != NULL; connections = connections->next)
{
GraphGtkConnection *connection = (GraphGtkConnection*)connections->data;
@@ -196,7 +218,7 @@ graph_gtk_view_draw(GtkWidget *widget, cairo_t* cr)
}
}
- GSList* list;
+ GList* list;
for(list = view->nodes; list != NULL; list = list->next)
{
GraphGtkNode* node = (GraphGtkNode*)list->data;
@@ -229,8 +251,8 @@ graph_gtk_view_button_pressed(GtkWidget* widget, GdkEventButton* event)
REDRAW();
//TODO: shift click to select multiple nodes
- GSList *deselect = g_slist_copy(self->selected_nodes);
- GSList* nodes;
+ GList *deselect = g_list_copy(self->selected_nodes);
+ GList* nodes;
for(nodes = self->selected_nodes; nodes != NULL; nodes = nodes->next)
{
GraphGtkNode *node = nodes->data;
@@ -238,10 +260,10 @@ graph_gtk_view_button_pressed(GtkWidget* widget, GdkEventButton* event)
node->is_selected = FALSE;
}
- g_slist_free(self->selected_nodes);
+ g_list_free(self->selected_nodes);
self->selected_nodes = NULL;
- GSList *select = NULL;
+ GList *select = NULL;
for(nodes = self->nodes; nodes != NULL; nodes = nodes->next)
{
GraphGtkNode *node = (GraphGtkNode*)nodes->data;
@@ -257,9 +279,9 @@ graph_gtk_view_button_pressed(GtkWidget* widget, GdkEventButton* event)
else if(graph_gtk_node_is_within(node, event->x, event->y))
{
node->is_selected = TRUE;
- deselect = g_slist_remove(deselect, node);
- select = g_slist_append(select, node);
- self->selected_nodes = g_slist_append(self->selected_nodes, node);
+ deselect = g_list_remove(deselect, node);
+ select = g_list_append(select, node);
+ self->selected_nodes = g_list_append(self->selected_nodes, node);
self->is_mouse_dragging = TRUE;
self->drag_begin_x = event->x;
@@ -288,8 +310,8 @@ graph_gtk_view_button_pressed(GtkWidget* widget, GdkEventButton* event)
}
}
- g_slist_free(deselect);
- g_slist_free(select);
+ g_list_free(deselect);
+ g_list_free(select);
}
else if(event->button == 3)
{
@@ -314,7 +336,7 @@ graph_gtk_view_button_released(GtkWidget* widget, GdkEventButton* event)
self->is_mouse_dragging = FALSE;
- GSList* nodes;
+ GList* nodes;
for(nodes = self->selected_nodes; nodes != NULL; nodes = nodes->next)
{
GraphGtkNode *node = nodes->data;
@@ -333,7 +355,7 @@ graph_gtk_view_button_released(GtkWidget* widget, GdkEventButton* event)
self->is_mouse_connecting = FALSE;
- GSList *nodes;
+ GList *nodes;
for(nodes = self->nodes; nodes != NULL; nodes = nodes->next)
{
GraphGtkNode *node = (GraphGtkNode*)nodes->data;
@@ -389,7 +411,7 @@ graph_gtk_view_mouse_moved(GtkWidget* widget, GdkEventMotion* event)
if(self->is_mouse_dragging)
{
- GSList* nodes;
+ GList* nodes;
for(nodes = self->selected_nodes; nodes != NULL; nodes = nodes->next)
{
GraphGtkNode *node = nodes->data;
@@ -412,10 +434,10 @@ graph_gtk_view_new()
void
graph_gtk_view_add_node(GraphGtkView* self, GraphGtkNode* node)
{
- if(!g_slist_find(self->nodes, node))
+ if(!g_list_find(self->nodes, node))
{
g_object_ref_sink(G_OBJECT(node)); //is sink the right thing to do here?
- self->nodes = g_slist_append(self->nodes, node);
+ self->nodes = g_list_append(self->nodes, node);
node->view = self;
REDRAW();
@@ -428,18 +450,18 @@ graph_gtk_view_remove_selected_nodes(GraphGtkView* self)
while(self->selected_nodes)
{
graph_gtk_view_remove_node(self, (GraphGtkNode*)self->selected_nodes->data);
- self->selected_nodes = g_slist_remove(self->selected_nodes, (GraphGtkNode*)self->selected_nodes->data);
+ self->selected_nodes = g_list_remove(self->selected_nodes, (GraphGtkNode*)self->selected_nodes->data);
}
}
void
graph_gtk_view_remove_node(GraphGtkView* self, GraphGtkNode* node)
{
- if(g_slist_find(self->nodes, node))
+ if(g_list_find(self->nodes, node))
{
- self->nodes = g_slist_remove(self->nodes, node);
+ self->nodes = g_list_remove(self->nodes, node);
- GSList *pad;
+ GList *pad;
for(pad = graph_gtk_node_get_input_pads(node); pad != NULL; pad = pad->next)
{
graph_gtk_pad_disconnect((GraphGtkPad*)(pad->data));
@@ -459,20 +481,27 @@ graph_gtk_view_remove_node(GraphGtkView* self, GraphGtkNode* node)
void
graph_gtk_view_clear(GraphGtkView* self)
{
- GSList* list;
+ GList* list;
for(list = self->nodes; list != NULL; list = list->next)
{
g_object_unref(G_OBJECT(list->data));
}
- g_slist_free(self->nodes);
+ g_list_free(self->nodes);
self->nodes = NULL;
REDRAW();
}
-GSList*
+GList*
graph_gtk_view_get_nodes(GraphGtkView* self)
{
- return g_slist_copy(self->nodes);
+ return g_list_copy(self->nodes);
+}
+
+void
+graph_gtk_view_set_bg(GraphGtkView* self, cairo_surface_t* bg)
+{
+ self->bg = bg;
+ REDRAW();
}
diff --git a/graph-gtk/graph-gtk-view.h b/graph-gtk/graph-gtk-view.h
index edf0de3..a8b1c07 100644
--- a/graph-gtk/graph-gtk-view.h
+++ b/graph-gtk/graph-gtk-view.h
@@ -53,10 +53,10 @@ struct _GraphGtkView
{
GtkDrawingArea parent;
- GSList* nodes;
+ GList* nodes;
/* private state management */
- GSList* selected_nodes; //list of currently selected nodes
+ GList* selected_nodes; //list of currently selected nodes
gboolean is_mouse_connecting;
GraphGtkPad* pad_connecting_from;
@@ -69,6 +69,8 @@ struct _GraphGtkView
gboolean is_mouse_panning; //mouse was pressed on the canvas and has not yet been released
gint pan_x, pan_y; //current pan offset
gint pan_begin_x, pan_begin_y;
+
+ cairo_surface_t *bg;
};
GType graph_gtk_view_get_type (void) G_GNUC_CONST;
@@ -78,7 +80,8 @@ void graph_gtk_view_add_node(GraphGtkView* self, GraphGtkNode* node);
void graph_gtk_view_remove_node(GraphGtkView* self, GraphGtkNode* node);
void graph_gtk_view_remove_selected_nodes(GraphGtkView* self);
void graph_gtk_view_clear(GraphGtkView* self);
-GSList* graph_gtk_view_get_nodes(GraphGtkView* self);
+GList* graph_gtk_view_get_nodes(GraphGtkView* self);
+void graph_gtk_view_set_bg(GraphGtkView* self, cairo_surface_t* bg); //NULL means no background should be rendered
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]