This commit is contained in:
Nathan Isom 2016-03-13 17:48:07 +00:00
commit 7026829e6c
2 changed files with 94 additions and 4 deletions

View File

@ -98,6 +98,16 @@ static rgba_t fgc, bgc, ugc;
static rgba_t dfgc, dbgc, dugc;
static area_stack_t area_stack;
// slant vars
static int slant;
static int right;
static int slant_width;
static int full_slant_width;
static int slant_counter;
static int upslant;
static int fg_height;
static int bg_height;
void
update_gc (void)
{
@ -186,7 +196,7 @@ xcb_void_cookie_t xcb_poly_text_16_simple(xcb_connection_t * c,
}
int
draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)
draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch, int slant)
{
int ch_width;
@ -209,10 +219,44 @@ draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)
x, bh);
x = mon->width - ch_width;
break;
}
// Draw the background first
fill_rect(mon->pixmap, gc[GC_CLEAR], x, 0, ch_width, bh);
if(slant_width)
{
if(!full_slant_width)
full_slant_width = slant_width * ch_width;
for(int i = 0; i < ch_width; i++)
{
slant_counter++;
if (right)
{
fg_height = (bh * (full_slant_width - slant_counter)) / full_slant_width;
bg_height = (slant_counter * bh) / full_slant_width;
}
else
{
fg_height = (slant_counter * bh) / full_slant_width;
bg_height = (bh * (full_slant_width - slant_counter)) / full_slant_width;
}
if (upslant)
bg_height *= -1;
else
fg_height *= -1;
fill_rect(mon->pixmap, gc[GC_DRAW], x+i, fg_height, 1, bh);
fill_rect(mon->pixmap, gc[GC_CLEAR], x+i, bg_height, 1, bh);
}
slant_width--;
}
else
{
fill_rect(mon->pixmap, gc[GC_CLEAR], x, 0, ch_width, bh);
}
// xcb accepts string in UCS-2 BE, so swap
ch = (ch >> 8) | (ch << 8);
@ -395,7 +439,7 @@ area_add (char *str, const char *optend, char **end, monitor_t *mon, const int x
}
if (area_stack.at + 1 > area_stack.max) {
fprintf(stderr, "Cannot add any more clickable areas (used %d/%d)\n",
fprintf(stderr, "Cannot add any more clickable areas (used %d/%d)\n",
area_stack.at, area_stack.max);
return false;
}
@ -522,6 +566,20 @@ parse (char *text)
case 'F': fgc = parse_color(p, &p, dfgc); update_gc(); break;
case 'U': ugc = parse_color(p, &p, dugc); update_gc(); break;
case 'E':
case 'e':
case 'D':
case 'd':
slant = *(p-1) - 'A'; // 4,36,5,37
slant_width = (*p++) - '0';
right = slant % 2;
full_slant_width = 0;
fg_height = 0;
bg_height = 0;
slant_counter = 0;
upslant = slant > 20 ? 1 : 0;
break;
case 'S':
if (*p == '+' && cur_mon->next)
{ cur_mon = cur_mon->next; }
@ -614,7 +672,7 @@ parse (char *text)
xcb_change_gc(c, gc[GC_DRAW] , XCB_GC_FONT, (const uint32_t []){ cur_font->ptr });
int w = draw_char(cur_mon, cur_font, pos_x, align, ucs);
int w = draw_char(cur_mon, cur_font, pos_x, align, ucs, slant);
pos_x += w;
area_shift(cur_mon->window, align, w);

32
slant_demo.sh Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
#
# demonstrate slant flags and what they look like
Len=2
geom=400x20+10+10
slant_fg='#a7a7a7'
slant_bg='#3e3e3e'
colors="%{F${slant_fg}}%{B${slant_bg}}"
invert="%{B${slant_fg}}%{F${slant_bg}}"
reset='%{B-}%{F-}'
space()
{
printf %${Len}s
}
slant()
{
echo -n "${colors}%{${1}${Len}}$(space)"
}
echo " \
${colors}%{E${Len}}$(space)${reset} - \
${colors}%{e${Len}}$(space)${reset} - \
${colors}%{D${Len}}$(space)${reset} - \
${colors}%{d${Len}}$(space)${reset} \
\
$(slant d)${invert}slants$(slant E)${reset}and$(slant d)${invert}shit$(slant E)" \
| ./lemonbar -g $geom -p -B "$slant_bg" -F "$slant_fg"