[cairo-commit] pycairo/examples/gtk cairo-knockout.py,1.5,1.6

Steve Chaplin commit at pdx.freedesktop.org
Mon May 9 02:12:33 PDT 2005


Committed by: stevech1097

Update of /cvs/cairo/pycairo/examples/gtk
In directory gabe:/tmp/cvs-serv16365/examples/gtk

Modified Files:
	cairo-knockout.py 
Log Message:
SC

Index: cairo-knockout.py
===================================================================
RCS file: /cvs/cairo/pycairo/examples/gtk/cairo-knockout.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cairo-knockout.py	9 May 2005 00:52:47 -0000	1.5
+++ cairo-knockout.py	9 May 2005 09:12:31 -0000	1.6
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-"""Based on cairo-demo/X11/cairo-knockout.c
+"""Based on gtk+/test/testcairo.c
 """
 
 from __future__ import division
@@ -12,7 +12,7 @@
 
 
 def oval_path(ctx, xc, yc, xr, yr):
-    matrix = cairo.Matrix ()
+    ctx.save()
 
     ctx.translate (xc, yc)
     ctx.scale (1.0, yr / xr)
@@ -22,14 +22,15 @@
                0, 2 * math.pi)
     ctx.close_path ()
 
-    ctx.set_matrix (matrix)
+    ctx.restore()
     
 def fill_checks(ctx, x, y, width, height):
+    # update to match testcairo.c
     ctx.save()
 
     CHECK_SIZE = 32
-    check = ctx.target_surface.create_similar(cairo.FORMAT_RGB24,
-                                              2*CHECK_SIZE, 2*CHECK_SIZE)
+    check = ctx.target.create_similar(cairo.FORMAT_RGB24,
+                                      2*CHECK_SIZE, 2*CHECK_SIZE)
     check.set_repeat(1)
 
     ctx.save()
@@ -82,21 +83,15 @@
               subradius, subradius)
     ctx.fill()
 
-def expose(drawingarea, event):
-    drawable = drawingarea.window
-    width  = drawingarea.allocation.width
-    height = drawingarea.allocation.height
 
+def draw (ctx, width, height):
     radius = 0.5 * min(width, height) - 10
     xc = width / 2.
     yc = height / 2.
-
-    ctx = cairo.gtk.create_cairo_context(drawable)
-    surface = ctx.target
-
-    overlay = surface.create_similar(cairo.FORMAT_ARGB32, width,height)
-    punch   = surface.create_similar(cairo.FORMAT_A8,     width,height)
-    circles = surface.create_similar(cairo.FORMAT_ARGB32, width,height)
+    
+    overlay = ctx.target.create_similar(cairo.FORMAT_ARGB32, width, height)
+    punch   = ctx.target.create_similar(cairo.FORMAT_A8,     width, height)
+    circles = ctx.target.create_similar(cairo.FORMAT_ARGB32, width, height)
 
     fill_checks(ctx, 0, 0, width, height)
 
@@ -120,7 +115,6 @@
     ctx.set_operator(cairo.OPERATOR_OUT_REVERSE)
     ctx.set_source_surface (punch, 0, 0)
     ctx.paint()
-    #ctx.show_surface(punch, width, height)
 
     ctx.save()
 
@@ -133,14 +127,21 @@
     ctx.set_operator(cairo.OPERATOR_ADD)
     ctx.set_source_surface (circles, 0, 0)
     ctx.paint()
-    #ctx.show_surface(circles, width, height)
 
     ctx.restore()
 
     ctx.set_source_surface (overlay, 0, 0)
     ctx.paint()
-    #ctx.show_surface(overlay, width, height)
+
     
+def expose(drawingarea, event):
+    ctx = cairo.gtk.create_cairo_context(drawingarea.window)
+
+    draw (ctx, drawingarea.allocation.width, drawingarea.allocation.height)
+                                         
+    return False
+
+
 def main():
     win = gtk.Window()
     win.connect('destroy', gtk.main_quit)




More information about the cairo-commit mailing list