forked from enlightenment/efl
[evas] Example files for basic object manipulation
functions. SVN revision: 60317
This commit is contained in:
parent
b61a6eea67
commit
4d8c554a08
|
@ -10,6 +10,8 @@
|
|||
* @ref Example_Evas_Load_Error_Str
|
||||
*
|
||||
* @ref Example_Evas_Events
|
||||
*
|
||||
* @ref Example_Evas_Object_Manipulation
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -41,3 +43,10 @@
|
|||
* @include evas-events.c
|
||||
* @example evas-events.c
|
||||
*/
|
||||
|
||||
/**
|
||||
* @page Example_Evas_Object_Manipulation Evas objects basic manipulation example
|
||||
*
|
||||
* @include evas-object-manipulation.c
|
||||
* @example evas-object-manipulation.c
|
||||
*/
|
||||
|
|
|
@ -46,10 +46,15 @@ pkglib_PROGRAMS += evas_events
|
|||
evas_events_SOURCES = evas-events.c
|
||||
evas_events_LDADD = $(top_builddir)/src/lib/libevas.la @ECORE_EVAS_LIBS@
|
||||
|
||||
pkglib_PROGRAMS += evas_object_manipulation
|
||||
evas_object_manipulation_SOURCES = evas-object-manipulation.c
|
||||
evas_object_manipulation_LDADD = $(top_builddir)/src/lib/libevas.la @ECORE_EVAS_LIBS@
|
||||
|
||||
endif # if BUILD_EXAMPLES
|
||||
|
||||
filesdir = $(datadir)/$(PACKAGE)/examples
|
||||
files_DATA = $(srcdir)/enlightenment.png
|
||||
files_DATA = $(srcdir)/enlightenment.png \
|
||||
$(srcdir)/red.png
|
||||
|
||||
if INSTALL_EXAMPLES
|
||||
files_DATA += \
|
||||
|
|
|
@ -0,0 +1,231 @@
|
|||
/**
|
||||
* Simple Evas example illustrating basic objects manipulation.
|
||||
*
|
||||
* You'll need at least one engine built for it (excluding the buffer
|
||||
* one) and the png image loader also built. See stdout/stderr for
|
||||
* output.
|
||||
*
|
||||
* @verbatim
|
||||
* gcc -o evas-events evas-events.c `pkg-config --libs --cflags ecore-evas`
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <Ecore.h>
|
||||
#include <Ecore_Evas.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define WIDTH (320)
|
||||
#define HEIGHT (240)
|
||||
|
||||
static const char *img_path = PACKAGE_EXAMPLES_DIR "/enlightenment.png";
|
||||
static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
|
||||
|
||||
struct test_data
|
||||
{
|
||||
Ecore_Evas *ee;
|
||||
Evas *canvas;
|
||||
Eina_Bool obscured;
|
||||
Ecore_Timer *resize_timer;
|
||||
Evas_Object *img, *bg, *clipper, *clipper_border, *text;
|
||||
};
|
||||
|
||||
static struct test_data d = {0};
|
||||
|
||||
/* here just to keep our example's window size and background image's
|
||||
* size in synchrony */
|
||||
static void
|
||||
_canvas_resize_cb(Ecore_Evas *ee)
|
||||
{
|
||||
int w, h;
|
||||
|
||||
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
|
||||
evas_object_resize(d.bg, w, h);
|
||||
}
|
||||
|
||||
static void
|
||||
_on_keydown(void *data __UNUSED__,
|
||||
Evas *evas __UNUSED__,
|
||||
Evas_Object *o __UNUSED__,
|
||||
void *einfo)
|
||||
{
|
||||
Evas_Event_Key_Down *ev = einfo;
|
||||
|
||||
if (strcmp(ev->keyname, "h") == 0) /* print help */
|
||||
{
|
||||
fprintf(stdout, "commands are:\n"
|
||||
"\to - change clipper's opacity\n"
|
||||
"\tr - toggle clipper's color between red and white\n"
|
||||
"\tc - toggle clipper's clipping function\n"
|
||||
"\tv - toggle clipper's visibility\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(ev->keyname, "o") == 0) /* change clipper's opacity */
|
||||
{
|
||||
int alpha, r, g, b;
|
||||
|
||||
evas_object_color_get(d.clipper, &r, &g, &b, &alpha);
|
||||
alpha -= 20;
|
||||
if (alpha < 0)
|
||||
alpha = 255;
|
||||
|
||||
evas_object_color_set(d.clipper, r, g, b, alpha);
|
||||
|
||||
fprintf(stdout, "Changing clipper's opacity: %d%%\n",
|
||||
(int)((alpha / 255.0) * 100));
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(ev->keyname, "r") == 0) /* toggle clipper's color
|
||||
* between red and white */
|
||||
{
|
||||
int alpha, r, g, b;
|
||||
|
||||
fprintf(stdout, "Changing clipper's color to");
|
||||
|
||||
evas_object_color_get(d.clipper, &r, &g, &b, &alpha);
|
||||
if (g > 0)
|
||||
{
|
||||
fprintf(stdout, "red\n");
|
||||
g = b = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stdout, "white\n");
|
||||
g = b = 255;
|
||||
}
|
||||
|
||||
evas_object_color_set(d.clipper, r, g, b, alpha);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(ev->keyname, "c") == 0) /* toggle clipper's clipping function */
|
||||
{
|
||||
fprintf(stdout, "Toggling clipping ");
|
||||
|
||||
if (evas_object_clip_get(d.img) == d.clipper)
|
||||
{
|
||||
evas_object_clip_unset(d.img);
|
||||
fprintf(stdout, "off\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
evas_object_clip_set(d.img, d.clipper);
|
||||
fprintf(stdout, "on\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(ev->keyname, "v") == 0) /* toggle clipper's visibility */
|
||||
{
|
||||
fprintf(stdout, "Clipper is now ");
|
||||
|
||||
if (evas_object_visible_get(d.clipper))
|
||||
{
|
||||
evas_object_hide(d.clipper);
|
||||
fprintf(stdout, "hidden\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
evas_object_show(d.clipper);
|
||||
fprintf(stdout, "visible\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (!ecore_evas_init())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
/* this will give you a window with an Evas canvas under the first
|
||||
* engine available */
|
||||
d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
|
||||
if (!d.ee)
|
||||
goto error;
|
||||
|
||||
ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
|
||||
ecore_evas_show(d.ee);
|
||||
|
||||
/* the canvas pointer, de facto */
|
||||
d.canvas = ecore_evas_get(d.ee);
|
||||
|
||||
d.bg = evas_object_rectangle_add(d.canvas);
|
||||
evas_object_name_set(d.bg, "background rectangle");
|
||||
evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
|
||||
evas_object_move(d.bg, 0, 0); /* at canvas' origin */
|
||||
evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
|
||||
evas_object_show(d.bg);
|
||||
|
||||
evas_object_focus_set(d.bg, EINA_TRUE);
|
||||
evas_object_event_callback_add(
|
||||
d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
|
||||
|
||||
d.img = evas_object_image_filled_add(d.canvas);
|
||||
evas_object_image_file_set(d.img, img_path, NULL);
|
||||
err = evas_object_image_load_error_get(d.img);
|
||||
if (err != EVAS_LOAD_ERROR_NONE)
|
||||
{
|
||||
goto panic;
|
||||
}
|
||||
else
|
||||
{
|
||||
evas_object_move(d.img, 0, 0);
|
||||
evas_object_resize(d.img, WIDTH, HEIGHT);
|
||||
evas_object_show(d.img);
|
||||
|
||||
fprintf(stdout, "Image object added, type is: %s\n",
|
||||
evas_object_type_get(d.img));
|
||||
}
|
||||
|
||||
/* border on the image's clipper, here just to emphasize its position */
|
||||
d.clipper_border = evas_object_image_filled_add(d.canvas);
|
||||
evas_object_image_file_set(d.clipper_border, border_img_path, NULL);
|
||||
err = evas_object_image_load_error_get(d.clipper_border);
|
||||
if (err != EVAS_LOAD_ERROR_NONE)
|
||||
{
|
||||
goto panic;
|
||||
}
|
||||
else
|
||||
{
|
||||
evas_object_image_border_set(d.clipper_border, 3, 3, 3, 3);
|
||||
evas_object_image_border_center_fill_set(
|
||||
d.clipper_border, EVAS_BORDER_FILL_NONE);
|
||||
evas_object_move(d.clipper_border, (WIDTH / 4) - 3, (HEIGHT / 4) - 3);
|
||||
evas_object_resize(
|
||||
d.clipper_border, (WIDTH / 2) + 6, (HEIGHT / 2) + 6);
|
||||
evas_object_show(d.clipper_border);
|
||||
}
|
||||
|
||||
/* solid white clipper (note that it's the default color for a
|
||||
* rectangle) - it won't change clippees' colors, then (multiplying
|
||||
* by 255) */
|
||||
d.clipper = evas_object_rectangle_add(d.canvas);
|
||||
evas_object_move(d.clipper, WIDTH / 4, HEIGHT / 4);
|
||||
evas_object_resize(d.clipper, WIDTH / 2, HEIGHT / 2);
|
||||
evas_object_clip_set(d.img, d.clipper);
|
||||
evas_object_show(d.clipper);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
ecore_evas_free(d.ee);
|
||||
ecore_evas_shutdown();
|
||||
return 0;
|
||||
|
||||
error:
|
||||
fprintf(stderr, "you got to have at least one evas engine built and linked"
|
||||
" up to ecore-evas for this example to run properly.\n");
|
||||
panic:
|
||||
ecore_evas_shutdown();
|
||||
return -1;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 185 B |
|
@ -2707,18 +2707,11 @@ EAPI const Eina_List *evas_font_path_list (const Evas *e) EINA_WA
|
|||
* calling evas_object_clip_unset() on the @p obj object.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* extern Evas *evas;
|
||||
* extern Evas_Object *obj;
|
||||
* Evas_Object *clipper;
|
||||
* @dontinclude evas-object-manipulation.c
|
||||
* @skip solid white clipper (note that it's the default color for a
|
||||
* @until evas_object_show(d.clipper);
|
||||
*
|
||||
* clipper = evas_object_rectangle_add(evas);
|
||||
* evas_object_color_set(clipper, 255, 255, 255, 255);
|
||||
* evas_object_move(clipper, 10, 10);
|
||||
* evas_object_resize(clipper, 20, 50);
|
||||
* evas_object_clip_set(obj, clipper);
|
||||
* evas_object_show(clipper);
|
||||
* @endcode
|
||||
* See the full @ref Example_Evas_Object_Manipulation "example".
|
||||
*/
|
||||
EAPI void evas_object_clip_set (Evas_Object *obj, Evas_Object *clip) EINA_ARG_NONNULL(1, 2);
|
||||
|
||||
|
@ -2735,14 +2728,11 @@ EAPI void evas_object_clip_set (Evas_Object *obj, Evas
|
|||
* evas_object_clipees_get().
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* extern Evas_Object *obj;
|
||||
* Evas_Object *clipper;
|
||||
*
|
||||
* clipper = evas_object_clip_get(obj);
|
||||
* if (clipper) evas_object_show(clipper);
|
||||
* @endcode
|
||||
* @dontinclude evas-object-manipulation.c
|
||||
* @skip if (evas_object_clip_get(d.img) == d.clipper)
|
||||
* @until return
|
||||
*
|
||||
* See the full @ref Example_Evas_Object_Manipulation "example".
|
||||
*/
|
||||
EAPI Evas_Object *evas_object_clip_get (const Evas_Object *obj) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE;
|
||||
|
||||
|
@ -2756,21 +2746,8 @@ EAPI Evas_Object *evas_object_clip_get (const Evas_Object *obj
|
|||
* the previous clipper. If it wasn't, this has no effect. The object
|
||||
* @p obj must be a valid ::Evas_Object.
|
||||
*
|
||||
* See also evas_object_clip_set(), evas_object_clipees_get() and
|
||||
* evas_object_clip_get().
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* extern Evas_Object *obj;
|
||||
* Evas_Object *clipper;
|
||||
*
|
||||
* clipper = evas_object_clip_get(obj);
|
||||
* if (clipper)
|
||||
* {
|
||||
* evas_object_clip_unset(obj);
|
||||
* evas_object_hide(obj);
|
||||
* }
|
||||
* @endcode
|
||||
* See also evas_object_clip_set() (for an example),
|
||||
* evas_object_clipees_get() and evas_object_clip_get().
|
||||
*
|
||||
*/
|
||||
EAPI void evas_object_clip_unset (Evas_Object *obj);
|
||||
|
@ -2887,6 +2864,12 @@ EAPI short evas_object_layer_get (const Evas_Object *obj
|
|||
* There might be ocasions where one would like to name his/her
|
||||
* objects.
|
||||
*
|
||||
* Example:
|
||||
* @dontinclude evas-events.c
|
||||
* @skip d.bg = evas_object_rectangle_add(d.canvas);
|
||||
* @until evas_object_name_set(d.bg, "our dear rectangle");
|
||||
*
|
||||
* See the full @ref Example_Evas_Events "example".
|
||||
*/
|
||||
EAPI void evas_object_name_set (Evas_Object *obj, const char *name) EINA_ARG_NONNULL(1);
|
||||
|
||||
|
@ -2896,6 +2879,13 @@ EAPI void evas_object_name_set (Evas_Object *obj, cons
|
|||
* @param obj The given object.
|
||||
* @return The name of the object or @c NULL, if no name has been given
|
||||
* to it.
|
||||
*
|
||||
* Example:
|
||||
* @dontinclude evas-events.c
|
||||
* @skip fprintf(stdout, "An object got focused: %s\n",
|
||||
* @until evas_focus_get
|
||||
*
|
||||
* See the full @ref Example_Evas_Events "example".
|
||||
*/
|
||||
EAPI const char *evas_object_name_get (const Evas_Object *obj) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE;
|
||||
|
||||
|
@ -2995,6 +2985,13 @@ EAPI void evas_object_del (Evas_Object *obj) EINA
|
|||
* @note Naturally, newly created objects are placed at the canvas'
|
||||
* origin: <code>0, 0</code>.
|
||||
*
|
||||
* Example:
|
||||
* @dontinclude evas-object-manipulation.c
|
||||
* @skip evas_object_image_border_set(d.clipper_border, 3, 3, 3, 3);
|
||||
* @until evas_object_show
|
||||
*
|
||||
* See the full @ref Example_Evas_Object_Manipulation "example".
|
||||
*
|
||||
* @ingroup Evas_Object_Group_Basic
|
||||
*/
|
||||
EAPI void evas_object_move (Evas_Object *obj, Evas_Coord x, Evas_Coord y) EINA_ARG_NONNULL(1);
|
||||
|
@ -3055,6 +3052,13 @@ EAPI void evas_object_resize (Evas_Object *obj, Evas
|
|||
* @note Use @c NULL pointers on the geometry components you're not
|
||||
* interested in: they'll be ignored by the function.
|
||||
*
|
||||
* Example:
|
||||
* @dontinclude evas-events.c
|
||||
* @skip int w, h, cw, ch;
|
||||
* @until return
|
||||
*
|
||||
* See the full @ref Example_Evas_Events "example".
|
||||
*
|
||||
* @ingroup Evas_Object_Group_Basic
|
||||
*/
|
||||
EAPI void evas_object_geometry_get (const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h) EINA_ARG_NONNULL(1);
|
||||
|
@ -3096,6 +3100,13 @@ EAPI void evas_object_show (Evas_Object *obj) EINA
|
|||
* @see evas_object_show()
|
||||
* @see evas_object_visible_get()
|
||||
*
|
||||
* Example:
|
||||
* @dontinclude evas-object-manipulation.c
|
||||
* @skip if (evas_object_visible_get(d.clipper))
|
||||
* @until return
|
||||
*
|
||||
* See the full @ref Example_Evas_Object_Manipulation "example".
|
||||
*
|
||||
* @ingroup Evas_Object_Group_Basic
|
||||
*/
|
||||
EAPI void evas_object_hide (Evas_Object *obj) EINA_ARG_NONNULL(1);
|
||||
|
@ -3115,7 +3126,7 @@ EAPI void evas_object_hide (Evas_Object *obj) EINA
|
|||
* stacked below other object.
|
||||
*
|
||||
* @see evas_object_show()
|
||||
* @see evas_object_hide()
|
||||
* @see evas_object_hide() (for an example)
|
||||
*
|
||||
* @ingroup Evas_Object_Group_Basic
|
||||
*/
|
||||
|
@ -3132,7 +3143,7 @@ EAPI Eina_Bool evas_object_visible_get (const Evas_Object *obj
|
|||
* @param b The blue component of the given color.
|
||||
* @param a The alpha component of the given color.
|
||||
*
|
||||
* @see evas_object_color_get()
|
||||
* @see evas_object_color_get() (for an example)
|
||||
*
|
||||
* @ingroup Evas_Object_Group_Basic
|
||||
*/
|
||||
|
@ -3167,6 +3178,13 @@ EAPI void evas_object_color_set (Evas_Object *obj, int
|
|||
* @note Use @c NULL pointers on the components you're not interested
|
||||
* in: they'll be ignored by the function.
|
||||
*
|
||||
* Example:
|
||||
* @dontinclude evas-object-manipulation.c
|
||||
* @skip int alpha, r, g, b;
|
||||
* @until return
|
||||
*
|
||||
* See the full @ref Example_Evas_Object_Manipulation "example".
|
||||
*
|
||||
* @ingroup Evas_Object_Group_Basic
|
||||
*/
|
||||
EAPI void evas_object_color_get (const Evas_Object *obj, int *r, int *g, int *b, int *a) EINA_ARG_NONNULL(1);
|
||||
|
@ -3202,6 +3220,13 @@ EAPI Evas *evas_object_evas_get (const Evas_Object *obj
|
|||
* For Evas smart objects (see @ref Evas_Smart_Group), the name of the
|
||||
* smart class itself is returned on this call. For the built-in
|
||||
* clipped smart object, it is <c>"EvasObjectSmartClipped"</c>.
|
||||
*
|
||||
* Example:
|
||||
* @dontinclude evas-object-manipulation.c
|
||||
* @skip d.img = evas_object_image_filled_add(d.canvas);
|
||||
* @until border on the
|
||||
*
|
||||
* See the full @ref Example_Evas_Object_Manipulation "example".
|
||||
*/
|
||||
EAPI const char *evas_object_type_get (const Evas_Object *obj) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE;
|
||||
|
||||
|
|
Loading…
Reference in New Issue