2009-12-07 Rolf Bjarne Kvinge <RKvinge@novell.com>
[moon.git] / class / System.Windows / System.Windows.Media.Animation / KeyTime.cs
blob95a7c64cce15c33ffceaea5b0de4d6c8f65ca6ef
1 // Contact:
2 // Moonlight List (moonlight-list@lists.ximian.com)
3 //
4 // Copyright 2007 Novell, Inc.
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sublicense, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 using System;
27 using System.Windows;
28 using System.Windows.Media;
29 using System.Windows.Input;
30 using System.Runtime.InteropServices;
31 using Mono;
33 namespace System.Windows.Media.Animation {
34 public struct KeyTime {
35 internal KeyTimeType type;
36 private int padding;
37 internal double percent;
38 internal TimeSpan time_span;
40 internal KeyTime (KeyTimeType type, double percent, TimeSpan time_span)
42 this.type = type;
43 this.percent = percent;
44 this.time_span = time_span;
45 this.padding = 0;
48 public static KeyTime FromTimeSpan(TimeSpan timeSpan)
50 return new KeyTime (KeyTimeType.TimeSpan, 0, timeSpan);
53 public static bool Equals (KeyTime keyTime1, KeyTime keyTime2)
55 return keyTime1 == keyTime2;
58 public static bool operator ==(KeyTime keyTime1, KeyTime keyTime2)
60 if (keyTime1.type != keyTime2.type)
61 return false;
63 switch (keyTime1.type) {
64 case KeyTimeType.TimeSpan:
65 return keyTime1.time_span == keyTime2.time_span;
67 return false;
70 public static bool operator !=(KeyTime keyTime1, KeyTime keyTime2)
72 return !(keyTime1 == keyTime2);
75 public bool Equals(KeyTime value)
77 return this == value;
80 public override bool Equals(object value)
82 if (value is KeyTime)
83 return this == (KeyTime) value;
85 return false;
88 public override int GetHashCode()
90 switch (type) {
91 case KeyTimeType.TimeSpan:
92 return time_span.GetHashCode ();
93 default:
94 return base.GetHashCode ();
98 public override string ToString ()
100 switch (type) {
101 case KeyTimeType.TimeSpan:
102 return time_span.ToString ();
103 case KeyTimeType.Uniform:
104 return "Uniform";
105 default:
106 return "KeyTime";
110 public static implicit operator KeyTime (TimeSpan timeSpan)
112 return KeyTime.FromTimeSpan (timeSpan);
115 public TimeSpan TimeSpan {
116 get { return time_span; }
119 public KeyTimeType Type {
120 get { return type; }
123 public static KeyTime Uniform {
124 get {
125 KeyTime result = new KeyTime ();
126 result.type = KeyTimeType.Uniform;
127 return result;