[gtk] Improve the scale handling
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] Improve the scale handling
- Date: Fri, 16 Mar 2018 00:29:36 +0000 (UTC)
commit 62aa487500dcca29711385f992216f72fd005c32
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Mar 15 20:25:06 2018 -0400
Improve the scale handling
Always use the smallest scale that is larger than requested,
or, failing that, the largest available scale.
gtk/gtkcssimagescaled.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkcssimagescaled.c b/gtk/gtkcssimagescaled.c
index 6b0b50eecd..09166e884c 100644
--- a/gtk/gtkcssimagescaled.c
+++ b/gtk/gtkcssimagescaled.c
@@ -107,34 +107,38 @@ gtk_css_image_scaled_compute (GtkCssImage *image,
int scale;
GtkCssImageScaled *res;
int i;
- int max_scale;
-
- max_scale = 1;
- for (i = 0; i < scaled->n_images; i++)
- max_scale = MAX (max_scale, scaled->scales[i]);
+ int best;
scale = gtk_style_provider_get_scale (provider);
- scale = MAX(MIN (scale, max_scale), 1);
+ scale = MAX(scale, 1);
+ best = 0;
for (i = 0; i < scaled->n_images; i++)
{
if (scaled->scales[i] == scale)
- break;
+ {
+ best = i;
+ break;
+ }
+ else if ((scaled->scales[best] < scaled->scales[i] && scaled->scales[i] < scale) ||
+ (scale < scaled->scales[i] && scaled->scales[i] < scaled->scales[best]) ||
+ (scaled->scales[best] < scale && scaled->scales[i] > scale))
+ {
+ best = i;
+ }
}
- if (i == scaled->n_images)
- i = 0;
res = g_object_new (GTK_TYPE_CSS_IMAGE_SCALED, NULL);
res->n_images = 1;
res->images = g_new (GtkCssImage *, 1);
res->scales = g_new (int, 1);
- res->images[0] = _gtk_css_image_compute (scaled->images[i],
+ res->images[0] = _gtk_css_image_compute (scaled->images[best],
property_id,
provider,
style,
parent_style);
- res->scales[0] = scaled->scales[i];
+ res->scales[0] = scaled->scales[best];
return res;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]