[hackers] [swk] add CCCOLOR for Current Column Color || pancake

From: <hg_AT_suckless.org>
Date: Tue, 24 Aug 2010 21:17:33 +0000 (UTC)

changeset: 65:1c88f618843c
tag: tip
user: pancake <pancake_AT_nopcode.org>
date: Tue Aug 24 23:14:10 2010 +0200
files: config.def.h gi_sdl.c gi_x11.c swk.c swk.h t/test.c
description:
add CCCOLOR for Current Column Color
fill the background of some widgets with ColorBG
fix text height in SDL rendering
update config.def.h

diff -r 39801049cfcd -r 1c88f618843c config.def.h
--- a/config.def.h Tue Aug 24 22:06:11 2010 +0200
+++ b/config.def.h Tue Aug 24 23:14:10 2010 +0200
@@ -8,16 +8,17 @@
 #define WINWIDTH 640
 #define WINHEIGHT 480
 #define TOUCHSCREEN 0
-#ifdef FG
+#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
-#else
-#define SWK_COLOR(r,g,b) 0x##r,0x##g,0x##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 -r 39801049cfcd -r 1c88f618843c gi_sdl.c
--- a/gi_sdl.c Tue Aug 24 22:06:11 2010 +0200
+++ b/gi_sdl.c Tue Aug 24 23:14:10 2010 +0200
@@ -17,6 +17,8 @@
 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 @@
         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 @@
                 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 @@
                 }
                 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 -r 39801049cfcd -r 1c88f618843c gi_x11.c
--- a/gi_x11.c Tue Aug 24 22:06:11 2010 +0200
+++ b/gi_x11.c Tue Aug 24 23:14:10 2010 +0200
@@ -21,7 +21,7 @@
 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 @@
                 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 -r 39801049cfcd -r 1c88f618843c swk.c
--- a/swk.c Tue Aug 24 22:06:11 2010 +0200
+++ b/swk.c Tue Aug 24 23:14:10 2010 +0200
@@ -28,6 +28,31 @@
         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 @@
                         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 @@
                                         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 @@
         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 @@
                 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 @@
         switch(e->type) {
         case EExpose:
                 r = e->box->r;
+ 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);
- r.x--;
- r.w--;
- swk_gi_rect(r, BORDERCOLOR);
                 break;
         default:
                 break;
@@ -434,13 +464,16 @@
         case EExpose:
                 e->box->r.h = 3;
                 r = e->box->r;
+ 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);
- r.x--;
- r.y--;
- r.w--;
- swk_gi_rect(r, BORDERCOLOR);
                 break;
         default:
                 break;
@@ -501,6 +534,7 @@
         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 @@
         }
         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 -r 39801049cfcd -r 1c88f618843c swk.h
--- a/swk.h Tue Aug 24 22:06:11 2010 +0200
+++ b/swk.h Tue Aug 24 23:14:10 2010 +0200
@@ -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 -r 39801049cfcd -r 1c88f618843c t/test.c
--- a/t/test.c Tue Aug 24 22:06:11 2010 +0200
+++ b/t/test.c Tue Aug 24 23:14:10 2010 +0200
@@ -130,7 +130,7 @@
         { .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, },
Received on Tue Aug 24 2010 - 23:17:33 CEST

This archive was generated by hypermail 2.2.0 : Tue Aug 24 2010 - 23:24:04 CEST