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
This commit is contained in:
patacongo 2011-08-24 17:00:51 +00:00
parent bf81d60a62
commit 840c4fb49f
4 changed files with 141 additions and 51 deletions

View File

@ -98,3 +98,5 @@
6.9 2011-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> 6.9 2011-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
* apps/examples/nxlines: Extend the line drawing text to include drawing
of circles.

View File

@ -424,8 +424,21 @@ examplex/nxlines
depends on CONFIG_EXAMPLES_NXLINES_BPP. depends on CONFIG_EXAMPLES_NXLINES_BPP.
CONFIG_EXAMPLES_NXLINES_LINEWIDTH - Selects the width of the lines in CONFIG_EXAMPLES_NXLINES_LINEWIDTH - Selects the width of the lines in
pixels (default: 16) pixels (default: 16)
CONFIG_EXAMPLES_NXLINES_LINECOLOR -- The color of the lines drawn in the CONFIG_EXAMPLES_NXLINES_LINECOLOR -- The color of the central lines drawn
background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP. 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 CONFIG_EXAMPLES_NXLINES_BPP -- Pixels per pixel to use. Valid options
include 2, 4, 8, 16, 24, and 32. Default is 16. include 2, 4, 8, 16, 24, and 32. Default is 16.
CONFIG_EXAMPLES_NXLINES_EXTERNINIT - The driver for the graphics device on CONFIG_EXAMPLES_NXLINES_EXTERNINIT - The driver for the graphics device on

View File

@ -92,6 +92,30 @@
# endif # 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 ********************************************************************/ /* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS #ifdef CONFIG_CPP_HAVE_VARARGS

View File

@ -201,28 +201,79 @@ static void nxlines_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
void nxlines_test(NXWINDOW hwnd) void nxlines_test(NXWINDOW hwnd)
{ {
struct nxgl_point_s center;
struct nxgl_vector_s vector; struct nxgl_vector_s vector;
struct nxgl_vector_s previous; struct nxgl_vector_s previous;
nxgl_mxpixel_t color[CONFIG_NX_NPLANES]; nxgl_mxpixel_t color[CONFIG_NX_NPLANES];
nxgl_coord_t xcenter; nxgl_coord_t maxradius;
nxgl_coord_t ycenter;
nxgl_coord_t radius; nxgl_coord_t radius;
nxgl_coord_t halfx; nxgl_coord_t halfx;
nxgl_coord_t halfy; nxgl_coord_t halfy;
b16_t angle; b16_t angle;
int ret; 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; maxradius = MIN(g_nxlines.yres, g_nxlines.xres) >> 1;
xcenter = g_nxlines.xres >> 1; center.x = g_nxlines.xres >> 1;
ycenter = g_nxlines.yres >> 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; angle = 0;
previous.pt1.x = xcenter; previous.pt1.x = center.x;
previous.pt1.y = ycenter; previous.pt1.y = center.y;
previous.pt2.x = xcenter; previous.pt2.x = center.x;
previous.pt2.y = ycenter; previous.pt2.y = center.y;
for (;;) for (;;)
{ {
@ -231,17 +282,17 @@ void nxlines_test(NXWINDOW hwnd)
halfx = b16toi(b16muli(b16sin(angle), radius)); halfx = b16toi(b16muli(b16sin(angle), radius));
halfy = b16toi(b16muli(b16cos(angle), radius)); halfy = b16toi(b16muli(b16cos(angle), radius));
vector.pt1.x = xcenter + halfx; vector.pt1.x = center.x + halfx;
vector.pt1.y = ycenter + halfy; vector.pt1.y = center.y + halfy;
vector.pt2.x = xcenter - halfx; vector.pt2.x = center.x - halfx;
vector.pt2.y = ycenter - halfy; vector.pt2.y = center.y - halfy;
message("Angle: %08x vector: (%d,%d)->(%d,%d)\n", message("Angle: %08x vector: (%d,%d)->(%d,%d)\n",
angle, vector.pt1.x, vector.pt1.y, vector.pt2.x, vector.pt2.y); 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; color[0] = CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR;
ret = nx_drawline((NXWINDOW)hwnd, &previous, CONFIG_EXAMPLES_NXLINES_LINEWIDTH, color); ret = nx_drawline((NXWINDOW)hwnd, &previous, CONFIG_EXAMPLES_NXLINES_LINEWIDTH, color);
if (ret < 0) if (ret < 0)
{ {