Changeset 56198

Show
Ignore:
Timestamp:
10/09/08 08:31:16 (6 weeks ago)
Author:
RD
Message:

Try alternate approaches to creating the bitmap

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • wxPython/branches/WX_2_8_BRANCH/sandbox/test_EmptyBitmapRGBA.py

    r55616 r56198  
    11import wx 
    22print wx.version() 
     3 
     4USE_CAIRO = False 
     5if USE_CAIRO: 
     6    import wx.lib.wxcairo 
     7    import cairo 
    38 
    49DIM = 100 
     
    1823 
    1924    def MakeBitmap(self, red=0, green=0, blue=0, alpha=0): 
    20         bmp = wx.EmptyBitmapRGBA(DIM, DIM, red, green, blue, alpha) 
    21          
    22         dc = wx.MemoryDC(bmp) 
    23         gc = wx.GraphicsContext.Create(dc) 
    24  
    25         path = gc.CreatePath() 
    26         path.MoveToPoint(POS,POS) 
    27         path.AddLineToPoint(DIM-POS, DIM-POS) 
    28         gc.SetPen(wx.Pen("red", 8)) 
    29         gc.StrokePath(path) 
     25        if not USE_CAIRO: 
     26            # This one works fine on Mac and Windows, but not wxGTK... 
     27            bmp = wx.EmptyBitmapRGBA(DIM, DIM, red, green, blue, alpha) 
     28            dc = wx.MemoryDC(bmp) 
     29            gc = wx.GraphicsContext.Create(dc)             
     30            path = gc.CreatePath() 
     31            path.MoveToPoint(POS,POS) 
     32            path.AddLineToPoint(DIM-POS, DIM-POS) 
     33            gc.SetPen(wx.Pen("red", 8)) 
     34            gc.StrokePath(path) 
     35             
     36        else: 
     37            # try out a couple possible workarounds 
     38            sfc = cairo.ImageSurface(cairo.FORMAT_ARGB32, DIM, DIM) 
     39            ctx = cairo.Context(sfc) 
     40            if False: 
     41                # use straight cairo 
     42                ctx.set_source_rgba(red/255.0, green/255.0, blue/255.0, alpha/255.0) 
     43                ctx.paint() 
     44                ctx.set_line_width(8) 
     45                ctx.set_line_cap(cairo.LINE_CAP_ROUND) 
     46                ctx.set_source_rgb(1, 0, 0) 
     47                ctx.move_to(POS, POS) 
     48                ctx.line_to(DIM-POS, DIM-POS) 
     49                ctx.stroke() 
     50            else: 
     51                # use our GC-like wrapper 
     52                import wx.lib.graphics as g 
     53                gc = g.GraphicsContext.CreateFromNative(ctx) 
     54                gc.Clear(wx.Colour(red, green, blue, alpha)) 
     55                path = gc.CreatePath() 
     56                path.MoveToPoint(POS,POS) 
     57                path.AddLineToPoint(DIM-POS, DIM-POS) 
     58                gc.SetPen(wx.Pen("red", 8)) 
     59                gc.StrokePath(path) 
     60            bmp = wx.lib.wxcairo.BitmapFromImageSurface(sfc) 
    3061 
    3162        return bmp