aboutsummaryrefslogtreecommitdiffstats
path: root/draw.c
diff options
context:
space:
mode:
authorgotmor <gotmor@f2baff5b-bf2c-0410-a398-912abdc3d8b2>2008-02-01 17:49:00 +0000
committergotmor <gotmor@f2baff5b-bf2c-0410-a398-912abdc3d8b2>2008-02-01 17:49:00 +0000
commit63cefbcb3609fc32a1187b28ac32b007d3b38f9e (patch)
treec1757e81864808d2349380a8692ea7eb42c7a566 /draw.c
parent9b2e296cb82a5e800e58b3c5eea56f8dd25ae632 (diff)
downloaddzen-63cefbcb3609fc32a1187b28ac32b007d3b38f9e.tar.gz
dzen-63cefbcb3609fc32a1187b28ac32b007d3b38f9e.zip
added a simple pixmap cache
git-svn-id: http://dzen.googlecode.com/svn/trunk@214 f2baff5b-bf2c-0410-a398-912abdc3d8b2
Diffstat (limited to 'draw.c')
-rw-r--r--draw.c137
1 files changed, 99 insertions, 38 deletions
diff --git a/draw.c b/draw.c
index d6d13f1..02aad95 100644
--- a/draw.c
+++ b/draw.c
@@ -14,7 +14,17 @@
#endif
#define ARGLEN 256
+#define MAX_ICON_CACHE 32
+typedef struct ICON_C {
+ char name[ARGLEN];
+ Pixmap p;
+
+ int w, h;
+} icon_c;
+
+icon_c icons[MAX_ICON_CACHE];
+int icon_cnt;
int otx;
/* command types for the in-text parser */
@@ -294,6 +304,34 @@ get_pos_vals(char *s, int *d, int *a) {
return ret;
}
+static int
+find_icon(const char* name) {
+ int i;
+
+ for(i=0; i < MAX_ICON_CACHE; i++)
+ if(!strncmp(icons[i].name, name, ARGLEN))
+ return i;
+
+ return -1;
+}
+
+static void
+insert_icon(const char* name, Pixmap pm, int w, int h) {
+ int i;
+
+ if(icon_cnt >= MAX_ICON_CACHE)
+ icon_cnt = 0;
+
+ if(icons[icon_cnt].p)
+ XFreePixmap(dzen.dpy, icons[icon_cnt].p);
+
+ strncpy(icons[icon_cnt].name, name, ARGLEN);
+ icons[icon_cnt].w = w;
+ icons[icon_cnt].h = h;
+ icons[icon_cnt].p = pm;
+ icon_cnt++;
+}
+
char *
parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
/* bitmaps */
@@ -328,6 +366,9 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
XpmColorSymbol xpms;
#endif
+ /* icon cache */
+ int ip;
+
/* parse line and return the text without control commands */
if(nodraw) {
rbuf = emalloc(MAX_LINE_LEN);
@@ -414,26 +455,36 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
if(t != -1 && tval) {
switch(t) {
case icon:
- if(XReadBitmapFile(dzen.dpy, *pm, tval, &bm_w,
- &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess
- && (h/2 + px + (signed)bm_w < dzen.w)) {
- setcolor(pm, px, bm_w, lastfg, lastbg, reverse, nobg);
- XCopyPlane(dzen.dpy, bm, *pm, dzen.tgc,
- 0, 0, bm_w, bm_h, px, set_posy ? py :
- (dzen.line_height >= (signed)bm_h ? (dzen.line_height - bm_h)/2 : 0), 1);
- XFreePixmap(dzen.dpy, bm);
- px += bm_w;
- }
+ if( (ip=find_icon(tval)) != -1) {
+ XCopyArea(dzen.dpy, icons[ip].p, *pm, dzen.tgc,
+ 0, 0, icons[ip].w, icons[ip].h, px, set_posy ? py :
+ (dzen.line_height >= (signed)icons[ip].h ?
+ (dzen.line_height - icons[ip].h)/2 : 0));
+ px += icons[ip].w;
+ } else {
+ if(XReadBitmapFile(dzen.dpy, *pm, tval, &bm_w,
+ &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess
+ && (h/2 + px + (signed)bm_w < dzen.w)) {
+ setcolor(pm, px, bm_w, lastfg, lastbg, reverse, nobg);
+ XCopyPlane(dzen.dpy, bm, *pm, dzen.tgc,
+ 0, 0, bm_w, bm_h, px, set_posy ? py :
+ (dzen.line_height >= (signed)bm_h ? (dzen.line_height - bm_h)/2 : 0), 1);
+ XFreePixmap(dzen.dpy, bm);
+ px += bm_w;
+ }
#ifdef DZEN_XPM
- else if(XpmReadFileToPixmap(dzen.dpy, dzen.title_win.win, tval, &xpm_pm, NULL, &xpma) == XpmSuccess) {
- setcolor(pm, px, xpma.width, lastfg, lastbg, reverse, nobg);
- XCopyArea(dzen.dpy, xpm_pm, *pm, dzen.tgc,
- 0, 0, xpma.width, xpma.height, px, set_posy ? py :
- (dzen.line_height >= (signed)xpma.height ? (dzen.line_height - xpma.height)/2 : 0));
- px += xpma.width;
-
- XFreePixmap(dzen.dpy, xpm_pm);
- free_xpm_attrib = 1;
+ else if(XpmReadFileToPixmap(dzen.dpy, dzen.title_win.win, tval, &xpm_pm, NULL, &xpma) == XpmSuccess) {
+ setcolor(pm, px, xpma.width, lastfg, lastbg, reverse, nobg);
+ insert_icon(tval, xpm_pm, xpma.width, xpma.height);
+
+ XCopyArea(dzen.dpy, xpm_pm, *pm, dzen.tgc,
+ 0, 0, xpma.width, xpma.height, px, set_posy ? py :
+ (dzen.line_height >= (signed)xpma.height ? (dzen.line_height - xpma.height)/2 : 0));
+ px += xpma.width;
+
+ //XFreePixmap(dzen.dpy, xpm_pm);
+ free_xpm_attrib = 1;
+ }
}
#endif
break;
@@ -617,26 +668,36 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
if(t != -1 && tval) {
switch(t) {
case icon:
- if(XReadBitmapFile(dzen.dpy, *pm, tval, &bm_w,
- &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess
- && (h/2 + px + (signed)bm_w < dzen.w)) {
- setcolor(pm, px, bm_w, lastfg, lastbg, reverse, nobg);
- XCopyPlane(dzen.dpy, bm, *pm, dzen.tgc,
- 0, 0, bm_w, bm_h, px, set_posy ? py :
- (dzen.line_height >= (signed)bm_h ? (dzen.line_height - bm_h)/2 : 0), 1);
- XFreePixmap(dzen.dpy, bm);
- px += bm_w;
- }
+ if( (ip=find_icon(tval)) != -1) {
+ XCopyArea(dzen.dpy, icons[ip].p, *pm, dzen.tgc,
+ 0, 0, icons[ip].w, icons[ip].h, px, set_posy ? py :
+ (dzen.line_height >= (signed)icons[ip].h ?
+ (dzen.line_height - icons[ip].h)/2 : 0));
+ px += icons[ip].w;
+ } else {
+ if(XReadBitmapFile(dzen.dpy, *pm, tval, &bm_w,
+ &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess
+ && (h/2 + px + (signed)bm_w < dzen.w)) {
+ setcolor(pm, px, bm_w, lastfg, lastbg, reverse, nobg);
+ XCopyPlane(dzen.dpy, bm, *pm, dzen.tgc,
+ 0, 0, bm_w, bm_h, px, set_posy ? py :
+ (dzen.line_height >= (signed)bm_h ? (dzen.line_height - bm_h)/2 : 0), 1);
+ XFreePixmap(dzen.dpy, bm);
+ px += bm_w;
+ }
#ifdef DZEN_XPM
- else if(XpmReadFileToPixmap(dzen.dpy, dzen.title_win.win, tval, &xpm_pm, NULL, &xpma) == XpmSuccess) {
- setcolor(pm, px, xpma.width, lastfg, lastbg, reverse, nobg);
- XCopyArea(dzen.dpy, xpm_pm, *pm, dzen.tgc,
- 0, 0, xpma.width, xpma.height, px, set_posy ? py :
- (dzen.line_height >= (signed)xpma.height ? (dzen.line_height - xpma.height)/2 : 0));
- px += xpma.width;
-
- XFreePixmap(dzen.dpy, xpm_pm);
- free_xpm_attrib = 1;
+ else if(XpmReadFileToPixmap(dzen.dpy, dzen.title_win.win, tval, &xpm_pm, NULL, &xpma) == XpmSuccess) {
+ setcolor(pm, px, xpma.width, lastfg, lastbg, reverse, nobg);
+ insert_icon(tval, xpm_pm, xpma.width, xpma.height);
+
+ XCopyArea(dzen.dpy, xpm_pm, *pm, dzen.tgc,
+ 0, 0, xpma.width, xpma.height, px, set_posy ? py :
+ (dzen.line_height >= (signed)xpma.height ? (dzen.line_height - xpma.height)/2 : 0));
+ px += xpma.width;
+
+ //XFreePixmap(dzen.dpy, xpm_pm);
+ free_xpm_attrib = 1;
+ }
}
#endif
break;