swk

static widget kit
git clone git://git.suckless.org/swk
Log | Files | Refs | README | LICENSE

commit cac5b29726e7921c332a8428fad7d141d30fdfa8
parent 428895db9fe578899db0efdc588a01b54224c4fb
Author: pancake <pancake@nopcode.org>
Date:   Tue, 24 Aug 2010 23:14:10 +0200

add CCCOLOR for Current Column Color
fill the background of some widgets with ColorBG
fix text height in SDL rendering
update config.def.h
Diffstat:
config.def.h | 9+++++----
gi_sdl.c | 13+++++++++++--
gi_x11.c | 6+++++-
swk.c | 51+++++++++++++++++++++++++++++++++++++++++++--------
swk.h | 2+-
t/test.c | 2+-
6 files changed, 66 insertions(+), 17 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -8,16 +8,17 @@ #define WINWIDTH 640 #define WINHEIGHT 480 #define TOUCHSCREEN 0 -#ifdef FG -#define SWK_COLOR(r,g,b) 0x##r##g##b -#else +#ifdef USE_SDL #define SWK_COLOR(r,g,b) 0x##r,0x##g,0x##b +#else +#define SWK_COLOR(r,g,b) 0x##r##g##b #endif #define HICOLOR SWK_COLOR(00,66,ff) -#define BGCOLOR SWK_COLOR(20,20,20) +#define BGCOLOR SWK_COLOR(10,10,10) #define FGCOLOR SWK_COLOR(e0,e0,e0) #define TFCOLOR SWK_COLOR(cc,cc,cc) +#define CCCOLOR SWK_COLOR(20,20,20) /* key bindings */ static SwkKeyBind keys[] = { diff --git a/gi_sdl.c b/gi_sdl.c @@ -17,6 +17,8 @@ static int fs = FONTSIZE; static Uint32 pal[ColorLast]; static SDL_Color fontcolor = { TFCOLOR }; static SDL_Color bgcolor = { BGCOLOR }; +static SDL_Color tfcolor = { TFCOLOR }; +static SDL_Color cccolor = { CCCOLOR }; static SDL_Surface *screen = NULL; static TTF_Font *font = NULL; /* FIXME: put ugly statics into void *aux of SwkWindow ? */ @@ -91,6 +93,8 @@ swk_gi_init(SwkWindow *w) { pal[ColorFG] = SDL_MapRGB(screen->format, FGCOLOR); pal[ColorBG] = SDL_MapRGB(screen->format, BGCOLOR); pal[ColorHI] = SDL_MapRGB(screen->format, HICOLOR); + pal[ColorTF] = SDL_MapRGB(screen->format, TFCOLOR); + pal[ColorCC] = SDL_MapRGB(screen->format, CCCOLOR); return swk_gi_fontsize(0); } @@ -256,6 +260,10 @@ swk_gi_fill(Rect r, int color, int lil) { area.y+=4; area.w/=4; area.h-=4; + } else if (lil==3) { + const int s = fs/4; + area.w -= (s*2); + area.h -= (s*4); } if(!area.w) area.w = 1; if(!area.h) area.h = 1; @@ -283,8 +291,9 @@ swk_gi_text(Rect r, const char *text) { } SDL_Surface *ts = TTF_RenderText_Shaded(font, tptr, fontcolor, bgcolor); if(ts) { - SDL_Rect to = { (r.x)*fs, r.y*fs, ts->w, ts->h }; - SDL_BlitSurface(ts, NULL, screen, &to); + SDL_Rect from = { 0, 4, ts->w, ts->h-2 }; + SDL_Rect to = { (r.x)*fs, 2+r.y*fs, ts->w, ts->h-4 }; + SDL_BlitSurface(ts, &from, screen, &to); SDL_FreeSurface(ts); } else fprintf(stderr, "Cannot render string (%s)\n", text); } diff --git a/gi_x11.c b/gi_x11.c @@ -21,7 +21,7 @@ static Window window; static XWindowAttributes wa; static DC *dc = NULL; static int col[ColorLast]; -static int colors[ColorLast] = { FGCOLOR, BGCOLOR, HICOLOR, TFCOLOR }; +static int colors[ColorLast] = { FGCOLOR, BGCOLOR, HICOLOR, TFCOLOR, CCCOLOR }; #define EVENTMASK PointerMotionMask | ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask int @@ -223,6 +223,10 @@ swk_gi_fill(Rect r, int color, int lil) { area.width/=4; area.y+=4; area.height-=4; + } else if (lil==3) { + const int s = fs/4; + area.width -= (s*2); + area.height -= (s*4); } if(area.width<1) area.width = 1; if(area.height<1) area.height = 1; diff --git a/swk.c b/swk.c @@ -28,6 +28,31 @@ swk_use(SwkWindow *win) { return 1; } +// TODO: merge with clean() +void +drawcol(SwkWindow *w) { + Rect r = {0}; + r.h = 1; + if (!w->boxes[1]) { + r.x = 0; + r.y = 0; + r.w = w->r.w+2; + r.h = w->r.h+2; + } else + if (!w->col) { + r.x = 0; + r.y = 0; + r.w = w->colpos; + r.h = w->r.h+2; + } else { + r.x = w->colpos; + r.y = 0; + r.w = 100; + r.h = w->r.h+2; + } + swk_gi_fill(r, ColorCC, 0); +} + void swk_update() { char text[8]; @@ -51,6 +76,7 @@ swk_update() { count--; col = w->r.w; } + drawcol(w); for(w->r.w=col; ; b = w->boxes[1]) { swk_fit(w); roy = oy = 0; @@ -68,7 +94,8 @@ swk_update() { r.w = 3; sprintf(text, "(%d)", scroll); swk_gi_text(r, text); - swk_gi_line(--r.x, roy, 2, 0, ColorHI); + //swk_gi_line(--r.x, roy, 2, 0, ColorHI); + swk_gi_line((b==w->boxes[0])?w->colpos:0, roy, w->r.w, 0, ColorHI); } else b->cb(&w->_e); oy = b->r.y; } @@ -343,6 +370,7 @@ swk_password(SwkEvent *e) { switch(e->type) { case EExpose: r = e->box->r; + swk_gi_fill(r, ColorBG, 1); if(e->win->box == e->box) swk_gi_line(r.x, r.y+1, r.w, 0, ColorHI); len = strlen(e->box->text); @@ -401,6 +429,7 @@ swk_entry(SwkEvent *e) { len = 3*e->box->r.x; len += strlen(e->box->text)+1; #endif + swk_gi_fill(e->box->r, ColorBG, 1); swk_label(e); { Rect r = {len, e->box->r.y, 1, 1 }; @@ -416,11 +445,12 @@ swk_button(SwkEvent *e) { switch(e->type) { case EExpose: r = e->box->r; - r.x++; - swk_gi_text(r, e->box->text); - r.x--; r.w--; + swk_gi_fill(r, ColorBG, 0); swk_gi_rect(r, BORDERCOLOR); + r = e->box->r; + r.x++; + swk_gi_text(r, e->box->text); break; default: break; @@ -434,13 +464,16 @@ swk_bigbutton(SwkEvent *e) { case EExpose: e->box->r.h = 3; r = e->box->r; - r.x += 2; - r.y++; - swk_gi_text(r, e->box->text); r.x--; r.y--; r.w--; + r = e->box->r; + swk_gi_fill(r, ColorBG, 0); swk_gi_rect(r, BORDERCOLOR); + r = e->box->r; + r.x += 2; + r.y++; + swk_gi_text(r, e->box->text); break; default: break; @@ -501,6 +534,7 @@ swk_progress(SwkEvent *e) { switch(e->type) { case EExpose: r = e->box->r; + swk_gi_fill(r, ColorBG, 0); r.x+=1; swk_gi_text(r, e->box->text); r.x-=1; @@ -535,7 +569,8 @@ swk_image(SwkEvent *e) { } switch(e->type) { case EExpose: - swk_gi_rect(e->box->r, ColorFG); + swk_gi_img(e->box->r, e->box->data); +// swk_gi_rect(e->box->r, ColorFG); if(e->win->box == e->box) { Rect r = e->box->r; swk_gi_line(r.x, r.y+1, r.w, 0, ColorHI); diff --git a/swk.h b/swk.h @@ -7,7 +7,7 @@ typedef enum { EVoid, EClick, EMotion, EKey, EExpose, EQuit, ELast } SwkEventType; typedef enum { Shift=1, Ctrl=2, Alt=4, Meta=8 } SwkKeyMod; -typedef enum { ColorFG, ColorBG, ColorHI, ColorTF, ColorLast } Palete; +typedef enum { ColorFG, ColorBG, ColorHI, ColorTF, ColorCC, ColorLast } Palete; typedef enum { KUp=0xe0, KDown=0xe1, KLeft=0xe2, KRight=0xe3 } SwkKeyCode; typedef struct SwkBox SwkBox; diff --git a/t/test.c b/t/test.c @@ -130,7 +130,7 @@ static SwkBox helloworld[] = { { .cb=swk_image, .text="image.png" }, { .cb=swk_image, .text="image.png" }, { .cb=swk_filler, }, - SWK_BOX_NEWLINE(2), + SWK_BOX_NEWLINE(3), { .cb=mybutton, .text="yes" }, { .cb=mybutton, .text="no" }, { .cb=swk_filler, },