demo_fullscreen.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "ftk.h"
  2. static Ret on_prepare_options_menu(void* ctx, FtkWidget* menu_panel)
  3. {
  4. int i = 0;
  5. for(i = 0; i < 3; i++)
  6. {
  7. char text[32] = {0};
  8. FtkWidget* item = ftk_menu_item_create(menu_panel);
  9. ftk_snprintf(text, sizeof(text), "Menu%02d", i);
  10. ftk_widget_set_text(item, text);
  11. ftk_widget_show(item, 1);
  12. }
  13. return i > 0 ? RET_OK : RET_FAIL;
  14. }
  15. #define IDC_TEST_BUTTON 1000
  16. static Ret button_quit_clicked(void* ctx, void* obj)
  17. {
  18. ftk_widget_unref(ctx);
  19. return RET_OK;
  20. }
  21. static const char* buttons[] = {"OK", NULL};
  22. static Ret button_unfullscreen_clicked(void* ctx, void* obj)
  23. {
  24. if(!ftk_window_is_fullscreen(ctx))
  25. {
  26. ftk_infomation("Infomation", "Windows is not fullscreen.", buttons);
  27. }
  28. else
  29. {
  30. ftk_window_set_fullscreen(ctx, 0);
  31. }
  32. return RET_OK;
  33. }
  34. static Ret button_fullscreen_clicked(void* ctx, void* obj)
  35. {
  36. if(ftk_window_is_fullscreen(ctx))
  37. {
  38. ftk_infomation("Infomation", "Windows is fullscreen.", buttons);
  39. }
  40. else
  41. {
  42. ftk_window_set_fullscreen(ctx, 1);
  43. }
  44. return RET_OK;
  45. }
  46. #ifdef FTK_AS_PLUGIN
  47. #include "ftk_app_demo.h"
  48. FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
  49. FtkApp* ftk_app_demo_fullscreen_create()
  50. {
  51. return ftk_app_demo_create(_("fullscreen"), ftk_main);
  52. }
  53. #else
  54. #define FTK_HIDE extern
  55. #endif /*FTK_AS_PLUGIN*/
  56. FTK_HIDE int FTK_MAIN(int argc, char* argv[])
  57. {
  58. int width = 0;
  59. int height = 0;
  60. FtkWidget* win = NULL;
  61. FtkWidget* button = NULL;
  62. FTK_INIT(argc, argv);
  63. win = ftk_app_window_create();
  64. ftk_window_set_animation_hint(win, "app_main_window");
  65. width = ftk_widget_width(win);
  66. height = ftk_widget_height(win);
  67. width = width/2 - 10;
  68. button = ftk_button_create(win, 0, height/4, width, 50);
  69. ftk_widget_set_text(button, "Fullscreen");
  70. ftk_button_set_clicked_listener(button, button_fullscreen_clicked, win);
  71. button = ftk_button_create(win, width + 10, height/4, width, 50);
  72. ftk_widget_set_text(button, "Unfullscreen");
  73. ftk_button_set_clicked_listener(button, button_unfullscreen_clicked, win);
  74. button = ftk_button_create(win, width/2, height/2, width, 60);
  75. ftk_widget_set_text(button, "quit");
  76. ftk_button_set_clicked_listener(button, button_quit_clicked, win);
  77. ftk_window_set_focus(win, button);
  78. ftk_widget_set_text(win, "fullscreen");
  79. ftk_widget_show_all(win, 1);
  80. FTK_QUIT_WHEN_WIDGET_CLOSE(win);
  81. ftk_app_window_set_on_prepare_options_menu(win, on_prepare_options_menu, win);
  82. FTK_RUN();
  83. return 0;
  84. }