Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / wpixmap.c
blob3902fc05291cfc605591e2a9962be610204e5568
2 #include "WINGsP.h"
4 #include <wraster.h>
6 WMPixmap *WMRetainPixmap(WMPixmap * pixmap)
7 {
8 if (pixmap)
9 pixmap->refCount++;
11 return pixmap;
12 }
14 void WMReleasePixmap(WMPixmap * pixmap)
15 {
16 wassertr(pixmap != NULL);
18 pixmap->refCount--;
20 if (pixmap->refCount < 1) {
21 if (pixmap->pixmap)
22 XFreePixmap(pixmap->screen->display, pixmap->pixmap);
23 if (pixmap->mask)
24 XFreePixmap(pixmap->screen->display, pixmap->mask);
25 wfree(pixmap);
26 }
27 }
29 WMPixmap *WMCreatePixmap(WMScreen * scrPtr, int width, int height, int depth, Bool masked)
30 {
31 WMPixmap *pixPtr;
33 pixPtr = wmalloc(sizeof(WMPixmap));
34 pixPtr->screen = scrPtr;
35 pixPtr->width = width;
36 pixPtr->height = height;
37 pixPtr->depth = depth;
38 pixPtr->refCount = 1;
40 pixPtr->pixmap = XCreatePixmap(scrPtr->display, W_DRAWABLE(scrPtr), width, height, depth);
41 if (masked) {
42 pixPtr->mask = XCreatePixmap(scrPtr->display, W_DRAWABLE(scrPtr), width, height, 1);
43 } else {
44 pixPtr->mask = None;
45 }
47 return pixPtr;
48 }
50 WMPixmap *WMCreatePixmapFromXPixmaps(WMScreen * scrPtr, Pixmap pixmap, Pixmap mask,
51 int width, int height, int depth)
52 {
53 WMPixmap *pixPtr;
55 pixPtr = wmalloc(sizeof(WMPixmap));
56 pixPtr->screen = scrPtr;
57 pixPtr->pixmap = pixmap;
58 pixPtr->mask = mask;
59 pixPtr->width = width;
60 pixPtr->height = height;
61 pixPtr->depth = depth;
62 pixPtr->refCount = 1;
64 return pixPtr;
65 }
67 WMPixmap *WMCreatePixmapFromFile(WMScreen * scrPtr, char *fileName)
68 {
69 WMPixmap *pixPtr;
70 RImage *image;
72 image = RLoadImage(scrPtr->rcontext, fileName, 0);
73 if (!image)
74 return NULL;
76 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127);
78 RReleaseImage(image);
80 return pixPtr;
81 }
83 WMPixmap *WMCreatePixmapFromRImage(WMScreen * scrPtr, RImage * image, int threshold)
84 {
85 WMPixmap *pixPtr;
86 Pixmap pixmap, mask;
88 if (!RConvertImageMask(scrPtr->rcontext, image, &pixmap, &mask, threshold)) {
89 return NULL;
90 }
92 pixPtr = wmalloc(sizeof(WMPixmap));
93 pixPtr->screen = scrPtr;
94 pixPtr->pixmap = pixmap;
95 pixPtr->mask = mask;
96 pixPtr->width = image->width;
97 pixPtr->height = image->height;
98 pixPtr->depth = scrPtr->depth;
99 pixPtr->refCount = 1;
101 return pixPtr;
104 WMPixmap *WMCreateBlendedPixmapFromRImage(WMScreen * scrPtr, RImage * image, RColor * color)
106 WMPixmap *pixPtr;
107 RImage *copy;
109 copy = RCloneImage(image);
110 if (!copy)
111 return NULL;
113 RCombineImageWithColor(copy, color);
114 pixPtr = WMCreatePixmapFromRImage(scrPtr, copy, 0);
115 RReleaseImage(copy);
117 return pixPtr;
120 WMPixmap *WMCreateBlendedPixmapFromFile(WMScreen * scrPtr, char *fileName, RColor * color)
122 WMPixmap *pixPtr;
123 RImage *image;
125 image = RLoadImage(scrPtr->rcontext, fileName, 0);
126 if (!image)
127 return NULL;
129 RCombineImageWithColor(image, color);
131 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 0);
133 RReleaseImage(image);
135 return pixPtr;
138 WMPixmap *WMCreatePixmapFromXPMData(WMScreen * scrPtr, char **data)
140 WMPixmap *pixPtr;
141 RImage *image;
143 image = RGetImageFromXPMData(scrPtr->rcontext, data);
144 if (!image)
145 return NULL;
147 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127);
149 RReleaseImage(image);
151 return pixPtr;
154 Pixmap WMGetPixmapXID(WMPixmap * pixmap)
156 wassertrv(pixmap != NULL, None);
158 return pixmap->pixmap;
161 Pixmap WMGetPixmapMaskXID(WMPixmap * pixmap)
163 wassertrv(pixmap != NULL, None);
165 return pixmap->mask;
168 WMSize WMGetPixmapSize(WMPixmap * pixmap)
170 WMSize size = { 0, 0 };
172 wassertrv(pixmap != NULL, size);
174 size.width = pixmap->width;
175 size.height = pixmap->height;
177 return size;
180 WMPixmap *WMGetSystemPixmap(WMScreen * scr, int image)
182 switch (image) {
183 case WSIReturnArrow:
184 return WMRetainPixmap(scr->buttonArrow);
186 case WSIHighlightedReturnArrow:
187 return WMRetainPixmap(scr->pushedButtonArrow);
189 case WSIScrollerDimple:
190 return WMRetainPixmap(scr->scrollerDimple);
192 case WSIArrowLeft:
193 return WMRetainPixmap(scr->leftArrow);
195 case WSIHighlightedArrowLeft:
196 return WMRetainPixmap(scr->hiLeftArrow);
198 case WSIArrowRight:
199 return WMRetainPixmap(scr->rightArrow);
201 case WSIHighlightedArrowRight:
202 return WMRetainPixmap(scr->hiRightArrow);
204 case WSIArrowUp:
205 return WMRetainPixmap(scr->upArrow);
207 case WSIHighlightedArrowUp:
208 return WMRetainPixmap(scr->hiUpArrow);
210 case WSIArrowDown:
211 return WMRetainPixmap(scr->downArrow);
213 case WSIHighlightedArrowDown:
214 return WMRetainPixmap(scr->hiDownArrow);
216 case WSICheckMark:
217 return WMRetainPixmap(scr->checkMark);
219 default:
220 return NULL;
224 void WMDrawPixmap(WMPixmap * pixmap, Drawable d, int x, int y)
226 WMScreen *scr = pixmap->screen;
228 XSetClipMask(scr->display, scr->clipGC, pixmap->mask);
229 XSetClipOrigin(scr->display, scr->clipGC, x, y);
231 XCopyArea(scr->display, pixmap->pixmap, d, scr->clipGC, 0, 0, pixmap->width, pixmap->height, x, y);