diff --git a/lib/squib/api/shapes.rb b/lib/squib/api/shapes.rb index aa94988..e3044eb 100644 --- a/lib/squib/api/shapes.rb +++ b/lib/squib/api/shapes.rb @@ -65,8 +65,8 @@ module Squib # @option opts y2 [Integer] (50) the y-coordinate to place # @option opts x3 [Integer] (0) the x-coordinate to place # @option opts y3 [Integer] (50) the y-coordinate to place - # @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 fill_color [String] ('#0000') the color with which to fill the triangle + # @option opts stroke_color [String] (:black) the color with which to stroke the outside of the triangle # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke # @return [nil] intended to be void # @api public @@ -78,6 +78,29 @@ module Squib opts[:fill_color], opts[:stroke_color], opts[:stroke_width]) end end + + # Draw a line using the given coordinates + # + # @example + # triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50 + # + # @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 x1 [Integer] (0) the x-coordinate to place + # @option opts y1 [Integer] (0) the y-coordinate to place + # @option opts x2 [Integer] (50) the x-coordinate to place + # @option opts y2 [Integer] (50) the y-coordinate to place + # @option opts stroke_color [String] (:black) the color with which to stroke the line + # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke + # @return [nil] intended to be void + # @api public + def line(opts = {}) + opts = needs(opts, [:range, :x1, :y1, :x2, :y2, :layout, + :stroke_color, :stroke_width]) + opts[:range].each do |i| + @cards[i].line(opts[:x1], opts[:y1], opts[:x2], opts[:y2], + 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 5054f5f..95a7753 100644 --- a/lib/squib/graphics/shapes.rb +++ b/lib/squib/graphics/shapes.rb @@ -40,6 +40,17 @@ module Squib cc.set_source_color(fill_color) cc.fill end + + # :nodoc: + # @api private + def line(x1, y1, x2, y2, stroke_color, stroke_width) + cc = cairo_context + cc.move_to(x1, y1) + cc.line_to(x2, y2) + cc.set_source_color(stroke_color) + cc.set_line_width(stroke_width) + cc.stroke + end end end \ No newline at end of file diff --git a/samples/draw_shapes.rb b/samples/draw_shapes.rb index d19510e..2fdfa3e 100644 --- a/samples/draw_shapes.rb +++ b/samples/draw_shapes.rb @@ -11,5 +11,9 @@ Squib::Deck.new do x2: 150, y2: 150, x3: 75, y3: 250 + line x1: 50, y1: 550, + x2: 150, y2: 650, + stroke_width: 25.0 + save_png prefix: 'shape_' end \ No newline at end of file