edje: add example of messages handling (receiving /
authorBruno Dilly <bdilly@profusion.mobi>
Fri, 23 Nov 2012 21:28:02 +0000 (21:28 +0000)
committerBruno Dilly <bdilly@profusion.mobi>
Fri, 23 Nov 2012 21:28:02 +0000 (21:28 +0000)
 sending)

All types!

SVN revision: 79589

legacy/edje/src/examples/Makefile.am
legacy/edje/src/examples/messages_echo.edc [new file with mode: 0644]

index f20e683..7ad48bf 100644 (file)
@@ -38,6 +38,7 @@ external_elm_check.edc \
 external_elm_panes.edc \
 external_emotion_elm.edc \
 lua_script.edc \
+messages_echo.edc \
 perspective.edc \
 signalsBubble.edc \
 signals-messages.edc \
diff --git a/legacy/edje/src/examples/messages_echo.edc b/legacy/edje/src/examples/messages_echo.edc
new file mode 100644 (file)
index 0000000..045ec92
--- /dev/null
@@ -0,0 +1,97 @@
+/* Simple EDC exemplifying how to receive and emit all types of messages */
+
+/* Actually for sets it will send back a message of the same type with the
+ * first item and N other messages with the remaining items. */
+
+collections {
+   group {
+      name: "messages_echo";
+
+      parts {
+         part {
+            name: "bg";
+            type: RECT;
+            description {
+               state: "default" 0.0;
+               min: 400 50;
+               max: 400 50;
+               color: 0 0 0 255;
+            }
+         }
+
+         part {
+            name: "text";
+            type: TEXT;
+            description {
+               state: "default" 0.0;
+               color: 255 255 255 255;
+               text {
+                  font: "Sans";
+                  size: 20;
+                  text: "I will echo all your messages ;)";
+               }
+            }
+         }
+      }
+
+      script {
+         public message(Msg_Type:type, id, ...) {
+            if (type == MSG_INT)
+               send_message(type, id, getarg(2));
+            else if (type == MSG_FLOAT)
+               send_message(type, id, getfarg(2));
+            else if (type == MSG_STRING) {
+               new buf[1024];
+               getsarg(2, buf, sizeof(buf));
+               send_message(type, id, buf);
+            }
+            else if (type == MSG_STRING_INT) {
+               new buf[1024];
+               getsarg(2, buf, sizeof(buf));
+               send_message(type, id, buf, getarg(3));
+            }
+            else if (type == MSG_STRING_FLOAT) {
+               new buf[1024];
+               getsarg(2, buf, sizeof(buf));
+               send_message(type, id, buf, getfarg(3));
+            }
+            else if (type == MSG_INT_SET) {
+               new i, n = numargs();
+               send_message(type, id, getarg(2));
+               for (i = 3; i < n; i++)
+                  send_message(MSG_STRING_INT, id, "Extra INT:", getarg(i));
+            }
+            else if (type == MSG_FLOAT_SET) {
+               new i, n = numargs();
+               send_message(type, id, getfarg(2));
+               for (i = 3; i < n; i++)
+                  send_message(MSG_STRING_FLOAT, id, "Extra FLOAT:",
+                        getfarg(i));
+            }
+            else if (type == MSG_STRING_SET) {
+               new buf[1024], i, n = numargs();
+               getsarg(2, buf, sizeof(buf));
+               send_message(type, id, buf);
+               for (i = 3; i < n; i++) {
+                  getsarg(i, buf, sizeof(buf));
+                  send_message(MSG_STRING_SET, id, "Extra STRING:", buf);
+               }
+            }
+            else if (type == MSG_STRING_INT_SET) {
+               new buf[1024], i, n = numargs();
+               getsarg(2, buf, sizeof(buf));
+               send_message(type, id, buf, getarg(3));
+               for (i = 4; i < n; i++)
+                  send_message(MSG_STRING_INT, id, "Extra INT:", getarg(i));
+            }
+            else if (type == MSG_STRING_FLOAT_SET) {
+               new buf[1024], i, n = numargs();
+               getsarg(2, buf, sizeof(buf));
+               send_message(type, id, buf, getfarg(3));
+               for (i = 4; i < n; i++)
+                  send_message(MSG_STRING_INT, id, "Extra FLOAT:", getfarg(i));
+            }
+         }
+      }
+   }
+}