4 * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
5 * This file is part of DevLib - See README.devlib for information.
10 * \author Bernardo Innocenti <bernie@develer.com>
12 * \brief Very simple hierarchical windowing system.
14 * All functions in this module are to be intended as methods
15 * of the Window class. Please see its documentation
16 * for a module-wise introduction.
23 *#* Revision 1.2 2006/01/26 00:36:48 bernie
24 *#* Const correctness for some new functions.
26 *#* Revision 1.1 2006/01/23 23:14:29 bernie
27 *#* Implement simple, but impressive windowing system.
34 * Map the contents of all child-windows into the bitmap of \a w.
36 * Please note that recursively draw children into their parent
37 * effectively damages the parent buffer.
39 void win_compose(Window *w)
44 * Walk over all children, in back to front order and tell them
47 REVERSE_FOREACH_NODE(child, &w->children)
49 /* Recursively compose child first. */
52 /* Draw child into our bitmap. */
54 gfx_blit(w->bitmap, &child->geom, child->bitmap, 0, 0);
59 * Map window \a w into \a parent.
61 * The new window becomes the topmost window.
63 * \note Opening a window twice is illegal.
67 void win_open(Window *w, Window *parent)
71 ADDHEAD(&parent->children, &w->link);
75 * Detach window from its parent.
77 * Closing a window causes it to become orphan of its
78 * parent. Its content will no longer appear in its
79 * parent after the next refresh cycle.
81 * \note Closing a window that has not been previously
86 void win_close(Window *w)
94 * Move window to the topmost position relative to its sibling.
96 * \see win_move(), win_resize(), win_setGeometry()
98 void win_raise(Window *w)
102 ADDHEAD(&w->parent->children, &w->link);
106 * Set window position and size at the same time.
108 * This function is equivalent to subsequent calls to win_move()
109 * and win_resize() using the coordinates provided by the
110 * \a new_geom rectangle.
112 * \note The xmax and ymax members of \a new_geom are non-inclusive,
113 * as usual for the Rect interface.
118 void win_setGeometry(Window *w, const Rect *new_geom)
121 // memcpy(&w->geom, new_geom, sizeof(w->geom));
126 * Move window to specified position.
128 * Move the window top-left corner to the pixel coordinates
129 * \a left and \a top, which are relative to the parent window.
131 * \note A window can also be moved outside the borders
132 * of its parent, or at negative coordinates.
134 * \note It is allowed to move an orphan window.
136 void win_move(Window *w, coord_t left, coord_t top)
142 r.xmax = r.xmin + RECT_WIDTH(&w->geom);
143 r.ymax = r.ymin + RECT_WIDTH(&w->geom);
145 win_setGeometry(w, &r);
149 * Resize the rectangle of a window.
151 * The window shrinks or grows to the specified size.
153 * \note Growing a window beyond the size of its
154 * backing bitmap results in unspecified behavior.
156 * \note It is allowed to resize an orphan window.
158 void win_resize(Window *w, coord_t width, coord_t height)
162 r.xmin = w->geom.xmin;
163 r.ymin = w->geom.ymin;
164 r.xmax = r.xmin + width;
165 r.ymax = r.ymin + height;
167 win_setGeometry(w, &r);
171 * Initialize a new window structure.
174 * The new window initial position is set to (0,0).
175 * The size is set to the size of the installed bitmap,
176 * or (0,0) if there's no backing store.
178 * \arg bm The bitmap to install as backing store
179 * for drawing into the window, or NULL if
180 * the window is not drawable.
182 void win_create(Window *w, Bitmap *bm)
190 w->geom.xmax = bm->width;
191 w->geom.ymax = bm->height;
193 LIST_INIT(&w->children);