Sha256: e996c6a1dd78ef09e9e73a82312b0c234e5918b0545e89bda5d18f9c32f884c1
Contents?: true
Size: 1.62 KB
Versions: 1
Compression:
Stored size: 1.62 KB
Contents
require 'squib/graphics/cairo_context_wrapper' module Squib class Deck # Draw cards in a fan. # @api private def render_hand(range, radius, angle_range, trim, trim_radius, margin, fill_color, dir, file) cards = range.collect { |i| @cards[i] } center_x = width / 2.0 center_y = radius + height out_size = 3.0 * center_y angle_delta = (angle_range.last - 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(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(trim, trim, width - (2 * trim), height - (2 * trim), trim_radius, 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*margin, h + 2*margin))) png_cxt.set_source_squibcolor(fill_color) png_cxt.paint png_cxt.translate(-x + margin, -y + margin) png_cxt.set_source(cxt.target) png_cxt.paint png_cxt.target.write_to_png("#{dir}/#{file}") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
squib-0.6.0 | lib/squib/graphics/hand.rb |