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