Guest User

Untitled

a guest
Jan 4th, 2018
218
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // gcc file.c -o a.out $(pkg-config --cflags --libs elementary)
  2. //
  3. // TESTS:
  4. //
  5. // time ./a.out 10 500
  6. // perf record -- ./a.out 10 500
  7. // valgrind --tool=massif ./a.out 10 500
  8.  
  9. #include <Elementary.h>
  10.  
  11.  
  12. typedef struct
  13. {
  14.    Evas_Object *gl;
  15.    Elm_Object_Item *it1, *it2;
  16.    int state;
  17. } Bounce;
  18.  
  19. static Bounce _bounce;
  20. static int _count = 0;
  21.  
  22. static unsigned long long frames = 0;
  23.  
  24. static void
  25. _bounce_cb_frame(void *data EINA_UNUSED, Evas *e EINA_UNUSED, void *event_info EINA_UNUSED)
  26. {
  27.    frames++;
  28. }
  29.  
  30. static Eina_Bool
  31. _bounce_cb(void *data)
  32. {
  33.    Bounce *bounce = data;
  34.    bounce->state++;
  35.    if (bounce->state & 0x1)
  36.      elm_genlist_item_bring_in(bounce->it2, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
  37.    else
  38.      elm_genlist_item_bring_in(bounce->it1, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
  39.  
  40.    static struct timespec t0;
  41.    if (bounce->state == 2)
  42.      {
  43.         evas_event_callback_add(evas_object_evas_get(bounce->gl),
  44.                                 EVAS_CALLBACK_RENDER_FLUSH_POST,
  45.                                 _bounce_cb_frame, NULL);
  46.         clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t0);
  47.      }
  48.  
  49.    if (bounce->state > _count)
  50.      {
  51.         struct timespec t;
  52.         unsigned long long tll, t0ll, tdll;
  53.  
  54.         clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t);
  55.         t0ll = (t0.tv_sec * 1000000000) + t0.tv_nsec;
  56.         tll = (t.tv_sec * 1000000000) + t.tv_nsec;
  57.         tdll = tll - t0ll;
  58.         printf("NS since 2 = %llu , %llu frames = %llu / frame\n",
  59.                tdll, frames, tdll / (unsigned long long)frames);
  60.         elm_exit();
  61.      }
  62.    return EINA_TRUE;
  63. }
  64.  
  65. static void
  66. _btbounce_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
  67. {
  68.    Ecore_Timer *tim = evas_object_data_get(obj, "timer");
  69.    if (!tim)
  70.      {
  71.         _bounce_cb(data);
  72.         evas_object_data_set(obj, "timer", tim);
  73.      }
  74. }
  75.  
  76. static void
  77. _btdel_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
  78. {
  79.    Bounce *bounce = data;
  80.    Ecore_Timer *tim = evas_object_data_get(obj, "timer");
  81.    if (tim)
  82.      {
  83.         ecore_timer_del(tim);
  84.         evas_object_data_del(obj, "timer");
  85.      }
  86.    free(bounce);
  87. }
  88.  
  89.  
  90. static void
  91. _win_close_cb(void *data,
  92.               Evas_Object *obj EINA_UNUSED,
  93.               void *info EINA_UNUSED)
  94. {
  95.    elm_exit();
  96. }
  97.  
  98. static
  99. Evas_Object *_get(void *data , Evas_Object *obj, const char *part)
  100. {
  101.    Evas_Object *fr, *bx, *ic, *bt, *ck;
  102.  
  103.    if (strcmp(part, "elm.swallow.content") != 0) return NULL;
  104.  
  105.    fr = elm_frame_add(obj);
  106.    elm_layout_text_set(fr, NULL, "A Frame");
  107.  
  108.    bx = elm_box_add(fr);
  109.    elm_box_horizontal_set(bx, EINA_TRUE);
  110.  
  111.    ic = elm_icon_add(bx);
  112.    elm_icon_standard_set(ic, "home");
  113.    evas_object_size_hint_min_set(ic, 32, 32);
  114.    evas_object_size_hint_align_set(ic, 0.5, EVAS_HINT_FILL);
  115.    evas_object_show(ic);
  116.    elm_box_pack_end(bx, ic);
  117.  
  118.    bt = elm_button_add(bx);
  119.    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
  120.    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  121.    elm_layout_text_set(bt, NULL, "Click Me");
  122.    evas_object_show(bt);
  123.    elm_box_pack_end(bx, bt);
  124.  
  125.    ck = elm_check_add(bx);
  126.    evas_object_size_hint_align_set(ck, EVAS_HINT_FILL, EVAS_HINT_FILL);
  127.    evas_object_size_hint_weight_set(ck, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  128.    elm_layout_text_set(ck, NULL, "some checkbox");
  129.    evas_object_show(ck);
  130.    elm_box_pack_end(bx, ck);
  131.  
  132.    elm_layout_content_set(fr, NULL, bx);
  133.    evas_object_size_hint_min_set(fr, 100, 100);
  134.  
  135.    return fr;
  136. }
  137.  
  138. static Elm_Object_Item *_first, *_last;
  139.  
  140. EAPI_MAIN int
  141. elm_main(int argc, char**argv)
  142. {
  143.    Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
  144.    itc->item_style = "full";
  145.    itc->func.content_get = _get;
  146.    int max = 300;
  147.  
  148.    if (argc >= 2)
  149.      _count = atoi(argv[1]);
  150.    if (argc >= 3)
  151.      max = atoi(argv[2]);
  152.  
  153.    Evas_Object *w = elm_win_util_standard_add("test", "test");
  154.    elm_win_autodel_set(w, EINA_TRUE);
  155.    evas_object_smart_callback_add(w, "delete,request", _win_close_cb, NULL);
  156.  
  157.    Evas_Object *g = elm_genlist_add(w);
  158.    evas_object_size_hint_weight_set(g, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  159.    evas_object_size_hint_align_set(g, EVAS_HINT_FILL, EVAS_HINT_FILL);
  160.    elm_win_resize_object_add(w, g);
  161.    evas_object_show(g);
  162.    evas_object_show(w);
  163.  
  164.  
  165.    _first = elm_genlist_item_append(g, itc, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
  166.    for (unsigned int i = 0; i < max; i++)
  167.      elm_genlist_item_append(g, itc, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
  168.    _last = elm_genlist_item_append(g, itc, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
  169.  
  170.    _bounce.gl =g;
  171.    _bounce.it1 =_first;
  172.    _bounce.it2 =_last;
  173.  
  174.    elm_win_maximized_set(w, 1);
  175.  
  176.     ecore_timer_add(2.0, _bounce_cb, &_bounce);
  177.    elm_run();
  178.    return 0;
  179. }
  180. ELM_MAIN()
RAW Paste Data