2015-01-20 00:48:46 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2014,2015 Benjamin Otte
|
|
|
|
*
|
|
|
|
* Authors: Benjamin Otte <otte@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkrendericonprivate.h"
|
|
|
|
|
2016-12-31 00:15:52 +00:00
|
|
|
#include "gtkcssfiltervalueprivate.h"
|
2015-01-20 00:48:46 +00:00
|
|
|
#include "gtkcssimagevalueprivate.h"
|
2020-01-14 13:34:15 +00:00
|
|
|
#include "gtkcssshadowvalueprivate.h"
|
2015-01-20 00:48:46 +00:00
|
|
|
#include "gtkcssstyleprivate.h"
|
|
|
|
#include "gtkcsstransformvalueprivate.h"
|
2017-11-10 14:04:13 +00:00
|
|
|
#include "gtkiconthemeprivate.h"
|
2018-03-11 05:29:46 +00:00
|
|
|
#include "gtksnapshot.h"
|
2021-08-27 22:23:29 +00:00
|
|
|
#include "gtksymbolicpaintable.h"
|
2019-02-28 08:52:49 +00:00
|
|
|
#include "gsktransform.h"
|
2015-01-20 00:48:46 +00:00
|
|
|
|
2015-12-16 01:15:20 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2016-11-16 19:51:53 +00:00
|
|
|
void
|
|
|
|
gtk_css_style_snapshot_icon (GtkCssStyle *style,
|
|
|
|
GtkSnapshot *snapshot,
|
|
|
|
double width,
|
2020-01-10 18:11:59 +00:00
|
|
|
double height)
|
2016-11-16 19:51:53 +00:00
|
|
|
{
|
2019-02-28 08:52:49 +00:00
|
|
|
GskTransform *transform;
|
2016-12-12 23:11:06 +00:00
|
|
|
GtkCssImage *image;
|
2017-10-28 20:10:46 +00:00
|
|
|
gboolean has_shadow;
|
2016-11-16 19:51:53 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CSS_STYLE (style));
|
|
|
|
g_return_if_fail (snapshot != NULL);
|
|
|
|
|
2017-10-09 15:38:54 +00:00
|
|
|
if (width == 0.0 || height == 0.0)
|
|
|
|
return;
|
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
image = _gtk_css_image_value_get_image (style->other->icon_source);
|
2016-11-16 19:51:53 +00:00
|
|
|
if (image == NULL)
|
|
|
|
return;
|
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
transform = gtk_css_transform_value_get_transform (style->other->icon_transform);
|
2016-11-16 19:51:53 +00:00
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
gtk_snapshot_push_debug (snapshot, "CSS Icon @ %gx%g", width, height);
|
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
gtk_css_filter_value_push_snapshot (style->other->icon_filter, snapshot);
|
2016-12-31 00:15:52 +00:00
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
has_shadow = gtk_css_shadow_value_push_snapshot (style->icon->icon_shadow, snapshot);
|
2016-11-16 19:51:53 +00:00
|
|
|
|
2019-02-21 05:27:30 +00:00
|
|
|
if (transform == NULL)
|
2016-12-12 23:11:06 +00:00
|
|
|
{
|
2020-01-10 18:11:59 +00:00
|
|
|
gtk_css_image_snapshot (image, snapshot, width, height);
|
2016-12-12 23:11:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-21 04:34:12 +00:00
|
|
|
gtk_snapshot_save (snapshot);
|
2016-12-12 23:11:06 +00:00
|
|
|
|
|
|
|
/* XXX: Implement -gtk-icon-transform-origin instead of hardcoding "50% 50%" here */
|
2019-02-21 04:34:12 +00:00
|
|
|
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (width / 2.0, height / 2.0));
|
2019-02-21 05:27:30 +00:00
|
|
|
gtk_snapshot_transform (snapshot, transform);
|
2019-02-21 04:34:12 +00:00
|
|
|
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (- width / 2.0, - height / 2.0));
|
2016-12-13 08:40:24 +00:00
|
|
|
|
2020-01-10 18:11:59 +00:00
|
|
|
gtk_css_image_snapshot (image, snapshot, width, height);
|
2016-12-13 08:40:24 +00:00
|
|
|
|
2019-02-21 04:34:12 +00:00
|
|
|
gtk_snapshot_restore (snapshot);
|
2016-12-12 23:11:06 +00:00
|
|
|
}
|
2016-12-18 23:45:35 +00:00
|
|
|
|
2017-10-28 20:10:46 +00:00
|
|
|
if (has_shadow)
|
2017-09-30 11:11:51 +00:00
|
|
|
gtk_snapshot_pop (snapshot);
|
2017-10-28 20:10:46 +00:00
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
gtk_css_filter_value_pop_snapshot (style->other->icon_filter, snapshot);
|
2018-04-24 01:17:23 +00:00
|
|
|
|
|
|
|
gtk_snapshot_pop (snapshot);
|
2019-02-21 05:27:30 +00:00
|
|
|
|
2019-02-28 08:52:49 +00:00
|
|
|
gsk_transform_unref (transform);
|
2016-11-16 19:51:53 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 05:19:16 +00:00
|
|
|
void
|
2018-02-16 08:09:35 +00:00
|
|
|
gtk_css_style_snapshot_icon_paintable (GtkCssStyle *style,
|
|
|
|
GtkSnapshot *snapshot,
|
|
|
|
GdkPaintable *paintable,
|
|
|
|
double width,
|
2020-02-05 08:49:23 +00:00
|
|
|
double height)
|
2016-11-15 05:19:16 +00:00
|
|
|
{
|
2019-02-28 08:52:49 +00:00
|
|
|
GskTransform *transform;
|
2017-10-28 20:10:46 +00:00
|
|
|
gboolean has_shadow;
|
2021-08-27 22:23:29 +00:00
|
|
|
gboolean is_symbolic_paintable;
|
|
|
|
GdkRGBA colors[4];
|
2016-11-15 05:19:16 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CSS_STYLE (style));
|
|
|
|
g_return_if_fail (snapshot != NULL);
|
2018-02-16 08:09:35 +00:00
|
|
|
g_return_if_fail (GDK_IS_PAINTABLE (paintable));
|
|
|
|
g_return_if_fail (width > 0);
|
|
|
|
g_return_if_fail (height > 0);
|
2016-11-15 05:19:16 +00:00
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
transform = gtk_css_transform_value_get_transform (style->other->icon_transform);
|
2016-11-15 05:19:16 +00:00
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
gtk_css_filter_value_push_snapshot (style->other->icon_filter, snapshot);
|
2016-12-31 00:15:52 +00:00
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
has_shadow = gtk_css_shadow_value_push_snapshot (style->icon->icon_shadow, snapshot);
|
2016-11-15 05:19:16 +00:00
|
|
|
|
2021-08-27 22:23:29 +00:00
|
|
|
is_symbolic_paintable = GTK_IS_SYMBOLIC_PAINTABLE (paintable);
|
|
|
|
if (is_symbolic_paintable)
|
2020-02-06 15:23:11 +00:00
|
|
|
{
|
2021-08-30 02:52:47 +00:00
|
|
|
gtk_icon_theme_lookup_symbolic_colors (style, colors);
|
2017-11-09 03:21:42 +00:00
|
|
|
|
2021-08-27 22:23:29 +00:00
|
|
|
if (gdk_rgba_is_clear (&colors[0]))
|
2020-02-06 15:23:11 +00:00
|
|
|
goto transparent;
|
|
|
|
}
|
2017-10-23 09:42:23 +00:00
|
|
|
|
2019-02-21 05:27:30 +00:00
|
|
|
if (transform == NULL)
|
2016-12-12 23:11:06 +00:00
|
|
|
{
|
2021-08-27 22:23:29 +00:00
|
|
|
if (is_symbolic_paintable)
|
|
|
|
gtk_symbolic_paintable_snapshot_symbolic (GTK_SYMBOLIC_PAINTABLE (paintable), snapshot, width, height, colors, G_N_ELEMENTS (colors));
|
2020-02-05 08:49:23 +00:00
|
|
|
else
|
|
|
|
gdk_paintable_snapshot (paintable, snapshot, width, height);
|
2016-12-12 23:11:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-21 04:34:12 +00:00
|
|
|
gtk_snapshot_save (snapshot);
|
2016-12-12 23:11:06 +00:00
|
|
|
|
|
|
|
/* XXX: Implement -gtk-icon-transform-origin instead of hardcoding "50% 50%" here */
|
2019-02-21 04:34:12 +00:00
|
|
|
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (width / 2.0, height / 2.0));
|
2019-02-21 05:27:30 +00:00
|
|
|
gtk_snapshot_transform (snapshot, transform);
|
2019-02-21 04:34:12 +00:00
|
|
|
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (- width / 2.0, - height / 2.0));
|
2016-12-12 23:11:06 +00:00
|
|
|
|
2021-08-27 22:23:29 +00:00
|
|
|
if (is_symbolic_paintable)
|
|
|
|
gtk_symbolic_paintable_snapshot_symbolic (GTK_SYMBOLIC_PAINTABLE (paintable), snapshot, width, height, colors, G_N_ELEMENTS (colors));
|
2020-02-05 08:49:23 +00:00
|
|
|
else
|
|
|
|
gdk_paintable_snapshot (paintable, snapshot, width, height);
|
2016-12-12 23:11:06 +00:00
|
|
|
|
2019-02-21 04:34:12 +00:00
|
|
|
gtk_snapshot_restore (snapshot);
|
2016-12-12 23:11:06 +00:00
|
|
|
}
|
2016-12-18 23:45:35 +00:00
|
|
|
|
2019-10-16 15:48:25 +00:00
|
|
|
transparent:
|
2017-10-28 20:10:46 +00:00
|
|
|
if (has_shadow)
|
2017-09-30 11:11:51 +00:00
|
|
|
gtk_snapshot_pop (snapshot);
|
2017-10-28 20:10:46 +00:00
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
gtk_css_filter_value_pop_snapshot (style->other->icon_filter, snapshot);
|
2019-02-21 05:27:30 +00:00
|
|
|
|
2019-02-28 08:52:49 +00:00
|
|
|
gsk_transform_unref (transform);
|
2016-11-15 05:19:16 +00:00
|
|
|
}
|