~ubuntu-branches/ubuntu/lucid/docky/lucid-proposed

« back to all changes in this revision

Viewing changes to Docky.Widgets/Docky.Widgets/AnimatedWidget.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2010-02-17 15:10:07 UTC
  • Revision ID: james.westby@ubuntu.com-20100217151007-msxpd0lsj300ndde
Tags: upstream-2.0.0
ImportĀ upstreamĀ versionĀ 2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// AnimatedVboxActor.cs
 
3
//
 
4
// Authors:
 
5
//   Scott Peterson <lunchtimemama@gmail.com>
 
6
//
 
7
// Copyright (C) 2008 Scott Peterson
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
//
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
//
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
using System;
 
30
using System.Collections.Generic;
 
31
using Gdk;
 
32
using Gtk;
 
33
 
 
34
//using Hyena.Gui.Theatrics;
 
35
 
 
36
namespace Docky.Widgets
 
37
{
 
38
        internal enum AnimationState
 
39
        {
 
40
                Coming,
 
41
                Idle,
 
42
                IntendingToGo,
 
43
                Going
 
44
        }
 
45
        
 
46
        internal class AnimatedWidget : Container
 
47
        {
 
48
                public event EventHandler WidgetDestroyed;
 
49
                
 
50
                public Widget Widget;
 
51
                public Easing Easing;
 
52
                public Blocking Blocking;
 
53
                public AnimationState AnimationState;
 
54
                public uint Duration;
 
55
                public double Bias = 1.0;
 
56
                public int Width;
 
57
                public int Height;
 
58
                public int StartPadding;
 
59
                public int EndPadding;
 
60
                public LinkedListNode <AnimatedWidget> Node;
 
61
                
 
62
                private readonly bool horizontal;
 
63
                private double percent;
 
64
                private Rectangle widget_alloc;
 
65
                private Pixmap canvas;
 
66
                
 
67
                public AnimatedWidget (Widget widget, uint duration, Easing easing, Blocking blocking, bool horizontal)
 
68
                {
 
69
                        this.horizontal = horizontal;
 
70
                        Widget = widget;
 
71
                        Duration = duration;
 
72
                        Easing = easing;
 
73
                        Blocking = blocking;
 
74
                        AnimationState = AnimationState.Coming;
 
75
                        
 
76
                        Widget.Parent = this;
 
77
                        Widget.Destroyed += OnWidgetDestroyed;
 
78
                        ShowAll ();
 
79
                }
 
80
                
 
81
                protected AnimatedWidget (IntPtr raw) : base (raw)
 
82
                {
 
83
                }
 
84
                
 
85
                public double Percent {
 
86
                        get { return percent; }
 
87
                        set {
 
88
                                percent = value * Bias;
 
89
                                QueueResizeNoRedraw ();
 
90
                        }
 
91
                }
 
92
                
 
93
                private void OnWidgetDestroyed (object sender, EventArgs args)
 
94
                {
 
95
                        if (!IsRealized) {
 
96
                                return;
 
97
                        }
 
98
                        
 
99
                        canvas = new Pixmap (GdkWindow, widget_alloc.Width, widget_alloc.Height);
 
100
                        canvas.DrawDrawable (Style.BackgroundGC (State), GdkWindow,
 
101
                                             widget_alloc.X, widget_alloc.Y, 0, 0, widget_alloc.Width, widget_alloc.Height);
 
102
                        
 
103
                        if (AnimationState != AnimationState.Going) {
 
104
                                WidgetDestroyed (this, args);
 
105
                        }
 
106
                }
 
107
                
 
108
                #region Overrides
 
109
                
 
110
                protected override void OnRemoved (Widget widget)
 
111
                {
 
112
                        if (widget == Widget) {
 
113
                                widget.Unparent ();
 
114
                                Widget = null;
 
115
                        }
 
116
                }
 
117
                
 
118
                protected override void OnRealized ()
 
119
                {
 
120
                        WidgetFlags |= WidgetFlags.Realized;
 
121
                        
 
122
                        Gdk.WindowAttr attributes = new Gdk.WindowAttr ();
 
123
                        attributes.WindowType = Gdk.WindowType.Child;
 
124
                        attributes.Wclass = Gdk.WindowClass.InputOutput;
 
125
                        attributes.EventMask = (int)Gdk.EventMask.ExposureMask;
 
126
                        
 
127
                        GdkWindow = new Gdk.Window (Parent.GdkWindow, attributes, 0);
 
128
                        GdkWindow.UserData = Handle;
 
129
                        GdkWindow.Background = Style.Background (State);
 
130
                        Style.Attach (GdkWindow);
 
131
                }
 
132
                
 
133
                protected override void OnSizeRequested (ref Requisition requisition)
 
134
                {
 
135
                        if (Widget != null) {
 
136
                                Requisition req = Widget.SizeRequest ();
 
137
                                widget_alloc.Width = req.Width;
 
138
                                widget_alloc.Height = req.Height;
 
139
                        }
 
140
                        
 
141
                        if (horizontal) {
 
142
                                Width = Choreographer.PixelCompose (percent, widget_alloc.Width + StartPadding + EndPadding, Easing);
 
143
                                Height = widget_alloc.Height;
 
144
                        } else {
 
145
                                Width = widget_alloc.Width;
 
146
                                Height = Choreographer.PixelCompose (percent, widget_alloc.Height + StartPadding + EndPadding, Easing);
 
147
                        }
 
148
                        
 
149
                        requisition.Width = Width;
 
150
                        requisition.Height = Height;
 
151
                }
 
152
                
 
153
                protected override void OnSizeAllocated (Rectangle allocation)
 
154
                {
 
155
                        base.OnSizeAllocated (allocation);
 
156
                        if (Widget != null) {
 
157
                                if (horizontal) {
 
158
                                        widget_alloc.Height = allocation.Height;
 
159
                                        widget_alloc.X = StartPadding;
 
160
                                        if (Blocking == Blocking.Downstage) {
 
161
                                                widget_alloc.X += allocation.Width - widget_alloc.Width;
 
162
                                        }
 
163
                                } else {
 
164
                                        widget_alloc.Width = allocation.Width;
 
165
                                        widget_alloc.Y = StartPadding;
 
166
                                        if (Blocking == Blocking.Downstage) {
 
167
                                                widget_alloc.Y = allocation.Height - widget_alloc.Height;
 
168
                                        }
 
169
                                }
 
170
                                Widget.SizeAllocate (widget_alloc);
 
171
                        }
 
172
                }
 
173
                
 
174
                protected override bool OnExposeEvent (EventExpose evnt)
 
175
                {
 
176
                        if (canvas != null) {
 
177
                                GdkWindow.DrawDrawable (Style.BackgroundGC (State), canvas,
 
178
                                                        0, 0, widget_alloc.X, widget_alloc.Y, widget_alloc.Width, widget_alloc.Height);
 
179
                                return true;
 
180
                        } else {
 
181
                                return base.OnExposeEvent (evnt);
 
182
                        }
 
183
                }
 
184
                
 
185
                protected override void ForAll (bool include_internals, Callback callback)
 
186
                {
 
187
                        if (Widget != null) {
 
188
                                callback (Widget);
 
189
                        }
 
190
                }
 
191
                
 
192
                #endregion
 
193
                
 
194
        }
 
195
}
 
 
b'\\ No newline at end of file'