Submitted by golgbg on Wed, 10/06/2004 - 07:44.
Hi,
Under the section Tips 'n Tricks there is an article Howto create an insensitive pixmap. The link to the sourcecode is broken.
Is there anybody out there who has this code available and can send it to me ?
Regards
Goran
Wed, 03/30/2005 - 15:57#1
UltraJoe
XmGetInsensitivePixmap reengineered
Nobody seems to know where XmGetInsensitivePixmap went to, so, since I needed it, I reengineered it. The code follows. Note that this works under Motif 1.2, and should work under 2.x as well. It does require a widget for reference.
/*<br />
* XmGetInsensitivePixmap - return a new pixmap that's the same<br />
* as srcPixmap, but "stippled" in a fashion similar to how<br />
* XmLabel stipples its text.<br />
*<br />
* Written 30-MAR-2005 by Joe Sewell<br />
*<br />
* No warranties are expressed, implied, or otherwise brought<br />
* out by this code. Use at your own risk. Your mileage may<br />
* vary. Do not operate heavy machinery while taking this<br />
* code.<br />
*/<br />
#include <Xm/Xm.h><br />
#include <Mrm/MrmPublic.h></p>
<p>Pixmap XmGetInsensitivePixmap (Widget w, Pixmap srcPixmap)<br />
{<br />
Pixmap insensPixmap = None;<br />
Pixel wBackground;<br />
Display *wDisplay = XtDisplay(w);<br />
Screen *wScreen = XtScreen(w);<br />
Window srcRoot;<br />
int srcX, srcY;<br />
unsigned int srcWidth, srcHeight, srcBorderWidth, srcDepth;<br />
static Boolean GCsSet = False;<br />
XGCValues GCValues;<br />
static GC clearGC, makeMaskGC, copyMaskedGC;<br />
static struct maskData<br />
{<br />
unsigned int width, height;<br />
Pixmap pixmap;<br />
} mask = {0, 0, None};<br />
static char grayPixmapName[] = "50_foreground";</p>
<p> XtVaGetValues (w,<br />
XmNbackground, &wBackground,<br />
NULL);<br />
if (!XGetGeometry (wDisplay,<br />
srcPixmap,<br />
&srcRoot,<br />
&srcX,<br />
&srcY,<br />
&srcWidth,<br />
&srcBorderWidth,<br />
&srcDepth))<br />
{<br />
return None;<br />
}<br />
if (!GCsSet)<br />
{<br />
clearGC = XtAllocateGC (w,<br />
srcDepth,<br />
(XtGCMask) 0,<br />
&GCValues,<br />
(GCForeground | GCBackground),<br />
(GCLineWidth | GCCapStyle | GCJoinStyle |<br />
GCFillRule | GCFont |<br />
GCDashOffset | GCDashList | GCArcMode));<br />
GCValues.fill_style = FillTiled;<br />
GCValues.tile = XmGetPixmapByDepth (wScreen,<br />
grayPixmapName,<br />
WhitePixelOfScreen(wScreen),<br />
BlackPixelOfScreen(wScreen),<br />
1);<br />
if (GCValues.tile == None)<br />
{<br />
XtReleaseGC (clearGC);<br />
return None;<br />
}<br />
GCValues.foreground = WhitePixelOfScreen(wScreen);<br />
GCValues.background = BlackPixelOfScreen(wScreen);<br />
makeMaskGC = XtAllocateGC (w,<br />
1,<br />
(GCFillStyle | GCTile | GCForeground |<br />
GCBackground),<br />
&GCValues,<br />
(XtGCMask) 0,<br />
(GCLineWidth | GCCapStyle | GCJoinStyle |<br />
GCFillRule | GCFont |<br />
GCDashOffset | GCDashList | GCArcMode));<br />
copyMaskedGC = XtAllocateGC (w,<br />
srcDepth,<br />
(XtGCMask) 0,<br />
&GCValues,<br />
GCClipMask,<br />
(GCForeground | GCBackground |<br />
GCLineWidth | GCLineStyle |<br />
GCCapStyle | GCJoinStyle | GCFillStyle |<br />
GCFillRule | GCTile | GCStipple |<br />
GCTileStipXOrigin | GCTileStipYOrigin |<br />
GCFont | GCDashOffset | GCDashList |<br />
GCArcMode));<br />
GCsSet = True;<br />
}<br />
if (mask.width < srcWidth ||<br />
mask.height < srcHeight)<br />
{<br />
if (mask.pixmap != None)<br />
{<br />
XFreePixmap (wDisplay,<br />
mask.pixmap);<br />
}<br />
mask.width = srcWidth;<br />
mask.height = srcHeight;<br />
mask.pixmap = XCreatePixmap (wDisplay,<br />
srcPixmap,<br />
srcWidth,<br />
srcHeight,<br />
1);<br />
if (mask.pixmap == None)<br />
{<br />
mask.width = mask.height = 0;<br />
return None;<br />
}<br />
XFillRectangle (wDisplay,<br />
mask.pixmap,<br />
makeMaskGC,<br />
0, 0,<br />
srcWidth, srcHeight);<br />
XSetClipMask (wDisplay,<br />
copyMaskedGC,<br />
mask.pixmap);<br />
}<br />
insensPixmap = XCreatePixmap (wDisplay,<br />
srcPixmap,<br />
srcWidth,<br />
srcHeight,<br />
srcDepth);<br />
if (insensPixmap == None)<br />
{<br />
return None;<br />
}<br />
XSetForeground (wDisplay,<br />
clearGC,<br />
wBackground);<br />
XSetBackground (wDisplay,<br />
clearGC,<br />
wBackground);<br />
XFillRectangle (wDisplay,<br />
insensPixmap,<br />
clearGC,<br />
0, 0,<br />
srcWidth, srcHeight);<br />
XCopyArea (wDisplay,<br />
srcPixmap,<br />
insensPixmap,<br />
copyMaskedGC,<br />
0, 0,<br />
srcWidth, srcHeight,<br />
0, 0);<br />
return insensPixmap;<br />
}