diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-12-03 15:27:40 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-12-03 15:27:40 +0000 |
commit | 148215506db4a47326caf083d90ffed788583061 (patch) | |
tree | 2a6cf811d1e1c86821e0cd284c056bb2e7f531f7 /nuttx/examples/nx/nx_events.c | |
parent | 37b3d65d15fa5e041a5cdb03d404505ae293e38e (diff) | |
download | px4-nuttx-148215506db4a47326caf083d90ffed788583061.tar.gz px4-nuttx-148215506db4a47326caf083d90ffed788583061.tar.bz2 px4-nuttx-148215506db4a47326caf083d90ffed788583061.zip |
Modify examples/nx to use NXTK; fix related bugs
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1407 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/examples/nx/nx_events.c')
-rw-r--r-- | nuttx/examples/nx/nx_events.c | 277 |
1 files changed, 189 insertions, 88 deletions
diff --git a/nuttx/examples/nx/nx_events.c b/nuttx/examples/nx/nx_events.c index 9d6b2f055..a3c7d7830 100644 --- a/nuttx/examples/nx/nx_events.c +++ b/nuttx/examples/nx/nx_events.c @@ -46,12 +46,19 @@ #include <errno.h> #include <nuttx/nx.h> +#include <nuttx/nxtk.h> #include "nx_internal.h" /**************************************************************************** * Definitions ****************************************************************************/ +#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS +# define NXEGWINDOW NXWINDOW +#else +# define NXEGWINDOW NXTKWINDOW +#endif + /**************************************************************************** * Private Types ****************************************************************************/ @@ -60,26 +67,34 @@ * Private Function Prototypes ****************************************************************************/ -static void nxeg_redraw1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, - boolean morem, FAR void *arg); -static void nxeg_redraw2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, - boolean more, FAR void *arg); -static void nxeg_position1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size, - FAR const struct nxgl_point_s *pos, - FAR const struct nxgl_rect_s *bounds, - FAR void *arg); -static void nxeg_position2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size, - FAR const struct nxgl_point_s *pos, - FAR const struct nxgl_rect_s *bounds, - FAR void *arg); +static void nxeg_redraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect, + boolean morem, FAR void *arg); +static void nxeg_position(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg); #ifdef CONFIG_NX_MOUSE -static void nxeg_mousein1(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, - ubyte buttons, FAR void *arg); -static void nxeg_mousein2(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, - ubyte buttons, FAR void *arg); +static void nxeg_mousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos, + ubyte buttons, FAR void *arg); #endif #ifdef CONFIG_NX_KBD -static void nxeg_kbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch); +static void nxeg_kbdin(NXEGWINDOW hwnd, ubyte nch, const ubyte *ch); +#endif + +#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS +static void nxeg_tbredraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect, + boolean morem, FAR void *arg); +static void nxeg_tbposition(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg); +#ifdef CONFIG_NX_MOUSE +static void nxeg_tbmousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos, + ubyte buttons, FAR void *arg); +#endif +#ifdef CONFIG_NX_KBD +static void nxeg_tbkbdin(NXEGWINDOW hwnd, ubyte nch, const ubyte *ch); +#endif #endif /**************************************************************************** @@ -90,77 +105,115 @@ static void nxeg_kbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch); * Public Data ****************************************************************************/ -const struct nx_callback_s g_nxcb1 = +const struct nx_callback_s g_nxcb = { - nxeg_redraw1, /* redraw */ - nxeg_position1 /* position */ + nxeg_redraw, /* redraw */ + nxeg_position /* position */ #ifdef CONFIG_NX_MOUSE - , nxeg_mousein1 /* mousein */ + , nxeg_mousein /* mousein */ #endif #ifdef CONFIG_NX_KBD - , nxeg_kbdin1 /* my kbdin */ + , nxeg_kbdin /* my kbdin */ #endif }; -const struct nx_callback_s g_nxcb2 = +#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS +const struct nx_callback_s g_tbcb = { - nxeg_redraw2, /* redraw */ - nxeg_position2 /* position */ + nxeg_tbredraw, /* redraw */ + nxeg_tbposition /* position */ #ifdef CONFIG_NX_MOUSE - , nxeg_mousein2 /* mousein */ + , nxeg_tbmousein /* mousein */ #endif #ifdef CONFIG_NX_KBD - , nxeg_kbdin2 /* my kbdin */ + , nxeg_tbkbdin /* my kbdin */ #endif }; +#endif /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: nxeg_redraw1 + * Name: nxeg_fillwindow ****************************************************************************/ -static void nxeg_redraw1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, - boolean more, FAR void *arg) +static inline void nxeg_fillwindow(NXEGWINDOW hwnd, + FAR const struct nxgl_rect_s *rect, + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) { - 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"); - nx_fill(hwnd, rect, g_color1); + int ret; + +#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS + ret = nx_fill(hwnd, rect, color); + if (ret < 0) + { + message("nxeg_fillwindow: nx_fill failed: %d\n", errno); + } +#else + ret = nxtk_fillwindow(hwnd, rect, color); + if (ret < 0) + { + message("nxeg_fillwindow: nxtk_fillwindow failed: %d\n", errno); + } +#endif +} + +/**************************************************************************** + * Name: nxeg_fillwindow + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS +static inline void nxeg_filltoolbar(NXTKTOOLBAR htb, + FAR const struct nxgl_rect_s *rect, + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) +{ + int ret; + + ret = nxtk_filltoolbar(htb, rect, color); + if (ret < 0) + { + message("nxeg_filltoolbar: nxtk_filltoolbar failed: %d\n", errno); + } } +#endif /**************************************************************************** - * Name: nxeg_redraw2 + * Name: nxeg_redraw1 ****************************************************************************/ -static void nxeg_redraw2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, - boolean more, FAR void *arg) +static void nxeg_redraw(NXEGWINDOW 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\n", (int)arg, hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y, more ? "TRUE" : "FALSE"); - nx_fill(hwnd, rect, g_color2); + + if (arg == (FAR void *)2) + { + nxeg_fillwindow(hwnd, rect, g_color2); + } + else + { + nxeg_fillwindow(hwnd, rect, g_color1); + } } /**************************************************************************** - * Name: nxeg_position1 + * Name: nxeg_position ****************************************************************************/ -static void nxeg_position1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size, - FAR const struct nxgl_point_s *pos, - FAR const struct nxgl_rect_s *bounds, - FAR void *arg) +static void nxeg_position(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg) { /* Report the position */ - message("nxeg_position%d: hwnd=%p size={(%d,%d),(%d,%d)} pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n", - arg, hwnd, - size->pt1.x, size->pt1.y, size->pt2.x, size->pt2.y, - pos->x, pos->y, + message("nxeg_position%d: hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n", + arg, hwnd, size->w, size->h, pos->x, pos->y, bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y); /* Have we picked off the window bounds yet? */ @@ -179,30 +232,12 @@ static void nxeg_position1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size, } /**************************************************************************** - * Name: nxeg_position2 - ****************************************************************************/ - -static void nxeg_position2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size, - FAR const struct nxgl_point_s *pos, - FAR const struct nxgl_rect_s *bounds, - FAR void *arg) -{ - /* Report the position */ - - message("nxeg_position%d: hwnd=%p size={(%d,%d),(%d,%d)} pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n", - arg, hwnd, - size->pt1.x, size->pt1.y, size->pt2.x, size->pt2.y, - pos->x, pos->y, - bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y); -} - -/**************************************************************************** - * Name: nxeg_mousein1 + * Name: nxeg_mousein ****************************************************************************/ #ifdef CONFIG_NX_MOUSE -static void nxeg_mousein1(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, - ubyte buttons, FAR void *arg) +static void nxeg_mousein(NXEGWINDOW 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", (int)arg, hwnd, pos->x, pos->y, buttons); @@ -210,19 +245,6 @@ static void nxeg_mousein1(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, #endif /**************************************************************************** - * Name: nxeg_mousein2 - ****************************************************************************/ - -#ifdef CONFIG_NX_MOUSE -static void nxeg_mousein2(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", - (int)arg, hwnd, pos->x, pos->y, buttons); -} -#endif - -/**************************************************************************** * Name: nxeg_kbdinfo ****************************************************************************/ @@ -245,28 +267,109 @@ static void nxeg_kbdinfo(ubyte nch, const ubyte *ch) #endif /**************************************************************************** - * Name: nxeg_kbdin1 + * Name: nxeg_kbdin ****************************************************************************/ #ifdef CONFIG_NX_KBD -static void nxeg_kbdin1(NXWINDOW hwnd, ubyte nch, const ubyte *ch) +static void nxeg_kbdin(NXEGWINDOW hwnd, ubyte nch, const ubyte *ch) { - message("nxeg_kbdin1: hwnd=%p nch=%d\n", hwnd, nch); + message("nxeg_kbdin: hwnd=%p nch=%d\n", hwnd, nch); nxeg_kbdinfo(nch, ch); } #endif /**************************************************************************** + * Name: nxeg_tbredraw + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS +static void nxeg_tbredraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect, + boolean more, FAR void *arg) +{ + message("nxeg_tbredraw%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"); + nxeg_filltoolbar(hwnd, rect, g_tbcolor); +} +#endif + +/**************************************************************************** + * Name: nxeg_position1 + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS +static void nxeg_tbposition(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg) +{ + /* Report the position */ + + message("nxeg_ptbosition%d: hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n", + arg, hwnd, size->w, size->h, pos->x, pos->y, + bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y); +} +#endif + +/**************************************************************************** + * Name: nxeg_tbmousein + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS +#ifdef CONFIG_NX_MOUSE +static void nxeg_tbmousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos, + ubyte buttons, FAR void *arg) +{ + message("nxeg_tbmousein%d: hwnd=%p pos=(%d,%d) button=%02x\n", + (int)arg, hwnd, pos->x, pos->y, buttons); +} +#endif +#endif + +/**************************************************************************** + * Name: nxeg_tbkbdin + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS +#ifdef CONFIG_NX_KBD +static void nxeg_tbkbdin(NXEGWINDOW hwnd, ubyte nch, const ubyte *ch) +{ + message("nxeg_tbkbdin: ERROR -- toolbar should not received keyboard input\n"; + message("nxeg_tbkbdin: hwnd=%p nch=%d\n", hwnd, nch); + nxeg_kbdinfo(nch, ch); +} +#endif +#endif + +/**************************************************************************** * Name: nxeg_kbdin2 ****************************************************************************/ +#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS #ifdef CONFIG_NX_KBD -static void nxeg_kbdin2(NXWINDOW hwnd, ubyte nch, const ubyte *ch) +static void nxeg_kbdin2(NXEGWINDOW hwnd, ubyte nch, const ubyte *ch) { message("nxeg_kbdin2: hwnd=%p nch=%d\n", hwnd, nch); nxeg_kbdinfo(nch, ch); } #endif +#endif + +/**************************************************************************** + * Name: nxeg_mousein2 + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS +#ifdef CONFIG_NX_MOUSE +static void nxeg_mousein2(NXEGWINDOW 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", + (int)arg, hwnd, pos->x, pos->y, buttons); +} +#endif +#endif /**************************************************************************** * Public Functions @@ -281,8 +384,6 @@ FAR void *nx_listenerthread(FAR void *arg) { int ret; - /* Set up to catch a signal */ - /* Process events forever */ for (;;) |