Add a colored mixin so we can talk about multiple inheritance
This commit is contained in:
parent
6e78b6caa3
commit
1acb71b216
|
@ -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"
|
|
@ -1,29 +1,4 @@
|
|||
#include "eo_inherit.h"
|
||||
|
||||
Example_Shape *
|
||||
_rectangle_create()
|
||||
{
|
||||
Example_Rectangle *rectangle;
|
||||
|
||||
rectangle = efl_add(EXAMPLE_RECTANGLE_CLASS, NULL,
|
||||
efl_name_set(efl_added, "Rectangle"),
|
||||
example_rectangle_width_set(efl_added, 5),
|
||||
example_rectangle_height_set(efl_added, 10));
|
||||
|
||||
return rectangle;
|
||||
}
|
||||
|
||||
Example_Shape *
|
||||
_square_create()
|
||||
{
|
||||
Example_Square *square;
|
||||
|
||||
square = efl_add(EXAMPLE_SQUARE_CLASS, NULL,
|
||||
efl_name_set(efl_added, "Square"),
|
||||
example_rectangle_width_set(efl_added, 7));
|
||||
|
||||
return square;
|
||||
}
|
||||
#include "eo_multiinherit.h"
|
||||
|
||||
Example_Shape *
|
||||
_circle_create()
|
||||
|
@ -37,10 +12,45 @@ _circle_create()
|
|||
return circle;
|
||||
}
|
||||
|
||||
Example_Shape *
|
||||
_rectangle_create()
|
||||
{
|
||||
Example_Rectangle *rectangle;
|
||||
|
||||
rectangle = efl_add(EXAMPLE_RECTANGLE_CLASS, NULL,
|
||||
efl_name_set(efl_added, "Rectangle"),
|
||||
example_rectangle_width_set(efl_added, 5),
|
||||
example_rectangle_height_set(efl_added, 10));
|
||||
|
||||
example_colored_color_set(rectangle, 255, 0, 0);
|
||||
return rectangle;
|
||||
}
|
||||
|
||||
Example_Shape *
|
||||
_square_create()
|
||||
{
|
||||
Example_Square *square;
|
||||
|
||||
square = efl_add(EXAMPLE_SQUARE_CLASS, NULL,
|
||||
efl_name_set(efl_added, "Square"),
|
||||
example_rectangle_width_set(efl_added, 7));
|
||||
|
||||
example_colored_color_set(square, 64, 64, 64);
|
||||
return square;
|
||||
}
|
||||
|
||||
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,6 +58,10 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
|||
{
|
||||
Eo *shape;
|
||||
|
||||
shape = _circle_create();
|
||||
_shape_print(shape);
|
||||
efl_unref(shape);
|
||||
|
||||
shape = _rectangle_create();
|
||||
_shape_print(shape);
|
||||
efl_unref(shape);
|
||||
|
@ -56,10 +70,6 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
|||
_shape_print(shape);
|
||||
efl_unref(shape);
|
||||
|
||||
shape = _circle_create();
|
||||
_shape_print(shape);
|
||||
efl_unref(shape);
|
||||
|
||||
efl_exit(0);
|
||||
}
|
||||
EFL_MAIN()
|
|
@ -2,7 +2,7 @@
|
|||
#include <Eo.h>
|
||||
#include "example_circle.eo.h"
|
||||
|
||||
#include "eo_inherit.h"
|
||||
#include "eo_multiinherit.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
|
|
@ -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"
|
|
@ -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]]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
#include <Eo.h>
|
||||
#include "example_rectangle.eo.h"
|
||||
|
||||
#include "eo_inherit.h"
|
||||
#include "eo_multiinherit.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <Eo.h>
|
||||
#include "example_square.eo.h"
|
||||
|
||||
#include "eo_inherit.h"
|
||||
#include "eo_multiinherit.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue