4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-01-30 22:10:28 +08:00

gui 引擎已知问题优化修复;

This commit is contained in:
yangfasheng 2018-01-02 11:50:17 +08:00
parent 2c145743cb
commit c4e8c922d3
10 changed files with 142 additions and 56 deletions

View File

@ -342,6 +342,8 @@ struct rtgui_event_gesture
_RTGUI_EVENT_WIN_ELEMENTS
enum rtgui_gesture_type type;
rt_uint32_t win_acti_cnt; /* win id */
};
/*
@ -359,6 +361,8 @@ struct rtgui_event_mouse
/* id of touch session(from down to up). Different session should have
* different id. id should never be 0. */
rt_uint32_t id;
rt_uint32_t win_acti_cnt; /* win id */
};
#define RTGUI_MOUSE_BUTTON_LEFT 0x01
#define RTGUI_MOUSE_BUTTON_RIGHT 0x02
@ -379,6 +383,8 @@ struct rtgui_event_kbd
{
_RTGUI_EVENT_WIN_ELEMENTS
rt_uint32_t win_acti_cnt; /* win id */
rt_uint16_t type; /* key down or up */
rt_uint16_t key; /* current key */
rt_uint16_t mod; /* current key modifiers */

View File

@ -81,6 +81,8 @@ struct rtgui_app
rtgui_idle_func_t on_idle;
unsigned int window_cnt;
/* window activate count */
unsigned int win_acti_cnt;
void *user_data;
};
@ -115,6 +117,9 @@ rt_err_t rtgui_app_set_as_wm(struct rtgui_app *app);
void rtgui_app_set_main_win(struct rtgui_app *app, struct rtgui_win *win);
struct rtgui_win* rtgui_app_get_main_win(struct rtgui_app *app);
/* get the topwin belong app window activate count */
unsigned int rtgui_app_get_win_acti_cnt(void);
#ifdef __cplusplus
}
#endif

View File

@ -54,6 +54,8 @@ DECLARE_CLASS_TYPE(win);
#define RTGUI_WIN_STYLE_ONBTM 0x0080 /* window is in the bottom layer */
#define RTGUI_WIN_STYLE_MAINWIN 0x0106 /* window is a main window */
#define RTGUI_WIN_MAGIC 0xA5A55A5A /* win magic flag */
#define RTGUI_WIN_STYLE_DEFAULT (RTGUI_WIN_STYLE_CLOSEBOX | RTGUI_WIN_STYLE_MINIBOX)
#define WINTITLE_HEIGHT 20
@ -143,6 +145,7 @@ struct rtgui_win
/* app ref_count */
rt_uint16_t app_ref_count;
/* win magic flag, magic value is 0xA5A55A5A */
rt_uint32_t magic;
};

View File

@ -1689,6 +1689,13 @@ void rtgui_dc_get_rect(struct rtgui_dc *dc, rtgui_rect_t *rect)
dc_hw = (struct rtgui_dc_hw *) dc;
owner = dc_hw->owner;
rtgui_widget_get_rect(owner, rect);
if (owner->extent.x1 + rect->x2 > dc_hw->hw_driver->width)
rect->x2 = dc_hw->hw_driver->width - owner->extent.x1;
if (owner->extent.y1 + rect->y2 > dc_hw->hw_driver->height)
rect->y2 = dc_hw->hw_driver->height - owner->extent.y1;
break;
}
case RTGUI_DC_BUFFER:
@ -1806,7 +1813,7 @@ extern void rtgui_mouse_hide_cursor(void);
struct rtgui_dc *rtgui_dc_begin_drawing(rtgui_widget_t *owner)
{
struct rtgui_dc *dc;
struct rtgui_widget *widget;
struct rtgui_widget *widget, *parent;
struct rtgui_win *win;
RT_ASSERT(owner != RT_NULL);
@ -1815,11 +1822,18 @@ struct rtgui_dc *rtgui_dc_begin_drawing(rtgui_widget_t *owner)
if (win == RT_NULL)
return RT_NULL;
parent = (struct rtgui_widget *)win;
if (!(win->flag & RTGUI_WIN_FLAG_ACTIVATE) &&
(win->outer_clip.extents.x1 == win->outer_clip.extents.x2 ||
win->outer_clip.extents.y1 == win->outer_clip.extents.y2))
return RT_NULL;
if (!(win->flag & RTGUI_WIN_FLAG_ACTIVATE) &&
(parent->clip.extents.x1 == parent->clip.extents.x2 ||
parent->clip.extents.y1 == parent->clip.extents.y2))
return RT_NULL;
/* increase drawing count */
if (win->drawing == 0)
{

View File

@ -216,32 +216,22 @@ static void rtgui_dc_hw_fill_rect(struct rtgui_dc *self, struct rtgui_rect *rect
return;
if (x1 < dc->owner->extent.x1)
x1 = dc->owner->extent.x1;
if (x1 < 0)
x1 = 0;
x2 = rect->x2 + dc->owner->extent.x1;
if (x2 < dc->owner->extent.x1)
return;
if (x2 > dc->owner->extent.x2)
x2 = dc->owner->extent.x2;
if (x2 > dc->hw_driver->width)
x2 = dc->hw_driver->width;
y1 = rect->y1 + dc->owner->extent.y1;
if (y1 > dc->owner->extent.y2)
return;
if (y1 < dc->owner->extent.y1)
y1 = dc->owner->extent.y1;
if (y1 < 0)
y1 = 0;
y2 = rect->y2 + dc->owner->extent.y1;
if (y2 < dc->owner->extent.y1)
return;
if (y2 > dc->owner->extent.y2)
y2 = dc->owner->extent.y2;
if (y2 > dc->hw_driver->height)
y2 = dc->hw_driver->height;
/* fill rect */
for (; y1 < y2; y1++)

View File

@ -103,7 +103,7 @@ static void rtgui_bitmap_font_draw_text(struct rtgui_font *font, struct rtgui_dc
RT_ASSERT(bmp_font != RT_NULL);
rtgui_font_get_metrics(rtgui_dc_get_gc(dc)->font, text, &text_rect);
rtgui_font_get_metrics(font, text, &text_rect);
rtgui_rect_move_to_align(rect, &text_rect, RTGUI_DC_TEXTALIGN(dc));
/* parameter check */

View File

@ -29,7 +29,7 @@
#include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_app.h>
#include <rtgui/widgets/window.h>
#include "topwin.h"
#include <topwin.h>
static void _rtgui_app_constructor(struct rtgui_app *app)
{
@ -43,6 +43,7 @@ static void _rtgui_app_constructor(struct rtgui_app *app)
app->state_flag = RTGUI_APP_FLAG_EXITED;
app->ref_count = 0;
app->window_cnt = 0;
app->win_acti_cnt = 0;
app->exit_code = 0;
app->tid = RT_NULL;
app->mq = RT_NULL;
@ -204,7 +205,7 @@ rt_inline rt_bool_t _rtgui_application_dest_handle(
if (wevent->wid == RT_NULL)
return RT_FALSE;
if (wevent->wid->magic != 0xA5A55A5A)
if (wevent->wid->magic != RTGUI_WIN_MAGIC)
{
return RT_FALSE;
}
@ -249,19 +250,55 @@ rt_bool_t rtgui_app_event_handler(struct rtgui_object *object, rtgui_event_t *ev
switch (event->type)
{
case RTGUI_EVENT_PAINT:
case RTGUI_EVENT_VPAINT_REQ:
case RTGUI_EVENT_KBD:
{
struct rtgui_event_kbd *kbd = (struct rtgui_event_kbd*)event;
if (kbd->win_acti_cnt != app->win_acti_cnt)
break;
_rtgui_application_dest_handle(app, event);
}
break;
case RTGUI_EVENT_MOUSE_BUTTON:
case RTGUI_EVENT_MOUSE_MOTION:
case RTGUI_EVENT_CLIP_INFO:
{
struct rtgui_event_mouse *wevent = (struct rtgui_event_mouse *)event;
if (wevent->win_acti_cnt != app->win_acti_cnt)
break;
_rtgui_application_dest_handle(app, event);
}
break;
case RTGUI_EVENT_GESTURE:
{
struct rtgui_event_gesture *wevent = (struct rtgui_event_gesture *)event;
if (wevent->win_acti_cnt != app->win_acti_cnt)
break;
_rtgui_application_dest_handle(app, event);
}
break;
case RTGUI_EVENT_WIN_ACTIVATE:
{
app->win_acti_cnt++;
_rtgui_application_dest_handle(app, event);
}
break;
case RTGUI_EVENT_PAINT:
case RTGUI_EVENT_VPAINT_REQ:
case RTGUI_EVENT_CLIP_INFO:
case RTGUI_EVENT_WIN_DEACTIVATE:
case RTGUI_EVENT_WIN_CLOSE:
case RTGUI_EVENT_WIN_MOVE:
case RTGUI_EVENT_WIN_SHOW:
case RTGUI_EVENT_WIN_HIDE:
case RTGUI_EVENT_KBD:
case RTGUI_EVENT_GESTURE:
_rtgui_application_dest_handle(app, event);
break;
@ -507,3 +544,16 @@ struct rtgui_win *rtgui_app_get_main_win(struct rtgui_app *app)
}
RTM_EXPORT(rtgui_app_get_main_win);
unsigned int rtgui_app_get_win_acti_cnt(void)
{
struct rtgui_app *app = rtgui_topwin_app_get_focus();
if (app)
{
return app->win_acti_cnt;
}
return 0;
}
RTM_EXPORT(rtgui_app_get_win_acti_cnt);

View File

@ -853,6 +853,19 @@ struct rtgui_topwin *rtgui_topwin_get_focus(void)
return _rtgui_topwin_get_focus_from_list(&_rtgui_topwin_list);
}
struct rtgui_app *rtgui_topwin_app_get_focus(void)
{
struct rtgui_app *topwin_app = RT_NULL;
struct rtgui_topwin *topwin = rtgui_topwin_get_focus();
if (topwin)
{
topwin_app = topwin->app;
}
return topwin_app;
}
static struct rtgui_topwin *_rtgui_topwin_get_wnd_from_tree(struct rt_list_node *list,
int x, int y,
rt_bool_t exclude_modaled)
@ -978,7 +991,8 @@ static void _rtgui_topwin_redraw_tree(struct rt_list_node *list,
if (rtgui_rect_is_intersect(rect, &(topwin->extent)) == RT_EOK)
{
epaint->wid = topwin->wid;
rtgui_send(topwin->app, &(epaint->parent), sizeof(*epaint));
// < XY do !!! >
//rtgui_send(topwin->app, &(epaint->parent), sizeof(*epaint));
}
_rtgui_topwin_redraw_tree(&topwin->child_list, rect, epaint);
@ -1026,7 +1040,8 @@ rt_err_t rtgui_topwin_modal_enter(struct rtgui_event_win_modal_enter *event)
parent_top->flag |= WINTITLE_MODALED;
parent_top->wid->flag |= RTGUI_WIN_FLAG_UNDER_MODAL;
parent_top = parent_top->parent;
} while (parent_top);
}
while (parent_top);
topwin->flag &= ~WINTITLE_MODALED;
topwin->wid->flag &= ~RTGUI_WIN_FLAG_UNDER_MODAL;

View File

@ -64,6 +64,9 @@ void rtgui_topwin_remove_monitor_rect(struct rtgui_win *wid, rtgui_rect_t *rect)
/* get the topwin that is currently focused */
struct rtgui_topwin *rtgui_topwin_get_focus(void);
/* get the topwin which app I belong */
struct rtgui_app *rtgui_topwin_app_get_focus(void);
struct rtgui_topwin *rtgui_topwin_get_topmost_window_shown_all(void);
#endif

View File

@ -440,7 +440,7 @@ rt_base_t rtgui_win_show(struct rtgui_win *win, rt_bool_t is_modal)
{
RTGUI_WIDGET_UNHIDE(win);
win->magic = 0xA5A55A5A;
win->magic = RTGUI_WIN_MAGIC;
if (is_modal)
win->flag |= RTGUI_WIN_FLAG_MODAL;