starting the material window
[retroray] / src / rtk.c
index 4bb93c8..4049f88 100644 (file)
--- a/src/rtk.c
+++ b/src/rtk.c
@@ -126,6 +126,23 @@ void rtk_set_callback(rtk_widget *w, rtk_callback cbfunc, void *cls)
        w->any.cbcls = cls;
 }
 
+void rtk_show(rtk_widget *w)
+{
+       w->any.flags |= VISIBLE;
+       rtk_invalidate(w);
+}
+
+void rtk_hide(rtk_widget *w)
+{
+       w->any.flags &= ~VISIBLE;
+       invalfb(w);
+}
+
+int rtk_visible(const rtk_widget *w)
+{
+       return w->any.flags & VISIBLE;
+}
+
 void rtk_invalidate(rtk_widget *w)
 {
        w->any.flags |= DIRTY;
@@ -247,7 +264,8 @@ rtk_icon *rtk_bn_get_icon(rtk_widget *w)
 
 /* --- constructors --- */
 
-rtk_widget *rtk_create_window(rtk_widget *par, const char *title, int x, int y, int width, int height)
+rtk_widget *rtk_create_window(rtk_widget *par, const char *title, int x, int y,
+               int width, int height, unsigned int flags)
 {
        rtk_widget *w;
 
@@ -259,6 +277,8 @@ rtk_widget *rtk_create_window(rtk_widget *par, const char *title, int x, int y,
        rtk_set_text(w, title);
        rtk_move(w, x, y);
        rtk_resize(w, width, height);
+
+       w->any.flags |= flags << 16;
        return w;
 }
 
@@ -496,8 +516,11 @@ void rtk_draw_widget(rtk_widget *w)
 {
        int dirty;
 
+       if(!(w->any.flags & VISIBLE)) {
+               return;
+       }
+
        if(need_relayout(w)) {
-               dbgmsg("calc layout %s\n", w->any.text ? w->any.text : "?");
                calc_layout(w);
        }
 
@@ -563,6 +586,9 @@ static void abs_pos(rtk_widget *w, int *xpos, int *ypos)
 #define COL_LBEV       0xffaaaaaa
 #define COL_SBEV       0xff222222
 #define COL_TEXT       0xff000000
+#define COL_WINFRM     0xff2244aa
+#define COL_WINFRM_LIT 0xff4466ff
+#define COL_WINFRM_SHAD        0xff051166
 
 static void hline(int x, int y, int sz, uint32_t col)
 {
@@ -586,6 +612,16 @@ static void vline(int x, int y, int sz, uint32_t col)
 
 enum {FRM_SOLID, FRM_OUTSET, FRM_INSET};
 
+enum {UICOL_BG, UICOL_LBEV, UICOL_SBEV};
+static uint32_t uicol[3];
+
+static void uicolor(uint32_t col, uint32_t lcol, uint32_t scol)
+{
+       uicol[UICOL_BG] = col;
+       uicol[UICOL_LBEV] = lcol;
+       uicol[UICOL_SBEV] = scol;
+}
+
 static void draw_frame(rtk_rect *rect, int type)
 {
        int tlcol, brcol;
@@ -595,12 +631,12 @@ static void draw_frame(rtk_rect *rect, int type)
                tlcol = brcol = 0xff000000;
                break;
        case FRM_OUTSET:
-               tlcol = COL_LBEV;
-               brcol = COL_SBEV;
+               tlcol = uicol[UICOL_LBEV];
+               brcol = uicol[UICOL_SBEV];
                break;
        case FRM_INSET:
-               tlcol = COL_SBEV;
-               brcol = COL_LBEV;
+               tlcol = uicol[UICOL_SBEV];
+               brcol = uicol[UICOL_LBEV];
                break;
        default:
                break;
@@ -612,14 +648,47 @@ static void draw_frame(rtk_rect *rect, int type)
        vline(rect->x + rect->width - 1, rect->y + 1, rect->height - 2, brcol);
 }
 
+#define WINFRM_SZ      2
+#define WINFRM_TBAR    16
+
 static void draw_window(rtk_widget *w)
 {
-       rtk_rect rect;
+       rtk_rect rect, frmrect, tbrect;
        rtk_widget *c;
        int win_dirty = w->any.flags & DIRTY;
 
        if(win_dirty) {
                widget_rect(w, &rect);
+
+               if(w->any.flags & FRAME) {
+                       uicolor(COL_WINFRM, COL_WINFRM_LIT, COL_WINFRM_SHAD);
+
+                       frmrect = rect;
+                       frmrect.width += WINFRM_SZ * 2;
+                       frmrect.height += WINFRM_SZ * 2 + WINFRM_TBAR;
+                       frmrect.x -= WINFRM_SZ;
+                       frmrect.y -= WINFRM_SZ + WINFRM_TBAR;
+
+                       tbrect.x = rect.x;
+                       tbrect.y = rect.y - WINFRM_TBAR;
+                       tbrect.width = rect.width;
+                       tbrect.height = WINFRM_TBAR;
+
+                       draw_frame(&frmrect, FRM_OUTSET);
+                       frmrect.x++;
+                       frmrect.y++;
+                       frmrect.width -= 2;
+                       frmrect.height -= 2;
+                       draw_frame(&frmrect, FRM_INSET);
+
+                       draw_frame(&tbrect, FRM_OUTSET);
+                       tbrect.x++;
+                       tbrect.y++;
+                       tbrect.width -= 2;
+                       tbrect.height -= 2;
+                       gfx.fill(&tbrect, COL_WINFRM);
+               }
+
                gfx.fill(&rect, COL_BG);
        }
 
@@ -647,6 +716,8 @@ static void draw_button(rtk_widget *w)
                pressed = w->any.flags & PRESS;
        }
 
+       uicolor(COL_BG, COL_LBEV, COL_SBEV);
+
        if(rect.width > 2 && rect.height > 2) {
                draw_frame(&rect, pressed ? FRM_INSET : FRM_OUTSET);
 
@@ -676,6 +747,8 @@ static void draw_separator(rtk_widget *w)
 
        if(!win) return;
 
+       uicolor(COL_BG, COL_LBEV, COL_SBEV);
+
        widget_rect(w, &rect);
        abs_pos(w, &rect.x, &rect.y);
 
@@ -818,6 +891,31 @@ int rtk_input_mmotion(rtk_widget *w, int x, int y)
        return 0;
 }
 
+void rtk_fix_rect(rtk_rect *rect)
+{
+       int x, y, w, h;
+
+       x = rect->x;
+       y = rect->y;
+
+       if(rect->width < 0) {
+               w = -rect->width;
+               x += rect->width;
+       } else {
+               w = rect->width;
+       }
+       if(rect->height < 0) {
+               h = -rect->height;
+               y += rect->height;
+       } else {
+               h = rect->height;
+       }
+
+       rect->x = x;
+       rect->y = y;
+       rect->width = w;
+       rect->height = h;
+}
 
 void rtk_rect_union(rtk_rect *a, const rtk_rect *b)
 {