mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
rework main loop
This commit is contained in:
parent
b98540a502
commit
bdc017faca
@ -46,7 +46,7 @@ static main_loop_t* s_default_main_loop = NULL;
|
||||
|
||||
main_loop_t* main_loop(void) { return s_default_main_loop; }
|
||||
|
||||
ret_t main_loop_set_default(main_loop_t* loop) {
|
||||
ret_t main_loop_set(main_loop_t* loop) {
|
||||
return_value_if_fail(loop != NULL, RET_BAD_PARAMS);
|
||||
s_default_main_loop = loop;
|
||||
|
||||
|
@ -44,7 +44,7 @@ struct _main_loop_t {
|
||||
main_loop_t* main_loop_init(int w, int h);
|
||||
|
||||
main_loop_t* main_loop(void);
|
||||
ret_t main_loop_set_default(main_loop_t* loop);
|
||||
ret_t main_loop_set(main_loop_t* loop);
|
||||
|
||||
ret_t main_loop_run(main_loop_t* l);
|
||||
ret_t main_loop_quit(main_loop_t* l);
|
||||
|
@ -26,7 +26,6 @@
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
ret_t platform_prepare(void);
|
||||
uint32_t get_time_ms(void);
|
||||
|
||||
END_C_DECLS
|
||||
|
@ -19,10 +19,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef WITH_G2D
|
||||
|
||||
#include "base/g2d.h"
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f4xx_hal_rcc.h"
|
||||
#include "stm32f4xx_hal_dma2d.h"
|
||||
#include "base/g2d.h"
|
||||
|
||||
#define DMA2D_WORKING ((DMA2D->CR & DMA2D_CR_START))
|
||||
#define DMA2D_WAIT \
|
||||
@ -224,3 +226,4 @@ ret_t g2d_blend_image(bitmap_t* fb, bitmap_t* img, rect_t* src, xy_t x, xy_t y)
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
#endif/*WITH_G2D*/
|
||||
|
@ -1,134 +0,0 @@
|
||||
/**
|
||||
* File: lcd_rtthread.c
|
||||
* Author: Li XianJing <xianjimli@hotmail.com>
|
||||
* Brief: rtthread implemented lcd interface/
|
||||
*
|
||||
* 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-02-22 Li XianJing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lcd/lcd_mem.h"
|
||||
#include "lcd/lcd_rtthread.h"
|
||||
|
||||
typedef struct _lcd_rtthread_t {
|
||||
lcd_t base;
|
||||
lcd_mem_t* lcd_mem;
|
||||
struct rtgui_graphic_driver* driver;
|
||||
} lcd_rtthread_t;
|
||||
|
||||
static ret_t lcd_rtthread_begin_frame(lcd_t* lcd, rect_t* dr) {
|
||||
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
|
||||
|
||||
lcd->dirty_rect = dr;
|
||||
rtt->lcd_mem->pixels = rtt->driver->framebuffer;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_rtthread_draw_hline(lcd_t* lcd, xy_t x, xy_t y, wh_t w) {
|
||||
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(rtt->lcd_mem);
|
||||
mem->stroke_color = lcd->stroke_color;
|
||||
|
||||
return lcd_draw_hline(mem, x, y, w);
|
||||
}
|
||||
|
||||
static ret_t lcd_rtthread_draw_vline(lcd_t* lcd, xy_t x, xy_t y, wh_t h) {
|
||||
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(rtt->lcd_mem);
|
||||
mem->stroke_color = lcd->stroke_color;
|
||||
|
||||
return lcd_draw_vline(mem, x, y, h);
|
||||
}
|
||||
|
||||
static ret_t lcd_rtthread_draw_points(lcd_t* lcd, point_t* points, uint32_t nr) {
|
||||
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(rtt->lcd_mem);
|
||||
mem->stroke_color = lcd->stroke_color;
|
||||
|
||||
return lcd_draw_points(mem, points, nr);
|
||||
}
|
||||
|
||||
static ret_t lcd_rtthread_fill_rect(lcd_t* lcd, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(rtt->lcd_mem);
|
||||
mem->fill_color = lcd->fill_color;
|
||||
|
||||
return lcd_fill_rect(mem, x, y, w, h);
|
||||
}
|
||||
|
||||
static ret_t lcd_rtthread_draw_glyph(lcd_t* lcd, glyph_t* glyph, rect_t* src, xy_t x, xy_t y) {
|
||||
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(rtt->lcd_mem);
|
||||
mem->text_color = lcd->text_color;
|
||||
mem->fill_color = lcd->fill_color;
|
||||
|
||||
return lcd_draw_glyph(mem, glyph, src, x, y);
|
||||
}
|
||||
|
||||
static ret_t lcd_rtthread_draw_image(lcd_t* lcd, bitmap_t* img, rect_t* src, rect_t* dst) {
|
||||
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(rtt->lcd_mem);
|
||||
|
||||
return lcd_draw_image(mem, img, src, dst);
|
||||
}
|
||||
|
||||
static ret_t lcd_rtthread_end_frame(lcd_t* lcd) {
|
||||
rtgui_rect_t rect;
|
||||
rect_t* dr = lcd->dirty_rect;
|
||||
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
|
||||
|
||||
rect.x1 = dr->x;
|
||||
rect.y1 = dr->y;
|
||||
rect.x2 = dr->x + dr->w;
|
||||
rect.y2 = dr->y + dr->w;
|
||||
|
||||
rtgui_graphic_driver_screen_update(rtt->driver, &rect);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_rtthread_destroy(lcd_t* lcd) {
|
||||
(void)lcd;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
lcd_t* lcd_rtthread_init(struct rtgui_graphic_driver* driver) {
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
static lcd_rtthread_t lcd;
|
||||
lcd_t* base = &(lcd.base);
|
||||
return_value_if_fail(driver != NULL, NULL);
|
||||
|
||||
memset(&lcd, 0x00, sizeof(lcd_rtthread_t));
|
||||
|
||||
base->begin_frame = lcd_rtthread_begin_frame;
|
||||
base->draw_vline = lcd_rtthread_draw_vline;
|
||||
base->draw_hline = lcd_rtthread_draw_hline;
|
||||
base->fill_rect = lcd_rtthread_fill_rect;
|
||||
base->draw_image = lcd_rtthread_draw_image;
|
||||
base->draw_glyph = lcd_rtthread_draw_glyph;
|
||||
base->draw_points = lcd_rtthread_draw_points;
|
||||
base->end_frame = lcd_rtthread_end_frame;
|
||||
base->destroy = lcd_rtthread_destroy;
|
||||
|
||||
base->width = (wh_t)driver->width;
|
||||
base->height = (wh_t)driver->height;
|
||||
|
||||
lcd.driver = driver;
|
||||
lcd.lcd_mem = (lcd_mem_t*)lcd_mem_create(base->width, base->height, FALSE);
|
||||
|
||||
return base;
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* File: lcd_rtthread.h
|
||||
* Author: Li XianJing <xianjimli@hotmail.com>
|
||||
* Brief: rtthread implemented lcd interface/
|
||||
*
|
||||
* 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-02-22 Li XianJing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LCD_RTT_H
|
||||
#define LCD_RTT_H
|
||||
|
||||
#include "base/lcd.h"
|
||||
#include "rtgui/driver.h"
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
lcd_t* lcd_rtthread_init(struct rtgui_graphic_driver* driver);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /*LCD_RTT_H*/
|
@ -1,32 +0,0 @@
|
||||
/**
|
||||
* File: lcd_stm32_raw.c
|
||||
* Author: Li XianJing <xianjimli@hotmail.com>
|
||||
* Brief: stm32_raw implemented lcd interface/
|
||||
*
|
||||
* 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-02-16 Li XianJing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gui.h"
|
||||
#include "lcd_driver.h"
|
||||
#include "lcd/lcd_reg.h"
|
||||
|
||||
#define set_window_func TFT_SetWindow
|
||||
#define write_data_func TFT_WriteData
|
||||
|
||||
#include "base/color.h"
|
||||
#include "base/mem.h"
|
||||
#include "lcd/rgb565.h"
|
||||
#include "lcd/lcd_reg.inc"
|
@ -1,37 +0,0 @@
|
||||
/**
|
||||
* file: lcd_stm32_raw.h
|
||||
* author: li xianjing <xianjimli@hotmail.com>
|
||||
* brief: stm32_rawory implemented lcd interface/
|
||||
*
|
||||
* copyright (c) 2018 - 2018 li xianjing <xianjimli@hotmail.com>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LCD_STM32_RAW_H
|
||||
#define LCD_STM32_RAW_H
|
||||
|
||||
#include "base/lcd.h"
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
typedef void (*tft_write_data_t)(uint16_t dat);
|
||||
typedef void (*tft_set_window_t)(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
|
||||
|
||||
lcd_t* lcd_stm32_raw_create(wh_t w, wh_t h, tft_write_data_t write_data,
|
||||
tft_set_window_t set_window);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /*LCD_STM32_RAW_H*/
|
@ -245,7 +245,7 @@ main_loop_t* main_loop_init(int w, int h) {
|
||||
loop.wm = wm;
|
||||
window_manager_resize(wm, w, h);
|
||||
main_loop_nanovg_create_window(&loop, fm, w, h);
|
||||
main_loop_set_default(base);
|
||||
main_loop_set(base);
|
||||
|
||||
log_debug("%s:%s\n", __FILE__, __func__);
|
||||
|
||||
|
139
src/main_loop/main_loop_raw.inc
Normal file
139
src/main_loop/main_loop_raw.inc
Normal file
@ -0,0 +1,139 @@
|
||||
|
||||
typedef struct _main_loop_raw_t {
|
||||
main_loop_t base;
|
||||
|
||||
int w;
|
||||
int h;
|
||||
widget_t* wm;
|
||||
canvas_t canvas;
|
||||
|
||||
xy_t touch_x;
|
||||
xy_t touch_y;
|
||||
bool_t pressed;
|
||||
event_queue_t* queue;
|
||||
} main_loop_raw_t;
|
||||
|
||||
static main_loop_raw_t s_main_loop;
|
||||
|
||||
static void dispatch_touch_events(bool_t pressed, xy_t x, xy_t y) {
|
||||
event_all_t any;
|
||||
pointer_event_t event;
|
||||
main_loop_raw_t* loop = &s_main_loop;
|
||||
|
||||
loop->touch_x = x;
|
||||
loop->touch_y = y;
|
||||
|
||||
event.button = 0;
|
||||
event.x = loop->touch_x;
|
||||
event.y = loop->touch_y;
|
||||
|
||||
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;
|
||||
|
||||
any.e.pointer_event = event;
|
||||
event_queue_send(loop->queue, &any);
|
||||
} else {
|
||||
if (loop->pressed) {
|
||||
loop->pressed = FALSE;
|
||||
event.e.type = EVT_POINTER_UP;
|
||||
event.pressed = loop->pressed;
|
||||
|
||||
any.e.pointer_event = event;
|
||||
event_queue_send(loop->queue, &any);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ret_t main_loop_raw_dispatch(main_loop_raw_t* loop) {
|
||||
event_all_t event;
|
||||
widget_t* widget = loop->wm;
|
||||
uint8_t key = platform_scan_key();
|
||||
|
||||
/*TODO dispatch key*/
|
||||
while (event_queue_recv(loop->queue, &event) == RET_OK) {
|
||||
switch (event.e.event.type) {
|
||||
case EVT_POINTER_DOWN:
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&(event.e.pointer_event));
|
||||
break;
|
||||
case EVT_POINTER_MOVE:
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&(event.e.pointer_event));
|
||||
break;
|
||||
case EVT_POINTER_UP:
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&(event.e.pointer_event));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t main_loop_raw_paint(main_loop_raw_t* loop) {
|
||||
canvas_t* c = &(loop->canvas);
|
||||
|
||||
// return canvas_test_paint(c, loop->pressed, loop->touch_x, loop->touch_y);
|
||||
return window_manager_paint(loop->wm, c);
|
||||
}
|
||||
|
||||
static ret_t main_loop_raw_run(main_loop_t* l) {
|
||||
main_loop_raw_t* loop = (main_loop_raw_t*)l;
|
||||
|
||||
while (l->running) {
|
||||
timer_check();
|
||||
main_loop_raw_dispatch(loop);
|
||||
idle_dispatch();
|
||||
|
||||
main_loop_raw_paint(loop);
|
||||
if (!WINDOW_MANAGER(loop->wm)->animating) {
|
||||
platform_delay_ms(30);
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t main_loop_raw_quit(main_loop_t* l) { return RET_OK; }
|
||||
|
||||
static ret_t main_loop_raw_destroy(main_loop_t* l) {
|
||||
main_loop_raw_t* loop = (main_loop_raw_t*)l;
|
||||
event_queue_destroy(loop->queue);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
main_loop_t* main_loop_init(int w, int h) {
|
||||
lcd_t* lcd = NULL;
|
||||
event_queue_t* queue = NULL;
|
||||
widget_t* wm = window_manager();
|
||||
main_loop_raw_t* loop = &s_main_loop;
|
||||
main_loop_t* base = &(loop->base);
|
||||
return_value_if_fail(wm != NULL, NULL);
|
||||
|
||||
queue = event_queue_create(20);
|
||||
return_value_if_fail(queue != NULL, NULL);
|
||||
|
||||
lcd = platform_create_lcd(w, h);
|
||||
return_value_if_fail(lcd != NULL, NULL);
|
||||
|
||||
memset(&loop, 0x00, sizeof(loop));
|
||||
|
||||
base->run = main_loop_raw_run;
|
||||
base->quit = main_loop_raw_quit;
|
||||
base->destroy = main_loop_raw_destroy;
|
||||
|
||||
loop->wm = wm;
|
||||
loop->queue = queue;
|
||||
window_manager_resize(wm, w, h);
|
||||
|
||||
main_loop_set(base);
|
||||
canvas_init(&(loop->canvas), lcd, font_manager());
|
||||
|
||||
return base;
|
||||
}
|
@ -1,196 +0,0 @@
|
||||
/**
|
||||
* file: main_loop_rtthread.c
|
||||
* author: li xianjing <xianjimli@hotmail.com>
|
||||
* brief: rtthread implemented main_loop interface
|
||||
*
|
||||
* copyright (c) 2018 - 2018 li xianjing <xianjimli@hotmail.com>
|
||||
*
|
||||
* 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-17 li xianjing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base/timer.h"
|
||||
#include "rtgui/event.h"
|
||||
#include "lcd/lcd_rtthread.h"
|
||||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/event.h>
|
||||
#include <rtgui/rtgui_app.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include "base/font_manager.h"
|
||||
#include "base/window_manager.h"
|
||||
#include "main_loop/main_loop_rtthread.h"
|
||||
|
||||
typedef struct _main_loop_rtthread_t {
|
||||
main_loop_t base;
|
||||
|
||||
int w;
|
||||
int h;
|
||||
widget_t* wm;
|
||||
canvas_t canvas;
|
||||
|
||||
xy_t touch_x;
|
||||
xy_t touch_y;
|
||||
bool_t pressed;
|
||||
struct rtgui_app* app;
|
||||
struct rtgui_win* main_win;
|
||||
} main_loop_rtthread_t;
|
||||
|
||||
static main_loop_rtthread_t loop;
|
||||
|
||||
static void dispatch_touch_events(bool_t pressed, xy_t x, xy_t y) {
|
||||
pointer_event_t event;
|
||||
widget_t* widget = loop.wm;
|
||||
|
||||
loop.touch_x = x;
|
||||
loop.touch_y = y;
|
||||
|
||||
event.button = 0;
|
||||
event.x = loop.touch_x;
|
||||
event.y = loop.touch_y;
|
||||
|
||||
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;
|
||||
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&event);
|
||||
} else {
|
||||
if (loop.pressed) {
|
||||
loop.pressed = FALSE;
|
||||
event.e.type = EVT_POINTER_UP;
|
||||
event.pressed = loop.pressed;
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ret_t main_loop_rtthread_dispatch(main_loop_rtthread_t* loop) {
|
||||
rt_err_t result = 0;
|
||||
widget_t* widget = loop->wm;
|
||||
struct rtgui_event* rt_event = (struct rtgui_event*)(loop->app->event_buffer);
|
||||
|
||||
result = rtgui_recv(rt_event, sizeof(union rtgui_event_generic), 100);
|
||||
if (result == RT_EOK) {
|
||||
uint32_t type = rt_event->type;
|
||||
switch (type) {
|
||||
case RTGUI_EVENT_MOUSE_BUTTON: {
|
||||
pointer_event_t event;
|
||||
struct rtgui_event_mouse* e = (struct rtgui_event_mouse*)rt_event;
|
||||
event.x = e->x;
|
||||
event.y = e->y;
|
||||
event.button = e->button;
|
||||
if (e->button & RTGUI_MOUSE_BUTTON_DOWN) {
|
||||
printf("type=%d down\n", type);
|
||||
loop->pressed = 1;
|
||||
event.e.type = EVT_POINTER_DOWN;
|
||||
event.pressed = loop->pressed;
|
||||
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&event);
|
||||
} else {
|
||||
printf("type=%d up\n", type);
|
||||
event.e.type = EVT_POINTER_UP;
|
||||
event.pressed = loop->pressed;
|
||||
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&event);
|
||||
loop->pressed = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RTGUI_EVENT_MOUSE_MOTION: {
|
||||
struct rtgui_event_mouse* e = (struct rtgui_event_mouse*)rt_event;
|
||||
break;
|
||||
}
|
||||
case RTGUI_EVENT_KBD: {
|
||||
struct rtgui_event_kbd* e = (struct rtgui_event_kbd*)rt_event;
|
||||
break;
|
||||
}
|
||||
case RTGUI_EVENT_PAINT: {
|
||||
struct rtgui_event_paint* e = (struct rtgui_event_paint*)rt_event;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t main_loop_rtthread_paint(main_loop_rtthread_t* loop) {
|
||||
canvas_t* c = &(loop->canvas);
|
||||
|
||||
return window_manager_paint(loop->wm, c);
|
||||
}
|
||||
|
||||
static ret_t main_loop_rtthread_run(main_loop_t* l) {
|
||||
main_loop_rtthread_t* loop = (main_loop_rtthread_t*)l;
|
||||
|
||||
while (l->running) {
|
||||
timer_check();
|
||||
main_loop_rtthread_dispatch(loop);
|
||||
main_loop_rtthread_paint(loop);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t main_loop_rtthread_quit(main_loop_t* l) { return RET_OK; }
|
||||
|
||||
static ret_t main_loop_rtthread_destroy(main_loop_t* l) {
|
||||
(void)l;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
rt_bool_t on_event(struct rtgui_object* object, rtgui_event_t* event) {
|
||||
uint32_t type = event->type;
|
||||
|
||||
printf("type=%d\n", type);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
main_loop_t* main_loop_init(int w, int h) {
|
||||
lcd_t* lcd = NULL;
|
||||
widget_t* wm = window_manager();
|
||||
main_loop_t* base = &(loop.base);
|
||||
struct rtgui_graphic_driver* driver = rtgui_graphic_driver_get_default();
|
||||
return_value_if_fail(driver != NULL, NULL);
|
||||
|
||||
memset(&loop, 0x00, sizeof(loop));
|
||||
|
||||
base->run = main_loop_rtthread_run;
|
||||
base->quit = main_loop_rtthread_quit;
|
||||
base->destroy = main_loop_rtthread_destroy;
|
||||
|
||||
loop.wm = wm;
|
||||
loop.app = rtgui_app_create("gui_demo");
|
||||
window_manager_resize(wm, driver->width, driver->height);
|
||||
|
||||
lcd = lcd_rtthread_init(driver);
|
||||
canvas_init(&(loop.canvas), lcd, font_manager());
|
||||
|
||||
// DebugBreak();
|
||||
loop.main_win = rtgui_mainwin_create(RT_NULL, "UiWindow", RTGUI_WIN_STYLE_NO_TITLE);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(&loop), on_event);
|
||||
rtgui_win_show(loop.main_win, RT_FALSE);
|
||||
main_loop_set_default(base);
|
||||
|
||||
(void)w;
|
||||
(void)h;
|
||||
|
||||
return base;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/**
|
||||
* file: main_loop_rtthread.h
|
||||
* author: li xianjing <xianjimli@hotmail.com>
|
||||
* brief: rtthread implemented main_loop interface
|
||||
*
|
||||
* copyright (c) 2018 - 2018 li xianjing <xianjimli@hotmail.com>
|
||||
*
|
||||
* 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-22 li xianjing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TK_MAIN_LOOP_RTTHREAD_H
|
||||
#define TK_MAIN_LOOP_RTTHREAD_H
|
||||
|
||||
#include "base/main_loop.h"
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
main_loop_t* main_loop_init(int w, int h);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /*TK_MAIN_LOOP_RTTHREAD_H*/
|
@ -215,7 +215,7 @@ main_loop_t* main_loop_init(int w, int h) {
|
||||
loop.wm = wm;
|
||||
window_manager_resize(wm, w, h);
|
||||
main_loop_sdl2_create_window(&loop, fm, w, h);
|
||||
main_loop_set_default(base);
|
||||
main_loop_set(base);
|
||||
|
||||
log_debug("%s:%s\n", __FILE__, __func__);
|
||||
|
||||
|
@ -1,184 +0,0 @@
|
||||
/**
|
||||
* file: main_loop_stm32_raw.c
|
||||
* author: li xianjing <xianjimli@hotmail.com>
|
||||
* brief: stm32_raw implemented main_loop interface
|
||||
*
|
||||
* copyright (c) 2018 - 2018 li xianjing <xianjimli@hotmail.com>
|
||||
*
|
||||
* 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-17 li xianjing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#include "button.h"
|
||||
#include "delay.h"
|
||||
#include "flash.h"
|
||||
#include "gui.h"
|
||||
#include "lcd_driver.h"
|
||||
#include "led.h"
|
||||
#include "rtc.h"
|
||||
#include "stdlib.h"
|
||||
#include "sys.h"
|
||||
#include "tim.h"
|
||||
#include "touch.h"
|
||||
#include "usart.h"
|
||||
|
||||
#include "base/idle.h"
|
||||
#include "base/timer.h"
|
||||
#include "lcd/lcd_reg.h"
|
||||
#include "base/event_queue.h"
|
||||
#include "base/font_manager.h"
|
||||
#include "base/window_manager.h" 8
|
||||
#include "main_loop/main_loop_stm32_raw.h"
|
||||
|
||||
typedef struct _main_loop_stm32_raw_t {
|
||||
main_loop_t base;
|
||||
|
||||
int w;
|
||||
int h;
|
||||
widget_t* wm;
|
||||
canvas_t canvas;
|
||||
|
||||
xy_t touch_x;
|
||||
xy_t touch_y;
|
||||
bool_t pressed;
|
||||
event_queue_t* queue;
|
||||
} main_loop_stm32_raw_t;
|
||||
|
||||
static main_loop_stm32_raw_t loop;
|
||||
|
||||
static void dispatch_touch_events(bool_t pressed, xy_t x, xy_t y) {
|
||||
event_all_t any;
|
||||
pointer_event_t event;
|
||||
|
||||
loop.touch_x = x;
|
||||
loop.touch_y = y;
|
||||
|
||||
event.button = 0;
|
||||
event.x = loop.touch_x;
|
||||
event.y = loop.touch_y;
|
||||
|
||||
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;
|
||||
|
||||
any.e.pointer_event = event;
|
||||
event_queue_send(loop.queue, &any);
|
||||
} else {
|
||||
if (loop.pressed) {
|
||||
loop.pressed = FALSE;
|
||||
event.e.type = EVT_POINTER_UP;
|
||||
event.pressed = loop.pressed;
|
||||
|
||||
any.e.pointer_event = event;
|
||||
event_queue_send(loop.queue, &any);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TIM3_IRQHandler(void) {
|
||||
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) {
|
||||
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
|
||||
|
||||
if (TOUCH_Scan() == 0) {
|
||||
dispatch_touch_events(TRUE, TouchData.lcdx, TouchData.lcdy);
|
||||
} else {
|
||||
dispatch_touch_events(FALSE, TouchData.lcdx, TouchData.lcdy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ret_t main_loop_stm32_raw_dispatch(main_loop_stm32_raw_t* loop) {
|
||||
event_all_t event;
|
||||
widget_t* widget = loop->wm;
|
||||
uint8_t key = keyscan(0);
|
||||
/*TODO dispatch key*/
|
||||
while (event_queue_recv(loop->queue, &event) == RET_OK) {
|
||||
switch (event.e.event.type) {
|
||||
case EVT_POINTER_DOWN:
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&(event.e.pointer_event));
|
||||
break;
|
||||
case EVT_POINTER_MOVE:
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&(event.e.pointer_event));
|
||||
break;
|
||||
case EVT_POINTER_UP:
|
||||
window_manager_dispatch_input_event(widget, (event_t*)&(event.e.pointer_event));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t main_loop_stm32_raw_paint(main_loop_stm32_raw_t* loop) {
|
||||
canvas_t* c = &(loop->canvas);
|
||||
|
||||
// return canvas_test_paint(c, loop->pressed, loop->touch_x, loop->touch_y);
|
||||
return window_manager_paint(loop->wm, c);
|
||||
}
|
||||
|
||||
static ret_t main_loop_stm32_raw_run(main_loop_t* l) {
|
||||
main_loop_stm32_raw_t* loop = (main_loop_stm32_raw_t*)l;
|
||||
|
||||
while (l->running) {
|
||||
timer_check();
|
||||
main_loop_stm32_raw_dispatch(loop);
|
||||
idle_dispatch();
|
||||
|
||||
main_loop_stm32_raw_paint(loop);
|
||||
|
||||
delay_ms(100);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t main_loop_stm32_raw_quit(main_loop_t* l) { return RET_OK; }
|
||||
|
||||
static ret_t main_loop_stm32_raw_destroy(main_loop_t* l) {
|
||||
main_loop_stm32_raw_t* loop = (main_loop_stm32_raw_t*)l;
|
||||
event_queue_destroy(loop->queue);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
main_loop_t* main_loop_init(int w, int h) {
|
||||
lcd_t* lcd = NULL;
|
||||
event_queue_t* queue = NULL;
|
||||
widget_t* wm = window_manager();
|
||||
main_loop_t* base = &(loop.base);
|
||||
queue = event_queue_create(20);
|
||||
return_value_if_fail(queue != NULL, NULL);
|
||||
|
||||
memset(&loop, 0x00, sizeof(loop));
|
||||
|
||||
base->run = main_loop_stm32_raw_run;
|
||||
base->quit = main_loop_stm32_raw_quit;
|
||||
base->destroy = main_loop_stm32_raw_destroy;
|
||||
|
||||
loop.wm = wm;
|
||||
loop.queue = queue;
|
||||
window_manager_resize(wm, w, h);
|
||||
|
||||
lcd = lcd_reg_create(w, h);
|
||||
canvas_init(&(loop.canvas), lcd, font_manager());
|
||||
main_loop_set_default(base);
|
||||
|
||||
return base;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/**
|
||||
* file: main_loop_stm32_raw.h
|
||||
* author: li xianjing <xianjimli@hotmail.com>
|
||||
* brief: stm32_raw implemented main_loop interface
|
||||
*
|
||||
* copyright (c) 2018 - 2018 li xianjing <xianjimli@hotmail.com>
|
||||
*
|
||||
* 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-17 li xianjing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TK_MAIN_LOOP_STM32_RAW_H
|
||||
#define TK_MAIN_LOOP_STM32_RAW_H
|
||||
|
||||
#include "base/main_loop.h"
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
main_loop_t* main_loop_init(int w, int h);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /*TK_MAIN_LOOP_STM32_RAW_H*/
|
@ -22,12 +22,6 @@
|
||||
#include "base/timer.h"
|
||||
#include "base/platform.h"
|
||||
|
||||
ret_t platform_prepare() {
|
||||
timer_init(get_time_ms);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* File: platform_default.c
|
||||
* Author: Li XianJing <xianjimli@hotmail.com>
|
||||
* Brief: default platform
|
||||
*
|
||||
* 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-02-21 Li XianJing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base/timer.h"
|
||||
#include "base/platform.h"
|
||||
|
||||
ret_t platform_prepare() {
|
||||
timer_init(get_time_ms);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
uint32_t get_time_ms() {
|
||||
/**/
|
||||
return 0;
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/**
|
||||
* File: stm32f103ze_raw.c
|
||||
* Author: Li XianJing <xianjimli@hotmail.com>
|
||||
* Brief: stm32f103ze-raw platforma
|
||||
*
|
||||
* 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-02-21 Li XianJing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base/timer.h"
|
||||
#include "base/platform.h"
|
||||
#include "button.h"
|
||||
#include "delay.h"
|
||||
#include "flash.h"
|
||||
#include "gui.h"
|
||||
#include "lcd_driver.h"
|
||||
#include "led.h"
|
||||
#include "rtc.h"
|
||||
#include "stdlib.h"
|
||||
#include "sys.h"
|
||||
#include "tim.h"
|
||||
#include "touch.h"
|
||||
#include "usart.h"
|
||||
|
||||
ret_t platform_prepare() {
|
||||
delay_init();
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
||||
led_init();
|
||||
button_init();
|
||||
TFT_Init();
|
||||
TFT_ClearScreen(BLACK);
|
||||
FLASH_Init();
|
||||
TOUCH_Init();
|
||||
|
||||
TIM3_Init(50, 7199);
|
||||
rtc_init();
|
||||
|
||||
timer_init(get_time_ms);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
uint32_t get_time_ms() { return RTC_GetCounter(); }
|
@ -1,32 +0,0 @@
|
||||
/**
|
||||
* File: stm32f103ze_raw.c
|
||||
* Author: Li XianJing <xianjimli@hotmail.com>
|
||||
* Brief: stm32f103ze-raw platforma
|
||||
*
|
||||
* 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-07 Li XianJing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base/timer.h"
|
||||
#include "base/platform.h"
|
||||
#include "stm32f4xx_hal.h"
|
||||
|
||||
ret_t platform_prepare() {
|
||||
timer_init(get_time_ms);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
uint32_t get_time_ms() { return HAL_GetTick(); }
|
4
src/tk.c
4
src/tk.c
@ -21,9 +21,9 @@
|
||||
|
||||
#include "tk.h"
|
||||
#include "base/mem.h"
|
||||
#include "base/time.h"
|
||||
#include "base/timer.h"
|
||||
#include "base/locale.h"
|
||||
#include "base/platform.h"
|
||||
#include "base/main_loop.h"
|
||||
#include "font/font_bitmap.h"
|
||||
#include "base/font_manager.h"
|
||||
@ -80,8 +80,8 @@ ret_t tk_init(wh_t w, wh_t h, uint32_t* heap, uint32_t size) {
|
||||
loader = image_loader_stb();
|
||||
#endif /*WITH_STB_IMAGE*/
|
||||
|
||||
return_value_if_fail(platform_prepare() == RET_OK, RET_FAIL);
|
||||
return_value_if_fail(mem_init(heap, size) == RET_OK, RET_FAIL);
|
||||
return_value_if_fail(timer_init(time_now_ms) == RET_OK, RET_FAIL);
|
||||
|
||||
return_value_if_fail(resource_manager_set(resource_manager_create(30)) == RET_OK, RET_FAIL);
|
||||
return_value_if_fail(locale_set(locale_create(NULL, NULL)) == RET_OK, RET_FAIL);
|
||||
|
Loading…
Reference in New Issue
Block a user