class PhantomAnimationEditor::Frame

Animation frame.

Constants

THUMBNAIL_SIZE

Attributes

filename[RW]
pixbuf[RW]

Public Class Methods

new(filename, parent) click to toggle source
Calls superclass method
# File lib/phantom_animation_editor/frame.rb, line 8
def initialize(filename, parent)
  super()
  @filename = filename
  @parent = parent

  image = create_thumbnail
  @pixbuf = image.pixbuf

  create_image_button(image)
  create_spinner
  create_delete_button

  add(create_box)
end

Public Instance Methods

create_box() click to toggle source
# File lib/phantom_animation_editor/frame.rb, line 65
def create_box
  box = Gtk::Box.new(:vertical)
  box.pack_start(@image_button, expand: true, fill: false, padding: 10)
  box.pack_start(@delay_spinner, expand: false, fill: false)
  box.pack_start(@delete_button, expand: false, fill: false)
  box
end
create_delete_button() click to toggle source
# File lib/phantom_animation_editor/frame.rb, line 58
def create_delete_button
  @delete_button = Gtk::Button.new(label: 'Delete')
  @delete_button.signal_connect('clicked') do
    @parent.delete(self)
  end
end
create_image_button(image) click to toggle source
# File lib/phantom_animation_editor/frame.rb, line 44
def create_image_button(image)
  @image_button = Gtk::Button.new
  @image_button.set_relief(Gtk::ReliefStyle::NONE)
  @image_button.add(image)
  @image_button.signal_connect('clicked') do
    @parent.focus(self)
  end
end
create_spinner() click to toggle source
# File lib/phantom_animation_editor/frame.rb, line 53
def create_spinner
  adjustment = Gtk::Adjustment.new(100, 1, 999, 1, 1, 0)
  @delay_spinner = Gtk::SpinButton.new(adjustment, 1, 0)
end
create_thumbnail() click to toggle source
# File lib/phantom_animation_editor/frame.rb, line 23
def create_thumbnail
  image = Gtk::Image.new(file: @filename)
  unless image.pixbuf.nil?
    if image.pixbuf.width > THUMBNAIL_SIZE || image.pixbuf.height > THUMBNAIL_SIZE
      image.pixbuf = resize(image.pixbuf, THUMBNAIL_SIZE)
    end
  end
  image
end
delay() click to toggle source
# File lib/phantom_animation_editor/frame.rb, line 73
def delay
  @delay_spinner.value
end
resize(pixbuf, size) click to toggle source
# File lib/phantom_animation_editor/frame.rb, line 33
def resize(pixbuf, size)
  if pixbuf.width >= pixbuf.height
    scale = pixbuf.height.to_f / pixbuf.width.to_f
    pixbuf = pixbuf.scale(size, size * scale, GdkPixbuf::InterpType::BILINEAR)
  else
    scale = pixbuf.width.to_f / pixbuf.height.to_f
    pixbuf = pixbuf.scale(size * scale, size, GdkPixbuf::InterpType::BILINEAR)
  end
  pixbuf
end
set_delay(value) click to toggle source
# File lib/phantom_animation_editor/frame.rb, line 77
def set_delay(value)
  @delay_spinner.set_value(value)
end