[glade3/offscreen-gtk3] gladeui: Move remaining placeholder drawing code to cairo



commit 07d1583f0480b9df9f0c1858d79c97f5e038af3f
Author: Johannes Schmid <jhs gnome org>
Date:   Mon Nov 15 14:49:47 2010 +0100

    gladeui: Move remaining placeholder drawing code to cairo
    
    gdk_window_set_back_pixmap is still missing and has to be implemented in cairo somehow

 gladeui/glade-placeholder.c |   21 +++++++++------------
 gladeui/glade-utils.c       |   41 +++++++++++++++++++++++++++--------------
 2 files changed, 36 insertions(+), 26 deletions(-)
---
diff --git a/gladeui/glade-placeholder.c b/gladeui/glade-placeholder.c
index 171fc69..84c2d95 100644
--- a/gladeui/glade-placeholder.c
+++ b/gladeui/glade-placeholder.c
@@ -263,6 +263,7 @@ glade_placeholder_draw (GtkWidget *widget, cairo_t *cr)
 	GtkStyle *style;
 	GdkColor *light;
 	GdkColor *dark;
+	gint      w, h;
 
 	g_return_val_if_fail (GLADE_IS_PLACEHOLDER (widget), FALSE);
 
@@ -270,21 +271,17 @@ glade_placeholder_draw (GtkWidget *widget, cairo_t *cr)
 	light = &style->light[GTK_STATE_NORMAL];
 	dark  = &style->dark[GTK_STATE_NORMAL];
 
-	cairo_set_line_width (cr, 1.0);
-	cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+	h = gtk_widget_get_allocated_height (widget);
+	w = gtk_widget_get_allocated_width (widget);
 
-	gdk_cairo_set_source_color (cr, light);
-	cairo_move_to (cr, 0, 0);
-	cairo_line_to (cr, 1, 0);
-	cairo_move_to (cr, 0, 0);
-	cairo_line_to (cr, 0, 1);
+	cairo_set_line_width (cr, 1.0);
 
-	gdk_cairo_set_source_color (cr, light);
-	cairo_move_to (cr, 0, 1);
-	cairo_line_to (cr, 1, 1);
-	cairo_line_to (cr, 1, 0);
+	glade_utils_cairo_draw_line (cr, light, 0, 0, w - 1, 0);
+	glade_utils_cairo_draw_line (cr, light, 0, 0, 0, h - 1);
+	glade_utils_cairo_draw_line (cr, dark, 0, h - 1, w - 1, h - 1);
+	glade_utils_cairo_draw_line (cr, dark, w - 1, 0, w - 1, h - 1);
 
-	glade_util_draw_selection_nodes (widget, cr);
+	glade_util_draw_selection_nodes (widget, cr);	
 
 	return FALSE;
 }
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index de28f90..f943e25 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -789,16 +789,30 @@ glade_util_can_draw_nodes (GtkWidget *sel_widget, GdkWindow *sel_win,
 void
 glade_util_draw_selection_nodes (GtkWidget* expose_widget, cairo_t *cr)
 {
-#if 0
-	GdkWindow   *expose_toplevel;
+	gint expose_win_x, expose_win_y;
+	gint expose_win_w, expose_win_h;
+	GdkWindow   *expose_win;
+	GdkWindow   *expose_toplevel;	
 	GdkColor *color;
 	GList *elem;
-	GtkAllocation expose_allocation;
+
+	cairo_save (cr);
+	
+	g_return_if_fail (GTK_IS_WIDGET (expose_widget));
 
 	color = &(gtk_widget_get_style (expose_widget)->black);
 
-	gtk_widget_get_allocation (expose_widget, &expose_allocation);
-	
+	/* Calculate the offset of the expose window within its toplevel. */
+	expose_toplevel = gtk_widget_get_window (gtk_widget_get_toplevel (expose_widget));
+	expose_win = gtk_widget_get_window (expose_widget);
+	glade_util_calculate_window_offset (expose_win,
+					    &expose_win_x,
+					    &expose_win_y,
+					    &expose_toplevel);
+
+	expose_win_w = gtk_widget_get_allocated_width (expose_widget);
+	expose_win_h = gtk_widget_get_allocated_height (expose_widget);
+
 	/* Step through all the selected widgets. */
 	for (elem = glade_util_selection; elem; elem = elem->next) {
 
@@ -807,10 +821,10 @@ glade_util_draw_selection_nodes (GtkWidget* expose_widget, cairo_t *cr)
 		gint sel_x, sel_y, x, y, w, h;
 
 		sel_widget = elem->data;
-		
+
 		if ((sel_win = glade_util_get_window_positioned_in (sel_widget)) == NULL)
 			continue;
-		
+
 		/* Calculate the offset of the selected widget's window
 		   within its toplevel. */
 		glade_util_calculate_window_offset (sel_win, &sel_x, &sel_y,
@@ -820,24 +834,23 @@ glade_util_draw_selection_nodes (GtkWidget* expose_widget, cairo_t *cr)
 		   event is in the same toplevel as the selected widget. */
 		if (expose_toplevel == sel_toplevel
 		    && glade_util_can_draw_nodes (sel_widget, sel_win,
-		                                  cr)) {
-		                                  GtkAllocation allocation;
+						  expose_win)) {
+			GtkAllocation allocation;
 
 			gtk_widget_get_allocation (sel_widget, &allocation);
-			x = sel_x + allocation.x - expose_allocation.x;
-			y = sel_y + allocation.y - expose_allocation.y;
+			x = sel_x + allocation.x - expose_win_x;
+			y = sel_y + allocation.y - expose_win_y;
 			w = allocation.width;
 			h = allocation.height;
 
 			/* Draw the selection nodes if they intersect the
 			   expose window bounds. */
-			if (x < expose_allocation.width && x + w >= 0
-			    && y < expose_allocation.height && y + h >= 0) {
+			if (x < expose_win_w && x + w >= 0
+			    && y < expose_win_h && y + h >= 0) {
 				glade_util_draw_nodes (cr, color, x, y, w, h);
 			}
 		}
 	}
-#endif
 }
 
 /**



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