Browse Source
Draw args also now requires custom_colors from Deck. (Can't trust caller to override the default.)dev
6 changed files with 94 additions and 19 deletions
@ -0,0 +1,44 @@ |
|||||||
|
require 'cairo' |
||||||
|
require 'squib/args/arg_loader' |
||||||
|
require 'squib/args/color_validator' |
||||||
|
|
||||||
|
module Squib |
||||||
|
# @api private |
||||||
|
module Args |
||||||
|
class Paint |
||||||
|
include ArgLoader |
||||||
|
include ColorValidator |
||||||
|
|
||||||
|
def self.parameters |
||||||
|
{ alpha: 1.0, |
||||||
|
blend: :none, |
||||||
|
mask: nil, |
||||||
|
} |
||||||
|
end |
||||||
|
|
||||||
|
|
||||||
|
def self.expanding_parameters |
||||||
|
parameters.keys # all of them are expandable |
||||||
|
end |
||||||
|
|
||||||
|
def self.params_with_units |
||||||
|
[] |
||||||
|
end |
||||||
|
|
||||||
|
def initialize(custom_colors) |
||||||
|
@custom_colors = custom_colors |
||||||
|
end |
||||||
|
|
||||||
|
def validate_alpha(arg, _i) |
||||||
|
raise 'alpha must respond to to_f' unless arg.respond_to? :to_f |
||||||
|
arg.to_f |
||||||
|
end |
||||||
|
|
||||||
|
def validate_mask(arg, _i) |
||||||
|
colorify(arg, @custom_colors) |
||||||
|
end |
||||||
|
|
||||||
|
|
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
require 'spec_helper' |
||||||
|
require 'squib/args/paint' |
||||||
|
|
||||||
|
describe Squib::Args::Draw do |
||||||
|
let(:custom_colors) { {'foo' => 'abc'} } |
||||||
|
subject(:paint) {Squib::Args::Paint.new(custom_colors)} |
||||||
|
|
||||||
|
context 'alpha' do |
||||||
|
|
||||||
|
it 'can be a float' do |
||||||
|
args = {alpha: 0.6} |
||||||
|
paint.load!(args) |
||||||
|
expect(paint.alpha).to eq [0.6] |
||||||
|
end |
||||||
|
|
||||||
|
it 'raises exception when not a float' do |
||||||
|
args = {alpha: /6/} |
||||||
|
expect { paint.load!(args) }.to raise_error('alpha must respond to to_f') |
||||||
|
end |
||||||
|
|
||||||
|
end |
||||||
|
end |
||||||
Loading…
Reference in new issue