\section{photocam\+\_\+example\+\_\+01.\+c}

\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{//gcc -o photocam\_example\_01 photocam\_example\_01.c -g `pkg-config --cflags --libs elementary`
       -DDATA\_DIR="\(\backslash\)"<directory>\(\backslash\)""}
\textcolor{comment}{//where directory is the path where images/insanely\_huge\_test\_image.jpg can be found.}

\textcolor{preprocessor}{#include <Elementary.h>}

\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_fit(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info);
\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_unfit(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info);
\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_zoom(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info);
\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_bring\_in(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info);
\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_orient(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info);
\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_orient\_do(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info);

\textcolor{keyword}{typedef} \textcolor{keyword}{struct }\_Orient\_Data Orient\_Data;
\textcolor{keyword}{struct }\_Orient\_Data
\{
   Evas\_Object *ph;
   Evas\_Image\_Orient orient;
\};

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *obj, *photocam, *menu;
   Orient\_Data *orient\_data;
   \textcolor{keywordtype}{char} buf[PATH\_MAX];

   elm_app_info_set(elm\_main, \textcolor{stringliteral}{"elementary"}, \textcolor{stringliteral}{"images/insanely\_huge\_test\_image.jpg"});
   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"photocam"}, \textcolor{stringliteral}{"Photocam"});
   elm_win_autodel_set(win, EINA\_TRUE);

   photocam = elm_photocam_add(win);
   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"%s/images/insanely\_huge\_test\_image.jpg"}, 
      elm_app_data_dir_get());
   elm_photocam_file_set(photocam, buf);
   elm_scroller_bounce_set(photocam, EINA\_FALSE, EINA\_TRUE);
   evas\_object\_smart\_callback\_add(photocam, \textcolor{stringliteral}{"loaded,detail"}, \_bring\_in, NULL);
   evas\_object\_resize(photocam, 500, 400);
   evas\_object\_show(photocam);

   obj = elm_button_add(win);
   elm\_object\_text\_set(obj, \textcolor{stringliteral}{"Fit"});
   evas\_object\_show(obj);
   evas\_object\_resize(obj, 50, 30);
   evas\_object\_move(obj, 10, 410);
   evas\_object\_smart\_callback\_add(obj, \textcolor{stringliteral}{"clicked"}, \_fit, photocam);

   obj = elm_button_add(win);
   elm\_object\_text\_set(obj, \textcolor{stringliteral}{"Unfit"});
   evas\_object\_show(obj);
   evas\_object\_resize(obj, 70, 30);
   evas\_object\_move(obj, 70, 410);
   evas\_object\_smart\_callback\_add(obj, \textcolor{stringliteral}{"clicked"}, \_unfit, photocam);

   orient\_data = (Orient\_Data *)malloc(\textcolor{keyword}{sizeof}(Orient\_Data));
   orient\_data->ph = photocam;
   orient\_data->orient = 0;
   menu = elm_menu_add(win);
   elm_menu_item_add(menu, NULL, NULL, \textcolor{stringliteral}{"orient 0"}, \_orient\_do, orient\_data);
   orient\_data = (Orient\_Data *)malloc(\textcolor{keyword}{sizeof}(Orient\_Data));
   orient\_data->ph = photocam;
   orient\_data->orient = 1;
   elm_menu_item_add(menu, NULL, NULL, \textcolor{stringliteral}{"orient 90"}, \_orient\_do, orient\_data);
   orient\_data = (Orient\_Data *)malloc(\textcolor{keyword}{sizeof}(Orient\_Data));
   orient\_data->ph = photocam;
   orient\_data->orient = 2;
   elm_menu_item_add(menu, NULL, NULL, \textcolor{stringliteral}{"orient 180"}, \_orient\_do, orient\_data);
   orient\_data = (Orient\_Data *)malloc(\textcolor{keyword}{sizeof}(Orient\_Data));
   orient\_data->ph = photocam;
   orient\_data->orient = 3;
   elm_menu_item_add(menu, NULL, NULL, \textcolor{stringliteral}{"orient 270"}, \_orient\_do, orient\_data);
   orient\_data = (Orient\_Data *)malloc(\textcolor{keyword}{sizeof}(Orient\_Data));
   orient\_data->ph = photocam;
   orient\_data->orient = 4;
   elm_menu_item_add(menu, NULL, NULL, \textcolor{stringliteral}{"flip horizontal"}, \_orient\_do, orient\_data);
   orient\_data = (Orient\_Data *)malloc(\textcolor{keyword}{sizeof}(Orient\_Data));
   orient\_data->ph = photocam;
   orient\_data->orient = 5;
   elm_menu_item_add(menu, NULL, NULL, \textcolor{stringliteral}{"flip vertical"}, \_orient\_do, orient\_data);
   orient\_data = (Orient\_Data *)malloc(\textcolor{keyword}{sizeof}(Orient\_Data));
   orient\_data->ph = photocam;
   orient\_data->orient = 6;
   elm_menu_item_add(menu, NULL, NULL, \textcolor{stringliteral}{"flip transverse"}, \_orient\_do, orient\_data);
   orient\_data = (Orient\_Data *)malloc(\textcolor{keyword}{sizeof}(Orient\_Data));
   orient\_data->ph = photocam;
   orient\_data->orient = 7;
   elm_menu_item_add(menu, NULL, NULL, \textcolor{stringliteral}{"flip transpose"}, \_orient\_do, orient\_data);

   obj = elm_button_add(win);
   elm\_object\_text\_set(obj, \textcolor{stringliteral}{"Orient"});
   evas\_object\_show(obj);
   evas\_object\_resize(obj, 70, 30);
   evas\_object\_move(obj, 470, 410);
   evas\_object\_smart\_callback\_add(obj, \textcolor{stringliteral}{"clicked"}, \_orient, menu);

   obj = elm_slider_add(win);
   elm\_object\_text\_set(obj, \textcolor{stringliteral}{"Zoom"});
   evas\_object\_show(obj);
   evas\_object\_resize(obj, 300, 30);
   evas\_object\_move(obj, 150, 410);
   evas\_object\_smart\_callback\_add(obj, \textcolor{stringliteral}{"changed"}, \_zoom, photocam);

   evas\_object\_resize(win, 500, 440);
   evas\_object\_show(win);

   elm_run();

   \textcolor{keywordflow}{return} 0;
\}
ELM_MAIN()

static \textcolor{keywordtype}{void}
\_bring\_in(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordtype}{int} w, h;
   elm_photocam_image_size_get(obj, &w, &h);
   elm_photocam_image_region_bring_in(obj, w/2, h/2, 500, 400);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_fit(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordtype}{int} x, y, w, h;
   elm_photocam_image_region_get(data, &x, &y, &w, &h);
   printf(\textcolor{stringliteral}{"region: \{%d, %d, %d, %d\}\(\backslash\)n"}, x, y, w, h);
   elm_photocam_zoom_mode_set(data, ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_unfit(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   elm_photocam_zoom_mode_set(data, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_zoom(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordtype}{double} z = elm_slider_value_get(obj) * 8;
   elm_photocam_zoom_set(data, z);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_orient(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *mn = data;
   \textcolor{keywordflow}{if} (!mn) \textcolor{keywordflow}{return};

   evas\_object\_show(mn);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_orient\_do(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Orient\_Data *orient\_data = data;
   \textcolor{keywordflow}{if} (!orient\_data) \textcolor{keywordflow}{return};

   elm_photocam_image_orient_set(orient\_data->ph, orient\_data->orient);
\}
\end{DoxyCodeInclude}
 