Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2012-10-23 12:03:17 (GMT)
committer Manuel Kaufmann <humitos@gmail.com>2012-10-23 12:03:17 (GMT)
commitd85d992edb04a0e935ecf618fa957a03d30a1aa6 (patch)
tree01074e7fa93139baf3dd6725f80be507dde278ff
parentb9c29bc13b516b7e78aea86667a814b9d8ee9376 (diff)
Cairo example
-rw-r--r--examples/cairo_zoom_rotate.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/examples/cairo_zoom_rotate.py b/examples/cairo_zoom_rotate.py
new file mode 100644
index 0000000..ea3940d
--- /dev/null
+++ b/examples/cairo_zoom_rotate.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+
+import cairo
+import math
+
+from gi.repository import Gtk
+
+R_WIDTH = 150
+R_HEIGHT = 100
+
+S_WIDTH = 300
+S_HEIGHT = 250
+
+SCALE = 1.5
+
+
+class TestCairo(Gtk.DrawingArea):
+
+ def __init__(self):
+ super(TestCairo, self).__init__()
+
+ self.surface = None
+
+ self.connect('draw', self.__draw_cb)
+
+ def __draw_cb(self, widget, ctx):
+ print '__draw_cb'
+
+ if self.surface is None:
+ self.surface = ctx.get_target().create_similar(
+ cairo.CONTENT_COLOR_ALPHA, S_WIDTH, S_HEIGHT)
+ ctx_surface = cairo.Context(self.surface)
+ ctx_surface.set_source_rgba(1, 0, 0, 0.7)
+ ctx_surface.rectangle(0, 0, R_WIDTH, R_HEIGHT)
+ ctx_surface.fill()
+
+ ctx_surface.set_source_rgb(0, 0, 0)
+ ctx_surface.rectangle(0, 0, R_WIDTH, R_HEIGHT)
+ ctx_surface.stroke()
+ ctx_surface.set_line_width(5)
+ ctx_surface.rectangle(0, 0, S_WIDTH, S_HEIGHT)
+ ctx_surface.stroke()
+
+ # ROTATE 90
+ ctx.rotate(math.pi / 2)
+ ctx.translate(0, -R_HEIGHT * SCALE)
+
+ # ROTATE 180
+ # ctx.rotate(math.pi)
+ # ctx.translate(-R_WIDTH * SCALE, -R_HEIGHT * SCALE)
+
+ # ROTATE 270
+ # ctx.rotate(math.pi * 3 / 2)
+ # ctx.translate(-R_WIDTH * SCALE, 0)
+
+ # a little cirle at (10, 10)
+ ctx.set_source_rgba(0.3, 0.3, 0.3, 0.7)
+ ctx.arc(10, 10, 10, 0., 2 * math.pi)
+ ctx.fill()
+
+ ctx.scale(SCALE, SCALE)
+
+ ctx.set_source_surface(self.surface, 0, 0)
+ ctx.paint()
+
+
+def main():
+ window = Gtk.Window()
+ test_cairo = TestCairo()
+
+ window.add(test_cairo)
+ window.connect("destroy", Gtk.main_quit)
+ window.show_all()
+ window.set_size_request(S_WIDTH, S_HEIGHT)
+ # window.maximize()
+ Gtk.main()
+
+if __name__ == "__main__":
+ main()