Edje: Color class documentation

By: ceolin <flavio.ceolin@profusion.mobi>



SVN revision: 62065
This commit is contained in:
Iván Briano 2011-08-03 18:57:38 +00:00
parent fd7f67a183
commit 941adf033b
7 changed files with 3179 additions and 39 deletions

View File

@ -7,6 +7,7 @@
* @li @ref tutorial_edje_swallow
* @li @ref tutorial_edje_text
* @li @ref tutorial_edje_table
* @li @ref tutorial_edje_color_class
* @li @ref Example_Edje_Signals_Messages
* @li @ref tutorial_edje_box
* @li @ref tutorial_edje_box2
@ -518,3 +519,71 @@
* @include edje-signals-messages.c
* @example edje-signals-messages.c
*/
/**
* @page tutorial_edje_color_class Edje Color Class example
* @dontinclude edje-color-class.c
*
* 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 proccess 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, althoug 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:
* @skip static color colors_init_data
* @until return EINA_FALSE
* @until }
*
* 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).
* @skip edje_color_class_set
* @until Text shadow
* @until Text shadow
* @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.
* @dontinclude edje-color-class.c
* @skip _color_classes_print(void)
* @until free
* @until }
* @until }
*
* 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 emmited when a color class is deleted.
* @skip evas_object_event
* @until NULL
* @skip edje_object_si
* @until process
*
* And then we delete the color class:
* @dontinclude edje-color-class.c
* @skip _on_mouse_down
* @until }
*
* Our example will look like this, if you run with the parameters "green_class gray pink yellow":
*
* @image html edje-color-class-example.png
* @image rtf edje-color-class-example.png
* @image latex edje-color-class-example.eps
*
* The full source code follows:
* @include edje-color-class.c
* @example edje-color-class.c
*
* The theme used in this example is:
* @include color-class.edc
* @example color-class.edc
*/

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -8,7 +8,8 @@ EDCS = basic.edc \
text.edc \
table.edc \
box.edc \
signals-messages.edc
signals-messages.edc \
color-class.edc
filesdir = $(datadir)/$(PACKAGE)/examples
files_DATA =
@ -36,7 +37,8 @@ pkglib_PROGRAMS += \
edje-table \
edje-box \
edje-box2 \
edje-signals-messages
edje-signals-messages \
edje-color-class
LDADD = $(top_builddir)/src/lib/libedje.la @EDJE_LIBS@
@ -62,7 +64,8 @@ files_DATA += \
$(srcdir)/edje-table.c \
$(srcdir)/edje-box.c \
$(srcdir)/edje-box2.c \
$(srcdir)/edje-signals-messages.c
$(srcdir)/edje-signals-messages.c \
$(srcdir)/edje-color-class.c
endif
EXTRA_DIST = $(EDCS) \
@ -73,4 +76,5 @@ EXTRA_DIST = $(EDCS) \
$(srcdir)/edje-table.c \
$(srcdir)/edje-box.c \
$(srcdir)/edje-box2.c \
$(srcdir)/edje-signals-messages.c
$(srcdir)/edje-signals-messages.c \
$(srcdir)/edje-color-class.c

View File

@ -0,0 +1,87 @@
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;
}
}
}
}
}
}

View File

@ -0,0 +1,257 @@
/**
* Simple Edje example illustrating color class functions.
*
* You'll need at least one Evas engine built for it (excluding the
* buffer one). See stdout/stderr for output.
*
* @verbatim
* edje_cc color-class.edc && gcc -o edje-table edje-color-class.c `pkg-config --libs --cflags evas ecore ecore-evas edje`
* @endverbatim
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define PACKAGE_EXAMPLES_DIR "."
#define __UNUSED__
#endif
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <Edje.h>
#define WIDTH (400)
#define HEIGHT (400)
static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/color-class.edj";
typedef int color[4]; /* rgba */
static Ecore_Evas *ee, *ee2;
static Evas *evas, *evas2;
static Evas_Object *bg, *edje_obj, *bg2, *edje_obj2;
static const char *selected_class;
static color colors_init_data[] =
{{255, 0, 0, 255}, /* red */
{0, 255, 0, 255}, /* green */
{0, 0, 255, 255}, /* blue */
{0, 0, 0, 255}, /* black */
{255, 255, 255, 255}, /* white */
{128, 128, 128, 255}, /* gray */
{255, 255, 0, 255}, /* yellow */
{255, 0, 255, 255} /* pink */
};
static char *color_names[] =
{"red", "green", "blue", "black", "white",
"gray", "yellow", "pink"};
static Eina_Bool
_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];
return EINA_TRUE;
}
return EINA_FALSE;
}
static void
_color_classes_print(void)
{
Eina_List *classes;
char *class_name;
fprintf(stdout, "Getting the color classes\n\n");
classes = edje_color_class_list();
EINA_LIST_FREE(classes, class_name)
{
int r1, r2, r3, g1, g2, g3, b1, b2, b3,
a1, a2, a3;
fprintf(stdout, "\ncolor class: %s\n", class_name);
if (!edje_color_class_get(class_name, &r1, &g1, &b1, &a1,
&r2, &g2, &b2, &a2, &r3, &g3, &b3, &a3))
fprintf(stderr, "Cannot get the color class\n");
else
{
fprintf(stdout,"Object color r: %d g: %d b: %d a: %d\n",
r1, g1, b1, a1);
fprintf(stdout,"Text outline color r: %d g: %d b: %d a: %d\n",
r2, g2, b2, a2);
fprintf(stdout,"Text shadow color r: %d g: %d b: %d a: %d\n",
r3, g3, b3, a3);
}
free(class_name);
}
}
static void
_on_destroy(Ecore_Evas *ee)
{
ecore_main_loop_quit();
}
static void
_on_mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info)
{
Evas_Event_Mouse_Down *ev = event_info;
if (ev->button == 1)
if (obj == edje_obj)
edje_color_class_del(selected_class);
else
edje_object_color_class_del(edje_obj2, selected_class);
}
/* here just to keep our example's window size
* in synchrony. */
static void
_canvas_resize_cb(Ecore_Evas *_ee)
{
int w, h;
ecore_evas_geometry_get(_ee, NULL, NULL, &w, &h);
if (_ee == ee)
{
evas_object_resize(bg, w, h);
evas_object_resize(edje_obj, w, h);
}
else
{
evas_object_resize(bg2, w, h);
evas_object_resize(edje_obj2, w, h);
}
}
static void
_color_class_callback_delete(void *data, Evas *evas, Evas_Object *obj,
const char *emission, void *source)
{
if (!strcmp(data, "process"))
fprintf(stdout, "Color class: %s deleted on process level\n", emission);
else
fprintf(stdout, "Color class: %s deleted on object level\n", emission);
}
static void
_create_windows(void)
{
/* this will give you a window with an Evas canvas under the first
* engine available */
ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
ee2 = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
ecore_evas_callback_destroy_set(ee, _on_destroy);
ecore_evas_callback_resize_set(ee, _canvas_resize_cb);
ecore_evas_title_set(ee, "Edje Color Class Example");
ecore_evas_show(ee);
ecore_evas_callback_destroy_set(ee2, _on_destroy);
ecore_evas_callback_resize_set(ee2, _canvas_resize_cb);
ecore_evas_title_set(ee2, "Edje Object Color Class Example");
ecore_evas_show(ee2);
evas = ecore_evas_get(ee);
evas2 = ecore_evas_get(ee2);
bg = evas_object_rectangle_add(evas);
evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */
evas_object_move(bg, 0, 0); /* at canvas' origin */
evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */
evas_object_show(bg);
bg2 = evas_object_rectangle_add(evas2);
evas_object_color_set(bg2, 255, 255, 255, 255); /* white bg */
evas_object_move(bg2, 0, 0); /* at canvas' origin */
evas_object_resize(bg2, WIDTH, HEIGHT); /* covers full canvas */
evas_object_show(bg2);
edje_obj = edje_object_add(evas);
evas_object_event_callback_add(edje_obj, EVAS_CALLBACK_MOUSE_DOWN,
_on_mouse_down, NULL);
edje_object_file_set(edje_obj, edje_file_path, "example_color_class");
evas_object_move(edje_obj, 0, 0); /* at canvas' origin */
evas_object_resize(edje_obj, WIDTH, HEIGHT);
edje_object_part_text_set(edje_obj, "part_four", "EDJE EXAMPLE");
edje_object_signal_callback_add(edje_obj, "color_class,del", "*",
(Edje_Signal_Cb) _color_class_callback_delete,
"process");
evas_object_show(edje_obj);
edje_obj2 = edje_object_add(evas2);
evas_object_event_callback_add(edje_obj2, EVAS_CALLBACK_MOUSE_DOWN,
_on_mouse_down, NULL);
edje_object_file_set(edje_obj2, edje_file_path, "example_color_class");
evas_object_move(edje_obj2, 0, 0); /* at canvas' origin */
evas_object_resize(edje_obj2, WIDTH, HEIGHT);
edje_object_part_text_set(edje_obj2, "part_four", "EDJE OBJECT EXAMPLE");
edje_object_signal_callback_add(edje_obj2, "color_class,del", "*",
(Edje_Signal_Cb) _color_class_callback_delete,
"object");
evas_object_show(edje_obj2);
}
int
main(int argc, char *argv[])
{
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 1;
}
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 2;
}
ecore_evas_init();
edje_init();
_create_windows();
edje_color_class_set(argv[1], /* class name */
c1[0], c1[1], c1[2], c1[3], /* Object color */
c2[0], c2[1], c2[2], c2[3], /* Text outline */
c3[0], c3[1], c3[2], c3[3]); /* Text shadow */
/* Setting an arbitrary value just to see the difference between */
/* process level and object level */
edje_object_color_class_set(edje_obj2, argv[1], /* class name */
128, 180, 77, 255, /* Object color */
200, 22, 86, 255, /* Text outline */
39, 90, 187, 255); /* Text shadow */
_color_classes_print();
ecore_main_loop_begin();
ecore_evas_free(ee);
ecore_evas_free(ee2);
ecore_evas_shutdown();
edje_shutdown();
return 0;
}

View File

@ -451,6 +451,7 @@ part of Edje's API:
- @ref tutorial_edje_table
- @ref tutorial_edje_box
- @ref tutorial_edje_box2
- @ref tutorial_edje_color_class
- @ref Example_Edje_Signals_Messages
@ -1533,19 +1534,31 @@ EAPI Eina_Bool edje_color_class_set (const char *color_class, int
EAPI Eina_Bool edje_color_class_get (const char *color_class, int *r, int *g, int *b, int *a, int *r2, int *g2, int *b2, int *a2, int *r3, int *g3, int *b3, int *a3);
/**
* @brief Delete the object color class.
* @brief Delete edje color class.
*
* @param obj The edje object's reference.
* @param color_class The color class to be deleted.
* @param color_class
*
* This function deletes any values at the object level for the
* specified object and color class.
* This function deletes any values at the process level for the
* specified color class.
* @note Deleting the color class will revert it to the
* values defined in the theme file.
*
* Deleting color emits a signal "color_class,del" with source being
* the given color.
* Deleting the color class will emit the signal "color_class,del"
* to all the Edje objects in the running program.
*/
EAPI void edje_color_class_del (const char *color_class);
EAPI Eina_List *edje_color_class_list (void);
/**
* @brief Lists color classes.
*
* @return A list of color class names (strings). These strings and
* the list must be free()'d by the caller.
*
* This function lists all color classes known about by the current
* process.
*
*/
EAPI Eina_List *edje_color_class_list (void);
/**
* @brief Set the Edje text class.
@ -1554,8 +1567,10 @@ EAPI void edje_color_class_del (const char *color_class);
* @param font The font name
* @param size The font size
*
* This function sets updates all edje members which belong to this
* text class with the new font attributes.
* @return @c EINA_TRUE, on success or @c EINA_FALSE, on error
*
* This function updates all Edje members at the process level which
* belong to this text class with the new font attributes.
*
* @see edje_text_class_get().
*
@ -2077,35 +2092,12 @@ EAPI int edje_object_thaw (Evas_Object *obj);
* @note unlike Evas, Edje colors are @b not pre-multiplied. That is,
* half-transparent white is 255 255 255 128.
*/
/**
* @brief Lists color classes.
*
* @return A list of color class names (strings). These strings and
* the list must be free()'d by the caller.
*
* This function lists all color classes known about by the current
* process.
*
*/
/**
* @brief Delete edje color class.
*
* @param color_class
*
* This function deletes any values at the process level for the
* specified color class.
*
* Deleting color emits a signal "color_class,del" with source being
* the given color class in all objects.
*/
EAPI Eina_Bool edje_object_color_class_set (Evas_Object *obj, const char *color_class, int r, int g, int b, int a, int r2, int g2, int b2, int a2, int r3, int g3, int b3, int a3);
/**
* @brief Gets the object color class.
*
* @param obj A valid Evas_Object handle
* @param o A valid Evas_Object handle
* @param color_class
* @param r Object Red value
* @param g Object Green value
@ -2135,7 +2127,23 @@ EAPI Eina_Bool edje_object_color_class_set (Evas_Object *obj, const c
* half-transparent white is 255 255 255 128.
*/
EAPI Eina_Bool edje_object_color_class_get (const Evas_Object *o, const char *color_class, int *r, int *g, int *b, int *a, int *r2, int *g2, int *b2, int *a2, int *r3, int *g3, int *b3, int *a3);
EAPI void edje_object_color_class_del (Evas_Object *obj, const char *color_class);
/**
* @brief Delete the object color class.
*
* @param obj The edje object's reference.
* @param color_class The color class to be deleted.
*
* This function deletes any values at the object level for the
* specified object and color class.
* @note Deleting the color class will revert it to the values
* defined by edje_color_class_set() or the color class
* defined in the theme file.
*
* Deleting the color class will emit the signal "color_class,del"
* for the given Edje object.
*/
EAPI void edje_object_color_class_del (Evas_Object *obj, const char *color_class);
/**
* @brief Sets Edje text class.
@ -2145,6 +2153,8 @@ EAPI Eina_Bool edje_object_color_class_get (const Evas_Object *o, con
* @param font Font name
* @param size Font Size
*
* @return @c EINA_TRUE, on success or @c EINA_FALSE, on error
*
* This function sets the text class for the Edje.
*
*/