/** * ppg_ruler_expose_event: * @ruler: (in): A #PpgRuler. * * Handle the "expose-event" for the widget. Blit the background and position * arrow to the surface. * * Returns: None. * Side effects: None. */ static gboolean ppg_ruler_expose_event (GtkWidget *widget, GdkEventExpose *expose) { PpgRuler *ruler = (PpgRuler *)widget; PpgRulerPrivate *priv; GtkAllocation alloc; cairo_t *cr; gint x; gint y; g_return_val_if_fail(PPG_IS_RULER(ruler), FALSE); GTK_WIDGET_CLASS(ppg_ruler_parent_class)->expose_event(widget, expose); priv = ruler->priv; gtk_widget_get_allocation(widget, &alloc); cr = gdk_cairo_create(expose->window); /* * Clip to exposure region. */ gdk_cairo_rectangle(cr, &expose->area); cairo_clip(cr); /* * Render the contents immediately if needed. */ if (priv->dirty) { ppg_ruler_draw_arrow(ruler); ppg_ruler_draw_ruler(ruler); priv->dirty = FALSE; } /* * Blit the background to the surface. */ cairo_rectangle(cr, 0, 0, alloc.width, alloc.height); gdk_cairo_set_source_pixmap(cr, priv->ruler, 0, 0); cairo_fill(cr); /* * Blit the arrow to the surface. */ x = (gint)(((priv->pos - priv->lower) / (priv->upper - priv->lower) * alloc.width) - (ARROW_SIZE / 2.0)); y = alloc.height - ARROW_SIZE - 1; gdk_cairo_set_source_pixmap(cr, priv->arrow, x, y); cairo_rectangle(cr, x, y, ARROW_SIZE, ARROW_SIZE); cairo_fill(cr); /* * Cleanup. */ cairo_destroy(cr); return FALSE; }
/** * ppg_ruler_draw: * @ruler: (in): A #PpgRuler. * @cr: (in): A #cairo_t to draw to. * * Handle the "draw" event for the widget. Blit the background and position * arrow to the surface. * * Returns: FALSE always. * Side effects: None. */ static gboolean ppg_ruler_draw (GtkWidget *widget, cairo_t *cr) { PpgRuler *ruler = (PpgRuler *)widget; PpgRulerPrivate *priv; GtkAllocation alloc; gboolean ret; gint x; gint y; g_return_val_if_fail(PPG_IS_RULER(ruler), FALSE); #if GTK_CHECK_VERSION(2, 91, 0) ret = GTK_WIDGET_CLASS(ppg_ruler_parent_class)->draw(widget, cr); #else ret = GTK_WIDGET_CLASS(ppg_ruler_parent_class)-> expose_event(widget, (GdkEventExpose *)gtk_get_current_event()); #endif priv = ruler->priv; gtk_widget_get_allocation(widget, &alloc); /* * Render the contents immediately if needed. */ if (priv->dirty) { ppg_ruler_draw_arrow(ruler); ppg_ruler_draw_ruler(ruler); priv->dirty = FALSE; } /* * Blit the background to the surface. */ cairo_rectangle(cr, 0, 0, alloc.width, alloc.height); cairo_set_source_surface(cr, priv->ruler, 0, 0); cairo_fill(cr); /* * Blit the arrow to the surface. */ x = (gint)(((priv->pos - priv->lower) / (priv->upper - priv->lower) * alloc.width) - (ARROW_SIZE / 2.0)); y = alloc.height - ARROW_SIZE - 1; cairo_set_source_surface(cr, priv->arrow, x, y); cairo_rectangle(cr, x, y, ARROW_SIZE, ARROW_SIZE); cairo_fill(cr); return ret; }
static gboolean ppg_ruler_expose_event (GtkWidget *widget, GdkEventExpose *expose) { PpgRuler *ruler = (PpgRuler *)widget; PpgRulerPrivate *priv; GtkAllocation alloc; cairo_t *cr; gint x; gint y; g_return_val_if_fail(PPG_IS_RULER(ruler), FALSE); GTK_WIDGET_CLASS(ppg_ruler_parent_class)->expose_event(widget, expose); priv = ruler->priv; gtk_widget_get_allocation(widget, &alloc); cr = gdk_cairo_create(expose->window); if (priv->dirty) { ppg_ruler_draw_arrow(ruler); ppg_ruler_draw_ruler(ruler); priv->dirty = FALSE; } cairo_rectangle(cr, 0, 0, alloc.width, alloc.height); gdk_cairo_set_source_pixmap(cr, priv->ruler, 0, 0); cairo_fill(cr); x = (gint)(((priv->pos - priv->lower) / (priv->upper - priv->lower) * alloc.width) - (ARROW_SIZE / 2.0)); y = alloc.height - ARROW_SIZE - 1; gdk_cairo_set_source_pixmap(cr, priv->arrow, x, y); cairo_rectangle(cr, x, y, ARROW_SIZE, ARROW_SIZE); cairo_fill(cr); cairo_destroy(cr); return FALSE; }