diff --git a/src/draw.c b/src/draw.c index f5c6a85..5e5e41f 100644 --- a/src/draw.c +++ b/src/draw.c @@ -109,6 +109,32 @@ draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color) return; } +/** Draw a Graph in a drawable + * \param dr Drawable + * \param x X position + * \param y Y position + * \param w Width + * \param h Height + * \param color Color of the graph + * \param data Array of bytes that will be draw +*/ +void +draw_graph(Drawable dr, int x, int y, uint w, uint h, uint color, char *data) +{ + int i; + + XSetForeground(dpy, gc, color); + + for(i = 0; i < w; ++i) + { + XRectangle r = { (x + i), (y + h - data[i]), 1, data[i] }; + + XFillRectangles(dpy, dr, gc, &r, 1); + } + + return; +} + #ifdef HAVE_IMLIB /** Draw an image in a drawable * \param dr Drawable diff --git a/src/menu.c b/src/menu.c index bde9cd6..6ad1a55 100644 --- a/src/menu.c +++ b/src/menu.c @@ -319,7 +319,6 @@ uicb_menu(uicb_t cmd) void menu_clear(Menu *menu) { - /*menu->item = emalloc(sizeof(MenuItem), nitem);*/ IFREE(menu->item); menu->nitem = 0; diff --git a/src/status.c b/src/status.c index ef6164d..5ac3d13 100644 --- a/src/status.c +++ b/src/status.c @@ -56,6 +56,56 @@ statustext_rectangle(StatusRec *r, char *str) return n; } +/** Check graphs blocks in str and return properties + * --> \g[x;y;width;height;#color;data]\ + *\param g StatusGraph pointer, graphs properties + *\param str String + *\return n Length of g + */ +int +statustext_graph(StatusGraph *g, char *str) +{ + char as, c, *p; + int n, i, j, k, m, w; + + for(i = j = n = 0; i < 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 + && as == '\\') + { + /* data is a list of numbers separated by ';' */ + w = g[n].w; + p = strtok(g[n].data, ";"); + m = 0; + + while(p && m < w) + { + c = atoi(p); + /* height limits */ + if(c < 0) + c = 0; + if(c > g[n].h) + c = g[n].h; + g[n].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(++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; +} + /** Check text blocks in str and return properties * --> \s[x;y;#color;text]\ *\param s StatusText pointer, text properties @@ -142,8 +192,9 @@ void statustext_handle(int sc, char *str) { char *lastst; - int i, nr, ns, len; + int i, nr, ng, ns, len; StatusRec r[128]; + StatusGraph g[128]; StatusText s[128]; /* If the str == the current statustext, return (not needed) */ @@ -160,6 +211,7 @@ statustext_handle(int sc, char *str) /* Store rectangles, located text & images properties. */ nr = statustext_rectangle(r, str); + ng = statustext_graph(g, str); ns = statustext_text(s, str); /* Draw normal text (and possibly colored with \#color\ blocks) */ @@ -169,6 +221,10 @@ statustext_handle(int sc, char *str) for(i = 0; i < nr; ++i) draw_rectangle(infobar[sc].bar->dr, r[i].x, 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, 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, s[i].y, s[i].color, 0, s[i].text); diff --git a/src/structs.h b/src/structs.h index 4f123b5..cc86600 100644 --- a/src/structs.h +++ b/src/structs.h @@ -444,6 +444,13 @@ typedef struct uint color; } StatusRec; +typedef struct +{ + uint x, y, w, h; + uint color; + char data[512]; +} StatusGraph; + typedef struct { uint x, y; diff --git a/src/wmfs.h b/src/wmfs.h index 088b662..38ae281 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -133,6 +133,7 @@ void barwin_refresh(BarWindow *bw); /* draw.c */ void draw_text(Drawable d, int x, int y, char* fg, int pad, char *str); void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color); +void draw_graph(Drawable dr, int x, int y, uint w, uint h, uint color, char *data); #ifdef HAVE_IMLIB void draw_image(Drawable dr, int x, int y, int w, int h, char *name); @@ -314,6 +315,7 @@ void uicb_screen_prev_sel(uicb_t); /* status.c */ int statustext_rectangle(StatusRec *r, char *str); +int statustext_graph(StatusGraph *g, char *str); int statustext_text(StatusText *s, char *str); void statustext_normal(int sc, char *str); void statustext_handle(int sc, char *str);