ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/tools/examples.git/commit/?id=1acb71b216dfbd6d2a2ac38ab7721a38a9e28b50

commit 1acb71b216dfbd6d2a2ac38ab7721a38a9e28b50
Author: Andy Williams <a...@andywilliams.me>
Date:   Fri Nov 17 16:46:59 2017 +0000

    Add a colored mixin so we can talk about multiple inheritance
---
 .../src/{eo_inherit.h => eo_multiinherit.h}        |  1 +
 .../{eo_inherit_main.c => eo_multiinherit_main.c}  | 42 +++++++++++++---------
 tutorial/c/eo-multiinherit/src/example_circle.c    |  2 +-
 tutorial/c/eo-multiinherit/src/example_colored.c   | 33 +++++++++++++++++
 tutorial/c/eo-multiinherit/src/example_colored.eo  | 18 ++++++++++
 tutorial/c/eo-multiinherit/src/example_rectangle.c |  2 +-
 .../c/eo-multiinherit/src/example_rectangle.eo     |  2 +-
 tutorial/c/eo-multiinherit/src/example_shape.c     |  2 +-
 tutorial/c/eo-multiinherit/src/example_square.c    |  2 +-
 tutorial/c/eo-multiinherit/src/meson.build         |  7 ++--
 10 files changed, 87 insertions(+), 24 deletions(-)

diff --git a/tutorial/c/eo-multiinherit/src/eo_inherit.h 
b/tutorial/c/eo-multiinherit/src/eo_multiinherit.h
similarity index 90%
rename from tutorial/c/eo-multiinherit/src/eo_inherit.h
rename to tutorial/c/eo-multiinherit/src/eo_multiinherit.h
index 4c9fe63..04d0545 100644
--- a/tutorial/c/eo-multiinherit/src/eo_inherit.h
+++ b/tutorial/c/eo-multiinherit/src/eo_multiinherit.h
@@ -10,6 +10,7 @@
 #include <Efl_Core.h>
 
 #include "example_shape.eo.h"
+#include "example_colored.eo.h"
 #include "example_rectangle.eo.h"
 #include "example_square.eo.h"
 #include "example_circle.eo.h"
diff --git a/tutorial/c/eo-multiinherit/src/eo_inherit_main.c 
b/tutorial/c/eo-multiinherit/src/eo_multiinherit_main.c
similarity index 79%
rename from tutorial/c/eo-multiinherit/src/eo_inherit_main.c
rename to tutorial/c/eo-multiinherit/src/eo_multiinherit_main.c
index eb6091f..ccb65f7 100644
--- a/tutorial/c/eo-multiinherit/src/eo_inherit_main.c
+++ b/tutorial/c/eo-multiinherit/src/eo_multiinherit_main.c
@@ -1,4 +1,16 @@
-#include "eo_inherit.h"
+#include "eo_multiinherit.h"
+
+Example_Shape *
+_circle_create()
+{
+   Example_Circle *circle;
+
+   circle = efl_add(EXAMPLE_CIRCLE_CLASS, NULL,
+                    efl_name_set(efl_added, "Circle"),
+                    example_circle_radius_set(efl_added, 5));
+
+   return circle;
+}
 
 Example_Shape *
 _rectangle_create()
@@ -10,6 +22,7 @@ _rectangle_create()
                        example_rectangle_width_set(efl_added, 5),
                        example_rectangle_height_set(efl_added, 10));
 
+   example_colored_color_set(rectangle, 255, 0, 0);
    return rectangle;
 }
 
@@ -22,25 +35,22 @@ _square_create()
                     efl_name_set(efl_added, "Square"),
                     example_rectangle_width_set(efl_added, 7));
 
+   example_colored_color_set(square, 64, 64, 64);
    return square;
 }
 
-Example_Shape *
-_circle_create()
-{
-   Example_Circle *circle;
-
-   circle = efl_add(EXAMPLE_CIRCLE_CLASS, NULL,
-                    efl_name_set(efl_added, "Circle"),
-                    example_circle_radius_set(efl_added, 5));
-
-   return circle;
-}
-
 void
 _shape_print(Example_Shape *shape)
 {
    printf("Shape named %s has area %d\n", efl_name_get(shape), 
example_shape_area(shape));
+
+   if (efl_isa(shape, EXAMPLE_COLORED_MIXIN))
+     {
+        int red, green, blue;
+
+        example_colored_color_get(shape, &red, &green, &blue);
+        printf("  Colored %d, %d, %d\n", red, green, blue);
+     }
 }
 
 EAPI_MAIN void
@@ -48,15 +58,15 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev 
EINA_UNUSED)
 {
    Eo *shape;
 
-   shape = _rectangle_create();
+   shape = _circle_create();
    _shape_print(shape);
    efl_unref(shape);
 
-   shape = _square_create();
+   shape = _rectangle_create();
    _shape_print(shape);
    efl_unref(shape);
 
-   shape = _circle_create();
+   shape = _square_create();
    _shape_print(shape);
    efl_unref(shape);
 
diff --git a/tutorial/c/eo-multiinherit/src/example_circle.c 
b/tutorial/c/eo-multiinherit/src/example_circle.c
index 2051a80..74541fb 100644
--- a/tutorial/c/eo-multiinherit/src/example_circle.c
+++ b/tutorial/c/eo-multiinherit/src/example_circle.c
@@ -2,7 +2,7 @@
 #include <Eo.h>
 #include "example_circle.eo.h"
 
-#include "eo_inherit.h"
+#include "eo_multiinherit.h"
 
 typedef struct
 {
diff --git a/tutorial/c/eo-multiinherit/src/example_colored.c 
b/tutorial/c/eo-multiinherit/src/example_colored.c
new file mode 100644
index 0000000..49d0814
--- /dev/null
+++ b/tutorial/c/eo-multiinherit/src/example_colored.c
@@ -0,0 +1,33 @@
+#define EFL_BETA_API_SUPPORT
+#include <Eo.h>
+#include "example_colored.eo.h"
+
+#include "eo_multiinherit.h"
+
+typedef struct
+{
+   int red, green, blue;
+} Example_Colored_Data;
+
+EOLIAN static void
+_example_colored_color_set(Eo *obj EINA_UNUSED, Example_Colored_Data *pd,
+                           int red, int green, int blue)
+{
+   pd->red = red;
+   pd->green = green;
+   pd->blue = blue;
+}
+
+EOLIAN static void
+_example_colored_color_get(Eo *obj EINA_UNUSED, Example_Colored_Data *pd,
+                           int *red, int *green, int *blue)
+{
+   if (red)
+     *red = pd->red;
+   if (green)
+     *green = pd->green;
+   if (blue)
+     *blue = pd->blue;
+}
+
+#include "example_colored.eo.c"
diff --git a/tutorial/c/eo-multiinherit/src/example_colored.eo 
b/tutorial/c/eo-multiinherit/src/example_colored.eo
new file mode 100644
index 0000000..80fa8de
--- /dev/null
+++ b/tutorial/c/eo-multiinherit/src/example_colored.eo
@@ -0,0 +1,18 @@
+mixin Example.Colored {
+   [[A mixin for providing APIs for managing colour properties]]
+   methods {
+      @property color {
+         [[The colour to associate with the class we are coloring.
+           We use RGB to manage the colour, so have 3 in and out parameters.]]
+         get {
+         }
+         set {
+         }
+         values {
+            red: int; [[The red colour channel]]
+            green: int; [[The green colour channel]]
+            blue: int; [[The blue colour channel]]
+         }
+      }
+   }
+}
diff --git a/tutorial/c/eo-multiinherit/src/example_rectangle.c 
b/tutorial/c/eo-multiinherit/src/example_rectangle.c
index f2128bd..3062f90 100644
--- a/tutorial/c/eo-multiinherit/src/example_rectangle.c
+++ b/tutorial/c/eo-multiinherit/src/example_rectangle.c
@@ -2,7 +2,7 @@
 #include <Eo.h>
 #include "example_rectangle.eo.h"
 
-#include "eo_inherit.h"
+#include "eo_multiinherit.h"
 
 typedef struct
 {
diff --git a/tutorial/c/eo-multiinherit/src/example_rectangle.eo 
b/tutorial/c/eo-multiinherit/src/example_rectangle.eo
index 957f09b..82cdc84 100644
--- a/tutorial/c/eo-multiinherit/src/example_rectangle.eo
+++ b/tutorial/c/eo-multiinherit/src/example_rectangle.eo
@@ -1,4 +1,4 @@
-class Example.Rectangle (Efl.Object, Example.Shape) {
+class Example.Rectangle (Efl.Object, Example.Shape, Example.Colored) {
    [[A rectangle shape object]]
    methods {
       @property width {
diff --git a/tutorial/c/eo-multiinherit/src/example_shape.c 
b/tutorial/c/eo-multiinherit/src/example_shape.c
index 1fc8dd0..5fa2226 100644
--- a/tutorial/c/eo-multiinherit/src/example_shape.c
+++ b/tutorial/c/eo-multiinherit/src/example_shape.c
@@ -2,6 +2,6 @@
 #include <Eo.h>
 #include "example_shape.eo.h"
 
-#include "eo_inherit.h"
+#include "eo_multiinherit.h"
 
 #include "example_shape.eo.c"
diff --git a/tutorial/c/eo-multiinherit/src/example_square.c 
b/tutorial/c/eo-multiinherit/src/example_square.c
index 8ebb696..da5120f 100644
--- a/tutorial/c/eo-multiinherit/src/example_square.c
+++ b/tutorial/c/eo-multiinherit/src/example_square.c
@@ -2,7 +2,7 @@
 #include <Eo.h>
 #include "example_square.eo.h"
 
-#include "eo_inherit.h"
+#include "eo_multiinherit.h"
 
 typedef struct
 {
diff --git a/tutorial/c/eo-multiinherit/src/meson.build 
b/tutorial/c/eo-multiinherit/src/meson.build
index 26fffb7..23cf36b 100644
--- a/tutorial/c/eo-multiinherit/src/meson.build
+++ b/tutorial/c/eo-multiinherit/src/meson.build
@@ -1,6 +1,7 @@
 eolian_gen = find_program('eolian_gen')
 
-eo_src = ['example_shape', 'example_rectangle', 'example_square', 
'example_circle']
+eo_src = ['example_shape', 'example_colored', 'example_rectangle',
+          'example_square', 'example_circle']
 eo_csrc = []
 eo_gen = []
 
@@ -19,8 +20,8 @@ foreach eo : eo_src
 endforeach
 
 src = files([
-  'eo_inherit.h',
-  'eo_inherit_main.c',
+  'eo_multiinherit.h',
+  'eo_multiinherit_main.c',
 ])
 
 deps = [eina, efl]

-- 


Reply via email to