//gcc `pkg-config enlightenment --cflags` -c zoom2.c
//gcc zoom2.o `pkg-config enlightenment --libs` `pkg-config ecore-input --libs`
#include <Eina.h>
#include <Ecore.h>
#include <Ecore_X.h>
#include <Ecore_Evas.h>
#include <stdio.h>
#include <math.h>
typedef struct _Item Item;
struct _Item
{
Evas_Object *o;
int posx;
int posy;
int mx;
int my;
};
#define SIZE 8
#define WIDTH 600
#define HEIGHT 600
#define OFFSET 100
static Evas_Object *move, *o;
static Eina_List *items = NULL;
static float zoom = 2.0;
static float range = 100.0;
static Ecore_Idle_Enterer *idler = NULL;
static int mx = 0;
static int my = 0;
static int changed = 0;
static void
_mouse_down_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info)
{
Evas_Event_Mouse_Wheel *e = event_info;
if (e->z< 0)
zoom += 0.1;
else if (e->z > 0)
zoom -= 0.1;
changed = 1;
}
static double
_zoom(double dist)
{
if (dist >= range)
{
return range * zoom;
}
else if (dist <= -range)
{
return -range * zoom;
}
return sin(M_PI/2.0 * dist/range) * range * zoom;
}
static double arc = 0.0;
static int dir = 1;
static Eina_Bool
_redraw(void *data)
{
Item *it;
Eina_List *l;
double posx1, posx2, posy1, posy2;
/* if (!changed)
* return EINA_TRUE; */
if (dir)
{
zoom += 0.1;
if (zoom > 5)
dir = 0;
}
else
{
zoom -= 0.1;
if (zoom <= 0)
dir = 1;
}
mx = OFFSET + WIDTH/2 + 2 * range * sin(arc);
my = OFFSET + HEIGHT/2 + 2 * range * cos(arc);
arc += 0.03;
EINA_LIST_FOREACH(items, l, it)
{
int x1 = it->posx + SIZE/2;
int y1 = it->posy + SIZE/2;
double dist1 = sqrt ((x1 - mx) * (x1 - mx) + ((y1 - my) * (y1 - my)));
double ndist1 = _zoom(dist1);
posx1 = x1 - SIZE/2 + (x1 - mx) / dist1 * ndist1;
posy1 = y1 - SIZE/2 + (y1 - my) / dist1 * ndist1;
posx2 = x1 + SIZE/2 + (x1 - mx) / dist1 * ndist1;
posy2 = y1 + SIZE/2 + (y1 - my) / dist1 * ndist1;
evas_object_move(it->o, posx1, posy1);
evas_object_resize(it->o, (posx2 - posx1) - 0.5, (posy2 - posy1) - 0.5);
}
changed = 0;
return EINA_TRUE;
}
static void
_mouse_move_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info)
{
Evas_Event_Mouse_Move *e = event_info;
mx = e->cur.canvas.x;
my = e->cur.canvas.y;
changed = 1;
_redraw(NULL);
}
int main(int argc, char *argv[])
{
Ecore_Evas *ee;
Evas *e;
int k, j;
Evas_Object *bg;
ecore_init();
ecore_evas_init();
ee = ecore_evas_software_x11_new(NULL, 0, 10, 10, WIDTH +200, HEIGHT + 200);
/* ecore_evas_alpha_set(ee, 1); */
/* ecore_evas_borderless_set(ee, 1); */
ecore_evas_name_class_set(ee, "BOX", "TEST");
ecore_evas_show(ee);
e = ecore_evas_get(ee);
bg = evas_object_rectangle_add(e);
evas_object_resize(bg, WIDTH + 200, HEIGHT + 200);
evas_object_color_set(bg, 20, 20, 20, 255);
/* evas_object_layer_set(bg, 255); */
evas_object_show(bg);
evas_object_event_callback_add(bg, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move_cb, bg);
evas_object_event_callback_add(bg, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_down_cb, bg);
Item *item;
Evas_Object *oo;
for (k = 0; k < WIDTH/SIZE+1; k++)
{
for (j = 0; j < HEIGHT/SIZE+1; j++)
{
item = calloc(1, sizeof(Item));
oo = evas_object_rectangle_add(e);
evas_object_resize(oo, SIZE, SIZE);
evas_object_color_set(oo, 255 - 5 * k, 5 * j-k, 5 * k, 220);
evas_object_show(oo);
evas_object_pass_events_set(oo, EINA_TRUE);
item->o = oo;
item->posx = OFFSET + k * SIZE;
item->posy = OFFSET + j * SIZE;
evas_object_move(oo, item->posx, item->posy);
items = eina_list_append(items, item);
}
}
ecore_timer_add(0.0001, _redraw, NULL);
ecore_main_loop_begin();
EINA_LIST_FREE(items, item)
free(item);
evas_object_del(bg);
ecore_evas_shutdown();
ecore_shutdown();
return 0;
}