Class: Flms::AnimationLayerViewObject

Inherits:
LayerViewObject show all
Defined in:
app/view_objects/flms/animation_layer_view_object.rb

Instance Method Summary collapse

Methods inherited from LayerViewObject

#initialize, #keyframe_data_hash, link_path_for, #view_partial_name

Constructor Details

This class inherits a constructor from Flms::LayerViewObject

Instance Method Details

#attributes(scroll_offset = 0) ⇒ Object



8
9
10
11
# File 'app/view_objects/flms/animation_layer_view_object.rb', line 8

def attributes(scroll_offset = 0)
  attributes = { id: @layer.name }
  attributes.merge keyframe_data_hash(scroll_offset)
end

#frame_pixel_end(frame, scroll_offset = 0) ⇒ Object

Pixel end of specified frame (frame number is 0..n)



32
33
34
# File 'app/view_objects/flms/animation_layer_view_object.rb', line 32

def frame_pixel_end(frame, scroll_offset = 0)
  (scroll_offset + ((frame + 1) * @layer.frame_rate) - 1).to_i
end

#frame_pixel_start(frame, scroll_offset = 0) ⇒ Object

Pixel start of specified frame (frame number is 0..n)



27
28
29
# File 'app/view_objects/flms/animation_layer_view_object.rb', line 27

def frame_pixel_start(frame, scroll_offset = 0)
  (scroll_offset + (frame * @layer.frame_rate)).to_i
end

#frame_sprite_heightObject

Calculate the pixel size of a single frame of animation; since animation sprites contain multiple frames stiched together vertically, the pixel height will be the image height divided by the number of frames contained within the sprite.



40
41
42
# File 'app/view_objects/flms/animation_layer_view_object.rb', line 40

def frame_sprite_height
  @layer.image_height / @layer.frame_count
end

#frames_attributes(scroll_offset = 0) ⇒ Object

Define attributes related to animating the sprited image



14
15
16
17
18
19
20
21
22
23
24
# File 'app/view_objects/flms/animation_layer_view_object.rb', line 14

def frames_attributes(scroll_offset = 0)
  data = { }
  (0...@layer.frame_count).each do |frame_index|
    y_offset = -(frame_index * frame_sprite_height)
    data["data-#{ frame_pixel_start(frame_index, scroll_offset) }"] = "background-position: 0 #{ y_offset }px;"
    data["data-#{ frame_pixel_end(frame_index, scroll_offset) }"] = "background-position: 0 #{ y_offset }px;"
  end
  data[:style] = "width: #{ @layer.image_width }px; height: #{ frame_sprite_height }px;" \
                 "background-image: url(#{ src }); background-size: #{ @layer.image_display_mode };"
  data
end

#srcObject



4
5
6
# File 'app/view_objects/flms/animation_layer_view_object.rb', line 4

def src
  @layer.image.url
end