Fri 08 Aug 2003 12:09:43 AM UTC, original submission:
I'm writing a game in ParaGUI, and I've found it very
useful to be able to resize widgets automatically. I
have a parent widget that takes up the whole screen,
and child widgets are embedded in it. When I resize
the screen, I call widget_zoom() on my parent widget,
and it automatically resizes every widget on the
screen. I've posted it here in case anyone might find
it useful (maybe even to be included in ParaGUI?).
It's not perfect - rounding errors accumulate if you
resize too much, and things look a little off. But it
serves pretty well in normal use.
void widget_zoom(PG_Widget *widget, double zoomx,
double zoomy)
{
int px=0, py=0;
if (widget->GetParent()) {
px = widget->GetParent()->x;
py = widget->GetParent()->y;
}
PG_Rect r(
px + int((widget->x-px) * zoomx + 0.5),
py + int((widget->y-py) * zoomy + 0.5),
int(widget->w * zoomx + 0.5),
int(widget->h * zoomy + 0.5));
widget->MoveRect(r.x, r.y);
widget->SizeWidget(r.w, r.h);
PG_RectList *children = widget->GetChildList();
if (children) {
PG_RectList::iterator it;
for (it = children->begin(); it != children->end();
it++) {
widget_zoom(*it, zoomx, zoomy);
}
}
}
|