Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / Media / LinearGradientBrush.cs / 1305600 / LinearGradientBrush.cs
//----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Description: This file contains the implementation of LinearGradientBrush.
// The LinearGradientBrush is a GradientBrush which defines its
// Gradient as a linear interpolation between two parallel lines.
//
// History:
// 05/07/2003 : [....] - Created it.
// 09/21/2004 : timothyc - Added GradientStopCollection constructors.
//
//---------------------------------------------------------------------------
using MS.Internal;
using MS.Internal.PresentationCore;
using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics;
using System.Reflection;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Runtime.InteropServices;
using System.Windows.Media.Composition;
using System.Security;
using System.Security.Permissions;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
namespace System.Windows.Media
{
///
/// LinearGradientBrush - This GradientBrush defines its Gradient as an interpolation
/// between two parallel lines.
///
public sealed partial class LinearGradientBrush : GradientBrush
{
#region Constructors
///
/// Default constructor for LinearGradientBrush. The resulting brush has no content.
///
public LinearGradientBrush() : base()
{
}
///
/// LinearGradientBrush Constructor
/// Constructs a LinearGradientBrush with GradientStops specified at offset 0.0 and
/// 1.0. The StartPoint is set to (0,0) and the EndPoint is derived from the angle
/// such that 1) the line containing the StartPoint and EndPoint is 'angle' degrees
/// from the horizontal in the direction of positive Y, and 2) the EndPoint lies on
/// the perimeter of the unit circle.
///
/// The Color at offset 0.0.
/// The Color at offset 1.0.
/// The angle, in degrees, that the gradient will be away from horizontal.
public LinearGradientBrush(Color startColor,
Color endColor,
double angle) : base()
{
EndPoint = EndPointFromAngle(angle);
GradientStops.Add(new GradientStop(startColor, 0.0));
GradientStops.Add(new GradientStop(endColor, 1.0));
}
///
/// LinearGradientBrush Constructor
/// Constructs a LinearGradientBrush with two colors at the specified start and end points.
///
/// The Color at offset 0.0.
/// The Color at offset 1.0.
/// The start point
/// The end point
public LinearGradientBrush(Color startColor,
Color endColor,
Point startPoint,
Point endPoint) : base()
{
StartPoint = startPoint;
EndPoint = endPoint;
GradientStops.Add(new GradientStop(startColor, 0.0));
GradientStops.Add(new GradientStop(endColor, 1.0));
}
///
/// LinearGradientBrush Constructor
/// Constructs a LinearGradientBrush with GradientStops set to the passed-in collection.
///
/// GradientStopCollection to set on this brush.
public LinearGradientBrush(GradientStopCollection gradientStopCollection)
: base (gradientStopCollection)
{
}
///
/// LinearGradientBrush Constructor
/// Constructs a LinearGradientBrush with GradientStops set to the passed-in collection.
/// Constructs a LinearGradientBrush with GradientStops specified at offset 0.0 and
/// 1.0. The StartPoint is set to (0,0) and the EndPoint is derived from the angle
/// such that 1) the line containing the StartPoint and EndPoint is 'angle' degrees
/// from the horizontal in the direction of positive Y, and 2) the EndPoint lies on
/// the perimeter of the unit circle.
///
/// GradientStopCollection to set on this brush.
/// The angle, in degrees, that the gradient will be away from horizontal.
public LinearGradientBrush(GradientStopCollection gradientStopCollection,
double angle) : base (gradientStopCollection)
{
EndPoint = EndPointFromAngle(angle);
}
///
/// LinearGradientBrush Constructor
/// Constructs a LinearGradientBrush with GradientStops set to the passed-in collection.
/// The StartPoint and EndPoint are set to the specified startPoint and endPoint.
///
/// GradientStopCollection to set on this brush.
/// The start point
/// The end point
public LinearGradientBrush(GradientStopCollection gradientStopCollection,
Point startPoint,
Point endPoint) : base (gradientStopCollection)
{
StartPoint = startPoint;
EndPoint = endPoint;
}
#endregion Constructors
///
/// Critical: This code accesses unsafe code blocks
/// TreatAsSafe: This code does is safe to call but needs to be verified for correctness
///
[SecurityCritical, SecurityTreatAsSafe]
private void ManualUpdateResource(DUCE.Channel channel, bool skipOnChannelCheck)
{
// If we're told we can skip the channel check, then we must be on channel
Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel));
if (skipOnChannelCheck || _duceResource.IsOnChannel(channel))
{
Transform vTransform = Transform;
Transform vRelativeTransform = RelativeTransform;
GradientStopCollection vGradientStops = GradientStops;
DUCE.ResourceHandle hTransform;
if (vTransform == null ||
Object.ReferenceEquals(vTransform, Transform.Identity)
)
{
hTransform = DUCE.ResourceHandle.Null;
}
else
{
hTransform = ((DUCE.IResource)vTransform).GetHandle(channel);
}
DUCE.ResourceHandle hRelativeTransform;
if (vRelativeTransform == null ||
Object.ReferenceEquals(vRelativeTransform, Transform.Identity)
)
{
hRelativeTransform = DUCE.ResourceHandle.Null;
}
else
{
hRelativeTransform = ((DUCE.IResource)vRelativeTransform).GetHandle(channel);
}
DUCE.ResourceHandle hOpacityAnimations = GetAnimationResourceHandle(OpacityProperty, channel);
DUCE.ResourceHandle hStartPointAnimations = GetAnimationResourceHandle(StartPointProperty, channel);
DUCE.ResourceHandle hEndPointAnimations = GetAnimationResourceHandle(EndPointProperty, channel);
unsafe
{
DUCE.MILCMD_LINEARGRADIENTBRUSH data;
data.Type = MILCMD.MilCmdLinearGradientBrush;
data.Handle = _duceResource.GetHandle(channel);
double tempOpacity = Opacity;
DUCE.CopyBytes((byte*)&data.Opacity, (byte*)&tempOpacity, 8);
data.hOpacityAnimations = hOpacityAnimations;
data.hTransform = hTransform;
data.hRelativeTransform = hRelativeTransform;
data.ColorInterpolationMode = ColorInterpolationMode;
data.MappingMode = MappingMode;
data.SpreadMethod = SpreadMethod;
Point tempStartPoint = StartPoint;
DUCE.CopyBytes((byte*)&data.StartPoint, (byte*)&tempStartPoint, 16);
data.hStartPointAnimations = hStartPointAnimations;
Point tempEndPoint = EndPoint;
DUCE.CopyBytes((byte*)&data.EndPoint, (byte*)&tempEndPoint, 16);
data.hEndPointAnimations = hEndPointAnimations;
// NTRAID#Longhorn-1011154-2004/8/12-asecchia GradientStopCollection: Need to enforce upper-limit of gradient stop capacity
int count = (vGradientStops == null) ? 0 : vGradientStops.Count;
data.GradientStopsSize = (UInt32)(sizeof(DUCE.MIL_GRADIENTSTOP)*count);
channel.BeginCommand(
(byte*)&data,
sizeof(DUCE.MILCMD_LINEARGRADIENTBRUSH),
sizeof(DUCE.MIL_GRADIENTSTOP)*count
);
for (int i=0; i
/// LinearGradientBrush - This GradientBrush defines its Gradient as an interpolation
/// between two parallel lines.
///
public sealed partial class LinearGradientBrush : GradientBrush
{
#region Constructors
///
/// Default constructor for LinearGradientBrush. The resulting brush has no content.
///
public LinearGradientBrush() : base()
{
}
///
/// LinearGradientBrush Constructor
/// Constructs a LinearGradientBrush with GradientStops specified at offset 0.0 and
/// 1.0. The StartPoint is set to (0,0) and the EndPoint is derived from the angle
/// such that 1) the line containing the StartPoint and EndPoint is 'angle' degrees
/// from the horizontal in the direction of positive Y, and 2) the EndPoint lies on
/// the perimeter of the unit circle.
///
/// The Color at offset 0.0.
/// The Color at offset 1.0.
/// The angle, in degrees, that the gradient will be away from horizontal.
public LinearGradientBrush(Color startColor,
Color endColor,
double angle) : base()
{
EndPoint = EndPointFromAngle(angle);
GradientStops.Add(new GradientStop(startColor, 0.0));
GradientStops.Add(new GradientStop(endColor, 1.0));
}
///
/// LinearGradientBrush Constructor
/// Constructs a LinearGradientBrush with two colors at the specified start and end points.
///
/// The Color at offset 0.0.
/// The Color at offset 1.0.
/// The start point
/// The end point
public LinearGradientBrush(Color startColor,
Color endColor,
Point startPoint,
Point endPoint) : base()
{
StartPoint = startPoint;
EndPoint = endPoint;
GradientStops.Add(new GradientStop(startColor, 0.0));
GradientStops.Add(new GradientStop(endColor, 1.0));
}
///
/// LinearGradientBrush Constructor
/// Constructs a LinearGradientBrush with GradientStops set to the passed-in collection.
///
/// GradientStopCollection to set on this brush.
public LinearGradientBrush(GradientStopCollection gradientStopCollection)
: base (gradientStopCollection)
{
}
///
/// LinearGradientBrush Constructor
/// Constructs a LinearGradientBrush with GradientStops set to the passed-in collection.
/// Constructs a LinearGradientBrush with GradientStops specified at offset 0.0 and
/// 1.0. The StartPoint is set to (0,0) and the EndPoint is derived from the angle
/// such that 1) the line containing the StartPoint and EndPoint is 'angle' degrees
/// from the horizontal in the direction of positive Y, and 2) the EndPoint lies on
/// the perimeter of the unit circle.
///
/// GradientStopCollection to set on this brush.
/// The angle, in degrees, that the gradient will be away from horizontal.
public LinearGradientBrush(GradientStopCollection gradientStopCollection,
double angle) : base (gradientStopCollection)
{
EndPoint = EndPointFromAngle(angle);
}
///
/// LinearGradientBrush Constructor
/// Constructs a LinearGradientBrush with GradientStops set to the passed-in collection.
/// The StartPoint and EndPoint are set to the specified startPoint and endPoint.
///
/// GradientStopCollection to set on this brush.
/// The start point
/// The end point
public LinearGradientBrush(GradientStopCollection gradientStopCollection,
Point startPoint,
Point endPoint) : base (gradientStopCollection)
{
StartPoint = startPoint;
EndPoint = endPoint;
}
#endregion Constructors
///
/// Critical: This code accesses unsafe code blocks
/// TreatAsSafe: This code does is safe to call but needs to be verified for correctness
///
[SecurityCritical, SecurityTreatAsSafe]
private void ManualUpdateResource(DUCE.Channel channel, bool skipOnChannelCheck)
{
// If we're told we can skip the channel check, then we must be on channel
Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel));
if (skipOnChannelCheck || _duceResource.IsOnChannel(channel))
{
Transform vTransform = Transform;
Transform vRelativeTransform = RelativeTransform;
GradientStopCollection vGradientStops = GradientStops;
DUCE.ResourceHandle hTransform;
if (vTransform == null ||
Object.ReferenceEquals(vTransform, Transform.Identity)
)
{
hTransform = DUCE.ResourceHandle.Null;
}
else
{
hTransform = ((DUCE.IResource)vTransform).GetHandle(channel);
}
DUCE.ResourceHandle hRelativeTransform;
if (vRelativeTransform == null ||
Object.ReferenceEquals(vRelativeTransform, Transform.Identity)
)
{
hRelativeTransform = DUCE.ResourceHandle.Null;
}
else
{
hRelativeTransform = ((DUCE.IResource)vRelativeTransform).GetHandle(channel);
}
DUCE.ResourceHandle hOpacityAnimations = GetAnimationResourceHandle(OpacityProperty, channel);
DUCE.ResourceHandle hStartPointAnimations = GetAnimationResourceHandle(StartPointProperty, channel);
DUCE.ResourceHandle hEndPointAnimations = GetAnimationResourceHandle(EndPointProperty, channel);
unsafe
{
DUCE.MILCMD_LINEARGRADIENTBRUSH data;
data.Type = MILCMD.MilCmdLinearGradientBrush;
data.Handle = _duceResource.GetHandle(channel);
double tempOpacity = Opacity;
DUCE.CopyBytes((byte*)&data.Opacity, (byte*)&tempOpacity, 8);
data.hOpacityAnimations = hOpacityAnimations;
data.hTransform = hTransform;
data.hRelativeTransform = hRelativeTransform;
data.ColorInterpolationMode = ColorInterpolationMode;
data.MappingMode = MappingMode;
data.SpreadMethod = SpreadMethod;
Point tempStartPoint = StartPoint;
DUCE.CopyBytes((byte*)&data.StartPoint, (byte*)&tempStartPoint, 16);
data.hStartPointAnimations = hStartPointAnimations;
Point tempEndPoint = EndPoint;
DUCE.CopyBytes((byte*)&data.EndPoint, (byte*)&tempEndPoint, 16);
data.hEndPointAnimations = hEndPointAnimations;
// NTRAID#Longhorn-1011154-2004/8/12-asecchia GradientStopCollection: Need to enforce upper-limit of gradient stop capacity
int count = (vGradientStops == null) ? 0 : vGradientStops.Count;
data.GradientStopsSize = (UInt32)(sizeof(DUCE.MIL_GRADIENTSTOP)*count);
channel.BeginCommand(
(byte*)&data,
sizeof(DUCE.MILCMD_LINEARGRADIENTBRUSH),
sizeof(DUCE.MIL_GRADIENTSTOP)*count
);
for (int i=0; i
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SettingsPropertyWrongTypeException.cs
- VerticalAlignConverter.cs
- FatalException.cs
- ListBindingConverter.cs
- IndexOutOfRangeException.cs
- InvalidPipelineStoreException.cs
- RegexWriter.cs
- RowSpanVector.cs
- GridErrorDlg.cs
- coordinatorfactory.cs
- BufferedGraphicsContext.cs
- TraceHwndHost.cs
- Visual3D.cs
- PresentationSource.cs
- wgx_render.cs
- AsnEncodedData.cs
- CompositeControl.cs
- Pen.cs
- AttachedAnnotationChangedEventArgs.cs
- Rotation3DKeyFrameCollection.cs
- SemanticBasicElement.cs
- NetworkInformationPermission.cs
- DelimitedListTraceListener.cs
- ProfileSection.cs
- FormClosedEvent.cs
- CrossSiteScriptingValidation.cs
- EntryIndex.cs
- CodeFieldReferenceExpression.cs
- TextBounds.cs
- TemplateBindingExpressionConverter.cs
- BitmapCacheBrush.cs
- Overlapped.cs
- UpdatePanel.cs
- AccessKeyManager.cs
- ArgumentDirectionHelper.cs
- regiisutil.cs
- ComplexObject.cs
- DataContractJsonSerializerOperationFormatter.cs
- SerializationInfo.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- ScriptingScriptResourceHandlerSection.cs
- LinqDataSourceHelper.cs
- StringAttributeCollection.cs
- InputProcessorProfilesLoader.cs
- EventBuilder.cs
- StaticSiteMapProvider.cs
- SmtpNtlmAuthenticationModule.cs
- GPPOINTF.cs
- SqlDelegatedTransaction.cs
- PriorityQueue.cs
- XmlSchemas.cs
- LoginCancelEventArgs.cs
- SupportsPreviewControlAttribute.cs
- SecurityContextTokenCache.cs
- ConfigPathUtility.cs
- StylusPointPropertyInfoDefaults.cs
- Helpers.cs
- ManifestResourceInfo.cs
- OdbcConnectionStringbuilder.cs
- CodePropertyReferenceExpression.cs
- SizeIndependentAnimationStorage.cs
- IIS7WorkerRequest.cs
- ImageIndexConverter.cs
- AncestorChangedEventArgs.cs
- TableItemStyle.cs
- ColorConvertedBitmapExtension.cs
- ProcessModuleCollection.cs
- DeliveryStrategy.cs
- ReadOnlyHierarchicalDataSourceView.cs
- CircleHotSpot.cs
- LinkedResourceCollection.cs
- TemplateControl.cs
- TriggerAction.cs
- CodeTypeParameterCollection.cs
- PeerContact.cs
- ValidationErrorCollection.cs
- XmlFormatWriterGenerator.cs
- shaperfactory.cs
- XsltInput.cs
- precedingsibling.cs
- ListDictionary.cs
- AttributeConverter.cs
- BitmapEffect.cs
- XmlSerializerImportOptions.cs
- DecimalConverter.cs
- ControlEvent.cs
- XsltLibrary.cs
- SpellerStatusTable.cs
- XmlArrayItemAttribute.cs
- nulltextcontainer.cs
- EntityModelBuildProvider.cs
- PermissionListSet.cs
- ServicePointManagerElement.cs
- AccessDataSourceView.cs
- EventToken.cs
- ForeignKeyFactory.cs
- EdgeModeValidation.cs
- SqlClientWrapperSmiStream.cs
- RunInstallerAttribute.cs
- BlurBitmapEffect.cs