Add bar future to draw graph with 'wmfs -s \g[x;y;w;h;#color;data]\'

This commit is contained in:
OldMan 2010-04-17 15:31:04 +06:00
parent 5875af2949
commit 84f6aa31d0
5 changed files with 92 additions and 2 deletions

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);