File: cairo-image.rb

package info (click to toggle)
ruby-gnome2 0.15.0-1.1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 7,704 kB
  • ctags: 8,558
  • sloc: ansic: 69,912; ruby: 19,511; makefile: 97; xml: 35; sql: 13
file content (49 lines) | stat: -rw-r--r-- 1,282 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright (c) 2005 Ruby-GNOME2 Project Team
# This program is licenced under the same licence as Ruby-GNOME2.
#
# $Id: cairo-image.rb,v 1.2 2005/10/16 12:07:32 mutoh Exp $
=begin
= cairo/Image

This demo shows how to use GDK and cairo to show image.
From http://cairographics.org/samples/image.html.
=end
require 'common'

module Demo
  class CairoImage < CairoWindow
    def initialize
      super('cairo gradient')
    end

    def draw(cr)
      cr.save do
        loader = Gdk::PixbufLoader.new
        File.open("background.jpg", "rb") do |f|
          loader.last_write(f.read)
        end
        pixbuf = loader.pixbuf
        
        cr.translate(0.5, 0.5)
        cr.rotate(45 * Math::PI / 180)
        cr.scale(1.0 / pixbuf.width, 1.0 / pixbuf.height)
        cr.translate(-0.5 * pixbuf.width, -0.5 * pixbuf.height)
        
        cr.set_source_pixbuf(pixbuf, 0, 0)
        cr.paint
      end

      cr.save do
        image = Cairo::ImageSurface.from_png("ruby-gnome2-logo.png")
        
        cr.translate(0.5, 0.5)
        cr.rotate(60 * Math::PI / 180)
        cr.scale(0.8 / image.width, 0.8 / image.height)
        cr.translate(-0.5 * image.width, -0.5 * image.height)
        
        cr.set_source(image, 0, 0)
        cr.paint
      end
    end
  end
end