~dangarner/xibo/335652

« back to all changes in this revision

Viewing changes to client/dotNET/WindowAnimator.cs

  • Committer: Alex Harrington
  • Date: 2009-02-23 08:34:26 UTC
  • mfrom: (1.1.85 Xibo)
  • Revision ID: alex@longhill.org.uk-20090223083426-kdq80nu0zucqjyu0
[server] Merged from lp:~dangarner/xibo/xibo-server for 1.0.0-rc1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Xibo - Digitial Signage - http://www.xibo.org.uk
 
3
 * Copyright (C) 2006,2007,2008 Daniel Garner and James Packer
 
4
 *
 
5
 * This file is part of Xibo.
 
6
 *
 
7
 * Xibo is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU Affero General Public License as published by
 
9
 * the Free Software Foundation, either version 3 of the License, or
 
10
 * any later version. 
 
11
 *
 
12
 * Xibo is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU Affero General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Affero General Public License
 
18
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
using System;
 
21
using System.Windows.Forms;
 
22
 
 
23
namespace XiboClient
 
24
{    
 
25
    public class WindowAnimator    
 
26
    {        
 
27
        Form window;        
 
28
        float Step;        
 
29
        Timer time;
 
30
        Direction dir;
 
31
 
 
32
        public enum Direction
 
33
        {
 
34
            FadeIn, FadeOut
 
35
        }
 
36
 
 
37
        bool fadeOut = false;
 
38
        
 
39
        public WindowAnimator(Form FormToAnimate)        
 
40
        {            
 
41
            window = FormToAnimate;        
 
42
        }        
 
43
        
 
44
        public void WindowFadeIn(int interval, float steps, Direction direction)        
 
45
        {            
 
46
            //Save steps            
 
47
            Step = steps;
 
48
            
 
49
            //Create Timer            
 
50
            time = new Timer();            
 
51
            time.Interval = interval;
 
52
            if (direction == Direction.FadeIn)
 
53
            {
 
54
                time.Tick += new EventHandler(Timer_TickIn); 
 
55
            }
 
56
            else
 
57
            {
 
58
                time.Tick += new EventHandler(Timer_TickOut); 
 
59
            }
 
60
                       
 
61
            time.Start();        
 
62
        }        
 
63
        
 
64
        private void Timer_TickIn(object sender, EventArgs e)        
 
65
        {            
 
66
            //Check the Opacity of the form            
 
67
            if (window.Opacity != 1.0)            
 
68
            {                
 
69
                //Lower then 1, increment opacity                
 
70
                window.Opacity += Step;            
 
71
            }            
 
72
            else            
 
73
            {                
 
74
                //We�re finished, stop the timer                
 
75
                time.Stop();
 
76
 
 
77
                try
 
78
                {
 
79
                    FadeComplete(window);
 
80
                }
 
81
                catch { 
 
82
                    // There might not be an event handler
 
83
                }
 
84
            }        
 
85
        }
 
86
 
 
87
        private void Timer_TickOut(object sender, EventArgs e)
 
88
        {
 
89
            //Check the Opacity of the form            
 
90
            if (window.Opacity != 0.0)
 
91
            {
 
92
                //Lower then 1, increment opacity                
 
93
                window.Opacity -= Step;
 
94
            }
 
95
            else
 
96
            {
 
97
                //We�re finished, stop the timer                
 
98
                time.Stop();
 
99
 
 
100
                FadeComplete(window);
 
101
            }
 
102
        }
 
103
 
 
104
        public delegate void FadeCompleteDelegate(Form f);
 
105
        public event FadeCompleteDelegate FadeComplete;
 
106
    }
 
107
}
 
 
b'\\ No newline at end of file'