1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'animation_field'
13 EASING = Qt::EasingCurve.new(Qt::EasingCurve::InOutCubic)
15 def group(*animations)
16 unless animations.empty?
17 anim = animations.dup.compact
18 return nil if anim.empty?
23 "group (#{anim.map{|a| a.to_s}.join(',')})"
25 Animation.new(name) do |i|
34 def sequence(*animations)
35 anim = animations.dup.compact
36 return nil if anim.empty?
41 "sequence (#{anim.map{|a| a.to_s}.join(',')})"
43 Animation.new(name) do |i|
51 def movement(item, src, dst, path_factory)
53 name = "move to #{dst}"
60 dst = board.to_real(dst)
61 path = path_factory.new(src, dst)
63 SimpleAnimation.new name, LENGTH,
64 lambda { board.raise(item) },
65 lambda {|i| item.pos = src + path[i] },
66 lambda { item.pos = dst; board.lower(item) },
71 def disappear(item, name, opts = { })
74 Animation.new(name) { item.visible = false; true }
76 SimpleAnimation.new name, LENGTH,
77 lambda { item.opacity = 1.0; item.visible = true },
78 lambda {|t| item.opacity = 1.0 - t },
79 lambda { item.remove },
85 def appear(item, name, opts = { })
87 Animation.new(name) { item.opacity = 1.0; item.visible = true; true }
89 SimpleAnimation.new name, LENGTH,
90 lambda { item.opacity = 0.0; item.visible = true },
91 lambda {|i| item.opacity = i },
92 lambda { item.opacity = 1.0 },
99 Linear = Factory.new do |src, dst|
101 lambda {|i| delta * i }
105 FACTOR = Math.exp(3.0) - 1
106 def initialize(src, dst)
108 nonlin = lambda{|i| (Math.exp(3.0 * i) - 1) / FACTOR }
109 lin = lambda {|i| i }
110 if @delta.x.abs < @delta.y.abs
120 Qt::PointF.new(@delta.x * @x[i], @delta.y * @y[i])