]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/Mask.py
Some little tweaks
[wxWidgets.git] / wxPython / demo / Mask.py
... / ...
CommitLineData
1
2import wx
3
4#----------------------------------------------------------------------
5
6logicList = [
7 ('wx.AND', wx.AND),
8 ('wx.AND_INVERT', wx.AND_INVERT),
9 ('wx.AND_REVERSE', wx.AND_REVERSE),
10 ('wx.CLEAR', wx.CLEAR),
11 ('wx.COPY', wx.COPY),
12 ('wx.EQUIV', wx.EQUIV),
13 ('wx.INVERT', wx.INVERT),
14 ('wx.NAND', wx.NAND),
15
16 # this one causes an assert on wxGTK, and doesn't seem to
17 # do much on MSW anyway, so I'll just take it out....
18 #('wxNOR', wxNOR),
19
20 ('wx.NO_OP', wx.NO_OP),
21 ('wx.OR', wx.OR),
22 ('wx.OR_INVERT', wx.OR_INVERT),
23 ('wx.OR_REVERSE', wx.OR_REVERSE),
24 ('wx.SET', wx.SET),
25 ('wx.SRC_INVERT', wx.SRC_INVERT),
26 ('wx.XOR', wx.XOR),
27]
28
29import images
30
31class TestMaskWindow(wx.ScrolledWindow):
32 def __init__(self, parent):
33 wx.ScrolledWindow.__init__(self, parent, -1)
34 self.SetBackgroundColour(wx.Colour(0,128,0))
35
36 # A reference bitmap that we won't mask
37 self.bmp_nomask = images.getTestStar2Bitmap()
38
39 # One that we will
40 self.bmp_withmask = images.getTestStar2Bitmap()
41
42 # this mask comes from a monochrome bitmap
43 self.bmp_themask = images.getTestMaskBitmap()
44 mask = wx.Mask(self.bmp_themask)
45
46 # set the mask on our bitmap
47 self.bmp_withmask.SetMask(mask)
48
49 # Now we'll create a mask in a bit of an easier way, by picking a
50 # colour in the image that is to be the transparent colour.
51 self.bmp_withcolourmask = images.getTestStar2Bitmap()
52 mask = wx.Mask(self.bmp_withcolourmask, wx.WHITE)
53 self.bmp_withcolourmask.SetMask(mask)
54
55 self.SetScrollbars(20, 20, 700/20, 460/20)
56
57 self.Bind(wx.EVT_PAINT, self.OnPaint)
58
59
60 def OnPaint (self, e):
61 self.SetBackgroundColour(wx.Colour(0,128,0))
62 dc = wx.PaintDC(self)
63 self.PrepareDC(dc)
64 dc.SetTextForeground(wx.WHITE)
65
66 # make an interesting background...
67 dc.SetPen(wx.MEDIUM_GREY_PEN)
68 for i in range(100):
69 dc.DrawLine(0,i*10, i*10,0)
70
71 # draw raw image, mask, and masked images
72 dc.DrawText('original image', 0,0)
73 dc.DrawBitmap(self.bmp_nomask, 0,20, 0)
74 dc.DrawText('with colour mask', 0,100)
75 dc.DrawBitmap(self.bmp_withcolourmask, 0,120, 1)
76 dc.DrawText('the mask image', 0,200)
77 dc.DrawBitmap(self.bmp_themask, 0,220, 0)
78 dc.DrawText('masked image', 0,300)
79 dc.DrawBitmap(self.bmp_withmask, 0,320, 1)
80
81 cx,cy = self.bmp_themask.GetWidth(), self.bmp_themask.GetHeight()
82
83 # draw array of assorted blit operations
84 mdc = wx.MemoryDC()
85 i = 0
86
87 for text, code in logicList:
88 x,y = 120+150*(i%4), 20+100*(i/4)
89 dc.DrawText(text, x, y-20)
90 mdc.SelectObject(self.bmp_withcolourmask)
91 dc.Blit(x,y, cx,cy, mdc, 0,0, code, True)
92 i = i + 1
93
94
95# On wxGTK there needs to be a panel under wx.ScrolledWindows if they are
96# going to be in a wxNotebook...
97class TestPanel(wx.Panel):
98 def __init__(self, parent, ID):
99 wx.Panel.__init__(self, parent, ID)
100 self.win = TestMaskWindow(self)
101 self.Bind(wx.EVT_SIZE, self.OnSize)
102
103 def OnSize(self, evt):
104 self.win.SetSize(evt.GetSize())
105
106
107#----------------------------------------------------------------------
108
109def runTest(frame, nb, log):
110 win = TestPanel(nb, -1)
111 return win
112
113#----------------------------------------------------------------------
114
115
116overview = """\
117This class encapsulates a monochrome mask bitmap, where the masked area is black
118and the unmasked area is white. When associated with a bitmap and drawn in a device
119context, the unmasked area of the bitmap will be drawn, and the masked area will
120not be drawn.
121
122This example shows not only how to create a Mask, but the effects of the Device
123Context (dc) <code>Blit()</code> method's logic codes.
124"""
125
126
127
128if __name__ == '__main__':
129 import sys,os
130 import run
131 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
132