win.c

Go to the documentation of this file.
00001 
00046 /*#*
00047  *#* $Log$
00048  *#* Revision 1.2  2006/08/01 17:26:04  batt
00049  *#* Update docs.
00050  *#*
00051  *#* Revision 1.1  2006/08/01 15:43:01  batt
00052  *#* Add in board_kd current edited channel visualization.
00053  *#*
00054  *#* Revision 1.4  2006/07/19 12:56:26  bernie
00055  *#* Convert to new Doxygen style.
00056  *#*
00057  *#* Revision 1.3  2006/02/10 12:25:41  bernie
00058  *#* Add missing header.
00059  *#*
00060  *#* Revision 1.2  2006/01/26 00:36:48  bernie
00061  *#* Const correctness for some new functions.
00062  *#*
00063  *#* Revision 1.1  2006/01/23 23:14:29  bernie
00064  *#* Implement simple, but impressive windowing system.
00065  *#*
00066  *#*/
00067 
00068 #include "win.h"
00069 #include <struct/list.h>
00070 
00077 void win_compose(Window *w)
00078 {
00079     Window *child;
00080 
00081     /*
00082      * Walk over all children, in back to front order and tell them
00083      * to compose into us.
00084      */
00085     REVERSE_FOREACH_NODE(child, &w->children)
00086     {
00087         /* Recursively compose child first. */
00088         win_compose(child);
00089 
00090         /* Draw child into our bitmap. */
00091         if (w->bitmap)
00092             gfx_blit(w->bitmap, &child->geom, child->bitmap, 0, 0);
00093     }
00094 }
00095 
00105 void win_open(Window *w, Window *parent)
00106 {
00107     ASSERT(!w->parent);
00108     w->parent = parent;
00109     ADDHEAD(&parent->children, &w->link);
00110 }
00111 
00124 void win_close(Window *w)
00125 {
00126     ASSERT(w->parent);
00127     REMOVE(&w->link);
00128     w->parent = NULL;
00129 }
00130 
00136 void win_raise(Window *w)
00137 {
00138     ASSERT(w->parent);
00139     REMOVE(&w->link);
00140     ADDHEAD(&w->parent->children, &w->link);
00141 }
00142 
00156 void win_setGeometry(Window *w, const Rect *new_geom)
00157 {
00158     // requires C99?
00159     // memcpy(&w->geom, new_geom, sizeof(w->geom));
00160     w->geom = *new_geom;
00161 }
00162 
00174 void win_move(Window *w, coord_t left, coord_t top)
00175 {
00176     Rect r;
00177 
00178     r.xmin = left;
00179     r.ymin = top;
00180     r.xmax = r.xmin + RECT_WIDTH(&w->geom);
00181     r.ymax = r.ymin + RECT_WIDTH(&w->geom);
00182 
00183     win_setGeometry(w, &r);
00184 }
00185 
00196 void win_resize(Window *w, coord_t width, coord_t height)
00197 {
00198     Rect r;
00199 
00200     r.xmin = w->geom.xmin;
00201     r.ymin = w->geom.ymin;
00202     r.xmax = r.xmin + width;
00203     r.ymax = r.ymin + height;
00204 
00205     win_setGeometry(w, &r);
00206 }
00207 
00219 void win_create(Window *w, Bitmap *bm)
00220 {
00221     w->parent = NULL;
00222     w->bitmap = bm;
00223     w->geom.xmin = 0;
00224     w->geom.ymin = 0;
00225     if (bm)
00226     {
00227         w->geom.xmax = bm->width;
00228         w->geom.ymax = bm->height;
00229     }
00230     LIST_INIT(&w->children);
00231 }
00232