[cairo-commit] pycairo/examples/gtk cairo-knockout.py,1.6,1.7
Steve Chaplin
commit at pdx.freedesktop.org
Tue May 10 23:22:55 PDT 2005
Committed by: stevech1097
Update of /cvs/cairo/pycairo/examples/gtk
In directory gabe:/tmp/cvs-serv32284/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.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- cairo-knockout.py 9 May 2005 09:12:31 -0000 1.6
+++ cairo-knockout.py 11 May 2005 06:22:53 -0000 1.7
@@ -17,47 +17,26 @@
ctx.translate (xc, yc)
ctx.scale (1.0, yr / xr)
ctx.move_to (xr, 0.0)
- ctx.arc ( 0, 0,
- xr,
- 0, 2 * math.pi)
+ ctx.arc (0, 0, xr, 0, 2 * math.pi)
ctx.close_path ()
ctx.restore()
def fill_checks(ctx, x, y, width, height):
- # update to match testcairo.c
- ctx.save()
-
CHECK_SIZE = 32
- check = ctx.target.create_similar(cairo.FORMAT_RGB24,
- 2*CHECK_SIZE, 2*CHECK_SIZE)
- check.set_repeat(1)
-
- ctx.save()
- ctx.set_target_surface(check)
- ctx.set_operator(cairo.OPERATOR_SRC)
-
- ctx.set_source_rgb(0.4, 0.4, 0.4)
-
- ctx.rectangle(0, 0, 2*CHECK_SIZE, 2*CHECK_SIZE)
- ctx.fill()
-
- ctx.set_source_rgb(0.7, 0.7, 0.7)
-
- ctx.rectangle(x, y, CHECK_SIZE, CHECK_SIZE)
- ctx.fill()
- ctx.rectangle(x+CHECK_SIZE, y+CHECK_SIZE, CHECK_SIZE, CHECK_SIZE)
- ctx.fill()
- ctx.restore()
+ ctx.rectangle (x, y, width, height)
+ ctx.set_source_rgb (0.4, 0.4, 0.4)
+ ctx.fill ()
- check_pattern = cairo.Pattern.create_for_surface (check)
- ctx.set_source(check_pattern)
- ctx.rectangle(0, 0, width, height)
- ctx.fill()
+ # Only works for CHECK_SIZE a power of 2
+ for j in range (x & -CHECK_SIZE, height, CHECK_SIZE):
+ for i in range (y & -CHECK_SIZE, width, CHECK_SIZE):
+ if ((i / CHECK_SIZE + j / CHECK_SIZE) % 2 == 0):
+ ctx.rectangle (i, j, CHECK_SIZE, CHECK_SIZE)
- ctx.restore()
-
+ ctx.set_source_rgb (0.7, 0.7, 0.7)
+ ctx.fill ()
def draw_3circles(ctx, xc, yc, radius, alpha):
subradius = radius * (2 / 3. - 0.1)
@@ -83,7 +62,6 @@
subradius, subradius)
ctx.fill()
-
def draw (ctx, width, height):
radius = 0.5 * min(width, height) - 10
xc = width / 2.
@@ -95,44 +73,35 @@
fill_checks(ctx, 0, 0, width, height)
- ctx.save()
- ctx.set_target_surface(overlay)
-
# Draw a black circle on the overlay
- ctx.set_source_rgb(0, 0, 0)
- oval_path(ctx, xc, yc, radius, radius)
- ctx.fill()
-
- ctx.save()
- ctx.set_target_surface(punch)
+ overlay_cr = cairo.Context (overlay)
+ overlay_cr.set_source_rgb (0, 0, 0)
+ oval_path (overlay_cr, xc, yc, radius, radius)
+ overlay_cr.fill()
# Draw 3 circles to the punch surface, then cut
# that out of the main circle in the overlay
- draw_3circles(ctx, xc, yc, radius, 1.0)
-
- ctx.restore()
-
- ctx.set_operator(cairo.OPERATOR_OUT_REVERSE)
- ctx.set_source_surface (punch, 0, 0)
- ctx.paint()
-
- ctx.save()
+ punch_cr = cairo.Context (punch)
+ draw_3circles (punch_cr, xc, yc, radius, 1.0)
- ctx.set_target_surface(circles)
- ctx.set_operator(cairo.OPERATOR_OVER)
- draw_3circles(ctx, xc, yc, radius, 0.5)
-
- ctx.restore()
+ overlay_cr.set_operator (cairo.OPERATOR_DEST_OUT)
+ overlay_cr.set_source_surface (punch, 0, 0)
+ overlay_cr.paint()
- ctx.set_operator(cairo.OPERATOR_ADD)
- ctx.set_source_surface (circles, 0, 0)
- ctx.paint()
+ # Now draw the 3 circles in a subgroup again
+ # at half intensity, and use OperatorAdd to join up
+ # without seams.
+ circles_cr = cairo.Context (circles)
+
+ circles_cr.set_operator (cairo.OPERATOR_OVER)
+ draw_3circles (circles_cr, xc, yc, radius, 0.5)
- ctx.restore()
+ overlay_cr.set_operator (cairo.OPERATOR_ADD)
+ overlay_cr.set_source_surface (circles, 0, 0)
+ overlay_cr.paint()
ctx.set_source_surface (overlay, 0, 0)
ctx.paint()
-
def expose(drawingarea, event):
ctx = cairo.gtk.create_cairo_context(drawingarea.window)
@@ -141,7 +110,6 @@
return False
-
def main():
win = gtk.Window()
win.connect('destroy', gtk.main_quit)
More information about the cairo-commit
mailing list