demo_zoom.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include "ftk.h"
  2. #include "ftk_animator_zoom.h"
  3. static void create_ani_window(int type, int sync);
  4. static Ret button_to_zoom_in_clicked(void* ctx, void* obj)
  5. {
  6. create_ani_window(FTK_ANI_ZOOM_IN, 1);
  7. return RET_OK;
  8. }
  9. static Ret button_to_zoom_out_clicked(void* ctx, void* obj)
  10. {
  11. create_ani_window(FTK_ANI_ZOOM_OUT, 1);
  12. return RET_OK;
  13. }
  14. static Ret button_close_clicked(void* ctx, void* obj)
  15. {
  16. FtkWidget* win = ctx;
  17. ftk_logd("%s: close window %s\n", __func__, ftk_widget_get_text(win));
  18. ftk_widget_unref(win);
  19. return RET_OK;
  20. }
  21. static Ret button_quit_clicked(void* ctx, void* obj)
  22. {
  23. FtkWidget* win = ctx;
  24. ftk_widget_unref(win);
  25. ftk_logd("%s: close window %s\n", __func__, ftk_widget_get_text(win));
  26. return RET_OK;
  27. }
  28. static void create_ani_window(int type, int sync)
  29. {
  30. int delta = 0;
  31. int width = 0;
  32. int height = 0;
  33. FtkWidget* button = NULL;
  34. FtkGc gc = {0};
  35. char filename[FTK_MAX_PATH+1] = {0};
  36. FtkWidget* win = ftk_app_window_create();
  37. FtkAnimator* ani = ftk_animator_zoom_create(1);
  38. gc.mask = FTK_GC_BITMAP;
  39. width = ftk_widget_width(win);
  40. height = ftk_widget_height(win);
  41. delta = height/6;
  42. button = ftk_button_create(win, width/3, height/3, width/3, 50);
  43. ftk_widget_set_text(button, "关闭");
  44. ftk_widget_show(button, 1);
  45. ftk_button_set_clicked_listener(button, button_close_clicked, win);
  46. ftk_snprintf(filename, FTK_MAX_PATH, "%s/jpeg1.jpg",
  47. ftk_config_get_test_data_dir(ftk_default_config()));
  48. gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
  49. ftk_widget_set_gc(win, FTK_WIDGET_NORMAL, &gc);
  50. ftk_gc_reset(&gc);
  51. switch(type)
  52. {
  53. case FTK_ANI_ZOOM_IN:
  54. {
  55. ftk_animator_set_param(ani, type, 10, 100, delta, 200);
  56. break;
  57. }
  58. case FTK_ANI_ZOOM_OUT:
  59. {
  60. ftk_animator_set_param(ani, type, 10, 100, delta, 200);
  61. break;
  62. }
  63. default:break;
  64. }
  65. ftk_animator_start(ani, win, 0);
  66. return;
  67. }
  68. static void create_app_window(void)
  69. {
  70. char title[32] = {0};
  71. int width = 0;
  72. int height = 0;
  73. FtkWidget* win = ftk_app_window_create();
  74. FtkWidget* button = NULL;
  75. width = ftk_widget_width(win);
  76. height = ftk_widget_height(win);
  77. button = ftk_button_create(win, 5, height/6 + 60, width/2-5, 50);
  78. ftk_widget_set_text(button, "ZoomIn");
  79. ftk_button_set_clicked_listener(button, button_to_zoom_in_clicked, win);
  80. button = ftk_button_create(win, width/2, height/6 + 60, width/2-5, 50);
  81. ftk_widget_set_text(button, "ZoomOut");
  82. ftk_button_set_clicked_listener(button, button_to_zoom_out_clicked, win);
  83. button = ftk_button_create(win, width/4-2, height/6 + 180, width/2-5, 50);
  84. ftk_widget_set_text(button, "Quit");
  85. ftk_button_set_clicked_listener(button, button_quit_clicked, win);
  86. ftk_snprintf(title, sizeof(title), "Zoom Demo");
  87. ftk_widget_set_text(win, title);
  88. FTK_QUIT_WHEN_WIDGET_CLOSE(win);
  89. ftk_widget_show_all(win, 1);
  90. return;
  91. }
  92. #ifdef FTK_AS_PLUGIN
  93. #include "ftk_app_demo.h"
  94. FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
  95. FtkApp* ftk_app_demo_zoom_create()
  96. {
  97. return ftk_app_demo_create(_("zoom"), ftk_main);
  98. }
  99. #else
  100. #define FTK_HIDE extern
  101. #endif /*FTK_AS_PLUGIN*/
  102. FTK_HIDE int FTK_MAIN(int argc, char* argv[])
  103. {
  104. FTK_INIT(argc, argv);
  105. create_app_window();
  106. FTK_RUN();
  107. return 0;
  108. }