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