/src/demos/demo_fullscreen.c

http://ftk.googlecode.com/ · C · 103 lines · 86 code · 17 blank · 0 comment · 3 complexity · c6779d31e84fefcadd314078c5c30a38 MD5 · raw file

  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. ftk_logd("%s: width=%d height=%d\n", __func__, ftk_widget_width(ctx), ftk_widget_height(ctx));
  33. return RET_OK;
  34. }
  35. static Ret button_fullscreen_clicked(void* ctx, void* obj)
  36. {
  37. if(ftk_window_is_fullscreen(ctx))
  38. {
  39. ftk_infomation("Infomation", "Windows is fullscreen.", buttons);
  40. }
  41. else
  42. {
  43. ftk_window_set_fullscreen(ctx, 1);
  44. }
  45. ftk_logd("%s: width=%d height=%d\n", __func__, ftk_widget_width(ctx), ftk_widget_height(ctx));
  46. return RET_OK;
  47. }
  48. #ifdef FTK_AS_PLUGIN
  49. #include "ftk_app_demo.h"
  50. FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
  51. FtkApp* ftk_app_demo_fullscreen_create()
  52. {
  53. return ftk_app_demo_create(_("fullscreen"), ftk_main);
  54. }
  55. #else
  56. #define FTK_HIDE extern
  57. #endif /*FTK_AS_PLUGIN*/
  58. FTK_HIDE int FTK_MAIN(int argc, char* argv[])
  59. {
  60. int width = 0;
  61. int height = 0;
  62. FtkWidget* win = NULL;
  63. FtkWidget* button = NULL;
  64. FTK_INIT(argc, argv);
  65. win = ftk_app_window_create();
  66. ftk_window_set_animation_hint(win, "app_main_window");
  67. width = ftk_widget_width(win);
  68. height = ftk_widget_height(win);
  69. width = width/2 - 10;
  70. button = ftk_button_create(win, 0, height/4, width, 50);
  71. ftk_widget_set_text(button, "Fullscreen");
  72. ftk_button_set_clicked_listener(button, button_fullscreen_clicked, win);
  73. button = ftk_button_create(win, width + 10, height/4, width, 50);
  74. ftk_widget_set_text(button, "Unfullscreen");
  75. ftk_button_set_clicked_listener(button, button_unfullscreen_clicked, win);
  76. button = ftk_button_create(win, width/2, height/2, width, 60);
  77. ftk_widget_set_text(button, "quit");
  78. ftk_button_set_clicked_listener(button, button_quit_clicked, win);
  79. ftk_window_set_focus(win, button);
  80. ftk_widget_set_text(win, "fullscreen");
  81. ftk_widget_show_all(win, 1);
  82. FTK_QUIT_WHEN_WIDGET_CLOSE(win);
  83. ftk_app_window_set_on_prepare_options_menu(win, on_prepare_options_menu, win);
  84. FTK_RUN();
  85. return 0;
  86. }