Added underlining support.

This commit is contained in:
LemonBoy 2012-07-20 16:28:12 +02:00
parent 054ee4396f
commit 741b9da4a1
3 changed files with 22 additions and 15 deletions

View File

@ -41,6 +41,7 @@ To draw a backslash just backslash escape it (\\\\).
``` ```
f<0-9> Selects the text foreground color from the palette. f<0-9> Selects the text foreground color from the palette.
b<0-9> Selects the text background color from the palette. b<0-9> Selects the text background color from the palette.
u<0-9> Selects the underline color from the palette.
To reset the bg/fg color just pass 'r' as color index. To reset the bg/fg color just pass 'r' as color index.
l Aligns the text to the left. l Aligns the text to the left.

14
bar.c
View File

@ -13,12 +13,12 @@
// Here be dragons // Here be dragons
static xcb_connection_t *c; static xcb_connection_t *c;
static int font_height, font_width, font_descent;
static xcb_window_t root, win; static xcb_window_t root, win;
static xcb_gcontext_t gc; static xcb_gcontext_t gc;
static xcb_drawable_t canvas;
static int font_height, font_width, font_descent;
static int bar_width; static int bar_width;
static const uint32_t pal[] = {COLOR0,COLOR1,COLOR2,COLOR3,COLOR4,COLOR5,COLOR6,COLOR7,COLOR8,COLOR9}; static const uint32_t pal[] = {COLOR0,COLOR1,COLOR2,COLOR3,COLOR4,COLOR5,COLOR6,COLOR7,COLOR8,COLOR9};
static xcb_drawable_t canvas;
#define MIN(a,b) ((a > b ? b : a)) #define MIN(a,b) ((a > b ? b : a))
@ -38,7 +38,7 @@ wcslen_ (wchar_t *s) {
} }
int int
draw_string (int x, int align, int fgcol, int bgcol, wchar_t *text) draw_string (int x, int align, int fgcol, int bgcol, int udcol, wchar_t *text)
{ {
int done = 0; int done = 0;
int pos_x = x; int pos_x = x;
@ -61,6 +61,8 @@ draw_string (int x, int align, int fgcol, int bgcol, wchar_t *text)
} }
/* Draw the background first */ /* Draw the background first */
fill_rect (bgcol, pos_x, 0, strw, BAR_HEIGHT); fill_rect (bgcol, pos_x, 0, strw, BAR_HEIGHT);
/* Draw the underline */
if (BAR_UNDERLINE_HEIGHT) fill_rect (udcol, pos_x, BAR_HEIGHT-BAR_UNDERLINE_HEIGHT, strw, BAR_UNDERLINE_HEIGHT);
/* Setup the colors */ /* Setup the colors */
xcb_change_gc (c, gc, XCB_GC_FOREGROUND, (const uint32_t []){ pal[fgcol] }); xcb_change_gc (c, gc, XCB_GC_FOREGROUND, (const uint32_t []){ pal[fgcol] });
xcb_change_gc (c, gc, XCB_GC_BACKGROUND, (const uint32_t []){ pal[bgcol] }); xcb_change_gc (c, gc, XCB_GC_BACKGROUND, (const uint32_t []){ pal[bgcol] });
@ -87,16 +89,18 @@ parse (char *text)
int fgcol = 1; int fgcol = 1;
int bgcol = 0; int bgcol = 0;
int udcol = 0;
fill_rect (0, 0, 0, bar_width, BAR_HEIGHT); fill_rect (0, 0, 0, bar_width, BAR_HEIGHT);
for (;;) { for (;;) {
if (*p == 0x0 || *p == 0xA || (*p == '\\' && p++ && *p != '\\' && strchr ("fblcr", *p))) { if (*p == 0x0 || *p == 0xA || (*p == '\\' && p++ && *p != '\\' && strchr ("fbulcr", *p))) {
pos_x += draw_string (pos_x, align, fgcol, bgcol, parsed_text); pos_x += draw_string (pos_x, align, fgcol, bgcol, udcol, parsed_text);
switch (*p++) { switch (*p++) {
case 0x0: return; /* EOL */ case 0x0: return; /* EOL */
case 0xA: return; /* NL */ case 0xA: return; /* NL */
case 'f': if (*p == 'r') *p = '1'; if (isdigit (*p)) { fgcol = *p-'0'; } p++; break; case 'f': if (*p == 'r') *p = '1'; if (isdigit (*p)) { fgcol = *p-'0'; } p++; break;
case 'b': if (*p == 'r') *p = '0'; if (isdigit (*p)) { bgcol = *p-'0'; } p++; break; case 'b': if (*p == 'r') *p = '0'; if (isdigit (*p)) { bgcol = *p-'0'; } p++; break;
case 'u': if (*p == 'r') *p = '0'; if (isdigit (*p)) { udcol = *p-'0'; } p++; break;
case 'l': align = 0; pos_x = 0; break; case 'l': align = 0; pos_x = 0; break;
case 'c': align = 1; pos_x = 0; break; case 'c': align = 1; pos_x = 0; break;
case 'r': align = 2; pos_x = 0; break; case 'r': align = 2; pos_x = 0; break;

View File

@ -1,13 +1,15 @@
#define BAR_HEIGHT 18 #define BAR_HEIGHT 18
#define BAR_UNDERLINE_HEIGHT 2
#define BAR_FONT "-*-terminus-medium-r-normal-*-12-*-*-*-c-*-*-1" #define BAR_FONT "-*-terminus-medium-r-normal-*-12-*-*-*-c-*-*-1"
#define COLOR0 0x262729 /* background */ #define COLOR0 0x1A1A1A /* background */
#define COLOR1 0xebebeb /* foreground */ #define COLOR1 0xA9A9A9 /* foreground */
#define COLOR2 0x262729 #define COLOR2 0x303030
#define COLOR3 0xf92671 #define COLOR3 0xF92672
#define COLOR4 0xa6e22e #define COLOR4 0xA6E22E
#define COLOR5 0xfd971f #define COLOR5 0xFD971F
#define COLOR6 0x34bdef #define COLOR6 0x66D9EF
#define COLOR7 0x9e6ffe #define COLOR7 0x9E6FFE
#define COLOR8 0x5e7175 #define COLOR8 0xAF875F
#define COLOR9 0xccccc6 #define COLOR9 0xCCCCC6