diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-07-27 14:43:45 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-07-27 14:43:45 +0000 |
commit | 99ffb319c5af373ef135c2a3e73bf1171e55559e (patch) | |
tree | 7aa08fa81a006d354469de2652043ab969d8a3c4 /apps/examples/nxtext | |
parent | ce09509ff8c3127b4cc07ebcaae78229d5b2d90a (diff) | |
download | nuttx-99ffb319c5af373ef135c2a3e73bf1171e55559e.tar.gz nuttx-99ffb319c5af373ef135c2a3e73bf1171e55559e.tar.bz2 nuttx-99ffb319c5af373ef135c2a3e73bf1171e55559e.zip |
Incorporated new fonts into examples; fix glyph allocation bug in nxhello
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3822 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/examples/nxtext')
-rw-r--r-- | apps/examples/nxtext/nxtext_bkgd.c | 8 | ||||
-rw-r--r-- | apps/examples/nxtext/nxtext_internal.h | 19 | ||||
-rw-r--r-- | apps/examples/nxtext/nxtext_main.c | 21 | ||||
-rw-r--r-- | apps/examples/nxtext/nxtext_popup.c | 6 | ||||
-rw-r--r-- | apps/examples/nxtext/nxtext_putc.c | 24 |
5 files changed, 49 insertions, 29 deletions
diff --git a/apps/examples/nxtext/nxtext_bkgd.c b/apps/examples/nxtext/nxtext_bkgd.c index a87425112..90cc19165 100644 --- a/apps/examples/nxtext/nxtext_bkgd.c +++ b/apps/examples/nxtext/nxtext_bkgd.c @@ -136,7 +136,7 @@ static void nxbg_redrawrect(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect) for (i = 0; i < g_bgstate.nchars; i++) { - nxtext_fillchar(hwnd, rect, &g_bgstate, &g_bgstate.bm[i]); + nxtext_fillchar(hwnd, rect, &g_bgstate, g_bghfont, &g_bgstate.bm[i]); } } @@ -271,7 +271,7 @@ static inline void nxbg_movedisplay(NXWINDOW hwnd, int bottom, int lineheight) bm = &g_bgstate.bm[i]; if (bm->pos.y <= rect.pt2.y && bm->pos.y + g_bgstate.fheight >= rect.pt1.y) { - nxtext_fillchar(hwnd, &rect, &g_bgstate, bm); + nxtext_fillchar(hwnd, &rect, &g_bgstate, g_bghfont, bm); } } } @@ -402,7 +402,7 @@ FAR struct nxtext_state_s *nxbg_getstate(void) * state structure */ - fontset = nxf_getfontset(g_fonthandle); + fontset = nxf_getfontset(g_bghfont); g_bgstate.fheight = fontset->mxheight; g_bgstate.fwidth = fontset->mxwidth; g_bgstate.spwidth = fontset->spwidth; @@ -462,6 +462,6 @@ void nxbg_write(NXWINDOW hwnd, FAR const uint8_t *buffer, size_t buflen) /* Finally, we can output the character */ - nxtext_putc(hwnd, &g_bgstate, (uint8_t)*buffer++); + nxtext_putc(hwnd, &g_bgstate, g_bghfont, (uint8_t)*buffer++); } } diff --git a/apps/examples/nxtext/nxtext_internal.h b/apps/examples/nxtext/nxtext_internal.h index 98579ffdf..caf8cd9fc 100644 --- a/apps/examples/nxtext/nxtext_internal.h +++ b/apps/examples/nxtext/nxtext_internal.h @@ -45,8 +45,10 @@ #include <stdint.h> #include <stdbool.h> #include <semaphore.h> + #include <nuttx/nx/nx.h> #include <nuttx/nx/nxtk.h> +#include <nuttx/nx/nxfonts.h> /**************************************************************************** * Definitions @@ -76,6 +78,10 @@ # endif #endif +#ifndef CONFIG_EXAMPLES_NXTEXT_PUFONTID +# define CONFIG_EXAMPLES_NXTEXT_PUFONTID NXFONT_DEFAULT +#endif + #ifndef CONFIG_EXAMPLES_NXTEXT_PUCOLOR # if CONFIG_EXAMPLES_NXTEXT_BPP == 24 || CONFIG_EXAMPLES_NXTEXT_BPP == 32 # define CONFIG_EXAMPLES_NXTEXT_PUCOLOR 0x00dcdcdc @@ -86,6 +92,10 @@ # endif #endif +#ifndef CONFIG_EXAMPLES_NXTEXT_BGFONTID +# define CONFIG_EXAMPLES_NXTEXT_BGFONTID NXFONT_DEFAULT +#endif + #ifndef CONFIG_EXAMPLES_NXTEXT_BGFONTCOLOR # if CONFIG_EXAMPLES_NXTEXT_BPP == 24 || CONFIG_EXAMPLES_NXTEXT_BPP == 32 # define CONFIG_EXAMPLES_NXTEXT_BGFONTCOLOR 0x00000000 @@ -263,9 +273,10 @@ extern NXHANDLE g_hnx; extern NXHANDLE g_bgwnd; -/* The font handle */ +/* The font handlse */ -extern NXHANDLE g_fonthandle; +extern NXHANDLE g_bghfont; +extern NXHANDLE g_puhfont; /* NX callback vtables */ @@ -311,9 +322,9 @@ extern int nxpu_close(NXWINDOW hwnd); extern void nxtext_home(FAR struct nxtext_state_s *st); extern void nxtext_newline(FAR struct nxtext_state_s *st); extern void nxtext_putc(NXWINDOW hwnd, FAR struct nxtext_state_s *st, - uint8_t ch); + NXHANDLE hfont, uint8_t ch); extern void nxtext_fillchar(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, - FAR struct nxtext_state_s *st, + FAR struct nxtext_state_s *st, NXHANDLE hfont, FAR const struct nxtext_bitmap_s *bm); #endif /* __EXAMPLES_NXTEXT_NXTEXT_INTERNAL_H */ diff --git a/apps/examples/nxtext/nxtext_main.c b/apps/examples/nxtext/nxtext_main.c index 2ff941d0c..b7e2a3356 100644 --- a/apps/examples/nxtext/nxtext_main.c +++ b/apps/examples/nxtext/nxtext_main.c @@ -135,9 +135,10 @@ static const char *g_bgmsg[BGMSG_LINES] = NXHANDLE g_hnx = NULL; -/* The font handle */ +/* The font handles */ -NXHANDLE g_fonthandle = NULL; +NXHANDLE g_bghfont = NULL; +NXHANDLE g_puhfont = NULL; /* The screen resolution */ @@ -375,12 +376,20 @@ int MAIN_NAME(int argc, char **argv) goto errout; } - /* Get the default font handle */ + /* Get the configured font handles */ - g_fonthandle = nxf_getfonthandle(NXFONT_DEFAULT); - if (!g_fonthandle) + g_bghfont = nxf_getfonthandle(CONFIG_EXAMPLES_NXTEXT_BGFONTID); + if (!g_bghfont) { - message(MAIN_NAME_STRING ": Failed to get font handle: %d\n", errno); + message(MAIN_NAME_STRING ": Failed to get background font handle: %d\n", errno); + g_exitcode = NXEXIT_FONTOPEN; + goto errout; + } + + g_puhfont = nxf_getfonthandle(CONFIG_EXAMPLES_NXTEXT_PUFONTID); + if (!g_puhfont) + { + message(MAIN_NAME_STRING ": Failed to get pop-up font handle: %d\n", errno); g_exitcode = NXEXIT_FONTOPEN; goto errout; } diff --git a/apps/examples/nxtext/nxtext_popup.c b/apps/examples/nxtext/nxtext_popup.c index c0c66f4ef..f00f6a040 100644 --- a/apps/examples/nxtext/nxtext_popup.c +++ b/apps/examples/nxtext/nxtext_popup.c @@ -196,7 +196,7 @@ static inline void nxpu_fillwindow(NXWINDOW hwnd, nxtext_home(st); for (i = 0; i < st->nchars; i++) { - nxtext_fillchar(hwnd, rect, st, &st->bm[i]); + nxtext_fillchar(hwnd, rect, st, g_puhfont, &st->bm[i]); } #endif } @@ -265,7 +265,7 @@ static inline void nxpu_puts(NXWINDOW hwnd, FAR struct nxtext_state_s *st, nxtext_home(st); while (nch--) { - nxtext_putc(hwnd, st, *ch++); + nxtext_putc(hwnd, st, g_puhfont, *ch++); } } @@ -304,7 +304,7 @@ static inline void nxpu_initstate(void) */ #ifdef CONFIG_NX_KBD - fontset = nxf_getfontset(g_fonthandle); + fontset = nxf_getfontset(g_puhfont); g_pustate.fheight = fontset->mxheight; g_pustate.fwidth = fontset->mxwidth; g_pustate.spwidth = fontset->spwidth; diff --git a/apps/examples/nxtext/nxtext_putc.c b/apps/examples/nxtext/nxtext_putc.c index 5c1749269..dfecfe33f 100644 --- a/apps/examples/nxtext/nxtext_putc.c +++ b/apps/examples/nxtext/nxtext_putc.c @@ -326,13 +326,13 @@ nxtext_renderglyph(FAR struct nxtext_state_s *st, * Name: nxtext_fontsize ****************************************************************************/ -static int nxtext_fontsize(uint8_t ch, FAR struct nxgl_size_s *size) +static int nxtext_fontsize(NXHANDLE hfont, uint8_t ch, FAR struct nxgl_size_s *size) { FAR const struct nx_fontbitmap_s *fbm; /* No, it is not cached... Does the code map to a font? */ - fbm = nxf_getbitmap(g_fonthandle, ch); + fbm = nxf_getbitmap(hfont, ch); if (fbm) { /* Yes.. return the font size */ @@ -350,7 +350,7 @@ static int nxtext_fontsize(uint8_t ch, FAR struct nxgl_size_s *size) ****************************************************************************/ static FAR struct nxtext_glyph_s * -nxtext_getglyph(FAR struct nxtext_state_s *st, uint8_t ch) +nxtext_getglyph(NXHANDLE hfont, FAR struct nxtext_state_s *st, uint8_t ch) { FAR struct nxtext_glyph_s *glyph; FAR const struct nx_fontbitmap_s *fbm; @@ -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(g_fonthandle, ch); + fbm = nxf_getbitmap(hfont, ch); if (fbm) { /* Yes.. render the glyph */ @@ -384,7 +384,7 @@ nxtext_getglyph(FAR struct nxtext_state_s *st, uint8_t ch) ****************************************************************************/ static FAR const struct nxtext_bitmap_s * -nxtext_addchar(FAR struct nxtext_state_s *st, uint8_t ch) +nxtext_addchar(NXHANDLE hfont, FAR struct nxtext_state_s *st, uint8_t ch) { FAR struct nxtext_bitmap_s *bm = NULL; FAR struct nxtext_glyph_s *glyph; @@ -403,7 +403,7 @@ nxtext_addchar(FAR struct nxtext_state_s *st, uint8_t ch) /* Find (or create) the matching glyph */ - glyph = nxtext_getglyph(st, ch); + glyph = nxtext_getglyph(hfont, st, ch); if (!glyph) { /* No, there is no font for this code. Just mark this as a space. */ @@ -479,7 +479,7 @@ void nxtext_newline(FAR struct nxtext_state_s *st) * ****************************************************************************/ -void nxtext_putc(NXWINDOW hwnd, FAR struct nxtext_state_s *st, uint8_t ch) +void nxtext_putc(NXWINDOW hwnd, FAR struct nxtext_state_s *st, NXHANDLE hfont, uint8_t ch) { FAR const struct nxtext_bitmap_s *bm; @@ -498,10 +498,10 @@ void nxtext_putc(NXWINDOW hwnd, FAR struct nxtext_state_s *st, uint8_t ch) else { - bm = nxtext_addchar(st, ch); + bm = nxtext_addchar(hfont, st, ch); if (bm) { - nxtext_fillchar(hwnd, NULL, st, bm); + nxtext_fillchar(hwnd, NULL, st, hfont, bm); } } } @@ -517,7 +517,7 @@ void nxtext_putc(NXWINDOW hwnd, FAR struct nxtext_state_s *st, uint8_t ch) void nxtext_fillchar(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, FAR struct nxtext_state_s *st, - FAR const struct nxtext_bitmap_s *bm) + NXHANDLE hfont, FAR const struct nxtext_bitmap_s *bm) { FAR struct nxtext_glyph_s *glyph; struct nxgl_rect_s bounds; @@ -534,7 +534,7 @@ void nxtext_fillchar(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, /* Get the size of the font glyph (which may not have been created yet) */ - ret = nxtext_fontsize(bm->code, &fsize); + ret = nxtext_fontsize(hfont, bm->code, &fsize); if (ret < 0) { /* This would mean that there is no bitmap for the character code and @@ -576,7 +576,7 @@ void nxtext_fillchar(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, /* Find (or create) the glyph that goes with this font */ - glyph = nxtext_getglyph(st, bm->code); + glyph = nxtext_getglyph(hfont, st, bm->code); if (!glyph) { /* Shouldn't happen */ |