summaryrefslogtreecommitdiff
path: root/src/examples/eolian_cxx/colourable.c
blob: 3e289583ddb6a35ce5d23b0c14edf248e1ad80aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <stdio.h>

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "Eo.h"
#include "Eina.h"
#include "colourable.eo.h"

#define MY_CLASS COLOURABLE_CLASS

static int _colourable_impl_logdomain;

#ifdef DBG
#undef DBG
#endif
#define DBG(...) EINA_LOG_DOM_DBG(_colourable_impl_logdomain, __VA_ARGS__)

#ifdef INFO
#undef INFO
#endif
#define INFO(...) EINA_LOG_DOM_INFO(_colourable_impl_logdomain, __VA_ARGS__)

#ifdef ERR
#undef ERR
#endif
#define ERR(...) EINA_LOG_DOM_ERR(_colourable_impl_logdomain, __VA_ARGS__)

struct _Colourable_Data
{
   int r;
   int g;
   int b;
};

typedef struct _Colourable_Data  Colourable_Data;

#define COLOURABLE_DATA_GET(o, wd)                             \
  Colourable_Data *wd = eo_data_scope_get(o, MY_CLASS)

void
_colourable_constructor(Eo *obj, Colourable_Data *self)
{
   if(!_colourable_impl_logdomain)
     {
        _colourable_impl_logdomain
          = eina_log_domain_register("colourable", EINA_COLOR_BLUE);
     }
   DBG("_colourable_constructor(%p, %p)\n", obj, MY_CLASS);
   eo_do_super(obj, MY_CLASS, eo_constructor());
}

void
_colourable_destructor(Eo *obj, Colourable_Data *self)
{
   if(_colourable_impl_logdomain)
     {
        eina_log_domain_unregister(_colourable_impl_logdomain);
        _colourable_impl_logdomain = 0;
     }
   DBG("_colourable_destructor()\n");
   eo_do_super(obj, MY_CLASS, eo_destructor());
}

void
_colourable_rgb_composite_constructor(Eo *obj, Colourable_Data *self, int r, int g, int b)
{
   if(!_colourable_impl_logdomain)
     {
        _colourable_impl_logdomain
          = eina_log_domain_register("colourable", EINA_COLOR_BLUE);
     }
   self->r = r;
   self->g = g;
   self->b = b;
   DBG("_colourable_rgb_composite_constructor(0x%2.x, %0x2.x, %0x2.x)\n",
       (unsigned int)self->r,
       (unsigned int)self->g,
       (unsigned int)self->b);
   eo_do_super(obj, MY_CLASS, eo_constructor());
}

void
_colourable_rgb_24bits_constructor(Eo *obj, Colourable_Data *self, int rgb)
{
   if(!_colourable_impl_logdomain)
     {
        _colourable_impl_logdomain
          = eina_log_domain_register("colourable", EINA_COLOR_BLUE);
     }

   self->r = (rgb & 0x00ff0000) >> 16;
   self->g = (rgb & 0x0000ff00) >> 8;
   self->b = rgb & 0x000000ff;
   DBG("_colourable_rgb_24bits_constructor(0x%.6x)\n", (int)rgb);
   eo_do_super(obj, MY_CLASS, eo_constructor());
}

void
_colourable_print_colour(Eo *obj, Colourable_Data *self)
{
   DBG("_colourable_print_colour() ==> 0x%2.x 0x%2.x 0x%2.x\n", self->r, self->g, self->b);
}

int
_colourable_colour_mask(Eo *obj, Colourable_Data *self, int mask)
{
   int masked_rgb =
     (((self->r << 16)& 0x00ff0000) |
      ((self->g << 8) & 0x0000ff00) |
      (self->b & 0x000000ff)) & mask;
   DBG("_colourable_colour_mask() ==> 0x%2.x\n", (unsigned int)masked_rgb);
   return masked_rgb;
}

void
_colourable_composite_colour_get(Eo *obj, Colourable_Data *self, int* r, int* g, int* b)
{
   *r = self->r;
   *g = self->g;
   *b = self->b;
   DBG("_colourable_composite_colour_get() ==> 0x%2.x 0x%2.x 0x%2.x\n", *r, *g, *b);
   return;
}

void
_colourable_composite_colour_set(Eo *obj, Colourable_Data *self, int r, int g, int b)
{
   self->r = r;
   self->g = g;
   self->b = b;
   DBG("_colourable_composite_colour_set(0x%2.x, 0x%2.x, 0x%2.x)\n",
       (int)self->r, (int)self->g, (int)self->b);
   return;
}

int
_colourable_colour_get(Eo *obj, Colourable_Data *self)
{
   int rgb =
     ((self->r << 16)& 0x00ff0000) |
     ((self->g << 8) & 0x0000ff00) |
     (self->b & 0x000000ff);
   DBG("_colourable_colour_get() ==> 0x%.6x\n", (unsigned int)rgb);
   return rgb;
}

void
_colourable_colour_set(Eo *obj, Colourable_Data *self, int rgb)
{
   self->r = (rgb & 0x00ff0000) >> 16;
   self->g = (rgb & 0x0000ff00) >> 8;
   self->b = rgb & 0x000000ff;
   DBG("_colourable_colour_set(0x%.6x)\n", (unsigned int)rgb);
   return;
}

static void
_user_colourable_class_constructor(Eo_Class *klass)
{
   DBG("_colourable_class_constructor()\n");
}

#include "colourable.eo.c"