class DYI::Shape::Base
Base
class of all graphical shapes. @abstract @since 0.0.0
Attributes
Returns a location of a reference of a source anchor for the link. @return [String] a location of a reference @since 1.0.0
Returns a relevant presentation context when the link is activated. @return [String] a relevant presentation context @since 1.0.0
Returns optional attributes of the shape. @return [Hash] optional attributes
Returns clipping status of the shape. @return [Drawing::Clipping] clipping status
Returns a parent element of the shape. @return [GraphicalElement] a parent element @since 1.0.0
Public Instance Methods
Adds animation to the shape @param [Animation::Base] animation a animation that the shape is run @since 1.0.0
# File lib/dyi/shape/base.rb, line 317 def add_animation(animation) animations << animation end
Adds animation of painting to the shape @option options [Painting] :from the starting painting of the animation @option options [Painting] :to the ending painting of the animation @option options [Number] :duration a simple duration in seconds @option options [Number] :begin_offset a offset that determine the
animation begin, in seconds
@option options [Event] :begin_event an event that determine the
animation begin
@option options [Number] :end_offset a offset that determine the
animation end, in seconds
@option options [Event] :end_event an event that determine the animation
end
@option options [String] :fill ‘freeze’ or ‘remove’ @since 1.0.0
# File lib/dyi/shape/base.rb, line 335 def add_painting_animation(options) add_animation(Animation::PaintingAnimation.new(self, options)) end
Adds animation of transform to the shape @param [Symbol] type a type of transformation which is to have values @option options [Number, Array] :from the starting transform of the
animation
@option options [Number, Array] :to the ending transform of the animation @option options [Number] :duration a simple duration in seconds @option options [Number] :begin_offset a offset that determine the
animation begin, in seconds
@option options [Event] :begin_event an event that determine the
animation begin
@option options [Number] :end_offset a offset that determine the
animation end, in seconds
@option options [Event] :end_event an event that determine the animation
end
@option options [String] :fill ‘freeze’ or ‘remove’ @since 1.0.0
# File lib/dyi/shape/base.rb, line 355 def add_transform_animation(type, options) add_animation(Animation::TransformAnimation.new(self, type, options)) end
Sets a location of a reference of a source anchor for the link. @param [String] href a location of a reference @since 1.0.0
# File lib/dyi/shape/base.rb, line 370 def anchor_href=(href) anchor_href = href.strip @anchor_href = anchor_href.empty? ? nil : anchor_href end
Returns whether the shape is animated. @return [Boolean] true if the shape is animated, false otherwise @since 1.0.0
# File lib/dyi/shape/base.rb, line 310 def animate? !(@animations.nil? || @animations.empty?) end
Returns registed animations. @return [Array<Animation::Base>] amination list. since 1.0.0
# File lib/dyi/shape/base.rb, line 303 def animations @animations ||= [] end
Crears clipping settings.
# File lib/dyi/shape/base.rb, line 281 def clear_clipping @clipping = nil end
Draws the shape on a parent element. @param [Element] parent a container element on which the shape is drawn @return [Shape::Base] itself @raise [ArgumentError] parent is nil @raise [RuntimeError] this shape already has a parent, or descendants of
this shape include itself
# File lib/dyi/shape/base.rb, line 155 def draw_on(parent) raise ArgumentError, "parent is nil" if parent.nil? return self if @parent == parent raise RuntimeError, "this shape already has a parent" if @parent current_node = parent loop do break if current_node.nil? || current_node.root_element? if current_node == self raise RuntimeError, "descendants of this shape include itself" end current_node = current_node.parent end (@parent = parent).child_elements.push(self) self end
Returns whether this shape has a marker symbol. @param [Symbol] position the position where a marker symbol is drawn.
Specifies the following values: +:start+, +:mid+, +:end+
@return [Boolean] always false
# File lib/dyi/shape/base.rb, line 296 def has_marker?(position) return false end
Returns whether the element has URI reference. @return [Boolean] true if the element has URI reference, false otherwise @since 1.0.0
# File lib/dyi/shape/base.rb, line 378 def has_uri_reference? @anchor_href ? true : false end
Returns whether this instance is root element of the shape. @return [Boolean] always false. @since 1.0.0
# File lib/dyi/shape/base.rb, line 182 def root_element? false end
@deprecated Use {#root_element?} instead.
# File lib/dyi/shape/base.rb, line 172 def root_node? msg = [__FILE__, __LINE__, ' waring'] msg << ' DYI::Shape::Base#root_node? is depricated; use DYI::Shape::Base#root_element?' warn(msg.join(':')) false end
Rotates this shape. @param [Numeric] angle rotation angle. specifies degree @param [Coordinate] base_point based coordinate of rotetion
# File lib/dyi/shape/base.rb, line 233 def rotate(angle, base_point=Coordinate::ZERO) angle %= 360 return if angle == 0 base_point = Coordinate.new(base_point) translate(base_point.x, base_point.y) if base_point.nonzero? lt = transform.last if lt && lt.first == :rotate lt[1] = (lt[1] + angle) % 360 transform.pop if lt[1] == 0 else transform.push([:rotate, angle]) end translate(- base_point.x, - base_point.y) if base_point.nonzero? end
Scales up (or down) this shape. @param [Numeric] x scaled ratio along x-axis @param [Numeric] y scaled ratio along y-axis. If this parameter is nil,
uses value that equals to parameter 'x' value
@param [Coordinate] base_point based coordinate of scaling up (or down)
# File lib/dyi/shape/base.rb, line 214 def scale(x, y=nil, base_point=Coordinate::ZERO) y ||= x return if x == 1 && y == 1 base_point = Coordinate.new(base_point) translate(base_point.x, base_point.y) if base_point.nonzero? lt = transform.last if lt && lt.first == :scale lt[1] *= x lt[2] *= y transform.pop if lt[1] == 1 && lt[2] == 1 else transform.push([:scale, x, y]) end translate(- base_point.x, - base_point.y) if base_point.nonzero? end
Restricts the region to which paint can be applied. @param [Drawing::Clipping] clipping a clipping object
# File lib/dyi/shape/base.rb, line 275 def set_clipping(clipping) clipping.set_canvas(canvas) @clipping = clipping end
Sets shapes that is used to estrict the region to which paint can be
applied.
@param [Base] shapes a shape that is used to clip
# File lib/dyi/shape/base.rb, line 288 def set_clipping_shapes(*shapes) set_clipping(Drawing::Clipping.new(*shapes)) end
Adds animation of painting to the shape @param [Event] an event that is set to the shape @since 1.0.0
DYI::GraphicalElement#set_event
# File lib/dyi/shape/base.rb, line 362 def set_event(event) super canvas.set_event(event) end
Skews this shape along x-axis. @param [Numeric] angle skew angle. specifies degree @param [Coordinate] base_point based coordinate of skew
# File lib/dyi/shape/base.rb, line 251 def skew_x(angle, base_point=Coordinate::ZERO) angle %= 180 return if angle == 0 base_point = Coordinate.new(base_point) translate(base_point.x, base_point.y) if base_point.nonzero? transform.push([:skewX, angle]) translate(- base_point.x, - base_point.y) if base_point.nonzero? end
Skews this shape along y-axis. @param [Numeric] angle skew angle. specifies degree @param [Coordinate] base_point based coordinate of skew
# File lib/dyi/shape/base.rb, line 263 def skew_y(angle, base_point=Coordinate::ZERO) angle %= 180 return if angle == 0 base_point = Coordinate.new(base_point) translate(base_point.x, base_point.y) if base_point.nonzero? lt = transform.last transform.push([:skewY, angle]) translate(- base_point.x, - base_point.y) if base_point.nonzero? end
Returns transform list. @return [Array] transform list.
# File lib/dyi/shape/base.rb, line 188 def transform @transform ||= [] end
Translates the shape. @param [Numeric] x translated value along x-axis @param [Numeric] y translated value along y-axis
# File lib/dyi/shape/base.rb, line 195 def translate(x, y=0) x = Length.new(x) y = Length.new(y) return if x.zero? && y.zero? lt = transform.last if lt && lt.first == :translate lt[1] += x lt[2] += y transform.pop if lt[1].zero? && lt[2].zero? else transform.push([:translate, x, y]) end end
Private Instance Methods
# File lib/dyi/shape/base.rb, line 384 def init_attributes(options) options = options.clone @font = Font.new_or_nil(options.delete(:font)) @painting = Painting.new_or_nil(options.delete(:painting)) @anchor_href = options.delete(:anchor_href) @anchor_target = options.delete(:anchor_target) self.css_class = options.delete(:css_class) self.id = options.delete(:id) if options[:id] self.description = options.delete(:description) if options[:description] self.title = options.delete(:title) if options[:title] options end