In this example we will make use of signals to help to move an image away from the mouse pointer.

Signals are software interruption, this means that when it happens and if the program is sensitive to it the program will stop whatever it is doing and handle the signal.

In this example we are only sensitive to the \char`\"{}mouse,move\char`\"{} signal so we need to register a callback to it. To do this we will add a signal callback to our edje object that will detect \char`\"{}mouse,move\char`\"{} signal coming from the part \char`\"{}part\+\_\+image\char`\"{} and when this happens we will call the function \+\_\+on\+\_\+mouse\+\_\+over passing the evas pointer as a parameter. The evas pointer is passed as a parameter because we need to know where is the mouse pointer in the screen.

We can see bellow how we can listen to the signal\+:

 
\begin{DoxyCodeInclude}
   edje\_object\_signal\_callback\_add(edje\_obj, \textcolor{stringliteral}{"mouse,move"}, \textcolor{stringliteral}{"part\_image"},
                                   \_on\_mouse\_over, evas);

\end{DoxyCodeInclude}


Now, let's pass to the callback function. If we want to keep the ball away from the mouse pointer we need to now where is the ball and where is the mouse and we can easily discovery these things using this\+:

For the object position in the canvas\+:  
\begin{DoxyCodeInclude}
   \hyperlink{group__Evas__Object__Group__Basic_ga6f52fab1a96dc58c85ee481d84bac871}{evas\_object\_geometry\_get}(edje\_obj, &x, &y, NULL, NULL);

\end{DoxyCodeInclude}


For the mouse position relative to the screen\+: 
\begin{DoxyCodeInclude}
   evas\_pointer\_output\_xy\_get(evas, &mouseX, &mouseY);

\end{DoxyCodeInclude}


Now that we have the position of the mouse and the object we just need to set the new location and move the object. To set the new location we do this\+: 
\begin{DoxyCodeInclude}
   \textcolor{keywordflow}{if} ((rand() % 2) == 0)
     x += ((mouseX - x) + (x / 4 + mouseY / 2));
   \textcolor{keywordflow}{else}
     x -= ((mouseX - x) + (x / 4 + mouseY / 2));

   \textcolor{keywordflow}{if} ((rand() % 2) == 0)
     y += ((mouseY - y) + (y / 4 + mouseX / 2));
   \textcolor{keywordflow}{else}
     y -= ((mouseY - y) + (y / 4 + mouseX / 2));

\end{DoxyCodeInclude}


You can change the formula above if you like. Because we are changing the object's position we need to do something if the new position is beyond the canvas size. So here it is\+:


\begin{DoxyCodeInclude}
   \textcolor{keywordflow}{if} (x > WIDTH)
     x = WIDTH;
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (x < 0) x = 0;

   \textcolor{keywordflow}{if} (y > HEIGHT)
     y = HEIGHT;
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (y < 0) y = 0;

\end{DoxyCodeInclude}


Then now what we need to do is move the object\+: 
\begin{DoxyCodeInclude}
   evas\_object\_move(edje\_obj, x, y);

\end{DoxyCodeInclude}


Here is the complete callback function\+:

 
\begin{DoxyCodeInclude}
\_on\_mouse\_over(\textcolor{keywordtype}{void} *data, \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *edje\_obj,
               \textcolor{keyword}{const} \textcolor{keywordtype}{char} *emission EINA\_UNUSED, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *source EINA\_UNUSED)
\{
   \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *evas;
   \textcolor{keywordtype}{int} x, y, mouseX, mouseY;

   evas = (\hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *) data;
   \hyperlink{group__Evas__Object__Group__Basic_ga6f52fab1a96dc58c85ee481d84bac871}{evas\_object\_geometry\_get}(edje\_obj, &x, &y, NULL, NULL);

   evas\_pointer\_output\_xy\_get(evas, &mouseX, &mouseY);

   \textcolor{keywordflow}{if} ((rand() % 2) == 0)
     x += ((mouseX - x) + (x / 4 + mouseY / 2));
   \textcolor{keywordflow}{else}
     x -= ((mouseX - x) + (x / 4 + mouseY / 2));

   \textcolor{keywordflow}{if} ((rand() % 2) == 0)
     y += ((mouseY - y) + (y / 4 + mouseX / 2));
   \textcolor{keywordflow}{else}
     y -= ((mouseY - y) + (y / 4 + mouseX / 2));

   \textcolor{keywordflow}{if} (x > WIDTH)
     x = WIDTH;
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (x < 0) x = 0;

   \textcolor{keywordflow}{if} (y > HEIGHT)
     y = HEIGHT;
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (y < 0) y = 0;

   fprintf(stdout, \textcolor{stringliteral}{"Moving object to - (%d,%d)\(\backslash\)n"}, x, y);

   evas\_object\_move(edje\_obj, x, y);
\}

\end{DoxyCodeInclude}


When you compile and run it you should see this\+:   
\begin{DoxyImage}
\includegraphics{signal2final}
\caption{width=}
\end{DoxyImage}


The .edc file\+: 
\begin{DoxyCodeInclude}
1 collections\{
2    group\{
3       name: "image\_group";
4       max: 500 500;
5       min: 50 50;
6       images\{
7            image: "bubble.png" COMP;
8      \}
9     parts\{
10             part\{
11                    name: "part\_image";
12                    type: IMAGE;
13                    description\{
14                        min:63 63;
15                        image\{
16                             normal: "bubble.png";
17                        \}
18                    \}
19                  \}
20           \}
21    \}
22 \}
\end{DoxyCodeInclude}


The source code\+: 
\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{// edje\_cc signalsBubble.edc && gcc -o signals2 signals2.c `pkg-config --libs --cflags ecore ecore-evas
       edje`}

\textcolor{preprocessor}{#ifdef HAVE\_CONFIG\_H}
\textcolor{preprocessor}{#include "config.h"}
\textcolor{preprocessor}{#else}
\textcolor{preprocessor}{#define PACKAGE\_EXAMPLES\_DIR "."}
\textcolor{preprocessor}{#define EINA\_UNUSED}
\textcolor{preprocessor}{#endif}

\textcolor{preprocessor}{#ifndef PACKAGE\_DATA\_DIR}
\textcolor{preprocessor}{#define PACKAGE\_DATA\_DIR "."}
\textcolor{preprocessor}{#endif}

\textcolor{preprocessor}{#include <Ecore.h>}
\textcolor{preprocessor}{#include <\hyperlink{Ecore__Evas_8h}{Ecore\_Evas.h}>}
\textcolor{preprocessor}{#include <\hyperlink{Edje_8h}{Edje.h}>}
\textcolor{preprocessor}{#include <stdio.h>}

\textcolor{preprocessor}{#define WIDTH     (700)}
\textcolor{preprocessor}{#define HEIGHT    (700)}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_on\_delete(Ecore\_Evas *ee EINA\_UNUSED)
\{
   \hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}();
\}

\textcolor{comment}{/* mouse over signals */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_on\_mouse\_over(\textcolor{keywordtype}{void} *data, \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *edje\_obj,
               \textcolor{keyword}{const} \textcolor{keywordtype}{char} *emission EINA\_UNUSED, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *source EINA\_UNUSED)
\{
   \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *evas;
   \textcolor{keywordtype}{int} x, y, mouseX, mouseY;

   evas = (\hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *) data;
   \hyperlink{group__Evas__Object__Group__Basic_ga6f52fab1a96dc58c85ee481d84bac871}{evas\_object\_geometry\_get}(edje\_obj, &x, &y, NULL, NULL);

   evas\_pointer\_output\_xy\_get(evas, &mouseX, &mouseY);

   \textcolor{keywordflow}{if} ((rand() % 2) == 0)
     x += ((mouseX - x) + (x / 4 + mouseY / 2));
   \textcolor{keywordflow}{else}
     x -= ((mouseX - x) + (x / 4 + mouseY / 2));

   \textcolor{keywordflow}{if} ((rand() % 2) == 0)
     y += ((mouseY - y) + (y / 4 + mouseX / 2));
   \textcolor{keywordflow}{else}
     y -= ((mouseY - y) + (y / 4 + mouseX / 2));

   \textcolor{keywordflow}{if} (x > WIDTH)
     x = WIDTH;
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (x < 0) x = 0;

   \textcolor{keywordflow}{if} (y > HEIGHT)
     y = HEIGHT;
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (y < 0) y = 0;

   fprintf(stdout, \textcolor{stringliteral}{"Moving object to - (%d,%d)\(\backslash\)n"}, x, y);

   evas\_object\_move(edje\_obj, x, y);
\}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{int} argc EINA\_UNUSED, \textcolor{keywordtype}{char} **argv EINA\_UNUSED)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *edje\_file = PACKAGE\_DATA\_DIR\textcolor{stringliteral}{"/signalsBubble.edj"};
   Ecore\_Evas *ee;
   \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *evas;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *bg;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *edje\_obj;

   \textcolor{keywordflow}{if} (!\hyperlink{group__Ecore__Evas__Group_ga32ddbb6457033ad435a177eb0c4fe235}{ecore\_evas\_init}()) \textcolor{keywordflow}{return} EXIT\_FAILURE;

   \textcolor{keywordflow}{if} (!\hyperlink{group__Edje__General__Group_ga1c9c6594f38023c29fbfb2d0c8c675db}{edje\_init}()) \textcolor{keywordflow}{goto} shutdown\_ecore\_evas;

   ee = \hyperlink{group__Ecore__Evas__Group_gac7f2cdbcb79635c34317c1183dd04cb0}{ecore\_evas\_new}(NULL, 0, 0, WIDTH, HEIGHT, NULL);

   \textcolor{keywordflow}{if} (!ee) \textcolor{keywordflow}{goto} shutdown\_edje;

   \hyperlink{group__Ecore__Evas__Group_ga3d478e975e2101b9b821ef24baf3dd9e}{ecore\_evas\_callback\_delete\_request\_set}(ee, \_on\_delete);
   \hyperlink{group__Ecore__Evas__Group_ga3b2832e0373bbafae2bb7143618535c1}{ecore\_evas\_title\_set}(ee, \textcolor{stringliteral}{"Edje animations and signals"});

   evas = \hyperlink{group__Ecore__Evas__Group_ga75a7cc694b6069e78df47dab0b0f2d20}{ecore\_evas\_get}(ee);

   bg = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(evas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(bg, 255, 255, 255, 255); \textcolor{comment}{//White}
   evas\_object\_move(bg, 0, 0); \textcolor{comment}{//orign}
   evas\_object\_resize(bg, WIDTH, HEIGHT); \textcolor{comment}{//cover the window}
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(bg);

   \hyperlink{group__Ecore__Evas__Group_gac35627a5c3a766ee42762dbcc9eb733d}{ecore\_evas\_object\_associate}(ee, bg, ECORE\_EVAS\_OBJECT\_ASSOCIATE\_BASE);
   evas\_object\_focus\_set(bg, \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});

   edje\_obj = edje\_object\_add(evas);

   \textcolor{keywordflow}{if} (!edje\_object\_file\_set(edje\_obj, edje\_file, \textcolor{stringliteral}{"image\_group"}))
     \{
        \textcolor{keywordtype}{int} err = edje\_object\_load\_error\_get(edje\_obj);
        \textcolor{keyword}{const} \textcolor{keywordtype}{char} *errmsg = \hyperlink{group__Edje__Object__File_ga034465c2de4ab495802da20f332c386e}{edje\_load\_error\_str}(err);
        fprintf(stderr, \textcolor{stringliteral}{"Could not load the edje file - reason:%s\(\backslash\)n"}, errmsg);
        \textcolor{keywordflow}{goto} shutdown\_edje;
     \}

   edje\_object\_signal\_callback\_add(edje\_obj, \textcolor{stringliteral}{"mouse,move"}, \textcolor{stringliteral}{"part\_image"},
                                   \_on\_mouse\_over, evas);
   evas\_object\_resize(edje\_obj, 63, 63);
   evas\_object\_move(edje\_obj, 50, 50);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(edje\_obj);

   \hyperlink{group__Ecore__Evas__Group_ga4953047ff97d4f1b0d75a7d513d4f317}{ecore\_evas\_show}(ee);

   \hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}();

   \hyperlink{group__Ecore__Evas__Group_gad3ec61f2aa03df4d3dbfd0d311e0c8dc}{ecore\_evas\_free}(ee);
   \hyperlink{group__Edje__General__Group_ga01041f6702f2d81bf10c3e41899805cb}{edje\_shutdown}();
   \hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}();

   \textcolor{keywordflow}{return} EXIT\_SUCCESS;

   shutdown\_edje: \hyperlink{group__Edje__General__Group_ga01041f6702f2d81bf10c3e41899805cb}{edje\_shutdown}();

   shutdown\_ecore\_evas: \hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}();

   \textcolor{keywordflow}{return} EXIT\_FAILURE;
\}
\end{DoxyCodeInclude}


To compile use this command\+: \begin{DoxyVerb}* gcc -o signals2 signals2.c -DPACKAGE_BIN_DIR=\"/Where/enlightenment/is/installed/bin\"
* -DPACKAGE_LIB_DIR=\"/Where/enlightenment/is/installed/lib\"
* -DPACKAGE_DATA_DIR=\"/Where/enlightenment/is/installed/share\"
* `pkg-config --cflags --libs evas ecore ecore-evas edje`
*
* edje_cc -id /path/to/the/image signalsBubble.edc
* \end{DoxyVerb}
 