Exemplo n.º 1
0
 /// <inheritdoc/>
 protected internal override void Draw(DrawingContext dc, UIElement element, OutOfBandRenderTarget target)
 {
     if (Shader.IsValid && Shader.IsLoaded)
     {
         DrawRenderTargetAtVisualBounds(dc, element, target, Shader);
     }
 }
Exemplo n.º 2
0
 void DrawScene(DrawingContext dc) {
   dc.Rect(Color.FromArgb(255, 0, 0, 30), 0, 0, 500, 500);
   // sun
   dc.Ellipse(Colors.Yellow, 250, 250, 30, 30);
   
   Planet(dc);
   
   Stars(dc);
 }
        public static Point ConvertUnitToPixelPoint(Point unitPoint, DrawingContext drawingContext)
        {
            Point pixelPoint = new Point();

            pixelPoint.X = drawingContext.DrawingSize.Width / (drawingContext.XMaximum - drawingContext.XMinimum) * (unitPoint.X - drawingContext.XMinimum);
            pixelPoint.Y = drawingContext.DrawingSize.Height / (drawingContext.YMaximum - drawingContext.YMinimum) * (unitPoint.Y - drawingContext.YMinimum);

            return pixelPoint;
        }
Exemplo n.º 4
0
 /// <summary>
 /// When overriden in a class, renders the visual
 /// </summary>
 /// <param name="drawingContext">The <see cref="DrawingContext"/> in whihc to render the visual</param>
 protected override void OnRender(DrawingContext drawingContext)
 {
     if(this.Background != null || this.BorderBrush != null)
     {
         drawingContext.DrawRectangle(this.RenderTarget, this.BorderThickness, this.Background, this.BorderBrush);
     }
     if (this.Child != null)
     {
         this.Child.Render(drawingContext);
     }
 }
        public static PointCollection ConvertUnitToPixelPointCollection(IEnumerable<Point> unitPoints, DrawingContext drawingContext)
        {
            PointCollection pixelPoints = new PointCollection();

            foreach (var unitPoint in unitPoints)
            {
                pixelPoints.Add(ConvertUnitToPixelPoint(unitPoint, drawingContext));
            }

            return pixelPoints;
        }
Exemplo n.º 6
0
        public static AutoResetEvent RegisterDrawMethod(Action action)
        {
            Exceptions.CheckArgumentNull(action, "action");

            DrawingContext drawingContext = new DrawingContext(action, new Thread(DrawingThreadProc) {IsBackground = true});

            if (!DrawingContexts.TryAdd(action, drawingContext))
                throw new Exception("Метод уже зарегистрирован.");

            drawingContext.StartWorking();
            return drawingContext.DrawEvent;
        }
Exemplo n.º 7
0
        internal DrawingContext(DrawingContext context)
        {
            Context = context.Context;

            if (context.Pen != null)
                AllocatePen (context.colorBrush.Color, context.Pen.Thickness, context.Pen.DashStyle);

            patternBrush = context.patternBrush;

            geometry = (PathGeometry) context.Geometry.Clone ();
            Path = geometry.Figures[geometry.Figures.Count - 1];
            positionSet = context.positionSet;
        }
Exemplo n.º 8
0
 void DrawScene(DrawingContext dc) {
   dc.DrawEllipse(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), null, new Point(50, 18), 12, 12);
   dc.DrawEllipse(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Point(50, 51), 12, 12);
   dc.DrawEllipse(null, new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Point(50, 87), 12, 12);
   
   dc.DrawRectangle(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), null, new Rect(25, 111, 24, 24));
   dc.DrawRectangle(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Rect(25, 147, 24, 24));
   dc.DrawRectangle(null, new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Rect(25, 184, 24, 24));
   
   dc.DrawRoundedRectangle(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), null, new Rect(25, 237, 24, 24), 5, 5);
   dc.DrawRoundedRectangle(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Rect(25, 270, 24, 24), 5, 5);
   dc.DrawRoundedRectangle(null, new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Rect(25, 307, 24, 24), 5, 5);
   
   dc.DrawLine(new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Point(50, 340), new Point (70, 360));
 }
Exemplo n.º 9
0
        /// <inheritdoc/>
        protected internal override void DrawRenderTargets(DrawingContext dc, UIElement element, OutOfBandRenderTarget target)
        {
            var blurTarget = target.Next.RenderTarget;

            var gfx = dc.Ultraviolet.GetGraphics();
            gfx.SetRenderTarget(blurTarget);
            gfx.Clear(Color.Transparent);

            effect.Value.Radius = GetRadiusInPixels(element);
            effect.Value.Direction = BlurDirection.Horizontal;

            dc.Begin(SpriteSortMode.Immediate, effect, Matrix.Identity);
            dc.Draw(target.ColorBuffer, Vector2.Zero, Color.White);
            dc.End();
        }
Exemplo n.º 10
0
  void DrawScene(DrawingContext dc) {
    dc.Rect(Color.FromArgb(0, 0, 0, 0), 0, 0, 500, 500);
    dc.Ellipse(Colors.Red, 250, 250, 20, 20);   

    for (int i = 0; i < 5; ++i) {
       dc.PushTransform(new RotateTransform(36*i, 250, 250));
       dc.Ellipse(Colors.Gray, 3, 250, 250, 40, 150);
       dc.Ellipse(Colors.Black,
          250 + 40*Math.Cos(angle[i]*0.05),
          250 + 150*Math.Sin(angle[i]*0.05),
          8, 8);
       dc.Pop();
    }
    
  }
Exemplo n.º 11
0
        /// <inheritdoc/>
        protected override void DrawOverride(UltravioletTime time, DrawingContext dc)
        {
            var font = Font;
            if (font.IsLoaded)
            {
                View.Resources.StringFormatter.Reset();
                View.Resources.StringFormatter.AddArgument(Value);
                View.Resources.StringFormatter.Format(Format ?? "{0}", View.Resources.StringBuffer);

                var face = font.Resource.Value.GetFace(FontStyle);
                var position = Display.DipsToPixels(UntransformedAbsolutePosition);
                var positionRounded = dc.IsTransformed ? (Vector2)position : (Vector2)(Point2)position;

                dc.DrawString(face, View.Resources.StringBuffer, positionRounded, Foreground);
            }
            base.DrawOverride(time, dc);
        }
Exemplo n.º 12
0
        public IShape GetShape(DrawingContext drawingContext, Point start, Point end)
        {
            var pen = (Pen)drawingContext.Pen.Clone();
            var brush = drawingContext.Brush == Brushes.Transparent ? Brushes.Transparent : (Brush)drawingContext.Brush.Clone();

            switch (drawingContext.ShapeType)
            {
                case ShapeType.Line:
                    return new Line(pen, start, end);
                case ShapeType.Rectangle:
                    return new Rectangle(pen, brush, start, end);
                case ShapeType.Ellipse:
                    return new Ellipse(pen, brush, start, end);
                default:
                    throw new ArgumentException("Unknown shape type.");
            }
        }
Exemplo n.º 13
0
        public MainWindow()
        {
            InitializeComponent();
            InitializeGraphics();
            InitializePlugins();

            drawingArea.CanUndoChanged += newValue => undo.Enabled = newValue;
            drawingArea.CanRedoChanged += newValue => redo.Enabled = newValue;

            _lastSelectedShapeTypeSelector = lineSelector;

            _drawingContext = new DrawingContext
                {
                    ShapeType = ShapeType.Line,
                    Pen = new Pen(penColorSelector.Value, int.Parse(penWidthSelector.Text)),
                    Brush = Brushes.Transparent
                };

            drawingArea.DrawingContext = _drawingContext;
        }
Exemplo n.º 14
0
        /// <inheritdoc/>
        protected internal override void Draw(DrawingContext dc, UIElement element, OutOfBandRenderTarget target)
        {
            var state = dc.GetCurrentState();
            
            var position = (Vector2)element.View.Display.DipsToPixels(target.VisualBounds.Location);
            var positionRounded = new Vector2((Int32)position.X, (Int32)position.Y);

            dc.End();

            effect.Value.Radius = GetRadiusInPixels(element);
            effect.Value.Direction = BlurDirection.Vertical;

            dc.Begin(SpriteSortMode.Immediate, effect, Matrix.Identity);

            var shadowTexture = target.Next.ColorBuffer;
            dc.Draw(shadowTexture, positionRounded, null, Color.White, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            
            dc.End();
            dc.Begin(state);
        }
Exemplo n.º 15
0
            protected override void OnRender(DrawingContext dc)
            {
                string testString = "Formatted MML Document is displayed here!\nPlease implement the user oriented layout logic.";

                FormattedText formattedText = new FormattedText(testString, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 30, Brushes.Black);

                formattedText.MaxTextWidth = 280;
                formattedText.MaxTextHeight = 280;

                formattedText.SetForegroundBrush(new LinearGradientBrush(Colors.Blue, Colors.Teal, 90.0), 10, 12);

                formattedText.SetFontStyle(FontStyles.Italic, 36, 5);
                formattedText.SetForegroundBrush(new LinearGradientBrush(Colors.Pink, Colors.Crimson, 90.0), 36, 5);
                formattedText.SetFontSize(36, 36, 5);

                formattedText.SetFontWeight(FontWeights.Bold, 42, 48);

                dc.DrawRectangle(Brushes.White, null, new Rect(0, 0, 300, 300));

                dc.DrawText(formattedText, new Point(10, 10));
            }
Exemplo n.º 16
0
        /// <summary>
        /// Draws the specified render target at its desired visual bounds.
        /// </summary>
        /// <param name="dc">The current drawing context.</param>
        /// <param name="element">The element being drawn.</param>
        /// <param name="target">The render target that contains the element's graphics.</param>
        /// <param name="effect">The shader effect to apply to the render target, if any.</param>
        public static void DrawRenderTargetAtVisualBounds(DrawingContext dc, UIElement element, OutOfBandRenderTarget target, GraphicsEffect effect = null)
        {
            Contract.Require(dc, "dc");
            Contract.Require(element, "element");
            Contract.Require(target, "rtarget");

            if (element.View == null)
                return;

            var state = dc.GetCurrentState();

            dc.End();
            dc.Begin(SpriteSortMode.Immediate, effect, Matrix.Identity);

            var position = (Vector2)element.View.Display.DipsToPixels(target.VisualBounds.Location);
            var positionRounded = new Vector2((Int32)position.X, (Int32)position.Y);
            dc.Draw(target.ColorBuffer, positionRounded, null, Color.White, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);

            dc.End();
            dc.Begin(state);
        }
Exemplo n.º 17
0
        /// <inheritdoc/>
        protected override void DrawOverride(UltravioletTime time, DrawingContext dc)
        {
            if (textLayoutCommands != null && textLayoutCommands.Count > 0 && containingControl != null)
            {
                var positionRaw = Display.DipsToPixels(UntransformedAbsolutePosition + ContentOffset);
                var positionX = dc.IsTransformed ? positionRaw.X : Math.Round(positionRaw.X, MidpointRounding.AwayFromZero);
                var positionY = dc.IsTransformed ? positionRaw.Y : Math.Round(positionRaw.Y, MidpointRounding.AwayFromZero);
                var position = new Vector2((Single)positionX, (Single)positionY);
                View.Resources.TextRenderer.Draw((SpriteBatch)dc, textLayoutCommands, position, containingControl.Foreground * dc.Opacity);
            }

            base.DrawOverride(time, dc);
        }
Exemplo n.º 18
0
        /// <summary>
        /// If the popup is currently open, this method adds it to the view's popup queue for drawing.
        /// </summary>
        /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Draw(UltravioletTime)"/>.</param>
        /// <param name="dc">The drawing context that describes the render state of the layout.</param>
        internal void EnqueueForDrawingIfOpen(UltravioletTime time, DrawingContext dc)
        {
            if (!IsOpen)
                return;

            EnqueueForDrawing(time, dc);
        }
Exemplo n.º 19
0
 public override void Draw(DrawingContext context, IList <IDrawableObject> drawables)
 {
 }
Exemplo n.º 20
0
        /// <summary>
        /// Draw all formatted glyphruns
        /// </summary>
        /// <returns>drawing bounding box</returns>
        public Rect Draw(
            DrawingContext drawingContext,
            Point currentOrigin
            )
        {
            Rect inkBoundingBox = Rect.Empty;

            Debug.Assert(_glyphs != null);

            foreach (Glyphs glyphs in _glyphs)
            {
                GlyphRun glyphRun = glyphs.CreateGlyphRun(currentOrigin, _rightToLeft);
                Rect     boundingBox;

                if (glyphRun != null)
                {
                    boundingBox = glyphRun.ComputeInkBoundingBox();

                    if (drawingContext != null)
                    {
                        // Emit glyph run background.
                        glyphRun.EmitBackground(drawingContext, glyphs.BackgroundBrush);

                        drawingContext.PushGuidelineY1(currentOrigin.Y);
                        try
                        {
                            drawingContext.DrawGlyphRun(glyphs.ForegroundBrush, glyphRun);
                        }
                        finally
                        {
                            drawingContext.Pop();
                        }
                    }
                }
                else
                {
                    boundingBox = Rect.Empty;
                }

                if (!boundingBox.IsEmpty)
                {
                    // glyph run's ink bounding box is relative to its origin
                    boundingBox.X += glyphRun.BaselineOrigin.X;
                    boundingBox.Y += glyphRun.BaselineOrigin.Y;
                }

                // accumulate overall ink bounding box
                inkBoundingBox.Union(boundingBox);

                if (_rightToLeft)
                {
                    currentOrigin.X -= glyphs.Width;
                }
                else
                {
                    currentOrigin.X += glyphs.Width;
                }
            }

            return(inkBoundingBox);
        }
 public override void Draw(DrawingContext drawingContext, Point origin, bool rightToLeft, bool sideways)
 {
     origin.Y -= element.text.Baseline;
     element.text.Draw(drawingContext, origin, InvertAxes.None);
 }
Exemplo n.º 22
0
 public override void Render(DrawingContext context)
 {
     //TODO Apply grid background
     context.FillRectangle(BackgroundBrush, new Rect(Bounds.Size));
     base.Render(context);
 }
Exemplo n.º 23
0
        public void Draw(ApplicationContext actx, SWM.DrawingContext dc, double scaleFactor, double x, double y, ImageDescription idesc)
        {
            if (drawCallback != null) {
                DrawingContext c = new DrawingContext (dc, scaleFactor);
                actx.InvokeUserCode (delegate {
                    drawCallback (c, new Rectangle (x, y, idesc.Size.Width, idesc.Size.Height));
                });
            }
            else {
                if (idesc.Alpha < 1)
                    dc.PushOpacity (idesc.Alpha);

                var f = GetBestFrame (actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false);
                dc.DrawImage (f, new Rect (x, y, idesc.Size.Width, idesc.Size.Height));

                if (idesc.Alpha < 1)
                    dc.Pop ();
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// In addition to the child, Border renders a background + border.  The background is drawn inside the border.
        /// </summary>
        protected override void OnRender(DrawingContext dc)
        {
            bool     useLayoutRounding = this.UseLayoutRounding;
            DpiScale dpi = GetDpi();

            if (_useComplexRenderCodePath)
            {
                Brush          brush;
                StreamGeometry borderGeometry = BorderGeometryCache;
                if (borderGeometry != null &&
                    (brush = BorderBrush) != null)
                {
                    dc.DrawGeometry(brush, null, borderGeometry);
                }

                StreamGeometry backgroundGeometry = BackgroundGeometryCache;
                if (backgroundGeometry != null &&
                    (brush = Background) != null)
                {
                    dc.DrawGeometry(brush, null, backgroundGeometry);
                }
            }
            else
            {
                Thickness border = BorderThickness;
                Brush     borderBrush;

                CornerRadius cornerRadius      = CornerRadius;
                double       outerCornerRadius = cornerRadius.TopLeft; // Already validated that all corners have the same radius
                bool         roundedCorners    = !DoubleUtil.IsZero(outerCornerRadius);

                // If we have a brush with which to draw the border, do so.
                // NB: We double draw corners right now.  Corner handling is tricky (bevelling, &c...) and
                //     we need a firm spec before doing "the right thing."  (greglett, ffortes)
                if (!border.IsZero &&
                    (borderBrush = BorderBrush) != null)
                {
                    // Initialize the first pen.  Note that each pen is created via new()
                    // and frozen if possible.  Doing this avoids the pen
                    // being copied when used in the DrawLine methods.
                    Pen pen = LeftPenCache;
                    if (pen == null)
                    {
                        pen       = new Pen();
                        pen.Brush = borderBrush;

                        if (useLayoutRounding)
                        {
                            pen.Thickness = UIElement.RoundLayoutValue(border.Left, dpi.DpiScaleX);
                        }
                        else
                        {
                            pen.Thickness = border.Left;
                        }
                        if (borderBrush.IsFrozen)
                        {
                            pen.Freeze();
                        }

                        LeftPenCache = pen;
                    }

                    double halfThickness;
                    if (border.IsUniform)
                    {
                        halfThickness = pen.Thickness * 0.5;


                        // Create rect w/ border thickness, and round if applying layout rounding.
                        Rect rect = new Rect(new Point(halfThickness, halfThickness),
                                             new Point(RenderSize.Width - halfThickness, RenderSize.Height - halfThickness));

                        if (roundedCorners)
                        {
                            dc.DrawRoundedRectangle(
                                null,
                                pen,
                                rect,
                                outerCornerRadius,
                                outerCornerRadius);
                        }
                        else
                        {
                            dc.DrawRectangle(
                                null,
                                pen,
                                rect);
                        }
                    }
                    else
                    {
                        // Nonuniform border; stroke each edge.
                        if (DoubleUtil.GreaterThan(border.Left, 0))
                        {
                            halfThickness = pen.Thickness * 0.5;
                            dc.DrawLine(
                                pen,
                                new Point(halfThickness, 0),
                                new Point(halfThickness, RenderSize.Height));
                        }

                        if (DoubleUtil.GreaterThan(border.Right, 0))
                        {
                            pen = RightPenCache;
                            if (pen == null)
                            {
                                pen       = new Pen();
                                pen.Brush = borderBrush;

                                if (useLayoutRounding)
                                {
                                    pen.Thickness = UIElement.RoundLayoutValue(border.Right, dpi.DpiScaleX);
                                }
                                else
                                {
                                    pen.Thickness = border.Right;
                                }

                                if (borderBrush.IsFrozen)
                                {
                                    pen.Freeze();
                                }

                                RightPenCache = pen;
                            }

                            halfThickness = pen.Thickness * 0.5;
                            dc.DrawLine(
                                pen,
                                new Point(RenderSize.Width - halfThickness, 0),
                                new Point(RenderSize.Width - halfThickness, RenderSize.Height));
                        }

                        if (DoubleUtil.GreaterThan(border.Top, 0))
                        {
                            pen = TopPenCache;
                            if (pen == null)
                            {
                                pen       = new Pen();
                                pen.Brush = borderBrush;
                                if (useLayoutRounding)
                                {
                                    pen.Thickness = UIElement.RoundLayoutValue(border.Top, dpi.DpiScaleY);
                                }
                                else
                                {
                                    pen.Thickness = border.Top;
                                }

                                if (borderBrush.IsFrozen)
                                {
                                    pen.Freeze();
                                }

                                TopPenCache = pen;
                            }

                            halfThickness = pen.Thickness * 0.5;
                            dc.DrawLine(
                                pen,
                                new Point(0, halfThickness),
                                new Point(RenderSize.Width, halfThickness));
                        }

                        if (DoubleUtil.GreaterThan(border.Bottom, 0))
                        {
                            pen = BottomPenCache;
                            if (pen == null)
                            {
                                pen       = new Pen();
                                pen.Brush = borderBrush;
                                if (useLayoutRounding)
                                {
                                    pen.Thickness = UIElement.RoundLayoutValue(border.Bottom, dpi.DpiScaleY);
                                }
                                else
                                {
                                    pen.Thickness = border.Bottom;
                                }
                                if (borderBrush.IsFrozen)
                                {
                                    pen.Freeze();
                                }

                                BottomPenCache = pen;
                            }

                            halfThickness = pen.Thickness * 0.5;
                            dc.DrawLine(
                                pen,
                                new Point(0, RenderSize.Height - halfThickness),
                                new Point(RenderSize.Width, RenderSize.Height - halfThickness));
                        }
                    }
                }

                // Draw background in rectangle inside border.
                Brush background = Background;
                if (background != null)
                {
                    // Intialize background
                    Point ptTL, ptBR;

                    if (useLayoutRounding)
                    {
                        ptTL = new Point(UIElement.RoundLayoutValue(border.Left, dpi.DpiScaleX),
                                         UIElement.RoundLayoutValue(border.Top, dpi.DpiScaleY));

                        if (FrameworkAppContextSwitches.DoNotApplyLayoutRoundingToMarginsAndBorderThickness)
                        {
                            ptBR = new Point(UIElement.RoundLayoutValue(RenderSize.Width - border.Right, dpi.DpiScaleX),
                                             UIElement.RoundLayoutValue(RenderSize.Height - border.Bottom, dpi.DpiScaleY));
                        }
                        else
                        {
                            ptBR = new Point(RenderSize.Width - UIElement.RoundLayoutValue(border.Right, dpi.DpiScaleX),
                                             RenderSize.Height - UIElement.RoundLayoutValue(border.Bottom, dpi.DpiScaleY));
                        }
                    }
                    else
                    {
                        ptTL = new Point(border.Left, border.Top);
                        ptBR = new Point(RenderSize.Width - border.Right, RenderSize.Height - border.Bottom);
                    }

                    // Do not draw background if the borders are so large that they overlap.
                    if (ptBR.X > ptTL.X && ptBR.Y > ptTL.Y)
                    {
                        if (roundedCorners)
                        {
                            Radii  innerRadii        = new Radii(cornerRadius, border, false); // Determine the inner edge radius
                            double innerCornerRadius = innerRadii.TopLeft;                     // Already validated that all corners have the same radius
                            dc.DrawRoundedRectangle(background, null, new Rect(ptTL, ptBR), innerCornerRadius, innerCornerRadius);
                        }
                        else
                        {
                            dc.DrawRectangle(background, null, new Rect(ptTL, ptBR));
                        }
                    }
                }
            }
        }
Exemplo n.º 25
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     drawingContext.DrawRectangle(Colour, new Pen(Brushes.Black, 1), new Rect(0, 0, _drawingWidth, _drawingHeight));
 }
Exemplo n.º 26
0
        /// <summary>
        /// 绘制当前钢梁
        /// </summary>
        public override void Update()
        {
            points = new List <Vector2D>();
            var halfFW    = PlateWidth / 2;
            var Orgion    = new Albert.Geometry.Primitives.Vector3D(Central.X, Central.Y, 0);
            var Direction = new Albert.Geometry.Primitives.Vector3D(this.face.X, this.face.Y, 0);

            //当前偏移的方向
            Vector3D offsetDir = Direction.Cross(new Vector3D(0, 0, 1)).Normalize();

            var v1 = Orgion.Offset(offsetDir * halfFW);
            var v2 = Orgion.Offset(-offsetDir * halfFW);

            var v3  = v2.Offset(Direction * 5);
            var v12 = v1.Offset(Direction * 5);

            var cent = Orgion.Offset(Direction * 5);

            //把中心区域向两边偏移

            var v4 = cent.Offset(-offsetDir * (SternaSeparation / 2 + 5));
            var v5 = v4.Offset(Direction * SternaLength);

            var v7 = cent.Offset(-offsetDir * (SternaSeparation / 2));
            var v6 = v7.Offset(Direction * SternaLength);

            var v8 = cent.Offset(offsetDir * (SternaSeparation / 2 + 5));
            var v9 = v8.Offset(Direction * SternaLength);

            var v11 = cent.Offset(offsetDir * (SternaSeparation / 2));
            var v10 = v11.Offset(Direction * SternaLength);


            var v13 = v12.Offset(Direction * SternaLength);
            var v14 = v3.Offset(Direction * SternaLength);

            points.Add(TransformUtil.Projection(v1));
            points.Add(TransformUtil.Projection(v2));
            points.Add(TransformUtil.Projection(v3));
            points.Add(TransformUtil.Projection(v4));
            points.Add(TransformUtil.Projection(v5));
            points.Add(TransformUtil.Projection(v6));
            points.Add(TransformUtil.Projection(v7));
            points.Add(TransformUtil.Projection(v8));
            points.Add(TransformUtil.Projection(v9));
            points.Add(TransformUtil.Projection(v10));
            points.Add(TransformUtil.Projection(v11));
            points.Add(TransformUtil.Projection(v12));


            DrawingContext dc = this.RenderOpen();

            Pen.Freeze();  //冻结画笔,这样能加快绘图速度
            PathGeometry paths = new PathGeometry();

            PathFigureCollection pfc = new PathFigureCollection();
            PathFigure           pf  = new PathFigure();

            pfc.Add(pf);
            pf.StartPoint = KernelProperty.MMToPix(points[0]);
            for (int i = 0; i < points.Count; i++)
            {
                LineSegment ps = new LineSegment();
                ps.Point = KernelProperty.MMToPix(points[i]);
                pf.Segments.Add(ps);
            }
            pf.IsClosed   = true;
            paths.Figures = pfc;
            dc.DrawGeometry(Brush, Pen, paths);

            this.Pen.DashStyle = new System.Windows.Media.DashStyle(new double[] { 5, 5 }, 10);

            dc.DrawLine(Pen, KernelProperty.MMToPix(TransformUtil.Projection(v12)), KernelProperty.MMToPix(TransformUtil.Projection(v13)));
            dc.DrawLine(Pen, KernelProperty.MMToPix(TransformUtil.Projection(v3)), KernelProperty.MMToPix(TransformUtil.Projection(v14)));
            dc.DrawLine(Pen, KernelProperty.MMToPix(TransformUtil.Projection(v13)), KernelProperty.MMToPix(TransformUtil.Projection(v14)));
            dc.Close();
        }
Exemplo n.º 27
0
        void timer_Tick4(object sender, EventArgs e)
        {
            if (!isMovieAvi2)
            {
                if (currentFrameKosciec2 < allFrames2.Count)
                {
                    SkeletonFrame frame = allFrames2[currentFrameKosciec2];
                    using (DrawingContext dc = this.drawingGroup2.Open())
                    {
                        // czarne tło
                        dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, kosciecVideoKosciec2.Width, kosciecVideoKosciec2.Height));

                        int bodyIndex = 0;

                        foreach (int body in frame.getBodyIds())
                        {
                            Pen drawPen = this.bodyColors[bodyIndex];
                            foreach (var bone in this.bones)
                            {
                                drawPen = this.bodyColors[bodyIndex];
                                if ((frame.getJoint(body, (int)bone.Item1).getTrackingState() != (int)CustomJoint.TrackingState.Tracked) || (frame.getJoint(body, (int)bone.Item2).getTrackingState() != (int)CustomJoint.TrackingState.Tracked))
                                {
                                    drawPen = this.inferredBonePen;
                                }

                                dc.DrawLine(drawPen, new Point(frame.getJoint(body, (int)bone.Item1).getX(), frame.getJoint(body, (int)bone.Item1).getY()),
                                            new Point(frame.getJoint(body, (int)bone.Item2).getX(), frame.getJoint(body, (int)bone.Item2).getY()));
                                kosciecVideoKosciec2.Source = skeletonMovie2;
                            }
                            for (int CustomJointType = 0; CustomJointType < 25; ++CustomJointType)
                            {
                                Brush drawBrush = null;

                                int trackingState = allFrames2[currentFrameKosciec2].getJoint(body, CustomJointType).getTrackingState();

                                if (trackingState == (int)CustomJoint.TrackingState.Tracked)
                                {
                                    drawBrush = this.trackedJointBrush;
                                }
                                else if (trackingState == (int)CustomJoint.TrackingState.Inferred)
                                {
                                    drawBrush = this.inferredJointBrush;
                                }

                                if (drawBrush != null)
                                {
                                    dc.DrawEllipse(drawBrush, null, new Point(frame.getJoint(body, CustomJointType).getX(), frame.getJoint(body, CustomJointType).getY()),
                                                   JointThickness, JointThickness);
                                }
                            }
                            ++bodyIndex;
                        }

                        this.drawingGroup2.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, kosciecVideoKosciec2.Width, kosciecVideoKosciec2.Height));

                        framesKosciec2.Content = (currentFrameKosciec2 + 1).ToString() + " / " + allFrames2.Count.ToString();
                        sliderKosciec2.Value   = currentFrameKosciec2;

                        labelKosciec2.Content = String.Format("{0} / {1} s", string.Format("{0:F1}", (double)currentFrameKosciec2 / allFrames2.Count * (double)allFrames2.Count / framesPerSecond2),
                                                              string.Format("{0:F1}", (double)allFrames2.Count / framesPerSecond2));
                        if (playKosciecMovie2)
                        {
                            currentFrameKosciec2++;
                        }
                    }
                }
                if (currentFrameKosciec2 == allFrames2.Count)
                {
                    playKosciecMovie2 = false;
                }
            }
        }
 protected override void OnRender(DrawingContext drawingContext)
 {
     SetChart();
 }
 void DrawScene(DrawingContext dc) {
   dc.Rect(Color.FromArgb(70, 0, 255, 255), 0, 0, 500, 500);
   DrawSun(dc);
   DrawBall(dc);
   DrawBlocks(dc);
 }
Exemplo n.º 30
0
 protected override void OnRender(DrawingContext dc)
 {
     VisualBitmapScalingMode = BitmapScalingMode.NearestNeighbor;
     base.OnRender(dc);
 }
 void DrawSun(DrawingContext dc) {
   dc.Ellipse(Colors.Yellow, sunX, 50, 40, 40);
 }
Exemplo n.º 32
0
        private void Drawing(DrawingContext ctx)
        {
            OverlaySettings settings = OverlaySettings.Instance;

            if (settings.OnlyDrawInForeground &&
                Imports.GetForegroundWindow() != Core.Memory.Process.MainWindowHandle)
            {
                return;
            }

            if (QuestLogManager.InCutscene)
            {
                return;
            }

            //Gameobject list is threadstatic, always need to pulse otherwise new objects wont show up
            GameObjectManager.Update();

            NVector3 mypos    = Core.Me.Location;
            Vector3  vecStart = new Vector3(mypos.X, mypos.Y, mypos.Z);
            int      myLevel  = Core.Me.ClassLevel;


            if (settings.DrawGameStats)
            {
                StringBuilder sb = new StringBuilder();

                GameObject currentTarget = Core.Me.CurrentTarget;


                sb.AppendLine("My Position: " + Core.Me.Location);
                if (currentTarget != null)
                {
                    sb.AppendLine("Current Target: " + currentTarget.Name + ", Distance: " +
                                  Math.Round(currentTarget.Distance(), 3));

                    NVector3 end    = currentTarget.Location;
                    Vector3  vecEnd = new Vector3(end.X, end.Y, end.Z);

                    ctx.DrawLine(vecStart, vecEnd, Color.DeepSkyBlue);
                }
                else
                {
                    sb.AppendLine("");
                }
                sb.AppendLine("");
                sb.AppendLine(string.Format("XP Per Hour: {0:F0}", GameStatsManager.XPPerHour));
                sb.AppendLine(string.Format("Deaths Per Hour: {0:F0}", GameStatsManager.DeathsPerHour));

                if (myLevel < 90)
                {
                    sb.AppendLine(string.Format("Time to Level: {0}", GameStatsManager.TimeToLevel));
                }

                sb.AppendLine(string.Format("TPS: {0:F2}", GameStatsManager.TicksPerSecond));

                sb.AppendLine();

                if (settings.UseShadowedText)
                {
                    ctx.DrawOutlinedText(sb.ToString(),
                                         settings.GameStatsPositionX,
                                         settings.GameStatsPositionY,
                                         settings.GameStatsForegroundColor,
                                         settings.GameStatsShadowColor,
                                         settings.GameStatsFontSize
                                         );
                }
                else
                {
                    ctx.DrawText(sb.ToString(),
                                 settings.GameStatsPositionX,
                                 settings.GameStatsPositionY,
                                 settings.GameStatsForegroundColor,
                                 settings.GameStatsFontSize
                                 );
                }

                ctx.DrawOutlinedBox(Core.Me.Location.Convert() + new Vector3(0, 1, 0), new Vector3(1),
                                    Color.FromArgb(255, Color.Blue));
            }

            if (settings.DrawHostilityBoxes || settings.DrawUnitLines || settings.DrawGameObjectBoxes || settings.DrawGameObjectLines)
            {
                foreach (GameObject obj in GameObjectManager.GameObjects)
                {
                    if (!obj.IsVisible)
                    {
                        continue;
                    }

                    if (settings.OnlyRenderTargetable)
                    {
                        if (obj.Type != GameObjectType.EventObject)
                        {
                            if (!obj.IsTargetable)
                            {
                                continue;
                            }
                        }
                    }



                    if (obj.Type == GameObjectType.Mount)
                    {
                        continue;
                    }

                    var name      = obj.Name;
                    var vecCenter = obj.Location.Convert() + new Vector3(0, 1, 0);


                    //.Where(i => i.Type == GameObjectType.GatheringPoint || i.Type == GameObjectType.BattleNpc || i.Type == GameObjectType.EventObject || i.Type == GameObjectType.Treasure || i.Type == GameObjectType.Pc)



                    var color = Color.FromArgb(150, Color.Blue);

                    //some generic objects. If you want to add a specific object it should probably go here or in it's own block below this.
                    if (obj.Type == GameObjectType.GatheringPoint || obj.Type == GameObjectType.EventObject || obj.Type == GameObjectType.Treasure)
                    {
                        if (obj.Type == GameObjectType.GatheringPoint)
                        {
                            color = Color.FromArgb(150, Color.BlueViolet);
                        }
                        if (obj.Type == GameObjectType.EventObject)
                        {
                            color = Color.FromArgb(150, Color.Fuchsia);
                        }
                        if (obj.Type == GameObjectType.Treasure)
                        {
                            color = Color.SandyBrown;
                        }

                        if (settings.DrawGameObjectNames && !string.IsNullOrEmpty(name))
                        {
                            ctx.Draw3DText(name, vecCenter);
                        }

                        if (settings.DrawGameObjectBoxes)
                        {
                            ctx.DrawOutlinedBox(vecCenter, new Vector3(1), Color.FromArgb(150, color));
                        }



                        //if (settings.DrawGameObjectLines)
                        //{
                        //    if (!settings.DrawGameObjectLinesLos || obj.InLineOfSight())
                        //        ctx.DrawLine(vecStart, vecCenter, Color.FromArgb(150, color));
                        //}
                    }

                    var u = obj as Character;
                    if (u != null)
                    {
                        var playerOrPlayerOwned = (!u.IsNpc || u.SummonerObjectId != GameObjectManager.EmptyGameObject);
                        if (!settings.DrawPlayers && playerOrPlayerOwned)
                        {
                            continue;
                        }

                        var hostilityColor = Color.FromArgb(150, Color.Green);

                        var uStatusFlags = u.StatusFlags;
                        if (uStatusFlags.HasFlag(StatusFlags.Hostile))
                        {
                            hostilityColor = Color.FromArgb(150, Color.Red);

                            //if (settings.DrawAggroRangeCircles)
                            //    ctx.DrawCircle(vecCenter, u.MyAggroRange, 64,
                            //                   Color.FromArgb(75, Color.DeepSkyBlue));
                        }

                        if (uStatusFlags == StatusFlags.None)
                        {
                            hostilityColor = Color.FromArgb(150, Color.Yellow);
                        }

                        if (uStatusFlags.HasFlag(StatusFlags.Friend) || uStatusFlags.HasFlag(StatusFlags.PartyMember) || uStatusFlags.HasFlag(StatusFlags.AllianceMember))
                        {
                            hostilityColor = Color.FromArgb(150, Color.Green);
                        }



                        if (playerOrPlayerOwned)
                        {
                            if (settings.DrawPlayerNames)
                            {
                                ctx.Draw3DText(name, vecCenter);
                            }
                        }
                        else
                        {
                            if (settings.DrawUnitNames)
                            {
                                if (!string.IsNullOrEmpty(name) && obj.IsTargetable)
                                {
                                    ctx.Draw3DText(name, vecCenter);
                                }
                            }
                        }



                        ctx.DrawOutlinedBox(vecCenter, new Vector3(1), Color.FromArgb(255, hostilityColor));
                    }
                }
            }


            //Profile curProfile = ProfileManager.CurrentProfile;
            //if (curProfile != null)
            //{
            //    if (settings.DrawHotspots)
            //    {
            //        GrindArea ga = QuestState.Instance.CurrentGrindArea;
            //        if (ga != null)
            //        {
            //            if (ga.Hotspots != null)
            //            {
            //                foreach (Hotspot hs in ga.Hotspots)
            //                {
            //                    var p = hs.Position;
            //                    Vector3 vec = new Vector3(p.X, p.Y, p.Z);
            //                    ctx.DrawCircle(vec, 10.0f, 32, Color.FromArgb(200, Color.Red));

            //                    if (!string.IsNullOrWhiteSpace(hs.Name))
            //                        ctx.Draw3DText("Hotspot: " + hs.Name, vec);
            //                    else
            //                    {
            //                        ctx.Draw3DText("Hotspot", vec);
            //                    }
            //                }
            //            }
            //        }

            //        // This is only used by grind profiles.
            //        if (curProfile.HotspotManager != null)
            //        {
            //            foreach (NVector3 p in curProfile.HotspotManager.Hotspots)
            //            {
            //                Vector3 vec = new Vector3(p.X, p.Y, p.Z);
            //                ctx.DrawCircle(vec, 10.0f, 32, Color.FromArgb(200, Color.Red));
            //                ctx.Draw3DText("Hotspot", vec);
            //            }
            //        }
            //    }

            //    if (settings.DrawBlackspots)
            //    {
            //        foreach (Blackspot bs in BlackspotManager.GetAllCurrentBlackspots())
            //        {
            //            var p = bs.Location;
            //            Vector3 vec = new Vector3(p.X, p.Y, p.Z);
            //            ctx.DrawCircle(vec, bs.Radius, 32, Color.FromArgb(200, Color.Black));

            //            if (!string.IsNullOrWhiteSpace(bs.Name))
            //                ctx.Draw3DText("Blackspot: " + bs.Name, vec);
            //            else
            //            {
            //                ctx.Draw3DText("Blackspot: " + vec, vec);
            //            }
            //        }
            //    }
            //}
        }
Exemplo n.º 33
0
 public abstract void Draw(DrawingContext drawingContext);
Exemplo n.º 34
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     base.OnRender(drawingContext);
     this.UpdateLayout();
     Canvas.SetLeft(XRect, m_updateCount % ActualWidth);
 }
Exemplo n.º 35
0
        // OnRender вызывается, чтобы перерисовать кнопку
        protected override void OnRender(DrawingContext dc)
        {
            // Определение цвета фона
            Brush brushBackground = SystemColors.ControlBrush;

            if (isMouseReallyOver && IsMouseCaptured)
            {
                brushBackground = SystemColors.ControlDarkBrush;
            }

            // Определить ширину пера
            Pen pen = new Pen(Foreground, IsMouseOver ? 2 : 1);

            // Нарисовать заполненный прямоугольник с закругленными углами
            dc.DrawRoundedRectangle(brushBackground, pen,
                                    new Rect(new Point(0, 0), RenderSize), 4, 4);

            // Определение цвета переднего плана
            formtxt.SetForegroundBrush(
                IsEnabled ? Foreground : SystemColors.ControlDarkBrush);

            // Определение начала текста
            Point ptText = new Point(2, 2);

            switch (HorizontalContentAlignment)
            {
            case HorizontalAlignment.Left:
                ptText.X += Padding.Left;
                break;

            case HorizontalAlignment.Right:
                ptText.X += RenderSize.Width - formtxt.Width - Padding.Right;
                break;

            case HorizontalAlignment.Center:
            case HorizontalAlignment.Stretch:
                ptText.X += (RenderSize.Width - formtxt.Width -
                             Padding.Left - Padding.Right) / 2;
                break;
            }
            switch (VerticalContentAlignment)
            {
            case VerticalAlignment.Top:
                ptText.Y += Padding.Top;
                break;

            case VerticalAlignment.Bottom:
                ptText.Y +=
                    RenderSize.Height - formtxt.Height - Padding.Bottom;
                break;

            case VerticalAlignment.Center:
            case VerticalAlignment.Stretch:
                ptText.Y += (RenderSize.Height - formtxt.Height -
                             Padding.Top - Padding.Bottom) / 2;
                break;
            }

            // Рисование текста
            dc.DrawText(formtxt, ptText);
        }
Exemplo n.º 36
0
        /// <summary>ボーンを描画</summary>
        private static void DrawBones(IReadOnlyDictionary <JointType, Joint> joints, IDictionary <JointType, Point> jointPoints, DrawingContext dc)
        {
            foreach (var bone in KinectBoneConnections.Bones)
            {
                JointType jointType0 = bone.Item1;
                JointType jointType1 = bone.Item2;

                Joint joint0 = joints[jointType0];
                Joint joint1 = joints[jointType1];

                // If we can't find either of these joints, exit
                if (joint0.TrackingState == TrackingState.NotTracked ||
                    joint1.TrackingState == TrackingState.NotTracked)
                {
                    return;
                }

                // We assume all drawn bones are inferred unless BOTH joints are tracked
                Pen drawPen = inferredBonePen;
                if ((joint0.TrackingState == TrackingState.Tracked) &&
                    (joint1.TrackingState == TrackingState.Tracked))
                {
                    drawPen = bodyColor;
                }

                dc.DrawLine(drawPen, jointPoints[jointType0], jointPoints[jointType1]);
            }
        }
Exemplo n.º 37
0
 public override void Draw(DrawingContext drawingContext, Point origin)
 {
 }
Exemplo n.º 38
0
        /// <summary>関節を描画</summary>
        private static void DrawJoints(IReadOnlyDictionary <JointType, Joint> joints, IDictionary <JointType, Point> jointPoints, DrawingContext dc)
        {
            foreach (JointType jointType in joints.Keys)
            {
                TrackingState trackingState = joints[jointType].TrackingState;

                Brush drawBrush =
                    (trackingState == TrackingState.Tracked) ? trackedJointBrush :
                    (trackingState == TrackingState.Inferred) ? inferredJointBrush :
                    Brushes.Transparent;

                dc.DrawEllipse(drawBrush, null, jointPoints[jointType], JointThickness, JointThickness);
            }
        }
        /// <summary>
        /// Event handler for Kinect sensor's SkeletonFrameReady event
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            Skeleton[] skeletons = new Skeleton[0];

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletons);
                }
            }

            using (DrawingContext dc = this.drawingGroup.Open())
            {
                Rect  rec       = new Rect(50.0, 50.0, 50.0, 50.0); // rectangle that helps debugging. Depending on the color it has different meanings
                Joint HandLeft  = new Joint();
                Joint HandRight = new Joint();
                Rect  rec2      = new Rect(0.0, 0.0, 25.0, 25.0);


                // Draw a transparent background to set the render size
                //dc.DrawImage(imageSource, rec);
                //dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight));  // only to say the background has to be dark but actually it's not our case

                if (skeletons.Length != 0)
                {
                    foreach (Skeleton skel in skeletons)
                    {
                        RenderClippedEdges(skel, dc);

                        if (skel.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            this.DrawBonesAndJoints(skel, dc);   // draw the skeleton
                            foreach (Joint joint in skel.Joints) // we go through the whole skeleton
                            {
                                if (joint.JointType.Equals(JointType.HipCenter))
                                {
                                    hip.Position = joint.Position; // we track the position of the hip to detect when the hands are down
                                }

                                if (joint.JointType.Equals(JointType.Head))
                                {
                                    head.Position = joint.Position;
                                }

                                if (joint.JointType.Equals(JointType.HandLeft) || joint.JointType.Equals(JointType.HandRight))
                                {
                                    if (joint.JointType.Equals(JointType.HandLeft))
                                    {
                                        HandLeft.Position = joint.Position; // we track the position of the left hand because that's what we are interested in
                                    }
                                    else if (joint.JointType.Equals(JointType.HandRight))
                                    {
                                        HandRight.Position = joint.Position; // we track the position of the right hand because that's what we are interested in
                                    }

                                    if (HandRight.Position.X < 0.1f && HandLeft.Position.X > -0.15f)  // if the hands are closed on to each other in the center
                                    {
                                        // if the hands are closed one to each other, it either means that we start zooming in, or we finish zooming out

                                        if (counterout > 7) // if the hands have decreased from wide opened to close to each other
                                        //&& !isZoomedIn)
                                        {
                                            zoomoutMap(); // we zoom in
                                            isZoomedOut = true;
                                            // we initialize the values used before : the wide hands are no longer saved and the compteur goes back to 0
                                            HandLeftZoomout.X  = 0.0f;
                                            HandRightZoomout.X = 0.0f;
                                            counterout         = 0;
                                        }

                                        // if the hands are closed and we haven't zoomed out, we want to zoom in so we save the positions of the hands. Thanks to that, we will see if they get further to each others
                                        HandsClosedR.X = HandRight.Position.X;
                                        HandsClosedR.Y = HandRight.Position.Y;
                                        HandsClosedL.X = HandLeft.Position.X;
                                        HandsClosedL.Y = HandLeft.Position.Y;
                                        //dc.DrawRectangle(Brushes.Black, null, rec); // if the black rectangles appears, it means the hands are closed to each other
                                    }


                                    if (HandRight.Position.X < 0.5f && HandLeft.Position.X > -0.5f)                        // if the hands are really far one from each other
                                    {
                                        if (HandsClosedR.X < HandRight.Position.X && HandsClosedL.X > HandLeft.Position.X) // if the hands are further than when they were closed
                                        {
                                            counterin = counterin + 1;                                                     // we increase a counter which tells us if they more spaced
                                            // if (counterin>8) dc.DrawRectangle(Brushes.Purple, null, rec);
                                        }
                                        else if (HandRight.Position.X < 0.1f && HandLeft.Position.X > -0.15f) // if they stay in the middle or return in the middle before getting very wide we initialize everything again
                                        {
                                            counterin = 0;
                                            //dc.DrawRectangle(Brushes.Green, null, rec);
                                        }

                                        if (HandLeftZoomout.X < HandLeft.Position.X && HandRightZoomout.X > HandRight.Position.X) // if the hands get closer and closer
                                        {
                                            counterout = counterout + 1;
                                        }
                                        else if (HandRight.Position.X > 0.3f && HandLeft.Position.X < -0.3f) // if they don't and go wide again, we initialize everything
                                        {
                                            counterout = 0;
                                        }
                                    }

                                    if (HandLeft.Position.Y < hip.Position.Y || HandRight.Position.Y < hip.Position.Y)  // if the hands go below the hips, everything is initialized
                                    {
                                        counterin            = 0;
                                        counterout           = 0;
                                        HandLeftZoomout.X    = 0.0f;
                                        HandRightZoomout.X   = 0.0f;
                                        HandRightMoveRight.X = 0.5f;
                                        HandLeftMoveRight.X  = -0.5f;
                                        HandsClosedL.X       = 0.5f;
                                        HandsClosedR.X       = 0.5f;
                                        //dc.DrawRectangle(Brushes.RosyBrown, null, rec);
                                    }


                                    if (HandRight.Position.X > 0.3f && HandLeft.Position.X < -0.3f) // if the hands are wide
                                    {
                                        if (counterin > 7 && !isZoomedIn)                           // if they have been closed before and got wider

                                        {
                                            zoominMap(); // we zoom in
                                            isZoomedIn     = true;
                                            HandsClosedL.X = 0.5f;
                                            HandsClosedR.X = 0.5f;
                                            counterin      = 0;
                                            counterout     = 0;
                                        }
                                    }

                                    if (HandRight.Position.X > 0.5f && HandLeft.Position.X < -0.5f) // if the hands are wide, it can also mean that we want to zoom out, so we save the positions
                                    {
                                        HandLeftZoomout.X  = HandLeft.Position.X;
                                        HandRightZoomout.X = HandRight.Position.X;
                                        HandLeftZoomout.Y  = HandLeft.Position.Y;
                                        HandRightZoomout.Y = HandRight.Position.Y;
                                    }


                                    // implementation of the moving movement.
                                    // we first check if the hands are closed , then when they are left or right to the head. Then we record and check when they pass the previous right/left hand

                                    if (Math.Abs(Math.Abs(HandLeft.Position.X) - Math.Abs(HandRight.Position.X)) < 0.2 && HandRight.Position.X < head.Position.X && Math.Abs(Math.Abs(HandLeft.Position.X) - Math.Abs(HandRight.Position.X)) > 0.1)
                                    {
                                        HandRightMoveRight.X = HandRight.Position.X;
                                        HandLeftMoveRight.X  = HandLeft.Position.X;
                                        //dc.DrawRectangle(Brushes.DarkBlue, null, rec2);
                                    }
                                    if (HandRight.Position.X > head.Position.X)
                                    {
                                        if (HandLeft.Position.X > HandRightMoveRight.X)
                                        {
                                            dc.DrawRectangle(Brushes.Gray, null, rec);
                                            HandRightMoveRight.X = 0.5f;
                                            HandLeftMoveRight.X  = -0.5f;

                                            // MOVE RIGHT
                                        }
                                        else
                                        {
                                            HandRightMoveRight.X = 0.5f;
                                            HandLeftMoveRight.X  = -0.5f;
                                        }
                                    }
                                }


                                isZoomedIn  = false;
                                isZoomedOut = false;
                            }
                        }
                        else if (skel.TrackingState == SkeletonTrackingState.PositionOnly) // if the skeleton is seated
                        {
                            dc.DrawEllipse(
                                this.centerPointBrush,
                                null,
                                this.SkeletonPointToScreen(skel.Position),
                                BodyCenterThickness,
                                BodyCenterThickness);
                        }
                    }
                }



                // prevent drawing outside of our render area
                //this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight));
            }
        }
Exemplo n.º 40
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }
            if (drawingContext == null)
            {
                throw new ArgumentNullException("drawingContext");
            }
            if (markers == null || !textView.VisualLinesValid)
            {
                return;
            }
            var visualLines = textView.VisualLines;

            if (visualLines.Count == 0)
            {
                return;
            }
            int viewStart = visualLines.First().FirstDocumentLine.Offset;
            int viewEnd   = visualLines.Last().LastDocumentLine.Offset + visualLines.Last().LastDocumentLine.Length;

            foreach (LineMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart))
            {
                if (marker.BackgroundColor != null)
                {
                    BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder();
                    geoBuilder.AlignToWholePixels = true;
                    geoBuilder.CornerRadius       = 3;
                    geoBuilder.AddSegment(textView, marker);
                    Geometry geometry = geoBuilder.CreateGeometry();
                    if (geometry != null)
                    {
                        Color           color = marker.BackgroundColor.Value;
                        SolidColorBrush brush = new SolidColorBrush(color);
                        brush.Freeze();
                        drawingContext.DrawGeometry(brush, null, geometry);
                    }
                }
                if (marker.MarkerType != TextMarkerType.None)
                {
                    foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
                    {
                        Point startPoint = r.BottomLeft;
                        Point endPoint   = r.BottomRight;

                        Pen usedPen = new Pen(new SolidColorBrush(marker.MarkerColor), 1);
                        usedPen.Freeze();
                        switch (marker.MarkerType)
                        {
                        case TextMarkerType.Underlined:
                            double offset = 2.5;

                            int count = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4);

                            StreamGeometry geometry = new StreamGeometry();

                            using (StreamGeometryContext ctx = geometry.Open())
                            {
                                ctx.BeginFigure(startPoint, false, false);
                                ctx.PolyLineTo(CreatePoints(startPoint, endPoint, offset, count).ToArray(), true, false);
                            }

                            geometry.Freeze();

                            drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 41
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }

            if (drawingContext == null)
            {
                throw new ArgumentNullException("drawingContext");
            }

            if (this.markers == null || !textView.VisualLinesValid)
            {
                return;
            }

            var visualLines = textView.VisualLines;

            if (visualLines.Count == 0)
            {
                return;
            }

            var viewStart = visualLines.First().FirstDocumentLine.Offset;
            var viewEnd   = visualLines.Last().LastDocumentLine.EndOffset;

            foreach (var marker in this.markers.FindOverlappingSegments(viewStart, viewEnd - viewStart))
            {
                if (marker.BackgroundColor != null)
                {
                    var geoBuilder = new BackgroundGeometryBuilder()
                    {
                        AlignToWholePixels = true,
                        CornerRadius       = 3
                    };
                    geoBuilder.AddSegment(textView, marker);
                    var geometry = geoBuilder.CreateGeometry();
                    if (geometry != null)
                    {
                        var color = marker.BackgroundColor.Value;
                        var brush = new SolidColorBrush(color);
                        brush.Freeze();
                        drawingContext.DrawGeometry(brush, null, geometry);
                    }
                }
                var underlineMarkerTypes = TextMarkerTypes.SquigglyUnderline | TextMarkerTypes.NormalUnderline | TextMarkerTypes.DottedUnderline;
                if ((marker.MarkerTypes & underlineMarkerTypes) != 0)
                {
                    foreach (var r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
                    {
                        var startPoint = r.BottomLeft;
                        var endPoint   = r.BottomRight;

                        Brush usedBrush = new SolidColorBrush(marker.MarkerColor);
                        usedBrush.Freeze();
                        if ((marker.MarkerTypes & TextMarkerTypes.SquigglyUnderline) != 0)
                        {
                            var offset = 2.5;

                            var count = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4);

                            var geometry = new StreamGeometry();

                            using (var ctx = geometry.Open())
                            {
                                ctx.BeginFigure(startPoint, false, false);
                                ctx.PolyLineTo(CreatePoints(startPoint, endPoint, offset, count).ToArray(), true, false);
                            }

                            geometry.Freeze();

                            var usedPen = new Pen(usedBrush, 1);
                            usedPen.Freeze();
                            drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
                        }
                        if ((marker.MarkerTypes & TextMarkerTypes.NormalUnderline) != 0)
                        {
                            var usedPen = new Pen(usedBrush, 1);
                            usedPen.Freeze();
                            drawingContext.DrawLine(usedPen, startPoint, endPoint);
                        }
                        if ((marker.MarkerTypes & TextMarkerTypes.DottedUnderline) != 0)
                        {
                            var usedPen = new Pen(usedBrush, 1)
                            {
                                DashStyle = DashStyles.Dot
                            };
                            usedPen.Freeze();
                            drawingContext.DrawLine(usedPen, startPoint, endPoint);
                        }
                    }
                }
            }
        }
Exemplo n.º 42
0
        /// <summary>
        /// Draw glyphrun
        /// </summary>
        /// <param name="drawingContext">The drawing context to draw into </param>
        /// <param name="foregroundBrush">
        /// The foreground brush of the glyphrun. Pass in "null" to draw the
        /// glyph run with the foreground in TextRunProperties.
        /// </param>
        /// <param name="glyphRun">The GlyphRun to be drawn </param>
        /// <returns>bounding rectangle of drawn glyphrun</returns>
        /// <Remarks>
        /// TextEffect drawing code may use a different foreground brush for the text.
        /// </Remarks>
        internal Rect DrawGlyphRun(
            DrawingContext drawingContext,
            Brush foregroundBrush,
            GlyphRun glyphRun
            )
        {
            Debug.Assert(_shapeable != null);

            Rect inkBoundingBox = glyphRun.ComputeInkBoundingBox();

            if (!inkBoundingBox.IsEmpty)
            {
                // glyph run's ink bounding box is relative to its origin
                inkBoundingBox.X += glyphRun.BaselineOrigin.X;
                inkBoundingBox.Y += glyphRun.BaselineOrigin.Y;
            }

            if (drawingContext != null)
            {
                int pushCount = 0;              // the number of push we do
                try
                {
                    if (_textEffects != null)
                    {
                        // we need to push in the same order as they are set
                        for (int i = 0; i < _textEffects.Count; i++)
                        {
                            // get the text effect by its index
                            TextEffect textEffect = _textEffects[i];

                            if (textEffect.Transform != null && textEffect.Transform != Transform.Identity)
                            {
                                drawingContext.PushTransform(textEffect.Transform);
                                pushCount++;
                            }

                            if (textEffect.Clip != null)
                            {
                                drawingContext.PushClip(textEffect.Clip);
                                pushCount++;
                            }

                            if (textEffect.Foreground != null)
                            {
                                // remember the out-most non-null brush
                                // this brush will be used to draw the glyph run
                                foregroundBrush = textEffect.Foreground;
                            }
                        }
                    }

                    _shapeable.Draw(drawingContext, foregroundBrush, glyphRun);
                }
                finally
                {
                    for (int i = 0; i < pushCount; i++)
                    {
                        drawingContext.Pop();
                    }
                }
            }

            return(inkBoundingBox);
        }
Exemplo n.º 43
0
 /// <summary>
 /// Adds the popup to the view's popup queue for drawing.
 /// </summary>
 /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Draw(UltravioletTime)"/>.</param>
 /// <param name="dc">The drawing context that describes the render state of the layout.</param>
 internal void EnqueueForDrawing(UltravioletTime time, DrawingContext dc)
 {
     if (View.Popups.IsDrawingPopup(this))
         return;
     
     View.Popups.Enqueue(this);
 }
Exemplo n.º 44
0
        public void Draw(ApplicationContext actx, SWM.DrawingContext dc, double scaleFactor, double x, double y, ImageDescription idesc)
        {
            if (drawCallback != null) {
                DrawingContext c = new DrawingContext (dc, scaleFactor);
                actx.InvokeUserCode (delegate {
                    drawCallback (c, new Rectangle (x, y, idesc.Size.Width, idesc.Size.Height), idesc, actx.Toolkit);
                });
            }
            else {
                if (idesc.Alpha < 1)
                    dc.PushOpacity (idesc.Alpha);

                var f = GetBestFrame (actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false);
                var bmpImage = f as BitmapSource;

                // When an image is a single bitmap that doesn't have the same intrinsic size as the drawing size, dc.DrawImage makes a very poor job of down/up scaling it.
                // Thus we handle this manually by using a TransformedBitmap to handle the conversion in a better way when it's needed.

                var scaledWidth = idesc.Size.Width * scaleFactor;
                var scaledHeight = idesc.Size.Height * scaleFactor;
                if (bmpImage != null && (Math.Abs (bmpImage.PixelHeight - scaledHeight) > 0.001 || Math.Abs (bmpImage.PixelWidth - scaledWidth) > 0.001))
                    f = new TransformedBitmap (bmpImage, new ScaleTransform (scaledWidth / bmpImage.PixelWidth, scaledHeight / bmpImage.PixelHeight));

                dc.DrawImage (f, new Rect (x, y, idesc.Size.Width, idesc.Size.Height));

                if (idesc.Alpha < 1)
                    dc.Pop ();
            }
        }
Exemplo n.º 45
0
 /// <inheritdoc/>
 protected override void DrawOverride(UltravioletTime time, DrawingContext dc)
 {
     if (View.Popups.IsDrawingPopup(this))
     {
         root.Draw(time, dc);
     }
     else
     {
         EnqueueForDrawingIfOpen(time, dc);
     }
 }
Exemplo n.º 46
0
        private void DrawArc(DrawingContext drawingContext, float scale, double height, Pen pen, float offset)
        {
            Arc a1;
            Arc a2;

            //BiarcInterpolation.Biarc(p1, t1, p2, t2, out a1, out a2);

            BiarcInterpolation.Biarc(Start, End, out a1, out a2);



            var cp = a1.Interpolate(1, offset);

            var sp = a1.Interpolate(0, offset);

            var ep = a2.Interpolate(1, offset);


            var start = new Point(sp.x * scale, height - sp.y * scale);
            var end   = new Point(ep.x * scale, height - ep.y * scale);

            var center = new Point(cp.x * scale, height - cp.y * scale);

            var r1 = Math.Max(0, a1.radius + (a1.IsClockwise() ? offset : -offset));
            var r2 = Math.Max(0, a2.radius + (a2.IsClockwise() ? offset : -offset));


            var size1 = new Size(r1 * scale, r1 * scale);
            var size2 = new Size(r2 * scale, r2 * scale);

            var sweep1 = a1.IsClockwise() ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
            var sweep2 = a2.IsClockwise() ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;


            var geometry = new StreamGeometry();

            using (var context = geometry.Open())
            {
                context.BeginFigure(start, false, false);

                if ((start - center).LengthSquared > 0.01)
                {
                    if (Math.Abs(a1.angle) < 0.1)
                    {
                        context.LineTo(center, true, false);
                    }
                    else
                    {
                        context.ArcTo(center, size1, 0, a1.IsGreatArc(), sweep1, true, false);
                    }
                }


                if ((center - end).LengthSquared > 0.01)
                {
                    if (a2.radius < 0.1)
                    {
                        context.LineTo(end, true, false);
                    }
                    else
                    {
                        if (Math.Abs(a2.angle) < 0.1)
                        {
                            context.LineTo(end, true, false);
                        }
                        else
                        {
                            context.ArcTo(end, size2, 0, a1.IsGreatArc(), sweep2, true, false);
                        }
                    }
                }

                context.LineTo(end, true, true);
            }

            geometry.Freeze();
            drawingContext.DrawGeometry(null, pen, geometry);
        }
Exemplo n.º 47
0
        /// <inheritdoc/>
        protected override void DrawOverride(UltravioletTime time, DrawingContext dc)
        {
            var borderColor = BorderColor;
            var borderThickness = BorderThickness;

            var borderArea = new RectangleD(0, 0, UntransformedRelativeBounds.Width, UntransformedRelativeBounds.Height);

            var leftSize = Math.Min(borderThickness.Left, borderArea.Width);
            if (leftSize > 0)
            {
                var leftArea = new RectangleD(borderArea.Left, borderArea.Top, leftSize, borderArea.Height);
                DrawBlank(dc, leftArea, borderColor);
            }

            var topSize = Math.Min(borderThickness.Top, borderArea.Height);
            if (topSize > 0)
            {
                var topArea = new RectangleD(borderArea.Left, borderArea.Top, borderArea.Width, topSize);
                DrawBlank(dc, topArea, borderColor);
            }

            var rightSize = Math.Min(borderThickness.Right, borderArea.Width);
            if (rightSize > 0)
            {
                var rightPos = Math.Max(borderArea.Left, borderArea.Right - rightSize);
                var rightArea = new RectangleD(rightPos, borderArea.Top, rightSize, borderArea.Height);
                DrawBlank(dc, rightArea, borderColor);
            }

            var bottomSize = Math.Min(borderThickness.Bottom, borderArea.Height);
            if (bottomSize > 0)
            {
                var bottomPos = Math.Max(borderArea.Top, borderArea.Bottom - bottomSize);
                var bottomArea = new RectangleD(borderArea.Left, bottomPos, borderArea.Width, bottomSize);
                DrawBlank(dc, bottomArea, borderColor);
            }

            base.DrawOverride(time, dc);
        }
Exemplo n.º 48
0
 protected override void OnRender(DrawingContext dc)
 {
     dc.DrawImage(Surface, new Rect(RenderSize));
 }
 void DrawBall(DrawingContext dc) {
   dc.Ellipse(Colors.Black, ballX, ballY, ballSize, ballSize);
 }
Exemplo n.º 50
0
        public override void Draw(DrawingContext drawingContext, ulong tickMinVis, ulong tickMaxVis)
        {
            Rect r = new Rect(new Point(0, 0), new Size(this.ActualWidth, this.ActualHeight));

            // Use a slightly oversize clip region.  Otherwise the user wouldn't see the left edge
            // of the outline on an event starting right at zero.
            Rect r2 = new Rect(new Point(-2, 0), new Size(this.ActualWidth + 4, this.ActualHeight));
            RectangleGeometry rg = new RectangleGeometry(r2);

            drawingContext.PushClip(rg);

            drawingContext.DrawRectangle(Brushes.Transparent, null, r);

            drawingContext.DrawLine(axisPen, new Point(0, this.ActualHeight / 2), new Point(this.ActualWidth, this.ActualHeight / 2));

            bool doOptimizedBorders = false;

            // Chunks are ordered by z-index, then by start time.  For each z-index, chunks should be in left-to-right order
            // and not overlap.  Track the maximum drawn X pixel for each z-index pass, so we can draw very small events
            // without drawing a crazy number of rectangles.  See DrawChunk() for the comparisons against maximumDrawnX.
            int                   currentZIndex     = -1;
            ChunkDrawData         previousChunkData = null;
            List <IEventDataNode> forceDrawChunks   = new List <IEventDataNode>();

            foreach (var chunk in this.sortedNodes)
            {
                if (chunk.ZIndex > currentZIndex)
                {
                    currentZIndex = chunk.ZIndex;

                    // Draw the previous chunk data (if any) and the forced-drawn (selected/hot) chunks at the previous level
                    DrawLastDelayedAndForcedDrawChunks(drawingContext, previousChunkData, forceDrawChunks);
                    previousChunkData = null;
                    forceDrawChunks.Clear();

                    // If dataSource.ContiguousEvents is true, then we are guaranteed that the events are
                    // always right next to each other -- but only at level 0.  At higher levels, they may
                    // not be contiguous due to the tree expansion state.  The "doOptimizedBorders" mode is to
                    // fill the entire region with the outline color, then draw the chunks with no borders
                    // (if they are big enough to be visible).
                    doOptimizedBorders = (dataSource.ContiguousEvents && currentZIndex == 0);

                    if (doOptimizedBorders)
                    {
                        // Draw the full bar in the standard pen brush color, as if it were full of 1-px wide chunks.
                        r = new Rect(new Point(0, verticalMargin), new Size(this.ActualWidth, this.ActualHeight - (verticalMargin * 2)));
                        if (currentZIndex > 0)
                        {
                            double delta = chunk.ZIndex * 2;
                            r.Inflate(0, -delta);
                        }
                        drawingContext.DrawRectangle(this.Stroke, null, r);
                    }
                }

                if (chunk.Visible)
                {
                    Brush brush;
                    Pen   pen;

                    if (chunk == hotChunk || this.selectedChunks.Contains(chunk))
                    {
                        // We need to draw these a second time.  If we skip them, it causes different
                        // merging behavior and you get visual artifacts as you select/hover over events.
                        forceDrawChunks.Add(chunk);
                    }

                    pen = doOptimizedBorders ? null : standardPen;

                    if (UseEventColor)
                    {
                        uint nodeColor = chunk.Color;
                        if (!customBrushes.TryGetValue(nodeColor, out brush))
                        {
                            brush = new SolidColorBrush(new EventColor(nodeColor));
                            customBrushes.Add(nodeColor, brush);
                        }
                    }
                    else
                    {
                        brush = this.Fill;
                    }

                    previousChunkData = DrawChunk(drawingContext, chunk, brush, pen, previousChunkData, forceDraw: false);
                }
            }

            DrawLastDelayedAndForcedDrawChunks(drawingContext, previousChunkData, forceDrawChunks);

            double?lastDrawnSlicingMarkerX = null;

            foreach (var marker in this.slicingMarkers)
            {
                lastDrawnSlicingMarkerX = DrawSlicingMarker(drawingContext, marker, lastDrawnSlicingMarkerX);
            }

            List <Rect>   labelRects = new List <Rect>();
            FormattedText ftLabel    = null;

            // Draw selected chunk arrows, and calculate label rect requirements
            foreach (var selectedChunk in this.selectedChunks)
            {
                if (selectedChunk != hotChunk)
                {
                    var    brush        = IsFocused ? this.SelectedFill : this.InactiveSelectedFill;
                    var    middle       = TimeAxis.TimeToScreen(selectedChunk.StartTime + (selectedChunk.Duration / 2));
                    double heightAdjust = 0.5;

                    if (selectedChunk.Style == EventRenderStyle.SlicingMarker)
                    {
                        heightAdjust = verticalMargin - 6;
                    }

                    var geom = selectionArrowGeometry.Clone();
                    geom.Transform = new TranslateTransform(middle, verticalMargin - heightAdjust);
                    drawingContext.DrawGeometry(brush, selectedPen, geom);

                    var x1 = TimeAxis.TimeToScreen(selectedChunk.StartTime);
                    var x2 = TimeAxis.TimeToScreen(selectedChunk.StartTime + selectedChunk.Duration);
                    if (x1 < this.ActualWidth && x2 > 0)
                    {
                        // Draw label, if selected chunk is visible
                        if (ftLabel == null)
                        {
                            // NOTE:  It is assumed that all selected chunks have the same name...
                            ftLabel = new FormattedText(selectedChunk.Name, CultureInfo.CurrentCulture,
                                                        FlowDirection.LeftToRight, labelTypeface, labelFontSize, Brushes.Black);
                        }

                        // Try to center the label under the event.  But adjust its position if it
                        // is clipped by the left or right edge of the timeline.
                        var left = middle - ftLabel.Width / 2;
                        if (left < 0)
                        {
                            left = 0;
                        }
                        else if (left + ftLabel.Width > this.ActualWidth)
                        {
                            left = this.ActualWidth - ftLabel.Width;
                        }

                        // Create a rect (top/height insignificant) for this label and remember it
                        labelRects.Add(new Rect(left, 0, ftLabel.Width, 10));
                    }
                }
            }

            if (ftLabel != null)
            {
                List <Rect> mergedRects = new List <Rect>(labelRects.Count);

                // Merge the overlapping label rects together
                while (labelRects.Count > 0)
                {
                    Rect rect = labelRects[0];

                    labelRects.RemoveAt(0);

                    for (int i = 0; i < labelRects.Count;)
                    {
                        if (rect.IntersectsWith(labelRects[i]))
                        {
                            rect.Union(labelRects[i]);
                            labelRects.RemoveAt(i);
                        }
                        else
                        {
                            i++;
                        }
                    }

                    mergedRects.Add(rect);
                }

                // Draw the text centered in each of the remaining label rects
                foreach (var rect in mergedRects)
                {
                    double centerX = rect.Left + (rect.Width / 2) - (ftLabel.Width / 2);
                    drawingContext.DrawText(ftLabel, new Point(centerX, this.ActualHeight - verticalMargin));
                }
            }

            // Draw hot chunk arrow
            if (hotChunk != null)
            {
                var    middle       = TimeAxis.TimeToScreen(hotChunk.StartTime + (hotChunk.Duration / 2));
                double heightAdjust = 0.5;

                if (hotChunk.Style == EventRenderStyle.SlicingMarker)
                {
                    heightAdjust = verticalMargin - 6;
                }

                hotArrowGeometry.Transform = new TranslateTransform(middle, verticalMargin - heightAdjust);
                drawingContext.DrawGeometry(this.HighlightedFill, this.highlightedPen, hotArrowGeometry);
            }

            drawingContext.Pop(); // pop clip

            UpdateToolTip();
        }
 void DrawBlocks(DrawingContext dc) {
   for (int i = 0; i < blockCount; ++i) {
     for (int j = 0; j < blockCount; ++j) {
       if (blocks[i, j] == 1)
         dc.Rect(Colors.Green, i * blockSize, j * blockSize, blockSize, blockSize);
       if (blocks[i, j] == 2)
         dc.Rect(Colors.Blue, i * blockSize, j * blockSize, blockSize, blockSize);
     }
   }
 }
Exemplo n.º 52
0
        ChunkDrawData DrawChunk(DrawingContext drawingContext, IEventDataNode chunk, Brush brush, Pen pen, ChunkDrawData previousChunkData, bool forceDraw)
        {
            var x1 = TimeAxis.TimeToScreen(chunk.StartTime);
            var x2 = Math.Max(x1, TimeAxis.TimeToScreen(chunk.StartTime + chunk.Duration));  // Max in case the duration is bogus

            if (x2 < 0 || x1 > this.ActualWidth)
            {
                if (previousChunkData != null)
                {
                    drawingContext.DrawRectangle(previousChunkData.Fill, previousChunkData.Pen, previousChunkData.Rect);
                }

                return(null);
            }

            var r = new Rect(new Point(x1, verticalMargin), new Size(x2 - x1, this.ActualHeight - (verticalMargin * 2)));
            var halfHeightRect = new Rect(new Point(x1, (this.ActualHeight - halfHeight) / 2), new Size(x2 - x1, halfHeight));
            var style          = chunk.Style;

            if (pen == null)
            {
                // Since there is no stroke (pen == null), this is a "normal" chunk with no border
                // (the bar has already been filled w/ border color) so deflate 1/2 pixel to simulate
                // a border stroke.
                r.Inflate(-0.5, -0.5);
            }
            else
            {
                r.Inflate(0, -0.5);
            }

            const int minWidth = 3;

            // Points-in-time (markers) are always 3px wide
            if (style == EventRenderStyle.ParentedMarker)
            {
                r = new Rect(x1 - Math.Floor((double)minWidth / 2), verticalMargin, minWidth, this.ActualHeight - (verticalMargin * 2));
            }

            // Adjust rect height based on chunk nesting depth
            if (chunk.ZIndex > 0 && !r.IsEmpty && style != EventRenderStyle.HalfHeight)
            {
                double delta = chunk.ZIndex * 2;
                r.Inflate(0, -delta);
            }

            if (forceDraw)
            {
                // This is a special (hot or selected) chunk, so enforce a minimum width and always draw it.
                if (style == EventRenderStyle.HalfHeight)
                {
                    r = halfHeightRect;
                }

                var width = r.Width;
                if (width < minWidth)
                {
                    var halfGap = (minWidth - width) / 2;
                    r = new Rect(new Point(r.Left - halfGap, r.Top), new Point(r.Right + halfGap, r.Bottom));
                }
                drawingContext.DrawRectangle(brush, pen, r);
                return(null);
            }

            const double minDistance = 16;

            if (style == EventRenderStyle.HalfHeight)
            {
                r = halfHeightRect;
            }

            // Draw the chunk.  We may need to merge it with the previous rect if there is one.
            if (previousChunkData != null)
            {
                // We have a previous rect.  If it's far enough away from this one, then draw it.
                // OR, if this one is big enough BY ITSELF to be drawn, draw the previous one.
                // Otherwise, merge it with this one, and draw the result if it's wide enough.
                if (previousChunkData.Rect.Right < (r.Left - (minDistance / 4)) || (r.Width >= minDistance))
                {
                    drawingContext.DrawRectangle(previousChunkData.Fill, previousChunkData.Pen, previousChunkData.Rect);
                }
                else
                {
                    previousChunkData.Rect = Rect.Union(previousChunkData.Rect, r);
                    previousChunkData.Fill = Brushes.Gray;

                    if (previousChunkData.Rect.Width >= minDistance)
                    {
                        drawingContext.DrawRectangle(previousChunkData.Fill, previousChunkData.Pen, previousChunkData.Rect);
                        previousChunkData = null;
                    }

                    return(previousChunkData);
                }
            }

            if (r.Width >= minDistance)
            {
                drawingContext.DrawRectangle(brush, pen, r);
                previousChunkData = null;
            }
            else
            {
                previousChunkData = new ChunkDrawData {
                    Fill = brush, Rect = r, Pen = pen
                };
            }

            return(previousChunkData);
        }
Exemplo n.º 53
0
 public void AppendPath(DrawingContext context)
 {
     foreach (var f in context.Geometry.Figures)
         geometry.Figures.Add (f.Clone ());
     Path = context.geometry.Figures[context.geometry.Figures.Count - 1];
 }
Exemplo n.º 54
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            drawingContext.DrawDrawing(_drawingGroup);
        }
Exemplo n.º 55
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     base.OnRender(drawingContext);
     drawingContext.DrawRectangle(brush, pen, rect);
 }
Exemplo n.º 56
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     drawingContext.DrawImage(sScrollOrigin, new Rect(mLocation, sImageSize));
 }
Exemplo n.º 57
0
        /// <inheritdoc/>
        protected override void DrawOverride(UltravioletTime time, DrawingContext dc)
        {
            /* NOTE:
             * By pre-emptively setting the clip region in the Grid itself, we can prevent
             * multiple batch flushes when drawing consecutive children within the same clip region.
             * This is because DrawingContext evaluates the current clip state and only performs
             * a flush if something has changed. */

            var clip = (RectangleD?)null;

            for (int i = 0; i < Children.Count; i++)
            {
                var child = Children.GetByZOrder(i);
                if (child.ClipRectangle != clip)
                {
                    if (clip.HasValue)
                    {
                        clip = null;
                        dc.PopClipRectangle();
                    }

                    if (child.ClipRectangle.HasValue)
                    {
                        clip = child.ClipRectangle;
                        dc.PushClipRectangle(clip.Value);
                    }
                }

                child.Draw(time, dc);
            }

            if (clip.HasValue)
                dc.PopClipRectangle();
        }
Exemplo n.º 58
0
        /// <summary>
        /// Generates a BitmapSource from IVisualizationWireframe data.  Useful for thumbnails
        /// and GIF exports.
        /// </summary>
        public static BitmapSource GenerateWireframeImage(WireframeObject wireObj,
                                                          double dim, int eulerX, int eulerY, int eulerZ, bool doPersp, bool doBfc,
                                                          bool doRecenter)
        {
            if (wireObj == null)
            {
                // Can happen if the visualization generator is failing on stuff loaded from
                // the project file.
                return(BROKEN_IMAGE);
            }

            // Generate the path geometry.
            GeometryGroup geo = GenerateWireframePath(wireObj, dim, eulerX, eulerY, eulerZ,
                                                      doPersp, doBfc, doRecenter);

            // Render geometry to bitmap -- https://stackoverflow.com/a/869767/294248
            Rect bounds = geo.GetRenderBounds(null);

            //Debug.WriteLine("RenderWF dim=" + dim + " bounds=" + bounds + ": " + wireObj);

            // Create bitmap.
            RenderTargetBitmap bitmap = new RenderTargetBitmap(
                (int)dim,
                (int)dim,
                96,
                96,
                PixelFormats.Pbgra32);
            //RenderOptions.SetEdgeMode(bitmap, EdgeMode.Aliased);  <-- no apparent effect

            DrawingVisual dv = new DrawingVisual();

            using (DrawingContext dc = dv.RenderOpen()) {
                dc.DrawRectangle(Brushes.Black, null, new Rect(0, 0, bounds.Width, bounds.Height));
                Pen pen = new Pen(Brushes.White, 1.0);
                dc.DrawGeometry(null, pen, geo);
            }
            bitmap.Render(dv);

#if false
            // Old way: render Path to bitmap -- https://stackoverflow.com/a/23582564/294248

            // Clear the bitmap to black.  (Is there an easier way?)
            GeometryGroup bkgnd = new GeometryGroup();
            bkgnd.Children.Add(new RectangleGeometry(new Rect(0, 0, bounds.Width, bounds.Height)));
            Path path = new Path();
            path.Data   = bkgnd;
            path.Stroke = path.Fill = Brushes.Black;
            path.Measure(bounds.Size);
            path.Arrange(bounds);
            bitmap.Render(path);

            path        = new Path();
            path.Data   = geo;
            path.Stroke = Brushes.White;
            path.Measure(bounds.Size);
            path.Arrange(bounds);
            bitmap.Render(path);
#endif

            bitmap.Freeze();
            return(bitmap);
        }
Exemplo n.º 59
0
        /// <inheritdoc/>
        protected override void DrawOverride(UltravioletTime time, DrawingContext dc)
        {
            if (textLayoutCommands != null && textLayoutCommands.Count > 0 && containingControl != null)
            {
                var position = Display.DipsToPixels(UntransformedAbsolutePosition + ContentOffset);
                var positionRounded = dc.IsTransformed ? (Vector2)position : (Vector2)(Point2)position;
                View.Resources.TextRenderer.Draw((SpriteBatch)dc, textLayoutCommands, positionRounded, containingControl.Foreground * dc.Opacity);
            }

            base.DrawOverride(time, dc);
        }
Exemplo n.º 60
0
        public override void Draw(DrawingContext drawingContext)
        {
            var diagonal = Point.Subtract(Coordinates[0], Coordinates[1]);

            drawingContext.DrawRoundedRectangle(BrushColor, Pen, new Rect(Coordinates[1], diagonal), (Coordinates[1].X - Coordinates[0].X) / 2, (Coordinates[1].Y - Coordinates[0].Y) / 2);
        }