[cluttermm] Adds the Rect class.



commit ac85441ec72e63373a72cb9afad552d286af2ed4
Author: Ian Martin <martin_id vodafone co nz>
Date:   Wed Mar 26 08:40:10 2014 +1300

    Adds the Rect class.

 clutter/src/types.ccg         |   27 ++++++++++++++++++++++
 clutter/src/types.hg          |   50 +++++++++++++++++++++++++++++++++++++++++
 codegen/m4/convert_clutter.m4 |    5 ++++
 3 files changed, 82 insertions(+), 0 deletions(-)
---
diff --git a/clutter/src/types.ccg b/clutter/src/types.ccg
index 733a640..4f200d3 100644
--- a/clutter/src/types.ccg
+++ b/clutter/src/types.ccg
@@ -95,6 +95,33 @@ void Geometry::set_size(guint width, guint height)
   gobject_.height = height;
 }
 
+Rect::Rect(float x, float y, float width, float height)
+{
+  ClutterRect* rect = clutter_rect_alloc();
+  rect =clutter_rect_init(rect, x, y, width, height);
+  gobject_ = clutter_rect_copy(rect);
+}
+
+static gboolean cluttermm_rect_equals(const ClutterRect* a, const ClutterRect* b)
+{
+  return clutter_rect_equals(const_cast<ClutterRect*>(a), const_cast<ClutterRect*>(b));
+}
+
+Point Rect::get_centre() const
+{
+  ClutterPoint* p = 0;
+  clutter_rect_get_center(const_cast<ClutterRect*>(gobj()), p);
+  return Glib::wrap(p);
+}
+
+Rect Rect::rect_union(const Rect& b) const
+{
+  ClutterRect* crect = 0;
+  clutter_rect_union(const_cast<ClutterRect*>(gobj()), const_cast<ClutterRect*>(b.gobj()), crect);
+  return Glib::wrap(crect);
+}
+
+
 Point::Point(float x, float y)
 {
   ClutterPoint* point = clutter_point_alloc();
diff --git a/clutter/src/types.hg b/clutter/src/types.hg
index 1ec5b35..209be7b 100644
--- a/clutter/src/types.hg
+++ b/clutter/src/types.hg
@@ -118,6 +118,56 @@ public:
   _MEMBER_SET(y, y, float, gfloat)
 };
 
+//This has replaced Clutter::Geometry in new code.
+//Note: ClutterRect normalizes the rects in each call, even get_x(),
+//and should not be accessed directly via its struct fields,
+//so we consider several methods to be const even though they actually
+//change the internal struct field values.
+//TODO: Put this in its own file.
+class Rect
+{
+  _CLASS_BOXEDTYPE(Rect, ClutterRect,  NONE , clutter_rect_copy, clutter_rect_free)
+  _IGNORE(clutter_rect_alloc, clutter_rect_copy, clutter_rect_free)
+
+public:
+  _CUSTOM_DEFAULT_CTOR
+
+  /**
+   * Create a new Rect object, optionally specifying its dimensions.
+   */
+  explicit Rect(float x = 0, float y = 0, float width = 0, float height = 0);
+
+  _WRAP_EQUAL(cluttermm_rect_equals)
+
+  _WRAP_METHOD(Rect normalise(), clutter_rect_normalize)
+
+  /** Retrieves the center of the rect and returns a rect with the correct coordinates.
+   */
+  Point get_centre() const;
+  _IGNORE(clutter_rect_get_center)
+
+  _WRAP_METHOD(bool contains_point(const Point& point) const, clutter_rect_contains_point)
+  _WRAP_METHOD(bool contains_rect(const Rect& b) const, clutter_rect_contains_rect)
+
+  //We can't call this union() because it's a reserved word. 
+  /**
+   * Computes the smallest possible rectangle capable of fully containing both this rect and @a b, and 
returns it.
+   */
+  Rect rect_union(const Rect& b) const;
+  _IGNORE(clutter_rect_union)
+
+#m4 _INITIALIZATION(`Rect&',`ClutterRect', `$3 = Glib::wrap(&($4))') 
+  _WRAP_METHOD(bool intersection(const Rect& b, Rect& res{>>}) const, clutter_rect_intersection)
+
+  _WRAP_METHOD(void offset(float d_x, float d_y), clutter_rect_offset)
+  _WRAP_METHOD(void inset(float d_x, float d_y), clutter_rect_inset)
+  _WRAP_METHOD(void clamp_to_pixel(), clutter_rect_clamp_to_pixel )
+  _WRAP_METHOD(float get_x() const, clutter_rect_get_x)
+  _WRAP_METHOD(float get_y() const, clutter_rect_get_y)
+  _WRAP_METHOD(float get_width() const, clutter_rect_get_width)
+  _WRAP_METHOD(float get_height() const, clutter_rect_get_height)
+};
+
 
 class Knot
 {
diff --git a/codegen/m4/convert_clutter.m4 b/codegen/m4/convert_clutter.m4
index 88717e2..d523fc2 100644
--- a/codegen/m4/convert_clutter.m4
+++ b/codegen/m4/convert_clutter.m4
@@ -95,6 +95,11 @@ _CONVERSION(`ClutterPath*',`Glib::RefPtr<Path>',`Glib::wrap($3)')
 _CONVERSION(`ClutterPath*',`Glib::RefPtr<const Path>',`Glib::wrap($3)')
 
 _CONVERSION(`const Point&',`const ClutterPoint*',`($3).gobj()')
+_CONVERSION(`const Point&',`ClutterPoint*',`const_cast<ClutterPoint*>(($3).gobj())')
+
+#_CONVERSION(`ClutterRect*',`Rect&',`Rect($3)')
+_CONVERSION(`ClutterRect*',`Rect',`Glib::wrap($3)')
+_CONVERSION(`const Rect&',`ClutterRect*',`const_cast<ClutterRect*>(($3).gobj())')
 
 _CONVERSION(`const Glib::RefPtr<Shader>&',`ClutterShader*',__CONVERT_REFPTR_TO_P)
 _CONVERSION(`ClutterShader*',`Glib::RefPtr<Shader>', `Glib::wrap($3)')


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