1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-09-29 13:39:10 +00:00

Use coordinate offsets to draw shades/outlines. Corrects behavior when GOTO-ing. (#287)

This commit is contained in:
Ovnuniarchos 2016-07-14 18:45:06 +02:00 committed by Brenden Matthews
parent d621199883
commit e2bd14e7b7

View File

@ -422,6 +422,7 @@ struct _x11_stuff_s {
/* text size */
static int text_start_x, text_start_y; /* text start position in window */
static int text_offset_x, text_offset_y; /* offset for start position */
static int text_width = 1, text_height = 1; /* initially 1 so no zero-sized window is created */
#endif /* BUILD_X11 */
@ -1372,20 +1373,20 @@ static void draw_string(const char *s)
c2.color.alpha = fonts[selected_font].font_alpha;
if (utf8_mode.get(*state)) {
XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
cur_x, cur_y, (const XftChar8 *) s, strlen(s));
text_offset_x + cur_x, text_offset_y + cur_y, (const XftChar8 *) s, strlen(s));
} else {
XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
cur_x, cur_y, (const XftChar8 *) s, strlen(s));
text_offset_x + cur_x, text_offset_y + cur_y, (const XftChar8 *) s, strlen(s));
}
} else
#endif
{
if (utf8_mode.get(*state)) {
Xutf8DrawString(display, window.drawable, fonts[selected_font].fontset, window.gc, cur_x, cur_y, s,
strlen(s));
Xutf8DrawString(display, window.drawable, fonts[selected_font].fontset, window.gc,
text_offset_x + cur_x, text_offset_y + cur_y, s, strlen(s));
} else {
XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
strlen(s));
XDrawString(display, window.drawable, window.gc,
text_offset_x + cur_x, text_offset_y + cur_y, s, strlen(s));
}
}
cur_x += width_of_s;
@ -1443,8 +1444,8 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
XSetLineAttributes(display, window.gc, h, LineSolid,
CapButt, JoinMiter);
XDrawLine(display, window.drawable, window.gc, cur_x,
cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
XDrawLine(display, window.drawable, window.gc, text_offset_x + cur_x,
text_offset_y + cur_y - mid / 2, text_offset_x + cur_x + w, text_offset_y + cur_y - mid / 2);
break;
}
@ -1459,8 +1460,8 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
XSetLineAttributes(display, window.gc, h, LineOnOffDash,
CapButt, JoinMiter);
XSetDashes(display, window.gc, 0, ss, 2);
XDrawLine(display, window.drawable, window.gc, cur_x,
cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
XDrawLine(display, window.drawable, window.gc, text_offset_x + cur_x,
text_offset_y + cur_y - mid / 2, text_offset_x + cur_x + w, text_offset_x + cur_y - mid / 2);
break;
}
@ -1490,10 +1491,10 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
XSetLineAttributes(display, window.gc, 1, LineSolid,
CapButt, JoinMiter);
XDrawRectangle(display, window.drawable, window.gc, cur_x,
by, w, h);
XFillRectangle(display, window.drawable, window.gc, cur_x,
by, w * bar_usage / scale, h);
XDrawRectangle(display, window.drawable, window.gc, text_offset_x + cur_x,
text_offset_y + by, w, h);
XFillRectangle(display, window.drawable, window.gc, text_offset_x + cur_x,
text_offset_y + by, w * bar_usage / scale, h);
if (h > cur_y_add
&& h > font_h) {
cur_y_add = h;
@ -1532,7 +1533,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
CapButt, JoinMiter);
XDrawArc(display, window.drawable, window.gc,
cur_x, by, w, h * 2, 0, 180*64);
text_offset_x + cur_x, text_offset_y + by, w, h * 2, 0, 180*64);
#ifdef BUILD_MATH
usage = current->arg;
@ -1542,7 +1543,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
py = (float)(by+(h))-(float)(h)*sin(angle);
XDrawLine(display, window.drawable, window.gc,
cur_x + (w/2.), by+(h), (int)(px), (int)(py));
text_offset_x + cur_x + (w/2.), text_offset_y + by+(h), text_offset_x + (int)(px), text_offset_y + (int)(py));
#endif /* BUILD_MATH */
if (h > cur_y_add
@ -1586,7 +1587,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
XSetLineAttributes(display, window.gc, 1, LineSolid,
CapButt, JoinMiter);
XDrawRectangle(display, window.drawable, window.gc,
cur_x, by, w, h);
text_offset_x + cur_x, text_offset_y + by, w, h);
}
XSetLineAttributes(display, window.gc, 1, LineSolid,
CapButt, JoinMiter);
@ -1633,8 +1634,8 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
}
/* this is mugfugly, but it works */
XDrawLine(display, window.drawable, window.gc,
cur_x + i + 1, by + h, cur_x + i + 1,
round_to_int((double)by + h - current->graph[j] *
text_offset_x + cur_x + i + 1, text_offset_y + by + h, text_offset_x + cur_x + i + 1,
text_offset_y + round_to_int((double)by + h - current->graph[j] *
(h - 1) / current->scale));
++j;
}
@ -1897,7 +1898,7 @@ static void draw_text(void)
int offset = border_inner_margin.get(*state) + bw;
XDrawRectangle(display, window.drawable, window.gc,
text_start_x - offset, text_start_y - offset,
text_offset_x + text_start_x - offset, text_offset_y + text_start_y - offset,
text_width + 2*offset, text_height + 2*offset);
}
@ -1919,6 +1920,7 @@ static void draw_text(void)
static void draw_stuff(void)
{
text_offset_x = text_offset_y = 0;
#ifdef BUILD_IMLIB2
cimlib_render(text_start_x, text_start_y, window.width, window.height);
#endif /* BUILD_IMLIB2 */
@ -1937,33 +1939,28 @@ static void draw_stuff(void)
if (out_to_x.get(*state)) {
selected_font = 0;
if (draw_shades.get(*state) && !draw_outline.get(*state)) {
text_start_x++;
text_offset_x = text_offset_y = 1;
text_start_y++;
set_foreground_color(default_shade_color.get(*state));
draw_mode = BG;
draw_text();
text_start_x--;
text_start_y--;
text_offset_x = text_offset_y = 0;
}
if (draw_outline.get(*state)) {
int i, j;
selected_font = 0;
for (i = -1; i < 2; i++) {
for (j = -1; j < 2; j++) {
if (i == 0 && j == 0) {
for (text_offset_x = -1; text_offset_x < 2; text_offset_x++) {
for (text_offset_y = -1; text_offset_y < 2; text_offset_y++) {
if (text_offset_x == 0 && text_offset_y == 0) {
continue;
}
text_start_x += i;
text_start_y += j;
set_foreground_color(default_outline_color.get(*state));
draw_mode = OUTLINE;
draw_text();
text_start_x -= i;
text_start_y -= j;
}
}
text_offset_x = text_offset_y = 0;
}
set_foreground_color(default_color.get(*state));