1
// DockAnimationState.cs
3
// Copyright (C) 2008 GNOME Do
5
// This program is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program. If not, see <http://www.gnu.org/licenses/>.
20
using System.Collections.Generic;
28
namespace Docky.Interface
30
public delegate bool AnimationConditionHandler ();
32
public enum Animations {
44
public class DockAnimationState : IDisposable
46
Dictionary<Animations, AnimationConditionHandler> animation_conditions;
47
bool previous_animation_needed;
49
public bool AnimationNeeded {
51
// we will pass one additional animation requirement after none of our handlers say its needed.
52
// this is to allow these handlers to "0" on the screen, and not just be in a half finished state
53
bool animationNeeded = animation_conditions.Values.Any (handler => handler.Invoke ());
54
bool retVal = previous_animation_needed || animationNeeded;
55
previous_animation_needed = animationNeeded;
60
public DockAnimationState()
62
animation_conditions = new Dictionary<Animations, AnimationConditionHandler> ();
65
public void AddCondition (Animations id, AnimationConditionHandler handler)
67
if (animation_conditions.ContainsKey (id))
68
throw new Exception (string.Format ("Animation Condition Handler already contains callback for {0}", id));
70
animation_conditions [id] = handler;
73
public bool Contains (Animations id)
75
return animation_conditions.ContainsKey (id);
78
public bool this [Animations condition]
81
if (!animation_conditions.ContainsKey (condition))
83
return animation_conditions [condition].Invoke ();
87
public void RemoveCondition (Animations id)
89
animation_conditions.Remove (id);
92
#region IDisposable implementation
94
public void Dispose ()
96
animation_conditions.Clear ();