Class: Vedeu::MoveCursor
- Inherits:
-
Object
- Object
- Vedeu::MoveCursor
- Extended by:
- Forwardable
- Defined in:
- lib/vedeu/cursor/move_cursor.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
-
#cursor ⇒ Object
readonly
private
Returns the value of attribute cursor.
-
#dx ⇒ Object
readonly
private
Returns the value of attribute dx.
-
#dy ⇒ Object
readonly
private
Returns the value of attribute dy.
-
#interface ⇒ Object
readonly
private
Returns the value of attribute interface.
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(cursor, interface) ⇒ Cursor
Moves the cursor down by one row.
-
.left(cursor, interface) ⇒ Cursor
Moves the cursor left by one column.
-
.origin(cursor, interface) ⇒ Cursor
Moves the cursor to the top left coordinate of the interface.
-
.right(cursor, interface) ⇒ Cursor
Moves the cursor right by one column.
-
.up(cursor, interface) ⇒ Cursor
Moves the cursor up by one row.
Instance Method Summary collapse
-
#bordered_height ⇒ Fixnum
private
Return the height of the interface, minus any borders.
-
#bordered_width ⇒ Fixnum
private
Return the width of the interface, minus any borders.
- #coordinate ⇒ Coordinate private
-
#initialize(cursor, interface, dy = 0, dx = 0) ⇒ MoveCursor
constructor
Returns an instance of MoveCursor.
-
#move ⇒ Cursor
Returns a newly positioned and stored Cursor.
- #moved_attributes ⇒ Hash private
-
#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
Constructor Details
#initialize(cursor, interface, dy = 0, dx = 0) ⇒ MoveCursor
Returns an instance of MoveCursor.
56 57 58 59 60 61 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 56 def initialize(cursor, interface, dy = 0, dx = 0) @cursor = cursor @dy = dy || 0 @dx = dx || 0 @interface = interface end |
Instance Attribute Details
#cursor ⇒ Object (readonly, private)
Returns the value of attribute cursor.
148 149 150 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 148 def cursor @cursor end |
#dx ⇒ Object (readonly, private)
Returns the value of attribute dx.
148 149 150 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 148 def dx @dx end |
#dy ⇒ Object (readonly, private)
Returns the value of attribute dy.
148 149 150 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 148 def dy @dy end |
#interface ⇒ Object (readonly, private)
Returns the value of attribute interface.
148 149 150 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 148 def interface @interface 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.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 73 def self.by_name(direction, name = nil) if name cursor = Vedeu.cursors.by_name(name) interface = Vedeu.interfaces.find(name) new_cursor = MoveCursor.send(direction, cursor, interface) Refresh.by_name(name) else cursor = Vedeu.cursor interface = Vedeu.interfaces.current new_cursor = MoveCursor.send(direction, cursor, interface) Refresh.by_focus end new_cursor end |
.down(cursor, interface) ⇒ Cursor
Moves the cursor down by one row.
95 96 97 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 95 def self.down(cursor, interface) new(cursor, interface, 1, 0).move end |
.left(cursor, interface) ⇒ Cursor
Moves the cursor left by one column.
104 105 106 107 108 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 104 def self.left(cursor, interface) return cursor unless cursor.ox > 0 new(cursor, interface, 0, -1).move end |
.origin(cursor, interface) ⇒ Cursor
Moves the cursor to the top left coordinate of the interface.
135 136 137 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 135 def self.origin(cursor, interface) new(cursor, interface, (0 - cursor.y), (0 - cursor.x)).move end |
.right(cursor, interface) ⇒ Cursor
Moves the cursor right by one column.
115 116 117 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 115 def self.right(cursor, interface) new(cursor, interface, 0, 1).move end |
.up(cursor, interface) ⇒ Cursor
Moves the cursor up by one row.
124 125 126 127 128 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 124 def self.up(cursor, interface) return cursor unless cursor.oy > 0 new(cursor, interface, -1, 0).move end |
Instance Method Details
#bordered_height ⇒ Fixnum (private)
Return the height of the interface, minus any borders.
198 199 200 201 202 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 198 def bordered_height return border.height if border? height end |
#bordered_width ⇒ Fixnum (private)
Return the width of the interface, minus any borders.
207 208 209 210 211 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 207 def bordered_width return border.width if border? width end |
#coordinate ⇒ Coordinate (private)
188 189 190 191 192 193 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 188 def coordinate @coordinate ||= Vedeu::Coordinate.new(bordered_height, bordered_width, left, top) end |
#move ⇒ Cursor
Returns a newly positioned and stored Cursor.
142 143 144 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 142 def move Cursor.new(cursor.attributes.merge!(moved_attributes)).store end |
#moved_attributes ⇒ Hash (private)
151 152 153 154 155 156 157 158 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 151 def moved_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.
171 172 173 174 175 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 171 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.
181 182 183 184 185 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 181 def oy oy = cursor.oy + dy oy = 0 if oy < 0 oy end |
#validator ⇒ PositionValidator (private)
161 162 163 164 165 |
# File 'lib/vedeu/cursor/move_cursor.rb', line 161 def validator @validator ||= Vedeu::PositionValidator.validate(interface, coordinate.x_position(ox), coordinate.y_position(oy)) end |