~ubuntu-branches/ubuntu/saucy/f-spot/saucy

« back to all changes in this revision

Viewing changes to lib/Hyena/src/Hyena.Gui/Hyena.Widgets/AnimatedWidget.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2010-05-24 10:35:57 UTC
  • mfrom: (2.4.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20100524103557-1j0i8f66caybci2n
Tags: 0.7.0-1
* New upstream release 0.7.0
 + First release of the unstable 0.7 development series. Massive changes.
 + Reparenting and detaching support (Anton Keks) (Closes: #559745)
 + A new Mallard-based documentation (Harold Schreckengost)
 + No longer embeds flickrnet, uses distribution copy (Iain Lane)
 + Adoption of a large amount of Hyena functionality (Paul Lange, Peter
   Goetz)
 + No longer embeds gnome-keyring-sharp
 + Completely rewritten import, much faster and less memory hungry (Ruben
   Vermeersch) (Closes: #559080, #492658, #341790, #357811, #426017) (LP:
   #412091)
 + No longer use gphoto2-sharp, now uses gvfs which is less crash-pron
   (Ruben Vermeersch)
 + Fix Facebook support (Ruben Vermeersch)
 + Modernized unit tests
 + Revamped build (Mike Gemünde)
 + Much improved duplicate detection (much faster too) (Ruben Vermeersch)
 + Mouse selection in Iconview (Vincent Pomey)
 + Image panning support using middle mouse button (Wojciech Dzierżanowski)
 + Timeline slider now restricted to the size of the window (Iain Churcher)
 + Over 100 bugs closed (http://bit.ly/cyVjnD)
   - No more warnings about schema defaults (Closes: #584215) (LP: #586132)
* debian/control: Clean up build deps to match configure checks
* debian/rules: Don't run dh_makeshilbs as we don't ship any shared
  libraries. There are some private ones though, which get picked up and
  result in a useless postinst/postrm call to ldconfig. Thanks, lintian.
* debian/patches/debian_fix-distclean.patch,
  debian/patches/debian_fix_f-spot.exe.config.patch,
  debian/patches/debian_link-system-flickrnet.patch,
  debian/patches/debian_link-system-gnome-keyring.patch,
  debian/patches/debian_disable-unit-tests,
  debian/patches/git_transition_duration.patch,
  debian/patches/ubuntu_fix_folder_export_hang.patch:
  Clean up obsolete patches which are no longer necessary 
* debian/patches/*: Temporarily disable patches which originated from Ubuntu
  and no longer apply cleanly. We will get these back in a future upstream
  development release.
* debian/patches/*: Refresh to apply cleanly 
* debian/rules: Add new include dir to autoreconf call to pick up f-spot
  macros 

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 Hyena.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
 
 
171
                if (widget_alloc.Height > 0 && widget_alloc.Width > 0) {
 
172
                    Widget.SizeAllocate (widget_alloc);
 
173
                }
 
174
            }
 
175
        }
 
176
 
 
177
        protected override bool OnExposeEvent (EventExpose evnt)
 
178
        {
 
179
            if (canvas != null) {
 
180
                GdkWindow.DrawDrawable (Style.BackgroundGC (State), canvas,
 
181
                    0, 0, widget_alloc.X, widget_alloc.Y, widget_alloc.Width, widget_alloc.Height);
 
182
                return true;
 
183
            } else {
 
184
                return base.OnExposeEvent (evnt);
 
185
            }
 
186
        }
 
187
 
 
188
        protected override void ForAll (bool include_internals, Callback callback)
 
189
        {
 
190
            if (Widget != null) {
 
191
                callback (Widget);
 
192
            }
 
193
        }
 
194
 
 
195
#endregion
 
196
 
 
197
    }
 
198
}