[evas] Example code for evas{_init,_shutdown,_load_error_str}.

SVN revision: 60142
This commit is contained in:
Gustavo Lima Chaves 2011-06-09 17:00:24 +00:00
parent e79cc153ea
commit ef41d78fce
7 changed files with 225 additions and 5 deletions

View File

@ -1569,10 +1569,14 @@ AM_CONDITIONAL([INSTALL_EXAMPLES], [test "x${install_examples}" = "xyes"])
build_examples="no"
AC_ARG_ENABLE([build-examples],
AC_HELP_STRING([--enable-build-examples],
[enable building examples. @<:@default==disabled@:>@]),
[enable building examples (this requires extra denpendencies. if you don't have them installed yet, don't build with this option or it will fail. build again when you have it, overriding the previous installation). @<:@default==disabled@:>@]),
[
if test "x${enableval}" = "xyes" ; then
build_examples="yes"
# put in here the dependencies for Evas' examples. they are
# meant to be 'real world' usage examples, thus one will be
# using higher level libraries on these programs
PKG_CHECK_MODULES([ECORE_EVAS], [ecore-evas])
else
build_examples="no"
fi

View File

@ -1,7 +1,7 @@
PROJECT_NAME = Evas
PROJECT_NUMBER = @PACKAGE_VERSION@
OUTPUT_DIRECTORY = .
INPUT = @srcdir@/evas.dox @top_srcdir@/src/lib
INPUT = @srcdir@/evas.dox @srcdir@/examples.dox @top_srcdir@/src/lib
IMAGE_PATH = img
OUTPUT_LANGUAGE = English
GENERATE_HTML = YES

View File

@ -0,0 +1,35 @@
/**
* @page Examples Examples
*
* Here is a page with examples.
*
* @ref Example_Evas_Buffer_Simple
*
* @ref Example_Evas_Init_Shutdown
*
* @ref Example_Evas_Load_Error_Str
*
*/
/**
* @page Example_Evas_Buffer_Simple Simple Evas canvas example
*
* The canvas will here use the buffer engine.
*
* @include evas-buffer-simple.c
* @example evas-buffer-simple.c
*/
/**
* @page Example_Evas_Init_Shutdown Nested buffer example
*
* @include evas-init-shutdown.c
* @example evas-init-shutdown.c
*/
/**
* @page Example_Evas_Load_Error_Str File descriptor buffer example
*
* @include evas-load-error-str.c
* @example evas-load-error-str.c
*/

View File

@ -11,6 +11,7 @@ AM_CPPFLAGS = \
-DPACKAGE_BIN_DIR=\"$(bindir)\" \
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
-DPACKAGE_EXAMPLES_DIR=\"$(datadir)/$(PACKAGE)/examples\" \
@EINA_CFLAGS@ \
@FREETYPE_CFLAGS@ \
@PIXMAN_CFLAGS@ \
@ -31,14 +32,31 @@ evas_buffer_simple_SOURCES = evas-buffer-simple.c
evas_buffer_simple_LDADD = $(top_builddir)/src/lib/libevas.la
endif
pkglib_PROGRAMS += evas_init_shutdown
evas_init_shutdown_SOURCES = evas-init-shutdown.c
evas_init_shutdown_LDADD = $(top_builddir)/src/lib/libevas.la
# put in here the dependencies for Evas' examples. they are meant to
# be 'real world' usage examples, thus one will be using higher level
# libraries on these programs. also remember to link with these extra
# libs only the example requiring them
if BUILD_ENGINE_SOFTWARE_X11
AM_CPPFLAGS += -I$(top_srcdir)/src/modules/engines/software_x11 \
@ECORE_EVAS_CFLAGS@
pkglib_PROGRAMS += evas_load_error_str
evas_load_error_str_SOURCES = evas-load-error-str.c
evas_load_error_str_LDADD = $(top_builddir)/src/lib/libevas.la @ECORE_EVAS_LIBS@
endif
endif
filesdir = $(datadir)/$(PACKAGE)/examples
files_DATA =
files_DATA = $(srcdir)/enlightenment.png
if INSTALL_EXAMPLES
files_DATA += \
evas-buffer-simple.c
$(srcdir)/evas-buffer-simple.c \
$(srcdir)/evas-init-shutdown.c \
$(srcdir)/evas-load-error-str.c
endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -0,0 +1,56 @@
/**
* Simple example illustrating usage of evas_init() and
* evas_shutdown(). Usually one would instantiate a canvas to have
* something useful out of Evas. For an example of this kind, see the
* @ref Example_Evas_Buffer_Simple.
*
* Here, we are just listing the engine Evas was compiled with support
* to.
*
* @verbatim
* gcc -o evas-init-shutdown evas-init-shutdown.c `pkg-config --libs \
* --cflags evas`
* @endverbatim
*
*/
#include <Evas.h>
#include <stdio.h>
#include <errno.h>
/*
* Simple example illustrating usage of evas_init() and
* evas_shutdown(). Usually one would instantiate a canvas to have
* something useful out of Evas. For an example of this kind, see the
* evas-buffer-simple.c, which requires the buffer engine module
* compiled in Evas.
*
* Here, we are just listing the engine Evas was compiled with support
* to.
*/
int
main(void)
{
Evas *canvas;
Eina_List *engine_list, *l;
char *engine_name;
evas_init();
engine_list = evas_render_method_list();
if (!engine_list)
{
fprintf(stderr, "ERROR: Evas supports no engines! Exit.\n");
exit(-1);
}
printf("Available Evas Engines:\n");
EINA_LIST_FOREACH(engine_list, l, engine_name)
printf("%s\n", engine_name);
evas_render_method_list_free(engine_list);
evas_shutdown();
}

View File

@ -0,0 +1,107 @@
/**
* Simple Evas example illustrating evas_load_error_str()'s usage.
*
* 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-load-error-str evas-load-error-str.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 *valid_path = PACKAGE_EXAMPLES_DIR "/enlightenment.png";
static const char *bogus_path = "/tmp/non-existent-220986.png";
int
main(void)
{
Evas *evas;
Ecore_Evas *ee;
Evas_Object *img1, *img2, *bg;
int err;
if (!ecore_evas_init())
return EXIT_FAILURE;
/* this will give you a window with an Evas canvas under the first
* engine available */
ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
if (!ee)
goto error;
ecore_evas_show(ee);
/* the canvas pointer, de facto */
evas = ecore_evas_get(ee);
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);
img1 = evas_object_image_filled_add(evas);
evas_object_image_file_set(img1, valid_path, NULL);
err = evas_object_image_load_error_get(img1);
if (err != EVAS_LOAD_ERROR_NONE)
{
fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
valid_path, evas_load_error_str(err));
}
else
{
fprintf(stdout,
"loaded image '%s' with succes! error string is \"%s\"\n",
valid_path, evas_load_error_str(err));
evas_object_move(img1, 0, 0);
evas_object_resize(img1, WIDTH / 2, HEIGHT / 2);
evas_object_show(img1);
}
/* image loading will fail for this one -- unless one cheats and
* puts a valid image on that path */
img2 = evas_object_image_filled_add(evas);
evas_object_image_file_set(img2, bogus_path, NULL);
err = evas_object_image_load_error_get(img2);
if (err != EVAS_LOAD_ERROR_NONE)
{
fprintf(stderr, "could not load image '%s': error string is \"%s\"\n",
bogus_path, evas_load_error_str(err));
}
else
{
evas_object_move(img2, WIDTH / 2, HEIGHT / 2);
evas_object_resize(img2, WIDTH / 2, HEIGHT / 2);
evas_object_show(img2);
}
ecore_main_loop_begin();
ecore_evas_free(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");
ecore_evas_shutdown();
return -1;
}