]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Mask.py
   4 #---------------------------------------------------------------------- 
   8     ('wx.AND_INVERT', wx
.AND_INVERT
), 
   9     ('wx.AND_REVERSE', wx
.AND_REVERSE
), 
  10     ('wx.CLEAR', wx
.CLEAR
), 
  12     ('wx.EQUIV', wx
.EQUIV
), 
  13     ('wx.INVERT', wx
.INVERT
), 
  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.... 
  20     ('wx.NO_OP', wx
.NO_OP
), 
  22     ('wx.OR_INVERT', wx
.OR_INVERT
), 
  23     ('wx.OR_REVERSE', wx
.OR_REVERSE
), 
  25     ('wx.SRC_INVERT', wx
.SRC_INVERT
), 
  29 if 'mac-cg' in wx
.PlatformInfo
: 
  37 class TestMaskWindow(wx
.ScrolledWindow
): 
  38     def __init__(self
, parent
): 
  39         wx
.ScrolledWindow
.__init
__(self
, parent
, -1) 
  40         self
.SetBackgroundColour(wx
.Colour(0,128,0)) 
  42         # A reference bitmap that we won't mask 
  43         self
.bmp_nomask  
= images
.getTestStar2Bitmap() 
  46         self
.bmp_withmask  
= images
.getTestStar2Bitmap() 
  48         # this mask comes from a monochrome bitmap 
  49         self
.bmp_themask 
= images
.getTestMaskBitmap() 
  50         mask 
= wx
.Mask(self
.bmp_themask
) 
  52         # set the mask on our bitmap 
  53         self
.bmp_withmask
.SetMask(mask
) 
  55         # Now we'll create a mask in a bit of an easier way, by picking a 
  56         # colour in the image that is to be the transparent colour. 
  57         self
.bmp_withcolourmask  
= images
.getTestStar2Bitmap() 
  58         mask 
= wx
.Mask(self
.bmp_withcolourmask
, wx
.WHITE
) 
  59         self
.bmp_withcolourmask
.SetMask(mask
) 
  61         self
.SetScrollbars(20, 20, 700/20, 460/20) 
  63         self
.Bind(wx
.EVT_PAINT
, self
.OnPaint
) 
  66     def OnPaint (self
, e
): 
  67         self
.SetBackgroundColour(wx
.Colour(0,128,0)) 
  70         dc
.SetTextForeground(wx
.WHITE
) 
  72         # make an interesting background... 
  73         dc
.SetPen(wx
.MEDIUM_GREY_PEN
) 
  75             dc
.DrawLine(0,i
*10, i
*10,0) 
  77         # draw raw image, mask, and masked images 
  78         dc
.DrawText('original image', 0,0) 
  79         dc
.DrawBitmap(self
.bmp_nomask
, 0,20, 0) 
  80         dc
.DrawText('with colour mask', 0,100) 
  81         dc
.DrawBitmap(self
.bmp_withcolourmask
, 0,120, 1) 
  82         dc
.DrawText('the mask image', 0,200) 
  83         dc
.DrawBitmap(self
.bmp_themask
, 0,220, 0) 
  84         dc
.DrawText('masked image', 0,300) 
  85         dc
.DrawBitmap(self
.bmp_withmask
, 0,320, 1) 
  87         cx
,cy 
= self
.bmp_themask
.GetWidth(), self
.bmp_themask
.GetHeight() 
  89         # draw array of assorted blit operations 
  93         for text
, code 
in logicList
: 
  94             x
,y 
= 120+150*(i
%4), 20+100*(i
/4) 
  95             dc
.DrawText(text
, x
, y
-20) 
  96             mdc
.SelectObject(self
.bmp_withcolourmask
) 
  97             dc
.Blit(x
,y
, cx
,cy
, mdc
, 0,0, code
, True) 
 101 # On wxGTK there needs to be a panel under wx.ScrolledWindows if they are 
 102 # going to be in a wxNotebook... 
 103 class TestPanel(wx
.Panel
): 
 104     def __init__(self
, parent
, ID
): 
 105         wx
.Panel
.__init
__(self
, parent
, ID
) 
 106         self
.win 
= TestMaskWindow(self
) 
 107         self
.Bind(wx
.EVT_SIZE
, self
.OnSize
) 
 109     def OnSize(self
, evt
): 
 110         self
.win
.SetSize(evt
.GetSize()) 
 113 #---------------------------------------------------------------------- 
 115 def runTest(frame
, nb
, log
): 
 116     win 
= TestPanel(nb
, -1) 
 119 #---------------------------------------------------------------------- 
 123 This class encapsulates a monochrome mask bitmap, where the masked area is black  
 124 and the unmasked area is white. When associated with a bitmap and drawn in a device  
 125 context, the unmasked area of the bitmap will be drawn, and the masked area will  
 128 This example shows not only how to create a Mask, but the effects of the Device 
 129 Context (dc) <code>Blit()</code> method's logic codes. 
 134 if __name__ 
== '__main__': 
 137     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])