summaryrefslogtreecommitdiff
path: root/nuttx/examples
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-12-04 16:45:06 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-12-04 16:45:06 +0000
commit6fd4a801b4330342cfdee6f44a81d64b41785c74 (patch)
tree281112b23ca6848793245604ba590feecc87743c /nuttx/examples
parent05d31bd06816565ec8af26885ecaa26851851e18 (diff)
downloadpx4-nuttx-6fd4a801b4330342cfdee6f44a81d64b41785c74.tar.gz
px4-nuttx-6fd4a801b4330342cfdee6f44a81d64b41785c74.tar.bz2
px4-nuttx-6fd4a801b4330342cfdee6f44a81d64b41785c74.zip
Add font test
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1413 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/examples')
-rw-r--r--nuttx/examples/README.txt16
-rw-r--r--nuttx/examples/nx/Makefile2
-rw-r--r--nuttx/examples/nx/nx_events.c105
-rw-r--r--nuttx/examples/nx/nx_internal.h88
-rw-r--r--nuttx/examples/nx/nx_kbdin.c373
-rw-r--r--nuttx/examples/nx/nx_main.c132
6 files changed, 584 insertions, 132 deletions
diff --git a/nuttx/examples/README.txt b/nuttx/examples/README.txt
index d4d7017a7..5aef5abf1 100644
--- a/nuttx/examples/README.txt
+++ b/nuttx/examples/README.txt
@@ -63,10 +63,18 @@ examples/nx
CONFIG_EXAMPLES_NX_VPLANE -- The plane to select from the frame-
buffer driver for use in the test. Default: 0
- CONFIG_EXAMPLES_NX_BGCOLOR -- The color of the background. Default: ' '.
- CONFIG_EXAMPLES_NX_COLOR1 -- The color of window 1. Default: '1'
- CONFIG_EXAMPLES_NX_COLOR2 -- The color of window 2. Default: '2'
- CONFIG_EXAMPLES_NX_TBCOLOR -- The color of the toolbar. Default: '3'
+ CONFIG_EXAMPLES_NX_BGCOLOR -- The color of the background. Default depends on
+ CONFIG_EXAMPLES_NX_BPP.
+ CONFIG_EXAMPLES_NX_COLOR1 -- The color of window 1. Default depends on
+ CONFIG_EXAMPLES_NX_BPP.
+ CONFIG_EXAMPLES_NX_COLOR2 -- The color of window 2. Default depends on
+ CONFIG_EXAMPLES_NX_BPP.
+ CONFIG_EXAMPLES_NX_TBCOLOR -- The color of the toolbar. Default depends on
+ CONFIG_EXAMPLES_NX_BPP.
+ CONFIG_EXAMPLES_NX_FONTCOLOR -- The color of the toolbar. Default depends on
+ CONFIG_EXAMPLES_NX_BPP.
+ CONFIG_EXAMPLES_NX_BPP -- Pixels per pixel to use. Valid options
+ include 2, 4, 8, 16, 24, and 32. Default is 32.
CONFIG_EXAMPLES_NX_RAWWINDOWS -- Use raw windows; Default is to
use pretty, framed NXTK windows with toolbars.
diff --git a/nuttx/examples/nx/Makefile b/nuttx/examples/nx/Makefile
index 2447ae575..dd67eee50 100644
--- a/nuttx/examples/nx/Makefile
+++ b/nuttx/examples/nx/Makefile
@@ -39,7 +39,7 @@
ASRCS =
AOBJS = $(ASRCS:.S=$(OBJEXT))
-CSRCS = nx_main.c nx_events.c
+CSRCS = nx_main.c nx_events.c nx_kbdin.c
ifeq ($(CONFIG_NX_MULTIUSER),y)
CSRCS += nx_server.c
endif
diff --git a/nuttx/examples/nx/nx_events.c b/nuttx/examples/nx/nx_events.c
index 083bb0f03..464c8eafd 100644
--- a/nuttx/examples/nx/nx_events.c
+++ b/nuttx/examples/nx/nx_events.c
@@ -41,7 +41,6 @@
#include <sys/types.h>
#include <stdlib.h>
-#include <ctype.h>
#include <semaphore.h>
#include <debug.h>
#include <errno.h>
@@ -54,12 +53,6 @@
* Definitions
****************************************************************************/
-#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
-# define NXEGWINDOW NXWINDOW
-#else
-# define NXEGWINDOW NXTKWINDOW
-#endif
-
/****************************************************************************
* Private Types
****************************************************************************/
@@ -78,9 +71,6 @@ static void nxeg_position(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size,
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, FAR void *arg);
-#endif
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
static void nxeg_tbredraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
@@ -93,9 +83,6 @@ static void nxeg_tbposition(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size,
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(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg);
-#endif
#endif
/****************************************************************************
@@ -142,22 +129,25 @@ const struct nx_callback_s g_tbcb =
static inline void nxeg_fillwindow(NXEGWINDOW hwnd,
FAR const struct nxgl_rect_s *rect,
- nxgl_mxpixel_t color[CONFIG_NX_NPLANES])
+ FAR struct nxeg_state_s *st)
{
int ret;
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
- ret = nx_fill(hwnd, rect, color);
+ ret = nx_fill(hwnd, rect, st->color);
if (ret < 0)
{
message("nxeg_fillwindow: nx_fill failed: %d\n", errno);
}
#else
- ret = nxtk_fillwindow(hwnd, rect, color);
+ ret = nxtk_fillwindow(hwnd, rect, st->color);
if (ret < 0)
{
message("nxeg_fillwindow: nxtk_fillwindow failed: %d\n", errno);
}
+#ifdef CONFIG_NX_KBD
+ nxeg_filltext(hwnd, rect, st);
+#endif
#endif
}
@@ -181,25 +171,19 @@ static inline void nxeg_filltoolbar(NXTKWINDOW htb,
#endif
/****************************************************************************
- * Name: nxeg_redraw1
+ * Name: nxeg_redraw
****************************************************************************/
static void nxeg_redraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
boolean more, FAR void *arg)
{
+ FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
message("nxeg_redraw%d: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
- (int)arg, hwnd,
+ st->wnum, hwnd,
rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
more ? "TRUE" : "FALSE");
- if (arg == (FAR void *)2)
- {
- nxeg_fillwindow(hwnd, rect, g_color2);
- }
- else
- {
- nxeg_fillwindow(hwnd, rect, g_color1);
- }
+ nxeg_fillwindow(hwnd, rect, st);
}
/****************************************************************************
@@ -211,10 +195,12 @@ static void nxeg_position(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size,
FAR const struct nxgl_rect_s *bounds,
FAR void *arg)
{
+ FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
+
/* Report the position */
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,
+ st->wnum, 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? */
@@ -240,42 +226,9 @@ static void nxeg_position(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size,
static void nxeg_mousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos,
ubyte buttons, FAR void *arg)
{
+ FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)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
- ****************************************************************************/
-
-#ifdef CONFIG_NX_KBD
-static void nxeg_kbdinfo(ubyte nch, const ubyte *ch)
-{
- int i;
- for (i = 0; i < nch; i++)
- {
- if (isprint(ch[i]))
- {
- message(" ch[%d]=%c (%02x)\n", i, ch[i], ch[i]);
- }
- else
- {
- message(" ch[%d]= (%02x)\n", i, ch[i]);
- }
- }
-}
-#endif
-
-/****************************************************************************
- * Name: nxeg_kbdin
- ****************************************************************************/
-
-#ifdef CONFIG_NX_KBD
-static void nxeg_kbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg)
-{
- message("nxeg_kbdin%d: hwnd=%p nch=%d\n", (int)arg, hwnd, nch);
- nxeg_kbdinfo(nch, ch);
+ st->wnum, hwnd, pos->x, pos->y, buttons);
}
#endif
@@ -287,8 +240,9 @@ static void nxeg_kbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg)
static void nxeg_tbredraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
boolean more, FAR void *arg)
{
+ FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
message("nxeg_tbredraw%d: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
- (int)arg, hwnd,
+ st->wnum, hwnd,
rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
more ? "TRUE" : "FALSE");
nxeg_filltoolbar(hwnd, rect, g_tbcolor);
@@ -296,7 +250,7 @@ static void nxeg_tbredraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
#endif
/****************************************************************************
- * Name: nxeg_position1
+ * Name: nxeg_position
****************************************************************************/
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
@@ -305,10 +259,12 @@ static void nxeg_tbposition(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size,
FAR const struct nxgl_rect_s *bounds,
FAR void *arg)
{
+ FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)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,
+ st->wnum, hwnd, size->w, size->h, pos->x, pos->y,
bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y);
}
#endif
@@ -322,23 +278,10 @@ static void nxeg_tbposition(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size,
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
- ****************************************************************************/
+ FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
-#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
-#ifdef CONFIG_NX_KBD
-static void nxeg_tbkbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg)
-{
- message("nxeg_tbkbdin: ERROR -- toolbar should not received keyboard input\n");
- message("nxeg_tbkbdin%d: hwnd=%p nch=%d\n", (int)arg, hwnd, nch);
- nxeg_kbdinfo(nch, ch);
+ message("nxeg_tbmousein%d: hwnd=%p pos=(%d,%d) button=%02x\n",
+ st->wnum, hwnd, pos->x, pos->y, buttons);
}
#endif
#endif
diff --git a/nuttx/examples/nx/nx_internal.h b/nuttx/examples/nx/nx_internal.h
index 58febc5b7..5c98e9af1 100644
--- a/nuttx/examples/nx/nx_internal.h
+++ b/nuttx/examples/nx/nx_internal.h
@@ -43,6 +43,8 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <semaphore.h>
+#include <nuttx/nx.h>
+#include <nuttx/nxtk.h>
/****************************************************************************
* Definitions
@@ -58,10 +60,14 @@
# define CONFIG_EXAMPLES_NX_VPLANE 0
#endif
+#ifndef CONFIG_EXAMPLES_NX_BPP
+# define CONFIG_EXAMPLES_NX_BPP 32
+#endif
+
#ifndef CONFIG_EXAMPLES_NX_BGCOLOR
-# if CONFIG_SIM_FBBPP == 24 || CONFIG_SIM_FBBPP == 32
+# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
# define CONFIG_EXAMPLES_NX_BGCOLOR 0x007b68ee
-# elif CONFIG_SIM_FBBPP = 16
+# elif CONFIG_EXAMPLES_NX_BPP = 16
# define CONFIG_EXAMPLES_NX_BGCOLOR 0x3088
# else
# define CONFIG_EXAMPLES_NX_BGCOLOR ' '
@@ -69,9 +75,9 @@
#endif
#ifndef CONFIG_EXAMPLES_NX_COLOR1
-# if CONFIG_SIM_FBBPP == 24 || CONFIG_SIM_FBBPP == 32
+# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
# define CONFIG_EXAMPLES_NX_COLOR1 0x00e6e6fa
-# elif CONFIG_SIM_FBBPP = 16
+# elif CONFIG_EXAMPLES_NX_BPP = 16
# define CONFIG_EXAMPLES_NX_COLOR1 0x30c8
# else
# define CONFIG_EXAMPLES_NX_COLOR1 '1'
@@ -79,9 +85,9 @@
#endif
#ifndef CONFIG_EXAMPLES_NX_COLOR2
-# if CONFIG_SIM_FBBPP == 24 || CONFIG_SIM_FBBPP == 32
+# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
# define CONFIG_EXAMPLES_NX_COLOR2 0x00dcdcdc
-# elif CONFIG_SIM_FBBPP = 16
+# elif CONFIG_EXAMPLES_NX_BPP = 16
# define CONFIG_EXAMPLES_NX_COLOR2 0x30cc
# else
# define CONFIG_EXAMPLES_NX_COLOR2 '2'
@@ -89,12 +95,22 @@
#endif
#ifndef CONFIG_EXAMPLES_NX_TBCOLOR
-# if CONFIG_SIM_FBBPP == 24 || CONFIG_SIM_FBBPP == 32
+# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
# define CONFIG_EXAMPLES_NX_TBCOLOR 0x00a9a9a9
-# elif CONFIG_SIM_FBBPP = 16
+# elif CONFIG_EXAMPLES_NX_BPP = 16
# define CONFIG_EXAMPLES_NX_TBCOLOR 0xad55
# else
-# define CONFIG_EXAMPLES_NX_TBCOLOR '3'
+# define CONFIG_EXAMPLES_NX_TBCOLOR 'T'
+# endif
+#endif
+
+#ifndef CONFIG_EXAMPLES_NX_FONTCOLOR
+# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
+# define CONFIG_EXAMPLES_NX_FONTCOLOR 0x00000000
+# elif CONFIG_EXAMPLES_NX_BPP = 16
+# define CONFIG_EXAMPLES_NX_FONTCOLOR 0x0000
+# else
+# define CONFIG_EXAMPLES_NX_FONTCOLOR 'F'
# endif
#endif
@@ -132,6 +148,14 @@
# endif
#endif
+#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
+# define NXEGWINDOW NXWINDOW
+#else
+# define NXEGWINDOW NXTKWINDOW
+#endif
+
+#define NXTK_MAXKBDCHARS 16
+
/* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
@@ -179,6 +203,43 @@ enum exitcode_e
NXEXIT_LOSTSERVERCONN
};
+/* Describes one cached glyph bitmap */
+
+struct nxeg_glyph_s
+{
+ ubyte code; /* Character code */
+ ubyte width; /* Visible width of this glyph */
+ ubyte stride; /* Width of the glyph row in bytes */
+ FAR ubyte *bitmap; /* Allocated bitmap memory */
+};
+
+/* Describes on character on the display */
+
+struct nxeg_bitmap_s
+{
+ struct nxgl_rect_s bounds; /* Size/position of bitmap */
+ FAR const struct nxeg_glyph_s *glyph; /* The cached glyph */
+};
+
+/* Describes the overall state of on one window */
+
+struct nxeg_state_s
+{
+ ubyte wnum; /* Window number */
+ nxgl_mxpixel_t color[CONFIG_NX_NPLANES]; /* Window color */
+
+#if !defined(CONFIG_EXAMPLES_NX_RAWWINDOWS) && defined(CONFIG_NX_KBD)
+ ubyte height; /* Max height of a font in pixels */
+ ubyte width; /* Max width of a font in pixels */
+
+ ubyte nchars; /* Number of KBD chars received */
+ ubyte nglyphs; /* Number of glyphs cached */
+
+ struct nxeg_bitmap_s bm[NXTK_MAXKBDCHARS];
+ struct nxeg_glyph_s glyph[NXTK_MAXKBDCHARS];
+#endif
+};
+
/****************************************************************************
* Public Variables
****************************************************************************/
@@ -222,4 +283,13 @@ extern int nx_servertask(int argc, char *argv[]);
extern FAR void *nx_listenerthread(FAR void *arg);
#endif
+#ifdef CONFIG_NX_KBD
+extern void nxeg_kbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg);
+#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
+extern void nxeg_tbkbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg);
+extern void nxeg_filltext(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
+ FAR struct nxeg_state_s *st);
+#endif
+#endif
+
#endif /* __EXAMPLES_NX_NX_INTERNAL_H */
diff --git a/nuttx/examples/nx/nx_kbdin.c b/nuttx/examples/nx/nx_kbdin.c
new file mode 100644
index 000000000..04d4e6aa1
--- /dev/null
+++ b/nuttx/examples/nx/nx_kbdin.c
@@ -0,0 +1,373 @@
+/****************************************************************************
+ * examples/nx/nx_kbdin.c
+ *
+ * Copyright (C) 2008 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <debug.h>
+#include <errno.h>
+
+#include <nuttx/nx.h>
+#include <nuttx/nxtk.h>
+#include <nuttx/nxfonts.h>
+
+#include "nx_internal.h"
+
+#ifdef CONFIG_NX_KBD
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/* Select renderer -- Some additional logic would be required to support
+ * pixel depths that are not directly addressable (1,2,4, and 24).
+ */
+
+#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
+#if CONFIG_EXAMPLES_NX_BPP == 8
+# define RENDERER nxf_convert_8bpp
+#elif CONFIG_EXAMPLES_NX_BPP == 16
+# define RENDERER nxf_convert_16bpp
+#elif CONFIG_EXAMPLES_NX_BPP == 32
+# define RENDERER nxf_convert_32bpp
+#else
+# error "Unsupported CONFIG_EXAMPLES_NX_BPP"
+#endif
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxeg_fillchar
+ ****************************************************************************/
+
+#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
+static void nxeg_fillchar(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
+ FAR const struct nxeg_bitmap_s *bm)
+{
+ struct nxgl_rect_s intersection;
+ int ret;
+
+ /* Get the intersection of the redraw region and the characer bitmap */
+
+ nxgl_rectintersect(&intersection, rect, &bm->bounds);
+ if (!nxgl_nullrect(&intersection))
+ {
+ FAR void *src = (FAR void *)bm->glyph->bitmap;
+ ret = nxtk_bitmapwindow((NXTKWINDOW)hwnd, &intersection, src,
+ &bm->bounds.pt1,
+ (unsigned int)bm->glyph->stride);
+#if 0
+EXTERN int nxtk_bitmapwindow(NXTKWINDOW hfwnd,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const void *src[CONFIG_NX_NPLANES],
+ FAR const struct nxgl_point_s *origin,
+ unsigned int stride);
+#endif
+ if (ret < 0)
+ {
+ message("nxeg_fillchar: nxtk_bitmapwindow failed: %d\n", errno);
+ }
+ }
+}
+#endif
+
+/****************************************************************************
+ * Name: nxeg_kbdinfo
+ ****************************************************************************/
+
+static void nxeg_kbdinfo(ubyte nch, const ubyte *ch)
+{
+ int i;
+ for (i = 0; i < nch; i++)
+ {
+ if (isprint(ch[i]))
+ {
+ message(" ch[%d]=%c (%02x)\n", i, ch[i], ch[i]);
+ }
+ else
+ {
+ message(" ch[%d]= (%02x)\n", i, ch[i]);
+ }
+ }
+}
+
+/****************************************************************************
+ * Name: nxeg_renderglyph
+ ****************************************************************************/
+
+#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
+static inline FAR const struct nxeg_glyph_s *
+nxeg_renderglyph(FAR struct nxeg_state_s *st, ubyte ch)
+{
+ FAR struct nxeg_glyph_s *glyph = NULL;
+ FAR nxgl_mxpixel_t *ptr;
+ int bmstride;
+ int bmsize;
+ int row;
+ int col;
+
+ /* Make sure that there is room for another glyph */
+
+ message("nxeg_renderglyph: ch=%02x\n", ch);
+ if (st->nglyphs < NXTK_MAXKBDCHARS)
+ {
+ /* Allocate the glyph */
+
+ glyph = &st->glyph[st->nglyphs];
+
+ /* Allocate the maximum size for the bitmap */
+
+ glyph->stride = (st->width * CONFIG_EXAMPLES_NX_BPP + 4) / 8;
+ bmsize = glyph->stride * st->height;
+ glyph->bitmap = (FAR ubyte *)malloc(bmsize);
+ if (glyph->bitmap)
+ {
+ /* Initialize the glyph memory to the background color */
+
+#if CONFIG_EXAMPLES_NX_BPP < 8 || CONFIG_EXAMPLES_NX_BPP == 24
+# error "Additional logic is needed here"
+#else
+ ptr = (FAR nxgl_mxpixel_t *)glyph->bitmap;
+ for (row = 0; row < st->height; row++)
+ {
+ for (col = 0; col < st->width; col++)
+ {
+ *ptr++ = st->color[0];
+ }
+ }
+#endif
+ /* Then render the glyph into the allocated memory */
+
+ glyph->width = RENDERER((FAR nxgl_mxpixel_t*)glyph->bitmap,
+ st->height, st->width, bmstride,
+ ch, CONFIG_EXAMPLES_NX_FONTCOLOR);
+ if (glyph->width <= 0)
+ {
+ message("nxeg_renderglyph: RENDERER returned width=%d\n", glyph->width);
+ free(glyph->bitmap);
+ glyph->bitmap = NULL;
+ glyph = NULL;
+ }
+ else
+ {
+ /* Make it permanent */
+
+ st->nglyphs++;
+ }
+ }
+ }
+
+ return glyph;
+}
+#endif
+
+/****************************************************************************
+ * Name: nxeg_getglyph
+ ****************************************************************************/
+
+#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
+static FAR const struct nxeg_glyph_s *
+nxeg_getglyph(FAR struct nxeg_state_s *st, ubyte ch)
+{
+ int i;
+
+ /* First, try to find the glyph in the cache of pre-rendered glyphs */
+
+ message("nxeg_getglyph: ch=%02x\n", ch);
+ for (i = 0; i < st->nglyphs; i++)
+ {
+ if (st->glyph[i].code == ch)
+ {
+ return &st->glyph[i];
+ }
+ }
+
+ /* No, it is not cached... render it now and add it to the cache */
+
+ return nxeg_renderglyph(st, ch);
+}
+#endif
+
+/****************************************************************************
+ * Name: nxeg_addchar
+ ****************************************************************************/
+
+#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
+static FAR const struct nxeg_bitmap_s *
+nxeg_addchar(FAR struct nxeg_state_s *st, ubyte ch)
+{
+ FAR struct nxeg_bitmap_s *bm = NULL;
+ FAR struct nxeg_bitmap_s *bmleft;
+ FAR const struct nx_font_s *fontset;
+ nxgl_coord_t leftx;
+
+ /* Is there space for another character on the display? */
+
+ message("nxeg_addchar: ch=%02x\n", ch);
+ if (st->nchars < NXTK_MAXKBDCHARS)
+ {
+ /* Yes, setup the bitmap */
+
+ bm = &st->bm[st->nchars];
+
+ /* Find the matching glyph */
+
+ bm->glyph = nxeg_getglyph(st, ch);
+ if (!bm->glyph)
+ {
+ return NULL;
+ }
+
+ /* Set up the bounds for the bitmap */
+
+ if (st->nchars <= 0)
+ {
+ /* The first character is one space from the left */
+
+ fontset = nxf_getfontset();
+ leftx = fontset->spwidth;
+ }
+ else
+ {
+ /* Otherwise, it is to the left of the preceding char */
+
+ bmleft = &st->bm[st->nchars-1];
+ leftx = bmleft->bounds.pt2.x + 1;
+ }
+
+ bm->bounds.pt1.x = leftx;
+ bm->bounds.pt1.y = 2;
+ bm->bounds.pt2.x = leftx + bm->glyph->width - 1;
+ bm->bounds.pt2.x = 2 + st->height - 1;
+
+ st->nchars++;
+ }
+ return bm;
+}
+#endif
+
+/****************************************************************************
+ * Name: nxeg_addchars
+ ****************************************************************************/
+
+#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
+static inline void nxeg_addchars(NXWINDOW hwnd, FAR struct nxeg_state_s *st,
+ ubyte nch, FAR const ubyte *ch)
+{
+ FAR const struct nxeg_bitmap_s *bm;
+
+ while (nch--)
+ {
+ bm = nxeg_addchar(st, *ch++);
+ nxeg_fillchar(hwnd, &bm->bounds, bm);
+ }
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxeg_kbdin
+ ****************************************************************************/
+
+void nxeg_kbdin(NXWINDOW hwnd, ubyte nch, FAR const ubyte *ch, FAR void *arg)
+{
+ FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
+ message("nxeg_kbdin%d: hwnd=%p nch=%d\n", st->wnum, hwnd, nch);
+#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
+ nxeg_kbdinfo(nch, ch);
+#else
+ nxeg_addchars(hwnd, st, nch, ch);
+#endif
+}
+
+/****************************************************************************
+ * Name: nxeg_tbkbdin
+ ****************************************************************************/
+
+#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
+void nxeg_tbkbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg)
+{
+ FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
+ message("nxeg_tbkbdin: ERROR -- toolbar should not received keyboard input\n");
+ message("nxeg_tbkbdin%d: hwnd=%p nch=%d\n", st->wnum, hwnd, nch);
+ nxeg_kbdinfo(nch, ch);
+}
+#endif
+
+/****************************************************************************
+ * Name: nxeg_tbkbdin
+ ****************************************************************************/
+
+#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
+void nxeg_filltext(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
+ FAR struct nxeg_state_s *st)
+{
+ int i;
+ for (i = 0; i < st->nchars; i++)
+ {
+ nxeg_fillchar(hwnd, rect, &st->bm[i]);
+ }
+}
+#endif
+
+#endif /* CONFIG_NX_KBD */
diff --git a/nuttx/examples/nx/nx_main.c b/nuttx/examples/nx/nx_main.c
index bc4bd0abe..ca6c43e85 100644
--- a/nuttx/examples/nx/nx_main.c
+++ b/nuttx/examples/nx/nx_main.c
@@ -53,6 +53,8 @@
#include <nuttx/arch.h>
#include <nuttx/nx.h>
#include <nuttx/nxtk.h>
+#include <nuttx/nxfonts.h>
+
#include "nx_internal.h"
/****************************************************************************
@@ -73,12 +75,13 @@
static int g_exitcode = NXEXIT_SUCCESS;
+static struct nxeg_state_s g_wstate[2];
+
#ifdef CONFIG_NX_KBD
static const ubyte g_kbdmsg1[] = "NuttX is cool!";
static const ubyte g_kbdmsg2[] = "NuttX is fun!";
#endif
-
/****************************************************************************
* Public Data
****************************************************************************/
@@ -134,16 +137,73 @@ static void nxeg_drivemouse(void)
#endif
/****************************************************************************
+ * Name: nxeg_initstate
+ ****************************************************************************/
+
+static void nxeg_initstate(FAR struct nxeg_state_s *st, int wnum,
+ nxgl_mxpixel_t color)
+{
+#if !defined(CONFIG_EXAMPLES_NX_RAWWINDOWS) && defined(CONFIG_NX_KBD)
+ FAR const struct nx_font_s *fontset;
+#endif
+
+ /* Initialize the window number (used for debug output only) and color
+ * (used for redrawing the window)
+ */
+
+ st->wnum = wnum;
+ st->color[0] = color;
+
+ /* Get information about the font set being used and save this in the
+ * state structure
+ */
+
+#if !defined(CONFIG_EXAMPLES_NX_RAWWINDOWS) && defined(CONFIG_NX_KBD)
+ fontset = nxf_getfontset();
+ st->nchars = 0;
+ st->nglyphs = 0;
+ st->height = fontset->mxheight;
+ st->width = fontset->mxwidth;
+#endif
+}
+
+/****************************************************************************
+ * Name: nxeg_freestate
+ ****************************************************************************/
+
+#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
+static void nxeg_freestate(FAR struct nxeg_state_s *st)
+{
+#ifdef CONFIG_NX_KBD
+ int i;
+
+ if (st)
+ {
+ for (i = 0; i < st->nglyphs; i++)
+ {
+ if (st->glyph[i].bitmap)
+ {
+ free(st->glyph[i].bitmap);
+ }
+ st->glyph[i].bitmap = NULL;
+ }
+ st->nchars = 0;
+ }
+#endif
+}
+#endif
+
+/****************************************************************************
* Name: nxeg_openwindow
****************************************************************************/
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
-static inline NXWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb,
- FAR void *arg)
+static inline NXEGWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb,
+ FAR struct nxeg_state_s *state)
{
- NXWINDOW hwnd;
+ NXEGWINDOW hwnd;
- hwnd = nx_openwindow(g_hnx, cb, arg);
+ hwnd = nx_openwindow(g_hnx, cb, (FAR void *)state);
if (!hwnd)
{
message("user_start: nx_openwindow failed: %d\n", errno);
@@ -152,12 +212,12 @@ static inline NXWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb,
return hwnd;
}
#else
-static inline NXTKWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb,
- FAR void *arg)
+static inline NXEGWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb,
+ FAR struct nxeg_state_s *state)
{
- NXTKWINDOW hwnd;
+ NXEGWINDOW hwnd;
- hwnd = nxtk_openwindow(g_hnx, cb, arg);
+ hwnd = nxtk_openwindow(g_hnx, cb, (FAR void *)state);
if (!hwnd)
{
message("user_start: nxtk_openwindow failed: %d\n", errno);
@@ -172,25 +232,26 @@ static inline NXTKWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb,
****************************************************************************/
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
-static inline int nxeg_closewindow(NXWINDOW hwnd)
+static inline int nxeg_closewindow(NXEGWINDOW hwnd, FAR struct nxeg_state_s *state)
{
int ret = nx_closewindow(hwnd);
if (ret < 0)
{
- message("user_start: nx_openwindow failed: %d\n", errno);
+ message("user_start: nx_closewindow failed: %d\n", errno);
g_exitcode = NXEXIT_NXCLOSEWINDOW;
}
return ret;
}
#else
-static inline int nxeg_closewindow(NXTKWINDOW hwnd)
+static inline int nxeg_closewindow(NXEGWINDOW hwnd, FAR struct nxeg_state_s *state)
{
int ret = nxtk_closewindow(hwnd);
if (ret < 0)
{
- message("user_start: nxtk_openwindow failed: %d\n", errno);
+ message("user_start: nxtk_closewindow failed: %d\n", errno);
g_exitcode = NXEXIT_NXCLOSEWINDOW;
}
+ nxeg_freestate(state);
return ret;
}
#endif
@@ -200,7 +261,7 @@ static inline int nxeg_closewindow(NXTKWINDOW hwnd)
****************************************************************************/
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
-static inline int nxeg_setsize(NXWINDOW hwnd, FAR struct nxgl_size_s *size)
+static inline int nxeg_setsize(NXEGWINDOW hwnd, FAR struct nxgl_size_s *size)
{
int ret = nx_setsize(hwnd, size);
if (ret < 0)
@@ -211,7 +272,7 @@ static inline int nxeg_setsize(NXWINDOW hwnd, FAR struct nxgl_size_s *size)
return ret;
}
#else
-static inline int nxeg_setsize(NXTKWINDOW hwnd, FAR struct nxgl_size_s *size)
+static inline int nxeg_setsize(NXEGWINDOW hwnd, FAR struct nxgl_size_s *size)
{
int ret = nxtk_setsize(hwnd, size);
if (ret < 0)
@@ -228,7 +289,7 @@ static inline int nxeg_setsize(NXTKWINDOW hwnd, FAR struct nxgl_size_s *size)
****************************************************************************/
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
-static inline int nxeg_setposition(NXWINDOW hwnd, FAR struct nxgl_point_s *pos)
+static inline int nxeg_setposition(NXEGWINDOW hwnd, FAR struct nxgl_point_s *pos)
{
int ret = nx_setposition(hwnd, pos);
if (ret < 0)
@@ -239,7 +300,7 @@ static inline int nxeg_setposition(NXWINDOW hwnd, FAR struct nxgl_point_s *pos)
return ret;
}
#else
-static inline int nxeg_setposition(NXTKWINDOW hwnd, FAR struct nxgl_point_s *pos)
+static inline int nxeg_setposition(NXEGWINDOW hwnd, FAR struct nxgl_point_s *pos)
{
int ret = nxtk_setposition(hwnd, pos);
if (ret < 0)
@@ -256,12 +317,12 @@ static inline int nxeg_setposition(NXTKWINDOW hwnd, FAR struct nxgl_point_s *pos
****************************************************************************/
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
-static inline int nxeq_opentoolbar(NXTKWINDOW hwnd, nxgl_coord_t height,
+static inline int nxeq_opentoolbar(NXEGWINDOW hwnd, nxgl_coord_t height,
FAR const struct nx_callback_s *cb,
- FAR void *arg)
+ FAR struct nxeg_state_s *state)
{
int ret;
- ret = nxtk_opentoolbar(hwnd, height, cb, arg);
+ ret = nxtk_opentoolbar(hwnd, height, cb, (FAR void *)state);
if (ret < 0)
{
message("user_start: nxtk_opentoolbar failed: %d\n", errno);
@@ -276,7 +337,7 @@ static inline int nxeq_opentoolbar(NXTKWINDOW hwnd, nxgl_coord_t height,
****************************************************************************/
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
-static inline int nxeg_lower(NXWINDOW hwnd)
+static inline int nxeg_lower(NXEGWINDOW hwnd)
{
int ret = nx_lower(hwnd);
if (ret < 0)
@@ -287,7 +348,7 @@ static inline int nxeg_lower(NXWINDOW hwnd)
return ret;
}
#else
-static inline int nxeg_lower(NXTKWINDOW hwnd)
+static inline int nxeg_lower(NXEGWINDOW hwnd)
{
int ret = nxtk_lower(hwnd);
if (ret < 0)
@@ -304,7 +365,7 @@ static inline int nxeg_lower(NXTKWINDOW hwnd)
****************************************************************************/
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
-static inline int nxeg_raise(NXWINDOW hwnd)
+static inline int nxeg_raise(NXEGWINDOW hwnd)
{
int ret = nx_raise(hwnd);
if (ret < 0)
@@ -315,7 +376,7 @@ static inline int nxeg_raise(NXWINDOW hwnd)
return ret;
}
#else
-static inline int nxeg_raise(NXTKWINDOW hwnd)
+static inline int nxeg_raise(NXEGWINDOW hwnd)
{
int ret = nxtk_raise(hwnd);
if (ret < 0)
@@ -499,13 +560,8 @@ void user_initialize(void)
int user_start(int argc, char *argv[])
{
-#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
- NXWINDOW hwnd1;
- NXWINDOW hwnd2;
-#else
- NXTKWINDOW hwnd1;
- NXTKWINDOW hwnd2;
-#endif
+ NXEGWINDOW hwnd1;
+ NXEGWINDOW hwnd2;
struct nxgl_size_s size;
struct nxgl_point_s pt;
nxgl_mxpixel_t color;
@@ -537,7 +593,8 @@ int user_start(int argc, char *argv[])
/* Create window #1 */
message("user_start: Create window #1\n");
- hwnd1 = nxeg_openwindow(&g_nxcb, (FAR void *)1);
+ nxeg_initstate(&g_wstate[0], 1, CONFIG_EXAMPLES_NX_COLOR1);
+ hwnd1 = nxeg_openwindow(&g_nxcb, &g_wstate[0]);
message("user_start: hwnd1=%p\n", hwnd1);
if (!hwnd1)
{
@@ -593,7 +650,7 @@ int user_start(int argc, char *argv[])
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
message("user_start: Add toolbar to window #1\n");
- ret = nxeq_opentoolbar(hwnd1, CONFIG_TOOLBAR_HEIGHT, &g_tbcb, (FAR void*)1);
+ ret = nxeq_opentoolbar(hwnd1, CONFIG_TOOLBAR_HEIGHT, &g_tbcb, &g_wstate[0]);
if (ret < 0)
{
goto errout_with_hwnd1;
@@ -608,7 +665,8 @@ int user_start(int argc, char *argv[])
/* Create window #2 */
message("user_start: Create window #2\n");
- hwnd2 = nxeg_openwindow(&g_nxcb, (FAR void *)2);
+ nxeg_initstate(&g_wstate[1], 2, CONFIG_EXAMPLES_NX_COLOR2);
+ hwnd2 = nxeg_openwindow(&g_nxcb, &g_wstate[1]);
message("user_start: hwnd1=%p\n", hwnd1);
if (!hwnd1)
{
@@ -653,7 +711,7 @@ int user_start(int argc, char *argv[])
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
message("user_start: Add toolbar to window #2\n");
- ret = nxeq_opentoolbar(hwnd2, CONFIG_TOOLBAR_HEIGHT, &g_tbcb, (FAR void*)2);
+ ret = nxeq_opentoolbar(hwnd2, CONFIG_TOOLBAR_HEIGHT, &g_tbcb, &g_wstate[1]);
if (ret < 0)
{
goto errout_with_hwnd2;
@@ -748,13 +806,13 @@ int user_start(int argc, char *argv[])
errout_with_hwnd2:
message("user_start: Close window\n");
- (void)nxeg_closewindow(hwnd2);
+ (void)nxeg_closewindow(hwnd2, &g_wstate[2]);
/* Close the window1 */
errout_with_hwnd1:
message("user_start: Close window #1\n");
- (void)nxeg_closewindow(hwnd1);
+ (void)nxeg_closewindow(hwnd1, &g_wstate[0]);
errout_with_nx:
#ifdef CONFIG_NX_MULTIUSER