summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-08-24 17:00:51 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-08-24 17:00:51 +0000
commit67d6e613acb5129a2ca4a66ddf9cc6577933bc37 (patch)
treeaf72d8bd42567dc63ea75f7361bfc20133f3bbb6 /apps
parentb2273926830dcc8a4369bd41f2941f5ce22b3d3a (diff)
downloadnuttx-67d6e613acb5129a2ca4a66ddf9cc6577933bc37.tar.gz
nuttx-67d6e613acb5129a2ca4a66ddf9cc6577933bc37.tar.bz2
nuttx-67d6e613acb5129a2ca4a66ddf9cc6577933bc37.zip
Add a test of the circle rendering logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3911 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps')
-rwxr-xr-xapps/ChangeLog.txt2
-rw-r--r--apps/examples/README.txt17
-rw-r--r--apps/examples/nxlines/nxlines.h28
-rw-r--r--apps/examples/nxlines/nxlines_bkgd.c145
4 files changed, 141 insertions, 51 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index 41c26a13b..ffdc1e0f3 100755
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -98,3 +98,5 @@
6.9 2011-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
+ * apps/examples/nxlines: Extend the line drawing text to include drawing
+ of circles.
diff --git a/apps/examples/README.txt b/apps/examples/README.txt
index b155a3ab2..8bd704ccf 100644
--- a/apps/examples/README.txt
+++ b/apps/examples/README.txt
@@ -424,8 +424,21 @@ examplex/nxlines
depends on CONFIG_EXAMPLES_NXLINES_BPP.
CONFIG_EXAMPLES_NXLINES_LINEWIDTH - Selects the width of the lines in
pixels (default: 16)
- CONFIG_EXAMPLES_NXLINES_LINECOLOR -- The color of the lines drawn in the
- background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP.
+ CONFIG_EXAMPLES_NXLINES_LINECOLOR -- The color of the central lines drawn
+ in the background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP
+ (there really is no meaningful default).
+ CONFIG_EXAMPLES_NXLINES_BORDERWIDTH -- The width of the circular border
+ drawn in the background window. (default: 4).
+ CONFIG_EXAMPLES_NXLINES_BORDERCOLOR -- The color of the circular border
+ drawn in the background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP
+ (there really is no meaningful default).
+ CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR -- The color of the circular region
+ filled in the background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP
+ (there really is no meaningful default).
+ CONFIG_EXAMPLES_NXLINES_BORDERCOLOR -- The color of the lines drawn in the
+ background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP (there
+ really is no meaningful default).
+
CONFIG_EXAMPLES_NXLINES_BPP -- Pixels per pixel to use. Valid options
include 2, 4, 8, 16, 24, and 32. Default is 16.
CONFIG_EXAMPLES_NXLINES_EXTERNINIT - The driver for the graphics device on
diff --git a/apps/examples/nxlines/nxlines.h b/apps/examples/nxlines/nxlines.h
index 59ca282d0..fb91f23a3 100644
--- a/apps/examples/nxlines/nxlines.h
+++ b/apps/examples/nxlines/nxlines.h
@@ -75,7 +75,7 @@
# define CONFIG_EXAMPLES_NXLINES_BGCOLOR RGB16_DARKGREEN
# else
# define CONFIG_EXAMPLES_NXLINES_BGCOLOR RGB8_DARKGREEN
-# endif
+# endif
#endif
#ifndef CONFIG_EXAMPLES_NXLINES_LINEWIDTH
@@ -89,7 +89,31 @@
# define CONFIG_EXAMPLES_NXLINES_LINECOLOR RGB16_YELLOW
# else
# define CONFIG_EXAMPLES_NXLINES_LINECOLOR RGB8_YELLOW
-# endif
+# endif
+#endif
+
+#ifndef CONFIG_EXAMPLES_NXLINES_BORDERWIDTH
+# define CONFIG_EXAMPLES_NXLINES_BORDERWIDTH 16
+#endif
+
+#ifndef CONFIG_EXAMPLES_NXLINES_BORDERCOLOR
+# if CONFIG_EXAMPLES_NXLINES_BPP == 24 || CONFIG_EXAMPLES_NXLINES_BPP == 32
+# define CONFIG_EXAMPLES_NXLINES_BORDERCOLOR RGB24_YELLOW
+# elif CONFIG_EXAMPLES_NXLINES_BPP == 16
+# define CONFIG_EXAMPLES_NXLINES_BORDERCOLOR RGB16_YELLOW
+# else
+# define CONFIG_EXAMPLES_NXLINES_BORDERCOLOR RGB8_YELLOW
+# endif
+#endif
+
+#ifndef CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR
+# if CONFIG_EXAMPLES_NXLINES_BPP == 24 || CONFIG_EXAMPLES_NXLINES_BPP == 32
+# define CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR RGB24_BEIGE
+# elif CONFIG_EXAMPLES_NXLINES_BPP == 16
+# define CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR RGB16_BEIGE
+# else
+# define CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR RGB8_YELLOW
+# endif
#endif
/* Debug ********************************************************************/
diff --git a/apps/examples/nxlines/nxlines_bkgd.c b/apps/examples/nxlines/nxlines_bkgd.c
index 80808b1da..c9cbc921d 100644
--- a/apps/examples/nxlines/nxlines_bkgd.c
+++ b/apps/examples/nxlines/nxlines_bkgd.c
@@ -201,84 +201,135 @@ static void nxlines_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
void nxlines_test(NXWINDOW hwnd)
{
+ struct nxgl_point_s center;
struct nxgl_vector_s vector;
struct nxgl_vector_s previous;
nxgl_mxpixel_t color[CONFIG_NX_NPLANES];
- nxgl_coord_t xcenter;
- nxgl_coord_t ycenter;
+ nxgl_coord_t maxradius;
nxgl_coord_t radius;
nxgl_coord_t halfx;
nxgl_coord_t halfy;
b16_t angle;
int ret;
- /* Get the radius and center of the circle */
+ /* Get the maximum radius and center of the circle */
- radius = MIN(g_nxlines.yres, g_nxlines.xres) >> 1;
- xcenter = g_nxlines.xres >> 1;
- ycenter = g_nxlines.yres >> 1;
+ maxradius = MIN(g_nxlines.yres, g_nxlines.xres) >> 1;
+ center.x = g_nxlines.xres >> 1;
+ center.y = g_nxlines.yres >> 1;
+
+ /* Draw a circular background */
+
+ radius = maxradius - ((CONFIG_EXAMPLES_NXLINES_BORDERWIDTH+1)/2);
+ color[0] = CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR;
+ ret = nx_fillcircle((NXWINDOW)hwnd, &center, radius, color);
+ if (ret < 0)
+ {
+ message("nxlines_test: nx_fillcircle failed: %d\n", ret);
+ }
+
+ /* Draw the circular border */
+
+ color[0] = CONFIG_EXAMPLES_NXLINES_BORDERCOLOR;
+ ret = nx_drawcircle((NXWINDOW)hwnd, &center, radius,
+ CONFIG_EXAMPLES_NXLINES_BORDERWIDTH, color);
+ if (ret < 0)
+ {
+ message("nxlines_test: nx_fillcircle failed: %d\n", ret);
+ }
+
+ /* Back off the radius to account for the thickness of border line
+ * and with a big fudge factor that will (hopefully) prevent the corners
+ * of the lines from overwriting the border. This is overly complicated
+ * here because we don't assume anything about the screen resolution or
+ * the borderwidth or the line thickness (and there are certainly some
+ * smarter ways to do this).
+ */
+
+ if (maxradius > (CONFIG_EXAMPLES_NXLINES_BORDERWIDTH + 80))
+ {
+ radius = maxradius - (CONFIG_EXAMPLES_NXLINES_BORDERWIDTH + 40);
+ }
+ else if (maxradius > (CONFIG_EXAMPLES_NXLINES_BORDERWIDTH + 60))
+ {
+ radius = maxradius - (CONFIG_EXAMPLES_NXLINES_BORDERWIDTH + 30);
+ }
+ else if (maxradius > (CONFIG_EXAMPLES_NXLINES_BORDERWIDTH + 40))
+ {
+ radius = maxradius - (CONFIG_EXAMPLES_NXLINES_BORDERWIDTH + 20);
+ }
+ else if (maxradius > (CONFIG_EXAMPLES_NXLINES_BORDERWIDTH + 20))
+ {
+ radius = maxradius - (CONFIG_EXAMPLES_NXLINES_BORDERWIDTH + 10);
+ }
+ else
+ {
+ radius = maxradius - CONFIG_EXAMPLES_NXLINES_BORDERWIDTH;
+ }
+
+ /* The loop, showing the line in various orientations */
angle = 0;
- previous.pt1.x = xcenter;
- previous.pt1.y = ycenter;
- previous.pt2.x = xcenter;
- previous.pt2.y = ycenter;
+ previous.pt1.x = center.x;
+ previous.pt1.y = center.y;
+ previous.pt2.x = center.x;
+ previous.pt2.y = center.y;
for (;;)
{
- /* Determine the position of the line on this pass */
+ /* Determine the position of the line on this pass */
- halfx = b16toi(b16muli(b16sin(angle), radius));
- halfy = b16toi(b16muli(b16cos(angle), radius));
+ halfx = b16toi(b16muli(b16sin(angle), radius));
+ halfy = b16toi(b16muli(b16cos(angle), radius));
- vector.pt1.x = xcenter + halfx;
- vector.pt1.y = ycenter + halfy;
- vector.pt2.x = xcenter - halfx;
- vector.pt2.y = ycenter - halfy;
+ vector.pt1.x = center.x + halfx;
+ vector.pt1.y = center.y + halfy;
+ vector.pt2.x = center.x - halfx;
+ vector.pt2.y = center.y - halfy;
- message("Angle: %08x vector: (%d,%d)->(%d,%d)\n",
- angle, vector.pt1.x, vector.pt1.y, vector.pt2.x, vector.pt2.y);
+ message("Angle: %08x vector: (%d,%d)->(%d,%d)\n",
+ angle, vector.pt1.x, vector.pt1.y, vector.pt2.x, vector.pt2.y);
- /* Clear the previous line */
+ /* Clear the previous line by overwriting it with the circle color */
- color[0] = CONFIG_EXAMPLES_NXLINES_BGCOLOR;
- ret = nx_drawline((NXWINDOW)hwnd, &previous, CONFIG_EXAMPLES_NXLINES_LINEWIDTH, color);
- if (ret < 0)
- {
- message("nxlines_test: nx_drawline failed clearing: %d\n", ret);
- }
+ color[0] = CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR;
+ ret = nx_drawline((NXWINDOW)hwnd, &previous, CONFIG_EXAMPLES_NXLINES_LINEWIDTH, color);
+ if (ret < 0)
+ {
+ message("nxlines_test: nx_drawline failed clearing: %d\n", ret);
+ }
- /* Draw the new line */
+ /* Draw the new line */
- color[0] = CONFIG_EXAMPLES_NXLINES_LINECOLOR;
- ret = nx_drawline((NXWINDOW)hwnd, &vector, CONFIG_EXAMPLES_NXLINES_LINEWIDTH, color);
- if (ret < 0)
- {
- message("nxlines_test: nx_drawline failed clearing: %d\n", ret);
- }
+ color[0] = CONFIG_EXAMPLES_NXLINES_LINECOLOR;
+ ret = nx_drawline((NXWINDOW)hwnd, &vector, CONFIG_EXAMPLES_NXLINES_LINEWIDTH, color);
+ if (ret < 0)
+ {
+ message("nxlines_test: nx_drawline failed clearing: %d\n", ret);
+ }
- /* Set up for the next time through the loop then sleep for a bit. */
+ /* Set up for the next time through the loop then sleep for a bit. */
- angle += b16PI / 16; /* 32 angular positions in full circle */
+ angle += b16PI / 16; /* 32 angular positions in full circle */
- /* Check if we have gone all the way around */
+ /* Check if we have gone all the way around */
- if (angle > (31 * (2 * b16PI) / 32))
- {
+ if (angle > (31 * (2 * b16PI) / 32))
+ {
#ifdef CONFIG_EXAMPLES_NXLINES_BUILTIN
- /* If this example was built as an NSH add-on, then exit after we
- * have gone all the way around once.
- */
+ /* If this example was built as an NSH add-on, then exit after we
+ * have gone all the way around once.
+ */
- return;
+ return;
#else
- /* Wrap back to zero and continue with the test */
+ /* Wrap back to zero and continue with the test */
- angle = 0;
+ angle = 0;
#endif
- }
+ }
- memcpy(&previous, &vector, sizeof(struct nxgl_vector_s));
- usleep(500*1000);
+ memcpy(&previous, &vector, sizeof(struct nxgl_vector_s));
+ usleep(500*1000);
}
}