Convert hand method to args classes
parent
697a51d8e5
commit
4d1661ac0b
|
|
@ -1,4 +1,5 @@
|
||||||
require 'squib/args/card_range'
|
require 'squib/args/card_range'
|
||||||
|
require 'squib/args/hand_special'
|
||||||
require 'squib/args/save_batch'
|
require 'squib/args/save_batch'
|
||||||
require 'squib/args/sheet'
|
require 'squib/args/sheet'
|
||||||
require 'squib/args/showcase_special'
|
require 'squib/args/showcase_special'
|
||||||
|
|
@ -138,13 +139,15 @@ module Squib
|
||||||
# @return [nil] Returns nothing.
|
# @return [nil] Returns nothing.
|
||||||
# @api public
|
# @api public
|
||||||
def hand(opts = {})
|
def hand(opts = {})
|
||||||
|
range = Args::CardRange.new(opts[:range], deck_size: size)
|
||||||
|
hand = Args::HandSpecial.new(height).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||||
|
sheet = Args::Sheet.new(custom_colors, {file: 'hand.png', trim_radius: 0}).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||||
|
|
||||||
opts = {file: 'hand.png', fill_color: :white, radius: :auto, trim_radius: 0}
|
opts = {file: 'hand.png', fill_color: :white, radius: :auto, trim_radius: 0}
|
||||||
.merge(opts)
|
.merge(opts)
|
||||||
opts = needs(opts,[:range, :margin, :trim, :trim_radius, :creatable_dir, :file_to_save])
|
opts = needs(opts,[:range, :margin, :trim, :trim_radius, :creatable_dir, :file_to_save])
|
||||||
opts[:radius] = 0.3 * height if opts[:radius] == :auto
|
opts[:radius] = 0.3 * height if opts[:radius] == :auto
|
||||||
render_hand(opts[:range], opts[:radius], opts[:angle_range],
|
render_hand(range, sheet, hand)
|
||||||
opts[:trim], opts[:trim_radius], opts[:margin],
|
|
||||||
opts[:fill_color], opts[:dir], opts[:file])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
require 'cairo'
|
||||||
|
|
||||||
|
module Squib
|
||||||
|
# @api private
|
||||||
|
module Args
|
||||||
|
|
||||||
|
class HandSpecial
|
||||||
|
include ArgLoader
|
||||||
|
|
||||||
|
def initialize(card_height)
|
||||||
|
@card_height = card_height
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.parameters
|
||||||
|
{
|
||||||
|
angle_range: (Math::PI / -4.0)..(Math::PI / 4),
|
||||||
|
radius: :auto
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.expanding_parameters
|
||||||
|
[] # none of them
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.params_with_units
|
||||||
|
[ :radius ]
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_radius(arg)
|
||||||
|
return 0.3 * @card_height if arg.to_s.downcase.strip == 'auto'
|
||||||
|
arg
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -62,6 +62,10 @@ module Squib
|
||||||
(@deck_size.to_i / columns.to_i).ceil
|
(@deck_size.to_i / columns.to_i).ceil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def full_filename
|
||||||
|
"#{dir}/#{file}"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
require 'cairo'
|
require 'cairo'
|
||||||
require 'squib/args/arg_loader'
|
require 'squib/args/arg_loader'
|
||||||
|
require 'squib/args/dir_validator'
|
||||||
|
|
||||||
module Squib
|
module Squib
|
||||||
# @api private
|
# @api private
|
||||||
|
|
|
||||||
|
|
@ -5,25 +5,24 @@ module Squib
|
||||||
|
|
||||||
# Draw cards in a fan.
|
# Draw cards in a fan.
|
||||||
# @api private
|
# @api private
|
||||||
def render_hand(range, radius, angle_range, trim, trim_radius, margin,
|
def render_hand(range, sheet, hand)
|
||||||
fill_color, dir, file)
|
|
||||||
cards = range.collect { |i| @cards[i] }
|
cards = range.collect { |i| @cards[i] }
|
||||||
center_x = width / 2.0
|
center_x = width / 2.0
|
||||||
center_y = radius + height
|
center_y = hand.radius + height
|
||||||
out_size = 3.0 * center_y
|
out_size = 3.0 * center_y
|
||||||
angle_delta = (angle_range.last - angle_range.first) / cards.size
|
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 = Cairo::Context.new(Cairo::RecordingSurface.new(0, 0, out_size, out_size))
|
||||||
cxt.translate(out_size / 2.0, out_size / 2.0)
|
cxt.translate(out_size / 2.0, out_size / 2.0)
|
||||||
cxt.rotate(angle_range.first)
|
cxt.rotate(hand.angle_range.first)
|
||||||
cxt.translate(-width, -width)
|
cxt.translate(-width, -width)
|
||||||
cards.each_with_index do |card, i|
|
cards.each_with_index do |card, i|
|
||||||
cxt.translate(center_x, center_y)
|
cxt.translate(center_x, center_y)
|
||||||
cxt.rotate(angle_delta)
|
cxt.rotate(angle_delta)
|
||||||
cxt.translate(-center_x, -center_y)
|
cxt.translate(-center_x, -center_y)
|
||||||
card.use_cairo do |card_cxt|
|
card.use_cairo do |card_cxt|
|
||||||
cxt.rounded_rectangle(trim, trim,
|
cxt.rounded_rectangle(sheet.trim, sheet.trim,
|
||||||
width - (2 * trim), height - (2 * trim),
|
width - (2 * sheet.trim), height - (2 * sheet.trim),
|
||||||
trim_radius, trim_radius)
|
sheet.trim_radius, sheet.trim_radius)
|
||||||
cxt.clip
|
cxt.clip
|
||||||
cxt.set_source(card_cxt.target)
|
cxt.set_source(card_cxt.target)
|
||||||
cxt.paint
|
cxt.paint
|
||||||
|
|
@ -31,13 +30,13 @@ module Squib
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
x, y, w, h = cxt.target.ink_extents # I love Ruby assignment ;)
|
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 = Squib::Graphics::CairoContextWrapper.new(Cairo::Context.new(Cairo::ImageSurface.new(w + 2*sheet.margin, h + 2*sheet.margin)))
|
||||||
png_cxt.set_source_squibcolor(fill_color)
|
png_cxt.set_source_squibcolor(sheet.fill_color)
|
||||||
png_cxt.paint
|
png_cxt.paint
|
||||||
png_cxt.translate(-x + margin, -y + margin)
|
png_cxt.translate(-x + sheet.margin, -y + sheet.margin)
|
||||||
png_cxt.set_source(cxt.target)
|
png_cxt.set_source(cxt.target)
|
||||||
png_cxt.paint
|
png_cxt.paint
|
||||||
png_cxt.target.write_to_png("#{dir}/#{file}")
|
png_cxt.target.write_to_png sheet.full_filename
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -441,7 +441,7 @@ cairo: set_source([MockDouble])
|
||||||
cairo: paint([])
|
cairo: paint([])
|
||||||
cairo: reset_clip([])
|
cairo: reset_clip([])
|
||||||
cairo: restore([])
|
cairo: restore([])
|
||||||
cairo: set_source_color([:white])
|
cairo: set_source_color(["white"])
|
||||||
cairo: paint([])
|
cairo: paint([])
|
||||||
cairo: translate([75, 75])
|
cairo: translate([75, 75])
|
||||||
cairo: set_source([MockDouble])
|
cairo: set_source([MockDouble])
|
||||||
|
|
@ -530,7 +530,7 @@ cairo: set_source([MockDouble])
|
||||||
cairo: paint([])
|
cairo: paint([])
|
||||||
cairo: reset_clip([])
|
cairo: reset_clip([])
|
||||||
cairo: restore([])
|
cairo: restore([])
|
||||||
cairo: set_source_color([:white])
|
cairo: set_source_color(["white"])
|
||||||
cairo: paint([])
|
cairo: paint([])
|
||||||
cairo: translate([75, 75])
|
cairo: translate([75, 75])
|
||||||
cairo: set_source([MockDouble])
|
cairo: set_source([MockDouble])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue