Mercurial > audlegacy
annotate audacious/skin.c @ 442:10535124cc8a trunk
[svn] This commit allows for the use of alternate formats to bmp in skin
files.
author | nenolod |
---|---|
date | Mon, 16 Jan 2006 10:30:11 -0800 |
parents | 5c457dac866a |
children | aedd5dbc1a1c |
rev | line source |
---|---|
0 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 */ | |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 # include "config.h" | |
24 #endif | |
25 | |
26 /* TODO: enforce default sizes! */ | |
27 | |
28 #include <glib.h> | |
29 #include <stdio.h> | |
30 #include <stdlib.h> | |
31 #include <string.h> | |
32 #include <ctype.h> | |
33 | |
34 #include "equalizer.h" | |
35 #include "main.h" | |
383 | 36 #include "ui_playlist.h" |
0 | 37 #include "skin.h" |
38 #include "skinwin.h" | |
39 #include "util.h" | |
40 | |
41 #include "debug.h" | |
42 | |
43 #include <gdk/gdkx.h> | |
44 #include <X11/Xlib.h> | |
45 | |
442
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
46 #define EXTENSION_TARGETS 7 |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
47 |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
48 gchar *ext_targets[EXTENSION_TARGETS] = { "bmp", "xpm", "png", "svg", |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
49 "gif", "jpg", "jpeg" }; |
0 | 50 |
51 struct _SkinPixmapIdMapping { | |
52 SkinPixmapId id; | |
53 const gchar *name; | |
54 const gchar *alt_name; | |
55 gint width, height; | |
56 }; | |
57 | |
58 struct _SkinMaskInfo { | |
59 gint width, height; | |
60 gchar *inistr; | |
61 }; | |
62 | |
63 typedef struct _SkinPixmapIdMapping SkinPixmapIdMapping; | |
64 typedef struct _SkinMaskInfo SkinMaskInfo; | |
65 | |
66 | |
67 Skin *bmp_active_skin = NULL; | |
68 | |
69 static gint skin_current_num; | |
70 | |
71 static SkinMaskInfo skin_mask_info[] = { | |
72 {275, 116, "Normal"}, | |
73 {275, 16, "WindowShade"}, | |
74 {275, 116, "Equalizer"}, | |
75 {275, 16, "EqualizerWS"} | |
76 }; | |
77 | |
78 static SkinPixmapIdMapping skin_pixmap_id_map[] = { | |
79 {SKIN_MAIN, "main", NULL}, | |
80 {SKIN_CBUTTONS, "cbuttons", NULL}, | |
81 {SKIN_SHUFREP, "shufrep", NULL}, | |
82 {SKIN_TEXT, "text", NULL}, | |
83 {SKIN_TITLEBAR, "titlebar", NULL}, | |
84 {SKIN_VOLUME, "volume", NULL}, | |
85 {SKIN_BALANCE, "balance", "volume"}, | |
86 {SKIN_MONOSTEREO, "monoster", NULL}, | |
87 {SKIN_PLAYPAUSE, "playpaus", NULL}, | |
88 {SKIN_NUMBERS, "nums_ex", "numbers"}, | |
89 {SKIN_POSBAR, "posbar", NULL}, | |
90 {SKIN_EQMAIN, "eqmain", NULL}, | |
91 {SKIN_PLEDIT, "pledit", NULL}, | |
92 {SKIN_EQ_EX, "eq_ex", NULL} | |
93 }; | |
94 | |
95 static guint skin_pixmap_id_map_size = G_N_ELEMENTS(skin_pixmap_id_map); | |
96 | |
97 static const guchar skin_default_viscolor[24][3] = { | |
98 {9, 34, 53}, | |
99 {10, 18, 26}, | |
100 {0, 54, 108}, | |
101 {0, 58, 116}, | |
102 {0, 62, 124}, | |
103 {0, 66, 132}, | |
104 {0, 70, 140}, | |
105 {0, 74, 148}, | |
106 {0, 78, 156}, | |
107 {0, 82, 164}, | |
108 {0, 86, 172}, | |
109 {0, 92, 184}, | |
110 {0, 98, 196}, | |
111 {0, 104, 208}, | |
112 {0, 110, 220}, | |
113 {0, 116, 232}, | |
114 {0, 122, 244}, | |
115 {0, 128, 255}, | |
116 {0, 128, 255}, | |
117 {0, 104, 208}, | |
118 {0, 80, 160}, | |
119 {0, 56, 112}, | |
120 {0, 32, 64}, | |
121 {200, 200, 200} | |
122 }; | |
123 | |
124 static GdkBitmap * | |
125 skin_create_transparent_mask(const gchar *, | |
126 const gchar *, | |
127 const gchar *, | |
128 GdkWindow *, | |
129 gint, gint); | |
130 | |
131 static void | |
132 skin_setup_masks(Skin * skin); | |
133 | |
134 static void | |
135 skin_set_default_vis_color(Skin * skin); | |
136 | |
137 | |
138 void | |
139 skin_lock(Skin * skin) | |
140 { | |
141 g_mutex_lock(skin->lock); | |
142 } | |
143 | |
144 void | |
145 skin_unlock(Skin * skin) | |
146 { | |
147 g_mutex_unlock(skin->lock); | |
148 } | |
149 | |
150 gboolean | |
151 bmp_active_skin_reload(void) | |
152 { | |
153 return bmp_active_skin_load(bmp_active_skin->path); | |
154 } | |
155 | |
156 gboolean | |
157 bmp_active_skin_load(const gchar * path) | |
158 { | |
159 g_return_val_if_fail(bmp_active_skin != NULL, FALSE); | |
160 | |
161 if (!skin_load(bmp_active_skin, path)) | |
162 return FALSE; | |
163 | |
164 skin_setup_masks(bmp_active_skin); | |
165 draw_main_window(TRUE); | |
166 draw_playlist_window(TRUE); | |
167 draw_equalizer_window(TRUE); | |
168 | |
169 vis_set_window(mainwin_vis, mainwin->window); | |
170 playlistwin_update_list(); | |
171 | |
172 return TRUE; | |
173 } | |
174 | |
175 void | |
176 skin_pixmap_free(SkinPixmap * p) | |
177 { | |
178 g_return_if_fail(p != NULL); | |
179 g_return_if_fail(p->pixmap != NULL); | |
180 | |
181 g_object_unref(p->pixmap); | |
182 p->pixmap = NULL; | |
183 } | |
184 | |
185 Skin * | |
186 skin_new(void) | |
187 { | |
188 Skin *skin; | |
189 skin = g_new0(Skin, 1); | |
190 skin->lock = g_mutex_new(); | |
191 return skin; | |
192 } | |
193 | |
194 void | |
195 skin_free(Skin * skin) | |
196 { | |
197 gint i; | |
198 | |
199 g_return_if_fail(skin != NULL); | |
200 | |
201 skin_lock(skin); | |
202 | |
203 for (i = 0; i < SKIN_PIXMAP_COUNT; i++) | |
204 skin_pixmap_free(&skin->pixmaps[i]); | |
205 | |
206 for (i = 0; i < SKIN_PIXMAP_COUNT; i++) { | |
207 if (skin->masks[i]) | |
208 g_object_unref(skin->masks[i]); | |
209 | |
210 skin->masks[i] = NULL; | |
211 } | |
212 | |
213 skin_set_default_vis_color(skin); | |
214 skin_unlock(skin); | |
215 } | |
216 | |
217 void | |
218 skin_destroy(Skin * skin) | |
219 { | |
220 g_return_if_fail(skin != NULL); | |
221 skin_free(skin); | |
222 g_mutex_free(skin->lock); | |
223 g_free(skin); | |
224 } | |
225 | |
226 const SkinPixmapIdMapping * | |
227 skin_pixmap_id_lookup(gint id) | |
228 { | |
229 gint i; | |
230 | |
231 for (i = 0; i < skin_pixmap_id_map_size; i++) { | |
232 if (id == skin_pixmap_id_map[i].id) { | |
233 return &skin_pixmap_id_map[i]; | |
234 } | |
235 } | |
236 | |
237 return NULL; | |
238 } | |
239 | |
240 const gchar * | |
241 skin_pixmap_id_to_name(SkinPixmapId id) | |
242 { | |
243 gint i; | |
244 | |
245 for (i = 0; i < skin_pixmap_id_map_size; i++) { | |
246 if (id == skin_pixmap_id_map[i].id) | |
247 return skin_pixmap_id_map[i].name; | |
248 } | |
249 return NULL; | |
250 } | |
251 | |
252 static void | |
253 skin_set_default_vis_color(Skin * skin) | |
254 { | |
255 memcpy(skin->vis_color, skin_default_viscolor, | |
256 sizeof(skin_default_viscolor)); | |
257 } | |
258 | |
442
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
259 /* |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
260 * I have rewritten this to take an array of possible targets, |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
261 * once we find a matching target we now return, instead of loop |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
262 * recursively. This allows for us to support many possible format |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
263 * targets for our skinning engine than just the original winamp |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
264 * formats. |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
265 * |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
266 * -- nenolod, 16 January 2006 |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
267 */ |
0 | 268 gchar * |
442
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
269 skin_pixmap_locate(const gchar * dirname, gchar ** basenames) |
0 | 270 { |
271 gchar *filename; | |
442
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
272 gint i; |
0 | 273 |
442
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
274 for (i = 0; basenames[i]; i++) |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
275 if (!(filename = find_file_recursively(dirname, basenames[i]))) |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
276 { |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
277 g_warning(G_STRLOC ": couldn't locate %s in directory %s", |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
278 basenames[i], dirname); |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
279 g_free(filename); |
0 | 280 } |
442
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
281 else |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
282 return filename; |
0 | 283 |
442
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
284 /* can't find any targets -- sorry */ |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
285 return NULL; |
0 | 286 } |
287 | |
288 /* FIXME: this function is temporary. It will be removed when the skinning system | |
289 uses GdkPixbuf in place of GdkPixmap */ | |
290 | |
291 static GdkPixmap * | |
292 pixmap_new_from_file(const gchar * filename) | |
293 { | |
294 GdkPixbuf *pixbuf; | |
295 GdkPixmap *pixmap; | |
296 gint width, height; | |
297 | |
298 if (!(pixbuf = gdk_pixbuf_new_from_file(filename, NULL))) | |
299 return NULL; | |
300 | |
301 width = gdk_pixbuf_get_width(pixbuf); | |
302 height = gdk_pixbuf_get_height(pixbuf); | |
303 | |
304 if (!(pixmap = gdk_pixmap_new(mainwin->window, width, height, | |
305 gdk_rgb_get_visual()->depth))) { | |
306 g_object_unref(pixbuf); | |
307 return NULL; | |
308 } | |
309 | |
310 gdk_pixbuf_render_to_drawable(pixbuf, pixmap, mainwin_gc, 0, 0, 0, 0, | |
311 width, height, GDK_RGB_DITHER_MAX, 0, 0); | |
312 g_object_unref(pixbuf); | |
313 | |
314 return pixmap; | |
315 } | |
316 | |
317 static gboolean | |
318 skin_load_pixmap_id(Skin * skin, SkinPixmapId id, const gchar * path_p) | |
319 { | |
320 const gchar *path; | |
321 gchar *filename; | |
322 gint width, height; | |
323 const SkinPixmapIdMapping *pixmap_id_mapping; | |
324 GdkPixmap *gpm; | |
325 SkinPixmap *pm = NULL; | |
442
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
326 gchar *basenames[EXTENSION_TARGETS * 2 + 1]; /* alternate basenames */ |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
327 gint i, y; |
0 | 328 |
329 g_return_val_if_fail(skin != NULL, FALSE); | |
330 g_return_val_if_fail(id < SKIN_PIXMAP_COUNT, FALSE); | |
331 | |
332 pixmap_id_mapping = skin_pixmap_id_lookup(id); | |
333 g_return_val_if_fail(pixmap_id_mapping != NULL, FALSE); | |
334 | |
442
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
335 memset(&basenames, 0, sizeof(basenames)); |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
336 |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
337 for (i = 0, y = 0; ext_targets[i]; i++, y++) |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
338 { |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
339 basenames[y] = g_strdup_printf("%s.%s", pixmap_id_mapping->name, |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
340 ext_targets[i]); |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
341 |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
342 if (pixmap_id_mapping->alt_name) |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
343 basenames[++y] = g_strdup_printf("%s.%s", |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
344 pixmap_id_mapping->alt_name, ext_targets[i]); |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
345 } |
0 | 346 |
347 path = path_p ? path_p : skin->path; | |
442
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
348 filename = skin_pixmap_locate(path, basenames); |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
349 |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
350 for (i = 0; basenames[i] != NULL; i++) |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
351 { |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
352 g_free(basenames[i]); |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
353 basenames[i] = NULL; |
10535124cc8a
[svn] This commit allows for the use of alternate formats to bmp in skin
nenolod
parents:
383
diff
changeset
|
354 } |
0 | 355 |
356 if (!(gpm = pixmap_new_from_file(filename))) { | |
357 g_warning("loading of %s failed", filename); | |
358 g_free(filename); | |
359 return FALSE; | |
360 } | |
361 | |
362 g_free(filename); | |
363 | |
364 gdk_window_get_size(gpm, &width, &height); | |
365 pm = &skin->pixmaps[id]; | |
366 pm->pixmap = gpm; | |
367 pm->width = width; | |
368 pm->height = height; | |
369 pm->current_width = width; | |
370 pm->current_height = height; | |
371 | |
372 return TRUE; | |
373 } | |
374 | |
375 void | |
376 skin_mask_create(Skin * skin, | |
377 const gchar * path, | |
378 gint id, | |
379 GdkWindow * window) | |
380 { | |
381 skin->masks[id] = | |
382 skin_create_transparent_mask(path, "region.txt", | |
383 skin_mask_info[id].inistr, window, | |
384 skin_mask_info[id].width, | |
385 skin_mask_info[id].height); | |
386 } | |
387 | |
388 static void | |
389 skin_setup_masks(Skin * skin) | |
390 { | |
391 GdkBitmap *mask; | |
392 | |
393 if (cfg.show_wm_decorations) | |
394 return; | |
395 | |
396 if (cfg.player_visible) { | |
397 mask = skin_get_mask(skin, SKIN_MASK_MAIN + cfg.player_shaded); | |
398 gtk_widget_shape_combine_mask(mainwin, mask, 0, 0); | |
399 } | |
400 | |
401 mask = skin_get_mask(skin, SKIN_MASK_EQ + cfg.equalizer_shaded); | |
402 gtk_widget_shape_combine_mask(equalizerwin, mask, 0, 0); | |
403 } | |
404 | |
405 static GdkBitmap * | |
406 create_default_mask(GdkWindow * parent, gint w, gint h) | |
407 { | |
408 GdkBitmap *ret; | |
409 GdkGC *gc; | |
410 GdkColor pattern; | |
411 | |
412 ret = gdk_pixmap_new(parent, w, h, 1); | |
413 gc = gdk_gc_new(ret); | |
414 pattern.pixel = 1; | |
415 gdk_gc_set_foreground(gc, &pattern); | |
416 gdk_draw_rectangle(ret, gc, TRUE, 0, 0, w, h); | |
417 gdk_gc_destroy(gc); | |
418 | |
419 return ret; | |
420 } | |
421 | |
422 static void | |
423 skin_query_color(GdkColormap * cm, GdkColor * c) | |
424 { | |
425 XColor xc = { 0 }; | |
426 | |
427 xc.pixel = c->pixel; | |
428 XQueryColor(GDK_COLORMAP_XDISPLAY(cm), GDK_COLORMAP_XCOLORMAP(cm), &xc); | |
429 c->red = xc.red; | |
430 c->green = xc.green; | |
431 c->blue = xc.blue; | |
432 } | |
433 | |
434 static glong | |
435 skin_calc_luminance(GdkColor * c) | |
436 { | |
437 return (0.212671 * c->red + 0.715160 * c->green + 0.072169 * c->blue); | |
438 } | |
439 | |
440 static void | |
441 skin_get_textcolors(GdkPixmap * text, GdkColor * bgc, GdkColor * fgc) | |
442 { | |
443 /* | |
444 * Try to extract reasonable background and foreground colors | |
445 * from the font pixmap | |
446 */ | |
447 | |
448 GdkImage *gi; | |
449 GdkColormap *cm; | |
450 gint i; | |
451 | |
452 g_return_if_fail(text != NULL); | |
453 | |
454 /* Get the first line of text */ | |
455 gi = gdk_drawable_get_image(text, 0, 0, 152, 6); | |
456 cm = gdk_window_get_colormap(playlistwin->window); | |
457 g_return_if_fail(GDK_IS_WINDOW(playlistwin->window)); | |
458 | |
459 for (i = 0; i < 6; i++) { | |
460 GdkColor c; | |
461 gint x; | |
462 glong d, max_d; | |
463 | |
464 /* Get a pixel from the middle of the space character */ | |
465 bgc[i].pixel = gdk_image_get_pixel(gi, 151, i); | |
466 skin_query_color(cm, &bgc[i]); | |
467 | |
468 max_d = 0; | |
469 for (x = 1; x < 150; x++) { | |
470 c.pixel = gdk_image_get_pixel(gi, x, i); | |
471 skin_query_color(cm, &c); | |
472 | |
473 d = labs(skin_calc_luminance(&c) - skin_calc_luminance(&bgc[i])); | |
474 if (d > max_d) { | |
475 memcpy(&fgc[i], &c, sizeof(GdkColor)); | |
476 max_d = d; | |
477 } | |
478 } | |
479 } | |
480 gdk_image_destroy(gi); | |
481 } | |
482 | |
483 gboolean | |
484 init_skins(const gchar * path) | |
485 { | |
486 bmp_active_skin = skin_new(); | |
487 | |
488 if (!bmp_active_skin_load(path)) { | |
489 /* FIXME: Oddly, g_message() causes a crash if path is NULL on | |
490 * Solaris (see bug #165) */ | |
491 if (path) | |
492 g_message("Unable to load skin (%s), trying default...", path); | |
493 | |
494 /* can't load configured skin, retry with default */ | |
495 if (!bmp_active_skin_load(BMP_DEFAULT_SKIN_PATH)) { | |
496 g_message("Unable to load default skin (%s)! Giving up.", | |
497 BMP_DEFAULT_SKIN_PATH); | |
498 return FALSE; | |
499 } | |
500 } | |
501 | |
502 if (cfg.random_skin_on_play) | |
503 skinlist_update(); | |
504 | |
505 return TRUE; | |
506 } | |
507 | |
508 static guint | |
509 hex_chars_to_int(gchar hi, gchar lo) | |
510 { | |
511 /* | |
512 * Converts a value in the range 0x00-0xFF | |
513 * to a integer in the range 0-65535 | |
514 */ | |
515 gchar str[3]; | |
516 | |
517 str[0] = hi; | |
518 str[1] = lo; | |
519 str[2] = 0; | |
520 | |
521 return (CLAMP(strtol(str, NULL, 16), 0, 0xFF) << 8); | |
522 } | |
523 | |
524 GdkColor * | |
525 skin_load_color(const gchar * path, const gchar * file, | |
526 const gchar * section, const gchar * key) | |
527 { | |
528 gchar *filename, *value; | |
529 GdkColor *color = NULL; | |
530 | |
531 filename = find_file_recursively(path, file); | |
532 if (filename) { | |
533 value = read_ini_string(filename, section, key); | |
534 if (value) { | |
535 gchar *ptr = value; | |
536 gint len; | |
537 | |
538 color = g_new0(GdkColor, 1); | |
539 g_strstrip(value); | |
540 | |
541 if (value[0] == '#') | |
542 ptr++; | |
543 len = strlen(ptr); | |
544 | |
545 /* | |
546 * The handling of incomplete values is done this way | |
547 * to maximize winamp compatibility | |
548 */ | |
549 if (len >= 6) { | |
550 color->red = hex_chars_to_int(*ptr, *(ptr + 1)); | |
551 ptr += 2; | |
552 } | |
553 if (len >= 4) { | |
554 color->green = hex_chars_to_int(*ptr, *(ptr + 1)); | |
555 ptr += 2; | |
556 } | |
557 if (len >= 2) | |
558 color->blue = hex_chars_to_int(*ptr, *(ptr + 1)); | |
559 | |
560 | |
561 gdk_color_alloc(gdk_window_get_colormap(playlistwin->window), | |
562 color); | |
563 g_free(value); | |
564 } | |
565 g_free(filename); | |
566 } | |
567 return color; | |
568 } | |
569 | |
570 | |
571 | |
572 GdkBitmap * | |
573 skin_create_transparent_mask(const gchar * path, | |
574 const gchar * file, | |
575 const gchar * section, | |
576 GdkWindow * window, | |
577 gint width, | |
578 gint height) | |
579 { | |
580 GdkBitmap *mask = NULL; | |
581 GdkGC *gc = NULL; | |
582 GdkColor pattern; | |
583 GdkPoint *gpoints; | |
584 | |
585 gchar *filename = NULL; | |
586 gboolean created_mask = FALSE; | |
587 GArray *num, *point; | |
588 gint i, j, k; | |
589 | |
590 if (path) | |
591 filename = find_file_recursively(path, file); | |
592 | |
593 /* filename will be null if path wasn't set */ | |
594 if (!filename) { | |
595 return create_default_mask(window, width, height); | |
596 } | |
597 | |
598 if ((num = read_ini_array(filename, section, "NumPoints")) == NULL) { | |
599 g_free(filename); | |
600 return NULL; | |
601 } | |
602 | |
603 if ((point = read_ini_array(filename, section, "PointList")) == NULL) { | |
604 g_array_free(num, TRUE); | |
605 g_free(filename); | |
606 return NULL; | |
607 } | |
608 | |
609 mask = gdk_pixmap_new(window, width, height, 1); | |
610 gc = gdk_gc_new(mask); | |
611 | |
612 pattern.pixel = 0; | |
613 gdk_gc_set_foreground(gc, &pattern); | |
614 gdk_draw_rectangle(mask, gc, TRUE, 0, 0, width, height); | |
615 pattern.pixel = 1; | |
616 gdk_gc_set_foreground(gc, &pattern); | |
617 | |
618 j = 0; | |
619 for (i = 0; i < num->len; i++) { | |
620 if ((point->len - j) >= (g_array_index(num, gint, i) * 2)) { | |
621 created_mask = TRUE; | |
622 gpoints = g_new(GdkPoint, g_array_index(num, gint, i)); | |
623 for (k = 0; k < g_array_index(num, gint, i); k++) { | |
624 gpoints[k].x = g_array_index(point, gint, j + k * 2); | |
625 gpoints[k].y = g_array_index(point, gint, j + k * 2 + 1); | |
626 } | |
627 j += k * 2; | |
628 gdk_draw_polygon(mask, gc, TRUE, gpoints, | |
629 g_array_index(num, gint, i)); | |
630 g_free(gpoints); | |
631 } | |
632 } | |
633 g_array_free(num, TRUE); | |
634 g_array_free(point, TRUE); | |
635 g_free(filename); | |
636 | |
637 if (!created_mask) | |
638 gdk_draw_rectangle(mask, gc, TRUE, 0, 0, width, height); | |
639 | |
640 gdk_gc_destroy(gc); | |
641 | |
642 return mask; | |
643 } | |
644 | |
645 void | |
646 skin_load_viscolor(Skin * skin, const gchar * path, const gchar * basename) | |
647 { | |
648 FILE *file; | |
649 gint i, c; | |
650 gchar line[256], *filename; | |
651 GArray *a; | |
652 | |
653 g_return_if_fail(skin != NULL); | |
654 g_return_if_fail(path != NULL); | |
655 g_return_if_fail(basename != NULL); | |
656 | |
657 skin_set_default_vis_color(skin); | |
658 | |
659 filename = find_file_recursively(path, basename); | |
660 if (!filename) | |
661 return; | |
662 | |
663 if (!(file = fopen(filename, "r"))) { | |
664 g_free(filename); | |
665 return; | |
666 } | |
667 | |
668 g_free(filename); | |
669 | |
670 for (i = 0; i < 24; i++) { | |
671 if (fgets(line, 255, file)) { | |
672 a = string_to_garray(line); | |
673 if (a->len > 2) { | |
674 for (c = 0; c < 3; c++) | |
675 skin->vis_color[i][c] = g_array_index(a, gint, c); | |
676 } | |
677 g_array_free(a, TRUE); | |
678 } | |
679 else | |
680 break; | |
681 } | |
682 | |
683 fclose(file); | |
684 } | |
685 | |
686 #if 0 | |
687 static void | |
688 skin_numbers_generate_dash(Skin * skin) | |
689 { | |
690 GdkGC *gc; | |
691 GdkPixmap *pixmap; | |
692 SkinPixmap *numbers; | |
693 | |
694 g_return_if_fail(skin != NULL); | |
695 | |
696 numbers = &skin->pixmaps[SKIN_NUMBERS]; | |
697 if (!numbers->pixmap || numbers->current_width < 99) | |
698 return; | |
699 | |
700 gc = gdk_gc_new(numbers->pixmap); | |
701 pixmap = gdk_pixmap_new(mainwin->window, 108, | |
702 numbers->current_height, | |
703 -1); | |
704 | |
705 skin_draw_pixmap(skin, pixmap, gc, SKIN_NUMBERS, 0, 0, 0, 0, 99, 13); | |
706 skin_draw_pixmap(skin, pixmap, gc, SKIN_NUMBERS, 90, 0, 99, 0, 9, 13); | |
707 skin_draw_pixmap(skin, pixmap, gc, SKIN_NUMBERS, 20, 6, 101, 6, 5, 1); | |
708 | |
709 g_object_unref(numbers->pixmap); | |
710 g_object_unref(gc); | |
711 | |
712 numbers->pixmap = pixmap; | |
713 numbers->current_width = 108; | |
714 } | |
715 #endif | |
716 | |
717 static void | |
718 skin_load_cursor(Skin * skin, const gchar * dirname) | |
719 { | |
720 const gchar * basename = "normal.cur"; | |
721 gchar * filename = NULL; | |
722 GdkPixbuf * cursor_pixbuf = NULL; | |
723 GdkPixbufAnimation * cursor_animated = NULL; | |
724 GdkCursor * cursor_gdk = NULL; | |
725 GError * error = NULL; | |
726 | |
727 filename = find_file_recursively(dirname, basename); | |
728 | |
729 if (filename && cfg.custom_cursors) { | |
730 cursor_animated = gdk_pixbuf_animation_new_from_file(filename, &error); | |
731 cursor_pixbuf = gdk_pixbuf_animation_get_static_image(cursor_animated); | |
732 cursor_gdk = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), | |
733 cursor_pixbuf, 0, 0); | |
734 } else { | |
735 cursor_gdk = gdk_cursor_new(GDK_LEFT_PTR); | |
736 } | |
737 | |
738 gdk_window_set_cursor(mainwin->window, cursor_gdk); | |
739 gdk_window_set_cursor(playlistwin->window, cursor_gdk); | |
740 gdk_window_set_cursor(equalizerwin->window, cursor_gdk); | |
741 } | |
742 | |
743 static void | |
744 skin_load_pixmaps(Skin * skin, const gchar * path) | |
745 { | |
746 GdkPixmap *text_pm; | |
747 guint i; | |
748 | |
749 for (i = 0; i < SKIN_PIXMAP_COUNT; i++) | |
750 skin_load_pixmap_id(skin, i, path); | |
751 | |
752 text_pm = skin->pixmaps[SKIN_TEXT].pixmap; | |
753 | |
754 if (text_pm) | |
755 skin_get_textcolors(text_pm, skin->textbg, skin->textfg); | |
756 | |
757 #if 0 | |
758 if (skin->pixmaps[SKIN_NUMBERS].pixmap) | |
759 skin_numbers_generate_dash(skin); | |
760 #endif | |
761 | |
762 skin->colors[SKIN_PLEDIT_NORMAL] = | |
763 skin_load_color(path, "pledit.txt", "text", "normal"); | |
764 skin->colors[SKIN_PLEDIT_CURRENT] = | |
765 skin_load_color(path, "pledit.txt", "text", "current"); | |
766 skin->colors[SKIN_PLEDIT_NORMALBG] = | |
767 skin_load_color(path, "pledit.txt", "text", "normalbg"); | |
768 skin->colors[SKIN_PLEDIT_SELECTEDBG] = | |
769 skin_load_color(path, "pledit.txt", "text", "selectedbg"); | |
770 | |
771 skin_mask_create(skin, path, SKIN_MASK_MAIN, mainwin->window); | |
772 skin_mask_create(skin, path, SKIN_MASK_MAIN_SHADE, mainwin->window); | |
773 | |
774 skin_mask_create(skin, path, SKIN_MASK_EQ, equalizerwin->window); | |
775 skin_mask_create(skin, path, SKIN_MASK_EQ_SHADE, equalizerwin->window); | |
776 | |
777 skin_load_viscolor(skin, path, "viscolor.txt"); | |
778 } | |
779 | |
780 static gboolean | |
781 skin_load_nolock(Skin * skin, const gchar * path, gboolean force) | |
782 { | |
783 gchar *cpath; | |
784 | |
785 g_return_val_if_fail(skin != NULL, FALSE); | |
786 g_return_val_if_fail(path != NULL, FALSE); | |
787 REQUIRE_LOCK(skin->lock); | |
788 | |
789 if (!g_file_test(path, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_DIR)) | |
790 return FALSE; | |
791 | |
792 if (!force) { | |
793 if (skin->path) | |
794 if (!strcmp(skin->path, path)) | |
795 return FALSE; | |
796 } | |
797 | |
798 skin_current_num++; | |
799 | |
800 skin->path = g_strdup(path); | |
801 | |
802 | |
803 if (!file_is_archive(path)) { | |
804 skin_load_pixmaps(skin, path); | |
805 skin_load_cursor(skin, path); | |
806 return TRUE; | |
807 } | |
808 | |
809 if (!(cpath = archive_decompress(path))) { | |
810 g_message("Unable to extract skin archive (%s)", path); | |
811 return FALSE; | |
812 } | |
813 | |
814 skin_load_pixmaps(skin, cpath); | |
815 skin_load_cursor(skin, cpath); | |
816 del_directory(cpath); | |
817 g_free(cpath); | |
818 | |
819 return TRUE; | |
820 } | |
821 | |
822 void | |
823 skin_install_skin(const gchar * path) | |
824 { | |
825 gchar *command; | |
826 | |
827 g_return_if_fail(path != NULL); | |
828 | |
829 command = g_strdup_printf("cp %s %s", path, bmp_paths[BMP_PATH_USER_SKIN_DIR]); | |
830 if (system(command)) { | |
831 g_message("Unable to install skin (%s) into user directory (%s)", | |
832 path, bmp_paths[BMP_PATH_USER_SKIN_DIR]); | |
833 } | |
834 g_free(command); | |
835 } | |
836 | |
837 | |
838 gboolean | |
839 skin_load(Skin * skin, const gchar * path) | |
840 { | |
841 gboolean error; | |
842 | |
843 g_return_val_if_fail(skin != NULL, FALSE); | |
844 g_return_val_if_fail(path != NULL, FALSE); | |
845 | |
846 skin_lock(skin); | |
847 error = skin_load_nolock(skin, path, FALSE); | |
848 skin_unlock(skin); | |
849 | |
850 return error; | |
851 } | |
852 | |
853 gboolean | |
854 skin_reload_forced(void) | |
855 { | |
856 gboolean error; | |
857 | |
858 skin_lock(bmp_active_skin); | |
859 error = skin_load_nolock(bmp_active_skin, bmp_active_skin->path, TRUE); | |
860 skin_unlock(bmp_active_skin); | |
861 | |
862 return error; | |
863 } | |
864 | |
865 void | |
866 skin_reload(Skin * skin) | |
867 { | |
868 g_return_if_fail(skin != NULL); | |
869 skin_load_nolock(skin, skin->path, TRUE); | |
870 } | |
871 | |
872 | |
873 static SkinPixmap * | |
874 skin_get_pixmap(Skin * skin, SkinPixmapId map_id) | |
875 { | |
876 g_return_val_if_fail(skin != NULL, NULL); | |
877 g_return_val_if_fail(map_id < SKIN_PIXMAP_COUNT, NULL); | |
878 | |
879 return &skin->pixmaps[map_id]; | |
880 } | |
881 | |
882 GdkBitmap * | |
883 skin_get_mask(Skin * skin, SkinMaskId mi) | |
884 { | |
885 g_return_val_if_fail(skin != NULL, NULL); | |
886 g_return_val_if_fail(mi < SKIN_PIXMAP_COUNT, NULL); | |
887 | |
888 return skin->masks[mi]; | |
889 } | |
890 | |
891 GdkColor * | |
892 skin_get_color(Skin * skin, SkinColorId color_id) | |
893 { | |
894 GdkColor *ret = NULL; | |
895 | |
896 g_return_val_if_fail(skin != NULL, NULL); | |
897 | |
898 switch (color_id) { | |
899 case SKIN_TEXTBG: | |
900 if (skin->pixmaps[SKIN_TEXT].pixmap) | |
901 ret = skin->textbg; | |
902 else | |
903 ret = skin->def_textbg; | |
904 break; | |
905 case SKIN_TEXTFG: | |
906 if (skin->pixmaps[SKIN_TEXT].pixmap) | |
907 ret = skin->textfg; | |
908 else | |
909 ret = skin->def_textfg; | |
910 break; | |
911 default: | |
912 if (color_id < SKIN_COLOR_COUNT) | |
913 ret = skin->colors[color_id]; | |
914 break; | |
915 } | |
916 return ret; | |
917 } | |
918 | |
919 void | |
920 skin_get_viscolor(Skin * skin, guchar vis_color[24][3]) | |
921 { | |
922 gint i; | |
923 | |
924 g_return_if_fail(skin != NULL); | |
925 | |
926 for (i = 0; i < 24; i++) { | |
927 vis_color[i][0] = skin->vis_color[i][0]; | |
928 vis_color[i][1] = skin->vis_color[i][1]; | |
929 vis_color[i][2] = skin->vis_color[i][2]; | |
930 } | |
931 } | |
932 | |
933 gint | |
934 skin_get_id(void) | |
935 { | |
936 return skin_current_num; | |
937 } | |
938 | |
939 void | |
940 skin_draw_pixmap(Skin * skin, GdkDrawable * drawable, GdkGC * gc, | |
941 SkinPixmapId pixmap_id, | |
942 gint xsrc, gint ysrc, gint xdest, gint ydest, | |
943 gint width, gint height) | |
944 { | |
945 SkinPixmap *pixmap; | |
946 | |
947 g_return_if_fail(skin != NULL); | |
948 | |
949 pixmap = skin_get_pixmap(skin, pixmap_id); | |
950 g_return_if_fail(pixmap != NULL); | |
951 g_return_if_fail(pixmap->pixmap != NULL); | |
952 | |
953 if (xsrc > pixmap->width || ysrc > pixmap->height) | |
954 return; | |
955 | |
956 width = MIN(width, pixmap->width - xsrc); | |
957 height = MIN(height, pixmap->height - ysrc); | |
958 gdk_draw_pixmap(drawable, gc, pixmap->pixmap, xsrc, ysrc, | |
959 xdest, ydest, width, height); | |
960 } | |
961 | |
962 void | |
963 skin_get_eq_spline_colors(Skin * skin, guint32 colors[19]) | |
964 { | |
965 gint i; | |
966 GdkPixmap *pixmap; | |
967 GdkImage *img; | |
968 SkinPixmap *eqmainpm; | |
969 | |
970 g_return_if_fail(skin != NULL); | |
971 | |
972 eqmainpm = &skin->pixmaps[SKIN_EQMAIN]; | |
973 if (eqmainpm->pixmap && | |
974 eqmainpm->current_width >= 116 && eqmainpm->current_height >= 313) | |
975 pixmap = eqmainpm->pixmap; | |
976 else | |
977 return; | |
978 | |
979 if (!GDK_IS_DRAWABLE(pixmap)) | |
980 return; | |
981 | |
982 if (!(img = gdk_drawable_get_image(pixmap, 115, 294, 1, 19))) | |
983 return; | |
984 | |
985 for (i = 0; i < 19; i++) | |
986 colors[i] = gdk_image_get_pixel(img, 0, i); | |
987 | |
988 gdk_image_destroy(img); | |
989 } | |
990 | |
991 | |
992 static void | |
993 skin_draw_playlistwin_frame_top(Skin * skin, | |
994 GdkDrawable * drawable, | |
995 GdkGC * gc, | |
996 gint width, gint height, gboolean focus) | |
997 { | |
998 /* The title bar skin consists of 2 sets of 4 images, 1 set | |
999 * for focused state and the other for unfocused. The 4 images | |
1000 * are: | |
1001 * | |
1002 * a. right corner (25,20) | |
1003 * b. left corner (25,20) | |
1004 * c. tiler (25,20) | |
1005 * d. title (100,20) | |
1006 * | |
1007 * min allowed width = 100+25+25 = 150 | |
1008 */ | |
1009 | |
1010 gint i, y, c; | |
1011 | |
1012 /* get y offset of the pixmap set to use */ | |
1013 if (focus) | |
1014 y = 0; | |
1015 else | |
1016 y = 21; | |
1017 | |
1018 /* left corner */ | |
1019 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 0, y, 0, 0, 25, 20); | |
1020 | |
1021 /* titlebar title */ | |
1022 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 26, y, | |
1023 (width - 100) / 2, 0, 100, 20); | |
1024 | |
1025 /* titlebar right corner */ | |
1026 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 153, y, | |
1027 width - 25, 0, 25, 20); | |
1028 | |
1029 /* tile draw the remaining frame */ | |
1030 | |
1031 /* compute tile count */ | |
1032 c = (width - (100 + 25 + 25)) / 25; | |
1033 | |
1034 for (i = 0; i < c / 2; i++) { | |
1035 /* left of title */ | |
1036 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 127, y, | |
1037 25 + i * 25, 0, 25, 20); | |
1038 | |
1039 /* right of title */ | |
1040 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 127, y, | |
1041 (width + 100) / 2 + i * 25, 0, 25, 20); | |
1042 } | |
1043 | |
1044 if (c & 1) { | |
1045 /* Odd tile count, so one remaining to draw. Here we split | |
1046 * it into two and draw half on either side of the title */ | |
1047 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 127, y, | |
1048 ((c / 2) * 25) + 25, 0, 12, 20); | |
1049 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 127, y, | |
1050 (width / 2) + ((c / 2) * 25) + 50, 0, 13, 20); | |
1051 } | |
1052 } | |
1053 | |
1054 static void | |
1055 skin_draw_playlistwin_frame_bottom(Skin * skin, | |
1056 GdkDrawable * drawable, | |
1057 GdkGC * gc, | |
1058 gint width, gint height, gboolean focus) | |
1059 { | |
1060 /* The bottom frame skin consists of 1 set of 4 images. The 4 | |
1061 * images are: | |
1062 * | |
1063 * a. left corner with menu buttons (125,38) | |
1064 * b. visualization window (75,38) | |
1065 * c. right corner with play buttons (150,38) | |
1066 * d. frame tile (25,38) | |
1067 * | |
1068 * (min allowed width = 125+150+25=300 | |
1069 */ | |
1070 | |
1071 gint i, c; | |
1072 | |
1073 /* bottom left corner (menu buttons) */ | |
1074 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 0, 72, | |
1075 0, height - 38, 125, 38); | |
1076 | |
1077 c = (width - 275) / 25; | |
1078 | |
1079 /* draw visualization window, if width allows */ | |
1080 if (c >= 3) { | |
1081 c -= 3; | |
1082 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 205, 0, | |
1083 width - (150 + 75), height - 38, 75, 38); | |
1084 } | |
1085 | |
1086 /* Bottom right corner (playbuttons etc) */ | |
1087 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, | |
1088 126, 72, width - 150, height - 38, 150, 38); | |
1089 | |
1090 /* Tile draw the remaining undrawn portions */ | |
1091 for (i = 0; i < c; i++) | |
1092 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 179, 0, | |
1093 125 + i * 25, height - 38, 25, 38); | |
1094 } | |
1095 | |
1096 static void | |
1097 skin_draw_playlistwin_frame_sides(Skin * skin, | |
1098 GdkDrawable * drawable, | |
1099 GdkGC * gc, | |
1100 gint width, gint height, gboolean focus) | |
1101 { | |
1102 /* The side frames consist of 2 tile images. 1 for the left, 1 for | |
1103 * the right. | |
1104 * a. left (12,29) | |
1105 * b. right (19,29) | |
1106 */ | |
1107 | |
1108 gint i; | |
1109 | |
1110 /* frame sides */ | |
1111 for (i = 0; i < (height - (20 + 38)) / 29; i++) { | |
1112 /* left */ | |
1113 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 0, 42, | |
1114 0, 20 + i * 29, 12, 29); | |
1115 | |
1116 /* right */ | |
1117 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 32, 42, | |
1118 width - 19, 20 + i * 29, 19, 29); | |
1119 } | |
1120 } | |
1121 | |
1122 | |
1123 void | |
1124 skin_draw_playlistwin_frame(Skin * skin, | |
1125 GdkDrawable * drawable, GdkGC * gc, | |
1126 gint width, gint height, gboolean focus) | |
1127 { | |
1128 skin_draw_playlistwin_frame_top(skin, drawable, gc, width, height, focus); | |
1129 skin_draw_playlistwin_frame_bottom(skin, drawable, gc, width, height, | |
1130 focus); | |
1131 skin_draw_playlistwin_frame_sides(skin, drawable, gc, width, height, | |
1132 focus); | |
1133 } | |
1134 | |
1135 | |
1136 void | |
1137 skin_draw_playlistwin_shaded(Skin * skin, | |
1138 GdkDrawable * drawable, GdkGC * gc, | |
1139 gint width, gboolean focus) | |
1140 { | |
1141 /* The shade mode titlebar skin consists of 4 images: | |
1142 * a) left corner offset (72,42) size (25,14) | |
1143 * b) right corner, focused offset (99,57) size (50,14) | |
1144 * c) right corner, unfocused offset (99,42) size (50,14) | |
1145 * d) bar tile offset (72,57) size (25,14) | |
1146 */ | |
1147 | |
1148 gint i; | |
1149 | |
1150 /* left corner */ | |
1151 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 72, 42, 0, 0, 25, 14); | |
1152 | |
1153 /* bar tile */ | |
1154 for (i = 0; i < (width - 75) / 25; i++) | |
1155 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 72, 57, | |
1156 (i * 25) + 25, 0, 25, 14); | |
1157 | |
1158 /* right corner */ | |
1159 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 99, focus ? 57 : 42, | |
1160 width - 50, 0, 50, 14); | |
1161 } | |
1162 | |
1163 | |
1164 void | |
1165 skin_draw_mainwin_titlebar(Skin * skin, | |
1166 GdkDrawable * drawable, GdkGC * gc, | |
1167 gboolean shaded, gboolean focus) | |
1168 { | |
1169 /* The titlebar skin consists of 2 sets of 2 images, one for for | |
1170 * shaded and the other for unshaded mode, giving a total of 4. | |
1171 * The images are exactly 275x14 pixels, aligned and arranged | |
1172 * vertically on each other in the pixmap in the following order: | |
1173 * | |
1174 * a) unshaded, focused offset (27, 0) | |
1175 * b) unshaded, unfocused offset (27, 15) | |
1176 * c) shaded, focused offset (27, 29) | |
1177 * d) shaded, unfocused offset (27, 42) | |
1178 */ | |
1179 | |
1180 gint y_offset; | |
1181 | |
1182 if (shaded) { | |
1183 if (focus) | |
1184 y_offset = 29; | |
1185 else | |
1186 y_offset = 42; | |
1187 } | |
1188 else { | |
1189 if (focus) | |
1190 y_offset = 0; | |
1191 else | |
1192 y_offset = 15; | |
1193 } | |
1194 | |
1195 skin_draw_pixmap(skin, drawable, gc, SKIN_TITLEBAR, 27, y_offset, | |
1196 0, 0, MAINWIN_WIDTH, MAINWIN_TITLEBAR_HEIGHT); | |
1197 } | |
1198 | |
1199 #if 0 | |
1200 void | |
1201 skin_draw_mainwin(Skin * skin, | |
1202 GdkDrawable * drawable, GdkGC gc, | |
1203 gboolean doublesize, gboolean shaded, gboolean focus) | |
1204 { | |
1205 | |
1206 } | |
1207 #endif |