Added Edje::IntMessage and Edje::FloatMessage.
authorBrian Mattern <brian.mattern@gmail.com>
Thu, 9 Dec 2004 18:40:44 +0000 (18:40 +0000)
committerTilman Sauerbeck <tilman@code-monkey.de>
Thu, 9 Dec 2004 18:40:44 +0000 (18:40 +0000)
src/rb_messages.c

index b5c4f5be71802372e9b0e34240818dcbf2ca4bf3..455e89b7e13c1da1b71d70207c4ca9ec33ff9015 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * $Id: rb_messages.c 139 2004-10-30 09:41:17Z tilman $
+ * $Id: rb_messages.c 153 2004-12-09 18:40:44Z tilman $
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
@@ -31,7 +31,7 @@
        rb_define_const ((mod), #name, \
                         INT2FIX (prefix##name));
 
        rb_define_const ((mod), #name, \
                         INT2FIX (prefix##name));
 
-VALUE cMsg, cStrMsg;
+VALUE cMsg, cStrMsg, cIntMsg, cFloatMsg;
 
 static VALUE c_msg_init (VALUE self)
 {
 
 static VALUE c_msg_init (VALUE self)
 {
@@ -47,7 +47,7 @@ static VALUE c_str_msg_init (VALUE self, VALUE str)
        rb_call_super (0, NULL);
 
        rb_iv_set (self, "@type", UINT2NUM (EDJE_MESSAGE_STRING));
        rb_call_super (0, NULL);
 
        rb_iv_set (self, "@type", UINT2NUM (EDJE_MESSAGE_STRING));
-       rb_iv_set (self, "@string", str);
+       rb_iv_set (self, "@value", str);
 
        return self;
 }
 
        return self;
 }
@@ -57,12 +57,58 @@ static VALUE c_str_msg_serialize (VALUE self)
        static volatile Edje_Message_String ret;
        VALUE s;
 
        static volatile Edje_Message_String ret;
        VALUE s;
 
-       s = rb_iv_get (self, "@string");
+       s = rb_iv_get (self, "@value");
        ret.str = StringValuePtr (s);
 
        return (VALUE) &ret;
 }
 
        ret.str = StringValuePtr (s);
 
        return (VALUE) &ret;
 }
 
+static VALUE c_int_msg_init (VALUE self, VALUE val)
+{
+       Check_Type (val, T_FIXNUM);
+
+       rb_call_super (0, NULL);
+
+       rb_iv_set (self, "@type", UINT2NUM (EDJE_MESSAGE_INT));
+       rb_iv_set (self, "@value", val);
+
+       return self;
+}
+
+static VALUE c_int_msg_serialize (VALUE self)
+{
+       static volatile Edje_Message_Int ret;
+       VALUE i;
+
+       i = rb_iv_get (self, "@value");
+       ret.val = NUM2INT (i);
+
+       return (VALUE) &ret;
+}
+
+static VALUE c_float_msg_init (VALUE self, VALUE val)
+{
+       Check_Type (val, T_FLOAT);
+
+       rb_call_super (0, NULL);
+
+       rb_iv_set (self, "@type", UINT2NUM (EDJE_MESSAGE_FLOAT));
+       rb_iv_set (self, "@value", val);
+
+       return self;
+}
+
+static VALUE c_float_msg_serialize (VALUE self)
+{
+       static volatile Edje_Message_Float ret;
+       VALUE f;
+
+       f = rb_iv_get (self, "@value");
+       ret.val = NUM2DBL (f);
+
+       return (VALUE) &ret;
+}
+
 void Init_Messages (void)
 {
        cMsg = rb_define_class_under (mEdje, "Message", rb_cObject);
 void Init_Messages (void)
 {
        cMsg = rb_define_class_under (mEdje, "Message", rb_cObject);
@@ -71,10 +117,20 @@ void Init_Messages (void)
 
        rb_define_attr (cMsg, "type", 1, 0);
        rb_define_attr (cMsg, "id", 1, 1);
 
        rb_define_attr (cMsg, "type", 1, 0);
        rb_define_attr (cMsg, "id", 1, 1);
+       rb_define_attr (cMsg, "value", 1, 1);
 
 
+       /* StringMessage */
        cStrMsg = rb_define_class_under (mEdje, "StringMessage", cMsg);
        rb_define_method (cStrMsg, "initialize", c_str_msg_init, 1);
        rb_define_method (cStrMsg, "serialize", c_str_msg_serialize, 0);
 
        cStrMsg = rb_define_class_under (mEdje, "StringMessage", cMsg);
        rb_define_method (cStrMsg, "initialize", c_str_msg_init, 1);
        rb_define_method (cStrMsg, "serialize", c_str_msg_serialize, 0);
 
-       rb_define_attr (cStrMsg, "string", 1, 1);
+       /* IntMessage */
+       cIntMsg = rb_define_class_under (mEdje, "IntMessage", cMsg);
+       rb_define_method (cIntMsg, "initialize", c_int_msg_init, 1);
+       rb_define_method (cIntMsg, "serialize", c_int_msg_serialize, 0);
+
+       /* FloatMessage */
+       cFloatMsg = rb_define_class_under (mEdje, "FloatMessage", cMsg);
+       rb_define_method (cFloatMsg, "initialize", c_float_msg_init, 1);
+       rb_define_method (cFloatMsg, "serialize", c_float_msg_serialize, 0);
 }
 }