\chapter{Photocam example}
\hypertarget{tutorial_photocam}{}\label{tutorial_photocam}\index{Photocam example@{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\textquotesingle{}ll only show the parts of the example that relate to the photocam, the full source code can be seen \doxylink{photocam_example_01_8c-example}{here}.

Creating a photocam is as easy as creating any other widget\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ photocam\ =\ \mbox{\hyperlink{group__Elm__Photocam__Group_gaca84805f2b6169d7f7949bd10d5f9e4d}{elm\_photocam\_add}}(win);}

\end{DoxyCodeInclude}
 A photocam is only useful if we have a image on it, so lets set a file for it to work with\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ snprintf(buf,\ \textcolor{keyword}{sizeof}(buf),\ \textcolor{stringliteral}{"{}\%s/images/insanely\_huge\_test\_image.jpg"{}},\ \mbox{\hyperlink{group__Elm__App_gab10cf98c5aa3936dfda01d6bca366d09}{elm\_app\_data\_dir\_get}}());}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Photocam__Group_gaa4cb6e360aab7307380ac92de4e04dd2}{elm\_photocam\_file\_set}}(photocam,\ buf);}

\end{DoxyCodeInclude}
 We now set the photocam to not bounce horizontally\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Scroller__Group_gae69101dbdb089598ca790c73bd9d7a42}{elm\_scroller\_bounce\_set}}(photocam,\ \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}},\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}

\end{DoxyCodeInclude}
 And we want to know when the photocam has finished loading the image so\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Smart__Object__Group_gac12dd6655f488cc47ce6cf00eb7d12b2}{evas\_object\_smart\_callback\_add}}(photocam,\ \textcolor{stringliteral}{"{}loaded,detail"{}},\ \_bring\_in,\ NULL);}

\end{DoxyCodeInclude}
 The reason to know when the image is loaded is so that we can bring the center of the image into view\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_bring\_in(\textcolor{keywordtype}{void}\ *data\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ Evas\_Object\ *obj,\ \textcolor{keywordtype}{void}\ *event\_info\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ w,\ h;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Photocam__Group_gae578f8117d96e92a27037947fabd3d15}{elm\_photocam\_image\_size\_get}}(obj,\ \&w,\ \&h);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Photocam__Group_ga51a9dd5b4e7c6593e9734d1838e11266}{elm\_photocam\_image\_region\_bring\_in}}(obj,\ w/2,\ h/2,\ 500,\ 400);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 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\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_fit(\textcolor{keywordtype}{void}\ *data,\ Evas\_Object\ *obj\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{void}\ *event\_info\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ x,\ y,\ w,\ h;}
\DoxyCodeLine{\ \ \ elm\_photocam\_image\_region\_get(data,\ \&x,\ \&y,\ \&w,\ \&h);}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}region:\ \{\%d,\ \%d,\ \%d,\ \%d\}\(\backslash\)n"{}},\ x,\ y,\ w,\ h);}

\end{DoxyCodeInclude}
\begin{DoxyNote}{Note}
When in fit mode our slider(explained below) won\textquotesingle{}t work.
\end{DoxyNote}
The second button("{}\+Unfit"{}) will bring the photocam back into manual zoom mode\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_unfit(\textcolor{keywordtype}{void}\ *data,\ Evas\_Object\ *obj\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{void}\ *event\_info\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Photocam__Group_ga36acb49e545f2426115f74f4b33eb67f}{elm\_photocam\_zoom\_mode\_set}}(data,\ ELM\_PHOTOCAM\_ZOOM\_MODE\_MANUAL);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 Our slider controls the level of zoom of the photocam\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_zoom(\textcolor{keywordtype}{void}\ *data,\ Evas\_Object\ *obj,\ \textcolor{keywordtype}{void}\ *event\_info\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{double}\ z\ =\ \mbox{\hyperlink{group__Elm__Slider_ga2dd3f70cdbcb4a81b5d7a08a18afaa1d}{elm\_slider\_value\_get}}(obj)\ *\ 8;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Photocam__Group_ga2f63118a574a0c42a615c0da60cf622a}{elm\_photocam\_zoom\_set}}(data,\ z);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
\begin{DoxyNote}{Note}
It is important to note that this only works when in manual zoom mode.
\end{DoxyNote}
Our example will initially look like this\+:

 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/photocam_example_01}}
\end{DoxyImageNoCaption}
 