]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/wxMask.py
disable #warning because it's an error for some compilers
[wxWidgets.git] / utils / wxPython / demo / wxMask.py
1
2 from wxPython.wx import *
3
4 #----------------------------------------------------------------------
5
6 logic = ['']*16
7 def rlf(x):
8 logic[eval(x)]=x
9
10
11 rlf('wxAND')
12 rlf('wxAND_INVERT')
13 rlf('wxAND_REVERSE')
14 rlf('wxCLEAR')
15 rlf('wxCOPY')
16 rlf('wxEQUIV')
17 rlf('wxINVERT')
18 rlf('wxNAND')
19 rlf('wxNOR')
20 rlf('wxNO_OP')
21 rlf('wxOR')
22 rlf('wxOR_INVERT')
23 rlf('wxOR_REVERSE')
24 rlf('wxSET')
25 rlf('wxSRC_INVERT')
26 rlf('wxXOR')
27
28 class TestMaskWindow(wxScrolledWindow):
29 def __init__(self, parent):
30 wxScrolledWindow.__init__(self, parent, -1)
31 self.SetBackgroundColour(wxColour(0,128,0))
32
33 # A reference bitmap that we won't mask
34 self.bmp_nomask = wxBitmap('bitmaps/test_image.png', wxBITMAP_TYPE_PNG)
35
36 # One that we will
37 self.bmp_withmask = wxBitmap('bitmaps/test_image.png', wxBITMAP_TYPE_PNG)
38
39 # this mask comes from a monochrome bitmap
40 self.bmp_themask = wxBitmap('bitmaps/test_mask.bmp', wxBITMAP_TYPE_BMP)
41 self.bmp_themask.SetDepth(1)
42 mask = wxMask(self.bmp_themask)
43
44 # set the mask on our bitmap
45 self.bmp_withmask.SetMask(mask)
46
47 # Now we'll create a mask in a bit of an easier way, by picking a
48 # colour in the image that is to be the transparent colour.
49 self.bmp_withcolourmask = wxBitmap('bitmaps/test_image.png', wxBITMAP_TYPE_PNG)
50 mask = wxMaskColour(self.bmp_withcolourmask, wxWHITE)
51 self.bmp_withcolourmask.SetMask(mask)
52
53 self.SetScrollbars(20, 20, 600/20, 460/20)
54
55
56
57 def OnPaint (self, e):
58 dc = wxPaintDC(self)
59 self.PrepareDC(dc)
60 dc.SetTextForeground(wxWHITE)
61
62 # make an interesting background...
63 dc.SetPen(wxMEDIUM_GREY_PEN)
64 for i in range(100):
65 dc.DrawLine(0,i*10,i*10,0)
66
67 # draw raw image, mask, and masked images
68 dc.DrawText('original image', 0,0)
69 dc.DrawBitmap(self.bmp_nomask, 0,20, 0)
70 dc.DrawText('with colour mask', 0,100)
71 dc.DrawBitmap(self.bmp_withcolourmask, 0,120, 1)
72 dc.DrawText('the mask image', 0,200)
73 dc.DrawBitmap(self.bmp_themask, 0,220, 0)
74 dc.DrawText('masked image', 0,300)
75 dc.DrawBitmap(self.bmp_withmask, 0,320, 1)
76
77 cx,cy = self.bmp_themask.GetWidth(), self.bmp_themask.GetHeight()
78
79 # draw array of assorted blit operations
80 mdc = wxMemoryDC()
81 for i in range(16):
82 text = logic[i]
83 x,y = 120+100*(i%4), 20+100*(i/4)
84 dc.DrawText(text, x,y-20)
85 mdc.SelectObject(self.bmp_withcolourmask)
86 dc.Blit(x,y, cx,cy, mdc, 0,0, i,1)
87
88
89
90
91
92 #----------------------------------------------------------------------
93
94 def runTest(frame, nb, log):
95 win = TestMaskWindow(nb)
96 return win
97
98 #----------------------------------------------------------------------
99
100
101
102 overview = """\
103 """