protected override void OnRender(DrawingContext drawingContext)
 {
     base.OnRender(drawingContext);
     drawingContext.PushTransform(new TranslateTransform(AdornedElement.RenderSize.Width - 14, (AdornedElement.RenderSize.Height - 18) / 2.0));
     drawingContext.DrawGeometry(ArrowBrush, null, sda_render_geometry);
     drawingContext.Pop();
 }
        protected override void DrawPointElement(DrawingContext dc, int Zoom)
        {
            dc.DrawLine(new Pen(Brushes.Black, 2), new Point(), new Point(0, -BodyOffset));

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

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

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

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

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

            dc.Pop();

            dc.Pop();
        }
Exemple #3
0
		public void drawLimb(DrawingContext dc, Point p1, Point p2, int margin)
		{

			dc.PushTransform(new TranslateTransform(p1.X, p1.Y));
			
			Vector diff = p2 - p1;
			diff.Normalize();

			double angle = Math.Acos(diff.Y) * (180.0 / Math.PI);
			if (Double.IsNaN(angle))
				angle = 0;

            if (Double.IsNaN(diff.X))
                diff.X = 0;

			dc.PushTransform(new RotateTransform(Math.Sign(diff.X) * (-1) * angle));

			Vector diff2 = p2 - p1;
			double scale = diff2.Length / (this.Height - 2 * margin);
			dc.PushTransform(new ScaleTransform(1, scale));

			dc.PushTransform(new TranslateTransform(-this.Width / 2.0, -margin));

			
			dc.DrawImage(this.Image, new Rect(0, 0, this.Width, this.Height));

			dc.Pop();
			dc.Pop();
			dc.Pop();
			dc.Pop();
		}
Exemple #4
0
		protected override void InnerDraw(DrawingContext drawingContext)
		{
			drawingContext.PushTransform(_translateTransform);
			drawingContext.PushTransform(_rotateTransform);
			base.InnerDraw(drawingContext);
			drawingContext.Pop();
			drawingContext.Pop();
		}
    private void DrawTriangle(DrawingContext drawingContext, Point origin, double rotation)
    {
      drawingContext.PushTransform(new TranslateTransform(origin.X, origin.Y));
      drawingContext.PushTransform(new RotateTransform(rotation));

      drawingContext.DrawGeometry(m_Pen.Brush, null, m_Triangle);

      drawingContext.Pop();
      drawingContext.Pop();
    }
 /// <summary>This method performs the actual render operation to show a text label</summary>
 /// <param name="dc">Drawing context</param>
 /// <param name="info">Render info</param>
 /// <param name="scale">The scale.</param>
 /// <param name="offset">The offset.</param>
 public virtual void RenderHeader(DrawingContext dc, AutoHeaderTextRenderInfo info, double scale, Point offset)
 {
     dc.PushTransform(new TranslateTransform(offset.X, offset.Y));
     dc.PushTransform(new ScaleTransform(scale, scale));
     dc.PushClip(new RectangleGeometry(info.RenderRect));
     info.FormattedText.SetMaxTextWidths(new[] { info.RenderRect.Width });
     info.FormattedText.MaxLineCount = 1;
     info.FormattedText.Trimming = TextTrimming.CharacterEllipsis;
     dc.DrawText(info.FormattedText, info.RenderRect.TopLeft);
     dc.Pop();
     dc.Pop();
     dc.Pop();
 }
Exemple #7
0
		//private const int Margin = 3;
		protected override void InnerDraw(DrawingContext drawingContext)
		{
			base.InnerDraw(drawingContext);
			if (_scaleTransform != null)
				drawingContext.PushTransform(_scaleTransform);
			if (_clipGeometry != null)
				drawingContext.PushClip(_clipGeometry);
			drawingContext.DrawDrawing(_textDrawing);
			if (_clipGeometry != null)
				drawingContext.Pop();
			if (_scaleTransform != null)
				drawingContext.Pop();
		}
Exemple #8
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            AnimationControl();
            var width = Width < 1 ? 1 : Width;
            drawingContext.PushTransform(new TranslateTransform(RenderSize.Width / 2, RenderSize.Height / 2));

            for (int i = 0; i < c_Blobs; i++)
            {
                drawingContext.PushTransform(new RotateTransform((360 / c_Blobs) * i));
                drawingContext.DrawRectangle(m_Brushes[i], null, new Rect(0, width / 4.25, width / 16.0, width / 4.0));
                drawingContext.Pop();
            }
            drawingContext.Pop();
        }
		protected override void InnerDraw(DrawingContext drawingContext)
		{
			base.InnerDraw(drawingContext);
			drawingContext.PushTransform(_scaleTransform);
			drawingContext.DrawDrawing(_textDrawing);
			drawingContext.Pop();
		}
 /// <summary>This method draws a rectangular background around a group of elements</summary>
 /// <param name="dc">The drawing context.</param>
 /// <param name="info">Render info</param>
 /// <param name="scale">The scale.</param>
 /// <param name="offset">The offset.</param>
 public virtual void RenderBackground(DrawingContext dc, GroupBackgroundRenderInfo info, double scale, Point offset)
 {
     dc.PushTransform(new TranslateTransform(offset.X, offset.Y));
     dc.PushTransform(new ScaleTransform(scale, scale));
     dc.DrawRectangle(info.Background, null, info.RenderRect);
     if (info.Border != null && info.BorderWidth > 0)
     {
         var rect2 = new Rect(info.RenderRect.X + (info.BorderWidth/2),
                              info.RenderRect.Y + (info.BorderWidth/2),
                              info.RenderRect.Width + info.BorderWidth,
                              info.RenderRect.Height + info.BorderWidth);
         dc.DrawRectangle(null, new Pen(info.Border, info.BorderWidth), rect2);
     }
     dc.Pop();
     dc.Pop();
 }
		protected override void OnRender(DrawingContext drawingContext) {
			// draw everything except the reflection
			base.OnRender(drawingContext);

			// set opacity
			drawingContext.PushOpacityMask(opacityMask);

			reflection.Visual = Child;
			var group = new TransformGroup();


			if (Child.RenderTransform is TransformGroup) {
				foreach (var child in ((TransformGroup)Child.RenderTransform).Children) {
					group.Children.Add(child);
				}
			}
			else {
				group.Children.Add(Child.RenderTransform);
			}

			scaleTransform.CenterY = (ActualHeight / 1.5) + ((ActualHeight / 1.5) / 4);
			scaleTransform.CenterX = ActualWidth / 2;
			group.Children.Add(scaleTransform);

			reflection.Transform = group;

			// draw the reflection
			drawingContext.DrawRectangle(
					reflection, null,
					new Rect(0, ActualHeight / 1.5, ActualWidth, ActualHeight / 3));

			// cleanup
			drawingContext.Pop();
		}
 protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
 {
     Vector offsetSize = GetOffsetSize() + new Vector(Size, Size);
     dc.PushTransform(new TranslateTransform(offsetSize.X, offsetSize.Y));
     base.ApplyFilter(source, dc, width, height);
     dc.Pop();
 }
Exemple #13
0
        public void Draw(LayerPropertiesModel props, LayerPropertiesModel applied, DrawingContext c)
        {
            if (applied?.Brush == null)
                return;

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

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

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

            c.PushClip(new RectangleGeometry(clip));
            c.DrawRectangle(applied.Brush, null, rect);
            c.Pop();
        }
        protected override void OnRender(DrawingContext dc)
        {
            Point pos, tangent;
            double angleInRadians;
            double angleInDegrees;
            TransformGroup tg;
            Pen pen = new Pen(Stroke, StrokeThickness);
            //dc.DrawGeometry(null, pen, LinePath);
            if (BeginCap != null)
            {

                LinePath.GetPointAtFractionLength(0.01d, out pos, out tangent);
                angleInRadians = Math.Atan2(tangent.Y, tangent.X) + Math.PI;
                angleInDegrees = angleInRadians * 180 / Math.PI + 180;
                tg = new TransformGroup();
                tg.Children.Add(new RotateTransform(angleInDegrees));
                LinePath.GetPointAtFractionLength(0.0d, out pos, out tangent);
                tg.Children.Add(new TranslateTransform(pos.X, pos.Y));
                dc.PushTransform(tg);
                dc.DrawGeometry(Brushes.DeepPink, pen, BeginCap);
                dc.Pop();
            }
            if (EndCap != null)
            {
                LinePath.GetPointAtFractionLength(0.99, out pos, out tangent);
                angleInRadians = Math.Atan2(tangent.Y, tangent.X) + Math.PI;
                angleInDegrees = angleInRadians * 180 / Math.PI;
                tg = new TransformGroup();
                tg.Children.Add(new RotateTransform(angleInDegrees));
                LinePath.GetPointAtFractionLength(1, out pos, out tangent);
                tg.Children.Add(new TranslateTransform(pos.X, pos.Y));
                dc.PushTransform(tg);
                dc.DrawGeometry(Brushes.DeepPink, pen, EndCap);
            }
        }
Exemple #15
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (AdornedElement.RenderSize.Width < 20)
                return;

            TranslateTransform transform = new TranslateTransform
                    (
                            AdornedElement.RenderSize.Width - 15,
                            (AdornedElement.RenderSize.Height - 5) / 2
                    );
            transform = new TranslateTransform
                    (
                            AdornedElement.RenderSize.Width / 2 - 3.5,
                            AdornedElement.RenderSize.Height / 2 - 10
                    );
            drawingContext.PushTransform(transform);

            Geometry geometry = ascGeometry;
            if (this.Direction == ListSortDirection.Descending)
                geometry = descGeometry;
            drawingContext.DrawGeometry(Brushes.LightGray, null, geometry);

            drawingContext.Pop();
        }
Exemple #16
0
        private void RenderImportanceArrow(DrawingContext dc, FrameworkElement mostImportant, FrameworkElement leastImportant)
        {
            var startPoint = FindPoint(mostImportant, new Point(mostImportant.ActualWidth/2, mostImportant.ActualHeight));
            var endPoint = FindPoint(leastImportant, new Point(leastImportant.ActualWidth/2, 0));

            var vector = Point.Subtract(endPoint, startPoint);

            var midPoint = Point.Add(startPoint, Vector.Multiply(vector, 0.66));

            Transform arrowTransform = Transform.Identity;
            double angle;
            if (Math.Abs((angle = Vector.AngleBetween(vector, new Vector(0, -1))) - 0) > double.Epsilon)
            {
                arrowTransform = new RotateTransform(angle, midPoint.X, midPoint.Y);
            }

            var line = BuildPath.From(startPoint).LineTo(endPoint.X, endPoint.Y).Build();
            var arrow = BuildPath.From(midPoint.X - 3, midPoint.Y - 3).LineTo(midPoint.X, midPoint.Y)
                .LineTo(midPoint.X + 3, midPoint.Y - 3).Build();

            dc.DrawGeometry(null, _pen, line);

            dc.PushTransform(arrowTransform);

            dc.DrawGeometry(null, _pen, arrow);

            dc.Pop();
        }
Exemple #17
0
		protected override void OnRender(DrawingContext drawingContext)
		{
			base.OnRender(drawingContext);

			if (AdornedElement.RenderSize.Width < 20)
				return;

			drawingContext.PushTransform(
					 new TranslateTransform(
						 AdornedElement.RenderSize.Width - 15,
						(AdornedElement.RenderSize.Height - 5) / 2));

			if (IsSecondaryAdorner)
			{
				drawingContext.DrawGeometry(null, new Pen(Brushes.Black, 0.5),
						Direction == ListSortDirection.Ascending ?
							_AscGeometry : _DescGeometry);
			}
			else
			{
				drawingContext.DrawGeometry(Brushes.Black, null,
						Direction == ListSortDirection.Ascending ?
							_AscGeometry : _DescGeometry);
			}

			drawingContext.Pop();
		}
        protected override void OnRender(DrawingContext drawingContext)
        {
            PushButton pushButton = Visual as PushButton;
            if (pushButton.Pushed && _pushedImage != null)
            {
                drawingContext.DrawImage(_pushedImage, _imageRect);
            }
            else if (_image != null)
            {
                drawingContext.DrawImage(_image, _imageRect);
            }

            if (pushButton.Pushed)
            {
                drawingContext.PushTransform(new TranslateTransform(pushButton.TextPushOffset.X, pushButton.TextPushOffset.Y));
            }

            if (pushButton.Glyph != PushButtonGlyph.None)
            {
                drawingContext.DrawGeometry(_glyphBrush, _glyphPen, _glyphPath);
            }
            pushButton.TextFormat.RenderText(drawingContext, _textBrush, pushButton.Text, _imageRect);

            if (pushButton.Pushed)
            {
                drawingContext.Pop();
            }
        }
 protected override void Draw(DrawingContext dc, int Zoom)
 {
     Point elementPoint = Projector.Project(Position, Zoom);
     dc.PushTransform(new TranslateTransform(elementPoint.X, elementPoint.Y));
     DrawPointElement(dc, Zoom);
     dc.Pop();
 }
Exemple #20
0
        public void Draw(LayerModel layer, DrawingContext c)
        {
            // If an animation is present, let it handle the drawing
            if (layer.LayerAnimation != null && !(layer.LayerAnimation is NoneAnimation))
            {
                layer.LayerAnimation.Draw(layer.Properties, layer.AppliedProperties, c);
                return;
            }

            // Otherwise draw the rectangle with its layer.AppliedProperties dimensions and brush
            var rect = layer.Properties.Contain
                ? new Rect(layer.AppliedProperties.X*4,
                    layer.AppliedProperties.Y*4,
                    layer.AppliedProperties.Width*4,
                    layer.AppliedProperties.Height*4)
                : new Rect(layer.Properties.X*4,
                    layer.Properties.Y*4,
                    layer.Properties.Width*4,
                    layer.Properties.Height*4);

            var clip = new Rect(layer.AppliedProperties.X*4, layer.AppliedProperties.Y*4,
                layer.AppliedProperties.Width*4, layer.AppliedProperties.Height*4);


            c.PushClip(new RectangleGeometry(clip));
            c.DrawRectangle(layer.AppliedProperties.Brush, null, rect);
            c.Pop();
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            var fe = AdornedElement as FrameworkElement;
            if (fe == null)
            {
                return;
            }

            var rect = new Rect(1, 1, Math.Max(0, fe.ActualWidth - 2), Math.Max(0, fe.ActualHeight - 2));
            var color = Colors.Red;
            var brush = new SolidColorBrush(color);
            var pen = new Pen(brush, 1);
            pen.Freeze();

            var dashPen = new Pen(brush, 1) { DashStyle = new DashStyle(new double[] { 1, 6 }, 0) };
            dashPen.Freeze();

            var guidelineSet = new GuidelineSet();
            guidelineSet.GuidelinesX.Add(0.5);
            guidelineSet.GuidelinesY.Add(0.5);

            //var outlinePen = new Pen(new SolidColorBrush(Color.FromArgb(0x70, 0xFF, 0xFF, 0xFF)), 5);
            //outlinePen.Freeze();

            drawingContext.PushGuidelineSet(guidelineSet);

            //drawingContext.DrawRectangle(null, outlinePen, rect);
            drawingContext.DrawRectangle(null, pen, rect);

            //var parent = VisualTreeHelper.GetParent(fe) as FrameworkElement;
            //if (parent != null)
            //{
            //    var thisLeft = new Point(0, fe.ActualHeight / 2);
            //    var thisRight = new Point(fe.ActualWidth, fe.ActualHeight / 2);
            //    var thisTop = new Point(fe.ActualWidth / 2, 0);
            //    var thisBottom = new Point(fe.ActualWidth / 2, fe.ActualHeight);
            //    var ancestorLeft = new Point(parent.TranslatePoint(thisLeft, fe).X, thisLeft.Y);
            //    var ancestorRight = ancestorLeft + new Vector(parent.ActualWidth, 0);
            //    var ancestorTop = new Point(thisTop.X, parent.TranslatePoint(new Point(), fe).Y);
            //    var ancestorBottom = new Point(thisBottom.X, parent.TranslatePoint(new Point(), fe).Y + parent.ActualHeight);

            //    var leftPen = fe.HorizontalAlignment == HorizontalAlignment.Left || fe.HorizontalAlignment == HorizontalAlignment.Stretch ? pen : dashPen;
            //    var rightPen = fe.HorizontalAlignment == HorizontalAlignment.Right || fe.HorizontalAlignment == HorizontalAlignment.Stretch ? pen : dashPen;
            //    var topPen = fe.VerticalAlignment == VerticalAlignment.Top || fe.VerticalAlignment == VerticalAlignment.Stretch ? pen : dashPen;
            //    var bottomPen = fe.VerticalAlignment == VerticalAlignment.Bottom || fe.VerticalAlignment == VerticalAlignment.Stretch ? pen : dashPen;

            //    drawingContext.DrawLine(leftPen, thisLeft, ancestorLeft);
            //    drawingContext.DrawLine(rightPen, thisRight, ancestorRight);
            //    drawingContext.DrawLine(topPen, thisTop, ancestorTop);
            //    drawingContext.DrawLine(bottomPen, thisBottom, ancestorBottom);
            //}

            var formattedHeight = new FormattedText(string.Format("{0:0}", fe.ActualHeight), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, TypeFace, 10, brush);
            var formattedWidth = new FormattedText(string.Format("{0:0}", fe.ActualWidth), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, TypeFace, 10, brush);
            drawingContext.DrawText(formattedHeight, new Point(rect.Width + 5, (rect.Height / 2) - (formattedHeight.Height / 2)));
            drawingContext.DrawText(formattedWidth, new Point(rect.Width / 2 - formattedWidth.Width / 2, rect.Height + 5));

            drawingContext.Pop();
        }
        protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
        {
            // Clip to rounded rectangle shape.
            dc.PushClip(new RectangleGeometry(new Rect(new Size(width, height)), Roundness, Roundness));

            // Draw image.
            dc.PushTransform(new TranslateTransform(BorderWidth, BorderWidth));
            dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
            dc.Pop();

            dc.Pop();

            // Draw border.
            dc.DrawRoundedRectangle(null, new Pen(new SolidColorBrush(BorderColor.ToWpfColor()), BorderWidth),
                new Rect(BorderWidth / 2.0, BorderWidth / 2.0, width - BorderWidth, height - BorderWidth),
                Roundness, Roundness);
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (this.textBoxHasSelection)
            {
                // up button
                drawingContext.PushTransform(new TranslateTransform(this.x, this.top));
                drawingContext.PushTransform(new ScaleTransform(1, -1));
                drawingContext.DrawGeometry(TextBoxUpDownAdorner.Fill, TextBoxUpDownAdorner.Outline, this.triangle);
                drawingContext.Pop();
                drawingContext.Pop();

                // down button
                drawingContext.PushTransform(new TranslateTransform(this.x, this.bottom));
                drawingContext.DrawGeometry(TextBoxUpDownAdorner.Fill, TextBoxUpDownAdorner.Outline, this.triangle);
                drawingContext.Pop();
            }
        }
Exemple #24
0
		public void Render(DrawingContext dc, Point location, Brush tint, int tileIndex)
		{
			var dstRect = new Rect(location, new Size(TileWidth, TileHeight));

			dc.PushOpacityMask(new ImageBrush(_tiles[tileIndex]));
			dc.DrawRectangle(tint, null, dstRect);

			dc.Pop();
		}
		public void Render(DrawingContext drawingContext)
		{
			if (IsVisible)
			{
				drawingContext.PushClip(_clipGeometry);
				drawingContext.DrawGeometry(null, PainterCache.GridLinePen, _geometry);
				drawingContext.Pop();
			}
		}
        protected override void OnRender(DrawingContext drawingContext)
        {
            // draw everything except the reflection
            base.OnRender(drawingContext);

            // set opacity
            drawingContext.PushOpacityMask(_opacityMask);
            drawingContext.PushOpacity(0.4);

            // set reflection parameters based on content size
            _reflection.Visual = Child;

            // draw the reflection
            drawingContext.DrawRectangle(_reflection, null, new Rect(0, ActualHeight + _gap, ActualWidth, ActualHeight));

            // cleanup
            drawingContext.Pop();
            drawingContext.Pop();
        }
Exemple #27
0
        protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
        {
            // Draw border.
            dc.DrawRectangle(Fill.GetBrush(), null, new Rect(0, 0, width, height));

            // Draw image.
            dc.PushTransform(new TranslateTransform(Width, Width));
            dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
            dc.Pop();
        }
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            double textMaxWidth = 0;
            double textX        = ActualWidth;

            switch (TextAlignment)
            {
            case TextAlignment.Left:
                textX = 0;
                break;

            case TextAlignment.Center:
                textX = ActualWidth / 2;
                break;

            case TextAlignment.Right:
                textX = ActualWidth;
                break;
            }

            if (TickRenderMode == TickRenderMode.Text || TickRenderMode == TickRenderMode.Both)
            {
                foreach (double value in Ticks)
                {
                    double y = CalculateY(value);

                    FormattedText text = new FormattedText(value.ToString(), CultureInfo.CurrentUICulture,
                                                           FlowDirection.LeftToRight, new Typeface("Tahoma"), 8.0d, Fill, _pixelsPerDip)
                    {
                        TextAlignment = TextAlignment
                    };
                    drawingContext.DrawText(text, new Point(textX, y - text.Height / 2));
                    textMaxWidth = Math.Max(textMaxWidth, text.Width);
                }

                textMaxWidth += 3;
            }

            if (TickRenderMode == TickRenderMode.Tick || TickRenderMode == TickRenderMode.Both)
            {
                Pen pen = new Pen(Fill, 1.0d);

                GuidelineSet guidelineSet = new GuidelineSet();
                drawingContext.PushGuidelineSet(guidelineSet);

                foreach (double value in Ticks)
                {
                    double y = CalculateY(value) + 1;
                    drawingContext.DrawLine(pen, new Point(0, y), new Point(ActualWidth - textMaxWidth, y));
                    guidelineSet.GuidelinesY.Add(y - 0.5);
                }

                drawingContext.Pop();
            }
        }
Exemple #29
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (AdornedElement.RenderSize.Width < 20) return;

            var transform = new TranslateTransform(AdornedElement.RenderSize.Width - 15, (AdornedElement.RenderSize.Height - 5) / 2);
            drawingContext.PushTransform(transform);

            Geometry geometry = (this.Direction == ListSortDirection.Descending ? descGeometry : ascGeometry);
            drawingContext.DrawGeometry(Brushes.Black, null, geometry);
            drawingContext.Pop();
        }
Exemple #30
0
        public void Render(DrawingContext dc, Size renderSize, TileRenderContext ctx)
        {
            dc.DrawRectangle(Brushes.Black, null, new Rect(0, 0, renderSize.Width, renderSize.Height));

            dc.PushTransform(new TranslateTransform(ctx.RenderOffset.X, ctx.RenderOffset.Y));
            dc.PushTransform(new ScaleTransform(ctx.TileSize, ctx.TileSize));

            for (int y = 0; y < ctx.RenderGridSize.Height && y < m_renderData.Height; ++y)
            {
                for (int x = 0; x < ctx.RenderGridSize.Width && x < m_renderData.Width; ++x)
                {
                    dc.PushTransform(new TranslateTransform(x, y));
                    RenderTile(dc, x, y);
                    dc.Pop();
                }
            }

            dc.Pop();
            dc.Pop();
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            Point povCenter = new Point(ActualHeight / 2d, ActualWidth / 2d);

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

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

            if (rotary != null)
            {
                drawingContext.PushTransform(new RotateTransform(rotary.KnobRotation, _center.X, _center.Y));
                drawingContext.DrawImage(_image, _imageRect);
                drawingContext.Pop();
            }
        }
Exemple #33
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            TransformGroup transform = new TransformGroup();

            transform.Children.Add(new TranslateTransform((-_center.X + HorizontalOffset) * _xScale, (-_center.Y + VerticalOffset) * _yScale));
            transform.Children.Add(new RotateTransform(_rotation + _baseRotation));
            transform.Children.Add(new TranslateTransform(_location.X * _xScale, _location.Y * _yScale));

            drawingContext.PushTransform(transform);
            drawingContext.DrawImage(_image, _rectangle);
            drawingContext.Pop();
        }
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            Metric metric = Visual as Metric;

            if (metric != null)
            {
                drawingContext.PushTransform(new TranslateTransform(metric.MetricTranslationX, metric.MetricTranslationY));
                drawingContext.PushTransform(new RotateTransform(metric.MetricRotation, _center.X, _center.Y - metric.MetricTranslationY));
                drawingContext.DrawImage(_image, _imageRect);
                drawingContext.Pop( );
            }
        }
Exemple #35
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            double x = AdornedElement.RenderSize.Width - 20;
            double y = (AdornedElement.RenderSize.Height - 5) / 2;

            if (x >= 20)
            {
                // Right order of the statements is important
                drawingContext.PushTransform(new TranslateTransform(x, y));
                drawingContext.DrawGeometry(Brushes.Black, null, _sortDirection);
                drawingContext.Pop();
            }
        }
Exemple #36
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            double x = AdornedElement.RenderSize.Width - 12;
            double y = (AdornedElement.RenderSize.Height - 8) / 2;

            if (x >= 10)
            {
                // Right order of the statements is important
                drawingContext.PushTransform(new TranslateTransform(x, y));
                drawingContext.DrawGeometry(brush, pen, direction);
                drawingContext.Pop();
            }
        }
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            if (_bitmap != null)
            {
                var bitmapSize         = new Vector(_bitmap.Width, _bitmap.Height);
                var dpiScaleToWpfScale = CurrentHwndSource.CompositionTarget.TransformFromDevice;
                var adjustedBitmapSize = dpiScaleToWpfScale.Transform(bitmapSize);

                drawingContext.PushClip(new RectangleGeometry(new Rect(RenderSize)));
                drawingContext.DrawImage(_bitmap, new Rect(new Size(adjustedBitmapSize.X, adjustedBitmapSize.Y)));
                drawingContext.Pop();
            }
        }
Exemple #38
0
        private void DrawText(System.Windows.Media.DrawingContext dc)
        {
            dc.PushClip(new RectangleGeometry(new Rect(10, 0, Width - 20, Height)));

            for (int lineNumber = StartLine; lineNumber < Lines.Count && lineNumber <= StartLine + Height / LineHeight; lineNumber++)
            {
                double Y = (lineNumber - StartLine) * LineHeight + 2;
                if (lineNumber == CursorLine)
                {
                    dc.DrawRectangle(BackCursorBrush, null, new Rect(0, Y, Width, LineHeight));
                }
                DrawTextUsingString(dc, lineNumber, Y);
            }
            dc.Pop();
        }
Exemple #39
0
        protected void RenderTiles(System.Windows.Media.DrawingContext dc)
        {
            double opacityIncrement = 1.0f / Layers.Count;
            double opacity          = opacityIncrement;

            foreach (Layer layer in Layers)
            {
                dc.PushOpacity(opacity);
                foreach (Sprite sprite in layer.Tiles)
                {
                    dc.DrawImage(sprite.ImageSource, sprite.Rect);
                }
                dc.Pop();
                opacity += opacityIncrement;
            }
        }
Exemple #40
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            if (this.pen == null)
            {
                pen = new Pen(Foreground, Thickness)
                {
                    StartLineCap = PenLineCap.Round,
                    EndLineCap   = PenLineCap.Round
                };

                previousForeground = Foreground;
                previousThickness  = Thickness;

                penHalfThickness = pen.Thickness / 2.0;
            }
            else
            {
                if (Foreground != previousForeground || Thickness != previousThickness)
                {
                    previousForeground = Foreground;
                    previousThickness  = Thickness;
                    pen.Brush          = Foreground;
                    pen.Thickness      = Thickness;

                    penHalfThickness = pen.Thickness / 2.0;
                }
            }

            rect.X      = 0.0;
            rect.Y      = 0.0;
            rect.Width  = this.ActualWidth;
            rect.Height = this.ActualHeight;

            GuidelineSet g = new GuidelineSet();

            g.GuidelinesX.Add(rect.Left + penHalfThickness);
            g.GuidelinesX.Add(rect.Right + penHalfThickness);
            g.GuidelinesY.Add(rect.Top + penHalfThickness);
            g.GuidelinesY.Add(rect.Bottom + penHalfThickness);
            drawingContext.PushGuidelineSet(g);
            drawingContext.DrawRectangle(Background, pen, rect);
            drawingContext.Pop();

            //drawingContext.DrawRectangle(Background, pen, rect);
        }
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            _scopeBrush = new SolidColorBrush(Color.FromRgb(255, 0, 0));
            Pen _scopePen = new Pen(_scopeBrush, 1d);


            CustomNeedle customNeedle = Visual as CustomNeedle;

            if (customNeedle != null)
            {
                drawingContext.DrawImage(_bgplate_image, _bgplate_imageRect);

                drawingContext.PushTransform(new RotateTransform(customNeedle.KnobRotation, _center.X, _center.Y));
                drawingContext.DrawImage(_image, _imageRect);
                drawingContext.DrawLine(_scopePen, _center, _punto); //draw rotation point for reference
                drawingContext.Pop();
            }
        }
 protected override void DrawCore(System.Windows.Media.DrawingContext context, DrawingAttributes overrides)
 {
     // create a drop shadow
     //
     if (this.Shadowed)
     {
         Geometry pathGeometry = this.GetGeometry(overrides).Clone();
         pathGeometry.Transform = new TranslateTransform(5, 0);
         try
         {
             context.PushOpacity(0.5);
             context.DrawGeometry(Brushes.DarkGray, null, pathGeometry);
         }
         finally
         {
             context.Pop();
         }
     }
     base.DrawCore(context, overrides);
 }
Exemple #43
0
        public void DrawLine(Pen p, Point startPoint, Point endPoint)
        {
#if !GRID_GUIDELINE
            double halfPenWidth = p.Thickness / 2;

            // Create a guidelines set
            System.Windows.Media.GuidelineSet guidelines = new System.Windows.Media.GuidelineSet();

            guidelines.GuidelinesX.Add(startPoint.X + halfPenWidth);
            guidelines.GuidelinesY.Add(startPoint.Y + halfPenWidth);

            g.PushGuidelineSet(guidelines);
#endif // GRID_GUIDELINE

            g.DrawLine(p, (System.Windows.Point)startPoint, (System.Windows.Point)endPoint);

#if !GRID_GUIDELINE
            g.Pop();
#endif // GRID_GUIDELINE
        }
Exemple #44
0
        ImageSource RenderFrame(ApplicationContext actx, double scaleFactor, ImageDescription idesc)
        {
            SWM.DrawingVisual visual = new SWM.DrawingVisual();
            using (SWM.DrawingContext ctx = visual.RenderOpen()) {
                ctx.PushTransform(new ScaleTransform(scaleFactor, scaleFactor));
                Draw(actx, ctx, scaleFactor, 0, 0, idesc);
                ctx.Pop();
            }

            SWMI.RenderTargetBitmap bmp = new SWMI.RenderTargetBitmap((int)(idesc.Size.Width * scaleFactor), (int)(idesc.Size.Height * scaleFactor), 96, 96, PixelFormats.Pbgra32);
            bmp.Render(visual);

            var f = new ImageFrame(bmp, idesc.Size.Width, idesc.Size.Height);

            if (drawCallback == null)
            {
                AddFrame(f);
            }
            return(bmp);
        }
Exemple #45
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            RotaryKnob rotary = Visual as RotaryKnob;

            if (rotary != null)
            {
                drawingContext.PushTransform(new RotateTransform(rotary.KnobRotation, _center.X, _center.Y));
                drawingContext.DrawImage(_image, _imageRect);
                if (rotary.VisualizeDragging)
                {
                    double length = (rotary.DragPoint - _center).Length;
                    drawingContext.DrawLine(HeadingPen, _center, _center + new Vector(0d, -length));
                }
                drawingContext.Pop();

                if (rotary.VisualizeDragging)
                {
                    drawingContext.DrawLine(DragPen, _center, rotary.DragPoint);
                }
            }
        }
        ImageSource RenderFrame(ApplicationContext actx, double scaleFactor, double width, double height)
        {
            ImageDescription idesc = new ImageDescription()
            {
                Alpha = 1,
                Size  = new Size(width, height)
            };

            SWM.DrawingVisual visual = new SWM.DrawingVisual();
            using (SWM.DrawingContext ctx = visual.RenderOpen()) {
                ctx.PushTransform(new ScaleTransform(scaleFactor, scaleFactor));
                Draw(actx, ctx, scaleFactor, 0, 0, idesc);
                ctx.Pop();
            }

            SWMI.RenderTargetBitmap bmp = new SWMI.RenderTargetBitmap((int)(width * scaleFactor), (int)(height * scaleFactor), 96, 96, PixelFormats.Pbgra32);
            bmp.Render(visual);

            var f = new ImageFrame(bmp, width, height);

            AddFrame(f);
            return(bmp);
        }
Exemple #47
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();
                }
            }
        }
Exemple #48
0
        public void Restore()
        {
            if (pushes.Count == 0)
            {
                return;
            }

            for (int n = 0; n < pushCount; n++)
            {
                Context.Pop();
            }

            var cd = pushes.Pop();

            pushCount = cd.PushCount;

            while (transforms.Children.Count > cd.TransformCount)
            {
                transforms.Children.RemoveAt(transforms.Children.Count - 1);
            }

            AllocatePen(cd.CurrentColor, cd.Thickness, cd.DashStyle);
            patternBrush = cd.Pattern;
        }
Exemple #49
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            drawingContext.PushTransform(new ScaleTransform(_scaleX, _scaleY));

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

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

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

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

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

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

                            DrawContactSymbol(drawingContext, contact, primary);

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

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

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

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

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

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

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

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


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

            RenderElapsedTime = renderStopwatch.Elapsed.TotalSeconds;
            renderStopwatch.Restart();
        }
Exemple #51
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            double actualWidth  = ActualWidth;
            double actualHeight = ActualHeight;

            // draw background
            drawingContext.DrawRectangle(Background, null, new Rect(0, 0, actualWidth, actualHeight));

            Interval viewportInterval        = VirtualViewportInterval;
            double   scale                   = actualWidth / viewportInterval.Length;
            long     ticks                   = FindTicks(viewportInterval.Length, (int)(Math.Round(actualWidth / 20)));
            Interval viewportIntervalAligned = new Interval(
                viewportInterval.From - (viewportInterval.From % ticks),
                viewportInterval.To + (viewportInterval.To % ticks));
            double drawingOffset = (viewportIntervalAligned.From - viewportInterval.From) * scale;

            GuidelineSet guidelineSet = new GuidelineSet();

            drawingContext.PushGuidelineSet(guidelineSet);

            // draw interval start, length & end time
            FormattedText formattedStartText = new FormattedText(
                new TimeSpan(viewportInterval.From).ToString(SCALE_TEXT_FORMAT),
                CultureInfo.CurrentUICulture, System.Windows.FlowDirection.LeftToRight,
                new Typeface("Tahoma"), SCALE_FONT_SIZE, IntervalTextColor)
            {
                TextAlignment = TextAlignment.Left
            };

            drawingContext.DrawText(formattedStartText, new Point(1, 0));
            FormattedText formattedLengthText = new FormattedText(
                new TimeSpan(viewportInterval.Length).ToString(SCALE_TEXT_FORMAT),
                CultureInfo.CurrentUICulture, System.Windows.FlowDirection.LeftToRight,
                new Typeface("Tahoma"), SCALE_FONT_SIZE, IntervalTextColor)
            {
                TextAlignment = TextAlignment.Center
            };

            drawingContext.DrawText(formattedLengthText, new Point(actualWidth / 2, 0));
            FormattedText formattedEndText = new FormattedText(
                new TimeSpan(viewportInterval.To).ToString(SCALE_TEXT_FORMAT),
                CultureInfo.CurrentUICulture, System.Windows.FlowDirection.LeftToRight,
                new Typeface("Tahoma"), SCALE_FONT_SIZE, IntervalTextColor)
            {
                TextAlignment = TextAlignment.Right
            };

            drawingContext.DrawText(formattedEndText, new Point(actualWidth - 1, 0));

            // draw markers and time
            int  timeDrawingRate = 5;
            long markerCount     = (viewportIntervalAligned.From / ticks) % timeDrawingRate;

            for (long i = 0; i < viewportIntervalAligned.Length; i += ticks)
            {
                double markerHeight = actualHeight - (SCALE_HEIGHT / 2 * 1.5);
                double x            = i * scale + drawingOffset;

                // draw time
                if (markerCount++ % timeDrawingRate == 0)
                {
                    markerHeight = actualHeight - SCALE_HEIGHT;
                    FormattedText formattedText = new FormattedText(
                        new TimeSpan(viewportIntervalAligned.From + i).ToString(SCALE_TEXT_FORMAT),
                        CultureInfo.CurrentUICulture, System.Windows.FlowDirection.LeftToRight,
                        new Typeface("Tahoma"), SCALE_FONT_SIZE, Foreground)
                    {
                        TextAlignment = TextAlignment.Center
                    };
                    drawingContext.DrawText(formattedText, new Point(x, actualHeight - SCALE_HEIGHT - SCALE_FONT_SIZE * 1.2));
                }

                // draw marker
                guidelineSet.GuidelinesX.Add(x + 0.5);
                drawingContext.DrawLine(new Pen(Foreground, 1),
                                        new Point(x, markerHeight), new Point(x, actualHeight));
            }

            // draw markers' bottom line
            //guidelineSet.GuidelinesY.Add(actualHeight - 0.5);
            //drawingContext.DrawLine(new Pen(Foreground, 1),
            //            new Point(0, actualHeight - 1), new Point(actualWidth, actualHeight - 1));

            drawingContext.Pop();
        }
Exemple #52
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            if (_editor.SelectedItems.Count > 0)
            {
                Pen   rectPen     = _drawFocus ? SelectionRectPen : SelectionRectPenNoFocus;
                Brush circleBrush = _drawFocus ? SelectionResizeBrush : SelectionResizeBrushNoFocus;

                if (_isline)
                {
                    Point start;
                    Point end;

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

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

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

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

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

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

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

                    drawingContext.DrawRectangle(null, rectPen, selectionRect);

                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.TopLeft, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.TopRight, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.BottomLeft, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.BottomRight, ResizeRadius, ResizeRadius);
                }
            }
        }
Exemple #53
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            if (group == null)
            {
                return;
            }

            Rect area = new Rect(0, 0, AdornedElement.RenderSize.Width, AdornedElement.RenderSize.Height);

            drawingContext.PushClip(new RectangleGeometry(area));

            drawingContext.DrawRectangle(Brushes.White, null, area);

            var threads = group.Threads;

            int rowIndex = 0;

            KeyValuePair <int, int> mainThreadInterval = new KeyValuePair <int, int>();

            for (int threadIndex = 0; threadIndex < threads.Count; ++threadIndex)
            {
                List <EventFrame> frames   = threads[threadIndex].Events;
                RowRange          rowRange = rows[threadIndex];

                if (rowRange.MaxDepth > 0 && frames.Count > 0)
                {
                    KeyValuePair <int, int> interval = CalculateEventRange(frames, Position, Position + Range);
                    if (threadIndex == group.Board.MainThreadIndex)
                    {
                        mainThreadInterval = interval;
                    }

                    Brush backgroundBrush = Brushes.White;

                    if (rowIndex++ % 2 == 0)
                    {
                        backgroundBrush = AlternativeBackgroundColor;
                        drawingContext.DrawRectangle(AlternativeBackgroundColor, null, new Rect(0, rowRange.Offset, AdornedElement.RenderSize.Width, rowRange.Height));
                    }

                    for (int i = interval.Key; i <= interval.Value; ++i)
                    {
                        OnRenderFrame(drawingContext, frames[i], rowRange.Offset, rowRange.MaxDepth, backgroundBrush);
                    }
                }
            }

            int mainThreadIndex = group.Board.MainThreadIndex;

            RenderFPSLines(drawingContext, group.Threads[mainThreadIndex].Events, mainThreadInterval);

            if (FocusedFrame != null)
            {
                RowRange rowRange = rows[FocusedFrame.Header.ThreadIndex];

                Durable interval = FocusedNode != null ? FocusedNode.Entry as Durable : FocusedFrame.Header as Durable;

                Rect focusedRectangle = CalculateRect(interval, rowRange.Offset, rowRange.Height);
                drawingContext.DrawRectangle(null, selectedPen, focusedRectangle);
            }

            RenderSelectedScopes(drawingContext);

            drawingContext.Pop();

            base.OnRender(drawingContext);
        }
Exemple #54
0
        /// <summary>
        /// Draws the contours against a horizontal and vertical axis.
        /// </summary>
        /// <param name="dc">The drawing context on which to draw.</param>
        /// <param name="hAxis">The horizontal physical axis to draw against.</param>
        /// <param name="vAxis">The vertical physical axis to draw against.</param>
        public void Draw(System.Windows.Media.DrawingContext dc, HorizontalPhysicalAxis hAxis, VerticalPhysicalAxis vAxis)
        {
            double worldHorizontalRange = hAxis.Axis.WorldMax - hAxis.Axis.WorldMin;
            double worldVerticalRange   = vAxis.Axis.WorldMax - vAxis.Axis.WorldMin;

            for (int i = 0; i < _internalGridSize.Rows; ++i)
            {
                for (int j = 0; j < _internalGridSize.Columns; ++j)
                {
                    double worldY = (double)i / (double)(_internalGridSize.Rows - 1) * worldVerticalRange + vAxis.Axis.WorldMin;
                    double worldX = (double)j / (double)(_internalGridSize.Columns - 1) * worldHorizontalRange + hAxis.Axis.WorldMin;
                    _grid[i, j] = _fieldMethod(worldX, worldY);
                }
            }

            Pair <List <double>, List <List <LineSegment> > > contourGroups = ContourUtils.ContourGenCore.Generate(_grid, _levels);

            double physicalHorizontalRange = hAxis.PhysicalMaxX - hAxis.PhysicalMinX;
            double physicalVerticalRange   = vAxis.PhysicalMaxY - vAxis.PhysicalMinY;

            Pen p = new Pen(_stroke, _strokeThickness);

            for (int i = 0; i < contourGroups.First.Count; ++i)
            {
                List <LineSegment> lineSegments = contourGroups.Second[i];

                // find best index to put label.
                int bestJ = DetermineBestLabelPosition(lineSegments, 0, _internalGridSize.Columns - 1, 0, _internalGridSize.Rows - 1);

                // see if line segment sequence is reasonably long. If so, put a contour label on it.
                bool drawingLabel = false;
                if (_showContourLabels)
                {
                    double sum = 0.0;
                    for (int k = 0; k < lineSegments.Count; ++k)
                    {
                        sum += Math.Abs(lineSegments[k].X1 - lineSegments[k].X2) + Math.Abs(lineSegments[k].Y1 - lineSegments[k].Y2);
                        if (sum > _internalGridSize.Rows / 6.0)
                        {
                            drawingLabel = true;
                            break;
                        }
                    }
                }

                if (drawingLabel)
                {
                    LineSegment ls = lineSegments[bestJ];

                    double x1 = ls.X1 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double x2 = ls.X2 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double y1 = ls.Y1 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;
                    double y2 = ls.Y2 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;

                    FormattedText ft = new FormattedText(contourGroups.First[i].ToString(_contourLabelFormat),
                                                         System.Globalization.CultureInfo.CurrentCulture,
                                                         FlowDirection.LeftToRight, new Typeface("Arial"), 11, _stroke);

                    double angle = Math.Atan2(
                        contourGroups.Second[i][bestJ].Y1 - contourGroups.Second[i][bestJ].Y2,
                        contourGroups.Second[i][bestJ].X2 - contourGroups.Second[i][bestJ].X1) / Math.PI * 180.0;

                    if (angle > 90)
                    {
                        angle -= 180;
                    }
                    if (angle < -90)
                    {
                        angle += 180;
                    }

                    RotateTransform rt = new RotateTransform(angle);

                    dc.PushTransform(new TranslateTransform((x1 + x2) / 2.0, (y1 + y2) / 2.0));
                    dc.PushTransform(rt);
                    dc.DrawText(ft, new Point(-ft.Width / 2.0, -ft.Height / 2.0));
                    dc.Pop();
                    dc.Pop();

                    Rect r1 = new Rect(hAxis.PhysicalMinX, vAxis.PhysicalMaxY, hAxis.PhysicalMaxX - hAxis.PhysicalMinX, vAxis.PhysicalMinY - vAxis.PhysicalMaxY);
                    Rect r2 = new Rect((x1 + x2) / 2.0 - ft.Width * 1.6 / 2.0, (y1 + y2) / 2.0 - ft.Height * 1.6 / 2.0, ft.Width * 1.6, ft.Height * 1.6);

                    DrawingBrush db = new DrawingBrush();
                    db.ViewboxUnits  = BrushMappingMode.Absolute;
                    db.ViewportUnits = BrushMappingMode.Absolute;
                    db.Viewport      = r1;
                    db.Viewbox       = r1;

                    GeometryGroup gg = new GeometryGroup();
                    gg.FillRule = FillRule.Nonzero;

                    if (r2.Left - r1.Left > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r1.Left, r1.Top, r2.Left - r1.Left, r1.Height));
                        gg.Children.Add(rg);
                    }
                    if (r1.Right - r2.Right > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r2.Right, r1.Top, r1.Right - r2.Right, r1.Height));
                        gg.Children.Add(rg);
                    }
                    if (r2.Top - r1.Top > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r1.Left, r1.Top, r1.Width, r2.Top - r1.Top));
                        gg.Children.Add(rg);
                    }
                    if (r1.Bottom - r2.Bottom > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r1.Left, r2.Bottom, r1.Width, r1.Bottom - r2.Bottom));
                        gg.Children.Add(rg);
                    }

                    SolidColorBrush scb = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                    GeometryDrawing gd  = new GeometryDrawing(scb, null, gg);
                    db.Drawing = gd;

                    dc.PushOpacityMask(db);
                }

                for (int j = 0; j < lineSegments.Count; ++j)
                {
                    LineSegment ls = lineSegments[j];

                    double x1 = ls.X1 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double x2 = ls.X2 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double y1 = ls.Y1 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;
                    double y2 = ls.Y2 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;

                    dc.DrawLine(p, new Point(x1, y1), new Point(x2, y2));
                }

                if (drawingLabel)
                {
                    // pop opacity mask.
                    dc.Pop();
                }
            }
        }