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/>.
32 char name[DEFAULT_TEXT_BUFFER_SIZE];
36 struct image_list_s *next;
39 struct image_list_s *image_list_start, *image_list_end;
42 Imlib_Updates updates, current_update;
43 /* our virtual framebuffer image we draw into */
44 Imlib_Image buffer, image;
46 #define DEFAULT_CACHE_SIZE 4096 * 1024 /* default cache size for loaded images */
48 void cimlib_set_cache_size(long size)
50 imlib_set_cache_size(size);
53 void cimlib_cleanup(void)
55 struct image_list_s *cur = image_list_start, *last = NULL;
61 image_list_start = image_list_end = NULL;
64 void cimlib_init(Display *display, Window drawable, Visual *visual, Colormap colourmap)
66 image_list_start = image_list_end = NULL;
67 cimlib_set_cache_size(DEFAULT_CACHE_SIZE);
68 /* set the maximum number of colors to allocate for 8bpp and less to 256 */
69 imlib_set_color_usage(256);
70 /* dither for depths < 24bpp */
71 imlib_context_set_dither(1);
72 /* set the display , visual, colormap and drawable we are using */
73 imlib_context_set_display(display);
74 imlib_context_set_visual(visual);
75 imlib_context_set_colormap(colourmap);
76 imlib_context_set_drawable(drawable);
79 void cimlib_add_image(const char *args)
81 struct image_list_s *cur = NULL;
84 cur = malloc(sizeof(struct image_list_s));
85 memset(cur, 0, sizeof(struct image_list_s));
87 if (!sscanf(args, "%1024s", cur->name)) {
88 ERR("Invalid args for $image. Format is: '<path to image> (-p x,y) (-s WxH)' (got '%s')", args);
90 // now we check for optional args
91 tmp = strstr(args, "-p ");
94 sscanf(tmp, "%i,%i", &cur->x, &cur->y);
96 tmp = strstr(args, "-s ");
99 if (sscanf(tmp, "%ix%i", &cur->w, &cur->h)) {
104 if (image_list_end) {
105 image_list_end->next = cur;
106 image_list_end = cur;
108 image_list_start = image_list_end = cur;
112 static void cimlib_draw_image(struct image_list_s *cur)
114 image = imlib_load_image(cur->name);
117 DBGP("Drawing image '%s' at (%i,%i) scaled to %ix%i", cur->name, cur->x, cur->y, cur->w, cur->h);
118 imlib_context_set_image(image);
119 w = imlib_image_get_width();
120 h = imlib_image_get_height();
121 imlib_context_set_image(buffer);
122 imlib_blend_image_onto_image(image, 1, 0, 0, h, w,
123 cur->x, cur->y, cur->w, cur->h);
124 imlib_context_set_image(image);
127 ERR("Unable to load image '%s'", cur->name);
131 static void cimlib_draw_all(void)
133 struct image_list_s *cur = image_list_start;
135 cimlib_draw_image(cur);
140 void cimlib_render(int x, int y, int width, int height)
142 if (!image_list_start) return; /* are we actually drawing anything? */
143 /* take all the little rectangles to redraw and merge them into
144 * something sane for rendering */
145 buffer = imlib_create_image(width, height);
146 /* clear our buffer */
147 imlib_context_set_image(buffer);
149 /* we can blend stuff now */
150 imlib_context_set_blend(1);
154 /* set the buffer image as our current image */
155 imlib_context_set_image(buffer);
156 /* render the image at 0, 0 */
157 imlib_render_image_on_drawable(x, y);
158 /* don't need that temporary buffer image anymore */