Parent

Files

GD2::Canvas

Attributes

anti_aliasing[RW]
anti_aliasing?[RW]
brush[R]
color[R]
dont_blend[R]
font[RW]
style[R]
thickness[R]
tile[R]
transformation_matrix[R]

Public Class Methods

new(image) click to toggle source
# File lib/gd2/canvas.rb, line 229
def initialize(image)
  @image = image
  self.thickness = 1
  self.anti_aliasing = false
  @transformation_matrix = Matrix.identity(3)
  move_to(0, 0)
end

Public Instance Methods

affine_transform(a, b, c, d, tx, ty) click to toggle source
# File lib/gd2/canvas.rb, line 273
def affine_transform(a, b, c, d, tx, ty)
  old_matrix = @transformation_matrix
  begin
    @transformation_matrix = Matrix[[a, b, 0], [c, d, 0], [tx, ty, 1]] *
      @transformation_matrix
    yield
  ensure
    @transformation_matrix = old_matrix
  end
end
arc(cx, cy, width, height, range) click to toggle source
# File lib/gd2/canvas.rb, line 359
def arc(cx, cy, width, height, range)
  Arc.new(point(cx, cy), width, height, range).draw(@image, line_pixel)
end
brush=(image) click to toggle source
# File lib/gd2/canvas.rb, line 255
def brush=(image)
  if @brush = image
    SYM[:gdImageSetBrush].call(@image.image_ptr, image.image_ptr)
  end
end
cartesian(&block) click to toggle source
# File lib/gd2/canvas.rb, line 298
def cartesian(&block)
  affine_transform(1, 0, 0, -1, 0, @image.height - 1, &block)
end
circle(cx, cy, diameter, filled = false) click to toggle source
# File lib/gd2/canvas.rb, line 373
def circle(cx, cy, diameter, filled = false)
  ellipse(cx, cy, diameter, diameter, filled)
end
color=(color) click to toggle source
# File lib/gd2/canvas.rb, line 237
def color=(color)
  @pixel = @image.color2pixel(@color = color)
  @brush = @style = nil
end
dont_blend=(color) click to toggle source
# File lib/gd2/canvas.rb, line 269
def dont_blend=(color)
  @dont_blend = color ? @image.color2pixel(color) : nil
end
ellipse(cx, cy, width, height, filled = false) click to toggle source
# File lib/gd2/canvas.rb, line 368
def ellipse(cx, cy, width, height, filled = false)
  (filled ? FilledEllipse : Ellipse).new(point(cx, cy), width, height).
    draw(@image, filled ? fill_pixel : line_pixel)
end
fill() click to toggle source
# File lib/gd2/canvas.rb, line 333
def fill
  SYM[:gdImageFill].call(@image.image_ptr, @point.x, @point.y, fill_pixel)
  self
end
fill_to(border) click to toggle source
# File lib/gd2/canvas.rb, line 338
def fill_to(border)
  # An apparent bug in gd prevents us from using fill_pixel
  SYM[:gdImageFillToBorder].call(@image.image_ptr, @point.x, @point.y,
    @image.color2pixel(border), pixel)
  self
end
line(x1, y1, x2, y2) click to toggle source
# File lib/gd2/canvas.rb, line 322
def line(x1, y1, x2, y2)
  Line.new(point(x1, y1), point(x2, y2)).draw(@image, line_pixel)
end
line_to(x, y) click to toggle source
# File lib/gd2/canvas.rb, line 326
def line_to(x, y)
  point2 = point(x, y)
  Line.new(@point, point2).draw(@image, line_pixel)
  @point = point2
  self
end
location() click to toggle source
# File lib/gd2/canvas.rb, line 318
def location
  @point.transform(transformation_matrix.inverse).coordinates
end
move(x, y) click to toggle source
# File lib/gd2/canvas.rb, line 311
def move(x, y)
  @point.transform!(Matrix[[1, 0, 0], [0, 1, 0], [x, y, 1]] *
    @transformation_matrix)
  # @point = point(@point.x + x, @point.y + y)
  self
end
move_to(x, y) click to toggle source
# File lib/gd2/canvas.rb, line 306
def move_to(x, y)
  @point = point(x, y)
  self
end
point(x, y) click to toggle source
# File lib/gd2/canvas.rb, line 302
def point(x, y)
  Point.new(x, y).transform!(transformation_matrix)
end
polygon(points, filled = false, open = false) click to toggle source
# File lib/gd2/canvas.rb, line 350
def polygon(points, filled = false, open = false)
  points = points.map { |(x, y)| point(x, y) }
  if filled
    FilledPolygon.new(points).draw(@image, fill_pixel)
  else
    (open ? OpenPolygon : Polygon).new(points).draw(@image, line_pixel)
  end
end
rectangle(x1, y1, x2, y2, filled = false) click to toggle source
# File lib/gd2/canvas.rb, line 345
def rectangle(x1, y1, x2, y2, filled = false)
  (filled ? FilledRectangle : Rectangle).new(point(x1, y1), point(x2, y2)).
    draw(@image, filled ? fill_pixel : line_pixel)
end
rotate(angle, &block) click to toggle source
# File lib/gd2/canvas.rb, line 292
def rotate(angle, &block)
  cos = Math.cos(angle)
  sin = Math.sin(angle)
  affine_transform(cos, sin, -sin, cos, 0, 0, &block)
end
scale(sx, sy = sx, &block) click to toggle source
# File lib/gd2/canvas.rb, line 288
def scale(sx, sy = sx, &block)
  affine_transform(sx, 0, 0, sy, 0, 0, &block)
end
style=(ary) click to toggle source
# File lib/gd2/canvas.rb, line 246
def style=(ary)
  if @style = ary
    SYM[:gdImageSetStyle].call(@image.image_ptr,
      ary.map { |c|
        !c ? TRANSPARENT : true == c ? -1 : @image.color2pixel(c)
      }, ary.length)
  end
end
text(string, angle = 0.0) click to toggle source
# File lib/gd2/canvas.rb, line 377
def text(string, angle = 0.0)
  Text.new(get_font, @point, angle, string).draw(@image, pixel)
end
text_circle(top, bottom, radius, text_radius, fill_portion) click to toggle source
# File lib/gd2/canvas.rb, line 381
def text_circle(top, bottom, radius, text_radius, fill_portion)
  TextCircle.new(get_font, @point, radius, text_radius, fill_portion,
    top, bottom).draw(@image, pixel)
end
thickness=(thickness) click to toggle source
# File lib/gd2/canvas.rb, line 242
def thickness=(thickness)
  SYM[:gdImageSetThickness].call(@image.image_ptr, @thickness = thickness)
end
tile=(image) click to toggle source
# File lib/gd2/canvas.rb, line 261
def tile=(image)
  if @tile = image
    SYM[:gdImageSetTile].call(@image.image_ptr, image.image_ptr)
  end
end
translate(tx, ty, &block) click to toggle source
# File lib/gd2/canvas.rb, line 284
def translate(tx, ty, &block)
  affine_transform(1, 0, 0, 1, tx, ty, &block)
end
wedge(cx, cy, width, height, range, filled = false, chord = false) click to toggle source
# File lib/gd2/canvas.rb, line 363
def wedge(cx, cy, width, height, range, filled = false, chord = false)
  (filled ? FilledWedge : Wedge).new(point(cx, cy), width, height,
    range, chord).draw(@image, filled ? fill_pixel : line_pixel)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.