Mercurial > audlegacy
annotate audacious/skin.c @ 1029:54dd4df67688 trunk
[svn] - src/tagging_mp4.c, fileinfo.c, libmp4.c: Finish conversion to internal container code.
- include/mpeg4ip.h, mpeg4ip_version.h, systems.h: Remove libmp4v2.
- libmp4v2/: Remove libmp4v2.
- Makefile.in: Remove references to libmp4v2.
- configure.ac: Remove references to libmp4v2.
author | nenolod |
---|---|
date | Fri, 12 May 2006 06:48:55 -0700 |
parents | 247d1f58fbfe |
children | f866da587845 |
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, | |
551 const gchar * section, const gchar * key) | |
552 { | |
553 gchar *filename, *value; | |
554 GdkColor *color = NULL; | |
555 | |
556 filename = find_file_recursively(path, file); | |
557 if (filename) { | |
558 value = read_ini_string(filename, section, key); | |
559 if (value) { | |
560 gchar *ptr = value; | |
561 gint len; | |
562 | |
563 color = g_new0(GdkColor, 1); | |
564 g_strstrip(value); | |
565 | |
566 if (value[0] == '#') | |
567 ptr++; | |
568 len = strlen(ptr); | |
569 | |
570 /* | |
571 * The handling of incomplete values is done this way | |
572 * to maximize winamp compatibility | |
573 */ | |
574 if (len >= 6) { | |
575 color->red = hex_chars_to_int(*ptr, *(ptr + 1)); | |
576 ptr += 2; | |
577 } | |
578 if (len >= 4) { | |
579 color->green = hex_chars_to_int(*ptr, *(ptr + 1)); | |
580 ptr += 2; | |
581 } | |
582 if (len >= 2) | |
583 color->blue = hex_chars_to_int(*ptr, *(ptr + 1)); | |
584 | |
585 | |
586 gdk_color_alloc(gdk_window_get_colormap(playlistwin->window), | |
587 color); | |
588 g_free(value); | |
589 } | |
590 g_free(filename); | |
591 } | |
592 return color; | |
593 } | |
594 | |
595 | |
596 | |
597 GdkBitmap * | |
598 skin_create_transparent_mask(const gchar * path, | |
599 const gchar * file, | |
600 const gchar * section, | |
601 GdkWindow * window, | |
602 gint width, | |
603 gint height) | |
604 { | |
605 GdkBitmap *mask = NULL; | |
606 GdkGC *gc = NULL; | |
607 GdkColor pattern; | |
608 GdkPoint *gpoints; | |
609 | |
610 gchar *filename = NULL; | |
611 gboolean created_mask = FALSE; | |
612 GArray *num, *point; | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
443
diff
changeset
|
613 guint i, j; |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
443
diff
changeset
|
614 gint k; |
0 | 615 |
616 if (path) | |
617 filename = find_file_recursively(path, file); | |
618 | |
619 /* filename will be null if path wasn't set */ | |
620 if (!filename) { | |
621 return create_default_mask(window, width, height); | |
622 } | |
623 | |
624 if ((num = read_ini_array(filename, section, "NumPoints")) == NULL) { | |
625 g_free(filename); | |
626 return NULL; | |
627 } | |
628 | |
629 if ((point = read_ini_array(filename, section, "PointList")) == NULL) { | |
630 g_array_free(num, TRUE); | |
631 g_free(filename); | |
632 return NULL; | |
633 } | |
634 | |
635 mask = gdk_pixmap_new(window, width, height, 1); | |
636 gc = gdk_gc_new(mask); | |
637 | |
638 pattern.pixel = 0; | |
639 gdk_gc_set_foreground(gc, &pattern); | |
640 gdk_draw_rectangle(mask, gc, TRUE, 0, 0, width, height); | |
641 pattern.pixel = 1; | |
642 gdk_gc_set_foreground(gc, &pattern); | |
643 | |
644 j = 0; | |
645 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
|
646 if ((int)(point->len - j) >= (g_array_index(num, gint, i) * 2)) { |
0 | 647 created_mask = TRUE; |
648 gpoints = g_new(GdkPoint, g_array_index(num, gint, i)); | |
649 for (k = 0; k < g_array_index(num, gint, i); k++) { | |
650 gpoints[k].x = g_array_index(point, gint, j + k * 2); | |
651 gpoints[k].y = g_array_index(point, gint, j + k * 2 + 1); | |
652 } | |
653 j += k * 2; | |
654 gdk_draw_polygon(mask, gc, TRUE, gpoints, | |
655 g_array_index(num, gint, i)); | |
656 g_free(gpoints); | |
657 } | |
658 } | |
659 g_array_free(num, TRUE); | |
660 g_array_free(point, TRUE); | |
661 g_free(filename); | |
662 | |
663 if (!created_mask) | |
664 gdk_draw_rectangle(mask, gc, TRUE, 0, 0, width, height); | |
665 | |
666 gdk_gc_destroy(gc); | |
667 | |
668 return mask; | |
669 } | |
670 | |
671 void | |
672 skin_load_viscolor(Skin * skin, const gchar * path, const gchar * basename) | |
673 { | |
674 FILE *file; | |
675 gint i, c; | |
676 gchar line[256], *filename; | |
677 GArray *a; | |
678 | |
679 g_return_if_fail(skin != NULL); | |
680 g_return_if_fail(path != NULL); | |
681 g_return_if_fail(basename != NULL); | |
682 | |
683 skin_set_default_vis_color(skin); | |
684 | |
685 filename = find_file_recursively(path, basename); | |
686 if (!filename) | |
687 return; | |
688 | |
689 if (!(file = fopen(filename, "r"))) { | |
690 g_free(filename); | |
691 return; | |
692 } | |
693 | |
694 g_free(filename); | |
695 | |
696 for (i = 0; i < 24; i++) { | |
697 if (fgets(line, 255, file)) { | |
698 a = string_to_garray(line); | |
699 if (a->len > 2) { | |
700 for (c = 0; c < 3; c++) | |
701 skin->vis_color[i][c] = g_array_index(a, gint, c); | |
702 } | |
703 g_array_free(a, TRUE); | |
704 } | |
705 else | |
706 break; | |
707 } | |
708 | |
709 fclose(file); | |
710 } | |
711 | |
712 #if 0 | |
713 static void | |
714 skin_numbers_generate_dash(Skin * skin) | |
715 { | |
716 GdkGC *gc; | |
717 GdkPixmap *pixmap; | |
718 SkinPixmap *numbers; | |
719 | |
720 g_return_if_fail(skin != NULL); | |
721 | |
722 numbers = &skin->pixmaps[SKIN_NUMBERS]; | |
723 if (!numbers->pixmap || numbers->current_width < 99) | |
724 return; | |
725 | |
726 gc = gdk_gc_new(numbers->pixmap); | |
727 pixmap = gdk_pixmap_new(mainwin->window, 108, | |
728 numbers->current_height, | |
729 -1); | |
730 | |
731 skin_draw_pixmap(skin, pixmap, gc, SKIN_NUMBERS, 0, 0, 0, 0, 99, 13); | |
732 skin_draw_pixmap(skin, pixmap, gc, SKIN_NUMBERS, 90, 0, 99, 0, 9, 13); | |
733 skin_draw_pixmap(skin, pixmap, gc, SKIN_NUMBERS, 20, 6, 101, 6, 5, 1); | |
734 | |
735 g_object_unref(numbers->pixmap); | |
736 g_object_unref(gc); | |
737 | |
738 numbers->pixmap = pixmap; | |
739 numbers->current_width = 108; | |
740 } | |
741 #endif | |
742 | |
743 static void | |
744 skin_load_cursor(Skin * skin, const gchar * dirname) | |
745 { | |
746 const gchar * basename = "normal.cur"; | |
747 gchar * filename = NULL; | |
748 GdkPixbuf * cursor_pixbuf = NULL; | |
749 GdkPixbufAnimation * cursor_animated = NULL; | |
750 GdkCursor * cursor_gdk = NULL; | |
751 GError * error = NULL; | |
752 | |
753 filename = find_file_recursively(dirname, basename); | |
754 | |
755 if (filename && cfg.custom_cursors) { | |
756 cursor_animated = gdk_pixbuf_animation_new_from_file(filename, &error); | |
757 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
|
758 cursor_gdk = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), |
0 | 759 cursor_pixbuf, 0, 0); |
760 } 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
|
761 cursor_gdk = gdk_cursor_new(GDK_LEFT_PTR); |
0 | 762 } |
763 | |
764 gdk_window_set_cursor(mainwin->window, cursor_gdk); | |
765 gdk_window_set_cursor(playlistwin->window, cursor_gdk); | |
766 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
|
767 gdk_cursor_unref(cursor_gdk); |
0 | 768 } |
769 | |
770 static void | |
771 skin_load_pixmaps(Skin * skin, const gchar * path) | |
772 { | |
773 GdkPixmap *text_pm; | |
774 guint i; | |
775 | |
776 for (i = 0; i < SKIN_PIXMAP_COUNT; i++) | |
777 skin_load_pixmap_id(skin, i, path); | |
778 | |
779 text_pm = skin->pixmaps[SKIN_TEXT].pixmap; | |
780 | |
781 if (text_pm) | |
782 skin_get_textcolors(text_pm, skin->textbg, skin->textfg); | |
783 | |
784 #if 0 | |
785 if (skin->pixmaps[SKIN_NUMBERS].pixmap) | |
786 skin_numbers_generate_dash(skin); | |
787 #endif | |
788 | |
789 skin->colors[SKIN_PLEDIT_NORMAL] = | |
790 skin_load_color(path, "pledit.txt", "text", "normal"); | |
791 skin->colors[SKIN_PLEDIT_CURRENT] = | |
792 skin_load_color(path, "pledit.txt", "text", "current"); | |
793 skin->colors[SKIN_PLEDIT_NORMALBG] = | |
794 skin_load_color(path, "pledit.txt", "text", "normalbg"); | |
795 skin->colors[SKIN_PLEDIT_SELECTEDBG] = | |
796 skin_load_color(path, "pledit.txt", "text", "selectedbg"); | |
797 | |
798 skin_mask_create(skin, path, SKIN_MASK_MAIN, mainwin->window); | |
799 skin_mask_create(skin, path, SKIN_MASK_MAIN_SHADE, mainwin->window); | |
800 | |
801 skin_mask_create(skin, path, SKIN_MASK_EQ, equalizerwin->window); | |
802 skin_mask_create(skin, path, SKIN_MASK_EQ_SHADE, equalizerwin->window); | |
803 | |
804 skin_load_viscolor(skin, path, "viscolor.txt"); | |
805 } | |
806 | |
807 static gboolean | |
808 skin_load_nolock(Skin * skin, const gchar * path, gboolean force) | |
809 { | |
810 gchar *cpath; | |
811 | |
812 g_return_val_if_fail(skin != NULL, FALSE); | |
813 g_return_val_if_fail(path != NULL, FALSE); | |
814 REQUIRE_LOCK(skin->lock); | |
815 | |
816 if (!g_file_test(path, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_DIR)) | |
817 return FALSE; | |
818 | |
819 if (!force) { | |
820 if (skin->path) | |
821 if (!strcmp(skin->path, path)) | |
822 return FALSE; | |
823 } | |
824 | |
825 skin_current_num++; | |
826 | |
827 skin->path = g_strdup(path); | |
828 | |
829 if (!file_is_archive(path)) { | |
830 skin_load_pixmaps(skin, path); | |
831 skin_load_cursor(skin, path); | |
839 | 832 |
833 /* Parse the hints for this skin. */ | |
834 skin_parse_hints(skin, NULL); | |
835 | |
0 | 836 return TRUE; |
837 } | |
838 | |
839 if (!(cpath = archive_decompress(path))) { | |
840 g_message("Unable to extract skin archive (%s)", path); | |
841 return FALSE; | |
842 } | |
843 | |
844 skin_load_pixmaps(skin, cpath); | |
845 skin_load_cursor(skin, cpath); | |
839 | 846 |
847 /* Parse the hints for this skin. */ | |
848 skin_parse_hints(skin, cpath); | |
849 | |
0 | 850 del_directory(cpath); |
851 g_free(cpath); | |
852 | |
853 return TRUE; | |
854 } | |
855 | |
856 void | |
857 skin_install_skin(const gchar * path) | |
858 { | |
859 gchar *command; | |
860 | |
861 g_return_if_fail(path != NULL); | |
862 | |
863 command = g_strdup_printf("cp %s %s", path, bmp_paths[BMP_PATH_USER_SKIN_DIR]); | |
864 if (system(command)) { | |
865 g_message("Unable to install skin (%s) into user directory (%s)", | |
866 path, bmp_paths[BMP_PATH_USER_SKIN_DIR]); | |
867 } | |
868 g_free(command); | |
869 } | |
870 | |
871 | |
872 gboolean | |
873 skin_load(Skin * skin, const gchar * path) | |
874 { | |
875 gboolean error; | |
876 | |
877 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
|
878 |
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
|
879 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
|
880 return FALSE; |
0 | 881 |
882 skin_lock(skin); | |
883 error = skin_load_nolock(skin, path, FALSE); | |
884 skin_unlock(skin); | |
885 | |
886 return error; | |
887 } | |
888 | |
889 gboolean | |
890 skin_reload_forced(void) | |
891 { | |
892 gboolean error; | |
893 | |
894 skin_lock(bmp_active_skin); | |
895 error = skin_load_nolock(bmp_active_skin, bmp_active_skin->path, TRUE); | |
896 skin_unlock(bmp_active_skin); | |
897 | |
898 return error; | |
899 } | |
900 | |
901 void | |
902 skin_reload(Skin * skin) | |
903 { | |
904 g_return_if_fail(skin != NULL); | |
905 skin_load_nolock(skin, skin->path, TRUE); | |
906 } | |
907 | |
908 | |
909 static SkinPixmap * | |
910 skin_get_pixmap(Skin * skin, SkinPixmapId map_id) | |
911 { | |
912 g_return_val_if_fail(skin != NULL, NULL); | |
913 g_return_val_if_fail(map_id < SKIN_PIXMAP_COUNT, NULL); | |
914 | |
915 return &skin->pixmaps[map_id]; | |
916 } | |
917 | |
918 GdkBitmap * | |
919 skin_get_mask(Skin * skin, SkinMaskId mi) | |
920 { | |
921 g_return_val_if_fail(skin != NULL, NULL); | |
922 g_return_val_if_fail(mi < SKIN_PIXMAP_COUNT, NULL); | |
923 | |
924 return skin->masks[mi]; | |
925 } | |
926 | |
927 GdkColor * | |
928 skin_get_color(Skin * skin, SkinColorId color_id) | |
929 { | |
930 GdkColor *ret = NULL; | |
931 | |
932 g_return_val_if_fail(skin != NULL, NULL); | |
933 | |
934 switch (color_id) { | |
935 case SKIN_TEXTBG: | |
936 if (skin->pixmaps[SKIN_TEXT].pixmap) | |
937 ret = skin->textbg; | |
938 else | |
939 ret = skin->def_textbg; | |
940 break; | |
941 case SKIN_TEXTFG: | |
942 if (skin->pixmaps[SKIN_TEXT].pixmap) | |
943 ret = skin->textfg; | |
944 else | |
945 ret = skin->def_textfg; | |
946 break; | |
947 default: | |
948 if (color_id < SKIN_COLOR_COUNT) | |
949 ret = skin->colors[color_id]; | |
950 break; | |
951 } | |
952 return ret; | |
953 } | |
954 | |
955 void | |
956 skin_get_viscolor(Skin * skin, guchar vis_color[24][3]) | |
957 { | |
958 gint i; | |
959 | |
960 g_return_if_fail(skin != NULL); | |
961 | |
962 for (i = 0; i < 24; i++) { | |
963 vis_color[i][0] = skin->vis_color[i][0]; | |
964 vis_color[i][1] = skin->vis_color[i][1]; | |
965 vis_color[i][2] = skin->vis_color[i][2]; | |
966 } | |
967 } | |
968 | |
969 gint | |
970 skin_get_id(void) | |
971 { | |
972 return skin_current_num; | |
973 } | |
974 | |
975 void | |
976 skin_draw_pixmap(Skin * skin, GdkDrawable * drawable, GdkGC * gc, | |
977 SkinPixmapId pixmap_id, | |
978 gint xsrc, gint ysrc, gint xdest, gint ydest, | |
979 gint width, gint height) | |
980 { | |
981 SkinPixmap *pixmap; | |
982 | |
983 g_return_if_fail(skin != NULL); | |
984 | |
985 pixmap = skin_get_pixmap(skin, pixmap_id); | |
986 g_return_if_fail(pixmap != NULL); | |
987 g_return_if_fail(pixmap->pixmap != NULL); | |
988 | |
989 if (xsrc > pixmap->width || ysrc > pixmap->height) | |
990 return; | |
991 | |
992 width = MIN(width, pixmap->width - xsrc); | |
993 height = MIN(height, pixmap->height - ysrc); | |
994 gdk_draw_pixmap(drawable, gc, pixmap->pixmap, xsrc, ysrc, | |
995 xdest, ydest, width, height); | |
996 } | |
997 | |
998 void | |
999 skin_get_eq_spline_colors(Skin * skin, guint32 colors[19]) | |
1000 { | |
1001 gint i; | |
1002 GdkPixmap *pixmap; | |
1003 GdkImage *img; | |
1004 SkinPixmap *eqmainpm; | |
1005 | |
1006 g_return_if_fail(skin != NULL); | |
1007 | |
1008 eqmainpm = &skin->pixmaps[SKIN_EQMAIN]; | |
1009 if (eqmainpm->pixmap && | |
1010 eqmainpm->current_width >= 116 && eqmainpm->current_height >= 313) | |
1011 pixmap = eqmainpm->pixmap; | |
1012 else | |
1013 return; | |
1014 | |
1015 if (!GDK_IS_DRAWABLE(pixmap)) | |
1016 return; | |
1017 | |
1018 if (!(img = gdk_drawable_get_image(pixmap, 115, 294, 1, 19))) | |
1019 return; | |
1020 | |
1021 for (i = 0; i < 19; i++) | |
1022 colors[i] = gdk_image_get_pixel(img, 0, i); | |
1023 | |
1024 gdk_image_destroy(img); | |
1025 } | |
1026 | |
1027 | |
1028 static void | |
1029 skin_draw_playlistwin_frame_top(Skin * skin, | |
1030 GdkDrawable * drawable, | |
1031 GdkGC * gc, | |
1032 gint width, gint height, gboolean focus) | |
1033 { | |
1034 /* The title bar skin consists of 2 sets of 4 images, 1 set | |
1035 * for focused state and the other for unfocused. The 4 images | |
1036 * are: | |
1037 * | |
1038 * a. right corner (25,20) | |
1039 * b. left corner (25,20) | |
1040 * c. tiler (25,20) | |
1041 * d. title (100,20) | |
1042 * | |
1043 * min allowed width = 100+25+25 = 150 | |
1044 */ | |
1045 | |
1046 gint i, y, c; | |
1047 | |
1048 /* get y offset of the pixmap set to use */ | |
1049 if (focus) | |
1050 y = 0; | |
1051 else | |
1052 y = 21; | |
1053 | |
1054 /* left corner */ | |
1055 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 0, y, 0, 0, 25, 20); | |
1056 | |
1057 /* titlebar title */ | |
1058 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 26, y, | |
1059 (width - 100) / 2, 0, 100, 20); | |
1060 | |
1061 /* titlebar right corner */ | |
1062 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 153, y, | |
1063 width - 25, 0, 25, 20); | |
1064 | |
1065 /* tile draw the remaining frame */ | |
1066 | |
1067 /* compute tile count */ | |
1068 c = (width - (100 + 25 + 25)) / 25; | |
1069 | |
1070 for (i = 0; i < c / 2; i++) { | |
1071 /* left of title */ | |
1072 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 127, y, | |
1073 25 + i * 25, 0, 25, 20); | |
1074 | |
1075 /* right of title */ | |
1076 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 127, y, | |
1077 (width + 100) / 2 + i * 25, 0, 25, 20); | |
1078 } | |
1079 | |
1080 if (c & 1) { | |
1081 /* Odd tile count, so one remaining to draw. Here we split | |
1082 * it into two and draw half on either side of the title */ | |
1083 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 127, y, | |
1084 ((c / 2) * 25) + 25, 0, 12, 20); | |
1085 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 127, y, | |
1086 (width / 2) + ((c / 2) * 25) + 50, 0, 13, 20); | |
1087 } | |
1088 } | |
1089 | |
1090 static void | |
1091 skin_draw_playlistwin_frame_bottom(Skin * skin, | |
1092 GdkDrawable * drawable, | |
1093 GdkGC * gc, | |
1094 gint width, gint height, gboolean focus) | |
1095 { | |
1096 /* The bottom frame skin consists of 1 set of 4 images. The 4 | |
1097 * images are: | |
1098 * | |
1099 * a. left corner with menu buttons (125,38) | |
1100 * b. visualization window (75,38) | |
1101 * c. right corner with play buttons (150,38) | |
1102 * d. frame tile (25,38) | |
1103 * | |
1104 * (min allowed width = 125+150+25=300 | |
1105 */ | |
1106 | |
1107 gint i, c; | |
1108 | |
1109 /* bottom left corner (menu buttons) */ | |
1110 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 0, 72, | |
1111 0, height - 38, 125, 38); | |
1112 | |
1113 c = (width - 275) / 25; | |
1114 | |
1115 /* draw visualization window, if width allows */ | |
1116 if (c >= 3) { | |
1117 c -= 3; | |
1118 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 205, 0, | |
1119 width - (150 + 75), height - 38, 75, 38); | |
1120 } | |
1121 | |
1122 /* Bottom right corner (playbuttons etc) */ | |
1123 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, | |
1124 126, 72, width - 150, height - 38, 150, 38); | |
1125 | |
1126 /* Tile draw the remaining undrawn portions */ | |
1127 for (i = 0; i < c; i++) | |
1128 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 179, 0, | |
1129 125 + i * 25, height - 38, 25, 38); | |
1130 } | |
1131 | |
1132 static void | |
1133 skin_draw_playlistwin_frame_sides(Skin * skin, | |
1134 GdkDrawable * drawable, | |
1135 GdkGC * gc, | |
1136 gint width, gint height, gboolean focus) | |
1137 { | |
1138 /* The side frames consist of 2 tile images. 1 for the left, 1 for | |
1139 * the right. | |
1140 * a. left (12,29) | |
1141 * b. right (19,29) | |
1142 */ | |
1143 | |
1144 gint i; | |
1145 | |
1146 /* frame sides */ | |
1147 for (i = 0; i < (height - (20 + 38)) / 29; i++) { | |
1148 /* left */ | |
1149 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 0, 42, | |
1150 0, 20 + i * 29, 12, 29); | |
1151 | |
1152 /* right */ | |
1153 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 32, 42, | |
1154 width - 19, 20 + i * 29, 19, 29); | |
1155 } | |
1156 } | |
1157 | |
1158 | |
1159 void | |
1160 skin_draw_playlistwin_frame(Skin * skin, | |
1161 GdkDrawable * drawable, GdkGC * gc, | |
1162 gint width, gint height, gboolean focus) | |
1163 { | |
1164 skin_draw_playlistwin_frame_top(skin, drawable, gc, width, height, focus); | |
1165 skin_draw_playlistwin_frame_bottom(skin, drawable, gc, width, height, | |
1166 focus); | |
1167 skin_draw_playlistwin_frame_sides(skin, drawable, gc, width, height, | |
1168 focus); | |
1169 } | |
1170 | |
1171 | |
1172 void | |
1173 skin_draw_playlistwin_shaded(Skin * skin, | |
1174 GdkDrawable * drawable, GdkGC * gc, | |
1175 gint width, gboolean focus) | |
1176 { | |
1177 /* The shade mode titlebar skin consists of 4 images: | |
1178 * a) left corner offset (72,42) size (25,14) | |
1179 * b) right corner, focused offset (99,57) size (50,14) | |
1180 * c) right corner, unfocused offset (99,42) size (50,14) | |
1181 * d) bar tile offset (72,57) size (25,14) | |
1182 */ | |
1183 | |
1184 gint i; | |
1185 | |
1186 /* left corner */ | |
1187 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 72, 42, 0, 0, 25, 14); | |
1188 | |
1189 /* bar tile */ | |
1190 for (i = 0; i < (width - 75) / 25; i++) | |
1191 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 72, 57, | |
1192 (i * 25) + 25, 0, 25, 14); | |
1193 | |
1194 /* right corner */ | |
1195 skin_draw_pixmap(skin, drawable, gc, SKIN_PLEDIT, 99, focus ? 57 : 42, | |
1196 width - 50, 0, 50, 14); | |
1197 } | |
1198 | |
1199 | |
1200 void | |
1201 skin_draw_mainwin_titlebar(Skin * skin, | |
1202 GdkDrawable * drawable, GdkGC * gc, | |
1203 gboolean shaded, gboolean focus) | |
1204 { | |
1205 /* The titlebar skin consists of 2 sets of 2 images, one for for | |
1206 * shaded and the other for unshaded mode, giving a total of 4. | |
1207 * The images are exactly 275x14 pixels, aligned and arranged | |
1208 * vertically on each other in the pixmap in the following order: | |
1209 * | |
1210 * a) unshaded, focused offset (27, 0) | |
1211 * b) unshaded, unfocused offset (27, 15) | |
1212 * c) shaded, focused offset (27, 29) | |
1213 * d) shaded, unfocused offset (27, 42) | |
1214 */ | |
1215 | |
1216 gint y_offset; | |
1217 | |
1218 if (shaded) { | |
1219 if (focus) | |
1220 y_offset = 29; | |
1221 else | |
1222 y_offset = 42; | |
1223 } | |
1224 else { | |
1225 if (focus) | |
1226 y_offset = 0; | |
1227 else | |
1228 y_offset = 15; | |
1229 } | |
1230 | |
1231 skin_draw_pixmap(skin, drawable, gc, SKIN_TITLEBAR, 27, y_offset, | |
1232 0, 0, MAINWIN_WIDTH, MAINWIN_TITLEBAR_HEIGHT); | |
1233 } | |
1234 | |
1235 #if 0 | |
1236 void | |
1237 skin_draw_mainwin(Skin * skin, | |
1238 GdkDrawable * drawable, GdkGC gc, | |
1239 gboolean doublesize, gboolean shaded, gboolean focus) | |
1240 { | |
1241 | |
1242 } | |
1243 #endif |