Class: PhantomAnimationEditor::FrameList

Inherits:
Object
  • Object
show all
Defined in:
lib/phantom_animation_editor/frame_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#curObject

Returns the value of attribute cur.



6
7
8
# File 'lib/phantom_animation_editor/frame_list.rb', line 6

def cur
  @cur
end

#frame_hboxObject

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

#listObject

Returns the value of attribute list.



6
7
8
# File 'lib/phantom_animation_editor/frame_list.rb', line 6

def list
  @list
end

#phantom_svgObject

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_allObject



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

#sizeObject



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_reloadObject



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