Files
wmaker/WINGs/wpixmap.c
T

268 lines
5.2 KiB
C
Raw Normal View History

1998-09-29 22:36:29 +00:00
#include "WINGsP.h"
#include <wraster.h>
WMPixmap*
WMRetainPixmap(WMPixmap *pixmap)
{
if (pixmap)
2004-10-12 21:28:27 +00:00
pixmap->refCount++;
1998-09-29 22:36:29 +00:00
return pixmap;
}
void
WMReleasePixmap(WMPixmap *pixmap)
{
1999-01-06 15:22:33 +00:00
wassertr(pixmap!=NULL);
1998-09-29 22:36:29 +00:00
pixmap->refCount--;
if (pixmap->refCount<1) {
2004-10-12 21:28:27 +00:00
if (pixmap->pixmap)
XFreePixmap(pixmap->screen->display, pixmap->pixmap);
if (pixmap->mask)
XFreePixmap(pixmap->screen->display, pixmap->mask);
wfree(pixmap);
1998-09-29 22:36:29 +00:00
}
}
1999-03-09 14:58:01 +00:00
WMPixmap*
WMCreatePixmap(WMScreen *scrPtr, int width, int height, int depth, Bool masked)
{
WMPixmap *pixPtr;
2001-04-21 07:12:21 +00:00
pixPtr = wmalloc(sizeof(WMPixmap));
1999-03-09 14:58:01 +00:00
pixPtr->screen = scrPtr;
pixPtr->width = width;
pixPtr->height = height;
pixPtr->depth = depth;
pixPtr->refCount = 1;
pixPtr->pixmap = XCreatePixmap(scrPtr->display, W_DRAWABLE(scrPtr),
2004-10-12 21:28:27 +00:00
width, height, depth);
1999-03-09 14:58:01 +00:00
if (masked) {
2001-04-16 00:10:58 +00:00
pixPtr->mask = XCreatePixmap(scrPtr->display, W_DRAWABLE(scrPtr),
width, height, 1);
1999-03-09 14:58:01 +00:00
} else {
2004-10-12 21:28:27 +00:00
pixPtr->mask = None;
1999-03-09 14:58:01 +00:00
}
2004-10-12 21:28:27 +00:00
return pixPtr;
1999-03-09 14:58:01 +00:00
}
1998-09-29 22:36:29 +00:00
WMPixmap*
WMCreatePixmapFromXPixmaps(WMScreen *scrPtr, Pixmap pixmap, Pixmap mask,
2004-10-12 21:28:27 +00:00
int width, int height, int depth)
1998-09-29 22:36:29 +00:00
{
WMPixmap *pixPtr;
2001-04-21 07:12:21 +00:00
pixPtr = wmalloc(sizeof(WMPixmap));
1998-09-29 22:36:29 +00:00
pixPtr->screen = scrPtr;
pixPtr->pixmap = pixmap;
pixPtr->mask = mask;
pixPtr->width = width;
pixPtr->height = height;
pixPtr->depth = depth;
pixPtr->refCount = 1;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
return pixPtr;
}
WMPixmap*
WMCreatePixmapFromFile(WMScreen *scrPtr, char *fileName)
{
WMPixmap *pixPtr;
RImage *image;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
image = RLoadImage(scrPtr->rcontext, fileName, 0);
if (!image)
2004-10-12 21:28:27 +00:00
return NULL;
1998-09-29 22:36:29 +00:00
pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127);
2001-04-21 07:12:21 +00:00
RReleaseImage(image);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
return pixPtr;
}
WMPixmap*
WMCreatePixmapFromRImage(WMScreen *scrPtr, RImage *image, int threshold)
{
WMPixmap *pixPtr;
Pixmap pixmap, mask;
2004-10-12 21:28:27 +00:00
if (!RConvertImageMask(scrPtr->rcontext, image, &pixmap, &mask,
threshold)) {
return NULL;
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
2001-04-21 07:12:21 +00:00
pixPtr = wmalloc(sizeof(WMPixmap));
1998-09-29 22:36:29 +00:00
pixPtr->screen = scrPtr;
pixPtr->pixmap = pixmap;
pixPtr->mask = mask;
pixPtr->width = image->width;
pixPtr->height = image->height;
pixPtr->depth = scrPtr->depth;
pixPtr->refCount = 1;
2004-10-12 21:28:27 +00:00
return pixPtr;
1998-09-29 22:36:29 +00:00
}
2001-04-16 00:10:58 +00:00
WMPixmap*
WMCreateBlendedPixmapFromRImage(WMScreen *scrPtr, RImage *image, RColor *color)
{
WMPixmap *pixPtr;
RImage *copy;
copy = RCloneImage(image);
2001-04-21 07:12:21 +00:00
if (!copy)
return NULL;
2001-04-16 00:10:58 +00:00
RCombineImageWithColor(copy, color);
pixPtr = WMCreatePixmapFromRImage(scrPtr, copy, 0);
2001-04-21 07:12:21 +00:00
RReleaseImage(copy);
2001-04-16 00:10:58 +00:00
return pixPtr;
}
1998-09-29 22:36:29 +00:00
WMPixmap*
WMCreateBlendedPixmapFromFile(WMScreen *scrPtr, char *fileName, RColor *color)
{
WMPixmap *pixPtr;
RImage *image;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
image = RLoadImage(scrPtr->rcontext, fileName, 0);
if (!image)
2004-10-12 21:28:27 +00:00
return NULL;
1998-09-29 22:36:29 +00:00
RCombineImageWithColor(image, color);
pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 0);
2004-10-12 21:28:27 +00:00
2001-04-21 07:12:21 +00:00
RReleaseImage(image);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
return pixPtr;
}
WMPixmap*
WMCreatePixmapFromXPMData(WMScreen *scrPtr, char **data)
{
WMPixmap *pixPtr;
RImage *image;
image = RGetImageFromXPMData(scrPtr->rcontext, data);
if (!image)
2004-10-12 21:28:27 +00:00
return NULL;
1998-09-29 22:36:29 +00:00
pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127);
2001-04-21 07:12:21 +00:00
RReleaseImage(image);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
return pixPtr;
}
Pixmap
WMGetPixmapXID(WMPixmap *pixmap)
{
1999-01-06 15:22:33 +00:00
wassertrv(pixmap != NULL, None);
1998-09-29 22:36:29 +00:00
return pixmap->pixmap;
}
1999-01-06 15:22:33 +00:00
1998-09-29 22:36:29 +00:00
Pixmap
WMGetPixmapMaskXID(WMPixmap *pixmap)
{
1999-01-06 15:22:33 +00:00
wassertrv(pixmap != NULL, None);
1998-09-29 22:36:29 +00:00
return pixmap->mask;
}
2004-10-12 21:28:27 +00:00
WMSize
1998-09-29 22:36:29 +00:00
WMGetPixmapSize(WMPixmap *pixmap)
{
1999-01-06 15:22:33 +00:00
WMSize size = {0,0};
wassertrv(pixmap != NULL, size);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
size.width = pixmap->width;
size.height = pixmap->height;
1999-01-06 15:22:33 +00:00
1998-09-29 22:36:29 +00:00
return size;
}
WMPixmap*
WMGetSystemPixmap(WMScreen *scr, int image)
{
switch (image) {
2004-10-12 21:28:27 +00:00
case WSIReturnArrow:
return WMRetainPixmap(scr->buttonArrow);
case WSIHighlightedReturnArrow:
return WMRetainPixmap(scr->pushedButtonArrow);
case WSIScrollerDimple:
return WMRetainPixmap(scr->scrollerDimple);
case WSIArrowLeft:
return WMRetainPixmap(scr->leftArrow);
case WSIHighlightedArrowLeft:
return WMRetainPixmap(scr->hiLeftArrow);
case WSIArrowRight:
return WMRetainPixmap(scr->rightArrow);
case WSIHighlightedArrowRight:
return WMRetainPixmap(scr->hiRightArrow);
case WSIArrowUp:
return WMRetainPixmap(scr->upArrow);
case WSIHighlightedArrowUp:
return WMRetainPixmap(scr->hiUpArrow);
case WSIArrowDown:
return WMRetainPixmap(scr->downArrow);
case WSIHighlightedArrowDown:
return WMRetainPixmap(scr->hiDownArrow);
case WSICheckMark:
return WMRetainPixmap(scr->checkMark);
default:
return NULL;
1998-09-29 22:36:29 +00:00
}
}
1999-01-06 15:22:33 +00:00
void
WMDrawPixmap(WMPixmap *pixmap, Drawable d, int x, int y)
{
WMScreen *scr = pixmap->screen;
XSetClipMask(scr->display, scr->clipGC, pixmap->mask);
XSetClipOrigin(scr->display, scr->clipGC, x, y);
2004-10-12 21:28:27 +00:00
XCopyArea(scr->display, pixmap->pixmap, d, scr->clipGC, 0, 0,
pixmap->width, pixmap->height, x, y);
1999-01-06 15:22:33 +00:00
}
2004-10-12 21:28:27 +00:00