mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-29 18:48:09 +08:00
port to aworks
This commit is contained in:
parent
1d5794f7ff
commit
ff1a79eb67
@ -27,7 +27,7 @@ static ret_t on_ok(void* ctx, event_t* e) {
|
||||
|
||||
dialog_quit(dialog, 0);
|
||||
(void)e;
|
||||
mem_info_dump();
|
||||
tk_mem_info_dump();
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
@ -42,6 +42,6 @@ static ret_t on_cancel(void* ctx, event_t* e) {
|
||||
|
||||
dialog_quit(dialog, 1);
|
||||
(void)e;
|
||||
mem_info_dump();
|
||||
tk_mem_info_dump();
|
||||
return RET_OK;
|
||||
}
|
||||
|
@ -61,9 +61,9 @@ static ret_t on_show_dialog(void* ctx, event_t* e) {
|
||||
|
||||
widget_to_xml(win);
|
||||
code = dialog_modal(win);
|
||||
log_debug("code=%d\n", code);
|
||||
log_debug("code=%d\n", (int)code);
|
||||
|
||||
mem_info_dump();
|
||||
tk_mem_info_dump();
|
||||
(void)e;
|
||||
|
||||
return RET_OK;
|
||||
|
@ -43,7 +43,7 @@ static ret_t on_show_dialog(void* ctx, event_t* e) {
|
||||
|
||||
code = dialog_modal(win);
|
||||
|
||||
mem_info_dump();
|
||||
tk_mem_info_dump();
|
||||
(void)e;
|
||||
(void)code;
|
||||
|
||||
|
@ -4,7 +4,7 @@ AWTK的可移植性很高,在移植时只需要实现平台初始化、lcd和m
|
||||
|
||||
### 一、平台初始化
|
||||
|
||||
除了基本的libc函数外,AWTK对平台没有特别要求,在stm32f103ze上没有函数gettimeofday,所以要实现一个获取当前时间的函数get\_time\_ms。另外需要给GUI分配一块内存空间,并调用mem\_init。
|
||||
除了基本的libc函数外,AWTK对平台没有特别要求,在stm32f103ze上没有函数gettimeofday,所以要实现一个获取当前时间的函数get\_time\_ms。另外需要给GUI分配一块内存空间,并调用tk\_mem\_init。
|
||||
|
||||
```
|
||||
uint32_t get_time_ms() {
|
||||
@ -17,7 +17,7 @@ static uint32_t s_heam_mem[2048];
|
||||
|
||||
ret_t platform_prepare(void) {
|
||||
timer_init(get_time_ms);
|
||||
mem_init(s_heam_mem, sizeof(s_heam_mem));
|
||||
tk_mem_init(s_heam_mem, sizeof(s_heam_mem));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ AWTK的可移植性很高,在移植时只需要实现平台初始化、lcd和m
|
||||
|
||||
### 一、平台初始化
|
||||
|
||||
除了基本的libc函数外,AWTK对平台没有特别要求,在stm32f429igtx上没有函数gettimeofday,所以要实现一个获取当前时间的函数get\_time\_ms。另外需要给GUI分配一块内存空间,并调用mem\_init。
|
||||
除了基本的libc函数外,AWTK对平台没有特别要求,在stm32f429igtx上没有函数gettimeofday,所以要实现一个获取当前时间的函数get\_time\_ms。另外需要给GUI分配一块内存空间,并调用tk\_mem\_init。
|
||||
|
||||
```
|
||||
uint32_t get_time_ms() {
|
||||
@ -20,7 +20,7 @@ void sleep_ms(uint32_t ms) {
|
||||
|
||||
ret_t platform_prepare(void) {
|
||||
timer_init(get_time_ms);
|
||||
mem_init(MEM2_ADDR, MEM2_MAX_SIZE);
|
||||
tk_mem_init(MEM2_ADDR, MEM2_MAX_SIZE);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
@ -22,19 +22,19 @@
|
||||
#include "base/mem.h"
|
||||
|
||||
#ifdef HAS_STD_MALLOC
|
||||
ret_t mem_init(void* buffer, uint32_t length) {
|
||||
ret_t tk_mem_init(void* buffer, uint32_t length) {
|
||||
(void)buffer;
|
||||
(void)length;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
mem_stat_t mem_stat(void) {
|
||||
mem_stat_t tk_mem_stat(void) {
|
||||
mem_stat_t stat;
|
||||
memset(&stat, 0x00, sizeof(stat));
|
||||
return stat;
|
||||
}
|
||||
|
||||
void mem_info_dump(void) {}
|
||||
void tk_mem_info_dump(void) {}
|
||||
|
||||
#else
|
||||
typedef struct _free_node_t {
|
||||
@ -119,8 +119,8 @@ void* tk_alloc(uint32_t size) {
|
||||
}
|
||||
|
||||
if (iter == NULL) {
|
||||
log_debug("%s: Out of memory(%d):\n", __func__, size);
|
||||
mem_info_dump();
|
||||
log_debug("%s: Out of memory(%d):\n", __func__, (int)size);
|
||||
tk_mem_info_dump();
|
||||
}
|
||||
|
||||
return_value_if_fail(iter != NULL, NULL);
|
||||
@ -270,7 +270,7 @@ void* tk_realloc(void* ptr, uint32_t size) {
|
||||
return new_ptr;
|
||||
}
|
||||
|
||||
ret_t mem_init(void* buffer, uint32_t length) {
|
||||
ret_t tk_mem_init(void* buffer, uint32_t length) {
|
||||
return_value_if_fail(buffer != NULL && length > MIN_SIZE, RET_BAD_PARAMS);
|
||||
|
||||
memset(buffer, 0x00, length);
|
||||
@ -285,21 +285,22 @@ ret_t mem_init(void* buffer, uint32_t length) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void mem_info_dump() {
|
||||
void tk_mem_info_dump() {
|
||||
int32_t i = 0;
|
||||
free_node_t* iter = NULL;
|
||||
mem_stat_t st = mem_stat();
|
||||
mem_stat_t st = tk_mem_stat();
|
||||
|
||||
for (iter = s_mem_info.free_list; iter != NULL; iter = iter->next, i++) {
|
||||
log_debug("[%d] %p %d\n", i, iter, iter->length);
|
||||
log_debug("[%d] %p %d\n", (int)i, iter, (int)(iter->length));
|
||||
}
|
||||
|
||||
log_debug("total=%d used=%d free=%d free_block_nr=%d used_block_nr=%d\n", st.total, st.used,
|
||||
st.free, st.free_block_nr, st.used_block_nr);
|
||||
log_debug("total=%d used=%d free=%d free_block_nr=%d used_block_nr=%d\n",
|
||||
(int)(st.total), (int)(st.used),
|
||||
(int)(st.free), (int)(st.free_block_nr), (int)(st.used_block_nr));
|
||||
return;
|
||||
}
|
||||
|
||||
mem_stat_t mem_stat() {
|
||||
mem_stat_t tk_mem_stat() {
|
||||
mem_stat_t st;
|
||||
free_node_t* iter = NULL;
|
||||
|
||||
|
@ -34,11 +34,11 @@ typedef struct _mem_stat_t {
|
||||
uint32_t used_block_nr;
|
||||
} mem_stat_t;
|
||||
|
||||
ret_t mem_init(void* buffer, uint32_t length);
|
||||
ret_t tk_mem_init(void* buffer, uint32_t length);
|
||||
|
||||
mem_stat_t mem_stat(void);
|
||||
mem_stat_t tk_mem_stat(void);
|
||||
|
||||
void mem_info_dump(void);
|
||||
void tk_mem_info_dump(void);
|
||||
|
||||
#ifdef HAS_STD_MALLOC
|
||||
#define TKMEM_INIT(size)
|
||||
@ -56,7 +56,7 @@ void* tk_alloc(uint32_t size);
|
||||
#define TKMEM_INIT(size) \
|
||||
{ \
|
||||
static uint32_t s_heap_mem[size >> 2]; \
|
||||
mem_init(s_heap_mem, sizeof(s_heap_mem)); \
|
||||
tk_mem_init(s_heap_mem, sizeof(s_heap_mem)); \
|
||||
}
|
||||
|
||||
#define TKMEM_ALLOC(size) tk_alloc(size)
|
||||
|
@ -42,7 +42,7 @@ int main() {
|
||||
|
||||
srand(time(0));
|
||||
mem_stack_init(&s);
|
||||
mem_init(s_heap_mem, sizeof(s_heap_mem));
|
||||
tk_mem_init(s_heap_mem, sizeof(s_heap_mem));
|
||||
|
||||
tk_free(tk_alloc(100));
|
||||
|
||||
@ -62,7 +62,7 @@ int main() {
|
||||
}
|
||||
|
||||
mem_stack_free_n(&s, s.top);
|
||||
mem_info_dump();
|
||||
tk_mem_info_dump();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -27,46 +27,46 @@
|
||||
BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* @class mutex_t
|
||||
* @class tk_mutex_t
|
||||
* 互斥锁。
|
||||
*/
|
||||
struct _mutex_t;
|
||||
typedef struct _mutex_t mutex_t;
|
||||
struct _tk_mutex_t;
|
||||
typedef struct _tk_mutex_t tk_mutex_t;
|
||||
|
||||
/**
|
||||
* @method mutex_create
|
||||
* @method tk_mutex_create
|
||||
* 创建mutex。
|
||||
*
|
||||
* @return {mutex_t*} mutex对象。
|
||||
* @return {tk_mutex_t*} mutex对象。
|
||||
*/
|
||||
mutex_t* mutex_create(void);
|
||||
tk_mutex_t* tk_mutex_create(void);
|
||||
|
||||
/**
|
||||
* @method mutex_lock
|
||||
* @method tk_mutex_lock
|
||||
* 加锁。
|
||||
* @param {mutex_t*} mutex mutex对象。
|
||||
* @param {tk_mutex_t*} mutex mutex对象。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t mutex_lock(mutex_t* mutex);
|
||||
ret_t tk_mutex_lock(tk_mutex_t* mutex);
|
||||
|
||||
/**
|
||||
* @method mutex_unlock
|
||||
* @method tk_mutex_unlock
|
||||
* 解锁。
|
||||
* @param {mutex_t*} mutex mutex对象。
|
||||
* @param {tk_mutex_t*} mutex mutex对象。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t mutex_unlock(mutex_t* mutex);
|
||||
ret_t tk_mutex_unlock(tk_mutex_t* mutex);
|
||||
|
||||
/**
|
||||
* @method mutex_destroy
|
||||
* @method tk_mutex_destroy
|
||||
* 销毁mutex对象。
|
||||
* @param {mutex_t*} mutex mutex对象。
|
||||
* @param {tk_mutex_t*} mutex mutex对象。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t mutex_destroy(mutex_t* mutex);
|
||||
ret_t tk_mutex_destroy(tk_mutex_t* mutex);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
|
@ -157,7 +157,10 @@ typedef enum _ret_t {
|
||||
#define FALSE 0
|
||||
#endif /*FALSE*/
|
||||
|
||||
typedef int8_t bool_t;
|
||||
#ifndef bool_t
|
||||
#define bool_t uint8_t
|
||||
#endif/*bool_t*/
|
||||
|
||||
typedef void* pointer_t;
|
||||
|
||||
#ifndef ftk_min
|
||||
|
@ -990,7 +990,7 @@ ret_t widget_to_xml(widget_t* widget) {
|
||||
const key_type_value_t* kv = widget_type_find_by_value(widget->type);
|
||||
|
||||
log_debug("<%s name=\"%s\" x=\"%d\" y=\"%d\" w=\"%d\" h=\"%d\"", kv->name, widget->name.str,
|
||||
widget->x, widget->y, widget->w, widget->h);
|
||||
(int)(widget->x), (int)(widget->y), (int)(widget->w), (int)(widget->h));
|
||||
text = widget_get_text(widget);
|
||||
if (text) {
|
||||
char str[128];
|
||||
|
@ -227,7 +227,7 @@ static ret_t window_manager_paint_normal(widget_t* widget, canvas_t* c) {
|
||||
ENSURE(widget_paint(WIDGETP(wm), c) == RET_OK);
|
||||
ENSURE(canvas_end_frame(c) == RET_OK);
|
||||
}
|
||||
log_debug("%s x=%d y=%d w=%d h=%d\n", __func__, r.x, r.y, r.w, r.h);
|
||||
log_debug("%s x=%d y=%d w=%d h=%d\n", __func__, (int)(r.x), (int)(r.y), (int)(r.w), (int)(r.h));
|
||||
}
|
||||
|
||||
wm->last_dirty_rect = wm->dirty_rect;
|
||||
@ -251,6 +251,7 @@ static ret_t window_manager_paint_animation(widget_t* widget, canvas_t* c) {
|
||||
|
||||
ret_t ret = window_animator_update(wm->animator, start_time);
|
||||
uint32_t cost = time_now_ms() - start_time;
|
||||
(void)cost;
|
||||
|
||||
if (ret == RET_DONE) {
|
||||
window_animator_destroy(wm->animator);
|
||||
|
@ -35,6 +35,7 @@ typedef struct _lcd_mem_t {
|
||||
} lcd_mem_t;
|
||||
|
||||
lcd_t* lcd_mem_create(wh_t w, wh_t h, bool_t alloc);
|
||||
lcd_t* lcd_mem_create_single_fb(wh_t w, wh_t h, uint8_t* fbuff);
|
||||
lcd_t* lcd_mem_create_double_fb(wh_t w, wh_t h, uint8_t* online_fb, uint8_t* offline_fb);
|
||||
|
||||
END_C_DECLS
|
||||
|
@ -367,3 +367,12 @@ lcd_t* lcd_mem_create_double_fb(wh_t w, wh_t h, uint8_t* online_fb, uint8_t* off
|
||||
|
||||
return lcd;
|
||||
}
|
||||
|
||||
lcd_t* lcd_mem_create_single_fb(wh_t w, wh_t h, uint8_t* fbuff) {
|
||||
lcd_t* lcd = lcd_mem_create(w, h, FALSE);
|
||||
lcd_mem_t* mem = (lcd_mem_t*)lcd;
|
||||
|
||||
mem->fbuff = fbuff;
|
||||
|
||||
return lcd;
|
||||
}
|
||||
|
@ -1,203 +1,203 @@
|
||||
/**
|
||||
* File: main_loop_simple.c
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: a simple main loop
|
||||
*
|
||||
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
* 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-05-17 li xianjing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#include "main_loop/main_loop_simple.h"
|
||||
|
||||
static ret_t main_loop_simple_queue_event(main_loop_t* l, const event_queue_req_t* r) {
|
||||
ret_t ret = RET_FAIL;
|
||||
main_loop_simple_t* loop = (main_loop_simple_t*)l;
|
||||
|
||||
mutex_lock(loop->mutex);
|
||||
ret = event_queue_send(loop->queue, r);
|
||||
mutex_unlock(loop->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ret_t main_loop_simple_recv_event(main_loop_simple_t* loop, event_queue_req_t* r) {
|
||||
ret_t ret = RET_FAIL;
|
||||
|
||||
mutex_lock(loop->mutex);
|
||||
ret = event_queue_recv(loop->queue, r);
|
||||
mutex_unlock(loop->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_t main_loop_post_pointer_event(main_loop_t* l, bool_t pressed, xy_t x, xy_t y) {
|
||||
event_queue_req_t r;
|
||||
pointer_event_t event;
|
||||
main_loop_simple_t* loop = (main_loop_simple_t*)l;
|
||||
|
||||
return_value_if_fail(loop != NULL, RET_BAD_PARAMS);
|
||||
|
||||
loop->last_x = x;
|
||||
loop->last_y = y;
|
||||
|
||||
event.x = x;
|
||||
event.y = y;
|
||||
event.button = 0;
|
||||
|
||||
if (pressed) {
|
||||
if (loop->pressed) {
|
||||
event.e.type = EVT_POINTER_MOVE;
|
||||
} else {
|
||||
event.e.type = EVT_POINTER_DOWN;
|
||||
}
|
||||
loop->pressed = TRUE;
|
||||
event.pressed = loop->pressed;
|
||||
|
||||
r.pointer_event = event;
|
||||
|
||||
return main_loop_queue_event(l, &r);
|
||||
} else {
|
||||
if (loop->pressed) {
|
||||
loop->pressed = FALSE;
|
||||
event.e.type = EVT_POINTER_UP;
|
||||
event.pressed = loop->pressed;
|
||||
|
||||
r.pointer_event = event;
|
||||
return main_loop_queue_event(l, &r);
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t main_loop_post_key_event(main_loop_t* l, bool_t pressed, uint8_t key) {
|
||||
event_queue_req_t r;
|
||||
key_event_t event;
|
||||
main_loop_simple_t* loop = (main_loop_simple_t*)l;
|
||||
return_value_if_fail(loop != NULL, RET_BAD_PARAMS);
|
||||
|
||||
loop->last_key = key;
|
||||
event.key = key;
|
||||
|
||||
if (pressed) {
|
||||
loop->key_pressed = TRUE;
|
||||
event.e.type = EVT_KEY_DOWN;
|
||||
|
||||
r.key_event = event;
|
||||
return main_loop_queue_event(l, &r);
|
||||
} else {
|
||||
if (loop->key_pressed) {
|
||||
loop->key_pressed = FALSE;
|
||||
event.e.type = EVT_KEY_UP;
|
||||
|
||||
r.key_event = event;
|
||||
return main_loop_queue_event(l, &r);
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t main_loop_dispatch_events(main_loop_simple_t* loop) {
|
||||
event_queue_req_t r;
|
||||
widget_t* widget = loop->wm;
|
||||
|
||||
while (main_loop_simple_recv_event(loop, &r) == RET_OK) {
|
||||
switch (r.event.type) {
|
||||
case EVT_POINTER_DOWN:
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&(r.pointer_event));
|
||||
break;
|
||||
case EVT_POINTER_MOVE:
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&(r.pointer_event));
|
||||
break;
|
||||
case EVT_POINTER_UP:
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&(r.pointer_event));
|
||||
break;
|
||||
case REQ_ADD_IDLE: {
|
||||
idle_add(r.add_idle.func, r.add_idle.e.target);
|
||||
break;
|
||||
}
|
||||
case REQ_ADD_TIMER: {
|
||||
timer_add(r.add_timer.func, r.add_timer.e.target, r.add_timer.duration);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/*HANDLE OTHER EVENT*/
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t main_loop_dispatch_input(main_loop_simple_t* loop) {
|
||||
if (loop->dispatch_input) {
|
||||
loop->dispatch_input(loop);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t main_loop_simple_run(main_loop_t* l) {
|
||||
main_loop_simple_t* loop = (main_loop_simple_t*)l;
|
||||
|
||||
while (l->running) {
|
||||
timer_dispatch();
|
||||
main_loop_dispatch_input(loop);
|
||||
main_loop_dispatch_events(loop);
|
||||
idle_dispatch();
|
||||
|
||||
window_manager_paint(loop->wm, &(loop->canvas));
|
||||
main_loop_sleep(l);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
main_loop_simple_t* main_loop_simple_init(int w, int h) {
|
||||
static main_loop_simple_t s_main_loop_simple;
|
||||
main_loop_simple_t* loop = &s_main_loop_simple;
|
||||
|
||||
memset(loop, 0x00, sizeof(main_loop_simple_t));
|
||||
|
||||
loop->w = w;
|
||||
loop->h = h;
|
||||
loop->wm = window_manager();
|
||||
return_value_if_fail(loop->wm != NULL, NULL);
|
||||
|
||||
loop->queue = event_queue_create(20);
|
||||
return_value_if_fail(loop->queue != NULL, NULL);
|
||||
|
||||
loop->mutex = mutex_create();
|
||||
return_value_if_fail(loop->mutex != NULL, NULL);
|
||||
|
||||
loop->base.run = main_loop_simple_run;
|
||||
loop->base.queue_event = main_loop_simple_queue_event;
|
||||
|
||||
window_manager_resize(loop->wm, w, h);
|
||||
main_loop_set((main_loop_t*)loop);
|
||||
|
||||
return loop;
|
||||
}
|
||||
|
||||
ret_t main_loop_simple_reset(main_loop_simple_t* loop) {
|
||||
return_value_if_fail(loop != NULL, RET_BAD_PARAMS);
|
||||
event_queue_destroy(loop->queue);
|
||||
mutex_destroy(loop->mutex);
|
||||
|
||||
memset(loop, 0x00, sizeof(main_loop_simple_t));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
/**
|
||||
* File: main_loop_simple.c
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: a simple main loop
|
||||
*
|
||||
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
* 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-05-17 li xianjing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#include "main_loop/main_loop_simple.h"
|
||||
|
||||
static ret_t main_loop_simple_queue_event(main_loop_t* l, const event_queue_req_t* r) {
|
||||
ret_t ret = RET_FAIL;
|
||||
main_loop_simple_t* loop = (main_loop_simple_t*)l;
|
||||
|
||||
tk_mutex_lock(loop->mutex);
|
||||
ret = event_queue_send(loop->queue, r);
|
||||
tk_mutex_unlock(loop->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ret_t main_loop_simple_recv_event(main_loop_simple_t* loop, event_queue_req_t* r) {
|
||||
ret_t ret = RET_FAIL;
|
||||
|
||||
tk_mutex_lock(loop->mutex);
|
||||
ret = event_queue_recv(loop->queue, r);
|
||||
tk_mutex_unlock(loop->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_t main_loop_post_pointer_event(main_loop_t* l, bool_t pressed, xy_t x, xy_t y) {
|
||||
event_queue_req_t r;
|
||||
pointer_event_t event;
|
||||
main_loop_simple_t* loop = (main_loop_simple_t*)l;
|
||||
|
||||
return_value_if_fail(loop != NULL, RET_BAD_PARAMS);
|
||||
|
||||
loop->last_x = x;
|
||||
loop->last_y = y;
|
||||
|
||||
event.x = x;
|
||||
event.y = y;
|
||||
event.button = 0;
|
||||
|
||||
if (pressed) {
|
||||
if (loop->pressed) {
|
||||
event.e.type = EVT_POINTER_MOVE;
|
||||
} else {
|
||||
event.e.type = EVT_POINTER_DOWN;
|
||||
}
|
||||
loop->pressed = TRUE;
|
||||
event.pressed = loop->pressed;
|
||||
|
||||
r.pointer_event = event;
|
||||
|
||||
return main_loop_queue_event(l, &r);
|
||||
} else {
|
||||
if (loop->pressed) {
|
||||
loop->pressed = FALSE;
|
||||
event.e.type = EVT_POINTER_UP;
|
||||
event.pressed = loop->pressed;
|
||||
|
||||
r.pointer_event = event;
|
||||
return main_loop_queue_event(l, &r);
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t main_loop_post_key_event(main_loop_t* l, bool_t pressed, uint8_t key) {
|
||||
event_queue_req_t r;
|
||||
key_event_t event;
|
||||
main_loop_simple_t* loop = (main_loop_simple_t*)l;
|
||||
return_value_if_fail(loop != NULL, RET_BAD_PARAMS);
|
||||
|
||||
loop->last_key = key;
|
||||
event.key = key;
|
||||
|
||||
if (pressed) {
|
||||
loop->key_pressed = TRUE;
|
||||
event.e.type = EVT_KEY_DOWN;
|
||||
|
||||
r.key_event = event;
|
||||
return main_loop_queue_event(l, &r);
|
||||
} else {
|
||||
if (loop->key_pressed) {
|
||||
loop->key_pressed = FALSE;
|
||||
event.e.type = EVT_KEY_UP;
|
||||
|
||||
r.key_event = event;
|
||||
return main_loop_queue_event(l, &r);
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t main_loop_dispatch_events(main_loop_simple_t* loop) {
|
||||
event_queue_req_t r;
|
||||
widget_t* widget = loop->wm;
|
||||
|
||||
while (main_loop_simple_recv_event(loop, &r) == RET_OK) {
|
||||
switch (r.event.type) {
|
||||
case EVT_POINTER_DOWN:
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&(r.pointer_event));
|
||||
break;
|
||||
case EVT_POINTER_MOVE:
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&(r.pointer_event));
|
||||
break;
|
||||
case EVT_POINTER_UP:
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&(r.pointer_event));
|
||||
break;
|
||||
case REQ_ADD_IDLE: {
|
||||
idle_add(r.add_idle.func, r.add_idle.e.target);
|
||||
break;
|
||||
}
|
||||
case REQ_ADD_TIMER: {
|
||||
timer_add(r.add_timer.func, r.add_timer.e.target, r.add_timer.duration);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/*HANDLE OTHER EVENT*/
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t main_loop_dispatch_input(main_loop_simple_t* loop) {
|
||||
if (loop->dispatch_input) {
|
||||
loop->dispatch_input(loop);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t main_loop_simple_run(main_loop_t* l) {
|
||||
main_loop_simple_t* loop = (main_loop_simple_t*)l;
|
||||
|
||||
while (l->running) {
|
||||
timer_dispatch();
|
||||
main_loop_dispatch_input(loop);
|
||||
main_loop_dispatch_events(loop);
|
||||
idle_dispatch();
|
||||
|
||||
window_manager_paint(loop->wm, &(loop->canvas));
|
||||
main_loop_sleep(l);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
main_loop_simple_t* main_loop_simple_init(int w, int h) {
|
||||
static main_loop_simple_t s_main_loop_simple;
|
||||
main_loop_simple_t* loop = &s_main_loop_simple;
|
||||
|
||||
memset(loop, 0x00, sizeof(main_loop_simple_t));
|
||||
|
||||
loop->w = w;
|
||||
loop->h = h;
|
||||
loop->wm = window_manager();
|
||||
return_value_if_fail(loop->wm != NULL, NULL);
|
||||
|
||||
loop->queue = event_queue_create(20);
|
||||
return_value_if_fail(loop->queue != NULL, NULL);
|
||||
|
||||
loop->mutex = tk_mutex_create();
|
||||
return_value_if_fail(loop->mutex != NULL, NULL);
|
||||
|
||||
loop->base.run = main_loop_simple_run;
|
||||
loop->base.queue_event = main_loop_simple_queue_event;
|
||||
|
||||
window_manager_resize(loop->wm, w, h);
|
||||
main_loop_set((main_loop_t*)loop);
|
||||
|
||||
return loop;
|
||||
}
|
||||
|
||||
ret_t main_loop_simple_reset(main_loop_simple_t* loop) {
|
||||
return_value_if_fail(loop != NULL, RET_BAD_PARAMS);
|
||||
event_queue_destroy(loop->queue);
|
||||
tk_mutex_destroy(loop->mutex);
|
||||
|
||||
memset(loop, 0x00, sizeof(main_loop_simple_t));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ typedef struct _main_loop_simple_t {
|
||||
xy_t last_x;
|
||||
xy_t last_y;
|
||||
uint8_t last_key;
|
||||
mutex_t* mutex;
|
||||
tk_mutex_t* mutex;
|
||||
void* user1;
|
||||
void* user2;
|
||||
void* user3;
|
||||
|
@ -24,21 +24,21 @@
|
||||
|
||||
#ifdef WIN32
|
||||
#include "Windows.h"
|
||||
#define mutex_handle_t HANDLE
|
||||
#define tk_mutex_handle_t HANDLE
|
||||
#elif defined(HAS_PTHREAD)
|
||||
#include "pthread.h"
|
||||
#define mutex_handle_t pthread_mutex_t
|
||||
#define tk_mutex_handle_t pthread_mutex_t
|
||||
#else
|
||||
#define mutex_handle_t int
|
||||
#define tk_mutex_handle_t int
|
||||
#endif
|
||||
|
||||
struct _mutex_t {
|
||||
ret_t created;
|
||||
mutex_handle_t mutex;
|
||||
tk_mutex_handle_t mutex;
|
||||
};
|
||||
|
||||
mutex_t* mutex_create() {
|
||||
mutex_t* mutex = (mutex_t*)TKMEM_ZALLOC(mutex_t);
|
||||
tk_mutex_t* tk_mutex_create() {
|
||||
tk_mutex_t* mutex = (tk_mutex_t*)TKMEM_ZALLOC(tk_mutex_t);
|
||||
return_value_if_fail(mutex != NULL, NULL);
|
||||
#ifdef WIN32
|
||||
mutex->mutex = CreateMutex(NULL, RET_BAD_PARAMS, NULL);
|
||||
@ -50,7 +50,7 @@ mutex_t* mutex_create() {
|
||||
return mutex;
|
||||
}
|
||||
|
||||
ret_t mutex_lock(mutex_t* mutex) {
|
||||
ret_t tk_mutex_lock(tk_mutex_t* mutex) {
|
||||
return_value_if_fail(mutex != NULL && mutex->created, RET_BAD_PARAMS);
|
||||
|
||||
#ifdef WIN32
|
||||
@ -62,7 +62,7 @@ ret_t mutex_lock(mutex_t* mutex) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t mutex_unlock(mutex_t* mutex) {
|
||||
ret_t tk_mutex_unlock(tk_mutex_t* mutex) {
|
||||
return_value_if_fail(mutex != NULL && mutex->created, RET_BAD_PARAMS);
|
||||
|
||||
#ifdef WIN32
|
||||
@ -74,7 +74,7 @@ ret_t mutex_unlock(mutex_t* mutex) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t mutex_destroy(mutex_t* mutex) {
|
||||
ret_t tk_mutex_destroy(tk_mutex_t* mutex) {
|
||||
return_value_if_fail(mutex != NULL && mutex->created, RET_BAD_PARAMS);
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -70,7 +70,7 @@ static uint32_t s_heap_mem[1024 * 1024];
|
||||
|
||||
ret_t platform_prepare(void) {
|
||||
#ifndef HAS_STD_MALLOC
|
||||
mem_init(s_heap_mem, sizeof(s_heap_mem));
|
||||
tk_mem_init(s_heap_mem, sizeof(s_heap_mem));
|
||||
#endif /*HAS_STD_MALLOC*/
|
||||
|
||||
return RET_OK;
|
||||
|
@ -22,25 +22,25 @@
|
||||
#include "base/mem.h"
|
||||
#include "base/mutex.h"
|
||||
|
||||
struct _mutex_t {
|
||||
struct _tk_mutex_t {
|
||||
uint32_t none;
|
||||
};
|
||||
|
||||
static mutex_t s_mutex_null;
|
||||
static tk_mutex_t s_tk_mutex_null;
|
||||
|
||||
mutex_t* mutex_create() { return &s_mutex_null; }
|
||||
tk_mutex_t* tk_mutex_create() { return &s_tk_mutex_null; }
|
||||
|
||||
ret_t mutex_lock(mutex_t* mutex) {
|
||||
ret_t tk_mutex_lock(tk_mutex_t* mutex) {
|
||||
(void)mutex;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t mutex_unlock(mutex_t* mutex) {
|
||||
ret_t tk_mutex_unlock(tk_mutex_t* mutex) {
|
||||
(void)mutex;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t mutex_destroy(mutex_t* mutex) {
|
||||
ret_t tk_mutex_destroy(tk_mutex_t* mutex) {
|
||||
(void)mutex;
|
||||
return RET_OK;
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ static ret_t ui_builder_default_on_widget_start(ui_builder_t* b, const widget_de
|
||||
b->root = widget;
|
||||
}
|
||||
|
||||
log_debug("%d %d %d %d %d\n", type, x, y, w, h);
|
||||
log_debug("%d %d %d %d %d\n", (int)(type), (int)(x), (int)(y), (int)(w), (int)(h));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
31
src/vgcanvas/vgcanvas_null.c
Normal file
31
src/vgcanvas/vgcanvas_null.c
Normal file
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* File: vgcanvas.c
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: vector graphics canvas base on agg
|
||||
*
|
||||
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
* 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-03-24 Li XianJing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base/mem.h"
|
||||
#include "base/vgcanvas.h"
|
||||
|
||||
vgcanvas_t* vgcanvas_create(uint32_t w, uint32_t h, bitmap_format_t format, void* buff) {
|
||||
(void)w;
|
||||
(void)h;
|
||||
(void)format;
|
||||
(void)buff;
|
||||
return NULL;
|
||||
}
|
Loading…
Reference in New Issue
Block a user