]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxMask.py
2 from wxPython
.wx
import *
4 #----------------------------------------------------------------------
8 ('wxAND_INVERT', wxAND_INVERT
),
9 ('wxAND_REVERSE', wxAND_REVERSE
),
13 ('wxINVERT', wxINVERT
),
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....
22 ('wxOR_INVERT', wxOR_INVERT
),
23 ('wxOR_REVERSE', wxOR_REVERSE
),
25 ('wxSRC_INVERT', wxSRC_INVERT
),
31 class TestMaskWindow(wxScrolledWindow
):
32 def __init__(self
, parent
):
33 wxScrolledWindow
.__init
__(self
, parent
, -1)
34 self
.SetBackgroundColour(wxColour(0,128,0))
36 # A reference bitmap that we won't mask
37 self
.bmp_nomask
= images
.getTestStar2Bitmap()
40 self
.bmp_withmask
= images
.getTestStar2Bitmap()
42 # this mask comes from a monochrome bitmap
43 self
.bmp_themask
= wxBitmapFromImage(images
.getTestMaskImage(), 1)
44 mask
= wxMask(self
.bmp_themask
)
46 # set the mask on our bitmap
47 self
.bmp_withmask
.SetMask(mask
)
49 # Now we'll create a mask in a bit of an easier way, by picking a
50 # colour in the image that is to be the transparent colour.
51 self
.bmp_withcolourmask
= images
.getTestStar2Bitmap()
52 mask
= wxMaskColour(self
.bmp_withcolourmask
, wxWHITE
)
53 self
.bmp_withcolourmask
.SetMask(mask
)
55 self
.SetScrollbars(20, 20, 700/20, 460/20)
57 EVT_PAINT(self
, self
.OnPaint
)
60 def OnPaint (self
, e
):
63 dc
.SetTextForeground(wxWHITE
)
65 # make an interesting background...
66 dc
.SetPen(wxMEDIUM_GREY_PEN
)
68 dc
.DrawLine((0,i
*10), (i
*10,0))
70 # draw raw image, mask, and masked images
71 dc
.DrawText('original image', (0,0))
72 dc
.DrawBitmap(self
.bmp_nomask
, (0,20), 0)
73 dc
.DrawText('with colour mask', (0,100))
74 dc
.DrawBitmap(self
.bmp_withcolourmask
, (0,120), 1)
75 dc
.DrawText('the mask image', (0,200))
76 dc
.DrawBitmap(self
.bmp_themask
, (0,220), 0)
77 dc
.DrawText('masked image', (0,300))
78 dc
.DrawBitmap(self
.bmp_withmask
, (0,320), 1)
80 cx
,cy
= self
.bmp_themask
.GetWidth(), self
.bmp_themask
.GetHeight()
82 # draw array of assorted blit operations
85 for text
, code
in logicList
:
86 x
,y
= 120+150*(i
%4), 20+100*(i
/4)
87 dc
.DrawText(text
, (x
, y
-20))
88 mdc
.SelectObject(self
.bmp_withcolourmask
)
89 dc
.Blit((x
,y
), (cx
,cy
), mdc
, (0,0), code
, True)
93 # On wxGTK there needs to be a panel under wxScrolledWindows if they are
94 # going to be in a wxNotebook...
95 class TestPanel(wxPanel
):
96 def __init__(self
, parent
, ID
):
97 wxPanel
.__init
__(self
, parent
, ID
)
98 self
.win
= TestMaskWindow(self
)
99 EVT_SIZE(self
, self
.OnSize
)
101 def OnSize(self
, evt
):
102 self
.win
.SetSize(evt
.GetSize())
105 #----------------------------------------------------------------------
107 def runTest(frame
, nb
, log
):
108 win
= TestPanel(nb
, -1)
111 #----------------------------------------------------------------------
120 if __name__
== '__main__':
123 run
.main(['', os
.path
.basename(sys
.argv
[0])])