]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/Mask.py
fix building/running of tex2rtf
[wxWidgets.git] / wxPython / demo / Mask.py
CommitLineData
9b3d3bc4 1
8fa876ca 2import wx
9b3d3bc4
RD
3
4#----------------------------------------------------------------------
5
8e425133 6logicList = [
8fa876ca
RD
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),
8e425133
RD
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
8fa876ca
RD
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),
8e425133 27]
9b3d3bc4 28
dee1a629
KO
29if 'mac-cg' in wx.PlatformInfo:
30 # that's all, folks!
31 logicList = [
32 ('wx.COPY', wx.COPY),
33 ]
34
96bfd053
RD
35import images
36
8fa876ca 37class TestMaskWindow(wx.ScrolledWindow):
9b3d3bc4 38 def __init__(self, parent):
8fa876ca
RD
39 wx.ScrolledWindow.__init__(self, parent, -1)
40 self.SetBackgroundColour(wx.Colour(0,128,0))
9b3d3bc4
RD
41
42 # A reference bitmap that we won't mask
96bfd053 43 self.bmp_nomask = images.getTestStar2Bitmap()
9b3d3bc4
RD
44
45 # One that we will
96bfd053 46 self.bmp_withmask = images.getTestStar2Bitmap()
9b3d3bc4
RD
47
48 # this mask comes from a monochrome bitmap
0482c494 49 self.bmp_themask = images.getTestMaskBitmap()
8fa876ca 50 mask = wx.Mask(self.bmp_themask)
9b3d3bc4
RD
51
52 # set the mask on our bitmap
53 self.bmp_withmask.SetMask(mask)
54
55 # Now we'll create a mask in a bit of an easier way, by picking a
56 # colour in the image that is to be the transparent colour.
96bfd053 57 self.bmp_withcolourmask = images.getTestStar2Bitmap()
d7403ad2 58 mask = wx.Mask(self.bmp_withcolourmask, wx.WHITE)
9b3d3bc4
RD
59 self.bmp_withcolourmask.SetMask(mask)
60
f6bcfd97 61 self.SetScrollbars(20, 20, 700/20, 460/20)
9b3d3bc4 62
8fa876ca 63 self.Bind(wx.EVT_PAINT, self.OnPaint)
9b3d3bc4
RD
64
65
66 def OnPaint (self, e):
5cd7ab8d 67 self.SetBackgroundColour(wx.Colour(0,128,0))
8fa876ca 68 dc = wx.PaintDC(self)
9b3d3bc4 69 self.PrepareDC(dc)
8fa876ca 70 dc.SetTextForeground(wx.WHITE)
9b3d3bc4
RD
71
72 # make an interesting background...
8fa876ca 73 dc.SetPen(wx.MEDIUM_GREY_PEN)
9b3d3bc4 74 for i in range(100):
d7403ad2 75 dc.DrawLine(0,i*10, i*10,0)
9b3d3bc4
RD
76
77 # draw raw image, mask, and masked images
d7403ad2
RD
78 dc.DrawText('original image', 0,0)
79 dc.DrawBitmap(self.bmp_nomask, 0,20, 0)
80 dc.DrawText('with colour mask', 0,100)
81 dc.DrawBitmap(self.bmp_withcolourmask, 0,120, 1)
82 dc.DrawText('the mask image', 0,200)
83 dc.DrawBitmap(self.bmp_themask, 0,220, 0)
84 dc.DrawText('masked image', 0,300)
85 dc.DrawBitmap(self.bmp_withmask, 0,320, 1)
9b3d3bc4
RD
86
87 cx,cy = self.bmp_themask.GetWidth(), self.bmp_themask.GetHeight()
88
89 # draw array of assorted blit operations
8fa876ca 90 mdc = wx.MemoryDC()
8e425133 91 i = 0
8fa876ca 92
8e425133 93 for text, code in logicList:
854862f5 94 x,y = 120+150*(i%4), 20+100*(i/4)
d7403ad2 95 dc.DrawText(text, x, y-20)
9b3d3bc4 96 mdc.SelectObject(self.bmp_withcolourmask)
d7403ad2 97 dc.Blit(x,y, cx,cy, mdc, 0,0, code, True)
8e425133 98 i = i + 1
9b3d3bc4
RD
99
100
299647ac 101# On wxGTK there needs to be a panel under wx.ScrolledWindows if they are
b166c703 102# going to be in a wxNotebook...
8fa876ca 103class TestPanel(wx.Panel):
b166c703 104 def __init__(self, parent, ID):
8fa876ca 105 wx.Panel.__init__(self, parent, ID)
b166c703 106 self.win = TestMaskWindow(self)
8fa876ca 107 self.Bind(wx.EVT_SIZE, self.OnSize)
b166c703
RD
108
109 def OnSize(self, evt):
110 self.win.SetSize(evt.GetSize())
9b3d3bc4
RD
111
112
113#----------------------------------------------------------------------
114
115def runTest(frame, nb, log):
b166c703 116 win = TestPanel(nb, -1)
9b3d3bc4
RD
117 return win
118
119#----------------------------------------------------------------------
120
121
9b3d3bc4 122overview = """\
8fa876ca
RD
123This class encapsulates a monochrome mask bitmap, where the masked area is black
124and the unmasked area is white. When associated with a bitmap and drawn in a device
125context, the unmasked area of the bitmap will be drawn, and the masked area will
126not be drawn.
127
128This example shows not only how to create a Mask, but the effects of the Device
129Context (dc) <code>Blit()</code> method's logic codes.
9b3d3bc4 130"""
1e4a197e
RD
131
132
133
134if __name__ == '__main__':
135 import sys,os
136 import run
8eca4fef 137 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1e4a197e 138