Syncing some files updated after running configure
[wmaker-crm.git] / WINGs / wpixmap.c
blob49b99bb5cefc665ac22336df947c10a078281b7f
2 #include "WINGsP.h"
4 #include <wraster.h>
7 WMPixmap*
8 WMRetainPixmap(WMPixmap *pixmap)
10 if (pixmap)
11 pixmap->refCount++;
13 return pixmap;
17 void
18 WMReleasePixmap(WMPixmap *pixmap)
20 wassertr(pixmap!=NULL);
22 pixmap->refCount--;
24 if (pixmap->refCount<1) {
25 XFreePixmap(pixmap->screen->display, pixmap->pixmap);
26 if (pixmap->mask)
27 XFreePixmap(pixmap->screen->display, pixmap->mask);
28 free(pixmap);
33 WMPixmap*
34 WMCreatePixmap(WMScreen *scrPtr, int width, int height, int depth, Bool masked)
36 WMPixmap *pixPtr;
38 pixPtr = malloc(sizeof(WMPixmap));
39 if (!pixPtr) {
40 return NULL;
42 pixPtr->screen = scrPtr;
43 pixPtr->width = width;
44 pixPtr->height = height;
45 pixPtr->depth = depth;
46 pixPtr->refCount = 1;
48 pixPtr->pixmap = XCreatePixmap(scrPtr->display, W_DRAWABLE(scrPtr),
49 width, height, depth);
50 if (masked) {
51 pixPtr->mask = XCreatePixmap(scrPtr->display, W_DRAWABLE(scrPtr),
52 width, height, 1);
53 } else {
54 pixPtr->mask = None;
57 return pixPtr;
61 WMPixmap*
62 WMCreatePixmapFromXPixmaps(WMScreen *scrPtr, Pixmap pixmap, Pixmap mask,
63 int width, int height, int depth)
65 WMPixmap *pixPtr;
67 pixPtr = malloc(sizeof(WMPixmap));
68 if (!pixPtr) {
69 return NULL;
71 pixPtr->screen = scrPtr;
72 pixPtr->pixmap = pixmap;
73 pixPtr->mask = mask;
74 pixPtr->width = width;
75 pixPtr->height = height;
76 pixPtr->depth = depth;
77 pixPtr->refCount = 1;
79 return pixPtr;
85 WMPixmap*
86 WMCreatePixmapFromFile(WMScreen *scrPtr, char *fileName)
88 WMPixmap *pixPtr;
89 RImage *image;
91 image = RLoadImage(scrPtr->rcontext, fileName, 0);
92 if (!image)
93 return NULL;
95 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127);
97 RDestroyImage(image);
99 return pixPtr;
103 WMPixmap*
104 WMCreatePixmapFromRImage(WMScreen *scrPtr, RImage *image, int threshold)
106 WMPixmap *pixPtr;
107 Pixmap pixmap, mask;
109 if (!RConvertImageMask(scrPtr->rcontext, image, &pixmap, &mask,
110 threshold)) {
111 return NULL;
114 pixPtr = malloc(sizeof(WMPixmap));
115 if (!pixPtr) {
116 return NULL;
118 pixPtr->screen = scrPtr;
119 pixPtr->pixmap = pixmap;
120 pixPtr->mask = mask;
121 pixPtr->width = image->width;
122 pixPtr->height = image->height;
123 pixPtr->depth = scrPtr->depth;
124 pixPtr->refCount = 1;
126 return pixPtr;
130 WMPixmap*
131 WMCreateBlendedPixmapFromFile(WMScreen *scrPtr, char *fileName, RColor *color)
133 WMPixmap *pixPtr;
134 RImage *image;
137 image = RLoadImage(scrPtr->rcontext, fileName, 0);
138 if (!image)
139 return NULL;
141 RCombineImageWithColor(image, color);
143 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 0);
145 RDestroyImage(image);
147 return pixPtr;
151 WMPixmap*
152 WMCreatePixmapFromXPMData(WMScreen *scrPtr, char **data)
154 WMPixmap *pixPtr;
155 RImage *image;
157 image = RGetImageFromXPMData(scrPtr->rcontext, data);
158 if (!image)
159 return NULL;
161 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127);
163 RDestroyImage(image);
165 return pixPtr;
169 Pixmap
170 WMGetPixmapXID(WMPixmap *pixmap)
172 wassertrv(pixmap != NULL, None);
174 return pixmap->pixmap;
178 Pixmap
179 WMGetPixmapMaskXID(WMPixmap *pixmap)
181 wassertrv(pixmap != NULL, None);
183 return pixmap->mask;
187 WMSize
188 WMGetPixmapSize(WMPixmap *pixmap)
190 WMSize size = {0,0};
192 wassertrv(pixmap != NULL, size);
194 size.width = pixmap->width;
195 size.height = pixmap->height;
197 return size;
201 WMPixmap*
202 WMGetSystemPixmap(WMScreen *scr, int image)
204 switch (image) {
205 case WSIReturnArrow:
206 return WMRetainPixmap(scr->buttonArrow);
208 case WSIHighlightedReturnArrow:
209 return WMRetainPixmap(scr->pushedButtonArrow);
211 case WSIScrollerDimple:
212 return WMRetainPixmap(scr->scrollerDimple);
214 case WSIArrowLeft:
215 return WMRetainPixmap(scr->leftArrow);
217 case WSIHighlightedArrowLeft:
218 return WMRetainPixmap(scr->hiLeftArrow);
220 case WSIArrowRight:
221 return WMRetainPixmap(scr->rightArrow);
223 case WSIHighlightedArrowRight:
224 return WMRetainPixmap(scr->hiRightArrow);
226 case WSIArrowUp:
227 return WMRetainPixmap(scr->upArrow);
229 case WSIHighlightedArrowUp:
230 return WMRetainPixmap(scr->hiUpArrow);
232 case WSIArrowDown:
233 return WMRetainPixmap(scr->downArrow);
235 case WSIHighlightedArrowDown:
236 return WMRetainPixmap(scr->hiDownArrow);
238 case WSICheckMark:
239 return WMRetainPixmap(scr->checkMark);
241 default:
242 return NULL;
248 void
249 WMDrawPixmap(WMPixmap *pixmap, Drawable d, int x, int y)
251 WMScreen *scr = pixmap->screen;
253 XSetClipMask(scr->display, scr->clipGC, pixmap->mask);
254 XSetClipOrigin(scr->display, scr->clipGC, x, y);
256 XCopyArea(scr->display, pixmap->pixmap, d, scr->clipGC, 0, 0,
257 pixmap->width, pixmap->height, x, y);