~and471/+junk/do-with-docky

« back to all changes in this revision

Viewing changes to Do.Interface.Linux.Docky/src/Docky.Interface/DockAnimationState.cs

  • Committer: rugby471 at gmail
  • Date: 2010-10-15 16:08:38 UTC
  • Revision ID: rugby471@gmail.com-20101015160838-z9m3utbf7bxzb5ty
reverted to before docky removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// DockAnimationState.cs
 
2
// 
 
3
// Copyright (C) 2008 GNOME Do
 
4
//
 
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.
 
9
//
 
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.
 
14
//
 
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/>.
 
17
//
 
18
 
 
19
using System;
 
20
using System.Collections.Generic;
 
21
using System.Linq;
 
22
 
 
23
using Do;
 
24
using Do.Interface;
 
25
using Do.Platform;
 
26
using Do.Universe;
 
27
 
 
28
namespace Docky.Interface
 
29
{
 
30
        public delegate bool AnimationConditionHandler ();
 
31
        
 
32
        public enum Animations {
 
33
                Open,
 
34
                Zoom,
 
35
                Bounce,
 
36
                Painter,
 
37
                Summon,
 
38
                IconInsert,
 
39
                UrgencyChanged,
 
40
                InputModeChanged,
 
41
                ActiveWindowChanged,
 
42
        }
 
43
        
 
44
        public class DockAnimationState : IDisposable
 
45
        {
 
46
                Dictionary<Animations, AnimationConditionHandler> animation_conditions;
 
47
                bool previous_animation_needed;
 
48
                
 
49
                public bool AnimationNeeded {
 
50
                        get {
 
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;
 
56
                                return retVal;
 
57
                        }
 
58
                }
 
59
                
 
60
                public DockAnimationState()
 
61
                {
 
62
                        animation_conditions = new Dictionary<Animations, AnimationConditionHandler> ();
 
63
                }
 
64
                
 
65
                public void AddCondition (Animations id, AnimationConditionHandler handler)
 
66
                {
 
67
                        if (animation_conditions.ContainsKey (id))
 
68
                                throw new Exception (string.Format ("Animation Condition Handler already contains callback for {0}", id));
 
69
                        
 
70
                        animation_conditions [id] = handler;
 
71
                }
 
72
 
 
73
                public bool Contains (Animations id)
 
74
                {
 
75
                        return animation_conditions.ContainsKey (id);
 
76
                }
 
77
                
 
78
                public bool this [Animations condition]
 
79
                {
 
80
                        get { 
 
81
                                if (!animation_conditions.ContainsKey (condition))
 
82
                                        return false;
 
83
                                return animation_conditions [condition].Invoke (); 
 
84
                        }
 
85
                }
 
86
                
 
87
                public void RemoveCondition (Animations id)
 
88
                {
 
89
                        animation_conditions.Remove (id);
 
90
                }
 
91
 
 
92
                #region IDisposable implementation 
 
93
                
 
94
                public void Dispose ()
 
95
                {
 
96
                        animation_conditions.Clear ();
 
97
                }
 
98
                
 
99
                #endregion 
 
100
                
 
101
        }
 
102
}