Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / wpixmap.c
1
2 #include "WINGsP.h"
3
4 #include <wraster.h>
5
6 WMPixmap *WMRetainPixmap(WMPixmap * pixmap)
7 {
8 if (pixmap)
9 pixmap->refCount++;
10
11 return pixmap;
12 }
13
14 void WMReleasePixmap(WMPixmap * pixmap)
15 {
16 wassertr(pixmap != NULL);
17
18 pixmap->refCount--;
19
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 }
28
29 WMPixmap *WMCreatePixmap(WMScreen * scrPtr, int width, int height, int depth, Bool masked)
30 {
31 WMPixmap *pixPtr;
32
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;
39
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 }
46
47 return pixPtr;
48 }
49
50 WMPixmap *WMCreatePixmapFromXPixmaps(WMScreen * scrPtr, Pixmap pixmap, Pixmap mask,
51 int width, int height, int depth)
52 {
53 WMPixmap *pixPtr;
54
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;
63
64 return pixPtr;
65 }
66
67 WMPixmap *WMCreatePixmapFromFile(WMScreen * scrPtr, char *fileName)
68 {
69 WMPixmap *pixPtr;
70 RImage *image;
71
72 image = RLoadImage(scrPtr->rcontext, fileName, 0);
73 if (!image)
74 return NULL;
75
76 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127);
77
78 RReleaseImage(image);
79
80 return pixPtr;
81 }
82
83 WMPixmap *WMCreatePixmapFromRImage(WMScreen * scrPtr, RImage * image, int threshold)
84 {
85 WMPixmap *pixPtr;
86 Pixmap pixmap, mask;
87
88 if (!RConvertImageMask(scrPtr->rcontext, image, &pixmap, &mask, threshold)) {
89 return NULL;
90 }
91
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;
100
101 return pixPtr;
102 }
103
104 WMPixmap *WMCreateBlendedPixmapFromRImage(WMScreen * scrPtr, RImage * image, RColor * color)
105 {
106 WMPixmap *pixPtr;
107 RImage *copy;
108
109 copy = RCloneImage(image);
110 if (!copy)
111 return NULL;
112
113 RCombineImageWithColor(copy, color);
114 pixPtr = WMCreatePixmapFromRImage(scrPtr, copy, 0);
115 RReleaseImage(copy);
116
117 return pixPtr;
118 }
119
120 WMPixmap *WMCreateBlendedPixmapFromFile(WMScreen * scrPtr, char *fileName, RColor * color)
121 {
122 WMPixmap *pixPtr;
123 RImage *image;
124
125 image = RLoadImage(scrPtr->rcontext, fileName, 0);
126 if (!image)
127 return NULL;
128
129 RCombineImageWithColor(image, color);
130
131 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 0);
132
133 RReleaseImage(image);
134
135 return pixPtr;
136 }
137
138 WMPixmap *WMCreatePixmapFromXPMData(WMScreen * scrPtr, char **data)
139 {
140 WMPixmap *pixPtr;
141 RImage *image;
142
143 image = RGetImageFromXPMData(scrPtr->rcontext, data);
144 if (!image)
145 return NULL;
146
147 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127);
148
149 RReleaseImage(image);
150
151 return pixPtr;
152 }
153
154 Pixmap WMGetPixmapXID(WMPixmap * pixmap)
155 {
156 wassertrv(pixmap != NULL, None);
157
158 return pixmap->pixmap;
159 }
160
161 Pixmap WMGetPixmapMaskXID(WMPixmap * pixmap)
162 {
163 wassertrv(pixmap != NULL, None);
164
165 return pixmap->mask;
166 }
167
168 WMSize WMGetPixmapSize(WMPixmap * pixmap)
169 {
170 WMSize size = { 0, 0 };
171
172 wassertrv(pixmap != NULL, size);
173
174 size.width = pixmap->width;
175 size.height = pixmap->height;
176
177 return size;
178 }
179
180 WMPixmap *WMGetSystemPixmap(WMScreen * scr, int image)
181 {
182 switch (image) {
183 case WSIReturnArrow:
184 return WMRetainPixmap(scr->buttonArrow);
185
186 case WSIHighlightedReturnArrow:
187 return WMRetainPixmap(scr->pushedButtonArrow);
188
189 case WSIScrollerDimple:
190 return WMRetainPixmap(scr->scrollerDimple);
191
192 case WSIArrowLeft:
193 return WMRetainPixmap(scr->leftArrow);
194
195 case WSIHighlightedArrowLeft:
196 return WMRetainPixmap(scr->hiLeftArrow);
197
198 case WSIArrowRight:
199 return WMRetainPixmap(scr->rightArrow);
200
201 case WSIHighlightedArrowRight:
202 return WMRetainPixmap(scr->hiRightArrow);
203
204 case WSIArrowUp:
205 return WMRetainPixmap(scr->upArrow);
206
207 case WSIHighlightedArrowUp:
208 return WMRetainPixmap(scr->hiUpArrow);
209
210 case WSIArrowDown:
211 return WMRetainPixmap(scr->downArrow);
212
213 case WSIHighlightedArrowDown:
214 return WMRetainPixmap(scr->hiDownArrow);
215
216 case WSICheckMark:
217 return WMRetainPixmap(scr->checkMark);
218
219 default:
220 return NULL;
221 }
222 }
223
224 void WMDrawPixmap(WMPixmap * pixmap, Drawable d, int x, int y)
225 {
226 WMScreen *scr = pixmap->screen;
227
228 XSetClipMask(scr->display, scr->clipGC, pixmap->mask);
229 XSetClipOrigin(scr->display, scr->clipGC, x, y);
230
231 XCopyArea(scr->display, pixmap->pixmap, d, scr->clipGC, 0, 0, pixmap->width, pixmap->height, x, y);
232 }