9
0
Fork 0

Don't keep sizes in rectangles

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@1392 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2008-12-02 20:02:59 +00:00
parent 43425d4c44
commit 3cdd621fd0
21 changed files with 169 additions and 72 deletions

View File

@ -293,7 +293,7 @@ int user_start(int argc, char *argv[])
{
NXWINDOW hwnd1;
NXWINDOW hwnd2;
struct nxgl_rect_s rect;
struct nxgl_size_s size;
struct nxgl_point_s pt;
nxgl_mxpixel_t color;
int ret;
@ -344,13 +344,11 @@ int user_start(int argc, char *argv[])
/* Set the size of the window 1 */
rect.pt1.x = 0;
rect.pt1.y = 0;
rect.pt2.x = g_xres/2;
rect.pt2.y = g_yres/2;
size.w = g_xres / 2;
size.h = g_yres / 2;
message("user_start: Set hwnd1 size to (%d,%d)\n", rect.pt2.x, rect.pt2.y);
ret = nx_setsize(hwnd1, &rect);
message("user_start: Set hwnd1 size to (%d,%d)\n", size.w, size.h);
ret = nx_setsize(hwnd1, &size);
if (ret < 0)
{
message("user_start: nx_setsize failed: %d\n", errno);
@ -405,8 +403,8 @@ int user_start(int argc, char *argv[])
/* Set the size of the window 2 == size of window 1*/
message("user_start: Set hwnd2 size to (%d,%d)\n", rect.pt2.x, rect.pt2.y);
ret = nx_setsize(hwnd2, &rect);
message("user_start: Set hwnd2 size to (%d,%d)\n", size.w, size.h);
ret = nx_setsize(hwnd2, &size);
if (ret < 0)
{
message("user_start: nx_setsize failed: %d\n", errno);
@ -421,8 +419,8 @@ int user_start(int argc, char *argv[])
/* Set the position of window #2 */
pt.x = g_xres - rect.pt2.x - pt.x;
pt.y = g_yres - rect.pt2.y - pt.y;
pt.x = g_xres - size.w - pt.x;
pt.y = g_yres - size.h - pt.y;
message("user_start: Set hwnd2 postion to (%d,%d)\n", pt.x, pt.y);
ret = nx_setposition(hwnd2, &pt);

View File

@ -261,7 +261,7 @@ EXTERN void nxbe_setposition(FAR struct nxbe_window_s *wnd,
****************************************************************************/
EXTERN void nxbe_setsize(FAR struct nxbe_window_s *wnd,
FAR const struct nxgl_rect_s *size);
FAR const struct nxgl_size_s *size);
/****************************************************************************
* Name: nxbe_raise

View File

@ -79,7 +79,7 @@
****************************************************************************/
void nxbe_setsize(FAR struct nxbe_window_s *wnd,
FAR const struct nxgl_rect_s *size)
FAR const struct nxgl_size_s *size)
{
struct nxgl_rect_s bounds;
@ -96,7 +96,12 @@ void nxbe_setsize(FAR struct nxbe_window_s *wnd,
/* Add the window origin to supplied size get the new window bounding box */
nxgl_rectoffset(&wnd->bounds, size, wnd->origin.x, wnd->origin.y);
wnd->bounds.pt2.x = wnd->bounds.pt1.x + size->w - 1;
wnd->bounds.pt2.y = wnd->bounds.pt1.y + size->h - 1;
/* Clip the new bounding box so that lies within the background screen */
nxgl_rectintersect(&wnd->bounds, &wnd->bounds, &wnd->be->bkgd.bounds);
/* We need to update the larger of the two rectangles. That will be the
* union of the before and after sizes.
@ -104,12 +109,6 @@ void nxbe_setsize(FAR struct nxbe_window_s *wnd,
nxgl_rectunion(&bounds, &bounds, &wnd->bounds);
/* Clip the bounding box so that is lies with the screen defined by the
* background window.
*/
nxgl_rectintersect(&bounds, &bounds, &wnd->be->bkgd.bounds);
/* Then redraw this window AND all windows below it. Having resized the
* window, we may have exposed previoulsy obscured portions of windows
* below this one.

View File

@ -54,7 +54,7 @@ RCOPY2_CSRCS = nxglib_copyrectangle_8bpp.c nxglib_copyrectangle_16bpp.c \
RECT_CSRCS = nxglib_rectcopy.c nxglib_rectoffset.c nxglib_vectoradd.c \
nxglib_vectsubtract.c nxglib_rectintersect.c \
nxglib_nonintersecting.c nxglib_rectunion.c nxglib_rectinside.c \
nxglib_rectoverlap.c nxglib_nullrect.c
nxglib_rectoverlap.c nxglib_rectsize.c nxglib_nullrect.c
TRAP_CSRCS = nxglib_runoffset.c nxglib_runcopy.c \
nxglib_trapoffset.c nxglib_trapcopy.c
COLOR_CSRCS = nxglib_colorcopy.c

View File

@ -104,8 +104,8 @@ void NXGL_FUNCNAME(nxgl_copyrectangle,NXGLIB_SUFFIX)
/* Get the dimensions of the rectange to fill: height in rows and width in bytes */
width = NXGL_SCALEX(dest->pt2.x - dest->pt1.x);
rows = dest->pt2.y - dest->pt1.y;
width = NXGL_SCALEX(dest->pt2.x - dest->pt1.x + 1);
rows = dest->pt2.y - dest->pt1.y + 1;
#if NXGLIB_BITSPERPIXEL < 8
# ifdef CONFIG_NXGL_PACKEDMSFIRST

View File

@ -104,8 +104,8 @@ void NXGL_FUNCNAME(nxgl_fillrectangle,NXGLIB_SUFFIX)
/* Get the dimensions of the rectange to fill in pixels */
width = rect->pt2.x - rect->pt1.x;
rows = rect->pt2.y - rect->pt1.y;
width = rect->pt2.x - rect->pt1.x + 1;
rows = rect->pt2.y - rect->pt1.y + 1;
/* Get the address of the first byte in the first line to write */

View File

@ -125,8 +125,8 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)(
/* Calculate the slope of the left and right side of the trapezoid */
dx1dy = b16divi((trap->bot.x1 - x1), nrows);
dx2dy = b16divi((trap->bot.x2 - x2), nrows);
dx1dy = b16divi((trap->bot.x1 - x1), nrows - 1);
dx2dy = b16divi((trap->bot.x2 - x2), nrows - 1);
/* Perform vertical clipping */

View File

@ -147,8 +147,8 @@ void NXGL_FUNCNAME(nxgl_moverectangle,NXGLIB_SUFFIX)
/* Get the dimensions of the rectange to fill: height in rows and width in bytes */
width = NXGL_SCALEX(rect->pt2.x - rect->pt1.x);
rows = rect->pt2.y - rect->pt1.y;
width = NXGL_SCALEX(rect->pt2.x - rect->pt1.x + 1);
rows = rect->pt2.y - rect->pt1.y + 1;
#if NXGLIB_BITSPERPIXEL < 8
# ifdef CONFIG_NXGL_PACKEDMSFIRST

View File

@ -0,0 +1,83 @@
/****************************************************************************
* graphics/nxglib/nxglib_rectsize.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* 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 <nuttx/config.h>
#include <sys/types.h>
#include <nuttx/fb.h>
#include <nuttx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_rectsize
*
* Description:
* Return the size of the specified rectangle.
*
****************************************************************************/
void nxgl_rectsize(FAR struct nxgl_size_s *size,
FAR const struct nxgl_rect_s *rect)
{
size->w = rect->pt2.x - rect->pt1.x + 1;
size->h = rect->pt2.y - rect->pt1.y + 1;
}

View File

@ -85,7 +85,7 @@
*
****************************************************************************/
int nx_setsize(NXWINDOW hwnd, FAR struct nxgl_rect_s *size)
int nx_setsize(NXWINDOW hwnd, FAR struct nxgl_size_s *size)
{
FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd;
struct nxsvrmsg_setsize_s outmsg;
@ -101,9 +101,10 @@ int nx_setsize(NXWINDOW hwnd, FAR struct nxgl_rect_s *size)
/* Then inform the server of the changed position */
outmsg.msgid = NX_SVRMSG_SETSIZE;
outmsg.wnd = wnd;
nxgl_rectcopy(&outmsg.size, size);
outmsg.msgid = NX_SVRMSG_SETSIZE;
outmsg.wnd = wnd;
outmsg.size.w = size->w;
outmsg.size.h = size->h;
ret = mq_send(wnd->conn->cwrmq, &outmsg, sizeof(struct nxsvrmsg_setsize_s), NX_SVRMSG_PRIO);
if (ret < 0)

View File

@ -217,7 +217,7 @@ struct nxclimsg_newposition_s
{
uint32 msgid; /* NX_CLIMSG_NEWPOSITION */
FAR struct nxbe_window_s *wnd; /* The window whose position/size has changed */
FAR struct nxgl_rect_s size; /* The current window size */
FAR struct nxgl_size_s size; /* The current window size */
FAR struct nxgl_point_s pos; /* The current window position */
FAR struct nxgl_rect_s bounds; /* Size of screen */
};
@ -307,7 +307,7 @@ struct nxsvrmsg_setsize_s
{
uint32 msgid; /* NX_SVRMSG_SETSIZE */
FAR struct nxbe_window_s *wnd; /* The window whose position/size has changed */
FAR struct nxgl_rect_s size; /* The new window size */
FAR struct nxgl_size_s size; /* The new window size */
};
/* This message informs the server that the size or position of the window has changed */

View File

@ -86,14 +86,12 @@ void nxfe_reportposition(FAR struct nxbe_window_s *wnd)
/* Send the size/position info */
outmsg.msgid = NX_CLIMSG_NEWPOSITION;
outmsg.wnd = wnd;
outmsg.pos.x = wnd->origin.x;
outmsg.pos.y = wnd->origin.y;
outmsg.msgid = NX_CLIMSG_NEWPOSITION;
outmsg.wnd = wnd;
outmsg.pos.x = wnd->origin.x;
outmsg.pos.y = wnd->origin.y;
/* Convert the window bounding box to a window-relative rectangle */
nxgl_rectoffset(&outmsg.size, &wnd->bounds, -wnd->origin.x, -wnd->origin.y);
nxgl_rectsize(&outmsg.size, &wnd->bounds);
/* Provide the background window bounding box which is the screen limits
* It must always have (0,0) as its origin

View File

@ -430,7 +430,7 @@ int nx_runinstance(FAR const char *mqname, FAR struct fb_vtable_s *fb)
case NX_SVRMSG_LOWER: /* Lower the window to the bottom of the display */
{
FAR struct nxsvrmsg_lower_s *lowermsg = (FAR struct nxsvrmsg_lower_s *)buffer;
nxbe_raise(lowermsg->wnd);
nxbe_lower(lowermsg->wnd);
}
break;

View File

@ -85,7 +85,7 @@
*
****************************************************************************/
int nx_setsize(NXWINDOW hwnd, FAR struct nxgl_rect_s *size)
int nx_setsize(NXWINDOW hwnd, FAR struct nxgl_size_s *size)
{
#ifdef CONFIG_DEBUG
if (!hwnd || !size)

View File

@ -81,7 +81,7 @@
void nxfe_reportposition(FAR struct nxbe_window_s *wnd)
{
FAR struct nxbe_state_s *be = wnd->be;
struct nxgl_rect_s rect;
struct nxgl_size_s size;
#ifdef CONFIG_DEBUG
if (!wnd)
@ -96,9 +96,9 @@ void nxfe_reportposition(FAR struct nxbe_window_s *wnd)
if (wnd->cb->position)
{
/* Convert the frame rectangle to a window-relative rectangle */
/* Get the size of the bounding rectangle */
nxgl_rectoffset(&rect, &wnd->bounds, -wnd->origin.x, -wnd->origin.y);
nxgl_rectsize(&size, &wnd->bounds);
/* And provide this to the client */

View File

@ -63,7 +63,7 @@
static void nxtk_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
boolean morem, FAR void *arg);
static void nxtk_position(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size,
static void nxtk_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds,
FAR void *arg);
@ -155,37 +155,38 @@ static void nxtk_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
* Name: nxtk_position
****************************************************************************/
static void nxtk_position(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size,
static void nxtk_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds,
FAR void *arg)
{
FAR struct nxtk_framedwindow_s *fwnd = (FAR struct nxtk_framedwindow_s *)hwnd;
struct nxgl_rect_s relrect;
struct nxgl_size_s subwindowsize;
gvdbg("nxtk_position: hwnd=%p size={(%d,%d),(%d,%d)} pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n",
hwnd, size->pt1.x, size->pt1.y, size->pt2.x, size->pt2.y,
pos->x, pos->y,
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,
bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y);
/* Recalculate the dimensions of the toolbar and client windows */
nxtk_setsubwindows(fwnd);
/* Report the size position of the client sub-window */
/* Report the size / position of the client sub-window */
if (fwnd->fwcb->position)
{
nxgl_rectoffset(&relrect, &fwnd->fwrect, fwnd->fwrect.pt1.x, fwnd->fwrect.pt1.y);
fwnd->fwcb->position((NXTKWINDOW)fwnd, &relrect, &fwnd->fwrect.pt1, bounds, fwnd->fwarg);
nxgl_rectsize(&subwindowsize, &fwnd->fwrect);
fwnd->fwcb->position((NXTKWINDOW)fwnd, &subwindowsize,
&fwnd->fwrect.pt1, bounds, fwnd->fwarg);
}
/* Report the size position of the toolbar sub-window */
/* Report the size / position of the toolbar sub-window */
if (fwnd->tbcb && fwnd->tbcb->position)
{
nxgl_rectoffset(&relrect, &fwnd->tbrect, fwnd->tbrect.pt1.x, fwnd->tbrect.pt1.y);
fwnd->tbcb->position((NXTKWINDOW)fwnd, &relrect, &fwnd->fwrect.pt1, bounds, fwnd->tbarg);
nxgl_rectsize(&subwindowsize, &fwnd->tbrect);
fwnd->tbcb->position((NXTKWINDOW)fwnd, &subwindowsize,
&fwnd->tbrect.pt1, bounds, fwnd->tbarg);
}
}

View File

@ -91,10 +91,10 @@
*
****************************************************************************/
int nxtk_setsize(NXTKWINDOW hfwnd, FAR struct nxgl_rect_s *size)
int nxtk_setsize(NXTKWINDOW hfwnd, FAR struct nxgl_size_s *size)
{
FAR struct nxtk_framedwindow_s *fwnd = (FAR struct nxtk_framedwindow_s *)hfwnd;
struct nxgl_rect_s newsize;
struct nxgl_size_s newsize;
#ifdef CONFIG_DEBUG
if (!hfwnd || !size)
@ -106,10 +106,8 @@ int nxtk_setsize(NXTKWINDOW hfwnd, FAR struct nxgl_rect_s *size)
/* Add the sizes need for the toolbar and the borders */
newsize.pt1.x = 0;
newsize.pt1.y = 0;
newsize.pt2.x = size->pt2.x + 2 * CONFIG_NXTK_BORDERWIDTH;
newsize.pt2.y = size->pt2.y + fwnd->tbheight + 2 * CONFIG_NXTK_BORDERWIDTH;
newsize.w = size->w + 2 * CONFIG_NXTK_BORDERWIDTH;
newsize.h = size->w + fwnd->tbheight + 2 * CONFIG_NXTK_BORDERWIDTH;
/* Then set the window size */

View File

@ -142,7 +142,7 @@ void nxtk_setsubwindows(FAR struct nxtk_framedwindow_s *fwnd)
/* Divide up the horizontal dimensions of the window */
fullwidth = fwnd->wnd.bounds.pt2.x - fwnd->wnd.bounds.pt1.x;
fullwidth = fwnd->wnd.bounds.pt2.x - fwnd->wnd.bounds.pt1.x + 1;
bdrwidth = ngl_min(2 * CONFIG_NXTK_BORDERWIDTH, fullwidth);
fwwidth = fullwidth - bdrwidth;
fwleft = fwnd->wnd.origin.x + bdrwidth/2;
@ -151,11 +151,11 @@ void nxtk_setsubwindows(FAR struct nxtk_framedwindow_s *fwnd)
fwnd->tbrect.pt1.x = fwleft;
fwnd->tbrect.pt1.y = tbtop;
fwnd->tbrect.pt2.x = fwleft + fwwidth;
fwnd->tbrect.pt2.x = fwleft + fwwidth - 1;
fwnd->tbrect.pt2.y = tbtop + tbheight - 1;
fwnd->fwrect.pt1.x = fwleft;
fwnd->fwrect.pt1.y = fwtop;
fwnd->fwrect.pt2.x = fwleft + fwwidth;
fwnd->fwrect.pt2.x = fwleft + fwwidth - 1;
fwnd->fwrect.pt2.y = fwtop + fwheight - 1;
}

View File

@ -120,7 +120,7 @@ struct nx_callback_s
*
* Input Parameters:
* hwnd - Window handle
* size - The size of the window (pt1 should always be zero)
* size - The size of the window
* pos - The position of the upper left hand corner of the window on
* the overalll display
* bounds - The bounding rectangle that the describes the entire
@ -132,7 +132,7 @@ struct nx_callback_s
*
**************************************************************************/
void (*position)(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size,
void (*position)(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds,
FAR void *arg);
@ -536,7 +536,7 @@ EXTERN int nx_setposition(NXWINDOW hwnd, FAR struct nxgl_point_s *pos);
*
****************************************************************************/
EXTERN int nx_setsize(NXWINDOW hwnd, FAR struct nxgl_rect_s *size);
EXTERN int nx_setsize(NXWINDOW hwnd, FAR struct nxgl_size_s *size);
/****************************************************************************
* Name: nx_raise

View File

@ -100,6 +100,14 @@ struct nxgl_point_s
nxgl_coord_t y; /* Y position, range: 0 to screen height - 1 */
};
/* Describes the size of a rectangulare region */
struct nxgl_size_s
{
nxgl_coord_t w; /* Width in pixels */
nxgl_coord_t h; /* Height in rows */
};
/* Describes a rectangle on the display */
struct nxgl_rect_s
@ -424,6 +432,17 @@ EXTERN boolean nxgl_rectoverlap(FAR struct nxgl_rect_s *rect1,
EXTERN boolean nxgl_rectinside(FAR const struct nxgl_rect_s *rect,
FAR const struct nxgl_point_s *pt);
/****************************************************************************
* Name: nxgl_rectsize
*
* Description:
* Return the size of the specified rectangle.
*
****************************************************************************/
EXTERN void nxgl_rectsize(FAR struct nxgl_size_s *size,
FAR const struct nxgl_rect_s *rect);
/****************************************************************************
* Name: nxgl_nullrect
*

View File

@ -169,7 +169,7 @@ EXTERN int nxtk_setposition(NXTKWINDOW hfwnd, FAR struct nxgl_point_s *pos);
*
****************************************************************************/
EXTERN int nxtk_setsize(NXTKWINDOW hfwnd, FAR struct nxgl_rect_s *size);
EXTERN int nxtk_setsize(NXTKWINDOW hfwnd, FAR struct nxgl_size_s *size);
/****************************************************************************
* Name: nxtk_raise