Add ellipse method

Also experimenting with using stroke_preserve, which in turn may make the other methods less repetitive.

Closes #66
This commit is contained in:
Andy Meneely
2015-04-30 11:48:21 -04:00
parent 9b4eb7f00b
commit dab544a53b
8 changed files with 81 additions and 2 deletions
+28
View File
@@ -59,6 +59,34 @@ module Squib
end
end
# Draw an ellipse
#
# @example
# ellipse x: 0, y: 0, width: 825, height: 1125
#
# Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
#
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
# @option opts x [Integer] (0) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts y [Integer] (0) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts width [Integer] the width of the rectangle. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts height [Integer] the height of the rectangle. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts fill_color [String] ('#0000') the color with which to fill the rectangle. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}
# @option opts stroke_color [String] (:black) the color with which to stroke the outside of the rectangle. {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}
# @return [nil] intended to be void
# @api public
def ellipse(opts = {})
opts = needs(opts, [:range, :x, :y, :width, :height,
:fill_color, :stroke_color, :stroke_width, :layout])
opts[:range].each do |i|
@cards[i].ellipse(opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
opts[:fill_color][i], opts[:stroke_color][i],
opts[:stroke_width][i])
end
end
# Draw a triangle using the given coordinates
#
# @example
+2 -1
View File
@@ -22,7 +22,8 @@ module Squib
:show_pango_layout, :rounded_rectangle, :set_line_width, :stroke, :fill,
:set_source, :scale, :render_rsvg_handle, :circle, :triangle, :line_to,
:operator=, :show_page, :clip, :transform, :mask, :create_pango_layout,
:antialias=, :curve_to, :matrix, :matrix=, :identity_matrix, :pango_layout_path
:antialias=, :curve_to, :matrix, :matrix=, :identity_matrix, :pango_layout_path,
:stroke_preserve
# :nodoc:
# @api private
+28
View File
@@ -32,6 +32,34 @@ module Squib
end
end
# Ellipse drawing taken from looking at the control points in Inkscape
# Think of it like a rectangle. Curves go from mid-points of the sides
# of the rectangle. Control points are at 1/4 and 3/4 of the side.
# :nodoc:
# @api private
def ellipse(x, y, w, h, fill_color, stroke_color, stroke_width)
use_cairo do |cc|
cc.move_to(x, y + 0.5*h) # start west
cc.curve_to(x, y + 0.25*h, # west to north
x + 0.25*w, y,
x + 0.5*w, y)
cc.curve_to(x + 0.75*w, y, # north to east
x + w, y + 0.25*h,
x + w, y + 0.5*h)
cc.curve_to(x + w, y + 0.75*h, # east to south
x + 0.75*w, y + h,
x + 0.5*w, y + h)
cc.curve_to(x + 0.25*w, y + h, # south to west
x, y + 0.75*h,
x, y + 0.5*h)
cc.set_source_squibcolor(stroke_color)
cc.set_line_width(stroke_width)
cc.stroke_preserve
cc.set_source_squibcolor(fill_color)
cc.fill
end
end
# :nodoc:
# @api private
def triangle(x1, y1, x2, y2, x3, y3, fill_color, stroke_color, stroke_width)