Cairo Global Scaling and Translation

11 views
Skip to first unread message

King

unread,
Dec 16, 2009, 12:31:28 AM12/16/09
to wxPython-users
This is related to Cairo and double buffer example at here:
http://wiki.wxpython.org/DoubleBufferedDrawing

Replace the "draw" function with this

def Draw(self, dc):
dc.SetBackground( wx.Brush("White") )
dc.Clear() # make sure you clear the bitmap!

# Set global scale and translation
dc.SetUserScale(1.5, 1.5)
dc.SetDeviceOrigin(50, 50)
# now draw something with cairo
ctx = Cr.GraphicsContext.Create(dc) # wx.GCDC(dc) # This
works!!!
ctx.SetBrush(wx.Brush("blue"))
ctx.DrawEllipse(0,0,100,50)
# Reset global scale and translation
dc.SetUserScale(1, 1)
dc.SetDeviceOrigin(0, 0)

Just before rendering on cairo I am setting up global scale/zoom and
translation. Ellipse is rendered as it has been scaled as bitmap not a
proper scaled shape.
This works if fine you use wx.GCDC instead of cairo by changing the
line

ctx = Cr.GraphicsContext.Create(dc)
to

ctx = wx.GCDC(dc)

How to set global scale & translation in and cairo before you draw
anything?

Prashant
Python 2.6.2
wxPython 2.8.10.1
Win XP 32

Robin Dunn

unread,
Dec 16, 2009, 3:50:17 PM12/16/09
to wxpytho...@googlegroups.com
On 12/15/09 9:31 PM, King wrote:
> This is related to Cairo and double buffer example at here:
> http://wiki.wxpython.org/DoubleBufferedDrawing
>
> Replace the "draw" function with this
>
> def Draw(self, dc):
> dc.SetBackground( wx.Brush("White") )
> dc.Clear() # make sure you clear the bitmap!
>
> # Set global scale and translation
> dc.SetUserScale(1.5, 1.5)
> dc.SetDeviceOrigin(50, 50)
> # now draw something with cairo
> ctx = Cr.GraphicsContext.Create(dc) # wx.GCDC(dc) # This
> works!!!
> ctx.SetBrush(wx.Brush("blue"))
> ctx.DrawEllipse(0,0,100,50)
> # Reset global scale and translation
> dc.SetUserScale(1, 1)
> dc.SetDeviceOrigin(0, 0)
>
> Just before rendering on cairo I am setting up global scale/zoom and
> translation. Ellipse is rendered as it has been scaled as bitmap not a
> proper scaled shape.

Use the GC's Scale and Translate methods instead of the DC methods.


--
Robin Dunn
Software Craftsman
http://wxPython.org

Reply all
Reply to author
Forward
0 new messages