Esempio n. 1
0
void ftk_widget_init(FtkWidget* thiz, int type, int id)
{
	return_if_fail(thiz != NULL);

	thiz->ref = 1;
	thiz->priv = (FtkWidgetInfo*)FTK_ZALLOC(sizeof(FtkWidgetInfo));

	if(thiz->priv != NULL)
	{
		FtkWidgetInfo* priv =  thiz->priv;

		priv->id     = id;
		priv->type   = type;
		priv->gc[FTK_WIDGET_NORMAL].mask = FTK_GC_BG | FTK_GC_FG | FTK_GC_FONT;
		priv->gc[FTK_WIDGET_NORMAL].fg.a = 0xff;
		priv->gc[FTK_WIDGET_NORMAL].fg.r = 0x00;
		priv->gc[FTK_WIDGET_NORMAL].fg.g = 0x00;
		priv->gc[FTK_WIDGET_NORMAL].fg.b = 0x00;
		priv->gc[FTK_WIDGET_NORMAL].font = ftk_default_font();
		priv->gc[FTK_WIDGET_NORMAL].bg.a = 0xff;
		priv->gc[FTK_WIDGET_NORMAL].bg.r = 0xe0;
		priv->gc[FTK_WIDGET_NORMAL].bg.g = 0xd0;
		priv->gc[FTK_WIDGET_NORMAL].bg.b = 0xe0;
		
		priv->gc[FTK_WIDGET_FOCUSED].mask = FTK_GC_BG | FTK_GC_FG | FTK_GC_FONT;
		priv->gc[FTK_WIDGET_FOCUSED].fg.a = 0xff;
		priv->gc[FTK_WIDGET_FOCUSED].fg.r = 0x00;
		priv->gc[FTK_WIDGET_FOCUSED].fg.g = 0x00;
		priv->gc[FTK_WIDGET_FOCUSED].fg.b = 0x00;
		priv->gc[FTK_WIDGET_FOCUSED].font = ftk_default_font();
		priv->gc[FTK_WIDGET_FOCUSED].bg.a = 0xff;
		priv->gc[FTK_WIDGET_FOCUSED].bg.r = 0xe0;
		priv->gc[FTK_WIDGET_FOCUSED].bg.g = 0xd0;
		priv->gc[FTK_WIDGET_FOCUSED].bg.b = 0xe0;
		
		priv->gc[FTK_WIDGET_INSENSITIVE].mask = FTK_GC_BG | FTK_GC_FG | FTK_GC_FONT;
		priv->gc[FTK_WIDGET_INSENSITIVE].fg.a = 0xff;
		priv->gc[FTK_WIDGET_INSENSITIVE].fg.r = 0x00;
		priv->gc[FTK_WIDGET_INSENSITIVE].fg.g = 0x00;
		priv->gc[FTK_WIDGET_INSENSITIVE].fg.b = 0x00;
		priv->gc[FTK_WIDGET_INSENSITIVE].font = ftk_default_font();
		priv->gc[FTK_WIDGET_INSENSITIVE].bg.a = 0xff;
		priv->gc[FTK_WIDGET_INSENSITIVE].bg.r = 0xe0;
		priv->gc[FTK_WIDGET_INSENSITIVE].bg.g = 0xd0;
		priv->gc[FTK_WIDGET_INSENSITIVE].bg.b = 0xe0;
	}

	return;
}
Esempio n. 2
0
static Ret ftk_message_box_size(int has_title, int has_button, const char* text, int* w, int* h)
{
	int start  = 0;
	int width  = 0;
	int height = 0;
	int font_h = 0;
	FtkRect rect = {0};
	const char* end = text;
	FtkCanvas* canvas = ftk_shared_canvas();
	
	ftk_wnd_manager_get_work_area(ftk_default_wnd_manager(), &rect);

	width  = rect.width - 2 * (FTK_DIALOG_MARGIN + FTK_LABEL_LEFT_MARGIN + FTK_DIALOG_BORDER);

	height = 4 * FTK_V_MARGIN + FTK_DIALOG_BORDER;
	height += has_title ? ftk_dialog_get_title_height() : 0;
	height += has_button ? FTK_BUTTON_DEFAULT_HEIGHT : 0;

	font_h = ftk_font_desc_get_size(ftk_default_font());
	while(*end != '\0')
	{
		height += font_h + FTK_LABEL_TOP_MARGIN;
		end = ftk_canvas_calc_str_visible_range(canvas, text, start, -1, width, NULL);
		start = end - text;
	}

	height = height < FTK_MESSAGE_BOX_MIN_HEIGHT ? FTK_MESSAGE_BOX_MIN_HEIGHT : height;
	height = height < rect.height ? height : rect.height;

	*h = (height + 1) & 0xfffffffe;
	*w = (rect.width + 1)  & 0xfffffffe;

	return RET_OK;
}
Esempio n. 3
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;
}
Esempio n. 4
0
void ftk_deinit(void)
{
	if(ftk_default_input_method_preeditor() != NULL)
	{
		ftk_input_method_preeditor_destroy(ftk_default_input_method_preeditor());
		ftk_set_input_method_preeditor(NULL);
	}

	if(ftk_default_wnd_manager() != NULL)
	{
		ftk_wnd_manager_destroy(ftk_default_wnd_manager());
		ftk_set_wnd_manager(NULL);
	}
	
	if(ftk_default_main_loop() != NULL)
	{
		ftk_main_loop_destroy(ftk_default_main_loop());
		ftk_set_main_loop(NULL);
	}

	if(ftk_default_sources_manager() != NULL)
	{
		ftk_sources_manager_destroy(ftk_default_sources_manager());
		ftk_set_sources_manager(NULL);
	}

	if(ftk_default_bitmap_factory() != NULL)
	{
		ftk_bitmap_factory_destroy(ftk_default_bitmap_factory());
		ftk_set_bitmap_factory(NULL);
	}

	if(ftk_default_text_layout() != NULL)
	{
		ftk_text_layout_destroy(ftk_default_text_layout());
		ftk_set_text_layout(NULL);
	}

	if(ftk_default_font() != NULL)
	{
		ftk_font_destroy(ftk_default_font());
		ftk_set_font(NULL);
	}

	if(ftk_default_display() != NULL)
	{
		ftk_display_destroy(ftk_default_display());
		ftk_set_display(NULL);
	}

	if(ftk_default_theme() != NULL)
	{
		ftk_theme_destroy(ftk_default_theme());
		ftk_set_theme(NULL);
	}

	if(ftk_shared_canvas() != NULL)
	{
		ftk_canvas_destroy(ftk_shared_canvas());
		ftk_set_shared_canvas(NULL);
	}

	if(ftk_default_input_method_manager() != NULL)
	{
		ftk_input_method_manager_destroy(ftk_default_input_method_manager());
		ftk_set_input_method_manager(NULL);
	}

	if(ftk_default_config() != NULL)
	{
		ftk_config_destroy(ftk_default_config());
		ftk_set_config(NULL);
	}
	
	ftk_platform_deinit();

#ifndef USE_STD_MALLOC
	if(ftk_default_allocator() != NULL)
	{
		ftk_allocator_destroy(ftk_default_allocator());
		ftk_set_allocator(NULL);
	}
#endif

	ftk_logd("%s: ftk exit.\n", __func__);

	return;
}