]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxMask.py
1 # 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
8 #----------------------------------------------------------------------
12 ('wx.AND_INVERT', wx
.AND_INVERT
),
13 ('wx.AND_REVERSE', wx
.AND_REVERSE
),
14 ('wx.CLEAR', wx
.CLEAR
),
16 ('wx.EQUIV', wx
.EQUIV
),
17 ('wx.INVERT', wx
.INVERT
),
20 # this one causes an assert on wxGTK, and doesn't seem to
21 # do much on MSW anyway, so I'll just take it out....
24 ('wx.NO_OP', wx
.NO_OP
),
26 ('wx.OR_INVERT', wx
.OR_INVERT
),
27 ('wx.OR_REVERSE', wx
.OR_REVERSE
),
29 ('wx.SRC_INVERT', wx
.SRC_INVERT
),
35 class TestMaskWindow(wx
.ScrolledWindow
):
36 def __init__(self
, parent
):
37 wx
.ScrolledWindow
.__init
__(self
, parent
, -1)
38 self
.SetBackgroundColour(wx
.Colour(0,128,0))
40 # A reference bitmap that we won't mask
41 self
.bmp_nomask
= images
.getTestStar2Bitmap()
44 self
.bmp_withmask
= images
.getTestStar2Bitmap()
46 # this mask comes from a monochrome bitmap
47 self
.bmp_themask
= wx
.BitmapFromImage(images
.getTestMaskImage(), 1)
48 mask
= wx
.Mask(self
.bmp_themask
)
50 # set the mask on our bitmap
51 self
.bmp_withmask
.SetMask(mask
)
53 # Now we'll create a mask in a bit of an easier way, by picking a
54 # colour in the image that is to be the transparent colour.
55 self
.bmp_withcolourmask
= images
.getTestStar2Bitmap()
56 mask
= wx
.MaskColour(self
.bmp_withcolourmask
, wx
.WHITE
)
57 self
.bmp_withcolourmask
.SetMask(mask
)
59 self
.SetScrollbars(20, 20, 700/20, 460/20)
61 self
.Bind(wx
.EVT_PAINT
, self
.OnPaint
)
64 def OnPaint (self
, e
):
67 dc
.SetTextForeground(wx
.WHITE
)
69 # make an interesting background...
70 dc
.SetPen(wx
.MEDIUM_GREY_PEN
)
72 dc
.DrawLine((0,i
*10), (i
*10,0))
74 # draw raw image, mask, and masked images
75 dc
.DrawText('original image', (0,0))
76 dc
.DrawBitmap(self
.bmp_nomask
, (0,20), 0)
77 dc
.DrawText('with colour mask', (0,100))
78 dc
.DrawBitmap(self
.bmp_withcolourmask
, (0,120), 1)
79 dc
.DrawText('the mask image', (0,200))
80 dc
.DrawBitmap(self
.bmp_themask
, (0,220), 0)
81 dc
.DrawText('masked image', (0,300))
82 dc
.DrawBitmap(self
.bmp_withmask
, (0,320), 1)
84 cx
,cy
= self
.bmp_themask
.GetWidth(), self
.bmp_themask
.GetHeight()
86 # draw array of assorted blit operations
90 for text
, code
in logicList
:
91 x
,y
= 120+150*(i
%4), 20+100*(i
/4)
92 dc
.DrawText(text
, (x
, y
-20))
93 mdc
.SelectObject(self
.bmp_withcolourmask
)
94 dc
.Blit((x
,y
), (cx
,cy
), mdc
, (0,0), code
, True)
98 # On wxGTK there needs to be a panel under wxScrolledWindows if they are
99 # going to be in a wxNotebook...
100 class TestPanel(wx
.Panel
):
101 def __init__(self
, parent
, ID
):
102 wx
.Panel
.__init
__(self
, parent
, ID
)
103 self
.win
= TestMaskWindow(self
)
104 self
.Bind(wx
.EVT_SIZE
, self
.OnSize
)
106 def OnSize(self
, evt
):
107 self
.win
.SetSize(evt
.GetSize())
110 #----------------------------------------------------------------------
112 def runTest(frame
, nb
, log
):
113 win
= TestPanel(nb
, -1)
116 #----------------------------------------------------------------------
120 This class encapsulates a monochrome mask bitmap, where the masked area is black
121 and the unmasked area is white. When associated with a bitmap and drawn in a device
122 context, the unmasked area of the bitmap will be drawn, and the masked area will
125 This example shows not only how to create a Mask, but the effects of the Device
126 Context (dc) <code>Blit()</code> method's logic codes.
131 if __name__
== '__main__':
134 run
.main(['', os
.path
.basename(sys
.argv
[0])])