CTWM
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"
22
23
24/* Shared with cursor.c for bitmap cursors */
26
27
28static Image *LoadBitmapImage(const char *name, ColorPair cp);
29static 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 */
39GetBitmap(const char *name)
40{
41 return FindBitmap(name, &JunkWidth, &JunkHeight);
42}
43
44
45/*
46 * Load with FG/BG adjusted to given colorpair
47 */
48Image *
49GetBitmapImage(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 */
80static Pixmap
81FindBitmap(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] == ':') {
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 */
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);
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
136static Image *
137LoadBitmapImage(const char *name, ColorPair cp)
138{
139 Image *image;
140 Pixmap bm;
141 unsigned int width, height;
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;
157 XCopyPlane(dpy, bm, image->pixmap, Scr->rootGC, 0, 0, width, height,
158 0, 0, (unsigned long) 1);
160 image->width = width;
161 image->height = height;
162 return image;
163}
164
static int PlaceX
Definition add_window.c:82
char * ProgramName
Definition ctwm_main.c:146
unsigned int JunkWidth
Definition ctwm_main.c:144
Display * dpy
Definition ctwm_main.c:84
unsigned int JunkHeight
Definition ctwm.h:359
#define Scr
bool reportfilenotfound
Definition image.c:29
Image * get_image_anim_cp(const char *name, ColorPair cp, Image *(*imgloader)(const char *, ColorPair))
Definition image.c:277
Image * AllocImage(void)
Definition image.c:158
static Image * LoadBitmapImage(const char *name, ColorPair cp)
int HotX
static Pixmap FindBitmap(const char *name, unsigned int *widthp, unsigned int *heightp)
Image * GetBitmapImage(const char *name, ColorPair cp)
Pixmap GetBitmap(const char *name)
int HotY
Pixmap get_builtin_plain_pixmap(const char *name, unsigned int *widthp, unsigned int *heightp)
Pixel back
Definition ctwm.h:141
Pixel fore
Definition ctwm.h:141
Definition image.h:9
int height
Definition image.h:13
Pixmap pixmap
Definition image.h:10
int width
Definition image.h:12
char * ExpandFilename(const char *name)
Definition util.c:131