From 15141fcc2a7047dd86c2ae2a9ed6c804d70fdb52 Mon Sep 17 00:00:00 2001 From: glima Date: Tue, 2 Aug 2011 16:44:08 +0000 Subject: [PATCH] [ecore] Documenting the following: - ecore_evas_size_base_get - ecore_evas_size_base_set - ecore_evas_size_max_get - ecore_evas_size_max_set - ecore_evas_size_min_get - ecore_evas_size_min_set - ecore_evas_size_step_get - ecore_evas_size_step_set git-svn-id: http://svn.enlightenment.org/svn/e/trunk/ecore@62012 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- doc/examples.dox | 74 ++++++++- src/examples/Makefile.am | 7 +- src/examples/ecore_evas_window_sizes_example.c | 204 +++++++++++++++++++++++++ src/lib/ecore_evas/Ecore_Evas.h | 123 +++++++++++++++ src/lib/ecore_evas/ecore_evas.c | 65 -------- 5 files changed, 405 insertions(+), 68 deletions(-) create mode 100644 src/examples/ecore_evas_window_sizes_example.c diff --git a/doc/examples.dox b/doc/examples.dox index fe609a7..9ac9131 100644 --- a/doc/examples.dox +++ b/doc/examples.dox @@ -1219,4 +1219,76 @@ * Here you have the full-source of the code: * @include ecore_evas_callbacks.c * @example ecore_evas_callbacks.c - */ \ No newline at end of file + */ + +/** + * @page Ecore_Evas_Window_Sizes_Example_c @c Ecore_Evas window sizes + * + * On this example, we show you how to deal with @c Ecore_Evas window + * size hints, which are implemented per Evas engine. + * + * We start by defining an initial size for our window and, after + * creating it, adding a background white rectangle and a text object + * to it, to be used to display the current window's sizes, at any + * given time: + * @dontinclude ecore_evas_window_sizes_example.c + * @skip define WIDTH + * @until define + * @until define + * @dontinclude ecore_evas_window_sizes_example.c + * @skip evas_init + * @until show(bg) + * @dontinclude ecore_evas_window_sizes_example.c + * @skip text = + * @until main_loop_begin + * @dontinclude ecore_evas_window_sizes_example.c + * @skip to inform + * @until } + * + * The program has a command line interface, responding to the + * following keys: + * @dontinclude ecore_evas_window_sizes_example.c + * @skip commands + * @until ; + * + * Use the @c 'm' key to impose a minimum size of half the initial + * ones on our window. Test it by trying to resize it to smaller sizes + * than that: + * @dontinclude ecore_evas_window_sizes_example.c + * @skip keyname, "m" + * @until } + * @until } + * @until } + * + * The @c 'x' key will, in turn, set a maximum size on our window -- + * to two times our initial size. Test it by trying to resize the + * window to bigger sizes than that: + * @dontinclude ecore_evas_window_sizes_example.c + * @skip keyname, "x" + * @until } + * @until } + * @until } + * + * Window base sizes will override any minimum sizes set, so try it + * with the @c 'b' key. It will set a base size of two times the + * initial one: + * @dontinclude ecore_evas_window_sizes_example.c + * @skip keyname, "b" + * @until } + * @until } + * @until } + * + * Finally, there's a key to impose a "step size" on our window, of 40 + * pixels. With than on (@c 's' key), you'll see the window will + * always be bound to @b multiples of that size, for dimensions on + * both axis: + * @skip keyname, "s" + * @until } + * @until } + * @until } + * + * The full example follows. + * + * @include ecore_evas_window_sizes_example.c + * @example ecore_evas_window_sizes_example.c + */ diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am index 0e3e7db..df13e74 100644 --- a/src/examples/Makefile.am +++ b/src/examples/Makefile.am @@ -44,7 +44,8 @@ SRCS = \ ecore_pipe_simple_example.c \ ecore_pipe_gstreamer_example.c \ ecore_thread_example.c \ - ecore_evas_callbacks.c + ecore_evas_callbacks.c \ + ecore_evas_window_sizes_example.c EXTRA_DIST = $(SRCS) @@ -74,7 +75,8 @@ pkglib_PROGRAMS += \ ecore_con_server_http_example \ ecore_con_client_simple_example \ ecore_thread_example \ - ecore_evas_callbacks + ecore_evas_callbacks \ + ecore_evas_window_sizes_example ecore_animator_example_LDADD = $(ECOREBASELDADD) @EVAS_LIBS@ $(top_builddir)/src/lib/ecore_evas/libecore_evas.la ecore_con_lookup_example_LDADD = $(ECOREBASELDADD) $(top_builddir)/src/lib/ecore_con/libecore_con.la @@ -84,6 +86,7 @@ ecore_con_url_cookies_example_LDADD = $(ECOREBASELDADD) $(top_builddir)/src/lib/ ecore_con_server_simple_example_LDADD = $(ECOREBASELDADD) $(top_builddir)/src/lib/ecore_con/libecore_con.la ecore_con_server_http_example_LDADD = $(ECOREBASELDADD) $(top_builddir)/src/lib/ecore_con/libecore_con.la ecore_con_client_simple_example_LDADD = $(ECOREBASELDADD) $(top_builddir)/src/lib/ecore_con/libecore_con.la +ecore_evas_window_sizes_example_LDADD = $(ECOREBASELDADD) @EVAS_LIBS@ $(top_builddir)/src/lib/ecore_evas/libecore_evas.la endif diff --git a/src/examples/ecore_evas_window_sizes_example.c b/src/examples/ecore_evas_window_sizes_example.c new file mode 100644 index 0000000..badfb16 --- /dev/null +++ b/src/examples/ecore_evas_window_sizes_example.c @@ -0,0 +1,204 @@ +/** + * Simple @c Ecore_Evas example illustrating how to deal with window + * sizes + * + * You'll need at least one engine built for it (excluding the buffer + * one). See stdout/stderr for output. + * + * @verbatim + * gcc -o evas-smart-object evas-smart-object.c `pkg-config --libs --cflags evas ecore ecore-evas` + * @endverbatim + */ + +#ifdef HAVE_CONFIG_H + +#include "config.h" +#else +#define __UNUSED__ +#endif + +#include +#include + +#define WIDTH (300) +#define HEIGHT (300) + +static Ecore_Evas *ee; +static Evas_Object *text, *bg; +static Eina_Bool min_set = EINA_FALSE; +static Eina_Bool max_set = EINA_FALSE; +static Eina_Bool base_set = EINA_FALSE; +static Eina_Bool step_set = EINA_FALSE; + +static const char commands[] = \ + "commands are:\n" + "\tm - impose a minumum size to the window\n" + "\tx - impose a maximum size to the window\n" + "\tb - impose a base size to the window\n" + "\ts - impose a step size (different than 1 px) to the window\n" + "\th - print help\n"; + +/* to inform current window's size */ +static void +_canvas_resize_cb(Ecore_Evas *ee) +{ + int w, h; + char buf[1024]; + + ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); + snprintf(buf, sizeof(buf), "%d x %d", w, h); + evas_object_text_text_set(text, buf); + evas_object_move(text, (w - 150) / 2, (h - 50) / 2); + + evas_object_resize(bg, w, h); +} + +static void +_on_destroy(Ecore_Evas *ee __UNUSED__) +{ + ecore_main_loop_quit(); +} + +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); + return; + } + + if (strcmp(ev->keyname, "m") == 0) /* impose a minimum size on the window */ + { + min_set = !min_set; + + if (min_set) + { + ecore_evas_size_min_set(ee, WIDTH / 2, HEIGHT / 2); + fprintf(stdout, "Imposing a minimum size of %d x %d\n", + WIDTH / 2, HEIGHT / 2); + } + else + { + ecore_evas_size_min_set(ee, 0, 0); + fprintf(stdout, "Taking off minimum size restriction from the" + " window\n"); + } + return; + } + + if (strcmp(ev->keyname, "x") == 0) /* impose a maximum size on the window */ + { + max_set = !max_set; + + if (max_set) + { + ecore_evas_size_max_set(ee, WIDTH * 2, HEIGHT * 2); + fprintf(stdout, "Imposing a maximum size of %d x %d\n", + WIDTH * 2, HEIGHT * 2); + } + else + { + ecore_evas_size_max_set(ee, 0, 0); + fprintf(stdout, "Taking off maximum size restriction from the" + " window\n"); + } + return; + } + + if (strcmp(ev->keyname, "b") == 0) /* impose a base size on the window */ + { + base_set = !base_set; + + if (base_set) + { + ecore_evas_size_base_set(ee, WIDTH * 2, HEIGHT * 2); + fprintf(stdout, "Imposing a base size of %d x %d\n", + WIDTH * 2, HEIGHT * 2); + } + else + { + ecore_evas_size_base_set(ee, 0, 0); + fprintf(stdout, "Taking off base size restriction from the" + " window\n"); + } + return; + } + + if (strcmp(ev->keyname, "s") == 0) /* impose a step size on the window */ + { + step_set = !step_set; + + if (step_set) + { + ecore_evas_size_step_set(ee, 40, 40); + fprintf(stdout, "Imposing a step size of %d x %d\n", 40, 40); + } + else + { + ecore_evas_size_step_set(ee, 0, 0); + fprintf(stdout, "Taking off step size restriction from the" + " window\n"); + } + return; + } +} + +int +main(void) +{ + Evas *evas; + + 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, 0, 0, WIDTH, HEIGHT, NULL); + if (!ee) goto error; + + ecore_evas_callback_delete_request_set(ee, _on_destroy); + ecore_evas_title_set(ee, "Ecore_Evas window sizes example"); + ecore_evas_callback_resize_set(ee, _canvas_resize_cb); + ecore_evas_show(ee); + + 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); + + evas_object_focus_set(bg, EINA_TRUE); + evas_object_event_callback_add( + bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL); + + text = evas_object_text_add(evas); + evas_object_color_set(text, 0, 0, 0, 255); + evas_object_resize(text, 150, 50); + evas_object_text_font_set(text, "Sans", 20); + evas_object_show(text); + + _canvas_resize_cb(ee); + fprintf(stdout, commands); + 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; +} + diff --git a/src/lib/ecore_evas/Ecore_Evas.h b/src/lib/ecore_evas/Ecore_Evas.h index 1dda9da..9a88477 100644 --- a/src/lib/ecore_evas/Ecore_Evas.h +++ b/src/lib/ecore_evas/Ecore_Evas.h @@ -55,6 +55,14 @@ extern "C" { #endif +/** + * @defgroup Ecore_Evas_Group Ecore_Evas wrapper/helper set of functions + * + * This is a list of examples of these functions: + * - @ref Ecore_Evas_Window_Sizes_Example_c + * @{ + */ + /* these are dummy and just tell u what API levels ecore_evas supports - not if * the actual support is compiled in. you need to query for that separately. */ @@ -477,14 +485,125 @@ EAPI void ecore_evas_title_set(Ecore_Evas *ee, const char *t); EAPI const char *ecore_evas_title_get(const Ecore_Evas *ee); EAPI void ecore_evas_name_class_set(Ecore_Evas *ee, const char *n, const char *c); EAPI void ecore_evas_name_class_get(const Ecore_Evas *ee, const char **n, const char **c); + +/** + * Set the minimum size of a given @c Ecore_Evas window + * + * @param ee An @c Ecore_Evas window's handle + * @param w The minimum width + * @param h The minimum height + * + * This function sets the minimum size of @p ee to be @p w x @p h. + * One won't be able to resize that window to dimensions smaller than + * the ones set. + * + * @note When base sizes are set, via ecore_evas_size_base_set(), + * they'll be used to calculate a window's minimum size, instead of + * those set by this function. + * + * @see ecore_evas_size_min_get() + */ EAPI void ecore_evas_size_min_set(Ecore_Evas *ee, int w, int h); + +/** + * Get the minimum size set for a given @c Ecore_Evas window + * + * @param ee An @c Ecore_Evas window's handle + * @param w A pointer to an int to place the minimum width in. + * @param h A pointer to an int to place the minimum height in. + * + * @note Use @c NULL pointers on the size components you're not + * interested in: they'll be ignored by the function. + * + * @see ecore_evas_size_min_set() for more details + */ EAPI void ecore_evas_size_min_get(const Ecore_Evas *ee, int *w, int *h); + +/** + * Set the maximum size of a given @c Ecore_Evas window + * + * @param ee An @c Ecore_Evas window's handle + * @param w The maximum width + * @param h The maximum height + * + * This function sets the maximum size of @p ee to be @p w x @p h. + * One won't be able to resize that window to dimensions bigger than + * the ones set. + * + * @see ecore_evas_size_max_get() + */ EAPI void ecore_evas_size_max_set(Ecore_Evas *ee, int w, int h); + +/** + * Get the maximum size set for a given @c Ecore_Evas window + * + * @param ee An @c Ecore_Evas window's handle + * @param w A pointer to an int to place the maximum width in. + * @param h A pointer to an int to place the maximum height in. + * + * @note Use @c NULL pointers on the size components you're not + * interested in: they'll be ignored by the function. + * + * @see ecore_evas_size_max_set() for more details + */ EAPI void ecore_evas_size_max_get(const Ecore_Evas *ee, int *w, int *h); + +/** + * Set the base size for a given @c Ecore_Evas window + * + * @param ee An @c Ecore_Evas window's handle + * @param w The base width + * @param h The base height + * + * This function sets the @b base size of @p ee to be @p w x @p h. + * When base sizes are set, they'll be used to calculate a window's + * @b minimum size, instead of those set by ecore_evas_size_min_get(). + * + * @see ecore_evas_size_base_get() + */ EAPI void ecore_evas_size_base_set(Ecore_Evas *ee, int w, int h); + +/** + * Get the base size set for a given @c Ecore_Evas window + * + * @param ee An @c Ecore_Evas window's handle + * @param w A pointer to an int to place the base width in. + * @param h A pointer to an int to place the base height in. + * + * @note Use @c NULL pointers on the size components you're not + * interested in: they'll be ignored by the function. + * + * @see ecore_evas_size_base_set() for more details + */ EAPI void ecore_evas_size_base_get(const Ecore_Evas *ee, int *w, int *h); + +/** + * Set the "size step" for a given @c Ecore_Evas window + * + * @param ee An @c Ecore_Evas window's handle + * @param w The step width + * @param h The step height + * + * This function sets the size steps of @p ee to be @p w x @p h. This + * limits the size of this @cEcore_Evas window to be @b always an + * integer multiple of the step size, for each axis. + */ EAPI void ecore_evas_size_step_set(Ecore_Evas *ee, int w, int h); + +/** + * Get the "size step" set for a given @c Ecore_Evas window + * + * @param ee An @c Ecore_Evas window's handle + * @param w A pointer to an int to place the step width in. + * @param h A pointer to an int to place the step height in. + * + * @note Use @c NULL pointers on the size components you're not + * interested in: they'll be ignored by the function. + * + * @see ecore_evas_size_base_set() for more details + */ EAPI void ecore_evas_size_step_get(const Ecore_Evas *ee, int *w, int *h); + EAPI void ecore_evas_cursor_set(Ecore_Evas *ee, const char *file, int layer, int hot_x, int hot_y); EAPI void ecore_evas_object_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int hot_x, int hot_y); EAPI void ecore_evas_cursor_get(const Ecore_Evas *ee, Evas_Object **obj, int *layer, int *hot_x, int *hot_y); @@ -540,6 +659,10 @@ EAPI void ecore_evas_x11_shape_input_empty(Ecore_Evas *ee); EAPI void ecore_evas_x11_shape_input_reset(Ecore_Evas *ee); EAPI void ecore_evas_x11_shape_input_apply(Ecore_Evas *ee); +/** + * @} + */ + #ifdef __cplusplus } #endif diff --git a/src/lib/ecore_evas/ecore_evas.c b/src/lib/ecore_evas/ecore_evas.c index ae78e08..d2883c1 100644 --- a/src/lib/ecore_evas/ecore_evas.c +++ b/src/lib/ecore_evas/ecore_evas.c @@ -1694,14 +1694,6 @@ ecore_evas_name_class_get(const Ecore_Evas *ee, const char **n, const char **c) if (c) *c = ee->prop.clas; } -/** - * Set the min size of an Ecore_Evas' window - * @param ee The Ecore_Evas to set - * @param w The minimum width - * @param h The minimum height - * - * This function sets the minimum size of @p ee to @p w x @p h. - */ EAPI void ecore_evas_size_min_set(Ecore_Evas *ee, int w, int h) { @@ -1725,14 +1717,6 @@ ecore_evas_size_min_set(Ecore_Evas *ee, int w, int h) } } -/** - * Get the min size of an Ecore_Evas' window - * @param ee The Ecore_Evas to set - * @param w A pointer to an int to place the min width in. - * @param h A pointer to an int to place the min height in. - * - * This function puts the minimum size of @p ee into @p w and @p h. - */ EAPI void ecore_evas_size_min_get(const Ecore_Evas *ee, int *w, int *h) { @@ -1754,14 +1738,6 @@ ecore_evas_size_min_get(const Ecore_Evas *ee, int *w, int *h) } } -/** - * Set the max size of an Ecore_Evas' window - * @param ee The Ecore_Evas to set - * @param w The maximum width - * @param h The maximum height - * - * This function sets the maximum size of @p ee to @p w x @p h. - */ EAPI void ecore_evas_size_max_set(Ecore_Evas *ee, int w, int h) { @@ -1785,14 +1761,6 @@ ecore_evas_size_max_set(Ecore_Evas *ee, int w, int h) } } -/** - * Get the max size of an Ecore_Evas' window - * @param ee The Ecore_Evas to set - * @param w A pointer to an int to place the max width in. - * @param h A pointer to an int to place the max height in. - * - * This function puts the maximum size of @p ee into @p w and @p h. - */ EAPI void ecore_evas_size_max_get(const Ecore_Evas *ee, int *w, int *h) { @@ -1814,14 +1782,6 @@ ecore_evas_size_max_get(const Ecore_Evas *ee, int *w, int *h) } } -/** - * Set the base size of an Ecore_Evas' window - * @param ee The Ecore_Evas to set - * @param w The base width - * @param h The base height - * - * This function sets the base size of @p ee to @p w x @p h. - */ EAPI void ecore_evas_size_base_set(Ecore_Evas *ee, int w, int h) { @@ -1845,14 +1805,6 @@ ecore_evas_size_base_set(Ecore_Evas *ee, int w, int h) } } -/** - * Get the base size of an Ecore_Evas' window - * @param ee The Ecore_Evas to set - * @param w A pointer to an int to place the base width in. - * @param h A pointer to an int to place the base height in. - * - * This function puts the base size of @p ee into @p w and @p h. - */ EAPI void ecore_evas_size_base_get(const Ecore_Evas *ee, int *w, int *h) { @@ -1874,15 +1826,6 @@ ecore_evas_size_base_get(const Ecore_Evas *ee, int *w, int *h) } } -/** - * Set the step size of an Ecore_Evas - * @param ee The Ecore_Evas to set - * @param w The step width - * @param h The step height - * - * This function sets the step size of @p ee to @p w x @p h. This limits the - * size of an Ecore_Evas to always being an integer multiple of the step size. - */ EAPI void ecore_evas_size_step_set(Ecore_Evas *ee, int w, int h) { @@ -1906,14 +1849,6 @@ ecore_evas_size_step_set(Ecore_Evas *ee, int w, int h) } } -/** - * Get the step size of an Ecore_Evas' window - * @param ee The Ecore_Evas to set - * @param w A pointer to an int to place the step width in. - * @param h A pointer to an int to place the step height in. - * - * This function puts the step size of @p ee into @p w and @p h. - */ EAPI void ecore_evas_size_step_get(const Ecore_Evas *ee, int *w, int *h) { -- 2.7.4