From 0363cbbc1a111f650c8e6ec52d9a0719737511e3 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 27 Nov 2008 23:31:37 +0000 Subject: More graphic support routines git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1321 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/graphics/Makefile | 18 ++-- nuttx/graphics/nxbe/nxbe_closewindow.c | 4 +- nuttx/graphics/nxbe/nxbe_move.c | 3 +- nuttx/graphics/nxbe/nxbe_raise.c | 2 +- nuttx/graphics/nxbe/nxbe_redraw.c | 3 +- nuttx/graphics/nxbe/nxbe_setposition.c | 6 +- nuttx/graphics/nxbe/nxbe_setsize.c | 6 +- nuttx/graphics/nxglib/Make.defs | 3 + nuttx/graphics/nxglib/nxglib_nonintersecting.c | 116 +++++++++++++++++++++++++ nuttx/graphics/nxglib/nxglib_nullrect.c | 82 +++++++++++++++++ nuttx/graphics/nxglib/nxglib_rectcopy.c | 86 ++++++++++++++++++ nuttx/graphics/nxglib/nxglib_rectintersect.c | 86 ++++++++++++++++++ nuttx/graphics/nxglib/nxglib_rectoffset.c | 89 +++++++++++++++++++ nuttx/graphics/nxglib/nxglib_rectoverlap.c | 90 +++++++++++++++++++ nuttx/graphics/nxglib/nxglib_vectoradd.c | 86 ++++++++++++++++++ nuttx/include/nuttx/nxglib.h | 83 ++++++++++++++++++ 16 files changed, 744 insertions(+), 19 deletions(-) create mode 100644 nuttx/graphics/nxglib/nxglib_nonintersecting.c create mode 100644 nuttx/graphics/nxglib/nxglib_nullrect.c create mode 100644 nuttx/graphics/nxglib/nxglib_rectcopy.c create mode 100644 nuttx/graphics/nxglib/nxglib_rectintersect.c create mode 100644 nuttx/graphics/nxglib/nxglib_rectoffset.c create mode 100644 nuttx/graphics/nxglib/nxglib_rectoverlap.c create mode 100644 nuttx/graphics/nxglib/nxglib_vectoradd.c diff --git a/nuttx/graphics/Makefile b/nuttx/graphics/Makefile index 34e0c6984..a30f037e5 100644 --- a/nuttx/graphics/Makefile +++ b/nuttx/graphics/Makefile @@ -42,17 +42,21 @@ include nxglib/Make.defs DEPPATH += --dep-path nxglib CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh "$(CC)" $(TOPDIR)/graphics/nxglib} -HAVENX := ${shell if [ -d nx ]; then echo "y"; else echo "n";fi} +include nxbe/Make.defs +DEPPATH += --dep-path nxbe +CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh "$(CC)" $(TOPDIR)/graphics/nxbe} + +HAVENX := ${shell if [ -d nxmu ]; then echo "y"; else echo "n";fi} ifeq ($(HAVENX),y) -include nx/Make.defs -DEPPATH += --dep-path nx -CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh "$(CC)" $(TOPDIR)/graphics/nx} +include nxmu/Make.defs +DEPPATH += --dep-path nxmu +CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh "$(CC)" $(TOPDIR)/graphics/nxmu} endif -ASRCS = $(NXGLIB_ASRCS) $(NX_ASRCS) +ASRCS = $(NXGLIB_ASRCS) $(NXBE_ASRCS) $(NX_ASRCS) AOBJS = $(ASRCS:.S=$(OBJEXT)) -CSRCS = $(NXGLIB_CSRCS) $(NX_CSRCS) +CSRCS = $(NXGLIB_CSRCS) $(NXBE_CSRCS) $(NX_CSRCS) COBJS = $(CSRCS:.c=$(OBJEXT)) SRCS = $(ASRCS) $(CSRCS) @@ -60,7 +64,7 @@ OBJS = $(AOBJS) $(COBJS) BIN = libgraphics$(LIBEXT) -VPATH = nxglib:nx +VPATH = nxglib:nxbe:nxmu all: mklibgraphics .PHONY : depend clean distclean mklibgraphics gensources gen1bppsources \ diff --git a/nuttx/graphics/nxbe/nxbe_closewindow.c b/nuttx/graphics/nxbe/nxbe_closewindow.c index 8987b898b..7d7a79eb7 100644 --- a/nuttx/graphics/nxbe/nxbe_closewindow.c +++ b/nuttx/graphics/nxbe/nxbe_closewindow.c @@ -44,8 +44,8 @@ #include #include -#include -#include "nxfe.h" +#include +#include "nxbe.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/nuttx/graphics/nxbe/nxbe_move.c b/nuttx/graphics/nxbe/nxbe_move.c index 1dbfe4fc8..872ed55eb 100644 --- a/nuttx/graphics/nxbe/nxbe_move.c +++ b/nuttx/graphics/nxbe/nxbe_move.c @@ -41,10 +41,9 @@ #include #include -#include #include "nxbe.h" -#include "nxfe.h" +//#include "nxfe.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/nuttx/graphics/nxbe/nxbe_raise.c b/nuttx/graphics/nxbe/nxbe_raise.c index 109fdaf1d..70353ab22 100644 --- a/nuttx/graphics/nxbe/nxbe_raise.c +++ b/nuttx/graphics/nxbe/nxbe_raise.c @@ -43,7 +43,7 @@ #include #include "nxbe.h" -#include "nxfe.h" +//#include "nxfe.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/nuttx/graphics/nxbe/nxbe_redraw.c b/nuttx/graphics/nxbe/nxbe_redraw.c index ed78228a0..576b969ee 100644 --- a/nuttx/graphics/nxbe/nxbe_redraw.c +++ b/nuttx/graphics/nxbe/nxbe_redraw.c @@ -43,8 +43,9 @@ #include #include +#include #include "nxbe.h" -#include "nxfe.h" +//#include "nxfe.h" /**************************************************************************** * Pre-Processor Definitions diff --git a/nuttx/graphics/nxbe/nxbe_setposition.c b/nuttx/graphics/nxbe/nxbe_setposition.c index 13e100eda..87083a8c7 100644 --- a/nuttx/graphics/nxbe/nxbe_setposition.c +++ b/nuttx/graphics/nxbe/nxbe_setposition.c @@ -40,10 +40,10 @@ #include #include -#include +#include #include "nxbe.h" -#include "nxfe.h" +//#include "nxfe.h" /**************************************************************************** * Pre-Processor Definitions @@ -119,6 +119,6 @@ void nxbe_setposition(FAR struct nxbe_window_s *wnd, /* Report the new size/position */ #ifdef CONFIG_NX_MULTIUSER - nxmu_getposition(wnd); + nxmu_reportposition(wnd); #endif } diff --git a/nuttx/graphics/nxbe/nxbe_setsize.c b/nuttx/graphics/nxbe/nxbe_setsize.c index 322a814a4..b75aabfe6 100644 --- a/nuttx/graphics/nxbe/nxbe_setsize.c +++ b/nuttx/graphics/nxbe/nxbe_setsize.c @@ -40,8 +40,8 @@ #include #include -#include -#include "nxfe.h" +#include +#include "nxbe.h" /**************************************************************************** * Pre-Processor Definitions @@ -108,6 +108,6 @@ void nxbe_setsize(FAR struct nxbe_window_s *wnd, /* Report the new size/position */ #ifdef CONFIG_NX_MULTIUSER - nxmu_getposition(wnd); + nxmu_reportposition(wnd); #endif } diff --git a/nuttx/graphics/nxglib/Make.defs b/nuttx/graphics/nxglib/Make.defs index 4010fc601..ab0427e8b 100644 --- a/nuttx/graphics/nxglib/Make.defs +++ b/nuttx/graphics/nxglib/Make.defs @@ -51,6 +51,9 @@ RMOVE2_CSRCS = nxglib_moverectangle_8bpp.c nxglib_moverectangle_16bpp.c \ # nxglib_copyrectangle_4bpp.c RCOPY2_CSRCS = nxglib_copyrectangle_8bpp.c nxglib_copyrectangle_16bpp.c \ nxglib_copyrectangle_24bpp.c nxglib_copyrectangle_32bpp.c +RECT_CRCS = nxglib_rectcopy.c nxglib_rectoffset.c nxglib_vectoradd.c \ + nxglib_rectintersect.c nxglib_nonintersecting.c \ + nxglib_rectoverlap.c nxglib_nullrect.c NXGLIB_CSRCS = nxglib_rgb2yuv.c nxglib_yuv2rgb.c \ $(RFILL1_CSRCS) $(RFILL2_CSRCS) $(TFILL1_CSRCS) $(TFILL2_CSRCS) \ $(RMOVE1_CSRCS) $(RMOVE2_CSRCS) $(RCOPY1_CSRCS) $(RCOPY2_CSRCS) diff --git a/nuttx/graphics/nxglib/nxglib_nonintersecting.c b/nuttx/graphics/nxglib/nxglib_nonintersecting.c new file mode 100644 index 000000000..b498e6294 --- /dev/null +++ b/nuttx/graphics/nxglib/nxglib_nonintersecting.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * graphics/nxglib/nxsglib_rectnonintersecting.c + * + * Copyright (C) 2008 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 + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxgl_nonintersecting + * + * Description: + * Return the regions of rectangle rect 1 that do not intersect with + * rect2. This may be up to founr rectangles some of which may be + * degenerate (and can be picked off with nxgl_nullrect) + * + ****************************************************************************/ + +void nxgl_nonintersecting(FAR struct nxgl_rect_s result[4], + FAR const struct nxgl_rect_s *rect1, + FAR const struct nxgl_rect_s *rect2) +{ + struct nxgl_rect_s intersection; + + /* Get the intersection of the two rectangles */ + + nxgl_rectintersect(&intersection, rect1, rect2); + + /* Then return the four rectangles representing the regions NON included + * in the intersection. Some of these rectangles may be invalid (zero + * area), but those can be picked off using nxgl_nullrect() + */ + + result[NX_TOP_NDX].pt1.x = rect1->pt1.x; + result[NX_TOP_NDX].pt1.y = rect1->pt1.y; + result[NX_TOP_NDX].pt2.x = rect1->pt2.x; + result[NX_TOP_NDX].pt2.y = intersection.pt1.y; + + result[NX_BOTTOM_NDX].pt1.x = rect1->pt1.x; + result[NX_BOTTOM_NDX].pt1.y = intersection.pt2.y; + result[NX_BOTTOM_NDX].pt2.x = rect1->pt2.x; + result[NX_BOTTOM_NDX].pt2.y = rect1->pt2.y; + + result[NX_LEFT_NDX].pt1.x = rect1->pt1.x; + result[NX_LEFT_NDX].pt1.y = intersection.pt1.y; + result[NX_LEFT_NDX].pt2.x = intersection.pt1.x; + result[NX_LEFT_NDX].pt2.y = intersection.pt2.y; + + result[NX_RIGHT_NDX].pt1.x = intersection.pt2.x; + result[NX_RIGHT_NDX].pt1.y = intersection.pt1.y; + result[NX_RIGHT_NDX].pt2.x = rect1->pt2.x; + result[NX_RIGHT_NDX].pt2.y = intersection.pt2.y; +} + + diff --git a/nuttx/graphics/nxglib/nxglib_nullrect.c b/nuttx/graphics/nxglib/nxglib_nullrect.c new file mode 100644 index 000000000..4895a2f6c --- /dev/null +++ b/nuttx/graphics/nxglib/nxglib_nullrect.c @@ -0,0 +1,82 @@ +/**************************************************************************** + * graphics/nxglib/nxsglib_nullrect.c + * + * Copyright (C) 2008 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 + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxgl_nullrect + * + * Description: + * Return TRUE if the area of the retangle is <= 0. + * + ****************************************************************************/ + +boolean nxgl_nullrect(FAR const struct nxgl_rect_s *rect) +{ + return (rect->pt1.x >= rect->pt2.x || rect->pt1.y >= rect->pt2.y); +} + diff --git a/nuttx/graphics/nxglib/nxglib_rectcopy.c b/nuttx/graphics/nxglib/nxglib_rectcopy.c new file mode 100644 index 000000000..bf266f263 --- /dev/null +++ b/nuttx/graphics/nxglib/nxglib_rectcopy.c @@ -0,0 +1,86 @@ +/**************************************************************************** + * graphics/nxglib/nxsglib_rectcopy.c + * + * Copyright (C) 2008 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 + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxgl_rectcopy + * + * Description: + * This is essentially memcpy for rectangles. We don't do structure + * assignements because some compilers are not good at that. + * + ****************************************************************************/ + +void nxgl_rectcopy(FAR struct nxgl_rect_s *dest, + FAR const struct nxgl_rect_s *src) +{ + dest->pt1.x = src->pt1.x; + dest->pt1.y = src->pt1.y; + dest->pt2.x = src->pt2.x; + dest->pt2.y = src->pt2.y; +} diff --git a/nuttx/graphics/nxglib/nxglib_rectintersect.c b/nuttx/graphics/nxglib/nxglib_rectintersect.c new file mode 100644 index 000000000..b4f1bd611 --- /dev/null +++ b/nuttx/graphics/nxglib/nxglib_rectintersect.c @@ -0,0 +1,86 @@ +/**************************************************************************** + * graphics/nxglib/nxsglib_rectintersect.c + * + * Copyright (C) 2008 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 + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxgl_rectintersect + * + * Description: + * Return the rectangle representing the intersection of the two rectangles. + * + ****************************************************************************/ + +void nxgl_rectintersect(FAR struct nxgl_rect_s *dest, + FAR const struct nxgl_rect_s *src1, + FAR const struct nxgl_rect_s *src2) +{ + dest->pt1.x = ngl_max(src1->pt1.x, src2->pt1.x); + dest->pt1.y = ngl_max(src1->pt1.y, src2->pt1.y); + dest->pt2.x = ngl_min(src1->pt2.x, src2->pt2.x); + dest->pt2.y = ngl_min(src1->pt2.y, src2->pt2.y); +} diff --git a/nuttx/graphics/nxglib/nxglib_rectoffset.c b/nuttx/graphics/nxglib/nxglib_rectoffset.c new file mode 100644 index 000000000..622def5dc --- /dev/null +++ b/nuttx/graphics/nxglib/nxglib_rectoffset.c @@ -0,0 +1,89 @@ +/**************************************************************************** + * graphics/nxglib/nxsglib_rectoffset.c + * + * Copyright (C) 2008 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 + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxgl_rectoffset + * + * Description: + * Offset the rectangle position by the specified dx, dy values. + * + ****************************************************************************/ + +void nxgl_rectoffset(FAR struct nxgl_rect_s *dest, + FAR const struct nxgl_rect_s *src, + nxgl_coord_t dx, nxgl_coord_t dy) +{ + dest->pt1.x = src->pt1.x + dx; + dest->pt1.y = src->pt1.y + dy; + dest->pt2.x = src->pt2.x + dx; + dest->pt2.y = src->pt2.y + dy; +} + + + diff --git a/nuttx/graphics/nxglib/nxglib_rectoverlap.c b/nuttx/graphics/nxglib/nxglib_rectoverlap.c new file mode 100644 index 000000000..ec33d8969 --- /dev/null +++ b/nuttx/graphics/nxglib/nxglib_rectoverlap.c @@ -0,0 +1,90 @@ +/**************************************************************************** + * graphics/nxglib/nxsglib_nulloverlap.c + * + * Copyright (C) 2008 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 + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxgl_rectoverlap + * + * Description: + * Return TRUE if the two rectangles overlap + * + ****************************************************************************/ + +boolean nxgl_rectoverlap(FAR struct nxgl_rect_s *rect1, + FAR struct nxgl_rect_s *rect2) +{ + /* The neither is wholly above, below, right, or left of the other, then + * the two rectangles overlap in some fashion. + */ + + return (rect1->pt1.x < rect2->pt2.x) && /* FALSE: rect1 is wholly to the right */ + (rect2->pt1.x < rect1->pt2.x) && /* FALSE: rect2 is wholly to the right */ + (rect1->pt1.y < rect2->pt2.y) && /* FALSE: rect1 is wholly below rect2 */ + (rect2->pt1.y < rect1->pt2.y); /* FALSE: rect2 is wholly below rect1 */ +} + diff --git a/nuttx/graphics/nxglib/nxglib_vectoradd.c b/nuttx/graphics/nxglib/nxglib_vectoradd.c new file mode 100644 index 000000000..fe854ece1 --- /dev/null +++ b/nuttx/graphics/nxglib/nxglib_vectoradd.c @@ -0,0 +1,86 @@ +/**************************************************************************** + * graphics/nxglib/nxsglib_vectoradd.c + * + * Copyright (C) 2008 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 + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxgl_vectoradd + * + * Description: + * Add two 2x1 vectors and save the result to a third. + * + ****************************************************************************/ + +void nxgl_vectoradd(FAR struct nxgl_point_s *dest, + FAR const struct nxgl_point_s *v1, + FAR const struct nxgl_point_s *v2) +{ + dest->x = v1->x + v2->x; + dest->y = v1->y + v2->y; +} + + diff --git a/nuttx/include/nuttx/nxglib.h b/nuttx/include/nuttx/nxglib.h index cc065ab6a..28df97ab2 100644 --- a/nuttx/include/nuttx/nxglib.h +++ b/nuttx/include/nuttx/nxglib.h @@ -306,6 +306,89 @@ EXTERN void nxgl_copyrectangle_32bpp(FAR struct fb_planeinfo_s *pinfo, FAR const struct nxgl_point_s *origin, unsigned int srcstride); +/**************************************************************************** + * Name: nxgl_rectcopy + * + * Description: + * This is essentially memcpy for rectangles. We don't do structure + * assignements because some compilers are not good at that. + * + ****************************************************************************/ + +EXTERN void nxgl_rectcopy(FAR struct nxgl_rect_s *dest, + FAR const struct nxgl_rect_s *src); + +/**************************************************************************** + * Name: nxgl_rectoffset + * + * Description: + * Offset the rectangle position by the specified dx, dy values. + * + ****************************************************************************/ + +EXTERN void nxgl_rectoffset(FAR struct nxgl_rect_s *dest, + FAR const struct nxgl_rect_s *src, + nxgl_coord_t dx, nxgl_coord_t dy); + +/**************************************************************************** + * Name: nxgl_vectoradd + * + * Description: + * Add two 2x1 vectors and save the result to a third. + * + ****************************************************************************/ + +EXTERN void nxgl_vectoradd(FAR struct nxgl_point_s *dest, + FAR const struct nxgl_point_s *v1, + FAR const struct nxgl_point_s *v2); + +/**************************************************************************** + * Name: nxgl_rectintersect + * + * Description: + * Return the rectangle representing the intersection of the two rectangles. + * + ****************************************************************************/ + +EXTERN void nxgl_rectintersect(FAR struct nxgl_rect_s *dest, + FAR const struct nxgl_rect_s *src1, + FAR const struct nxgl_rect_s *src2); + +/**************************************************************************** + * Name: nxgl_nonintersecting + * + * Description: + * Return the regions of rectangle rect 1 that do not intersect with + * rect2. This may be up to founr rectangles some of which may be + * degenerate (and can be picked off with nxgl_nullrect) + * + ****************************************************************************/ + +EXTERN void nxgl_nonintersecting(FAR struct nxgl_rect_s result[4], + FAR const struct nxgl_rect_s *rect1, + FAR const struct nxgl_rect_s *rect2); + +/**************************************************************************** + * Name: nxgl_rectoverlap + * + * Description: + * Return TRUE if the two rectangles overlap + * + ****************************************************************************/ + +EXTERN boolean nxgl_rectoverlap(FAR struct nxgl_rect_s *rect1, + FAR struct nxgl_rect_s *rect2); + +/**************************************************************************** + * Name: nxgl_nullrect + * + * Description: + * Return TRUE if the area of the retangle is <= 0. + * + ****************************************************************************/ + +EXTERN boolean nxgl_nullrect(FAR const struct nxgl_rect_s *rect); + #undef EXTERN #if defined(__cplusplus) } -- cgit v1.2.3