Add pixel offset

Add a formatting command to offset the text position by a pixel amount.
This commit is contained in:
Steven Allen 2014-03-01 13:31:27 -05:00
parent e9cdee9701
commit 2e2b32ac88
2 changed files with 44 additions and 9 deletions

View File

@ -76,6 +76,10 @@ Aligns the following text to the center of the screen.
Aligns the following text to the right side of the screen.
=item B<O>I<width>
Offset the current position by I<width> pixels in the alignment direction.
=item B<B>I<color>
Set the text background color. The parameter I<color> can be I<-> or a color in one of the formats mentioned before. The special value I<-> resets the color to the default one.

49
bar.c
View File

@ -101,10 +101,8 @@ fill_rect (xcb_drawable_t d, xcb_gcontext_t gc, int x, int y, int width, int hei
}
int
draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)
shift (monitor_t *mon, int x, int align, int ch_width)
{
int ch_width = cur_font->width_lut[ch - cur_font->char_min].character_width;
switch (align) {
case ALIGN_C:
xcb_copy_area(c, mon->pixmap, mon->pixmap, gc[GC_DRAW], mon->width / 2 - x / 2, 0,
@ -118,8 +116,33 @@ draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)
break;
}
/* Draw the background first */
fill_rect(mon->pixmap, gc[GC_CLEAR], x, by, ch_width, bh);
return x;
}
void
draw_lines (monitor_t *mon, int x, int w)
{
/* We can render both at the same time */
if (attrs & ATTR_OVERL)
fill_rect(mon->pixmap, gc[GC_ATTR], x, 0, w, bu);
if (attrs & ATTR_UNDERL)
fill_rect(mon->pixmap, gc[GC_ATTR], x, bh - bu, w, bu);
}
void
draw_shift (monitor_t *mon, int x, int align, int w)
{
x = shift(mon, x, align, w);
draw_lines(mon, x, w);
}
int
draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)
{
int ch_width = cur_font->width_lut[ch - cur_font->char_min].character_width;
x = shift(mon, x, align, ch_width);
/* xcb accepts string in UCS-2 BE, so swap */
ch = (ch >> 8) | (ch << 8);
@ -127,11 +150,7 @@ draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)
/* String baseline coordinates */
xcb_image_text_16(c, 1, mon->pixmap, gc[GC_DRAW], x, bh / 2 + cur_font->height / 2 - cur_font->descent, (xcb_char2b_t *)&ch);
/* We can render both at the same time */
if (attrs & ATTR_OVERL)
fill_rect(mon->pixmap, gc[GC_ATTR], x, 0, ch_width, bu);
if (attrs & ATTR_UNDERL)
fill_rect(mon->pixmap, gc[GC_ATTR], x, bh - bu, ch_width, bu);
draw_lines(mon, x, ch_width);
return ch_width;
}
@ -358,6 +377,7 @@ parse (char *text)
if (*p == '%' && p++ && *p == '{' && (end = strchr(p++, '}'))) {
while (p < end) {
int w;
while (isspace(*p))
p++;
@ -409,6 +429,17 @@ parse (char *text)
p++;
pos_x = 0;
break;
case 'O':
errno = 0;
w = (int) strtoul(p, &p, 10);
if (errno)
continue;
draw_shift(cur_mon, pos_x, align, w);
pos_x += w;
area_shift(cur_mon->window, align, w);
break;
/* In case of error keep parsing after the closing } */
default: