Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / MS / Internal / AnimatedTypeHelpers.cs / 1 / AnimatedTypeHelpers.cs
// AnimatedTypeHelpers.cs
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Media3D;
namespace MS.Internal.PresentationFramework
{
internal static class AnimatedTypeHelpers
{
#region Interpolation Methods
///
/// To support "By" animations and to make our internal code easily readable
/// this method will interpolate between Auto and non-Auto values treating
/// the Auto value essentially as a zero value for whatever the UnitType
/// of the other value is via the fact that Auto returns 0.0 for the Value
/// property rather than throwing an exception as a Nullable would.
///
/// If both values are Auto, we return Auto.
///
/// The from value.
/// The to value.
/// The progress value used for interpolation.
/// The interpolated value.
///
/// Thrown if one of the values is a percent and the other is not.
///
private static Double InterpolateDouble(Double from, Double to, Double progress)
{
return from + ((to - from) * progress);
}
internal static Thickness InterpolateThickness(Thickness from, Thickness to, double progress)
{
return new Thickness(
InterpolateDouble(from.Left, to.Left, progress),
InterpolateDouble(from.Top, to.Top, progress),
InterpolateDouble(from.Right, to.Right, progress),
InterpolateDouble(from.Bottom, to.Bottom, progress));
}
#endregion
#region Add Methods
private static Double AddDouble(Double value1, Double value2)
{
return value1 + value2;
}
internal static Thickness AddThickness(Thickness value1, Thickness value2)
{
return new Thickness(
AddDouble(value1.Left, value2.Left),
AddDouble(value1.Top, value2.Top),
AddDouble(value1.Right, value2.Right),
AddDouble(value1.Bottom, value2.Bottom));
}
#endregion
#region Subtract Methods
internal static Thickness SubtractThickness(Thickness value1, Thickness value2)
{
return new Thickness(
value1.Left - value2.Left,
value1.Top - value2.Top,
value1.Right - value2.Right,
value1.Bottom - value2.Bottom);
}
#endregion
#region GetSegmentLength Methods
private static Double GetSegmentLengthDouble(Double from, Double to)
{
return Math.Abs(to - from);
}
internal static double GetSegmentLengthThickness(Thickness from, Thickness to)
{
double totalLength =
Math.Pow(GetSegmentLengthDouble(from.Left, to.Left), 2.0)
+ Math.Pow(GetSegmentLengthDouble(from.Top, to.Top), 2.0)
+ Math.Pow(GetSegmentLengthDouble(from.Right, to.Right), 2.0)
+ Math.Pow(GetSegmentLengthDouble(from.Bottom, to.Bottom), 2.0);
return Math.Sqrt(totalLength);
}
#endregion
#region Scale Methods
private static Double ScaleDouble(Double value, Double factor)
{
return value * factor;
}
internal static Thickness ScaleThickness(Thickness value, double factor)
{
return new Thickness(
ScaleDouble(value.Left, factor),
ScaleDouble(value.Top, factor),
ScaleDouble(value.Right, factor),
ScaleDouble(value.Bottom, factor));
}
#endregion
#region IsValidAnimationValue Methods
private static bool IsValidAnimationValueDouble(Double value)
{
if (IsInvalidDouble(value))
{
return false;
}
return true;
}
internal static bool IsValidAnimationValueThickness(Thickness value)
{
// At least one of the sub-values must be an interpolatable length.
if ( IsValidAnimationValueDouble(value.Left)
|| IsValidAnimationValueDouble(value.Top)
|| IsValidAnimationValueDouble(value.Right)
|| IsValidAnimationValueDouble(value.Bottom))
{
return true;
}
return false;
}
#endregion
#region GetZeroValueMethods
private static Double GetZeroValueDouble(Double baseValue)
{
return 0.0;
}
internal static Thickness GetZeroValueThickness(Thickness baseValue)
{
return new Thickness(
GetZeroValueDouble(baseValue.Left),
GetZeroValueDouble(baseValue.Top),
GetZeroValueDouble(baseValue.Right),
GetZeroValueDouble(baseValue.Bottom));
}
#endregion
#region Helpers
private static bool IsInvalidDouble(double value)
{
return Double.IsInfinity(value)
|| DoubleUtil.IsNaN(value);
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
// AnimatedTypeHelpers.cs
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Media3D;
namespace MS.Internal.PresentationFramework
{
internal static class AnimatedTypeHelpers
{
#region Interpolation Methods
///
/// To support "By" animations and to make our internal code easily readable
/// this method will interpolate between Auto and non-Auto values treating
/// the Auto value essentially as a zero value for whatever the UnitType
/// of the other value is via the fact that Auto returns 0.0 for the Value
/// property rather than throwing an exception as a Nullable would.
///
/// If both values are Auto, we return Auto.
///
/// The from value.
/// The to value.
/// The progress value used for interpolation.
/// The interpolated value.
///
/// Thrown if one of the values is a percent and the other is not.
///
private static Double InterpolateDouble(Double from, Double to, Double progress)
{
return from + ((to - from) * progress);
}
internal static Thickness InterpolateThickness(Thickness from, Thickness to, double progress)
{
return new Thickness(
InterpolateDouble(from.Left, to.Left, progress),
InterpolateDouble(from.Top, to.Top, progress),
InterpolateDouble(from.Right, to.Right, progress),
InterpolateDouble(from.Bottom, to.Bottom, progress));
}
#endregion
#region Add Methods
private static Double AddDouble(Double value1, Double value2)
{
return value1 + value2;
}
internal static Thickness AddThickness(Thickness value1, Thickness value2)
{
return new Thickness(
AddDouble(value1.Left, value2.Left),
AddDouble(value1.Top, value2.Top),
AddDouble(value1.Right, value2.Right),
AddDouble(value1.Bottom, value2.Bottom));
}
#endregion
#region Subtract Methods
internal static Thickness SubtractThickness(Thickness value1, Thickness value2)
{
return new Thickness(
value1.Left - value2.Left,
value1.Top - value2.Top,
value1.Right - value2.Right,
value1.Bottom - value2.Bottom);
}
#endregion
#region GetSegmentLength Methods
private static Double GetSegmentLengthDouble(Double from, Double to)
{
return Math.Abs(to - from);
}
internal static double GetSegmentLengthThickness(Thickness from, Thickness to)
{
double totalLength =
Math.Pow(GetSegmentLengthDouble(from.Left, to.Left), 2.0)
+ Math.Pow(GetSegmentLengthDouble(from.Top, to.Top), 2.0)
+ Math.Pow(GetSegmentLengthDouble(from.Right, to.Right), 2.0)
+ Math.Pow(GetSegmentLengthDouble(from.Bottom, to.Bottom), 2.0);
return Math.Sqrt(totalLength);
}
#endregion
#region Scale Methods
private static Double ScaleDouble(Double value, Double factor)
{
return value * factor;
}
internal static Thickness ScaleThickness(Thickness value, double factor)
{
return new Thickness(
ScaleDouble(value.Left, factor),
ScaleDouble(value.Top, factor),
ScaleDouble(value.Right, factor),
ScaleDouble(value.Bottom, factor));
}
#endregion
#region IsValidAnimationValue Methods
private static bool IsValidAnimationValueDouble(Double value)
{
if (IsInvalidDouble(value))
{
return false;
}
return true;
}
internal static bool IsValidAnimationValueThickness(Thickness value)
{
// At least one of the sub-values must be an interpolatable length.
if ( IsValidAnimationValueDouble(value.Left)
|| IsValidAnimationValueDouble(value.Top)
|| IsValidAnimationValueDouble(value.Right)
|| IsValidAnimationValueDouble(value.Bottom))
{
return true;
}
return false;
}
#endregion
#region GetZeroValueMethods
private static Double GetZeroValueDouble(Double baseValue)
{
return 0.0;
}
internal static Thickness GetZeroValueThickness(Thickness baseValue)
{
return new Thickness(
GetZeroValueDouble(baseValue.Left),
GetZeroValueDouble(baseValue.Top),
GetZeroValueDouble(baseValue.Right),
GetZeroValueDouble(baseValue.Bottom));
}
#endregion
#region Helpers
private static bool IsInvalidDouble(double value)
{
return Double.IsInfinity(value)
|| DoubleUtil.IsNaN(value);
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- OracleBoolean.cs
- RadioButton.cs
- MessageDispatch.cs
- EditorPartChrome.cs
- SerializationInfo.cs
- GridItemPattern.cs
- UIElement3D.cs
- FamilyCollection.cs
- NonVisualControlAttribute.cs
- TreeViewAutomationPeer.cs
- EditorZone.cs
- InvokeGenerator.cs
- FloaterBaseParaClient.cs
- SmiEventSink_DeferedProcessing.cs
- ObjectItemConventionAssemblyLoader.cs
- XmlValueConverter.cs
- DelegatingConfigHost.cs
- DataGridLinkButton.cs
- XamlTreeBuilder.cs
- unitconverter.cs
- formatter.cs
- CodeNamespace.cs
- TypeValidationEventArgs.cs
- EnumValidator.cs
- XmlIlTypeHelper.cs
- PreservationFileWriter.cs
- GroupBoxAutomationPeer.cs
- input.cs
- ObjectDataSourceWizardForm.cs
- DesignerCatalogPartChrome.cs
- PropagatorResult.cs
- IdentityHolder.cs
- UpdatePanelTriggerCollection.cs
- UnionCodeGroup.cs
- MsmqBindingElementBase.cs
- TextSchema.cs
- ProviderConnectionPointCollection.cs
- GridViewRowEventArgs.cs
- BridgeDataRecord.cs
- ContentWrapperAttribute.cs
- CultureTableRecord.cs
- LongPath.cs
- WorkflowMarkupElementEventArgs.cs
- DynamicDataResources.Designer.cs
- coordinatorscratchpad.cs
- DataControlExtensions.cs
- LOSFormatter.cs
- Int32AnimationBase.cs
- PermissionAttributes.cs
- TableLayoutPanelResizeGlyph.cs
- ObjectListFieldsPage.cs
- DecimalKeyFrameCollection.cs
- FileClassifier.cs
- ProfileSettingsCollection.cs
- BamlResourceContent.cs
- UpdatePanelTriggerCollection.cs
- ReadOnlyPropertyMetadata.cs
- controlskin.cs
- ElementAction.cs
- ProfilePropertySettings.cs
- FileStream.cs
- ShaderEffect.cs
- RegionInfo.cs
- ProxyManager.cs
- NavigationProperty.cs
- LayoutUtils.cs
- TagNameToTypeMapper.cs
- EditingCoordinator.cs
- EndOfStreamException.cs
- SqlDataRecord.cs
- NetworkAddressChange.cs
- StaticFileHandler.cs
- FaultHandlingFilter.cs
- HelpProvider.cs
- SafeLibraryHandle.cs
- DataBindingList.cs
- APCustomTypeDescriptor.cs
- InputMethodStateTypeInfo.cs
- TreeIterator.cs
- MediaTimeline.cs
- BaseDataList.cs
- SqlConnectionPoolProviderInfo.cs
- ZipIOLocalFileBlock.cs
- ProxyWebPartManager.cs
- TextBox.cs
- ArrayElementGridEntry.cs
- _ScatterGatherBuffers.cs
- ParameterModifier.cs
- LicenseContext.cs
- ObjectMemberMapping.cs
- PassportAuthenticationEventArgs.cs
- EndpointAddressMessageFilterTable.cs
- AttributeAction.cs
- XmlSchemaSimpleContentExtension.cs
- DbgUtil.cs
- ConfigurationStrings.cs
- nulltextnavigator.cs
- ListenerAdaptersInstallComponent.cs
- HttpRequestTraceRecord.cs
- BitmapEffect.cs