Merge pull request #170 from Stebalien/pixel-offset

Pixel Offset
This commit is contained in:
TheLemonMan 2016-04-23 08:24:09 +02:00
commit ae5a3a477a
2 changed files with 46 additions and 12 deletions

View File

@ -89,6 +89,10 @@ Aligns the following text to the center of the screen.
Aligns the following text to the right side 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> =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. 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.

View File

@ -186,14 +186,8 @@ xcb_void_cookie_t xcb_poly_text_16_simple(xcb_connection_t * c,
} }
int 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;
ch_width = (cur_font->width_lut) ?
cur_font->width_lut[ch - cur_font->char_min].character_width:
cur_font->width;
switch (align) { switch (align) {
case ALIGN_C: case ALIGN_C:
xcb_copy_area(c, mon->pixmap, mon->pixmap, gc[GC_DRAW], xcb_copy_area(c, mon->pixmap, mon->pixmap, gc[GC_DRAW],
@ -213,6 +207,34 @@ draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)
// Draw the background first // Draw the background first
fill_rect(mon->pixmap, gc[GC_CLEAR], x, 0, ch_width, bh); fill_rect(mon->pixmap, gc[GC_CLEAR], x, 0, 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) ?
cur_font->width_lut[ch - cur_font->char_min].character_width:
cur_font->width;
x = shift(mon, x, align, ch_width);
// xcb accepts string in UCS-2 BE, so swap // xcb accepts string in UCS-2 BE, so swap
ch = (ch >> 8) | (ch << 8); ch = (ch >> 8) | (ch << 8);
@ -222,11 +244,7 @@ draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)
x, bh / 2 + cur_font->height / 2 - cur_font->descent, x, bh / 2 + cur_font->height / 2 - cur_font->descent,
1, &ch); 1, &ch);
// We can render both at the same time draw_lines(mon, x, ch_width);
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);
return ch_width; return ch_width;
} }
@ -490,6 +508,7 @@ parse (char *text)
if (p[0] == '%' && p[1] == '{' && (block_end = strchr(p++, '}'))) { if (p[0] == '%' && p[1] == '{' && (block_end = strchr(p++, '}'))) {
p++; p++;
while (p < block_end) { while (p < block_end) {
int w;
while (isspace(*p)) while (isspace(*p))
p++; p++;
@ -542,6 +561,17 @@ parse (char *text)
p++; p++;
pos_x = 0; pos_x = 0;
break; 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;
case 'T': case 'T':
if (*p == '-') { //Reset to automatic font selection if (*p == '-') { //Reset to automatic font selection