protected virtual Size GetElementSize(FrameworkElement child, Size availableSize, CoordinateTransform transform) { Size result = availableSize; DataRect ownViewportBounds = GetViewportBounds(child); if (!ownViewportBounds.IsEmpty) { result = ownViewportBounds.ViewportToScreen(transform).Size; } else { double viewportWidth = GetViewportWidth(child); double viewportHeight = GetViewportHeight(child); bool hasViewportWidth = viewportWidth.IsNotNaN(); bool hasViewportHeight = viewportHeight.IsNotNaN(); double minScreenWidth = GetMinScreenWidth(child); bool hasMinScreenWidth = minScreenWidth.IsNotNaN(); double selfWidth = child.Width.IsNotNaN() ? child.Width : availableSize.Width; double width = hasViewportWidth ? viewportWidth : selfWidth; double selfHeight = child.Height.IsNotNaN() ? child.Height : availableSize.Height; double height = hasViewportHeight ? viewportHeight : selfHeight; if (width < 0) width = 0; if (height < 0) height = 0; DataRect bounds = new DataRect(new Size(width, height)); Rect screenBounds = bounds.ViewportToScreen(transform); result = new Size(hasViewportWidth ? screenBounds.Width : selfWidth, hasViewportHeight ? screenBounds.Height : selfHeight); if (hasMinScreenWidth && result.Width < minScreenWidth) { result.Width = minScreenWidth; } } if (result.Width.IsNaN()) result.Width = 0; if (result.Height.IsNaN()) result.Height = 0; return result; }
protected virtual Rect GetElementScreenBoundsCore(CoordinateTransform transform, UIElement child) { Rect bounds = new Rect(0, 0, 1, 1); DataRect ownViewportBounds = GetViewportBounds(child); if (!ownViewportBounds.IsEmpty) { bounds = ownViewportBounds.ViewportToScreen(transform); } else { double viewportX = GetX(child); double viewportY = GetY(child); if (viewportX.IsNaN() || viewportY.IsNaN()) { //Debug.WriteLine("ViewportRectPanel: Position is not set!"); return bounds; } double viewportWidth = GetViewportWidth(child); if (viewportWidth < 0) viewportWidth = 0; double viewportHeight = GetViewportHeight(child); if (viewportHeight < 0) viewportHeight = 0; bool hasViewportWidth = viewportWidth.IsNotNaN(); bool hasViewportHeight = viewportHeight.IsNotNaN(); DataRect r = new DataRect(new Size(hasViewportWidth ? viewportWidth : child.DesiredSize.Width, hasViewportHeight ? viewportHeight : child.DesiredSize.Height)); r = r.ViewportToScreen(transform); double screenWidth = hasViewportWidth ? r.Width : child.DesiredSize.Width; double screenHeight = hasViewportHeight ? r.Height : child.DesiredSize.Height; double minScreenWidth = GetMinScreenWidth(child); bool hasMinScreemWidth = minScreenWidth.IsNotNaN(); if (hasViewportWidth && screenWidth < minScreenWidth) screenWidth = minScreenWidth; Point location = new Point(viewportX, viewportY).ViewportToScreen(transform); double screenX = location.X; double screenY = location.Y; HorizontalAlignment horizAlignment = GetViewportHorizontalAlignment(child); switch (horizAlignment) { case HorizontalAlignment.Stretch: case HorizontalAlignment.Center: screenX -= screenWidth / 2; break; case HorizontalAlignment.Left: break; case HorizontalAlignment.Right: screenX -= screenWidth; break; } VerticalAlignment vertAlignment = GetViewportVerticalAlignment(child); switch (vertAlignment) { case VerticalAlignment.Bottom: screenY -= screenHeight; break; case VerticalAlignment.Center: case VerticalAlignment.Stretch: screenY -= screenHeight / 2; break; case VerticalAlignment.Top: break; default: break; } bounds = new Rect(screenX, screenY, screenWidth, screenHeight); } // applying screen offset double screenOffsetX = GetScreenOffsetX(child); if (screenOffsetX.IsNaN()) screenOffsetX = 0; double screenOffsetY = GetScreenOffsetY(child); if (screenOffsetY.IsNaN()) screenOffsetY = 0; Vector screenOffset = new Vector(screenOffsetX, screenOffsetY); bounds.Offset(screenOffset); return bounds; }
protected virtual void UpdateLevel(CoordinateTransform transform) { bool ok = false; do { double width = tileProvider.GetTileWidth(tileProvider.Level); double height = tileProvider.GetTileHeight(tileProvider.Level); DataRect size = new DataRect(new Size(width, height)); Rect onScreen = size.ViewportToScreen(transform); // todo написать нормально if (onScreen.Width > tileWidth * 1.45) { if (tileProvider.IncreaseLevel()) { continue; } } else if (onScreen.Width < tileWidth / 1.45) { if (tileProvider.DecreaseLevel()) { continue; } } ok = true; } while (!ok); }