#include <Elementary.h>
static Ecore_Thread *thr = NULL;
static Evas_Object *win = NULL;
static Evas_Object *rect = NULL;
struct info
{
double x, y;
};
static void
th_do(void *data, Ecore_Thread *th)
{
double t = 0.0;
for (;;)
{
struct info *inf = malloc(sizeof(struct info));
if (inf)
{
inf->x = 200 + (200 * sin(t));
inf->y = 200 + (200 * cos(t));
ecore_thread_feedback(th, inf);
}
usleep(1000);
t += 0.02;
if (ecore_thread_check(th)) break;
}
}
static void
th_feedback(void *data, Ecore_Thread *th, void *msg)
{
struct info *inf = msg;
evas_object_move(rect, inf->x - 50, inf->y - 50);
free(inf);
}
static void th_end(void *data, Ecore_Thread *th) { printf("thread ended\n"); }
static void th_cancel(void *data, Ecore_Thread *th) { printf("thread cancelled\n"); }
static void
down(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
if (thr) ecore_thread_cancel(thr);
thr = NULL;
}
static void
del(void *data, Evas_Object *obj, void *event_info)
{
if (thr) ecore_thread_cancel(thr);
thr = NULL;
evas_object_del(obj);
}
EAPI_MAIN int
elm_main(int argc, char **argv)
{
Evas_Object *o;
evas_object_smart_callback_add(win, "delete,request", del, NULL);
o = evas_object_rectangle_add(evas_object_evas_get(win));
evas_object_color_set(o, 50, 80, 180, 255);
evas_object_resize(o, 100, 100);
evas_object_show(o);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, down, NULL);
rect = o;
thr = ecore_thread_feedback_run(th_do, th_feedback, th_end, th_cancel,
NULL, EINA_TRUE);
evas_object_resize(win, 400, 400);
evas_object_show(win);
if (thr) ecore_thread_cancel(thr);
return 0;
}