2008-12-03 00:39:39 +08:00
|
|
|
/****************************************************************************
|
2018-05-30 03:21:26 +08:00
|
|
|
* libs/libnx/nxtk/nxtk_setsubwindows.c
|
2008-12-03 00:39:39 +08:00
|
|
|
*
|
2021-02-24 02:55:00 +08:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2008-12-03 00:39:39 +08:00
|
|
|
*
|
2021-02-24 02:55:00 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-12-03 00:39:39 +08:00
|
|
|
*
|
2021-02-24 02:55:00 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2008-12-03 00:39:39 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2011-07-25 04:49:01 +08:00
|
|
|
#include <nuttx/nx/nx.h>
|
2015-12-30 07:31:17 +08:00
|
|
|
#include "nxtk.h"
|
2008-12-03 00:39:39 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxtk_setsubwindows
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Give the window dimensions, border width, and toolbar height,
|
|
|
|
* calculate the new dimensions of the toolbar region and client window
|
|
|
|
* region
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void nxtk_setsubwindows(FAR struct nxtk_framedwindow_s *fwnd)
|
|
|
|
{
|
|
|
|
nxgl_coord_t fullheight;
|
|
|
|
nxgl_coord_t bdrheight = 0;
|
2008-12-03 04:57:45 +08:00
|
|
|
nxgl_coord_t tbtop = fwnd->wnd.bounds.pt1.y;
|
2008-12-03 00:39:39 +08:00
|
|
|
nxgl_coord_t tbheight = 0;
|
2008-12-03 04:57:45 +08:00
|
|
|
nxgl_coord_t fwtop = fwnd->wnd.bounds.pt1.y;
|
2008-12-03 00:39:39 +08:00
|
|
|
nxgl_coord_t fwheight = 0;
|
|
|
|
nxgl_coord_t fullwidth;
|
|
|
|
nxgl_coord_t bdrwidth;
|
|
|
|
nxgl_coord_t fwwidth;
|
|
|
|
nxgl_coord_t fwleft;
|
|
|
|
|
|
|
|
/* Divide up the vertical dimension of the window */
|
|
|
|
|
|
|
|
fullheight = fwnd->wnd.bounds.pt2.y - fwnd->wnd.bounds.pt1.y + 1;
|
|
|
|
|
|
|
|
/* Is it tall enough for a border? */
|
|
|
|
|
|
|
|
if (fullheight > 0)
|
|
|
|
{
|
|
|
|
/* Get the border height */
|
|
|
|
|
|
|
|
bdrheight = ngl_min(2 * CONFIG_NXTK_BORDERWIDTH, fullheight);
|
|
|
|
|
|
|
|
/* Position the toolbar and client window just under the top border */
|
|
|
|
|
2008-12-03 08:33:59 +08:00
|
|
|
#if CONFIG_NXTK_BORDERWIDTH > 1
|
|
|
|
tbtop += CONFIG_NXTK_BORDERWIDTH - 1;
|
|
|
|
fwtop = tbtop + 1;
|
|
|
|
#else
|
|
|
|
tbtop += CONFIG_NXTK_BORDERWIDTH;
|
2008-12-03 00:39:39 +08:00
|
|
|
fwtop = tbtop;
|
2008-12-03 08:33:59 +08:00
|
|
|
#endif
|
2008-12-03 00:39:39 +08:00
|
|
|
|
|
|
|
/* Is it big enough for any part of the toolbar? */
|
|
|
|
|
|
|
|
if (fullheight > 2 * CONFIG_NXTK_BORDERWIDTH)
|
|
|
|
{
|
2021-02-24 03:23:56 +08:00
|
|
|
/* Yes.. get the height of the toolbar */
|
2008-12-03 00:39:39 +08:00
|
|
|
|
|
|
|
tbheight = fwnd->tbheight;
|
|
|
|
if (tbheight >= fullheight - bdrheight)
|
|
|
|
{
|
|
|
|
tbheight = fullheight - bdrheight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* And the client window gets whatever is left */
|
|
|
|
|
|
|
|
fwheight = fullheight - bdrheight - tbheight;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Position the client window just under the toolbar */
|
|
|
|
|
|
|
|
fwtop += tbheight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Divide up the horizontal dimensions of the window */
|
|
|
|
|
2008-12-03 04:02:59 +08:00
|
|
|
fullwidth = fwnd->wnd.bounds.pt2.x - fwnd->wnd.bounds.pt1.x + 1;
|
2008-12-03 00:39:39 +08:00
|
|
|
bdrwidth = ngl_min(2 * CONFIG_NXTK_BORDERWIDTH, fullwidth);
|
|
|
|
fwwidth = fullwidth - bdrwidth;
|
2008-12-03 04:57:45 +08:00
|
|
|
fwleft = fwnd->wnd.bounds.pt1.x + bdrwidth / 2;
|
2008-12-03 00:39:39 +08:00
|
|
|
|
|
|
|
/* Realize the positions/dimensions */
|
|
|
|
|
|
|
|
fwnd->tbrect.pt1.x = fwleft;
|
|
|
|
fwnd->tbrect.pt1.y = tbtop;
|
2008-12-03 04:02:59 +08:00
|
|
|
fwnd->tbrect.pt2.x = fwleft + fwwidth - 1;
|
2008-12-03 00:39:39 +08:00
|
|
|
fwnd->tbrect.pt2.y = tbtop + tbheight - 1;
|
|
|
|
|
|
|
|
fwnd->fwrect.pt1.x = fwleft;
|
|
|
|
fwnd->fwrect.pt1.y = fwtop;
|
2008-12-03 04:02:59 +08:00
|
|
|
fwnd->fwrect.pt2.x = fwleft + fwwidth - 1;
|
2008-12-03 00:39:39 +08:00
|
|
|
fwnd->fwrect.pt2.y = fwtop + fwheight - 1;
|
|
|
|
}
|