Exemple #1
1
      // assumptions for pixel snapping: 
      // - the drawing context itself is pixel snapped
      // - all strokes have same thickness
      // - the thickness is a whole number


      #region ELLIPSES
      /// <summary>See <c>WpfExtensions</c> for details.</summary>
      public static void DrawEllipse(DrawingContext dc, Paint paint, Point center, double radiusX, double radiusY, bool snapToPixel) {
         // get brush and stroke resources
         if (paint == null) return;
         var fill = paint.Fill;
         var hasFill = (fill != null);
         var strokes = paint.GetStrokePens().ToArray();
         var numStrokes = strokes.Length;
         if (!hasFill && numStrokes == 0) return;

         var halfThickness = Math.Round(numStrokes > 0? strokes[0].Thickness : 0.0) / 2;
         if (snapToPixel) {
            center = new Point(center.X + halfThickness, center.Y + halfThickness);
         }

         if (numStrokes > 0) {
            for (var i = 0; i < numStrokes - 1; i++) {
               dc.DrawEllipse(null, strokes[i], center, radiusX, radiusY);
               radiusX = (radiusX - 2 * halfThickness).Max(0);
               radiusY = (radiusY - 2 * halfThickness).Max(0);
            }
            dc.DrawEllipse(fill, strokes[numStrokes - 1], center, radiusX, radiusY);
         } else {
            dc.DrawEllipse(fill, null, center, radiusX, radiusY);
         }

      }
Exemple #2
0
 public static void GetDrContext(System.Windows.Media.DrawingContext drawingContext, LIVE_TYPE type, bool isSelect, string name)
 {
     if (type == LIVE_TYPE.HUMANOID)
     {
         drawingContext.DrawEllipse(new SolidColorBrush(Colors.Red), new Pen(new SolidColorBrush(Colors.Black), 1), new System.Windows.Point(15, 6), 3, 3);
         drawingContext.DrawEllipse(new SolidColorBrush(Colors.Red), new Pen(new SolidColorBrush(Colors.Black), 1), new System.Windows.Point(15, 15), 3, 5);
         drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Black), 1), new Point(14, 20), new Point(12, 27));
         drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Black), 1), new Point(16, 20), new Point(18, 27));
         drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Black), 1), new Point(14, 11), new Point(7, 13));
         drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Black), 1), new Point(16, 11), new Point(23, 13));
         drawingContext.DrawText(new FormattedText(name, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 12, new SolidColorBrush(Colors.Green)), new Point(0, 30));
         if (isSelect)
         {
             drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Green), 1), new Point(7, 11), new Point(7, 27));
         }
     }
     if (type == LIVE_TYPE.DOG)
     {
         drawingContext.DrawEllipse(new SolidColorBrush(Colors.Blue), new Pen(new SolidColorBrush(Colors.Black), 1), new System.Windows.Point(10, 15), 3, 3);
         drawingContext.DrawEllipse(new SolidColorBrush(Colors.Blue), new Pen(new SolidColorBrush(Colors.Black), 1), new System.Windows.Point(15, 20), 5, 3);
         drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Black), 1), new Point(12, 23), new Point(10, 27));
         drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Black), 1), new Point(12, 23), new Point(14, 27));
         drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Black), 1), new Point(18, 23), new Point(16, 27));
         drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Black), 1), new Point(18, 23), new Point(20, 27));
         drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Black), 1), new Point(20, 20), new Point(23, 14));
         drawingContext.DrawText(new FormattedText(name, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 12, new SolidColorBrush(Colors.Green)), new Point(0, 30));
         if (isSelect)
         {
             drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Green), 1), new Point(7, 11), new Point(7, 27));
         }
     }
 }
        protected override void OnRender(DrawingContext dc)
        {

            var lightBrush = new SolidColorBrush(Colors.LightGray);
            var darkBrush = new SolidColorBrush(Colors.Black);
            lightBrush.Opacity = 0.4;
            darkBrush.Opacity = 0.1;

            double t1 = 6; // thickness of dark circle pen
            double t2 = 2; // thickness of light pen (circle, arcs, segments)
            double d = 0; // distance from light circle to segments
            double l = 10; // length of segments
            double r = 20.0; // radius of light circle

            double r1 = r - (t1 + t2) / 2;
            double r2 = r + l;
            double r3 = r + t2 / 2 + d;
            double r4 = (r + r2) / 2;

            var darkPen = new Pen(darkBrush, t1);
            var lightPen = new Pen(lightBrush, t2);

            dc.DrawEllipse(null, lightPen, Position, r, r);
            dc.DrawEllipse(null, darkPen, Position, r1, r1);
            dc.DrawArc(null, lightPen, Position, 10, 80, r4, r4);
            dc.DrawArc(null, lightPen, Position, 100, 170, r4, r4);
            dc.DrawArc(null, lightPen, Position, 190, 260, r4, r4);
            dc.DrawArc(null, lightPen, Position, 280, 350, r4, r4);

            dc.DrawLine(lightPen, new Point(Position.X, Position.Y - r2), new Point(Position.X, Position.Y - r3));
            dc.DrawLine(lightPen, new Point(Position.X, Position.Y + r2), new Point(Position.X, Position.Y + r3));
            dc.DrawLine(lightPen, new Point(Position.X - r2, Position.Y), new Point(Position.X - r3, Position.Y));
            dc.DrawLine(lightPen, new Point(Position.X + r2, Position.Y), new Point(Position.X + r3, Position.Y));
        }
Exemple #4
0
            protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
            {
                SolidColorBrush renderBrush = new SolidColorBrush(Colors.LightCoral);

                Pen renderPen = new Pen(new SolidColorBrush(Colors.DarkBlue), 1.0);


                if (this.AdornedElement is Path path)
                {
                    double fraction = 0.5;  //the relative point of the curve
                    Point  pt;              //the absolute point of the curve
                    Point  tg;              //the tangent point of the curve
                    (path.RenderedGeometry as PathGeometry).GetPointAtFractionLength(
                        fraction,
                        out pt,
                        out tg);
                    drawingContext.DrawEllipse(renderBrush, renderPen, new Point(pt.X, pt.Y), 20, 20);
                }
                if (this.AdornedElement is PathPolyLine pathpolyline)
                {
                    var y = ((ConnectionPoint)pathpolyline.EndPoint).Position.Y + ((ConnectionPoint)pathpolyline.StartPoint).Position.Y;
                    var x = ((ConnectionPoint)pathpolyline.EndPoint).Position.X + ((ConnectionPoint)pathpolyline.StartPoint).Position.X;

                    drawingContext.DrawEllipse(renderBrush, renderPen, new Point(x / 2, y / 2), 20, 20);
                }
                else
                {
                    drawingContext.DrawEllipse(renderBrush, renderPen, new Point(10, 10), 20, 20);
                }
            }
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            SolidColorBrush blackBrush = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            SolidColorBrush greenBrush = new SolidColorBrush(Color.FromRgb(0, 128, 0));
            SolidColorBrush redBrush   = new SolidColorBrush(Color.FromRgb(200, 0, 0));
            Pen             blackPen   = new Pen(blackBrush, 1);
            Pen             greenPen   = new Pen(greenBrush, 1);
            Pen             redPen     = new Pen(redBrush, 1);

            drawingContext.DrawRectangle(null, blackPen, _size);



            if (Universe == null)
            {
                return;
            }

            foreach (FoodElement element in Universe.Food)
            {
                drawingContext.DrawEllipse(null, greenPen, new Point(element.CenterX, element.CenterY), element.Width, element.Width);
            }

            foreach (CreatureElement creature in Universe.Creatures)
            {
                drawingContext.DrawEllipse(null, redPen, new Point(creature.CenterX, creature.CenterY), creature.Width, creature.Width);
            }
        }
Exemple #6
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            Pen pen = new Pen(new SolidColorBrush(Colors.Black), 1);

            if (LightOn)
            {
                GradientStopCollection stopC2 = new GradientStopCollection();
                stopC2.Add(new GradientStop(Colors.White, 0));
                stopC2.Add(new GradientStop(Colors.Red, 1));
                RadialGradientBrush r2 = new RadialGradientBrush(stopC2);
                r2.RadiusX        = 1;
                r2.RadiusY        = 1;
                r2.GradientOrigin = new Point(0.7, 0.3);

                drawingContext.DrawEllipse(r2, pen, new Point(Width / 2, Height / 2), Width / 2, Height / 2);
            }
            else
            {
                GradientStopCollection stopC1 = new GradientStopCollection();
                stopC1.Add(new GradientStop(Colors.White, 0));
                stopC1.Add(new GradientStop(Colors.LightGreen, 1));
                RadialGradientBrush r1 = new RadialGradientBrush(stopC1);
                r1.RadiusX        = 1;
                r1.RadiusY        = 1;
                r1.GradientOrigin = new Point(0.7, 0.3);

                drawingContext.DrawEllipse(r1, pen, new Point(Width / 2, Height / 2), Width / 2, Height / 2);
            }
        }
Exemple #7
0
 protected virtual void DrawCenter(HandData hand, DrawingContext drawingContext)
 {
     drawingContext.DrawEllipse(Brushes.Blue, null, new System.Windows.Point(hand.Location.X, hand.Location.Y), 5, 5);
     if (hand.HasPalmPoint) {
         drawingContext.DrawEllipse(Brushes.SpringGreen, null, new System.Windows.Point(hand.PalmPoint.Value.X, hand.PalmPoint.Value.Y), 5, 5);
         var palmSize = hand.PalmDistance;
         drawingContext.DrawEllipse(null, this.greenPen, new System.Windows.Point(hand.PalmPoint.Value.X, hand.PalmPoint.Value.Y), palmSize, palmSize);
     }
 }
Exemple #8
0
 protected override void OnRender(DrawingContext dc)
 {
     base.OnRender(dc);
     Size rectSize = new Size(RenderSize.Width + 6, RenderSize.Height + 6);
     Rect rect = new Rect(new Point(-3, -3), rectSize);
     dc.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Blue, 1), rect);
     dc.DrawEllipse(Brushes.Red, new Pen(Brushes.Blue, 1), new Point(0, 0), 6, 6);
     dc.DrawEllipse(Brushes.Red, new Pen(Brushes.Blue, 1), new Point(0, this.ActualHeight), 6, 6);
     dc.DrawEllipse(Brushes.Red, new Pen(Brushes.Blue, 1), new Point(this.ActualWidth, this.ActualHeight), 6, 6);
     dc.DrawEllipse(Brushes.Red, new Pen(Brushes.Blue, 1), new Point(this.ActualWidth, 0), 6, 6);
 }
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            Rect adornedElementRect = GetAdornedElementRect();
            drawingContext.DrawRectangle(Brushes.Transparent, _pen, adornedElementRect);
            drawingContext.DrawEllipse(_brush, null, adornedElementRect.TopLeft, HANDLE_SIZE, HANDLE_SIZE);
            drawingContext.DrawEllipse(_brush, null, adornedElementRect.TopRight, HANDLE_SIZE, HANDLE_SIZE);
            drawingContext.DrawEllipse(_brush, null, adornedElementRect.BottomRight, HANDLE_SIZE, HANDLE_SIZE);
            drawingContext.DrawEllipse(_brush, null, adornedElementRect.BottomLeft, HANDLE_SIZE, HANDLE_SIZE);
        }
Exemple #10
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            //if (!(_target is IScreen))
            {
                if (_isOpening)
                {
                    SolidColorBrush fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2200FF00"));
                    drawingContext.DrawRectangle(fill, null, new Rect(0, 0, ActualWidth, ActualHeight));
                }
                else
                {
                    SolidColorBrush fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#050000FF"));
                    drawingContext.DrawRectangle(fill, null, new Rect(0, 0, ActualWidth, ActualHeight));
                }

                if (_canDrop)
                {
                    SolidColorBrush border = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#CCFFFFFF"));
                    SolidColorBrush dot    = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#CC0000FF"));

                    RenderOptions.SetEdgeMode(this, EdgeMode.Unspecified);
                    drawingContext.DrawEllipse(border, null, new Point(0, 0), RADIUS + BORDER, RADIUS + BORDER);
                    drawingContext.DrawEllipse(border, null, new Point(0, ActualHeight), RADIUS + BORDER, RADIUS + BORDER);
                    drawingContext.DrawEllipse(border, null, new Point(ActualWidth, 0), RADIUS + BORDER, RADIUS + BORDER);
                    drawingContext.DrawEllipse(border, null, new Point(ActualWidth, ActualHeight), RADIUS + BORDER, RADIUS + BORDER);

                    drawingContext.DrawEllipse(dot, null, new Point(0, 0), RADIUS, RADIUS);
                    drawingContext.DrawEllipse(dot, null, new Point(0, ActualHeight), RADIUS, RADIUS);
                    drawingContext.DrawEllipse(dot, null, new Point(ActualWidth, 0), RADIUS, RADIUS);
                    drawingContext.DrawEllipse(dot, null, new Point(ActualWidth, ActualHeight), RADIUS, RADIUS);
                }
            }
        }
Exemple #11
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            Pen pen = new Pen(Stroke, Thickness)
            {
                StartLineCap = PenLineCap.Round,
                EndLineCap   = PenLineCap.Round
            };

            Point start = new Point(X1, Y1);
            Point end   = new Point(X2, Y2);

            double alpha = Math.Atan2(start.Y - end.Y, end.X - start.X);
            double theta = Math.PI - alpha;
            double zet   = theta - Math.PI / 2;
            //double headWidthY = Math.Sin(zet) * (2 + InvertedThickness);
            //double headWidthX = Math.Cos(zet) * (2 + InvertedThickness);
            double headHeightY = Math.Cos(zet) * (InvertedThickness + Thickness / 2);
            double headHeightX = Math.Sin(zet) * (InvertedThickness + Thickness / 2);

            if (IsStartInverted)
            {
                Point startCenter = new Point(start.X, start.Y);

                startCenter.X += headHeightX;
                startCenter.Y -= headHeightY;

                start.X += 2 * headHeightX;
                start.Y -= 2 * headHeightY;

                drawingContext.DrawEllipse(null, pen, new Point(startCenter.X, startCenter.Y), InvertedThickness, InvertedThickness);
            }

            if (IsEndInverted)
            {
                Point endCenter = new Point(end.X, end.Y);

                endCenter.X -= headHeightX;
                endCenter.Y += headHeightY;

                end.X -= 2 * headHeightX;
                end.Y += 2 * headHeightY;

                drawingContext.DrawEllipse(null, pen, new Point(endCenter.X, endCenter.Y), InvertedThickness, InvertedThickness);
            }

            drawingContext.DrawLine(pen, start, end);

            //System.Diagnostics.Debug.Print("[{0}] CustomLineElement OnRender", DateTime.Now);
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            Rect adornedElementRect = new Rect(this.AdornedElement.DesiredSize);

            SolidColorBrush renderBrush = new SolidColorBrush(Colors.Red);
            renderBrush.Opacity = 0.5;
            Pen renderPen = new Pen(new SolidColorBrush(Colors.White), 1.5);
            double renderRadius = 5.0;

            // Draw a circle at each corner.
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopLeft, renderRadius, renderRadius);
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopRight, renderRadius, renderRadius);
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomRight, renderRadius, renderRadius);
        }
 protected override void OnRender(DrawingContext drawingContext)
 {
     c++;
     Console.WriteLine("RENDER : " + c);
     drawingContext.DrawEllipse(Brushes.Blue, new Pen(Brushes.Black, 1), new Point(_element.X2, _element.Y2), 3, 3);
     base.OnRender(drawingContext);
 }
		public override void Render(DrawingContext dc, CoordinateTransform transform)
		{
			var x = ViewportPanel.GetX(this);
			var y = ViewportPanel.GetY(this);

			dc.DrawEllipse(Brushes.Red, null, new Point(x, y).ViewportToScreen(transform), 3, 3);
		}
        internal static void CopyToFrameToDrawingContext(this HighDefinitionFaceFrame highDefinitionFaceFrame, DrawingContext context, bool useDepthSpace = true, byte bodyIndex = 1, double pointRadius = 2F)
        {
            var faceAlignment = new FaceAlignment();
            var coordinateMapper = highDefinitionFaceFrame.HighDefinitionFaceFrameSource.KinectSensor.CoordinateMapper;
            var brush = BodyIndexColor.GetBrushFromBodyIndex(bodyIndex);

            highDefinitionFaceFrame.GetAndRefreshFaceAlignmentResult(faceAlignment);

            var faceModel = new FaceModel();
            var vertices = faceModel.CalculateVerticesForAlignment(faceAlignment);

            if (vertices.Count > 0)
            {
                for (int index = 0; index < vertices.Count; index++)
                {
                    CameraSpacePoint vertice = vertices[index];
                    DepthSpacePoint point = coordinateMapper.MapCameraPointToDepthSpace(vertice);

                    if (float.IsInfinity(point.X) || float.IsInfinity(point.Y))
                        return;

                    context.DrawEllipse(brush, null, point.GetPoint(), pointRadius, pointRadius);
                }
            }
        }
Exemple #16
0
        protected override void DrawCore(System.Windows.Media.DrawingContext context, DrawingAttributes overrides)
        {
            SolidColorBrush strokeBrush = new SolidColorBrush(overrides.Color);

            // If strokeMode it set to Solid, draw the strokes regularly.
            // Otherwise, draw the stylus points.
            if (strokeMode == DrawingMode.Solid)
            {
                Geometry geometry = GetGeometry(overrides);
                context.DrawGeometry(strokeBrush, null, geometry);
            }
            else // strokeMode == DrawingMode.StylusPoints
            {
                StylusPointCollection points;

                // Get the stylus points used to draw the stroke.  The points used depends on
                // the value of FitToCurve.
                if (this.DrawingAttributes.FitToCurve)
                {
                    points = this.GetBezierStylusPoints();
                }
                else
                {
                    points = this.StylusPoints;
                }

                // Draw a circle at each stylus point.
                foreach (StylusPoint p in points)
                {
                    context.DrawEllipse(null, new Pen(strokeBrush, 1), (Point)p, 5, 5);
                }
            }
        }
Exemple #17
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            Rect adornedElementRect = new Rect(this.AdornedElement.DesiredSize);

            adornedElementRect.X += offsetX;
            adornedElementRect.Y += offsetY;

            SolidColorBrush renderBrush  = new SolidColorBrush(Colors.LightGray);
            Pen             renderPen    = new Pen(new SolidColorBrush(Colors.Black), 1);
            double          renderRadius = 3.0;

            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopLeft, renderRadius, renderRadius);
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopRight, renderRadius, renderRadius);
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomRight, renderRadius, renderRadius);
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
                

                drawingContext.DrawEllipse(Brushes.Blue, null, new Point(0,0), 1.0, 1.0);
            }
        //Переопределение базового метода, который позволяет рисовать круг, имея координаты центра и радиус
        protected override void DrawCore(DrawingContext context, DrawingAttributes overrides)
        {
            StylusPointCollection points = this.GetBezierStylusPoints();

            StylusPoint p1 = points[0];
            context.DrawEllipse(new SolidColorBrush(fillColor), new Pen(new SolidColorBrush(strokeColor), thickness), new Point(p1.X, p1.Y), xRadius, yRaduis);
        }
    /// <summary>
    /// When overridden in a derived class, participates in rendering operations that are directed by the layout system. The rendering instructions for this element are not used directly when this method is invoked, and are instead preserved for later asynchronous use by layout and drawing.
    /// </summary>
    /// <param name="drawingContext">The drawing instructions for a specific element. This context is provided to the layout system.</param>
    protected override void OnRender(DrawingContext drawingContext)
    {
      // When no interfaces have been defined, there is nothing to draw.
      if (this.interfaceNames.Count == 0)
      {
        return;
      }

      base.OnRender(drawingContext);

      Pen pen = new Pen(Brushes.Gray, 0.5);
      Point origin = new Point(30, 3);
      double length = Constants.StartHeight + (this.interfaceNames.Count * Constants.LineHeight);

      // draw path at top left
      drawingContext.DrawLine(pen, origin, new Point(origin.X, origin.Y - length));
      drawingContext.DrawEllipse(Brushes.Transparent, pen, new Point(origin.X, origin.Y - length - Constants.Radius), Constants.Radius, Constants.Radius);

      // draw interface names
      origin.Offset(5.0D, -length - Constants.Radius);
      foreach (string name in this.interfaceNames)
      {
        drawingContext.DrawText(new FormattedText(name, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, new Typeface("Segoe UI"), 7, pen.Brush), origin);
        origin.Offset(0, 7.0D);
      }
    }
        protected override void DrawPointElement(DrawingContext dc, int Zoom)
        {
            dc.DrawLine(new Pen(Brushes.Black, 2), new Point(), new Point(0, -BodyOffset));

            dc.PushTransform(new TranslateTransform(0, - 0.5 * BodyHeight - BodyOffset));

            dc.DrawRectangle(Brushes.Black, null,
                             new Rect(-0.5 * BodyWidth, -0.5 * BodyHeight, BodyWidth, BodyHeight));

            for (int i = 0; i < Lights.Length; i++)
                dc.DrawEllipse(Lights[i], null, new Point(0, (2 + LightRadius + 1) * (i - 1)), LightRadius, LightRadius);

            dc.PushTransform(new TranslateTransform(0.5 * BodyWidth + 2, -0.5 * BodyHeight));

            if (Zoom > 11)
            {
                PrintStack(dc,
                           new FormattedText(Target.Name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 10, Brushes.Black),
                           new FormattedText(OrdinateString, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 8, Brushes.Blue));
            }

            dc.Pop();

            dc.Pop();
        }
Exemple #22
0
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            base.OnRender(dc);

            foreach (var placement in Screen.Entities)
            {
                var entity = Screen.Stage.Project.EntityByName(placement.entity);

                if (entity != null)
                {
                    var sprite = entity.DefaultSprite;
                    if (sprite != null)
                    {
                        var frame = SpriteBitmapCache.GetOrLoadFrame(sprite.SheetPath.Absolute, sprite.CurrentFrame.SheetLocation);

                        var flip = (placement.direction == Common.Direction.Left) ^ sprite.Reversed;
                        int hx   = flip ? sprite.Width - sprite.HotSpot.X : sprite.HotSpot.X;

                        dc.DrawImage(frame, new Rect(this.Zoom * (placement.screenX - hx), this.Zoom * (placement.screenY - sprite.HotSpot.Y), this.Zoom * frame.PixelWidth, this.Zoom * frame.PixelHeight));

                        continue;
                    }
                }

                dc.DrawEllipse(Brushes.Orange, null, new System.Windows.Point(this.Zoom * placement.screenX, this.Zoom * placement.screenY), 10 * Zoom, 10 * Zoom);
            }
        }
Exemple #23
0
        // Can't use Conditional on overrides
#if DEBUG
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            drawingContext.DrawRectangle(null, new Pen(Brushes.DarkBlue, 3.0), new Rect(0, 0, DesiredSize.Width - Margin.Left - Margin.Right, DesiredSize.Height - Margin.Top - Margin.Bottom));
            // show the visual center
            drawingContext.DrawEllipse(Brushes.Red, null, AlignReferencePoint, 3, 3);
        }
 protected override void Draw(object sender, DrawingContext g)
 {
     // -> Preview circle if drawing
     if (this.drawing)
     {
         g.DrawEllipse(null, new Pen(Brushes.Black,1), new Point(this.center.X, this.center.Y), this.radius, this.radius);
     }
 }
        internal void DrawHand(HandData handData, DrawingContext drawingContext)
        {
            if (this.AnimationInProgress)
            {
                var brush = new SolidColorBrush(Color.FromArgb(this.Opacity, 255, 255, 255));
                this.CreateText((int)this.Center.X + " | " + (int)this.Center.Y + "\n" + new Random().NextDouble(), brush);
                this.CreateNumberText(handData.FingerCount.ToString(), brush);

                drawingContext.DrawText(this.text, this.Center);
                drawingContext.DrawText(this.number, new Point(this.Center.X, this.Center.Y - this.Radius - 40));
                drawingContext.DrawEllipse(null, new Pen(brush, 4), this.Center, this.Radius - 20, this.Radius - 20);
                drawingContext.DrawEllipse(null, new Pen(brush, 4), this.Center, this.Radius + 10, this.Radius + 10);
                this.DrawFingerPoints(handData, drawingContext);
                this.UpdateProgress(brush);
                drawingContext.DrawGeometry(brush, null, path.Data);
            }
        }
Exemple #26
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            foreach (MouseObject mo in MousePosition.Values)
            {
                if (mo.Key == 0)
                {
                    drawingContext.DrawEllipse(Brushes.Transparent, Stroke1, new Point(mo.point.X, mo.point.Y), 10.0, 10.0);
                }
                else
                {
                    drawingContext.DrawEllipse(Brushes.Transparent, Stroke2, new Point(mo.point.X, mo.point.Y), 10.0, 10.0);
                }
            }

            this.IsHitTestVisible = false;
            base.OnRender(drawingContext);
        }
 protected override void OnRender(DrawingContext dc)
 {
     //DrawingContext : ���� ���� ������ �׸���� ���� �޼ҵ�
     //�� �ٸ� �ǹ̴� dc or drawingContext
     dc.DrawEllipse(Brushes.Blue, //Ÿ���� ����
         new Pen(Brushes.Red, 24),//Ÿ���� ��輱
         new Point(RenderSize.Width / 2, RenderSize.Height / 2),//Ÿ���� �߽��� ����Ű�� Point��ü
         RenderSize.Width / 2, RenderSize.Height / 2);//���� �ݰ�� ���� �ݰ�
 }
Exemple #28
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            double rX     = RenderSize.Width / 2;
            double rY     = RenderSize.Height / 2;
            Point  center = new Point(rX, rY);

            drawingContext.DrawEllipse(Brushes.Red, null, center, rX, rY);
            base.OnRender(drawingContext);
        }
        // A common way to implement an adorner's rendering behavior is to override the OnRender
        // method, which is called by the layout subsystem as part of a rendering pass.
        protected override void OnRender(DrawingContext drawingContext)
        {
            // Get a rectangle that represents the desired size of the rendered element
            // after the rendering pass.  This will be used to draw at the corners of the
            // adorned element.
            Rect adornedElementRect = new Rect(this.AdornedElement.DesiredSize);

            // Some arbitrary drawing implements.
            SolidColorBrush renderBrush = new SolidColorBrush(Colors.Green) { Opacity = 0.2 };
            Pen renderPen = new Pen(new SolidColorBrush(Colors.Navy), 1.5);
            double renderRadius = 5.0;

            // Just draw a circle at each corner.
            drawingContext.DrawRectangle(renderBrush, renderPen, adornedElementRect);
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopLeft, renderRadius, renderRadius);
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopRight, renderRadius, renderRadius);
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomRight, renderRadius, renderRadius);
        }
        internal static void CopyToFrameToDrawingContext(this FaceFrame faceFrame, DrawingContext context, bool useInfraredSpace = true, byte bodyIndex = 1, double pointRadius = 1F, double line = 1F)
        {
            var brush = BodyIndexColor.GetBrushFromBodyIndex(bodyIndex);
            var pen = new System.Windows.Media.Pen(brush, line);

            if (useInfraredSpace)
            {
                if ((faceFrame.FaceFrameResult.FaceFrameFeatures & FaceFrameFeatures.BoundingBoxInInfraredSpace) == FaceFrameFeatures.BoundingBoxInInfraredSpace)
                {
                    context.DrawRectangle(null, pen, faceFrame.FaceFrameResult.FaceBoundingBoxInInfraredSpace.ToRect());
                }

                if ((faceFrame.FaceFrameResult.FaceFrameFeatures & FaceFrameFeatures.PointsInInfraredSpace) == FaceFrameFeatures.PointsInInfraredSpace)
                {
                    context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInInfraredSpace[FacePointType.EyeLeft].ToPoint(), pointRadius, pointRadius);
                    context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInInfraredSpace[FacePointType.EyeRight].ToPoint(), pointRadius, pointRadius);
                    context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInInfraredSpace[FacePointType.Nose].ToPoint(), pointRadius, pointRadius);
                    context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInInfraredSpace[FacePointType.MouthCornerLeft].ToPoint(), pointRadius, pointRadius);
                    context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInInfraredSpace[FacePointType.MouthCornerRight].ToPoint(), pointRadius, pointRadius);

                    context.DrawLine(pen, faceFrame.FaceFrameResult.FacePointsInInfraredSpace[FacePointType.MouthCornerLeft].ToPoint(), faceFrame.FaceFrameResult.FacePointsInInfraredSpace[FacePointType.MouthCornerRight].ToPoint());
                }
            }
            else
            {
                if ((faceFrame.FaceFrameResult.FaceFrameFeatures & FaceFrameFeatures.BoundingBoxInColorSpace) == FaceFrameFeatures.BoundingBoxInColorSpace)
                {
                    context.DrawRectangle(null, pen, faceFrame.FaceFrameResult.FaceBoundingBoxInColorSpace.ToRect());
                }

                if ((faceFrame.FaceFrameResult.FaceFrameFeatures & FaceFrameFeatures.PointsInColorSpace) == FaceFrameFeatures.PointsInColorSpace)
                {
                    context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInColorSpace[FacePointType.EyeLeft].ToPoint(), pointRadius, pointRadius);
                    context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInColorSpace[FacePointType.EyeRight].ToPoint(), pointRadius, pointRadius);
                    context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInColorSpace[FacePointType.Nose].ToPoint(), pointRadius, pointRadius);
                    context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInColorSpace[FacePointType.MouthCornerLeft].ToPoint(), pointRadius, pointRadius);
                    context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInColorSpace[FacePointType.MouthCornerRight].ToPoint(), pointRadius, pointRadius);

                    context.DrawLine(pen, faceFrame.FaceFrameResult.FacePointsInColorSpace[FacePointType.MouthCornerLeft].ToPoint(), faceFrame.FaceFrameResult.FacePointsInColorSpace[FacePointType.MouthCornerRight].ToPoint());
                }
            }
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            Point povCenter = new Point(ActualHeight / 2d, ActualWidth / 2d);

            drawingContext.DrawEllipse(null, _linePen, povCenter, povCenter.X - 5d, povCenter.Y - 5d);
            drawingContext.DrawEllipse(_lineBrush, null, povCenter, 5, 5);

            if (Direction == POVDirection.Center)
            {
                drawingContext.DrawEllipse(_activePositionBrush, null, povCenter, 4, 4);
            }
            else
            {
                drawingContext.PushTransform(new RotateTransform((double)Direction, povCenter.X, povCenter.Y));
                drawingContext.PushTransform(new TranslateTransform(povCenter.X - 5, 0));
                drawingContext.DrawGeometry(_activePositionBrush, null, _arrowPath);
                drawingContext.Pop();
                drawingContext.Pop();
            }
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            drawingContext.DrawRectangle(Brushes.Transparent, null, new Rect(RenderSize));

            drawingContext.DrawRectangle(RectFill, Pen, new Rect(AdornedElement.DesiredSize));

            drawingContext.DrawEllipse(CircleFill, null, new Point(0, 0), CircleRadius, CircleRadius);
            drawingContext.DrawEllipse(
                CircleFill, null, new Point(AdornedElement.DesiredSize.Width, 0), CircleRadius, CircleRadius);
            drawingContext.DrawEllipse(
                CircleFill, null, new Point(0, AdornedElement.DesiredSize.Height), CircleRadius, CircleRadius);
            drawingContext.DrawEllipse(
                CircleFill,
                null,
                new Point(AdornedElement.DesiredSize.Width, AdornedElement.DesiredSize.Height),
                CircleRadius,
                CircleRadius);
        }
Exemple #33
0
        public void OnRender(DrawingContext dc, bool renderDetails)
        {
            var renderSize = new Size(1, 1);

            dc.DrawRectangle(this.Brush, s_edgePen, new Rect(renderSize));

            if (this.Stairs == Stairs.Down)
            {
                double tri = renderSize.Width / 3;
                dc.DrawLine(new Pen(Brushes.White, 0.05), new Point(tri, tri), new Point(tri * 2, renderSize.Height / 2));
                dc.DrawLine(new Pen(Brushes.White, 0.05), new Point(tri * 2, renderSize.Height / 2), new Point(tri, tri * 2));
            }
            else if (this.Stairs == Stairs.Up)
            {
                double tri = renderSize.Width / 3;
                dc.DrawLine(new Pen(Brushes.White, 0.05), new Point(tri * 2, tri), new Point(tri, renderSize.Height / 2));
                dc.DrawLine(new Pen(Brushes.White, 0.05), new Point(tri, renderSize.Height / 2), new Point(tri * 2, tri * 2));
            }

            if (!renderDetails)
                return;

            if (From != Direction.None)
            {
                var iv = IntVector2.FromDirection(From);
                var v = new Vector(iv.X, iv.Y);
                v *= renderSize.Width / 4;
                Point mp = new Point(renderSize.Width / 2, renderSize.Height / 2);
                dc.DrawEllipse(Brushes.White, null, mp, 0.1, 0.1);
                dc.DrawLine(new Pen(Brushes.White, 0.05), mp, mp + new Vector(v.X, v.Y));
            }

            if (this.Weight != 0)
            {
                var ft = new FormattedText(this.Weight.ToString(), System.Globalization.CultureInfo.CurrentCulture,
                    FlowDirection.LeftToRight, new Typeface("Verdana"), 0.2, Brushes.White);
                dc.DrawText(ft, new Point(renderSize.Width - ft.Width - 0.02, 0));
            }

            if (G != 0 || H != 0)
            {
                var ft = new FormattedText(G.ToString(), System.Globalization.CultureInfo.CurrentCulture,
                    FlowDirection.LeftToRight, new Typeface("Verdana"), 0.2, Brushes.White);
                dc.DrawText(ft, new Point(0.02, renderSize.Height - ft.Height - 0.02));

                ft = new FormattedText(H.ToString(), System.Globalization.CultureInfo.CurrentCulture,
                    FlowDirection.LeftToRight, new Typeface("Verdana"), 0.2, Brushes.White);
                dc.DrawText(ft, new Point(renderSize.Width - ft.Width - 0.02, renderSize.Height - ft.Height - 0.02));

                ft = new FormattedText((G + H).ToString(), System.Globalization.CultureInfo.CurrentCulture,
                    FlowDirection.LeftToRight, new Typeface("Verdana"), 0.2, Brushes.White);
                dc.DrawText(ft, new Point(0.02, 0.02));
            }
        }
Exemple #34
0
     public void Draw(DrawingContext ctx)
     {
         for (int x = 0; x < Size; x++)
         {
             for (int y = 0; y < Size; y++)
             {
                 //ctx.DrawRectangle(_grid[_state, x, y] ? Brushes.Wheat : Brushes.Black, null, new Rect(x * 8, y * 8, 8, 8));
                 if (_grid[_state, x, y]) ctx.DrawEllipse(Brushes.SteelBlue, null, new Point(x * 8, y * 8) + new Vector(4, 4), 4, 4);
             }
         }
 }
Exemple #35
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     drawingContext.DrawRectangle(Brushes.Red, new Pen(), new Rect(5, _playerPaddlePos - 20, 10, 40));
     drawingContext.DrawRectangle(Brushes.Red, new Pen(),
                                  new Rect(RenderSize.Width - 7.5, _computerPaddlePos - 20, 10, 40));
     drawingContext.DrawEllipse(Brushes.WhiteSmoke, new Pen(), _ballPos, 5, 5);
     drawingContext.DrawText(
         new FormattedText(String.Format("{0} - {1}", _playerScore, _computerScore), CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                           new Typeface("Courier New"), 12, Brushes.White), new Point(RenderSize.Width / 2, 10));
     base.OnRender(drawingContext);
 }
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (Selected)
            {
                drawingContext.DrawEllipse(
                    background,
                    new Pen(outline, 2),
                    RelativePosition,
                    Radius, Radius);
            }
            else
            {
                drawingContext.DrawEllipse(
                    background,
                    null,//new Pen(outline, 2),
                    RelativePosition,
                    Radius, Radius);
            }
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            var adornedElementRect = new Rect(AdornedElement.RenderSize);

            var renderBrush = new SolidColorBrush(Colors.Red) { Opacity = 0.5 };
            var renderPen = new Pen(new SolidColorBrush(Colors.White), 1.5);

            const double renderRadius = 5.0;

            if (_dropType == DropType.Top || _dropType == DropType.Normal)
            {
                drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopLeft, renderRadius, renderRadius);
                drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopRight, renderRadius, renderRadius);
            }

            if (_dropType == DropType.Bottom || _dropType == DropType.Normal)
            {
                drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
                drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomRight, renderRadius, renderRadius);
            }
        }
Exemple #38
0
        public void DrawCircle(Point center, DrawingContext drawingContext, Size windowSize, bool drawCircle)
        {
            var rectangle = new Rect(center.X - Radius, center.Y - Radius, Radius * 2, Radius * 2);
            var path = new PathGeometry();
            path.AddGeometry(new EllipseGeometry(rectangle));
            drawingContext.PushClip(path);
            var windowRect = new Rect(windowSize);
            drawingContext.DrawImage(Bitmap, windowRect);

            if (drawCircle)
                drawingContext.DrawEllipse(Brushes.Transparent, new Pen(Brushes.Red, 1.5), center, Radius, Radius);
        }
Exemple #39
0
 protected override void OnOverlayRender(DrawingContext dc)
 {
     if (_timeTracker != null)
     {
         for (var i = _lowerRing; i < _upperRing; i++)
         {
             var radius = RingRadius*(i + 1);
             dc.DrawEllipse(Brushes.Transparent, new Pen(new SolidColorBrush(RingColor), RingThickness),
                 _clickPosition, radius, radius);
         }
     }
 }
        /// <summary>
        /// jointの座標に円を描く
        /// </summary>
        /// <param name="drawingContext"></param>
        /// <param name="joint"></param>
        private void DrawSkeletonPoint( DrawingContext drawingContext, Joint joint )
        {
            if ( joint.TrackingState != JointTrackingState.Tracked ) {
            return;
              }

              // 円を書く
              ColorImagePoint point = kinect.MapSkeletonPointToColor( joint.Position,
            kinect.ColorStream.Format );
              drawingContext.DrawEllipse( new SolidColorBrush( Colors.Red ),
              new Pen( Brushes.Red, 1 ), new Point( point.X, point.Y ), R, R );
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            SolidColorBrush renderBrush = new SolidColorBrush(Colors.Green);
            renderBrush.Opacity = 0.2;
            Pen renderPen = new Pen(new SolidColorBrush(Colors.Black), 1.5);
            double renderRadius = 5.0;

            Nullable<Point> closestDropPoint = getClosestPoint(m_panel.DropPoints, m_mousePosition);
            if (closestDropPoint.HasValue)
            {
                drawingContext.DrawEllipse(renderBrush, renderPen, closestDropPoint.Value, renderRadius, renderRadius);
            }
        }
Exemple #42
0
        protected override void OnRender(DrawingContext dc)
        {
            Size size = RenderSize;

            if (Stroke != null)
            {
                size.Width = Math.Max(0, size.Width-Stroke.Thickness);
                size.Height = Math.Max(0, size.Height-Stroke.Thickness);
            }

            dc.DrawEllipse(Fill, Stroke, new Point(RenderSize.Width/2, RenderSize.Height/2),
                size.Width/2, size.Height/2);
        }
Exemple #43
0
        protected override void OnRender(System.Windows.Media.DrawingContext g)
        {
            base.OnRender(g);

            if (_r == 0)
            {
                return;
            }

            // Draw clock
            g.DrawEllipse(BRUSH_CIRCLE, null, _center, _r, _r);

            DrawArc(g);

            g.DrawEllipse(Brushes.White, PEN_WHITE, _center, 2, 2);

            // Draw Hour marks
            int inc = 360 / 12;

            for (int i = 0; i < 12; i++)
            {
                if (i % 3 == 0)
                {
                    var centerPoint = PointOnCircle(_r - 13, inc * i, _center);

                    g.DrawEllipse(BRUSH_CIRCLE_HOUR, null, centerPoint, 4, 4);
                }
                else
                {
                    var topPoint    = PointOnCircle(_r - 12, inc * i, _center);
                    var bottomPoint = PointOnCircle(_r - 21, inc * i, _center);

                    g.DrawLine(PEN_MINUTE, topPoint, bottomPoint);
                }
            }
        }
Exemple #44
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            double width  = this.AdornedElement.DesiredSize.Width;
            double height = this.AdornedElement.DesiredSize.Height;

            Rect adornedElementRect = new Rect(this.AdornedElement.DesiredSize);

            SolidColorBrush renderBrush = new SolidColorBrush(Colors.Red);

            renderBrush.Opacity = 0.5;
            Pen    renderPen    = new Pen(new SolidColorBrush(Colors.White), 1.5);
            double renderRadius = 5.0;

            if (this.IsAboveElement)
            {
                drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopLeft, renderRadius, renderRadius);
                drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopRight, renderRadius, renderRadius);
            }
            else
            {
                drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
                drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomRight, renderRadius, renderRadius);
            }
        }
Exemple #45
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            double penThickness        = BorderBen.Thickness;
            Size   effectiveRenderSize = new Size(this.RenderSize.Width - penThickness, this.RenderSize.Height - penThickness);

            //two possible scenarios
            //1) we are driven by width
            //2) we are driven by height
            //let's run both to see which works

            double circleDiameter;

            circleDiameter = (effectiveRenderSize.Width - (BlockCount - 1) * BlockMargin) / BlockCount;
            if (circleDiameter > effectiveRenderSize.Height)
            {
                circleDiameter = effectiveRenderSize.Height;
            }

            double startLeft = penThickness / 2 + effectiveRenderSize.Width - (this.BlockCount * circleDiameter + (this.BlockCount - 1) * BlockMargin);
            double startTop  = penThickness / 2 + (effectiveRenderSize.Height - circleDiameter) / 2;

            double circleRadius = circleDiameter / 2;
            Point  center       = new Point();

            int threshHold = BlockBarBase.GetThreshold(this.Value, this.BlockCount);

            Brush brushToUse;

            for (int i = 0; i < this.BlockCount; i++)
            {
                brushToUse = ((this.BlockCount - (i + 1)) < threshHold) ? Foreground : Background;

                center.X = startLeft + circleRadius;
                center.Y = startTop + circleRadius;
                drawingContext.DrawEllipse(brushToUse, BorderBen, center, circleRadius, circleRadius);
                startLeft += circleDiameter + BlockMargin;
            }
        }
        /// <summary>
        /// Draws the content of a <see cref="T:System.Windows.Media.DrawingContext" /> object during the render pass of a <see cref="T:System.Windows.Controls.Panel" /> element.
        /// </summary>
        /// <param name="dc">The <see cref="T:System.Windows.Media.DrawingContext" /> object to draw.</param>
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            //For each face
            foreach (KeyValuePair <int, Affdex.Face> pair in Faces)
            {
                Affdex.Face face = pair.Value;

                var featurePoints = face.FeaturePoints;

                //Calculate bounding box corners coordinates.
                System.Windows.Point tl = new System.Windows.Point(featurePoints.Min(r => r.X) * XScale,
                                                                   featurePoints.Min(r => r.Y) * YScale);
                System.Windows.Point br = new System.Windows.Point(featurePoints.Max(r => r.X) * XScale,
                                                                   featurePoints.Max(r => r.Y) * YScale);

                System.Windows.Point bl = new System.Windows.Point(tl.X, br.Y);

                //Draw Points
                if (DrawPoints)
                {
                    foreach (var point in featurePoints)
                    {
                        dc.DrawEllipse(pointBrush, null, new System.Windows.Point(point.X * XScale, point.Y * YScale), fpRadius, fpRadius);
                    }

                    //Draw BoundingBox
                    dc.DrawRectangle(null, boundingPen, new System.Windows.Rect(tl, br));
                }

                //Draw Metrics
                if (DrawMetrics)
                {
                    double padding = (bl.Y - tl.Y) / MetricNames.Count;
                    double startY  = tl.Y - padding;
                    foreach (string metric in MetricNames)
                    {
                        double       width  = maxTxtWidth;
                        double       height = maxTxtHeight;
                        float        value  = -1;
                        PropertyInfo info;
                        if ((info = face.Expressions.GetType().GetProperty(NameMappings(metric))) != null)
                        {
                            value = (float)info.GetValue(face.Expressions, null);
                        }
                        else if ((info = face.Emotions.GetType().GetProperty(NameMappings(metric))) != null)
                        {
                            value = (float)info.GetValue(face.Emotions, null);
                        }

                        SolidColorBrush metricBrush = value > 0 ? pozMetricBrush : negMetricBrush;
                        value = Math.Abs(value);
                        SolidColorBrush txtBrush = value > 1 ? emojiBrush : boundingBrush;

                        double x           = tl.X - width - margin;
                        double y           = startY += padding;
                        double valBarWidth = width * (value / 100);

                        if (value > 1)
                        {
                            dc.DrawRectangle(null, boundingPen, new System.Windows.Rect(x, y, width, height));
                        }
                        dc.DrawRectangle(metricBrush, null, new System.Windows.Rect(x, y, valBarWidth, height));

                        FormattedText metricFTScaled = new FormattedText((String)upperConverter.Convert(metric, null, null, null),
                                                                         System.Globalization.CultureInfo.CurrentCulture,
                                                                         System.Windows.FlowDirection.LeftToRight,
                                                                         metricTypeFace, metricFontSize * width / maxTxtWidth, txtBrush);

                        dc.DrawText(metricFTScaled, new System.Windows.Point(x, y));
                    }
                }


                //Draw Emoji
                if (DrawEmojis)
                {
                    if (face.Emojis.dominantEmoji != Affdex.Emoji.Unknown)
                    {
                        BitmapImage          img      = emojiImages[face.Emojis.dominantEmoji];
                        double               imgRatio = ((br.Y - tl.Y) * 0.3) / img.Width;
                        System.Windows.Point tr       = new System.Windows.Point(br.X + margin, tl.Y);
                        dc.DrawImage(img, new System.Windows.Rect(tr.X, tr.Y, img.Width * imgRatio, img.Height * imgRatio));
                    }
                }

                //Draw Appearance metrics
                if (DrawAppearance)
                {
                    BitmapImage img      = appImgs[ConcatInt((int)face.Appearance.Gender, (int)face.Appearance.Glasses)];
                    double      imgRatio = ((br.Y - tl.Y) * 0.3) / img.Width;
                    double      imgH     = img.Height * imgRatio;
                    dc.DrawImage(img, new System.Windows.Rect(br.X + margin, br.Y - imgH, img.Width * imgRatio, imgH));
                }
            }



            //base.OnRender(dc);
        }
Exemple #47
0
        public void Draw()
        {
            if (g != null)
            {
                double tWidth  = Width;
                double tHeight = Height;

                double RelativeWidth  = tWidth / (GLenght + MarginX);
                double RelativeHeight = tHeight / (GHeight + MarginY);

                int TilesCountY = 0;
                int TilesCountX = 0;

                for (double y = MinY % (TileFreqY * RelativeHeight); y <= tHeight + MinY; y += (TileFreqY * RelativeHeight))
                {
                    g.DrawLine(new Pen(TileColor, LineSize), new Point(0, y), new Point(tWidth, y));
                    TilesCountY++;
                }

                for (double x = MinX % (TileFreqX * RelativeWidth); x <= tWidth + MinX; x += (TileFreqX * RelativeWidth))
                {
                    g.DrawLine(new Pen(TileColor, LineSize), new Point(x, 0), new Point(x, tHeight));
                    TilesCountX++;
                }

                if (TilesCountY > TileAdjustUpLimit)
                {
                    TileFreqY = TileFreqY * (TileAdjustUpLimit / TileAdjustDownLimit);
                }
                else if (TilesCountY < TileAdjustUpLimit / TileAdjustDownLimit)
                {
                    TileFreqY = TileFreqY / (TileAdjustUpLimit / TileAdjustDownLimit);
                }

                if (TilesCountX > TileAdjustUpLimit)
                {
                    TileFreqX = TileFreqX * (TileAdjustUpLimit / TileAdjustDownLimit);
                }
                else if (TilesCountX < TileAdjustUpLimit / TileAdjustDownLimit)
                {
                    TileFreqX = TileFreqX / (TileAdjustUpLimit / TileAdjustDownLimit);
                }

                for (int i = 0; i < Points.Count; i++)
                {
                    Point p1 = new Point((int)((Points[i].X - MinX) * RelativeWidth), (int)((Points[i].Y - MinY) * RelativeHeight));

                    if (p1.X >= 0 && p1.Y >= 0)
                    {
                        g.DrawEllipse(DotColor, new Pen(DotColor, DotSize), p1, (int)DotSize, (int)DotSize);
                    }

                    if (Points.Count - i != 1)
                    {
                        Point p2 = new Point((int)((Points[i + 1].X - MinX) * RelativeWidth), (int)((Points[i + 1].Y - MinY) * RelativeHeight));

                        g.DrawLine(new Pen(LineColor, LineSize), p1, p2);
                    }
                }
            }
        }
Exemple #48
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            if (_editor.SelectedItems.Count > 0)
            {
                Pen   rectPen     = _drawFocus ? SelectionRectPen : SelectionRectPenNoFocus;
                Brush circleBrush = _drawFocus ? SelectionResizeBrush : SelectionResizeBrushNoFocus;

                if (_isline)
                {
                    Point start;
                    Point end;

                    drawingContext.PushTransform(new ScaleTransform(_editor.ZoomFactor, _editor.ZoomFactor));
                    if (_editor.SnapManager.Action == SnapAction.LineStart || _editor.SnapManager.Action == SnapAction.LineEnd)
                    {
                        drawingContext.PushTransform(new TranslateTransform(_tempLine.Left, _tempLine.Top));
                        _tempLine.Renderer.Render(drawingContext);
                        drawingContext.Pop();

                        start = _tempLine.Start;
                        end   = _tempLine.End;
                    }
                    else
                    {
                        Helios.Controls.LineDecoration line = _editor.SelectedItems[0] as Helios.Controls.LineDecoration;

                        start = line.Start;
                        end   = line.End;
                        if (_editor.SnapManager.Action == SnapAction.Move)
                        {
                            start += _editor.SnapManager.LocationOffset;
                            end   += _editor.SnapManager.LocationOffset;
                            _tempLine.Clone(line);

                            drawingContext.PushTransform(new TranslateTransform(_tempLine.Left + _editor.SnapManager.LocationOffset.X, _tempLine.Top + _editor.SnapManager.LocationOffset.Y));
                            _tempLine.Renderer.Render(drawingContext);
                            drawingContext.Pop();
                        }
                    }
                    drawingContext.Pop();

                    start.X *= _editor.ZoomFactor;
                    start.Y *= _editor.ZoomFactor;
                    end.X   *= _editor.ZoomFactor;
                    end.Y   *= _editor.ZoomFactor;

                    drawingContext.DrawEllipse(circleBrush, rectPen, start, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, end, ResizeRadius, ResizeRadius);
                }
                else
                {
                    foreach (HeliosVisual visual in _editor.SelectedItems)
                    {
                        Rect visualRect = visual.DisplayRectangle;
                        visualRect.Scale(_editor.ZoomFactor, _editor.ZoomFactor);
                        drawingContext.DrawRectangle(null, SelectionBorderPen, visualRect);
                    }

                    Rect selectionRect = (_editor.SnapManager.Action != SnapAction.None && _editor.SnapManager.Action != SnapAction.Drop && _editor.SnapManager.IsValidDrag) ? _editor.SnapManager.NewRectangle : _editor.SelectedItems.Rectangle;
                    selectionRect.Scale(_editor.ZoomFactor, _editor.ZoomFactor);

                    drawingContext.DrawRectangle(null, rectPen, selectionRect);

                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.TopLeft, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.TopRight, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.BottomLeft, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.BottomRight, ResizeRadius, ResizeRadius);
                }
            }
        }
        //      -----------------------------------------------
        // 4.1) drawingContext is moved already to the left and down to cater for Margin, Border and Padding.
        // 4.2) The CustomsControl's RenderSize cannot be used, since it includes Border and Padding. renderContentSize must be used instead, which
        // is exactly the same as what ArrangeContentOverride() returned. RenderSize would be used for children FrameworkElements.

        protected override void OnRenderContent(System.Windows.Media.DrawingContext drawingContext, Size renderContentSize)
        {
            //draws an ellipse next to the ChildTextBox using the same size
            double radiusX = ChildTextBox.RenderSize.Width / 2;
            double radiusY = ChildTextBox.RenderSize.Height / 2;
            double offsetX;
            double offsetY;

            if (!double.IsNaN(Width) || HorizontalAlignment == HorizontalAlignment.Stretch)
            {
                //HorizontalContentAlignment matters only if space available is different from the needed space, which is only possible if
                //CustomControlSample is stretched or a width is defined
                switch (HorizontalContentAlignment)
                {
                case HorizontalAlignment.Left:
                case HorizontalAlignment.Stretch:
                    offsetX = ChildTextBox.RenderSize.Width + radiusX;
                    break;

                case HorizontalAlignment.Center:
                    offsetX = renderContentSize.Width / 2 + radiusX;
                    break;

                case HorizontalAlignment.Right:
                    offsetX = renderContentSize.Width - radiusX;
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
            else
            {
                //if CustomControlSample is not stretched, renderContentSize.Width=2*textBox.RenderSize.Width
                offsetX = ChildTextBox.RenderSize.Width + radiusX;
            }
            if (!double.IsNaN(Height) || VerticalAlignment == VerticalAlignment.Stretch)
            {
                //VerticalContentAlignment matters only if space available is different from the needed space, which is only possible if
                //CustomControlSample is stretched or height is defined
                switch (VerticalContentAlignment)
                {
                case VerticalAlignment.Top:
                case VerticalAlignment.Stretch:
                    offsetY = radiusY;
                    break;

                case VerticalAlignment.Center:
                    offsetY = renderContentSize.Height / 2;
                    break;

                case VerticalAlignment.Bottom:
                    offsetY = renderContentSize.Height - radiusY;
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
            else
            {
                //if CustomControlSample is not stretched, renderContentSize.Height=textBox.RenderSize.Height
                offsetY = ChildTextBox.RenderSize.Height / 2;
            }
            drawingContext.DrawEllipse(Brushes.LightGoldenrodYellow, null, new Point(offsetX, offsetY), radiusX, radiusY);
        }
Exemple #50
0
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     drawingContext.DrawEllipse(_brush, null, new Point(_line.Line.X1, _line.Line.Y1), HANDLE_SIZE, HANDLE_SIZE);
     drawingContext.DrawEllipse(_brush, null, new Point(_line.Line.X2, _line.Line.Y2), HANDLE_SIZE, HANDLE_SIZE);
 }
Exemple #51
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            var b = new Rect(Padding.Left, Padding.Top, ActualWidth - Padding.Left - Padding.Right, ActualHeight - Padding.Top - Padding.Bottom);

            drawingContext.DrawRectangle(Background, null, b);

            var ft = CreateFormattedText("1", Brushes.Transparent);

            var    textHeight = ft.Height;
            double titleTab   = string.IsNullOrEmpty(Title)? 0: (textHeight + 2);

            var bigRadiusH = (b.Height - textHeight - titleTab) / 2 - ValueWidth;
            var bigRadiusW = b.Width / 2 - ValueWidth;
            var bigRadius  = Math.Min(bigRadiusH, bigRadiusW);

            var smallRadius  = bigRadius - ValueWidth;
            var middleRadius = (bigRadius + smallRadius) / 2;

            FLeftRightTab2 = 180 * Math.Acos(1 - 3 * ValueWidth / middleRadius / middleRadius) / Math.PI;
            FCenter        = new Point(b.Left + b.Width / 2, b.Top + titleTab + ValueWidth + bigRadius);

            var    maxminDelta = MaxValue - MinValue;
            double valuePct    = (maxminDelta == 0)? 0: (Value - MinValue) / maxminDelta;

            if (valuePct > 1)
            {
                valuePct = 1;
            }
            if (valuePct < 0)
            {
                valuePct = 0;
            }

            Func <double, double, Point> getArcPoint = (double APct, double ARadius) =>
            {
                var angle = PercentToAngle(APct);
                return(new Point(
                           FCenter.X + ARadius * Math.Cos(angle),
                           FCenter.Y - ARadius * Math.Sin(angle)));
            };

            var bigStart = getArcPoint(0, bigRadius);
            var smallEnd = getArcPoint(0, smallRadius);

            Action <double, Brush> drawArc = (double AEndPct, Brush AFillBrush) =>
            {
                var smallStart = getArcPoint(AEndPct, smallRadius);
                var bigEnd     = getArcPoint(AEndPct, bigRadius);

                bool       isBigArc = Math.Abs(PercentToAngle(0) - PercentToAngle(AEndPct)) > Math.PI;
                PathFigure pf       = new PathFigure();
                pf.StartPoint = bigStart;
                pf.Segments.Add(new ArcSegment(bigEnd, new Size(bigRadius, bigRadius), 0, isBigArc, SweepDirection.Clockwise, true));
                pf.Segments.Add(new LineSegment(smallStart, true));
                pf.Segments.Add(new ArcSegment(smallEnd, new Size(smallRadius, smallRadius), 0, isBigArc, SweepDirection.Counterclockwise, true));
                pf.Segments.Add(new LineSegment(bigStart, true));
                pf.Freeze();

                PathGeometry g = new PathGeometry();
                g.FillRule = FillRule.Nonzero;
                g.Figures.Add(pf);
                g.Freeze();

                drawingContext.DrawGeometry(AFillBrush, null, g);
            };

            drawArc(1, ValueBackground);
            drawArc(valuePct, ValueForeground);

            var holderRadius = ValueWidth * 1.5;

            drawingContext.DrawEllipse((IsFocused)? FocusForeground: ValueForeground, null, getArcPoint(valuePct, middleRadius), holderRadius, holderRadius);

            if (!string.IsNullOrEmpty(Title))
            {
                ft = CreateFormattedText(Title, this.Foreground);
                ft.MaxTextWidth  = b.Width;
                ft.Trimming      = TextTrimming.CharacterEllipsis;
                ft.MaxTextHeight = textHeight + 2;
                ft.TextAlignment = TextAlignment.Center;
                drawingContext.DrawText(ft, new Point(b.Left, b.Top));
            }

            string vStr;

            if (ValueDigitCount > -1)
            {
                vStr = Value.ToString("F" + ValueDigitCount);
            }
            else
            {
                vStr = string.IsNullOrEmpty(ValueStringFormat)? Value.ToString(): string.Format(ValueStringFormat, Value);
            }

            ft = CreateFormattedText(vStr, (IsFocused)? FocusForeground: FocusForeground);
            ft.MaxTextWidth = 2 * smallRadius;
            ft.Trimming     = TextTrimming.CharacterEllipsis;
            drawingContext.DrawText(ft, new Point(FCenter.X - ft.Width / 2, FCenter.Y - ft.Height / 2));

            var pt = getArcPoint(0, bigRadius);

            ft = CreateFormattedText(MinValue.ToString(), Foreground);
            drawingContext.DrawText(ft, new Point(pt.X - ft.Width, pt.Y));

            pt = getArcPoint(1, bigRadius);
            ft = CreateFormattedText(MaxValue.ToString(), Foreground);
            drawingContext.DrawText(ft, pt);
        }
Exemple #52
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            drawingContext.DrawEllipse(Brushes.Yellow, new Pen(Brushes.Teal, 3), new Point(20, 20), 100, 10);
        }
Exemple #53
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            drawingContext.PushTransform(new ScaleTransform(_scaleX, _scaleY));

            drawingContext.DrawEllipse(Brushes.Black, null, _center, 187d, 187d);

            if (_rwr != null && _rwr.IsOn)
            {
                bool primary = DateTime.Now.Millisecond < 500;

                // Draw heart beat lines
                drawingContext.DrawLine(_scopePen, new Point(160d, 193.5), new Point(180d, 193.5d));
                drawingContext.DrawLine(_scopePen, new Point(220d, 193.5), new Point(240d, 193.5d));
                drawingContext.DrawLine(_scopePen, new Point(200d, 153.5), new Point(200d, 173.5));
                drawingContext.DrawLine(_scopePen, new Point(200d, 213.5), new Point(200d, 233.5));
                if (primary)
                {
                    drawingContext.DrawLine(_scopePen, new Point(220d, 193.5d), new Point(220d, 203.5d));
                }
                else
                {
                    drawingContext.DrawLine(_scopePen, new Point(220d, 183.5d), new Point(220d, 193.5d));
                }

                if (_rwr.Contacts != null)
                {
                    foreach (RadarContact contact in _rwr.Contacts)
                    {
                        if (contact.Visible)
                        {
                            double y = 0.0f;
                            if (contact.Lethality > 1f)
                            {
                                y = -((2.0f - contact.Lethality) * 178.0d);
                            }
                            else
                            {
                                //lethality values range in 1 = lowest priority to .01 = highest priority
                                //substract -(1.0f - contact.Lethality) * 178.0d) from the elipse radious (187d) to get the inverse value
                                //so that the symbol maps into the correct threat ring
                                y = -(187d - ((1.0f - contact.Lethality) * 178.0d));
                            }

                            drawingContext.PushTransform(new RotateTransform(contact.RelativeBearing));
                            drawingContext.PushTransform(new TranslateTransform(0d, y));
                            drawingContext.PushTransform(new RotateTransform(-contact.RelativeBearing));

                            if (contact.NewDetection && !primary)
                            {
                                _format.FontSize = 24;
                            }
                            else
                            {
                                _format.FontSize = 22;
                            }

                            DrawContactSymbol(drawingContext, contact, primary);

                            if (contact.Selected)
                            {
                                drawingContext.DrawLine(_scopePen, new Point(200d, 168.5d), new Point(225d, 193.5d));
                                drawingContext.DrawLine(_scopePen, new Point(225d, 193.5d), new Point(200d, 218.5d));
                                drawingContext.DrawLine(_scopePen, new Point(200d, 218.5d), new Point(175d, 193.5d));
                                drawingContext.DrawLine(_scopePen, new Point(175d, 193.5d), new Point(200d, 168.5d));
                            }

                            if ((contact.MissileActivity && !contact.MissileLaunch) ||
                                (contact.MissileActivity && contact.MissileLaunch && _rwr.Flash4Hz))
                            {
                                drawingContext.DrawEllipse(null, _scopePen, _center, 25, 25);
                            }

                            drawingContext.Pop();
                            drawingContext.Pop();
                            drawingContext.Pop();
                        }
                    }
                }
            }

            if (_bezelBrush != null)
            {
                drawingContext.DrawRectangle(_bezelBrush, null, _bezelRect);
            }

            drawingContext.Pop();
        }
Exemple #54
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            if (model == null)
            {
                return;
            }

            renderStopwatch.Restart();
            Pen forwardPen  = new Pen(Brushes.Silver, 1);
            Pen backwardPen = new Pen(Brushes.Pink, 1);
            Pen fixedPen    = new Pen(Brushes.Black, 1);

            foreach (var link in model.Links)
            {
                drawingContext.DrawLine(link.A.Position[0] < link.B.Position[0] ? forwardPen : backwardPen,
                                        transform.ToScreen(link.A.Position),
                                        transform.ToScreen(link.B.Position));
            }
            foreach (var particle in model.Particles)
            {
                DrawData drawData = particle.Tag as DrawData;
                if (drawData == null)
                {
                    drawData = new DrawData();
                    if (particle.FillColor.A != 0)
                    {
                        drawData.Brush = new SolidColorBrush(particle.FillColor);
                    }
                    if (particle.StrokeColor.A != 0)
                    {
                        drawData.Pen = new Pen(new SolidColorBrush(particle.StrokeColor), 1);
                    }
                    drawData.Pinned = particle.Fixed;
                    if (particle.Name != null)
                    {
                        drawData.Text = new FormattedText(particle.Name, CultureInfo.CurrentCulture,
                                                          FlowDirection.LeftToRight, textTypeface, textSize, Brushes.Black);
                    }
                    particle.Tag = drawData;
                }

                Point p = transform.ToScreen(particle.Position);
                drawingContext.DrawEllipse(drawData.Brush, drawData.Pen,
                                           p,
                                           ParticleSize,
                                           ParticleSize);
                if (drawData.Selected)
                {
                    drawingContext.DrawEllipse(null, fixedPen,
                                               p,
                                               ParticleSize * 1.3,
                                               ParticleSize * 1.3);
                }


                if (drawData.Text != null)
                {
                    drawingContext.DrawText(drawData.Text, p);
                }
                if (drawData.Pinned)
                {
                    //                    drawingContext.DrawRectangle(Brushes.Black, fixedPen, new Rect(0, 0, 8, 8));
                    drawingContext.PushTransform(new TranslateTransform(p.X, p.Y));
                    drawingContext.PushTransform(new ScaleTransform(ParticleSize / 8, ParticleSize / 8));
                    drawingContext.DrawGeometry(Brushes.LightCoral, fixedPen, pinImage);
                    drawingContext.Pop();
                    drawingContext.Pop();
                }
            }

            RenderElapsedTime = renderStopwatch.Elapsed.TotalSeconds;
            renderStopwatch.Restart();
        }