]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/wxMask.py
2 from wxPython
.wx
import *
4 #----------------------------------------------------------------------
28 class TestMaskWindow(wxScrolledWindow
):
29 def __init__(self
, parent
):
30 wxScrolledWindow
.__init
__(self
, parent
, -1)
31 self
.SetBackgroundColour(wxColour(0,128,0))
33 # A reference bitmap that we won't mask
34 self
.bmp_nomask
= wxBitmap('bitmaps/test_image.png', wxBITMAP_TYPE_PNG
)
37 self
.bmp_withmask
= wxBitmap('bitmaps/test_image.png', wxBITMAP_TYPE_PNG
)
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
)
44 # set the mask on our bitmap
45 self
.bmp_withmask
.SetMask(mask
)
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
)
53 self
.SetScrollbars(20, 20, 600/20, 460/20)
57 def OnPaint (self
, e
):
60 dc
.SetTextForeground(wxWHITE
)
62 # make an interesting background...
63 dc
.SetPen(wxMEDIUM_GREY_PEN
)
65 dc
.DrawLine(0,i
*10,i
*10,0)
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)
77 cx
,cy
= self
.bmp_themask
.GetWidth(), self
.bmp_themask
.GetHeight()
79 # draw array of assorted blit operations
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)
92 #----------------------------------------------------------------------
94 def runTest(frame
, nb
, log
):
95 win
= TestMaskWindow(nb
)
98 #----------------------------------------------------------------------