Class: Vedeu::Move
- Inherits:
-
Object
- Object
- Vedeu::Move
- Extended by:
- Forwardable
- Defined in:
- lib/vedeu/cursor/move.rb
Overview
The cursor may not be visible, but it will still move if requested. The cursor will not exceed the border or boundary of the interface. The cursor will move freely within the bounds of the interface,
irrespective of content.
Adjusts the position of the cursor. To use this class, call the appropriate event:
Instance Attribute Summary collapse
- #dx ⇒ Fixnum readonly protected
- #dy ⇒ Fixnum readonly protected
- #name ⇒ String readonly protected
Class Method Summary collapse
-
.by_name(direction, name = nil) ⇒ Cursor
Move the named cursor, or that which is currently in focus in the specified direction.
-
.down(name) ⇒ Cursor
Moves the cursor down by one row.
-
.left(name) ⇒ Cursor
Moves the cursor left by one column.
-
.origin(name) ⇒ Cursor
Moves the cursor to the top left coordinate of the interface.
-
.right(name) ⇒ Cursor
Moves the cursor right by one column.
-
.up(name) ⇒ Cursor
Moves the cursor up by one row.
Instance Method Summary collapse
-
#attributes ⇒ Hash<Symbol => Fixnum, String>
private
Retrieve the attributes of the cursor.
-
#border ⇒ Object
private
Retrieve the border for the named view: this will provide the geometry for the cursor, ensuring it displays within the interface boundaries.
- #coordinate ⇒ Coordinate private
- #cursor ⇒ Vedeu::Cursor private
-
#initialize(name, dy = 0, dx = 0) ⇒ Move
constructor
Returns an instance of Vedeu::Move.
-
#move ⇒ Cursor
Returns a newly positioned and stored Cursor.
-
#new_attributes ⇒ Hash<Symbol => Fixnum>
private
Provide the new attributes for the cursor.
-
#ox ⇒ Fixnum
private
Apply the direction amount to the cursor offset.
-
#oy ⇒ Fixnum
private
Apply the direction amount to the cursor offset.
-
#validator ⇒ PositionValidator
private
Validates the new position of the cursor.
-
#x_position ⇒ Fixnum
private
Returns the cursors x position based on its current offset.
-
#y_position ⇒ Fixnum
private
Returns the cursors y position based on its current offset.
Constructor Details
#initialize(name, dy = 0, dx = 0) ⇒ Move
Returns an instance of Vedeu::Move.
47 48 49 50 51 |
# File 'lib/vedeu/cursor/move.rb', line 47 def initialize(name, dy = 0, dx = 0) @name = name @dy = dy @dx = dx end |
Instance Attribute Details
#dx ⇒ Fixnum (readonly, protected)
124 125 126 |
# File 'lib/vedeu/cursor/move.rb', line 124 def dx @dx end |
#dy ⇒ Fixnum (readonly, protected)
128 129 130 |
# File 'lib/vedeu/cursor/move.rb', line 128 def dy @dy end |
#name ⇒ String (readonly, protected)
132 133 134 |
# File 'lib/vedeu/cursor/move.rb', line 132 def name @name end |
Class Method Details
.by_name(direction, name = nil) ⇒ Cursor
Move the named cursor, or that which is currently in focus in the specified direction.
63 64 65 66 67 |
# File 'lib/vedeu/cursor/move.rb', line 63 def self.by_name(direction, name = nil) name = name ? name : Vedeu.focus Vedeu::Move.send(direction, name) end |
.down(name) ⇒ Cursor
Moves the cursor down by one row.
73 74 75 |
# File 'lib/vedeu/cursor/move.rb', line 73 def self.down(name) new(name, 1, 0).move end |
.left(name) ⇒ Cursor
Moves the cursor left by one column.
81 82 83 |
# File 'lib/vedeu/cursor/move.rb', line 81 def self.left(name) new(name, 0, -1).move end |
.origin(name) ⇒ Cursor
Moves the cursor to the top left coordinate of the interface.
105 106 107 |
# File 'lib/vedeu/cursor/move.rb', line 105 def self.origin(name) new(name, -2000, -2000).move end |
.right(name) ⇒ Cursor
Moves the cursor right by one column.
89 90 91 |
# File 'lib/vedeu/cursor/move.rb', line 89 def self.right(name) new(name, 0, 1).move end |
.up(name) ⇒ Cursor
Moves the cursor up by one row.
97 98 99 |
# File 'lib/vedeu/cursor/move.rb', line 97 def self.up(name) new(name, -1, 0).move end |
Instance Method Details
#attributes ⇒ Hash<Symbol => Fixnum, String> (private)
Retrieve the attributes of the cursor.
139 140 141 |
# File 'lib/vedeu/cursor/move.rb', line 139 def attributes cursor.attributes end |
#border ⇒ Object (private)
Retrieve the border for the named view: this will provide the geometry for the cursor, ensuring it displays within the interface boundaries.
182 183 184 |
# File 'lib/vedeu/cursor/move.rb', line 182 def border @border ||= Vedeu.borders.by_name(name) end |
#coordinate ⇒ Coordinate (private)
187 188 189 |
# File 'lib/vedeu/cursor/move.rb', line 187 def coordinate @coordinate ||= Vedeu::Coordinate.new(height, width, x, y) end |
#cursor ⇒ Vedeu::Cursor (private)
192 193 194 |
# File 'lib/vedeu/cursor/move.rb', line 192 def cursor @cursor ||= Vedeu.cursors.by_name(name) end |
#move ⇒ Cursor
Returns a newly positioned and stored Cursor.
112 113 114 115 116 117 118 |
# File 'lib/vedeu/cursor/move.rb', line 112 def move cursor = Vedeu::Cursor.new(attributes.merge!(new_attributes)).store Vedeu.trigger(:_refresh_cursor_, name) cursor end |
#new_attributes ⇒ Hash<Symbol => Fixnum> (private)
Provide the new attributes for the cursor.
146 147 148 149 150 151 152 153 |
# File 'lib/vedeu/cursor/move.rb', line 146 def new_attributes { x: validator.x, y: validator.y, ox: ox, oy: oy, } end |
#ox ⇒ Fixnum (private)
Apply the direction amount to the cursor offset. If the offset is less than 0, correct to 0.
200 201 202 203 204 |
# File 'lib/vedeu/cursor/move.rb', line 200 def ox ox = cursor.ox + dx ox = 0 if ox < 0 ox end |
#oy ⇒ Fixnum (private)
Apply the direction amount to the cursor offset. If the offset is less than 0, correct to 0.
210 211 212 213 214 |
# File 'lib/vedeu/cursor/move.rb', line 210 def oy oy = cursor.oy + dy oy = 0 if oy < 0 oy end |
#validator ⇒ PositionValidator (private)
Validates the new position of the cursor.
158 159 160 161 162 |
# File 'lib/vedeu/cursor/move.rb', line 158 def validator @validator ||= Vedeu::PositionValidator.validate(name, x_position, y_position) end |
#x_position ⇒ Fixnum (private)
Returns the cursors x position based on its current offset.
167 168 169 |
# File 'lib/vedeu/cursor/move.rb', line 167 def x_position coordinate.x_position(ox) end |
#y_position ⇒ Fixnum (private)
Returns the cursors y position based on its current offset.
174 175 176 |
# File 'lib/vedeu/cursor/move.rb', line 174 def y_position coordinate.y_position(oy) end |