Draw: Can put image everywhere we can habitually put text with same sequences than in statustext: \i[x;y;w;h;/image/path.ext]\ (example: layout, tag: http://omploader.org/vM3lzNg)
This commit is contained in:
parent
0ce0d1a352
commit
09418c6dd7
@ -135,8 +135,6 @@ else()
|
|||||||
set(WMFS_HAVE_IMLIB "")
|
set(WMFS_HAVE_IMLIB "")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(wmfs ${LIBRARIES_TO_LINK})
|
target_link_libraries(wmfs ${LIBRARIES_TO_LINK})
|
||||||
|
|
||||||
# Messages
|
# Messages
|
||||||
|
|||||||
38
src/draw.c
38
src/draw.c
@ -49,6 +49,20 @@ draw_text(Drawable d, int x, int y, char* fg, int pad, char *str)
|
|||||||
if(!str)
|
if(!str)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/* To draw image everywhere we can draw text */
|
||||||
|
#ifdef HAVE_IMLIB
|
||||||
|
char *ostr = NULL;
|
||||||
|
int i, ni;
|
||||||
|
StatusImage im[56];
|
||||||
|
|
||||||
|
ostr = _strdup(str);
|
||||||
|
|
||||||
|
ni = statustext_image(im, str);
|
||||||
|
|
||||||
|
for(i = 0; i < ni; ++i)
|
||||||
|
draw_image(d, im[i].x, im[i].y, im[i].w, im[i].h, im[i].name);
|
||||||
|
#endif /* HAVE_IMLIB */
|
||||||
|
|
||||||
/* Transform X Drawable -> Xft Drawable */
|
/* Transform X Drawable -> Xft Drawable */
|
||||||
xftd = XftDrawCreate(dpy, d, DefaultVisual(dpy, SCREEN), DefaultColormap(dpy, SCREEN));
|
xftd = XftDrawCreate(dpy, d, DefaultVisual(dpy, SCREEN), DefaultColormap(dpy, SCREEN));
|
||||||
|
|
||||||
@ -63,6 +77,11 @@ draw_text(Drawable d, int x, int y, char* fg, int pad, char *str)
|
|||||||
|
|
||||||
XftDrawDestroy(xftd);
|
XftDrawDestroy(xftd);
|
||||||
|
|
||||||
|
#ifdef HAVE_IMLIB
|
||||||
|
strcpy(str, ostr);
|
||||||
|
IFREE(ostr);
|
||||||
|
#endif /* HAVE_IMLIB */
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +109,7 @@ draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color)
|
|||||||
* \param dr Drawable
|
* \param dr Drawable
|
||||||
* \param x X position
|
* \param x X position
|
||||||
* \param y Y position
|
* \param y Y position
|
||||||
* \param name Path of the XPM
|
* \param name Path of the image
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
draw_image(Drawable dr, int x, int y, int w, int h, char *name)
|
draw_image(Drawable dr, int x, int y, int w, int h, char *name)
|
||||||
@ -132,15 +151,30 @@ draw_image(Drawable dr, int x, int y, int w, int h, char *name)
|
|||||||
* \return final text width
|
* \return final text width
|
||||||
*/
|
*/
|
||||||
ushort
|
ushort
|
||||||
textw(const char *text)
|
textw(char *text)
|
||||||
{
|
{
|
||||||
XGlyphInfo gl;
|
XGlyphInfo gl;
|
||||||
|
|
||||||
if(!text)
|
if(!text)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
#ifdef HAVE_IMLIB
|
||||||
|
char *ostr = NULL;
|
||||||
|
|
||||||
|
StatusImage im[56];
|
||||||
|
|
||||||
|
ostr = _strdup(text);
|
||||||
|
|
||||||
|
statustext_image(im, text);
|
||||||
|
#endif /* HAVE_IMLIB */
|
||||||
|
|
||||||
XftTextExtentsUtf8(dpy, font, (FcChar8 *)text, strlen(text), &gl);
|
XftTextExtentsUtf8(dpy, font, (FcChar8 *)text, strlen(text), &gl);
|
||||||
|
|
||||||
|
#ifdef HAVE_IMLIB
|
||||||
|
strcpy(text, ostr);
|
||||||
|
IFREE(ostr);
|
||||||
|
#endif /* HAVE_IMLIB */
|
||||||
|
|
||||||
return gl.width + font->descent;
|
return gl.width + font->descent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -94,7 +94,6 @@ statustext_image(StatusImage *im, char *str)
|
|||||||
int n, i, j, k;
|
int n, i, j, k;
|
||||||
|
|
||||||
for(i = j = n = 0; i < strlen(str); ++i, ++j)
|
for(i = j = n = 0; i < strlen(str); ++i, ++j)
|
||||||
/* %512[^]] */
|
|
||||||
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
|
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 == '\\')
|
&& as == '\\')
|
||||||
for(++n, ++i, --j; str[i] != as || str[i - 1] != ']'; ++i);
|
for(++n, ++i, --j; str[i] != as || str[i - 1] != ']'; ++i);
|
||||||
@ -193,10 +192,9 @@ statustext_handle(int sc, char *str)
|
|||||||
int ni;
|
int ni;
|
||||||
StatusImage im[128];
|
StatusImage im[128];
|
||||||
|
|
||||||
ni = statustext_image(im, str);
|
ni = statustext_image(im, str);
|
||||||
#endif /* HAVE_IMLIB */
|
#endif /* HAVE_IMLIB */
|
||||||
|
|
||||||
|
|
||||||
/* Draw normal text (and possibly colored with \#color\ blocks) */
|
/* Draw normal text (and possibly colored with \#color\ blocks) */
|
||||||
statustext_normal(sc, str);
|
statustext_normal(sc, str);
|
||||||
|
|
||||||
|
|||||||
@ -136,7 +136,7 @@ void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color);
|
|||||||
void draw_image(Drawable dr, int x, int y, int w, int h, char *name);
|
void draw_image(Drawable dr, int x, int y, int w, int h, char *name);
|
||||||
#endif /* HAVE_IMLIB */
|
#endif /* HAVE_IMLIB */
|
||||||
|
|
||||||
ushort textw(const char *text);
|
ushort textw(char *text);
|
||||||
|
|
||||||
/* infobar.c */
|
/* infobar.c */
|
||||||
void infobar_init(void);
|
void infobar_init(void);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user