summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authoryangfasheng <[email protected]>2018-01-02 11:50:17 +0800
committeryangfasheng <[email protected]>2018-01-02 11:50:17 +0800
commitc4e8c922d38ad213c92ae130dbc5f0890f98dd79 (patch)
treedc5575c0f766bfe9f2762aaf24aa323ca5f425dd /components
parent2c145743cb5526b5027d375a9731ddd0e7a4015e (diff)
gui 引擎已知问题优化修复;
Diffstat (limited to 'components')
-rw-r--r--components/gui/include/rtgui/event.h8
-rw-r--r--components/gui/include/rtgui/rtgui_app.h5
-rw-r--r--components/gui/include/rtgui/widgets/window.h17
-rw-r--r--components/gui/src/dc.c22
-rw-r--r--components/gui/src/dc_hw.c10
-rw-r--r--components/gui/src/font_bmp.c2
-rw-r--r--components/gui/src/rtgui_app.c102
-rw-r--r--components/gui/src/topwin.c23
-rw-r--r--components/gui/src/topwin.h3
-rw-r--r--components/gui/src/window.c6
10 files changed, 142 insertions, 56 deletions
diff --git a/components/gui/include/rtgui/event.h b/components/gui/include/rtgui/event.h
index 1113da10ad..78f269a239 100644
--- a/components/gui/include/rtgui/event.h
+++ b/components/gui/include/rtgui/event.h
@@ -329,7 +329,7 @@ enum rtgui_gesture_type
RTGUI_GESTURE_PINCH = 0x0002,
RTGUI_GESTURE_DRAG = 0x0004,
RTGUI_GESTURE_LONGPRESS = 0x0008,
- RTGUI_GESTURE_DRAGGED = 0x0001 | 0x0004 | 0x0008,
+ RTGUI_GESTURE_DRAGGED = 0x0001 | 0x0004 | 0x0008,
/* PINCH, DRAG finished. */
RTGUI_GESTURE_FINISH = 0x8000,
/* The corresponding gesture should be canceled. */
@@ -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 */
diff --git a/components/gui/include/rtgui/rtgui_app.h b/components/gui/include/rtgui/rtgui_app.h
index 5cb2c83acc..8d17c9a21d 100644
--- a/components/gui/include/rtgui/rtgui_app.h
+++ b/components/gui/include/rtgui/rtgui_app.h
@@ -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
diff --git a/components/gui/include/rtgui/widgets/window.h b/components/gui/include/rtgui/widgets/window.h
index d9a0d2447b..1ef59a3d44 100644
--- a/components/gui/include/rtgui/widgets/window.h
+++ b/components/gui/include/rtgui/widgets/window.h
@@ -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
@@ -88,8 +90,8 @@ struct rtgui_win
/* inherit from container */
rtgui_container_t parent;
- /* update count */
- rt_base_t update;
+ /* update count */
+ rt_base_t update;
/* drawing count */
rt_base_t drawing;
@@ -140,11 +142,12 @@ struct rtgui_win
/* Private data. */
rt_base_t (*_do_show)(struct rtgui_win *win);
-
- /* app ref_count */
- rt_uint16_t app_ref_count;
- /* win magic flag, magic value is 0xA5A55A5A */
- rt_uint32_t magic;
+
+ /* app ref_count */
+ rt_uint16_t app_ref_count;
+
+ /* win magic flag, magic value is 0xA5A55A5A */
+ rt_uint32_t magic;
};
rtgui_win_t *rtgui_win_create(struct rtgui_win *parent_window, const char *title,
diff --git a/components/gui/src/dc.c b/components/gui/src/dc.c
index 004195a43f..849f05bb28 100644
--- a/components/gui/src/dc.c
+++ b/components/gui/src/dc.c
@@ -324,9 +324,9 @@ void rtgui_dc_draw_text(struct rtgui_dc *dc, const char *text, struct rtgui_rect
}
len = strlen((const char *)text);
- if (len == 0)
- return;
-
+ if (len == 0)
+ return;
+
rtgui_font_draw(font, dc, text, len, rect);
}
RTM_EXPORT(rtgui_dc_draw_text);
@@ -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)
{
diff --git a/components/gui/src/dc_hw.c b/components/gui/src/dc_hw.c
index 2af8ae94cf..dfed6f8e9f 100644
--- a/components/gui/src/dc_hw.c
+++ b/components/gui/src/dc_hw.c
@@ -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++)
diff --git a/components/gui/src/font_bmp.c b/components/gui/src/font_bmp.c
index 1aba5c34b4..52e12c81a5 100644
--- a/components/gui/src/font_bmp.c
+++ b/components/gui/src/font_bmp.c
@@ -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 */
diff --git a/components/gui/src/rtgui_app.c b/components/gui/src/rtgui_app.c
index 9878ff4ea7..c7210c12c4 100644
--- a/components/gui/src/rtgui_app.c
+++ b/components/gui/src/rtgui_app.c
@@ -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;
@@ -203,11 +204,11 @@ rt_inline rt_bool_t _rtgui_application_dest_handle(
if (wevent->wid == RT_NULL)
return RT_FALSE;
-
- if (wevent->wid->magic != 0xA5A55A5A)
- {
- return RT_FALSE;
- }
+
+ if (wevent->wid->magic != RTGUI_WIN_MAGIC)
+ {
+ return RT_FALSE;
+ }
/* this window has been closed. */
if (wevent->wid != RT_NULL && wevent->wid->flag & RTGUI_WIN_FLAG_CLOSED)
@@ -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;
@@ -284,14 +321,14 @@ rt_bool_t rtgui_app_event_handler(struct rtgui_object *object, rtgui_event_t *ev
case RTGUI_EVENT_TIMER:
{
- rt_base_t level;
+ rt_base_t level;
struct rtgui_timer *timer;
struct rtgui_event_timer *etimer = (struct rtgui_event_timer *) event;
timer = etimer->timer;
- level = rt_hw_interrupt_disable();
+ level = rt_hw_interrupt_disable();
timer->pending_cnt--;
- rt_hw_interrupt_enable(level);
+ rt_hw_interrupt_enable(level);
RT_ASSERT(timer->pending_cnt >= 0);
if (timer->state == RTGUI_TIMER_ST_DESTROY_PENDING)
{
@@ -320,21 +357,21 @@ rt_bool_t rtgui_app_event_handler(struct rtgui_object *object, rtgui_event_t *ev
if (ecmd->wid != RT_NULL)
return _rtgui_application_dest_handle(app, event);
- else
- {
- struct rtgui_topwin *wnd;
+ else
+ {
+ struct rtgui_topwin *wnd;
- wnd = rtgui_topwin_get_focus();
- if (wnd != RT_NULL)
- {
- RT_ASSERT(wnd->flag & WINTITLE_ACTIVATE)
+ wnd = rtgui_topwin_get_focus();
+ if (wnd != RT_NULL)
+ {
+ RT_ASSERT(wnd->flag & WINTITLE_ACTIVATE)
- /* send to focus window */
- ecmd->wid = wnd->wid;
+ /* send to focus window */
+ ecmd->wid = wnd->wid;
- return _rtgui_application_dest_handle(app, event);
- }
- }
+ return _rtgui_application_dest_handle(app, event);
+ }
+ }
}
default:
return rtgui_object_event_handler(object, event);
@@ -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);
+
diff --git a/components/gui/src/topwin.c b/components/gui/src/topwin.c
index fe379be60b..91719e0c99 100644
--- a/components/gui/src/topwin.c
+++ b/components/gui/src/topwin.c
@@ -764,7 +764,7 @@ rt_err_t rtgui_topwin_move(struct rtgui_event_win_move *event)
old_rect = topwin->extent;
/* move window rect */
- rtgui_rect_move(&(topwin->extent), dx, dy);
+ rtgui_rect_move(&(topwin->extent), dx, dy);
/* move the monitor rect list */
rtgui_list_foreach(node, &(topwin->monitor_list))
@@ -772,7 +772,7 @@ rt_err_t rtgui_topwin_move(struct rtgui_event_win_move *event)
struct rtgui_mouse_monitor *monitor = rtgui_list_entry(node,
struct rtgui_mouse_monitor,
list);
- rtgui_rect_move(&(monitor->rect), dx, dy);
+ rtgui_rect_move(&(monitor->rect), dx, dy);
}
/* update windows clip info */
@@ -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;
diff --git a/components/gui/src/topwin.h b/components/gui/src/topwin.h
index 35376f889b..1aa3a73141 100644
--- a/components/gui/src/topwin.h
+++ b/components/gui/src/topwin.h
@@ -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
diff --git a/components/gui/src/window.c b/components/gui/src/window.c
index 2fe8ae8777..894203e337 100644
--- a/components/gui/src/window.c
+++ b/components/gui/src/window.c
@@ -41,7 +41,7 @@ static void _rtgui_win_constructor(rtgui_win_t *win)
RTGUI_WIDGET(win)->toplevel = win;
/* init win property */
- win->update = 0;
+ win->update = 0;
win->drawing = 0;
RTGUI_WIDGET(win)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
@@ -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;
@@ -548,7 +548,7 @@ void rtgui_win_move(struct rtgui_win *win, int x, int y)
dy = y - wgt->extent.y1;
rtgui_widget_move_to_logic(wgt, dx, dy);
}
- rtgui_rect_move(&win->outer_extent, dx, dy);
+ rtgui_rect_move(&win->outer_extent, dx, dy);
if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
{