foo
[cdmenu] / menu / src / rtk_draw.c
index ad58bad..f92800b 100644 (file)
@@ -2,6 +2,7 @@
 #include "app.h"
 #include "rtk.h"
 #include "rtk_impl.h"
+#include "util.h"
 
 rtk_draw_ops rtk_gfx;
 #define gfx rtk_gfx
@@ -18,7 +19,7 @@ enum {
 static void widget_rect(rtk_widget *w, rtk_rect *rect);
 static void abs_widget_rect(rtk_widget *w, rtk_rect *rect);
 static void uicolor(uint32_t col, uint32_t lcol, uint32_t scol);
-static void draw_frame(rtk_rect *rect, int type, int sz);
+static void draw_frame(rtk_rect *rect, int type, int sz, uint32_t bgcol, uint32_t shad, uint32_t lit);
 
 static void draw_window(rtk_widget *w);
 static void draw_label(rtk_widget *w);
@@ -30,7 +31,7 @@ static void draw_separator(rtk_widget *w);
 static void draw_drawbox(rtk_widget *w);
 
 
-#define BEVELSZ                1
+#define BEVELSZ                2
 #define PAD                    (w->pad)
 #define OFFS           (BEVELSZ + PAD)
 #define CHKBOXSZ       (BEVELSZ * 2 + 8)
@@ -38,13 +39,33 @@ static void draw_drawbox(rtk_widget *w);
 #define WINFRM_SZ      2
 #define WINFRM_TBAR    16
 
+enum {
+       COL_BLACK = 240,
+       COL_BG,
+       COL_BGHL,
+       COL_SHAD,
+       COL_LIT,
+       COL_FRM_BG,
+       COL_FRM_SHAD,
+       COL_FRM_LIT,
+       COL_TEXT,
+       COL_FRM_TEXT,
+       COL_WHITE
+};
+
 void rtk_init_drawing(void)
 {
-       const char *s = "QI|9g/";
-       rtk_rect r;
-
-       gfx.textrect(s, &r);
-       fontheight = r.height;
+       app_setcolor(COL_BLACK, 0, 0, 0);
+       app_setcolor(COL_WHITE, 0xff, 0xff, 0xff);
+       app_setcolor(COL_TEXT, 0, 0, 0);
+       app_setcolor(COL_BG, 0x66, 0x66, 0x66);
+       app_setcolor(COL_BGHL, 0x80, 0x80, 0x80);
+       app_setcolor(COL_SHAD, 0x22, 0x22, 0x22);
+       app_setcolor(COL_LIT, 0xaa, 0xaa, 0xaa);
+       app_setcolor(COL_FRM_TEXT, 0xff, 0xff, 0xff);
+       app_setcolor(COL_FRM_BG, 0x6d, 0x2a, 0x83);
+       app_setcolor(COL_FRM_SHAD, 0x49, 0x26, 0x55);
+       app_setcolor(COL_FRM_LIT, 0xa1, 0x34, 0xc5);
 }
 
 
@@ -245,27 +266,6 @@ void rtk_invalfb(rtk_widget *w)
        app_invalidate(rect.x, rect.y, rect.width, rect.height);
 }
 
-void rtk_clearfb(rtk_widget *w)
-{
-       rtk_rect rect;
-
-       rect.x = w->x;
-       rect.y = w->y;
-       rect.width = w->width;
-       rect.height = w->height;
-
-       rtk_abs_pos(w, &rect.x, &rect.y);
-
-       if(w->type == RTK_WIN && (w->flags & FRAME)) {
-               rect.x -= WINFRM_SZ;
-               rect.y -= WINFRM_SZ + WINFRM_TBAR;
-               rect.width += WINFRM_SZ * 2;
-               rect.height += WINFRM_SZ * 2 + WINFRM_TBAR;
-       }
-
-       app_clear_rect(rect.x, rect.y, rect.width, rect.height);
-}
-
 static int need_relayout(rtk_widget *w)
 {
        rtk_widget *c;
@@ -408,13 +408,6 @@ void rtk_draw_widget(rtk_widget *w)
                w->drawcb(w, w->drawcls);
        }
 
-       if(w->flags & DBGRECT) {
-               rtk_rect r;
-               abs_widget_rect(w, &r);
-               uicolor(0xffff0000, 0xffff0000, 0xffff0000);
-               draw_frame(&r, FRM_SOLID, 1);
-       }
-
        if(dirty) {
                rtk_validate(w);
                rtk_invalfb(w);
@@ -437,19 +430,6 @@ static void abs_widget_rect(rtk_widget *w, rtk_rect *rect)
        rect->height = w->height;
 }
 
-#define COL_BG                                 0xff666666
-#define COL_BGHL                               0xff808080
-#define COL_LBEV                               0xffaaaaaa
-#define COL_SBEV                               0xff222222
-#define COL_TEXT                               0xff000000
-#define COL_WINFRM_FOCUS               0xff6688cc
-#define COL_WINFRM_LIT_FOCUS   0xff88aaff
-#define COL_WINFRM_SHAD_FOCUS  0xff224466
-#define COL_WINFRM                             0xff667788
-#define COL_WINFRM_LIT                 0xff8899aa
-#define COL_WINFRM_SHAD                        0xff224455
-#define COL_TBOX                               0xffeeccbb
-
 static void hline(int x, int y, int sz, uint32_t col)
 {
        rtk_rect rect;
@@ -470,17 +450,7 @@ static void vline(int x, int y, int sz, uint32_t col)
        gfx.fill(&rect, col);
 }
 
-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 sz)
+static void draw_frame(rtk_rect *rect, int type, int sz, uint32_t bgcol, uint32_t shad, uint32_t lit)
 {
        int i, tlcol, brcol, fillbg;
        rtk_rect r = *rect;
@@ -490,16 +460,16 @@ static void draw_frame(rtk_rect *rect, int type, int sz)
 
        switch(type) {
        case FRM_OUTSET:
-               tlcol = uicol[UICOL_LBEV];
-               brcol = uicol[UICOL_SBEV];
+               tlcol = lit;
+               brcol = shad;
                break;
        case FRM_INSET:
-               tlcol = uicol[UICOL_SBEV];
-               brcol = uicol[UICOL_LBEV];
+               tlcol = shad;
+               brcol = lit;
                break;
        case FRM_SOLID:
        default:
-               tlcol = brcol = uicol[UICOL_BG];
+               tlcol = brcol = bgcol;
        }
 
        for(i=0; i<sz; i++) {
@@ -517,7 +487,7 @@ static void draw_frame(rtk_rect *rect, int type, int sz)
        }
 
        if(fillbg) {
-               gfx.fill(&r, uicol[UICOL_BG]);
+               gfx.fill(&r, bgcol);
        }
 }
 
@@ -532,11 +502,11 @@ static void draw_window(rtk_widget *w)
                abs_widget_rect(w, &rect);
 
                if(w->flags & FRAME) {
-                       if(w->flags & FOCUS) {
+                       /*if(w->flags & FOCUS) {
                                uicolor(COL_WINFRM_FOCUS, COL_WINFRM_LIT_FOCUS, COL_WINFRM_SHAD_FOCUS);
                        } else {
                                uicolor(COL_WINFRM, COL_WINFRM_LIT, COL_WINFRM_SHAD);
-                       }
+                       }*/
 
                        frmrect = rect;
                        frmrect.width += WINFRM_SZ * 2;
@@ -549,14 +519,14 @@ static void draw_window(rtk_widget *w)
                        tbrect.width = rect.width;
                        tbrect.height = WINFRM_TBAR;
 
-                       draw_frame(&frmrect, FRM_OUTSET, 1);
+                       draw_frame(&frmrect, FRM_OUTSET, BEVELSZ, COL_FRM_BG, COL_FRM_SHAD, COL_FRM_LIT);
                        frmrect.x++;
                        frmrect.y++;
                        frmrect.width -= 2;
                        frmrect.height -= 2;
-                       draw_frame(&frmrect, FRM_INSET, 1);
+                       draw_frame(&frmrect, FRM_INSET, BEVELSZ, COL_FRM_BG, COL_FRM_SHAD, COL_FRM_LIT);
 
-                       draw_frame(&tbrect, FRM_OUTSET | FRM_FILLBG, 1);
+                       draw_frame(&tbrect, FRM_OUTSET | FRM_FILLBG, BEVELSZ, COL_FRM_BG, COL_FRM_SHAD, COL_FRM_LIT);
                        tbrect.x++;
                        tbrect.y++;
                        tbrect.width -= 2;
@@ -589,8 +559,9 @@ static void draw_label(rtk_widget *w)
 
 static void draw_button(rtk_widget *w)
 {
-       int pressed;
+       int pressed, flags;
        rtk_rect rect;
+       uint32_t col;
        rtk_button *bn = (rtk_button*)w;
 
        abs_widget_rect(w, &rect);
@@ -601,9 +572,10 @@ static void draw_button(rtk_widget *w)
                pressed = w->flags & PRESS;
        }
 
-       uicolor(w->flags & HOVER ? COL_BGHL : COL_BG, COL_LBEV, COL_SBEV);
+       col = w->flags & HOVER ? COL_BGHL : COL_BG;
+       flags = (pressed ? FRM_INSET : FRM_OUTSET) | FRM_FILLBG;
 
-       draw_frame(&rect, (pressed ? FRM_INSET : FRM_OUTSET) | FRM_FILLBG, 1);
+       draw_frame(&rect, flags, BEVELSZ, col, COL_SHAD, COL_LIT);
        rect.x++;
        rect.y++;
        rect.width -= 2;
@@ -629,9 +601,7 @@ static void draw_textbox(rtk_widget *w)
 
        abs_widget_rect(w, &rect);
 
-       uicolor(COL_TBOX, COL_LBEV, COL_SBEV);
-
-       draw_frame(&rect, FRM_INSET | FRM_FILLBG, w->flags & FOCUS ? 2 : 1);
+       draw_frame(&rect, FRM_INSET | FRM_FILLBG, BEVELSZ, COL_WHITE, COL_SHAD, COL_LIT);
 
        rect.x++;
        rect.y++;
@@ -650,7 +620,7 @@ static void draw_textbox(rtk_widget *w)
        if(w->flags & FOCUS) {
                int x = rect.x + PAD + curx - 1;
                int y = rect.y + rect.height - PAD - fontheight;
-               vline(x, y, fontheight, 0xff000000);
+               vline(x, y, fontheight, COL_TEXT);
        }
 
        rtk_invalfb(w);
@@ -667,8 +637,6 @@ static void draw_separator(rtk_widget *w)
 
        if(!win) return;
 
-       uicolor(COL_BG, COL_LBEV, COL_SBEV);
-
        abs_widget_rect(w, &rect);
 
        switch(win->layout) {
@@ -686,7 +654,7 @@ static void draw_separator(rtk_widget *w)
                break;
        }
 
-       draw_frame(&rect, FRM_INSET, 1);
+       draw_frame(&rect, FRM_INSET, BEVELSZ, COL_BG, COL_SHAD, COL_LIT);
 }
 
 static void draw_drawbox(rtk_widget *w)