PageRenderTime 18ms CodeModel.GetById 10ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/demos/demo_image_button.c

http://ftk.googlecode.com/
C | 126 lines | 115 code | 11 blank | 0 comment | 8 complexity | dcbc4262aea008bac7ec3d4b166278a7 MD5 | raw file
  1#include "ftk.h"
  2
  3const char* pngs[] = 
  4{
  5	"/Camera.png",
  6	"/Notes.png",
  7	"/RSS.png",
  8	"/Calculator.png",
  9	"/Twitter.png",
 10	"/Clock.png",
 11	"/Games.png",
 12	"/Youtube.png",
 13	"/AIM.png",
 14	"/LastFm.png",
 15	"/IP.png",
 16	"/Acrobat.png",
 17	"/Settings.png",
 18	"/App",
 19	"/Customize.png",
 20	"/Skype.png",
 21	"/Linkedin.png",
 22	"/Calender.png",
 23	"/Call.png",
 24	"/Install.png",
 25	"/Facebook.png",
 26	"/iPod.png",
 27	"/Chat.png",
 28	"/WLM.png",
 29	"/Flickr.png",
 30	"/Photos.png",
 31	"/Stock.png",
 32	"/Delicious.png",
 33	"/Maps.png",
 34	"/iTunes.png",
 35	"/Memory.png",
 36	"/Weather.png",
 37	"/Wordpress.png",
 38	"/iradio.png",
 39	"/Safari.png",
 40	"/Google.png",
 41	"/Yahoo.png",
 42	"/VLC.png",
 43	"/Sms.png",
 44	"/Mail.png",
 45	NULL
 46};
 47
 48static Ret button_clicked(void* ctx, void* obj)
 49{
 50	ftk_widget_unref(ctx);
 51
 52	return RET_OK;
 53}
 54
 55#ifdef FTK_AS_PLUGIN
 56#include "ftk_app_demo.h"
 57FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
 58FtkApp* ftk_app_demo_image_button_create()
 59{
 60	return ftk_app_demo_create(_("image_button"), ftk_main);
 61}
 62#else
 63#define FTK_HIDE extern
 64#endif /*FTK_AS_PLUGIN*/
 65
 66FTK_HIDE int FTK_MAIN(int argc, char* argv[])
 67{
 68	int i = 0;
 69	int j = 0;
 70	int w = 80;
 71	int h = 80;
 72	int width = 0;
 73	int height = 0;
 74	char filename[FTK_MAX_PATH] = {0};
 75	FtkGc gc = {0};
 76	FtkWidget* win = NULL;
 77	FtkWidget* button = NULL;
 78	FTK_INIT(argc, argv);
 79
 80	gc.mask = FTK_GC_BITMAP;
 81	win = ftk_app_window_create();
 82	ftk_window_set_animation_hint(win, "app_main_window");
 83	width = ftk_widget_width(win);
 84	height = ftk_widget_height(win);
 85	for(i = 0; i < height/h; i++)
 86	{
 87		for(j = 0; j < width/w; j++)
 88		{
 89			ftk_snprintf(filename, sizeof(filename), "%s%s", 
 90				ftk_config_get_test_data_dir(ftk_default_config()), pngs[i + 2]);
 91			gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
 92			button = ftk_button_create(win, j * w, i * h, ftk_bitmap_width(gc.bitmap), ftk_bitmap_height(gc.bitmap));
 93			if(i == 0)
 94			{
 95				ftk_widget_unset_attr(button, FTK_ATTR_TRANSPARENT);
 96			}
 97			ftk_widget_set_gc(button, FTK_WIDGET_NORMAL, &gc);
 98			ftk_bitmap_unref(gc.bitmap);
 99
100			ftk_snprintf(filename, sizeof(filename), "%s%s", 
101				ftk_config_get_test_data_dir(ftk_default_config()), pngs[1]);
102			gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
103			ftk_widget_set_gc(button, FTK_WIDGET_FOCUSED, &gc);
104			ftk_bitmap_unref(gc.bitmap);
105
106			ftk_snprintf(filename, sizeof(filename), "%s%s", 
107				ftk_config_get_test_data_dir(ftk_default_config()), pngs[0]);
108			gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
109			ftk_widget_set_gc(button, FTK_WIDGET_ACTIVE, &gc);
110			ftk_bitmap_unref(gc.bitmap);
111
112			if(i == 0 && j == 0)
113			{
114				ftk_button_set_clicked_listener(button, button_clicked, win);
115				ftk_widget_set_text(button, "Quit");
116			}
117		}
118	}
119	ftk_widget_set_text(win, "image button demo");
120	ftk_widget_show_all(win, 1);
121	FTK_QUIT_WHEN_WIDGET_CLOSE(win);
122
123	FTK_RUN();
124
125	return 0;
126}