summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-12-01 18:54:29 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-12-01 18:54:29 +0000
commitdda23c2074bb7dbb8df9251e41c2daea1b447cd7 (patch)
tree15e07d44e6416f8d95d00b95551b72de26eb9ce0 /nuttx
parent8e6e74e3d8a9f3ca62793363827378af2dea413d (diff)
downloadpx4-nuttx-dda23c2074bb7dbb8df9251e41c2daea1b447cd7.tar.gz
px4-nuttx-dda23c2074bb7dbb8df9251e41c2daea1b447cd7.tar.bz2
px4-nuttx-dda23c2074bb7dbb8df9251e41c2daea1b447cd7.zip
Integrated mouse support
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1384 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/examples/nx/nx_main.c55
-rw-r--r--nuttx/graphics/nxmu/nxfe.h8
-rw-r--r--nuttx/graphics/nxmu/nxmu_mouse.c57
-rw-r--r--nuttx/graphics/nxmu/nxmu_requestbkgd.c2
-rw-r--r--nuttx/graphics/nxsu/nx_mousein.c56
-rw-r--r--nuttx/graphics/nxsu/nx_requestbkgd.c2
-rw-r--r--nuttx/graphics/nxsu/nxfe.h8
7 files changed, 139 insertions, 49 deletions
diff --git a/nuttx/examples/nx/nx_main.c b/nuttx/examples/nx/nx_main.c
index febc8cc7f..039b1645e 100644
--- a/nuttx/examples/nx/nx_main.c
+++ b/nuttx/examples/nx/nx_main.c
@@ -167,7 +167,7 @@ static nxgl_mxpixel_t g_color2[CONFIG_NX_NPLANES];
static void nxeg_redraw1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
boolean more, FAR void *arg)
{
- message("nxeg_redraw%d: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s arg=%p\n",
+ message("nxeg_redraw%d: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
(int)arg, hwnd,
rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
more ? "TRUE" : "FALSE");
@@ -181,11 +181,10 @@ static void nxeg_redraw1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
static void nxeg_redraw2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
boolean more, FAR void *arg)
{
- message("nxeg_redraw%d: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s arg=%p\n",
+ message("nxeg_redraw%d: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
(int)arg, hwnd,
rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
- more ? "TRUE" : "FALSE",
- arg);
+ more ? "TRUE" : "FALSE");
nx_fill(hwnd, rect, g_color2);
}
@@ -248,7 +247,7 @@ static void nxeg_mousein1(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
ubyte buttons, FAR void *arg)
{
message("nxeg_mousein%d: hwnd=%p pos=(%d,%d) button=%02x\n",
- arg, hwnd, pos->x, pos->y, buttons);
+ (int)arg, hwnd, pos->x, pos->y, buttons);
}
#endif
@@ -260,8 +259,31 @@ static void nxeg_mousein1(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
static void nxeg_mousein2(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
ubyte buttons, FAR void *arg)
{
- message("nxeg_mousein2: hwnd=%p pos=(%d,%d) button=%02x\n",
- hwnd, pos->x, pos->y, buttons);
+ message("nxeg_mousein%d: hwnd=%p pos=(%d,%d) button=%02x\n",
+ (int)arg, hwnd, pos->x, pos->y, buttons);
+}
+#endif
+
+/****************************************************************************
+ * Name: nxeg_drivemouse
+ ****************************************************************************/
+
+#ifdef CONFIG_NX_MOUSE
+static void nxeg_drivemouse(void)
+{
+ nxgl_coord_t x;
+ nxgl_coord_t y;
+ nxgl_coord_t xstep = g_xres / 8;
+ nxgl_coord_t ystep = g_yres / 8;
+
+ for (x = 0; x < g_xres; x += xstep)
+ {
+ for (y = 0; y < g_yres; y += ystep)
+ {
+ message("nxeg_drivemouse: Mouse left button at (%d,%d)\n", x, y);
+ (void)nx_mousein(g_hnx, x, y, NX_MOUSE_LEFTBUTTON);
+ }
+ }
}
#endif
@@ -681,7 +703,18 @@ int user_start(int argc, char *argv[])
message("user_start: Sleeping\n\n");
sleep(1);
- /* Lower window 1 */
+ /* Put mouse left-button clicks all over the screen and see who responds */
+
+#ifdef CONFIG_NX_MOUSE
+ nxeg_drivemouse();
+
+ /* Sleep a bit */
+
+ message("user_start: Sleeping\n\n");
+ sleep(1);
+#endif
+
+ /* Raise window 2 */
message("user_start: Raise window #2\n");
ret = nx_raise(hwnd2);
@@ -692,6 +725,12 @@ int user_start(int argc, char *argv[])
goto errout_with_hwnd2;
}
+ /* Put mouse left-button clicks all over the screen and see who responds */
+
+#ifdef CONFIG_NX_MOUSE
+ nxeg_drivemouse();
+#endif
+
/* Sleep a bit */
message("user_start: Sleeping\n\n");
diff --git a/nuttx/graphics/nxmu/nxfe.h b/nuttx/graphics/nxmu/nxfe.h
index b8786dc63..04fdf9a40 100644
--- a/nuttx/graphics/nxmu/nxfe.h
+++ b/nuttx/graphics/nxmu/nxfe.h
@@ -571,10 +571,16 @@ EXTERN 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
+ *
****************************************************************************/
#ifdef CONFIG_NX_MOUSE
-EXTERN void nxmu_mousereport(struct nxbe_window_s *wnd);
+EXTERN int nxmu_mousereport(struct nxbe_window_s *wnd);
#endif
/****************************************************************************
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 <errno.h>
#include <debug.h>
+#include <nuttx/nxglib.h>
#include <nuttx/nx.h>
#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;
+ }
}
}
}
diff --git a/nuttx/graphics/nxmu/nxmu_requestbkgd.c b/nuttx/graphics/nxmu/nxmu_requestbkgd.c
index 962cb01ac..6dba04a98 100644
--- a/nuttx/graphics/nxmu/nxmu_requestbkgd.c
+++ b/nuttx/graphics/nxmu/nxmu_requestbkgd.c
@@ -116,7 +116,7 @@ void nxmu_requestbkgd(FAR struct nxfe_conn_s *conn,
/* Provide the mouse settings */
#ifdef CONFIG_NX_MOUSE
- nxsu_mousereport(be->bkgd);
+ nxsu_mousereport(&be->bkgd);
#endif
}
diff --git a/nuttx/graphics/nxsu/nx_mousein.c b/nuttx/graphics/nxsu/nx_mousein.c
index 31c9483d2..1c5427138 100644
--- a/nuttx/graphics/nxsu/nx_mousein.c
+++ b/nuttx/graphics/nxsu/nx_mousein.c
@@ -43,7 +43,9 @@
#include <errno.h>
#include <debug.h>
+#include <nuttx/nxglib.h>
#include <nuttx/nx.h>
+
#include "nxfe.h"
#ifdef CONFIG_NX_MOUSE
@@ -61,8 +63,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,26 +101,37 @@ void nxsu_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 nxsu_mousereport(struct nxbe_window_s *wnd)
+int nxsu_mousereport(struct nxbe_window_s *wnd)
{
struct nxgl_point_s relpos;
/* 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 */
- nxgl_vectsubtract(&relpos, g_mpos, wnd->origin);
- win->cb->mousein((NXWINDOW)wnd, &relpos, g_mbutton, wnd->arg);
+ nxgl_vectsubtract(&relpos, &g_mpos, &wnd->origin);
+ wnd->cb->mousein((NXWINDOW)wnd, &relpos, g_mbutton, wnd->arg);
+ return OK;
}
}
+
+ /* No error occurred, but the mouse report was not sent */
+
+ return 1;
}
/****************************************************************************
@@ -135,9 +148,7 @@ int nx_mousein(NXHANDLE handle, nxgl_coord_t x, nxgl_coord_t y, ubyte buttons)
{
FAR struct nxfe_state_s *fe = (FAR struct nxfe_state_s *)handle;
struct nxbe_window_s *wnd;
-
- x_coord_t x = pos->x;
- x_coord_t y = pos->y;
+ int ret;
/* Clip x and y to within the bounding rectangle */
@@ -145,35 +156,42 @@ int nx_mousein(NXHANDLE handle, nxgl_coord_t x, nxgl_coord_t y, ubyte buttons)
{
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)
{
- nxsu_mousereport(wnd);
+ ret = nxsu_mousereport(wnd);
+ if (ret == 0)
+ {
+ break;
+ }
}
}
}
diff --git a/nuttx/graphics/nxsu/nx_requestbkgd.c b/nuttx/graphics/nxsu/nx_requestbkgd.c
index 782679464..32eed1ab1 100644
--- a/nuttx/graphics/nxsu/nx_requestbkgd.c
+++ b/nuttx/graphics/nxsu/nx_requestbkgd.c
@@ -137,7 +137,7 @@ int nx_requestbkgd(NXHANDLE handle, FAR const struct nx_callback_s *cb)
/* Provide the mouse settings to the client */
#ifdef CONFIG_NX_MOUSE
- nxsu_mousereport(be->bkgd);
+ nxsu_mousereport(&be->bkgd);
#endif
/* In this single-user mode, we could return the background window
diff --git a/nuttx/graphics/nxsu/nxfe.h b/nuttx/graphics/nxsu/nxfe.h
index 7fd65f2f3..a95ae9c60 100644
--- a/nuttx/graphics/nxsu/nxfe.h
+++ b/nuttx/graphics/nxsu/nxfe.h
@@ -166,10 +166,16 @@ EXTERN void nxsu_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
+ *
****************************************************************************/
#ifdef CONFIG_NX_MOUSE
-EXTERN void nxsu_mousereport(struct nxbe_window_s *wnd);
+EXTERN int nxsu_mousereport(struct nxbe_window_s *wnd);
#endif
#undef EXTERN