class DYI::Painting
Painting
is used to specify how the drawing of the interior and the outline of the shape. {Shape::Base} objects (or objects of its subclass) have painting
attribute whose value is instance of this class. @since 0.0.0
Constants
- IMPLEMENT_ATTRIBUTES
@private
- VALID_VALUES
@private
Public Class Methods
Creates and returns a new instace of Paintng. If the argutment is a instance of Painting
, returns a copy of the argument. @option options [String] :display the value of attribute {#display display};
one of following values: <tt>"block"</tt>, <tt>"none"</tt>
@option options [Color, write_as] :fill the value of attribute {#fill fill} @option options [#to_f] :fill_opacity the value of attribute fill_opacity @option options [String] :fill_rule the value of attribute {#fill_rule
fill_rule}; one of following values: <tt>"nonzero"</tt>, <tt>"evenodd"</tt>
@option options [#to_f] :opacity the value of attribute {#opacity opacity} @option options [Color, write_as] :stroke the value of attribute {#stroke
stroke}
@option options [Array<Length>, String] :stroke_dasharray the value of
attribute {#stroke_dasharray stroke_dasharray}
@option options [Length] :stroke_dashoffset the value of attribute
{#stroke_dashoffset stroke_dashoffset}
@option options [String] :stroke_linecap the value of attribute
{#stroke_linecap stroke_linecap}; one of following values: <tt>"butt"</tt>, <tt>"round"</tt>, <tt>"square"</tt>
@option options [String] :stroke_linejoin the value of attribute
{#stroke_linejoin stroke_linejoin}; one of following values: <tt>"miter"</tt>, <tt>"round"</tt>, <tt>"bevel"</tt>
@option options [#to_f] :stroke_miterlimit the value of attribute
{#stroke_miterlimit stroke_miterlimit}
@option options [#to_f] :stroke_opacity the value of attribute
{#stroke_opacity stroke_opacity}
@option options [Length] :stroke_width the value of attribute
{#stroke_width stroke_width}
@option options [String] :visible the value of attribute {#visibility
visibility}; one of following values: <tt>"visible"</tt>, <tt>"hidden"</tt>
# File lib/dyi/painting.rb, line 142 def initialize(options={}) case options when Painting IMPLEMENT_ATTRIBUTES.each do |attr| instance_variable_set("@#{attr}", options.__send__(attr)) end when Hash options.each do |attr, value| __send__("#{attr}=", value) if IMPLEMENT_ATTRIBUTES.include?(attr.to_sym) end else raise TypeError, "#{options.class} can't be coerced into #{self.class}" end end
Returns a new instace of Painting
if the argments is not nil
(calls Painting.new
method), but returns nil
if the argument is nil
. @return [Painting, nil] a new instace of Painting
if the argments is not
nil, nil otherwise
@see initialize
# File lib/dyi/painting.rb, line 272 def new_or_nil(*args) (args.size == 1 && args.first.nil?) ? nil : new(*args) end
Public Instance Methods
Returns the hash of the attribute values. Even if the return value of this method is modified, the attribute value of the object is not modify. @return [Hash{Symbol => Object}] the copy of the attribute values
# File lib/dyi/painting.rb, line 246 def attributes IMPLEMENT_ATTRIBUTES.inject({}) do |hash, attr| value = instance_variable_get("@#{attr}") unless value.nil? hash[attr] = value end hash end end
# File lib/ironruby.rb, line 112 def cls_brush(shape) fill ? fill.create_cls_brush(fill_opacity, shape) : System::Drawing::SolidBrush.new(System::Drawing::Color.black) end
# File lib/ironruby.rb, line 93 def cls_dash_pattern return nil if !stroke_dasharray || stroke_dasharray.size == 0 pattern = System::Array[System::Single].new(stroke_dasharray.size) stroke_dasharray.each_with_index do |dash, i| pattern[i] = dash.to_f end pattern end
# File lib/ironruby.rb, line 85 def cls_fill_mode case fill_rule when 'nonzero' then System::Drawing::Drawing2D::FillMode.winding when 'evenodd' then System::Drawing::Drawing2D::FillMode.alternate else System::Drawing::Drawing2D::FillMode.winding end end
# File lib/ironruby.rb, line 76 def cls_line_cap case stroke_linecap when 'butt' then System::Drawing::Drawing2D::LineCap.flat when 'round' then System::Drawing::Drawing2D::LineCap.round when 'square' then System::Drawing::Drawing2D::LineCap.square else System::Drawing::Drawing2D::LineCap.flat end end
# File lib/ironruby.rb, line 67 def cls_line_join case stroke_linejoin when 'miter' then System::Drawing::Drawing2D::LineJoin.miter when 'round' then System::Drawing::Drawing2D::LineJoin.round when 'bevel' then System::Drawing::Drawing2D::LineJoin.bevel else System::Drawing::Drawing2D::LineJoin.miter end end
# File lib/ironruby.rb, line 102 def cls_pen return nil unless stroke && (stroke_width != DYI::Length::ZERO) pen = stroke.create_cls_pen(stroke_opacity) pen.width = stroke_width ? stroke_width.to_f : 1.0 pen.start_cap = pen.end_cap = cls_line_cap pen.line_join = cls_line_join pen.dash_pattern = cls_dash_pattern if cls_dash_pattern pen end
Returns whether a value has been set some attribute in this object. @return [Boolean] true if a value has been set some attribute in this
object, false otherwise
# File lib/dyi/painting.rb, line 259 def empty? IMPLEMENT_ATTRIBUTES.all? do |attr| not instance_variable_get("@#{attr}") end end
@attribute @param [Color, write_as] color the value of attribute fill
# File lib/dyi/painting.rb, line 184 def fill=(color) @fill = color.respond_to?(:color?) && color.color? ? color : Color.new_or_nil(color) end
@attribute @param [Float] opacity the value of attribute fill_opacity
# File lib/dyi/painting.rb, line 203 def fill_opacity=(opacity) @fill_opacity = opacity.nil? ? nil : opacity.to_f end
@attribute @param [Float] opacity the value of attribute opacity @since 1.0.0
# File lib/dyi/painting.rb, line 197 def opacity=(opacity) @opacity = opacity.nil? ? nil : opacity.to_f end
@attribute @param [Color, write_as] color the value of attribute stroke
# File lib/dyi/painting.rb, line 190 def stroke=(color) @stroke = color.respond_to?(:color?) && color.color? ? color : Color.new_or_nil(color) end
@attribute @param [Array<Legth>, String] array the value of attribute stroke_dasharray
# File lib/dyi/painting.rb, line 227 def stroke_dasharray=(array) if (array.nil? || array.empty?) @stroke_dasharray = nil elsif array.kind_of?(String) @stroke_dasharray = array.split(/\s*,\s*/).map {|len| Length.new(len)} else @stroke_dasharray = array.map {|len| Length.new(len)} end end
@attribute @param [Length] offset the value of attribute stroke_dashoffset
# File lib/dyi/painting.rb, line 239 def stroke_dashoffset=(offset) @stroke_dashoffset = Length.new_or_nil(offset) end
@attribute @param [Float] miterlimit the value of attribute stroke_miterlimit
# File lib/dyi/painting.rb, line 221 def stroke_miterlimit=(miterlimit) @stroke_miterlimit = miterlimit.nil? ? nil : [miterlimit.to_f, 1].max end
@attribute @param [Float] opacity the value of attribute stroke_opacity
# File lib/dyi/painting.rb, line 209 def stroke_opacity=(opacity) @stroke_opacity = opacity.nil? ? nil : opacity.to_f end
@attribute @param [Length] width the value of attribute stroke_width
# File lib/dyi/painting.rb, line 215 def stroke_width=(width) @stroke_width = Length.new_or_nil(width) end