]>
Commit | Line | Data |
---|---|---|
9b3d3bc4 RD |
1 | |
2 | from wxPython.wx import * | |
3 | ||
4 | #---------------------------------------------------------------------- | |
5 | ||
8e425133 RD |
6 | logicList = [ |
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 RD |
28 | |
29 | class TestMaskWindow(wxScrolledWindow): | |
30 | def __init__(self, parent): | |
31 | wxScrolledWindow.__init__(self, parent, -1) | |
32 | self.SetBackgroundColour(wxColour(0,128,0)) | |
33 | ||
34 | # A reference bitmap that we won't mask | |
35 | self.bmp_nomask = wxBitmap('bitmaps/test_image.png', wxBITMAP_TYPE_PNG) | |
36 | ||
37 | # One that we will | |
38 | self.bmp_withmask = wxBitmap('bitmaps/test_image.png', wxBITMAP_TYPE_PNG) | |
39 | ||
40 | # this mask comes from a monochrome bitmap | |
41 | self.bmp_themask = wxBitmap('bitmaps/test_mask.bmp', wxBITMAP_TYPE_BMP) | |
42 | self.bmp_themask.SetDepth(1) | |
43 | mask = wxMask(self.bmp_themask) | |
44 | ||
45 | # set the mask on our bitmap | |
46 | self.bmp_withmask.SetMask(mask) | |
47 | ||
48 | # Now we'll create a mask in a bit of an easier way, by picking a | |
49 | # colour in the image that is to be the transparent colour. | |
50 | self.bmp_withcolourmask = wxBitmap('bitmaps/test_image.png', wxBITMAP_TYPE_PNG) | |
51 | mask = wxMaskColour(self.bmp_withcolourmask, wxWHITE) | |
52 | self.bmp_withcolourmask.SetMask(mask) | |
53 | ||
f6bcfd97 | 54 | self.SetScrollbars(20, 20, 700/20, 460/20) |
9b3d3bc4 | 55 | |
f6bcfd97 | 56 | EVT_PAINT(self, self.OnPaint) |
9b3d3bc4 RD |
57 | |
58 | ||
59 | def OnPaint (self, e): | |
60 | dc = wxPaintDC(self) | |
61 | self.PrepareDC(dc) | |
62 | dc.SetTextForeground(wxWHITE) | |
63 | ||
64 | # make an interesting background... | |
65 | dc.SetPen(wxMEDIUM_GREY_PEN) | |
66 | for i in range(100): | |
67 | dc.DrawLine(0,i*10,i*10,0) | |
68 | ||
69 | # draw raw image, mask, and masked images | |
70 | dc.DrawText('original image', 0,0) | |
71 | dc.DrawBitmap(self.bmp_nomask, 0,20, 0) | |
72 | dc.DrawText('with colour mask', 0,100) | |
73 | dc.DrawBitmap(self.bmp_withcolourmask, 0,120, 1) | |
74 | dc.DrawText('the mask image', 0,200) | |
75 | dc.DrawBitmap(self.bmp_themask, 0,220, 0) | |
76 | dc.DrawText('masked image', 0,300) | |
77 | dc.DrawBitmap(self.bmp_withmask, 0,320, 1) | |
78 | ||
79 | cx,cy = self.bmp_themask.GetWidth(), self.bmp_themask.GetHeight() | |
80 | ||
81 | # draw array of assorted blit operations | |
82 | mdc = wxMemoryDC() | |
8e425133 RD |
83 | i = 0 |
84 | for text, code in logicList: | |
854862f5 RD |
85 | x,y = 120+150*(i%4), 20+100*(i/4) |
86 | dc.DrawText(text, x, y-20) | |
9b3d3bc4 | 87 | mdc.SelectObject(self.bmp_withcolourmask) |
8e425133 RD |
88 | dc.Blit(x,y, cx,cy, mdc, 0,0, code, true) |
89 | i = i + 1 | |
9b3d3bc4 RD |
90 | |
91 | ||
92 | ||
93 | ||
94 | #---------------------------------------------------------------------- | |
95 | ||
96 | def runTest(frame, nb, log): | |
97 | win = TestMaskWindow(nb) | |
98 | return win | |
99 | ||
100 | #---------------------------------------------------------------------- | |
101 | ||
102 | ||
103 | ||
104 | overview = """\ | |
105 | """ |