Class: Pongo::AbstractItem
- Inherits:
-
Object
- Object
- Pongo::AbstractItem
- Defined in:
- lib/pongo/abstract_item.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#always_repaint ⇒ Object
Returns the value of attribute always_repaint.
-
#display_object ⇒ Object
readonly
Returns the value of attribute display_object.
-
#display_object_offset ⇒ Object
readonly
Returns the value of attribute display_object_offset.
-
#display_object_rotation ⇒ Object
readonly
Returns the value of attribute display_object_rotation.
-
#fill_alpha ⇒ Object
readonly
Returns the value of attribute fill_alpha.
-
#fill_color ⇒ Object
readonly
Returns the value of attribute fill_color.
-
#line_alpha ⇒ Object
readonly
Returns the value of attribute line_alpha.
-
#line_color ⇒ Object
readonly
Returns the value of attribute line_color.
-
#line_thickness ⇒ Object
readonly
Returns the value of attribute line_thickness.
-
#renderer ⇒ Object
Returns the value of attribute renderer.
-
#solid ⇒ Object
Returns the value of attribute solid.
-
#user_data ⇒ Object
readonly
Returns the value of attribute user_data.
-
#visible ⇒ Object
Returns the value of attribute visible.
Instance Method Summary collapse
- #add_event_listener(event_type, callable = nil, &block) ⇒ Object
- #always_redraw! ⇒ Object
- #always_redraw=(bool) ⇒ Object
-
#always_redraw? ⇒ Boolean
(also: #always_redraw)
For performance, fixed Particles and SpringConstraints don’t have their
paint()method called in order to avoid unnecessary redrawing. - #cleanup ⇒ Object
- #dispatch_event(event) ⇒ Object
- #draw ⇒ Object (also: #paint)
- #has_event_listener(event_type) ⇒ Object
-
#init ⇒ Object
This method is automatically called when an item’s parent group is added to the engine, an item’s Composite is added to a Group, or the item is added to a Composite or Group.
-
#initialize ⇒ AbstractItem
constructor
A new instance of AbstractItem.
- #set_fill(color = 0xffffff, alpha = 1) ⇒ Object
- #set_line(thickness = 0, color = 0x000000, alpha = 1) ⇒ Object
- #set_style(line_thickness = 0, line_color = 0x000000, line_alpha = 1, fill_color = 0xffffff, fill_alpha = 1) ⇒ Object
- #visible! ⇒ Object
- #visible? ⇒ Boolean
Constructor Details
#initialize ⇒ AbstractItem
Returns a new instance of AbstractItem.
7 8 9 10 11 12 13 |
# File 'lib/pongo/abstract_item.rb', line 7 def initialize @solid = true @visible = true @always_repaint = false @events = Hash.new @user_data = {} end |
Instance Attribute Details
#always_repaint ⇒ Object
Returns the value of attribute always_repaint.
3 4 5 |
# File 'lib/pongo/abstract_item.rb', line 3 def always_repaint @always_repaint end |
#display_object ⇒ Object (readonly)
Returns the value of attribute display_object.
4 5 6 |
# File 'lib/pongo/abstract_item.rb', line 4 def display_object @display_object end |
#display_object_offset ⇒ Object (readonly)
Returns the value of attribute display_object_offset.
4 5 6 |
# File 'lib/pongo/abstract_item.rb', line 4 def display_object_offset @display_object_offset end |
#display_object_rotation ⇒ Object (readonly)
Returns the value of attribute display_object_rotation.
4 5 6 |
# File 'lib/pongo/abstract_item.rb', line 4 def display_object_rotation @display_object_rotation end |
#fill_alpha ⇒ Object (readonly)
Returns the value of attribute fill_alpha.
4 5 6 |
# File 'lib/pongo/abstract_item.rb', line 4 def fill_alpha @fill_alpha end |
#fill_color ⇒ Object (readonly)
Returns the value of attribute fill_color.
4 5 6 |
# File 'lib/pongo/abstract_item.rb', line 4 def fill_color @fill_color end |
#line_alpha ⇒ Object (readonly)
Returns the value of attribute line_alpha.
4 5 6 |
# File 'lib/pongo/abstract_item.rb', line 4 def line_alpha @line_alpha end |
#line_color ⇒ Object (readonly)
Returns the value of attribute line_color.
4 5 6 |
# File 'lib/pongo/abstract_item.rb', line 4 def line_color @line_color end |
#line_thickness ⇒ Object (readonly)
Returns the value of attribute line_thickness.
4 5 6 |
# File 'lib/pongo/abstract_item.rb', line 4 def line_thickness @line_thickness end |
#renderer ⇒ Object
Returns the value of attribute renderer.
3 4 5 |
# File 'lib/pongo/abstract_item.rb', line 3 def renderer @renderer end |
#solid ⇒ Object
Returns the value of attribute solid.
3 4 5 |
# File 'lib/pongo/abstract_item.rb', line 3 def solid @solid end |
#user_data ⇒ Object (readonly)
Returns the value of attribute user_data.
5 6 7 |
# File 'lib/pongo/abstract_item.rb', line 5 def user_data @user_data end |
#visible ⇒ Object
Returns the value of attribute visible.
3 4 5 |
# File 'lib/pongo/abstract_item.rb', line 3 def visible @visible end |
Instance Method Details
#add_event_listener(event_type, callable = nil, &block) ⇒ Object
47 48 49 |
# File 'lib/pongo/abstract_item.rb', line 47 def add_event_listener(event_type, callable=nil, &block) (@events[event_type] ||= []) << (callable || block) end |
#always_redraw! ⇒ Object
73 74 75 |
# File 'lib/pongo/abstract_item.rb', line 73 def always_redraw! @always_repaint = true end |
#always_redraw=(bool) ⇒ Object
69 70 71 |
# File 'lib/pongo/abstract_item.rb', line 69 def always_redraw=(bool) @always_repaint = bool end |
#always_redraw? ⇒ Boolean Also known as: always_redraw
For performance, fixed Particles and SpringConstraints don’t have their paint() method called in order to avoid unnecessary redrawing. A SpringConstraint is considered fixed if its two connecting Particles are fixed. Setting this property to true forces paint() to be called if this Particle or SpringConstraint fixed property is true. If you are rotating a fixed Particle or SpringConstraint then you would set it’s repaintFixed property to true. This property has no effect if a Particle or SpringConstraint is not fixed.
64 65 66 |
# File 'lib/pongo/abstract_item.rb', line 64 def always_redraw? @always_repaint end |
#cleanup ⇒ Object
34 35 36 |
# File 'lib/pongo/abstract_item.rb', line 34 def cleanup renderer.cleanup(self) end |
#dispatch_event(event) ⇒ Object
51 52 53 54 55 |
# File 'lib/pongo/abstract_item.rb', line 51 def dispatch_event(event) (@events[event.type] || []).each do |listener| listener.call(event) end end |
#draw ⇒ Object Also known as: paint
38 39 40 |
# File 'lib/pongo/abstract_item.rb', line 38 def draw renderer.draw(self) end |
#has_event_listener(event_type) ⇒ Object
43 44 45 |
# File 'lib/pongo/abstract_item.rb', line 43 def has_event_listener(event_type) @events[event_type] end |
#init ⇒ Object
This method is automatically called when an item’s parent group is added to the engine, an item’s Composite is added to a Group, or the item is added to a Composite or Group.
29 30 31 32 |
# File 'lib/pongo/abstract_item.rb', line 29 def init cleanup draw end |
#set_fill(color = 0xffffff, alpha = 1) ⇒ Object
88 89 90 91 |
# File 'lib/pongo/abstract_item.rb', line 88 def set_fill(color=0xffffff, alpha=1) @fill_color = color @fill_alpha = alpha end |
#set_line(thickness = 0, color = 0x000000, alpha = 1) ⇒ Object
82 83 84 85 86 |
# File 'lib/pongo/abstract_item.rb', line 82 def set_line(thickness=0, color=0x000000, alpha=1) @line_thickness = thickness @line_color = color @line_alpha = alpha end |
#set_style(line_thickness = 0, line_color = 0x000000, line_alpha = 1, fill_color = 0xffffff, fill_alpha = 1) ⇒ Object
77 78 79 80 |
# File 'lib/pongo/abstract_item.rb', line 77 def set_style(line_thickness=0, line_color=0x000000, line_alpha=1, fill_color=0xffffff, fill_alpha=1) set_line(line_thickness, line_color, line_alpha) set_fill(fill_color, fill_alpha) end |
#visible! ⇒ Object
19 20 21 |
# File 'lib/pongo/abstract_item.rb', line 19 def visible! @visible = true end |
#visible? ⇒ Boolean
15 16 17 |
# File 'lib/pongo/abstract_item.rb', line 15 def visible? @visible end |