2020-05-26 16:44:37 +08:00
|
|
|
|
/**
|
2018-03-09 21:54:46 +08:00
|
|
|
|
* File: demo1_app.c
|
2018-05-15 09:31:58 +08:00
|
|
|
|
* Author: AWTK Develop Team
|
2019-08-08 10:53:54 +08:00
|
|
|
|
* Brief: demoui
|
2018-03-09 21:54:46 +08:00
|
|
|
|
*
|
2020-01-01 11:27:36 +08:00
|
|
|
|
* Copyright (c) 2018 - 2020 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
2018-03-09 21:54:46 +08:00
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* License file for more details.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* History:
|
|
|
|
|
* ================================================================
|
|
|
|
|
* 2018-02-16 Li XianJing <xianjimli@hotmail.com> created
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-04-07 09:36:45 +08:00
|
|
|
|
/*
|
|
|
|
|
* XXX: 本示例只是为了展示功能,不适合作为编写代码参考,编写代码请参考:https://github.com/zlgopen/awtk-c-demos
|
|
|
|
|
*/
|
|
|
|
|
|
2018-11-11 18:03:17 +08:00
|
|
|
|
#include "awtk.h"
|
2018-08-23 15:33:08 +08:00
|
|
|
|
#include "ext_widgets.h"
|
2020-06-27 11:00:37 +08:00
|
|
|
|
#include "base/font_manager.h"
|
2020-05-18 12:32:42 +08:00
|
|
|
|
#include "base/event_recorder_player.h"
|
2018-03-09 21:54:46 +08:00
|
|
|
|
|
2019-07-16 18:07:52 +08:00
|
|
|
|
static ret_t on_clone_tab(void* ctx, event_t* e);
|
2019-07-17 07:01:07 +08:00
|
|
|
|
static ret_t widget_clone_tab(widget_t* widget);
|
2018-06-08 17:03:06 +08:00
|
|
|
|
static void install_click_hander(widget_t* widget);
|
2020-01-15 08:52:37 +08:00
|
|
|
|
static void open_window(const char* name, widget_t* to_close);
|
2018-06-06 16:18:14 +08:00
|
|
|
|
|
2018-10-04 11:14:59 +08:00
|
|
|
|
uint32_t tk_mem_speed_test(void* buffer, uint32_t length, uint32_t* pmemcpy_speed,
|
|
|
|
|
uint32_t* pmemset_speed) {
|
|
|
|
|
uint32_t i = 0;
|
|
|
|
|
uint32_t cost = 0;
|
|
|
|
|
uint32_t total_cost = 0;
|
|
|
|
|
uint32_t memcpy_speed;
|
|
|
|
|
uint32_t memset_speed;
|
|
|
|
|
uint32_t max_size = 100 * 1024 * 1024;
|
2019-09-04 14:17:18 +08:00
|
|
|
|
uint64_t start = time_now_ms();
|
2018-10-04 11:14:59 +08:00
|
|
|
|
uint32_t nr = max_size / length;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nr; i++) {
|
|
|
|
|
memset(buffer, 0x00, length);
|
|
|
|
|
}
|
|
|
|
|
cost = time_now_ms() - start;
|
|
|
|
|
total_cost = cost;
|
|
|
|
|
if (cost) {
|
|
|
|
|
memset_speed = ((max_size / cost) * 1000) / 1024;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
start = time_now_ms();
|
|
|
|
|
for (i = 0; i < nr; i++) {
|
|
|
|
|
uint32_t half = length >> 1;
|
|
|
|
|
memcpy(buffer, (char*)buffer + half, half);
|
|
|
|
|
memcpy((char*)buffer + half, buffer, half);
|
|
|
|
|
}
|
|
|
|
|
cost = time_now_ms() - start;
|
|
|
|
|
total_cost += cost;
|
|
|
|
|
|
|
|
|
|
if (cost) {
|
|
|
|
|
memcpy_speed = ((max_size / cost) * 1000) / 1024;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pmemset_speed != NULL) {
|
|
|
|
|
*pmemset_speed = memset_speed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pmemcpy_speed != NULL) {
|
|
|
|
|
*pmemcpy_speed = memcpy_speed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return total_cost;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 11:35:25 +08:00
|
|
|
|
static ret_t window_to_background(void* ctx, event_t* e) {
|
|
|
|
|
widget_t* win = WIDGET(e->target);
|
|
|
|
|
log_debug("%s to_background\n", win->name);
|
2019-06-06 18:19:03 +08:00
|
|
|
|
(void)win;
|
2019-05-27 11:35:25 +08:00
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ret_t window_to_foreground(void* ctx, event_t* e) {
|
|
|
|
|
widget_t* win = WIDGET(e->target);
|
|
|
|
|
log_debug("%s to_foreground\n", win->name);
|
2019-06-06 18:19:03 +08:00
|
|
|
|
(void)win;
|
2019-05-27 11:35:25 +08:00
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-15 08:52:37 +08:00
|
|
|
|
static ret_t on_context_menu(void* ctx, event_t* e) {
|
|
|
|
|
open_window("menu_point", NULL);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-21 17:24:09 +08:00
|
|
|
|
static ret_t update_title_on_timer(const timer_info_t* info) {
|
|
|
|
|
char text[128];
|
|
|
|
|
tk_snprintf(text, sizeof(text), "change title:%d", random() % 100);
|
|
|
|
|
|
|
|
|
|
widget_set_text_utf8(WIDGET(info->ctx), text);
|
|
|
|
|
|
|
|
|
|
return RET_REPEAT;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-20 17:35:32 +08:00
|
|
|
|
static void open_window(const char* name, widget_t* to_close) {
|
|
|
|
|
widget_t* win = to_close ? window_open_and_close(name, to_close) : window_open(name);
|
2018-03-09 21:54:46 +08:00
|
|
|
|
|
2019-05-27 11:35:25 +08:00
|
|
|
|
widget_on(win, EVT_WINDOW_TO_BACKGROUND, window_to_background, win);
|
|
|
|
|
widget_on(win, EVT_WINDOW_TO_FOREGROUND, window_to_foreground, win);
|
|
|
|
|
|
2018-06-08 17:03:06 +08:00
|
|
|
|
install_click_hander(win);
|
2018-03-09 21:54:46 +08:00
|
|
|
|
|
2019-07-17 07:01:07 +08:00
|
|
|
|
if (tk_str_eq(name, "tab_scrollable")) {
|
2019-07-16 18:07:52 +08:00
|
|
|
|
widget_clone_tab(win);
|
|
|
|
|
widget_clone_tab(win);
|
|
|
|
|
widget_clone_tab(win);
|
|
|
|
|
widget_clone_tab(win);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-21 17:24:09 +08:00
|
|
|
|
if (tk_str_eq(name, "list_view")) {
|
|
|
|
|
widget_add_timer(win, update_title_on_timer, 1000);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-04 17:11:32 +08:00
|
|
|
|
if (tk_str_eq(widget_get_type(win), WIDGET_TYPE_DIALOG)) {
|
2019-04-10 09:08:47 +08:00
|
|
|
|
int32_t ret = dialog_modal(win);
|
|
|
|
|
|
|
|
|
|
if (tk_str_eq(win->name, "back_to_home") && ret == 0) {
|
|
|
|
|
window_manager_back_to_home(window_manager());
|
|
|
|
|
}
|
2018-06-08 17:03:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-09 21:54:46 +08:00
|
|
|
|
|
2018-12-07 12:42:54 +08:00
|
|
|
|
static ret_t on_paint_linear_gradient(void* ctx, event_t* e) {
|
|
|
|
|
paint_event_t* evt = paint_event_cast(e);
|
|
|
|
|
canvas_t* c = evt->c;
|
|
|
|
|
widget_t* widget = WIDGET(e->target);
|
|
|
|
|
vgcanvas_t* vg = canvas_get_vgcanvas(c);
|
|
|
|
|
color_t scolor = color_init(0xff, 0, 0, 0xff);
|
2018-12-11 09:12:37 +08:00
|
|
|
|
color_t ecolor = color_init(0xff, 0, 0, 0x0);
|
2018-12-07 12:42:54 +08:00
|
|
|
|
uint32_t spacing = 10;
|
|
|
|
|
uint32_t w = (widget->w - 3 * spacing) >> 1;
|
|
|
|
|
uint32_t h = (widget->h - 3 * spacing) >> 1;
|
|
|
|
|
rect_t r = rect_init(spacing, spacing, w, h);
|
|
|
|
|
|
|
|
|
|
vgcanvas_save(vg);
|
|
|
|
|
vgcanvas_translate(vg, c->ox, c->oy);
|
|
|
|
|
|
|
|
|
|
vgcanvas_rect(vg, r.x, r.y, r.w, r.h);
|
|
|
|
|
vgcanvas_set_fill_linear_gradient(vg, r.x, r.y, r.x + r.w, r.y + r.h, scolor, ecolor);
|
|
|
|
|
vgcanvas_fill(vg);
|
|
|
|
|
|
|
|
|
|
vgcanvas_translate(vg, r.x + r.w, 0);
|
|
|
|
|
vgcanvas_rect(vg, r.x, r.y, r.w, r.h);
|
|
|
|
|
ecolor = color_init(0, 0, 0xff, 0xff);
|
|
|
|
|
vgcanvas_set_fill_linear_gradient(vg, r.x, r.y, r.x + r.w, r.y, scolor, ecolor);
|
|
|
|
|
vgcanvas_fill(vg);
|
|
|
|
|
|
|
|
|
|
vgcanvas_translate(vg, 0, r.y + r.h);
|
|
|
|
|
vgcanvas_rect(vg, r.x, r.y, r.w, r.h);
|
|
|
|
|
ecolor = color_init(0, 0xff, 0xff, 0xff);
|
|
|
|
|
vgcanvas_set_fill_linear_gradient(vg, r.x, r.y, r.x + r.w, r.y, scolor, ecolor);
|
|
|
|
|
vgcanvas_fill(vg);
|
|
|
|
|
|
|
|
|
|
vgcanvas_translate(vg, -(r.x + r.w), 0);
|
|
|
|
|
vgcanvas_rect(vg, r.x, r.y, r.w, r.h);
|
|
|
|
|
ecolor = color_init(0, 0, 0xff, 0xff);
|
|
|
|
|
vgcanvas_set_fill_linear_gradient(vg, r.x, r.y, r.x, r.y + r.h, scolor, ecolor);
|
|
|
|
|
vgcanvas_fill(vg);
|
|
|
|
|
|
|
|
|
|
vgcanvas_restore(vg);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ret_t on_paint_radial_gradient(void* ctx, event_t* e) {
|
|
|
|
|
paint_event_t* evt = paint_event_cast(e);
|
|
|
|
|
canvas_t* c = evt->c;
|
|
|
|
|
widget_t* widget = WIDGET(e->target);
|
|
|
|
|
vgcanvas_t* vg = canvas_get_vgcanvas(c);
|
|
|
|
|
color_t scolor = color_init(0xff, 0, 0, 0xff);
|
2018-12-11 09:12:37 +08:00
|
|
|
|
color_t ecolor = color_init(0xff, 0, 0, 0);
|
2018-12-07 12:42:54 +08:00
|
|
|
|
uint32_t spacing = 10;
|
|
|
|
|
uint32_t w = (widget->w - 3 * spacing) >> 1;
|
|
|
|
|
uint32_t h = (widget->h - 3 * spacing) >> 1;
|
|
|
|
|
rect_t r = rect_init(spacing, spacing, w, h);
|
|
|
|
|
uint32_t radial = tk_min(w, h) / 2;
|
|
|
|
|
|
|
|
|
|
vgcanvas_save(vg);
|
|
|
|
|
vgcanvas_translate(vg, c->ox, c->oy);
|
|
|
|
|
|
|
|
|
|
vgcanvas_rect(vg, r.x, r.y, r.w, r.h);
|
|
|
|
|
vgcanvas_set_fill_radial_gradient(vg, r.x + w / 2, r.y + h / 2, 0, radial, scolor, ecolor);
|
|
|
|
|
vgcanvas_fill(vg);
|
|
|
|
|
|
|
|
|
|
vgcanvas_translate(vg, r.x + r.w, 0);
|
|
|
|
|
vgcanvas_rect(vg, r.x, r.y, r.w, r.h);
|
|
|
|
|
ecolor = color_init(0, 0, 0xff, 0xff);
|
|
|
|
|
vgcanvas_set_fill_radial_gradient(vg, r.x + w / 2, r.y + h / 2, radial / 4, radial, scolor,
|
|
|
|
|
ecolor);
|
|
|
|
|
vgcanvas_fill(vg);
|
|
|
|
|
|
|
|
|
|
vgcanvas_translate(vg, 0, r.y + r.h);
|
|
|
|
|
vgcanvas_rect(vg, r.x, r.y, r.w, r.h);
|
|
|
|
|
ecolor = color_init(0, 0xff, 0xff, 0xff);
|
|
|
|
|
vgcanvas_set_fill_radial_gradient(vg, r.x + w / 2, r.y + h / 2, radial / 3, radial, scolor,
|
|
|
|
|
ecolor);
|
|
|
|
|
vgcanvas_fill(vg);
|
|
|
|
|
|
|
|
|
|
vgcanvas_translate(vg, -(r.x + r.w), 0);
|
|
|
|
|
vgcanvas_rect(vg, r.x, r.y, r.w, r.h);
|
|
|
|
|
ecolor = color_init(0, 0, 0xff, 0xff);
|
|
|
|
|
vgcanvas_set_fill_radial_gradient(vg, r.x + w / 2, r.y + h / 2, radial / 2, radial, scolor,
|
|
|
|
|
ecolor);
|
|
|
|
|
vgcanvas_fill(vg);
|
|
|
|
|
|
|
|
|
|
vgcanvas_restore(vg);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ret_t on_paint_stroke_gradient(void* ctx, event_t* e) {
|
|
|
|
|
paint_event_t* evt = paint_event_cast(e);
|
|
|
|
|
canvas_t* c = evt->c;
|
|
|
|
|
widget_t* widget = WIDGET(e->target);
|
|
|
|
|
vgcanvas_t* vg = canvas_get_vgcanvas(c);
|
|
|
|
|
color_t scolor = color_init(0xff, 0, 0, 0xff);
|
|
|
|
|
color_t ecolor = color_init(0, 0xff, 0, 0xff);
|
|
|
|
|
uint32_t r = tk_min(widget->w, widget->h) / 3;
|
|
|
|
|
|
|
|
|
|
vgcanvas_save(vg);
|
|
|
|
|
vgcanvas_translate(vg, c->ox, c->oy);
|
|
|
|
|
vgcanvas_set_stroke_linear_gradient(vg, 0, 0, widget->w, widget->h, scolor, ecolor);
|
|
|
|
|
|
|
|
|
|
vgcanvas_move_to(vg, 0, 0);
|
|
|
|
|
vgcanvas_set_line_width(vg, 5);
|
|
|
|
|
|
|
|
|
|
vgcanvas_line_to(vg, widget->w / 2, widget->h);
|
|
|
|
|
vgcanvas_line_to(vg, widget->w / 2, 0);
|
|
|
|
|
vgcanvas_line_to(vg, widget->w, widget->h);
|
|
|
|
|
vgcanvas_stroke(vg);
|
|
|
|
|
|
|
|
|
|
vgcanvas_begin_path(vg);
|
|
|
|
|
vgcanvas_arc(vg, widget->w / 2, widget->h / 2, r, 0, M_PI * 2, FALSE);
|
|
|
|
|
vgcanvas_stroke(vg);
|
|
|
|
|
|
|
|
|
|
vgcanvas_restore(vg);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "vg_common.inc"
|
|
|
|
|
|
|
|
|
|
static ret_t on_paint_vgcanvas(void* ctx, event_t* e) {
|
|
|
|
|
paint_event_t* evt = paint_event_cast(e);
|
|
|
|
|
canvas_t* c = evt->c;
|
|
|
|
|
vgcanvas_t* vg = canvas_get_vgcanvas(c);
|
|
|
|
|
|
|
|
|
|
vgcanvas_save(vg);
|
|
|
|
|
vgcanvas_translate(vg, c->ox, c->oy);
|
|
|
|
|
vgcanvas_set_line_width(vg, 1);
|
|
|
|
|
vgcanvas_set_stroke_color(vg, color_init(0, 0xff, 0, 0xff));
|
|
|
|
|
vgcanvas_set_fill_color(vg, color_init(0xff, 0, 0, 0xff));
|
|
|
|
|
|
|
|
|
|
draw_basic_shapes(vg, FALSE);
|
|
|
|
|
vgcanvas_translate(vg, 0, 50);
|
|
|
|
|
draw_basic_shapes(vg, TRUE);
|
|
|
|
|
vgcanvas_translate(vg, 0, 50);
|
|
|
|
|
stroke_lines(vg);
|
|
|
|
|
vgcanvas_translate(vg, 0, 50);
|
|
|
|
|
draw_image(vg);
|
|
|
|
|
|
|
|
|
|
vgcanvas_translate(vg, 50, 100);
|
|
|
|
|
draw_matrix(vg);
|
|
|
|
|
vgcanvas_translate(vg, 0, 100);
|
|
|
|
|
|
|
|
|
|
draw_text(vg);
|
|
|
|
|
vgcanvas_restore(vg);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-02 07:10:37 +08:00
|
|
|
|
static ret_t on_timer_show_toast(const timer_info_t* info) {
|
2020-09-02 07:18:30 +08:00
|
|
|
|
dialog_toast("Hello AWTK!\nThis is a toast(3)!", 2000);
|
2020-09-02 07:10:37 +08:00
|
|
|
|
|
2020-09-02 07:18:30 +08:00
|
|
|
|
return RET_REMOVE;
|
2020-09-02 07:10:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-08 17:03:06 +08:00
|
|
|
|
static ret_t on_open_window(void* ctx, event_t* e) {
|
2019-07-04 11:26:55 +08:00
|
|
|
|
const char* name = (const char*)ctx;
|
2019-03-01 18:04:57 +08:00
|
|
|
|
|
|
|
|
|
if (tk_str_eq(name, "toast")) {
|
2020-09-02 07:10:37 +08:00
|
|
|
|
timer_add(on_timer_show_toast, NULL, 0);
|
|
|
|
|
dialog_toast("Hello AWTK!\nThis is a toast(1)!", 2000);
|
|
|
|
|
dialog_toast("Hello AWTK!\nThis is a toast(2)!", 2000);
|
2019-03-02 18:04:29 +08:00
|
|
|
|
} else if (tk_str_eq(name, "info")) {
|
2019-12-09 07:53:32 +08:00
|
|
|
|
dialog_info("info", "hello awtk");
|
2019-03-02 18:04:29 +08:00
|
|
|
|
} else if (tk_str_eq(name, "warn")) {
|
2019-06-02 12:06:16 +08:00
|
|
|
|
dialog_warn(NULL, "Hello AWTK!\nDanger!!!");
|
2019-03-02 18:04:29 +08:00
|
|
|
|
} else if (tk_str_eq(name, "confirm")) {
|
2019-06-02 12:06:16 +08:00
|
|
|
|
dialog_confirm(NULL, "Hello AWTK!\nAre you sure to close?");
|
2019-03-01 18:04:57 +08:00
|
|
|
|
} else {
|
|
|
|
|
open_window(name, NULL);
|
|
|
|
|
}
|
2018-06-20 17:35:32 +08:00
|
|
|
|
|
2018-03-09 21:54:46 +08:00
|
|
|
|
(void)e;
|
|
|
|
|
|
2019-04-03 17:13:18 +08:00
|
|
|
|
#if 0
|
2019-03-11 12:02:54 +08:00
|
|
|
|
/*for test only*/
|
|
|
|
|
widget_on(WIDGET(e->target), EVT_CLICK, on_open_window, (void*)name);
|
|
|
|
|
return RET_REMOVE;
|
|
|
|
|
#else
|
2018-03-09 21:54:46 +08:00
|
|
|
|
return RET_OK;
|
2019-03-11 12:02:54 +08:00
|
|
|
|
#endif
|
2018-03-09 21:54:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-01 11:10:17 +08:00
|
|
|
|
static ret_t on_fullscreen(void* ctx, event_t* e) {
|
|
|
|
|
widget_t* btn = WIDGET(ctx);
|
|
|
|
|
window_t* win = WINDOW(widget_get_window(btn));
|
|
|
|
|
|
|
|
|
|
if (win->fullscreen) {
|
|
|
|
|
window_set_fullscreen(WIDGET(win), FALSE);
|
|
|
|
|
widget_set_text_utf8(btn, "Fullscreen");
|
|
|
|
|
} else {
|
|
|
|
|
window_set_fullscreen(WIDGET(win), TRUE);
|
|
|
|
|
widget_set_text_utf8(btn, "Unfullscreen");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-08 17:03:06 +08:00
|
|
|
|
static ret_t on_close(void* ctx, event_t* e) {
|
2019-03-14 10:52:25 +08:00
|
|
|
|
widget_t* win = WIDGET(ctx);
|
2018-04-21 17:21:55 +08:00
|
|
|
|
(void)e;
|
2018-06-08 17:03:06 +08:00
|
|
|
|
return window_close(win);
|
2018-04-21 17:21:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 13:46:39 +08:00
|
|
|
|
static ret_t on_start(void* ctx, event_t* e) {
|
|
|
|
|
widget_start_animator(NULL, NULL);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ret_t on_pause(void* ctx, event_t* e) {
|
|
|
|
|
widget_pause_animator(NULL, NULL);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ret_t on_stop(void* ctx, event_t* e) {
|
|
|
|
|
widget_stop_animator(NULL, NULL);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-14 10:52:25 +08:00
|
|
|
|
static ret_t on_send_key(void* ctx, event_t* e) {
|
|
|
|
|
widget_t* button = WIDGET(e->target);
|
|
|
|
|
char text[2];
|
|
|
|
|
text[0] = (char)button->text.str[0];
|
|
|
|
|
text[1] = '\0';
|
|
|
|
|
|
|
|
|
|
input_method_commit_text(input_method(), text);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ret_t on_backspace(void* ctx, event_t* e) {
|
|
|
|
|
input_method_dispatch_key(input_method(), TK_KEY_BACKSPACE);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-08 17:03:06 +08:00
|
|
|
|
static ret_t on_quit(void* ctx, event_t* e) {
|
2019-03-14 10:52:25 +08:00
|
|
|
|
widget_t* dialog = WIDGET(ctx);
|
2018-04-21 07:43:02 +08:00
|
|
|
|
|
2018-06-08 17:03:06 +08:00
|
|
|
|
dialog_quit(dialog, 0);
|
2018-04-21 07:43:02 +08:00
|
|
|
|
(void)e;
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-30 10:27:32 +08:00
|
|
|
|
static ret_t on_back_to_home(void* ctx, event_t* e) {
|
|
|
|
|
widget_t* dialog = WIDGET(ctx);
|
|
|
|
|
|
|
|
|
|
dialog_quit(dialog, 0);
|
|
|
|
|
|
|
|
|
|
(void)e;
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-28 17:45:34 +08:00
|
|
|
|
static ret_t on_quit_app(void* ctx, event_t* e) {
|
2018-11-11 18:03:17 +08:00
|
|
|
|
tk_quit();
|
2018-10-28 17:45:34 +08:00
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-04 16:16:27 +08:00
|
|
|
|
static ret_t on_combo_box_will_change(void* ctx, event_t* e) {
|
|
|
|
|
widget_t* combo_box = WIDGET(ctx);
|
|
|
|
|
widget_t* win = widget_get_window(combo_box);
|
|
|
|
|
widget_t* value = widget_lookup(win, "old_value", TRUE);
|
|
|
|
|
|
2020-04-07 09:31:06 +08:00
|
|
|
|
if (value != NULL) {
|
|
|
|
|
widget_set_tr_text(value, combo_box_get_text(combo_box));
|
|
|
|
|
}
|
2019-01-04 16:16:27 +08:00
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-18 15:39:12 +08:00
|
|
|
|
static ret_t on_pages_add_child(void* ctx, event_t* e) {
|
|
|
|
|
widget_t* widget = WIDGET(ctx);
|
|
|
|
|
widget_t* win = widget_get_window(widget);
|
|
|
|
|
|
|
|
|
|
widget_t* close_btn = widget_lookup(win, "close", TRUE);
|
|
|
|
|
widget_t* text_label = widget_lookup(win, "text", TRUE);
|
|
|
|
|
widget_t* tab_button_parent = widget_lookup_by_type(win, "tab_button", TRUE)->parent;
|
|
|
|
|
|
|
|
|
|
if (close_btn != NULL) {
|
|
|
|
|
widget_on(close_btn, EVT_CLICK, on_close, win);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (text_label != NULL) {
|
|
|
|
|
WIDGET_FOR_EACH_CHILD_BEGIN(tab_button_parent, iter, i)
|
|
|
|
|
|
|
|
|
|
if (tk_str_eq(iter->vt->type, "tab_button")) {
|
|
|
|
|
if (TAB_BUTTON(iter)->value) {
|
|
|
|
|
widget_set_text_utf8(text_label, iter->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WIDGET_FOR_EACH_CHILD_END();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-22 11:40:07 +08:00
|
|
|
|
static ret_t on_combo_box_changed(void* ctx, event_t* e) {
|
|
|
|
|
widget_t* combo_box = WIDGET(ctx);
|
|
|
|
|
widget_t* win = widget_get_window(combo_box);
|
|
|
|
|
widget_t* value = widget_lookup(win, "value", TRUE);
|
|
|
|
|
|
2020-04-07 09:31:06 +08:00
|
|
|
|
if (value != NULL) {
|
|
|
|
|
widget_set_tr_text(value, combo_box_get_text(combo_box));
|
|
|
|
|
}
|
2018-12-22 11:40:07 +08:00
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-14 12:44:27 +08:00
|
|
|
|
static ret_t on_remove_self(void* ctx, event_t* e) {
|
|
|
|
|
widget_t* widget = WIDGET(ctx);
|
|
|
|
|
widget_remove_child(widget->parent, widget);
|
2018-12-18 09:27:08 +08:00
|
|
|
|
widget_destroy(widget);
|
2018-12-14 12:44:27 +08:00
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ret_t on_clone_self(void* ctx, event_t* e) {
|
|
|
|
|
widget_t* widget = WIDGET(ctx);
|
|
|
|
|
widget_t* clone = widget_clone(widget, widget->parent);
|
|
|
|
|
widget_on(clone, EVT_CLICK, on_clone_self, clone);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-16 18:07:52 +08:00
|
|
|
|
static ret_t widget_clone_tab(widget_t* widget) {
|
2019-07-15 12:00:47 +08:00
|
|
|
|
char text[32];
|
|
|
|
|
widget_t* button = widget_lookup(widget, "clone_button", TRUE);
|
|
|
|
|
widget_t* view = widget_lookup(widget, "clone_view", TRUE);
|
|
|
|
|
widget_t* new_button = widget_clone(button, button->parent);
|
|
|
|
|
|
|
|
|
|
widget_t* new_view = widget_clone(view, view->parent);
|
|
|
|
|
tk_snprintf(text, sizeof(text), "Clone(%d)", widget_index_of(new_button));
|
|
|
|
|
widget_set_text_utf8(new_button, text);
|
|
|
|
|
widget_set_value(new_button, TRUE);
|
|
|
|
|
|
|
|
|
|
widget_child_on(new_view, "clone_tab", EVT_CLICK, on_clone_tab, widget_get_window(widget));
|
|
|
|
|
widget_set_text_utf8(widget_lookup_by_type(new_view, WIDGET_TYPE_LABEL, TRUE), text);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-16 18:07:52 +08:00
|
|
|
|
static ret_t on_clone_tab(void* ctx, event_t* e) {
|
|
|
|
|
return widget_clone_tab(WIDGET(ctx));
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-11 09:29:49 +08:00
|
|
|
|
static ret_t on_show_fps(void* ctx, event_t* e) {
|
2018-06-16 11:40:13 +08:00
|
|
|
|
widget_t* button = WIDGET(ctx);
|
2018-06-15 11:32:03 +08:00
|
|
|
|
widget_t* widget = window_manager();
|
|
|
|
|
window_manager_t* wm = WINDOW_MANAGER(widget);
|
2018-06-11 09:29:49 +08:00
|
|
|
|
|
2018-06-15 11:32:03 +08:00
|
|
|
|
widget_invalidate(widget, NULL);
|
|
|
|
|
window_manager_set_show_fps(widget, !wm->show_fps);
|
|
|
|
|
widget_set_text(button, wm->show_fps ? L"Hide FPS" : L"Show FPS");
|
2018-06-11 09:29:49 +08:00
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-19 16:44:31 +08:00
|
|
|
|
extern ret_t assets_set_global_theme(const char* name);
|
2019-10-18 18:18:12 +08:00
|
|
|
|
static ret_t on_reload_theme_test(void* ctx, event_t* e) {
|
2020-03-16 21:19:20 +08:00
|
|
|
|
widget_t* widget = WIDGET(e->target);
|
|
|
|
|
assets_manager_t* am = widget_get_assets_manager(widget);
|
2020-03-19 16:44:31 +08:00
|
|
|
|
const char* theme = "default";
|
2020-03-16 21:19:20 +08:00
|
|
|
|
|
2020-03-19 16:44:31 +08:00
|
|
|
|
if (tk_str_eq(am->theme, theme)) {
|
|
|
|
|
theme = "dark";
|
2020-03-16 21:19:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-19 16:44:31 +08:00
|
|
|
|
assets_set_global_theme(theme);
|
2019-10-18 18:18:12 +08:00
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-03 15:47:11 +08:00
|
|
|
|
static ret_t on_snapshot(void* ctx, event_t* e) {
|
2020-02-01 18:17:38 +08:00
|
|
|
|
#ifndef AWTK_WEB
|
2020-01-03 15:47:11 +08:00
|
|
|
|
bitmap_t* bitmap = widget_take_snapshot(window_manager());
|
|
|
|
|
bitmap_save_png(bitmap, "test.png");
|
|
|
|
|
bitmap_destroy(bitmap);
|
2020-02-07 11:19:46 +08:00
|
|
|
|
#endif /*AWTK_WEB*/
|
2020-01-03 15:47:11 +08:00
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-06 17:24:28 +08:00
|
|
|
|
static ret_t on_mem_test(void* ctx, event_t* e) {
|
2018-06-06 16:18:14 +08:00
|
|
|
|
char text[32];
|
2018-06-06 17:24:28 +08:00
|
|
|
|
uint32_t size = 100 * 1024;
|
|
|
|
|
uint32_t memset_speed = 0;
|
|
|
|
|
uint32_t memcpy_speed = 0;
|
2018-06-16 11:40:13 +08:00
|
|
|
|
widget_t* win = WIDGET(ctx);
|
2018-06-08 17:03:06 +08:00
|
|
|
|
widget_t* label_memset = widget_lookup(win, "memset", TRUE);
|
|
|
|
|
widget_t* label_cost = widget_lookup(win, "cost", TRUE);
|
|
|
|
|
widget_t* label_memcpy = widget_lookup(win, "memcpy", TRUE);
|
2018-06-06 17:24:28 +08:00
|
|
|
|
void* buff = TKMEM_ALLOC(size);
|
|
|
|
|
uint32_t cost = tk_mem_speed_test(buff, size, &memcpy_speed, &memset_speed);
|
|
|
|
|
TKMEM_FREE(buff);
|
2018-06-06 16:18:14 +08:00
|
|
|
|
|
2018-06-06 17:24:28 +08:00
|
|
|
|
tk_snprintf(text, sizeof(text), "%ums", cost);
|
2018-06-08 17:03:06 +08:00
|
|
|
|
widget_set_text_utf8(label_cost, text);
|
2018-06-06 17:38:50 +08:00
|
|
|
|
|
2018-06-08 17:03:06 +08:00
|
|
|
|
tk_snprintf(text, sizeof(text), "memset: %uK/s", memset_speed);
|
|
|
|
|
widget_set_text_utf8(label_memset, text);
|
|
|
|
|
|
|
|
|
|
tk_snprintf(text, sizeof(text), "memcpy: %uK/s", memcpy_speed);
|
|
|
|
|
widget_set_text_utf8(label_memcpy, text);
|
2018-06-06 17:24:28 +08:00
|
|
|
|
|
2020-06-27 11:00:37 +08:00
|
|
|
|
font_manager_shrink_cache(font_manager(), 1);
|
|
|
|
|
|
2018-06-06 17:24:28 +08:00
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 17:08:14 +08:00
|
|
|
|
static ret_t progress_bar_animate_delta(widget_t* win, const char* name, int32_t delta) {
|
|
|
|
|
widget_t* progress_bar = widget_lookup(win, name, TRUE);
|
|
|
|
|
int32_t value = (PROGRESS_BAR(progress_bar)->value + delta);
|
2020-01-14 10:01:24 +08:00
|
|
|
|
widget_animate_value_to(progress_bar, tk_max(0, tk_min(100, value)), 500);
|
2019-03-04 17:08:14 +08:00
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-08 17:03:06 +08:00
|
|
|
|
static ret_t on_inc(void* ctx, event_t* e) {
|
2018-06-16 11:40:13 +08:00
|
|
|
|
widget_t* win = WIDGET(ctx);
|
2019-03-04 17:08:14 +08:00
|
|
|
|
progress_bar_animate_delta(win, "bar1", 10);
|
|
|
|
|
progress_bar_animate_delta(win, "bar2", 10);
|
2018-06-08 17:03:06 +08:00
|
|
|
|
(void)e;
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ret_t on_dec(void* ctx, event_t* e) {
|
2018-06-16 11:40:13 +08:00
|
|
|
|
widget_t* win = WIDGET(ctx);
|
2019-03-04 17:08:14 +08:00
|
|
|
|
progress_bar_animate_delta(win, "bar1", -10);
|
|
|
|
|
progress_bar_animate_delta(win, "bar2", -10);
|
2018-06-08 17:03:06 +08:00
|
|
|
|
|
|
|
|
|
(void)e;
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-07 15:53:59 +08:00
|
|
|
|
static ret_t on_change_font_size(void* ctx, event_t* e) {
|
|
|
|
|
float_t font_scale = 1;
|
|
|
|
|
widget_t* win = WIDGET(ctx);
|
|
|
|
|
|
|
|
|
|
if (widget_get_value(widget_lookup(win, "font_small", TRUE))) {
|
|
|
|
|
font_scale = 0.9;
|
|
|
|
|
} else if (widget_get_value(widget_lookup(win, "font_big", TRUE))) {
|
|
|
|
|
font_scale = 1.1;
|
|
|
|
|
}
|
|
|
|
|
system_info_set_font_scale(system_info(), font_scale);
|
|
|
|
|
widget_invalidate_force(win, NULL);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-21 17:42:18 +08:00
|
|
|
|
static ret_t on_change_locale(void* ctx, event_t* e) {
|
|
|
|
|
char country[3];
|
|
|
|
|
char language[3];
|
|
|
|
|
const char* str = (const char*)ctx;
|
|
|
|
|
|
|
|
|
|
tk_strncpy(language, str, 2);
|
|
|
|
|
tk_strncpy(country, str + 3, 2);
|
2018-08-24 07:45:37 +08:00
|
|
|
|
locale_info_change(locale_info(), language, country);
|
2018-06-21 17:42:18 +08:00
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 09:45:24 +08:00
|
|
|
|
static ret_t install_one(void* ctx, const void* iter) {
|
2018-06-18 07:19:36 +08:00
|
|
|
|
widget_t* widget = WIDGET(iter);
|
2019-07-03 13:46:39 +08:00
|
|
|
|
widget_t* win = widget_get_window(widget);
|
2018-06-18 07:19:36 +08:00
|
|
|
|
|
2018-07-13 16:07:48 +08:00
|
|
|
|
if (widget->name != NULL) {
|
|
|
|
|
const char* name = widget->name;
|
2018-06-08 17:03:06 +08:00
|
|
|
|
if (strstr(name, "open:") != NULL) {
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_open_window, (void*)(name + 5));
|
2019-02-20 17:21:37 +08:00
|
|
|
|
widget_on(widget, EVT_LONG_PRESS, on_open_window, (void*)(name + 5));
|
2020-01-15 08:52:37 +08:00
|
|
|
|
if (tk_str_eq(name, "open:menu_point")) {
|
|
|
|
|
widget_on(widget, EVT_CONTEXT_MENU, on_context_menu, win);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-07 12:42:54 +08:00
|
|
|
|
} else if (tk_str_eq(name, "paint_linear_gradient")) {
|
|
|
|
|
widget_on(widget, EVT_PAINT, on_paint_linear_gradient, NULL);
|
|
|
|
|
} else if (tk_str_eq(name, "paint_radial_gradient")) {
|
|
|
|
|
widget_on(widget, EVT_PAINT, on_paint_radial_gradient, NULL);
|
|
|
|
|
} else if (tk_str_eq(name, "paint_stroke_gradient")) {
|
|
|
|
|
widget_on(widget, EVT_PAINT, on_paint_stroke_gradient, NULL);
|
|
|
|
|
} else if (tk_str_eq(name, "paint_vgcanvas")) {
|
|
|
|
|
widget_on(widget, EVT_PAINT, on_paint_vgcanvas, NULL);
|
2020-01-03 15:47:11 +08:00
|
|
|
|
} else if (tk_str_eq(name, "snapshot")) {
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_snapshot, NULL);
|
2018-06-29 19:33:01 +08:00
|
|
|
|
} else if (tk_str_eq(name, "memtest")) {
|
2018-06-08 17:03:06 +08:00
|
|
|
|
widget_t* win = widget_get_window(widget);
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_mem_test, win);
|
2019-10-18 18:18:12 +08:00
|
|
|
|
} else if (tk_str_eq(name, "reload_theme")) {
|
|
|
|
|
widget_t* win = widget_get_window(widget);
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_reload_theme_test, win);
|
2018-06-29 19:33:01 +08:00
|
|
|
|
} else if (tk_str_eq(name, "show_fps")) {
|
2018-06-15 11:32:03 +08:00
|
|
|
|
widget_on(widget, EVT_CLICK, on_show_fps, widget);
|
2018-12-14 12:44:27 +08:00
|
|
|
|
} else if (tk_str_eq(name, "clone_self")) {
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_clone_self, widget);
|
2019-07-15 12:00:47 +08:00
|
|
|
|
} else if (tk_str_eq(name, "clone_tab")) {
|
|
|
|
|
widget_t* win = widget_get_window(widget);
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_clone_tab, win);
|
2018-12-14 12:44:27 +08:00
|
|
|
|
} else if (tk_str_eq(name, "remove_self")) {
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_remove_self, widget);
|
2018-06-29 19:33:01 +08:00
|
|
|
|
} else if (tk_str_eq(name, "chinese")) {
|
2019-07-04 11:26:55 +08:00
|
|
|
|
widget_on(widget, EVT_CLICK, on_change_locale, (void*)"zh_CN");
|
2018-06-29 19:33:01 +08:00
|
|
|
|
} else if (tk_str_eq(name, "english")) {
|
2019-07-04 11:26:55 +08:00
|
|
|
|
widget_on(widget, EVT_CLICK, on_change_locale, (void*)"en_US");
|
2019-03-07 15:53:59 +08:00
|
|
|
|
} else if (tk_str_eq(name, "font_small") || tk_str_eq(name, "font_normal") ||
|
|
|
|
|
tk_str_eq(name, "font_big")) {
|
|
|
|
|
widget_t* win = widget_get_window(widget);
|
|
|
|
|
widget_on(widget, EVT_VALUE_CHANGED, on_change_font_size, win);
|
2018-06-29 19:33:01 +08:00
|
|
|
|
} else if (tk_str_eq(name, "inc_value")) {
|
|
|
|
|
widget_t* win = widget_get_window(widget);
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_inc, win);
|
|
|
|
|
} else if (strstr(name, "dec_value") != NULL) {
|
2018-06-08 17:03:06 +08:00
|
|
|
|
widget_t* win = widget_get_window(widget);
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_dec, win);
|
2018-06-29 19:33:01 +08:00
|
|
|
|
} else if (tk_str_eq(name, "close")) {
|
2019-07-03 13:46:39 +08:00
|
|
|
|
widget_on(widget, EVT_CLICK, on_close, win);
|
2019-08-01 11:10:17 +08:00
|
|
|
|
} else if (tk_str_eq(name, "fullscreen")) {
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_fullscreen, widget);
|
2019-07-03 13:46:39 +08:00
|
|
|
|
} else if (tk_str_eq(name, "start")) {
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_start, win);
|
|
|
|
|
} else if (tk_str_eq(name, "pause")) {
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_pause, win);
|
|
|
|
|
} else if (tk_str_eq(name, "stop")) {
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_stop, win);
|
2019-03-14 10:52:25 +08:00
|
|
|
|
} else if (tk_str_eq(name, "key")) {
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_send_key, NULL);
|
|
|
|
|
} else if (tk_str_eq(name, "backspace")) {
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_backspace, NULL);
|
2018-06-29 19:33:01 +08:00
|
|
|
|
} else if (tk_str_eq(name, "quit")) {
|
2018-06-08 17:03:06 +08:00
|
|
|
|
widget_t* win = widget_get_window(widget);
|
|
|
|
|
if (win) {
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_quit, win);
|
|
|
|
|
}
|
2019-03-30 10:27:32 +08:00
|
|
|
|
} else if (tk_str_eq(name, "back_to_home")) {
|
|
|
|
|
widget_t* win = widget_get_window(widget);
|
|
|
|
|
if (win) {
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_back_to_home, win);
|
|
|
|
|
}
|
2018-10-28 17:45:34 +08:00
|
|
|
|
} else if (tk_str_eq(name, "exit")) {
|
|
|
|
|
widget_t* win = widget_get_window(widget);
|
|
|
|
|
if (win) {
|
|
|
|
|
widget_on(widget, EVT_CLICK, on_quit_app, win);
|
|
|
|
|
}
|
2019-12-18 15:39:12 +08:00
|
|
|
|
} else if (tk_str_eq(name, "pages")) {
|
|
|
|
|
widget_on(widget, EVT_WIDGET_ADD_CHILD, on_pages_add_child, widget);
|
2018-06-08 17:03:06 +08:00
|
|
|
|
}
|
2018-12-22 11:40:07 +08:00
|
|
|
|
} else if (tk_str_eq(widget->vt->type, "combo_box")) {
|
|
|
|
|
widget_on(widget, EVT_VALUE_CHANGED, on_combo_box_changed, widget);
|
2019-01-04 16:16:27 +08:00
|
|
|
|
widget_on(widget, EVT_VALUE_WILL_CHANGE, on_combo_box_will_change, widget);
|
2018-06-08 17:03:06 +08:00
|
|
|
|
}
|
2018-06-18 07:19:36 +08:00
|
|
|
|
(void)ctx;
|
2018-06-08 17:03:06 +08:00
|
|
|
|
|
2018-06-18 07:19:36 +08:00
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void install_click_hander(widget_t* widget) {
|
|
|
|
|
widget_foreach(widget, install_one, widget);
|
2018-06-08 17:03:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-16 09:11:12 +08:00
|
|
|
|
#include "base/idle.h"
|
2018-08-24 07:45:37 +08:00
|
|
|
|
#include "base/assets_manager.h"
|
2018-06-16 09:11:12 +08:00
|
|
|
|
|
|
|
|
|
static uint32_t s_preload_nr = 0;
|
2019-03-13 15:31:15 +08:00
|
|
|
|
static const preload_res_t s_preload_res[] = {{ASSET_TYPE_IMAGE, "earth"},
|
2018-08-24 07:45:37 +08:00
|
|
|
|
{ASSET_TYPE_IMAGE, "dialog_title"},
|
|
|
|
|
{ASSET_TYPE_IMAGE, "rgb"},
|
|
|
|
|
{ASSET_TYPE_IMAGE, "rgba"}};
|
2018-06-16 09:11:12 +08:00
|
|
|
|
|
|
|
|
|
static ret_t timer_preload(const timer_info_t* timer) {
|
|
|
|
|
char text[64];
|
2018-06-16 11:40:13 +08:00
|
|
|
|
widget_t* win = WIDGET(timer->ctx);
|
2018-06-16 09:11:12 +08:00
|
|
|
|
uint32_t total = ARRAY_SIZE(s_preload_res);
|
|
|
|
|
widget_t* bar = widget_lookup(win, "bar", TRUE);
|
|
|
|
|
widget_t* status = widget_lookup(win, "status", TRUE);
|
|
|
|
|
|
|
|
|
|
if (s_preload_nr == total) {
|
2019-08-03 11:59:59 +08:00
|
|
|
|
#if !defined(MOBILE_APP)
|
2018-12-03 12:50:07 +08:00
|
|
|
|
window_open("system_bar");
|
2019-10-30 16:07:02 +08:00
|
|
|
|
/* window_open("system_bar_bottom");*/
|
2019-08-03 11:59:59 +08:00
|
|
|
|
#endif /*MOBILE_APP*/
|
2019-08-01 11:10:17 +08:00
|
|
|
|
|
2018-06-20 17:35:32 +08:00
|
|
|
|
open_window("main", win);
|
2018-06-16 09:11:12 +08:00
|
|
|
|
|
|
|
|
|
return RET_REMOVE;
|
|
|
|
|
} else {
|
|
|
|
|
uint32_t value = 0;
|
|
|
|
|
const preload_res_t* iter = s_preload_res + s_preload_nr++;
|
|
|
|
|
switch (iter->type) {
|
2018-08-24 07:45:37 +08:00
|
|
|
|
case ASSET_TYPE_IMAGE: {
|
2018-06-16 09:11:12 +08:00
|
|
|
|
bitmap_t img;
|
2018-12-29 12:17:06 +08:00
|
|
|
|
image_manager_get_bitmap(image_manager(), iter->name, &img);
|
2018-06-16 09:11:12 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
2018-08-24 07:45:37 +08:00
|
|
|
|
assets_manager_ref(assets_manager(), iter->type, iter->name);
|
2018-06-16 09:11:12 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value = (s_preload_nr * 100) / total;
|
|
|
|
|
tk_snprintf(text, sizeof(text), "Load: %s(%u/%u)", iter->name, s_preload_nr, total);
|
|
|
|
|
widget_set_value(bar, value);
|
|
|
|
|
widget_set_text_utf8(status, text);
|
|
|
|
|
|
|
|
|
|
return RET_REPEAT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ret_t show_preload_res_window() {
|
2018-06-22 12:01:36 +08:00
|
|
|
|
uint32_t interval = 500 / ARRAY_SIZE(s_preload_res);
|
2018-06-16 09:11:12 +08:00
|
|
|
|
widget_t* win = window_open("preload");
|
|
|
|
|
timer_add(timer_preload, win, interval);
|
2018-03-09 21:54:46 +08:00
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
2018-06-16 09:11:12 +08:00
|
|
|
|
|
2019-02-21 18:00:15 +08:00
|
|
|
|
static ret_t close_window_on_event(void* ctx, event_t* e) {
|
|
|
|
|
window_close(WIDGET(ctx));
|
|
|
|
|
|
|
|
|
|
return RET_REMOVE;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-20 15:02:13 +08:00
|
|
|
|
static ret_t on_screen_saver(void* ctx, event_t* e) {
|
2019-03-13 15:27:44 +08:00
|
|
|
|
widget_t* win = NULL;
|
|
|
|
|
const char* screen_saver_win = "image_animation";
|
2019-02-21 18:00:15 +08:00
|
|
|
|
|
2019-03-13 15:31:15 +08:00
|
|
|
|
if (widget_child(window_manager(), screen_saver_win) != NULL) {
|
2019-03-13 15:27:44 +08:00
|
|
|
|
log_debug("screen saver exist.\n");
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
win = window_open(screen_saver_win);
|
2019-02-21 18:00:15 +08:00
|
|
|
|
widget_on(win, EVT_POINTER_MOVE, close_window_on_event, win);
|
2019-03-13 15:33:51 +08:00
|
|
|
|
widget_on(win, EVT_POINTER_UP, close_window_on_event, win);
|
2019-02-21 18:00:15 +08:00
|
|
|
|
widget_on(win, EVT_KEY_UP, close_window_on_event, win);
|
2019-02-20 15:02:13 +08:00
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-18 12:32:42 +08:00
|
|
|
|
static ret_t on_key_record_play_events(void* ctx, event_t* e) {
|
|
|
|
|
#ifdef WITH_EVENT_RECORDER_PLAYER
|
2020-05-26 16:44:37 +08:00
|
|
|
|
key_event_t* evt = (key_event_t*)e;
|
2020-06-05 17:16:19 +08:00
|
|
|
|
|
2020-05-18 12:32:42 +08:00
|
|
|
|
if (evt->key == TK_KEY_F5) {
|
|
|
|
|
event_recorder_player_start_record("event_log.bin");
|
|
|
|
|
return RET_STOP;
|
|
|
|
|
} else if (evt->key == TK_KEY_F6) {
|
|
|
|
|
event_recorder_player_stop_record();
|
|
|
|
|
return RET_STOP;
|
|
|
|
|
} else if (evt->key == TK_KEY_F7) {
|
|
|
|
|
event_recorder_player_start_play("event_log.bin", 0xffff);
|
|
|
|
|
return RET_STOP;
|
|
|
|
|
} else if (evt->key == TK_KEY_F8) {
|
|
|
|
|
event_recorder_player_stop_play();
|
2020-06-17 17:59:38 +08:00
|
|
|
|
return RET_STOP;
|
|
|
|
|
} else if (evt->key == TK_KEY_F9) {
|
|
|
|
|
tk_mem_dump();
|
|
|
|
|
return RET_STOP;
|
|
|
|
|
} else if (evt->key == TK_KEY_F10) {
|
|
|
|
|
font_manager_unload_all(font_manager());
|
|
|
|
|
image_manager_unload_all(image_manager());
|
|
|
|
|
assets_manager_clear_cache(assets_manager(), ASSET_TYPE_UI);
|
|
|
|
|
tk_mem_dump();
|
2020-05-18 12:32:42 +08:00
|
|
|
|
return RET_STOP;
|
|
|
|
|
}
|
2020-05-18 17:42:26 +08:00
|
|
|
|
#endif /*WITH_EVENT_RECORDER_PLAYER*/
|
2020-05-18 12:32:42 +08:00
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-12 14:39:52 +08:00
|
|
|
|
static ret_t on_key_back_or_back_to_home(void* ctx, event_t* e) {
|
|
|
|
|
key_event_t* evt = (key_event_t*)e;
|
|
|
|
|
if (evt->key == TK_KEY_F2) {
|
|
|
|
|
window_manager_back(WIDGET(ctx));
|
2019-11-26 14:44:22 +08:00
|
|
|
|
|
|
|
|
|
return RET_STOP;
|
2019-03-12 14:39:52 +08:00
|
|
|
|
} else if (evt->key == TK_KEY_F3) {
|
|
|
|
|
window_manager_back_to_home(WIDGET(ctx));
|
2019-11-28 09:22:50 +08:00
|
|
|
|
|
2019-12-04 18:08:05 +08:00
|
|
|
|
return RET_STOP;
|
|
|
|
|
} else if (evt->key == TK_KEY_F4) {
|
|
|
|
|
window_manager_back_to(WIDGET(ctx), "main");
|
|
|
|
|
|
2019-11-26 14:44:22 +08:00
|
|
|
|
return RET_STOP;
|
2019-03-12 14:39:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-19 16:43:21 +08:00
|
|
|
|
static ret_t wm_on_before_paint(void* ctx, event_t* e) {
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ret_t wm_on_after_paint(void* ctx, event_t* e) {
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-26 09:52:58 +08:00
|
|
|
|
static ret_t wm_on_low_memory(void* ctx, event_t* evt) {
|
2019-06-26 09:59:11 +08:00
|
|
|
|
log_debug("low memory\n");
|
2019-06-26 09:52:58 +08:00
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ret_t wm_on_out_of_memory(void* ctx, event_t* evt) {
|
2019-06-26 09:59:11 +08:00
|
|
|
|
log_debug("out of memory\n");
|
2019-06-26 09:52:58 +08:00
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 17:30:50 +08:00
|
|
|
|
static ret_t wm_on_request_quit(void* ctx, event_t* evt) {
|
|
|
|
|
/*
|
|
|
|
|
* do some cleanup work here
|
|
|
|
|
* return RET_STOP to ignore the request
|
|
|
|
|
*/
|
|
|
|
|
/*return RET_STOP;*/
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-16 09:11:12 +08:00
|
|
|
|
ret_t application_init() {
|
2020-04-01 17:30:42 +08:00
|
|
|
|
char path[MAX_PATH + 1];
|
2019-03-12 14:39:52 +08:00
|
|
|
|
widget_t* wm = window_manager();
|
|
|
|
|
|
2019-02-21 18:00:15 +08:00
|
|
|
|
/*enable screen saver*/
|
2019-03-13 15:33:51 +08:00
|
|
|
|
window_manager_set_screen_saver_time(wm, 180 * 1000);
|
2019-03-12 14:39:52 +08:00
|
|
|
|
widget_on(wm, EVT_SCREEN_SAVER, on_screen_saver, NULL);
|
|
|
|
|
|
|
|
|
|
widget_on(wm, EVT_KEY_DOWN, on_key_back_or_back_to_home, wm);
|
2020-05-18 12:32:42 +08:00
|
|
|
|
widget_on(wm, EVT_KEY_UP, on_key_record_play_events, wm);
|
2019-04-19 16:43:21 +08:00
|
|
|
|
widget_on(wm, EVT_BEFORE_PAINT, wm_on_before_paint, wm);
|
|
|
|
|
widget_on(wm, EVT_AFTER_PAINT, wm_on_after_paint, wm);
|
2019-06-26 09:52:58 +08:00
|
|
|
|
widget_on(wm, EVT_LOW_MEMORY, wm_on_low_memory, wm);
|
|
|
|
|
widget_on(wm, EVT_OUT_OF_MEMORY, wm_on_out_of_memory, wm);
|
2019-09-19 17:30:50 +08:00
|
|
|
|
widget_on(wm, EVT_REQUEST_QUIT_APP, wm_on_request_quit, wm);
|
2019-02-20 15:02:13 +08:00
|
|
|
|
|
2020-04-01 17:30:42 +08:00
|
|
|
|
fs_get_user_storage_path(os_fs(), path);
|
|
|
|
|
log_debug("user storage path:%s\n", path);
|
|
|
|
|
|
2018-06-16 09:11:12 +08:00
|
|
|
|
return show_preload_res_window();
|
|
|
|
|
}
|
2020-03-19 11:11:32 +08:00
|
|
|
|
|
|
|
|
|
ret_t application_exit() {
|
|
|
|
|
log_debug("application_exit\n");
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-22 18:30:13 +08:00
|
|
|
|
#ifdef WITH_FS_RES
|
|
|
|
|
#define APP_DEFAULT_FONT "default_full"
|
2020-05-24 19:23:42 +08:00
|
|
|
|
#endif /*WITH_FS_RES*/
|
2020-05-22 18:30:13 +08:00
|
|
|
|
|
2020-03-19 11:11:32 +08:00
|
|
|
|
#include "awtk_main.inc"
|