X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fgtk-custom-hruler.c;h=61a34a7c418a61bc7feffec1a16f3fdef3b27e64;hb=b5148d93d5a9e6949f82f8685cab50cb772f2b9d;hp=d028d6472e61c9430c2ad99077adcd9c9b4e5866;hpb=209d967b1bb80a9735d690d8f4f0455ecb9970ca;p=ardour.git diff --git a/gtk2_ardour/gtk-custom-hruler.c b/gtk2_ardour/gtk-custom-hruler.c index d028d6472e..61a34a7c41 100644 --- a/gtk2_ardour/gtk-custom-hruler.c +++ b/gtk2_ardour/gtk-custom-hruler.c @@ -21,7 +21,7 @@ * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. + * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ /* modified by andreas meyer */ @@ -44,24 +44,30 @@ static gint gtk_custom_hruler_motion_notify (GtkWidget * widget, GdkEventMotion static void gtk_custom_hruler_draw_ticks (GtkCustomRuler * ruler); static void gtk_custom_hruler_draw_pos (GtkCustomRuler * ruler); -guint gtk_custom_hruler_get_type (void) +GType gtk_custom_hruler_get_type (void) { - static guint custom_hruler_type = 0; - - if (!custom_hruler_type) { - static const GtkTypeInfo custom_hruler_info = { - "GtkCustomHRuler", - sizeof (GtkCustomHRuler), - sizeof (GtkCustomHRulerClass), - (GtkClassInitFunc) gtk_custom_hruler_class_init, - (GtkObjectInitFunc) gtk_custom_hruler_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - custom_hruler_type = gtk_type_unique (gtk_custom_ruler_get_type (), &custom_hruler_info); + static GType hruler_type = 0; + + if (!hruler_type) { + static const GTypeInfo hruler_info = + { + sizeof (GtkCustomHRulerClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) gtk_custom_hruler_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GtkCustomHRuler), + 0, /* n_preallocs */ + (GInstanceInitFunc) gtk_custom_hruler_init, + NULL /* value_table */ + }; + + hruler_type = g_type_register_static (gtk_custom_ruler_get_type(), "GtkCustomHRuler", + &hruler_info, 0); } - return custom_hruler_type; + + return hruler_type; } static void @@ -85,8 +91,8 @@ gtk_custom_hruler_init (GtkCustomHRuler * custom_hruler) GtkWidget *widget; widget = GTK_WIDGET (custom_hruler); - widget->requisition.width = widget->style->klass->xthickness * 2 + 1; - widget->requisition.height = widget->style->klass->ythickness * 2 + RULER_HEIGHT; + widget->requisition.width = widget->style->xthickness * 2 + 1; + widget->requisition.height = widget->style->ythickness * 2 + RULER_HEIGHT; } @@ -127,11 +133,15 @@ gtk_custom_hruler_draw_ticks (GtkCustomRuler * ruler) { GtkWidget *widget; GdkGC *gc, *bg_gc; - GdkFont *font; gint i; GtkCustomRulerMark *marks; + gint xthickness; + gint ythickness; gint nmarks; gint max_chars; + gint digit_offset; + PangoLayout *layout; + PangoRectangle logical_rect, ink_rect; g_return_if_fail (ruler != NULL); g_return_if_fail (GTK_IS_CUSTOM_HRULER (ruler)); @@ -143,22 +153,29 @@ gtk_custom_hruler_draw_ticks (GtkCustomRuler * ruler) gc = widget->style->fg_gc[GTK_STATE_NORMAL]; bg_gc = widget->style->bg_gc[GTK_STATE_NORMAL]; - font = widget->style->font; + + layout = gtk_widget_create_pango_layout (widget, "012456789"); + pango_layout_get_extents (layout, &ink_rect, &logical_rect); + + digit_offset = ink_rect.y; + + xthickness = widget->style->xthickness; + ythickness = widget->style->ythickness; gtk_paint_box (widget->style, ruler->backing_store, GTK_STATE_NORMAL, GTK_SHADOW_NONE, NULL, widget, "custom_hruler", 0, 0, widget->allocation.width, widget->allocation.height); - gdk_draw_line (ruler->backing_store, gc, 0, widget->allocation.height - 1, + gdk_draw_line (ruler->backing_store, gc, 0, widget->allocation.height - 1, widget->allocation.width, widget->allocation.height - 1); if ((ruler->upper - ruler->lower) == 0) { return; } - + /* we have to assume a fixed width font here */ - max_chars = widget->allocation.width / gdk_string_width (font, "8"); + max_chars = widget->allocation.width / 12; // XXX FIX ME: pixel with of the char `8' nmarks = ruler->metric->get_marks (&marks, ruler->lower, ruler->upper, max_chars); @@ -181,13 +198,27 @@ gtk_custom_hruler_draw_ticks (GtkCustomRuler * ruler) break; } - gdk_draw_string (ruler->backing_store, font, gc, pos + 2, font->ascent - 1, marks[i].label); + pango_layout_set_text (layout, marks[i].label, -1); + pango_layout_get_extents (layout, &logical_rect, NULL); + + gtk_paint_layout (widget->style, + ruler->backing_store, + GTK_WIDGET_STATE (widget), + FALSE, + NULL, + widget, + "hruler", + pos + 2, ythickness + PANGO_PIXELS (logical_rect.y - digit_offset), + layout); + g_free (marks[i].label); } - + if (nmarks) { g_free (marks); } + + g_object_unref (layout); } static void @@ -208,8 +239,8 @@ gtk_custom_hruler_draw_pos (GtkCustomRuler * ruler) if (GTK_WIDGET_DRAWABLE (ruler) && (ruler->upper - ruler->lower) > 0) { widget = GTK_WIDGET (ruler); gc = widget->style->fg_gc[GTK_STATE_NORMAL]; - xthickness = widget->style->klass->xthickness; - ythickness = widget->style->klass->ythickness; + xthickness = widget->style->xthickness; + ythickness = widget->style->ythickness; width = widget->allocation.width; height = widget->allocation.height - ythickness * 2; @@ -223,7 +254,7 @@ gtk_custom_hruler_draw_pos (GtkCustomRuler * ruler) gdk_draw_pixmap (ruler->widget.window, ruler->non_gr_exp_gc, ruler->backing_store, ruler->xsrc, ruler->ysrc, ruler->xsrc, ruler->ysrc, bs_width, bs_height); - + increment = (gfloat) width / (ruler->upper - ruler->lower); x = ROUND ((ruler->position - ruler->lower) * increment) + (xthickness - bs_width) / 2 - 1; y = (height + bs_height) / 2 + ythickness;