本文整理汇总了C#中SharpDX.Size2F类的典型用法代码示例。如果您正苦于以下问题:C# Size2F类的具体用法?C# Size2F怎么用?C# Size2F使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Size2F类属于SharpDX命名空间,在下文中一共展示了Size2F类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginRenderEffectOverride
protected override bool BeginRenderEffectOverride(Texture texture, RenderContext renderContext)
{
if (_refresh)
{
_effectContext = new EffectContext();
_refresh = false;
}
RectangleF rect = renderContext.OccupiedTransformedBounds;
SizeF frameSize = new SizeF(rect.Width, rect.Height);
_effectContext.ExtraParameters = GetShaderParameters();
_effectContext.ShaderEffect = _shaderEffectName;
Vector4 lastFrameData = new Vector4(rect.Width, rect.Height, 0.0f, 0.0f);
_effectContext.StartRender(renderContext, frameSize, texture, CROP_FULLSIZE, Color.Transparent, lastFrameData);
return true;
}
示例2: BeginRenderEffectOverride
protected override bool BeginRenderEffectOverride(Texture texture, RenderContext renderContext)
{
if (_refresh)
{
_imageContext = new ImageContext();
_refresh = false;
}
RectangleF rect = renderContext.OccupiedTransformedBounds;
SizeF frameSize = new SizeF(rect.Width, rect.Height);
_imageContext.FrameSize = frameSize;
_imageContext.ExtraParameters = GetShaderParameters();
_imageContext.ShaderEffect = SkinResources.EFFECTS_SUB_DIRECTORY + '\\' + _partialShaderEffect;
Vector4 lastFrameData = new Vector4(rect.Width, rect.Height, 0.0f, 0.0f);
_imageContext.StartRender(renderContext, frameSize, texture, CROP_FULLSIZE, Color.Transparent, lastFrameData);
return true;
}
示例3: CalculateInnerDesiredSize
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize)
{
FrameworkElementCollection children = Children;
lock (children.SyncRoot)
{
if (_newItemProvider != null)
{
if (children.Count > 0)
children.Clear(false);
if (_itemProvider != null)
MPF.TryCleanupAndDispose(_itemProvider);
_itemProvider = _newItemProvider;
_newItemProvider = null;
_updateRenderOrder = true;
}
_averageItemSize = 0;
IItemProvider itemProvider = ItemProvider;
if (itemProvider == null)
return base.CalculateInnerDesiredSize(totalSize);
int numItems = itemProvider.NumItems;
if (numItems == 0)
return new SizeF();
SizeF resultSize;
// Get all viewable children (= visible children inside our range)
IList<FrameworkElement> exemplaryChildren = GetMeasuredViewableChildren(totalSize, out resultSize);
if (exemplaryChildren.Count == 0)
{ // Might be the case if no item matches into totalSize. Fallback: Use the first visible item.
for (int i = 0; i < numItems; i++)
{
FrameworkElement item = GetItem(i, itemProvider, true);
if (item == null || !item.IsVisible)
continue;
exemplaryChildren.Add(item);
}
}
if (exemplaryChildren.Count == 0)
return new SizeF();
_averageItemSize = GetExtendsInOrientationDirection(Orientation, resultSize) / exemplaryChildren.Count;
return Orientation == Orientation.Vertical ? new SizeF(resultSize.Width, resultSize.Height * numItems / exemplaryChildren.Count) :
new SizeF(resultSize.Width * numItems / exemplaryChildren.Count, resultSize.Height);
}
}
示例4: RefreshParameters
protected virtual void RefreshParameters(SizeF targetImageSize, Texture texture, RectangleF textureClip)
{
if (_refresh || _lastTexture != texture)
{
// Build our effects
_lastTexture = texture;
_effect = ContentManager.Instance.GetEffect(GetEffectName());
_refresh = false;
}
}
示例5: GetMeasuredViewableChildren
// It's actually "GetVisibleChildren", but that member already exists in Panel
protected IList<FrameworkElement> GetMeasuredViewableChildren(SizeF totalSize, out SizeF resultSize)
{
resultSize = new SizeF();
IList<FrameworkElement> result = new List<FrameworkElement>(20);
IItemProvider itemProvider = ItemProvider;
if (itemProvider == null)
return result;
int numItems = itemProvider.NumItems;
if (numItems == 0)
return result;
float availableSize = GetExtendsInNonOrientationDirection(Orientation, totalSize);
if (!_doScroll)
_actualFirstVisibleChildIndex = 0;
int start = _actualFirstVisibleChildIndex;
CalcHelper.Bound(ref start, 0, numItems - 1);
int end = start - 1;
float sumExtendsInOrientationDirection = 0;
float maxExtendsInNonOrientationDirection = 0;
int ct = MAX_NUM_VISIBLE_ITEMS;
// From scroll index until potentially up to the end
do
{
if (end == numItems - 1)
// Reached the last item
break;
FrameworkElement item = GetItem(end + 1, itemProvider, true);
if (item == null || !item.IsVisible)
{
end++;
continue;
}
if (ct-- == 0)
break;
float childExtendsInOrientationDirection = GetExtendsInOrientationDirection(Orientation, item.DesiredSize);
if (childExtendsInOrientationDirection > availableSize + DELTA_DOUBLE)
break;
float childExtendsInNonOrientationDirection = GetExtendsInNonOrientationDirection(Orientation, item.DesiredSize);
availableSize -= childExtendsInOrientationDirection;
sumExtendsInOrientationDirection += childExtendsInOrientationDirection;
if (childExtendsInNonOrientationDirection > maxExtendsInNonOrientationDirection)
maxExtendsInNonOrientationDirection = childExtendsInNonOrientationDirection;
result.Add(item);
end++;
} while (availableSize > 0 || !_doScroll);
// If there is still space left, try to get items above scroll index
while (availableSize > 0)
{
if (start == 0)
// Reached the last item
break;
FrameworkElement item = GetItem(start - 1, itemProvider, true);
if (item == null || !item.IsVisible)
continue;
if (ct-- == 0)
break;
float childExtendsInOrientationDirection = GetExtendsInOrientationDirection(Orientation, item.DesiredSize);
if (childExtendsInOrientationDirection > availableSize + DELTA_DOUBLE)
break;
float childExtendsInNonOrientationDirection = GetExtendsInNonOrientationDirection(Orientation, item.DesiredSize);
availableSize -= childExtendsInOrientationDirection;
sumExtendsInOrientationDirection += childExtendsInOrientationDirection;
if (childExtendsInNonOrientationDirection > maxExtendsInNonOrientationDirection)
maxExtendsInNonOrientationDirection = childExtendsInNonOrientationDirection;
result.Insert(0, item);
start--;
}
resultSize = Orientation == Orientation.Vertical ? new SizeF(maxExtendsInNonOrientationDirection, sumExtendsInOrientationDirection) :
new SizeF(sumExtendsInOrientationDirection, maxExtendsInNonOrientationDirection);
return result;
}
示例6: CalculateInnerDesiredSize
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize)
{
base.CalculateInnerDesiredSize(totalSize); // Needs to be called in each sub class of Control, see comment in Control.CalculateInnerDesiredSize()
AllocFont();
SizeF childSize = _asset == null ? new SizeF() : new SizeF(_asset.TextWidth(VisibleText ?? string.Empty), _asset.TextHeight(1));
if (PreferredTextLength.HasValue && _asset != null)
// We use the "W" character as the character which needs the most space in X-direction
childSize.Width = PreferredTextLength.Value * _asset.TextWidth("W");
return childSize;
}
示例7: TextBuffer
/// <summary>
/// Initializes a new instance of the <see cref="TextBuffer"/> class.
/// </summary>
/// <param name="fontName">The name of the font to use.</param>
/// <param name="size">The font size.</param>
public TextBuffer(string fontName, float size)
{
SetFont(fontName, size);
_kerning = true;
_lastTimeUsed = DateTime.MinValue;
_lastTextSize = new SizeF();
ResetScrollPosition();
}
示例8: Setup
public override void Setup(RectangleF ownerRect, float zOrder, bool skinNeutralAR)
{
PositionColoredTextured[] verts = new PositionColoredTextured[4];
// Upper left
verts[0].X = ownerRect.Left;
verts[0].Y = ownerRect.Top;
verts[0].Color = 0;
verts[0].Tu1 = 0.0f;
verts[0].Tv1 = 0.0f;
verts[0].Z = zOrder;
// Bottom left
verts[1].X = ownerRect.Left;
verts[1].Y = ownerRect.Bottom;
verts[1].Color = 0;
verts[1].Tu1 = 0.0f;
verts[1].Tv1 = 1.0f;
verts[1].Z = zOrder;
// Bottom right
verts[2].X = ownerRect.Right;
verts[2].Y = ownerRect.Bottom;
verts[2].Color = 0;
verts[2].Tu1 = 1.0f;
verts[2].Tv1 = 1.0f;
verts[2].Z = zOrder;
// Upper right
verts[3].X = ownerRect.Right;
verts[3].Y = ownerRect.Top;
verts[3].Color = 0;
verts[3].Tu1 = 1.0f;
verts[3].Tv1 = 0.0f;
verts[3].Z = zOrder;
PrimitiveBuffer.SetPrimitiveBuffer(ref _primitiveBuffer, ref verts, PrimitiveType.TriangleFan);
_frameSize = skinNeutralAR ? ImageContext.AdjustForSkinAR(ownerRect.Size) : ownerRect.Size;
_imageContext.FrameSize = _frameSize;
}
示例9: MaxSizeF
protected SizeF MaxSizeF(SizeF a, SizeF b)
{
return new SizeF(Math.Max(a.Width, b.Width), Math.Max(a.Height, b.Height));
}
示例10: Measure
/// <summary>
/// Measures this element's size and fills the <see cref="DesiredSize"/> property.
/// </summary>
/// <remarks>
/// <para>
/// This method is the first part of the two-phase measuring process. In this first phase, parent
/// controls collect all the size requirements of their child controls.
/// </para>
/// <para>
/// An input size value of <see cref="float.NaN"/> in any coordinate denotes that this child control doesn't have a size
/// constraint in that direction. Coordinates different from <see cref="float.NaN"/> should be considered by this child
/// control as the maximum available size in that direction. If this element still produces a bigger
/// <see cref="DesiredSize"/>, the <see cref="Arrange(RectangleF)"/> method might give it a smaller final region.
/// </para>
/// </remarks>
/// <param name="totalSize">Total size of the element including Margins. As input, this parameter
/// contains the size available for this child control (size constraint). As output, it must be set
/// to the <see cref="DesiredSize"/> plus <see cref="UIElement.Margin"/>.</param>
public void Measure(ref SizeF totalSize)
{
#if DEBUG_LAYOUT
#if DEBUG_MORE_LAYOUT
System.Diagnostics.Trace.WriteLine(string.Format("Measure {0} Name='{1}', totalSize={2}", GetType().Name, Name, totalSize));
#endif
#endif
if (!_isMeasureInvalid && SameSize(_availableSize, totalSize))
{ // Optimization: If our input data is the same and the layout isn't invalid, we don't need to measure again
totalSize = _desiredSize;
#if DEBUG_LAYOUT
#if DEBUG_MORE_LAYOUT
System.Diagnostics.Trace.WriteLine(string.Format("Measure {0} Name='{1}', cutting short, totalSize is like before and measurement is not invalid, returns desired size={2}", GetType().Name, Name, totalSize));
#endif
#endif
return;
}
#if DEBUG_LAYOUT
#if !DEBUG_MORE_LAYOUT
System.Diagnostics.Trace.WriteLine(string.Format("Measure {0} Name='{1}', totalSize={2}", GetType().Name, Name, totalSize));
#endif
#endif
_isMeasureInvalid = false;
_availableSize = totalSize;
RemoveMargin(ref totalSize, Margin);
Matrix? layoutTransform = LayoutTransform == null ? new Matrix?() : LayoutTransform.GetTransform();
if (layoutTransform.HasValue)
totalSize = FindMaxTransformedSize(layoutTransform.Value, totalSize);
if (!double.IsNaN(Width))
totalSize.Width = (float) Width;
if (!double.IsNaN(Height))
totalSize.Height = (float) Height;
totalSize = CalculateInnerDesiredSize(totalSize);
if (!double.IsNaN(Width))
totalSize.Width = (float) Width;
if (!double.IsNaN(Height))
totalSize.Height = (float) Height;
totalSize = ClampSize(totalSize);
_innerDesiredSize = totalSize;
if (layoutTransform.HasValue)
layoutTransform.Value.TransformIncludingRectangleSize(ref totalSize);
AddMargin(ref totalSize, Margin);
if (totalSize != _desiredSize)
InvalidateLayout(false, true);
_desiredSize = totalSize;
#if DEBUG_LAYOUT
System.Diagnostics.Trace.WriteLine(string.Format("Measure {0} Name='{1}', returns calculated desired size={2}", GetType().Name, Name, totalSize));
#endif
}
示例11: CalculateInnerDesiredSize
protected virtual SizeF CalculateInnerDesiredSize(SizeF totalSize)
{
return new SizeF();
}
示例12: SameSize
public static bool SameSize(SizeF? size1, SizeF size2)
{
return size1.HasValue && SameSize(size1.Value, size2);
}
示例13: FindMaxTransformedSize
/// <summary>
/// Given the transform to be applied to an unknown rectangle, this method finds (in axis-aligned local space)
/// the largest rectangle that, after transform, fits within <paramref name="localBounds"/>.
/// Largest rectangle means rectangle of the greatest area in local space (although maximal area in local space
/// implies maximal area in transform space).
/// </summary>
/// <param name="transform">Transformation matrix.</param>
/// <param name="localBounds">The bounds in local space where the returned size fits when transformed
/// via the given <paramref name="transform"/>.</param>
/// <returns>The dimensions, in local space, of the maximal area rectangle found.</returns>
private static SizeF FindMaxTransformedSize(Matrix transform, SizeF localBounds)
{
// X (width) and Y (height) constraints for axis-aligned bounding box in dest. space
float xConstr = localBounds.Width;
float yConstr = localBounds.Height;
// Avoid doing math on an empty rect
if (IsNear(xConstr, 0) || IsNear(yConstr, 0))
return new SizeF(0, 0);
bool xConstrInfinite = float.IsNaN(xConstr);
bool yConstrInfinite = float.IsNaN(yConstr);
if (xConstrInfinite && yConstrInfinite)
return new SizeF(float.NaN, float.NaN);
if (xConstrInfinite) // Assume square for one-dimensional constraint
xConstr = yConstr;
else if (yConstrInfinite)
yConstr = xConstr;
// We only deal with nonsingular matrices here. The nonsingular matrix is the one
// that has inverse (determinant != 0).
if (transform.Determinant() == 0)
return new SizeF(0, 0);
float a = transform.M11;
float b = transform.M12;
float c = transform.M21;
float d = transform.M22;
// Result width and height (in child/local space)
float w;
float h;
// Because we are dealing with nonsingular transform matrices, we have (b==0 || c==0) XOR (a==0 || d==0)
if (IsNear(b, 0) || IsNear(c, 0))
{ // (b == 0 || c == 0) ==> a != 0 && d != 0
float yCoverD = yConstrInfinite ? float.PositiveInfinity : Math.Abs(yConstr / d);
float xCoverA = xConstrInfinite ? float.PositiveInfinity : Math.Abs(xConstr / a);
if (IsNear(b, 0))
{
if (IsNear(c, 0))
{ // b == 0, c == 0, a != 0, d != 0
// No constraint relation; use maximal width and height
h = yCoverD;
w = xCoverA;
}
else
{ // b == 0, a != 0, c != 0, d != 0
// Maximizing under line (hIntercept=xConstr/c, wIntercept=xConstr/a)
// BUT we still have constraint: h <= yConstr/d
h = Math.Min(0.5f * Math.Abs(xConstr / c), yCoverD);
w = xCoverA - ((c * h) / a);
}
}
else
{ // c == 0, a != 0, b != 0, d != 0
// Maximizing under line (hIntercept=yConstr/d, wIntercept=yConstr/b)
// BUT we still have constraint: w <= xConstr/a
w = Math.Min(0.5f * Math.Abs(yConstr / b), xCoverA);
h = yCoverD - ((b * w) / d);
}
}
else if (IsNear(a, 0) || IsNear(d, 0))
{ // (a == 0 || d == 0) ==> b != 0 && c != 0
float yCoverB = Math.Abs(yConstr / b);
float xCoverC = Math.Abs(xConstr / c);
if (IsNear(a, 0))
{
if (IsNear(d, 0))
{ // a == 0, d == 0, b != 0, c != 0
// No constraint relation; use maximal width and height
h = xCoverC;
w = yCoverB;
}
else
{ // a == 0, b != 0, c != 0, d != 0
// Maximizing under line (hIntercept=yConstr/d, wIntercept=yConstr/b)
// BUT we still have constraint: h <= xConstr/c
h = Math.Min(0.5f * Math.Abs(yConstr / d), xCoverC);
w = yCoverB - ((d * h) / b);
}
//.........这里部分代码省略.........
示例14: StretchSource
/// <summary>
/// This is a helper provided to assist derived Sources when scaling their content to
/// the owner size.
/// </summary>
/// <param name="target">The total available space.</param>
/// <param name="source">The unscaled source size.</param>
/// <param name="stretchMode">The <see cref="Stretch"/> mode that determines which stretching technique to use.</param>
/// <param name="direction">The <see cref="StretchDirection"/> that determines when to perform scaling.</param>
/// <returns>The scaled source size, which may be larger than the <paramref name="target"/> size.</returns>
public SizeF StretchSource(SizeF target, SizeF source, Stretch stretchMode, StretchDirection direction)
{
if (direction == StretchDirection.DownOnly && source.Width <= target.Width && source.Height <= target.Height)
return source;
if (direction == StretchDirection.UpOnly && source.Width >= target.Width && source.Height >= target.Height)
return source;
switch (stretchMode)
{
case Stretch.None:
// Original size
break;
case Stretch.Fill:
// Stretch to fit
source = target;
break;
case Stretch.Uniform:
// Keep aspect ratio and show borders
{
float ratio = System.Math.Min(target.Width / source.Width, target.Height / source.Height);
source.Width *= ratio;
source.Height *= ratio;
}
break;
case Stretch.UniformToFill:
// Keep aspect ratio, zoom in to avoid borders
{
float ratio = System.Math.Max(target.Width / source.Width, target.Height / source.Height);
source.Width *= ratio;
source.Height *= ratio;
}
break;
}
return source;
}
示例15: CreateRoundedRectWithTitleRegionPath
/// <summary>
/// Creates a rectangular <see cref="GraphicsPath"/> with rounded edges, optionally with an open title
/// region specified by the parameters <paramref name="titleInset"/> and <paramref name="titleWidth"/>.
/// </summary>
/// <param name="baseRect">The rect which surrounds the created path.</param>
/// <param name="radiusX">The X radius of the rounded edges.</param>
/// <param name="radiusY">The Y radius of the rounded edges.</param>
/// <param name="withTitleRegion">If set to <c>true</c>, a title region will be left out.</param>
/// <param name="titleInset">Inset of the title region behind the corner. This parameter will only be used if
/// <paramref name="withTitleRegion"/> is set to <c>true</c>.</param>
/// <param name="titleWidth">Width of the title region to leave out. This parameter will only be used if
/// <paramref name="withTitleRegion"/> is set to <c>true</c>.</param>
public static GraphicsPath CreateRoundedRectWithTitleRegionPath(RectangleF baseRect, float radiusX, float radiusY,
bool withTitleRegion, float titleInset, float titleWidth)
{
GraphicsPath result = new GraphicsPath();
if (radiusX <= 0.0f && radiusY <= 0.0f || baseRect.Width == 0 || baseRect.Height == 0)
{
// if corner radius is less than or equal to zero, return the original rectangle
if (withTitleRegion)
{ // If we should leave out a title region, we need to do it manually, because we need to start next to the
// title.
titleWidth = Math.Min(titleWidth, baseRect.Width - 2 * titleInset);
// Right from the title to the upper right edge
result.AddLine(baseRect.Left + 2* titleInset + titleWidth, baseRect.Top,
baseRect.Right, baseRect.Top);
// Upper right edge to lower right edge
result.AddLine(baseRect.Right, baseRect.Top,
baseRect.Right, baseRect.Bottom);
// Lower right edge to lower left edge
result.AddLine(baseRect.Right, baseRect.Bottom,
baseRect.Left, baseRect.Bottom);
// Lower left edge to upper left edge
result.AddLine(baseRect.Left, baseRect.Bottom,
baseRect.Left, baseRect.Top);
// Upper left edge to the left side of the title
result.AddLine(baseRect.Left, baseRect.Top, baseRect.Left + titleInset, baseRect.Top);
}
else
result.AddRectangle(baseRect.ToDrawingRectF());
}
else
{
if (radiusX >= baseRect.Width / 2f)
radiusX = baseRect.Width/2f;
if (radiusY >= baseRect.Height / 2f)
radiusY = baseRect.Height/2f;
// create the arc for the rectangle sides and declare a graphics path object for the drawing
SizeF sizeF = new SizeF(radiusX * 2f, radiusY * 2f);
RectangleF arc = SharpDXExtensions.CreateRectangleF(baseRect.Location, sizeF);
if (withTitleRegion)
{
titleWidth = Math.Min(titleWidth, baseRect.Width - 2 * (radiusX + titleInset));
// Right of the title to the upper right edge
result.AddLine(baseRect.Left + radiusX + titleInset + titleWidth, baseRect.Top,
baseRect.Right - radiusX, baseRect.Top);
}
// Top right arc
arc.X = baseRect.Right - radiusX * 2f;
result.AddArc(arc.ToDrawingRectF(), 270, 90);
// Bottom right arc
arc.Y = baseRect.Bottom - radiusY * 2f;
result.AddArc(arc.ToDrawingRectF(), 0, 90);
// Bottom left arc
arc.X = baseRect.Left;
result.AddArc(arc.ToDrawingRectF(), 90, 90);
// Top left arc
arc.Y = baseRect.Top;
result.AddArc(arc.ToDrawingRectF(), 180, 90);
if (withTitleRegion)
// Upper left edge to the left side of the title
result.AddLine(baseRect.Left + radiusX, baseRect.Top, baseRect.Left + radiusX + titleInset, baseRect.Top);
else
result.CloseFigure();
}
result.Flatten();
return result;
}