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