}
gtk_snapshot_offset (snapshot, pix_rect.x, pix_rect.y);
- gtk_icon_helper_snapshot (&icon_helper, snapshot);
+ gtk_icon_helper_snapshot (&icon_helper, snapshot, pix_rect.width, pix_rect.height);
gtk_snapshot_offset (snapshot, - pix_rect.x, - pix_rect.y);
gtk_icon_helper_destroy (&icon_helper);
self->texture_is_symbolic = symbolic;
}
+void
+gtk_icon_helper_measure (GtkIconHelper *self,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural)
+{
+ switch (gtk_image_definition_get_storage_type (self->def))
+ {
+ case GTK_IMAGE_PAINTABLE:
+ {
+ double min_width, min_height, nat_width, nat_height;
+ int default_size = get_default_size (self);
+
+ gdk_paintable_compute_concrete_size (gtk_image_definition_get_paintable (self->def),
+ 0, 0,
+ default_size, default_size,
+ &min_width, &min_height);
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ gdk_paintable_compute_concrete_size (gtk_image_definition_get_paintable (self->def),
+ 0,
+ for_size < 0 ? 0 : for_size,
+ default_size, default_size,
+ &nat_width, &nat_height);
+ *minimum = ceil (min_width);
+ *natural = ceil (nat_width);
+ }
+ else
+ {
+ gdk_paintable_compute_concrete_size (gtk_image_definition_get_paintable (self->def),
+ for_size < 0 ? 0 : for_size,
+ 0,
+ default_size, default_size,
+ &nat_width, &nat_height);
+ *minimum = ceil (min_height);
+ *natural = ceil (nat_height);
+ }
+ }
+ break;
+
+ case GTK_IMAGE_TEXTURE:
+ case GTK_IMAGE_SURFACE:
+ case GTK_IMAGE_ICON_NAME:
+ case GTK_IMAGE_GICON:
+ case GTK_IMAGE_EMPTY:
+ default:
+ {
+ int width, height;
+
+ _gtk_icon_helper_get_size (self, &width, &height);
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ *minimum = *natural = width;
+ else
+ *minimum = *natural = height;
+ }
+ break;
+ }
+}
+
static void
get_size_for_paintable (GtkIconHelper *self,
GdkPaintable *paintable,
void
gtk_icon_helper_snapshot (GtkIconHelper *self,
- GtkSnapshot *snapshot)
+ GtkSnapshot *snapshot,
+ double width,
+ double height)
{
GtkCssStyle *style;
- gint width, height;
style = gtk_css_node_get_style (self->node);
if (self->paintable == NULL)
return;
- _gtk_icon_helper_get_size (self, &width, &height);
-
gtk_css_style_snapshot_icon_paintable (style,
snapshot,
self->paintable,
GtkImageDefinition *gtk_icon_helper_get_definition (GtkIconHelper *self);
const gchar *_gtk_icon_helper_get_icon_name (GtkIconHelper *self);
+void gtk_icon_helper_measure (GtkIconHelper *self,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural);
void _gtk_icon_helper_get_size (GtkIconHelper *self,
gint *width_out,
gint *height_out);
void gtk_icon_helper_snapshot (GtkIconHelper *self,
- GtkSnapshot *snapshot);
+ GtkSnapshot *snapshot,
+ double width,
+ double height);
gboolean _gtk_icon_helper_get_force_scale_pixbuf (GtkIconHelper *self);
void _gtk_icon_helper_set_force_scale_pixbuf (GtkIconHelper *self,
width = gtk_widget_get_width (widget);
height = gtk_widget_get_height (widget);
- y = 0;
- _gtk_icon_helper_get_size (&priv->icon_helper, &w, &h);
- x = (width - w) / 2;
+ if (_gtk_icon_helper_get_storage_type (&priv->icon_helper) == GTK_IMAGE_PAINTABLE)
+ {
+ gtk_icon_helper_snapshot (&priv->icon_helper, snapshot, width, height);
+ }
+ else
+ {
+ _gtk_icon_helper_get_size (&priv->icon_helper, &w, &h);
+ x = (width - w) / 2;
- baseline = gtk_widget_get_allocated_baseline (widget);
+ baseline = gtk_widget_get_allocated_baseline (widget);
- if (baseline == -1)
- y += floor(height - h) / 2;
- else
- y += CLAMP (baseline - h * gtk_image_get_baseline_align (image), 0, height - h);
+ if (baseline == -1)
+ y = floor(height - h) / 2;
+ else
+ y = CLAMP (baseline - h * gtk_image_get_baseline_align (image), 0, height - h);
- gtk_snapshot_offset (snapshot, x, y);
- gtk_icon_helper_snapshot (&priv->icon_helper, snapshot);
- gtk_snapshot_offset (snapshot, -x, -y);
+ gtk_snapshot_offset (snapshot, x, y);
+ gtk_icon_helper_snapshot (&priv->icon_helper, snapshot, w, h);
+ gtk_snapshot_offset (snapshot, -x, -y);
+ }
}
static void
int *natural_baseline)
{
GtkImagePrivate *priv = gtk_image_get_instance_private (GTK_IMAGE (widget));
- gint width, height;
float baseline_align;
- _gtk_icon_helper_get_size (&priv->icon_helper, &width, &height);
+ gtk_icon_helper_measure (&priv->icon_helper,
+ orientation,
+ for_size,
+ minimum, natural);
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- *minimum = *natural = width;
- }
- else
+ if (orientation == GTK_ORIENTATION_VERTICAL)
{
baseline_align = gtk_image_get_baseline_align (GTK_IMAGE (widget));
- *minimum = *natural = height;
if (minimum_baseline)
- *minimum_baseline = height * baseline_align;
+ *minimum_baseline = *minimum * baseline_align;
if (natural_baseline)
- *natural_baseline = height * baseline_align;
+ *natural_baseline = *natural * baseline_align;
}
}