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.1 2006/01/23 23:14:29 bernie
24 *#* Implement simple, but impressive windowing system.
31 * Map the contents of all child-windows into the bitmap of \a w.
33 * Please note that recursively draw children into their parent
34 * effectively damages the parent buffer.
36 void win_compose(Window *w)
41 * Walk over all children, in back to front order and tell them
44 REVERSE_FOREACH_NODE(child, &w->children)
46 /* Recursively compose child first. */
49 /* Draw child into our bitmap. */
51 gfx_blit(w->bitmap, &child->geom, child->bitmap, 0, 0);
56 * Map window \a w into \a parent.
58 * The new window becomes the topmost window.
60 * \note Opening a window twice is illegal.
64 void win_open(Window *w, Window *parent)
68 ADDHEAD(&parent->children, &w->link);
72 * Detach window from its parent.
74 * Closing a window causes it to become orphan of its
75 * parent. Its content will no longer appear in its
76 * parent after the next refresh cycle.
78 * \note Closing a window that has not been previously
83 void win_close(Window *w)
91 * Move window to the topmost position relative to its sibling.
93 * \see win_move(), win_resize(), win_setGeometry()
95 void win_raise(Window *w)
99 ADDHEAD(&w->parent->children, &w->link);
103 * Set window position and size at the same time.
105 * This function is equivalent to subsequent calls to win_move()
106 * and win_resize() using the coordinates provided by the
107 * \a new_geom rectangle.
109 * \note The xmax and ymax members of \a new_geom are non-inclusive,
110 * as usual for the Rect interface.
115 void win_setGeometry(Window *w, Rect *new_geom)
118 // memcpy(&w->geom, new_geom, sizeof(w->geom));
123 * Move window to specified position.
125 * Move the window top-left corner to the pixel coordinates
126 * \a left and \a top, which are relative to the parent window.
128 * \note A window can also be moved outside the borders
129 * of its parent, or at negative coordinates.
131 * \note It is allowed to move an orphan window.
133 void win_move(Window *w, coord_t left, coord_t top)
139 r.xmax = r.xmin + RECT_WIDTH(&w->geom);
140 r.ymax = r.ymin + RECT_WIDTH(&w->geom);
142 win_setGeometry(w, &r);
146 * Resize the rectangle of a window.
148 * The window shrinks or grows to the specified size.
150 * \note Growing a window beyond the size of its
151 * backing bitmap results in unspecified behavior.
153 * \note It is allowed to resize an orphan window.
155 void win_resize(Window *w, coord_t width, coord_t height)
159 r.xmin = w->geom.xmin;
160 r.ymin = w->geom.ymin;
161 r.xmax = r.xmin + width;
162 r.ymax = r.ymin + height;
164 win_setGeometry(w, &r);
168 * Initialize a new window structure.
171 * The new window initial position is set to (0,0).
172 * The size is set to the size of the installed bitmap,
173 * or (0,0) if there's no backing store.
175 * \arg bm The bitmap to install as backing store
176 * for drawing into the window, or NULL if
177 * the window is not drawable.
179 void win_create(Window *w, Bitmap *bm)
187 w->geom.xmax = bm->width;
188 w->geom.ymax = bm->height;
190 LIST_INIT(&w->children);