changeset 3129:5a7abf89bf8d

Updated #271: Added string type to supported argument list to Subtlext::Geometry#new
author unexist
date Tue, 15 Nov 2011 21:42:07 +0100
parents f78d6ad0fb0f
children 2715c8150dd8
files src/subtlext/geometry.c
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/subtlext/geometry.c	Tue Nov 15 21:41:24 2011 +0100
+++ b/src/subtlext/geometry.c	Tue Nov 15 21:42:07 2011 +0100
@@ -70,6 +70,7 @@
  * call-seq: new(x, y, width, height) -> Subtlext::Geometry
  *           new(array)               -> Subtlext::Geometry
  *           new(hash)                -> Subtlext::Geometry
+ *           new(string)              -> Subtlext::Geometry
  *           new(geometry)            -> Subtlext::Geometry
  *
  * Create a new Geometry object from givem <i>value</i> which can be of
@@ -77,6 +78,7 @@
  *
  * [Array]    Must be an array with values for x, y, width and height
  * [Hash]     Must be a hash with values for x, y, width and height
+ * [String]   Must be a string of following format: XxY+WIDTH+HEIGHT
  * [Geometry] Copy geometry from a Geometry object
  *
  * Or just pass one argument for x, y, width and height.
@@ -93,6 +95,9 @@
  *  geom = Subtlext::Geometry.new({ :x => 0, :y => 0, :width => 50, :height => 50 })
  *  => #<Subtlext::Geometry:xxx>
  *
+ *  geom = Subtlext::Geometry.new("0x0+100+100")
+ *  => #<Subtlext::Geometry:xxx>
+ *
  *  geom = Subtlext::Geometry.new(Subtlext::Geometry.new(0, 0, 50, 50))
  *  => #<Subtlext::Geometry:xxx>
  */
@@ -104,7 +109,7 @@
 {
   VALUE value = Qnil, data[4] = { Qnil };
 
-  rb_scan_args(argc, argv, "04", &data[0], &data[1], &data[2], &data[3]);
+  rb_scan_args(argc, argv, "13", &data[0], &data[1], &data[2], &data[3]);
   value = data[0];
 
   /* Check object type */
@@ -129,6 +134,20 @@
               data[i] = rb_hash_lookup(value, CHAR2SYM(syms[i]));
           }
         break;
+      case T_STRING:
+          {
+            XRectangle geom = { 0 };
+
+            sscanf(RSTRING_PTR(value), "%hdx%hd+%hu+%hu",
+              &geom.x, &geom.y, &geom.width, &geom.height);
+
+            /* Convert values */
+            data[0] = INT2FIX(geom.x);
+            data[1] = INT2FIX(geom.y);
+            data[2] = INT2FIX(geom.width);
+            data[3] = INT2FIX(geom.height);
+          }
+        break;
       case T_OBJECT:
           {
             VALUE klass = rb_const_get(mod, rb_intern("Geometry"));