示例#1
0
Ret ftk_progress_bar_set_interactive(FtkWidget* thiz, int interactive)
{
	DECL_PRIV0(thiz, priv);
	return_val_if_fail(thiz != NULL, RET_FAIL);

	priv->interactive = interactive;
	if(interactive)
	{
		if(priv->bg == NULL)
		{
			priv->bg = ftk_theme_load_image(ftk_default_theme(), 
				"progressbar_i_bg"FTK_STOCK_IMG_SUFFIX); 
		}

		if(priv->cursor == NULL)
		{
			priv->cursor = ftk_theme_load_image(ftk_default_theme(), 
				"progressbar_i_cursor"FTK_STOCK_IMG_SUFFIX); 
		}

		thiz->on_event = ftk_progress_bar_on_event_interactive;
		thiz->on_paint = ftk_progress_bar_on_paint_interactive;
	}
	else
	{
		thiz->on_event = ftk_progress_bar_on_event;
		thiz->on_paint = ftk_progress_bar_on_paint;
	}
	ftk_widget_set_insensitive(thiz, !interactive);

	return RET_OK;
}
示例#2
0
FtkWidget* ftk_scroll_bar_create(FtkWidget* parent, int x, int y, int width, int height)
{
	FtkWidget* thiz = (FtkWidget*)FTK_ZALLOC(sizeof(FtkWidget));
	return_val_if_fail(thiz != NULL, NULL);

	thiz->priv_subclass[0] = (PrivInfo*)FTK_ZALLOC(sizeof(PrivInfo));
	if(thiz != NULL)
	{
		DECL_PRIV0(thiz, priv);
		thiz->on_event = ftk_scroll_bar_on_event;
		thiz->on_paint = ftk_scroll_bar_on_paint;
		thiz->destroy  = ftk_scroll_bar_destroy;

		if(width < height)
		{
			/*vertical*/
			priv->vertical = 1;
			priv->bitmap = ftk_theme_load_image(ftk_default_theme(), 
				"scrollbar_handle_vertical"FTK_STOCK_IMG_SUFFIX);
		}
		else
		{
			priv->vertical = 0;
			priv->bitmap = ftk_theme_load_image(ftk_default_theme(), 
				"scrollbar_handle_horizontal"FTK_STOCK_IMG_SUFFIX);
		}

		ftk_widget_init(thiz, width < height ? FTK_SCROLL_VBAR : FTK_SCROLL_HBAR, 0, 
			x, y, width, height, FTK_ATTR_TRANSPARENT);
		ftk_widget_append_child(parent, thiz);
	}

	return thiz;
}
示例#3
0
文件: ftk.c 项目: bbw2008good/ftk
static void ftk_init_panel(void)
{
	FtkGc gc;
	FtkWidget* item = NULL;	
	FtkWidget* panel = ftk_status_panel_create(FTK_STATUS_PANEL_HEIGHT);
	size_t width = ftk_widget_width(panel);

	ftk_set_status_panel(panel);
	quit_if_fail(ftk_default_status_panel(), "Init status panel failed.\n");

	memset(&gc, 0x00, sizeof(gc));
	gc.mask   = FTK_GC_BITMAP;
	gc.bitmap = ftk_theme_load_image(ftk_default_theme(), "status-bg"FTK_STOCK_IMG_SUFFIX);
	ftk_widget_set_gc(panel, FTK_WIDGET_NORMAL, &gc);
	ftk_widget_set_gc(panel, FTK_WIDGET_ACTIVE, &gc);
	ftk_widget_set_gc(panel, FTK_WIDGET_FOCUSED, &gc);
	ftk_gc_reset(&gc);
	
	item = ftk_status_item_create(panel, -100, 32);
	ftk_widget_set_id(item, IDC_CLOSE_ITEM);
	gc.bitmap = ftk_theme_load_image(ftk_default_theme(), "close-32"FTK_STOCK_IMG_SUFFIX);
	if(gc.bitmap != NULL)
	{
		gc.mask = FTK_GC_BITMAP;
		ftk_widget_set_gc(item, FTK_WIDGET_NORMAL, &gc);
		ftk_widget_set_gc(item, FTK_WIDGET_FOCUSED, &gc);
		ftk_gc_reset(&gc);
		gc.mask = FTK_GC_BITMAP;
		gc.bitmap = ftk_theme_load_image(ftk_default_theme(), "close-pressed-32"FTK_STOCK_IMG_SUFFIX);
		ftk_widget_set_gc(item, FTK_WIDGET_ACTIVE, &gc);
		ftk_gc_reset(&gc);
	}
	ftk_status_item_set_clicked_listener(item, button_close_top_clicked, NULL);

	gc.bitmap = ftk_theme_load_image(ftk_default_theme(), "flag-32"FTK_STOCK_IMG_SUFFIX);
	item = ftk_status_item_create(panel, 1, gc.bitmap ? min(ftk_bitmap_width(gc.bitmap), 100) : 32);
	ftk_widget_set_id(item, IDC_ICON_ITEM);
	if(gc.bitmap != NULL)
	{
		gc.mask = FTK_GC_BITMAP;
		ftk_widget_set_gc(item, FTK_WIDGET_NORMAL, &gc);
		ftk_widget_set_gc(item, FTK_WIDGET_ACTIVE, &gc);
		ftk_widget_set_gc(item, FTK_WIDGET_FOCUSED, &gc);
		ftk_gc_reset(&gc);
	}
	ftk_widget_show(item, 1);

	item = ftk_status_item_create(panel, 2, width/2);
	ftk_widget_set_id(item, IDC_TITLE_ITEM);
	ftk_widget_show(item, 1);

	ftk_wnd_manager_add_global_listener(ftk_default_wnd_manager(), on_wnd_manager_global_event, NULL);
	ftk_widget_show(panel, 1);
	
	return;
}
示例#4
0
static Ret ftk_key_board_desc_load(FtkKeyBoardDesc* desc, const char* xml, size_t length)
{
	FtkXmlParser* parser = NULL;
	FtkXmlBuilder* builder = NULL;
	return_val_if_fail(desc != NULL && xml != NULL, RET_FAIL);

	parser  = ftk_xml_parser_create();
	return_val_if_fail(parser != NULL, RET_FAIL);

	builder = ftk_key_board_desc_builder_create();
	if(builder != NULL)
	{
		BuilderInfo* priv = (BuilderInfo*)builder->priv;
		priv->desc = desc;
		ftk_xml_parser_set_builder(parser, builder);
		ftk_xml_parser_parse(parser, xml, length);
	}
	ftk_xml_builder_destroy(builder);
	ftk_xml_parser_destroy(parser);

	desc->candidates_vertical_line = ftk_theme_load_image(ftk_default_theme(), 
		"key_board_candidates_vertical_line"FTK_STOCK_IMG_SUFFIX);
	desc->candidate_space = ftk_bitmap_width(desc->candidates_vertical_line) + 2;

	return RET_OK;
}
示例#5
0
FtkWidget* ftk_wait_box_create(FtkWidget* parent, int x, int y, int w, int h)
{
	FtkWidget* thiz = (FtkWidget*)FTK_ZALLOC(sizeof(FtkWidget));
	return_val_if_fail(thiz != NULL, NULL);

	thiz->priv_subclass[0] = (PrivInfo*)FTK_ZALLOC(sizeof(PrivInfo));
	if(thiz->priv_subclass[0] != NULL)
	{
		int w = 0;
		DECL_PRIV0(thiz, priv);

		thiz->on_event = ftk_wait_box_on_event;
		thiz->on_paint = ftk_wait_box_on_paint;
		thiz->destroy  = ftk_wait_box_destroy;

		priv->bitmap = ftk_theme_load_image(ftk_default_theme(), "wait_box"FTK_STOCK_IMG_SUFFIX);
		assert(priv->bitmap != NULL);
		
		w = ftk_bitmap_width(priv->bitmap);
		ftk_widget_init(thiz, FTK_WAIT_BOX, 0, x, y, w, w, FTK_ATTR_TRANSPARENT|FTK_ATTR_INSENSITIVE);
		ftk_widget_set_attr(thiz, FTK_ATTR_TRANSPARENT|FTK_ATTR_INSENSITIVE);

		priv->timer = ftk_source_timer_create(500, (FtkTimer)ftk_widget_invalidate, thiz);
		ftk_widget_append_child(parent, thiz);
	}
	else
	{
		FTK_FREE(thiz);
	}

	return thiz;
}
示例#6
0
文件: ftk.c 项目: suzp1984/parrot
static Ret ftk_enable_curosr(void)
{
	FtkSprite* sprite = ftk_sprite_create();
	FtkBitmap* icon = ftk_theme_load_image(ftk_default_theme(), "cursor"FTK_STOCK_IMG_SUFFIX);
	ftk_sprite_set_icon(sprite, icon);
	ftk_sprite_show(sprite, 1);
	ftk_wnd_manager_add_global_listener(ftk_default_wnd_manager(), ftk_move_cursor, sprite);

	return RET_OK;
}
示例#7
0
static Ret button_dialog_clicked(void* ctx, void* obj)
{
	int id = 0;
	int width = 0;
	int height = 0;
//	FtkWidget* label = NULL;
	FtkWidget* button = NULL;
	FtkWidget* dialog = NULL;
	FtkBitmap* icon = NULL;
	FtkWidget* combo_box = NULL;
	int modal = (int)ctx;
	
	ftk_logi("%s:%d begin\n", __func__, __LINE__);
	dialog = ftk_dialog_create(0, 40, 320, 240);
	
	icon = ftk_theme_load_image(ftk_default_theme(), "info"FTK_STOCK_IMG_SUFFIX);
	ftk_dialog_set_icon(dialog, icon);

	width = ftk_widget_width(dialog);
	height = ftk_widget_height(dialog);
//	label = ftk_label_create(dialog, width/6, height/4, 5*width/6, 20);
//	ftk_widget_set_text(label, "Are you sure to quit?");
	
	combo_box = ftk_combo_box_create(dialog, width/6, height/4, 2*width/3, 30);
	ftk_combo_box_set_text(combo_box, "1 second");
	ftk_combo_box_append(combo_box, NULL, "1 second");
	ftk_combo_box_append(combo_box, NULL, "2 seconds");
	ftk_combo_box_append(combo_box, NULL, "3 seconds");
	ftk_entry_set_readonly(ftk_combo_box_get_entry(combo_box), modal);

	button = ftk_button_create(dialog, width/6, height/2, width/3, 50);
	ftk_widget_set_text(button, "yes");
	ftk_button_set_clicked_listener(button, button_quit_clicked, modal ? &id : NULL);
	
	button = ftk_button_create(dialog, width/2, height/2, width/3, 50);
	ftk_widget_set_text(button, "no");
	ftk_button_set_clicked_listener(button, button_quit_clicked, modal ? &id : NULL);
	ftk_window_set_focus(dialog, button);

	ftk_widget_set_text(dialog, modal ? "model dialog" : "normal dialog");

	if(modal)
	{
		assert(ftk_dialog_run(dialog) == id);
		ftk_widget_unref(dialog);
	}
	else
	{
		ftk_widget_show_all(dialog, 1);
	}
	ftk_logi("%s:%d end\n", __func__, __LINE__);

	return RET_OK;
}
示例#8
0
static Ret ftk_check_button_on_paint(FtkWidget* thiz)
{
	int dx = 0;
	int dy = 0;
	int icon_w = 0;
	int icon_h = 0;

	FtkBitmap* bitmap = NULL;
	DECL_PRIV0(thiz, priv);
	const char** bg_imgs = NULL;
	FTK_BEGIN_PAINT(x, y, width, height, canvas);

	if (priv->onimg && priv->offimg) { 
		if (priv->checked)
			bitmap = priv->onimg;
		else
			bitmap = priv->offimg;
	}
	else { // orignal code
		if(priv->is_radio)
		{
			bg_imgs = priv->checked ? radio_bg_on_imgs : radio_bg_off_imgs;
		}
		else
		{
			bg_imgs = priv->checked ? check_bg_on_imgs : check_bg_off_imgs;
		}

		bitmap = ftk_theme_load_image(ftk_default_theme(), bg_imgs[ftk_widget_state(thiz)]);
	} 
	return_val_if_fail(bitmap != NULL, RET_FAIL);

	icon_w = ftk_bitmap_width(bitmap);
	icon_h = ftk_bitmap_height(bitmap);
	assert((icon_w) <= width && icon_h <= height);

	dy = (height - icon_h) / 2;
	dx = priv->icon_at_right ? width - icon_w : 0;
	ftk_canvas_draw_bitmap_simple(canvas, bitmap, 0, 0, icon_w, icon_h, x + dx, y + dy);
	if (NULL == priv->onimg) 
	ftk_bitmap_unref(bitmap);

	if(ftk_widget_get_text(thiz) != NULL)
	{
		dy = height/2;
		dx = priv->icon_at_right ? 2 : icon_w;
		
		ftk_canvas_set_gc(canvas, ftk_widget_get_gc(thiz)); 
		ftk_canvas_draw_string(canvas, x + dx, y + dy, ftk_widget_get_text(thiz), -1, 1);
	}

	FTK_END_PAINT();
}
示例#9
0
static Ret designer_on_popup_menu(void* ctx, void* obj)
{
	size_t i = 0;
	int nr = 0;
	int height = 0;
	FtkBitmap* icon = NULL; 
	FtkWidget* popup = NULL;
	FtkListItemInfo infos;
	FtkWidget* win = (FtkWidget*)ctx;

	memset(&infos, 0x00, sizeof(infos));
	icon = ftk_theme_load_image(ftk_default_theme(), "info"FTK_STOCK_IMG_SUFFIX); 

	for(i = 0; i < FTK_ARRAY_SIZE(s_popup_menu_items); i++)
	{
		if(s_popup_menu_items[i].need_selected_widget && !designer_has_selected_widget(win))
		{
			continue;
		}
		nr++;
	}

	height = (nr + 1) * FTK_POPUP_MENU_ITEM_HEIGHT;
	height = height < ftk_widget_height(win) ? height : ftk_widget_height(win);

	popup = ftk_popup_menu_create(0, 0, 0, height, icon, _("Edit"));	

	infos.state = 0;
	infos.type = FTK_LIST_ITEM_NORMAL;
	for(i = 0; i < FTK_ARRAY_SIZE(s_popup_menu_items); i++)
	{
		if(s_popup_menu_items[i].need_selected_widget && !designer_has_selected_widget(win))
		{
			continue;
		}

		infos.value = i;
		infos.text = s_popup_menu_items[i].name;
		infos.extra_user_data = s_popup_menu_items[i].on_clicked;
		
		ftk_popup_menu_add(popup, &infos);
	}
	ftk_bitmap_unref(icon);
	
	ftk_popup_menu_set_clicked_listener(popup, designer_on_popup_menu_item_clicked, ctx);
	ftk_widget_show_all(popup, 1);

	return RET_OK;
}
示例#10
0
static FtkBitmap* ftk_file_browser_load_mime_icon(const char* file_name)
{
	char* p = NULL;
	char icon_name[FTK_MAX_PATH+1] = {0};
	char mime_type[FTK_MIME_TYPE_LEN + 1] = {0};
	
	ftk_strcpy(mime_type, ftk_file_get_mime_type(file_name));

	p = strrchr(mime_type, '/');
	return_val_if_fail(p != NULL, NULL);

	*p = '\0';
	ftk_strs_cat(icon_name, FTK_MAX_PATH, "mime_", mime_type, FTK_STOCK_IMG_SUFFIX, NULL);

	return ftk_theme_load_image(ftk_default_theme(), icon_name);
}
示例#11
0
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
	int width = 0;
	int height = 0;
	FtkWidget* win = NULL;
	FtkWidget* button = NULL;
	FtkWidget* icon_view = NULL;
	FtkIconViewItem item;
	FTK_INIT(argc, argv);
	
	win = ftk_app_window_create();
	ftk_window_set_animation_hint(win, "app_main_window");
	width = ftk_widget_width(win);
	height = ftk_widget_height(win);

	button = ftk_button_create(win, 10, 0, width/3-10, 60);
	ftk_widget_set_text(button, "more");
	ftk_button_set_clicked_listener(button, button_more_clicked, win);
	ftk_window_set_focus(win, button);
	
	button = ftk_button_create(win, 2*width/3, 0, width/3-10, 60);
	ftk_widget_set_text(button, "quit");
	ftk_button_set_clicked_listener(button, button_quit_clicked, win);
	ftk_window_set_focus(win, button);

	item.icon = ftk_theme_load_image(ftk_default_theme(), "flag-32.png");
	icon_view = ftk_icon_view_create(win, 5, 70, width-10, height-80);
	ftk_widget_set_id(icon_view, 100);
	ftk_icon_view_set_clicked_listener(icon_view, item_clicked, win);
	for(; i < 4; i++)
	{
		char text[100] = {0};
		ftk_snprintf(text, sizeof(text), "%d", i);
		item.text = text;
		item.user_data = (void*)i;
		ftk_icon_view_add(icon_view, &item);
	}
	
	ftk_bitmap_unref(item.icon);
	ftk_widget_set_text(win, "icon view demo");
	ftk_widget_show_all(win, 1);
	FTK_QUIT_WHEN_WIDGET_CLOSE(win);

	FTK_RUN();

	return 0;
}
示例#12
0
文件: ftk_app_demo.c 项目: caicha/ftk
FtkApp* ftk_app_demo_create(const char* name, FtkMain ftk_main)
{
    FtkApp* thiz = FTK_ZALLOC(sizeof(FtkApp) + sizeof(PrivInfo));

    if(thiz != NULL)
    {
        DECL_PRIV(thiz, priv);

        priv->ftk_main = ftk_main;
        priv->name = ftk_strdup(name);
        priv->icon = ftk_theme_load_image(ftk_default_theme(), "flag-32"FTK_STOCK_IMG_SUFFIX);
        thiz->get_icon = ftk_app_demo_get_icon;
        thiz->get_name = ftk_app_demo_get_name;
        thiz->run = ftk_app_demo_run;
        thiz->destroy = ftk_app_demo_destroy;
    }

    return thiz;
}
示例#13
0
static Ret button_more_clicked(void* ctx, void* obj)
{
	int j = 0;
	FtkIconViewItem item;
	FtkWidget* icon_view = ftk_widget_lookup(ctx, 100);
	item.icon = ftk_theme_load_image(ftk_default_theme(), "flag-32.png");
	
	for(j=0; j < 4; j++)
	{
		char text[100] = {0};
		ftk_snprintf(text, sizeof(text), "%d", i);
		item.text = text;
		ftk_bitmap_ref(item.icon);
		item.user_data = (void*)i;
		ftk_icon_view_add(icon_view, &item);
		i+=1000;
	}
	ftk_bitmap_unref(item.icon);

	return RET_OK;
}
示例#14
0
FtkListRender* ftk_list_render_default_create(void)
{
	FtkListRender* thiz = FTK_NEW_PRIV(FtkListRender);
	
	if(thiz != NULL)
	{
		DECL_PRIV(thiz, priv);
		thiz->init    = ftk_list_render_default_init;
		thiz->paint   = ftk_list_render_default_paint;
		thiz->destroy = ftk_list_render_default_destroy;

		priv->focus_item = -1;
		priv->radio_off = ftk_theme_load_image(ftk_default_theme(), "btn_radio_off"FTK_STOCK_IMG_SUFFIX);
		priv->radio_on = ftk_theme_load_image(ftk_default_theme(),  "btn_radio_on"FTK_STOCK_IMG_SUFFIX);
		priv->check_off = ftk_theme_load_image(ftk_default_theme(), "btn_check_off"FTK_STOCK_IMG_SUFFIX);
		priv->check_on = ftk_theme_load_image(ftk_default_theme(),  "btn_check_on"FTK_STOCK_IMG_SUFFIX);
		priv->more = ftk_theme_load_image(ftk_default_theme(),      "more"FTK_STOCK_IMG_SUFFIX);
		priv->bg_disable = ftk_theme_load_image(ftk_default_theme(),  "list_selector_background_disabled"FTK_STOCK_IMG_SUFFIX);
	}

	return thiz;
}
示例#15
0
static void show_canvas(FtkDisplay* display, FtkCanvas* canvas)
{
	FtkBitmap* bitmap = NULL;
	FtkRect rect = {.x = 0, .y=0, .width=0, .height=0};
	rect.width = ftk_display_width(display);
	rect.height = ftk_display_height(display);

	ftk_canvas_lock_buffer(canvas, &bitmap);
	ftk_display_update(display, bitmap, &rect, 0, 0);
	ftk_canvas_unlock_buffer(canvas);

	return;
}
#if 1
void test_misc(FtkDisplay* display, FtkFont* font)
{
	if(display != NULL)
	{
		int i = 0;
		FtkGc gc = {0};
		int extent = 0;
		FtkColor color = {0x0, 0, 0, 0x0};
		FtkRect rect = {.x = 0, .y=0, .width=0, .height=0};
		rect.width = ftk_display_width(display);
		rect.height = ftk_display_height(display);
		gc.mask = FTK_GC_FG | FTK_GC_FONT;
		gc.fg.a = 0xff;
		gc.fg.r = 0x00;
		gc.fg.g = 0x00;
		gc.fg.b = 0xff;
		gc.font = font;

		FtkCanvas* thiz = ftk_canvas_create(rect.width, rect.height, &color);
		show_canvas(display, thiz);
		for(i = 0; i < ftk_display_height(display); i++)
		{
			if(gc.fg.r < 0xff)
			{
				gc.fg.r++;
			}
			else
			{
				gc.fg.g++;
			}
			ftk_canvas_set_gc(thiz, &gc);
			ftk_canvas_draw_hline(thiz, 0, i, 320);
		}
		FtkBitmap* bitmap = ftk_bitmap_create(100, 100, color);
		ftk_canvas_draw_bitmap_simple(thiz, bitmap, 0, 0, 100, 100, 100, 100);
		ftk_canvas_draw_string(thiz, 0, 240, " Jim is a Programmer.", -1, 0);
		gc.fg.b = 0xff;
		ftk_canvas_set_gc(thiz, &gc);
		ftk_canvas_draw_string(thiz, 0, 220, "李先静是一个程序员", -1, 0);
	
		unsigned int line_mask = 0xaaaaaaaa;
		gc.line_mask = line_mask;
		gc.mask = FTK_GC_LINE_MASK;
		ftk_canvas_set_gc(thiz, &gc);
		show_canvas(display, thiz);

		assert(ftk_canvas_font_height(thiz) == 16);
		extent = ftk_canvas_get_extent(thiz, "李先静", -1);
		printf("extent=%d\n", ftk_canvas_get_extent(thiz, "李先静", -1));


		ftk_bitmap_unref(bitmap);
		ftk_canvas_destroy(thiz);
	}

	sleep(3);

	return;
}
#if 0
void test_draw_point(FtkDisplay* display)
{
	int i = 0;
	FtkGc gc = {.mask = FTK_GC_FG};
	FtkRect rect = {0};
	FtkColor color = {.a = 0xff};
	int width = ftk_display_width(display);
	int height = ftk_display_height(display);
	FtkCanvas* thiz = ftk_canvas_create(width, height, color);

	rect.width = width;
	rect.height = height;

	color.r = 0xff;
	color.a = 0xff;
	gc.fg = color;
	for(i = 0; i < width; i++)
	{
		ftk_canvas_reset_gc(thiz, &gc);
		ftk_canvas_draw_point(thiz, i, 10);
	}
	
	color.g = 0xff;
	color.r = 0;
	for(i = 0; i < width; i++)
	{
		color.a = 0xff - (0xff & i);
		gc.fg = color;
		ftk_canvas_reset_gc(thiz, &gc);
		ftk_canvas_draw_point(thiz, i, 20);
	}
	
	color.r = 0;
	color.g = 0;
	color.b = 0xff;
	color.a = 0xff;
	gc.fg = color;
	gc.mask |= FTK_GC_ALPHA;
	for(i = 0; i < width; i++)
	{
		gc.alpha = 0xff - (0xff & i);
		ftk_canvas_reset_gc(thiz, &gc);
		ftk_canvas_draw_point(thiz, i, 30);
	}

	show_canvas(display, thiz);
	
	ftk_canvas_destroy(thiz);

	sleep(3);

	return;
}
#endif
void test_draw_vline(FtkDisplay* display)
{
	int i = 0;
	FtkGc gc = {.mask = FTK_GC_FG};
	FtkRect rect = {0};
	FtkColor color = {.a = 0xff};
	int width = ftk_display_width(display);
	int height = ftk_display_height(display);
	FtkCanvas* thiz = ftk_canvas_create(width, height, &color);

	rect.width = width;
	rect.height = height;

	color.r = 0xff;
	color.a = 0xff;
	gc.fg = color;
	for(i = 0; i < width; i++)
	{
		ftk_canvas_reset_gc(thiz, &gc);
		ftk_canvas_draw_vline(thiz, i, 0, 20);
	}
	
	color.g = 0xff;
	color.r = 0;
	for(i = 0; i < width; i++)
	{
		color.a = 0xff - (0xff & i);
		gc.fg = color;
		ftk_canvas_reset_gc(thiz, &gc);
		ftk_canvas_draw_vline(thiz, i, 30, 20);
	}
	
	color.r = 0;
	color.g = 0;
	color.b = 0xff;
	color.a = 0xff;
	gc.fg = color;
	gc.mask |= FTK_GC_ALPHA;
	for(i = 0; i < width; i++)
	{
		gc.alpha = 0xff - (0xff & i);
		ftk_canvas_reset_gc(thiz, &gc);
		ftk_canvas_draw_vline(thiz, i, 60, 20);
	}

	show_canvas(display, thiz);
	
	ftk_canvas_destroy(thiz);
	sleep(3);

	return;
}

void test_draw_hline(FtkDisplay* display)
{
	int i = 0;
	FtkGc gc = {.mask = FTK_GC_FG};
	FtkRect rect = {0};
	FtkColor color = {.a = 0xff};
	int width = ftk_display_width(display);
	int height = ftk_display_height(display);
	FtkCanvas* thiz = ftk_canvas_create(width, height, &color);

	rect.width = width;
	rect.height = height;

	color.r = 0xff;
	color.a = 0xff;
	gc.fg = color;
	for(i = 0; i < height; i++)
	{
		ftk_canvas_reset_gc(thiz, &gc);
		ftk_canvas_draw_hline(thiz, 0, i, 20);
	}
	
	color.g = 0xff;
	color.r = 0;
	for(i = 0; i < height; i++)
	{
		color.a = 0xff - (0xff & i);
		gc.fg = color;
		ftk_canvas_reset_gc(thiz, &gc);
		ftk_canvas_draw_hline(thiz, 30, i, 20);
	}
	
	color.r = 0;
	color.g = 0;
	color.b = 0xff;
	color.a = 0xff;
	gc.fg = color;
	gc.mask |= FTK_GC_ALPHA;
	for(i = 0; i < height; i++)
	{
		gc.alpha = 0xff - (0xff & i);
		ftk_canvas_reset_gc(thiz, &gc);
		ftk_canvas_draw_hline(thiz, 60, i, 20);
	}

	show_canvas(display, thiz);
	
	ftk_canvas_destroy(thiz);

	sleep(3);

	return;
}

#if 0
void test_draw_line(FtkDisplay* display)
{
	int i = 0;
	FtkGc gc = {.mask = FTK_GC_FG};
	FtkRect rect = {0};
	FtkColor color = {.a = 0xff};
	int width = ftk_display_width(display);
	int height = ftk_display_height(display);
	FtkCanvas* thiz = ftk_canvas_create(width, height, color);

	rect.width = width;
	rect.height = height;

	color.r = 0xff;
	color.a = 0xff;
	gc.fg = color;
	for(i = 0; i < height/2; i++)
	{
		ftk_canvas_reset_gc(thiz, &gc);
		ftk_canvas_draw_line(thiz, 0, i, 20, i+10);
	}
	
	color.g = 0xff;
	color.r = 0;
	for(i = 0; i < height/2; i++)
	{
		color.a = 0xff - (0xff & i);
		gc.fg = color;
		ftk_canvas_reset_gc(thiz, &gc);
		ftk_canvas_draw_line(thiz, 30, i, 50, i+10);
	}
	
	color.r = 0;
	color.g = 0;
	color.b = 0xff;
	color.a = 0xff;
	gc.fg = color;
	gc.mask |= FTK_GC_ALPHA;
	for(i = 0; i < height/2; i++)
	{
		gc.alpha = 0xff - (0xff & i);
		ftk_canvas_reset_gc(thiz, &gc);
		ftk_canvas_draw_line(thiz, 60, i, 80, i+10);
	}

	ftk_display_update(display, ftk_canvas_bitmap(thiz), &rect, 0, 0);
	
	ftk_canvas_destroy(thiz);

	sleep(3);

	return;
}
#endif
void test_alpha(FtkDisplay* display)
{
	int i = 0;
	FtkGc gc = {.mask = FTK_GC_FG};
	FtkRect rect = {0};
	FtkColor color = {.a = 0xff};
	int width = ftk_display_width(display);
	int height = ftk_display_height(display);
	FtkCanvas* thiz = ftk_canvas_create(width, height, &color);

	rect.width = width;
	rect.height = height;

	color.g = 0xff;
	color.r = 0;
	for(i = 0; i < 0xff; i += 4)
	{
		color.a = 0xff;
		color.g = 0;
		gc.fg = color;
		ftk_canvas_reset_gc(thiz, &gc);
		ftk_canvas_draw_rect(thiz, 0, 0, width, height, 0, 1);
		
		color.a = 0xff - i;
		color.g = 0xff;
		gc.fg = color;
		ftk_canvas_reset_gc(thiz, &gc);
		ftk_canvas_draw_rect(thiz, 0, 0, width, height, 0, 1);
		show_canvas(display, thiz);
		usleep(200000);
	}
	
	ftk_canvas_destroy(thiz);

	sleep(3);

	return;
}

void test_put_get_pixel(FtkDisplay* display)
{
	int i = 0;
	int j = 0;
	FtkColor color = {.a=0xff, .r=0xef, .g=0xdf, .b=0xcf};
	int width = ftk_display_width(display);
	int height = ftk_display_height(display);
	FtkCanvas* thiz = ftk_canvas_create(width, height, &color);

	for(i = 0; i < height; i++)
	{
		for(j = 0; j < width; j++)
		{
			FtkColor c = {0};
			FtkColor* colorp = NULL;
			colorp = &c;
			assert(colorp->r == color.r);
			assert(colorp->g == color.g);
			assert(colorp->b == color.b);
			assert(colorp->a == color.a);
		}
	}

	ftk_canvas_destroy(thiz);

	return;
}

void test_font(FtkDisplay* display, FtkFont* font)
{
	int extent2 = 0;
	FtkGc gc = {.mask = FTK_GC_FONT};
	FtkColor color = {.a=0xff, .r=0xef, .g=0xdf, .b=0xcf};
	int width = ftk_display_width(display);
	int height = ftk_display_height(display);
	FtkCanvas* thiz = ftk_canvas_create(width, height, &color);
	const char* str = "隐式声明与内建函数";
	const char* other_side = NULL;
	
	gc.font = font;
	ftk_canvas_set_gc(thiz, &gc);
	
	other_side = ftk_canvas_calc_str_visible_range(thiz, str, 0, -1, 60);
	assert(strcmp(other_side, "明与内建函数") == 0);

	other_side = ftk_canvas_calc_str_visible_range(thiz, str, other_side-str, -1, 60);
	assert(strcmp(other_side, "建函数") == 0);
	
	other_side = ftk_canvas_calc_str_visible_range(thiz, str, other_side-str, -1, 60);
	assert(strcmp(other_side, "") == 0);

	other_side = ftk_canvas_calc_str_visible_range(thiz, str, -1, other_side-str, 60);
	assert(strcmp(other_side, "建函数") == 0);
	
	other_side = ftk_canvas_calc_str_visible_range(thiz, str, -1, other_side-str, 60);
	assert(strcmp(other_side, "明与内建函数") == 0);
	
	other_side = ftk_canvas_calc_str_visible_range(thiz, str, -1, other_side-str, 60);
	assert(strcmp(other_side, str) == 0);
	
	other_side = ftk_canvas_calc_str_visible_range(thiz, str, -1, other_side-str, 60);
	assert(strcmp(other_side, str) == 0);

	printf("other_side = %s\n", other_side);
	

	str = "Single line editor, that means you can input a one line only.";
	
	extent2 = ftk_canvas_get_extent(thiz, str, -1);

	ftk_canvas_destroy(thiz);
	sleep(3);

	return;
}

static void test_fill_bg(FtkDisplay* display)
{
	FtkRect rect = {0};
	FtkColor color = {.a=0xff, .r=0xef, .g=0xdf, .b=0xcf};
	int width = ftk_display_width(display);
	int height = ftk_display_height(display);
	FtkCanvas* thiz = ftk_canvas_create(width, height, &color);
	FtkBitmap* bitmap = ftk_theme_load_image(ftk_default_theme(), "btn_default_pressed.9.png");
	ftk_canvas_draw_bg_image(thiz, bitmap, FTK_BG_FOUR_CORNER, 10, 10, 100, 60);
	ftk_canvas_draw_bg_image(thiz, bitmap, FTK_BG_FOUR_CORNER, 120, 10, 40, 60);
	
	ftk_canvas_draw_bg_image(thiz, bitmap, FTK_BG_FOUR_CORNER, 10, 80, 20, 20);
	ftk_canvas_draw_bg_image(thiz, bitmap, FTK_BG_FOUR_CORNER, 30, 80, 40, 20);
	ftk_canvas_draw_bg_image(thiz, bitmap, FTK_BG_FOUR_CORNER, 80, 80, 60, 20);
	rect.width = width;
	rect.height = height;
	show_canvas(display, thiz);
	ftk_canvas_destroy(thiz);

	sleep(3);
	
	return;
}

static void test_draw_rect(FtkDisplay* display)
{
	int i = 0;
	FtkColor color = {.a = 0xff};
	FtkRect rect = {0};
	int width = ftk_display_width(display);
	int height = ftk_display_height(display);
	FtkGc gc = {.mask = FTK_GC_FG};
	FtkCanvas* thiz = ftk_canvas_create(width, height, &color);
	gc.fg.a = 0xff;

	gc.fg.r = 0xff;
	for(i = 0; i < width/8; i++)
	{
		gc.fg.r -= 0x10;
		ftk_canvas_set_gc(thiz, &gc);
		ftk_canvas_draw_rect(thiz, width * i/8, 0, width/8 - 1, height/8 - 1, 0, 1);
	}
	
	gc.fg.r = 0xff;
	for(i = 0; i < width/8; i++)
	{
		gc.fg.r -= 0x10;
		gc.fg.b += 0x10;
		ftk_canvas_set_gc(thiz, &gc);
		ftk_canvas_draw_rect(thiz, width * i/8, height/8, width/8 - 1, height/8 - 1, 0, 0);
	}
	
	gc.fg.r = 0xff;
	for(i = 0; i < width/8; i++)
	{
		gc.fg.r -= 0x10;
		ftk_canvas_set_gc(thiz, &gc);
		ftk_canvas_draw_rect(thiz, width * i/8, height/4, width/8 - 1, height/8 - 1, 1, 1);
	}
	
	gc.fg.r = 0xff;
	for(i = 0; i < width/8; i++)
	{
		gc.fg.r -= 0x10;
		gc.fg.b += 0x10;
		ftk_canvas_set_gc(thiz, &gc);
		ftk_canvas_draw_rect(thiz, width * i/8, 3*height/8, width/8 - 1, height/8 - 1, 1, 0);
	}
	rect.width = width;
	rect.height = height;
	show_canvas(display, thiz);
	ftk_canvas_destroy(thiz);

	sleep(3);

	return;
}

int main(int argc, char* argv[])
{
	ftk_init(argc, argv);

	FtkRect rect = {0};
	FtkColor bg = {.a = 0xff};
	FtkBitmap* bitmap = NULL;
	FtkFont* font = ftk_default_font();
	FtkDisplay* display = ftk_default_display();

	rect.width = ftk_display_width(display);
	rect.height = ftk_display_height(display);
#if 0
#else	
	test_draw_rect(display);
	test_alpha(display);
	test_draw_vline(display);
	bitmap = ftk_bitmap_create(ftk_display_width(display), ftk_display_height(display), bg);
	ftk_display_snap(display, &rect, bitmap);
	test_draw_hline(display);
	ftk_display_update(display, bitmap, &rect, 0, 0);
	test_fill_bg(display);
	test_font(display, font);
	test_put_get_pixel(display);
	test_draw_hline(display);
	test_draw_vline(display);
	ftk_bitmap_unref(bitmap);
#endif
	ftk_run();

	return 0;
}
#else
int main(int argc, char* argv[])
{
	return 0;
}
示例#16
0
static void ftk_key_board_desc_builder_on_start(FtkXmlBuilder* thiz, const char* tag, const char** attrs)
{
	size_t i = 0;
	const char* key = NULL;
	const char* value = NULL;
	BuilderInfo* info = (BuilderInfo*)thiz->priv;
	FtkKeyBoardDesc* desc = info->desc;

	if(strcmp(tag, "keyboard") == 0)
	{
		for(i = 0; attrs[i] != NULL; i += 2)
		{
			key = attrs[i];
			value = attrs[i+1];
			if(strcmp(key, "min_width") == 0)
			{
				desc->min_width = ftk_atoi(value);
			}
			else if(strcmp(key, "min_height") == 0)
			{
				desc->min_height = ftk_atoi(value);
			}
			else if(strcmp(key, "views") == 0)
			{
				desc->view_nr = ftk_atoi(value);
			}
			else
			{
				ftk_logw("%s:%d unknown attr: %s\n", __func__, __LINE__, key);
			}
		}
		assert(desc->view_nr > 0);
		desc->current_view = 0;
		desc->views = (FtkKeyBoardView*)FTK_ZALLOC(desc->view_nr * sizeof(FtkKeyBoardView));
	}
	else if(strcmp(tag, "view") == 0)
	{
		FtkKeyBoardView* view = desc->views + desc->current_view;

		for(i = 0; attrs[i] != NULL; i += 2)
		{
			key = attrs[i];
			value = attrs[i+1];
			if(strcmp(key, "rows") == 0)
			{
				view->row_nr = ftk_atoi(value);
			}
			else if(strcmp(key, "bg") == 0)
			{
				view->bg = ftk_theme_load_image(ftk_default_theme(), value);
			}
			else if(strcmp(key, "cell_bg_image[normal]") == 0)
			{
				view->cell_bg_normal = ftk_theme_load_image(ftk_default_theme(), value);
			}
			else if(strcmp(key, "cell_bg_image[active]") == 0)
			{
				view->cell_bg_active = ftk_theme_load_image(ftk_default_theme(), value);
			}
			else
			{
				ftk_logw("%s:%d unknown attr: %s\n", __func__, __LINE__, key);
			}
		}

		assert(view->row_nr > 0);
		view->current_row = 0;
		view->rows = (FtkKeyBoardRow*)FTK_ZALLOC(view->row_nr * sizeof(FtkKeyBoardRow));
	}
	else if(strcmp(tag, "row") == 0)
	{
		FtkKeyBoardView* view = desc->views + desc->current_view;
		FtkKeyBoardRow* row = view->rows + view->current_row;

		for(i = 0; attrs[i] != NULL; i += 2)
		{
			key = attrs[i];
			value = attrs[i+1];
			if(strcmp(key, "cols") == 0)
			{
				row->cell_nr = ftk_atoi(value);
			}
			else if(strcmp(key, "height_weight") == 0)
			{
				row->height_weight = ftk_atoi(value);
			}
			else
			{
				ftk_logw("%s:%d unknown attr: %s\n", __func__, __LINE__, key);
			}
		}
		assert(row->cell_nr > 0);
		row->cells = (FtkKeyBoardCell*)FTK_ZALLOC(sizeof(FtkKeyBoardCell) * row->cell_nr);
	}
	else if(strcmp(tag, "spacer") == 0)
	{
		FtkKeyBoardView* view = desc->views + desc->current_view;
		FtkKeyBoardRow* row = view->rows + view->current_row;
		FtkKeyBoardCell* cell = row->cells + row->current_cell;

		for(i = 0; attrs[i] != NULL; i += 2)
		{
			key = attrs[i];
			value = attrs[i+1];

			if(strcmp(key, "width_weight") == 0)
			{
				cell->width_weight = ftk_atoi(value);
			}
		}
	}
	else if(strcmp(tag, "cell") == 0)
	{
		FtkKeyBoardView* view = desc->views + desc->current_view;
		FtkKeyBoardRow* row = view->rows + view->current_row;
		FtkKeyBoardCell* cell = row->cells + row->current_cell;

		for(i = 0; attrs[i] != NULL; i += 2)
		{
			key = attrs[i];
			value = attrs[i+1];
			if(strcmp(key, "text") == 0)
			{
				ftk_strncpy(cell->text, value, sizeof(cell->text));
			}
			else if(strcmp(key, "action") == 0)
			{
				ftk_key_board_cell_init_action(cell, value);
			}
			else if(strcmp(key, "width_weight") == 0)
			{
				cell->width_weight = ftk_atoi(value);
			}
			else if(strcmp(key, "icon") == 0)
			{
				cell->icon = ftk_theme_load_image(ftk_default_theme(), value);
			}
			else if(strcmp(key, "bg_image[normal]") == 0)
			{
				cell->bg_normal = ftk_theme_load_image(ftk_default_theme(), value);
			}
			else if(strcmp(key, "bg_image[active]") == 0)
			{
				cell->bg_active = ftk_theme_load_image(ftk_default_theme(), value);
			}
			else
			{
				ftk_logw("%s:%d unknown attr: %s\n", __func__, __LINE__, key);
			}
		}

		if(cell->bg_normal == NULL)
		{
			cell->bg_normal = view->cell_bg_normal;
			ftk_bitmap_ref(cell->bg_normal);
		}

		if(cell->bg_active == NULL)
		{
			cell->bg_active = view->cell_bg_active;
			ftk_bitmap_ref(cell->bg_active);
		}
	}
	else
	{
		ftk_logw("%s:%d unknown tag: %s\n", __func__, __LINE__, tag);
	}

	return;
}
示例#17
0
int ftk_infomation(const char* title, const char* text, const char* buttons[FTK_MSGBOX_MAX_BUTTONS + 1])
{
	FtkBitmap* icon = ftk_theme_load_image(ftk_default_theme(), "info"FTK_STOCK_IMG_SUFFIX); 

	return ftk_message_box(icon, title, text, buttons);
}
示例#18
0
Ret		   ftk_file_browser_load(FtkWidget* thiz)
{
	FtkFileInfo info = {0};
	FtkFsHandle handle = NULL;
	FtkListItemInfo item = {0};
	const char* mime_type = NULL;
	char path[FTK_MAX_PATH+1] = {0};
	PrivInfo* priv = ftk_widget_user_data(thiz);
	return_val_if_fail(priv != NULL && priv->path != NULL, RET_FAIL);	

	handle = ftk_dir_open(priv->path);
	if(handle == NULL)
	{
		ftk_logd("%s: open %s\n", __func__, priv->path);
	}
	return_val_if_fail(handle != NULL, RET_FAIL);

	ftk_list_model_reset(priv->model);
	ftk_list_model_disable_notify(priv->model);

	if(!ftk_fs_is_root(priv->path))
	{
		item.value = 1;
		item.text = _("..");
		item.type = FTK_LIST_ITEM_NORMAL;
		item.left_icon = ftk_theme_load_image(ftk_default_theme(), "up"FTK_STOCK_IMG_SUFFIX);
		ftk_list_model_add(priv->model, &item);
	}

	/*directory go first.*/
	while(ftk_dir_read(handle, &info) == RET_OK)
	{
		if(info.name[0] == '.') continue;

		if(info.is_dir)
		{
			item.value = 1;
			item.text = info.name;
			item.type = ftk_file_browser_get_display_style(priv, 1);
			item.left_icon = ftk_theme_load_image(ftk_default_theme(), "folder"FTK_STOCK_IMG_SUFFIX);
			ftk_list_model_add(priv->model, &item);
		}
	}
	ftk_dir_close(handle);

	if(priv->filter_mime_type == NULL || strcmp(priv->filter_mime_type, FTK_MIME_DIR) != 0)
	{
		handle = ftk_dir_open(priv->path);
		while(ftk_dir_read(handle, &info) == RET_OK)
		{
			if(info.name[0] == '.') continue;
			if(info.is_dir) continue;

			if(priv->filter_mime_type != NULL)
			{
				ftk_strs_cat(path, FTK_MAX_PATH, priv->path, "/", info.name, NULL);
				mime_type = ftk_file_get_mime_type(path);
				if(strstr(priv->filter_mime_type, mime_type) != NULL)
				{
					continue;
				}
			}
				
			item.value = 0;
			item.type = ftk_file_browser_get_display_style(priv, 0);
			item.text = info.name;
			item.left_icon = ftk_file_browser_load_mime_icon(info.name);
			ftk_list_model_add(priv->model, &item);
		}
		ftk_dir_close(handle);
	}

	ftk_window_set_focus(thiz, priv->list_view);
	ftk_list_view_set_cursor(priv->list_view, 0);
	ftk_list_model_enable_notify(priv->model);
	ftk_list_model_notify(priv->model);
	ftk_widget_show_all(thiz, 1);

	return RET_OK;
}