1 /* Conky, a system monitor, based on torsmo
3 * Please see COPYING for details
5 * Copyright (c) 2005-2009 Brenden Matthews, et. al.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #define NAME_SIZE 1024
38 struct image_list_s *next;
41 struct image_list_s *image_list_start, *image_list_end;
44 Imlib_Updates updates, current_update;
45 /* our virtual framebuffer image we draw into */
46 Imlib_Image buffer, image;
48 #define DEFAULT_CACHE_SIZE 4096 * 1024 /* default cache size for loaded images */
50 void cimlib_set_cache_size(long size)
52 imlib_set_cache_size(size);
55 void cimlib_cleanup(void)
57 struct image_list_s *cur = image_list_start, *last = NULL;
63 image_list_start = image_list_end = NULL;
66 void cimlib_init(Display *display, Window drawable, Visual *visual, Colormap colourmap)
68 image_list_start = image_list_end = NULL;
69 cimlib_set_cache_size(DEFAULT_CACHE_SIZE);
70 /* set the maximum number of colors to allocate for 8bpp and less to 256 */
71 imlib_set_color_usage(256);
72 /* dither for depths < 24bpp */
73 imlib_context_set_dither(1);
74 /* set the display , visual, colormap and drawable we are using */
75 imlib_context_set_display(display);
76 imlib_context_set_visual(visual);
77 imlib_context_set_colormap(colourmap);
78 imlib_context_set_drawable(drawable);
81 void cimlib_add_image(const char *args)
83 struct image_list_s *cur = NULL;
86 cur = malloc(sizeof(struct image_list_s));
87 memset(cur, 0, sizeof(struct image_list_s));
89 if (!sscanf(args, "%1024s", cur->name)) {
90 ERR("Invalid args for $image. Format is: '<path to image> (-p x,y) (-s WxH)' (got '%s')", args);
92 // now we check for optional args
93 tmp = strstr(args, "-p ");
96 sscanf(tmp, "%i,%i", &cur->x, &cur->y);
98 tmp = strstr(args, "-s ");
101 if (sscanf(tmp, "%ix%i", &cur->w, &cur->h)) {
106 if (image_list_end) {
107 image_list_end->next = cur;
108 image_list_end = cur;
110 image_list_start = image_list_end = cur;
114 static void cimlib_draw_image(struct image_list_s *cur)
116 image = imlib_load_image(cur->name);
119 DBGP("Drawing image '%s' at (%i,%i) scaled to %ix%i", cur->name, cur->x, cur->y, cur->w, cur->h);
120 imlib_context_set_image(image);
121 w = imlib_image_get_width();
122 h = imlib_image_get_height();
123 imlib_context_set_image(buffer);
124 imlib_blend_image_onto_image(image, 1, 0, 0, h, w,
125 cur->x, cur->y, cur->w, cur->h);
126 imlib_context_set_image(image);
129 ERR("Unable to load image '%s'", cur->name);
133 static void cimlib_draw_all(void)
135 struct image_list_s *cur = image_list_start;
137 cimlib_draw_image(cur);
142 void cimlib_render(int x, int y, int width, int height)
144 if (!image_list_start) return; /* are we actually drawing anything? */
145 /* take all the little rectangles to redraw and merge them into
146 * something sane for rendering */
147 buffer = imlib_create_image(width, height);
148 /* clear our buffer */
149 imlib_context_set_image(buffer);
151 /* we can blend stuff now */
152 imlib_context_set_blend(1);
156 /* set the buffer image as our current image */
157 imlib_context_set_image(buffer);
158 /* render the image at 0, 0 */
159 imlib_render_image_on_drawable(x, y);
160 /* don't need that temporary buffer image anymore */