Adding custom colors to the draw arg

This commit is contained in:
Andy Meneely
2015-07-03 00:47:46 -04:00
parent f16f285a0a
commit 6aecdbbb4a
20 changed files with 188 additions and 142 deletions
+3 -2
View File
@@ -11,8 +11,9 @@ module Squib
# @return [nil] nothing
# @api public
def background(opts = {})
opts = needs(opts,[:range, :color])
opts[:range].each { |i| @cards[i].background(opts[:color][i]) }
range = Args::CardRange.new(opts[:range], deck_size: size)
draw = Args::Draw.new(custom_colors).load!(opts, expand_by: size, layout: layout, dpi: dpi)
range.each { |i| @cards[i].background(draw.color[i]) }
end
end
+12
View File
@@ -0,0 +1,12 @@
module Squib
#@api private
module Args
module ColorValidator
def colorify(color, custom_colors = {})
custom_colors[color.to_s] || color.to_s
end
end
end
end
+20 -1
View File
@@ -1,5 +1,6 @@
require 'cairo'
require 'squib/args/arg_loader'
require 'squib/args/color_validator'
module Squib
# @api private
@@ -7,9 +8,15 @@ module Squib
class Draw
include ArgLoader
include ColorValidator
def initialize(custom_colors = {})
@custom_colors = custom_colors
end
def self.parameters
{ fill_color: '#0000',
{ color: :black,
fill_color: '#0000',
stroke_color: :black,
stroke_width: 2.0,
join: :miter,
@@ -54,6 +61,18 @@ module Squib
end
end
def validate_fill_color(arg, _i)
colorify(arg, @custom_colors)
end
def validate_stroke_color(arg, _i)
colorify(arg, @custom_colors)
end
def validate_color(arg, _i)
colorify(arg, @custom_colors)
end
end
end