Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / wpixmap.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001
2#include "WINGsP.h"
3
4#include <wraster.h>
5
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02006WMPixmap *WMRetainPixmap(WMPixmap * pixmap)
9d2e6ef9 scottc1998-09-29 22:36:29 +00007{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02008 if (pixmap)
9 pixmap->refCount++;
9d2e6ef9 scottc1998-09-29 22:36:29 +000010
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020011 return pixmap;
9d2e6ef9 scottc1998-09-29 22:36:29 +000012}
13
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020014void WMReleasePixmap(WMPixmap * pixmap)
9d2e6ef9 scottc1998-09-29 22:36:29 +000015{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020016 wassertr(pixmap != NULL);
0261c326 dan1999-01-06 15:22:33 +000017
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020018 pixmap->refCount--;
9d2e6ef9 scottc1998-09-29 22:36:29 +000019
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020020 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 }
9d2e6ef9 scottc1998-09-29 22:36:29 +000027}
28
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020029WMPixmap *WMCreatePixmap(WMScreen * scrPtr, int width, int height, int depth, Bool masked)
088c0ac2 dan1999-03-09 14:58:01 +000030{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020031 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;
088c0ac2 dan1999-03-09 14:58:01 +000048}
49
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020050WMPixmap *WMCreatePixmapFromXPixmaps(WMScreen * scrPtr, Pixmap pixmap, Pixmap mask,
51 int width, int height, int depth)
9d2e6ef9 scottc1998-09-29 22:36:29 +000052{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020053 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;
9d2e6ef9 scottc1998-09-29 22:36:29 +000065}
66
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020067WMPixmap *WMCreatePixmapFromFile(WMScreen * scrPtr, char *fileName)
9d2e6ef9 scottc1998-09-29 22:36:29 +000068{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020069 WMPixmap *pixPtr;
70 RImage *image;
6830b057 dan2004-10-12 21:28:27 +000071
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020072 image = RLoadImage(scrPtr->rcontext, fileName, 0);
73 if (!image)
74 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +000075
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020076 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127);
9d2e6ef9 scottc1998-09-29 22:36:29 +000077
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020078 RReleaseImage(image);
6830b057 dan2004-10-12 21:28:27 +000079
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020080 return pixPtr;
9d2e6ef9 scottc1998-09-29 22:36:29 +000081}
82
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020083WMPixmap *WMCreatePixmapFromRImage(WMScreen * scrPtr, RImage * image, int threshold)
9d2e6ef9 scottc1998-09-29 22:36:29 +000084{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020085 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;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000102}
103
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200104WMPixmap *WMCreateBlendedPixmapFromRImage(WMScreen * scrPtr, RImage * image, RColor * color)
79b17caa dan2001-04-16 00:10:58 +0000105{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200106 WMPixmap *pixPtr;
107 RImage *copy;
79b17caa dan2001-04-16 00:10:58 +0000108
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200109 copy = RCloneImage(image);
110 if (!copy)
111 return NULL;
36e46831 dan2001-04-21 07:12:21 +0000112
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200113 RCombineImageWithColor(copy, color);
114 pixPtr = WMCreatePixmapFromRImage(scrPtr, copy, 0);
115 RReleaseImage(copy);
79b17caa dan2001-04-16 00:10:58 +0000116
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200117 return pixPtr;
79b17caa dan2001-04-16 00:10:58 +0000118}
119
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200120WMPixmap *WMCreateBlendedPixmapFromFile(WMScreen * scrPtr, char *fileName, RColor * color)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000121{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200122 WMPixmap *pixPtr;
123 RImage *image;
6830b057 dan2004-10-12 21:28:27 +0000124
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200125 image = RLoadImage(scrPtr->rcontext, fileName, 0);
126 if (!image)
127 return NULL;
6830b057 dan2004-10-12 21:28:27 +0000128
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200129 RCombineImageWithColor(image, color);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000130
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200131 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 0);
6830b057 dan2004-10-12 21:28:27 +0000132
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200133 RReleaseImage(image);
6830b057 dan2004-10-12 21:28:27 +0000134
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200135 return pixPtr;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000136}
137
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200138WMPixmap *WMCreatePixmapFromXPMData(WMScreen * scrPtr, char **data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000139{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200140 WMPixmap *pixPtr;
141 RImage *image;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000142
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200143 image = RGetImageFromXPMData(scrPtr->rcontext, data);
144 if (!image)
145 return NULL;
6830b057 dan2004-10-12 21:28:27 +0000146
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200147 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000148
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200149 RReleaseImage(image);
6830b057 dan2004-10-12 21:28:27 +0000150
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200151 return pixPtr;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000152}
153
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200154Pixmap WMGetPixmapXID(WMPixmap * pixmap)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000155{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200156 wassertrv(pixmap != NULL, None);
0261c326 dan1999-01-06 15:22:33 +0000157
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200158 return pixmap->pixmap;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000159}
160
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200161Pixmap WMGetPixmapMaskXID(WMPixmap * pixmap)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000162{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200163 wassertrv(pixmap != NULL, None);
0261c326 dan1999-01-06 15:22:33 +0000164
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200165 return pixmap->mask;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000166}
167
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200168WMSize WMGetPixmapSize(WMPixmap * pixmap)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000169{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200170 WMSize size = { 0, 0 };
0261c326 dan1999-01-06 15:22:33 +0000171
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200172 wassertrv(pixmap != NULL, size);
6830b057 dan2004-10-12 21:28:27 +0000173
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200174 size.width = pixmap->width;
175 size.height = pixmap->height;
0261c326 dan1999-01-06 15:22:33 +0000176
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200177 return size;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000178}
179
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200180WMPixmap *WMGetSystemPixmap(WMScreen * scr, int image)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000181{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200182 switch (image) {
183 case WSIReturnArrow:
184 return WMRetainPixmap(scr->buttonArrow);
6830b057 dan2004-10-12 21:28:27 +0000185
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200186 case WSIHighlightedReturnArrow:
187 return WMRetainPixmap(scr->pushedButtonArrow);
6830b057 dan2004-10-12 21:28:27 +0000188
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200189 case WSIScrollerDimple:
190 return WMRetainPixmap(scr->scrollerDimple);
6830b057 dan2004-10-12 21:28:27 +0000191
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200192 case WSIArrowLeft:
193 return WMRetainPixmap(scr->leftArrow);
6830b057 dan2004-10-12 21:28:27 +0000194
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200195 case WSIHighlightedArrowLeft:
196 return WMRetainPixmap(scr->hiLeftArrow);
6830b057 dan2004-10-12 21:28:27 +0000197
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200198 case WSIArrowRight:
199 return WMRetainPixmap(scr->rightArrow);
6830b057 dan2004-10-12 21:28:27 +0000200
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200201 case WSIHighlightedArrowRight:
202 return WMRetainPixmap(scr->hiRightArrow);
6830b057 dan2004-10-12 21:28:27 +0000203
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200204 case WSIArrowUp:
205 return WMRetainPixmap(scr->upArrow);
6830b057 dan2004-10-12 21:28:27 +0000206
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200207 case WSIHighlightedArrowUp:
208 return WMRetainPixmap(scr->hiUpArrow);
6830b057 dan2004-10-12 21:28:27 +0000209
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200210 case WSIArrowDown:
211 return WMRetainPixmap(scr->downArrow);
6830b057 dan2004-10-12 21:28:27 +0000212
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200213 case WSIHighlightedArrowDown:
214 return WMRetainPixmap(scr->hiDownArrow);
6830b057 dan2004-10-12 21:28:27 +0000215
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200216 case WSICheckMark:
217 return WMRetainPixmap(scr->checkMark);
6830b057 dan2004-10-12 21:28:27 +0000218
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200219 default:
220 return NULL;
221 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000222}
223
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200224void WMDrawPixmap(WMPixmap * pixmap, Drawable d, int x, int y)
0261c326 dan1999-01-06 15:22:33 +0000225{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200226 WMScreen *scr = pixmap->screen;
0261c326 dan1999-01-06 15:22:33 +0000227
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200228 XSetClipMask(scr->display, scr->clipGC, pixmap->mask);
229 XSetClipOrigin(scr->display, scr->clipGC, x, y);
0261c326 dan1999-01-06 15:22:33 +0000230
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200231 XCopyArea(scr->display, pixmap->pixmap, d, scr->clipGC, 0, 0, pixmap->width, pixmap->height, x, y);
0261c326 dan1999-01-06 15:22:33 +0000232}