static void gimp_ruler_draw_pos (GimpRuler *ruler, cairo_t *cr) { GtkWidget *widget = GTK_WIDGET (ruler); GtkStyleContext *context = gtk_widget_get_style_context (widget); GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler); GdkRectangle pos_rect; if (! gtk_widget_is_drawable (widget)) return; pos_rect = gimp_ruler_get_pos_rect (ruler, gimp_ruler_get_position (ruler)); if ((pos_rect.width > 0) && (pos_rect.height > 0)) { GdkRGBA color; gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget), &color); gdk_cairo_set_source_rgba (cr, &color); cairo_move_to (cr, pos_rect.x, pos_rect.y); if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { cairo_line_to (cr, pos_rect.x + pos_rect.width / 2.0, pos_rect.y + pos_rect.height); cairo_line_to (cr, pos_rect.x + pos_rect.width, pos_rect.y); } else { cairo_line_to (cr, pos_rect.x + pos_rect.width, pos_rect.y + pos_rect.height / 2.0); cairo_line_to (cr, pos_rect.x, pos_rect.y + pos_rect.height); } cairo_fill (cr); } priv->last_pos_rect = pos_rect; }
static void gimp_ruler_draw_pos (GimpRuler *ruler, cairo_t *cr) { GtkWidget *widget = GTK_WIDGET (ruler); GtkStyle *style = gtk_widget_get_style (widget); GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler); GtkStateType state = gtk_widget_get_state (widget); GdkRectangle pos_rect; if (! gtk_widget_is_drawable (widget)) return; pos_rect = gimp_ruler_get_pos_rect (ruler, gimp_ruler_get_position (ruler)); if ((pos_rect.width > 0) && (pos_rect.height > 0)) { gdk_cairo_set_source_color (cr, &style->fg[state]); cairo_move_to (cr, pos_rect.x, pos_rect.y); if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { cairo_line_to (cr, pos_rect.x + pos_rect.width / 2.0, pos_rect.y + pos_rect.height); cairo_line_to (cr, pos_rect.x + pos_rect.width, pos_rect.y); } else { cairo_line_to (cr, pos_rect.x + pos_rect.width, pos_rect.y + pos_rect.height / 2.0); cairo_line_to (cr, pos_rect.x, pos_rect.y + pos_rect.height); } cairo_fill (cr); } }
static void gimp_ruler_draw_pos (GimpRuler *ruler) { GtkWidget *widget = GTK_WIDGET (ruler); GtkStyle *style = gtk_widget_get_style (widget); GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler); GtkStateType state = gtk_widget_get_state (widget); GtkAllocation allocation; gint x, y; gint width, height; gint bs_width, bs_height; gint xthickness; gint ythickness; if (! gtk_widget_is_drawable (widget)) return; gtk_widget_get_allocation (widget, &allocation); xthickness = style->xthickness; ythickness = style->ythickness; if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { width = allocation.width; height = allocation.height - ythickness * 2; bs_width = height / 2 + 2; bs_width |= 1; /* make sure it's odd */ bs_height = bs_width / 2 + 1; } else { width = allocation.width - xthickness * 2; height = allocation.height; bs_height = width / 2 + 2; bs_height |= 1; /* make sure it's odd */ bs_width = bs_height / 2 + 1; } if ((bs_width > 0) && (bs_height > 0)) { cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget)); gdouble lower; gdouble upper; gdouble position; gdouble increment; cairo_rectangle (cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip (cr); cairo_translate (cr, allocation.x, allocation.y); /* If a backing store exists, restore the ruler */ if (priv->backing_store) { cairo_set_source_surface (cr, priv->backing_store, 0, 0); cairo_rectangle (cr, priv->xsrc, priv->ysrc, bs_width, bs_height); cairo_fill (cr); } position = gimp_ruler_get_position (ruler); gimp_ruler_get_range (ruler, &lower, &upper, NULL); if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { increment = (gdouble) width / (upper - lower); x = ROUND ((position - lower) * increment) + (xthickness - bs_width) / 2 - 1; y = (height + bs_height) / 2 + ythickness; } else { increment = (gdouble) height / (upper - lower); x = (width + bs_width) / 2 + xthickness; y = ROUND ((position - lower) * increment) + (ythickness - bs_height) / 2 - 1; } gdk_cairo_set_source_color (cr, &style->fg[state]); cairo_move_to (cr, x, y); if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { cairo_line_to (cr, x + bs_width / 2.0, y + bs_height); cairo_line_to (cr, x + bs_width, y); } else { cairo_line_to (cr, x + bs_width, y + bs_height / 2.0); cairo_line_to (cr, x, y + bs_height); } cairo_fill (cr); cairo_destroy (cr); priv->xsrc = x; priv->ysrc = y; } }