Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / System / Windows / Shapes / ellipse.cs / 1 / ellipse.cs
//----------------------------------------------------------------------------
// File: Ellipse.cs
//
// Description:
// Implementation of Ellipse shape element.
//
// History:
// 05/30/02 - AdSmith - Created.
//
// Copyright (C) 2003 by Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System.Windows.Shapes;
using System.Diagnostics;
using System.Windows.Threading;
using System.Windows;
using System.Windows.Media;
using MS.Internal;
using System.ComponentModel;
using System;
namespace System.Windows.Shapes
{
///
/// The ellipse shape element
/// This element (like all shapes) belongs under a Canvas,
/// and will be presented by the parent canvas.
///
///
public sealed class Ellipse : Shape
{
#region Constructors
///
/// Instantiates a new instance of a Ellipse.
///
///
public Ellipse()
{
}
// The default stretch mode of Ellipse is Fill
static Ellipse()
{
StretchProperty.OverrideMetadata(typeof(Ellipse), new FrameworkPropertyMetadata(Stretch.Fill));
}
#endregion Constructors
#region Dynamic Properties
// For an Ellipse, RenderedGeometry = defining geometry and GeometryTransform = Identity
///
/// The RenderedGeometry property returns the final rendered geometry
///
public override Geometry RenderedGeometry
{
get
{
// RenderedGeometry = defining geometry
return DefiningGeometry;
}
}
///
/// Return the transformation applied to the geometry before rendering
///
public override Transform GeometryTransform
{
get
{
return Transform.Identity;
}
}
#endregion Dynamic Properties
#region Protected
///
/// Updates DesiredSize of the Ellipse. Called by parent UIElement. This is the first pass of layout.
///
/// Constraint size is an "upper limit" that Ellipse should not exceed.
/// Ellipse's desired size.
protected override Size MeasureOverride(Size constraint)
{
if (Stretch == Stretch.UniformToFill)
{
double width = constraint.Width;
double height = constraint.Height;
if (Double.IsInfinity(width) && Double.IsInfinity(height))
{
return GetNaturalSize();
}
else if (Double.IsInfinity(width) || Double.IsInfinity(height))
{
width = Math.Min(width, height);
}
else
{
width = Math.Max(width, height);
}
return new Size(width, width);
}
return GetNaturalSize();
}
///
/// Returns the final size of the shape and caches the bounds.
///
protected override Size ArrangeOverride(Size finalSize)
{
// We construct the rectangle to fit finalSize with the appropriate Stretch mode. The rendering
// transformation will thus be the identity.
double penThickness = GetStrokeThickness();
double margin = penThickness / 2;
_rect = new Rect(
margin, // X
margin, // Y
Math.Max(0, finalSize.Width - penThickness), // Width
Math.Max(0, finalSize.Height - penThickness)); // Height
switch (Stretch)
{
case Stretch.None:
// A 0 Rect.Width and Rect.Height rectangle
_rect.Width = _rect.Height = 0;
break;
case Stretch.Fill:
// The most common case: a rectangle that fills the box.
// _rect has already been initialized for that.
break;
case Stretch.Uniform:
// The maximal square that fits in the final box
if (_rect.Width > _rect.Height)
{
_rect.Width = _rect.Height;
}
else // _rect.Width <= _rect.Height
{
_rect.Height = _rect.Width;
}
break;
case Stretch.UniformToFill:
// The minimal square that fills the final box
if (_rect.Width < _rect.Height)
{
_rect.Width = _rect.Height;
}
else // _rect.Width >= _rect.Height
{
_rect.Height = _rect.Width;
}
break;
}
ResetRenderedGeometry();
return finalSize;
}
///
/// Get the ellipse that defines this shape
///
protected override Geometry DefiningGeometry
{
get
{
if (_rect.IsEmpty)
{
return Geometry.Empty;
}
return new EllipseGeometry(_rect);
}
}
///
/// Render callback.
///
protected override void OnRender(DrawingContext drawingContext)
{
if (!_rect.IsEmpty)
{
Pen pen = GetPen();
drawingContext.DrawGeometry(Fill, pen, new EllipseGeometry(_rect));
}
}
#endregion Protected
#region Internal Methods
internal override void CacheDefiningGeometry()
{
double margin = GetStrokeThickness() / 2;
_rect = new Rect(margin, margin, 0, 0);
}
///
/// Get the natural size of the geometry that defines this shape
///
internal override Size GetNaturalSize()
{
double strokeThickness = GetStrokeThickness();
return new Size(strokeThickness, strokeThickness);
}
///
/// Get the bonds of the rectangle that defines this shape
///
internal override Rect GetDefiningGeometryBounds()
{
return _rect;
}
//
// This property
// 1. Finds the correct initial size for the _effectiveValues store on the current DependencyObject
// 2. This is a performance optimization
//
internal override int EffectiveValuesInitialSize
{
get { return 13; }
}
#endregion Internal Methods
#region Private Fields
private Rect _rect = Rect.Empty;
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
// File: Ellipse.cs
//
// Description:
// Implementation of Ellipse shape element.
//
// History:
// 05/30/02 - AdSmith - Created.
//
// Copyright (C) 2003 by Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System.Windows.Shapes;
using System.Diagnostics;
using System.Windows.Threading;
using System.Windows;
using System.Windows.Media;
using MS.Internal;
using System.ComponentModel;
using System;
namespace System.Windows.Shapes
{
///
/// The ellipse shape element
/// This element (like all shapes) belongs under a Canvas,
/// and will be presented by the parent canvas.
///
///
public sealed class Ellipse : Shape
{
#region Constructors
///
/// Instantiates a new instance of a Ellipse.
///
///
public Ellipse()
{
}
// The default stretch mode of Ellipse is Fill
static Ellipse()
{
StretchProperty.OverrideMetadata(typeof(Ellipse), new FrameworkPropertyMetadata(Stretch.Fill));
}
#endregion Constructors
#region Dynamic Properties
// For an Ellipse, RenderedGeometry = defining geometry and GeometryTransform = Identity
///
/// The RenderedGeometry property returns the final rendered geometry
///
public override Geometry RenderedGeometry
{
get
{
// RenderedGeometry = defining geometry
return DefiningGeometry;
}
}
///
/// Return the transformation applied to the geometry before rendering
///
public override Transform GeometryTransform
{
get
{
return Transform.Identity;
}
}
#endregion Dynamic Properties
#region Protected
///
/// Updates DesiredSize of the Ellipse. Called by parent UIElement. This is the first pass of layout.
///
/// Constraint size is an "upper limit" that Ellipse should not exceed.
/// Ellipse's desired size.
protected override Size MeasureOverride(Size constraint)
{
if (Stretch == Stretch.UniformToFill)
{
double width = constraint.Width;
double height = constraint.Height;
if (Double.IsInfinity(width) && Double.IsInfinity(height))
{
return GetNaturalSize();
}
else if (Double.IsInfinity(width) || Double.IsInfinity(height))
{
width = Math.Min(width, height);
}
else
{
width = Math.Max(width, height);
}
return new Size(width, width);
}
return GetNaturalSize();
}
///
/// Returns the final size of the shape and caches the bounds.
///
protected override Size ArrangeOverride(Size finalSize)
{
// We construct the rectangle to fit finalSize with the appropriate Stretch mode. The rendering
// transformation will thus be the identity.
double penThickness = GetStrokeThickness();
double margin = penThickness / 2;
_rect = new Rect(
margin, // X
margin, // Y
Math.Max(0, finalSize.Width - penThickness), // Width
Math.Max(0, finalSize.Height - penThickness)); // Height
switch (Stretch)
{
case Stretch.None:
// A 0 Rect.Width and Rect.Height rectangle
_rect.Width = _rect.Height = 0;
break;
case Stretch.Fill:
// The most common case: a rectangle that fills the box.
// _rect has already been initialized for that.
break;
case Stretch.Uniform:
// The maximal square that fits in the final box
if (_rect.Width > _rect.Height)
{
_rect.Width = _rect.Height;
}
else // _rect.Width <= _rect.Height
{
_rect.Height = _rect.Width;
}
break;
case Stretch.UniformToFill:
// The minimal square that fills the final box
if (_rect.Width < _rect.Height)
{
_rect.Width = _rect.Height;
}
else // _rect.Width >= _rect.Height
{
_rect.Height = _rect.Width;
}
break;
}
ResetRenderedGeometry();
return finalSize;
}
///
/// Get the ellipse that defines this shape
///
protected override Geometry DefiningGeometry
{
get
{
if (_rect.IsEmpty)
{
return Geometry.Empty;
}
return new EllipseGeometry(_rect);
}
}
///
/// Render callback.
///
protected override void OnRender(DrawingContext drawingContext)
{
if (!_rect.IsEmpty)
{
Pen pen = GetPen();
drawingContext.DrawGeometry(Fill, pen, new EllipseGeometry(_rect));
}
}
#endregion Protected
#region Internal Methods
internal override void CacheDefiningGeometry()
{
double margin = GetStrokeThickness() / 2;
_rect = new Rect(margin, margin, 0, 0);
}
///
/// Get the natural size of the geometry that defines this shape
///
internal override Size GetNaturalSize()
{
double strokeThickness = GetStrokeThickness();
return new Size(strokeThickness, strokeThickness);
}
///
/// Get the bonds of the rectangle that defines this shape
///
internal override Rect GetDefiningGeometryBounds()
{
return _rect;
}
//
// This property
// 1. Finds the correct initial size for the _effectiveValues store on the current DependencyObject
// 2. This is a performance optimization
//
internal override int EffectiveValuesInitialSize
{
get { return 13; }
}
#endregion Internal Methods
#region Private Fields
private Rect _rect = Rect.Empty;
#endregion Private Fields
}
}
// 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
- WCFServiceClientProxyGenerator.cs
- XamlNamespaceHelper.cs
- CustomErrorCollection.cs
- MonthChangedEventArgs.cs
- XmlUrlResolver.cs
- _ProxyChain.cs
- Vector3DCollectionValueSerializer.cs
- Encoder.cs
- TextTreeUndo.cs
- QilXmlReader.cs
- MsmqInputChannel.cs
- BeginStoryboard.cs
- RelationshipSet.cs
- MetadataCollection.cs
- IdentityReference.cs
- SqlMethodAttribute.cs
- LostFocusEventManager.cs
- PropVariant.cs
- Decimal.cs
- MetafileHeaderWmf.cs
- ValidationHelper.cs
- TextLineBreak.cs
- CacheManager.cs
- ServiceEndpointAssociationProvider.cs
- RootContext.cs
- dsa.cs
- PermissionSetEnumerator.cs
- WebBrowserPermission.cs
- XsltLibrary.cs
- PageTrueTypeFont.cs
- BackgroundWorker.cs
- SqlIdentifier.cs
- ConfigurationManagerHelperFactory.cs
- JoinGraph.cs
- InfoCardServiceInstallComponent.cs
- FileDataSource.cs
- HostedTransportConfigurationBase.cs
- CodeTypeOfExpression.cs
- ThousandthOfEmRealDoubles.cs
- SecurityManager.cs
- SocketInformation.cs
- DataGridViewCellStyleChangedEventArgs.cs
- OutputCacheProfileCollection.cs
- HideDisabledControlAdapter.cs
- GridViewSelectEventArgs.cs
- TemplateControlBuildProvider.cs
- DataListItem.cs
- SplashScreen.cs
- MatrixKeyFrameCollection.cs
- StylusTip.cs
- UpnEndpointIdentity.cs
- XmlArrayItemAttribute.cs
- Peer.cs
- UseLicense.cs
- PageOutputColor.cs
- UserNameSecurityTokenProvider.cs
- SchemaTableOptionalColumn.cs
- base64Transforms.cs
- MultipleViewPattern.cs
- BroadcastEventHelper.cs
- RectangleF.cs
- DBSqlParserColumnCollection.cs
- ObjectTokenCategory.cs
- OneOfScalarConst.cs
- CreateWorkflowOwnerCommand.cs
- ToolStripSeparatorRenderEventArgs.cs
- PreloadedPackages.cs
- DesignTimeHTMLTextWriter.cs
- Triangle.cs
- ILGenerator.cs
- LocationUpdates.cs
- DataGridViewElement.cs
- ThicknessAnimationUsingKeyFrames.cs
- TextBoxView.cs
- SqlBulkCopyColumnMapping.cs
- ImmutableObjectAttribute.cs
- DataBinding.cs
- OleDbPermission.cs
- XmlSchemaSimpleType.cs
- CryptoApi.cs
- QueryContinueDragEvent.cs
- MenuCommands.cs
- WebRequest.cs
- FormsAuthenticationTicket.cs
- ResourceManagerWrapper.cs
- SerialErrors.cs
- PostBackTrigger.cs
- TableItemPatternIdentifiers.cs
- ToolStripPanelRow.cs
- TagPrefixAttribute.cs
- InstanceDataCollectionCollection.cs
- IgnoreFlushAndCloseStream.cs
- QueryInterceptorAttribute.cs
- ActivationWorker.cs
- HwndAppCommandInputProvider.cs
- CodeConstructor.cs
- SizeIndependentAnimationStorage.cs
- XsltConvert.cs
- PointLight.cs
- ConfigurationManagerHelper.cs