diff options
author | Marcus Karlsson <mk@acc.umu.se> | 2015-03-24 22:31:52 +0100 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2015-03-24 22:45:14 -0400 |
commit | abf3d78b5717cb66f3e231a521057188c426d473 (patch) | |
tree | c73202042f372ee64b11b9bd25115833635d7e89 /gtk/gtkrange.c | |
parent | 77197847335409a743688a50af51b39160f61754 (diff) | |
download | gtk+-abf3d78b5717cb66f3e231a521057188c426d473.tar.gz |
GtkRange: Fix drawing of fill-level
Compute the proportion of the range that should be filled to match the
fill level, and use it to compute the starting point and length of the
area between the slider and the fill level.
https://bugzilla.gnome.org/show_bug.cgi?id=734741
Diffstat (limited to 'gtk/gtkrange.c')
-rw-r--r-- | gtk/gtkrange.c | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c index ce3f54bc15..bbbfe220be 100644 --- a/gtk/gtkrange.c +++ b/gtk/gtkrange.c @@ -2111,11 +2111,12 @@ gtk_range_draw (GtkWidget *widget, gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_page_size (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment) != 0) { - gdouble fill_level = priv->fill_level; - gint fill_x = x; - gint fill_y = y; - gint fill_width = width; - gint fill_height = height; + gdouble fill_level = priv->fill_level; + gint fill_x = x; + gint fill_y = y; + gint fill_width = width; + gint fill_height = height; + gdouble fill_proportion = 0.0; gtk_style_context_save (context); gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR); @@ -2124,33 +2125,36 @@ gtk_range_draw (GtkWidget *widget, gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_page_size (priv->adjustment)); - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - fill_x = priv->trough.x; - fill_width = (priv->slider.width + - (fill_level - gtk_adjustment_get_lower (priv->adjustment)) / + fill_proportion = (fill_level - gtk_adjustment_get_lower (priv->adjustment)) / (gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment) - - gtk_adjustment_get_page_size (priv->adjustment)) * - (priv->trough.width - - priv->slider.width)); + gtk_adjustment_get_page_size (priv->adjustment)); - if (should_invert (range)) - fill_x += priv->trough.width - fill_width; + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + if (!should_invert (range)) + { + fill_x = priv->slider.x + (priv->slider.width / 2); + fill_width = (width * fill_proportion) - fill_x + x; + } + else + { + fill_x = x + width * (1.0 - fill_proportion); + fill_width = priv->slider.x + (priv->slider.width / 2) - fill_x; + } } else { - fill_y = priv->trough.y; - fill_height = (priv->slider.height + - (fill_level - gtk_adjustment_get_lower (priv->adjustment)) / - (gtk_adjustment_get_upper (priv->adjustment) - - gtk_adjustment_get_lower (priv->adjustment) - - gtk_adjustment_get_page_size (priv->adjustment)) * - (priv->trough.height - - priv->slider.height)); - - if (should_invert (range)) - fill_y += priv->trough.height - fill_height; + if (!should_invert (range)) + { + fill_y = priv->slider.y + (priv->slider.height / 2); + fill_height = (height * fill_proportion) - fill_y + y; + } + else + { + fill_y = y + height * (1.0 - fill_proportion); + fill_height = priv->slider.y + (priv->slider.height / 2) - fill_y; + } } gtk_render_background (context, cr, fill_x, fill_y, fill_width, fill_height); |