From 091ba6a8c69c9dcbbf4441babf376dd39aef3468 Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 3 Dec 2008 13:27:14 +0000 Subject: Fix error in re-draw clipping git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1405 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/graphics/nxtk/Make.defs | 2 +- nuttx/graphics/nxtk/nxtk_containerclip.c | 123 +++++++++++++++++++++++++++++++ nuttx/graphics/nxtk/nxtk_events.c | 23 +++--- nuttx/graphics/nxtk/nxtk_internal.h | 29 ++++++++ nuttx/graphics/nxtk/nxtk_subwindowclip.c | 9 ++- 5 files changed, 170 insertions(+), 16 deletions(-) create mode 100644 nuttx/graphics/nxtk/nxtk_containerclip.c (limited to 'nuttx') diff --git a/nuttx/graphics/nxtk/Make.defs b/nuttx/graphics/nxtk/Make.defs index 52b69b49c..67c9b63ae 100644 --- a/nuttx/graphics/nxtk/Make.defs +++ b/nuttx/graphics/nxtk/Make.defs @@ -41,4 +41,4 @@ NXTKWIN_CSRCS = nxtk_openwindow.c nxtk_closewindow.c nxtk_getposition.c \ NXTKTB_CSRCS = nxtk_opentoolbar.c nxtk_closetoolbar.c nxtk_filltoolbar.c \ nxtk_filltraptoolbar.c nxtk_movetoolbar.c nxtk_bitmaptoolbar.c NXTK_CSRCS = $(NXTKWIN_CSRCS) $(NXTKTB_CSRCS) nxtk_subwindowclip.c \ - nxtk_subwindowmove.c nxtk_drawframe.c + nxtk_containerclip.c nxtk_subwindowmove.c nxtk_drawframe.c diff --git a/nuttx/graphics/nxtk/nxtk_containerclip.c b/nuttx/graphics/nxtk/nxtk_containerclip.c new file mode 100644 index 000000000..0538cc31e --- /dev/null +++ b/nuttx/graphics/nxtk/nxtk_containerclip.c @@ -0,0 +1,123 @@ +/**************************************************************************** + * graphics/nxtk/nxtk_containerclip.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 +#include + +#include +#include + +#include "nxfe.h" +#include "nxtk_internal.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxtk_containerclip + * + * Description: + * We are given a 'src' rectangle in containing window, relative coordinates + * (i.e., (0,0) is the top left corner of the outer, containing window). + * This function will (1) clip that src rectangle so that it lies within + * the sub-window bounds, and then (2) move the rectangle to that it is + * relative to the sub-window (i.e., (0,0) is the top left corner of the + * sub-window). + * + * Input parameters: + * fwnd - The framed window to be used + * dest - The locaton to put the result + * src - The src rectangle in relative container-window coordinates + * bounds - The subwindow bounds in absolute screen coordinates. + * + * Returned value: + * None + * + ****************************************************************************/ + +void nxtk_containerclip(FAR struct nxtk_framedwindow_s *fwnd, + FAR struct nxgl_rect_s *dest, + FAR const struct nxgl_rect_s *src, + FAR const struct nxgl_rect_s *bounds) +{ + struct nxgl_rect_s relbounds; + + /* The 'src' rectangle is relative to the containing window. Convert + * the sub-window to the same origin. + */ + + nxgl_rectoffset(&relbounds, bounds, -fwnd->wnd.bounds.pt1.x, + -fwnd->wnd.bounds.pt1.y); + + /* The interection then leaves the portion of the containing window that + * needs to be updated window that needs to be updated. + */ + + nxgl_rectintersect(dest, src, &relbounds); + + /* Offset this so that is relative to client subwindow origin */ + + nxgl_rectoffset(dest, dest, fwnd->wnd.bounds.pt1.x - bounds->pt1.x, + fwnd->wnd.bounds.pt1.y - bounds->pt1.y); +} diff --git a/nuttx/graphics/nxtk/nxtk_events.c b/nuttx/graphics/nxtk/nxtk_events.c index 647c86048..1832eda75 100644 --- a/nuttx/graphics/nxtk/nxtk_events.c +++ b/nuttx/graphics/nxtk/nxtk_events.c @@ -108,26 +108,26 @@ static void nxtk_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, { FAR struct nxtk_framedwindow_s *fwnd = (FAR struct nxtk_framedwindow_s *)hwnd; struct nxgl_rect_s intersection; - struct nxgl_rect_s relbounds; DEBUGASSERT(hwnd && rect && fwnd->fwcb); gvdbg("nxtk_redraw: hwnd=%p rect={(%d,%d),(%d,%d)} more=%d\n", hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y, more); - /* If any part of the rectangle overlaps the client window region, then + /* The incoming rectangle (rect) is relative to the containing window + * (i.e., (0,0) is the top left corner of the outer, containing window). + * If any part of the rectangle overlaps the client sub-window region, then * forward the redraw callback. */ if (fwnd->fwcb->redraw) { - /* Convert the client window into a window relative rectangle, then - * get the intersection with the incoming rectangle. That leaves the - * portion of the client window that needs to be updated. + /* Clip the redraw rectangle so that it lies within the client sub-window + * bounds and move the rectangle to that it is relative to the client + * sub-window (i.e., (0,0) is the top left corner of the client sub-window). */ - nxgl_rectoffset(&relbounds, &fwnd->fwrect, -fwnd->fwrect.pt1.x, -fwnd->fwrect.pt1.y); - nxgl_rectintersect(&intersection, rect, &relbounds); + nxtk_containerclip(fwnd, &intersection, rect, &fwnd->fwrect); gvdbg("nxtk_redraw: fwrect intersction={(%d,%d),(%d,%d)}\n", intersection.pt1.x, intersection.pt1.y, @@ -145,13 +145,12 @@ static void nxtk_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, if (fwnd->tbcb && fwnd->tbcb->redraw) { - /* Convert the toolbar window into a window relative rectangle, then - * get the intersection with the incoming rectangle. That leaves the - * portion of the toolbar window that needs to be updated. + /* Clip the redraw rectangle so that it lies within the toolbar sub-window + * bounds and move the rectangle to that it is relative to the toolbar + * sub-window (i.e., (0,0) is the top left corner of the client sub-window). */ - nxgl_rectoffset(&relbounds, &fwnd->tbrect, -fwnd->tbrect.pt1.x, -fwnd->tbrect.pt1.y); - nxgl_rectintersect(&intersection, rect, &relbounds); + nxtk_containerclip(fwnd, &intersection, rect, &fwnd->tbrect); gvdbg("nxtk_redraw: tbrect intersction={(%d,%d),(%d,%d)}\n", intersection.pt1.x, intersection.pt1.y, diff --git a/nuttx/graphics/nxtk/nxtk_internal.h b/nuttx/graphics/nxtk/nxtk_internal.h index b2d20464c..e2403314d 100644 --- a/nuttx/graphics/nxtk/nxtk_internal.h +++ b/nuttx/graphics/nxtk/nxtk_internal.h @@ -150,6 +150,33 @@ EXTERN void nxtk_subwindowclip(FAR struct nxtk_framedwindow_s *fwnd, FAR const struct nxgl_rect_s *src, FAR const struct nxgl_rect_s *bounds); +/**************************************************************************** + * Name: nxtk_containerclip + * + * Description: + * We are given a 'src' rectangle in containing window, relative coordinates + * (i.e., (0,0) is the top left corner of the outer, containing window). + * This function will (1) clip that src rectangle so that it lies within + * the sub-window bounds, and then (2) move the rectangle to that it is + * relative to the sub-window (i.e., (0,0) is the top left corner of the + * sub-window). + * + * Input parameters: + * fwnd - The framed window to be used + * dest - The locaton to put the result + * src - The src rectangle in relative container-window coordinates + * bounds - The subwindow bounds in absolute screen coordinates. + * + * Returned value: + * None + * + ****************************************************************************/ + +EXTERN void nxtk_containerclip(FAR struct nxtk_framedwindow_s *fwnd, + FAR struct nxgl_rect_s *dest, + FAR const struct nxgl_rect_s *src, + FAR const struct nxgl_rect_s *bounds); + /**************************************************************************** * Name: nxtk_subwindowmove * @@ -178,6 +205,7 @@ EXTERN void nxtk_subwindowmove(FAR struct nxtk_framedwindow_s *fwnd, FAR const struct nxgl_rect_s *srcrect, FAR const struct nxgl_point_s *srcoffset, FAR const struct nxgl_rect_s *bounds); + /**************************************************************************** * Name: nxtk_drawframe * @@ -197,6 +225,7 @@ EXTERN void nxtk_subwindowmove(FAR struct nxtk_framedwindow_s *fwnd, EXTERN int nxtk_drawframe(FAR struct nxtk_framedwindow_s *fwnd, FAR const struct nxgl_rect_s *bounds); + #undef EXTERN #if defined(__cplusplus) } diff --git a/nuttx/graphics/nxtk/nxtk_subwindowclip.c b/nuttx/graphics/nxtk/nxtk_subwindowclip.c index 73dc1828b..e5495683c 100644 --- a/nuttx/graphics/nxtk/nxtk_subwindowclip.c +++ b/nuttx/graphics/nxtk/nxtk_subwindowclip.c @@ -78,9 +78,12 @@ * Name: nxtk_subwindowclip * * Description: - * Clip the src rectangle so that it lies within the sub-window bounds - * then move the rectangle to that it is relative to the containing - * window. + * We are given a 'src' rectangle in sub-window, relative coordinates + * (i.e., (0,0) is the top left corner of the sub-window). This function + * will (1) clip that src rectangle so that it lies within the sub-window + * bounds, and then (2) move the rectangle to that it is relative to the + * containing window (i.e., (0,0) is the top left corner of the containing + * window). * * Input parameters: * fwnd - The framed window to be used -- cgit v1.2.3