diff options
author | Owen Taylor <otaylor@gtk.org> | 1998-05-13 04:59:38 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 1998-05-13 04:59:38 +0000 |
commit | 4283c9de4ff02e1e18aebb0dc6988d23bbd8c88c (patch) | |
tree | a64befac1200d7e18ea5ca671775a5cc12321e12 /gtk/gtkhruler.c | |
parent | 43dfe74c56563d40451fe17c7e4c1bee78987829 (diff) | |
download | gdk-pixbuf-4283c9de4ff02e1e18aebb0dc6988d23bbd8c88c.tar.gz |
A few more GPOINTER_TO_UINT fixes.
Wed May 13 00:53:52 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtktypeutils.c gtk/gtksignal.c: A few more
GPOINTER_TO_UINT fixes.
* gtk/gtksignal.c: Include <string.h> for memset.
Tue May 12 23:10:53 1998 Owen Taylor <otaylor@gtk.org>
(Maximilian Bisani <bisani@kawo2.rwth-aachen.de>: gtk-bisani-980320-0)
* gtk/gtkvruler.c gtk/gtkhruler.c gtk/gtkruler.h:
Cleanups, comments and the ability to have rulers with
a reversed direction.
Diffstat (limited to 'gtk/gtkhruler.c')
-rw-r--r-- | gtk/gtkhruler.c | 166 |
1 files changed, 90 insertions, 76 deletions
diff --git a/gtk/gtkhruler.c b/gtk/gtkhruler.c index 1180ecab1..2ad6cce64 100644 --- a/gtk/gtkhruler.c +++ b/gtk/gtkhruler.c @@ -132,98 +132,112 @@ gtk_hruler_draw_ticks (GtkRuler *ruler) gint xthickness; gint ythickness; gint length, ideal_length; + gfloat lower, upper; /* Upper and lower limits, in ruler units */ + gfloat increment; /* Number of pixels per unit */ + gint scale; /* Number of units per major unit */ gfloat subd_incr; - gfloat step_incr; - gfloat increment; gfloat start, end, cur; gchar unit_str[32]; - gint text_height; gint digit_height; + gint text_width; gint pos; - gint scale; g_return_if_fail (ruler != NULL); g_return_if_fail (GTK_IS_HRULER (ruler)); - if (GTK_WIDGET_DRAWABLE (ruler)) - { - widget = GTK_WIDGET (ruler); + if (!GTK_WIDGET_DRAWABLE (ruler)) + return; - gc = widget->style->fg_gc[GTK_STATE_NORMAL]; - bg_gc = widget->style->bg_gc[GTK_STATE_NORMAL]; - font = widget->style->font; - - xthickness = widget->style->klass->xthickness; - ythickness = widget->style->klass->ythickness; - digit_height = font->ascent; /* assume descent == 0? */ + widget = GTK_WIDGET (ruler); - width = widget->allocation.width; - height = widget->allocation.height - ythickness * 2; - gdk_draw_line (ruler->backing_store, gc, - xthickness, - height + ythickness, - widget->allocation.width - xthickness, - height + ythickness); - - if ((ruler->upper - ruler->lower) == 0) - return; - - increment = (gfloat) width * ruler->metric->pixels_per_unit / (ruler->upper - ruler->lower); - - /* determine the scale - * use the maximum extents of the ruler to determine the largest possible - * number to be displayed. calculate the height in pixels of this displayed - * text as for the vertical ruler case. use this height to find a scale - * which leaves sufficient room for drawing the ruler. - */ - scale = ceil (ruler->max_size / ruler->metric->pixels_per_unit); - sprintf (unit_str, "%d", scale); - text_height = strlen (unit_str) * digit_height + 1; + gc = widget->style->fg_gc[GTK_STATE_NORMAL]; + bg_gc = widget->style->bg_gc[GTK_STATE_NORMAL]; + font = widget->style->font; + + xthickness = widget->style->klass->xthickness; + ythickness = widget->style->klass->ythickness; + digit_height = font->ascent; /* assume descent == 0 ? */ + + width = widget->allocation.width; + height = widget->allocation.height - ythickness * 2; + + gdk_draw_line (ruler->backing_store, gc, + xthickness, + height + ythickness, + widget->allocation.width - xthickness, + height + ythickness); + + upper = ruler->upper / ruler->metric->pixels_per_unit; + lower = ruler->lower / ruler->metric->pixels_per_unit; - for (scale = 0; scale < MAXIMUM_SCALES; scale++) - if (ruler->metric->ruler_scale[scale] * increment > 2 * text_height) - break; + if ((upper - lower) == 0) + return; + increment = (gfloat) width / (upper - lower); - if (scale == MAXIMUM_SCALES) - scale = MAXIMUM_SCALES - 1; + /* determine the scale + * We calculate the text size as for the vruler instead of using + * text_width = gdk_string_width(font, unit_str), so that the result + * for the scale looks consistent with an accompanying vruler + */ + scale = ceil (ruler->max_size / ruler->metric->pixels_per_unit); + sprintf (unit_str, "%d", scale); + text_width = strlen (unit_str) * digit_height + 1; - length = 0; - for (i = MAXIMUM_SUBDIVIDE - 1; i >= 0; i--) + for (scale = 0; scale < MAXIMUM_SCALES; scale++) + if (ruler->metric->ruler_scale[scale] * fabs(increment) > 2 * text_width) + break; + + if (scale == MAXIMUM_SCALES) + scale = MAXIMUM_SCALES - 1; + + /* drawing starts here */ + length = 0; + for (i = MAXIMUM_SUBDIVIDE - 1; i >= 0; i--) + { + subd_incr = (gfloat) ruler->metric->ruler_scale[scale] / + (gfloat) ruler->metric->subdivide[i]; + if (subd_incr * fabs(increment) <= MINIMUM_INCR) + continue; + + /* Calculate the length of the tickmarks. Make sure that + * this length increases for each set of ticks + */ + ideal_length = height / (i + 1) - 1; + if (ideal_length > ++length) + length = ideal_length; + + if (lower < upper) { - subd_incr = (gfloat) ruler->metric->ruler_scale[scale] / (gfloat) ruler->metric->subdivide[i]; - step_incr = subd_incr * increment; - if (step_incr <= MINIMUM_INCR) - continue; - - start = floor ((ruler->lower / ruler->metric->pixels_per_unit) / subd_incr) * subd_incr; - end = ceil ((ruler->upper / ruler->metric->pixels_per_unit) / subd_incr) * subd_incr; - - ideal_length = height / (i + 1) - 1; - if (ideal_length > ++length) - length = ideal_length; - - cur = start; - while (cur <= end) + start = floor (lower / subd_incr) * subd_incr; + end = ceil (upper / subd_incr) * subd_incr; + } + else + { + start = floor (upper / subd_incr) * subd_incr; + end = ceil (lower / subd_incr) * subd_incr; + } + + + for (cur = start; cur <= end; cur += subd_incr) + { + pos = ROUND ((cur - lower) * increment); + + gdk_draw_line (ruler->backing_store, gc, + pos, height + ythickness, + pos, height - length + ythickness); + + /* draw label */ + if (i == 0) { - pos = ROUND ((cur - (ruler->lower / ruler->metric->pixels_per_unit)) * increment); - - gdk_draw_line (ruler->backing_store, gc, - pos, height + ythickness, pos, - height - length + ythickness); - if (i == 0) - { - sprintf (unit_str, "%d", (int) cur); - gdk_draw_rectangle (ruler->backing_store, - bg_gc, TRUE, - pos + 1, ythickness, - gdk_string_width(font, unit_str) + 1, - digit_height); - gdk_draw_string (ruler->backing_store, font, gc, - pos + 2, ythickness + font->ascent - 1, - unit_str); - } - - cur += subd_incr; + sprintf (unit_str, "%d", (int) cur); + gdk_draw_rectangle (ruler->backing_store, + bg_gc, TRUE, + pos + 1, ythickness, + gdk_string_width(font, unit_str) + 1, + digit_height); + gdk_draw_string (ruler->backing_store, font, gc, + pos + 2, ythickness + font->ascent - 1, + unit_str); } } } |