From 8d2b74d22d0a734e9ff90f73d2e92dab5a4e6c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Mon, 12 Sep 2011 18:35:04 +0100 Subject: [PATCH 2/6] util/show-contour: Use accerssor functions instead direct access --- util/show-contour.c | 69 +++++++++++++++++++++++++++++++-------------------- 1 files changed, 42 insertions(+), 27 deletions(-) diff --git a/util/show-contour.c b/util/show-contour.c index 6e39446..d5c52a0 100644 --- a/util/show-contour.c +++ b/util/show-contour.c @@ -47,10 +47,14 @@ G_DEFINE_TYPE (TrapView, trap_view, GTK_TYPE_WIDGET) static cairo_surface_t * pixmap_create (TrapView *self, cairo_surface_t *target) { + GtkAllocation allocation; + + gtk_widget_get_allocation (&(self->widget), &allocation); + cairo_surface_t *surface = cairo_surface_create_similar (target, CAIRO_CONTENT_COLOR, - self->widget.allocation.width, - self->widget.allocation.height); + allocation.width, + allocation.height); cairo_t *cr = cairo_create (surface); contour_t *contour; gdouble sf_x, sf_y, sf; @@ -71,11 +75,11 @@ pixmap_create (TrapView *self, cairo_surface_t *target) mid = (extents.p2.x + extents.p1.x) / 2.; dim = (extents.p2.x - extents.p1.x) / 2. * 1.25; - sf_x = self->widget.allocation.width / dim / 2; + sf_x = allocation.width / dim / 2; mid = (extents.p2.y + extents.p1.y) / 2.; dim = (extents.p2.y - extents.p1.y) / 2. * 1.25; - sf_y = self->widget.allocation.height / dim / 2; + sf_y = allocation.height / dim / 2; sf = MIN (sf_x, sf_y); @@ -146,21 +150,24 @@ static void trap_view_draw (TrapView *self, cairo_t *cr) { contour_t *contour; + GtkAllocation allocation; gdouble sf_x, sf_y, sf; gdouble mid, dim; gdouble x0, y0; int n; box_t extents; + gtk_widget_get_allocation (&(self->widget), &allocation); + extents = self->extents; mid = (extents.p2.x + extents.p1.x) / 2.; dim = (extents.p2.x - extents.p1.x) / 2. * 1.25; - sf_x = self->widget.allocation.width / dim / 2; + sf_x = allocation.width / dim / 2; mid = (extents.p2.y + extents.p1.y) / 2.; dim = (extents.p2.y - extents.p1.y) / 2. * 1.25; - sf_y = self->widget.allocation.height / dim / 2; + sf_y = allocation.height / dim / 2; sf = MIN (sf_x, sf_y); @@ -171,13 +178,13 @@ trap_view_draw (TrapView *self, cairo_t *cr) dim = sf_y / sf * (extents.p2.y - extents.p1.y) / 2. * 1.25; y0 = mid - dim; - if (self->pixmap_width != self->widget.allocation.width || - self->pixmap_height != self->widget.allocation.height) + if (self->pixmap_width != allocation.width || + self->pixmap_height != allocation.height) { cairo_surface_destroy (self->pixmap); self->pixmap = pixmap_create (self, cairo_get_target (cr)); - self->pixmap_width = self->widget.allocation.width; - self->pixmap_height = self->widget.allocation.height; + self->pixmap_width = allocation.width; + self->pixmap_height = allocation.height; } cairo_set_source_surface (cr, self->pixmap, 0, 0); @@ -194,15 +201,15 @@ trap_view_draw (TrapView *self, cairo_t *cr) int mag_y = self->mag_y; if (1) { - if (self->px + size < self->widget.allocation.width/2) + if (self->px + size < allocation.width/2) mag_x = self->px + size/4; else mag_x = self->px - size/4 - size; mag_y = self->py - size/2; if (mag_y < 0) mag_y = 0; - if (mag_y + size > self->widget.allocation.height) - mag_y = self->widget.allocation.height - size; + if (mag_y + size > allocation.height) + mag_y = allocation.height - size; } cairo_save (cr); { @@ -375,7 +382,7 @@ trap_view_expose (GtkWidget *w, GdkEventExpose *ev) TrapView *self = (TrapView *) w; cairo_t *cr; - cr = gdk_cairo_create (w->window); + cr = gdk_cairo_create (gtk_widget_get_window (w)); gdk_cairo_region (cr, ev->region); cairo_clip (cr); @@ -477,15 +484,19 @@ trap_view_motion (GtkWidget *w, GdkEventMotion *ev) static void trap_view_realize (GtkWidget *widget) { + GtkAllocation allocation; GdkWindowAttr attributes; + GdkWindow *gdk_window; gtk_widget_set_realized (widget, TRUE); + gtk_widget_get_allocation (widget, &allocation); + attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; + attributes.x = allocation.x; + attributes.y = allocation.y; + attributes.width = allocation.width; + attributes.height = allocation.height; attributes.wclass = GDK_INPUT_OUTPUT; attributes.visual = gtk_widget_get_visual (widget); attributes.colormap = gtk_widget_get_colormap (widget); @@ -498,25 +509,29 @@ trap_view_realize (GtkWidget *widget) GDK_BUTTON_MOTION_MASK | GDK_EXPOSURE_MASK; - widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), - &attributes, - GDK_WA_X | GDK_WA_Y | - GDK_WA_VISUAL | GDK_WA_COLORMAP); - gdk_window_set_user_data (widget->window, widget); + gdk_window = gdk_window_new (gtk_widget_get_parent_window (widget), + &attributes, + GDK_WA_X | GDK_WA_Y | + GDK_WA_VISUAL | GDK_WA_COLORMAP); + gtk_widget_set_window (widget, gdk_window); + gdk_window_set_user_data (gdk_window, widget); - widget->style = gtk_style_attach (widget->style, widget->window); - gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); + gtk_widget_style_attach (widget); + gtk_style_set_background (gtk_widget_get_style (widget), gdk_window, GTK_STATE_NORMAL); } static void trap_view_size_allocate (GtkWidget *w, GdkRectangle *r) { TrapView *self = (TrapView *) w; + GtkAllocation allocation; GTK_WIDGET_CLASS (trap_view_parent_class)->size_allocate (w, r); - self->mag_x = w->allocation.width - self->mag_size - 10; - self->mag_y = w->allocation.height - self->mag_size - 10; + gtk_widget_get_allocation (w, &allocation); + + self->mag_x = allocation.width - self->mag_size - 10; + self->mag_y = allocation.height - self->mag_size - 10; } static void -- 1.7.5.4