[gtk/matthiasc/for-master] css: Implement -gtk-icon-transform-origin



commit 992094d33db2f4e96a3228358a50c418db586304
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jan 28 00:28:23 2021 -0500

    css: Implement -gtk-icon-transform-origin
    
    This is to -gtk-icon-transform as transform-origin is
    to transform.
    
    Fixes: #3625

 docs/reference/gtk/css-properties.md |  1 +
 gtk/gtkcssanimatedstyle.c            |  4 ++++
 gtk/gtkcssstaticstyle.c              |  5 +++++
 gtk/gtkcssstyleprivate.h             |  1 +
 gtk/gtkcssstylepropertyimpl.c        |  7 +++++++
 gtk/gtkcsstypesprivate.h             |  1 +
 gtk/gtkrendericon.c                  | 11 ++++++++---
 7 files changed, 27 insertions(+), 3 deletions(-)
---
diff --git a/docs/reference/gtk/css-properties.md b/docs/reference/gtk/css-properties.md
index 8fa9819fc7..ba8c91afd2 100644
--- a/docs/reference/gtk/css-properties.md
+++ b/docs/reference/gtk/css-properties.md
@@ -160,6 +160,7 @@ done with
 |-gtk-icon-size| [Length](https://www.w3.org/TR/css3-values/#length-value) | size used for builtin icons in 
buttons and expanders |
 |-gtk-icon-style| `requested`, `regular` or `symbolic` | preferred style for application-loaded icons |
 |-gtk-icon-transform| [Transform list](https://www.w3.org/TR/css-transforms-1/#typedef-transform-list) or 
`none` | applied to builtin and application-loaded icons |
+|-gtk-icon-transform-origin| [CSS Transforms Level 
1](https://www.w3.org/TR/css-transforms-1/#transform-origin-property) | |
 |-gtk-icon-palette| Color palette, as explained above | used to recolor symbolic icons |
 |-gtk-icon-shadow| [Shadow](https://www.w3.org/TR/css-backgrounds-3/#typedef-shadow) or `none` | applied to 
builtin and application-loaded icons |
 |-gtk-icon-filter| [Filter value list](https://www.w3.org/TR/filter-effects-1/#typedef-filter-value-list) or 
`none` | applied to builtin and application-loaded icons |
diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c
index 52e0cabc3b..e09efa1128 100644
--- a/gtk/gtkcssanimatedstyle.c
+++ b/gtk/gtkcssanimatedstyle.c
@@ -428,6 +428,10 @@ gtk_css_animated_style_set_animated_value (GtkCssAnimatedStyle *animated,
       unshare_other (animated);
       gtk_css_take_value (&style->other->icon_transform, value);
       break;
+    case GTK_CSS_PROPERTY_ICON_TRANSFORM_ORIGIN:
+      unshare_other (animated);
+      gtk_css_take_value (&style->other->icon_transform_origin, value);
+      break;
     case GTK_CSS_PROPERTY_ICON_FILTER:
       unshare_other (animated);
       gtk_css_take_value (&style->other->icon_filter, value);
diff --git a/gtk/gtkcssstaticstyle.c b/gtk/gtkcssstaticstyle.c
index 1c8dd80c56..28a43b39bd 100644
--- a/gtk/gtkcssstaticstyle.c
+++ b/gtk/gtkcssstaticstyle.c
@@ -161,6 +161,7 @@ static const int size_props[] = {
 static const int other_props[] = {
   GTK_CSS_PROPERTY_ICON_SOURCE,
   GTK_CSS_PROPERTY_ICON_TRANSFORM,
+  GTK_CSS_PROPERTY_ICON_TRANSFORM_ORIGIN,
   GTK_CSS_PROPERTY_ICON_FILTER,
   GTK_CSS_PROPERTY_TRANSFORM,
   GTK_CSS_PROPERTY_TRANSFORM_ORIGIN,
@@ -585,6 +586,9 @@ gtk_css_static_style_set_value (GtkCssStaticStyle *sstyle,
     case GTK_CSS_PROPERTY_ICON_TRANSFORM:
       gtk_css_take_value (&style->other->icon_transform, value);
       break;
+    case GTK_CSS_PROPERTY_ICON_TRANSFORM_ORIGIN:
+      gtk_css_take_value (&style->other->icon_transform_origin, value);
+      break;
     case GTK_CSS_PROPERTY_ICON_FILTER:
       gtk_css_take_value (&style->other->icon_filter, value);
       break;
@@ -882,6 +886,7 @@ gtk_css_other_create_initial_values (void)
 
   values->icon_source = _gtk_css_initial_value_new_compute (GTK_CSS_PROPERTY_ICON_SOURCE, NULL, NULL, NULL);
   values->icon_transform = _gtk_css_initial_value_new_compute (GTK_CSS_PROPERTY_ICON_TRANSFORM, NULL, NULL, 
NULL);
+  values->icon_transform_origin = _gtk_css_initial_value_new_compute 
(GTK_CSS_PROPERTY_ICON_TRANSFORM_ORIGIN, NULL, NULL, NULL);
   values->icon_filter = _gtk_css_initial_value_new_compute (GTK_CSS_PROPERTY_ICON_FILTER, NULL, NULL, NULL);
   values->transform = _gtk_css_initial_value_new_compute (GTK_CSS_PROPERTY_TRANSFORM, NULL, NULL, NULL);
   values->transform_origin = _gtk_css_initial_value_new_compute (GTK_CSS_PROPERTY_TRANSFORM_ORIGIN, NULL, 
NULL, NULL);
diff --git a/gtk/gtkcssstyleprivate.h b/gtk/gtkcssstyleprivate.h
index 27666e9978..77e0006e14 100644
--- a/gtk/gtkcssstyleprivate.h
+++ b/gtk/gtkcssstyleprivate.h
@@ -206,6 +206,7 @@ struct _GtkCssOtherValues {
   GtkCssValues base;
   GtkCssValue *icon_source;
   GtkCssValue *icon_transform;
+  GtkCssValue *icon_transform_origin;
   GtkCssValue *icon_filter;
   GtkCssValue *transform;
   GtkCssValue *transform_origin;
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 8e5d4bf796..63baa2c0ad 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -1250,6 +1250,13 @@ _gtk_css_style_property_init_properties (void)
                                           GTK_CSS_AFFECTS_CONTENT,
                                           transform_value_parse,
                                           _gtk_css_transform_value_new_none ());
+  gtk_css_style_property_register        ("-gtk-icon-transform-origin",
+                                          GTK_CSS_PROPERTY_ICON_TRANSFORM_ORIGIN,
+                                          GTK_STYLE_PROPERTY_ANIMATED,
+                                          GTK_CSS_AFFECTS_TRANSFORM,
+                                          transform_origin_parse,
+                                          _gtk_css_position_value_new (_gtk_css_number_value_new (50, 
GTK_CSS_PERCENT),
+                                                                       _gtk_css_number_value_new (50, 
GTK_CSS_PERCENT)));
   gtk_css_style_property_register        ("-gtk-icon-filter",
                                           GTK_CSS_PROPERTY_ICON_FILTER,
                                           GTK_STYLE_PROPERTY_ANIMATED,
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index 35ae56a41c..49373e643d 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -251,6 +251,7 @@ enum { /*< skip >*/
   GTK_CSS_PROPERTY_ICON_SHADOW,
   GTK_CSS_PROPERTY_ICON_STYLE,
   GTK_CSS_PROPERTY_ICON_TRANSFORM,
+  GTK_CSS_PROPERTY_ICON_TRANSFORM_ORIGIN,
   GTK_CSS_PROPERTY_ICON_FILTER,
   GTK_CSS_PROPERTY_BORDER_SPACING,
   GTK_CSS_PROPERTY_TRANSFORM,
diff --git a/gtk/gtkrendericon.c b/gtk/gtkrendericon.c
index a434c73010..92c5515694 100644
--- a/gtk/gtkrendericon.c
+++ b/gtk/gtkrendericon.c
@@ -26,6 +26,7 @@
 #include "gtkcssshadowvalueprivate.h"
 #include "gtkcssstyleprivate.h"
 #include "gtkcsstransformvalueprivate.h"
+#include "gtkcsspositionvalueprivate.h"
 #include "gtkiconthemeprivate.h"
 #include "gtksnapshot.h"
 #include "gsktransform.h"
@@ -66,12 +67,16 @@ gtk_css_style_snapshot_icon (GtkCssStyle            *style,
     }
   else
     {
+      double origin_x, origin_y;
+
+      origin_x = _gtk_css_position_value_get_x (style->other->icon_transform_origin, width);
+      origin_y = _gtk_css_position_value_get_y (style->other->icon_transform_origin, height);
+
       gtk_snapshot_save (snapshot);
 
-      /* XXX: Implement -gtk-icon-transform-origin instead of hardcoding "50% 50%" here */
-      gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (width / 2.0, height / 2.0));
+      gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (origin_x, origin_y));
       gtk_snapshot_transform (snapshot, transform);
-      gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (- width / 2.0, - height / 2.0));
+      gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (- origin_x, - origin_y));
 
       gtk_css_image_snapshot (image, snapshot, width, height);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]