diff --git a/ChangeLog b/ChangeLog index 2171a4066c0..99ae506e2a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1962,4 +1962,7 @@ * lib/math/lib_b16atan2.c: Add a fixed precision atan2() function * graphics/nxglib/nxglib_splitline.c: Add logic to divide a wide line into trapezoidal components. + * graphics/nxmu/nx_drawline.c, graphics/nxsu/nx_drawline.c, + graphics/nxtk/nxtk_drawlinewindow.c, graphics/nxtk/nxtk_drawlinetoolbar.c: + Add new line drawing interfaces (untested). diff --git a/Documentation/NXGraphicsSubsystem.html b/Documentation/NXGraphicsSubsystem.html index 681c2bc2836..a8367c60758 100644 --- a/Documentation/NXGraphicsSubsystem.html +++ b/Documentation/NXGraphicsSubsystem.html @@ -12,7 +12,7 @@
Last Updated: July 27 2011
+Last Updated: August 2, 2011
@@ -76,7 +76,8 @@ 2.2.15nxgl_runcopy()nxgl_trapoffset()nxgl_trapcopy()nxgl_colorcopy
+ 2.2.18 nxgl_colorcopynxgl_splitline
@@ -113,11 +114,12 @@
2.3.19 nx_lower()
2.3.20 nx_fill()
2.3.21 nx_filltrapezoid()
- 2.3.22 nx_setbgcolor()
- 2.3.23 nx_move()
- 2.3.24 nx_bitmap()
- 2.3.25 nx_kbdin()
- 2.3.26 nx_mousein()
+ 2.3.22 nx_drawline()
+ 2.3.23 nx_setbgcolor()
+ 2.3.24 nx_move()
+ 2.3.25 nx_bitmap()
+ 2.3.26 nx_kbdin()
+ 2.3.27 nx_mousein()
nxtk_lower()nxtk_fillwindow()nxtk_filltrapwindow()nxtk_movewindow()nxtk_bitmapwindow()nxtk_opentoolbar()nxtk_closetoolbar()nxtk_filltoolbar()nxtk_filltraptoolbar()nxtk_movetoolbar()nxtk_bitmaptoolbar()
+ 2.4.11 nxtk_drawlinewindow()nxtk_movewindow()nxtk_bitmapwindow()nxtk_opentoolbar()nxtk_closetoolbar()nxtk_filltoolbar()nxtk_filltraptoolbar()nxtk_drawlinetoolbar()nxtk_movetoolbar()nxtk_bitmaptoolbar()
@@ -711,7 +715,7 @@ void nxgl_trapoffset(FAR struct nxgl_trapezoid_s *dest,
Offset the trapezoid position by the specified dx, dy values.
nxgl_trapcopy()nxgl_trapcopy()Function Prototype:
#include <nuttx/nx/nxglib.h> @@ -724,7 +728,7 @@ void nxgl_trapcopy(FAR struct nxgl_trapezoid_s *dest, assignments because some compilers are not good at that. -2.2.1
+nxgl_colorcopy2.2.18
nxgl_colorcopyFunction Prototype:
#include <nuttx/nx/nxglib.h> @@ -738,6 +742,70 @@ nxgl_colorcopy(nxgl_mxpixel_t dest[CONFIG_NX_NPLANES], in one place. +2.2.19
+ +nxgl_splitlineFunction Prototype:
+
+#include <nuttx/nx/nxglib.h> +int nxgl_splitline(FAR struct nxgl_vector_s *vector, FAR struct nxgl_trapezoid_s *traps, + FAR struct nxgl_rect_s *rect, nxgl_coord_t linewidth); ++
+ Description: + In the general case, a line with width can be represented as a parallelogram with a triangle at the top and bottom. + Triangles and parallelograms are both degenerate versions of a trapeziod. + This function breaks a wide line into triangles and trapezoids. + This function also detects other degenerate cases: +
+y1 == y2 then the line is horizontal and is better represented as a rectangle.
+ x1 == x2 then the line is vertical and also better represented as a rectangle.
+ + Input parameters: +
+
vector
+ traps
+ rect
+ + Returned value: +
+
+ 0: Line successfully broken up into three trapezoids.
+ Values in traps[0], traps[1], and traps[2] are valid.
+
+ 1: Line successfully represented by one trapezoid.
+ Value in traps[1] is valid.
+
+ 2: Line successfully represented by one rectangle.
+ Value in rect is valid
+
+ <0: On errors, a negated errno value is returned.
+
+
ERROR on failure with errno set appropriately
-nx_setbgcolor()nx_drawline()Function Prototype:
++#include <nuttx/nx/nxglib.h> +#include <nuttx/nx/nx.h> + +int nx_drawline(NXWINDOW hwnd, FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, nxgl_mxpixel_t color[CONFIG_NX_NPLANES]); ++
+ Description:
+ Fill the specified trapezoidal region in the window with the specified color.
+ Fill the specified line in the window with the specified color.
+ This is simply a wrapper that uses nxgl_splitline() to break the line into
+ trapezoids and then calls nx_filltrapezoid() to render the line.
+
+ Input Parameters: +
hwnd
+ nx_openwindow()
+ or nx_requestbkgd()
+ vector
+ width
+ color
+
+ Returned Value:
+ OK on success;
+ ERROR on failure with errno set appropriately
+
nx_setbgcolor()Function Prototype:
#include <nuttx/nx/nxglib.h> @@ -1609,7 +1713,7 @@ int nx_setbgcolor(NXHANDLE handle,ERRORon failure witherrnoset appropriately -2.3.23
+nx_move()2.3.24
nx_move()Function Prototype:
#include <nuttx/nx/nxglib.h> @@ -1640,7 +1744,7 @@ int nx_move(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,ERRORon failure witherrnoset appropriately -2.3.24
+nx_bitmap()2.3.25
nx_bitmap()Function Prototype:
#include <nuttx/nx/nxglib.h> @@ -1682,7 +1786,7 @@ int nx_bitmap(NXWINDOW hwnd, FAR const struct nxgl_rect_s *dest,ERRORon failure witherrnoset appropriately -2.3.25
+nx_kbdin()2.3.26
nx_kbdin()Function Prototype:
#include <nuttx/nx/nxglib.h> @@ -1705,7 +1809,7 @@ int nx_kbdin(NXHANDLE handle, uint8_t nch, FAR const uint8_t *ch);ERRORon failure witherrnoset appropriately -2.3.26
+nx_mousein()2.3.27
nx_mousein()Function Prototype:
#include <nuttx/nx/nxglib.h> @@ -2061,7 +2165,44 @@ int nxtk_filltrapwindow(NXTKWINDOW hfwnd,ERRORon failure witherrnoset appropriately -2.4.11
+nxtk_movewindow()2.4.11
+nxtk_drawlinewindow()Function Prototype:
+
+#include <nuttx/nx/nxglib.h> +#include <nuttx/nx/nx.h> +#include <nuttx/nx/nxtk.h> + +int nxtk_drawlinewindow(NXTKWINDOW hfwnd, FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, nxgl_mxpixel_t color[CONFIG_NX_NPLANES]); ++
+ Description:
+ Fill the specified trapezoidal region in the window with the specified color.
+ Fill the specified line in the window with the specified color.
+ This is simply a wrapper that uses nxgl_splitline() to break the line into
+ trapezoids and then calls nxtk_filltrapwindow() to render the line.
+
+ Input Parameters: +
hfwnd
+ nxtk_openwindow().
+ vector
+ width
+ color
+
+ Returned Value:
+ OK on success;
+ ERROR on failure with errno set appropriately
+
nxtk_movewindow()Function Prototype:
#include <nuttx/nx/nxglib.h> @@ -2094,7 +2235,7 @@ int nxtk_movewindow(NXTKWINDOW hfwnd, FAR const struct nxgl_rect_s *rect,ERRORon failure witherrnoset appropriately -2.4.12
+nxtk_bitmapwindow()2.4.13
nxtk_bitmapwindow()Function Prototype:
#include <nuttx/nx/nxglib.h> @@ -2139,7 +2280,7 @@ int nxtk_bitmapwindow(NXTKWINDOW hfwnd,ERRORon failure witherrnoset appropriately -2.4.13
+nxtk_opentoolbar()2.4.14
nxtk_opentoolbar()Function Prototype:
#include <nuttx/nx/nxglib.h> @@ -2174,7 +2315,7 @@ int nxtk_opentoolbar(NXTKWINDOW hfwnd, nxgl_coord_t height,ERRORon failure witherrnoset appropriately -2.4.14
+nxtk_closetoolbar()2.4.15
nxtk_closetoolbar()Function Prototype:
#include <nuttx/nx/nxglib.h> @@ -2203,7 +2344,7 @@ int nxtk_closetoolbar(NXTKWINDOW hfwnd);ERRORon failure witherrnoset appropriately -2.4.15
+nxtk_filltoolbar()2.4.16
nxtk_filltoolbar()Function Prototype:
#include <nuttx/nx/nxglib.h> @@ -2235,7 +2376,7 @@ int nxtk_filltoolbar(NXTKWINDOW hfwnd, FAR const struct nxgl_rect_s *rect,ERRORon failure witherrnoset appropriately -2.4.16
+nxtk_filltraptoolbar()2.4.17
nxtk_filltraptoolbar()Function Prototype:
#include <nuttx/nx/nxglib.h> @@ -2267,7 +2408,44 @@ int nxtk_filltraptoolbar(NXTKWINDOW hfwnd, FAR const struct nxgl_trapezoid_s *trERRORon failure witherrnoset appropriately -2.4.17
+nxtk_movetoolbar()2.4.18
+nxtk_drawlinetoolbar()Function Prototype:
+
+#include <nuttx/nx/nxglib.h> +#include <nuttx/nx/nx.h> +#include <nuttx/nx/nxtk.h> + +int nxtk_drawlinetoolbar(NXTKWINDOW hfwnd, FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, nxgl_mxpixel_t color[CONFIG_NX_NPLANES]); + ++
+ Description:
+ Fill the specified line in the toolbar sub-window with the specified color.
+ This is simply a wrapper that uses nxgl_splitline() to break the line into
+ trapezoids and then calls nxtk_filltraptoolbar() to render the line.
+
+ Input Parameters: +
hfwnd
+ nxtk_openwindow().
+ vector
+ width
+ color
+
+ Returned Value:
+ OK on success;
+ ERROR on failure with errno set appropriately
+
nxtk_movetoolbar()Function Prototype:
#include <nuttx/nx/nxglib.h> @@ -2301,7 +2479,7 @@ int nxtk_movetoolbar(NXTKWINDOW hfwnd, FAR const struct nxgl_rect_s *rect,ERRORon failure witherrnoset appropriately -2.4.18
+nxtk_bitmaptoolbar()2.4.20
nxtk_bitmaptoolbar()Function Prototype:
#include <nuttx/nx/nxglib.h> @@ -3139,9 +3317,13 @@ makeYES ++ -+ nxgl_splitline+ PART +Table D.2: NX Server Callbacks Test Coverage
@@ -3285,6 +3467,11 @@ make +NO + + nx_drawline()+ NO ++ nx_setbgcolor()@@ -3367,6 +3554,11 @@ make NO + + nxtk_drawlinewindow()+ YES ++ nxtk_movewindow()@@ -3397,6 +3589,11 @@ make NO + + nxtk_drawlinetoolbar()+ NO +nxtk_movetoolbar()diff --git a/graphics/nxglib/nxglib_splitline.c b/graphics/nxglib/nxglib_splitline.c index d4d2899b3a9..7be9cc115b0 100644 --- a/graphics/nxglib/nxglib_splitline.c +++ b/graphics/nxglib/nxglib_splitline.c @@ -75,7 +75,8 @@ * In the general case, a line with width can be represented as a * parallelogram with a triangle at the top and bottom. Triangles and * parallelograms are both degenerate versions of a trapeziod. This - * function breaks. This function also detects other degenerate cases: + * function breaks a wide line into triangles and trapezoids. This + * function also detects other degenerate cases: * * 1. If y1 == y2 then the line is horizontal and is better represented * as a rectangle. @@ -83,9 +84,9 @@ * as a rectangle. * 3. If the width of the line is 1, then there are no triangles at the * top and bottome (this may also be the case if the width is narrow - * and the line is near vertical) + * and the line is near vertical). * 4. If the line is oriented is certain angles, it may consist only of - * the upper and lower triangles with no trapezoid inbetween. In + * the upper and lower triangles with no trapezoid in between. In * this case, 3 trapezoids will be returned, but traps[1] will be * degenerate. * diff --git a/graphics/nxmu/Make.defs b/graphics/nxmu/Make.defs index 64d5fc72427..79959a4a059 100644 --- a/graphics/nxmu/Make.defs +++ b/graphics/nxmu/Make.defs @@ -39,7 +39,7 @@ NXAPI_CSRCS = nx_bitmap.c nx_closewindow.c nx_connect.c nx_disconnect.c \ nx_getposition.c nx_kbdchin.c nx_kbdin.c nx_lower.c \ nx_mousein.c nx_move.c nx_openwindow.c nx_raise.c \ nx_releasebkgd.c nx_requestbkgd.c nx_setsize.c \ - nx_setbgcolor.c nx_setposition.c + nx_setbgcolor.c nx_setposition.c nx_drawline.c NXMU_CSRCS = nxmu_constructwindow.c nxmu_kbdin.c nxmu_mouse.c \ nxmu_openwindow.c nxmu_redrawreq.c nxmu_releasebkgd.c \ nxmu_requestbkgd.c nxmu_reportposition.c nxmu_semtake.c \ diff --git a/graphics/nxmu/nx_drawline.c b/graphics/nxmu/nx_drawline.c new file mode 100644 index 00000000000..0267d8058b0 --- /dev/null +++ b/graphics/nxmu/nx_drawline.c @@ -0,0 +1,136 @@ +/**************************************************************************** + * graphics/nxmu/nx_drawline.c + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_drawline + * + * Description: + * Fill the specified line in the window with the specified color. This + * is simply a wrapper that uses nxgl_splitline() to break the line into + * trapezoids and then calls nx_filltrapezoid() to render the line. + * + * Input Parameters: + * hwnd - The window handle + * vector - Describes the line to be drawn + * width - The width of the line + * color - The color to use to fill the line + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_drawline(NXWINDOW hwnd, FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) +{ + struct nxgl_trapezoid_s trap[3]; + struct nxgl_rect_s rect; + int ret; + +#ifdef CONFIG_DEBUG + if (!hwnd || !vector || width < 1 || !color) + { + set_errno(EINVAL); + return ERROR; + } +#endif + + ret = nxgl_splitline(vector, trap, &rect, width); + switch (ret) + { + case 0: + ret = nx_filltrapezoid(hwnd, NULL, &trap[0], color); + if (ret == OK) + { + ret = nx_filltrapezoid(hwnd, NULL, &trap[1], color); + if (ret == OK) + { + ret = nx_filltrapezoid(hwnd, NULL, &trap[2], color); + } + } + break; + + case 1: + ret = nx_filltrapezoid(hwnd, NULL, &trap[1], color); + break; + + case 2: + ret = nx_fill(hwnd, &rect, color); + break; + + default: + set_errno(-ret); + return ERROR; + } + + return ret; +} diff --git a/graphics/nxsu/Make.defs b/graphics/nxsu/Make.defs index af525bea997..3cddf3a2c5b 100644 --- a/graphics/nxsu/Make.defs +++ b/graphics/nxsu/Make.defs @@ -38,6 +38,6 @@ NXAPI_CSRCS = nx_bitmap.c nx_close.c nx_closewindow.c nx_fill.c \ nx_filltrapezoid.c nx_getposition.c nx_kbdchin.c \ nx_kbdin.c nx_lower.c nx_mousein.c nx_move.c nx_open.c \ nx_openwindow.c nx_raise.c nx_releasebkgd.c nx_requestbkgd.c \ - nx_setsize.c nx_setbgcolor.c nx_setposition.c + nx_setsize.c nx_setbgcolor.c nx_setposition.c nx_drawline.c NXSU_CSRCS = nxsu_constructwindow.c nxsu_redrawreq.c nxsu_reportposition.c NX_CSRCS = $(NXAPI_CSRCS) $(NXSU_CSRCS) diff --git a/graphics/nxsu/nx_drawline.c b/graphics/nxsu/nx_drawline.c new file mode 100644 index 00000000000..ca4ddaf188a --- /dev/null +++ b/graphics/nxsu/nx_drawline.c @@ -0,0 +1,136 @@ +/**************************************************************************** + * graphics/nxsu/nx_drawline.c + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_drawline + * + * Description: + * Fill the specified line in the window with the specified color. This + * is simply a wrapper that uses nxgl_splitline() to break the line into + * trapezoids and then calls nx_filltrapezoid() to render the line. + * + * Input Parameters: + * hwnd - The window handle + * vector - Describes the line to be drawn + * width - The width of the line + * color - The color to use to fill the line + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_drawline(NXWINDOW hwnd, FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) +{ + struct nxgl_trapezoid_s trap[3]; + struct nxgl_rect_s rect; + int ret; + +#ifdef CONFIG_DEBUG + if (!hwnd || !vector || width < 1 || !color) + { + set_errno(EINVAL); + return ERROR; + } +#endif + + ret = nxgl_splitline(vector, trap, &rect, width); + switch (ret) + { + case 0: + ret = nx_filltrapezoid(hwnd, NULL, &trap[0], color); + if (ret == OK) + { + ret = nx_filltrapezoid(hwnd, NULL, &trap[1], color); + if (ret == OK) + { + ret = nx_filltrapezoid(hwnd, NULL, &trap[2], color); + } + } + break; + + case 1: + ret = nx_filltrapezoid(hwnd, NULL, &trap[1], color); + break; + + case 2: + ret = nx_fill(hwnd, &rect, color); + break; + + default: + set_errno(-ret); + return ERROR; + } + + return ret; +} diff --git a/graphics/nxtk/Make.defs b/graphics/nxtk/Make.defs index 67c9b63ae05..736d91003c9 100644 --- a/graphics/nxtk/Make.defs +++ b/graphics/nxtk/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # graphics/nxtk/Make.defs # -# Copyright (C) 2008 Gregory Nutt. All rights reserved. +# Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -37,8 +37,10 @@ NXTK_ASRCS = NXTKWIN_CSRCS = nxtk_openwindow.c nxtk_closewindow.c nxtk_getposition.c \ nxtk_setposition.c nxtk_setsize.c nxtk_raise.c nxtk_lower.c \ nxtk_fillwindow.c nxtk_filltrapwindow.c nxtk_movewindow.c \ - nxtk_bitmapwindow.c nxtk_events.c nxtk_setsubwindows.c + nxtk_bitmapwindow.c nxtk_events.c nxtk_setsubwindows.c \ + nxtk_drawlinewindow.c NXTKTB_CSRCS = nxtk_opentoolbar.c nxtk_closetoolbar.c nxtk_filltoolbar.c \ - nxtk_filltraptoolbar.c nxtk_movetoolbar.c nxtk_bitmaptoolbar.c + nxtk_filltraptoolbar.c nxtk_movetoolbar.c nxtk_bitmaptoolbar.c \ + nxtk_drawlinetoolbar.c NXTK_CSRCS = $(NXTKWIN_CSRCS) $(NXTKTB_CSRCS) nxtk_subwindowclip.c \ nxtk_containerclip.c nxtk_subwindowmove.c nxtk_drawframe.c diff --git a/graphics/nxtk/nxtk_drawlinetoolbar.c b/graphics/nxtk/nxtk_drawlinetoolbar.c new file mode 100644 index 00000000000..4af8b373271 --- /dev/null +++ b/graphics/nxtk/nxtk_drawlinetoolbar.c @@ -0,0 +1,139 @@ +/**************************************************************************** + * graphics/nxtk/nxtk_drawlinetoolbar.c + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxtk_drawlinetoolbar + * + * Description: + * Fill the specified line in the toolbar sub-window with the specified + * color. This is simply a wrapper that uses nxgl_splitline() to break the + * line into trapezoids and then calls nxtk_filltrapwindow() to render the + * line. + * + * Input Parameters: + * hfwnd - The window handle returned by nxtk_openwindow + * vector - Describes the line to be drawn + * width - The width of the line + * color - The color to use to fill the line + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nxtk_drawlinetoolbar(NXTKWINDOW hfwnd, FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) + +{ + struct nxgl_trapezoid_s trap[3]; + struct nxgl_rect_s rect; + int ret; + +#ifdef CONFIG_DEBUG + if (!hfwnd || !vector || width < 1 || !color) + { + set_errno(EINVAL); + return ERROR; + } +#endif + + ret = nxgl_splitline(vector, trap, &rect, width); + switch (ret) + { + case 0: + ret = nxtk_filltraptoolbar(hfwnd, &trap[0], color); + if (ret == OK) + { + ret = nxtk_filltraptoolbar(hfwnd, &trap[1], color); + if (ret == OK) + { + ret = nxtk_filltraptoolbar(hfwnd, &trap[2], color); + } + } + break; + + case 1: + ret = nxtk_filltraptoolbar(hfwnd, &trap[1], color); + break; + + case 2: + ret = nxtk_filltoolbar(hfwnd, &rect, color); + break; + + default: + set_errno(EINVAL); + return ERROR; + } + + return ret; +} diff --git a/graphics/nxtk/nxtk_drawlinewindow.c b/graphics/nxtk/nxtk_drawlinewindow.c new file mode 100644 index 00000000000..2dfd7e84521 --- /dev/null +++ b/graphics/nxtk/nxtk_drawlinewindow.c @@ -0,0 +1,138 @@ +/**************************************************************************** + * graphics/nxtk/nxtk_drawlinewindow.c + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxtk_drawlinewindow + * + * Description: + * Fill the specified line in the window with the specified color. This + * is simply a wrapper that uses nxgl_splitline() to break the line into + * trapezoids and call calls nxtk_filltrapwindow() to render the line. + * + * Input Parameters: + * hfwnd - The window handle returned by nxtk_openwindow + * vector - Describes the line to be drawn + * width - The width of the line + * color - The color to use to fill the line + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nxtk_drawlinewindow(NXTKWINDOW hfwnd, FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) + +{ + struct nxgl_trapezoid_s trap[3]; + struct nxgl_rect_s rect; + int ret; + +#ifdef CONFIG_DEBUG + if (!hfwnd || !vector || width < 1 || !color) + { + set_errno(EINVAL); + return ERROR; + } +#endif + + ret = nxgl_splitline(vector, trap, &rect, width); + switch (ret) + { + case 0: + ret = nxtk_filltrapwindow(hfwnd, &trap[0], color); + if (ret == OK) + { + ret = nxtk_filltrapwindow(hfwnd, &trap[1], color); + if (ret == OK) + { + ret = nxtk_filltrapwindow(hfwnd, &trap[2], color); + } + } + break; + + case 1: + ret = nxtk_filltrapwindow(hfwnd, &trap[1], color); + break; + + case 2: + ret = nxtk_fillwindow(hfwnd, &rect, color); + break; + + default: + set_errno(EINVAL); + return ERROR; + } + + return ret; +} diff --git a/include/nuttx/nx/nx.h b/include/nuttx/nx/nx.h index c031a3bf95c..66163e6793e 100644 --- a/include/nuttx/nx/nx.h +++ b/include/nuttx/nx/nx.h @@ -611,6 +611,28 @@ EXTERN int nx_filltrapezoid(NXWINDOW hwnd, FAR const struct nxgl_rect_s *clip, FAR const struct nxgl_trapezoid_s *trap, nxgl_mxpixel_t color[CONFIG_NX_NPLANES]); +/**************************************************************************** + * Name: nx_drawline + * + * Description: + * Fill the specified line in the window with the specified color. This + * is simply a wrapper that uses nxgl_splitline() to break the line into + * trapezoids and then calls nx_filltrapezoid() to render the line. + * + * Input Parameters: + * hwnd - The window handle + * vector - Describes the line to be drawn + * width - The width of the line + * color - The color to use to fill the line + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +EXTERN int nx_drawline(NXWINDOW hwnd, FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, nxgl_mxpixel_t color[CONFIG_NX_NPLANES]); + /**************************************************************************** * Name: nx_setbgcolor * diff --git a/include/nuttx/nx/nxglib.h b/include/nuttx/nx/nxglib.h index 583eedf5733..c1dc3afc646 100644 --- a/include/nuttx/nx/nxglib.h +++ b/include/nuttx/nx/nxglib.h @@ -595,7 +595,8 @@ EXTERN void nxgl_colorcopy(nxgl_mxpixel_t dest[CONFIG_NX_NPLANES], * In the general case, a line with width can be represented as a * parallelogram with a triangle at the top and bottom. Triangles and * parallelograms are both degenerate versions of a trapeziod. This - * function breaks. This function also detects other degenerate cases: + * function breaks a wide line into triangles and trapezoids. This + * function also detects other degenerate cases: * * 1. If y1 == y2 then the line is horizontal and is better represented * as a rectangle. @@ -603,9 +604,9 @@ EXTERN void nxgl_colorcopy(nxgl_mxpixel_t dest[CONFIG_NX_NPLANES], * as a rectangle. * 3. If the width of the line is 1, then there are no triangles at the * top and bottome (this may also be the case if the width is narrow - * and the line is near vertical) + * and the line is near vertical). * 4. If the line is oriented is certain angles, it may consist only of - * the upper and lower triangles with no trapezoid inbetween. In + * the upper and lower triangles with no trapezoid in between. In * this case, 3 trapezoids will be returned, but traps[1] will be * degenerate. * diff --git a/include/nuttx/nx/nxtk.h b/include/nuttx/nx/nxtk.h index 76416ecbb93..d0a4dcb867b 100644 --- a/include/nuttx/nx/nxtk.h +++ b/include/nuttx/nx/nxtk.h @@ -240,6 +240,30 @@ EXTERN int nxtk_filltrapwindow(NXTKWINDOW hfwnd, FAR const struct nxgl_trapezoid_s *trap, nxgl_mxpixel_t color[CONFIG_NX_NPLANES]); +/**************************************************************************** + * Name: nxtk_drawlinewindow + * + * Description: + * Fill the specified line in the window with the specified color. This + * is simply a wrapper that uses nxgl_splitline() to break the line into + * trapezoids and then calls nxtk_filltrapwindow() to render the line. + * + * Input Parameters: + * hfwnd - The window handle returned by nxtk_openwindow + * vector - Describes the line to be drawn + * width - The width of the line + * color - The color to use to fill the line + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +EXTERN int nxtk_drawlinewindow(NXTKWINDOW hfwnd, + FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]); + /**************************************************************************** * Name: nxtk_movewindow * @@ -365,6 +389,31 @@ EXTERN int nxtk_filltoolbar(NXTKWINDOW hfwnd, FAR const struct nxgl_rect_s *rect EXTERN int nxtk_filltraptoolbar(NXTKWINDOW hfwnd, FAR const struct nxgl_trapezoid_s *trap, nxgl_mxpixel_t color[CONFIG_NX_NPLANES]); +/**************************************************************************** + * Name: nxtk_drawlinetoolbar + * + * Description: + * Fill the specified line in the toolbar sub-window with the specified + * color. This is simply a wrapper that uses nxgl_splitline() to break the + * line into trapezoids and then calls nxtk_filltrapwindow() to render the + * line. + * + * Input Parameters: + * hfwnd - The window handle returned by nxtk_openwindow + * vector - Describes the line to be drawn + * width - The width of the line + * color - The color to use to fill the line + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +EXTERN int nxtk_drawlinetoolbar(NXTKWINDOW hfwnd, + FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]); + /**************************************************************************** * Name: nxtk_movetoolbar *