From 1fe558baf34852d3e57f7e91d7e4e3fb051b5402 Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 3 Dec 2008 00:28:53 +0000 Subject: Add frame drawing logic git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1399 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/graphics/nxtk/Make.defs | 3 +- nuttx/graphics/nxtk/nxtk_drawframe.c | 217 ++++++++++++++++++++++++++++++++++ nuttx/graphics/nxtk/nxtk_events.c | 25 +++- nuttx/graphics/nxtk/nxtk_internal.h | 26 +++- nuttx/graphics/nxtk/nxtk_openwindow.c | 16 +++ 5 files changed, 281 insertions(+), 6 deletions(-) create mode 100644 nuttx/graphics/nxtk/nxtk_drawframe.c (limited to 'nuttx/graphics') diff --git a/nuttx/graphics/nxtk/Make.defs b/nuttx/graphics/nxtk/Make.defs index b63b11fda..52b69b49c 100644 --- a/nuttx/graphics/nxtk/Make.defs +++ b/nuttx/graphics/nxtk/Make.defs @@ -40,4 +40,5 @@ NXTKWIN_CSRCS = nxtk_openwindow.c nxtk_closewindow.c nxtk_getposition.c \ nxtk_bitmapwindow.c nxtk_events.c nxtk_setsubwindows.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 \ No newline at end of file +NXTK_CSRCS = $(NXTKWIN_CSRCS) $(NXTKTB_CSRCS) nxtk_subwindowclip.c \ + nxtk_subwindowmove.c nxtk_drawframe.c diff --git a/nuttx/graphics/nxtk/nxtk_drawframe.c b/nuttx/graphics/nxtk/nxtk_drawframe.c new file mode 100644 index 000000000..40746621d --- /dev/null +++ b/nuttx/graphics/nxtk/nxtk_drawframe.c @@ -0,0 +1,217 @@ +/**************************************************************************** + * graphics/nxtk/nxtk_drawframe.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 + +#include "nxfe.h" +#include "nxtk_internal.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxtk_drawframeside + ****************************************************************************/ + +static void nxtk_drawframeside(FAR struct nxtk_framedwindow_s *fwnd, + FAR const struct nxgl_rect_s *side, + FAR const struct nxgl_rect_s *bounds, + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) +{ + struct nxgl_rect_s intersection; + nxgl_rectintersect(&intersection, side, bounds); + if (!nxgl_nullrect(&intersection)) + { + nx_fill((NXWINDOW)fwnd, &intersection, color); + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxtk_drawframe + * + * Description: + * Redraw the window frame. + * + * Input parameters: + * fwnd - the framed window whose frame needs to be re-drawn. This must + * have been previously created by nxtk_openwindow(). + * bounds - Only draw the ports of the frame within this bounding box. + * (window relative coordinates). + * + * Returned value: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nxtk_drawframe(FAR struct nxtk_framedwindow_s *fwnd, + FAR const struct nxgl_rect_s *bounds) +{ + struct nxgl_rect_s frame; + struct nxgl_size_s wndsize; + struct nxgl_size_s tbsize; + + /* Get the size of the rectangle */ + + nxgl_rectsize(&wndsize, &fwnd->wnd.bounds); + nxgl_rectsize(&tbsize, &fwnd->tbrect); + + /* Draw the top. Thickness: CONFIG_NXTK_BORDERWIDTH-1, Color: + * CONFIG_NXTK_BORDERCOLOR1 + */ + + frame.pt1.x = 0; + frame.pt2.x = wndsize.w - 1; + + frame.pt1.y = 0; +#if CONFIG_NXTK_BORDERWIDTH > 1 + frame.pt2.y = CONFIG_NXTK_BORDERWIDTH - 2; +#else + frame.pt2.y = CONFIG_NXTK_BORDERWIDTH - 1; +#endif + nxtk_drawframeside(fwnd, &frame, bounds, g_bordercolor1); + + /* Draw a single line under the toolbar, color CONFIG_NXTK_BORDERCOLOR2 */ + +#if CONFIG_NXTK_BORDERWIDTH > 1 + frame.pt1.y += tbsize.h + CONFIG_NXTK_BORDERWIDTH - 1; + frame.pt2.y = frame.pt1.y; + nxtk_drawframeside(fwnd, &frame, bounds, g_bordercolor2); +#endif + + /* Draw the bottom. First, thickness: CONFIG_NXTK_BORDERWIDTH-1, + * Color: CONFIG_NXTK_BORDERCOLOR1 + */ + + frame.pt1.y = wndsize.h - CONFIG_NXTK_BORDERWIDTH; +#if CONFIG_NXTK_BORDERWIDTH > 1 + frame.pt2.y = wndsize.h - 2; +#else + frame.pt2.y = frame.pt1.y; +#endif + nxtk_drawframeside(fwnd, &frame, bounds, g_bordercolor1); + + /* Then a single line at the very bottom, Color: CONFIG_NXTK_BORDERCOLOR2 */ + +#if CONFIG_NXTK_BORDERWIDTH > 1 + frame.pt1.y = wndsize.h - 1; + frame.pt2.y = frame.pt1.y; + nxtk_drawframeside(fwnd, &frame, bounds, g_bordercolor2); +#endif + + /* Draw the outer left side. Thickness: CONFIG_NXTK_BORDERWIDTH-1, + * Color: CONFIG_NXTK_BORDERCOLOR1 + */ + + frame.pt1.y = 0; + frame.pt2.y = wndsize.h - 1; + + frame.pt1.x = 0; +#if CONFIG_NXTK_BORDERWIDTH > 1 + frame.pt2.x = CONFIG_NXTK_BORDERWIDTH - 2; +#else + frame.pt2.x = frame.pt1.x; +#endif + nxtk_drawframeside(fwnd, &frame, bounds, g_bordercolor1); + + /* Draw the outer right side. Thickness: 1, Color: CONFIG_NXTK_BORDERCOLOR2 */ + +#if CONFIG_NXTK_BORDERWIDTH > 1 + frame.pt1.x = wndsize.w - 1; + frame.pt2.x = frame.pt1.x; + nxtk_drawframeside(fwnd, &frame, bounds, g_bordercolor2); +#endif + + /* Draw the inner right side, Thickness: 1, Color: CONFIG_NXTK_BORDERCOLOR2 */ + +#if CONFIG_NXTK_BORDERWIDTH > 1 + frame.pt1.y = CONFIG_NXTK_BORDERWIDTH - 1 + tbsize.h; +#else + frame.pt1.y = CONFIG_NXTK_BORDERWIDTH + tbsize.h; +#endif + frame.pt2.y = wndsize.h - CONFIG_NXTK_BORDERWIDTH - 1; +#if CONFIG_NXTK_BORDERWIDTH > 1 + frame.pt1.x = CONFIG_NXTK_BORDERWIDTH - 1; + frame.pt2.x = frame.pt1.x; + nxtk_drawframeside(fwnd, &frame, bounds, g_bordercolor2); +#endif + + /* Draw the inner left side, Thickness: CONFIG_NXTK_BORDERWIDTH-1, + * Color: CONFIG_NXTK_BORDERCOLOR1 + */ + +#if CONFIG_NXTK_BORDERWIDTH > 1 + frame.pt1.x = wndsize.w - CONFIG_NXTK_BORDERWIDTH; + frame.pt2.x = wndsize.w - 2; +#else + frame.pt1.x = wndsize.w - 1; + frame.pt2.x = frame.pt1.x; +#endif + nxtk_drawframeside(fwnd, &frame, bounds, g_bordercolor1); + return OK; +} diff --git a/nuttx/graphics/nxtk/nxtk_events.c b/nuttx/graphics/nxtk/nxtk_events.c index f8ec80ea0..647c86048 100644 --- a/nuttx/graphics/nxtk/nxtk_events.c +++ b/nuttx/graphics/nxtk/nxtk_events.c @@ -108,6 +108,7 @@ 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); @@ -120,7 +121,14 @@ static void nxtk_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, if (fwnd->fwcb->redraw) { - nxgl_rectintersect(&intersection, &fwnd->fwrect, rect); + /* 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. + */ + + nxgl_rectoffset(&relbounds, &fwnd->fwrect, -fwnd->fwrect.pt1.x, -fwnd->fwrect.pt1.y); + nxgl_rectintersect(&intersection, rect, &relbounds); + gvdbg("nxtk_redraw: fwrect intersction={(%d,%d),(%d,%d)}\n", intersection.pt1.x, intersection.pt1.y, intersection.pt2.x, intersection.pt2.y); @@ -137,7 +145,14 @@ static void nxtk_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, if (fwnd->tbcb && fwnd->tbcb->redraw) { - nxgl_rectintersect(&intersection, &fwnd->tbrect, rect); + /* 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. + */ + + nxgl_rectoffset(&relbounds, &fwnd->tbrect, -fwnd->tbrect.pt1.x, -fwnd->tbrect.pt1.y); + nxgl_rectintersect(&intersection, rect, &relbounds); + gvdbg("nxtk_redraw: tbrect intersction={(%d,%d),(%d,%d)}\n", intersection.pt1.x, intersection.pt1.y, intersection.pt2.x, intersection.pt2.y); @@ -148,7 +163,9 @@ static void nxtk_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, } } -#warning "Need to redraw frame as well" + /* Then draw the frame */ + + nxtk_drawframe(fwnd, rect); } /**************************************************************************** @@ -164,7 +181,7 @@ static void nxtk_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, struct nxgl_size_s subwindowsize; gvdbg("nxtk_position: hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n", - hwnd, size->w, size->w, pos->x, pos->y, + hwnd, size->w, size->h, pos->x, pos->y, bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y); /* Recalculate the dimensions of the toolbar and client windows */ diff --git a/nuttx/graphics/nxtk/nxtk_internal.h b/nuttx/graphics/nxtk/nxtk_internal.h index 2f9878a99..b2d20464c 100644 --- a/nuttx/graphics/nxtk/nxtk_internal.h +++ b/nuttx/graphics/nxtk/nxtk_internal.h @@ -54,7 +54,7 @@ /* Configuration ************************************************************/ #ifndef CONFIG_NXTK_BORDERWIDTH -# define CONFIG_NXTK_BORDERWIDTH 2 +# define CONFIG_NXTK_BORDERWIDTH 4 #endif #ifndef CONFIG_NXTK_BORDERCOLOR1 @@ -105,6 +105,11 @@ extern "C" { extern FAR const struct nx_callback_s g_nxtkcb; +/* Frame border colors */ + +extern nxgl_mxpixel_t g_bordercolor1[CONFIG_NX_NPLANES]; +extern nxgl_mxpixel_t g_bordercolor2[CONFIG_NX_NPLANES]; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -173,6 +178,25 @@ 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 + * + * Description: + * Redraw the window frame. + * + * Input parameters: + * fwnd - the framed window whose frame needs to be re-drawn. This must + * have been previously created by nxtk_openwindow(). + * bounds - Only draw the ports of the frame within this bounding box. + * (window relative coordinates). + * + * Returned value: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +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_openwindow.c b/nuttx/graphics/nxtk/nxtk_openwindow.c index 121aa745b..89b6faddc 100644 --- a/nuttx/graphics/nxtk/nxtk_openwindow.c +++ b/nuttx/graphics/nxtk/nxtk_openwindow.c @@ -65,6 +65,22 @@ * Public Data ****************************************************************************/ +nxgl_mxpixel_t g_bordercolor1[CONFIG_NX_NPLANES] = +{ + CONFIG_NXTK_BORDERCOLOR1 +#if CONFIG_NX_NPLANES > 1 +# error "Multiple corder colors not defined" +#endif +}; + +nxgl_mxpixel_t g_bordercolor2[CONFIG_NX_NPLANES] = +{ + CONFIG_NXTK_BORDERCOLOR2 +#if CONFIG_NX_NPLANES > 1 +# error "Multiple border colors not defined" +#endif +}; + /**************************************************************************** * Private Functions ****************************************************************************/ -- cgit v1.2.3