class Squib::Deck
The main interface to Squib
. Provides a front-end porcelain whereas the Card
class interacts with the graphics plumbing.
@api public
Some helper methods specifically for samples @api private
Attributes
Attributes for the width, height (in pixels) and number of cards These are expected to be immuatble for the life of Deck
@api private
Attributes for the width, height (in pixels) and number of cards These are expected to be immuatble for the life of Deck
@api private
Attributes for the width, height (in pixels) and number of cards These are expected to be immuatble for the life of Deck
@api private
Attributes for the width, height (in pixels) and number of cards These are expected to be immuatble for the life of Deck
@api private
Public Instance Methods
# File lib/squib/dsl/background.rb, line 5 def background(opts = {}) DSL::Background.new(self, __callee__).run(opts) end
DSL
method. See squib.readthedocs.io
# File lib/squib/dsl/groups.rb, line 23 def build grp = :all, &block raise 'Please provide a block' unless block_given? block.yield if build_groups.include? grp end
DSL
method. See squib.readthedocs.io
# File lib/squib/dsl/groups.rb, line 41 def build_groups @build_groups ||= Set.new.add(:all) end
DSL
method. See squib.readthedocs.io
# File lib/squib/dsl/units.rb, line 32 def cells(n) n.to_f * @cell_px end
# File lib/squib/dsl/circle.rb, line 8 def circle(opts = {}) DSL::Circle.new(self, __callee__).run(opts) end
DSL
method. See squib.readthedocs.io
# File lib/squib/dsl/units.rb, line 17 def cm(n) @dpi * Squib::INCHES_IN_CM * n.to_f end
DSL
method. See squib.readthedocs.io
# File lib/squib/dsl/csv.rb, line 15 def csv(opts = {}, &block) DSL::Csv.new(__callee__).run(opts, &block) end
# File lib/squib/dsl/curve.rb, line 5 def curve(opts = {}) DSL::Curve.new(self, __callee__).run(opts) end
# File lib/squib/dsl/cut_zone.rb, line 5 def cut_zone(opts = {}) DSL::CutZone.new(self, __callee__).run(opts) end
DSL
method. See squib.readthedocs.io
# File lib/squib/dsl/units.rb, line 27 def deg(n) n.to_f * (Math::PI / 180.0) end
DSL
method. See squib.readthedocs.io
# File lib/squib/dsl/groups.rb, line 35 def disable_build grp build_groups # make sure it's initialized @build_groups.delete grp end
Draw graph paper for samples
# File lib/squib/sample_helpers.rb, line 9 def draw_graph_paper(width, height) background color: 'white' grid width: 50, height: 50, stroke_color: '#659ae9', stroke_width: 1.5 grid width: 200, height: 200, stroke_color: '#659ae9', stroke_width: 3, x: 50, y: 50 (50..height).step(200) do |y| text str: "y=#{y}", x: 3, y: y - 18, font: 'Open Sans, Sans 10' end end
# File lib/squib/dsl/ellipse.rb, line 5 def ellipse(opts = {}) DSL::Ellipse.new(self, __callee__).run(opts) end
DSL
method. See squib.readthedocs.io
# File lib/squib/dsl/groups.rb, line 29 def enable_build grp build_groups # make sure it's initialized @build_groups << grp end
Not a DSL
method, but initialized from Deck.new
# File lib/squib/dsl/groups.rb, line 46 def enable_groups_from_env! return if ENV['SQUIB_BUILD'].nil? ENV['SQUIB_BUILD'].split(',').each do |grp| enable_build grp.strip.to_sym end end
# File lib/squib/dsl/grid.rb, line 5 def grid(opts = {}) DSL::Grid.new(self, __callee__).run(opts) end
# File lib/squib/dsl/hand.rb, line 9 def hand(opts = {}) DSL::Hand.new(self, __callee__).run(opts) end
DSL
method. See squib.readthedocs.io
# File lib/squib/api/settings.rb, line 5 def hint(text: :off) conf.text_hint = text end
DSL
method. See squib.readthedocs.io
# File lib/squib/dsl/units.rb, line 7 def inches(n) @dpi * n.to_f end
# File lib/squib/dsl/line.rb, line 5 def line(opts = {}) DSL::Line.new(self, __callee__).run(opts) end
DSL
method. See squib.readthedocs.io
# File lib/squib/dsl/units.rb, line 22 def mm(n) @dpi * Squib::INCHES_IN_CM * n.to_f / 10.0 end
# File lib/squib/dsl/png.rb, line 10 def png(opts = {}) DSL::PNG.new(self, __callee__).run(opts) end
DSL
method. See squib.readthedocs.io
# File lib/squib/dsl/units.rb, line 12 def points(n) @dpi / Squib::POINTS_PER_IN * n.to_f end
# File lib/squib/dsl/polygon.rb, line 5 def polygon(opts = {}) DSL::Polygon.new(self, __callee__).run(opts) end
# File lib/squib/dsl/rect.rb, line 5 def rect(opts = {}) DSL::Rect.new(self, __callee__).run(opts) end
Draw cards in a fan. @api private
# File lib/squib/graphics/hand.rb, line 8 def render_hand(range, sheet, hand) cards = range.collect { |i| @cards[i] } center_x = width / 2.0 center_y = hand.radius + height out_size = 3.0 * center_y angle_delta = (hand.angle_range.last - hand.angle_range.first) / cards.size cxt = Cairo::Context.new(Cairo::RecordingSurface.new(0, 0, out_size, out_size)) cxt.translate(out_size / 2.0, out_size / 2.0) cxt.rotate(hand.angle_range.first) cxt.translate(-width, -width) cards.each_with_index do |card, i| cxt.translate(center_x, center_y) cxt.rotate(angle_delta) cxt.translate(-center_x, -center_y) card.use_cairo do |card_cxt| cxt.rounded_rectangle(sheet.trim, sheet.trim, width - (2 * sheet.trim), height - (2 * sheet.trim), sheet.trim_radius, sheet.trim_radius) cxt.clip cxt.set_source(card_cxt.target) cxt.paint cxt.reset_clip end end x, y, w, h = cxt.target.ink_extents # I love Ruby assignment ;) png_cxt = Squib::Graphics::CairoContextWrapper.new(Cairo::Context.new(Cairo::ImageSurface.new(w + 2 * sheet.margin, h + 2 * sheet.margin))) png_cxt.set_source_squibcolor(sheet.fill_color) png_cxt.paint png_cxt.translate(-x + sheet.margin, -y + sheet.margin) png_cxt.set_source(cxt.target) png_cxt.paint png_cxt.target.write_to_png sheet.full_filename end
# File lib/squib/dsl/safe_zone.rb, line 5 def safe_zone(opts = {}) DSL::SafeZone.new(self, __callee__).run(opts) end
Define a set of samples on some graph paper
# File lib/squib/sample_helpers.rb, line 19 def sample(str) @sample_x ||= 100 @sample_y ||= 100 rect x: 460, y: @sample_y - 40, width: 600, height: 180, fill_color: '#FFD655', stroke_color: 'black', radius: 15 text str: str, x: 460, y: @sample_y - 40, width: 540, height: 180, valign: 'middle', align: 'center', font: 'Times New Roman,Serif 8' yield @sample_x, @sample_y @sample_y += 200 end
# File lib/squib/dsl/save.rb, line 8 def save(opts = {}) fmts = Array(opts[:format]) warn 'Must specify format :png and/or :pdf' if fmts.empty? opts.delete :format # not needed anymore save_png(opts) if fmts.include? :png save_pdf(opts) if fmts.include? :pdf uns = fmts - [:pdf, :png ] unless uns.empty? warn "Unsupported format(s) #{uns} to #{'save'.cyan}()", uplevel: 1 end self end
# File lib/squib/dsl/save_pdf.rb, line 8 def save_pdf(opts = {}) DSL::SavePDF.new(self, __callee__).run(opts) end
# File lib/squib/dsl/save_png.rb, line 8 def save_png(opts = {}) DSL::SavePNG.new(self, __callee__).run(opts) end
# File lib/squib/dsl/save_sheet.rb, line 13 def save_sheet(opts = {}) DSL::SaveSheet.new(self, __callee__).run(opts) end
DSL
method. See squib.readthedocs.io
# File lib/squib/api/settings.rb, line 10 def set(opts = {}) raise 'DEPRECATED: As of v0.7 img_dir is no longer supported in "set". Use config.yml instead.' if opts.key? :img_dir @font = (opts[:font] == :default) ? Squib::DEFAULT_FONT : opts[:font] end
# File lib/squib/dsl/showcase.rb, line 8 def showcase(opts = {}) DSL::Showcase.new(self, __callee__).run(opts) end
# File lib/squib/dsl/star.rb, line 5 def star(opts = {}) DSL::Star.new(self, __callee__).run(opts) end
# File lib/squib/dsl/svg.rb, line 11 def svg(opts = {}) DSL::SVG.new(self, __callee__).run(opts) end
# File lib/squib/dsl/text.rb, line 11 def text(opts = {}) embed = TextEmbed.new self, __callee__ yield(embed) if block_given? # store the opts for later use DSL::Text.new(self, __callee__, embed).run(opts) end
# File lib/squib/dsl/triangle.rb, line 5 def triangle(opts = {}) DSL::Triangle.new(self, __callee__).run(opts) end
DSL
method. See squib.readthedocs.io
# File lib/squib/api/settings.rb, line 16 def use_layout(file: 'layout.yml') @layout = LayoutParser.new(@dpi).load_layout(file, @layout) end
DSL
method. See squib.readthedocs.io
# File lib/squib/dsl/xlsx.rb, line 14 def xlsx(opts = {}, &block) DSL::Xlsx.new(__callee__).run(opts, &block) end
DSL
method. See squib.readthedocs.io
# File lib/squib/dsl/yaml.rb, line 14 def yaml(opts = {}, &block) DSL::Yaml.new(__callee__).run(opts, &block) end