Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémie Laval <jeremie.laval@gmail.com>2013-07-15 22:37:27 +0400
committerJérémie Laval <jeremie.laval@gmail.com>2013-07-15 22:37:27 +0400
commiteef7a88b29df4ddccb94e61d9eba6b20c0c33f3a (patch)
tree8e62f28bb44d7b0e8474646136a8e81f7ce22ae0 /Xwt/Xwt.Motion
parentbfb3077c3df6d1c8da98565f3177c6615a28c939 (diff)
[Xwt.Motion] Add standard Xwt object interpolators
Diffstat (limited to 'Xwt/Xwt.Motion')
-rw-r--r--Xwt/Xwt.Motion/ObjectTransforms.cs66
1 files changed, 66 insertions, 0 deletions
diff --git a/Xwt/Xwt.Motion/ObjectTransforms.cs b/Xwt/Xwt.Motion/ObjectTransforms.cs
new file mode 100644
index 00000000..9a74d4c8
--- /dev/null
+++ b/Xwt/Xwt.Motion/ObjectTransforms.cs
@@ -0,0 +1,66 @@
+//
+// ObjectInterpolators.cs
+//
+// Author:
+// Jérémie Laval <jeremie dotlaval at gmail dot com>
+//
+// Copyright (c) 2013 Jérémie Laval
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using Xwt.Drawing;
+
+namespace Xwt.Motion
+{
+ public static class ObjectTransforms
+ {
+ public static Func<double, Color> GetColorTransform (Color initialColor, Color endColor)
+ {
+ return ratio => new Color (Interpolate (ratio, initialColor.Red, endColor.Red),
+ Interpolate (ratio, initialColor.Green, endColor.Green),
+ Interpolate (ratio, initialColor.Blue, endColor.Blue),
+ Interpolate (ratio, initialColor.Alpha, endColor.Alpha));
+ }
+
+ public static Func<double, Point> GetPointTransform (Point initialPoint, Point endPoint)
+ {
+ return ratio => new Point (Interpolate (ratio, initialPoint.X, endPoint.X),
+ Interpolate (ratio, initialPoint.Y, endPoint.Y));
+ }
+
+ public static Func<double, Size> GetSizeTransform (Size initialSize, Size endSize)
+ {
+ return ratio => new Size (Interpolate (ratio, initialSize.Width, endSize.Width),
+ Interpolate (ratio, initialSize.Height, endSize.Height));
+ }
+
+ public static Func<double, Rectangle> GetRectangleTransform (Rectangle initialRectangle, Rectangle endRectangle)
+ {
+ return ratio => new Rectangle (Interpolate (ratio, initialRectangle.X, endRectangle.X),
+ Interpolate (ratio, initialRectangle.Y, endRectangle.Y),
+ Interpolate (ratio, initialRectangle.Width, endRectangle.Width),
+ Interpolate (ratio, initialRectangle.Height, endRectangle.Height));
+ }
+
+ static double Interpolate (double ratio, double beginValue, double endValue)
+ {
+ return beginValue - (endValue - beginValue) * ratio;
+ }
+ }
+}