This example shows how to manipulate and change Color classes. In this example we will create two surfaces to show what happens when you change the color class at the process and object level.
It's a very simple example, there are two surfaces created from the same EDC, but just in one of them we will set a specific color class, although both will be affected by color class set at the process level as you will see.
It's important you know that all colors has the format R G B A. Just to be easier to understand this example, we will create a small set of colors that will be used along of the example. This piece of code is shown below:
static color colors_init_data[] =
{{255, 0, 0, 255},
{0, 255, 0, 255},
{0, 0, 255, 255},
{0, 0, 0, 255},
{255, 255, 255, 255},
{128, 128, 128, 255},
{255, 255, 0, 255},
{255, 0, 255, 255}
};
static char *color_names[] =
{"red", "green", "blue", "black", "white",
"gray", "yellow", "pink"};
_get_color_from_name(const char *n, color *c)
{
int i;
for (i = 0; i < 8; i++)
if (!strcmp(n, color_names[i]))
{
(*c)[0] = (colors_init_data[i])[0];
(*c)[1] = (colors_init_data[i])[1];
(*c)[2] = (colors_init_data[i])[2];
(*c)[3] = (colors_init_data[i])[3];
}
}
Focusing on the relevant parts of the code we go right to the part where we set the new color class. For that we will use the functions edje_color_class_set ( which will affect all edjes) and edje_object_color_class_set (which affects just the specific object).
c1[0], c1[1], c1[2], c1[3],
c2[0], c2[1], c2[2], c2[3],
c3[0], c3[1], c3[2], c3[3]);
128, 180, 77, 255,
200, 22, 86, 255,
39, 90, 187, 255);
- Note
- argv[1] is the name of a color class used in the EDC.
- The second and third colors only apply to text part.
- The color class set for the object overrides the color previously set.
After we have set the color class we will check the color classes, for that we created a function which prints all color classes and tries to get theirs values and print too.
_color_classes_print(void)
{
char *class_name;
printf("Getting the color classes\n\n");
{
int r1, r2, r3, g1, g2, g3, b1, b2, b3,
a1, a2, a3;
printf("\ncolor class: %s\n", class_name);
&r2, &g2, &b2, &a2, &r3, &g3, &b3, &a3))
fprintf(stderr, "Cannot get the color class\n");
else
{
printf("Object color r: %d g: %d b: %d a: %d\n",
r1, g1, b1, a1);
printf("Text outline color r: %d g: %d b: %d a: %d\n",
r2, g2, b2, a2);
printf("Text shadow color r: %d g: %d b: %d a: %d\n",
r3, g3, b3, a3);
}
free(class_name);
}
}
There are two other things that are worth mentioning, we added two callbacks for the objects, one for mouse down (that we use to delete the color class) and another for the signal emitted when a color class is deleted.
_on_mouse_down, NULL);
(Edje_Signal_Cb) _color_class_callback_delete,
"process");
And then we delete the color class:
{
{
if (obj == edje_obj1)
else
}
Our example will look like this, if you run with the parameters "green_class gray pink yellow":
The full source code follows:
#ifdef HAVE_CONFIG_H
# include "config.h"
#else
# define EINA_UNUSED
#endif
#ifndef PACKAGE_DATA_DIR
#define PACKAGE_DATA_DIR "."
#endif
#include <Ecore.h>
#define WIDTH (400)
#define HEIGHT (400)
typedef int color[4];
static Ecore_Evas *ee1, *ee2;
static Evas *evas1, *evas2;
static const char *selected_class;
static color colors_init_data[] =
{{255, 0, 0, 255},
{0, 255, 0, 255},
{0, 0, 255, 255},
{0, 0, 0, 255},
{255, 255, 255, 255},
{128, 128, 128, 255},
{255, 255, 0, 255},
{255, 0, 255, 255}
};
static char *color_names[] =
{"red", "green", "blue", "black", "white",
"gray", "yellow", "pink"};
_get_color_from_name(const char *n, color *c)
{
int i;
for (i = 0; i < 8; i++)
if (!strcmp(n, color_names[i]))
{
(*c)[0] = (colors_init_data[i])[0];
(*c)[1] = (colors_init_data[i])[1];
(*c)[2] = (colors_init_data[i])[2];
(*c)[3] = (colors_init_data[i])[3];
}
}
static void
_color_classes_print(void)
{
char *class_name;
printf("Getting the color classes\n\n");
{
int r1, r2, r3, g1, g2, g3, b1, b2, b3,
a1, a2, a3;
printf("\ncolor class: %s\n", class_name);
&r2, &g2, &b2, &a2, &r3, &g3, &b3, &a3))
fprintf(stderr, "Cannot get the color class\n");
else
{
printf("Object color r: %d g: %d b: %d a: %d\n",
r1, g1, b1, a1);
printf("Text outline color r: %d g: %d b: %d a: %d\n",
r2, g2, b2, a2);
printf("Text shadow color r: %d g: %d b: %d a: %d\n",
r3, g3, b3, a3);
}
free(class_name);
}
}
static void
{
}
static void
{
{
if (obj == edje_obj1)
else
}
}
static void
_canvas_resize_cb(Ecore_Evas *_ee)
{
int w, h;
if (_ee == ee1)
{
}
else
{
}
}
static void
{
if (!strcmp(data, "process"))
printf("Color class: %s deleted on process level\n", emission);
else
printf("Color class: %s deleted on object level\n", emission);
}
static int
_create_windows(const char *edje_file_path)
{
if (!ee1)
return 0;
if (!ee2)
return 0;
_on_mouse_down, NULL);
(Edje_Signal_Cb) _color_class_callback_delete,
"process");
_on_mouse_down, NULL);
(Edje_Signal_Cb) _color_class_callback_delete,
"object");
return 1;
}
int
main(int argc, char *argv[])
{
const char *edje_file = PACKAGE_DATA_DIR"/color-class.edj";
color c1, c2, c3;
int i;
if (argc != 5)
{
fprintf(stderr, "You have to use: %s color_class_name color1, color2," \
"color3\n", argv[0]);
fprintf(stderr, "Available colors:\n");
for (i = 0; i < 8; i++)
fprintf(stderr, "%s\n", color_names[i]);
return EXIT_FAILURE;
}
selected_class = argv[1];
if (!(_get_color_from_name(argv[2], &c1) &&
_get_color_from_name(argv[3], &c2) &&
_get_color_from_name(argv[4], &c3)))
{
fprintf(stderr, "Color not available!\n");
return EXIT_FAILURE;
}
return EXIT_FAILURE;
goto shutdown_ecore_evas;
if (!_create_windows(edje_file)) goto shutdown_edje;
c1[0], c1[1], c1[2], c1[3],
c2[0], c2[1], c2[2], c2[3],
c3[0], c3[1], c3[2], c3[3]);
128, 180, 77, 255,
200, 22, 86, 255,
39, 90, 187, 255);
_color_classes_print();
return EXIT_SUCCESS;
shutdown_edje:
shutdown_ecore_evas:
return EXIT_FAILURE;
}
The theme used in this example is:
color_classes {
color_class {
name: "red_class";
color: 255 0 0 255; /* red */
color2: 255 0 0 255; /* red */
color3: 255 0 0 255; /* red */
}
color_class {
name: "green_class";
color: 0 255 0 255; /* green */
color2: 0 255 0 255; /* green */
color3: 0 255 0 255; /* green */
}
color_class {
name: "blue_class";
color: 0 0 255 255; /* blue */
color2: 0 0 255 255; /* blue */
color3: 0 0 255 255; /* blue */
}
}
collections {
group {
name: "example_color_class";
max: 500 500;
min: 50 50;
parts {
part {
name: "part_one";
type: RECT;
scale: 1;
description {
state: "default" 0.0;
color: 255 255 255 255;
color_class: "blue_class";
rel1.relative: 0.0 0.0;
rel2.relative: 0.5 0.5;
}
}
part {
name: "part_two";
type: RECT;
description {
state: "default" 0.0;
color: 255 255 255 255;
color_class: "green_class";
rel1.relative: 0.5 0.0;
rel2.relative: 1.0 0.5;
}
}
part {
name: "part_three";
type: RECT;
description {
state: "default" 0.0;
color: 255 255 255 255;
color_class: "red_class";
rel1.relative: 0.0 0.5;
rel2.relative: 1.0 1.0;
}
}
part {
name: "part_four";
type: TEXT;
effect: OUTLINE_SHADOW;
description {
state: "default" 0.0;
min: 50 50;
color: 255 255 255 255;
color2: 255 255 255 255;
color3: 255 255 255 255;
color_class: "blue_class";
rel1.relative: 0.0 0.5;
rel2.relative: 1.0 1.0;
text {
text_class: "example";
font: "arial";
size: 45;
min: 1 1;
ellipsis: -1;
}
}
}
}
}
}
To compile use this command:
* gcc -o edje-color-class edje-color-class.c -DPACKAGE_BIN_DIR=\"/Where/enlightenment/is/installed/bin\"
* -DPACKAGE_LIB_DIR=\"/Where/enlightenment/is/installed/lib\"
* -DPACKAGE_DATA_DIR=\"/Where/enlightenment/is/installed/share\"
* `pkg-config --cflags --libs evas ecore ecore-evas edje`
*
* edje_cc color-class.edc
*