Class: RichEngine::Canvas::Slot
- Inherits:
-
RichEngine::Canvas
- Object
- RichEngine::Canvas
- RichEngine::Canvas::Slot
- Defined in:
- lib/rich_engine/canvas/slot.rb
Overview
A sub-section of a parent Canvas. All drawing operations are translated by the slot's origin (x, y).
Instance Attribute Summary collapse
-
#bg ⇒ String?
The slot's background fill, or nil to inherit the parent's.
Attributes inherited from RichEngine::Canvas
Instance Method Summary collapse
-
#[](x, y) ⇒ String?
Read the cell at the slot-local (x, y), translated to parent space.
-
#[]=(x, y, value) ⇒ void
Write the cell at the slot-local (x, y), translated to parent space.
-
#clear ⇒ void
Clear the slot, filling it with its background (or the parent's if the slot has none).
-
#initialize(parent, x, y, width, height, bg: nil) ⇒ Slot
constructor
A new instance of Slot.
Methods inherited from RichEngine::Canvas
#dimensions, #draw_circle, #draw_rect, #draw_sprite, #each_coord, #out_of_bounds?, #rows, #slot, #write_string
Constructor Details
#initialize(parent, x, y, width, height, bg: nil) ⇒ Slot
Returns a new instance of Slot.
19 20 21 22 23 24 25 26 |
# File 'lib/rich_engine/canvas/slot.rb', line 19 def initialize(parent, x, y, width, height, bg: nil) @parent = parent @offset_x = x @offset_y = y @width = width @height = height @bg = bg end |
Instance Attribute Details
#bg ⇒ String?
Returns the slot's background fill, or nil to inherit the parent's.
10 11 12 |
# File 'lib/rich_engine/canvas/slot.rb', line 10 def bg @bg end |
Instance Method Details
#[](x, y) ⇒ String?
Read the cell at the slot-local (x, y), translated to parent space.
34 35 36 37 |
# File 'lib/rich_engine/canvas/slot.rb', line 34 def [](x, y) return nil if out_of_bounds?(x, y) @parent[@offset_x + x, @offset_y + y] end |
#[]=(x, y, value) ⇒ void
This method returns an undefined value.
Write the cell at the slot-local (x, y), translated to parent space. Writes outside the slot are clipped.
46 47 48 49 |
# File 'lib/rich_engine/canvas/slot.rb', line 46 def []=(x, y, value) return if out_of_bounds?(x, y) @parent[@offset_x + x, @offset_y + y] = value end |
#clear ⇒ void
This method returns an undefined value.
Clear the slot, filling it with its background (or the parent's if the slot has none).
55 56 57 58 59 60 |
# File 'lib/rich_engine/canvas/slot.rb', line 55 def clear fill_char = @bg || @parent.bg each_coord do |x, y| self[x, y] = fill_char end end |