Class: DYI::Shape::Base Abstract
- Inherits:
-
GraphicalElement
- Object
- Element
- GraphicalElement
- DYI::Shape::Base
- Defined in:
- lib/dyi/shape/base.rb
Overview
Base class of all graphical shapes.
Direct Known Subclasses
Circle, Ellipse, GraphicalTemplate, Line, Path, Polyline, Rectangle, ReusedShape, ShapeGroup, Text
Constant Summary
Constants inherited from GraphicalElement
GraphicalElement::CLASS_REGEXP
Constants inherited from Element
Instance Attribute Summary collapse
-
#anchor_href ⇒ String
Returns a location of a reference of a source anchor for the link.
-
#anchor_target ⇒ String
Returns a relevant presentation context when the link is activated.
-
#attributes ⇒ Hash
readonly
Returns optional attributes of the shape.
-
#clipping ⇒ Drawing::Clipping
readonly
Returns clipping status of the shape.
-
#parent ⇒ GraphicalElement
readonly
Returns a parent element of the shape.
Attributes inherited from GraphicalElement
Attributes inherited from Element
Instance Method Summary collapse
-
#add_animation(animation) ⇒ Object
Adds animation to the shape.
-
#add_painting_animation(options) ⇒ Object
Adds animation of painting to the shape.
-
#add_transform_animation(type, options) ⇒ Object
Adds animation of transform to the shape.
-
#animate? ⇒ Boolean
Returns whether the shape is animated.
-
#animations ⇒ Array<Animation::Base>
Returns registed animations.
-
#clear_clipping ⇒ Object
Crears clipping settings.
-
#draw_on(parent) ⇒ Shape::Base
Draws the shape on a parent element.
-
#has_marker?(position) ⇒ Boolean
Returns whether this shape has a marker symbol.
-
#has_uri_reference? ⇒ Boolean
Returns whether the element has URI reference.
-
#root_element? ⇒ Boolean
Returns whether this instance is root element of the shape.
-
#root_node? ⇒ Boolean
deprecated
Deprecated.
Use #root_element? instead.
-
#rotate(angle, base_point = Coordinate::ZERO) ⇒ Object
Rotates this shape.
-
#scale(x, y = nil, base_point = Coordinate::ZERO) ⇒ Object
Scales up (or down) this shape.
-
#set_clipping(clipping) ⇒ Object
Restricts the region to which paint can be applied.
-
#set_clipping_shapes(*shapes) ⇒ Object
Sets shapes that is used to estrict the region to which paint can be applied.
-
#set_event(event) ⇒ Object
Adds animation of painting to the shape.
-
#skew_x(angle, base_point = Coordinate::ZERO) ⇒ Object
Skews this shape along x-axis.
-
#skew_y(angle, base_point = Coordinate::ZERO) ⇒ Object
Skews this shape along y-axis.
-
#transform ⇒ Array
Returns transform list.
-
#translate(x, y = 0) ⇒ Object
Translates the shape.
Methods inherited from GraphicalElement
#add_css_class, #add_event_listener, #css_classes, #event_listeners, #event_target?, #remove_css_class, #remove_event_listener, #to_reused_source
Methods inherited from Element
#canvas, #child_elements, #id, #id=, #include_external_file?, #inner_id
Instance Attribute Details
#anchor_href ⇒ String
Returns a location of a reference of a source anchor for the link.
143 144 145 |
# File 'lib/dyi/shape/base.rb', line 143 def anchor_href @anchor_href end |
#anchor_target ⇒ String
Returns a relevant presentation context when the link is activated.
148 149 150 |
# File 'lib/dyi/shape/base.rb', line 148 def anchor_target @anchor_target end |
#attributes ⇒ Hash (readonly)
Returns optional attributes of the shape.
129 130 131 |
# File 'lib/dyi/shape/base.rb', line 129 def attributes @attributes end |
#clipping ⇒ Drawing::Clipping (readonly)
Returns clipping status of the shape.
133 134 135 |
# File 'lib/dyi/shape/base.rb', line 133 def clipping @clipping end |
#parent ⇒ GraphicalElement (readonly)
Returns a parent element of the shape.
138 139 140 |
# File 'lib/dyi/shape/base.rb', line 138 def parent @parent end |
Instance Method Details
#add_animation(animation) ⇒ Object
Adds animation to the shape
318 319 320 |
# File 'lib/dyi/shape/base.rb', line 318 def add_animation(animation) animations << animation end |
#add_painting_animation(options) ⇒ Object
Adds animation of painting to the shape
336 337 338 |
# File 'lib/dyi/shape/base.rb', line 336 def add_painting_animation() add_animation(Animation::PaintingAnimation.new(self, )) end |
#add_transform_animation(type, options) ⇒ Object
Adds animation of transform to the shape
356 357 358 |
# File 'lib/dyi/shape/base.rb', line 356 def add_transform_animation(type, ) add_animation(Animation::TransformAnimation.new(self, type, )) end |
#animate? ⇒ Boolean
Returns whether the shape is animated.
311 312 313 |
# File 'lib/dyi/shape/base.rb', line 311 def animate? !(@animations.nil? || @animations.empty?) end |
#animations ⇒ Array<Animation::Base>
Returns registed animations. since 1.0.0
304 305 306 |
# File 'lib/dyi/shape/base.rb', line 304 def animations @animations ||= [] end |
#clear_clipping ⇒ Object
Crears clipping settings.
282 283 284 |
# File 'lib/dyi/shape/base.rb', line 282 def clear_clipping @clipping = nil end |
#draw_on(parent) ⇒ Shape::Base
Draws the shape on a parent element.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/dyi/shape/base.rb', line 156 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 |
#has_marker?(position) ⇒ Boolean
Returns whether this shape has a marker symbol.
297 298 299 |
# File 'lib/dyi/shape/base.rb', line 297 def has_marker?(position) return false end |
#has_uri_reference? ⇒ Boolean
Returns whether the element has URI reference.
379 380 381 |
# File 'lib/dyi/shape/base.rb', line 379 def has_uri_reference? @anchor_href ? true : false end |
#root_element? ⇒ Boolean
Returns whether this instance is root element of the shape.
183 184 185 |
# File 'lib/dyi/shape/base.rb', line 183 def root_element? false end |
#root_node? ⇒ Boolean
Use #root_element? instead.
173 174 175 176 177 178 |
# File 'lib/dyi/shape/base.rb', line 173 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 |
#rotate(angle, base_point = Coordinate::ZERO) ⇒ Object
Rotates this shape.
234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/dyi/shape/base.rb', line 234 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 |
#scale(x, y = nil, base_point = Coordinate::ZERO) ⇒ Object
Scales up (or down) this shape.
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/dyi/shape/base.rb', line 215 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 |
#set_clipping(clipping) ⇒ Object
Restricts the region to which paint can be applied.
276 277 278 279 |
# File 'lib/dyi/shape/base.rb', line 276 def set_clipping(clipping) clipping.set_canvas(canvas) @clipping = clipping end |
#set_clipping_shapes(*shapes) ⇒ Object
Sets shapes that is used to estrict the region to which paint can be
applied.
289 290 291 |
# File 'lib/dyi/shape/base.rb', line 289 def set_clipping_shapes(*shapes) set_clipping(Drawing::Clipping.new(*shapes)) end |
#set_event(event) ⇒ Object
Adds animation of painting to the shape
363 364 365 366 |
# File 'lib/dyi/shape/base.rb', line 363 def set_event(event) super canvas.set_event(event) end |
#skew_x(angle, base_point = Coordinate::ZERO) ⇒ Object
Skews this shape along x-axis.
252 253 254 255 256 257 258 259 |
# File 'lib/dyi/shape/base.rb', line 252 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 |
#skew_y(angle, base_point = Coordinate::ZERO) ⇒ Object
Skews this shape along y-axis.
264 265 266 267 268 269 270 271 272 |
# File 'lib/dyi/shape/base.rb', line 264 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 |
#transform ⇒ Array
Returns transform list.
189 190 191 |
# File 'lib/dyi/shape/base.rb', line 189 def transform @transform ||= [] end |
#translate(x, y = 0) ⇒ Object
Translates the shape.
196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/dyi/shape/base.rb', line 196 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 |