[graph-gtk] Can pan the view with the right mouse button
- From: Isaac Wagner <isaacbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [graph-gtk] Can pan the view with the right mouse button
- Date: Tue, 31 Jul 2012 11:22:14 +0000 (UTC)
commit bd0af37de7cf4c4c3fb1813a780b6a31f5ea0b67
Author: Isaac Wagner <isaacbw src gnome org>
Date: Mon Jul 30 11:54:57 2012 -0400
Can pan the view with the right mouse button
graph-gtk/graph-gtk-node.c | 8 ++-
graph-gtk/graph-gtk-view.c | 111 ++++++++++++++++++++++++++------------------
graph-gtk/graph-gtk-view.h | 1 +
3 files changed, 71 insertions(+), 49 deletions(-)
---
diff --git a/graph-gtk/graph-gtk-node.c b/graph-gtk/graph-gtk-node.c
index 278aa73..5c9ff54 100644
--- a/graph-gtk/graph-gtk-node.c
+++ b/graph-gtk/graph-gtk-node.c
@@ -255,7 +255,7 @@ graph_gtk_node_render_default(GraphGtkNode* self, cairo_t* cr)
graph_gtk_pad_render((GraphGtkPad*)pad->data, cr);
}
- if(self->show_image)
+ if(self->show_image && self->image)
{
//cairo_set_source_surface(cr, self->image, 0, 0);
gdouble surface_w = cairo_image_surface_get_width(self->image);
@@ -365,6 +365,8 @@ graph_gtk_node_recalculate_size(GraphGtkNode* self)
if(!view)
return FALSE;
+ gtk_widget_queue_draw(GTK_WIDGET(view));
+
self->height = 30;
//Calculate width
@@ -393,9 +395,9 @@ graph_gtk_node_recalculate_size(GraphGtkNode* self)
self->width = MAX(extents.width+20, longest_in+longest_out+45);
- gdouble image_w, image_h;
+ gdouble image_w = 0, image_h = 0;
- if(self->show_image)
+ if(self->show_image && self->image)
{
gdouble surface_w = cairo_image_surface_get_width(self->image);
gdouble surface_h = cairo_image_surface_get_height(self->image);
diff --git a/graph-gtk/graph-gtk-view.c b/graph-gtk/graph-gtk-view.c
index cce5d8b..33f4dc5 100644
--- a/graph-gtk/graph-gtk-view.c
+++ b/graph-gtk/graph-gtk-view.c
@@ -117,6 +117,8 @@ graph_gtk_view_init (GraphGtkView *self)
GDK_KEY_RELEASE_MASK);
gtk_widget_set_can_focus(GTK_WIDGET(self), TRUE);
+ self->pan_x = 0;
+ self->pan_y = 0;
}
static void
@@ -155,15 +157,15 @@ graph_gtk_view_draw(GtkWidget *widget, cairo_t* cr)
{
GraphGtkView *view = GRAPH_GTK_VIEW(widget);
- /*
- Need to figure out a clean way of letting the user render a custom background, such as the
- result of the combined graph operations. This should either be a signal or simply let the
- user set a cairo surface property on the GeglGtkView. For now just render a solid grey background
- */
-
cairo_set_source_rgb(cr, 124.0/256.0, 124.0/256.0, 124.0/256.0);
cairo_paint(cr);
+ cairo_translate(cr, -view->pan_x, -view->pan_y);
+ if(view->is_mouse_panning)
+ {
+ cairo_translate(cr, -(view->pan_begin_x-view->mouse_x), -(view->pan_begin_y-view->mouse_y));
+ }
+
//render the graph_gtk_view
GSList* nodes;
for(nodes = view->nodes; nodes != NULL; nodes = nodes->next)
@@ -289,7 +291,12 @@ graph_gtk_view_button_pressed(GtkWidget* widget, GdkEventButton* event)
g_slist_free(deselect);
g_slist_free(select);
}
-
+ else if(event->button == 3)
+ {
+ self->is_mouse_panning = TRUE;
+ self->pan_begin_x = event->x;
+ self->pan_begin_y = event->y;
+ }
return FALSE;
}
@@ -299,58 +306,70 @@ graph_gtk_view_button_released(GtkWidget* widget, GdkEventButton* event)
{
GraphGtkView *self = GRAPH_GTK_VIEW(widget);
- if(self->is_mouse_dragging)
+ if(event->button == 1)
{
- REDRAW();
+ if(self->is_mouse_dragging)
+ {
+ REDRAW();
- self->is_mouse_dragging = FALSE;
+ self->is_mouse_dragging = FALSE;
- GSList* nodes;
- for(nodes = self->selected_nodes; nodes != NULL; nodes = nodes->next)
- {
- GraphGtkNode *node = nodes->data;
- if(node->is_selected)
+ GSList* nodes;
+ for(nodes = self->selected_nodes; nodes != NULL; nodes = nodes->next)
{
- node->x += event->x-self->drag_begin_x;
- node->y += event->y-self->drag_begin_y;
- node->offset_x = 0;
- node->offset_y = 0;
+ GraphGtkNode *node = nodes->data;
+ if(node->is_selected)
+ {
+ node->x += event->x-self->drag_begin_x;
+ node->y += event->y-self->drag_begin_y;
+ node->offset_x = 0;
+ node->offset_y = 0;
+ }
}
}
- }
- else if(self->is_mouse_connecting)
- {
- REDRAW();
-
- self->is_mouse_connecting = FALSE;
-
- GSList *nodes;
- for(nodes = self->nodes; nodes != NULL; nodes = nodes->next)
+ else if(self->is_mouse_connecting)
{
- GraphGtkNode *node = (GraphGtkNode*)nodes->data;
- GraphGtkPad *pad;
+ REDRAW();
- if(pad = graph_gtk_node_is_on_pad(node, event->x, event->y))
+ self->is_mouse_connecting = FALSE;
+
+ GSList *nodes;
+ for(nodes = self->nodes; nodes != NULL; nodes = nodes->next)
{
- REDRAW();
- self->is_mouse_connecting = FALSE;
- if(self->pad_connecting_from->is_output)
- {
- graph_gtk_pad_connect_to(self->pad_connecting_from, pad);
- g_signal_emit_by_name(self, "nodes-connected",
- self->pad_connecting_from->node, self->pad_connecting_from->name,
- pad->node, pad->name);
- }
- else
+ GraphGtkNode *node = (GraphGtkNode*)nodes->data;
+ GraphGtkPad *pad;
+
+ if(pad = graph_gtk_node_is_on_pad(node, event->x, event->y))
{
- graph_gtk_pad_connect_to(pad, self->pad_connecting_from);
- g_signal_emit_by_name(self, "nodes-connected",
- pad->node, pad->name,
- self->pad_connecting_from->node, self->pad_connecting_from->name);
+ REDRAW();
+ self->is_mouse_connecting = FALSE;
+ if(self->pad_connecting_from->is_output)
+ {
+ graph_gtk_pad_connect_to(self->pad_connecting_from, pad);
+ g_signal_emit_by_name(self, "nodes-connected",
+ self->pad_connecting_from->node, self->pad_connecting_from->name,
+ pad->node, pad->name);
+ }
+ else
+ {
+ graph_gtk_pad_connect_to(pad, self->pad_connecting_from);
+ g_signal_emit_by_name(self, "nodes-connected",
+ pad->node, pad->name,
+ self->pad_connecting_from->node, self->pad_connecting_from->name);
+ }
}
}
}
}
+ else if(event->button == 3)
+ {
+ if(self->is_mouse_panning)
+ {
+ self->is_mouse_panning = FALSE;
+ self->pan_x += self->pan_begin_x-self->mouse_x;
+ self->pan_y += self->pan_begin_y-self->mouse_y;
+ }
+ }
return FALSE;
}
@@ -363,7 +382,7 @@ graph_gtk_view_mouse_moved(GtkWidget* widget, GdkEventMotion* event)
self->mouse_x = event->x;
self->mouse_y = event->y;
- if(self->is_mouse_connecting)
+ if(self->is_mouse_connecting || self->is_mouse_panning)
{
REDRAW();
}
diff --git a/graph-gtk/graph-gtk-view.h b/graph-gtk/graph-gtk-view.h
index 6cf6b07..edf0de3 100644
--- a/graph-gtk/graph-gtk-view.h
+++ b/graph-gtk/graph-gtk-view.h
@@ -68,6 +68,7 @@ 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;
};
GType graph_gtk_view_get_type (void) G_GNUC_CONST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]