Add font test

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1413 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2008-12-04 16:45:06 +00:00
parent 9db08181c2
commit 6d88b5b00c
14 changed files with 818 additions and 188 deletions

View File

@ -434,10 +434,18 @@ CONFIG_EXAMPLES_NSH_FATMOUNTPT=/tmp
#
# 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 ofthe 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.
# CONFIG_EXAMPLES_NX_STACKSIZE -- The stacksize to use when creating
@ -451,6 +459,8 @@ CONFIG_EXAMPLES_NX_VPLANE=0
#CONFIG_EXAMPLES_NX_COLOR1
#CONFIG_EXAMPLES_NX_COLOR2
#CONFIG_EXAMPLES_NX_TBCOLOR
#CONFIG_EXAMPLES_NX_FONTCOLOR
CONFIG_EXAMPLES_NX_BPP=CONFIG_SIM_FBBPP
CONFIG_EXAMPLES_NX_RAWWINDOWS=n
CONFIG_EXAMPLES_NX_STACKSIZE=8192
CONFIG_EXAMPLES_NX_CLIENTPRIO=80

View File

@ -434,10 +434,18 @@ CONFIG_EXAMPLES_NSH_FATMOUNTPT=/tmp
#
# 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 ofthe 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.
# CONFIG_EXAMPLES_NX_STACKSIZE -- The stacksize to use when creating
@ -451,6 +459,8 @@ CONFIG_EXAMPLES_NX_VPLANE=0
#CONFIG_EXAMPLES_NX_COLOR1
#CONFIG_EXAMPLES_NX_COLOR2
#CONFIG_EXAMPLES_NX_TBCOLOR
#CONFIG_EXAMPLES_NX_FONTCOLOR
CONFIG_EXAMPLES_NX_BPP=CONFIG_SIM_FBBPP
CONFIG_EXAMPLES_NX_RAWWINDOWS=n
CONFIG_EXAMPLES_NX_STACKSIZE=8192
CONFIG_EXAMPLES_NX_CLIENTPRIO=80

View File

@ -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.

View File

@ -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

View File

@ -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)
{
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)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(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);
st->wnum, hwnd, pos->x, pos->y, buttons);
}
#endif
#endif

View File

@ -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 */

373
examples/nx/nx_kbdin.c Normal file
View File

@ -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 */

View File

@ -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
****************************************************************************/
@ -133,17 +136,74 @@ 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

View File

@ -41,6 +41,8 @@
#include <sys/types.h>
#include <nuttx/nxfonts.h>
#include "nxfonts_internal.h"
/* Pick the fontset */
#ifdef CONFIG_NXFONT_SANS
@ -1622,26 +1624,28 @@ NXFONT_DEFMETRIC(255),
struct nx_fontset_s g_7bitfonts =
{
NXFONT_MAXHEIGHT, /* Max. height of a glyph in rows */
NXFONT_MAXWIDTH, /* Max. width of a glyph in pixels */
NXFONT_MIN7BIT, /* First font code */
NXFONT_N7BITFONTS, /* Number of bitmap fonts */
NXFONT_SPACEWIDTH, /* The width of a space in pixels */
g_7bitmaps /* List of fonts */
NXFONT_MIN7BIT, /* First glyph code */
NXFONT_N7BITFONTS, /* Number of bitmap glyphs */
g_7bitmaps /* List of glyphs */
};
#if CONFIG_NXFONTS_CHARBITS >= 8
struct nx_fontset_s g_8bitfonts =
{
NXFONT_MAXHEIGHT, /* Max. height of a glyph in rows */
NXFONT_MAXWIDTH, /* Max. width of a glyph in pixels */
NXFONT_MIN8BIT, /* First font code */
NXFONT_N8BITFONTS, /* Number of bitmap fonts */
NXFONT_SPACEWIDTH, /* The width of a space in pixels */
g_8bitmaps /* List of fonts */
NXFONT_MIN8BIT, /* First glyph code */
NXFONT_N8BITFONTS, /* Number of bitmap glyphs */
g_8bitmaps /* List of glyphs */
};
#endif
struct nx_font_s g_fonts =
{
NXFONT_MAXHEIGHT, /* Max. height of a glyph in rows */
NXFONT_MAXWIDTH, /* Max. width of a glyph in pixels */
CONFIG_NXFONTS_CHARBITS, /* Max number of bits per character code */
NXFONT_SPACEWIDTH, /* The width of a space in pixels */
};
/****************************************************************************
* Private Functions
****************************************************************************/

View File

@ -44,6 +44,8 @@
#include <nuttx/nxglib.h>
#include <nuttx/nxfonts.h>
#include "nxfonts_internal.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
@ -138,7 +140,6 @@ int NXF_FUNCNAME(nxf_convert,NXFONTS_SUFFIX)
(FAR NXF_PIXEL_T *dest, uint16 height, uint16 width, uint16 stride,
uint16 ch, nxgl_mxpixel_t color)
{
FAR const struct nx_fontset_s *set;
FAR const struct nx_fontbitmap_s *bm;
FAR ubyte *line;
FAR NXF_PIXEL_T *dptr;
@ -156,16 +157,6 @@ int NXF_FUNCNAME(nxf_convert,NXFONTS_SUFFIX)
int nbits;
#endif
/* Check if we have the fontset containing this character code */
set = nxf_getfontset(ch);
if (!set)
{
/* No fontset? Nothing to rend, return the width of a 7-bit space */
return g_7bitfonts.spwidth;
}
/* Map the character code to a bitmap font */
bm = nxf_getbitmap(ch);
@ -173,7 +164,7 @@ int NXF_FUNCNAME(nxf_convert,NXFONTS_SUFFIX)
{
/* No character? Nothing to rend, return the width of a space */
return set->spwidth;
return g_fonts.spwidth;
}
/* Get the starting position */
@ -285,5 +276,5 @@ int NXF_FUNCNAME(nxf_convert,NXFONTS_SUFFIX)
}
}
#endif
return bm->metric.width;
return bm->metric.width + bm->metric.xoffset;
}

View File

@ -40,9 +40,11 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <debug.h>
#
#include <nuttx/nxfonts.h>
#include "nxfonts_internal.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
@ -60,11 +62,7 @@
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxf_getfontset
* Name: nxf_getglyphset
*
* Description:
* Return information about the font set containtined he selected
@ -75,7 +73,7 @@
*
****************************************************************************/
FAR const struct nx_fontset_s *nxf_getfontset(uint16 ch)
static inline FAR const struct nx_fontset_s *nxf_getglyphset(uint16 ch)
{
if (ch < 128)
{
@ -101,6 +99,27 @@ FAR const struct nx_fontset_s *nxf_getfontset(uint16 ch)
{
gdbg("16-bit font not currently supported\n");
}
return NULL;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxf_getfontset
*
* Description:
* Return information about the current font set
*
* Input Parameters:
* None
*
****************************************************************************/
FAR const struct nx_font_s *nxf_getfontset(void)
{
return &g_fonts;
}
/****************************************************************************
@ -116,7 +135,7 @@ FAR const struct nx_fontset_s *nxf_getfontset(uint16 ch)
FAR const struct nx_fontbitmap_s *nxf_getbitmap(uint16 ch)
{
FAR const struct nx_fontset_s *set = nxf_getfontset(ch);
FAR const struct nx_fontset_s *set = nxf_getglyphset(ch);
FAR struct nx_fontbitmap_s *bm = NULL;
if (set)

View File

@ -0,0 +1,93 @@
/****************************************************************************
* graphics/nxfonts/nxfonts_internal.h
*
* 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.
*
****************************************************************************/
#ifndef __GRAPHICS_NXFONTS_NXFONTS_INTERNAL_H
#define __GRAPHICS_NXFONTS_NXFONTS_INTERNAL_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <nuttx/nxfonts.h>
/****************************************************************************
* Pre-processor definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifndef CONFIG_NXFONTS_CHARBITS
# define CONFIG_NXFONTS_CHARBITS 7
#endif
/* Only font supported for now */
#define CONFIG_NXFONT_SANS 1
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
# define EXTERN extern "C"
extern "C" {
#else
# define EXTERN extern
#endif
EXTERN struct nx_fontset_s g_7bitfonts;
#if CONFIG_NXFONTS_CHARBITS >= 8
EXTERN struct nx_fontset_s g_8bitfonts;
#endif
EXTERN struct nx_font_s g_fonts;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __GRAPHICS_NXFONTS_NXFONTS_INTERNAL_H */

View File

@ -42,6 +42,7 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <nuttx/nxglib.h>
/****************************************************************************
* Pre-processor definitions
@ -51,6 +52,8 @@
* Public Types
****************************************************************************/
/* This structures provides the metrics for one glyph */
struct nx_fontmetic_s
{
uint32 stride : 2; /* Width of one font row in bytes */
@ -61,22 +64,36 @@ struct nx_fontmetic_s
uint32 unused : 6;
};
/* This structure bings the glyph metrics to the glyph bitmap */
struct nx_fontbitmap_s
{
struct nx_fontmetic_s metric; /* Character metrics */
FAR const ubyte *bitmap; /* Pointer to the character bitmap */
};
/* This structure describes one contiguous grouping of glyphs that
* can be described by an array starting with encoding 'first' and
* extending through (first + nchars - 1).
*/
struct nx_fontset_s
{
uint32 mxheight : 6; /* Max height of one glyph in rows */
uint32 mxwidth : 6; /* Max width of any glyph in pixels */
uint32 first : 8; /* First bitmap character code */
uint32 nchars : 8; /* Number of bitmap character codes */
uint32 spwidth : 4; /* The width of a space in pixels */
ubyte first; /* First bitmap character code */
ubyte nchars; /* Number of bitmap character codes */
FAR const struct nx_fontbitmap_s *bitmap;
};
/* This structure describes the overall fontset */
struct nx_font_s
{
ubyte mxheight; /* Max height of one glyph in rows */
ubyte mxwidth; /* Max width of any glyph in pixels */
ubyte mxbits; /* Max number of bits per character code */
ubyte spwidth; /* The width of a space in pixels */
};
/****************************************************************************
* Public Data
****************************************************************************/
@ -89,11 +106,6 @@ extern "C" {
# define EXTERN extern
#endif
EXTERN struct nx_fontset_s g_7bitfonts;
#if CONFIG_NXFONTS_CHARBITS >= 8
EXTERN struct nx_fontset_s g_8bitfonts;
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
@ -102,15 +114,14 @@ EXTERN struct nx_fontset_s g_8bitfonts;
* Name: nxf_getfontset
*
* Description:
* Return information about the font set containtined he selected
* character encoding.
* Return information about the current font set
*
* Input Parameters:
* ch - character code
* None
*
****************************************************************************/
EXTERN FAR const struct nx_fontset_s *nxf_getfontset(uint16 ch);
EXTERN FAR const struct nx_font_s *nxf_getfontset(void);
/****************************************************************************
* Name: nxf_getbitmap
@ -125,6 +136,46 @@ EXTERN FAR const struct nx_fontset_s *nxf_getfontset(uint16 ch);
EXTERN FAR const struct nx_fontbitmap_s *nxf_getbitmap(uint16 ch);
/****************************************************************************
* Name: nxf_convert_*bpp
*
* Description:
* Convert the 1BPP font to a new pixel depth
*
* Input Parameters:
* dest - The destination buffer provided by the caller.
* height - The max height of the returned char in rows
* width - The max width of the returned char in pixels
* stride - The width of the destination buffer in bytes
* ch - The character code to convert
* color - The color to use for '1' bits in the font bitmap
* (0 bits are transparent)
*
* Returned Value:
* On Success, this function returns the actual width of the font in bytes.
* on failed, a negated errno is retured.
*
****************************************************************************/
EXTERN int nxf_convert_2bpp(FAR ubyte *dest, uint16 height,
uint16 width, uint16 stride, uint16 ch,
nxgl_mxpixel_t color);
EXTERN int nxf_convert_4bpp(FAR ubyte *dest, uint16 height,
uint16 width, uint16 stride, uint16 ch,
nxgl_mxpixel_t color);
EXTERN int nxf_convert_8bpp(FAR ubyte *dest, uint16 height,
uint16 width, uint16 stride, uint16 ch,
nxgl_mxpixel_t color);
EXTERN int nxf_convert_16bpp(FAR uint16 *dest, uint16 height,
uint16 width, uint16 stride, uint16 ch,
nxgl_mxpixel_t color);
EXTERN int nxf_convert_24bpp(FAR uint32 *dest, uint16 height,
uint16 width, uint16 stride, uint16 ch,
nxgl_mxpixel_t color);
EXTERN int nxf_convert_32bpp(FAR uint32 *dest, uint16 height,
uint16 width, uint16 stride, uint16 ch,
nxgl_mxpixel_t color);
#undef EXTERN
#if defined(__cplusplus)
}

View File

@ -286,7 +286,7 @@ EXTERN int nxtk_movewindow(NXTKWINDOW hfwnd, FAR const struct nxgl_rect_s *rect,
EXTERN int nxtk_bitmapwindow(NXTKWINDOW hfwnd,
FAR const struct nxgl_rect_s *dest,
FAR const void *src[CONFIG_NX_NPLANES],
FAR const void **src,
FAR const struct nxgl_point_s *origin,
unsigned int stride);