Status/Draw: Draw rec/img/str/graph block in status function, remove ofset draw functions

This commit is contained in:
Martin Duquesnoy 2011-06-14 17:51:01 +02:00
parent 74281424da
commit 134bb3add4
6 changed files with 111 additions and 149 deletions

View File

@ -123,26 +123,6 @@ barwin_draw_text(BarWindow *bw, int x, int y, char *text)
return;
}
/** Draw text in a Barwindow
*/
void
barwin_draw_image_ofset_text(BarWindow *bw, int x, int y, char *text, int x_image_ofset, int y_image_ofset)
{
if(!text)
return;
/* Background color of the text if there is stipple */
if(bw->flags & StippleFlag)
draw_rectangle(bw->dr, x - 4, 0, textw(text) + 8, bw->geo.height, bw->bg);
/* Draw text */
draw_image_ofset_text(bw->dr, x, y, bw->fg, text, x_image_ofset, y_image_ofset);
barwin_refresh(bw);
return;
}
void
barwin_color_set(BarWindow *bw, uint bg, char *fg)
{

View File

@ -44,10 +44,9 @@ draw_image(Drawable dr, int x, int y, int w, int h, char *name)
{
Imlib_Image image;
if(!name)
if(!name || !dr)
return;
imlib_set_cache_size(2048 << 10);
imlib_context_set_display(dpy);
imlib_context_set_visual(DefaultVisual(dpy, DefaultScreen(dpy)));
imlib_context_set_colormap(DefaultColormap(dpy, DefaultScreen(dpy)));
@ -63,23 +62,45 @@ draw_image(Drawable dr, int x, int y, int w, int h, char *name)
h = imlib_image_get_height();
if(image)
{
imlib_render_image_on_drawable_at_size(x, y, w, h);
imlib_free_image();
}
else
warnx("Can't draw image: '%s'", name);
imlib_free_image();
return;
}
/** Check images blocks in str and return properties
* --> \i[x;y;w;h;name]\
*\param im ImageAttr pointer, image properties
*\param str String
*\return n Lenght of i
*/
static int
parse_image_block(Drawable dr, char *str)
{
ImageAttr im;
char as;
int i, j, k, sw = systray_get_width();
for(i = j = 0; i < (int)strlen(str); ++i, ++j)
if(sscanf(&str[i], "\\i[%d;%d;%d;%d;%512[^]]]%c", &im.x, &im.y, &im.w, &im.h, im.name, &as) == 6
&& as == '\\')
{
draw_image(dr, im.x - sw, im.y, im.w, im.h, im.name);
for(++i, --j; str[i] != as || str[i - 1] != ']'; ++i);
}
else if(j != i)
str[j] = str[i];
for(k = j; k < i; str[k++] = 0);
return;
}
#endif /* HAVE_IMLIB */
void
draw_text(Drawable d, int x, int y, char* fg, char *str)
{
draw_image_ofset_text(d, x, y, fg, str, 0, 0);
}
/** Draw a string in a Drawable
* \param d Drawable
* \param x X position
@ -89,13 +110,13 @@ draw_text(Drawable d, int x, int y, char* fg, char *str)
* \param str String that will be draw
*/
void
draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image_ofset, int y_image_ofset)
draw_text(Drawable d, int x, int y, char* fg, char *str)
{
#ifdef HAVE_IMLIB
char *ostr = NULL;
int i, ni, sw = 0;
ImageAttr im[128];
size_t textlen;
bool ii = False;
#else
(void)x_image_ofset;
(void)y_image_ofset;
@ -111,13 +132,8 @@ draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image
if(strstr(str, "i["))
{
ni = parse_image_block(im, str);
if(infobar[conf.systray.screen].bar && d == infobar[conf.systray.screen].bar->dr)
sw = systray_get_width();
for(i = 0; i < ni; ++i)
draw_image(d, x_image_ofset + im[i].x - sw, y_image_ofset + im[i].y, im[i].w, im[i].h, im[i].name);
parse_image_block(d, str);
ii = True;
}
#endif /* HAVE_IMLIB */
@ -151,7 +167,7 @@ draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image
#ifdef HAVE_IMLIB
if(strstr(ostr, "i["))
if(ii)
strncpy(str, ostr, textlen);
free(ostr);
@ -212,11 +228,12 @@ draw_graph(Drawable dr, int x, int y, int w, int h, uint color, char *data)
ushort
textw(char *text)
{
Drawable d = 0;
ushort ret = 0;
#ifdef HAVE_IMLIB
char *ostr = NULL;
ImageAttr im[128];
size_t textlen;
bool ii = False;
#endif /* HAVE_IMLIB */
if(!text)
@ -227,7 +244,10 @@ textw(char *text)
textlen = strlen(ostr);
if(strstr(text, "i["))
parse_image_block(im, text);
{
parse_image_block(d, text);
ii = True;
}
#endif /* HAVE_IMLIB */
#ifdef HAVE_XFT
@ -248,7 +268,7 @@ textw(char *text)
}
#ifdef HAVE_IMLIB
if(strstr(ostr, "i["))
if(ii)
strncpy(text, ostr, textlen);
free(ostr);

View File

@ -71,11 +71,11 @@ menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[], int chcklen)
x = (width - (chcklen + PAD / 3)) / 2 - textw(menu->item[item].name) / 2 + chcklen + PAD / 3;
break;
}
barwin_draw_image_ofset_text(winitem[item], x, FHINFOBAR, menu->item[item].name, chcklen + PAD / 2, 0);
barwin_draw_text(winitem[item], x, FHINFOBAR, menu->item[item].name);
if(menu->item[item].check)
if(menu->item[item].check(menu->item[item].cmd))
barwin_draw_image_ofset_text(winitem[item], PAD / 3, FHINFOBAR, conf.selected_layout_symbol, PAD / 3, 0);
barwin_draw_text(winitem[item], PAD / 3, FHINFOBAR, conf.selected_layout_symbol);
if(menu->item[item].submenu)
barwin_draw_text(winitem[item], width + PAD * 2, FHINFOBAR, ">");
@ -147,7 +147,7 @@ static bool
menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[])
{
int i, c = 0;
KeySym ks;
KeySym ks = 0;
bool quit = False;
char acc = 0;
@ -349,6 +349,8 @@ menu_draw(Menu menu, int x, int y)
XGrabKeyboard(dpy, ROOT, True, GrabModeAsync, GrabModeAsync, CurrentTime);
XNextEvent(dpy, &ev);
while(!menu_manage_event(&ev, &menu, item));
XUngrabKeyboard(dpy, CurrentTime);

View File

@ -32,102 +32,112 @@
#include "wmfs.h"
/** Check rectangles blocks in str and return properties
* --> \b[x;y;width;height;#color]\
*\param r StatusRec pointer, rectangles properties
*\param str String
*\return n Length of r
*/
static int
statustext_rectangle(StatusRec *r, char *str)
{
char as;
int n, i, j, k;
/* Systray width */
int sw = 0;
for(i = j = n = 0; i < (int)strlen(str); ++i, ++j)
if(sscanf(&str[i], "\\b[%d;%d;%d;%d;#%x]%c", &r[n].x, &r[n].y, &r[n].w, &r[n].h, &r[n].color, &as) == 6
/** Check rectangles blocks in str and draw it
* --> \b[x;y;width;height;#color]\
*\param ib Infobar pointer
*\param str String
*/
static void
statustext_rectangle(InfoBar *ib, char *str)
{
StatusRec r;
char as;
int i, j, k;
for(i = j = 0; i < (int)strlen(str); ++i, ++j)
if(sscanf(&str[i], "\\b[%d;%d;%d;%d;#%x]%c", &r.x, &r.y, &r.w, &r.h, &r.color, &as) == 6
&& as == '\\')
for(++n, ++i, --j; str[i] != as || str[i - 1] != ']'; ++i);
{
draw_rectangle(ib->bar->dr, r.x - sw, r.y, r.w, r.h, r.color);
for(++i, --j; str[i] != as || str[i - 1] != ']'; ++i);
}
else if(j != i)
str[j] = str[i];
for(k = j; k < i; str[k++] = 0);
for(k = j; k < i; str[k++] = '\0');
return n;
return;
}
/** Check graphs blocks in str and return properties
/** Check graphs blocks in str and draw it
* --> \g[x;y;width;height;#color;data]\
*\param g StatusGraph pointer, graphs properties
*\param ib Infobar pointer
*\param str String
*\return n Length of g
*/
static int
statustext_graph(StatusGraph *g, char *str)
static void
statustext_graph(InfoBar *ib, char *str)
{
StatusGraph g;
char as, c, *p;
int n, i, j, k, m, w;
int i, j, k, m, w;
for(i = j = n = 0; i < (int)strlen(str); ++i, ++j)
for(i = j = 0; i < (int)strlen(str); ++i, ++j)
if(sscanf(&str[i], "\\g[%d;%d;%d;%d;#%x;%512[^]]]%c",
&g[n].x, &g[n].y, &g[n].w, &g[n].h, &g[n].color, g[n].data, &as) == 7
&g.x, &g.y, &g.w, &g.h, &g.color, g.data, &as) == 7
&& as == '\\')
{
/* data is a list of numbers separated by ';' */
w = g[n].w;
p = strtok(g[n].data, ";");
w = g.w;
p = strtok(g.data, ";");
m = 0;
while(p && m < w)
for(c = atoi(p); p && m < w; ++m)
{
c = atoi(p);
/* height limits */
if(c < 0)
c = 0;
if(c > (char)g[n].h)
c = g[n].h;
g[n].data[m] = c;
if(c > (char)g.h)
c = g.h;
g.data[m] = c;
p = strtok(NULL, ";");
++m;
}
/* width limits */
for(; m < w; ++m)
g[n].data[m] = 0;
/* data is a array[w] of bytes now */
for(; m < w; g.data[m++] = 0);
for(++n, ++i, --j; str[i] != as || str[i - 1] != ']'; ++i);
/* data is a array[w] of bytes now */
draw_graph(ib->bar->dr, g.x - sw, g.y, g.w, g.h, g.color, g.data);
for(++i, --j; str[i] != as || str[i - 1] != ']'; ++i);
}
else if(j != i)
str[j] = str[i];
for(k = j; k < i; str[k++] = 0);
return n;
return;
}
/** Check text blocks in str and return properties
/** Check text blocks in str and draw it
* --> \s[x;y;#color;text]\
*\param s StatusText pointer, text properties
*\param ib Infobar pointer
*\param str String
*\return n Length of s
*/
static int
statustext_text(StatusText *s, char *str)
static void
statustext_text(InfoBar *ib, char *str)
{
StatusText s;
char as;
int n, i, j, k;
int i, j, k;
for(i = j = n = 0; i < (int)strlen(str); ++i, ++j)
if(sscanf(&str[i], "\\s[%d;%d;%7[^;];%512[^]]]%c", &s[n].x, &s[n].y, s[n].color, s[n].text, &as) == 5
for(i = j = 0; i < (int)strlen(str); ++i, ++j)
if(sscanf(&str[i], "\\s[%d;%d;%7[^;];%512[^]]]%c", &s.x, &s.y, s.color, s.text, &as) == 5
&& as == '\\')
for(++n, ++i, --j; str[i] != as || str[i - 1] != ']'; ++i);
{
draw_text(ib->bar->dr, s.x - sw, s.y, s.color, s.text);
for(++i, --j; str[i] != as || str[i - 1] != ']'; ++i);
}
else if(j != i)
str[j] = str[i];
for(k = j; k < i; str[k++] = 0);
return n;
return;
}
/** Draw normal text and colored normal text
@ -141,10 +151,7 @@ statustext_normal(int sc, char *str)
char strwc[MAXSTATUS] = { 0 };
char buf[MAXSTATUS] = { 0 };
char col[8] = { 0 };
int n, i, j, k, sw = 0;
if(sc == conf.systray.screen)
sw = systray_get_width();
int n, i, j, k;
for(i = j = n = 0; i < (int)strlen(str); ++i, ++j)
if(str[i] == '\\' && str[i + 1] == '#' && str[i + 8] == '\\')
@ -195,10 +202,7 @@ void
statustext_handle(int sc, char *str)
{
char *lastst;
int i, nr, ng, ns, sw = 0;
StatusRec r[128];
StatusGraph g[128];
StatusText s[128];
int i;
/* If the str == the current statustext, return (not needed) */
if(!str)
@ -215,25 +219,13 @@ statustext_handle(int sc, char *str)
infobar[sc].statustext = xstrdup(str);
/* Store rectangles, located text & images properties. */
nr = statustext_rectangle(r, str);
ng = statustext_graph(g, str);
ns = statustext_text(s, str);
statustext_rectangle(&infobar[sc], str);
statustext_graph(&infobar[sc], str);
statustext_text(&infobar[sc], str);
/* Draw normal text (and possibly colored with \#color\ blocks) */
statustext_normal(sc, str);
/* Draw rectangles with stored properties. */
for(i = 0; i < nr; ++i)
draw_rectangle(infobar[sc].bar->dr, r[i].x - sw, r[i].y, r[i].w, r[i].h, r[i].color);
/* Draw graphs with stored properties. */
for(i = 0; i < ng; ++i)
draw_graph(infobar[sc].bar->dr, g[i].x - sw, g[i].y, g[i].w, g[i].h, g[i].color, g[i].data);
/* Draw located text with stored properties. */
for(i = 0; i < ns; ++i)
draw_text(infobar[sc].bar->dr, s[i].x - sw, s[i].y, s[i].color, s[i].text);
barwin_refresh(infobar[sc].bar);
free(lastst);

View File

@ -279,32 +279,6 @@ uicb_spawn(uicb_t cmd)
return;
}
#ifdef HAVE_IMLIB
/** Check images blocks in str and return properties
* --> \i[x;y;w;h;name]\
*\param im ImageAttr pointer, image properties
*\param str String
*\return n Lenght of i
*/
int
parse_image_block(ImageAttr *im, char *str)
{
char as;
int n, i, j, k;
for(i = j = n = 0; i < (int)strlen(str); ++i, ++j)
if(sscanf(&str[i], "\\i[%d;%d;%d;%d;%512[^]]]%c", &im[n].x, &im[n].y, &im[n].w, &im[n].h, im[n].name, &as) == 6
&& as == '\\')
for(++n, ++i, --j; str[i] != as || str[i - 1] != ']'; ++i);
else if(j != i)
str[j] = str[i];
for(k = j; k < i; str[k++] = 0);
return n;
}
#endif /* HAVE_IMLIB */
char*
clean_value(char *str)
{

View File

@ -136,7 +136,6 @@ BarWindow *barwin_create(Window parent,
bool stipple,
bool border);
void barwin_draw_text(BarWindow *bw, int x, int y, char *text);
void barwin_draw_image_ofset_text(BarWindow *bw, int x, int y, char *text, int x_image_ofset, int y_image_ofset);
void barwin_color_set(BarWindow *bw, uint bg, char *fg);
void barwin_delete(BarWindow *bw);
void barwin_delete_subwin(BarWindow *bw);
@ -151,7 +150,6 @@ void barwin_refresh(BarWindow *bw);
/* draw.c */
void draw_text(Drawable d, int x, int y, char* fg, char *str);
void draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image_ofset, int y_image_ofset);
void draw_rectangle(Drawable dr, int x, int y, int w, int h, uint color);
void draw_graph(Drawable dr, int x, int y, int w, int h, uint color, char *data);
@ -318,10 +316,6 @@ char *clean_value(char *str);
char* patht(char *path);
int qsort_string_compare (const void * a, const void * b);
#ifdef HAVE_IMLIB
int parse_image_block(ImageAttr *im, char *str);
#endif /* HAVE_IMLIB */
/* tag.c */
void tag_set(int tag);
void tag_transfert(Client *c, int tag);