protected FrameworkElement GetItem(int childIndex, IItemProvider itemProvider, bool forceMeasure) { lock (Children.SyncRoot) { bool newlyCreated; FrameworkElement item = itemProvider.GetOrCreateItem(childIndex, this, out newlyCreated); if (item == null) { return(null); } if (newlyCreated) { // VisualParent and item.Screen were set by the item provider item.SetElementState(ElementState.Preparing); if (_elementState == ElementState.Running) { item.SetElementState(ElementState.Running); } } if (newlyCreated || forceMeasure) { SizeF childSize = Orientation == Orientation.Vertical ? new SizeF((float)ActualWidth, float.NaN) : new SizeF(float.NaN, (float)ActualHeight); item.Measure(ref childSize); } return(item); } }
/// <summary> /// A copy of the <see cref="WrapPanel.LayoutLine"/> method, but using the <see cref="ItemProvider"/> /// via the <see cref="GetItem"/> method for item retrieval. /// </summary> protected void LayoutLine(PointF pos, LineMeasurement line) { float offset = 0; for (int i = line.StartIndex; i <= line.EndIndex; i++) { FrameworkElement layoutChild = GetItem(i, ItemProvider, true); SizeF desiredChildSize = layoutChild.DesiredSize; SizeF size; PointF location; if (Orientation == Orientation.Horizontal) { size = new SizeF(desiredChildSize.Width, line.TotalExtendsInNonOrientationDirection); location = new PointF(pos.X + offset, pos.Y); ArrangeChildVertical(layoutChild, layoutChild.VerticalAlignment, ref location, ref size); offset += desiredChildSize.Width; } else { size = new SizeF(line.TotalExtendsInNonOrientationDirection, desiredChildSize.Height); location = new PointF(pos.X, pos.Y + offset); ArrangeChildHorizontal(layoutChild, layoutChild.HorizontalAlignment, ref location, ref size); offset += desiredChildSize.Height; } layoutChild.Arrange(new RectangleF(location.X, location.Y, size.Width, size.Height)); _arrangedItems[i] = layoutChild; } }
/// <summary> /// <p>[This documentation is preliminary and is subject to change.]</p><p><strong>Applies to: </strong>desktop apps | Metro style apps</p><p>TBD</p> /// </summary> /// <param name="commandList">No documentation.</param> /// <param name="pageSize">No documentation.</param> /// <returns>No documentation.</returns> /// <msdn-id>hh847997</msdn-id> /// <unmanaged>HRESULT ID2D1PrintControl::AddPage([In] ID2D1CommandList* commandList,[In] D2D_SIZE_F pageSize,[In, Optional] IStream* pagePrintTicketStream,[Out, Optional] unsigned longlong* tag1,[Out, Optional] unsigned longlong* tag2)</unmanaged> /// <unmanaged-short>ID2D1PrintControl::AddPage</unmanaged-short> public void AddPage(SharpDX.Direct2D1.CommandList commandList, SharpDX.Size2F pageSize) { long tag1; long tag2; AddPage(commandList, pageSize, out tag1, out tag2); }
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize) { ImageSourceState allocatedSource = GetLoadedSource(false); if (allocatedSource == null) { _lastImageSourceSize = new SizeF(); return(new SizeF(10, 10)); } SizeF imageSize = allocatedSource.ImageSource.SourceSize; float sourceFrameRatio = imageSize.Width / imageSize.Height; // Adaptions when available size is not specified in any direction(s) if (double.IsNaN(totalSize.Width) && double.IsNaN(totalSize.Height)) { totalSize = imageSize; } else if (double.IsNaN(totalSize.Height)) { totalSize.Height = totalSize.Width / sourceFrameRatio; } else if (double.IsNaN(totalSize.Width)) { totalSize.Width = totalSize.Height * sourceFrameRatio; } _lastImageSourceSize = imageSize; return(allocatedSource.ImageSource.StretchSource(totalSize, imageSize, Stretch, StretchDirection)); }
/// <summary> /// Creates an Svg document from an xml string /// </summary> /// <param name="stream"></param> /// <param name="viewportSize"></param> /// <returns>Svg document model</returns> public SvgDocument CreateSvgDocument(IStream stream, SharpDX.Size2F viewportSize) { SvgDocument result; CreateSvgDocument_(ComStream.ToIntPtr(stream), viewportSize, out result); return(result); }
public override void GetTexture(SharpDX.Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out SharpDX.RectangleF textureSubRectangle) { if (_synchronizedTexture == null) { _synchronizedTexture = _host.CreateSynchronizedTexture(_controller.GetTexture()); } // Set output parameters. _textureSubRectangle.Left = 0.0f; _textureSubRectangle.Top = 0.0f; _textureSubRectangle.Right = surfaceSize.Width; _textureSubRectangle.Bottom = surfaceSize.Height; //HOW DO YOU DO A Microsoft::WRL::ComPtr<T> CopyTo ????? //m_synchronizedTexture.CopyTo(synchronizedTexture); synchronizedTexture = _synchronizedTexture; textureSubRectangle = _textureSubRectangle; //something is going wrong here as the second time thru the BeginDraw consumes //the call and controlnever returns back to this method, thus GetTexture //(the call after begindraw) never fires again... ?????? synchronizedTexture.BeginDraw(); _controller.GetTexture(surfaceSize, synchronizedTexture, textureSubRectangle); synchronizedTexture.EndDraw(); }
/// <summary> /// Creates an Svg document from an xml string /// </summary> /// <param name="stream"></param> /// <param name="viewportSize"></param> /// <returns>Svg document model</returns> public SvgDocument CreateSvgDocument(IStream stream, SharpDX.Size2F viewportSize) { SvgDocument result; CreateSvgDocument(stream, viewportSize, out result); return(result); }
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize) { FrameworkElement keyboardControl = _keyboardLayoutControl; if (keyboardControl == null) return new SizeF(); keyboardControl.Measure(ref totalSize); return totalSize; }
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize) { FrameworkElement keyboardControl = _keyboardLayoutControl; if (keyboardControl == null) { return(new SizeF()); } keyboardControl.Measure(ref totalSize); return(totalSize); }
// 生成と終了 /// <summary> /// 各種グローバルリソースを生成する。 /// </summary> public static void 生成する(App app, IntPtr hWindow, SharpDX.Size2F 設計画面サイズ, SharpDX.Size2F 物理画面サイズ) { using var _ = new LogBlock(Log.現在のメソッド名); Global.App = app; Global.Handle = hWindow; Global.GraphicResources.スワップチェーンに依存しないグラフィックリソースの作成 += _スワップチェーンに依存しないグラフィックリソースの作成; Global.GraphicResources.スワップチェーンに依存しないグラフィックリソースの解放 += _スワップチェーンに依存しないグラフィックリソースの解放; Global.GraphicResources.スワップチェーンに依存するグラフィックリソースの作成 += _スワップチェーンに依存するグラフィックリソースの作成; Global.GraphicResources.スワップチェーンに依存するグラフィックリソースの解放 += _スワップチェーンに依存するグラフィックリソースの解放; Global.GraphicResources.生成する(Global.Handle, 設計画面サイズ, 物理画面サイズ); Global._Dispose済み = false; }
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize) { if (ColumnDefinitions.Count == 0) { ColumnDefinitions.Add(new ColumnDefinition()); } if (RowDefinitions.Count == 0) { RowDefinitions.Add(new RowDefinition()); } // Reset values before we start measure the children. ColumnDefinitions.ResetAllCellLengths(); RowDefinitions.ResetAllCellLengths(); // Set the Width/Hight of the Columns/Rows according to the sizes of the children. foreach (FrameworkElement child in GetVisibleChildren()) { int col = GetColumn(child); int row = GetRow(child); if (col >= ColumnDefinitions.Count) { col = ColumnDefinitions.Count - 1; } if (col < 0) { col = 0; } if (row >= RowDefinitions.Count) { row = RowDefinitions.Count - 1; } if (row < 0) { row = 0; } SizeF childSize = new SizeF(totalSize.Width, totalSize.Height); // FIXME Albert: Would be better to use the size which is really available for the child here, // but this is not so easy to calculate (depends on col/row definition(s), colspan/rowspan) child.Measure(ref childSize); ColumnDefinitions.SetDesiredLength(col, GetColumnSpan(child), childSize.Width); RowDefinitions.SetDesiredLength(row, GetRowSpan(child), childSize.Height); } return(new SizeF((float)ColumnDefinitions.TotalDesiredLength, (float)RowDefinitions.TotalDesiredLength)); }
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; } _assumedLineExtendsInNonOrientationDirection = 0; IItemProvider itemProvider = ItemProvider; if (itemProvider == null) { return(base.CalculateInnerDesiredSize(totalSize)); } int numItems = itemProvider.NumItems; if (numItems == 0) { return(new SizeF()); } // CalculateInnerDesiredSize is called before ArrangeChildren! // under the precondition that all items use the same template and are equally sized // calulate just one line to find number of items and required size of a line LineMeasurement exemplaryLine = _firstArrangedLineIndex < 0 ? CalculateLine(0, totalSize, false) : _arrangedLines[_firstArrangedLineIndex]; _assumedLineExtendsInNonOrientationDirection = exemplaryLine.TotalExtendsInNonOrientationDirection; var itemsPerLine = exemplaryLine.EndIndex - exemplaryLine.StartIndex + 1; var estimatedExtendsInNonOrientationDirection = (float)Math.Ceiling((float)numItems / itemsPerLine) * _assumedLineExtendsInNonOrientationDirection; return(Orientation == Orientation.Horizontal ? new SizeF(exemplaryLine.TotalExtendsInOrientationDirection, estimatedExtendsInNonOrientationDirection) : new SizeF(estimatedExtendsInNonOrientationDirection, exemplaryLine.TotalExtendsInOrientationDirection)); } }
protected static SizeF CalculateDesiredSize(IEnumerator <FrameworkElement> currentVisibleChildEnumerator, SizeF currentAvailableSize) { if (!currentVisibleChildEnumerator.MoveNext()) { return(new SizeF(0, 0)); } FrameworkElement child = currentVisibleChildEnumerator.Current; if (child == null) // Not necessary to check this, only to avoid warning { return(new SizeF()); } SizeF childSize = new SizeF(currentAvailableSize.Width, currentAvailableSize.Height); SizeF nextChildrenDesiredSize; Dock childDock = GetDock(child); if (childDock == Dock.Top || childDock == Dock.Bottom) { child.Measure(ref childSize); currentAvailableSize.Height -= childSize.Height; nextChildrenDesiredSize = CalculateDesiredSize(currentVisibleChildEnumerator, currentAvailableSize); return(new SizeF(Math.Max(childSize.Width, nextChildrenDesiredSize.Width), childSize.Height + nextChildrenDesiredSize.Height)); } if (childDock == Dock.Left || childDock == Dock.Right) { child.Measure(ref childSize); currentAvailableSize.Width -= childSize.Width; nextChildrenDesiredSize = CalculateDesiredSize(currentVisibleChildEnumerator, currentAvailableSize); return(new SizeF(childSize.Width + nextChildrenDesiredSize.Width, Math.Max(childSize.Height, nextChildrenDesiredSize.Height))); } // Else assume center child.Measure(ref childSize); nextChildrenDesiredSize = CalculateDesiredSize(currentVisibleChildEnumerator, currentAvailableSize); return(new SizeF(Math.Max(childSize.Width, nextChildrenDesiredSize.Width), Math.Max(childSize.Height, nextChildrenDesiredSize.Height))); }
protected override void ArrangeOverride() { base.ArrangeOverride(); ColumnDefinitions.SetAvailableSize(ActualWidth); RowDefinitions.SetAvailableSize(ActualHeight); foreach (FrameworkElement child in GetVisibleChildren()) { int col = GetColumn(child); int row = GetRow(child); if (col >= ColumnDefinitions.Count) { col = ColumnDefinitions.Count - 1; } if (col < 0) { col = 0; } if (row >= RowDefinitions.Count) { row = RowDefinitions.Count - 1; } if (row < 0) { row = 0; } PointF position = new PointF( (float)ColumnDefinitions.GetOffset(col) + _innerRect.Location.X, (float)RowDefinitions.GetOffset(row) + _innerRect.Location.Y); SizeF childSize = new SizeF( (float)ColumnDefinitions.GetLength(col, GetColumnSpan(child)), (float)RowDefinitions.GetLength(row, GetRowSpan(child))); ArrangeChild(child, child.HorizontalAlignment, child.VerticalAlignment, ref position, ref childSize); child.Arrange(SharpDXExtensions.CreateRectangleF(position, childSize)); } }
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; } _assumedLineExtendsInNonOrientationDirection = 0; IItemProvider itemProvider = ItemProvider; if (itemProvider == null) return base.CalculateInnerDesiredSize(totalSize); int numItems = itemProvider.NumItems; if (numItems == 0) return new SizeF(); // CalculateInnerDesiredSize is called before ArrangeChildren! // under the precondition that all items use the same template and are equally sized // calulate just one line to find number of items and required size of a line LineMeasurement exemplaryLine = _firstArrangedLineIndex < 0 ? CalculateLine(0, totalSize, false) : _arrangedLines[_firstArrangedLineIndex]; _assumedLineExtendsInNonOrientationDirection = exemplaryLine.TotalExtendsInNonOrientationDirection; var itemsPerLine = exemplaryLine.EndIndex - exemplaryLine.StartIndex + 1; var estimatedExtendsInNonOrientationDirection = (float)Math.Ceiling((float)numItems / itemsPerLine) * _assumedLineExtendsInNonOrientationDirection; return Orientation == Orientation.Horizontal ? new SizeF(exemplaryLine.TotalExtendsInOrientationDirection, estimatedExtendsInNonOrientationDirection) : new SizeF(estimatedExtendsInNonOrientationDirection, exemplaryLine.TotalExtendsInOrientationDirection); } }
/// <summary> /// A copy of the <see cref="WrapPanel.CalculateLine"/> method, but using the <see cref="ItemProvider"/> /// for item retrieval. /// </summary> protected LineMeasurement CalculateLine(int startIndex, SizeF? measureSize, bool invertLayoutDirection) { LineMeasurement result = LineMeasurement.Create(); if (invertLayoutDirection) result.EndIndex = startIndex; else result.StartIndex = startIndex; result.TotalExtendsInNonOrientationDirection = 0; int numChildren = ItemProvider.NumItems; int directionOffset = invertLayoutDirection ? -1 : 1; float offsetInOrientationDirection = 0; float extendsInOrientationDirection = measureSize.HasValue ? GetExtendsInOrientationDirection(Orientation, measureSize.Value) : float.NaN; int currentIndex = startIndex; for (; invertLayoutDirection ? (currentIndex >= 0) : (currentIndex < numChildren); currentIndex += directionOffset) { FrameworkElement child = GetElement(currentIndex); SizeF desiredChildSize; if (measureSize.HasValue) { desiredChildSize = measureSize.Value; child.Measure(ref desiredChildSize); } else desiredChildSize = child.DesiredSize; float lastOffsetInOrientationDirection = offsetInOrientationDirection; offsetInOrientationDirection += GetExtendsInOrientationDirection(Orientation, desiredChildSize); if (!float.IsNaN(extendsInOrientationDirection) && offsetInOrientationDirection > extendsInOrientationDirection) { if (invertLayoutDirection) result.StartIndex = currentIndex + 1; else result.EndIndex = currentIndex - 1; result.TotalExtendsInOrientationDirection = lastOffsetInOrientationDirection; return result; } if (desiredChildSize.Height > result.TotalExtendsInNonOrientationDirection) result.TotalExtendsInNonOrientationDirection = GetExtendsInNonOrientationDirection(Orientation, desiredChildSize); } if (invertLayoutDirection) result.StartIndex = currentIndex + 1; else result.EndIndex = currentIndex - 1; result.TotalExtendsInOrientationDirection = offsetInOrientationDirection; return result; }
/// <summary>Adds a new string to the list to render.</summary> /// <param name="text">Text to render.</param> /// <param name="size">Font size.</param> /// <param name="kerning">True to use kerning, false otherwise.</param> /// <param name="textSize">Output size of the created text.</param> /// <param name="lineIndex">Output indices of the first vertex for of each line of text.</param> /// <returns>An array of vertices representing a triangle list.</returns> public PositionColoredTextured[] CreateText(string[] text, float size, bool kerning, out SizeF textSize, out int[] lineIndex) { return(_assetCore.CreateText(text, size, kerning, out textSize, out lineIndex)); }
protected override void ArrangeOverride() { base.ArrangeOverride(); float offsetTop = 0.0f; float offsetLeft = 0.0f; float offsetRight = 0.0f; float offsetBottom = 0.0f; SizeF availableSize = new SizeF(_innerRect.Width, _innerRect.Height); int count = 0; // Area allocated to child SizeF childArea; IList<FrameworkElement> visibleChildren = GetVisibleChildren(); foreach (FrameworkElement child in visibleChildren) { count++; //Trace.WriteLine(String.Format("DockPanel:arrange {0} {1}", count, child.Name)); // Size of the child SizeF childSize = child.DesiredSize; switch (GetDock(child)) { case Dock.Top: { PointF location = new PointF(offsetLeft, offsetTop); location.X += ActualPosition.X; location.Y += ActualPosition.Y; // Allocate area to child if (count == visibleChildren.Count && LastChildFill) childArea = new SizeF(availableSize.Width, availableSize.Height); else childArea = new SizeF(availableSize.Width, childSize.Height); // Position the child within the child area ArrangeChildHorizontal(child, child.HorizontalAlignment, ref location, ref childArea); child.Arrange(SharpDXExtensions.CreateRectangleF(location, childArea)); offsetTop += childArea.Height; availableSize.Height -= childArea.Height; } break; case Dock.Bottom: { PointF location; if (count == visibleChildren.Count && LastChildFill) location = new PointF(offsetLeft, _innerRect.Height - (offsetBottom + availableSize.Height)); else location = new PointF(offsetLeft, _innerRect.Height - (offsetBottom + childSize.Height)); location.X += ActualPosition.X; location.Y += ActualPosition.Y; // Allocate area to child if (count == visibleChildren.Count && LastChildFill) childArea = new SizeF(availableSize.Width, availableSize.Height); else childArea = new SizeF(availableSize.Width, childSize.Height); // Position the child within the child area ArrangeChildHorizontal(child, child.HorizontalAlignment, ref location, ref childArea); child.Arrange(SharpDXExtensions.CreateRectangleF(location, childArea)); offsetBottom += childArea.Height; availableSize.Height -= childArea.Height; } break; case Dock.Left: { PointF location = new PointF(offsetLeft, offsetTop); location.X += ActualPosition.X; location.Y += ActualPosition.Y; // Allocate area to child if (count == visibleChildren.Count && LastChildFill) childArea = new SizeF(availableSize.Width, availableSize.Height); else childArea = new SizeF(childSize.Width, availableSize.Height); // Position the child within the child area ArrangeChildVertical(child, child.VerticalAlignment, ref location, ref childArea); child.Arrange(SharpDXExtensions.CreateRectangleF(location, childArea)); offsetLeft += childArea.Width; availableSize.Width -= childArea.Width; } break; case Dock.Right: { PointF location; if (count == visibleChildren.Count && LastChildFill) location = new PointF(_innerRect.Width - (offsetRight + availableSize.Width), offsetTop); else location = new PointF(_innerRect.Width - (offsetRight + childSize.Width), offsetTop); location.X += ActualPosition.X; location.Y += ActualPosition.Y; // Allocate area to child if (count == visibleChildren.Count && LastChildFill) childArea = new SizeF(availableSize.Width,availableSize.Height); else childArea = new SizeF(childSize.Width,availableSize.Height); // Position the child within the child area ArrangeChildVertical(child, child.VerticalAlignment, ref location, ref childArea); child.Arrange(SharpDXExtensions.CreateRectangleF(location, childArea)); offsetRight += childArea.Width; availableSize.Width -= childArea.Width; } break; default: // Dock.Center { PointF location = new PointF(offsetLeft, offsetTop); location.X += ActualPosition.X; location.Y += ActualPosition.Y; childSize = new SizeF(availableSize.Width, availableSize.Height); if (count == visibleChildren.Count && LastChildFill) child.Arrange(SharpDXExtensions.CreateRectangleF(location, childSize)); else { ArrangeChild(child, child.HorizontalAlignment, child.VerticalAlignment, ref location, ref childSize); child.Arrange(SharpDXExtensions.CreateRectangleF(location, childSize)); } // Do not remove child size from a border offset or from size - the child will // stay in the "empty space" without taking place from the border layouting variables } break; } } }
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize) { ConfigureContentScrollFacility(); return(base.CalculateInnerDesiredSize(totalSize)); }
protected override void ArrangeOverride() { base.ArrangeOverride(); float offsetTop = 0.0f; float offsetLeft = 0.0f; float offsetRight = 0.0f; float offsetBottom = 0.0f; SizeF availableSize = new SizeF(_innerRect.Width, _innerRect.Height); int count = 0; // Area allocated to child SizeF childArea; IList <FrameworkElement> visibleChildren = GetVisibleChildren(); foreach (FrameworkElement child in visibleChildren) { count++; //Trace.WriteLine(String.Format("DockPanel:arrange {0} {1}", count, child.Name)); // Size of the child SizeF childSize = child.DesiredSize; switch (GetDock(child)) { case Dock.Top: { PointF location = new PointF(offsetLeft, offsetTop); location.X += ActualPosition.X; location.Y += ActualPosition.Y; // Allocate area to child if (count == visibleChildren.Count && LastChildFill) { childArea = new SizeF(availableSize.Width, availableSize.Height); } else { childArea = new SizeF(availableSize.Width, childSize.Height); } // Position the child within the child area ArrangeChildHorizontal(child, child.HorizontalAlignment, ref location, ref childArea); child.Arrange(SharpDXExtensions.CreateRectangleF(location, childArea)); offsetTop += childArea.Height; availableSize.Height -= childArea.Height; } break; case Dock.Bottom: { PointF location; if (count == visibleChildren.Count && LastChildFill) { location = new PointF(offsetLeft, _innerRect.Height - (offsetBottom + availableSize.Height)); } else { location = new PointF(offsetLeft, _innerRect.Height - (offsetBottom + childSize.Height)); } location.X += ActualPosition.X; location.Y += ActualPosition.Y; // Allocate area to child if (count == visibleChildren.Count && LastChildFill) { childArea = new SizeF(availableSize.Width, availableSize.Height); } else { childArea = new SizeF(availableSize.Width, childSize.Height); } // Position the child within the child area ArrangeChildHorizontal(child, child.HorizontalAlignment, ref location, ref childArea); child.Arrange(SharpDXExtensions.CreateRectangleF(location, childArea)); offsetBottom += childArea.Height; availableSize.Height -= childArea.Height; } break; case Dock.Left: { PointF location = new PointF(offsetLeft, offsetTop); location.X += ActualPosition.X; location.Y += ActualPosition.Y; // Allocate area to child if (count == visibleChildren.Count && LastChildFill) { childArea = new SizeF(availableSize.Width, availableSize.Height); } else { childArea = new SizeF(childSize.Width, availableSize.Height); } // Position the child within the child area ArrangeChildVertical(child, child.VerticalAlignment, ref location, ref childArea); child.Arrange(SharpDXExtensions.CreateRectangleF(location, childArea)); offsetLeft += childArea.Width; availableSize.Width -= childArea.Width; } break; case Dock.Right: { PointF location; if (count == visibleChildren.Count && LastChildFill) { location = new PointF(_innerRect.Width - (offsetRight + availableSize.Width), offsetTop); } else { location = new PointF(_innerRect.Width - (offsetRight + childSize.Width), offsetTop); } location.X += ActualPosition.X; location.Y += ActualPosition.Y; // Allocate area to child if (count == visibleChildren.Count && LastChildFill) { childArea = new SizeF(availableSize.Width, availableSize.Height); } else { childArea = new SizeF(childSize.Width, availableSize.Height); } // Position the child within the child area ArrangeChildVertical(child, child.VerticalAlignment, ref location, ref childArea); child.Arrange(SharpDXExtensions.CreateRectangleF(location, childArea)); offsetRight += childArea.Width; availableSize.Width -= childArea.Width; } break; default: // Dock.Center { PointF location = new PointF(offsetLeft, offsetTop); location.X += ActualPosition.X; location.Y += ActualPosition.Y; childSize = new SizeF(availableSize.Width, availableSize.Height); if (count == visibleChildren.Count && LastChildFill) { child.Arrange(SharpDXExtensions.CreateRectangleF(location, childSize)); } else { ArrangeChild(child, child.HorizontalAlignment, child.VerticalAlignment, ref location, ref childSize); child.Arrange(SharpDXExtensions.CreateRectangleF(location, childSize)); } // Do not remove child size from a border offset or from size - the child will // stay in the "empty space" without taking place from the border layouting variables } break; } } }
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize) { if (ColumnDefinitions.Count == 0) ColumnDefinitions.Add(new ColumnDefinition()); if (RowDefinitions.Count == 0) RowDefinitions.Add(new RowDefinition()); // Reset values before we start measure the children. ColumnDefinitions.ResetAllCellLengths(); RowDefinitions.ResetAllCellLengths(); // Set the Width/Hight of the Columns/Rows according to the sizes of the children. foreach (FrameworkElement child in GetVisibleChildren()) { int col = GetColumn(child); int row = GetRow(child); if (col >= ColumnDefinitions.Count) col = ColumnDefinitions.Count - 1; if (col < 0) col = 0; if (row >= RowDefinitions.Count) row = RowDefinitions.Count - 1; if (row < 0) row = 0; SizeF childSize = new SizeF(totalSize.Width, totalSize.Height); // FIXME Albert: Would be better to use the size which is really available for the child here, // but this is not so easy to calculate (depends on col/row definition(s), colspan/rowspan) child.Measure(ref childSize); ColumnDefinitions.SetDesiredLength(col, GetColumnSpan(child), childSize.Width); RowDefinitions.SetDesiredLength(row, GetRowSpan(child), childSize.Height); } return new SizeF((float) ColumnDefinitions.TotalDesiredLength, (float) RowDefinitions.TotalDesiredLength); }
protected override void ArrangeOverride() { base.ArrangeOverride(); ColumnDefinitions.SetAvailableSize(ActualWidth); RowDefinitions.SetAvailableSize(ActualHeight); foreach (FrameworkElement child in GetVisibleChildren()) { int col = GetColumn(child); int row = GetRow(child); if (col >= ColumnDefinitions.Count) col = ColumnDefinitions.Count - 1; if (col < 0) col = 0; if (row >= RowDefinitions.Count) row = RowDefinitions.Count - 1; if (row < 0) row = 0; PointF position = new PointF( (float) ColumnDefinitions.GetOffset(col) + _innerRect.Location.X, (float) RowDefinitions.GetOffset(row) + _innerRect.Location.Y); SizeF childSize = new SizeF( (float) ColumnDefinitions.GetLength(col, GetColumnSpan(child)), (float) RowDefinitions.GetLength(row, GetRowSpan(child))); ArrangeChild(child, child.HorizontalAlignment, child.VerticalAlignment, ref position, ref childSize); child.Arrange(SharpDXExtensions.CreateRectangleF(position, childSize)); } }
protected override void ArrangeChildren() { bool fireScrolled = false; lock (Children.SyncRoot) { if (ItemProvider == null) { base.ArrangeChildren(); return; } _totalHeight = 0; _totalWidth = 0; int numItems = ItemProvider.NumItems; if (numItems > 0) { PointF actualPosition = ActualPosition; SizeF actualSize = new SizeF((float)ActualWidth, (float)ActualHeight); // For Orientation == vertical, this is ActualHeight, for horizontal it is ActualWidth float actualExtendsInOrientationDirection = GetExtendsInOrientationDirection(Orientation, actualSize); // For Orientation == vertical, this is ActualWidth, for horizontal it is ActualHeight float actualExtendsInNonOrientationDirection = GetExtendsInNonOrientationDirection(Orientation, actualSize); // Hint: We cannot skip the arrangement of lines above _actualFirstVisibleLineIndex or below _actualLastVisibleLineIndex // because the rendering and focus system also needs the bounds of the currently invisible children float startPosition = 0; // If set to true, we'll check available space from the last to first visible child. // That is necessary if we want to scroll a specific child to the last visible position. bool invertLayouting = false; lock (_renderLock) if (_pendingScrollIndex.HasValue) { fireScrolled = true; int pendingSI = _pendingScrollIndex.Value; if (_scrollToFirst) { _actualFirstVisibleLineIndex = pendingSI; } else { _actualLastVisibleLineIndex = pendingSI; invertLayouting = true; } _pendingScrollIndex = null; } int itemsPerLine = 0; // if we haven't arranged any lines previously - items per line can't be calculated yet, but is not needed if (_firstArrangedLineIndex >= 0) { // to calculate the starting index of elements for a line we assume that every line (until the last) has the same number of items itemsPerLine = _arrangedLines[_firstArrangedLineIndex].EndIndex - _arrangedLines[_firstArrangedLineIndex].StartIndex + 1; _assumedLineExtendsInNonOrientationDirection = _arrangedLines[_firstArrangedLineIndex].TotalExtendsInNonOrientationDirection; } // scrolling may have set an invalid index for the first visible line if (_actualFirstVisibleLineIndex < 0) { _actualFirstVisibleLineIndex = 0; } if (itemsPerLine > 0) { int linesPerPage = (int)Math.Floor(actualExtendsInNonOrientationDirection / _assumedLineExtendsInNonOrientationDirection); int maxLineIndex = (int)Math.Ceiling((float)numItems / itemsPerLine); if (_actualFirstVisibleLineIndex > maxLineIndex - linesPerPage) { _actualFirstVisibleLineIndex = Math.Max(maxLineIndex - linesPerPage, 0); } } // clear values from previous arrange _arrangedItems = new FrameworkElement[numItems]; _arrangedLines.Clear(); _firstArrangedLineIndex = 0; _lastArrangedLineIndex = 0; // 1) Calculate scroll indices if (_doScroll) { // Calculate last visible child float spaceLeft = actualExtendsInNonOrientationDirection; if (invertLayouting) { if (_actualLastVisibleLineIndex == int.MaxValue) // when scroll to last item (END) was requested { _actualLastVisibleLineIndex = (int)Math.Ceiling((float)numItems / itemsPerLine) - 1; } _actualFirstVisibleLineIndex = _actualLastVisibleLineIndex + 1; int currentLineIndex = _actualLastVisibleLineIndex; _lastArrangedLineIndex = currentLineIndex; while (_arrangedLines.Count <= currentLineIndex) { _arrangedLines.Add(new LineMeasurement()); // add "unarranged lines" up to the last visible } int itemIndex = currentLineIndex * itemsPerLine; int additionalLinesBefore = 0; while (currentLineIndex >= 0 && additionalLinesBefore < NUM_ADD_MORE_FOCUS_LINES) { LineMeasurement line = CalculateLine(itemIndex, _innerRect.Size, false); _arrangedLines[currentLineIndex] = line; _firstArrangedLineIndex = currentLineIndex; currentLineIndex--; itemIndex = line.StartIndex - itemsPerLine; spaceLeft -= line.TotalExtendsInNonOrientationDirection; if (spaceLeft + DELTA_DOUBLE < 0) { additionalLinesBefore++; } else { _actualFirstVisibleLineIndex--; } } // now add NUM_ADD_MORE_FOCUS_LINES after last visible itemIndex = _arrangedLines[_lastArrangedLineIndex].EndIndex + 1; int additionalLinesAfterwards = 0; while (itemIndex < numItems && additionalLinesAfterwards < NUM_ADD_MORE_FOCUS_LINES) { LineMeasurement line = CalculateLine(itemIndex, _innerRect.Size, false); _arrangedLines.Add(line); _lastArrangedLineIndex = _arrangedLines.Count - 1; itemIndex = line.EndIndex + 1; additionalLinesAfterwards++; } } else { _actualLastVisibleLineIndex = _actualFirstVisibleLineIndex - 1; _firstArrangedLineIndex = Math.Max(_actualFirstVisibleLineIndex - NUM_ADD_MORE_FOCUS_LINES, 0); int currentLineIndex = _firstArrangedLineIndex; // add "unarranges lines" up until where we start while (_arrangedLines.Count < currentLineIndex) { _arrangedLines.Add(new LineMeasurement()); } int itemIndex = currentLineIndex * itemsPerLine; int additionalLinesAfterwards = 0; while (itemIndex < numItems && additionalLinesAfterwards < NUM_ADD_MORE_FOCUS_LINES) { LineMeasurement line = CalculateLine(itemIndex, _innerRect.Size, false); _arrangedLines.Add(line); _lastArrangedLineIndex = currentLineIndex; currentLineIndex++; itemIndex = line.EndIndex + 1; if (currentLineIndex > _actualFirstVisibleLineIndex) { spaceLeft -= line.TotalExtendsInNonOrientationDirection; if (spaceLeft + DELTA_DOUBLE < 0) { additionalLinesAfterwards++; } else { _actualLastVisibleLineIndex++; } } } } } else { _actualFirstVisibleLineIndex = 0; _actualLastVisibleLineIndex = _arrangedLines.Count - 1; } // now we know items per line for sure so just calculate it itemsPerLine = _arrangedLines[_firstArrangedLineIndex].EndIndex - _arrangedLines[_firstArrangedLineIndex].StartIndex + 1; _assumedLineExtendsInNonOrientationDirection = _arrangedLines[_firstArrangedLineIndex].TotalExtendsInNonOrientationDirection; // 2) Calculate start position (so the first visible line starts at 0) startPosition -= (_actualFirstVisibleLineIndex - _firstArrangedLineIndex) * _assumedLineExtendsInNonOrientationDirection; // 3) Arrange children if (Orientation == Orientation.Vertical) { _totalHeight = actualExtendsInOrientationDirection; } else { _totalWidth = actualExtendsInOrientationDirection; } PointF position = Orientation == Orientation.Vertical ? new PointF(actualPosition.X + startPosition, actualPosition.Y) : new PointF(actualPosition.X, actualPosition.Y + startPosition); foreach (LineMeasurement line in _arrangedLines.Skip(_firstArrangedLineIndex).Take(_lastArrangedLineIndex - _firstArrangedLineIndex + 1)) { LayoutLine(position, line); startPosition += line.TotalExtendsInNonOrientationDirection; if (Orientation == Orientation.Vertical) { position = new PointF(actualPosition.X + startPosition, actualPosition.Y); } else { position = new PointF(actualPosition.X, actualPosition.Y + startPosition); } } // estimate the desired size var estimatedExtendsInNonOrientationDirection = (float)Math.Ceiling((float)numItems / itemsPerLine) * _assumedLineExtendsInNonOrientationDirection; if (Orientation == Orientation.Horizontal) { _totalHeight = estimatedExtendsInNonOrientationDirection; } else { _totalWidth = estimatedExtendsInNonOrientationDirection; } // keep one more item, because we did use it in CalcLine (and need always one more to find the last item not fitting on the line) // -> if we dont, it will always be newlyCreated and we keep calling Arrange since the new item recursively sets the parent invalid _itemProvider.Keep(_arrangedLines[_firstArrangedLineIndex].StartIndex, _arrangedLines[_lastArrangedLineIndex].EndIndex + 1); } else { _actualFirstVisibleLineIndex = 0; _actualLastVisibleLineIndex = -1; } } if (fireScrolled) { InvokeScrolled(); } }
protected static SizeF CalculateDesiredSize(IEnumerator<FrameworkElement> currentVisibleChildEnumerator, SizeF currentAvailableSize) { if (!currentVisibleChildEnumerator.MoveNext()) return new SizeF(0, 0); FrameworkElement child = currentVisibleChildEnumerator.Current; if (child == null) // Not necessary to check this, only to avoid warning return new SizeF(); SizeF childSize = new SizeF(currentAvailableSize.Width, currentAvailableSize.Height); SizeF nextChildrenDesiredSize; Dock childDock = GetDock(child); if (childDock == Dock.Top || childDock == Dock.Bottom) { child.Measure(ref childSize); currentAvailableSize.Height -= childSize.Height; nextChildrenDesiredSize = CalculateDesiredSize(currentVisibleChildEnumerator, currentAvailableSize); return new SizeF(Math.Max(childSize.Width, nextChildrenDesiredSize.Width), childSize.Height + nextChildrenDesiredSize.Height); } if (childDock == Dock.Left || childDock == Dock.Right) { child.Measure(ref childSize); currentAvailableSize.Width -= childSize.Width; nextChildrenDesiredSize = CalculateDesiredSize(currentVisibleChildEnumerator, currentAvailableSize); return new SizeF(childSize.Width + nextChildrenDesiredSize.Width, Math.Max(childSize.Height, nextChildrenDesiredSize.Height)); } // Else assume center child.Measure(ref childSize); nextChildrenDesiredSize = CalculateDesiredSize(currentVisibleChildEnumerator, currentAvailableSize); return new SizeF(Math.Max(childSize.Width, nextChildrenDesiredSize.Width), Math.Max(childSize.Height, nextChildrenDesiredSize.Height)); }
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize) { return(CalculateDesiredSize(GetVisibleChildren().GetEnumerator(), totalSize)); }
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize) { return CalculateDesiredSize(GetVisibleChildren().GetEnumerator(), totalSize); }
public static unsafe int Calliint99(void *thisObject, void *arg0, SharpDX.Size2F arg1, void *arg2, void *arg3, void *arg4, void *methodPtr) { throw new NotImplementedException(); }
protected override void ArrangeChildren() { bool fireScrolled = false; lock (Children.SyncRoot) { if (ItemProvider == null) { base.ArrangeChildren(); return; } _totalHeight = 0; _totalWidth = 0; int numItems = ItemProvider.NumItems; if (numItems > 0) { PointF actualPosition = ActualPosition; SizeF actualSize = new SizeF((float)ActualWidth, (float)ActualHeight); // For Orientation == vertical, this is ActualHeight, for horizontal it is ActualWidth float actualExtendsInOrientationDirection = GetExtendsInOrientationDirection(Orientation, actualSize); // For Orientation == vertical, this is ActualWidth, for horizontal it is ActualHeight float actualExtendsInNonOrientationDirection = GetExtendsInNonOrientationDirection(Orientation, actualSize); // Hint: We cannot skip the arrangement of lines above _actualFirstVisibleLineIndex or below _actualLastVisibleLineIndex // because the rendering and focus system also needs the bounds of the currently invisible children float startPosition = 0; // If set to true, we'll check available space from the last to first visible child. // That is necessary if we want to scroll a specific child to the last visible position. bool invertLayouting = false; lock (_renderLock) if (_pendingScrollIndex.HasValue) { fireScrolled = true; int pendingSI = _pendingScrollIndex.Value; if (_scrollToFirst) _actualFirstVisibleLineIndex = pendingSI; else { _actualLastVisibleLineIndex = pendingSI; invertLayouting = true; } _pendingScrollIndex = null; } int itemsPerLine = 0; // if we haven't arranged any lines previously - items per line can't be calculated yet, but is not needed if (_firstArrangedLineIndex >= 0) { // to calculate the starting index of elements for a line we assume that every line (until the last) has the same number of items itemsPerLine = _arrangedLines[_firstArrangedLineIndex].EndIndex - _arrangedLines[_firstArrangedLineIndex].StartIndex + 1; _assumedLineExtendsInNonOrientationDirection = _arrangedLines[_firstArrangedLineIndex].TotalExtendsInNonOrientationDirection; } // scrolling may have set an invalid index for the first visible line if (_actualFirstVisibleLineIndex < 0) _actualFirstVisibleLineIndex = 0; if (itemsPerLine > 0) { int linesPerPage = (int)Math.Floor(actualExtendsInNonOrientationDirection / _assumedLineExtendsInNonOrientationDirection); int maxLineIndex = (int)Math.Ceiling((float)numItems / itemsPerLine); if (_actualFirstVisibleLineIndex > maxLineIndex - linesPerPage) { _actualFirstVisibleLineIndex = Math.Max(maxLineIndex - linesPerPage, 0); } } // clear values from previous arrange _arrangedItems = new FrameworkElement[numItems]; _arrangedLines.Clear(); _firstArrangedLineIndex = 0; _lastArrangedLineIndex = 0; // 1) Calculate scroll indices if (_doScroll) { // Calculate last visible child float spaceLeft = actualExtendsInNonOrientationDirection; if (invertLayouting) { if (_actualLastVisibleLineIndex == int.MaxValue) // when scroll to last item (END) was requested _actualLastVisibleLineIndex = (int)Math.Ceiling((float)numItems / itemsPerLine) - 1; _actualFirstVisibleLineIndex = _actualLastVisibleLineIndex + 1; int currentLineIndex = _actualLastVisibleLineIndex; _lastArrangedLineIndex = currentLineIndex; while (_arrangedLines.Count <= currentLineIndex) _arrangedLines.Add(new LineMeasurement()); // add "unarranged lines" up to the last visible int itemIndex = currentLineIndex * itemsPerLine; int additionalLinesBefore = 0; while (currentLineIndex >= 0 && additionalLinesBefore < NUM_ADD_MORE_FOCUS_LINES) { LineMeasurement line = CalculateLine(itemIndex, _innerRect.Size, false); _arrangedLines[currentLineIndex] = line; _firstArrangedLineIndex = currentLineIndex; currentLineIndex--; itemIndex = line.StartIndex - itemsPerLine; spaceLeft -= line.TotalExtendsInNonOrientationDirection; if (spaceLeft + DELTA_DOUBLE < 0) additionalLinesBefore++; else _actualFirstVisibleLineIndex--; } // now add NUM_ADD_MORE_FOCUS_LINES after last visible itemIndex = _arrangedLines[_lastArrangedLineIndex].EndIndex + 1; int additionalLinesAfterwards = 0; while (itemIndex < numItems && additionalLinesAfterwards < NUM_ADD_MORE_FOCUS_LINES) { LineMeasurement line = CalculateLine(itemIndex, _innerRect.Size, false); _arrangedLines.Add(line); _lastArrangedLineIndex = _arrangedLines.Count - 1; itemIndex = line.EndIndex + 1; additionalLinesAfterwards++; } } else { _actualLastVisibleLineIndex = _actualFirstVisibleLineIndex - 1; _firstArrangedLineIndex = Math.Max(_actualFirstVisibleLineIndex - NUM_ADD_MORE_FOCUS_LINES, 0); int currentLineIndex = _firstArrangedLineIndex; // add "unarranges lines" up until where we start while (_arrangedLines.Count < currentLineIndex) _arrangedLines.Add(new LineMeasurement()); int itemIndex = currentLineIndex * itemsPerLine; int additionalLinesAfterwards = 0; while (itemIndex < numItems && additionalLinesAfterwards < NUM_ADD_MORE_FOCUS_LINES) { LineMeasurement line = CalculateLine(itemIndex, _innerRect.Size, false); _arrangedLines.Add(line); _lastArrangedLineIndex = currentLineIndex; currentLineIndex++; itemIndex = line.EndIndex + 1; if (currentLineIndex > _actualFirstVisibleLineIndex) { spaceLeft -= line.TotalExtendsInNonOrientationDirection; if (spaceLeft + DELTA_DOUBLE < 0) additionalLinesAfterwards++; else _actualLastVisibleLineIndex++; } } } } else { _actualFirstVisibleLineIndex = 0; _actualLastVisibleLineIndex = _arrangedLines.Count - 1; } // now we know items per line for sure so just calculate it itemsPerLine = _arrangedLines[_firstArrangedLineIndex].EndIndex - _arrangedLines[_firstArrangedLineIndex].StartIndex + 1; _assumedLineExtendsInNonOrientationDirection = _arrangedLines[_firstArrangedLineIndex].TotalExtendsInNonOrientationDirection; // 2) Calculate start position (so the first visible line starts at 0) startPosition -= (_actualFirstVisibleLineIndex - _firstArrangedLineIndex) * _assumedLineExtendsInNonOrientationDirection; // 3) Arrange children if (Orientation == Orientation.Vertical) _totalHeight = actualExtendsInOrientationDirection; else _totalWidth = actualExtendsInOrientationDirection; PointF position = Orientation == Orientation.Vertical ? new PointF(actualPosition.X + startPosition, actualPosition.Y) : new PointF(actualPosition.X, actualPosition.Y + startPosition); foreach (LineMeasurement line in _arrangedLines.Skip(_firstArrangedLineIndex).Take(_lastArrangedLineIndex - _firstArrangedLineIndex + 1)) { LayoutLine(position, line); startPosition += line.TotalExtendsInNonOrientationDirection; if (Orientation == Orientation.Vertical) position = new PointF(actualPosition.X + startPosition, actualPosition.Y); else position = new PointF(actualPosition.X, actualPosition.Y + startPosition); } // estimate the desired size var estimatedExtendsInNonOrientationDirection = (float)Math.Ceiling((float)numItems / itemsPerLine) * _assumedLineExtendsInNonOrientationDirection; if (Orientation == Orientation.Horizontal) _totalHeight = estimatedExtendsInNonOrientationDirection; else _totalWidth = estimatedExtendsInNonOrientationDirection; // keep one more item, because we did use it in CalcLine (and need always one more to find the last item not fitting on the line) // -> if we dont, it will always be newlyCreated and we keep calling Arrange since the new item recursively sets the parent invalid _itemProvider.Keep(_arrangedLines[_firstArrangedLineIndex].StartIndex, _arrangedLines[_lastArrangedLineIndex].EndIndex + 1); } else { _actualFirstVisibleLineIndex = 0; _actualLastVisibleLineIndex = -1; } } if (fireScrolled) InvokeScrolled(); }
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize) { UpdatePreparedItems(); return(base.CalculateInnerDesiredSize(totalSize)); }
/// <summary> /// <p>[This documentation is preliminary and is subject to change.]</p><p><strong>Applies to: </strong>desktop apps | Metro style apps</p><p>TBD</p> /// </summary> /// <param name="commandList">No documentation.</param> /// <param name="pageSize">No documentation.</param> /// <param name="tag1">No documentation.</param> /// <param name="tag2">No documentation.</param> /// <returns>No documentation.</returns> /// <msdn-id>hh847997</msdn-id> /// <unmanaged>HRESULT ID2D1PrintControl::AddPage([In] ID2D1CommandList* commandList,[In] D2D_SIZE_F pageSize,[In, Optional] IStream* pagePrintTicketStream,[Out, Optional] unsigned longlong* tag1,[Out, Optional] unsigned longlong* tag2)</unmanaged> /// <unmanaged-short>ID2D1PrintControl::AddPage</unmanaged-short> public void AddPage(SharpDX.Direct2D1.CommandList commandList, SharpDX.Size2F pageSize, out long tag1, out long tag2) { AddPage_(commandList, pageSize, IntPtr.Zero, out tag1, out tag2); }
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize) { ConfigureContentScrollFacility(); return base.CalculateInnerDesiredSize(totalSize); }
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize) { UpdatePreparedItems(); return base.CalculateInnerDesiredSize(totalSize); }
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize) { ImageSourceState allocatedSource = GetLoadedSource(false); if (allocatedSource == null) { _lastImageSourceSize = new SizeF(); return new SizeF(10, 10); } SizeF imageSize = allocatedSource.ImageSource.SourceSize; float sourceFrameRatio = imageSize.Width / imageSize.Height; // Adaptions when available size is not specified in any direction(s) if (double.IsNaN(totalSize.Width) && double.IsNaN(totalSize.Height)) totalSize = imageSize; else if (double.IsNaN(totalSize.Height)) totalSize.Height = totalSize.Width / sourceFrameRatio; else if (double.IsNaN(totalSize.Width)) totalSize.Width = totalSize.Height * sourceFrameRatio; _lastImageSourceSize = imageSize; return allocatedSource.ImageSource.StretchSource(totalSize, imageSize, Stretch, StretchDirection); }
public override void PrepareResources(DateTime presentTargetTime, ref SharpDX.Size2F desiredRenderTargetSize) { }