2003-05-05 18:50:14 +00:00
|
|
|
/*
|
|
|
|
view.c
|
|
|
|
|
|
|
|
console view object
|
|
|
|
|
|
|
|
Copyright (C) 2003 Bill Currie
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2003/5/5
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2022-04-24 12:09:58 +00:00
|
|
|
#include "QF/cexpr.h"
|
2021-06-12 13:50:51 +00:00
|
|
|
#include "QF/ui/view.h"
|
2003-05-05 18:50:14 +00:00
|
|
|
|
2022-04-24 12:09:58 +00:00
|
|
|
static exprenum_t grav_t_enum;
|
|
|
|
exprtype_t grav_t_type = {
|
|
|
|
.name = "grav_t",
|
|
|
|
.size = sizeof (grav_t),
|
|
|
|
.data = &grav_t_enum,
|
|
|
|
.get_string = cexpr_enum_get_string,
|
|
|
|
};
|
|
|
|
static grav_t grav_t_values[] = {
|
|
|
|
grav_center,
|
|
|
|
grav_north,
|
|
|
|
grav_northeast,
|
|
|
|
grav_east,
|
|
|
|
grav_southeast,
|
|
|
|
grav_south,
|
|
|
|
grav_southwest,
|
|
|
|
grav_west,
|
|
|
|
grav_northwest,
|
|
|
|
};
|
|
|
|
static exprsym_t grav_t_symbols[] = {
|
|
|
|
{ "center", &grav_t_type, grav_t_values + grav_center },
|
|
|
|
{ "north", &grav_t_type, grav_t_values + grav_north },
|
|
|
|
{ "northeast", &grav_t_type, grav_t_values + grav_northeast },
|
|
|
|
{ "east", &grav_t_type, grav_t_values + grav_east },
|
|
|
|
{ "southeast", &grav_t_type, grav_t_values + grav_southeast },
|
|
|
|
{ "south", &grav_t_type, grav_t_values + grav_south },
|
|
|
|
{ "southwest", &grav_t_type, grav_t_values + grav_southwest },
|
|
|
|
{ "west", &grav_t_type, grav_t_values + grav_west },
|
|
|
|
{ "northwest", &grav_t_type, grav_t_values + grav_northwest },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
static exprtab_t grav_t_symtab = {
|
|
|
|
grav_t_symbols,
|
|
|
|
};
|
|
|
|
static exprenum_t grav_t_enum = {
|
|
|
|
&grav_t_type,
|
|
|
|
&grav_t_symtab,
|
|
|
|
};
|
|
|
|
|
2003-05-06 02:19:13 +00:00
|
|
|
static void
|
|
|
|
setgeometry (view_t *view)
|
2003-05-05 18:50:14 +00:00
|
|
|
{
|
2003-05-06 02:19:13 +00:00
|
|
|
int i;
|
|
|
|
view_t *par = view->parent;
|
|
|
|
|
|
|
|
if (!par) {
|
|
|
|
view->xabs = view->xrel = view->xpos;
|
|
|
|
view->yabs = view->yrel = view->ypos;
|
2005-06-14 11:30:33 +00:00
|
|
|
if (view->setgeometry)
|
|
|
|
view->setgeometry (view);
|
2003-05-06 02:19:13 +00:00
|
|
|
for (i = 0; i < view->num_children; i++)
|
|
|
|
setgeometry (view->children[i]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-05-05 18:50:14 +00:00
|
|
|
switch (view->gravity) {
|
|
|
|
case grav_center:
|
|
|
|
view->xrel = view->xpos + (par->xlen - view->xlen) / 2;
|
|
|
|
view->yrel = view->ypos + (par->ylen - view->ylen) / 2;
|
|
|
|
break;
|
|
|
|
case grav_north:
|
|
|
|
view->xrel = view->xpos + (par->xlen - view->xlen) / 2;
|
|
|
|
view->yrel = view->ypos;
|
|
|
|
break;
|
|
|
|
case grav_northeast:
|
|
|
|
view->xrel = par->xlen - view->xpos - view->xlen;
|
|
|
|
view->yrel = view->ypos;
|
|
|
|
break;
|
|
|
|
case grav_east:
|
|
|
|
view->xrel = par->xlen - view->xpos - view->xlen;
|
|
|
|
view->yrel = view->ypos + (par->ylen - view->ylen) / 2;
|
|
|
|
break;
|
|
|
|
case grav_southeast:
|
|
|
|
view->xrel = par->xlen - view->xpos - view->xlen;
|
|
|
|
view->yrel = par->ylen - view->ypos - view->ylen;
|
|
|
|
break;
|
|
|
|
case grav_south:
|
|
|
|
view->xrel = view->xpos + (par->xlen - view->xlen) / 2;
|
|
|
|
view->yrel = par->ylen - view->ypos - view->ylen;
|
|
|
|
break;
|
|
|
|
case grav_southwest:
|
|
|
|
view->xrel = view->xpos;
|
|
|
|
view->yrel = par->ylen - view->ypos - view->ylen;
|
|
|
|
break;
|
|
|
|
case grav_west:
|
|
|
|
view->xrel = view->xpos;
|
|
|
|
view->yrel = view->ypos + (par->ylen - view->ylen) / 2;
|
|
|
|
break;
|
|
|
|
case grav_northwest:
|
|
|
|
view->xrel = view->xpos;
|
|
|
|
view->yrel = view->ypos;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
view->xabs = par->xabs + view->xrel;
|
|
|
|
view->yabs = par->yabs + view->yrel;
|
2005-06-14 11:30:33 +00:00
|
|
|
if (view->setgeometry)
|
|
|
|
view->setgeometry (view);
|
2003-05-06 02:19:13 +00:00
|
|
|
for (i = 0; i < view->num_children; i++)
|
|
|
|
setgeometry (view->children[i]);
|
|
|
|
}
|
|
|
|
|
2007-04-08 08:47:47 +00:00
|
|
|
VISIBLE view_t *
|
|
|
|
view_new (int xp, int yp, int xl, int yl, grav_t grav)
|
|
|
|
{
|
|
|
|
view_t *view = calloc (1, sizeof (view_t));
|
|
|
|
view->xpos = xp;
|
|
|
|
view->ypos = yp;
|
|
|
|
view->xlen = xl;
|
|
|
|
view->ylen = yl;
|
|
|
|
view->gravity = grav;
|
|
|
|
view->visible = 1;
|
|
|
|
view->draw = view_draw;
|
|
|
|
setgeometry (view);
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2003-05-06 02:41:37 +00:00
|
|
|
view_insert (view_t *par, view_t *view, int pos)
|
2003-05-06 02:19:13 +00:00
|
|
|
{
|
2003-05-05 18:50:14 +00:00
|
|
|
view->parent = par;
|
2003-05-06 02:41:37 +00:00
|
|
|
if (pos < 0)
|
|
|
|
pos = par->num_children + 1 + pos;
|
|
|
|
if (pos < 0)
|
|
|
|
pos = 0;
|
|
|
|
if (pos > par->num_children)
|
|
|
|
pos = par->num_children;
|
2003-05-05 18:50:14 +00:00
|
|
|
if (par->num_children == par->max_children) {
|
|
|
|
par->max_children += 8;
|
|
|
|
par->children = realloc (par->children,
|
|
|
|
par->max_children * sizeof (view_t *));
|
|
|
|
memset (par->children + par->num_children, 0,
|
|
|
|
(par->max_children - par->num_children) * sizeof (view_t *));
|
|
|
|
}
|
2003-05-06 02:41:37 +00:00
|
|
|
memmove (par->children + pos + 1, par->children + pos,
|
|
|
|
(par->num_children - pos) * sizeof (view_t *));
|
|
|
|
par->num_children++;
|
|
|
|
par->children[pos] = view;
|
2003-05-06 02:19:13 +00:00
|
|
|
setgeometry (view);
|
2003-05-05 18:50:14 +00:00
|
|
|
}
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2003-05-06 02:41:37 +00:00
|
|
|
view_add (view_t *par, view_t *view)
|
|
|
|
{
|
|
|
|
view_insert (par, view, -1);
|
|
|
|
}
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2003-05-05 18:50:14 +00:00
|
|
|
view_remove (view_t *par, view_t *view)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < par->num_children; i++) {
|
|
|
|
if (par->children[i] == view) {
|
2003-08-13 17:07:42 +00:00
|
|
|
memmove (par->children + i, par->children + i + 1,
|
|
|
|
(par->num_children - i - 1) * sizeof (view_t *));
|
2003-05-16 19:36:03 +00:00
|
|
|
par->children [--par->num_children] = 0;
|
2003-05-05 18:50:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2003-05-05 18:50:14 +00:00
|
|
|
view_delete (view_t *view)
|
|
|
|
{
|
|
|
|
if (view->parent)
|
|
|
|
view_remove (view->parent, view);
|
|
|
|
while (view->num_children)
|
|
|
|
view_delete (view->children[0]);
|
2022-05-12 10:41:22 +00:00
|
|
|
free (view->children);
|
2003-05-05 18:50:14 +00:00
|
|
|
free (view);
|
|
|
|
}
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2003-05-05 18:50:14 +00:00
|
|
|
view_draw (view_t *view)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < view->num_children; i++) {
|
|
|
|
view_t *v = view->children[i];
|
2003-05-06 02:25:46 +00:00
|
|
|
if (v->visible && v->draw)
|
2003-05-05 18:50:14 +00:00
|
|
|
v->draw (v);
|
|
|
|
}
|
|
|
|
}
|
2003-05-06 02:19:13 +00:00
|
|
|
|
2003-05-07 07:10:15 +00:00
|
|
|
static void
|
|
|
|
_resize (view_t *view, int xl, int yl)
|
2003-05-06 02:19:13 +00:00
|
|
|
{
|
|
|
|
int i, xd, yd;
|
|
|
|
|
|
|
|
xd = xl - view->xlen;
|
|
|
|
yd = yl - view->ylen;
|
|
|
|
view->xlen = xl;
|
|
|
|
view->ylen = yl;
|
|
|
|
for (i = 0; i < view->num_children; i++) {
|
|
|
|
view_t *v = view->children[i];
|
|
|
|
|
|
|
|
if (v->resize_x && v->resize_y) {
|
2003-05-07 07:10:15 +00:00
|
|
|
_resize (v, v->xlen + xd, v->ylen + yd);
|
2003-05-06 02:19:13 +00:00
|
|
|
} else if (v->resize_x) {
|
2003-05-07 07:10:15 +00:00
|
|
|
_resize (v, v->xlen + xd, v->ylen);
|
2003-05-06 02:19:13 +00:00
|
|
|
} else if (v->resize_y) {
|
2003-05-07 07:10:15 +00:00
|
|
|
_resize (v, v->xlen, v->ylen + yd);
|
2003-05-06 02:19:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2003-05-07 07:10:15 +00:00
|
|
|
view_resize (view_t *view, int xl, int yl)
|
2003-05-06 02:19:13 +00:00
|
|
|
{
|
2003-05-07 07:10:15 +00:00
|
|
|
_resize (view, xl, yl);
|
|
|
|
setgeometry (view);
|
|
|
|
}
|
2003-05-06 02:19:13 +00:00
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2003-05-07 07:10:15 +00:00
|
|
|
view_move (view_t *view, int xp, int yp)
|
|
|
|
{
|
2003-05-06 02:19:13 +00:00
|
|
|
view->xpos = xp;
|
|
|
|
view->ypos = yp;
|
|
|
|
setgeometry (view);
|
|
|
|
}
|
2021-07-10 08:57:59 +00:00
|
|
|
|
|
|
|
VISIBLE void
|
|
|
|
view_setgeometry (view_t *view, int xp, int yp, int xl, int yl)
|
|
|
|
{
|
|
|
|
view->xpos = xp;
|
|
|
|
view->ypos = yp;
|
|
|
|
_resize (view, xl, yl);
|
|
|
|
setgeometry (view);
|
|
|
|
}
|
|
|
|
|
|
|
|
VISIBLE void
|
|
|
|
view_setgravity (view_t *view, grav_t grav)
|
|
|
|
{
|
|
|
|
view->gravity = grav;
|
|
|
|
setgeometry (view);
|
|
|
|
}
|