From e4d19009658aac2fa31f18c6d7f07aafddaa8e8c Mon Sep 17 00:00:00 2001 From: Andy Meneely Date: Tue, 29 Jul 2014 14:58:22 -0400 Subject: [PATCH] Added circle shape --- lib/squib/api/shapes.rb | 25 +++++++++++++++++++++++++ lib/squib/graphics/shapes.rb | 15 ++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/squib/api/shapes.rb b/lib/squib/api/shapes.rb index f9d3cfc..b49b398 100644 --- a/lib/squib/api/shapes.rb +++ b/lib/squib/api/shapes.rb @@ -6,6 +6,7 @@ module Squib # @example # 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 y [Integer] (0) the y-coordinate to place # @option opts width [Integer] the width of the rectangle. @@ -27,6 +28,30 @@ module Squib opts[:fill_color], opts[:stroke_color], opts[:stroke_width]) 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 \ No newline at end of file diff --git a/lib/squib/graphics/shapes.rb b/lib/squib/graphics/shapes.rb index 2ed9227..73bb7d6 100644 --- a/lib/squib/graphics/shapes.rb +++ b/lib/squib/graphics/shapes.rb @@ -8,12 +8,25 @@ module Squib cc = cairo_context cc.rounded_rectangle(x, y, width, height, x_radius, y_radius) cc.set_source_color(stroke_color) - cc.set_line_width(stroke_width); + cc.set_line_width(stroke_width) cc.stroke cc.rounded_rectangle(x, y, width, height, x_radius, y_radius) cc.set_source_color(fill_color) cc.fill 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 \ No newline at end of file