Floating irregular bitmap blitted (zoomed) from wxBitmap in wxScrolledWindow

I am attempting to create a magnifying glass cursor that floats above
a wxBitmap displayed in a wxScrolledWindow. The cursor displays an
enlarged view of a region from the bitmap below centered at the
current location. Nothing extraordinary about this, but I would
prefer to be able to use an irregularly shaped region for the
displayed image, and possibly a simple bitmap like a handle, or at
least a bounding circle or frame. This gets updated on every
wx.EVT_MOTION.

I have done this before in C++, (long ago) but I'm having difficulty
sorting it all out in wxPython. I began with the DragImage example
from the wxPython Demos. It has almost gotten me where I want to go.
Unlike that example, I don't want to just drag a simple static bitmap
around the screen, however. I need to be able to create the 'cursor'
bitmap by combining layers into a MemoryDC and finally blitting the
whole works to the screen.

My current code uses GetSubBitmap() to retrieve the region of the
original bitmap, and then attempts to composite it into a temporary
MemoryDC. Other components of the mask are created by drawing with
white and black brushes into the same DC. In my searches for a model
to follow I've gone back to Petzold's venerable 'Programming Windows'
and its discussion of creating irregular bitmaps.

In the example I have been following, he fills the rectangular area
using a black brush, then uses a white brush to create an ellipse to
contain the bitmap, then blits this against the desired image using a
SRCAND raster operation (rop). This zeros the are under the black
areas of the mask, and leaves the image areas that are exposed to the
white mask intact. So far, so good.

But the next action specified (in onpaint) is to blit the whole mask
onto the main (primary image) bitmap using an unnamed 0x220326 rop.
This is where I have a problem.

The 0x220326 rop is asid to be equivalent to a (Dest & (NOT Src))
operation, which is also not named in wxPython. And when I attempt to
force-feed this value as a HEX literal, wxPython tells me that this is
an invalid rop. It appears that wxPython does not accept any but the
sixteen named rops.

A final Blit of the image using a SRCPAINT rop finishes the sequence.

Can anyone suggest a way to accomplish what I'm trying to do or better
yet, point me to someone who has already done it? Failing that, can
anyone tell me that It cannot be done?

Thanks,

Dave W.

wittend wrote:

I would
prefer to be able to use an irregularly shaped region for the
displayed image,
But the next action specified (in onpaint) is to blit the whole mask
onto the main (primary image) bitmap using an unnamed 0x220326 rop.
This is where I have a problem.

You can apply a mask to a wx.Bitmap with the wx.Bitmap.SetMask method. You can then draw it to your DC with:

DC.DrawBitmap(bitmap, x, y, transparent=True)

Drawing masked bitmaps is a bit set with wx, but for a smallish one, it should be fine.

Another option is to use a Bitmap with an alpha layer, though it's a bit touch to create that from an existing bitmap. A little searching of this list should help with that. Drawing an alpha bitmap may be faster on some systems (notably OS-X, which only used alpha bitmaps).

HTH,

-Chris

ยทยทยท

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov