]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxMask.py
Commented out the bitmap-greying code until I have time to debug it
[wxWidgets.git] / wxPython / demo / wxMask.py
CommitLineData
9b3d3bc4
RD
1
2from wxPython.wx import *
3
4#----------------------------------------------------------------------
5
8e425133
RD
6logicList = [
7 ('wxAND', wxAND),
8 ('wxAND_INVERT', wxAND_INVERT),
9 ('wxAND_REVERSE', wxAND_REVERSE),
10 ('wxCLEAR', wxCLEAR),
11 ('wxCOPY', wxCOPY),
12 ('wxEQUIV', wxEQUIV),
13 ('wxINVERT', wxINVERT),
14 ('wxNAND', wxNAND),
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 ('wxNO_OP', wxNO_OP),
21 ('wxOR', wxOR),
22 ('wxOR_INVERT', wxOR_INVERT),
23 ('wxOR_REVERSE', wxOR_REVERSE),
24 ('wxSET', wxSET),
25 ('wxSRC_INVERT', wxSRC_INVERT),
26 ('wxXOR', wxXOR),
27]
9b3d3bc4 28
96bfd053
RD
29import images
30
9b3d3bc4
RD
31class TestMaskWindow(wxScrolledWindow):
32 def __init__(self, parent):
33 wxScrolledWindow.__init__(self, parent, -1)
34 self.SetBackgroundColour(wxColour(0,128,0))
35
36 # A reference bitmap that we won't mask
96bfd053 37 self.bmp_nomask = images.getTestStar2Bitmap()
9b3d3bc4
RD
38
39 # One that we will
96bfd053 40 self.bmp_withmask = images.getTestStar2Bitmap()
9b3d3bc4
RD
41
42 # this mask comes from a monochrome bitmap
96bfd053 43 self.bmp_themask = images.getTestMaskBitmap()
9b3d3bc4
RD
44 self.bmp_themask.SetDepth(1)
45 mask = wxMask(self.bmp_themask)
46
47 # set the mask on our bitmap
48 self.bmp_withmask.SetMask(mask)
49
50 # Now we'll create a mask in a bit of an easier way, by picking a
51 # colour in the image that is to be the transparent colour.
96bfd053 52 self.bmp_withcolourmask = images.getTestStar2Bitmap()
9b3d3bc4
RD
53 mask = wxMaskColour(self.bmp_withcolourmask, wxWHITE)
54 self.bmp_withcolourmask.SetMask(mask)
55
f6bcfd97 56 self.SetScrollbars(20, 20, 700/20, 460/20)
9b3d3bc4 57
f6bcfd97 58 EVT_PAINT(self, self.OnPaint)
9b3d3bc4
RD
59
60
61 def OnPaint (self, e):
62 dc = wxPaintDC(self)
63 self.PrepareDC(dc)
64 dc.SetTextForeground(wxWHITE)
65
66 # make an interesting background...
67 dc.SetPen(wxMEDIUM_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 = wxMemoryDC()
8e425133
RD
85 i = 0
86 for text, code in logicList:
854862f5
RD
87 x,y = 120+150*(i%4), 20+100*(i/4)
88 dc.DrawText(text, x, y-20)
9b3d3bc4 89 mdc.SelectObject(self.bmp_withcolourmask)
8e425133
RD
90 dc.Blit(x,y, cx,cy, mdc, 0,0, code, true)
91 i = i + 1
9b3d3bc4
RD
92
93
b166c703
RD
94# On wxGTK there needs to be a panel under wxScrolledWindows if they are
95# going to be in a wxNotebook...
96class TestPanel(wxPanel):
97 def __init__(self, parent, ID):
98 wxPanel.__init__(self, parent, ID)
99 self.win = TestMaskWindow(self)
100 EVT_SIZE(self, self.OnSize)
101
102 def OnSize(self, evt):
103 self.win.SetSize(evt.GetSize())
9b3d3bc4
RD
104
105
106#----------------------------------------------------------------------
107
108def runTest(frame, nb, log):
b166c703 109 win = TestPanel(nb, -1)
9b3d3bc4
RD
110 return win
111
112#----------------------------------------------------------------------
113
114
115
116overview = """\
117"""