From dda23c2074bb7dbb8df9251e41c2daea1b447cd7 Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 1 Dec 2008 18:54:29 +0000 Subject: Integrated mouse support git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1384 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/graphics/nxmu/nxmu_mouse.c | 57 +++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 18 deletions(-) (limited to 'nuttx/graphics/nxmu/nxmu_mouse.c') diff --git a/nuttx/graphics/nxmu/nxmu_mouse.c b/nuttx/graphics/nxmu/nxmu_mouse.c index 922b12c93..c18fb98eb 100644 --- a/nuttx/graphics/nxmu/nxmu_mouse.c +++ b/nuttx/graphics/nxmu/nxmu_mouse.c @@ -43,6 +43,7 @@ #include #include +#include #include #include "nxfe.h" @@ -61,8 +62,8 @@ ****************************************************************************/ static struct nxgl_point_s g_mpos; -static struct nxgl_rect_s g_mrange; -static struct g_mbutton; +static struct nxgl_point_s g_mrange; +static ubyte g_mbutton; /**************************************************************************** * Public Data @@ -99,20 +100,26 @@ void nxmu_mouseinit(int x, int y) * Description: * Report mouse position info to the specified window * + * Input Parameters: + * wnd - The window to receive the mouse report + * + * Returned Value: + * 0: Mouse report sent; >0: Mouse report not sent; <0: An error occurred + * ****************************************************************************/ -void nxmu_mousereport(struct nxbe_window_s *wnd) +int nxmu_mousereport(struct nxbe_window_s *wnd) { struct nxclimsg_mousein_s outmsg; int ret; /* Does this window support mouse callbacks? */ - if (win->cb->mousein) + if (wnd->cb->mousein) { - /* Yes.. Does the mount position lie within the window? */ + /* Yes.. Is the mouse position visible in this window? */ - if (nxgl_rectinside(wnd->bounds, g_mpos)) + if (nxbe_visible(wnd, &g_mpos)) { /* Yes... Convert the mouse position to window relative * coordinates and send it to the client @@ -121,7 +128,7 @@ void nxmu_mousereport(struct nxbe_window_s *wnd) outmsg.msgid = NX_CLIMSG_MOUSEIN; outmsg.wnd = wnd; outmsg.buttons = g_mbutton; - nxgl_vectsubtract(&outmsg.pos, g_mpos, wnd->origin); + nxgl_vectsubtract(&outmsg.pos, &g_mpos, &wnd->origin); ret = mq_send(wnd->conn->swrmq, outmsg, sizeof(struct nxclimsg_mousein_s), NX_SVRMSG_PRIO); @@ -129,8 +136,13 @@ void nxmu_mousereport(struct nxbe_window_s *wnd) { gdbg("mq_send failed: %d\n", errno); } + return ret; } } + + /* No error occurred, but the mouse report was not sent */ + + return 1; } /**************************************************************************** @@ -144,11 +156,12 @@ void nxmu_mousereport(struct nxbe_window_s *wnd) ****************************************************************************/ void nxmu_mousein(FAR struct nxfe_state_s *fe, - FAR const struct nxgl_point_s *pos, int button) + FAR const struct nxgl_point_s *pos, int buttons) { struct nxbe_window_s *wnd; - x_coord_t x = pos->x; - x_coord_t y = pos->y; + nxgl_coord_t x = pos->x; + nxgl_coord_t y = pos->y; + int ret; /* Clip x and y to within the bounding rectangle */ @@ -156,35 +169,43 @@ void nxmu_mousein(FAR struct nxfe_state_s *fe, { x = 0; } - else if (x >= g_mbound.x) + else if (x >= g_mrange.x) { - x = g_mbound.x - 1; + x = g_mrange.x - 1; } if (y < 0) { y = 0; } - else if (y >= g_mbound.y) + else if (y >= g_mrange.y) { - y = g_mbound.y - 1; + y = g_mrange.y - 1; } /* Look any change in values */ - if (x != g_mpos.x || y != g_mpos.y || button != g_mbutton) + if (x != g_mpos.x || y != g_mpos.y || buttons != g_mbutton) { /* Update the mouse value */ g_mpos.x = x; g_mpos.y = y; - b_mbutton = button; + g_mbutton = buttons; + - /* Pick the window to receive the mouse event */ + /* Pick the window to receive the mouse event. Start with + * the top window and go down. Step with the first window + * that gets the mouse report + */ for (wnd = fe->be.topwnd; wnd; wnd = wnd->below) { - nxmu_mousereport(wnd); + ret = nxsu_mousereport(wnd); + if (ret == 0) + { + break; + } } } } -- cgit v1.2.3