Files
wmaker/WINGs/wpixmap.c
T

261 lines
5.5 KiB
C
Raw Normal View History

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