Class: Wx::SF::CanvasHistory
- Inherits:
-
Object
- Object
- Wx::SF::CanvasHistory
- Defined in:
- lib/wx/shapes/canvas_history.rb
Defined Under Namespace
Modules: DEFAULT
Instance Attribute Summary collapse
-
#current_state ⇒ Object
readonly
Returns the value of attribute current_state.
-
#max_states ⇒ Object
Returns the value of attribute max_states.
Instance Method Summary collapse
-
#at_latest? ⇒ Boolean
Returns true if the current state is the newest state saved.
-
#can_redo ⇒ Object
The function gives information whether the ‘redo’ operation is available (exists any stored canvas state newer than the current one..
-
#can_undo ⇒ Boolean
The function gives information whether the ‘Undo’ operation is available (exists any stored canvas state older than the current one..
-
#clear ⇒ Object
Clear all canvas history.
- #clear_current_state ⇒ Object
-
#empty? ⇒ Boolean
Returns true if no state has been saved yet.
-
#initialize ⇒ CanvasHistory
constructor
Constructor.
-
#restore_newer_state ⇒ String
Perform the ‘Redo’ operation.
-
#restore_older_state ⇒ String
Perform the ‘Undo’ operation.
-
#save_canvas_state(state) ⇒ Object
Save current canvas state.
Constructor Details
#initialize ⇒ CanvasHistory
Constructor.
13 14 15 16 17 18 |
# File 'lib/wx/shapes/canvas_history.rb', line 13 def initialize @canvas_states = [] @current_state = nil @current_state_index = nil @max_states = DEFAULT::MAX_CANVAS_STATES end |
Instance Attribute Details
#current_state ⇒ Object (readonly)
Returns the value of attribute current_state.
21 22 23 |
# File 'lib/wx/shapes/canvas_history.rb', line 21 def current_state @current_state end |
#max_states ⇒ Object
Returns the value of attribute max_states.
20 21 22 |
# File 'lib/wx/shapes/canvas_history.rb', line 20 def max_states @max_states end |
Instance Method Details
#at_latest? ⇒ Boolean
Returns true if the current state is the newest state saved.
31 32 33 |
# File 'lib/wx/shapes/canvas_history.rb', line 31 def at_latest? @current_state && @current_state_index == (@canvas_states.size-1) end |
#can_redo ⇒ Object
The function gives information whether the ‘redo’ operation is available (exists any stored canvas state newer than the current one.
98 99 100 |
# File 'lib/wx/shapes/canvas_history.rb', line 98 def can_redo @current_state && @current_state_index < (@canvas_states.size - 1) end |
#can_undo ⇒ Boolean
The function gives information whether the ‘Undo’ operation is available (exists any stored canvas state older than the current one.
91 92 93 |
# File 'lib/wx/shapes/canvas_history.rb', line 91 def can_undo @current_state && @current_state_index>0 end |
#clear ⇒ Object
Clear all canvas history.
82 83 84 85 86 |
# File 'lib/wx/shapes/canvas_history.rb', line 82 def clear @canvas_states.clear @current_state = nil @current_state_index = nil end |
#clear_current_state ⇒ Object
74 75 76 77 78 79 |
# File 'lib/wx/shapes/canvas_history.rb', line 74 def clear_current_state restore_older_state if @current_state @canvas_states.slice!(@current_state_index+1, @canvas_states.size) end end |
#empty? ⇒ Boolean
Returns true if no state has been saved yet.
25 26 27 |
# File 'lib/wx/shapes/canvas_history.rb', line 25 def empty? @current_state.nil? end |
#restore_newer_state ⇒ String
Perform the ‘Redo’ operation.
66 67 68 69 70 71 72 |
# File 'lib/wx/shapes/canvas_history.rb', line 66 def restore_newer_state return nil unless @current_state && @current_state_index<(@canvas_states.size-1) # move to next canvas state and restore @current_state_index += 1 @current_state = @canvas_states[@current_state_index] end |
#restore_older_state ⇒ String
Perform the ‘Undo’ operation.
56 57 58 59 60 61 62 |
# File 'lib/wx/shapes/canvas_history.rb', line 56 def restore_older_state return nil unless @current_state && @current_state_index>0 # move to previous canvas state and restore @current_state_index -= 1 @current_state = @canvas_states[@current_state_index] end |
#save_canvas_state(state) ⇒ Object
Save current canvas state.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wx/shapes/canvas_history.rb', line 37 def save_canvas_state(state) # delete all states newer than the current state if @current_state @canvas_states.slice!(@current_state_index+1, @canvas_states.size) end # append new canvas state @current_state_index = @canvas_states.size @canvas_states << (@current_state = state) # check the history bounds if @canvas_states.size > @max_states @canvas_states.shift @current_state_index -= 1 end end |