Photocam example

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

Photocam example

In this example we will have a photocam and a couple of buttons and slider to control the photocam. To avoid cluttering we'll only show the parts of the example that relate to the photocam, the full source code can be seen here.

Creating a photocam is as easy as creating any other widget:

photocam = elm_photocam_add(win);
elm_photocam_add
Evas_Object * elm_photocam_add(Evas_Object *parent)
Add a new Photocam object.
Definition: efl_ui_image_zoomable.c:3320

A photocam is only useful if we have a image on it, so lets set a file for it to work with:

snprintf(buf, sizeof(buf), "%s/images/insanely_huge_test_image.jpg", elm_app_data_dir_get());
elm_photocam_file_set(photocam, buf);
elm_app_data_dir_get
const char * elm_app_data_dir_get(void)
Get the application's run time data prefix directory, as set by elm_app_info_set() and the way (envir...
Definition: elm_main.c:586
elm_photocam_file_set
Evas_Load_Error elm_photocam_file_set(Evas_Object *obj, const char *file)
Set the photo file to be shown.
Definition: efl_ui_image_zoomable.c:3438

We now set the photocam to not bounce horizontally:

elm_scroller_bounce_set(photocam, EINA_FALSE, EINA_TRUE);
EINA_TRUE
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
EINA_FALSE
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition: eina_types.h:533
elm_scroller_bounce_set
void elm_scroller_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
Set bouncing behavior.
Definition: elm_scroller.c:1050

And we want to know when the photocam has finished loading the image so:

evas_object_smart_callback_add(photocam, "loaded,detail", _bring_in, NULL);
evas_object_smart_callback_add
EVAS_API void evas_object_smart_callback_add(Evas_Object *eo_obj, const char *event, Evas_Smart_Cb func, const void *data)
Add (register) a callback function to the smart event specified by event on the smart object obj.
Definition: evas_object_smart.c:1040

The reason to know when the image is loaded is so that we can bring the center of the image into view:

static void
_bring_in(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
int w, h;
elm_photocam_image_size_get(obj, &w, &h);
elm_photocam_image_region_bring_in(obj, w/2, h/2, 500, 400);
}
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
elm_photocam_image_region_bring_in
void elm_photocam_image_region_bring_in(Evas_Object *obj, int x, int y, int w, int h)
Bring in the viewed portion of the image.
Definition: efl_ui_image_zoomable.c:3471
elm_photocam_image_size_get
void elm_photocam_image_size_get(const Evas_Object *obj, int *w, int *h)
Get the current image pixel width and height.
Definition: efl_ui_image_zoomable.c:3393
Evas_Object
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185

As mentioned we have 2 buttons in this example, the "Fit" one will cause the photocam to go in to a zoom mode that makes the image fit inside the photocam. Tough this has no effect on the image we also print what region was being viewed before setting the zoom mode:

static void
_fit(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
int x, y, w, h;
elm_photocam_image_region_get(data, &x, &y, &w, &h);
printf("region: {%d, %d, %d, %d}\n", x, y, w, h);

Note
  When in fit mode our slider(explained below) won't work.

The second button("Unfit") will bring the photocam back into manual zoom mode:

static void
_unfit(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
elm_photocam_zoom_mode_set(data, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
}
elm_photocam_zoom_mode_set
void elm_photocam_zoom_mode_set(Evas_Object *obj, Elm_Photocam_Zoom_Mode mode)
Set the zoom mode.
Definition: efl_ui_image_zoomable.c:3426

Our slider controls the level of zoom of the photocam:

static void
_zoom(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
double z = elm_slider_value_get(obj) * 8;
elm_photocam_zoom_set(data, z);
}
elm_photocam_zoom_set
void elm_photocam_zoom_set(Evas_Object *obj, double zoom)
Set the zoom level of the photo.
Definition: efl_ui_image_zoomable.c:3414
elm_slider_value_get
double elm_slider_value_get(const Evas_Object *obj)
Get the value displayed by the slider.
Definition: elm_slider.c:1531

Note
  It is important to note that this only works when in manual zoom mode.

Our example will initially look like this: