add ftk demo
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1204 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
162fbee8d6
commit
3569b27c32
|
@ -0,0 +1,138 @@
|
|||
include $(abs_top_srcdir)/src/rules.mk
|
||||
|
||||
lib_LTLIBRARIES=libftk_demos.la
|
||||
|
||||
noinst_PROGRAMS=demo_label demo_button demo_image demo_image_button demo_dialog demo_multi_win \
|
||||
demo_menu demo_entry demo_expand demo_zoom demo_progress_bar demo_check_button demo_wait_box \
|
||||
demo_scroll_bar demo_sprite demo_xul demo_transparent demo_listview demo_hello \
|
||||
demo_fullscreen demo_icon_view demo_text_view demo_msgbox demo_popup demo_alpha \
|
||||
demo_combo_box demo_ime demo_statusbar demo_file_browser demo_tab
|
||||
|
||||
LOCAL_CFLAGS=-I$(abs_top_srcdir)/apps/common
|
||||
libftk_demos_la_SOURCES=demo_button.c demo_alpha.c demo_label.c demo_image.c \
|
||||
demo_image_button.c demo_dialog.c demo_multi_win.c demo_menu.c demo_entry.c \
|
||||
demo_expand.c demo_zoom.c demo_progress_bar.c demo_check_button.c demo_wait_box.c \
|
||||
demo_scroll_bar.c demo_sprite.c demo_xul.c demo_transparent.c demo_listview.c \
|
||||
demo_fullscreen.c demo_icon_view.c demo_text_view.c demo_msgbox.c demo_popup.c \
|
||||
demo_combo_box.c demo_ime.c demo_statusbar.c demo_file_browser.c ftk_app_demo.c \
|
||||
demo_hello.c demo_tab.c
|
||||
|
||||
libftk_demos_la_LDFLAGS=$(MYLDFLAGS)
|
||||
libftk_demos_la_CFLAGS=$(LOCAL_CFLAGS) -DFTK_AS_PLUGIN
|
||||
|
||||
if ENABLE_CAIRO
|
||||
noinst_PROGRAMS+=demo_cairo
|
||||
demo_cairo_SOURCES=demo_cairo.c
|
||||
demo_cairo_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
libftk_demos_la_SOURCES += demo_cairo.c
|
||||
|
||||
endif
|
||||
|
||||
if ENABLE_FRIBIDI
|
||||
noinst_PROGRAMS+=demo_bidi
|
||||
demo_bidi_SOURCES=demo_bidi.c
|
||||
demo_bidi_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
libftk_demos_la_SOURCES += demo_bidi.c
|
||||
endif
|
||||
|
||||
demo_tab_SOURCES=demo_tab.c
|
||||
demo_tab_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_file_browser_SOURCES=demo_file_browser.c
|
||||
demo_file_browser_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_statusbar_SOURCES=demo_statusbar.c
|
||||
demo_statusbar_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_ime_SOURCES=demo_ime.c
|
||||
demo_ime_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_combo_box_SOURCES=demo_combo_box.c
|
||||
demo_combo_box_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_alpha_SOURCES=demo_alpha.c
|
||||
demo_alpha_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_zoom_SOURCES=demo_zoom.c
|
||||
demo_zoom_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_popup_SOURCES=demo_popup.c
|
||||
demo_popup_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_msgbox_SOURCES=demo_msgbox.c
|
||||
demo_msgbox_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_text_view_SOURCES=demo_text_view.c
|
||||
demo_text_view_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_icon_view_SOURCES=demo_icon_view.c
|
||||
demo_icon_view_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_fullscreen_SOURCES=demo_fullscreen.c
|
||||
demo_fullscreen_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_hello_SOURCES=demo_hello.c
|
||||
demo_hello_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_listview_SOURCES=demo_listview.c
|
||||
demo_listview_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_transparent_SOURCES=demo_transparent.c
|
||||
demo_transparent_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_xul_SOURCES=demo_xul.c
|
||||
demo_xul_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_sprite_SOURCES=demo_sprite.c
|
||||
demo_sprite_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_scroll_bar_SOURCES=demo_scroll_bar.c
|
||||
demo_scroll_bar_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_wait_box_SOURCES=demo_wait_box.c
|
||||
demo_wait_box_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_check_button_SOURCES=demo_check_button.c
|
||||
demo_check_button_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_progress_bar_SOURCES=demo_progress_bar.c
|
||||
demo_progress_bar_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_expand_SOURCES=demo_expand.c
|
||||
demo_expand_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_label_SOURCES=demo_label.c
|
||||
demo_label_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_button_SOURCES=demo_button.c
|
||||
demo_button_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_image_SOURCES=demo_image.c
|
||||
demo_image_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_image_button_SOURCES=demo_image_button.c
|
||||
demo_image_button_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_dialog_SOURCES=demo_dialog.c
|
||||
demo_dialog_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_multi_win_SOURCES=demo_multi_win.c
|
||||
demo_multi_win_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_menu_SOURCES=demo_menu.c
|
||||
demo_menu_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
demo_entry_SOURCES=demo_entry.c
|
||||
demo_entry_LDFLAGS=$(MYLDFLAGS)
|
||||
|
||||
desktopdir=$(datadir)/ftk/base/apps
|
||||
desktop_DATA=demos.desktop
|
||||
|
||||
iconsdir=$(datadir)/ftk/demos/icons
|
||||
icons_DATA=demo.png
|
||||
|
||||
EXTRA_DIST=demo.png test_util.c t1.xul t2.xul t3.xul t4.xul t5.xul t6.xul t7.xul demos.desktop \
|
||||
ftk_app_demo.h
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 597 B |
|
@ -0,0 +1,104 @@
|
|||
#include "ftk.h"
|
||||
#include "ftk_animator_alpha.h"
|
||||
|
||||
static void create_ani_window(int type, int sync);
|
||||
|
||||
static Ret button_fast_clicked(void* ctx, void* obj)
|
||||
{
|
||||
create_ani_window(1, 0);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_slow_clicked(void* ctx, void* obj)
|
||||
{
|
||||
create_ani_window(0, 0);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
FtkWidget* win = ctx;
|
||||
ftk_widget_unref(win);
|
||||
ftk_logd("%s: close window %s\n", __func__, ftk_widget_get_text(win));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static void create_ani_window(int type, int sync)
|
||||
{
|
||||
FtkGc gc = {0};
|
||||
char filename[FTK_MAX_PATH+1] = {0};
|
||||
FtkWidget* win = ftk_app_window_create();
|
||||
FtkAnimator* ani = ftk_animator_alpha_create(1);
|
||||
|
||||
gc.mask = FTK_GC_BITMAP;
|
||||
|
||||
ftk_snprintf(filename, FTK_MAX_PATH, "%s/jpeg1.jpg",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()));
|
||||
gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
|
||||
ftk_widget_set_gc(win, FTK_WIDGET_NORMAL, &gc);
|
||||
ftk_gc_reset(&gc);
|
||||
|
||||
ftk_animator_set_param(ani, 0, 0, 0xff, type ? 0x60 : 0x20, type ? 200 : 1000);
|
||||
ftk_animator_start(ani, win, 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void create_app_window(void)
|
||||
{
|
||||
char title[32] = {0};
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
FtkWidget* win = ftk_app_window_create();
|
||||
FtkWidget* button = NULL;
|
||||
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
button = ftk_button_create(win, 5, height/6, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "Fast");
|
||||
ftk_button_set_clicked_listener(button, button_fast_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width/2, height/6, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "Slow");
|
||||
ftk_button_set_clicked_listener(button, button_slow_clicked, win);
|
||||
|
||||
|
||||
button = ftk_button_create(win, width/4-2, height/6 + 180, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "Quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
|
||||
ftk_snprintf(title, sizeof(title), "Alpha Demo");
|
||||
ftk_widget_set_text(win, title);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
ftk_widget_show_all(win, 1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_alpha_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("alpha"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
create_app_window();
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
#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;
|
||||
}
|
||||
}
|
||||
|
||||
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 = 100;
|
||||
|
||||
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, "arabic bidi demo");
|
||||
|
||||
label = ftk_label_create(win, 10, 40, width - 20, 20);
|
||||
ftk_widget_set_text(label, "English Text");
|
||||
assert(strcmp(ftk_widget_get_text(label), "English Text") == 0);
|
||||
|
||||
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, "ان منح حياتك للمسيح تعد خطوة ايمان يمكنك القيام بها عن طريق الصلاة");
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
#include "ftk.h"
|
||||
|
||||
#define IDC_TEST_BUTTON 1000
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_hide_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_show(ftk_widget_lookup(ctx, IDC_TEST_BUTTON), 0);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_show_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_show(ftk_widget_lookup(ctx, IDC_TEST_BUTTON), 1);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_default_clicked(void* ctx, void* obj)
|
||||
{
|
||||
printf("%s: button %s is clicked.\n", __func__, ftk_widget_get_text(obj));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_button_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("button"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
width = width/3 - 10;
|
||||
button = ftk_button_create(win, 0, 30, width, 50);
|
||||
ftk_widget_set_text(button, "show");
|
||||
ftk_button_set_clicked_listener(button, button_show_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width + 10, 30, width, 50);
|
||||
ftk_widget_set_text(button, "hide");
|
||||
ftk_button_set_clicked_listener(button, button_hide_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, 2*(width + 10), 30, width, 50);
|
||||
ftk_widget_set_text(button, "按钮测试");
|
||||
ftk_widget_set_id(button, IDC_TEST_BUTTON);
|
||||
ftk_button_set_clicked_listener(button, button_default_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, 0, 130, width, 40);
|
||||
ftk_widget_set_text(button, "yes");
|
||||
ftk_button_set_clicked_listener(button, button_default_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, 2*(width + 10), 130, width, 40);
|
||||
ftk_widget_set_text(button, "no");
|
||||
ftk_button_set_clicked_listener(button, button_default_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width + 10, height/2, width, 60);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
ftk_window_set_focus(win, button);
|
||||
|
||||
ftk_widget_set_text(win, "button demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,373 @@
|
|||
#include <math.h>
|
||||
#include "ftk_cairo.h"
|
||||
|
||||
static cairo_t* cr = NULL;
|
||||
|
||||
static void paint_clip_image(int x, int y, int width, int height)
|
||||
{
|
||||
int w, h;
|
||||
cairo_surface_t *image;
|
||||
char filename[FTK_MAX_PATH+1] = {0};
|
||||
|
||||
cairo_translate (cr, x, y);
|
||||
|
||||
cairo_arc (cr, width/2, height/4, width/3, 0, 2*M_PI);
|
||||
cairo_clip (cr);
|
||||
cairo_new_path (cr); /* path not consumed by clip()*/
|
||||
|
||||
ftk_snprintf(filename, FTK_MAX_PATH, "%s/png1.png",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()));
|
||||
image = cairo_image_surface_create_from_png (filename);
|
||||
|
||||
w = cairo_image_surface_get_width (image);
|
||||
h = cairo_image_surface_get_height (image);
|
||||
|
||||
// cairo_scale (cr, 256.0/w, 256.0/h);
|
||||
|
||||
cairo_set_source_surface (cr, image, 0, 0);
|
||||
cairo_paint (cr);
|
||||
|
||||
cairo_surface_destroy (image);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void paint_rect(int x, int y, int width, int height)
|
||||
{
|
||||
/* a custom shape that could be wrapped in a function */
|
||||
double x0 = 25.6, /* parameters like cairo_rectangle */
|
||||
y0 = 25.6,
|
||||
rect_width = 204.8,
|
||||
rect_height = 204.8,
|
||||
radius = 102.4; /* and an approximate curvature radius */
|
||||
|
||||
double x1,y1;
|
||||
|
||||
cairo_translate (cr, x, y);
|
||||
x1=x0+rect_width;
|
||||
y1=y0+rect_height;
|
||||
if (!rect_width || !rect_height)
|
||||
return;
|
||||
if (rect_width/2<radius) {
|
||||
if (rect_height/2<radius) {
|
||||
cairo_move_to (cr, x0, (y0 + y1)/2);
|
||||
cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
|
||||
cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
|
||||
cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
|
||||
cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
|
||||
} else {
|
||||
cairo_move_to (cr, x0, y0 + radius);
|
||||
cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
|
||||
cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
|
||||
cairo_line_to (cr, x1 , y1 - radius);
|
||||
cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
|
||||
cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
|
||||
}
|
||||
} else {
|
||||
if (rect_height/2<radius) {
|
||||
cairo_move_to (cr, x0, (y0 + y1)/2);
|
||||
cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
|
||||
cairo_line_to (cr, x1 - radius, y0);
|
||||
cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
|
||||
cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
|
||||
cairo_line_to (cr, x0 + radius, y1);
|
||||
cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
|
||||
} else {
|
||||
cairo_move_to (cr, x0, y0 + radius);
|
||||
cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
|
||||
cairo_line_to (cr, x1 - radius, y0);
|
||||
cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
|
||||
cairo_line_to (cr, x1 , y1 - radius);
|
||||
cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
|
||||
cairo_line_to (cr, x0 + radius, y1);
|
||||
cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
|
||||
}
|
||||
}
|
||||
cairo_close_path (cr);
|
||||
|
||||
cairo_set_source_rgb (cr, 0.5, 0.5, 1);
|
||||
cairo_fill_preserve (cr);
|
||||
cairo_set_source_rgba (cr, 0.5, 0, 0, 0.5);
|
||||
cairo_set_line_width (cr, 10.0);
|
||||
cairo_stroke (cr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void paint_pic(int x, int y, int width, int height)
|
||||
{
|
||||
int w, h;
|
||||
cairo_surface_t *image;
|
||||
cairo_pattern_t *pattern;
|
||||
cairo_matrix_t matrix;
|
||||
char filename[FTK_MAX_PATH+1] = {0};
|
||||
|
||||
cairo_translate (cr, x, y);
|
||||
ftk_snprintf(filename, FTK_MAX_PATH, "%s/png1.png",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()));
|
||||
image = cairo_image_surface_create_from_png (filename);
|
||||
|
||||
w = cairo_image_surface_get_width (image);
|
||||
h = cairo_image_surface_get_height (image);
|
||||
|
||||
pattern = cairo_pattern_create_for_surface (image);
|
||||
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
|
||||
|
||||
cairo_translate (cr, 128.0, 128.0);
|
||||
cairo_rotate (cr, M_PI / 4);
|
||||
cairo_scale (cr, 1 / sqrt (2), 1 / sqrt (2));
|
||||
cairo_translate (cr, -128.0, -128.0);
|
||||
|
||||
cairo_matrix_init_scale (&matrix, w/256.0 * 5.0, h/256.0 * 5.0);
|
||||
cairo_pattern_set_matrix (pattern, &matrix);
|
||||
|
||||
cairo_set_source (cr, pattern);
|
||||
|
||||
cairo_rectangle (cr, 0, 0, 256.0, 256.0);
|
||||
cairo_fill (cr);
|
||||
|
||||
cairo_pattern_destroy (pattern);
|
||||
cairo_surface_destroy (image);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void paint_arrow(int x, int y, int width, int height)
|
||||
{
|
||||
cairo_translate (cr, x, y);
|
||||
cairo_set_line_width (cr, 40.96);
|
||||
cairo_move_to (cr, 76.8, 84.48);
|
||||
cairo_rel_line_to (cr, 51.2, -51.2);
|
||||
cairo_rel_line_to (cr, 51.2, 51.2);
|
||||
cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER); /* default */
|
||||
cairo_stroke (cr);
|
||||
|
||||
cairo_move_to (cr, 76.8, 161.28);
|
||||
cairo_rel_line_to (cr, 51.2, -51.2);
|
||||
cairo_rel_line_to (cr, 51.2, 51.2);
|
||||
cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
|
||||
cairo_stroke (cr);
|
||||
|
||||
cairo_move_to (cr, 76.8, 238.08);
|
||||
cairo_rel_line_to (cr, 51.2, -51.2);
|
||||
cairo_rel_line_to (cr, 51.2, 51.2);
|
||||
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
|
||||
cairo_stroke (cr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void paint_segments(int x, int y, int width, int height)
|
||||
{
|
||||
cairo_translate (cr, x, y);
|
||||
cairo_move_to (cr, 50.0, 75.0);
|
||||
cairo_line_to (cr, 200.0, 75.0);
|
||||
|
||||
cairo_move_to (cr, 50.0, 125.0);
|
||||
cairo_line_to (cr, 200.0, 125.0);
|
||||
|
||||
cairo_move_to (cr, 50.0, 175.0);
|
||||
cairo_line_to (cr, 200.0, 175.0);
|
||||
|
||||
cairo_set_line_width (cr, 30.0);
|
||||
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
|
||||
cairo_stroke (cr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void paint_ball(int x, int y, int width, int height)
|
||||
{
|
||||
cairo_pattern_t *pat;
|
||||
|
||||
pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, height);
|
||||
cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
|
||||
cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
|
||||
cairo_rectangle (cr, x, y, width, height);
|
||||
cairo_set_source (cr, pat);
|
||||
cairo_fill (cr);
|
||||
cairo_pattern_destroy (pat);
|
||||
|
||||
pat = cairo_pattern_create_radial (x+115.2, y+102.4, 25.6,
|
||||
x+102.4, y+102.4, 128.0);
|
||||
cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
|
||||
cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
|
||||
cairo_set_source (cr, pat);
|
||||
cairo_arc (cr, x+width/2, y+height/4, 76.8, 0, 2 * M_PI);
|
||||
cairo_fill (cr);
|
||||
cairo_pattern_destroy (pat);
|
||||
|
||||
return;
|
||||
}
|
||||
static void paint_helloworld(int x, int y, int width, int height)
|
||||
{
|
||||
cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
|
||||
CAIRO_FONT_WEIGHT_BOLD);
|
||||
cairo_set_font_size (cr, 90.0);
|
||||
|
||||
cairo_move_to (cr, x+10.0, y+135.0);
|
||||
cairo_show_text (cr, "Hello");
|
||||
|
||||
cairo_move_to (cr, x+70.0, y+165.0);
|
||||
cairo_text_path (cr, "void");
|
||||
cairo_set_source_rgb (cr, 0.5, 0.5, 1);
|
||||
cairo_fill_preserve (cr);
|
||||
cairo_set_source_rgb (cr, 0, 0, 0);
|
||||
cairo_set_line_width (cr, 2.56);
|
||||
cairo_stroke (cr);
|
||||
|
||||
/* draw helping lines */
|
||||
cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6);
|
||||
cairo_arc (cr, x+10.0, y+135.0, 5.12, 0, 2*M_PI);
|
||||
cairo_close_path (cr);
|
||||
cairo_arc (cr, x+70.0, y+165.0, 5.12, 0, 2*M_PI);
|
||||
cairo_fill (cr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void paint_car(int x, int y, int width, int height)
|
||||
{
|
||||
cairo_set_line_width (cr, 6);
|
||||
cairo_rectangle (cr, x+10, y+10, width-20, 70);
|
||||
cairo_new_sub_path (cr); cairo_arc (cr, x+64, y+64, 40, 0, 2*M_PI);
|
||||
cairo_new_sub_path (cr); cairo_arc_negative (cr, width-64, y+64, 40, 0, -2*M_PI);
|
||||
|
||||
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
|
||||
cairo_set_source_rgb (cr, 0, 0.7, 0); cairo_fill_preserve (cr);
|
||||
cairo_set_source_rgb (cr, 0, 0, 0); cairo_stroke (cr);
|
||||
|
||||
cairo_translate (cr, x, height/2);
|
||||
cairo_rectangle (cr, 10, 10, width-20, 70);
|
||||
cairo_new_sub_path (cr); cairo_arc (cr, 64, 64, 40, 0, 2*M_PI);
|
||||
cairo_new_sub_path (cr); cairo_arc_negative (cr, width-64, 64, 40, 0, -2*M_PI);
|
||||
|
||||
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
|
||||
cairo_set_source_rgb (cr, 0, 0, 0.9); cairo_fill_preserve (cr);
|
||||
cairo_set_source_rgb (cr, 0, 0, 0); cairo_stroke (cr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
typedef void (*PaintFunc)(int x, int y, int width, int height);
|
||||
|
||||
static size_t g_index = 0;
|
||||
|
||||
static const PaintFunc paints[] =
|
||||
{
|
||||
paint_car,
|
||||
paint_helloworld,
|
||||
paint_ball,
|
||||
paint_segments,
|
||||
paint_arrow,
|
||||
paint_pic,
|
||||
paint_rect,
|
||||
paint_clip_image
|
||||
};
|
||||
|
||||
static Ret on_paint(void* ctx, void* obj)
|
||||
{
|
||||
FtkWidget* thiz = obj;
|
||||
FTK_BEGIN_PAINT(x, y, width, height, canvas);
|
||||
|
||||
ftk_logd("%s:%d\n", __func__, __LINE__);
|
||||
if(cr == NULL)
|
||||
{
|
||||
cairo_surface_t* surface = ftk_cairo_surface_create(thiz);
|
||||
cr = cairo_create(surface);
|
||||
cairo_surface_destroy(surface);
|
||||
ftk_logd("%s:%d\n", __func__, __LINE__);
|
||||
}
|
||||
|
||||
cairo_save (cr);
|
||||
cairo_reset_clip (cr);
|
||||
cairo_identity_matrix (cr);
|
||||
cairo_new_path (cr);
|
||||
cairo_rectangle(cr, x, y, width, height);
|
||||
cairo_clip (cr);
|
||||
|
||||
ftk_logd("%s:%d\n", __func__, __LINE__);
|
||||
paints[g_index](x, y, width, height);
|
||||
ftk_logd("%s:%d\n", __func__, __LINE__);
|
||||
|
||||
cairo_restore (cr);
|
||||
|
||||
FTK_END_PAINT();
|
||||
ftk_logd("%s:%d\n", __func__, __LINE__);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_prev_clicked(void* ctx, void* obj)
|
||||
{
|
||||
g_index = g_index > 0 ? g_index - 1 : 0;
|
||||
ftk_widget_invalidate(ftk_widget_lookup(ctx, 100));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_next_clicked(void* ctx, void* obj)
|
||||
{
|
||||
g_index++;
|
||||
g_index = g_index % (sizeof(paints)/sizeof(paints[0]));
|
||||
|
||||
ftk_widget_invalidate(ftk_widget_lookup(ctx, 100));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_cairo_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("cairo"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
FtkWidget* painter = NULL;
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
button = ftk_button_create(win, 0, 10, width/3, 60);
|
||||
ftk_widget_set_text(button, "prev");
|
||||
ftk_button_set_clicked_listener(button, button_prev_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width/3, 10, width/3, 60);
|
||||
ftk_widget_set_text(button, "next");
|
||||
ftk_button_set_clicked_listener(button, button_next_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width*2/3, 10, width/3, 60);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
|
||||
painter = ftk_painter_create(win, 0, 70, width, height);
|
||||
ftk_widget_set_id(painter, 100);
|
||||
ftk_painter_set_paint_listener(painter, on_paint, NULL);
|
||||
|
||||
ftk_widget_set_text(win, "cairo demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
#include "ftk.h"
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_clicked(void* ctx, void* obj)
|
||||
{
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_check_button_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("check_button"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
FtkWidget* group = NULL;
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
width = width/2 - 10;
|
||||
button = ftk_check_button_create(win,0, 10, width, 50);
|
||||
ftk_widget_set_text(button, "show");
|
||||
ftk_check_button_set_clicked_listener(button, button_clicked, win);
|
||||
|
||||
button = ftk_check_button_create(win, width + 10, 10, width, 50);
|
||||
ftk_widget_set_text(button, "hide");
|
||||
ftk_check_button_set_clicked_listener(button, button_clicked, win);
|
||||
|
||||
group = ftk_radio_group_create(win, 0, 60, 2 * width, 60);
|
||||
|
||||
button = ftk_check_button_create_radio(group,0, 10, width, 50);
|
||||
ftk_widget_set_text(button, "Male");
|
||||
ftk_check_button_set_clicked_listener(button, button_clicked, win);
|
||||
|
||||
button = ftk_check_button_create_radio(group, width + 10, 10, width, 50);
|
||||
ftk_widget_set_text(button, "Female");
|
||||
ftk_check_button_set_clicked_listener(button, button_clicked, win);
|
||||
|
||||
group = ftk_radio_group_create(win, 0, 120, 2 * width, 60);
|
||||
|
||||
button = ftk_check_button_create_radio(group,0, 10, width, 50);
|
||||
ftk_widget_set_text(button, "1(图标右)");
|
||||
ftk_check_button_set_icon_position(button, 1);
|
||||
ftk_check_button_set_clicked_listener(button, button_clicked, win);
|
||||
|
||||
button = ftk_check_button_create_radio(group, width + 10, 10, width, 50);
|
||||
ftk_widget_set_text(button, "2(图标右)");
|
||||
ftk_check_button_set_icon_position(button, 1);
|
||||
ftk_check_button_set_clicked_listener(button, button_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width/2, 3*height/4, width, 60);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
ftk_window_set_focus(win, button);
|
||||
|
||||
ftk_widget_set_text(win, "check button demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
#include "ftk.h"
|
||||
|
||||
#define IDC_TEST_BUTTON 1000
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_combo_box_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("combo_box"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
FtkWidget* combo_box = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
width = width/2 - 10;
|
||||
combo_box = ftk_combo_box_create(win, 0, height/4, width, 50);
|
||||
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");
|
||||
combo_box = ftk_combo_box_create(win, width + 10, height/4, width, 50);
|
||||
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_combo_box_append(combo_box, NULL, "4 seconds");
|
||||
ftk_combo_box_append(combo_box, NULL, "5 seconds");
|
||||
ftk_combo_box_append(combo_box, NULL, "6 seconds");
|
||||
ftk_combo_box_append(combo_box, NULL, "7 seconds");
|
||||
ftk_combo_box_append(combo_box, NULL, "8 seconds");
|
||||
ftk_combo_box_append(combo_box, NULL, "9 seconds");
|
||||
ftk_combo_box_append(combo_box, NULL, "0 seconds");
|
||||
ftk_combo_box_append(combo_box, NULL, "0 seconds");
|
||||
|
||||
button = ftk_button_create(win, width/2, height/2, width, 60);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
ftk_window_set_focus(win, button);
|
||||
|
||||
combo_box = ftk_combo_box_create(win, 0, 3*height/4+5, width, 50);
|
||||
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");
|
||||
combo_box = ftk_combo_box_create(win, width + 10, 3*height/4+5, width, 50);
|
||||
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_combo_box_append(combo_box, NULL, "4 seconds");
|
||||
ftk_combo_box_append(combo_box, NULL, "5 seconds");
|
||||
ftk_combo_box_append(combo_box, NULL, "6 seconds");
|
||||
ftk_combo_box_append(combo_box, NULL, "7 seconds");
|
||||
ftk_combo_box_append(combo_box, NULL, "8 seconds");
|
||||
ftk_combo_box_append(combo_box, NULL, "9 seconds");
|
||||
ftk_combo_box_append(combo_box, NULL, "0 seconds");
|
||||
ftk_combo_box_append(combo_box, NULL, "0 seconds");
|
||||
|
||||
ftk_widget_set_text(win, "ComboBox Demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
#include "ftk.h"
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_dialog_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("dialog"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
if(ctx != NULL)
|
||||
{
|
||||
/*modal*/
|
||||
*(int*)ctx = ftk_widget_id(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*modal-less*/
|
||||
ftk_widget_unref(ftk_widget_toplevel(obj));
|
||||
}
|
||||
|
||||
return RET_QUIT;
|
||||
}
|
||||
|
||||
static Ret button_close_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
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;
|
||||
int modal = (int)ctx;
|
||||
|
||||
ftk_logd("%s:%d begin\n", __func__, __LINE__);
|
||||
dialog = ftk_dialog_create(0, 40, 320, 240);
|
||||
|
||||
icon = ftk_theme_load_image(ftk_default_theme(), "info-icon"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?");
|
||||
|
||||
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");
|
||||
ftk_widget_show_all(dialog, 1);
|
||||
|
||||
if(modal)
|
||||
{
|
||||
assert(ftk_dialog_run(dialog) == id);
|
||||
ftk_widget_unref(dialog);
|
||||
}
|
||||
else
|
||||
{
|
||||
ftk_widget_show_all(dialog, 1);
|
||||
}
|
||||
ftk_logd("%s:%d end\n", __func__, __LINE__);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
button = ftk_button_create(win, 0, height/6, width/3, 50);
|
||||
ftk_widget_set_text(button, "Normal");
|
||||
ftk_button_set_clicked_listener(button, button_dialog_clicked, NULL);
|
||||
|
||||
button = ftk_button_create(win, 2*width/3, height/6, width/3, 50);
|
||||
ftk_widget_set_text(button, "Modal");
|
||||
ftk_button_set_clicked_listener(button, button_dialog_clicked, (void*)1);
|
||||
|
||||
button = ftk_button_create(win, width/4, height/2, width/2, 60);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_close_clicked, win);
|
||||
|
||||
ftk_widget_set_text(win, "demo dialog");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
#include "ftk.h"
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_logd("%s: %s\n", __func__, ftk_widget_get_text(ftk_widget_lookup(ctx, 100)));
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret ftk_digit_only_filter(void* ctx, void* data)
|
||||
{
|
||||
FtkEvent* event = data;
|
||||
if(event->type == FTK_EVT_KEY_UP || event->type == FTK_EVT_KEY_DOWN)
|
||||
{
|
||||
int code = event->u.key.code;
|
||||
if(code >= FTK_KEY_0 && code <= FTK_KEY_9)
|
||||
{
|
||||
return RET_OK;
|
||||
}
|
||||
else if(code == FTK_KEY_UP
|
||||
|| code == FTK_KEY_DOWN
|
||||
|| code == FTK_KEY_LEFT
|
||||
|| code == FTK_KEY_RIGHT
|
||||
|| code == FTK_KEY_BACKSPACE
|
||||
|| code == FTK_KEY_DELETE
|
||||
|| code == FTK_KEY_HOME
|
||||
|| code == FTK_KEY_END
|
||||
|| code == FTK_KEY_TAB)
|
||||
{
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
return RET_REMOVE;
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_entry_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("entry"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
|
||||
#define STR_TEXT1 "Single line editor, that means you can input a one line only."
|
||||
#define STR_TEXT2 "Single line editor, 也就是说你只能输入一行文字."
|
||||
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
FtkWidget* entry = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
entry = ftk_entry_create(win, 10, 30, ftk_widget_width(win) - 20, 30);
|
||||
ftk_widget_set_id(entry, 100);
|
||||
ftk_widget_set_text(entry, "1234");
|
||||
ftk_widget_set_event_listener(entry, ftk_digit_only_filter, NULL);
|
||||
ftk_entry_set_tips(entry, "Please input some digits.");
|
||||
entry = ftk_entry_create(win, 10, 80, ftk_widget_width(win) - 20, 30);
|
||||
ftk_widget_set_text(entry, STR_TEXT1);
|
||||
assert(strcmp(STR_TEXT1, ftk_widget_get_text(entry)) == 0);
|
||||
|
||||
entry = ftk_entry_create(win, 10, 130, ftk_widget_width(win) - 20, 30);
|
||||
ftk_widget_set_text(entry, STR_TEXT2);
|
||||
assert(strcmp(STR_TEXT2, ftk_widget_get_text(entry)) == 0);
|
||||
|
||||
button = ftk_button_create(win, width/4, 3*height/4, width/2, 60);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
ftk_window_set_focus(win, button);
|
||||
|
||||
ftk_widget_set_text(win, "entry demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,189 @@
|
|||
#include "ftk.h"
|
||||
#include "ftk_animator_expand.h"
|
||||
|
||||
static void create_ani_window(int type, int sync);
|
||||
|
||||
static Ret button_to_east_south_clicked(void* ctx, void* obj)
|
||||
{
|
||||
create_ani_window(FTK_ANI_TO_EAST_SOUTH, 1);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_to_east_north_clicked(void* ctx, void* obj)
|
||||
{
|
||||
create_ani_window(FTK_ANI_TO_EAST_NORTH, 1);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_to_right_clicked(void* ctx, void* obj)
|
||||
{
|
||||
create_ani_window(FTK_ANI_TO_RIGHT, 0);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_to_down_clicked(void* ctx, void* obj)
|
||||
{
|
||||
create_ani_window(FTK_ANI_TO_DOWN, 0);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_to_up_clicked(void* ctx, void* obj)
|
||||
{
|
||||
create_ani_window(FTK_ANI_TO_UP, 0);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_to_brink_clicked(void* ctx, void* obj)
|
||||
{
|
||||
create_ani_window(FTK_ANI_TO_BRINK, 0);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_close_clicked(void* ctx, void* obj)
|
||||
{
|
||||
FtkWidget* win = ctx;
|
||||
ftk_logd("%s: close window %s\n", __func__, ftk_widget_get_text(win));
|
||||
ftk_widget_unref(win);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
FtkWidget* win = ctx;
|
||||
ftk_widget_unref(win);
|
||||
ftk_logd("%s: close window %s\n", __func__, ftk_widget_get_text(win));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static void create_ani_window(int type, int sync)
|
||||
{
|
||||
int delta = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
FtkWidget* button = NULL;
|
||||
FtkGc gc = {0};
|
||||
char filename[FTK_MAX_PATH+1] = {0};
|
||||
FtkWidget* win = ftk_app_window_create();
|
||||
FtkAnimator* ani = ftk_animator_expand_create(1);
|
||||
|
||||
gc.mask = FTK_GC_BITMAP;
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
delta = height/6;
|
||||
|
||||
button = ftk_button_create(win, width/3, height/3, width/3, 50);
|
||||
ftk_widget_set_text(button, "关闭");
|
||||
ftk_widget_show(button, 1);
|
||||
ftk_button_set_clicked_listener(button, button_close_clicked, win);
|
||||
|
||||
ftk_snprintf(filename, FTK_MAX_PATH, "%s/jpeg1.jpg",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()));
|
||||
gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
|
||||
ftk_widget_set_gc(win, FTK_WIDGET_NORMAL, &gc);
|
||||
ftk_gc_reset(&gc);
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case FTK_ANI_TO_RIGHT:
|
||||
case FTK_ANI_TO_EAST_SOUTH:
|
||||
case FTK_ANI_TO_EAST_NORTH:
|
||||
{
|
||||
ftk_animator_set_param(ani, type, 100, width, delta, 200);
|
||||
break;
|
||||
}
|
||||
case FTK_ANI_TO_BRINK:
|
||||
case FTK_ANI_TO_DOWN:
|
||||
{
|
||||
ftk_animator_set_param(ani, type, 100, height, delta, 200);
|
||||
break;
|
||||
}
|
||||
case FTK_ANI_TO_UP:
|
||||
{
|
||||
ftk_animator_set_param(ani, type, height - 100, ftk_widget_top(win), delta, 200);
|
||||
break;
|
||||
}
|
||||
default:break;
|
||||
}
|
||||
ftk_animator_start(ani, win, 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void create_app_window(void)
|
||||
{
|
||||
char title[32] = {0};
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
FtkWidget* win = ftk_app_window_create();
|
||||
FtkWidget* button = NULL;
|
||||
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
button = ftk_button_create(win, 5, height/6, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "向右伸展");
|
||||
ftk_button_set_clicked_listener(button, button_to_right_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width/2, height/6, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "Down");
|
||||
ftk_button_set_clicked_listener(button, button_to_down_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, 5, height/6 + 60, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "RightDown");
|
||||
ftk_button_set_clicked_listener(button, button_to_east_south_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width/2, height/6 + 60, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "RightUp");
|
||||
ftk_button_set_clicked_listener(button, button_to_east_north_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, 5, height/6 + 120, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "Up");
|
||||
ftk_button_set_clicked_listener(button, button_to_up_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width/2, height/6 + 120, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "Brink");
|
||||
ftk_button_set_clicked_listener(button, button_to_brink_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width/4-2, height/6 + 180, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "Quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
|
||||
ftk_snprintf(title, sizeof(title), "Expand Demo");
|
||||
ftk_widget_set_text(win, title);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
ftk_widget_show_all(win, 1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_expand_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("expand"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
create_app_window();
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
#include "ftk.h"
|
||||
#include "ftk_file_browser.h"
|
||||
|
||||
static Ret on_file_selected(void* ctx, int index, const char* path)
|
||||
{
|
||||
ftk_logd("%s: [%d] %s\n", __func__, index, path);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#define IDC_TEST_BUTTON 1000
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_browser_clicked(void* ctx, void* obj)
|
||||
{
|
||||
FtkWidget* win = ftk_file_browser_create(FTK_FILE_BROWER_APP);
|
||||
ftk_file_browser_set_path(win, "./");
|
||||
ftk_file_browser_load(win);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_single_choose_clicked(void* ctx, void* obj)
|
||||
{
|
||||
FtkWidget* win = ftk_file_browser_create(FTK_FILE_BROWER_SINGLE_CHOOSER);
|
||||
ftk_file_browser_set_choosed_handler(win, on_file_selected, NULL);
|
||||
ftk_file_browser_set_path(win, "./");
|
||||
ftk_file_browser_load(win);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_multi_choose_clicked(void* ctx, void* obj)
|
||||
{
|
||||
FtkWidget* win = ftk_file_browser_create(FTK_FILE_BROWER_MULTI_CHOOSER);
|
||||
ftk_file_browser_set_choosed_handler(win, on_file_selected, NULL);
|
||||
ftk_file_browser_set_path(win, "./");
|
||||
ftk_file_browser_load(win);
|
||||
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_file_browser_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("file_browser"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
width = width/2 - 10;
|
||||
button = ftk_button_create(win, 0, height/4, width, 50);
|
||||
ftk_widget_set_text(button, "Single Choose");
|
||||
ftk_button_set_clicked_listener(button, button_single_choose_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width + 10, height/4, width, 50);
|
||||
ftk_widget_set_text(button, "Browser");
|
||||
ftk_button_set_clicked_listener(button, button_browser_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, 0, height/2, width, 50);
|
||||
ftk_widget_set_text(button, "Multi Choose");
|
||||
ftk_button_set_clicked_listener(button, button_multi_choose_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width + 10, height/2, width, 50);
|
||||
ftk_widget_set_text(button, "Quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
ftk_window_set_focus(win, button);
|
||||
|
||||
ftk_widget_set_text(win, "FileBrowser");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
#include "ftk.h"
|
||||
|
||||
#define IDC_TEST_BUTTON 1000
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_unfullscreen_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_window_set_fullscreen(ctx, 0);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_fullscreen_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_window_set_fullscreen(ctx, 1);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_fullscreen_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("fullscreen"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
width = width/2 - 10;
|
||||
button = ftk_button_create(win, 0, height/4, width, 50);
|
||||
ftk_widget_set_text(button, "Fullscreen");
|
||||
ftk_button_set_clicked_listener(button, button_fullscreen_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width + 10, height/4, width, 50);
|
||||
ftk_widget_set_text(button, "Unfullscreen");
|
||||
ftk_button_set_clicked_listener(button, button_unfullscreen_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width/2, height/2, width, 60);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
ftk_window_set_focus(win, button);
|
||||
|
||||
ftk_widget_set_text(win, "fullscreen");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
#include "ftk.h"
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_hello_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("hello"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
FtkWidget* win = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
win = ftk_app_window_create();
|
||||
ftk_widget_set_text(win, "Hello FTK!");
|
||||
ftk_widget_show(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
#include "ftk.h"
|
||||
|
||||
#define IDC_TEST_BUTTON 1000
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static int i = 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;
|
||||
}
|
||||
|
||||
static Ret item_clicked(void* ctx, void* obj)
|
||||
{
|
||||
FtkIconViewItem* item = obj;
|
||||
|
||||
ftk_logd("%s: %s: user_data=%d\n", __func__, item->text, item->user_data);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_icon_view_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("icon_view"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
FtkWidget* icon_view = NULL;
|
||||
FtkIconViewItem item;
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
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;
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
#include "ftk.h"
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_image_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("image"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
FtkWidget* image = NULL;
|
||||
FtkWidget* win = NULL;
|
||||
char filename[FTK_MAX_PATH+1] = {0};
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
|
||||
ftk_snprintf(filename, FTK_MAX_PATH, "%s/earth.png",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()));
|
||||
|
||||
image = ftk_image_create(win, 0, 0, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
|
||||
ftk_image_set_image(image,
|
||||
ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
|
||||
|
||||
ftk_snprintf(filename, FTK_MAX_PATH, "%s/png_RGB_tRNS.png",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()));
|
||||
image = ftk_image_create(win, 0, 0, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
|
||||
ftk_image_set_image(image,
|
||||
ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
|
||||
ftk_widget_set_attr(image, FTK_ATTR_TRANSPARENT);
|
||||
|
||||
ftk_snprintf(filename, FTK_MAX_PATH, "%s/Calculator.png",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()));
|
||||
image = ftk_image_create(win, ftk_widget_width(win)/2, 0, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
|
||||
ftk_image_set_image(image,
|
||||
ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
|
||||
ftk_widget_set_attr(image, FTK_ATTR_BG_TILE);
|
||||
|
||||
ftk_snprintf(filename, FTK_MAX_PATH, "%s/t8.bmp",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()));
|
||||
image = ftk_image_create(win, 0, ftk_widget_height(win)/2, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
|
||||
ftk_image_set_image(image,
|
||||
ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
|
||||
ftk_widget_set_attr(image, FTK_ATTR_BG_CENTER);
|
||||
|
||||
ftk_snprintf(filename, FTK_MAX_PATH, "%s/jpeg1.jpg",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()));
|
||||
image = ftk_image_create(win, ftk_widget_width(win)/2, ftk_widget_height(win)/2, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
|
||||
ftk_image_set_image(image,
|
||||
ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
|
||||
ftk_widget_set_attr(image, FTK_ATTR_BG_TILE);
|
||||
|
||||
ftk_widget_set_text(win, "image demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
#include "ftk.h"
|
||||
|
||||
const char* pngs[] =
|
||||
{
|
||||
"/Camera.png",
|
||||
"/Notes.png",
|
||||
"/RSS.png",
|
||||
"/Calculator.png",
|
||||
"/Twitter.png",
|
||||
"/Clock.png",
|
||||
"/Games.png",
|
||||
"/Youtube.png",
|
||||
"/AIM.png",
|
||||
"/LastFm.png",
|
||||
"/IP.png",
|
||||
"/Acrobat.png",
|
||||
"/Settings.png",
|
||||
"/App",
|
||||
"/Customize.png",
|
||||
"/Skype.png",
|
||||
"/Linkedin.png",
|
||||
"/Calender.png",
|
||||
"/Call.png",
|
||||
"/Install.png",
|
||||
"/Facebook.png",
|
||||
"/iPod.png",
|
||||
"/Chat.png",
|
||||
"/WLM.png",
|
||||
"/Flickr.png",
|
||||
"/Photos.png",
|
||||
"/Stock.png",
|
||||
"/Delicious.png",
|
||||
"/Maps.png",
|
||||
"/iTunes.png",
|
||||
"/Memory.png",
|
||||
"/Weather.png",
|
||||
"/Wordpress.png",
|
||||
"/iradio.png",
|
||||
"/Safari.png",
|
||||
"/Google.png",
|
||||
"/Yahoo.png",
|
||||
"/VLC.png",
|
||||
"/Sms.png",
|
||||
"/Mail.png",
|
||||
NULL
|
||||
};
|
||||
|
||||
static Ret button_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_image_button_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("image_button"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
char filename[FTK_MAX_PATH] = {0};
|
||||
FtkGc gc = {0};
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
gc.mask = FTK_GC_BITMAP;
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
for(i = 0; i < height/80; i++)
|
||||
{
|
||||
for(j = 0; j < width/80; j++)
|
||||
{
|
||||
ftk_snprintf(filename, sizeof(filename), "%s%s",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()), pngs[i + 2]);
|
||||
gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
|
||||
button = ftk_button_create(win, j * 80, i * 80, ftk_bitmap_width(gc.bitmap), ftk_bitmap_height(gc.bitmap));
|
||||
if(i == 0)
|
||||
{
|
||||
ftk_widget_unset_attr(button, FTK_ATTR_TRANSPARENT);
|
||||
}
|
||||
ftk_widget_set_gc(button, FTK_WIDGET_NORMAL, &gc);
|
||||
ftk_bitmap_unref(gc.bitmap);
|
||||
|
||||
ftk_snprintf(filename, sizeof(filename), "%s%s",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()), pngs[1]);
|
||||
gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
|
||||
ftk_widget_set_gc(button, FTK_WIDGET_FOCUSED, &gc);
|
||||
ftk_bitmap_unref(gc.bitmap);
|
||||
|
||||
ftk_snprintf(filename, sizeof(filename), "%s%s",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()), pngs[0]);
|
||||
gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
|
||||
ftk_widget_set_gc(button, FTK_WIDGET_ACTIVE, &gc);
|
||||
ftk_bitmap_unref(gc.bitmap);
|
||||
|
||||
if(i == 0 && j == 0)
|
||||
{
|
||||
ftk_button_set_clicked_listener(button, button_clicked, win);
|
||||
ftk_widget_set_text(button, "Quit");
|
||||
}
|
||||
}
|
||||
}
|
||||
ftk_widget_set_text(win, "image button demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
#include "ftk.h"
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_ime_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("ime"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
FtkWidget* entry = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
entry = ftk_entry_create(win, 10, 30, ftk_widget_width(win) - 20, 30);
|
||||
ftk_entry_set_text(entry, "Single line editor");
|
||||
ftk_input_method_manager_set_current(ftk_default_input_method_manager(), 0);
|
||||
|
||||
entry = ftk_entry_create(win, 10, 80, ftk_widget_width(win) - 20, 30);
|
||||
ftk_entry_set_text(entry, "Single line editor, that means you can input a one line only.");
|
||||
|
||||
entry = ftk_entry_create(win, 10, 130, ftk_widget_width(win) - 20, 30);
|
||||
ftk_entry_set_text(entry, "Single line editor, 也就是说你只能输入一行文字.");
|
||||
|
||||
button = ftk_button_create(win, width/4, height/2, width/2, 60);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
ftk_window_set_focus(win, button);
|
||||
|
||||
entry = ftk_entry_create(win, 10, height-60, ftk_widget_width(win) - 20, 30);
|
||||
ftk_entry_set_text(entry, "Single line editor");
|
||||
|
||||
ftk_widget_set_text(win, "entry demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
#include "ftk.h"
|
||||
|
||||
#include "ftk_list_view.h"
|
||||
#include "ftk_list_render_default.h"
|
||||
#include "ftk_list_model_default.h"
|
||||
|
||||
#define IDC_TEST_BUTTON 1000
|
||||
static int g_index = 0;
|
||||
static FtkBitmap* left_icon = NULL;
|
||||
static FtkBitmap* right_icon = NULL;
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_more_clicked(void* ctx, void* obj)
|
||||
{
|
||||
int i = 0;
|
||||
char text[32] = {0};
|
||||
FtkListItemInfo info = {0};
|
||||
FtkListModel* model = ctx;
|
||||
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
g_index++;
|
||||
ftk_snprintf(text, sizeof(text), "item%04d", g_index);
|
||||
info.text = (text);
|
||||
info.left_icon = left_icon;
|
||||
info.right_icon = right_icon;
|
||||
info.type = g_index%4;
|
||||
ftk_list_model_add(model, &info);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
Ret on_item_clicked(void* ctx, void* list)
|
||||
{
|
||||
FtkListItemInfo* info = NULL;
|
||||
FtkListModel* model = ftk_list_view_get_model(list);
|
||||
int i = ftk_list_view_get_selected(list);
|
||||
|
||||
ftk_list_model_get_data(model, i, (void**)&info);
|
||||
if(info != NULL)
|
||||
{
|
||||
info->state = !info->state;
|
||||
}
|
||||
ftk_logd("%s: %d/%d\n", __func__,
|
||||
ftk_list_view_get_selected(list),
|
||||
ftk_list_model_get_total(model));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_listview_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("listview"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
FtkWidget* list = NULL;
|
||||
FtkListModel* model = NULL;
|
||||
FtkListRender* render = NULL;
|
||||
FtkListItemInfo info = {0};
|
||||
char filename[FTK_MAX_PATH+1] = {0};
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
list = ftk_list_view_create(win, 10, 5, width - 20, 3 * height/4-5);
|
||||
ftk_list_view_set_clicked_listener(list, on_item_clicked, NULL);
|
||||
|
||||
model = ftk_list_model_default_create(10);
|
||||
render = ftk_list_render_default_create();
|
||||
ftk_snprintf(filename, FTK_MAX_PATH, "%s/alarm/%s",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()), FTK_STOCK_IMG_SUFFIX);
|
||||
left_icon = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
|
||||
ftk_snprintf(filename, FTK_MAX_PATH, "%s/search/%s",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()), FTK_STOCK_IMG_SUFFIX);
|
||||
right_icon = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
|
||||
|
||||
g_index = 0;
|
||||
for(g_index = 0; g_index < 4; g_index++)
|
||||
{
|
||||
info.text = "滚动文字:Only those who attempt the absurd can achieve the impossible.";
|
||||
info.left_icon = left_icon;
|
||||
info.right_icon = right_icon;
|
||||
info.type = g_index%4;
|
||||
ftk_list_model_add(model, &info);
|
||||
}
|
||||
|
||||
ftk_list_render_default_set_marquee_attr(render, FTK_MARQUEE_AUTO | FTK_MARQUEE_RIGHT2LEFT | FTK_MARQUEE_FOREVER);
|
||||
ftk_list_view_init(list, model, render, 40);
|
||||
ftk_list_model_unref(model);
|
||||
|
||||
button = ftk_button_create(win, width/4, 3 * height/4 + 5, width/4, 60);
|
||||
ftk_widget_set_text(button, "more");
|
||||
ftk_button_set_clicked_listener(button, button_more_clicked, model);
|
||||
|
||||
button = ftk_button_create(win, width/2, 3 * height/4 + 5, width/4, 60);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
ftk_window_set_focus(win, button);
|
||||
|
||||
ftk_widget_set_text(win, "list view demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
#include "ftk.h"
|
||||
|
||||
static void create_app_window(void);
|
||||
static Ret button_open_clicked(void* ctx, void* obj)
|
||||
{
|
||||
create_app_window();
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_close_clicked(void* ctx, void* obj)
|
||||
{
|
||||
FtkWidget* win = ctx;
|
||||
ftk_logd("%s: close window %s\n", __func__, ftk_widget_get_text(win));
|
||||
ftk_widget_unref(win);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
static int g_index = 0;
|
||||
static void on_window_close(void* user_data)
|
||||
{
|
||||
g_index--;
|
||||
|
||||
ftk_logd("%s: g_index=%d\n", __func__, g_index);
|
||||
if(g_index == 0)
|
||||
{
|
||||
FTK_QUIT();
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
static Ret on_prepare_options_menu(void* ctx, FtkWidget* menu_panel)
|
||||
{
|
||||
int i = 0;
|
||||
for(i = 0; i < g_index && i < 8; i++)
|
||||
{
|
||||
char text[32] = {0};
|
||||
FtkWidget* item = ftk_menu_item_create(menu_panel);
|
||||
ftk_snprintf(text, sizeof(text), "Menu%02d", i);
|
||||
ftk_widget_set_text(item, text);
|
||||
ftk_widget_show(item, 1);
|
||||
}
|
||||
|
||||
return i > 0 ? RET_OK : RET_FAIL;
|
||||
}
|
||||
|
||||
static void create_app_window(void)
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
char title[32] = {0};
|
||||
FtkWidget* win = ftk_app_window_create();
|
||||
FtkWidget* label = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
button = ftk_button_create(win, 0, height/6, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "创建窗口");
|
||||
ftk_button_set_clicked_listener(button, button_open_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width/2+5, height/6, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "关闭窗口");
|
||||
ftk_button_set_clicked_listener(button, button_close_clicked, win);
|
||||
|
||||
label = ftk_label_create(win, 10, height/2, width-20, 60);
|
||||
ftk_widget_set_text(label, "Press F2 to open menu, Presss F3 close window.");
|
||||
|
||||
ftk_snprintf(title, sizeof(title), "window%02d", g_index++);
|
||||
ftk_widget_set_text(win, title);
|
||||
ftk_widget_show_all(win, 1);
|
||||
ftk_widget_set_user_data(win, on_window_close, win);
|
||||
|
||||
ftk_app_window_set_on_prepare_options_menu(win, on_prepare_options_menu, win);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_menu_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("menu"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
create_app_window();
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
#include "ftk.h"
|
||||
|
||||
static const char* buttons1[] = {"Yes", NULL};
|
||||
static const char* buttons2[] = {"Yes", "No", NULL};
|
||||
static const char* buttons3[] = {"Yes", "No", "Cancel", NULL};
|
||||
static Ret button_warning(void* ctx, void* obj)
|
||||
{
|
||||
int ret = ftk_warning("Warning", "December 31, 2008: patchwork.kernel.org is now available for general use. It is currently only monitoring the Linux Kernel mailing-list, but should be useful to kernel developers in dealing with patches flying across the wire.", buttons1);
|
||||
|
||||
ftk_logd("%s: ret = %d\n", __func__, ret);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_info(void* ctx, void* obj)
|
||||
{
|
||||
int ret = ftk_infomation("Infomation", "September 19, 2008: mirrors.kernel.org has been flipped over to using our new GeoDNS based bind server (named-geodns). This means that, at the dns query level, our servers will attempt to direct you to the nearest / fastest kernel.org mirror for your request. This means that you no longer have to use mirrors.us.kernel.org or mirrors.eu.kernel.org to generally route you to the right place. This does mean a change to mirrors.kernel.org no longer explicitly pointing at mirrors.us.kernel.org. Additional information on named-geodns will be forth coming, check back here for an addendum soon.", buttons2);
|
||||
|
||||
ftk_logd("%s: ret = %d\n", __func__, ret);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_question(void* ctx, void* obj)
|
||||
{
|
||||
int ret = ftk_question("Question", "Are you sure to quit?", buttons3);
|
||||
ftk_logd("%s: ret = %d\n", __func__, ret);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_tips(void* ctx, void* obj)
|
||||
{
|
||||
int ret = ftk_tips("The dialog will quit in 3 seconds.");
|
||||
ftk_logd("%s: ret = %d\n", __func__, ret);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_quit(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_msgbox_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("msgbox"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
int y = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
y = (height - 240)/2;
|
||||
y = y > 0 ? y : 0;
|
||||
|
||||
button = ftk_button_create(win, 0, y, width/2, 50);
|
||||
ftk_widget_set_text(button, "question");
|
||||
ftk_button_set_clicked_listener(button, button_question, win);
|
||||
|
||||
button = ftk_button_create(win, width/2, y, width/2, 50);
|
||||
ftk_widget_set_text(button, "warning");
|
||||
ftk_button_set_clicked_listener(button, button_warning, win);
|
||||
|
||||
button = ftk_button_create(win, 0, y+60, width/2, 50);
|
||||
ftk_widget_set_text(button, "info");
|
||||
ftk_button_set_clicked_listener(button, button_info, win);
|
||||
|
||||
button = ftk_button_create(win, width/2, y+60, width/2, 50);
|
||||
ftk_widget_set_text(button, "tips");
|
||||
ftk_button_set_clicked_listener(button, button_tips, win);
|
||||
|
||||
button = ftk_button_create(win, width/4, y+120, width/2, 50);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit, win);
|
||||
|
||||
ftk_widget_set_text(win, "message box demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
#include "ftk.h"
|
||||
|
||||
static void create_app_window(void);
|
||||
static Ret button_open_clicked(void* ctx, void* obj)
|
||||
{
|
||||
create_app_window();
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_close_clicked(void* ctx, void* obj)
|
||||
{
|
||||
FtkWidget* win = ctx;
|
||||
ftk_logd("%s: close window %s\n", __func__, ftk_widget_get_text(win));
|
||||
ftk_widget_unref(win);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static int g_index = 0;
|
||||
static void on_window_close(void* user_data)
|
||||
{
|
||||
g_index--;
|
||||
|
||||
ftk_logd("%s: g_index=%d\n", __func__, g_index);
|
||||
if(g_index == 0)
|
||||
{
|
||||
FTK_QUIT();
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
static void create_app_window(void)
|
||||
{
|
||||
char title[32] = {0};
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
FtkWidget* win = ftk_app_window_create();
|
||||
FtkWidget* label = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
button = ftk_button_create(win, 0, height/6, width/3, 50);
|
||||
ftk_widget_set_text(button, "创建窗口");
|
||||
ftk_button_set_clicked_listener(button, button_open_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, 2*width/3, height/6, width/3, 50);
|
||||
ftk_widget_set_text(button, "关闭窗口");
|
||||
ftk_button_set_clicked_listener(button, button_close_clicked, win);
|
||||
|
||||
snprintf(title, sizeof(title), "window%02d", g_index++);
|
||||
label = ftk_label_create(win, width/4, height/2, width/2, 30);
|
||||
ftk_widget_set_text(label, title);
|
||||
|
||||
ftk_widget_set_text(win, title);
|
||||
ftk_widget_show_all(win, 1);
|
||||
ftk_widget_set_user_data(win, on_window_close, win);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_multi_win_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("multi_win"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
create_app_window();
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
#include "ftk.h"
|
||||
|
||||
static Ret button_close_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static FtkListItemInfo g_infos[4];
|
||||
static Ret on_menu_item_clicked(void* ctx, void* data)
|
||||
{
|
||||
FtkListItemInfo* info = data;
|
||||
|
||||
ftk_logd("%s: %s is selected\n", __func__, info->text);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_normal_clicked(void* ctx, void* obj)
|
||||
{
|
||||
FtkBitmap* icon = ftk_theme_load_image(ftk_default_theme(), "info"FTK_STOCK_IMG_SUFFIX);
|
||||
FtkWidget* thiz = ftk_popup_menu_create(0, 0, 0, 200, icon, "Edit");
|
||||
|
||||
size_t i = 0;
|
||||
for(i = 0; i < FTK_ARRAY_SIZE(g_infos); i++)
|
||||
{
|
||||
g_infos[i].type = FTK_LIST_ITEM_NORMAL;
|
||||
ftk_popup_menu_add(thiz, g_infos+i);
|
||||
}
|
||||
ftk_bitmap_unref(icon);
|
||||
|
||||
ftk_widget_show_all(thiz, 1);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_radio_clicked(void* ctx, void* obj)
|
||||
{
|
||||
FtkBitmap* icon = ftk_theme_load_image(ftk_default_theme(), "info"FTK_STOCK_IMG_SUFFIX);
|
||||
FtkWidget* thiz = ftk_popup_menu_create(0, 0, 0, 200, icon, "Edit");
|
||||
|
||||
size_t i = 0;
|
||||
for(i = 0; i < FTK_ARRAY_SIZE(g_infos); i++)
|
||||
{
|
||||
g_infos[i].type = FTK_LIST_ITEM_RADIO;
|
||||
g_infos[i].state = i == 0;
|
||||
ftk_popup_menu_add(thiz, g_infos+i);
|
||||
}
|
||||
ftk_bitmap_unref(icon);
|
||||
|
||||
ftk_widget_show_all(thiz, 1);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_check_clicked(void* ctx, void* obj)
|
||||
{
|
||||
FtkBitmap* icon = ftk_theme_load_image(ftk_default_theme(), "info"FTK_STOCK_IMG_SUFFIX);
|
||||
FtkWidget* thiz = ftk_popup_menu_create(0, 0, 0, 200, icon, "Edit");
|
||||
|
||||
size_t i = 0;
|
||||
for(i = 0; i < FTK_ARRAY_SIZE(g_infos); i++)
|
||||
{
|
||||
g_infos[i].type = FTK_LIST_ITEM_CHECK;
|
||||
g_infos[i].state = i%2;
|
||||
ftk_popup_menu_add(thiz, g_infos+i);
|
||||
}
|
||||
ftk_bitmap_unref(icon);
|
||||
|
||||
ftk_widget_show_all(thiz, 1);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_popup_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("popup"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
g_infos[0].text = "Copy";
|
||||
g_infos[1].text = "Paste";
|
||||
g_infos[2].text = "Cut";
|
||||
g_infos[3].text = "Select All";
|
||||
g_infos[0].extra_user_data = on_menu_item_clicked;
|
||||
g_infos[1].extra_user_data = on_menu_item_clicked;
|
||||
g_infos[2].extra_user_data = on_menu_item_clicked;
|
||||
g_infos[3].extra_user_data = on_menu_item_clicked;
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
button = ftk_button_create(win, 0, height/6, width/3, 50);
|
||||
ftk_widget_set_text(button, "Normal");
|
||||
ftk_button_set_clicked_listener(button, button_normal_clicked, NULL);
|
||||
|
||||
button = ftk_button_create(win, 2*width/3, height/6, width/3, 50);
|
||||
ftk_widget_set_text(button, "Radio");
|
||||
ftk_button_set_clicked_listener(button, button_radio_clicked, NULL);
|
||||
|
||||
button = ftk_button_create(win, 0, height/2, width/3, 50);
|
||||
ftk_widget_set_text(button, "CheckBox");
|
||||
ftk_button_set_clicked_listener(button, button_check_clicked, NULL);
|
||||
|
||||
button = ftk_button_create(win, 2*width/3, height/2, width/3, 50);
|
||||
ftk_widget_set_text(button, "Quit");
|
||||
ftk_button_set_clicked_listener(button, button_close_clicked, win);
|
||||
|
||||
ftk_widget_set_text(win, "pupup");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
#include "ftk.h"
|
||||
#include "ftk_util.h"
|
||||
|
||||
static void on_window_destroy(void* user_data)
|
||||
{
|
||||
FtkSource* timer = user_data;
|
||||
|
||||
ftk_source_disable(timer);
|
||||
ftk_main_loop_remove_source(ftk_default_main_loop(), timer);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static Ret update_progress(void* ctx)
|
||||
{
|
||||
int percent = 0;
|
||||
char text[32] = {0};
|
||||
FtkWidget* progress_bar = ctx;
|
||||
|
||||
percent = ftk_progress_bar_get_percent(progress_bar);
|
||||
if(percent == 100)
|
||||
{
|
||||
return RET_REMOVE;
|
||||
}
|
||||
ftk_progress_bar_set_percent(progress_bar, percent + 10);
|
||||
|
||||
ftk_itoa(text, sizeof(text), ftk_progress_bar_get_percent(progress_bar));
|
||||
strcat(text, "%");
|
||||
ftk_widget_set_text(progress_bar, text);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_progress_bar_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("progress_bar"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* progress_bar = NULL;
|
||||
FtkSource* timer = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
width = width - 20;
|
||||
progress_bar = ftk_progress_bar_create(win, 10, height/6, width, 20);
|
||||
ftk_progress_bar_set_percent(progress_bar, 20);
|
||||
timer = ftk_source_timer_create(1000, update_progress, progress_bar);
|
||||
ftk_main_loop_add_source(ftk_default_main_loop(), timer);
|
||||
ftk_widget_set_user_data(progress_bar, on_window_destroy, timer);
|
||||
|
||||
progress_bar = ftk_progress_bar_create(win, 10, height/3, width, 20);
|
||||
ftk_progress_bar_set_percent(progress_bar, 20);
|
||||
timer = ftk_source_timer_create(1000, update_progress, progress_bar);
|
||||
ftk_main_loop_add_source(ftk_default_main_loop(), timer);
|
||||
ftk_widget_set_user_data(progress_bar, on_window_destroy, timer);
|
||||
ftk_progress_bar_set_interactive(progress_bar, 1);
|
||||
|
||||
progress_bar = ftk_progress_bar_create(win, 10, height/2, width, 20);
|
||||
ftk_progress_bar_set_percent(progress_bar, 20);
|
||||
timer = ftk_source_timer_create(1000, update_progress, progress_bar);
|
||||
ftk_main_loop_add_source(ftk_default_main_loop(), timer);
|
||||
ftk_widget_set_user_data(progress_bar, on_window_destroy, timer);
|
||||
|
||||
ftk_widget_set_text(win, "progress_bar demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
#include "ftk.h"
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret scroll_bar_on_scroll(void* ctx, void* scroll_bar)
|
||||
{
|
||||
ftk_logd("%s: value=%d\n", __func__, ftk_scroll_bar_get_value(scroll_bar));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_scroll_bar_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("scroll_bar"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
FtkWidget* scroll_bar = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
/*v*/
|
||||
scroll_bar = ftk_scroll_bar_create(win, width/8, 5, 0, height/2);
|
||||
ftk_scroll_bar_set_param(scroll_bar, 0, 120, 120);
|
||||
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
|
||||
|
||||
scroll_bar = ftk_scroll_bar_create(win, width/4, 5, 0, height/2);
|
||||
ftk_scroll_bar_set_param(scroll_bar, 40, 120, 60);
|
||||
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
|
||||
|
||||
scroll_bar = ftk_scroll_bar_create(win, 3*width/8, 5, 0, height/2);
|
||||
ftk_scroll_bar_set_param(scroll_bar, 110, 120, 30);
|
||||
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
|
||||
|
||||
scroll_bar = ftk_scroll_bar_create(win, width/2, 5, 0, height/2);
|
||||
ftk_scroll_bar_set_param(scroll_bar, 120, 120, 20);
|
||||
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
|
||||
|
||||
/*h*/
|
||||
scroll_bar = ftk_scroll_bar_create(win, 5, height/2 + 10, width - 10, 0);
|
||||
ftk_scroll_bar_set_param(scroll_bar, 120, 120, 20);
|
||||
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
|
||||
|
||||
scroll_bar = ftk_scroll_bar_create(win, 5, height/2 + 30, width - 10, 0);
|
||||
ftk_scroll_bar_set_param(scroll_bar, 110, 120, 30);
|
||||
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
|
||||
|
||||
scroll_bar = ftk_scroll_bar_create(win, 5, height/2 + 50, width - 10, 0);
|
||||
ftk_scroll_bar_set_param(scroll_bar, 40, 120, 60);
|
||||
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
|
||||
|
||||
scroll_bar = ftk_scroll_bar_create(win, 5, height/2 + 80, width - 10, 0);
|
||||
ftk_scroll_bar_set_param(scroll_bar, 0, 120, 120);
|
||||
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
|
||||
|
||||
button = ftk_button_create(win, 2*width/3, height/4, width/3-5, 50);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
ftk_window_set_focus(win, button);
|
||||
|
||||
ftk_widget_set_text(win, "scroll_bar demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
#include "ftk.h"
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
Ret on_move(void* ctx, void* obj)
|
||||
{
|
||||
ftk_logd("%s: %d %d\n", __func__, ftk_sprite_get_x(obj), ftk_sprite_get_y(obj));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
Ret move_cursor(void* ctx, void* obj)
|
||||
{
|
||||
FtkEvent* event = obj;
|
||||
|
||||
if(event->type == FTK_EVT_MOUSE_MOVE)
|
||||
{
|
||||
ftk_sprite_move(ctx, event->u.mouse.x, event->u.mouse.y);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_sprite_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("sprite"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
FtkSprite* sprite = NULL;
|
||||
FtkBitmap* icon = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
button = ftk_button_create(win, width/4, height/2, width/2, 60);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
ftk_window_set_focus(win, button);
|
||||
|
||||
ftk_widget_set_text(win, "sprite demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
#if 0
|
||||
/*multi sprite still has some problems.*/
|
||||
sprite = ftk_sprite_create();
|
||||
icon=ftk_theme_load_image(ftk_default_theme(), "flag-32"FTK_STOCK_IMG_SUFFIX);
|
||||
ftk_sprite_set_icon(sprite, icon);
|
||||
ftk_sprite_move(sprite, width/2, 0);
|
||||
ftk_sprite_set_move_listener(sprite, on_move, NULL);
|
||||
ftk_sprite_show(sprite, 1);
|
||||
ftk_main_loop_add_source(ftk_default_main_loop(), ftk_source_timer_create(200, timer, sprite));
|
||||
#endif
|
||||
|
||||
sprite = ftk_sprite_create();
|
||||
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(), move_cursor, sprite);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
#include "ftk.h"
|
||||
#include <time.h>
|
||||
|
||||
#define IDC_TIME_ITEM 2000
|
||||
|
||||
static Ret update_time(void* ctx)
|
||||
{
|
||||
char text[10] = {0};
|
||||
FtkWidget* item = NULL;
|
||||
FtkWidget* panel = NULL;
|
||||
|
||||
time_t now = time(0);
|
||||
struct tm* t = localtime(&now);
|
||||
panel = ftk_default_status_panel();
|
||||
|
||||
snprintf(text, sizeof(text)-1, "%2d:%2d", t->tm_hour, t->tm_min);
|
||||
|
||||
item = ftk_widget_lookup(panel, IDC_TIME_ITEM);
|
||||
|
||||
ftk_widget_set_text(item, text);
|
||||
|
||||
ftk_logd("%s: %s\n", __func__, text);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_statusbar_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("status_bar"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
FtkSource* timer = NULL;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* item = NULL;
|
||||
FtkWidget* panel = NULL;
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
/*create a time widget in statusbar.*/
|
||||
panel = ftk_default_status_panel();
|
||||
item = ftk_status_item_create(panel, -2, 60);
|
||||
ftk_widget_set_id(item, IDC_TIME_ITEM);
|
||||
|
||||
ftk_widget_show(item, 1);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
ftk_widget_set_text(win, "Hello FTK!");
|
||||
|
||||
ftk_widget_show(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
update_time(NULL);
|
||||
timer = ftk_source_timer_create(60000, update_time, NULL);
|
||||
ftk_main_loop_add_source(ftk_default_main_loop(), timer);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
#include "ftk.h"
|
||||
#include "ftk_tab.h"
|
||||
|
||||
static Ret button_default_clicked(void* ctx, void* obj)
|
||||
{
|
||||
printf("%s: button %s is clicked.\n", __func__, ftk_widget_get_text(obj));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_tab_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("tab"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
|
||||
static void add_page(FtkWidget* tab, const char* text, FtkBitmap* bitmap)
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
FtkWidget* page = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
|
||||
page = ftk_tab_add_page(tab, text, bitmap);
|
||||
width = ftk_widget_width(page);
|
||||
height = ftk_widget_height(page);
|
||||
|
||||
button = ftk_button_create(page, 0, height/2-30, width/2, 60);
|
||||
ftk_widget_set_text(button, text);
|
||||
ftk_widget_show(button, 1);
|
||||
ftk_button_set_clicked_listener(button, button_default_clicked, tab);
|
||||
|
||||
button = ftk_button_create(page, width/2, height/2-30, width/2, 60);
|
||||
ftk_widget_set_text(button, text);
|
||||
ftk_widget_show(button, 1);
|
||||
ftk_button_set_clicked_listener(button, button_default_clicked, tab);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* tab = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
FtkBitmap* bitmap = NULL;
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
bitmap = ftk_theme_load_image(ftk_default_theme(), "mime_audio"FTK_STOCK_IMG_SUFFIX);
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
tab = ftk_tab_create(win, 0, 0, width, height - 50);
|
||||
|
||||
add_page(tab, "General", bitmap);
|
||||
add_page(tab, "Graphic", bitmap);
|
||||
add_page(tab, "Audio", bitmap);
|
||||
|
||||
ftk_tab_set_active_page(tab, 0);
|
||||
|
||||
button = ftk_button_create(win, width/4, height - 50, width/2, 50);
|
||||
ftk_widget_set_text(button, _("Quit"));
|
||||
ftk_widget_show(button, 1);
|
||||
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
FTK_BITMAP_UNREF(bitmap);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
#include "ftk.h"
|
||||
#include <assert.h>
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#define TEXT_STR "libpng is the official PNG reference library. It supports almost all PNG features, is extensible, and has been extensively tested for over 15 years. The home site for development versions (i.e., may be buggy or subject to change or include experimental features) is http://libpng.sourceforge.net/, and the place to go for questions about the library is the png-mng-implement mailing list.\n\nlibpng is available as ANSI C (C89) source code and requires zlib 1.0.4 or later (1.2.3 or later recommended for performance and security reasons). The current public release, libpng 1.4.3, contains fixes for two potential security issues: "
|
||||
|
||||
#define TEXT1_STR "Several versions of libpng through 1.4.2 (and through 1.2.43 in the older series) contain a bug whereby progressive applications such as web browsers (or the rpng2 demo app included in libpng) could receive an extra row of image data beyond the height reported in the header, potentially leading to an out-of-bounds write to memory (depending on how the application is written) and the possibility of execution of an attacker's code with the privileges of the libpng user (including remote compromise in the case of a libpng-based browser visiting a hostile web site). This vulnerability has been assigned ID CVE-2010-1205 (via Mozilla). \n\n4\n5\n6\n7\n8\nlast line"
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_text_view_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("text_view"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
FtkWidget* text_view = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
text_view = ftk_text_view_create(win, 10, 10, ftk_widget_width(win) - 20, height/3);
|
||||
ftk_widget_set_text(text_view, TEXT1_STR);
|
||||
assert(strcmp(TEXT1_STR, ftk_widget_get_text(text_view)) == 0);
|
||||
|
||||
text_view = ftk_text_view_create(win, 10, 15 + height/3, ftk_widget_width(win) - 20, height/3);
|
||||
ftk_widget_set_text(text_view, TEXT_STR);
|
||||
assert(strcmp(TEXT_STR, ftk_widget_get_text(text_view)) == 0);
|
||||
ftk_text_view_set_readonly(text_view, 1);
|
||||
|
||||
button = ftk_button_create(win, width/4, 3*height/4, width/2, 60);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
ftk_window_set_focus(win, button);
|
||||
|
||||
ftk_widget_set_text(win, "text_view demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
#include "ftk.h"
|
||||
|
||||
void create_dialog(FtkBitmap* bitmap, FtkColor bg);
|
||||
static void create_app_window(void);
|
||||
|
||||
static Ret button_open_image_dialog(void* ctx, void* obj)
|
||||
{
|
||||
char filename[FTK_MAX_PATH+1] = {0};
|
||||
FtkBitmap* bitmap = NULL;
|
||||
FtkColor bg = {0};
|
||||
bg.r = 0xff;
|
||||
bg.g = 0xff;
|
||||
bg.b = 0xff;
|
||||
ftk_snprintf(filename, FTK_MAX_PATH, "%s/earth.png",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()));
|
||||
bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
|
||||
bg.a = 0x0;
|
||||
create_dialog(bitmap, bg);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_open_transparent_dialog(void* ctx, void* obj)
|
||||
{
|
||||
FtkColor bg = {0};
|
||||
bg.a = 0x80;
|
||||
bg.r = 0xff;
|
||||
bg.g = 0xff;
|
||||
bg.b = 0xff;
|
||||
create_dialog(NULL, bg);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
*(int*)ctx = ftk_widget_id(obj);
|
||||
|
||||
return RET_QUIT;
|
||||
}
|
||||
|
||||
static Ret button_close_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void create_dialog(FtkBitmap* bitmap, FtkColor bg)
|
||||
{
|
||||
int id = 0;
|
||||
int width = ftk_display_width(ftk_default_display());
|
||||
int height = ftk_display_height(ftk_default_display());
|
||||
FtkWidget* button = NULL;
|
||||
FtkWidget* label = NULL;
|
||||
FtkWidget* dialog = ftk_dialog_create(0, 5, 320, height-60);
|
||||
|
||||
ftk_widget_set_attr(dialog, FTK_ATTR_BG_CENTER);
|
||||
ftk_window_set_background_with_alpha(dialog, bitmap, bg);
|
||||
|
||||
width = ftk_widget_width(dialog);
|
||||
height = ftk_widget_height(dialog);
|
||||
|
||||
//label = ftk_label_create(dialog, width/8, height/4, 3*width/4, 20);
|
||||
//ftk_widget_set_text(label, "Are you sure to quit?");
|
||||
|
||||
label = ftk_label_create(dialog, width/8, height/2, 3*width/4, 20);
|
||||
ftk_widget_set_text(label, "Are you sure to quit?");
|
||||
|
||||
button = ftk_button_create(dialog, width/6, 3*height/4, width/3, 50);
|
||||
ftk_widget_set_text(button, "yes");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, &id);
|
||||
|
||||
button = ftk_button_create(dialog, width/2, 3*height/4, width/3, 50);
|
||||
ftk_widget_set_text(button, "no");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, &id);
|
||||
ftk_window_set_focus(dialog, button);
|
||||
|
||||
ftk_widget_set_text(dialog, "transparent demo");
|
||||
ftk_widget_show_all(dialog, 1);
|
||||
|
||||
assert(ftk_dialog_run(dialog) == id);
|
||||
ftk_widget_unref(dialog);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void create_app_window(void)
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
FtkWidget* win = ftk_app_window_create();
|
||||
FtkWidget* button = NULL;
|
||||
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
button = ftk_button_create(win, 0, height/6, width/3, 50);
|
||||
ftk_widget_set_text(button, "图片背景");
|
||||
ftk_button_set_clicked_listener(button, button_open_image_dialog, win);
|
||||
|
||||
button = ftk_button_create(win, 2*width/3, height/6, width/3, 50);
|
||||
ftk_widget_set_text(button, "半透明效果");
|
||||
ftk_button_set_clicked_listener(button, button_open_transparent_dialog, win);
|
||||
|
||||
button = ftk_button_create(win, width/4, height/2, width/2, 60);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_close_clicked, win);
|
||||
|
||||
ftk_widget_set_text(win, "transparent");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_transparent_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("transparent"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
create_app_window();
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
#include "ftk.h"
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_start_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_show(ctx, 1);
|
||||
ftk_wait_box_start_waiting(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_stop_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_wait_box_stop_waiting(ctx);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_wait_box_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("wait_box"), 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;
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* button = NULL;
|
||||
FtkWidget* wait_box = NULL;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
win = ftk_app_window_create();
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
wait_box = ftk_wait_box_create(win, width/2 - 16, height/4);
|
||||
|
||||
button = ftk_button_create(win, 0, height/2, width/3, 50);
|
||||
ftk_widget_set_text(button, "start");
|
||||
ftk_button_set_clicked_listener(button, button_start_clicked, wait_box);
|
||||
|
||||
button = ftk_button_create(win, 2*width/3, height/2, width/3, 50);
|
||||
ftk_widget_set_text(button, "stop");
|
||||
ftk_button_set_clicked_listener(button, button_stop_clicked, wait_box);
|
||||
|
||||
button = ftk_button_create(win, width/4, 3*height/4, width/2, 60);
|
||||
ftk_widget_set_text(button, "quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
ftk_window_set_focus(win, button);
|
||||
|
||||
ftk_widget_set_text(win, "wait_box demo");
|
||||
ftk_widget_show_all(win, 1);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
#include "ftk.h"
|
||||
#include "ftk_xul.h"
|
||||
|
||||
const char* t1 = "<window> </window>";
|
||||
|
||||
#define IDC_QUIT 100
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
ftk_widget_unref(ctx);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_xul_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("xul"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
if(argc > 1)
|
||||
{
|
||||
FtkWidget* win = NULL;
|
||||
FtkWidget* quit = NULL;
|
||||
FtkXulCallbacks callbacks;
|
||||
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
callbacks.translate_text = NULL;
|
||||
callbacks.load_image = (FtkXulLoadImage)ftk_icon_cache_load;
|
||||
callbacks.ctx = ftk_icon_cache_create(NULL, "testdata");
|
||||
win = ftk_xul_load_file(argv[1], &callbacks);
|
||||
ftk_icon_cache_destroy(callbacks.ctx);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
quit = ftk_widget_lookup(win, IDC_QUIT);
|
||||
ftk_button_set_clicked_listener(quit, button_quit_clicked, win);
|
||||
ftk_widget_show_all(win, 1);
|
||||
|
||||
FTK_RUN();
|
||||
}
|
||||
else
|
||||
{
|
||||
ftk_logd("Usage: %s xul\n", argv[0]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
#include "ftk.h"
|
||||
#include "ftk_animator_zoom.h"
|
||||
|
||||
static void create_ani_window(int type, int sync);
|
||||
|
||||
static Ret button_to_zoom_in_clicked(void* ctx, void* obj)
|
||||
{
|
||||
create_ani_window(FTK_ANI_ZOOM_IN, 1);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_to_zoom_out_clicked(void* ctx, void* obj)
|
||||
{
|
||||
create_ani_window(FTK_ANI_ZOOM_OUT, 1);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_close_clicked(void* ctx, void* obj)
|
||||
{
|
||||
FtkWidget* win = ctx;
|
||||
ftk_logd("%s: close window %s\n", __func__, ftk_widget_get_text(win));
|
||||
ftk_widget_unref(win);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static Ret button_quit_clicked(void* ctx, void* obj)
|
||||
{
|
||||
FtkWidget* win = ctx;
|
||||
ftk_widget_unref(win);
|
||||
ftk_logd("%s: close window %s\n", __func__, ftk_widget_get_text(win));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static void create_ani_window(int type, int sync)
|
||||
{
|
||||
int delta = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
FtkWidget* button = NULL;
|
||||
FtkGc gc = {0};
|
||||
char filename[FTK_MAX_PATH+1] = {0};
|
||||
FtkWidget* win = ftk_app_window_create();
|
||||
FtkAnimator* ani = ftk_animator_zoom_create(1);
|
||||
|
||||
gc.mask = FTK_GC_BITMAP;
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
delta = height/6;
|
||||
|
||||
button = ftk_button_create(win, width/3, height/3, width/3, 50);
|
||||
ftk_widget_set_text(button, "关闭");
|
||||
ftk_widget_show(button, 1);
|
||||
ftk_button_set_clicked_listener(button, button_close_clicked, win);
|
||||
|
||||
ftk_snprintf(filename, FTK_MAX_PATH, "%s/jpeg1.jpg",
|
||||
ftk_config_get_test_data_dir(ftk_default_config()));
|
||||
gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
|
||||
ftk_widget_set_gc(win, FTK_WIDGET_NORMAL, &gc);
|
||||
ftk_gc_reset(&gc);
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case FTK_ANI_ZOOM_IN:
|
||||
{
|
||||
ftk_animator_set_param(ani, type, 10, 100, delta, 200);
|
||||
break;
|
||||
}
|
||||
case FTK_ANI_ZOOM_OUT:
|
||||
{
|
||||
ftk_animator_set_param(ani, type, 10, 100, delta, 200);
|
||||
break;
|
||||
}
|
||||
default:break;
|
||||
}
|
||||
ftk_animator_start(ani, win, 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void create_app_window(void)
|
||||
{
|
||||
char title[32] = {0};
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
FtkWidget* win = ftk_app_window_create();
|
||||
FtkWidget* button = NULL;
|
||||
|
||||
width = ftk_widget_width(win);
|
||||
height = ftk_widget_height(win);
|
||||
|
||||
button = ftk_button_create(win, 5, height/6 + 60, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "ZoomIn");
|
||||
ftk_button_set_clicked_listener(button, button_to_zoom_in_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width/2, height/6 + 60, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "ZoomOut");
|
||||
ftk_button_set_clicked_listener(button, button_to_zoom_out_clicked, win);
|
||||
|
||||
button = ftk_button_create(win, width/4-2, height/6 + 180, width/2-5, 50);
|
||||
ftk_widget_set_text(button, "Quit");
|
||||
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
|
||||
|
||||
ftk_snprintf(title, sizeof(title), "Zoom Demo");
|
||||
ftk_widget_set_text(win, title);
|
||||
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
|
||||
|
||||
ftk_widget_show_all(win, 1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef FTK_AS_PLUGIN
|
||||
#include "ftk_app_demo.h"
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_zoom_create()
|
||||
{
|
||||
return ftk_app_demo_create(_("zoom"), ftk_main);
|
||||
}
|
||||
#else
|
||||
#define FTK_HIDE extern
|
||||
#endif /*FTK_AS_PLUGIN*/
|
||||
|
||||
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
|
||||
{
|
||||
FTK_INIT(argc, argv);
|
||||
|
||||
create_app_window();
|
||||
|
||||
FTK_RUN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<application name="alpha" exec="libftk_demos.so" init="ftk_app_demo_alpha_create" />
|
||||
<application name="button" exec="libftk_demos.so" init="ftk_app_demo_button_create" />
|
||||
<application name="cairo" exec="libftk_demos.so" init="ftk_app_demo_cairo_create" />
|
||||
<application name="check_button" exec="libftk_demos.so" init="ftk_app_demo_check_button_create" />
|
||||
<application name="combo_box" exec="libftk_demos.so" init="ftk_app_demo_combo_box_create" />
|
||||
<application name="dialog" exec="libftk_demos.so" init="ftk_app_demo_dialog_create" />
|
||||
<application name="entry" exec="libftk_demos.so" init="ftk_app_demo_entry_create" />
|
||||
<application name="expand" exec="libftk_demos.so" init="ftk_app_demo_expand_create" />
|
||||
<application name="file_browser" exec="libftk_demos.so" init="ftk_app_demo_file_browser_create" />
|
||||
<application name="fullscreen" exec="libftk_demos.so" init="ftk_app_demo_fullscreen_create" />
|
||||
<application name="hello" exec="libftk_demos.so" init="ftk_app_demo_hello_create" />
|
||||
<application name="icon_view" exec="libftk_demos.so" init="ftk_app_demo_icon_view_create" />
|
||||
<application name="image_button" exec="libftk_demos.so" init="ftk_app_demo_image_button_create" />
|
||||
<application name="image" exec="libftk_demos.so" init="ftk_app_demo_image_create" />
|
||||
<application name="ime" exec="libftk_demos.so" init="ftk_app_demo_ime_create" />
|
||||
<application name="label" exec="libftk_demos.so" init="ftk_app_demo_label_create" />
|
||||
<application name="listview" exec="libftk_demos.so" init="ftk_app_demo_listview_create" />
|
||||
<application name="menu" exec="libftk_demos.so" init="ftk_app_demo_menu_create" />
|
||||
<application name="msgbox" exec="libftk_demos.so" init="ftk_app_demo_msgbox_create" />
|
||||
<application name="multi_win" exec="libftk_demos.so" init="ftk_app_demo_multi_win_create" />
|
||||
<application name="popup" exec="libftk_demos.so" init="ftk_app_demo_popup_create" />
|
||||
<application name="progress_bar" exec="libftk_demos.so" init="ftk_app_demo_progress_bar_create" />
|
||||
<application name="scroll_bar" exec="libftk_demos.so" init="ftk_app_demo_scroll_bar_create" />
|
||||
<application name="sprite" exec="libftk_demos.so" init="ftk_app_demo_sprite_create" />
|
||||
<application name="statusbar" exec="libftk_demos.so" init="ftk_app_demo_statusbar_create" />
|
||||
<application name="text_view" exec="libftk_demos.so" init="ftk_app_demo_text_view_create" />
|
||||
<application name="transparent" exec="libftk_demos.so" init="ftk_app_demo_transparent_create" />
|
||||
<application name="wait_box" exec="libftk_demos.so" init="ftk_app_demo_wait_box_create" />
|
||||
<application name="zoom" exec="libftk_demos.so" init="ftk_app_demo_zoom_create" />
|
||||
<application name="tab" exec="libftk_demos.so" init="ftk_app_demo_tab_create" />
|
|
@ -0,0 +1,67 @@
|
|||
#include "ftk_app_demo.h"
|
||||
|
||||
typedef struct _PrivInfo
|
||||
{
|
||||
char* name;
|
||||
FtkMain ftk_main;
|
||||
FtkBitmap* icon;
|
||||
}PrivInfo;
|
||||
|
||||
static FtkBitmap* ftk_app_demo_get_icon(FtkApp* thiz)
|
||||
{
|
||||
DECL_PRIV(thiz, priv);
|
||||
return_val_if_fail(priv != NULL, NULL);
|
||||
|
||||
return priv->icon;
|
||||
}
|
||||
|
||||
static const char* ftk_app_demo_get_name(FtkApp* thiz)
|
||||
{
|
||||
DECL_PRIV(thiz, priv);
|
||||
return_val_if_fail(priv != NULL, NULL);
|
||||
|
||||
return priv->name;
|
||||
}
|
||||
|
||||
static Ret ftk_app_demo_run(FtkApp* thiz, int argc, char* argv[])
|
||||
{
|
||||
DECL_PRIV(thiz, priv);
|
||||
return_val_if_fail(priv != NULL, RET_FAIL);
|
||||
|
||||
priv->ftk_main(argc, argv);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static void ftk_app_demo_destroy(FtkApp* thiz)
|
||||
{
|
||||
if(thiz != NULL)
|
||||
{
|
||||
DECL_PRIV(thiz, priv);
|
||||
FTK_FREE(priv->name);
|
||||
ftk_bitmap_unref(priv->icon);
|
||||
FTK_FREE(thiz);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef FTK_APP_DEMO_H
|
||||
#define FTK_APP_DEMO_H
|
||||
|
||||
#include "ftk_app.h"
|
||||
|
||||
#define FTK_HIDE static
|
||||
|
||||
typedef int (*FtkMain)(int argc, char* argv[]);
|
||||
FtkApp* ftk_app_demo_create(const char* name, FtkMain main);
|
||||
|
||||
#endif/*FTK_APP_DEMO_H*/
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<window value="Entry Label" animator="$FTK_ANI_TO_UP" visible="1">
|
||||
<label id="1" x="5" y="5" w="$ww/4" h="30" value="Name" />
|
||||
<entry id="2" x="$ww/4+5" y="5" w="3*$ww/4-15" h="30" value="Li XianJing" />
|
||||
|
||||
<label id="3" x="5" y="40" w="$ww/4" h="30" value="EMail" />
|
||||
<entry id="4" x="$ww/4+5" y="40" w="3*$ww/4-15" h="30" value="xianjimli@hotmail.com" />
|
||||
|
||||
<label id="5" x="5" y="75" w="$ww/4" h="30" value="Mobile" />
|
||||
<entry id="6" x="$ww/4+5" y="75" w="3*$ww/4-15" h="30" value="+8613911112222" />
|
||||
|
||||
<button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" attr="$FTK_ATTR_INSENSITIVE" value="Save" />
|
||||
<button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" attr="$FTK_ATTR_FOCUSED" value="Quit" />
|
||||
</window>
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<window value="ProgressBar">
|
||||
<label id="1" x="5" y="5" w="$ww/4" h="30" value="Progress1" />
|
||||
<progress_bar id="2" x="$ww/4+5" y="5" w="3*$ww/4-15" h="30" value="0" />
|
||||
|
||||
<label id="3" x="5" y="40" w="$ww/4" h="30" value="Progress2" />
|
||||
<progress_bar id="4" x="$ww/4+5" y="40" w="3*$ww/4-15" h="30" value="50" />
|
||||
|
||||
<label id="5" x="5" y="75" w="$ww/4" h="30" value="Progress3" />
|
||||
<progress_bar id="6" x="$ww/4+5" y="75" w="3*$ww/4-15" h="30" value="100" />
|
||||
|
||||
<button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" value="Save" />
|
||||
<button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" value="Quit" />
|
||||
</window>
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<window value="Wait box">
|
||||
<wait_box id="1" x="5" y="5" w="$ww/4" h="30" value="1" />
|
||||
<progress_bar id="2" x="$ww/4+5" y="5" w="3*$ww/4-15" h="30" value="0" />
|
||||
|
||||
<wait_box id="3" x="5" y="40" w="$ww/4" h="30" value="0" />
|
||||
<progress_bar id="4" x="$ww/4+5" y="40" w="3*$ww/4-15" h="30" value="50" />
|
||||
|
||||
<wait_box id="5" x="5" y="75" w="$ww/4" h="30" value="1" />
|
||||
<progress_bar id="6" x="$ww/4+5" y="75" w="3*$ww/4-15" h="30" value="100" />
|
||||
|
||||
<button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" value="Save" />
|
||||
<button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" value="Quit" />
|
||||
</window>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<window value="Image">
|
||||
<image id="1" x="0" y="5" w="$ww/2" h="3*$wh/4-5" value="jpeg1.jpg" />
|
||||
<image id="1" x="$ww/2" y="5" w="$ww/2" h="3*$wh/4-5" attr="$FTK_ATTR_BG_CENTER" value="Acrobat.png" />
|
||||
|
||||
<button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" value="Save" />
|
||||
<button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" value="Quit" />
|
||||
</window>
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<window value="Check button">
|
||||
<check_button id="1" x="5" y="10" w="$ww/2" h="50" checked="1" value="Check Option1" />
|
||||
<check_button id="3" x="5" y="60" w="$ww/2" h="50" checked="0" value="Check Option2" />
|
||||
<check_button id="5" x="5" y="110" w="$ww/2" h="50" checked="1" value="Check Option3" />
|
||||
|
||||
<button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" value="Save" />
|
||||
<button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" value="Quit" />
|
||||
</window>
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<window value="Radio button">
|
||||
<radio_group x="0" y="0" w="$ww" h="$wh/3">
|
||||
<radio_button id="1" x="5" y="10" w="$ww/2" h="50" checked="1" value="Radio Option1" />
|
||||
<radio_button id="3" x="5" y="60" w="$ww/2" h="50" checked="0" value="Radio Option2" />
|
||||
</radio_group>
|
||||
|
||||
<radio_group x="0" y="$wh/3+5" w="$ww" h="$wh/3">
|
||||
<radio_button id="1" x="5" y="10" w="$ww/2" h="50" checked="1" value="Radio Option1" />
|
||||
<radio_button id="3" x="5" y="60" w="$ww/2" h="50" checked="0" value="Radio Option2" />
|
||||
</radio_group>
|
||||
|
||||
<button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" value="Save" />
|
||||
<button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" value="Quit" />
|
||||
</window>
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<window value="background">
|
||||
<button id="99" x="5" y="30" w="64" h="64" attr="$FTK_ATTR_INSENSITIVE"
|
||||
bg_image[disable]="Flickr.png" bg[disable]="ffff0000"/>
|
||||
|
||||
<button id="99" x="$ww/2-32" y="30" w="64" h="64"
|
||||
bg[normal]="ffff0000" bg[focused]="ff00ff00" bg[active]="ff0000ff"
|
||||
bg_image[normal]="Acrobat.png" bg_image[focused]="Chat.png" bg_image[active]="Flickr.png" />
|
||||
|
||||
<button id="99" x="$ww-70" y="30" w="64" h="64"
|
||||
bg_image[normal]="Acrobat.png" bg_image[focused]="Chat.png" bg_image[active]="Flickr.png" />
|
||||
|
||||
<button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" value="Save" />
|
||||
<button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" value="Quit" />
|
||||
</window>
|
|
@ -0,0 +1,21 @@
|
|||
#include <stdio.h>
|
||||
|
||||
char* read_file(const char* file_name, int* length)
|
||||
{
|
||||
struct stat st = {0};
|
||||
if(stat(file_name, &st))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
char* buffer = malloc(st.st_size + 1);
|
||||
FILE* fp = fopen(file_name, "rb");
|
||||
fread(buffer, 1, st.st_size, fp);
|
||||
fclose(fp);
|
||||
buffer[st.st_size] = '\0';
|
||||
*length = st.st_size;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue