summaryrefslogtreecommitdiff
path: root/apps/examples/nxhello
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-07-27 14:43:45 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-07-27 14:43:45 +0000
commit99ffb319c5af373ef135c2a3e73bf1171e55559e (patch)
tree7aa08fa81a006d354469de2652043ab969d8a3c4 /apps/examples/nxhello
parentce09509ff8c3127b4cc07ebcaae78229d5b2d90a (diff)
downloadnuttx-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/nxhello')
-rw-r--r--apps/examples/nxhello/nxhello.h7
-rw-r--r--apps/examples/nxhello/nxhello_bkgd.c14
-rw-r--r--apps/examples/nxhello/nxhello_main.c2
3 files changed, 17 insertions, 6 deletions
diff --git a/apps/examples/nxhello/nxhello.h b/apps/examples/nxhello/nxhello.h
index 93c6d8fac..169285856 100644
--- a/apps/examples/nxhello/nxhello.h
+++ b/apps/examples/nxhello/nxhello.h
@@ -46,8 +46,9 @@
#include <stdbool.h>
#include <semaphore.h>
-#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxglib.h>
+#include <nuttx/nx/nx.h>
+#include <nuttx/nx/nxfonts.h>
/****************************************************************************
* Definitions
@@ -77,6 +78,10 @@
# endif
#endif
+#ifndef CONFIG_EXAMPLES_NXHELLO_FONTID
+# define CONFIG_EXAMPLES_NXHELLO_FONTID NXFONT_DEFAULT
+#endif
+
#ifndef CONFIG_EXAMPLES_NXHELLO_FONTCOLOR
# if CONFIG_EXAMPLES_NXHELLO_BPP == 24 || CONFIG_EXAMPLES_NXHELLO_BPP == 32
# define CONFIG_EXAMPLES_NXHELLO_FONTCOLOR 0x00000000
diff --git a/apps/examples/nxhello/nxhello_bkgd.c b/apps/examples/nxhello/nxhello_bkgd.c
index 43bfc0516..93b7798e1 100644
--- a/apps/examples/nxhello/nxhello_bkgd.c
+++ b/apps/examples/nxhello/nxhello_bkgd.c
@@ -233,7 +233,7 @@ static void nxhello_center(FAR struct nxgl_point_s *pos,
{
/* Add the font size */
- width += fbm->metric.width;
+ width += fbm->metric.width + fbm->metric.xoffset;
}
else
{
@@ -349,6 +349,7 @@ void nxhello_hello(NXWINDOW hwnd)
FAR struct nxgl_rect_s dest;
FAR const void *src[CONFIG_NX_NPLANES];
unsigned int glyphsize;
+ unsigned int mxstride;
int ret;
/* Get information about the font we are going to use */
@@ -357,8 +358,9 @@ void nxhello_hello(NXWINDOW hwnd)
/* Allocate a bit of memory to hold the largest rendered font */
- glyphsize = (unsigned int)fontset->mxheight * (unsigned int)fontset->mxwidth;
- glyph = (FAR uint8_t*)malloc(glyphsize);
+ mxstride = (fontset->mxwidth * CONFIG_EXAMPLES_NXHELLO_BPP + 7) >> 3;
+ glyphsize = (unsigned int)fontset->mxheight * mxstride;
+ glyph = (FAR uint8_t*)malloc(glyphsize);
/* NOTE: no check for failure to allocate the memory. In a real application
* you would need to handle that event.
@@ -388,7 +390,7 @@ void nxhello_hello(NXWINDOW hwnd)
fwidth = fbm->metric.width + fbm->metric.xoffset;
fheight = fbm->metric.height + fbm->metric.yoffset;
- fstride = (fwidth * CONFIG_EXAMPLES_NXHELLO_BPP + 7) / 8;
+ fstride = (fwidth * CONFIG_EXAMPLES_NXHELLO_BPP + 7) >> 3;
/* Initialize the glyph memory to the background color */
@@ -434,4 +436,8 @@ void nxhello_hello(NXWINDOW hwnd)
pos.x += fontset->spwidth;
}
}
+
+ /* Free the allocated glyph */
+
+ free(glyph);
}
diff --git a/apps/examples/nxhello/nxhello_main.c b/apps/examples/nxhello/nxhello_main.c
index d83b354d7..e71df98d1 100644
--- a/apps/examples/nxhello/nxhello_main.c
+++ b/apps/examples/nxhello/nxhello_main.c
@@ -232,7 +232,7 @@ int MAIN_NAME(int argc, char *argv[])
/* Get the default font handle */
- g_nxhello.hfont = nxf_getfonthandle(NXFONT_DEFAULT);
+ g_nxhello.hfont = nxf_getfonthandle(CONFIG_EXAMPLES_NXHELLO_FONTID);
if (!g_nxhello.hfont)
{
message(MAIN_NAME_STRING ": Failed to get font handle: %d\n", errno);