[mutter/gbsneto/graphene: 5/6] Replace ClutterGeometry by graphene_rect_t



commit 47f06840b0e06b6ee645ef579edef07dddebf87c
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Feb 20 12:50:15 2019 -0300

    Replace ClutterGeometry by graphene_rect_t
    
    The last of the replacements. It is fine for now
    to replace ClutterGeometry's integers by floats.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/458

 clutter/clutter/clutter-actor.c                    |   6 +-
 clutter/clutter/clutter-base-types.c               | 108 ---------------------
 clutter/clutter/clutter-script-parser.c            |  65 +++++++------
 clutter/clutter/clutter-script-private.h           |   4 +-
 clutter/clutter/clutter-text.c                     |  16 +--
 clutter/clutter/clutter-text.h                     |   2 +-
 clutter/clutter/clutter-types.h                    |  37 -------
 .../clutter/deprecated/clutter-actor-deprecated.c  |  44 ---------
 clutter/clutter/deprecated/clutter-actor.h         |   4 -
 clutter/clutter/deprecated/clutter-rectangle.c     |  35 ++++---
 clutter/clutter/meson.build                        |   1 -
 11 files changed, 62 insertions(+), 260 deletions(-)
---
diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c
index b4835bb54..e6a406911 100644
--- a/clutter/clutter/clutter-actor.c
+++ b/clutter/clutter/clutter-actor.c
@@ -11458,8 +11458,7 @@ clutter_actor_set_y (ClutterActor *self,
  * the X coordinate of the origin of the allocation box.
  *
  * If the actor has any fixed coordinate set using clutter_actor_set_x(),
- * clutter_actor_set_position() or clutter_actor_set_geometry(), this
- * function will return that coordinate.
+ * clutter_actor_set_position(), this function will return that coordinate.
  *
  * If both the allocation and a fixed position are missing, this function
  * will return 0.
@@ -11506,8 +11505,7 @@ clutter_actor_get_x (ClutterActor *self)
  * the Y coordinate of the origin of the allocation box.
  *
  * If the actor has any fixed coordinate set using clutter_actor_set_y(),
- * clutter_actor_set_position() or clutter_actor_set_geometry(), this
- * function will return that coordinate.
+ * clutter_actor_set_position(), this function will return that coordinate.
  *
  * If both the allocation and a fixed position are missing, this function
  * will return 0.
diff --git a/clutter/clutter/clutter-base-types.c b/clutter/clutter/clutter-base-types.c
index 83920519b..fcbcd2ec7 100644
--- a/clutter/clutter/clutter-base-types.c
+++ b/clutter/clutter/clutter-base-types.c
@@ -41,114 +41,6 @@
 
 
 
-/*
- * ClutterGeometry
- */
-
-static ClutterGeometry*
-clutter_geometry_copy (const ClutterGeometry *geometry)
-{
-  return g_slice_dup (ClutterGeometry, geometry);
-}
-
-static void
-clutter_geometry_free (ClutterGeometry *geometry)
-{
-  if (G_LIKELY (geometry != NULL))
-    g_slice_free (ClutterGeometry, geometry);
-}
-
-/**
- * clutter_geometry_union:
- * @geometry_a: a #ClutterGeometry
- * @geometry_b: another #ClutterGeometry
- * @result: (out): location to store the result
- *
- * Find the union of two rectangles represented as #ClutterGeometry.
- *
- * Since: 1.4
- *
- * Deprecated: 1.16: Use #graphene_rect_t and graphene_rect_union()
- */
-void
-clutter_geometry_union (const ClutterGeometry *geometry_a,
-                        const ClutterGeometry *geometry_b,
-                        ClutterGeometry       *result)
-{
-  /* We don't try to handle rectangles that can't be represented
-   * as a signed integer box */
-  gint x_1 = MIN (geometry_a->x, geometry_b->x);
-  gint y_1 = MIN (geometry_a->y, geometry_b->y);
-  gint x_2 = MAX (geometry_a->x + (gint)geometry_a->width,
-                  geometry_b->x + (gint)geometry_b->width);
-  gint y_2 = MAX (geometry_a->y + (gint)geometry_a->height,
-                  geometry_b->y + (gint)geometry_b->height);
-  result->x = x_1;
-  result->y = y_1;
-  result->width = x_2 - x_1;
-  result->height = y_2 - y_1;
-}
-
-/**
- * clutter_geometry_intersects:
- * @geometry0: The first geometry to test
- * @geometry1: The second geometry to test
- *
- * Determines if @geometry0 and geometry1 intersect returning %TRUE if
- * they do else %FALSE.
- *
- * Return value: %TRUE of @geometry0 and geometry1 intersect else
- * %FALSE.
- *
- * Since: 1.4
- *
- * Deprecated: 1.16: Use #graphene_rect_t and graphene_rect_intersection()
- */
-gboolean
-clutter_geometry_intersects (const ClutterGeometry *geometry0,
-                             const ClutterGeometry *geometry1)
-{
-  if (geometry1->x >= (geometry0->x + (gint)geometry0->width) ||
-      geometry1->y >= (geometry0->y + (gint)geometry0->height) ||
-      (geometry1->x + (gint)geometry1->width) <= geometry0->x ||
-      (geometry1->y + (gint)geometry1->height) <= geometry0->y)
-    return FALSE;
-  else
-    return TRUE;
-}
-
-static gboolean
-clutter_geometry_progress (const GValue *a,
-                           const GValue *b,
-                           gdouble       progress,
-                           GValue       *retval)
-{
-  const ClutterGeometry *a_geom = g_value_get_boxed (a);
-  const ClutterGeometry *b_geom = g_value_get_boxed (b);
-  ClutterGeometry res = { 0, };
-  gint a_width = a_geom->width;
-  gint b_width = b_geom->width;
-  gint a_height = a_geom->height;
-  gint b_height = b_geom->height;
-
-  res.x = a_geom->x + (b_geom->x - a_geom->x) * progress;
-  res.y = a_geom->y + (b_geom->y - a_geom->y) * progress;
-
-  res.width = a_width + (b_width - a_width) * progress;
-  res.height = a_height + (b_height - a_height) * progress;
-
-  g_value_set_boxed (retval, &res);
-
-  return TRUE;
-}
-
-G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterGeometry, clutter_geometry,
-                               clutter_geometry_copy,
-                               clutter_geometry_free,
-                               CLUTTER_REGISTER_INTERVAL_PROGRESS (clutter_geometry_progress));
-
-
-
 /*
  * ClutterMargin
  */
diff --git a/clutter/clutter/clutter-script-parser.c b/clutter/clutter/clutter-script-parser.c
index ac3bd94f8..ea14b4166 100644
--- a/clutter/clutter/clutter-script-parser.c
+++ b/clutter/clutter/clutter-script-parser.c
@@ -352,63 +352,64 @@ _clutter_script_parse_knot (ClutterScript *script,
 }
 
 static gboolean
-parse_geometry_from_array (JsonArray       *array,
-                           ClutterGeometry *geometry)
+parse_rect_from_array (JsonArray       *array,
+                       graphene_rect_t *rect)
 {
   if (json_array_get_length (array) != 4)
     return FALSE;
 
-  geometry->x = json_array_get_int_element (array, 0);
-  geometry->y = json_array_get_int_element (array, 1);
-  geometry->width = json_array_get_int_element (array, 2);
-  geometry->height = json_array_get_int_element (array, 3);
+  graphene_rect_init (rect,
+                      json_array_get_int_element (array, 0),
+                      json_array_get_int_element (array, 1),
+                      json_array_get_int_element (array, 2),
+                      json_array_get_int_element (array, 3));
 
   return TRUE;
 }
 
 static gboolean
-parse_geometry_from_object (JsonObject      *object,
-                            ClutterGeometry *geometry)
+parse_rect_from_object (JsonObject      *object,
+                            graphene_rect_t *rect)
 {
   if (json_object_has_member (object, "x"))
-    geometry->x = json_object_get_int_member (object, "x");
+    rect->origin.x = json_object_get_int_member (object, "x");
   else
-    geometry->x = 0;
+    rect->origin.x = 0;
 
   if (json_object_has_member (object, "y"))
-    geometry->y = json_object_get_int_member (object, "y");
+    rect->origin.y = json_object_get_int_member (object, "y");
   else
-    geometry->y = 0;
+    rect->origin.y = 0;
 
   if (json_object_has_member (object, "width"))
-    geometry->width = json_object_get_int_member (object, "width");
+    rect->size.width = json_object_get_int_member (object, "width");
   else
-    geometry->width = 0;
+    rect->size.width = 0;
 
   if (json_object_has_member (object, "height"))
-    geometry->height = json_object_get_int_member (object, "height");
+    rect->size.height = json_object_get_int_member (object, "height");
   else
-    geometry->height = 0;
+    rect->size.height = 0;
 
   return TRUE;
 }
 
 gboolean
-_clutter_script_parse_geometry (ClutterScript   *script,
-                                JsonNode        *node,
-                                ClutterGeometry *geometry)
+_clutter_script_parse_rect (ClutterScript   *script,
+                            JsonNode        *node,
+                            graphene_rect_t *rect)
 {
   g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), FALSE);
   g_return_val_if_fail (node != NULL, FALSE);
-  g_return_val_if_fail (geometry != NULL, FALSE);
+  g_return_val_if_fail (rect != NULL, FALSE);
 
   switch (JSON_NODE_TYPE (node))
     {
     case JSON_NODE_ARRAY:
-      return parse_geometry_from_array (json_node_get_array (node), geometry);
+      return parse_rect_from_array (json_node_get_array (node), rect);
 
     case JSON_NODE_OBJECT:
-      return parse_geometry_from_object (json_node_get_object (node), geometry);
+      return parse_rect_from_object (json_node_get_object (node), rect);
 
     default:
       break;
@@ -1328,11 +1329,11 @@ _clutter_script_parse_node (ClutterScript *script,
                   return TRUE;
                 }
             }
-          else if (p_type == CLUTTER_TYPE_GEOMETRY)
+          else if (p_type == GRAPHENE_TYPE_RECT)
             {
-              ClutterGeometry geom = { 0, };
+              graphene_rect_t rect = GRAPHENE_RECT_INIT_ZERO;
 
-              /* geometry := {
+              /* rect := {
                *        "x" : (int),
                *        "y" : (int),
                *        "width" : (int),
@@ -1340,9 +1341,9 @@ _clutter_script_parse_node (ClutterScript *script,
                * }
                */
 
-              if (_clutter_script_parse_geometry (script, node, &geom))
+              if (_clutter_script_parse_rect (script, node, &rect))
                 {
-                  g_value_set_boxed (value, &geom);
+                  g_value_set_boxed (value, &rect);
                   return TRUE;
                 }
             }
@@ -1417,15 +1418,15 @@ _clutter_script_parse_node (ClutterScript *script,
                   return TRUE;
                 }
             }
-          else if (G_VALUE_HOLDS (value, CLUTTER_TYPE_GEOMETRY))
+          else if (G_VALUE_HOLDS (value, GRAPHENE_TYPE_RECT))
             {
-              ClutterGeometry geom = { 0, };
+              graphene_rect_t rect = GRAPHENE_RECT_INIT_ZERO;
 
-              /* geometry := [ (int), (int), (int), (int) ] */
+              /* rect := [ (int), (int), (int), (int) ] */
 
-              if (_clutter_script_parse_geometry (script, node, &geom))
+              if (_clutter_script_parse_rect (script, node, &rect))
                 {
-                  g_value_set_boxed (value, &geom);
+                  g_value_set_boxed (value, &rect);
                   return TRUE;
                 }
             }
diff --git a/clutter/clutter/clutter-script-private.h b/clutter/clutter/clutter-script-private.h
index 3b623c03c..9c08d82d6 100644
--- a/clutter/clutter/clutter-script-private.h
+++ b/clutter/clutter/clutter-script-private.h
@@ -122,9 +122,9 @@ gboolean _clutter_script_flags_from_string (GType          gtype,
 gboolean _clutter_script_parse_knot        (ClutterScript   *script,
                                             JsonNode        *node,
                                             ClutterKnot     *knot);
-gboolean _clutter_script_parse_geometry    (ClutterScript   *script,
+gboolean _clutter_script_parse_rect        (ClutterScript   *script,
                                             JsonNode        *node,
-                                            ClutterGeometry *geometry);
+                                            graphene_rect_t *rect);
 gboolean _clutter_script_parse_color       (ClutterScript   *script,
                                             JsonNode        *node,
                                             ClutterColor    *color);
diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c
index 3ad0d6152..aa1477bd1 100644
--- a/clutter/clutter/clutter-text.c
+++ b/clutter/clutter/clutter-text.c
@@ -1353,17 +1353,9 @@ clutter_text_ensure_cursor_position (ClutterText *self,
 
   if (!graphene_rect_equal (&priv->cursor_rect, &cursor_rect))
     {
-      ClutterGeometry cursor_pos;
-
       priv->cursor_rect = cursor_rect;
 
-      /* XXX:2.0 - remove */
-      cursor_pos.x = graphene_rect_get_x (&priv->cursor_rect);
-      cursor_pos.y = graphene_rect_get_y (&priv->cursor_rect);
-      cursor_pos.width = graphene_rect_get_width (&priv->cursor_rect);
-      cursor_pos.height = graphene_rect_get_height (&priv->cursor_rect);
-      g_signal_emit (self, text_signals[CURSOR_EVENT], 0, &cursor_pos);
-
+      g_signal_emit (self, text_signals[CURSOR_EVENT], 0, &cursor_rect);
       g_signal_emit (self, text_signals[CURSOR_CHANGED], 0);
 
       update_cursor_location (self);
@@ -4399,10 +4391,10 @@ clutter_text_class_init (ClutterTextClass *klass)
   /**
    * ClutterText::cursor-event:
    * @self: the #ClutterText that emitted the signal
-   * @geometry: the coordinates of the cursor
+   * @rect: the coordinates of the cursor
    *
    * The ::cursor-event signal is emitted whenever the cursor position
-   * changes inside a #ClutterText actor. Inside @geometry it is stored
+   * changes inside a #ClutterText actor. Inside @rect it is stored
    * the current position and size of the cursor, relative to the actor
    * itself.
    *
@@ -4417,7 +4409,7 @@ clutter_text_class_init (ClutterTextClass *klass)
                  G_STRUCT_OFFSET (ClutterTextClass, cursor_event),
                  NULL, NULL, NULL,
                  G_TYPE_NONE, 1,
-                 CLUTTER_TYPE_GEOMETRY | G_SIGNAL_TYPE_STATIC_SCOPE);
+                 GRAPHENE_TYPE_RECT | G_SIGNAL_TYPE_STATIC_SCOPE);
 
   /**
    * ClutterText::cursor-changed:
diff --git a/clutter/clutter/clutter-text.h b/clutter/clutter/clutter-text.h
index 5ca279f48..7fa8116da 100644
--- a/clutter/clutter/clutter-text.h
+++ b/clutter/clutter/clutter-text.h
@@ -82,7 +82,7 @@ struct _ClutterTextClass
   void (* text_changed)   (ClutterText           *self);
   void (* activate)       (ClutterText           *self);
   void (* cursor_event)   (ClutterText           *self,
-                           const ClutterGeometry *geometry);
+                           const graphene_rect_t *rect);
   void (* cursor_changed) (ClutterText           *self);
 
   /*< private >*/
diff --git a/clutter/clutter/clutter-types.h b/clutter/clutter/clutter-types.h
index 17c309bd6..d047b05d1 100644
--- a/clutter/clutter/clutter-types.h
+++ b/clutter/clutter/clutter-types.h
@@ -38,7 +38,6 @@
 G_BEGIN_DECLS
 
 #define CLUTTER_TYPE_ACTOR_BOX          (clutter_actor_box_get_type ())
-#define CLUTTER_TYPE_GEOMETRY           (clutter_geometry_get_type ())
 #define CLUTTER_TYPE_KNOT               (clutter_knot_get_type ())
 #define CLUTTER_TYPE_MARGIN             (clutter_margin_get_type ())
 #define CLUTTER_TYPE_MATRIX             (clutter_matrix_get_type ())
@@ -76,7 +75,6 @@ typedef struct _ClutterPathNode                 ClutterPathNode;
 
 typedef struct _ClutterActorBox                 ClutterActorBox;
 typedef struct _ClutterColor                    ClutterColor;
-typedef struct _ClutterGeometry                 ClutterGeometry; /* XXX:2.0 - remove */
 typedef struct _ClutterKnot                     ClutterKnot;
 typedef struct _ClutterMargin                   ClutterMargin;
 typedef struct _ClutterPerspective              ClutterPerspective;
@@ -259,41 +257,6 @@ CLUTTER_EXPORT
 void             clutter_actor_box_scale          (ClutterActorBox       *box,
                                                    gfloat                 scale);
 
-/**
- * ClutterGeometry:
- * @x: X coordinate of the top left corner of an actor
- * @y: Y coordinate of the top left corner of an actor
- * @width: width of an actor
- * @height: height of an actor
- *
- * The rectangle containing an actor's bounding box, measured in pixels.
- *
- * You should not use #ClutterGeometry, or operate on its fields
- * directly; you should use #cairo_rectangle_int_t or #graphene_rect_t  if you
- * need a rectangle type, depending on the precision required.
- *
- * Deprecated: 1.16
- */
-struct _ClutterGeometry
-{
-  /*< public >*/
-  gint   x;
-  gint   y;
-  guint  width;
-  guint  height;
-};
-
-CLUTTER_EXPORT
-GType clutter_geometry_get_type (void) G_GNUC_CONST;
-
-CLUTTER_DEPRECATED
-void      clutter_geometry_union      (const ClutterGeometry *geometry_a,
-                                       const ClutterGeometry *geometry_b,
-                                       ClutterGeometry       *result);
-CLUTTER_DEPRECATED
-gboolean  clutter_geometry_intersects (const ClutterGeometry *geometry0,
-                                       const ClutterGeometry *geometry1);
-
 /**
  * ClutterKnot:
  * @x: X coordinate of the knot
diff --git a/clutter/clutter/deprecated/clutter-actor.h b/clutter/clutter/deprecated/clutter-actor.h
index f568f5a40..40ebcec25 100644
--- a/clutter/clutter/deprecated/clutter-actor.h
+++ b/clutter/clutter/deprecated/clutter-actor.h
@@ -145,10 +145,6 @@ CLUTTER_DEPRECATED
 void            clutter_actor_get_transformation_matrix         (ClutterActor          *self,
                                                                  ClutterMatrix         *matrix);
 
-CLUTTER_DEPRECATED_FOR (clutter_actor_get_allocation_box)
-void            clutter_actor_get_allocation_geometry           (ClutterActor          *self,
-                                                                 ClutterGeometry       *geom);
-
 G_END_DECLS
 
 #endif /* __CLUTTER_ACTOR_DEPRECATED_H__ */
diff --git a/clutter/clutter/deprecated/clutter-rectangle.c b/clutter/clutter/deprecated/clutter-rectangle.c
index 6fb066b2f..da9f5014f 100644
--- a/clutter/clutter/deprecated/clutter-rectangle.c
+++ b/clutter/clutter/deprecated/clutter-rectangle.c
@@ -84,7 +84,7 @@ clutter_rectangle_paint (ClutterActor *self)
   CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
   static CoglPipeline *default_color_pipeline = NULL;
   CoglPipeline *content_pipeline;
-  ClutterGeometry geom;
+  ClutterActorBox alloc;
   CoglColor color;
   guint8 tmp_alpha;
 
@@ -92,7 +92,7 @@ clutter_rectangle_paint (ClutterActor *self)
                 "painting rect '%s'",
                clutter_actor_get_name (self) ? clutter_actor_get_name (self)
                                               : "unknown");
-  clutter_actor_get_allocation_geometry (self, &geom);
+  clutter_actor_get_allocation_box (self, &alloc);
 
   if (G_UNLIKELY (default_color_pipeline == NULL))
     {
@@ -140,40 +140,41 @@ clutter_rectangle_paint (ClutterActor *self)
       /* We paint the border and the content only if the rectangle
        * is big enough to show them
        */
-      if ((priv->border_width * 2) < geom.width &&
-          (priv->border_width * 2) < geom.height)
+      if ((priv->border_width * 2) < clutter_actor_box_get_width (&alloc) &&
+          (priv->border_width * 2) < clutter_actor_box_get_height (&alloc))
         {
           /* paint the border. this sucks, but it's the only way to make a border */
           cogl_framebuffer_draw_rectangle (framebuffer,
                                            border_pipeline,
                                            priv->border_width, 0,
-                                           geom.width,
+                                           clutter_actor_box_get_width (&alloc),
                                            priv->border_width);
 
           cogl_framebuffer_draw_rectangle (framebuffer,
                                            border_pipeline,
-                                           geom.width - priv->border_width,
+                                           clutter_actor_box_get_width (&alloc) - priv->border_width,
                                            priv->border_width,
-                                           geom.width, geom.height);
+                                           clutter_actor_box_get_width (&alloc),
+                                           clutter_actor_box_get_height (&alloc));
 
           cogl_framebuffer_draw_rectangle (framebuffer,
                                            border_pipeline,
-                                           0, geom.height - priv->border_width,
-                                           geom.width - priv->border_width,
-                                           geom.height);
+                                           0, clutter_actor_box_get_height (&alloc) - priv->border_width,
+                                           clutter_actor_box_get_width (&alloc) - priv->border_width,
+                                           clutter_actor_box_get_height (&alloc));
 
           cogl_framebuffer_draw_rectangle (framebuffer,
                                            border_pipeline,
                                            0, 0,
                                            priv->border_width,
-                                           geom.height - priv->border_width);
+                                           clutter_actor_box_get_height (&alloc) - priv->border_width);
 
           /* now paint the rectangle */
           cogl_framebuffer_draw_rectangle (framebuffer,
                                            content_pipeline,
                                            priv->border_width, priv->border_width,
-                                           geom.width - priv->border_width,
-                                           geom.height - priv->border_width);
+                                           clutter_actor_box_get_width (&alloc) - priv->border_width,
+                                           clutter_actor_box_get_height (&alloc) - priv->border_width);
         }
       else
         {
@@ -183,7 +184,9 @@ clutter_rectangle_paint (ClutterActor *self)
            */
           cogl_framebuffer_draw_rectangle (framebuffer,
                                            border_pipeline,
-                                           0, 0, geom.width, geom.height);
+                                           0, 0,
+                                           clutter_actor_box_get_width (&alloc),
+                                           clutter_actor_box_get_height (&alloc));
         }
 
       cogl_object_unref (border_pipeline);
@@ -192,7 +195,9 @@ clutter_rectangle_paint (ClutterActor *self)
     {
       cogl_framebuffer_draw_rectangle (framebuffer,
                                        content_pipeline,
-                                       0, 0, geom.width, geom.height);
+                                       0, 0,
+                                       clutter_actor_box_get_width (&alloc),
+                                       clutter_actor_box_get_height (&alloc));
     }
 
   cogl_object_unref (content_pipeline);
diff --git a/clutter/clutter/meson.build b/clutter/clutter/meson.build
index c551f8984..6928de133 100644
--- a/clutter/clutter/meson.build
+++ b/clutter/clutter/meson.build
@@ -242,7 +242,6 @@ clutter_deprecated_headers = [
 ]
 
 clutter_deprecated_sources = [
-  'deprecated/clutter-actor-deprecated.c',
   'deprecated/clutter-alpha.c',
   'deprecated/clutter-animation.c',
   'deprecated/clutter-behaviour.c',


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