Added line primitive
parent
10b0e1811e
commit
75c01f7d9e
|
|
@ -65,8 +65,8 @@ module Squib
|
||||||
# @option opts y2 [Integer] (50) the y-coordinate to place
|
# @option opts y2 [Integer] (50) the y-coordinate to place
|
||||||
# @option opts x3 [Integer] (0) the x-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 y3 [Integer] (50) the y-coordinate to place
|
||||||
# @option opts fill_color [String] ('#0000') the color with which to fill 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 rectangle
|
# @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
|
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
|
||||||
# @return [nil] intended to be void
|
# @return [nil] intended to be void
|
||||||
# @api public
|
# @api public
|
||||||
|
|
@ -79,5 +79,28 @@ module Squib
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
@ -41,5 +41,16 @@ module Squib
|
||||||
cc.fill
|
cc.fill
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
@ -11,5 +11,9 @@ Squib::Deck.new do
|
||||||
x2: 150, y2: 150,
|
x2: 150, y2: 150,
|
||||||
x3: 75, y3: 250
|
x3: 75, y3: 250
|
||||||
|
|
||||||
|
line x1: 50, y1: 550,
|
||||||
|
x2: 150, y2: 650,
|
||||||
|
stroke_width: 25.0
|
||||||
|
|
||||||
save_png prefix: 'shape_'
|
save_png prefix: 'shape_'
|
||||||
end
|
end
|
||||||
Loading…
Reference in New Issue