CTWM
Toggle main menu visibility
Loading...
Searching...
No Matches
/usr/src/RPM/BUILD/ctwm-4.1.0/image_bitmap.c
Go to the documentation of this file.
1
/*
2
* Bitmap image handling functions
3
*
4
* These are what's called "XBM", and represented by the Pixmap X data
5
* type (which has noting to do with "XPM" X PixMaps, just to confuse
6
* you). This is the format used for various builtin images, buttons,
7
* and cursors, and is also the fallback type for any user-specified
8
* images. Assuming any user has made and specified an XBM since the
9
* 1980's.
10
*/
11
12
#include "
ctwm.h
"
13
14
#include <X11/Xmu/Drawing.h>
15
16
#include "
screen.h
"
17
#include "
util.h
"
18
19
#include "
image.h
"
20
#include "
image_bitmap.h
"
21
#include "
image_bitmap_builtin.h
"
22
23
24
/* Shared with cursor.c for bitmap cursors */
25
int
HotX
,
HotY
;
26
27
28
static
Image
*
LoadBitmapImage
(
const
char
*name,
ColorPair
cp);
29
static
Pixmap
FindBitmap
(
const
char
*name,
unsigned
int
*widthp,
30
unsigned
int
*heightp);
31
32
33
/*
34
* External API's
35
*/
36
37
/* Simple load-by-name */
38
Pixmap
39
GetBitmap
(
const
char
*name)
40
{
41
return
FindBitmap
(name, &
JunkWidth
, &
JunkHeight
);
42
}
43
44
45
/*
46
* Load with FG/BG adjusted to given colorpair
47
*/
48
Image
*
49
GetBitmapImage
(
const
char
*name,
ColorPair
cp)
50
{
51
/* Non-animated */
52
if
(! strchr(name,
'%'
)) {
53
return
(
LoadBitmapImage
(name, cp));
54
}
55
56
/* Animated */
57
return
get_image_anim_cp
(name, cp,
LoadBitmapImage
);
58
}
59
60
61
/*
62
* Internal bits used by the above
63
*/
64
65
/***********************************************************************
66
*
67
* Procedure:
68
* FindBitmap - read in a bitmap file and return size
69
*
70
* Returned Value:
71
* the pixmap associated with the bitmap
72
* widthp - pointer to width of bitmap
73
* heightp - pointer to height of bitmap
74
*
75
* Inputs:
76
* name - the filename to read
77
*
78
***********************************************************************
79
*/
80
static
Pixmap
81
FindBitmap
(
const
char
*name,
unsigned
int
*widthp,
82
unsigned
int
*heightp)
83
{
84
char
*bigname;
85
Pixmap pm;
86
87
if
(!name) {
88
return
None;
89
}
90
91
/*
92
* Names of the form :name refer to hardcoded images that are scaled to
93
* look nice in title buttons. Eventually, it would be nice to put in a
94
* menu symbol as well....
95
*/
96
if
(name[0] ==
':'
) {
97
return
get_builtin_plain_pixmap
(name, widthp, heightp);
98
}
99
100
/*
101
* Generate a full pathname with any special prefix characters (such
102
* as ~) expanded.
103
*/
104
bigname =
ExpandFilename
(name);
105
if
(!bigname) {
106
/* Something failed bad */
107
return
None;
108
}
109
110
/*
111
* look along bitmapFilePath resource same as toolkit clients
112
*/
113
pm = XmuLocateBitmapFile(ScreenOfDisplay(
dpy
,
Scr
->screen), bigname, NULL,
114
0, (
int
*)widthp, (
int
*)heightp, &
HotX
, &
HotY
);
115
if
(pm == None &&
Scr
->IconDirectory && bigname[0] !=
'/'
) {
116
/*
117
* Didn't find it. Attempt to find icon in old IconDirectory
118
* (now obsolete)
119
*/
120
free(bigname);
121
asprintf(&bigname,
"%s/%s"
,
Scr
->IconDirectory, name);
122
if
(XReadBitmapFile(
dpy
,
Scr
->Root, bigname, widthp, heightp, &pm,
123
&
HotX
, &
HotY
) != BitmapSuccess) {
124
pm = None;
125
}
126
}
127
free(bigname);
128
if
((pm == None) &&
reportfilenotfound
) {
129
fprintf(stderr,
"%s: unable to find bitmap \"%s\"\n"
,
ProgramName
, name);
130
}
131
132
return
pm;
133
}
134
135
136
static
Image
*
137
LoadBitmapImage
(
const
char
*name,
ColorPair
cp)
138
{
139
Image
*image;
140
Pixmap bm;
141
unsigned
int
width, height;
142
XGCValues gcvalues;
143
144
if
(
Scr
->rootGC == (GC) 0) {
145
Scr
->rootGC = XCreateGC(
dpy
,
Scr
->Root, 0, &gcvalues);
146
}
147
bm =
FindBitmap
(name, &width, &height);
148
if
(bm == None) {
149
return
NULL;
150
}
151
152
image =
AllocImage
();
153
image->
pixmap
= XCreatePixmap(
dpy
,
Scr
->Root, width, height,
Scr
->d_depth);
154
gcvalues.background = cp.
back
;
155
gcvalues.foreground = cp.
fore
;
156
XChangeGC(
dpy
,
Scr
->rootGC, GCForeground | GCBackground, &gcvalues);
157
XCopyPlane(
dpy
, bm, image->
pixmap
,
Scr
->rootGC, 0, 0, width, height,
158
0, 0, (
unsigned
long
) 1);
159
XFreePixmap(
dpy
, bm);
160
image->
width
= width;
161
image->
height
= height;
162
return
image;
163
}
164
ctwm.h
ProgramName
char * ProgramName
Definition
ctwm_main.c:146
JunkWidth
unsigned int JunkWidth
Definition
ctwm_main.c:144
dpy
Display * dpy
Definition
ctwm_main.c:84
JunkHeight
unsigned int JunkHeight
Definition
ctwm.h:359
Scr
#define Scr
reportfilenotfound
bool reportfilenotfound
Definition
image.c:29
get_image_anim_cp
Image * get_image_anim_cp(const char *name, ColorPair cp, Image *(*imgloader)(const char *, ColorPair))
Definition
image.c:277
AllocImage
Image * AllocImage(void)
Definition
image.c:158
image.h
LoadBitmapImage
static Image * LoadBitmapImage(const char *name, ColorPair cp)
Definition
image_bitmap.c:137
HotX
int HotX
Definition
image_bitmap.c:25
FindBitmap
static Pixmap FindBitmap(const char *name, unsigned int *widthp, unsigned int *heightp)
Definition
image_bitmap.c:81
GetBitmapImage
Image * GetBitmapImage(const char *name, ColorPair cp)
Definition
image_bitmap.c:49
GetBitmap
Pixmap GetBitmap(const char *name)
Definition
image_bitmap.c:39
HotY
int HotY
Definition
image_bitmap.c:25
image_bitmap.h
get_builtin_plain_pixmap
Pixmap get_builtin_plain_pixmap(const char *name, unsigned int *widthp, unsigned int *heightp)
Definition
image_bitmap_builtin.c:43
image_bitmap_builtin.h
screen.h
ColorPair
Definition
ctwm.h:140
ColorPair::back
Pixel back
Definition
ctwm.h:141
ColorPair::fore
Pixel fore
Definition
ctwm.h:141
Image
Definition
image.h:9
Image::height
int height
Definition
image.h:13
Image::pixmap
Pixmap pixmap
Definition
image.h:10
Image::width
int width
Definition
image.h:12
ExpandFilename
char * ExpandFilename(const char *name)
Definition
util.c:131
util.h
image_bitmap.c
Generated by
1.18.0