WinSetPattern
Tip
Help! I'm trying to use WinSetPattern to draw a custom pattern to gray out a section of screen. It's not working on various devices.
Well, this seems to be a forgotten corner of the OS in many palms and palm-powered devices.
- Sony - bitdepth 8, the pattern seems to be used, but on the emulator masked the screen with yellow rather than black.
- Handera - bitdepth 2, blanked the screen completely.
- PalmOS 3.5 - in bitdepths 8 and 2, wrote alternating bands of grey and white to the screen.
- PalmOS 4.0 - worked fine in both bitdepths of 8 and 2.
So, the solution I've arrived at so far works for Handera and PalmOS 4.0+. I'll be improving this to work on some of the other models in time. Here's the code as it sits right now. I like long lines, so watch the line wrap...sorry.
void DimScreen()
{
CustomPatternType pattern = {0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55};
WinHandle winH;
RectangleType r;
register unsigned long *d;
register unsigned char *e;
register unsigned long s;
register unsigned short sw;
register short i,j;
UInt32 bigPattern[8];
UInt8 c;
BitmapType *bm = WinGetBitmap(WinGetDisplayWindow());
if (pow_drawContext.useHanderaHiRes) {
if (bm->pixelSize==1) {
// overlay the whole screen with a grey pattern.
// only works in 1 bit depth for handera.
i=0;
d=(unsigned long *)(BmpGetBits(bm));
while (i<304) {
c = pattern[i&7];
sw = (short)c<<8 | (short)c;
s = (unsigned long)(sw)<<16 | sw;
*d++&=~s;*d++&=~s;*d++&=~s;*d++&=~s;
*d++&=~s;*d++&=~s;*d++&=~s;
e = (unsigned char *)d;
*e++ |= (unsigned char)c;
*e++ |= (unsigned char)c;
d = (unsigned long *)e;
i++;
}
} else {
d=(unsigned long *)(BmpGetBits(bm));
// First, create the bit patterns in bigPattern.
// for 2 bit.
for (i=0;i<8;i++) {
bigPattern[i]=0L;
for (j=7;j>-1;j--) {
bigPattern[i] <<= 2;
if (pattern[i] & 1<<j) {
bigPattern[i] |= 3;
}
}
bigPattern[i] = bigPattern[i]<<16 | bigPattern[i];
}
// overlay the whole screen with a grey pattern.
i=0;
while (i<304) {
s = bigPattern[i&7];
*d++&=~s;*d++&=~s;*d++&=~s;*d++&=~s;
*d++&=~s;*d++&=~s;*d++&=~s;
*d++&=~s;*d++&=~s;*d++&=~s;*d++&=~s;
*d++&=~s;*d++&=~s;*d++&=~s;
*d++&=~s;
i++;
}
}
} else if (!pow_drawContext.useSonyHiRes) {
WinPushDrawState();
winH = WinSetDrawWindow(WinGetDisplayWindow());
WinSetPattern((const CustomPatternType *)&pattern);
WinSetDrawMode(winMask);
WinGetWindowBounds(&r);
WinPaintRectangle(&r,0);
WinSetDrawWindow(winH);
WinPopDrawState();
}
}
Hope this has helped. If you have any trouble with this hint, please holler over to Ken through the contact page.