# This one shows how to draw images on a DC.

import random

import wx

#------------------------------------------------------------------------------

class TestFrame( wx.Frame ) :
    
    def __init__( self ) :
        
        wx.Frame.__init__( self, None, title='DrawAlphaImage.py', pos=(10, 10) )
        self.ClientSize = (600, 600)
        self.SetMinSize( self.GetSize() )
        
        self.frm_pnl = wx.Panel( self )
        self.frm_pnl.BackgroundColour = (200, 255, 200)
        
        #-----
        
        img_bmap = wx.Bitmap( 'ImageWithAlpha.png' )
        rp_win = DrawingPanel( self.frm_pnl, img_bmap )
        
    #end __init__
    
#end TestFrame

#------------------------------------------------------------------------------

random.seed()

class DrawingPanel( wx.Panel ) :
    
    def __init__( self, parent, img_bmap ) :
        
        wx.Panel.__init__( self, parent, size=(500, 500), pos=(50, 50) )
        
        #-----
        
        self.img_bmap = img_bmap

        # Create some random positions to draw the image at :
        self.positions = [ (10, 10) ]   # First posn is fixed to gaurantee that it's shown.
        for x in range( 5 ) :
            x = random.randint( 0, 500 )
            y = random.randint( 0, 300 )
            self.positions.append( (x, y) )
            
        # Hook in the OnPaint handler.
        self.Bind( wx.EVT_PAINT, self.OnPaint )
        self.onPaint_ctr = 0
        
    #end __init__
    
    #-----------------------------
    
    def OnPaint( self, evt ) :
        
        self.onPaint_ctr += 1
        print '\n----  DrawingPanel::OnPaint():   self.onPaint_ctr ', self.onPaint_ctr
        
        # create and clear the DC
        dc = wx.BufferedPaintDC( self )
        
        brush = wx.Brush( 'sky blue' )
        dc.SetBackground( brush )
        dc.Clear()

        # draw the image in random locations
        for x,y in self.positions :
            dc.DrawBitmap( self.img_bmap, x, y, useMask=True )
    
    #end def
    
#end DrawingPanel class
        
#==============================================================================

app = wx.PySimpleApp()
frm = TestFrame()
frm.Show()
app.MainLoop()
