// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program 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 this program. If not, see .
*
* Authored by: Marco Trevisan
*/
#ifndef UNITY_ANIMATION_UTILS
#define UNITY_ANIMATION_UTILS
#include
namespace na = nux::animation;
namespace unity
{
namespace animation
{
enum class Direction
{
FORWARD,
BACKWARD
};
template
inline Direction GetDirection(na::AnimateValue const& animation)
{
if (animation.GetFinishValue() < animation.GetStartValue())
return Direction::BACKWARD;
return Direction::FORWARD;
}
template
inline VALUE StartValueForDirection(Direction dir)
{
return (dir == Direction::FORWARD) ? 0.0f : 1.0f;
}
template <>
inline unsigned StartValueForDirection(Direction dir)
{
return (dir == Direction::FORWARD) ? 0 : 100;
}
template <>
inline int StartValueForDirection(Direction dir)
{
return StartValueForDirection(dir);
}
template
inline VALUE FinishValueForDirection(Direction dir)
{
return StartValueForDirection(dir == Direction::FORWARD ? Direction::BACKWARD : Direction::FORWARD);
}
template
void Start(na::AnimateValue& animation, VALUE_TYPE start, VALUE_TYPE finish);
template
inline void Start(na::AnimateValue& animation, Direction dir)
{
Start(animation, StartValueForDirection(dir), FinishValueForDirection(dir));
}
template
void StartOrReverse(na::AnimateValue& animation, VALUE_TYPE start, VALUE_TYPE finish);
template
inline void StartOrReverse(na::AnimateValue& animation, Direction dir)
{
StartOrReverse(animation, StartValueForDirection(dir), FinishValueForDirection(dir));
}
template
inline void StartOrReverseIf(na::AnimateValue& animation, bool condition)
{
StartOrReverse(animation, condition ? Direction::FORWARD : Direction::BACKWARD);
}
template
inline void SetValue(na::AnimateValue& animation, VALUE const& value)
{
Start(animation, value, value);
}
template
inline void SetValue(na::AnimateValue& animation, Direction dir)
{
SetValue(animation, FinishValueForDirection(dir));
}
template
inline void Skip(na::AnimateValue& animation)
{
VALUE old_start = animation.GetStartValue();
SetValue(animation, animation.GetFinishValue());
animation.SetStartValue(old_start);
}
} // animation namespace
} // unity namespace
#include "AnimationUtils-inl.h"
#endif // UNITY_ANIMATION_UTILS