]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxMask.py
reSWIGged
[wxWidgets.git] / wxPython / demo / wxMask.py
CommitLineData
8fa876ca
RD
1# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated for wx namespace
4#
9b3d3bc4 5
8fa876ca 6import wx
9b3d3bc4
RD
7
8#----------------------------------------------------------------------
9
8e425133 10logicList = [
8fa876ca
RD
11 ('wx.AND', wx.AND),
12 ('wx.AND_INVERT', wx.AND_INVERT),
13 ('wx.AND_REVERSE', wx.AND_REVERSE),
14 ('wx.CLEAR', wx.CLEAR),
15 ('wx.COPY', wx.COPY),
16 ('wx.EQUIV', wx.EQUIV),
17 ('wx.INVERT', wx.INVERT),
18 ('wx.NAND', wx.NAND),
8e425133
RD
19
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....
22 #('wxNOR', wxNOR),
23
8fa876ca
RD
24 ('wx.NO_OP', wx.NO_OP),
25 ('wx.OR', wx.OR),
26 ('wx.OR_INVERT', wx.OR_INVERT),
27 ('wx.OR_REVERSE', wx.OR_REVERSE),
28 ('wx.SET', wx.SET),
29 ('wx.SRC_INVERT', wx.SRC_INVERT),
30 ('wx.XOR', wx.XOR),
8e425133 31]
9b3d3bc4 32
96bfd053
RD
33import images
34
8fa876ca 35class TestMaskWindow(wx.ScrolledWindow):
9b3d3bc4 36 def __init__(self, parent):
8fa876ca
RD
37 wx.ScrolledWindow.__init__(self, parent, -1)
38 self.SetBackgroundColour(wx.Colour(0,128,0))
9b3d3bc4
RD
39
40 # A reference bitmap that we won't mask
96bfd053 41 self.bmp_nomask = images.getTestStar2Bitmap()
9b3d3bc4
RD
42
43 # One that we will
96bfd053 44 self.bmp_withmask = images.getTestStar2Bitmap()
9b3d3bc4
RD
45
46 # this mask comes from a monochrome bitmap
8fa876ca
RD
47 self.bmp_themask = wx.BitmapFromImage(images.getTestMaskImage(), 1)
48 mask = wx.Mask(self.bmp_themask)
9b3d3bc4
RD
49
50 # set the mask on our bitmap
51 self.bmp_withmask.SetMask(mask)
52
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.
96bfd053 55 self.bmp_withcolourmask = images.getTestStar2Bitmap()
8fa876ca 56 mask = wx.MaskColour(self.bmp_withcolourmask, wx.WHITE)
9b3d3bc4
RD
57 self.bmp_withcolourmask.SetMask(mask)
58
f6bcfd97 59 self.SetScrollbars(20, 20, 700/20, 460/20)
9b3d3bc4 60
8fa876ca 61 self.Bind(wx.EVT_PAINT, self.OnPaint)
9b3d3bc4
RD
62
63
64 def OnPaint (self, e):
8fa876ca 65 dc = wx.PaintDC(self)
9b3d3bc4 66 self.PrepareDC(dc)
8fa876ca 67 dc.SetTextForeground(wx.WHITE)
9b3d3bc4
RD
68
69 # make an interesting background...
8fa876ca 70 dc.SetPen(wx.MEDIUM_GREY_PEN)
9b3d3bc4 71 for i in range(100):
fd3f2efe 72 dc.DrawLine((0,i*10), (i*10,0))
9b3d3bc4
RD
73
74 # draw raw image, mask, and masked images
fd3f2efe
RD
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)
9b3d3bc4
RD
83
84 cx,cy = self.bmp_themask.GetWidth(), self.bmp_themask.GetHeight()
85
86 # draw array of assorted blit operations
8fa876ca 87 mdc = wx.MemoryDC()
8e425133 88 i = 0
8fa876ca 89
8e425133 90 for text, code in logicList:
854862f5 91 x,y = 120+150*(i%4), 20+100*(i/4)
fd3f2efe 92 dc.DrawText(text, (x, y-20))
9b3d3bc4 93 mdc.SelectObject(self.bmp_withcolourmask)
fd3f2efe 94 dc.Blit((x,y), (cx,cy), mdc, (0,0), code, True)
8e425133 95 i = i + 1
9b3d3bc4
RD
96
97
b166c703
RD
98# On wxGTK there needs to be a panel under wxScrolledWindows if they are
99# going to be in a wxNotebook...
8fa876ca 100class TestPanel(wx.Panel):
b166c703 101 def __init__(self, parent, ID):
8fa876ca 102 wx.Panel.__init__(self, parent, ID)
b166c703 103 self.win = TestMaskWindow(self)
8fa876ca 104 self.Bind(wx.EVT_SIZE, self.OnSize)
b166c703
RD
105
106 def OnSize(self, evt):
107 self.win.SetSize(evt.GetSize())
9b3d3bc4
RD
108
109
110#----------------------------------------------------------------------
111
112def runTest(frame, nb, log):
b166c703 113 win = TestPanel(nb, -1)
9b3d3bc4
RD
114 return win
115
116#----------------------------------------------------------------------
117
118
9b3d3bc4 119overview = """\
8fa876ca
RD
120This class encapsulates a monochrome mask bitmap, where the masked area is black
121and the unmasked area is white. When associated with a bitmap and drawn in a device
122context, the unmasked area of the bitmap will be drawn, and the masked area will
123not be drawn.
124
125This example shows not only how to create a Mask, but the effects of the Device
126Context (dc) <code>Blit()</code> method's logic codes.
9b3d3bc4 127"""
1e4a197e
RD
128
129
130
131if __name__ == '__main__':
132 import sys,os
133 import run
134 run.main(['', os.path.basename(sys.argv[0])])
135