Evas aspect hints example
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define PACKAGE_EXAMPLES_DIR "."
#endif
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <Edje.h>
#include <stdio.h>
#include <errno.h>
#include "evas-common.h"
#define WIDTH 320
#define HEIGHT 480
static const char *border_img_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/red.png";
static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/aspect.edj";
struct test_data
{
Ecore_Evas *ee;
Evas *canvas;
Evas_Object *bg, *rect, *container, *border;
};
static struct test_data d = {0};
/* Keep the example's window size in sync with the background image's size */
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 const char *
_get_aspect_name(Evas_Aspect_Control aspect)
{
switch (aspect)
{
case 0:
return "NONE";
case 1:
return "NEITHER";
case 2:
return "HORIZONTAL";
case 3:
return "VERTICAL";
case 4:
return "BOTH";
default:
return "INVALID";
}
}
static void
_on_keydown(void *data EINA_UNUSED,
void *einfo)
{
const Evas_Modifier *mods;
Evas_Event_Key_Down *ev = einfo;
if (evas_key_modifier_is_set(mods, "Shift") &&
strcmp(ev->key, "h") == 0) /* print help */
{
printf("commands are:\n"
"\tc - cycle aspect control on object\n"
"\th - change horizontal aspect component\n"
"\tv - change vertical aspect component\n"
"\ts - print current object's status\n"
"\tH - print help\n");
return;
}
if (strcmp(ev->key, "s") == 0) /* get aspect status of the obj */
{
Evas_Coord w, h;
evas_object_size_hint_aspect_get(d.rect, &aspect, &w, &h);
printf("Object has aspect %s, with horizontal compontent %d"
" and vertical component %d\n",
_get_aspect_name(aspect), w, h);
return;
}
if (strcmp(ev->key, "c") == 0) /* cycle aspect control on obj */
{
Evas_Coord w, h;
evas_object_size_hint_aspect_get(d.rect, &aspect, &w, &h);
aspect = (aspect + 1) % 5;
evas_object_size_hint_aspect_set(d.rect, aspect, w, h);
printf("Changing aspect control to %s\n",
_get_aspect_name(aspect));
return;
}
if (strcmp(ev->key, "h") == 0) /* change horizontal aspect component */
{
Evas_Coord w, h;
evas_object_size_hint_aspect_get(d.rect, &aspect, &w, &h);
w = (w + 1) % 3;
evas_object_size_hint_aspect_set(d.rect, aspect, w, h);
printf("Changing horizontal aspect component to %d\n", w);
return;
}
if (strcmp(ev->key, "v") == 0) /* change vertical aspect component */
{
Evas_Coord w, h;
evas_object_size_hint_aspect_get(d.rect, &aspect, &w, &h);
h = (h + 1) % 3;
evas_object_size_hint_aspect_set(d.rect, aspect, w, h);
printf("Changing vertical aspect component to %d\n", h);
return;
}
}
int
main(void)
{
Eina_Bool ret;
return EXIT_FAILURE;
if (!edje_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);
/* the canvas pointer, de facto */
d.canvas = ecore_evas_get(d.ee);
d.bg = evas_object_rectangle_add(d.canvas);
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 */
d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
d.container = edje_object_add(d.canvas);
ret = edje_object_file_set(d.container, edje_file_path, "main");
if (!ret)
{
Edje_Load_Error err = edje_object_load_error_get(d.container);
const char *msg = edje_load_error_str(err);
fprintf(stderr, "could not load 'main' from %s: %s",
edje_file_path, msg);
goto panic;
}
evas_object_move(d.container, (WIDTH / 4), (HEIGHT / 4));
evas_object_resize(d.container, (WIDTH / 2), (HEIGHT / 2));
evas_object_show(d.container);
d.rect = evas_object_rectangle_add(d.canvas);
evas_object_color_set(d.rect, 0, 0, 255, 255);
edje_object_part_swallow(d.container, "content", d.rect);
/* this is a border around the edje object, container of the
* rectangle we are going to experiment with (change its aspect
* hints). this way you can see how their sizes relate */
d.border = evas_object_image_filled_add(d.canvas);
evas_object_image_file_set(d.border, border_img_path, NULL);
evas_object_image_border_set(d.border, 3, 3, 3, 3);
evas_object_move(d.border, (WIDTH / 4) - 3, (HEIGHT / 4) - 3);
evas_object_resize(d.border, (WIDTH / 2) + 6, (HEIGHT / 2) + 6);
evas_object_show(d.border);
return 0;
error:
fprintf(stderr, "error: Requires at least one Evas engine built and linked"
" to ecore-evas for this example to run properly.\n");
panic:
return -1;
}
Evas wrapper functions.
Edje Graphical Design Library.
enum _Evas_Aspect_Control Evas_Aspect_Control
Aspect types/policies for scaling size hints, used for evas_object_size_hint_aspect_set()
int Evas_Coord
Type used for coordinates (in pixels, int).
Definition: Evas_Common.h:116
@ EVAS_ASPECT_CONTROL_NONE
Preference on scaling unset.
Definition: Evas_Common.h:374
@ EVAS_CALLBACK_KEY_DOWN
Key Press Event.
Definition: Evas_Common.h:430
EAPI int ecore_evas_init(void)
Inits the Ecore_Evas system.
Definition: ecore_evas.c:602
EAPI void ecore_evas_show(Ecore_Evas *ee)
Shows an Ecore_Evas' window.
Definition: ecore_evas.c:1480
EAPI Evas * ecore_evas_get(const Ecore_Evas *ee)
Gets an Ecore_Evas's Evas.
Definition: ecore_evas.c:1300
EAPI void ecore_evas_geometry_get(const Ecore_Evas *ee, int *x, int *y, int *w, int *h)
Gets the geometry of an Ecore_Evas.
Definition: ecore_evas.c:1362
EAPI Ecore_Evas * ecore_evas_new(const char *engine_name, int x, int y, int w, int h, const char *extra_options)
Creates a new Ecore_Evas based on engine name and common parameters.
Definition: ecore_evas.c:1039
EAPI void ecore_evas_callback_resize_set(Ecore_Evas *ee, Ecore_Evas_Event_Cb func)
Sets a callback for Ecore_Evas resize events.
Definition: ecore_evas.c:1140
EAPI int ecore_evas_shutdown(void)
Shuts down the Ecore_Evas system.
Definition: ecore_evas.c:666
EAPI void ecore_evas_free(Ecore_Evas *ee)
Frees an Ecore_Evas.
Definition: ecore_evas.c:1083
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1311
int edje_shutdown(void)
Shuts down the Edje library.
Definition: edje_main.c:262
int edje_init(void)
Initializes the Edje library.
Definition: edje_main.c:35
Edje_Load_Error edje_object_load_error_get(const Eo *obj)
Gets the (last) file loading error for a given Edje object.
Definition: edje_legacy.c:15
Evas_Object * edje_object_add(Evas *evas)
Instantiates a new Edje object.
Definition: edje_smart.c:22
const char * edje_load_error_str(Edje_Load_Error error)
Converts the given Edje file load error code into a string describing it in English.
Definition: edje_load.c:108
Eina_Bool edje_object_file_set(Evas_Object *obj, const char *file, const char *group)
Sets the EDJ file (and group within it) to load an Edje object's contents from.
Definition: edje_smart.c:467
Eina_Bool edje_object_part_swallow(Evas_Object *obj, const char *part, Evas_Object *obj_swallow)
"Swallows" an object into one of the Edje object SWALLOW parts.
Definition: edje_util.c:6676
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:527
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
EVAS_API const Evas_Modifier * evas_key_modifier_get(const Evas *eo_e)
Returns a handle to the list of modifier keys registered in the canvas e.
Definition: evas_key.c:35
Eo Evas
An opaque handle to an Evas canvas.
Definition: Evas_Common.h:163
EVAS_API Eina_Bool evas_key_modifier_is_set(const Evas_Modifier *m, const char *keyname)
Checks the state of a given modifier of the default seat, at the time of the call.
Definition: evas_key.c:76
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
EVAS_API void evas_object_color_set(Evas_Object *obj, int r, int g, int b, int a)
Sets the general/main color of the given Evas object to the given one.
Definition: evas_object_main.c:2024
EVAS_API void evas_object_event_callback_add(Evas_Object *eo_obj, Evas_Callback_Type type, Evas_Object_Event_Cb func, const void *data)
Add (register) a callback function to a given Evas object event.
Definition: evas_callbacks.c:478
EVAS_API void evas_object_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
Move the given Evas object to the given location inside its canvas' viewport.
Definition: evas_object_main.c:1171
EVAS_API void evas_object_size_hint_aspect_get(const Evas_Object *obj, Evas_Aspect_Control *aspect, Evas_Coord *w, Evas_Coord *h)
Retrieves the hints for an object's aspect ratio.
Definition: evas_object_main.c:2587
EVAS_API Evas * evas_object_evas_get(const Eo *eo_obj)
Get the Evas to which this object belongs to.
Definition: evas_object_main.c:2662
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
EVAS_API void evas_object_size_hint_aspect_set(Evas_Object *obj, Evas_Aspect_Control aspect, Evas_Coord w, Evas_Coord h)
Sets the hints for an object's aspect ratio.
Definition: evas_object_main.c:2581
EVAS_API void evas_object_focus_set(Efl_Canvas_Object *obj, Eina_Bool focus)
Indicates that this object is the keyboard event receiver on its canvas.
Definition: efl_canvas_object_eo.legacy.c:39
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition: evas_object_main.c:1236
EVAS_API void evas_object_image_border_set(Evas_Object *obj, int l, int r, int t, int b)
Dimensions of this image's border, a region that does not scale with the center area.
Definition: evas_image_legacy.c:117
EVAS_API void evas_object_image_border_center_fill_set(Evas_Object *obj, Evas_Border_Fill_Mode fill)
Specifies how the center part of the object (not the borders) should be drawn when EFL is rendering i...
Definition: evas_image_legacy.c:145
EVAS_API void evas_object_image_file_set(Evas_Object *obj, const char *file, const char *key)
Set the source file from where an image object must fetch the real image data (it may be an Eet file,...
Definition: evas_image_legacy.c:194
EVAS_API Evas_Object * evas_object_image_filled_add(Evas *eo_e)
Creates a new image object that automatically scales its bound image to the object's area,...
Definition: evas_image_legacy.c:35
@ EVAS_BORDER_FILL_NONE
Image's center region is not to be rendered.
Definition: Evas_Legacy.h:5721
EVAS_API Evas_Object * evas_object_rectangle_add(Evas *e)
Adds a rectangle to the given evas.
Definition: evas_object_rectangle.c:78
EVAS_API void evas_object_smart_changed(Efl_Canvas_Group *obj)
Marks the object as dirty.
Definition: efl_canvas_group_eo.legacy.c:15
Key press event.
Definition: Evas_Legacy.h:314
const char * key
The logical key : (eg shift+1 == exclamation)
Definition: Evas_Legacy.h:320