# This file is part of Recently Used Desklet # # Recently Used Desklet is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # Recently Used Desklet is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with Recently Used Desklet; if not, write to the Free # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # 02111-1307 USA import math class Animator: __ANIM_STEPS = 3 def __init__(self): self.__zoom = [] self.__zoom_steps = [] self.__counter = 0 self.__align = [] self.__align_steps = [] self.__jump = [] self.__is_jumping = [] self.__counter = 0 self.__jump_counter = 0 self.__change = 1 def __zoom_function(self, x): a = -0.45 b = 1.6 return max(1.0, a * x*x + b) def __align_function(self, x): a = 0.1 b = 0.0 c = 0.0 return max(-0.5, min(0.5, 1.0 * x)) #a * x*x + b*x + c)) def __animate(self, values, deltas): for i in xrange(len(values)): values[i] += deltas[i] def set_size(self, size): self.__zoom = [1.0] * size self.__zoom_steps = [0.0] * size self.__align = [0.0] * size self.__align_steps = [0.0] * size if (len(self.__jump) != size): self.__jump = [0.0] * size self.__is_jumping = [0] * size self.__change = 1 def hilight(self, index): f = self.__zoom_function g = self.__align_function for i in xrange(len(self.__zoom)): zoom = f(i - index) align = g(i - index) #self.__zoom[i] = zoom #self.__align[i] = align self.__zoom_steps[i] = (zoom - self.__zoom[i]) / \ float(self.__ANIM_STEPS) self.__align_steps[i] = (align - self.__align[i]) / \ float(self.__ANIM_STEPS) #end for self.__change = 1 self.__counter = 0 def unhilight(self): self.set_size(len(self.__zoom)) self.__change = 1 def jump(self, index): self.unhilight() self.__is_jumping[index] = 1 self.__jump[index] = 0.0 self.__change = 1 def animation(self, callback): if (self.__change): self.__change = 0 jump = [] for i in xrange(len(self.__is_jumping)): if (self.__is_jumping[i]): self.__jump[i] += math.pi / 12.0 jump.append(abs(math.sin(0.9 * self.__jump[i]))) if (self.__jump[i] >= 3.25 * math.pi): self.__is_jumping[i] = 0 self.__change = 1 else: jump.append(0.0) if (self.__counter < self.__ANIM_STEPS): self.__animate(self.__zoom, self.__zoom_steps) self.__animate(self.__align, self.__align_steps) self.__counter += 1 self.__change = 1 callback(self.__zoom, self.__align, jump) return 1