Adding custom colors to the draw arg
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user