PageRenderTime 457ms CodeModel.GetById 232ms app.highlight 8ms RepoModel.GetById 154ms app.codeStats 1ms

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