Added line primitive
This commit is contained in:
+25
-2
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user