Inflate() public static method

public static Inflate ( Rect rect, Size size ) : Rect
rect Rect
size Size
return Rect
Example #1
0
        public void Update()
        {
            Drawing.Width  = width * Scale;
            Drawing.Height = height * Scale;
            Drawing.OpenLayers();

            var nodes    = Nodes.Where(n => n != null).ToArray();
            var segments = Segments.Where(n => n != null).ToArray();

            foreach (TrafficNode node in nodes)
            {
                node.Update();
            }
            foreach (TrafficSegment segment in segments.OrderBy(m => (m?.Description as TrafficSegmentDescription)?.Type))
            {
                segment.Update();
            }

            var layer = Drawing.GetLayer(DrawingLayer.Outlines);

            var rect = new System.Windows.Rect(0, 0, Drawing.Width, Drawing.Height);

            rect.Inflate(-10.0, -10.0);
            layer.DrawRectangle(null, new Pen(Brushes.HotPink, 1), rect);

            Drawing.CloseLayers();
            //Drawing.InvalidateVisual();
        }
Example #2
0
 /// <summary>
 /// Sets the item's position according to its tikzitem's value
 /// </summary>
 public override bool AdjustPosition(double Resolution)
 {
     Rect r = new Rect(0, 0, 0, 0);
     bool hasone = false;
     foreach (OverlayShape o in children)
     {
         o.AdjustPosition(Resolution);
         Rect rr = o.View.GetBB();
         if (hasone)
             r.Union(rr);
         else
         {
             r = rr;
             hasone = true;
         }
     }
     if (hasone)
     {
         r.Inflate(20, 20);
         //r = new Rect(10, 10, 100, 100);
         View.SetSize( r.Width, r.Height);
         View.SetPosition(r.X, r.Y);
         return true;
     }
     else return false;
 }
Example #3
0
        public static void ScrollIntoViewCentered(this SurfaceListBox listBox, object item)
        {
            Debug.Assert(!VirtualizingStackPanel.GetIsVirtualizing(listBox),
                         "VirtualizingStackPanel.IsVirtualizing must be disabled for ScrollIntoViewCentered to work.");
            Debug.Assert(!ScrollViewer.GetCanContentScroll(listBox),
                         "ScrollViewer.GetCanContentScroll must be disabled for ScrollIntoViewCentered to work.");

            // Get the container for the specified item
            var container = listBox.ItemContainerGenerator.ContainerFromItem(item) as FrameworkElement;
            if (null != container)
            {
                // Get the bounds of the item container
                var rect = new Rect(new Point(), container.RenderSize);

                // Find constraining parent (either the nearest ScrollContentPresenter or the ListBox itself)
                FrameworkElement constrainingParent = container;
                do
                {
                    constrainingParent = VisualTreeHelper.GetParent(constrainingParent) as FrameworkElement;
                } while ((null != constrainingParent) &&
                         (listBox != constrainingParent) &&
                         !(constrainingParent is ScrollContentPresenter));

                if (null != constrainingParent)
                {
                    // Inflate rect to fill the constraining parent
                    rect.Inflate(
                        Math.Max((constrainingParent.ActualWidth - rect.Width)/2, 0),
                        Math.Max((constrainingParent.ActualHeight - rect.Height)/2, 0));
                }

                // Bring the (inflated) bounds into view
                container.BringIntoView(rect);
            }
        }
Example #4
0
        public void Draw(LayerPropertiesModel props, LayerPropertiesModel applied, DrawingContext c)
        {
            if (applied?.Brush == null)
                return;

            const int scale = 4;
            // Set up variables for this frame
            var rect = props.Contain
                ? new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale)
                : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale);

            var clip = new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale);

            // Take an offset of 4 to allow layers to slightly leave their bounds
            var progress = (6.0 - props.AnimationProgress)*10.0;
            if (progress < 0)
            {
                // Can't meddle with the original brush because it's frozen.
                var brush = applied.Brush.Clone();
                brush.Opacity = 1 + 0.025*progress;
                if (brush.Opacity < 0)
                    brush.Opacity = 0;
                if (brush.Opacity > 1)
                    brush.Opacity = 1;
                applied.Brush = brush;
            }
            rect.Inflate(-rect.Width/100.0*progress, -rect.Height/100.0*progress);
            clip.Inflate(-clip.Width/100.0*progress, -clip.Height/100.0*progress);

            c.PushClip(new RectangleGeometry(clip));
            c.DrawRectangle(applied.Brush, null, rect);
            c.Pop();
        }
Example #5
0
      /// <summary>Creates a new <see cref=""/> instance.</summary>
      public DiagramPaginator(DiagramCanvas source, Size printSize) {
         PageSize = printSize;
         _contentSize = new Size(printSize.Width - 2 * Margin, printSize.Height - 2 * Margin);
         _frameRect = new Rect(new Point(Margin, Margin), _contentSize);
         _frameRect.Inflate(1, 1);
         _framePen = new Pen(Brushes.Black, 0.1);

         var scale = 0.25; // hardcoded zoom for printing
         var bounds = new Rect(0, 0, source.ActualWidth, source.ActualHeight);
         _pageCountX = (int)((bounds.Width * scale) / _contentSize.Width) + 1;
         _pageCountY = (int)((bounds.Height * scale) / _contentSize.Height) + 1;

         // Transformation to borderless print size
         var matrix = new Matrix();
         matrix.Translate(-bounds.Left, -bounds.Top);
         matrix.Scale(scale, scale);
         matrix.Translate((_pageCountX * _contentSize.Width - bounds.Width * scale) / 2, (_pageCountY * _contentSize.Height - bounds.Height * scale) / 2);

         // Create a new visual
         var printImage = new RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, 96, 96, PixelFormats.Pbgra32);
         printImage.Render(source);

         var printVisual = new DrawingVisual();
         var printContext = printVisual.RenderOpen();
         printContext.PushTransform(new MatrixTransform(matrix));
         printContext.DrawImage(printImage, bounds);
         printContext.Close();
         _printDiagram = printVisual.Drawing;
      }
        protected override void OnRender( DrawingContext dc )
        {
            Rect rect;

            if ( myLocation == DropLocation.InPlace )
            {
                rect = new Rect( new Size( myOwner.ActualWidth, myOwner.ActualHeight ) );
                rect.Inflate( -1, -1 );
            }
            else
            {
                rect = new Rect( new Size( myOwner.ActualWidth, myOwner.ActualHeight * 0.2 ) );
                if ( myLocation == DropLocation.Before )
                {
                    rect.Offset( 0, -myOwner.ActualHeight * 0.1 );
                }
                else if ( myLocation == DropLocation.After )
                {
                    rect.Offset( 0, myOwner.ActualHeight * 0.9 );
                }
                rect.Inflate( -1, 0 );
            }

            var brush = new SolidColorBrush( Colors.LightSkyBlue );
            brush.Opacity = 0.5;

            var pen = new Pen( new SolidColorBrush( Colors.White ), 1 );

            dc.DrawRectangle( brush, pen, rect );
        }
        internal static Rect GetRectWithMargin(ConnectorInfo connectorThumb, double margin)
        {
            Rect rect = new Rect(connectorThumb.DesignerItemLeft,
                                 connectorThumb.DesignerItemTop,
                                 connectorThumb.DesignerItemSize.Width,
                                 connectorThumb.DesignerItemSize.Height);

            rect.Inflate(margin, margin);

            return rect;
        }
        public Rect MapCubeToRenderPointRect(IntGrid3 grid)
        {
            var p1 = MapLocationToScreenTile(grid.Corner1);
            var p2 = MapLocationToScreenTile(grid.Corner2);

            var r = new Rect(p1, p2);
            r.Inflate(0.5, 0.5);

            p1 = ScreenToRenderPoint(r.TopLeft);
            p2 = ScreenToRenderPoint(r.BottomRight);

            return new Rect(p1, p2);
        }
Example #9
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            Rect adornedElementRect = new Rect(this.AdornedElement.DesiredSize);
           
            Rect newRect = new Rect(adornedElementRect.Right - App.StrokeThinkness * 2, adornedElementRect.Bottom - App.StrokeThinkness * 2,
                adornedElementRect.Right, adornedElementRect.Bottom);
            newRect.Inflate(1, 1);

            // Some arbitrary drawing implements.
            SolidColorBrush renderBrush = new SolidColorBrush(Colors.Red);
            renderBrush.Opacity = 0.2;
            Pen renderPen = new Pen(new SolidColorBrush(Colors.Navy), 1.5);

            //drawingContext.DrawRectangle(renderBrush, renderPen, newRect);
        }
Example #10
0
        public ColorCell(Color clr)
        {
            visColor = new DrawingVisual();
            DrawingContext dc = visColor.RenderOpen();

            Rect rect = new Rect(new Point(0,0), sizeCell);
            rect.Inflate(-4, -4);
            Pen pen = new Pen(SystemColors.ControlTextBrush, 1);
            brush = new SolidColorBrush(clr);
            dc.DrawRectangle(brush, pen, rect);
            dc.Close();

            AddVisualChild(visColor);
            AddLogicalChild(visColor);
        }
Example #11
0
        public static Rect Inflate(Rect rect, double width, double height)
        {
            if (width < rect.Width * -2)
            {
                return(Rect.Empty);
            }
            if (height < rect.Height * -2)
            {
                return(Rect.Empty);
            }

            Rect result = rect;

            result.Inflate(width, height);
            return(result);
        }
        // Constructor requires Color argument.
        public ColorCell(Color clr)
        {
            // Create a new DrawingVisual and store as field.
            visColor = new DrawingVisual();
            DrawingContext dc = visColor.RenderOpen();

            // Draw a rectangle with the color argument.
            Rect rect = new Rect(new Point(0, 0), sizeCell);
            rect.Inflate(-4, -4);
            Pen pen = new Pen(SystemColors.ControlTextBrush, 1);
            brush = new SolidColorBrush(clr);
            dc.DrawRectangle(brush, pen, rect);
            dc.Close();

            // AddVisualChild is necessary for event routing!
            AddVisualChild(visColor);
            AddLogicalChild(visColor);
        }
 private static void UIElement_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     var element = sender as UIElement;
     if (element == null)
     {
         return;
     }
     var lastClickLocation = element.GetValue(LastClickLocationProperty) as Point?;
     var lastClickTime = element.GetValue(LastClickTimeProperty) as int?;
     if (lastClickLocation.HasValue && lastClickTime.HasValue)
     {
         if (e.Timestamp - lastClickTime.Value > SystemInformation.DoubleClickTime)
         {
             element.SetValue(LastClickLocationProperty, e.GetPosition(element));
             element.SetValue(LastClickTimeProperty, e.Timestamp);
             return;
         }
         var size = SystemInformation.DoubleClickSize;
         var rect = new Rect(lastClickLocation.Value, lastClickLocation.Value);
         rect.Inflate(size.Width / 2, size.Height / 2);
         if (rect.Contains(e.GetPosition(element)))
         {
             var contentControl = element as ContentControl;
             if (contentControl != null)
             {
                 Debug.WriteLine($"Clipboard set to: \"{contentControl.Content.ToString()}\"");
                 System.Windows.Clipboard.SetText(contentControl.Content.ToString());
             }
             var textBlock = element as TextBlock;
             if (textBlock != null)
             {
                 Debug.WriteLine($"Clipboard set to: \"{textBlock.Text}\"");
                 System.Windows.Clipboard.SetText(textBlock.Text);
             }
             ClearDoubleClickProperties(element);
             return;
         }
     }
     element.SetValue(LastClickLocationProperty, e.GetPosition(element));
     element.SetValue(LastClickTimeProperty, e.Timestamp);
 }
        internal GraphPaginator( DrawingVisual source, Size printSize )
        {
            PageSize = printSize;

            contentSize = new Size( printSize.Width - 2 * Margin, printSize.Height - 2 * Margin );

            myFrameRect = new Rect( new Point( Margin, Margin ), contentSize );
            myFrameRect.Inflate( 1, 1 );
            myFramePen = new Pen( Brushes.Black, 0.1 );

            // Transformation to borderless print size
            var bounds = source.DescendantBounds;
            bounds.Union( source.ContentBounds );

            var m = new Matrix();
            m.Translate( -bounds.Left, -bounds.Top );

            double scale = 16; // hardcoded zoom for printing
            myPageCountX = ( int )( ( bounds.Width * scale ) / contentSize.Width ) + 1;
            myPageCountY = ( int )( ( bounds.Height * scale ) / contentSize.Height ) + 1;
            m.Scale( scale, scale );
        
            // Center on available pages
            m.Translate( ( myPageCountX * contentSize.Width - bounds.Width * scale ) / 2, ( myPageCountY * contentSize.Height - bounds.Height * scale ) / 2 );

            var target = new DrawingVisual();
            using( var dc = target.RenderOpen() )
            {
                dc.PushTransform( new MatrixTransform( m ) );
                dc.DrawDrawing( source.Drawing );

                foreach( DrawingVisual child in source.Children )
                {
                    dc.DrawDrawing( child.Drawing );
                }
            }
            myGraph = target.Drawing;
        }
        protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
        {
            base.OnRenderSizeChanged(sizeInfo);

            Size s = sizeInfo.NewSize;
            Rect inner = new Rect(0, 0, s.Width, s.Height);
            double radius = s.Width - this.BorderThickness.Left;
            double sinX = radius / Math.Sqrt(2);
            double margin = (int)(s.Width - sinX);

            inner.Inflate(-margin, -margin);

            Path p = (Path)Template.FindName("CrossShape", this);
            p.Data = new PathGeometry(new PathFigure[]
            {
                new PathFigure(new Point(inner.Left, inner.Top),
                    new PathSegment[] {
                        new LineSegment(new Point(inner.Right, inner.Bottom), true),
                        new LineSegment(new Point(inner.Left, inner.Bottom), false),
                        new LineSegment(new Point(inner.Right, inner.Top), true),
                    }, false)
            });
        }
        /// <summary>
        /// Gets the <see cref="DockTabItem"/> at the mouse position by testing against the
        /// <see cref="DockTabItem"/> tabs in the specified pane.
        /// </summary>
        /// <param name="dockTabPane">The <see cref="DockTabPane"/>.</param>
        /// <param name="verticalTolerance">
        /// The tolerance (margin at top and bottom) in pixels.
        /// </param>
        /// <returns>The <see cref="DockTabItem"/> under the mouse cursor.</returns>
        private static DockTabItem GetDockTabItemAtMouse(DockTabPane dockTabPane, double verticalTolerance = 0)
        {
            Debug.Assert(dockTabPane != null);

            if (dockTabPane.Items.Count == 0)
                return null;    // Empty DockTabPane.

            var itemsPanel = dockTabPane.GetItemsPanel();
            if (itemsPanel == null)
                return null;    // ItemsPanel missing.

            Point mousePosition = WindowsHelper.GetMousePosition(itemsPanel);

            Rect bounds = new Rect(itemsPanel.RenderSize);
            bounds.Inflate(0, verticalTolerance);
            if (!bounds.Contains(mousePosition))
                return null;    // Mouse position outside ItemsPanel.

            // Test mouse position against DockTabItems bounds.
            double height = itemsPanel.RenderSize.Height;
            double x = 0;
            for (int i = 0; i < dockTabPane.Items.Count; i++)
            {
                var dockTabItem = dockTabPane.ItemContainerGenerator.ContainerFromIndex(i) as DockTabItem;
                if (dockTabItem == null)
                    break;

                bounds = new Rect(new Point(x, 0), new Size(dockTabItem.RenderSize.Width, height));
                bounds.Inflate(0, verticalTolerance);
                if (bounds.Contains(mousePosition))
                    return dockTabItem;

                x += bounds.Width;
            }

            return null;
        }
Example #17
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (this.Frame != null)
            {
                double windowWidth = (this.ActualWidth / this.Frame.ColumnCount);
                double windowHeight = (this.ActualHeight / this.Frame.RowCount);
                double spaceX = 0.1 * windowWidth;
                double spaceY = 0.1 * windowHeight;

                // draw the background
                drawingContext.DrawRectangle(new SolidColorBrush(new System.Windows.Media.Color() { R = 179, G = 123, B = 123, A = 255 }), null, new Rect(0, 0, this.ActualWidth, this.ActualHeight));

                for (int row = 0; row < this.Frame.RowCount; row++)
                {
                    for (int col = 0; col < this.Frame.ColumnCount; col++)
                    {
                        double x = col * (windowWidth);
                        double y = row * (windowHeight);
                        System.Windows.Media.Color color = new System.Windows.Media.Color();
                        color.R = this.Frame.Get(row, col).Red;
                        color.G = this.Frame.Get(row, col).Green;
                        color.B = this.Frame.Get(row, col).Blue;
                        color.A = 255;

                        Rect window = new Rect(x, y, windowWidth, windowHeight);
                        //window.Scale(0.9, 0.9);
                        //window.Offset(spaceX, spaceY);
                        window.Inflate(-spaceX, -spaceY);
                        drawingContext.DrawRectangle(new SolidColorBrush(color), null, window);

                    }
                }
            }
        }
        protected override void OnRender(DrawingContext dc)
        {
            Rect rect = new Rect(new Point(0, 0), RenderSize);
            rect.Inflate(-1, -1);
            Pen pen = new Pen(SystemColors.HighlightBrush, 1);

            if (IsHighlighted)
                dc.DrawRectangle(SystemColors.ControlDarkBrush, pen, rect);
            else if (IsSelected)
                dc.DrawRectangle(SystemColors.ControlLightBrush, pen, rect);
            else
                dc.DrawRectangle(Brushes.Transparent, null, rect);
        }
        /// <summary>
        /// Returns the handle rect (both visibile and the tolerance one)
        /// </summary>
        private void GetHandleRect(InkCanvasSelectionHitResult hitResult, Rect rectWireFrame, out Rect visibleRect, out Rect toleranceRect)
        {
            Point center = new Point();
            double size = 0;
            double tolerance = ResizeHandleTolerance;

            switch ( hitResult )
            {
                case InkCanvasSelectionHitResult.TopLeft:
                    {
                        size = CornerResizeHandleSize;
                        center = new Point(rectWireFrame.Left, rectWireFrame.Top);
                        break;
                    }
                case InkCanvasSelectionHitResult.Top:
                    {
                        size = MiddleResizeHandleSize;
                        center = new Point(rectWireFrame.Left + rectWireFrame.Width / 2, rectWireFrame.Top);
                        tolerance = (CornerResizeHandleSize - MiddleResizeHandleSize) + ResizeHandleTolerance;
                        break;
                    }
                case InkCanvasSelectionHitResult.TopRight:
                    {
                        size = CornerResizeHandleSize;
                        center = new Point(rectWireFrame.Right, rectWireFrame.Top);
                        break;
                    }
                case InkCanvasSelectionHitResult.Left:
                    {
                        size = MiddleResizeHandleSize;
                        center = new Point(rectWireFrame.Left, rectWireFrame.Top + rectWireFrame.Height / 2);
                        tolerance = (CornerResizeHandleSize - MiddleResizeHandleSize) + ResizeHandleTolerance;
                        break;
                    }
                case InkCanvasSelectionHitResult.Right:
                    {
                        size = MiddleResizeHandleSize;
                        center = new Point(rectWireFrame.Right, rectWireFrame.Top + rectWireFrame.Height / 2);
                        tolerance = (CornerResizeHandleSize - MiddleResizeHandleSize) + ResizeHandleTolerance;
                        break;
                    }
                case InkCanvasSelectionHitResult.BottomLeft:
                    {
                        size = CornerResizeHandleSize;
                        center = new Point(rectWireFrame.Left, rectWireFrame.Bottom);
                        break;
                    }
                case InkCanvasSelectionHitResult.Bottom:
                    {
                        size = MiddleResizeHandleSize;
                        center = new Point(rectWireFrame.Left + rectWireFrame.Width / 2, rectWireFrame.Bottom);
                        tolerance = (CornerResizeHandleSize - MiddleResizeHandleSize) + ResizeHandleTolerance;
                        break;
                    }
                case InkCanvasSelectionHitResult.BottomRight:
                    {
                        size = CornerResizeHandleSize;
                        center = new Point(rectWireFrame.Right, rectWireFrame.Bottom);
                        break;
                    }
            }

            visibleRect = new Rect(center.X - size / 2, center.Y - size / 2, size, size);
            toleranceRect = visibleRect;
            toleranceRect.Inflate(tolerance, tolerance);
        }
        private static Rect GetRectWithMargin(ConnectorInfo connectorThumb, double margin)
        {
            Rect rect = new Rect(connectorThumb.DesignerItemLeft,
                                 connectorThumb.DesignerItemTop,
                                 0,
                                 0);

            rect.Inflate(margin, margin);

            return rect;
        }
        private void DrawBorders(DrawingContext dc, ref Rect bounds)
        {
            if ((bounds.Width >= 2.0) && (bounds.Height >= 2.0))
            {
                Brush brush = Fill;
                Pen pen = OuterBorder;
                if (pen != null)
                {
                    dc.DrawRoundedRectangle(
                        brush,
                        pen,
                        new Rect(bounds.X, bounds.Y, bounds.Width, bounds.Height),
                        2.0, 2.0);
                    brush = null; // Done with the fill
                    bounds.Inflate(-1.0, -1.0);
                }

                if ((bounds.Width >= 2.0) && (bounds.Height >= 2.0))
                {
                    pen = InnerBorder;
                    if ((pen != null) || (brush != null))
                    {
                        dc.DrawRoundedRectangle(
                            brush,
                            pen,
                            new Rect(bounds.X, bounds.Y, bounds.Width, bounds.Height),
                            1.5, 1.5);
                        bounds.Inflate(-1.0, -1.0);
                    }
                }
            }
        }
			FormattedText FormatText(String Input, Rect DrawingRect, double StartingFontSize = -1)
			{
			DrawingRect.Inflate(0, 0);
			double emSize = DrawingRect.Height;
			if (StartingFontSize > 0)
				emSize = StartingFontSize;
			String FontFamily = "Arial Narrow";		//"Gill Sans MT Condensed";	//"Arial Narrow";
			String FontStyle = "Bold";
			
			Typeface DefaultTypeface = new Typeface(new FontFamily(FontFamily), FontStyles.Normal,
				 FontWeights.Normal, FontStretches.UltraCondensed, new FontFamily(FontFamily));
			if (FontStyle == "Bold")
				DefaultTypeface = new Typeface(new FontFamily(FontFamily), FontStyles.Normal,
				 FontWeights.Bold, FontStretches.UltraCondensed, new FontFamily(FontFamily));

			Brush TextBrush = (Brush)new BrushConverter().ConvertFromString("black");
			FormattedText FinalTextBlock = null;
			do
				{
				FinalTextBlock = new FormattedText(Input, CultureInfo.CurrentCulture,
					FlowDirection.LeftToRight, DefaultTypeface, emSize, TextBrush);
				FinalTextBlock.TextAlignment = TextAlignment.Center;
				FinalTextBlock.MaxTextWidth = DrawingRect.Width;
				emSize /= 1.05;
				} while ((FinalTextBlock.Height > DrawingRect.Height)
						|| (FinalTextBlock.Width > DrawingRect.Width));

			return FinalTextBlock;
			}
Example #23
0
 /// <summary>
 /// Inflate - return the result of inflating rect by the size provided, in all directions
 /// If this is Empty, this method is illegal.
 /// </summary>
 public static Rect Inflate(Rect rect, Size size)
 {
     rect.Inflate(size._width, size._height);
     return(rect);
 }
Example #24
0
 public static Rect Inflate(Rect rect, Size size)
 {
     return(Rect.Inflate(rect, size.Width, size.Height));
 }
Example #25
0
        /// <summary>
        /// Draw the connector lines at a lower level (OnRender) instead
        /// of creating visual tree objects.
        /// </summary>
        protected override void OnRender(DrawingContext drawingContext)
        {
#if DEBUG
            if (displayBorder)
            {
                // Draws borders around the rows and groups.
                foreach (DiagramRow row in rows)
                {
                    // Display row border.
                    Rect bounds = new Rect(row.Location, row.DesiredSize);
                    drawingContext.DrawRectangle(null, new Pen(Brushes.DarkKhaki, 1), bounds);

                    foreach (DiagramGroup group in row.Groups)
                    {
                        // Display group border.
                        bounds = new Rect(group.Location, group.DesiredSize);
                        bounds.Offset(row.Location.X, row.Location.Y);
                        bounds.Inflate(-1, -1);
                        drawingContext.DrawRectangle(null, new Pen(Brushes.Gray, 1), bounds);
                    }
                }
            }
#endif

            // Draw child connectors first, so marriage information appears on top.
            foreach (DiagramConnector connector in logic.Connections)
            {
                if (connector.IsChildConnector)
                    connector.Draw(drawingContext);
            }

            // Draw all other non-child connectors.
            foreach (DiagramConnector connector in logic.Connections)
            {
                if (!connector.IsChildConnector)
                    connector.Draw(drawingContext);
            }
        }
Example #26
0
        public static BitmapSource DrawFaces(BitmapSource baseImage, Face[] faces, EmotionScores[] emotionScores,
                                             string[] celebName, List <string> _id)
        {
            if (faces == null)
            {
                return(baseImage);
            }

            Action <DrawingContext, double> drawAction = (drawingContext, annotationScale) =>
            {
                for (var i = 0; i < faces.Length; i++)
                {
                    var face = faces[i];
                    if (face.FaceRectangle == null)
                    {
                        continue;
                    }

                    var faceRect = new System.Windows.Rect(
                        face.FaceRectangle.Left, face.FaceRectangle.Top,
                        face.FaceRectangle.Width, face.FaceRectangle.Height);
                    var text = "";

                    if (face.FaceAttributes != null)
                    {
                        if (_id[i] != "Unidentified")
                        {
                            _sLineBrush = new SolidColorBrush(new Color {
                                R = 0, G = 185, B = 0, A = 255
                            });
                            text = _id[i];
                        }
                        else
                        {
                            _sLineBrush = new SolidColorBrush(new Color {
                                R = 255, G = 185, B = 0, A = 255
                            });
                            text  = _id[i] + "  (";
                            text += Aggregation.SummarizeFaceAttributes(face.FaceAttributes) + ")";
                        }
                    }

                    if (emotionScores?[i] != null)
                    {
                        text += Aggregation.SummarizeEmotion(emotionScores[i]);
                    }

                    if (celebName?[i] != null)
                    {
                        text += celebName[i];
                    }

                    faceRect.Inflate(6 * annotationScale, 6 * annotationScale);

                    var lineThickness = 4 * annotationScale;


                    drawingContext.DrawRectangle(
                        Brushes.Transparent,
                        new Pen(_sLineBrush, lineThickness),
                        faceRect);

                    if (text != "")
                    {
#pragma warning disable CS0618 // Type or member is obsolete
                        var ft = new FormattedText(text,
                                                   CultureInfo.CurrentCulture, FlowDirection.LeftToRight, STypeface,
                                                   16 * annotationScale, Brushes.Black);
#pragma warning restore CS0618 // Type or member is obsolete

                        var pad = 3 * annotationScale;

                        var ypad   = pad;
                        var xpad   = pad + 4 * annotationScale;
                        var origin = new Point(
                            faceRect.Left + xpad - lineThickness / 2,
                            faceRect.Top - ft.Height - ypad + lineThickness / 2);
                        var rect = ft.BuildHighlightGeometry(origin).GetRenderBounds(null);
                        rect.Inflate(xpad, ypad);

                        drawingContext.DrawRectangle(_sLineBrush, null, rect);
                        drawingContext.DrawText(ft, origin);
                    }
                }
            };

            return(DrawOverlay(baseImage, drawAction));
        }
Example #27
0
        /// <summary>
        /// Applies the selection box on the view to know the selected items.
        /// </summary>
        private void ApplySelectionBox()
        {
            // Clear selection.
            this.ParentView.SelectedItems.Clear();

            // Hidding the canvas hosting the selection box.
            this.SelectionBoxCanvas.Visibility = Visibility.Collapsed;
            this.SelectionBox.Visibility = Visibility.Collapsed;

            double lX = Canvas.GetLeft(this.SelectionBox);
            double lY = Canvas.GetTop(this.SelectionBox);
            double lWidth = this.SelectionBox.Width;
            double lHeight = this.SelectionBox.Height;
            Rect lSelectionRect = new Rect(lX, lY, lWidth, lHeight);

            // Inflate the drag selection-rectangle by 1/10 of its size to make sure the intended item is selected.
            lSelectionRect.Inflate(lWidth / 10, lHeight / 10);

            // Selecting the items contained in the selection rect.
            foreach (IGraphItemViewModel lItem in this.ParentView.ItemsSource)
            {
                // Getting the corresponding container.
                AGraphItemContainer lContainer = this.ParentView.GetContainerForViewModel(lItem);
                if (lContainer != null)
                {
                    if (lSelectionRect.Contains(lContainer.BoundingBox))
                    {
                        this.ParentView.SelectedItems.Add(lItem);
                    }
                }
            }
        }
        public Geometry BuildGeometryForRange(TextCoordinate end1, TextCoordinate end2)
        {
            if (end1 == end2)
            {
                // No selection. Empty geometry.
                return Geometry.Empty;
            }

            Geometry resultGeometry;

            if (end1.Line == end2.Line)
            {
                int left = Math.Min(end1.Index, end2.Index);
                int right = Math.Max(end1.Index, end2.Index);

                var rect = new Rect(left * this.charWidth, end1.Line * this.lineHeight, (right - left) * this.charWidth, this.lineHeight);

                // Must inflate the rect just a bit -- otherwise, rounding issues cause incomplete union combinations (below -- even though this
                // particular rect won't ever be combined, we want it to have the same size when single-line).
                rect.Inflate(.5, .5);
                resultGeometry = new RectangleGeometry(rect);
            }
            else
            {
                var top = (end1.Line < end2.Line) ? end1 : end2;
                var bottom = (end1.Line < end2.Line) ? end2 : end1;

                var topRect = new Rect(top.Index * charWidth, top.Line * this.lineHeight, this.maxHorizontal + this.canvas.ActualWidth + 2, this.lineHeight);
                var midRect = new Rect(0, (top.Line + 1) * this.lineHeight, this.maxHorizontal + this.canvas.ActualWidth + 2, (bottom.Line - top.Line - 1) * this.lineHeight);
                var bottomRect = new Rect(0, bottom.Line * this.lineHeight, bottom.Index * this.charWidth, this.lineHeight);

                // Inflate to ensure overlap for correct union combination
                topRect.Inflate(.5, .5);
                midRect.Inflate(.5, .5);
                bottomRect.Inflate(.5, .5);
                var topGeometry = new RectangleGeometry(topRect);
                var bottomGeometry = new RectangleGeometry(bottomRect);

                if (top.Line == bottom.Line - 1)
                {
                    // Just top and bottom -- no lines between
                    resultGeometry = new CombinedGeometry(GeometryCombineMode.Union, topGeometry, bottomGeometry);
                }
                else
                {
                    // Two combinations for 3 geometries
                    var midGeometry = new RectangleGeometry(midRect);
                    var firstCombinedGeometry = new CombinedGeometry(GeometryCombineMode.Union, topGeometry, midGeometry);

                    resultGeometry = new CombinedGeometry(GeometryCombineMode.Union, firstCombinedGeometry, bottomGeometry);
                }
            }

            resultGeometry.Transform = this.highlightTransform;
            return resultGeometry;
        }
Example #29
0
        private void CheckMouseOver(object?sender, EventArgs e)
        {
            if (this.mouseOverWindows.Count == 0)
            {
                return;
            }

            bool isOver = false;
            IEnumerable <Window> windows = this.mouseOverWindows.Where(w => w.IsVisible && w.Opacity > 0);

            Point?cursor = null;

            // Window.IsMouseOver is false if the mouse is over the window border, check if that's the case.
            foreach (Window window in windows)
            {
                if (window.IsMouseOver)
                {
                    isOver = true;
                    break;
                }

                cursor ??= PresentationSource.FromVisual(window)?.CompositionTarget.TransformFromDevice
                .Transform(WindowMovement.GetCursorPos());

                if (cursor is not null)
                {
                    System.Windows.Rect rc = window.GetRect();
                    rc.Inflate(10, 10);
                    if (rc.Contains(cursor.Value))
                    {
                        isOver = true;
                        if (this.mouseTimer is null)
                        {
                            // Keep an eye on the current position.
                            this.mouseTimer = new DispatcherTimer(DispatcherPriority.Input)
                            {
                                Interval = TimeSpan.FromMilliseconds(100),
                            };
                            this.mouseTimer.Tick += this.CheckMouseOver;
                            this.mouseTimer.Start();
                        }

                        break;
                    }
                }
            }

            if (!isOver)
            {
                this.mouseTimer?.Stop();
                this.mouseTimer = null;
            }

            if (this.mouseOver != isOver)
            {
                this.mouseOver = isOver;
                if (isOver)
                {
                    this.MouseEnter?.Invoke(sender, new EventArgs());
                }
                else
                {
                    this.MouseLeave?.Invoke(sender, new EventArgs());
                }
            }
        }
Example #30
0
        private Rect MakeRectVisible(Rect rectangle)
        {
            double desiredWidth = CanHorizontallyScroll ? Math.Min(rectangle.Width*1.6, _viewport.Width) : rectangle.Width;
            double desiredHeight = CanVerticallyScroll ? Math.Min(rectangle.Height*1.6, _viewport.Height) : rectangle.Height;
            rectangle.Inflate(Math.Max(desiredWidth - rectangle.Width, 0)*0.5, Math.Max(desiredHeight - rectangle.Height, 0)*0.5);

            if (ExtentWidth - rectangle.Right <= EndScrollPadding + 1) {
                rectangle.Width += EndScrollPadding;
            }

            var viewRect = new Rect(HorizontalOffset, VerticalOffset, ViewportWidth, ViewportHeight);
            viewRect.X = CalculateNewScrollOffset(viewRect.Left,
                                                  viewRect.Right, rectangle.Left, rectangle.Right);
            viewRect.Y = CalculateNewScrollOffset(viewRect.Top,
                                                  viewRect.Bottom, rectangle.Top, rectangle.Bottom);
            
            SetHorizontalOffset(viewRect.X);
            SetVerticalOffset(viewRect.Y);
            rectangle.Intersect(viewRect);
            rectangle.X -= viewRect.X;
            rectangle.Y -= viewRect.Y;

            return rectangle;
        }
		public void Inflate ()
		{
			Rect r = Rect.Inflate (new Rect (0, 0, 20, 20), 10, 15);
			Assert.AreEqual (new Rect (-10, -15, 40, 50), r);

			r = Rect.Inflate (new Rect (0, 0, 20, 20), new Size (10, 15));
			Assert.AreEqual (new Rect (-10, -15, 40, 50), r);

			r = new Rect (0, 0, 20, 20);
			r.Inflate (10, 15);
			Assert.AreEqual (new Rect (-10, -15, 40, 50), r);

			r = new Rect (0, 0, 20, 20);
			r.Inflate (new Size (10, 15));
			Assert.AreEqual (new Rect (-10, -15, 40, 50), r);
		}
Example #32
0
 /// <summary>
 /// Inflate - return the result of inflating rect by the size provided, in all directions
 /// If this is Empty, this method is illegal.
 /// </summary>
 public static Rect Inflate(Rect rect, double width, double height)
 {
     rect.Inflate(width, height);
     return(rect);
 }
			public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
			{
				Point p = _element.TranslatePoint(new Point(), panel.AdornedElement);
				var rect = new Rect(p, _element.RenderSize);
				rect.Inflate(3, 1);
				adorner.Arrange(rect);
			}
Example #34
0
 private static bool RectangleIntersectsLine(Rect rect, Point startPoint, Point endPoint)
 {
     rect.Inflate(-1, -1);
     return rect.IntersectsWith(new Rect(startPoint, endPoint));
 }
Example #35
0
            public void UpdateGeometry()
            {
                Rect tabRect = new Rect(2.0, 3.0, this.ActualWidth - 4.0, this.ActualHeight - 2.0);
                tabRect.Inflate(-.5, -.5);
                Rect leftTabCurveRect = new Rect(tabRect.Left, tabRect.Top, kTabCurveWidth, tabRect.Height);
                Rect rightTabCurveRect = new Rect(tabRect.Left + tabRect.Width - kTabCurveWidth, tabRect.Top, kTabCurveWidth, tabRect.Height);

                PathFigure tabFigure = new PathFigure();

                tabFigure.StartPoint = tabRect.BottomLeft;

                // Left curve
                tabFigure.Segments.Add(new BezierSegment(new Point(leftTabCurveRect.Left + (kTabCurveWidth / 2), leftTabCurveRect.Bottom),
                    new Point(leftTabCurveRect.Right - (kTabCurveWidth / 2), leftTabCurveRect.Top),
                    leftTabCurveRect.TopRight,
                    true));

                // Top line
                tabFigure.Segments.Add(new LineSegment(rightTabCurveRect.TopLeft, true));

                // Right curve
                tabFigure.Segments.Add(new BezierSegment(new Point(rightTabCurveRect.Left + (kTabCurveWidth / 2), rightTabCurveRect.Top),
                    new Point(rightTabCurveRect.Right - (kTabCurveWidth / 2), rightTabCurveRect.Bottom),
                    rightTabCurveRect.BottomRight,
                    true));

                PathGeometry tabGeometry = new PathGeometry();
                tabGeometry.Figures.Add(tabFigure);

                tabPath = tabGeometry;
            }
Example #36
0
        void Render()
        {
            if (!_loaded || UpdateCount > 0)
            return;

              if (Chart != null)
              {
            var prect = Chart.View.PlotRect;
            var bnds = new Rect(0,0,prect.Width, prect.Height);
            bnds.Inflate(1, 1);

            var offset = Chart.TranslatePoint(new Point(), (UIElement)this.Parent);
            offset.X = prect.X - offset.X;
            offset.Y = prect.Y - offset.Y;

            foreach (var label in Children)
            {
              if (!base.Children.Contains(label))
            base.Children.Add(label);
              var line = label.ConnectingLine;
              if (!base.Children.Contains(line))
            base.Children.Add(line);

              if (!Chart.ChartType.ToString().StartsWith("Pie"))
              {
            label.UpdateAttachPoint(Chart, offset);

            if (bnds.Contains(label.AttachPoint))
              label.Visibility = Visibility.Visible;
            else
              label.Visibility = Visibility.Collapsed;
              }
              else
            label.UpdateAttachPoint(Chart, new Point());
            }

            if (LabelArranger != null)
              LabelArranger.Arrange(Children.ToArray(), OccupiedRects, new Rect(0, 0, prect.Width, prect.Height));

            foreach (var label in Children)
            {
              var line = label.ConnectingLine;
              var pt = label.AttachPoint;

              line.X1 = pt.X; line.Y1 = pt.Y;

              var pt1 = LabelHelper.GetConnectingPoint(label);

              if (!double.IsNaN(pt1.X) && !double.IsNaN(pt1.Y))
              {
            line.X2 = pt1.X; line.Y2 = pt1.Y;
              }
            }

            _state = new ChartState(Chart);
              }
        }
Example #37
0
        private void UpdateAnimatingBackToRiver(RiverItemState state)
        {
            ScatterViewItem svi = state.Svi;

            if (state.IsAnimatingBackToRiverComplete)
            {
                // When the animation is complete, return the item to the river.
                state.IsAnimatingBackToRiver = false;
                state.IsAnimatingBackToRiverComplete = false;
                state.IsRemovedFromRiver = false;
                state.Svi.IsHitTestVisible = true;
                state.RemovedSize = Size.Empty;
                state.Svi = null;
                _scatterView.Items.Remove(svi);
                _stateToProxyMap[state].Visibility = Visibility.Visible;
                UpdateScrollPosition(_stateToProxyMap[state], state);
                return;
            }

            Rect screen = new Rect(0, 0, Application.Current.MainWindow.ActualWidth, Application.Current.MainWindow.ActualHeight);
            double diagonal = (new Point(svi.ActualWidth, svi.ActualHeight) - new Point()).Length;
            screen.Inflate(new Size(diagonal, diagonal));

            double currentTime = (DateTime.Now - state.AnimateBackBeginTime).TotalSeconds;

            // Determine the size to animate to.
            bool isPortrait = state.RowSpan > state.ColumnSpan;
            double itemWidth = state.ColumnSpan * GridCellSize.Width;
            double itemHeight = state.RowSpan * GridCellSize.Height;
            itemWidth += Plane.GetPlaneFrontPadding(svi).Left + Plane.GetPlaneFrontPadding(svi).Right;
            itemHeight += Plane.GetPlaneFrontPadding(svi).Top + Plane.GetPlaneFrontPadding(svi).Bottom;
            double targetWidth = isPortrait ? itemHeight : itemWidth;
            double targetHeight = isPortrait ? itemWidth : itemHeight;

            // Determine the orientation to animate to.
            double begin = state.AnimateBackFromOrientation % 360;
            double end = state.OriginalOrientation % 360;
            double change = end - begin;
            if (Math.Abs(change) > 180)
            {
                // Don't go the long way around.
                if (end < begin)
                {
                    end += 360;
                }
                else
                {
                    begin += 360;
                }
            }

            change = end - begin;
            double orientationTime = Math.Abs(change / OrientSpeed);

            // Determine the center to animate to.
            Point center = GetItemCenter(state);
            double scrollChange = state.ReturnHorizontalOffset - state.OriginalHorizontalOffset;
            if (center.X > ActualWidth && scrollChange > 0)
            {
                // The position looped around, so just go off-screen left.
                center.X = -diagonal;
            }
            else if (center.X < 0 && scrollChange < 0)
            {
                // The position looped around, so just go off-screen right.
                center.X = ActualWidth + diagonal;
            }

            double centerTime = (state.AnimateBackFromCenter - center).Length / ReturnToRiverSpeed;

            // The duration of the animation will be the duration of the orientation or center animations, whichever is longer.
            double totalTime = centerTime >= MinimumTransitionDuration.TotalSeconds || centerTime > orientationTime ? centerTime : orientationTime;
            totalTime = Math.Max(totalTime, MinimumTransitionDuration.TotalSeconds);

            // Update the orientation animation.
            if (currentTime < totalTime && Math.Abs(state.OriginalOrientation - svi.Orientation) > 1)
            {
                svi.Orientation = SineEaseOut(currentTime, begin, change, totalTime);
            }
            else
            {
                svi.Orientation = state.OriginalOrientation;
            }

            // Update the center animation.
            if (currentTime < totalTime && (svi.Center - center).Length > 1)
            {
                svi.Center = new Point(
                    SineEaseOut(currentTime, state.AnimateBackFromCenter.X, center.X - state.AnimateBackFromCenter.X, totalTime),
                    SineEaseOut(currentTime, state.AnimateBackFromCenter.Y, center.Y - state.AnimateBackFromCenter.Y, totalTime));
            }
            else
            {
                svi.Center = center;
            }

            // Update the width animation.
            if (currentTime < totalTime && Math.Abs(targetWidth - svi.ActualWidth) > 1)
            {
                svi.Width = SineEaseOut(currentTime, state.AnimateBackFromSize.Width, targetWidth - state.AnimateBackFromSize.Width, totalTime);
            }
            else
            {
                svi.Width = targetWidth;
            }

            // Update the height animation.
            if (currentTime < totalTime && Math.Abs(targetHeight - svi.ActualHeight) > 1)
            {
                svi.Height = SineEaseOut(currentTime, state.AnimateBackFromSize.Height, targetHeight - state.AnimateBackFromSize.Height, totalTime);
            }
            else
            {
                svi.Height = targetHeight;
            }

            // If the item animated offscreen, just let it go.
            bool isOutsideScreen = !screen.Contains(svi.Center);
            if (isOutsideScreen)
            {
                svi.Orientation = state.OriginalOrientation;
                svi.Center = center;
                svi.Width = targetWidth;
                svi.Height = targetHeight;
            }

            state.IsAnimatingBackToRiverComplete =
                svi.Orientation == state.OriginalOrientation &&
                svi.Center == center &&
                svi.Width == targetWidth &&
                svi.Height == targetHeight;
        }