Class: PhantomAnimationEditor::FrameList
- Inherits:
-
Object
- Object
- PhantomAnimationEditor::FrameList
- Defined in:
- lib/phantom_animation_editor/frame_list.rb
Instance Attribute Summary collapse
-
#cur ⇒ Object
Returns the value of attribute cur.
-
#frame_hbox ⇒ Object
Returns the value of attribute frame_hbox.
-
#list ⇒ Object
Returns the value of attribute list.
-
#phantom_svg ⇒ Object
Returns the value of attribute phantom_svg.
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #delay(position = nil) ⇒ Object
- #delete(child) ⇒ Object
- #delete_all ⇒ Object
- #delete_at(index) ⇒ Object
- #filename(position = nil) ⇒ Object
- #focus(child) ⇒ Object
-
#initialize(frame_hbox) ⇒ FrameList
constructor
A new instance of FrameList.
- #insert_first(list, old_position) ⇒ Object
- #insert_last(list, old_position) ⇒ Object
- #pixbuf(position = nil) ⇒ Object
- #size ⇒ Object
- #swap(old_position, new_position) ⇒ Object
- #swap_pos(list, old_position, new_position) ⇒ Object
- #view_reload ⇒ Object
Constructor Details
#initialize(frame_hbox) ⇒ FrameList
Returns a new instance of FrameList.
8 9 10 11 12 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 8 def initialize(frame_hbox) @frame_hbox = frame_hbox @list = [] @phantom_svg = Phantom::SVG::Base.new end |
Instance Attribute Details
#cur ⇒ Object
Returns the value of attribute cur.
6 7 8 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 6 def cur @cur end |
#frame_hbox ⇒ Object
Returns the value of attribute frame_hbox.
6 7 8 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 6 def frame_hbox @frame_hbox end |
#list ⇒ Object
Returns the value of attribute list.
6 7 8 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 6 def list @list end |
#phantom_svg ⇒ Object
Returns the value of attribute phantom_svg.
6 7 8 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 6 def phantom_svg @phantom_svg end |
Instance Method Details
#<<(data) ⇒ Object
14 15 16 17 18 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 14 def <<(data) @list << data @cur = @list.size - 1 @phantom_svg.add_frame_from_file(data.filename) if File.exist?(data.filename) end |
#delay(position = nil) ⇒ Object
36 37 38 39 40 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 36 def delay(position = nil) return @list[@cur].delay if position.nil? return nil if position > @list.size return @list[position].delay end |
#delete(child) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 70 def delete(child) @phantom_svg.frames.delete_at(@list.find_index(child)) @list.delete(child) @frame_hbox.remove(child) @cur -= 1 unless @cur == 0 if @list.size == 0 $preview.set_stock(Gtk::Stock::MISSING_IMAGE) else $preview.set_pixbuf(@list[@cur].pixbuf) end end |
#delete_all ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 88 def delete_all @list.size.times do child = @list[0] @list.delete(child) @frame_hbox.remove(child) end @phantom_svg.reset @cur = 0 $preview.set_stock(Gtk::Stock::MISSING_IMAGE) end |
#delete_at(index) ⇒ Object
83 84 85 86 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 83 def delete_at(index) child = @list[index] delete(child) end |
#filename(position = nil) ⇒ Object
24 25 26 27 28 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 24 def filename(position = nil) return @list[@cur].filename if position.nil? return nil if position > @list.size return @list[position].filename end |
#focus(child) ⇒ Object
99 100 101 102 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 99 def focus(child) @cur = @list.find_index(child) $preview.set_pixbuf(@list[@cur].pixbuf) end |
#insert_first(list, old_position) ⇒ Object
56 57 58 59 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 56 def insert_first(list, old_position) list.insert(0, list[old_position]) list.delete_at(old_position + 1) end |
#insert_last(list, old_position) ⇒ Object
61 62 63 64 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 61 def insert_last(list, old_position) list << list[old_position] list.delete_at(old_position) end |
#pixbuf(position = nil) ⇒ Object
30 31 32 33 34 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 30 def pixbuf(position = nil) return @list[@cur].pixbuf if position.nil? return nil if position > @list.size return @list[position].pixbuf end |
#size ⇒ Object
20 21 22 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 20 def size @list.size end |
#swap(old_position, new_position) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 42 def swap(old_position, new_position) case new_position when 0 then insert_first(@list, old_position) insert_first(@phantom_svg.frames, old_position) when @list.size - 1 then insert_last(@list, old_position) insert_last(@phantom_svg.frames, old_position) else swap_pos(@list, old_position, new_position) swap_pos(@phantom_svg.frames, old_position, new_position) end end |
#swap_pos(list, old_position, new_position) ⇒ Object
66 67 68 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 66 def swap_pos(list, old_position, new_position) list[old_position], list[new_position] = list[new_position], list[old_position] end |
#view_reload ⇒ Object
104 105 106 107 108 109 |
# File 'lib/phantom_animation_editor/frame_list.rb', line 104 def view_reload @list.each { |frame| @frame_hbox.remove(frame) } @list.each do |frame| @frame_hbox.pack_start(frame, expand: false, fill: false, padding: 10) end end |