~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-proposed

« back to all changes in this revision

Viewing changes to src/core/Mono.Texteditor/Mono.TextEditor.Theatrics/AnimatedWidget.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-07-05 13:00:05 UTC
  • mfrom: (1.2.8 upstream) (1.3.9 experimental)
  • Revision ID: james.westby@ubuntu.com-20100705130005-d6hp4k5gcn1xkj8c
Tags: 2.4+dfsg-1ubuntu1
* debian/patches/remove_support_for_moonlight.patch,
  debian/patches/dont_add_moonlight_to_core_addins.patch,
  debian/control:
  + Enable support for Moonlight
* debian/rules:
  + Ensure Moonlight addin isn't shipped in main MonoDevelop package by
    mistake

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
namespace Mono.TextEditor.Theatrics
 
35
{
 
36
    internal enum AnimationState
 
37
    {
 
38
        Coming,
 
39
        Idle,
 
40
        IntendingToGo,
 
41
        Going
 
42
    }
 
43
 
 
44
    internal class AnimatedWidget : Container
 
45
    {
 
46
        public event EventHandler WidgetDestroyed;
 
47
 
 
48
        public Widget Widget;
 
49
        public Easing Easing;
 
50
        public Blocking Blocking;
 
51
        public AnimationState AnimationState;
 
52
        public uint Duration;
 
53
        public double Bias = 1.0;
 
54
        public int Width;
 
55
        public int Height;
 
56
        public int StartPadding;
 
57
        public int EndPadding;
 
58
                
 
59
                public LinkedListNode <AnimatedWidget> Node;
 
60
 
 
61
        private readonly bool horizontal;
 
62
        private double percent;
 
63
        private Rectangle widget_alloc;
 
64
        private Pixmap canvas;
 
65
 
 
66
        public AnimatedWidget (Widget widget, uint duration, Easing easing, Blocking blocking, bool horizontal)
 
67
        {
 
68
            this.horizontal = horizontal;
 
69
            Widget = widget;
 
70
            Duration = duration;
 
71
            Easing = easing;
 
72
            Blocking = blocking;
 
73
            AnimationState = AnimationState.Coming;
 
74
 
 
75
            Widget.Parent = this;
 
76
            Widget.Destroyed += OnWidgetDestroyed;
 
77
            ShowAll ();
 
78
        }
 
79
 
 
80
        protected AnimatedWidget (IntPtr raw) : base (raw)
 
81
        {
 
82
        }
 
83
 
 
84
        public double Percent {
 
85
            get { return percent; }
 
86
            set {
 
87
                percent = value * Bias;
 
88
                QueueResizeNoRedraw ();
 
89
            }
 
90
        }
 
91
 
 
92
        private void OnWidgetDestroyed (object sender, EventArgs args)
 
93
        {
 
94
            if (!IsRealized) {
 
95
                return;
 
96
            }
 
97
 
 
98
            canvas = new Pixmap (GdkWindow, widget_alloc.Width, widget_alloc.Height);
 
99
            if (Platform.IsMac) {
 
100
                //FIXME: quick hack to make less ugly on Mac, because Mac GTK doesn't yet support offscreen drawing
 
101
                canvas.DrawRectangle (Style.BackgroundGC (State), true, 0, 0, widget_alloc.Width, widget_alloc.Height);
 
102
            } else {
 
103
                canvas.DrawDrawable (Style.BackgroundGC (State), GdkWindow,
 
104
                    widget_alloc.X, widget_alloc.Y, 0, 0, widget_alloc.Width, widget_alloc.Height);
 
105
            }
 
106
 
 
107
            if (AnimationState != AnimationState.Going) {
 
108
                WidgetDestroyed (this, args);
 
109
            }
 
110
        }
 
111
 
 
112
#region Overrides
 
113
 
 
114
        protected override void OnRemoved (Widget widget)
 
115
        {
 
116
            if (widget == Widget) {
 
117
                widget.Unparent ();
 
118
                Widget = null;
 
119
            }
 
120
        }
 
121
 
 
122
        protected override void OnRealized ()
 
123
        {
 
124
            WidgetFlags |= WidgetFlags.Realized;
 
125
 
 
126
            Gdk.WindowAttr attributes = new Gdk.WindowAttr ();
 
127
            attributes.WindowType = Gdk.WindowType.Child;
 
128
            attributes.Wclass = Gdk.WindowClass.InputOutput;
 
129
            attributes.EventMask = (int)Gdk.EventMask.ExposureMask;
 
130
 
 
131
            GdkWindow = new Gdk.Window (Parent.GdkWindow, attributes, 0);
 
132
            GdkWindow.UserData = Handle;
 
133
            GdkWindow.Background = Style.Background (State);
 
134
            Style.Attach (GdkWindow);
 
135
        }
 
136
 
 
137
        protected override void OnSizeRequested (ref Requisition requisition)
 
138
        {
 
139
            if (Widget != null) {
 
140
                Requisition req = Widget.SizeRequest ();
 
141
                widget_alloc.Width = req.Width;
 
142
                widget_alloc.Height = req.Height;
 
143
            }
 
144
 
 
145
            if (horizontal) {
 
146
                Width = Choreographer.PixelCompose (percent, widget_alloc.Width + StartPadding + EndPadding, Easing);
 
147
                Height = widget_alloc.Height;
 
148
            } else {
 
149
                Width = widget_alloc.Width;
 
150
                Height = Choreographer.PixelCompose (percent, widget_alloc.Height + StartPadding + EndPadding, Easing);
 
151
            }
 
152
 
 
153
            requisition.Width = Width;
 
154
            requisition.Height = Height;
 
155
        }
 
156
 
 
157
        protected override void OnSizeAllocated (Rectangle allocation)
 
158
        {
 
159
            base.OnSizeAllocated (allocation);
 
160
            if (Widget != null) {
 
161
                if (horizontal) {
 
162
                    widget_alloc.Height = allocation.Height;
 
163
                    widget_alloc.X = StartPadding;
 
164
                    if (Blocking == Blocking.Downstage) {
 
165
                        widget_alloc.X += allocation.Width - widget_alloc.Width;
 
166
                    }
 
167
                } else {
 
168
                    widget_alloc.Width = allocation.Width;
 
169
                    widget_alloc.Y = StartPadding;
 
170
                    if (Blocking == Blocking.Downstage) {
 
171
                        widget_alloc.Y = allocation.Height - widget_alloc.Height;
 
172
                    }
 
173
                }
 
174
 
 
175
                if (widget_alloc.Height > 0 && widget_alloc.Width > 0) {
 
176
                    Widget.SizeAllocate (widget_alloc);
 
177
                }
 
178
            }
 
179
        }
 
180
 
 
181
        protected override bool OnExposeEvent (EventExpose evnt)
 
182
        {
 
183
            if (canvas != null) {
 
184
                GdkWindow.DrawDrawable (Style.BackgroundGC (State), canvas,
 
185
                    0, 0, widget_alloc.X, widget_alloc.Y, widget_alloc.Width, widget_alloc.Height);
 
186
                return true;
 
187
            } else {
 
188
                return base.OnExposeEvent (evnt);
 
189
            }
 
190
        }
 
191
 
 
192
        protected override void ForAll (bool include_internals, Callback callback)
 
193
        {
 
194
            if (Widget != null) {
 
195
                callback (Widget);
 
196
            }
 
197
        }
 
198
 
 
199
#endregion
 
200
 
 
201
    }
 
202
}