int main (void) { int x,y; ftk_init (); ftk_getmaxxy (&x, &y); printf ("Got a %ix%i screen\n", x, y); x--; y--; //ftk_drawrawpix (0, 0, 100, 0, 150); //ftk_drawrawpix (10, 10, 100, 255, 150); ftk_drawhline (0, x, y/2, COL_WHITE); ftk_drawvline (x/2, 0, y, COL_WHITE); ftk_drawrect (DRAW_SKEL, 0,0, x,y, COL_WHITE); ftk_drawrect (DRAW_FILLED, 1,1, (x/2)-1,(y/2)-1, COL_RED); ftk_drawrect (DRAW_FILLED, (x/2)+1,1, x-1,(y/2)-1, COL_BLUE); ftk_drawrect (DRAW_FILLED, 1,(y/2)+1, (x/2)-1,(y/1)-1, COL_GREEN); ftk_drawrect (DRAW_FILLED, (x/2)+1,(y/2)+1, x-1,(y/1)-1, COL_YELLOW); ftk_quit (); exit(EXIT_SUCCESS); }
int main(int argc, char* argv[]) { FtkWidget* keyboard = NULL; ftk_init(argc, argv); ftk_key_board_test(argv[1]); return 0; }
int main(int argc, char* argv[]) { ftk_init(argc, argv); FtkWidget* thiz = ftk_label_create(NULL, 0, 0, 60, 20); ftk_widget_set_text(thiz, "ok"); assert(strcmp(ftk_widget_get_text(thiz), "ok") == 0); ftk_widget_destroy(thiz); return 0; }
int main(int argc, char* argv[]) { FtkWidget* win = NULL; ftk_init(argc, argv); win = ftk_xul_load(t1, strlen(t1)); ftk_widget_unref(win); return 0; }
Ret ftk_main(int argc, char* argv[]) #endif { #ifdef HAS_MAIN ftk_init(argc, argv); #endif ftk_app_run(ftk_app_calc_create(), argc, argv); #ifdef HAS_MAIN ftk_run(); #endif return RET_OK; }
Ret ftk_main(int argc, char* argv[]) #endif { FtkApp* app = ftk_app_music_create(); #ifdef HAS_MAIN ftk_init(argc, argv); #endif ftk_app_run(app, argc, argv); #ifdef HAS_MAIN ftk_run(); #endif return RET_OK; }
Ret ftk_main(int argc, char* argv[]) #endif { FtkApp* app = ftk_app_file_browser_create(); #ifdef HAS_MAIN ftk_init(argc, argv); #endif ftk_app_run(ftk_app_file_browser_create(), argc, argv); #ifdef HAS_MAIN ftk_run(); #endif return RET_OK; }
static int lua_ftk_init(lua_State* L) { tolua_Error err = {0}; Ret retv; int argc; char** argv; int param_ok = tolua_isnumber(L, 1, 0, &err) && tolua_istable(L, 2, 0, &err); return_val_if_fail(param_ok, 0); argc = tolua_tonumber(L, 1, 0); argv = (char**)tolua_tostrings(L, 2, 0); retv = ftk_init(argc, argv); tolua_pushnumber(L, (lua_Number)retv); free(argv); return 1; }
int main(int argc, char* argv[]) { int i = 0; int j = 0; int width = 0; int height = 0; FtkGc gc = {0}; FtkWidget* win = NULL; FtkWidget* button = NULL; ftk_init(argc, argv); width = ftk_display_width(ftk_default_display()); height = ftk_display_height(ftk_default_display()); gc.mask = FTK_GC_BITMAP; win = ftk_window_create(0, 0, width, height); for(i = 0; i < height/80; i++) { for(j = 0; j < width/80; j++) { gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), pngs[i + 1]); button = ftk_button_create(1000, j * 80, i * 80, ftk_bitmap_width(gc.bitmap), ftk_bitmap_height(gc.bitmap)); ftk_widget_set_gc(button, FTK_WIDGET_NORMAL, &gc); ftk_widget_set_gc(button, FTK_WIDGET_FOCUSED, &gc); ftk_widget_append_child(win, button); ftk_widget_show(button, 1); ftk_bitmap_unref(gc.bitmap); if(i == 0 && j == 0) { ftk_button_set_clicked_listener(button, button_clicked, NULL); ftk_button_set_text(button, "Quit"); } } } ftk_window_set_title(win, "button demo"); ftk_widget_show(win, 1); ftk_run(); return 0; }
int main(int argc, char* argv[]) { FtkBitmap* bitmap = NULL; FtkImageDecoder* decoder = NULL; ftk_init(argc, argv); decoder = ftk_image_bmp_decoder_create(); bitmap = ftk_image_decoder_decode(decoder, argv[1]); if(bitmap != NULL) { printf("%s: width=%d height=%d\n", argv[1], ftk_bitmap_width(bitmap), ftk_bitmap_height(bitmap)); ftk_bitmap_unref(bitmap); } ftk_image_decoder_destroy(decoder); return 0; }
int FTK_MAIN(int argc, char* argv[]) { int i = 0; FtkWidget* win = NULL; FtkWidget* button = NULL; FtkSource* timer = NULL; char path[FTK_MAX_PATH] = {0}; const char* root_path[FTK_ICON_PATH_NR] = {0}; ftk_init(argc, argv); for(i = 0; i < argc; i++) { const char* key_play="--event-play="; const char* key_record="--event-record="; #ifdef FTK_HAS_TESTER if(strncmp(argv[i], key_play, strlen(key_play)) == 0) { ftk_tester_start_play(argv[i] + strlen(key_play)); } if(strncmp(argv[i], key_record, strlen(key_record)) == 0) { ftk_tester_start_record(argv[i] + strlen(key_record)); } #endif } #ifdef ENABLE_NLS if(getenv("LANG") == NULL) { setenv("LANG", "zh_CN.UTF-8", 1); setlocale (LC_ALL, "zh_CN.UTF-8"); ftk_logd("LANG is not set, use zh_CN.UTF-8\n"); } else { setlocale (LC_ALL, ""); } bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR); textdomain (PACKAGE); ftk_logd("%s: locale=%s\n", _("Hello, GetText"), setlocale(LC_ALL, NULL)); #endif desktop_add_time_item_on_statusbar(); if(argv[1] != NULL && strncmp(argv[1], "--hor", 5) == 0) { g_desktop.is_horizonal = 1; } g_desktop.app_manager = app_info_manager_create(); ftk_snprintf(path, sizeof(path), "%s/base/apps", FTK_ROOT_DIR); ftk_normalize_path(path); if(app_info_manager_load_dir(g_desktop.app_manager, path) != RET_OK) { ftk_snprintf(path, sizeof(path), "%s/apps", LOCAL_DATA_DIR); app_info_manager_load_dir(g_desktop.app_manager, path); } ftk_snprintf(path, sizeof(path), "%s/desktop", FTK_ROOT_DIR); root_path[0] = path; root_path[1] = NULL; g_desktop.icon_cache = ftk_icon_cache_create(root_path, NULL); win = desktop_load_xul(g_desktop.is_horizonal ? "xul/desktop-h.xul" : "xul/desktop-v.xul"); ftk_app_window_set_on_prepare_options_menu(win, desktop_on_prepare_options_menu, win); button = ftk_widget_lookup(win, 100); ftk_button_set_clicked_listener(button, desktop_on_button_open_applist_clicked, win); ftk_widget_show_all(win, 1); desktop_update_time(win); timer = ftk_source_timer_create(60000, desktop_update_time, win); ftk_main_loop_add_source(ftk_default_main_loop(), timer); ftk_widget_set_user_data(win, desktop_destroy, &g_desktop); ftk_run(); return 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; }