Tim Churchard wrote:
I'm looking for a way to draw a circle shaped window - i've been nosing through the doc's and I found that wxFrame inherited from wxTopLevelWindow... which has a setShape function.
I'm not keen on using a bitmap to get the shape. Is it possible to make a circle shaped wxRegion without too much messing about, and maybe even a doughnut shaped region?
Non-rectangular regions are not so easy to construct without using a bitmap because you would have to decompose your shape into a series of rectangles that would need to be added or subtracted from the region. For curves that involves some math and a lot of loops.
On the other hand, there is nothing that requires the bitmap to be loaded from a file. You can build one on the fly in your program and then use that to make your region, no ugly math and no complex loops required. For example, something like this should work (untested):
def MakeDoughnutRegion(outerRadius, innerRadius):
bmp = wx.EmptyBitmap(outerRadious*2, outerRadious*2)
dc = wx.MemoryDC()
dc.SelectObject(bmp)
# black will be our transparent colour
dc.SetBackground(wx.Brush("black"))
dc.Clear()
# draw the outer circle (opaque)
dc.SetBrush(wx.Brush("white"))
dc.SetPen(wx.Pen("white"))
dc.DrawCircle(outerRadius, outerRadius, outerRadius)
# draw the inner circle (transparent)
dc.SetBrush(wx.Brush("black"))
dc.SetPen(wx.Pen("black"))
dc.DrawCircle(outerRadius, outerRadius, innerRadius)
dc.SelectObject(wx.NullBitmap)
del dc
bmp.SetMaskColour("black")
return wx.RegionFromBitmap(bmp)
ยทยทยท
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!