Use a handle instead of an ID in each font lookup; this saves doing the font set lookup each time
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3802 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
a6e00f570c
commit
5c0f5e790f
@ -77,4 +77,5 @@
|
||||
* apps/examples/nxhello: The simplest graphics example: It just says
|
||||
"Hello, World!" in the center of the display. This example can also be
|
||||
built as an NSH "built-in" command.
|
||||
|
||||
* apps/examples/nx, ntext, and nxhello: All updated to use the new
|
||||
NuttX font interfaces.
|
||||
|
@ -196,6 +196,7 @@ enum exitcode_e
|
||||
NXEXIT_LCDINITIALIZE,
|
||||
NXEXIT_LCDGETDEV,
|
||||
NXEXIT_NXOPEN,
|
||||
NXEXIT_FONTOPEN,
|
||||
NXEXIT_NXOPENTOOLBAR,
|
||||
NXEXIT_NXCONNECT,
|
||||
NXEXIT_NXSETBGCOLOR,
|
||||
@ -251,7 +252,7 @@ struct nxeg_state_s
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
/* The connecton handler */
|
||||
/* The connecton handle */
|
||||
|
||||
extern NXHANDLE g_hnx;
|
||||
|
||||
@ -262,6 +263,10 @@ extern const struct nx_callback_s g_nxcb;
|
||||
extern const struct nx_callback_s g_tbcb;
|
||||
#endif
|
||||
|
||||
/* The font handle */
|
||||
|
||||
extern NXHANDLE g_fonthandle;
|
||||
|
||||
/* The screen resolution */
|
||||
|
||||
extern nxgl_coord_t g_xres;
|
||||
|
@ -323,7 +323,7 @@ nxeg_getglyph(FAR struct nxeg_state_s *st, uint8_t ch)
|
||||
{
|
||||
/* No, it is not cached... Does the code map to a glyph? */
|
||||
|
||||
bm = nxf_getbitmap(ch, NXFONT_DEFAULT);
|
||||
bm = nxf_getbitmap(g_fonthandle, ch);
|
||||
if (!bm)
|
||||
{
|
||||
/* No, there is no glyph for this code. Use space */
|
||||
|
@ -102,6 +102,10 @@ static const uint8_t g_kbdmsg1[] = "NuttX is cool!";
|
||||
static const uint8_t g_kbdmsg2[] = "NuttX is fun!";
|
||||
#endif
|
||||
|
||||
/* The font handle */
|
||||
|
||||
NXHANDLE g_fonthandle;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
@ -179,7 +183,7 @@ static void nxeg_initstate(FAR struct nxeg_state_s *st, int wnum,
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NX_KBD
|
||||
fontset = nxf_getfontset(NXFONT_DEFAULT);
|
||||
fontset = nxf_getfontset(g_fonthandle);
|
||||
st->nchars = 0;
|
||||
st->nglyphs = 0;
|
||||
st->height = fontset->mxheight;
|
||||
@ -637,6 +641,16 @@ int user_start(int argc, char *argv[])
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Get the default font handle */
|
||||
|
||||
g_fonthandle = nxf_getfonthandle(NXFONT_DEFAULT);
|
||||
if (!g_fonthandle)
|
||||
{
|
||||
message("user_start: Failed to get font handle: %d\n", errno);
|
||||
g_exitcode = NXEXIT_FONTOPEN;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Set the background to the configured background color */
|
||||
|
||||
message("user_start: Set background color=%d\n", CONFIG_EXAMPLES_NX_BGCOLOR);
|
||||
|
@ -120,6 +120,7 @@ enum exitcode_e
|
||||
NXEXIT_LCDINITIALIZE,
|
||||
NXEXIT_LCDGETDEV,
|
||||
NXEXIT_NXOPEN,
|
||||
NXEXIT_FONTOPEN,
|
||||
NXEXIT_NXREQUESTBKGD,
|
||||
NXEXIT_NXSETBGCOLOR
|
||||
};
|
||||
@ -147,10 +148,11 @@ struct nxhello_bitmap_s
|
||||
|
||||
struct nxhello_data_s
|
||||
{
|
||||
/* The NX handle */
|
||||
/* The NX handles */
|
||||
|
||||
NXHANDLE hnx;
|
||||
NXHANDLE hbkgd;
|
||||
NXHANDLE hfont;
|
||||
|
||||
/* The screen resolution */
|
||||
|
||||
|
@ -228,7 +228,7 @@ static void nxhello_center(FAR struct nxgl_point_s *pos,
|
||||
{
|
||||
/* Get the font bitmap for this character */
|
||||
|
||||
fbm = nxf_getbitmap(*ptr, NXFONT_DEFAULT);
|
||||
fbm = nxf_getbitmap(g_nxhello.hfont, *ptr);
|
||||
if (fbm)
|
||||
{
|
||||
/* Add the font size */
|
||||
@ -353,7 +353,7 @@ void nxhello_hello(NXWINDOW hwnd)
|
||||
|
||||
/* Get information about the font we are going to use */
|
||||
|
||||
fontset = nxf_getfontset(NXFONT_DEFAULT);
|
||||
fontset = nxf_getfontset(g_nxhello.hfont);
|
||||
|
||||
/* Allocate a bit of memory to hold the largest rendered font */
|
||||
|
||||
@ -377,7 +377,7 @@ void nxhello_hello(NXWINDOW hwnd)
|
||||
{
|
||||
/* Get the bitmap font for this ASCII code */
|
||||
|
||||
fbm = nxf_getbitmap(*ptr, NXFONT_DEFAULT);
|
||||
fbm = nxf_getbitmap(g_nxhello.hfont, *ptr);
|
||||
if (fbm)
|
||||
{
|
||||
uint8_t fheight; /* Height of this glyph (in rows) */
|
||||
|
@ -61,6 +61,7 @@
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/nx.h>
|
||||
#include <nuttx/nxglib.h>
|
||||
#include <nuttx/nxfonts.h>
|
||||
|
||||
#include "nxhello.h"
|
||||
|
||||
@ -101,6 +102,7 @@ struct nxhello_data_s g_nxhello =
|
||||
{
|
||||
NULL, /* hnx */
|
||||
NULL, /* hbkgd */
|
||||
NULL, /* hfont */
|
||||
0, /* xres */
|
||||
0, /* yres */
|
||||
false, /* havpos */
|
||||
@ -228,6 +230,16 @@ int MAIN_NAME(int argc, char *argv[])
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Get the default font handle */
|
||||
|
||||
g_nxhello.hfont = nxf_getfonthandle(NXFONT_DEFAULT);
|
||||
if (!g_nxhello.hfont)
|
||||
{
|
||||
message("user_start: Failed to get font handle: %d\n", errno);
|
||||
g_nxhello.code = NXEXIT_FONTOPEN;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Set the background to the configured background color */
|
||||
|
||||
message(MAIN_NAME_STRING ": Set background color=%d\n",
|
||||
|
@ -402,7 +402,7 @@ FAR struct nxtext_state_s *nxbg_getstate(void)
|
||||
* state structure
|
||||
*/
|
||||
|
||||
fontset = nxf_getfontset(NXFONT_DEFAULT);
|
||||
fontset = nxf_getfontset(g_fonthandle);
|
||||
g_bgstate.fheight = fontset->mxheight;
|
||||
g_bgstate.fwidth = fontset->mxwidth;
|
||||
g_bgstate.spwidth = fontset->spwidth;
|
||||
|
@ -191,6 +191,7 @@ enum exitcode_e
|
||||
NXEXIT_LCDINITIALIZE,
|
||||
NXEXIT_LCDGETDEV,
|
||||
NXEXIT_NXOPEN,
|
||||
NXEXIT_FONTOPEN,
|
||||
NXEXIT_NXREQUESTBKGD,
|
||||
NXEXIT_NXCONNECT,
|
||||
NXEXIT_NXSETBGCOLOR,
|
||||
@ -262,6 +263,10 @@ extern NXHANDLE g_hnx;
|
||||
|
||||
extern NXHANDLE g_bgwnd;
|
||||
|
||||
/* The font handle */
|
||||
|
||||
extern NXHANDLE g_fonthandle;
|
||||
|
||||
/* NX callback vtables */
|
||||
|
||||
extern const struct nx_callback_s g_bgcb;
|
||||
|
@ -61,6 +61,7 @@
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/nx.h>
|
||||
#include <nuttx/nxglib.h>
|
||||
#include <nuttx/nxfonts.h>
|
||||
|
||||
#include "nxtext_internal.h"
|
||||
|
||||
@ -134,6 +135,10 @@ static const char *g_bgmsg[BGMSG_LINES] =
|
||||
|
||||
NXHANDLE g_hnx = NULL;
|
||||
|
||||
/* The font handle */
|
||||
|
||||
NXHANDLE g_fonthandle = NULL;
|
||||
|
||||
/* The screen resolution */
|
||||
|
||||
nxgl_coord_t g_xres;
|
||||
@ -366,6 +371,16 @@ int user_start(int argc, char *argv[])
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Get the default font handle */
|
||||
|
||||
g_fonthandle = nxf_getfonthandle(NXFONT_DEFAULT);
|
||||
if (!g_fonthandle)
|
||||
{
|
||||
message("user_start: Failed to get font handle: %d\n", errno);
|
||||
g_exitcode = NXEXIT_FONTOPEN;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Set the background to the configured background color */
|
||||
|
||||
message("user_start: Set background color=%d\n", CONFIG_EXAMPLES_NXTEXT_BGCOLOR);
|
||||
|
@ -304,7 +304,7 @@ static inline void nxpu_initstate(void)
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NX_KBD
|
||||
fontset = nxf_getfontset(NXFONT_DEFAULT);
|
||||
fontset = nxf_getfontset(g_fonthandle);
|
||||
g_pustate.fheight = fontset->mxheight;
|
||||
g_pustate.fwidth = fontset->mxwidth;
|
||||
g_pustate.spwidth = fontset->spwidth;
|
||||
|
@ -332,7 +332,7 @@ static int nxtext_fontsize(uint8_t ch, FAR struct nxgl_size_s *size)
|
||||
|
||||
/* No, it is not cached... Does the code map to a font? */
|
||||
|
||||
fbm = nxf_getbitmap(ch, NXFONT_DEFAULT);
|
||||
fbm = nxf_getbitmap(g_fonthandle, ch);
|
||||
if (fbm)
|
||||
{
|
||||
/* Yes.. return the font size */
|
||||
@ -362,7 +362,7 @@ nxtext_getglyph(FAR struct nxtext_state_s *st, uint8_t ch)
|
||||
{
|
||||
/* No, it is not cached... Does the code map to a font? */
|
||||
|
||||
fbm = nxf_getbitmap(ch, NXFONT_DEFAULT);
|
||||
fbm = nxf_getbitmap(g_fonthandle, ch);
|
||||
if (fbm)
|
||||
{
|
||||
/* Yes.. render the glyph */
|
||||
|
Loading…
x
Reference in New Issue
Block a user