5 #include <gdk-pixbuf-xlib/gdk-pixbuf-xlib.h>
7 #include <libdockapp/dockapp.h>
16 #include "defaultTile.xpm"
17 #include "defaultIcon.xpm"
19 static char ** CurrentDefault
= defaultIcon_xpm
;
23 extern void Pixmaps_FindLoad (const char * name
,
24 Pixmap
* imageP
, Pixmap
* maskP
, int * wP
, int * hP
)
26 static int mustInitGdkPixbuf
= 1 ;
27 char path
[FILENAME_MAX
] ;
30 void (* problem
) (const char *, ...) ;
31 GError
*gerror
= NULL
;
33 if (mustInitGdkPixbuf
)
35 gdk_pixbuf_xlib_init (DADisplay
, DefaultScreen (DADisplay
)) ;
36 mustInitGdkPixbuf
= 0 ;
39 assert (name
!= NULL
) ;
40 assert (imageP
!= NULL
) ;
41 assert (maskP
!= NULL
) ;
42 problem
= (CurrentDefault
== NULL
? error
: warn
) ;
44 #define UseDefault() \
45 if ((pix = gdk_pixbuf_new_from_xpm_data ( \
46 (const char **)CurrentDefault)) == NULL) \
47 error ("can't create internal default pixmap")
49 if (name
== NULL
|| name
[0] == EOS
)
51 if (CurrentDefault
== NULL
)
52 error ("missing image name specification") ;
57 if (! File_FindInPath (path
, sizeof path
, PixmapPath
, name
))
59 problem ("can't find image \"%s\"", name
) ;
63 if ((pix
= gdk_pixbuf_new_from_file (path
, &gerror
)) == NULL
)
65 problem ("can't load image \"%s\"", path
) ;
69 /* get loaded geometry */
70 width
= gdk_pixbuf_get_width (pix
) ;
71 height
= gdk_pixbuf_get_height (pix
) ;
73 /* scale if allowed, possible, and useful */
75 TileXSize
> 0 && TileYSize
> 0 &&
76 (width
> TileXSize
|| height
> TileYSize
))
81 Compare width/TileXSize to height/TileYSize to determine a new
82 size that fits within TileXSize x TileYSize and keeps the same
83 aspect ratio as before. The biggest ratio wins.
85 if (width
*TileYSize
>= height
*TileXSize
)
87 /* width directs re-scaling */
88 height
= (height
* TileXSize
) / width
;
93 /* height directs re-scaling */
94 width
= (width
* TileYSize
) / height
;
98 scaled
= gdk_pixbuf_scale_simple (pix
,
99 width
, height
, GDK_INTERP_HYPER
) ;
100 g_object_unref (pix
) ;
104 if (wP
!= NULL
) *wP
= width
;
105 if (hP
!= NULL
) *hP
= height
;
106 gdk_pixbuf_xlib_render_pixmap_and_mask (pix
, imageP
, maskP
, 128) ;
107 /* don't forget to free now we've done pixmaps */
108 g_object_unref (pix
) ;
112 We have to reimplement a few trivial gdk functions here to avoid linking with
123 extern gint
gdk_screen_width (void)
125 return DisplayWidth (DADisplay
, DefaultScreen (DADisplay
)) ;
128 extern gint
gdk_screen_height (void)
130 return DisplayHeight (DADisplay
, DefaultScreen (DADisplay
)) ;
133 extern gboolean
gdk_color_parse (const gchar
* spec
, GdkColor
* color
)
138 /* Lukasz Pankowski suggested this */
139 if (! XParseColor (DADisplay
,
140 DefaultColormap (DADisplay
, DefaultScreen (DADisplay
)),
145 if (! XAllocNamedColor (DADisplay
,
146 DefaultColormap (DADisplay
, DefaultScreen (DADisplay
)),
147 spec
, & scr
, & exact
))
154 color
->pixel
= scr
.pixel
;
155 color
->red
= scr
.red
;
156 color
->green
= scr
.green
;
157 color
->blue
= scr
.blue
;
164 extern void Pixmaps_FindLoad (const char * name
,
165 Pixmap
* imageP
, Pixmap
* maskP
, int * wP
, int * hP
)
167 char path
[FILENAME_MAX
] ;
169 void (* problem
) (const char *, ...) ;
171 assert (name
!= NULL
) ;
172 assert (imageP
!= NULL
) ;
173 assert (maskP
!= NULL
) ;
175 problem
= (CurrentDefault
== NULL
? error
: warn
) ;
177 #define UseDefault() \
178 if (XpmCreatePixmapFromData (DADisplay, DefaultRootWindow (DADisplay), \
179 CurrentDefault, imageP, maskP, & attr) != XpmSuccess) \
180 error ("can't create internal default pixmap")
182 if (! File_FindInPath (path
, sizeof path
, PixmapPath
, name
))
184 problem ("can't find file \"%s\"", name
) ;
188 if (XpmReadFileToPixmap (DADisplay
, DefaultRootWindow (DADisplay
),
189 path
, imageP
, maskP
, & attr
) != XpmSuccess
)
191 problem ("can't load pixmap \"%s\"", path
) ;
195 if (wP
!= NULL
) *wP
= attr
.width
;
196 if (hP
!= NULL
) *hP
= attr
.height
;
201 extern void Pixmaps_LoadMenu (void)
205 saveAutoScale
= AutoScale
; /* save old value */
206 AutoScale
= false ; /* set temporary value */
207 Pixmaps_FindLoad (Menu_GetPixmap (), & image
, & mask
, NULL
, NULL
) ;
209 DASetPixmap (image
) ;
210 AutoScale
= saveAutoScale
; /* restore initial value */
213 extern void Pixmaps_LoadTile (void)
217 if (TileImage
!= 0) XFreePixmap (DADisplay
, TileImage
) ;
218 if (TileMask
!= 0) XFreePixmap (DADisplay
, TileMask
) ;
220 CurrentDefault
= defaultTile_xpm
;
221 Pixmaps_FindLoad (TilePath
, & TileImage
, & TileMask
, & x
, & y
) ;
222 CurrentDefault
= defaultIcon_xpm
;
224 if (TileXSize
<= 0) TileXSize
= x
;
225 if (TileYSize
<= 0) TileYSize
= y
;
228 extern void Pixmaps_LoadHighlight (void)
232 if (HighlightImage
!= 0) XFreePixmap (DADisplay
, HighlightImage
) ;
233 if (HighlightMask
!= 0) XFreePixmap (DADisplay
, HighlightMask
) ;
235 if (HighlightPath
[0] != EOS
)
237 Pixmaps_FindLoad (HighlightPath
,
238 & HighlightImage
, & HighlightMask
, & x
, & y
) ;