2
// AnimatedVboxActor.cs
5
// Scott Peterson <lunchtimemama@gmail.com>
7
// Copyright (C) 2008 Scott Peterson
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:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
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.
30
using System.Collections.Generic;
34
namespace Mono.TextEditor.Theatrics
36
internal enum AnimationState
44
internal class AnimatedWidget : Container
46
public event EventHandler WidgetDestroyed;
50
public Blocking Blocking;
51
public AnimationState AnimationState;
53
public double Bias = 1.0;
56
public int StartPadding;
57
public int EndPadding;
59
public LinkedListNode <AnimatedWidget> Node;
61
private readonly bool horizontal;
62
private double percent;
63
private Rectangle widget_alloc;
64
private Pixmap canvas;
66
public AnimatedWidget (Widget widget, uint duration, Easing easing, Blocking blocking, bool horizontal)
68
this.horizontal = horizontal;
73
AnimationState = AnimationState.Coming;
76
Widget.Destroyed += OnWidgetDestroyed;
80
protected AnimatedWidget (IntPtr raw) : base (raw)
84
public double Percent {
85
get { return percent; }
87
percent = value * Bias;
88
QueueResizeNoRedraw ();
92
private void OnWidgetDestroyed (object sender, EventArgs args)
98
canvas = new Pixmap (GdkWindow, widget_alloc.Width, widget_alloc.Height);
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);
103
canvas.DrawDrawable (Style.BackgroundGC (State), GdkWindow,
104
widget_alloc.X, widget_alloc.Y, 0, 0, widget_alloc.Width, widget_alloc.Height);
107
if (AnimationState != AnimationState.Going) {
108
WidgetDestroyed (this, args);
114
protected override void OnRemoved (Widget widget)
116
if (widget == Widget) {
122
protected override void OnRealized ()
124
WidgetFlags |= WidgetFlags.Realized;
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;
131
GdkWindow = new Gdk.Window (Parent.GdkWindow, attributes, 0);
132
GdkWindow.UserData = Handle;
133
GdkWindow.Background = Style.Background (State);
134
Style.Attach (GdkWindow);
137
protected override void OnSizeRequested (ref Requisition requisition)
139
if (Widget != null) {
140
Requisition req = Widget.SizeRequest ();
141
widget_alloc.Width = req.Width;
142
widget_alloc.Height = req.Height;
146
Width = Choreographer.PixelCompose (percent, widget_alloc.Width + StartPadding + EndPadding, Easing);
147
Height = widget_alloc.Height;
149
Width = widget_alloc.Width;
150
Height = Choreographer.PixelCompose (percent, widget_alloc.Height + StartPadding + EndPadding, Easing);
153
requisition.Width = Width;
154
requisition.Height = Height;
157
protected override void OnSizeAllocated (Rectangle allocation)
159
base.OnSizeAllocated (allocation);
160
if (Widget != null) {
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;
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;
175
if (widget_alloc.Height > 0 && widget_alloc.Width > 0) {
176
Widget.SizeAllocate (widget_alloc);
181
protected override bool OnExposeEvent (EventExpose evnt)
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);
188
return base.OnExposeEvent (evnt);
192
protected override void ForAll (bool include_internals, Callback callback)
194
if (Widget != null) {