1999-12-23 15:05:08 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
import wx
|
1999-12-23 15:05:08 -05:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2000-01-19 01:58:56 -05:00
|
|
|
logicList = [
|
2003-12-08 20:23:28 -05:00
|
|
|
('wx.AND', wx.AND),
|
|
|
|
('wx.AND_INVERT', wx.AND_INVERT),
|
|
|
|
('wx.AND_REVERSE', wx.AND_REVERSE),
|
|
|
|
('wx.CLEAR', wx.CLEAR),
|
|
|
|
('wx.COPY', wx.COPY),
|
|
|
|
('wx.EQUIV', wx.EQUIV),
|
|
|
|
('wx.INVERT', wx.INVERT),
|
|
|
|
('wx.NAND', wx.NAND),
|
2000-01-19 01:58:56 -05:00
|
|
|
|
|
|
|
# this one causes an assert on wxGTK, and doesn't seem to
|
|
|
|
# do much on MSW anyway, so I'll just take it out....
|
|
|
|
#('wxNOR', wxNOR),
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
('wx.NO_OP', wx.NO_OP),
|
|
|
|
('wx.OR', wx.OR),
|
|
|
|
('wx.OR_INVERT', wx.OR_INVERT),
|
|
|
|
('wx.OR_REVERSE', wx.OR_REVERSE),
|
|
|
|
('wx.SET', wx.SET),
|
|
|
|
('wx.SRC_INVERT', wx.SRC_INVERT),
|
|
|
|
('wx.XOR', wx.XOR),
|
2000-01-19 01:58:56 -05:00
|
|
|
]
|
1999-12-23 15:05:08 -05:00
|
|
|
|
2006-11-22 14:52:23 -05:00
|
|
|
if 'mac-cg' in wx.PlatformInfo:
|
|
|
|
# that's all, folks!
|
|
|
|
logicList = [
|
|
|
|
('wx.COPY', wx.COPY),
|
|
|
|
]
|
|
|
|
|
2001-04-09 15:36:36 -04:00
|
|
|
import images
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestMaskWindow(wx.ScrolledWindow):
|
1999-12-23 15:05:08 -05:00
|
|
|
def __init__(self, parent):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.ScrolledWindow.__init__(self, parent, -1)
|
|
|
|
self.SetBackgroundColour(wx.Colour(0,128,0))
|
1999-12-23 15:05:08 -05:00
|
|
|
|
|
|
|
# A reference bitmap that we won't mask
|
2001-04-09 15:36:36 -04:00
|
|
|
self.bmp_nomask = images.getTestStar2Bitmap()
|
1999-12-23 15:05:08 -05:00
|
|
|
|
|
|
|
# One that we will
|
2001-04-09 15:36:36 -04:00
|
|
|
self.bmp_withmask = images.getTestStar2Bitmap()
|
1999-12-23 15:05:08 -05:00
|
|
|
|
|
|
|
# this mask comes from a monochrome bitmap
|
2004-02-13 15:09:55 -05:00
|
|
|
self.bmp_themask = images.getTestMaskBitmap()
|
2003-12-08 20:23:28 -05:00
|
|
|
mask = wx.Mask(self.bmp_themask)
|
1999-12-23 15:05:08 -05:00
|
|
|
|
|
|
|
# set the mask on our bitmap
|
|
|
|
self.bmp_withmask.SetMask(mask)
|
|
|
|
|
|
|
|
# Now we'll create a mask in a bit of an easier way, by picking a
|
|
|
|
# colour in the image that is to be the transparent colour.
|
2001-04-09 15:36:36 -04:00
|
|
|
self.bmp_withcolourmask = images.getTestStar2Bitmap()
|
2004-05-01 22:41:33 -04:00
|
|
|
mask = wx.Mask(self.bmp_withcolourmask, wx.WHITE)
|
1999-12-23 15:05:08 -05:00
|
|
|
self.bmp_withcolourmask.SetMask(mask)
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
self.SetScrollbars(20, 20, 700/20, 460/20)
|
1999-12-23 15:05:08 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
1999-12-23 15:05:08 -05:00
|
|
|
|
|
|
|
|
|
|
|
def OnPaint (self, e):
|
2004-03-28 12:02:16 -05:00
|
|
|
self.SetBackgroundColour(wx.Colour(0,128,0))
|
2003-12-08 20:23:28 -05:00
|
|
|
dc = wx.PaintDC(self)
|
1999-12-23 15:05:08 -05:00
|
|
|
self.PrepareDC(dc)
|
2003-12-08 20:23:28 -05:00
|
|
|
dc.SetTextForeground(wx.WHITE)
|
1999-12-23 15:05:08 -05:00
|
|
|
|
|
|
|
# make an interesting background...
|
2003-12-08 20:23:28 -05:00
|
|
|
dc.SetPen(wx.MEDIUM_GREY_PEN)
|
1999-12-23 15:05:08 -05:00
|
|
|
for i in range(100):
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawLine(0,i*10, i*10,0)
|
1999-12-23 15:05:08 -05:00
|
|
|
|
|
|
|
# draw raw image, mask, and masked images
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawText('original image', 0,0)
|
|
|
|
dc.DrawBitmap(self.bmp_nomask, 0,20, 0)
|
|
|
|
dc.DrawText('with colour mask', 0,100)
|
|
|
|
dc.DrawBitmap(self.bmp_withcolourmask, 0,120, 1)
|
|
|
|
dc.DrawText('the mask image', 0,200)
|
|
|
|
dc.DrawBitmap(self.bmp_themask, 0,220, 0)
|
|
|
|
dc.DrawText('masked image', 0,300)
|
|
|
|
dc.DrawBitmap(self.bmp_withmask, 0,320, 1)
|
1999-12-23 15:05:08 -05:00
|
|
|
|
|
|
|
cx,cy = self.bmp_themask.GetWidth(), self.bmp_themask.GetHeight()
|
|
|
|
|
|
|
|
# draw array of assorted blit operations
|
2003-12-08 20:23:28 -05:00
|
|
|
mdc = wx.MemoryDC()
|
2000-01-19 01:58:56 -05:00
|
|
|
i = 0
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2000-01-19 01:58:56 -05:00
|
|
|
for text, code in logicList:
|
2000-02-13 01:01:58 -05:00
|
|
|
x,y = 120+150*(i%4), 20+100*(i/4)
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawText(text, x, y-20)
|
1999-12-23 15:05:08 -05:00
|
|
|
mdc.SelectObject(self.bmp_withcolourmask)
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.Blit(x,y, cx,cy, mdc, 0,0, code, True)
|
2000-01-19 01:58:56 -05:00
|
|
|
i = i + 1
|
1999-12-23 15:05:08 -05:00
|
|
|
|
|
|
|
|
2004-01-02 20:14:17 -05:00
|
|
|
# On wxGTK there needs to be a panel under wx.ScrolledWindows if they are
|
2001-07-05 13:27:59 -04:00
|
|
|
# going to be in a wxNotebook...
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestPanel(wx.Panel):
|
2001-07-05 13:27:59 -04:00
|
|
|
def __init__(self, parent, ID):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self, parent, ID)
|
2001-07-05 13:27:59 -04:00
|
|
|
self.win = TestMaskWindow(self)
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
2001-07-05 13:27:59 -04:00
|
|
|
|
|
|
|
def OnSize(self, evt):
|
|
|
|
self.win.SetSize(evt.GetSize())
|
1999-12-23 15:05:08 -05:00
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
2001-07-05 13:27:59 -04:00
|
|
|
win = TestPanel(nb, -1)
|
1999-12-23 15:05:08 -05:00
|
|
|
return win
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
overview = """\
|
2003-12-08 20:23:28 -05:00
|
|
|
This class encapsulates a monochrome mask bitmap, where the masked area is black
|
|
|
|
and the unmasked area is white. When associated with a bitmap and drawn in a device
|
|
|
|
context, the unmasked area of the bitmap will be drawn, and the masked area will
|
|
|
|
not be drawn.
|
|
|
|
|
|
|
|
This example shows not only how to create a Mask, but the effects of the Device
|
|
|
|
Context (dc) <code>Blit()</code> method's logic codes.
|
1999-12-23 15:05:08 -05:00
|
|
|
"""
|
2003-03-25 01:35:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
2004-03-04 19:06:33 -05:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
2003-03-25 01:35:27 -05:00
|
|
|
|