From efdd4043bd568549f1ec4aa1db8d2a7a28670684 Mon Sep 17 00:00:00 2001 From: "bernard.xiong@gmail.com" Date: Fri, 10 Dec 2010 14:18:29 +0000 Subject: [PATCH] add ftk label demo. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1190 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- examples/module/ftk_label/SConscript | 34 ++++++++++ examples/module/ftk_label/demo_label.c | 93 ++++++++++++++++++++++++++ examples/module/rtconfig.h | 4 ++ 3 files changed, 131 insertions(+) create mode 100644 examples/module/ftk_label/SConscript create mode 100644 examples/module/ftk_label/demo_label.c diff --git a/examples/module/ftk_label/SConscript b/examples/module/ftk_label/SConscript new file mode 100644 index 0000000000..95137e573b --- /dev/null +++ b/examples/module/ftk_label/SConscript @@ -0,0 +1,34 @@ +Import('env') +Import('projects') +Import('RTT_ROOT') +Import('rtconfig') +Import('TARGET') + +RTMLINKER = RTT_ROOT + '/tools/rtmlinker.exe ' + +# group definitions +group = {} +group['CCFLAGS'] = '' +group['CPPPATH'] = [RTT_ROOT + '/include', + RTT_ROOT + '/examples/module', + RTT_ROOT + '/components/external/ftk/ftk/src'] +group['CPPDEFINES'] = '' + +target = 'label.so' +POST_ACTION = RTMLINKER + ' -l ' + TARGET + ' -o label.mo ' + '$TARGET' + +# add group to project list +projects.append(group) + +src_local = Split(""" +demo_label.c +""") + +env.Append(CCFLAGS = group['CCFLAGS']) +env.Append(CPPPATH = group['CPPPATH']) +env.Append(CPPDEFINES = group['CPPDEFINES']) +module_env = env.Clone(CCFLAGS = ' -mcpu=arm920t -O0 -fPIC') +module_env.Replace(LINKFLAGS = '-z max-page-size=0x4 -shared -fPIC -e main -nostdlib -s') +module_env.Program(target, src_local) +module_env.AddPostAction(target, POST_ACTION) + diff --git a/examples/module/ftk_label/demo_label.c b/examples/module/ftk_label/demo_label.c new file mode 100644 index 0000000000..bc293e26eb --- /dev/null +++ b/examples/module/ftk_label/demo_label.c @@ -0,0 +1,93 @@ +#include "ftk.h" + +typedef struct _TimerInfo +{ + int times; + FtkWidget* label; +}TimerInfo; + +static Ret timeout(void* ctx) +{ + TimerInfo* info = ctx; + char buffer[32] = {0}; + if(info->times > 0) + { + snprintf(buffer, sizeof(buffer), "Quit after %d seconds", info->times); + ftk_widget_set_text(info->label, buffer); + info->times--; + + return RET_OK; + } + else + { + ftk_widget_unref(ftk_widget_toplevel(info->label)); + ftk_logd("%s: timeout and quit.\n", __func__); + FTK_FREE(info); + FTK_QUIT(); + return RET_REMOVE; + } +} + +#ifdef FTK_AS_PLUGIN +#include "ftk_app_demo.h" +FTK_HIDE int FTK_MAIN(int argc, char* argv[]); +FtkApp* ftk_app_demo_label_create() +{ + return ftk_app_demo_create(_("label"), ftk_main); +} +#else +#define FTK_HIDE extern +#endif /*FTK_AS_PLUGIN*/ + +FTK_HIDE int FTK_MAIN(int argc, char* argv[]) +{ + int width = 0; + int height = 0; + FtkGc gc = {.mask = FTK_GC_BG}; + TimerInfo* info = NULL; + + FTK_INIT(argc, argv); + info = (TimerInfo*)FTK_ZALLOC(sizeof(TimerInfo)); + info->times = 5; + + FtkSource* timer = ftk_source_timer_create(1000, timeout, info); + FtkWidget* win = ftk_app_window_create(); + + width = ftk_widget_width(win); + height = ftk_widget_height(win); + + FtkWidget* label = ftk_label_create(win, 10, 10, width - 20, 20); + ftk_widget_set_text(label, "中文文本"); + + label = ftk_label_create(win, 10, 40, width - 20, 20); + ftk_widget_set_text(label, "English Text(center)"); + ftk_label_set_alignment(label, FTK_ALIGN_CENTER); + assert(strcmp(ftk_widget_get_text(label), "English Text(center)") == 0); + + label = ftk_label_create(win, 10, 70, width - 20, 20); + ftk_widget_set_text(label, "English Text(right)"); + ftk_label_set_alignment(label, FTK_ALIGN_RIGHT); + + gc.bg.a = 0xff; + gc.bg.r = 0xF0; + gc.bg.g = 0xF0; + gc.bg.b = 0x80; + label = ftk_label_create(win, 10, height/2, width - 20, 120); + ftk_widget_set_gc(label, FTK_WIDGET_INSENSITIVE, &gc); + ftk_widget_unset_attr(label, FTK_ATTR_TRANSPARENT); + ftk_widget_set_text(label, "中英文混合多行文本显示:the linux mobile development.带有背景颜色。"); + + label = ftk_label_create(win, 50, height/2-30, width, 20); + info->label = label; + + ftk_widget_set_text(win, "label demo"); + ftk_widget_show_all(win, 1); + + ftk_widget_set_attr(win, FTK_ATTR_IGNORE_CLOSE); + ftk_main_loop_add_source(ftk_default_main_loop(), timer); + + FTK_RUN(); + + return 0; +} + diff --git a/examples/module/rtconfig.h b/examples/module/rtconfig.h index 979bf7f31c..b3bb003469 100644 --- a/examples/module/rtconfig.h +++ b/examples/module/rtconfig.h @@ -37,4 +37,8 @@ /* name length of RTGUI object */ #define RTGUI_NAME_MAX 16 + +/* Using newlib as libc */ +#define RT_USING_NEWLIB + #endif