From 5a1c347acc12a68934fa322b2ff80f74b0110ada Mon Sep 17 00:00:00 2001 From: "qiuyiuestc@gmail.com" Date: Mon, 23 May 2011 13:38:44 +0000 Subject: reconstruct module examples git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1429 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- examples/module/ftk_app/ftk_calculator/SConstruct | 34 +++ .../module/ftk_app/ftk_calculator/calc.desktop | 3 + .../module/ftk_app/ftk_calculator/ftk_app_calc.c | 262 +++++++++++++++++++++ .../module/ftk_app/ftk_calculator/ftk_app_calc.h | 13 + examples/module/ftk_calculator/SConstruct | 34 --- examples/module/ftk_calculator/calc.desktop | 3 - examples/module/ftk_calculator/ftk_app_calc.c | 262 --------------------- examples/module/ftk_calculator/ftk_app_calc.h | 13 - 8 files changed, 312 insertions(+), 312 deletions(-) create mode 100644 examples/module/ftk_app/ftk_calculator/SConstruct create mode 100644 examples/module/ftk_app/ftk_calculator/calc.desktop create mode 100644 examples/module/ftk_app/ftk_calculator/ftk_app_calc.c create mode 100644 examples/module/ftk_app/ftk_calculator/ftk_app_calc.h delete mode 100644 examples/module/ftk_calculator/SConstruct delete mode 100644 examples/module/ftk_calculator/calc.desktop delete mode 100644 examples/module/ftk_calculator/ftk_app_calc.c delete mode 100644 examples/module/ftk_calculator/ftk_app_calc.h (limited to 'examples') diff --git a/examples/module/ftk_app/ftk_calculator/SConstruct b/examples/module/ftk_app/ftk_calculator/SConstruct new file mode 100644 index 0000000000..e7177f5e39 --- /dev/null +++ b/examples/module/ftk_app/ftk_calculator/SConstruct @@ -0,0 +1,34 @@ +import os +import sys + +EXEC_PATH = '/home/shaolin/CodeSourcery/Sourcery_G++_Lite/bin' +RTT_ROOT = os.path.normpath(os.getcwd() + '/../../..') +sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')] +PREFIX = 'arm-none-eabi-' +env = Environment(tools = ['mingw'], + AS = PREFIX + 'gcc', + ASFLAGS = '', + CC = PREFIX + 'gcc', + CCFLAGS = '-DRT_THREAD -DFTK_AS_PLUGIN -mcpu=arm920t -O0 -fPIC' , + AR = PREFIX + 'ar', + ARFLAGS = '-rc', + LINK = PREFIX + 'ld', + LINKFLAGS = '-z max-page-size=0x4 -shared -fPIC -e 0 -nostdlib -s', + CPPPATH = [ + RTT_ROOT + '/include', + RTT_ROOT + '/bsp/mini2440', + RTT_ROOT + '/components/external/ftk/ftk/src/os/rt-thread', + RTT_ROOT + '/components/external/ftk/ftk/src/demos', + RTT_ROOT + '/components/external/ftk/ftk/apps/common', + RTT_ROOT + '/components/external/ftk/ftk/src', + RTT_ROOT + '/components/dfs', + RTT_ROOT + '/components/dfs/include', + RTT_ROOT + '/components/libc/newlib' + ]) +env.PrependENVPath('PATH', EXEC_PATH) + +target = 'calculator.so' +src = Glob('*.c') + +env.Program(target, src) + diff --git a/examples/module/ftk_app/ftk_calculator/calc.desktop b/examples/module/ftk_app/ftk_calculator/calc.desktop new file mode 100644 index 0000000000..3c6407e662 --- /dev/null +++ b/examples/module/ftk_app/ftk_calculator/calc.desktop @@ -0,0 +1,3 @@ + + + diff --git a/examples/module/ftk_app/ftk_calculator/ftk_app_calc.c b/examples/module/ftk_app/ftk_calculator/ftk_app_calc.c new file mode 100644 index 0000000000..e2952572bc --- /dev/null +++ b/examples/module/ftk_app/ftk_calculator/ftk_app_calc.c @@ -0,0 +1,262 @@ +#include "ftk_xul.h" +#include "ftk_expr.h" +#include "ftk_app_calc.h" + +typedef struct _PrivInfo +{ + FtkBitmap* icon; +}PrivInfo; + +#define IDC_ENTRY 100 + +static Ret ftk_calc_on_button_clicked(void* ctx, void* obj); + +const char* ftk_translate_path(const char* path, char out_path[FTK_MAX_PATH+1]) +{ + snprintf(out_path, FTK_MAX_PATH, "%s/%s", APP_DATA_DIR, path); + if(access(out_path, R_OK) < 0) + { + snprintf(out_path, FTK_MAX_PATH, "%s/%s", APP_LOCAL_DATA_DIR, path); + } + ftk_logd("%s->%s\n", path, out_path); + + return out_path; +} + +const char* buttons[] = +{ + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + ".", + "+", + "-", + "*", + "/", + "(", + ")", + "=", + "<--", + "Quit" +}; + +static FtkWidget* ftk_calc_create_window(void) +{ + int i = 0; + int j = 0; + int x = 0; + int y = 0; + int row = 0; + int col = 0; + int small = 0; + int xoffset = 0; + int yoffset = 0; + int width = 0; + int height = 0; + int v_margin = 5; + int h_margin = 5; + int item_width = 0; + int item_height = 0; + FtkGc gc = {0}; + FtkWidget* entry = NULL; + FtkWidget* button = NULL; + FtkBitmap* bitmap_normal = NULL; + FtkBitmap* bitmap_active = NULL; + FtkBitmap* bitmap_focus = NULL; + char path[FTK_MAX_PATH+1] = {0}; + FtkWidget* win = ftk_app_window_create(); + ftk_window_set_animation_hint(win, "app_main_window"); + width = ftk_widget_width(win); + height = ftk_widget_height(win); + entry = ftk_entry_create(win, 0, 0, width, 30); + ftk_widget_set_id(entry, IDC_ENTRY); + height -= ftk_widget_height(entry); + + row = width > height ? 4 : 5; + col = width > height ? 5 : 4; + + item_width = width / col; + item_height = height /row; + small = (item_width < 60 || item_height < 60) ? 1 : 0; + + item_width = item_height = small ? 36 : 60; + + h_margin = width/col - item_width; + h_margin = h_margin > 5 ? 5 : h_margin; + + v_margin = height/row - item_height; + v_margin = v_margin > 5 ? 5 : v_margin; + + xoffset = (width - (h_margin + item_width) * col) >> 1; + yoffset = (height - (v_margin + item_height) * row) >> 1; + + xoffset = xoffset < 0 ? 0 : xoffset; + yoffset = yoffset < 0 ? 0 : yoffset; + + yoffset += ftk_widget_height(entry); + gc.mask = FTK_GC_BITMAP; + if(small) + { + bitmap_normal = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-small.png", path)); + bitmap_active = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-pressed-small.png", path)); + bitmap_focus = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-selected-small.png", path)); + } + else + { + bitmap_normal = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button.png", path)); + bitmap_active = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-pressed.png", path)); + bitmap_focus = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-selected.png", path)); + } + + for(i = 0; i < row; i++) + { + y = yoffset + i * (item_height + v_margin); + for(j = 0; j < col; j++) + { + const char* text = buttons[i * col + j]; + if(text != NULL) + { + x = xoffset + j * (item_width + h_margin); + button = ftk_button_create(win, x, y, item_width, item_height); + ftk_widget_set_text(button, text); + ftk_button_set_clicked_listener(button, ftk_calc_on_button_clicked, win); + gc.bitmap = bitmap_normal; + ftk_widget_set_gc(button, FTK_WIDGET_NORMAL, &gc); + + gc.bitmap = bitmap_focus; + ftk_widget_set_gc(button, FTK_WIDGET_FOCUSED, &gc); + + gc.bitmap = bitmap_active; + ftk_widget_set_gc(button, FTK_WIDGET_ACTIVE, &gc); + } + } + } + + ftk_bitmap_unref(bitmap_normal); + ftk_bitmap_unref(bitmap_active); + ftk_bitmap_unref(bitmap_focus); + + return win; +} + +static Ret ftk_calc_on_shutdown(void* ctx, void* obj) +{ + ftk_widget_unref(ctx); + + return RET_OK; +} + +static Ret ftk_calc_on_prepare_options_menu(void* ctx, FtkWidget* menu_panel) +{ + FtkWidget* item = ftk_menu_item_create(menu_panel); + ftk_widget_set_text(item, _("Quit")); + ftk_menu_item_set_clicked_listener(item, ftk_calc_on_shutdown, ctx); + ftk_widget_show(item, 1); + + return RET_OK; +} + +static Ret ftk_calc_on_button_clicked(void* ctx, void* obj) +{ + FtkWidget* entry = ftk_widget_lookup(ctx, IDC_ENTRY); + const char* text = ftk_widget_get_text(obj); + return_val_if_fail(text != NULL && entry != NULL, RET_FAIL); + + if(text[0] == '=') + { + char buff[32] = {0}; + double val = ftk_expr_eval(ftk_entry_get_text(entry)); + ftk_snprintf(buff, sizeof(buff), "%lf", val); + ftk_entry_set_text(entry, buff); + } + else if(text[0] == '<') + { + ftk_entry_set_text(entry, ""); + } + else if(text[0] == 'Q' || strcmp(text, _("Quit")) == 0) + { + ftk_widget_unref(ctx); + } + else + { + ftk_entry_insert_text(entry, -1, text); + } + + return RET_OK; +} + +static FtkBitmap* ftk_app_calc_get_icon(FtkApp* thiz) +{ + DECL_PRIV(thiz, priv); + const char* name="calc.png"; + char file_name[FTK_MAX_PATH + 1] = {0}; + return_val_if_fail(priv != NULL, NULL); + + if(priv->icon != NULL) return priv->icon; + + snprintf(file_name, FTK_MAX_PATH, "%s/icons/%s", APP_DATA_DIR, name); + priv->icon = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), file_name); + if(priv->icon != NULL) return priv->icon; + + snprintf(file_name, FTK_MAX_PATH, "%s/icons/%s", APP_LOCAL_DATA_DIR, name); + priv->icon = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), file_name); + + return priv->icon; +} + +static const char* ftk_app_calc_get_name(FtkApp* thiz) +{ + return _("Calculator"); +} + +static Ret ftk_app_calc_run(FtkApp* thiz, int argc, char* argv[]) +{ + DECL_PRIV(thiz, priv); + FtkWidget* win = NULL; + return_val_if_fail(priv != NULL, RET_FAIL); + + win = ftk_calc_create_window(); + ftk_app_window_set_on_prepare_options_menu(win, ftk_calc_on_prepare_options_menu, win); + ftk_widget_show_all(win, 1); + +#ifdef HAS_MAIN + FTK_QUIT_WHEN_WIDGET_CLOSE(win); +#endif + + return RET_OK; +} + +static void ftk_app_calc_destroy(FtkApp* thiz) +{ + if(thiz != NULL) + { + DECL_PRIV(thiz, priv); + ftk_bitmap_unref(priv->icon); + FTK_FREE(thiz); + } + + return; +} + +FtkApp* ftk_app_calc_create(void) +{ + FtkApp* thiz = FTK_ZALLOC(sizeof(FtkApp) + sizeof(PrivInfo)); + + if(thiz != NULL) + { + thiz->run = ftk_app_calc_run; + thiz->get_icon = ftk_app_calc_get_icon; + thiz->get_name = ftk_app_calc_get_name; + thiz->destroy = ftk_app_calc_destroy; + } + + return thiz; +} + diff --git a/examples/module/ftk_app/ftk_calculator/ftk_app_calc.h b/examples/module/ftk_app/ftk_calculator/ftk_app_calc.h new file mode 100644 index 0000000000..f25758f79f --- /dev/null +++ b/examples/module/ftk_app/ftk_calculator/ftk_app_calc.h @@ -0,0 +1,13 @@ +#ifndef FTK_APP_CALC_H +#define FTK_APP_CALC_H + +#include "ftk_app.h" + +FTK_BEGIN_DECLS + +FtkApp* ftk_app_calc_create(void); + +FTK_END_DECLS + +#endif/*FTK_APP_CALC_H*/ + diff --git a/examples/module/ftk_calculator/SConstruct b/examples/module/ftk_calculator/SConstruct deleted file mode 100644 index e7177f5e39..0000000000 --- a/examples/module/ftk_calculator/SConstruct +++ /dev/null @@ -1,34 +0,0 @@ -import os -import sys - -EXEC_PATH = '/home/shaolin/CodeSourcery/Sourcery_G++_Lite/bin' -RTT_ROOT = os.path.normpath(os.getcwd() + '/../../..') -sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')] -PREFIX = 'arm-none-eabi-' -env = Environment(tools = ['mingw'], - AS = PREFIX + 'gcc', - ASFLAGS = '', - CC = PREFIX + 'gcc', - CCFLAGS = '-DRT_THREAD -DFTK_AS_PLUGIN -mcpu=arm920t -O0 -fPIC' , - AR = PREFIX + 'ar', - ARFLAGS = '-rc', - LINK = PREFIX + 'ld', - LINKFLAGS = '-z max-page-size=0x4 -shared -fPIC -e 0 -nostdlib -s', - CPPPATH = [ - RTT_ROOT + '/include', - RTT_ROOT + '/bsp/mini2440', - RTT_ROOT + '/components/external/ftk/ftk/src/os/rt-thread', - RTT_ROOT + '/components/external/ftk/ftk/src/demos', - RTT_ROOT + '/components/external/ftk/ftk/apps/common', - RTT_ROOT + '/components/external/ftk/ftk/src', - RTT_ROOT + '/components/dfs', - RTT_ROOT + '/components/dfs/include', - RTT_ROOT + '/components/libc/newlib' - ]) -env.PrependENVPath('PATH', EXEC_PATH) - -target = 'calculator.so' -src = Glob('*.c') - -env.Program(target, src) - diff --git a/examples/module/ftk_calculator/calc.desktop b/examples/module/ftk_calculator/calc.desktop deleted file mode 100644 index 3c6407e662..0000000000 --- a/examples/module/ftk_calculator/calc.desktop +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/examples/module/ftk_calculator/ftk_app_calc.c b/examples/module/ftk_calculator/ftk_app_calc.c deleted file mode 100644 index e2952572bc..0000000000 --- a/examples/module/ftk_calculator/ftk_app_calc.c +++ /dev/null @@ -1,262 +0,0 @@ -#include "ftk_xul.h" -#include "ftk_expr.h" -#include "ftk_app_calc.h" - -typedef struct _PrivInfo -{ - FtkBitmap* icon; -}PrivInfo; - -#define IDC_ENTRY 100 - -static Ret ftk_calc_on_button_clicked(void* ctx, void* obj); - -const char* ftk_translate_path(const char* path, char out_path[FTK_MAX_PATH+1]) -{ - snprintf(out_path, FTK_MAX_PATH, "%s/%s", APP_DATA_DIR, path); - if(access(out_path, R_OK) < 0) - { - snprintf(out_path, FTK_MAX_PATH, "%s/%s", APP_LOCAL_DATA_DIR, path); - } - ftk_logd("%s->%s\n", path, out_path); - - return out_path; -} - -const char* buttons[] = -{ - "0", - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - ".", - "+", - "-", - "*", - "/", - "(", - ")", - "=", - "<--", - "Quit" -}; - -static FtkWidget* ftk_calc_create_window(void) -{ - int i = 0; - int j = 0; - int x = 0; - int y = 0; - int row = 0; - int col = 0; - int small = 0; - int xoffset = 0; - int yoffset = 0; - int width = 0; - int height = 0; - int v_margin = 5; - int h_margin = 5; - int item_width = 0; - int item_height = 0; - FtkGc gc = {0}; - FtkWidget* entry = NULL; - FtkWidget* button = NULL; - FtkBitmap* bitmap_normal = NULL; - FtkBitmap* bitmap_active = NULL; - FtkBitmap* bitmap_focus = NULL; - char path[FTK_MAX_PATH+1] = {0}; - FtkWidget* win = ftk_app_window_create(); - ftk_window_set_animation_hint(win, "app_main_window"); - width = ftk_widget_width(win); - height = ftk_widget_height(win); - entry = ftk_entry_create(win, 0, 0, width, 30); - ftk_widget_set_id(entry, IDC_ENTRY); - height -= ftk_widget_height(entry); - - row = width > height ? 4 : 5; - col = width > height ? 5 : 4; - - item_width = width / col; - item_height = height /row; - small = (item_width < 60 || item_height < 60) ? 1 : 0; - - item_width = item_height = small ? 36 : 60; - - h_margin = width/col - item_width; - h_margin = h_margin > 5 ? 5 : h_margin; - - v_margin = height/row - item_height; - v_margin = v_margin > 5 ? 5 : v_margin; - - xoffset = (width - (h_margin + item_width) * col) >> 1; - yoffset = (height - (v_margin + item_height) * row) >> 1; - - xoffset = xoffset < 0 ? 0 : xoffset; - yoffset = yoffset < 0 ? 0 : yoffset; - - yoffset += ftk_widget_height(entry); - gc.mask = FTK_GC_BITMAP; - if(small) - { - bitmap_normal = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-small.png", path)); - bitmap_active = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-pressed-small.png", path)); - bitmap_focus = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-selected-small.png", path)); - } - else - { - bitmap_normal = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button.png", path)); - bitmap_active = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-pressed.png", path)); - bitmap_focus = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-selected.png", path)); - } - - for(i = 0; i < row; i++) - { - y = yoffset + i * (item_height + v_margin); - for(j = 0; j < col; j++) - { - const char* text = buttons[i * col + j]; - if(text != NULL) - { - x = xoffset + j * (item_width + h_margin); - button = ftk_button_create(win, x, y, item_width, item_height); - ftk_widget_set_text(button, text); - ftk_button_set_clicked_listener(button, ftk_calc_on_button_clicked, win); - gc.bitmap = bitmap_normal; - ftk_widget_set_gc(button, FTK_WIDGET_NORMAL, &gc); - - gc.bitmap = bitmap_focus; - ftk_widget_set_gc(button, FTK_WIDGET_FOCUSED, &gc); - - gc.bitmap = bitmap_active; - ftk_widget_set_gc(button, FTK_WIDGET_ACTIVE, &gc); - } - } - } - - ftk_bitmap_unref(bitmap_normal); - ftk_bitmap_unref(bitmap_active); - ftk_bitmap_unref(bitmap_focus); - - return win; -} - -static Ret ftk_calc_on_shutdown(void* ctx, void* obj) -{ - ftk_widget_unref(ctx); - - return RET_OK; -} - -static Ret ftk_calc_on_prepare_options_menu(void* ctx, FtkWidget* menu_panel) -{ - FtkWidget* item = ftk_menu_item_create(menu_panel); - ftk_widget_set_text(item, _("Quit")); - ftk_menu_item_set_clicked_listener(item, ftk_calc_on_shutdown, ctx); - ftk_widget_show(item, 1); - - return RET_OK; -} - -static Ret ftk_calc_on_button_clicked(void* ctx, void* obj) -{ - FtkWidget* entry = ftk_widget_lookup(ctx, IDC_ENTRY); - const char* text = ftk_widget_get_text(obj); - return_val_if_fail(text != NULL && entry != NULL, RET_FAIL); - - if(text[0] == '=') - { - char buff[32] = {0}; - double val = ftk_expr_eval(ftk_entry_get_text(entry)); - ftk_snprintf(buff, sizeof(buff), "%lf", val); - ftk_entry_set_text(entry, buff); - } - else if(text[0] == '<') - { - ftk_entry_set_text(entry, ""); - } - else if(text[0] == 'Q' || strcmp(text, _("Quit")) == 0) - { - ftk_widget_unref(ctx); - } - else - { - ftk_entry_insert_text(entry, -1, text); - } - - return RET_OK; -} - -static FtkBitmap* ftk_app_calc_get_icon(FtkApp* thiz) -{ - DECL_PRIV(thiz, priv); - const char* name="calc.png"; - char file_name[FTK_MAX_PATH + 1] = {0}; - return_val_if_fail(priv != NULL, NULL); - - if(priv->icon != NULL) return priv->icon; - - snprintf(file_name, FTK_MAX_PATH, "%s/icons/%s", APP_DATA_DIR, name); - priv->icon = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), file_name); - if(priv->icon != NULL) return priv->icon; - - snprintf(file_name, FTK_MAX_PATH, "%s/icons/%s", APP_LOCAL_DATA_DIR, name); - priv->icon = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), file_name); - - return priv->icon; -} - -static const char* ftk_app_calc_get_name(FtkApp* thiz) -{ - return _("Calculator"); -} - -static Ret ftk_app_calc_run(FtkApp* thiz, int argc, char* argv[]) -{ - DECL_PRIV(thiz, priv); - FtkWidget* win = NULL; - return_val_if_fail(priv != NULL, RET_FAIL); - - win = ftk_calc_create_window(); - ftk_app_window_set_on_prepare_options_menu(win, ftk_calc_on_prepare_options_menu, win); - ftk_widget_show_all(win, 1); - -#ifdef HAS_MAIN - FTK_QUIT_WHEN_WIDGET_CLOSE(win); -#endif - - return RET_OK; -} - -static void ftk_app_calc_destroy(FtkApp* thiz) -{ - if(thiz != NULL) - { - DECL_PRIV(thiz, priv); - ftk_bitmap_unref(priv->icon); - FTK_FREE(thiz); - } - - return; -} - -FtkApp* ftk_app_calc_create(void) -{ - FtkApp* thiz = FTK_ZALLOC(sizeof(FtkApp) + sizeof(PrivInfo)); - - if(thiz != NULL) - { - thiz->run = ftk_app_calc_run; - thiz->get_icon = ftk_app_calc_get_icon; - thiz->get_name = ftk_app_calc_get_name; - thiz->destroy = ftk_app_calc_destroy; - } - - return thiz; -} - diff --git a/examples/module/ftk_calculator/ftk_app_calc.h b/examples/module/ftk_calculator/ftk_app_calc.h deleted file mode 100644 index f25758f79f..0000000000 --- a/examples/module/ftk_calculator/ftk_app_calc.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef FTK_APP_CALC_H -#define FTK_APP_CALC_H - -#include "ftk_app.h" - -FTK_BEGIN_DECLS - -FtkApp* ftk_app_calc_create(void); - -FTK_END_DECLS - -#endif/*FTK_APP_CALC_H*/ - -- cgit v1.3.1