demo_expand.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #include "ftk.h"
  2. #include "ftk_animator_expand.h"
  3. static void create_ani_window(int type, int sync);
  4. static Ret button_to_east_south_clicked(void* ctx, void* obj)
  5. {
  6. create_ani_window(FTK_ANI_TO_EAST_SOUTH, 1);
  7. return RET_OK;
  8. }
  9. static Ret button_to_east_north_clicked(void* ctx, void* obj)
  10. {
  11. create_ani_window(FTK_ANI_TO_EAST_NORTH, 1);
  12. return RET_OK;
  13. }
  14. static Ret button_to_right_clicked(void* ctx, void* obj)
  15. {
  16. create_ani_window(FTK_ANI_TO_RIGHT, 0);
  17. return RET_OK;
  18. }
  19. static Ret button_to_down_clicked(void* ctx, void* obj)
  20. {
  21. create_ani_window(FTK_ANI_TO_DOWN, 0);
  22. return RET_OK;
  23. }
  24. static Ret button_to_up_clicked(void* ctx, void* obj)
  25. {
  26. create_ani_window(FTK_ANI_TO_UP, 0);
  27. return RET_OK;
  28. }
  29. static Ret button_to_brink_clicked(void* ctx, void* obj)
  30. {
  31. create_ani_window(FTK_ANI_TO_BRINK, 0);
  32. return RET_OK;
  33. }
  34. static Ret button_close_clicked(void* ctx, void* obj)
  35. {
  36. FtkWidget* win = ctx;
  37. ftk_logd("%s: close window %s\n", __func__, ftk_widget_get_text(win));
  38. ftk_widget_unref(win);
  39. return RET_OK;
  40. }
  41. static Ret button_quit_clicked(void* ctx, void* obj)
  42. {
  43. FtkWidget* win = ctx;
  44. ftk_widget_unref(win);
  45. ftk_logd("%s: close window %s\n", __func__, ftk_widget_get_text(win));
  46. return RET_OK;
  47. }
  48. static void create_ani_window(int type, int sync)
  49. {
  50. int delta = 0;
  51. int width = 0;
  52. int height = 0;
  53. FtkWidget* button = NULL;
  54. FtkGc gc = {0};
  55. char filename[FTK_MAX_PATH+1] = {0};
  56. FtkWidget* win = ftk_app_window_create();
  57. FtkAnimator* ani = ftk_animator_expand_create(1);
  58. gc.mask = FTK_GC_BITMAP;
  59. width = ftk_widget_width(win);
  60. height = ftk_widget_height(win);
  61. delta = height/6;
  62. button = ftk_button_create(win, width/3, height/3, width/3, 50);
  63. ftk_widget_set_text(button, "关闭");
  64. ftk_widget_show(button, 1);
  65. ftk_button_set_clicked_listener(button, button_close_clicked, win);
  66. ftk_snprintf(filename, FTK_MAX_PATH, "%s/jpeg1.jpg",
  67. ftk_config_get_test_data_dir(ftk_default_config()));
  68. gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
  69. ftk_widget_set_gc(win, FTK_WIDGET_NORMAL, &gc);
  70. ftk_gc_reset(&gc);
  71. switch(type)
  72. {
  73. case FTK_ANI_TO_RIGHT:
  74. case FTK_ANI_TO_EAST_SOUTH:
  75. case FTK_ANI_TO_EAST_NORTH:
  76. {
  77. ftk_animator_set_param(ani, type, 100, width, delta, 200);
  78. break;
  79. }
  80. case FTK_ANI_TO_BRINK:
  81. case FTK_ANI_TO_DOWN:
  82. {
  83. ftk_animator_set_param(ani, type, 100, height, delta, 200);
  84. break;
  85. }
  86. case FTK_ANI_TO_UP:
  87. {
  88. ftk_animator_set_param(ani, type, height - 100, ftk_widget_top(win), delta, 200);
  89. break;
  90. }
  91. default:break;
  92. }
  93. ftk_animator_start(ani, win, 0);
  94. return;
  95. }
  96. static void create_app_window(void)
  97. {
  98. char title[32] = {0};
  99. int width = 0;
  100. int height = 0;
  101. FtkWidget* win = ftk_app_window_create();
  102. FtkWidget* button = NULL;
  103. width = ftk_widget_width(win);
  104. height = ftk_widget_height(win);
  105. button = ftk_button_create(win, 5, height/6, width/2-5, 50);
  106. ftk_widget_set_text(button, "向右伸展");
  107. ftk_button_set_clicked_listener(button, button_to_right_clicked, win);
  108. button = ftk_button_create(win, width/2, height/6, width/2-5, 50);
  109. ftk_widget_set_text(button, "Down");
  110. ftk_button_set_clicked_listener(button, button_to_down_clicked, win);
  111. button = ftk_button_create(win, 5, height/6 + 60, width/2-5, 50);
  112. ftk_widget_set_text(button, "RightDown");
  113. ftk_button_set_clicked_listener(button, button_to_east_south_clicked, win);
  114. button = ftk_button_create(win, width/2, height/6 + 60, width/2-5, 50);
  115. ftk_widget_set_text(button, "RightUp");
  116. ftk_button_set_clicked_listener(button, button_to_east_north_clicked, win);
  117. button = ftk_button_create(win, 5, height/6 + 120, width/2-5, 50);
  118. ftk_widget_set_text(button, "Up");
  119. ftk_button_set_clicked_listener(button, button_to_up_clicked, win);
  120. button = ftk_button_create(win, width/2, height/6 + 120, width/2-5, 50);
  121. ftk_widget_set_text(button, "Brink");
  122. ftk_button_set_clicked_listener(button, button_to_brink_clicked, win);
  123. button = ftk_button_create(win, width/4-2, height/6 + 180, width/2-5, 50);
  124. ftk_widget_set_text(button, "Quit");
  125. ftk_button_set_clicked_listener(button, button_quit_clicked, win);
  126. ftk_snprintf(title, sizeof(title), "Expand Demo");
  127. ftk_widget_set_text(win, title);
  128. FTK_QUIT_WHEN_WIDGET_CLOSE(win);
  129. ftk_widget_show_all(win, 1);
  130. return;
  131. }
  132. #ifdef FTK_AS_PLUGIN
  133. #include "ftk_app_demo.h"
  134. FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
  135. FtkApp* ftk_app_demo_expand_create()
  136. {
  137. return ftk_app_demo_create(_("expand"), ftk_main);
  138. }
  139. #else
  140. #define FTK_HIDE extern
  141. #endif /*FTK_AS_PLUGIN*/
  142. FTK_HIDE int FTK_MAIN(int argc, char* argv[])
  143. {
  144. FTK_INIT(argc, argv);
  145. create_app_window();
  146. FTK_RUN();
  147. return 0;
  148. }