[cairo-commit] rcairo/tests spline,NONE,1.1 test-nox,NONE,1.1 text,NONE,1.1

Evan Martin commit at pdx.freedesktop.org
Tue Oct 28 10:27:24 PST 2003


Committed by: martine

Update of /cvs/cairo/rcairo/tests
In directory pdx:/tmp/cvs-serv31046/tests

Added Files:
	spline test-nox text 
Log Message:
Initial import of Ruby/Cairo.

I just moved the code around a bit in anticipation of wanting to do it later,
and I haven't tested if it broke anything yet, so don't be surprised if it
doesn't quite build yet.


--- NEW FILE: spline ---
#!/usr/bin/env ruby
# vim: set ts=2 sw=2 et :

require 'cairo'

class SplineWindow < Cairo::Xlib::Window
  def initialize(dpy)
    @width = @height = 400
    super(dpy, @width, @height, false)
  end

  def randx
    10 + rand(@width-20)
  end
  def randy
    10 + rand(@height-20)
  end

  def draw
    @cairo.set_rgb_color(1, 1, 1)
    @cairo.line_width = 2 + ((rand**2.0) * 50)
    @cairo.stroke {
      @cairo.move_to(randx, randy)
      @cairo.curve_to(randx, randy, randx, randy, randx, randy)
    }
  end

  def keypress(key)
    case key.chr
    when 'q'
      @dpy.quit
    end
  end
end

dpy = Cairo::Xlib::Display.new
sw = SplineWindow.new(dpy)
dpy.mainloop



--- NEW FILE: test-nox ---
#!/usr/bin/env ruby
# vim: set ts=2 sw=2 et :

require 'cairo'

puts <<EOT
A diagonal line, from top-left to bottom-right, looks like this:

EOT

img = Cairo::Image.new(0, 8, 8, 8*4)

cairo = Cairo::Cairo.new
cairo.target_image = img

# cairo.set_rgb_color(0, 0, 0)
# cairo.fill {
#   cairo.move_to(0, 0)
#   cairo.line_to(8, 0)
#   cairo.line_to(8, 8)
#   cairo.line_to(0, 8)
#   cairo.close_path
# }

cairo.set_rgb_color(1, 1, 1)
cairo.stroke {
  cairo.move_to(0, 0)
  cairo.line_to(8, 8)
}

lasty = 0
img.each_pixel { |x, y, p|
  (puts; puts) if y != lasty
  print ("%08x" % p) + " "
  lasty = y
}
puts; puts


--- NEW FILE: text ---
#!/usr/bin/env ruby
# vim: set ts=2 sw=2 et :

require 'cairo'

class TextWindow < Cairo::Xlib::Window
  def initialize(dpy)
    @text = ">"
    super(dpy, 400, 40, true)
  end
  def draw
    @cairo.set_rgb_color(0, 0, 0)
    @cairo.scale_font(20)
    @cairo.move_to(10, 30)
    @cairo.show_text(@text)
  end
  def keypress(key)
    case key.chr
    when 'q'
      @dpy.quit
    else
      @text << key.chr if key > 0
    end
  end
end

dpy = Cairo::Xlib::Display.new
w = TextWindow.new(dpy)
dpy.mainloop






More information about the cairo-commit mailing list