Advertisement
Guest User

jeff

a guest
Feb 6th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.05 KB | None | 0 0
  1. //gcc  `pkg-config enlightenment --cflags` -c zoom2.c
  2. //gcc  zoom2.o `pkg-config enlightenment --libs` `pkg-config ecore-input --libs`
  3.  
  4. #include <Eina.h>
  5. #include <Ecore.h>
  6. #include <Ecore_X.h>
  7. #include <Ecore_Evas.h>
  8. #include <stdio.h>
  9. #include <math.h>
  10.  
  11. typedef struct _Item Item;
  12.  
  13. struct _Item
  14. {
  15.   Evas_Object *o;
  16.   int posx;
  17.   int posy;
  18.   int mx;
  19.   int my;  
  20. };
  21.  
  22. #define SIZE  8
  23. #define WIDTH 600
  24. #define HEIGHT 600
  25. #define OFFSET 100
  26.  
  27. static Evas_Object *move, *o;
  28. static Eina_List *items = NULL;
  29. static float zoom = 2.0;
  30. static float range = 100.0;
  31. static Ecore_Idle_Enterer *idler = NULL;
  32. static int mx = 0;
  33. static int my = 0;
  34. static int changed = 0;
  35.  
  36. static void
  37. _mouse_down_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info)
  38. {
  39.    Evas_Event_Mouse_Wheel *e = event_info;
  40.  
  41.    if (e->z< 0)
  42.      zoom += 0.1;
  43.    else if (e->z > 0)
  44.      zoom -= 0.1;
  45.  
  46.    changed = 1;
  47. }
  48.  
  49. static double
  50. _zoom(double dist)
  51. {
  52.    if (dist >= range)
  53.      {
  54.         return range * zoom;
  55.      }
  56.    else if (dist <= -range)
  57.      {
  58.         return -range * zoom;
  59.      }
  60.  
  61.    return sin(M_PI/2.0 * dist/range) * range * zoom;
  62. }
  63.  
  64. static double arc = 0.0;
  65. static int dir = 1;
  66.  
  67. static Eina_Bool
  68. _redraw(void *data)
  69. {
  70.    Item *it;
  71.    Eina_List *l;
  72.  
  73.    double posx1, posx2, posy1, posy2;
  74.  
  75.    /* if (!changed)
  76.     *   return EINA_TRUE; */
  77.  
  78.    if (dir)
  79.      {
  80.         zoom += 0.1;
  81.         if (zoom > 5)
  82.           dir = 0;
  83.      }
  84.    else
  85.      {
  86.         zoom -= 0.1;
  87.         if (zoom <= 0)
  88.           dir = 1;
  89.      }
  90.  
  91.    mx = OFFSET + WIDTH/2 +  2 * range * sin(arc);
  92.    my = OFFSET + HEIGHT/2 + 2 * range * cos(arc);
  93.    arc += 0.03;
  94.  
  95.      
  96.    EINA_LIST_FOREACH(items, l, it)
  97.      { 
  98.         int x1 = it->posx + SIZE/2;
  99.         int y1 = it->posy + SIZE/2;
  100.      
  101.         double dist1 = sqrt ((x1 - mx) * (x1 - mx) + ((y1 - my) * (y1 - my)));
  102.  
  103.         double ndist1 = _zoom(dist1);
  104.  
  105.         posx1 = x1 - SIZE/2 + (x1 - mx) / dist1 * ndist1;
  106.         posy1 = y1 - SIZE/2 + (y1 - my) / dist1 * ndist1;
  107.  
  108.         posx2 = x1 + SIZE/2 + (x1 - mx) / dist1 * ndist1;
  109.         posy2 = y1 + SIZE/2 + (y1 - my) / dist1 * ndist1;
  110.              
  111.         evas_object_move(it->o, posx1, posy1);
  112.  
  113.         evas_object_resize(it->o, (posx2 - posx1) - 0.5, (posy2 - posy1) - 0.5);
  114.      }
  115.  
  116.    changed = 0;
  117.    
  118.    return EINA_TRUE;
  119. }
  120.  
  121. static void
  122. _mouse_move_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info)
  123. {
  124.    Evas_Event_Mouse_Move *e = event_info;
  125.  
  126.    mx = e->cur.canvas.x;
  127.    my = e->cur.canvas.y;
  128.    
  129.    changed = 1;
  130.  
  131.    _redraw(NULL);
  132. }
  133.  
  134. int main(int argc, char *argv[])
  135. {
  136.    Ecore_Evas *ee;
  137.    Evas *e;
  138.    int k, j;
  139.    Evas_Object *bg;
  140.  
  141.    ecore_init();
  142.    ecore_evas_init();
  143.  
  144.    ee = ecore_evas_software_x11_new(NULL, 0, 10, 10, WIDTH +200, HEIGHT + 200);
  145.    
  146.    /* ecore_evas_alpha_set(ee, 1); */
  147.    /* ecore_evas_borderless_set(ee, 1); */
  148.    ecore_evas_name_class_set(ee, "BOX", "TEST");
  149.    ecore_evas_show(ee);
  150.    e = ecore_evas_get(ee);
  151.  
  152.    bg = evas_object_rectangle_add(e);
  153.    evas_object_resize(bg, WIDTH + 200, HEIGHT + 200);
  154.    evas_object_color_set(bg, 20, 20, 20, 255);
  155.    /* evas_object_layer_set(bg, 255);  */
  156.    evas_object_show(bg);
  157.  
  158.    evas_object_event_callback_add(bg, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move_cb, bg);
  159.    evas_object_event_callback_add(bg, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_down_cb, bg);
  160.  
  161.    Item *item;
  162.  
  163.    Evas_Object *oo;
  164.  
  165.    for (k = 0; k < WIDTH/SIZE+1; k++)
  166.      {
  167.     for (j = 0; j < HEIGHT/SIZE+1; j++)
  168.       {
  169.          item = calloc(1, sizeof(Item));
  170.      
  171.          oo = evas_object_rectangle_add(e);
  172.          evas_object_resize(oo, SIZE, SIZE);
  173.          evas_object_color_set(oo, 255 - 5 * k, 5 * j-k, 5 * k, 220);
  174.          evas_object_show(oo);
  175.              evas_object_pass_events_set(oo, EINA_TRUE);
  176.              
  177.          item->o = oo;
  178.          item->posx = OFFSET + k * SIZE;
  179.          item->posy = OFFSET + j * SIZE;
  180.          evas_object_move(oo, item->posx, item->posy);
  181.          items = eina_list_append(items, item);
  182.       }
  183.      }
  184.  
  185.    ecore_timer_add(0.0001, _redraw, NULL);
  186.    
  187.    ecore_main_loop_begin();
  188.  
  189.  
  190.    EINA_LIST_FREE(items, item)
  191.      free(item);
  192.    
  193.    evas_object_del(bg);
  194.  
  195.    ecore_evas_shutdown();
  196.    ecore_shutdown();
  197.    return 0;
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement