Browse Source

Added circle shape

dev
Andy Meneely 12 years ago
parent
commit
e4d1900965
  1. 25
      lib/squib/api/shapes.rb
  2. 15
      lib/squib/graphics/shapes.rb

25
lib/squib/api/shapes.rb

@ -6,6 +6,7 @@ module Squib
# @example # @example
# rect x: 0, y: 0, width: 825, height: 1125, radius: 25 # rect x: 0, y: 0, width: 825, height: 1125, radius: 25
# #
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
# @option opts x [Integer] (0) the x-coordinate to place # @option opts x [Integer] (0) the x-coordinate to place
# @option opts y [Integer] (0) the y-coordinate to place # @option opts y [Integer] (0) the y-coordinate to place
# @option opts width [Integer] the width of the rectangle. # @option opts width [Integer] the width of the rectangle.
@ -27,6 +28,30 @@ module Squib
opts[:fill_color], opts[:stroke_color], opts[:stroke_width]) opts[:fill_color], opts[:stroke_color], opts[:stroke_width])
end end
end end
# Draw a circle centered at the given coordinates
#
# @example
# circle x: 0, y: 0, radius: 100
#
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
# @option opts x [Integer] (0) the x-coordinate to place
# @option opts y [Integer] (0) the y-coordinate to place
# @option opts radius [Integer] (100) radius of the circle
# @option opts fill_color [String] ('#0000') the color with which to fill the rectangle
# @option opts stroke_color [String] (:black) the color with which to stroke the outside of the rectangle
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
# @return [nil] intended to be void
# @api public
def circle(opts = {})
opts = {radius: 100}.merge(opts)
opts = needs(opts, [:range, :x, :y, :circle_radius, :layout,
:fill_color, :stroke_color, :stroke_width])
opts[:range].each do |i|
@cards[i].circle(opts[:x], opts[:y], opts[:radius],
opts[:fill_color], opts[:stroke_color], opts[:stroke_width])
end
end
end end
end end

15
lib/squib/graphics/shapes.rb

@ -8,12 +8,25 @@ module Squib
cc = cairo_context cc = cairo_context
cc.rounded_rectangle(x, y, width, height, x_radius, y_radius) cc.rounded_rectangle(x, y, width, height, x_radius, y_radius)
cc.set_source_color(stroke_color) cc.set_source_color(stroke_color)
cc.set_line_width(stroke_width); cc.set_line_width(stroke_width)
cc.stroke cc.stroke
cc.rounded_rectangle(x, y, width, height, x_radius, y_radius) cc.rounded_rectangle(x, y, width, height, x_radius, y_radius)
cc.set_source_color(fill_color) cc.set_source_color(fill_color)
cc.fill cc.fill
end end
# :nodoc:
# @api private
def circle(x, y, radius, fill_color, stroke_color, stroke_width)
cc = cairo_context
cc.circle(x, y, radius)
cc.set_source_color(stroke_color)
cc.set_line_width(stroke_width)
cc.stroke
cc.circle(x, y, radius)
cc.set_source_color(fill_color)
cc.fill
end
end end
end end
Loading…
Cancel
Save