コード例 #1
0
        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();
        }
コード例 #2
0
ファイル: DrawableHandler.cs プロジェクト: modulexcite/Eto-1
            protected override void OnRender(swm.DrawingContext dc)
            {
                var rect     = new sw.Rect(Child.Bounds.X, Child.Bounds.Y, Child.Bounds.Width + 0.5, Child.Bounds.Height + 0.5);
                var graphics = new Graphics(Handler.Widget.Generator, new GraphicsHandler(this, dc, rect));

                dc.PushGuidelineSet(new swm.GuidelineSet(new double[] { Child.Bounds.Left, Child.Bounds.Right }, new double[] { Child.Bounds.Top, Child.Bounds.Bottom }));
                Handler.Widget.OnPaint(new PaintEventArgs(graphics, Generator.Convert(Child.Bounds)));
            }
コード例 #3
0
 protected override void Draw(DrawingContext dc, int RenderZoom)
 {
     EarthPoint topLeftPoint = OsmIndexes.GetTopLeftPoint(HorizontalIndex, VerticalIndex, RenderZoom);
     Point topLeftPointScreenProjection = Projector.Project(topLeftPoint, RenderZoom);
     dc.PushGuidelineSet(ScreenGuidelineSet);
     var tileRect = new Rect(topLeftPointScreenProjection, new Size(256, 256));
     DrawTile(dc, tileRect);
     //dc.DrawRectangle(null, new Pen(Brushes.Gray, 2), tileRect);
 }
コード例 #4
0
        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)
                    {
                        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();
            }
        }
コード例 #5
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     base.OnRender(drawingContext);
     Pen pen = new Pen(LineBrush, 1);
     GuidelineSet gs = new GuidelineSet();
     gs.GuidelinesX.Clear();
     gs.GuidelinesY.Clear();
     gs.GuidelinesY.Add(_lastPoint.Y - 0.5);
     gs.GuidelinesY.Add(_lastPoint.Y + 0.5);
     drawingContext.PushGuidelineSet(gs.Clone());
     drawingContext.DrawLine(pen, new Point(0, _lastPoint.Y), new Point(ActualWidth, _lastPoint.Y));
     drawingContext.PushGuidelineSet(gs.Clone());
     gs.GuidelinesX.Clear();
     gs.GuidelinesY.Clear();
     gs.GuidelinesX.Add(_lastPoint.X - 0.5);
     gs.GuidelinesX.Add(_lastPoint.X + 0.5);
     drawingContext.PushGuidelineSet(gs.Clone());
     drawingContext.DrawLine(pen, new Point(_lastPoint.X, 0), new Point(_lastPoint.X, ActualHeight));
     drawingContext.PushGuidelineSet(gs.Clone());
 }
コード例 #6
0
ファイル: RubberBandAdorner.cs プロジェクト: SuperJMN/Glass
        protected override void OnRender(DrawingContext drawingContext)
        {
            var rect = new Rect(startPoint, currentPoint);
            if (SurpassesThreshold(rect) && isDragging)
            {
                const double thickness = 1.0;
                const double thicknessOffset = thickness / 2;

                drawingContext.PushGuidelineSet(new GuidelineSet(new[] { startPoint.X - thicknessOffset, currentPoint.X - thicknessOffset }, new[] { startPoint.Y - thicknessOffset, currentPoint.Y - thicknessOffset }));
                drawingContext.DrawGeometry(brush, new Pen(SystemColors.HighlightBrush, thickness), new RectangleGeometry(rect));
            }

            base.OnRender(drawingContext);
        }
コード例 #7
0
ファイル: Timeline.cs プロジェクト: Clearic/MyToDoList
        protected override void OnRender(DrawingContext drawingContext)
        {
            Pen pen = new Pen(Brushes.Gray, 1);
            Pen penDash = new Pen(Brushes.Silver, 1) { DashStyle = DashStyles.Dash };
            Rect rect = new Rect(20, 20, 50, 60);

            double halfPenWidth = pen.Thickness / 2;

            TimeSpan StartTime = TimeSpan.FromHours(6);
            TimeSpan EndTime = TimeSpan.FromHours(24);

            GuidelineSet guidelines = new GuidelineSet();
            guidelines.GuidelinesX.Add(rect.Left + halfPenWidth);
            guidelines.GuidelinesX.Add(rect.Right + halfPenWidth);
            guidelines.GuidelinesY.Add(rect.Top + halfPenWidth);
            guidelines.GuidelinesY.Add(rect.Bottom + halfPenWidth);

            drawingContext.PushGuidelineSet(guidelines);

            TimeSpan tmpTime = StartTime;
            int drawHours = (int)EndTime.Subtract(StartTime).TotalHours;
            double segmentHeight = this.ActualHeight / drawHours;
            for (int i = 0; i < drawHours; i++)
            {
                int y = (int)(segmentHeight * i);
                drawingContext.DrawLine(pen, new Point(0, y), new Point(this.ActualWidth, y));
                int y2 = (int)(y + segmentHeight / 2);
                drawingContext.DrawLine(penDash, new Point(0, y2), new Point(this.ActualWidth, y2));
                drawingContext.DrawText(new FormattedText(
                    tmpTime.ToString(@"h\:mm"),
                    System.Globalization.CultureInfo.CurrentCulture,
                    FlowDirection.RightToLeft,
                    new Typeface("Segoe UI"),
                    12,
                    Brushes.Black,
                    null,
                    TextFormattingMode.Display),new Point(this.ActualWidth, y));
                tmpTime = tmpTime.Add(TimeSpan.FromHours(1));
            }

            TimeSpan timeNow = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second).Subtract(StartTime);

            double h = segmentHeight * (timeNow.TotalHours);
            drawingContext.DrawLine(new Pen(Brushes.Red, 1), new Point(0, h), new Point(this.ActualWidth, h));

            drawingContext.Pop();
        }
コード例 #8
0
        public GuidelineSetBlock(
            DrawingContext target,
            IEnumerable<double> xGuides = null,
            IEnumerable<double> yGuides = null)
        {
            Debug.Assert(target != null);

            _target = target;

            var guidelines = new GuidelineSet();
            {
                xGuides?.ForEach(g => guidelines.GuidelinesX.Add(g));
                yGuides?.ForEach(g => guidelines.GuidelinesY.Add(g));
            }

            target.PushGuidelineSet(guidelines);
        }
コード例 #9
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);
        }
コード例 #10
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
        }
コード例 #11
0
        //for linescontrol

        public static void DrawColumnLines(this FrameworkElement element, DrawingContext drawingContext, 
            double RowWidth, double xOffset,double offset,Pen pen)
        {
            double halfPenHeight = pen.Thickness / 2;
            Point start = new Point(0, 0);
            Point end = new Point(0, element.RenderSize.Height);
            
            GuidelineSet guidelines = new GuidelineSet();
            //draw column
            var count = Convert.ToInt32(element.RenderSize.Width / RowWidth);
            for (int i = 1; i <= count; i++)
            {
                start.X = xOffset - offset;
                end.X = xOffset - offset;
                guidelines.GuidelinesX = new DoubleCollection(new[] { xOffset - halfPenHeight, xOffset + halfPenHeight });
                drawingContext.PushGuidelineSet(guidelines);
                drawingContext.DrawLine(pen, start, end);
                drawingContext.Pop();
                xOffset += RowWidth;
            }
        }
コード例 #12
0
ファイル: Graphic.cs プロジェクト: NightmareX1337/lfs
       public static void DrawPoint(DrawingContext dc, Point? point,string fromColor, string toColor, double duration, bool isAutoReverse)
       {
           SolidColorBrush scbW = new SolidColorBrush(Colors.Black);
           ColorAnimation myAnimation = new ColorAnimation((Color)ColorConverter.ConvertFromString(fromColor),
                                                           (Color)ColorConverter.ConvertFromString(toColor),
                                                           new Duration(TimeSpan.FromSeconds(duration)));
           myAnimation.AutoReverse = isAutoReverse;
           myAnimation.RepeatBehavior = RepeatBehavior.Forever;
           scbW.BeginAnimation(SolidColorBrush.ColorProperty, myAnimation);
           Pen wpen = new Pen(scbW, 1);
           Rect rectW = new Rect(point.Value.X, point.Value.Y, 0.1, 0.1);
           double halfPenWidth = wpen.Thickness / 2;
           GuidelineSet guidelines = new GuidelineSet();
           guidelines.GuidelinesX.Add(rectW.Left + halfPenWidth);
           guidelines.GuidelinesX.Add(rectW.Right + halfPenWidth);
           guidelines.GuidelinesY.Add(rectW.Top + halfPenWidth);
           guidelines.GuidelinesY.Add(rectW.Bottom + halfPenWidth);
           dc.PushGuidelineSet(guidelines);

           dc.DrawRectangle(null, wpen, rectW);
           dc.Pop();
       }
コード例 #13
0
        public GuidelineSetBlock(
            DrawingContext target,
            Rect rect,
            double rectPenWidth = 0,
            IEnumerable<double> xGuides = null,
            IEnumerable<double> yGuides = null)
        {
            Debug.Assert(target != null);

            _target = target;

            var guidelines = new GuidelineSet();
            {
                guidelines.GuidelinesX.Add(rect.Left + rectPenWidth*0.5);
                guidelines.GuidelinesX.Add(rect.Right + rectPenWidth*0.5);
                guidelines.GuidelinesY.Add(rect.Top + rectPenWidth*0.5);
                guidelines.GuidelinesY.Add(rect.Bottom + rectPenWidth*0.5);

                xGuides?.ForEach(g => guidelines.GuidelinesX.Add(g));
                yGuides?.ForEach(g => guidelines.GuidelinesY.Add(g));
            }

            target.PushGuidelineSet(guidelines);
        }
コード例 #14
0
ファイル: WpfRenderer.cs プロジェクト: Core2D/Core2D
        private static void DrawLineInternal(DrawingContext dc, double half, Pen pen, bool isStroked, ref Point p0, ref Point p1)
        {
            if (!isStroked)
                return;

            var gs = new GuidelineSet(
                new double[] { p0.X + half, p1.X + half },
                new double[] { p0.Y + half, p1.Y + half });
            dc.PushGuidelineSet(gs);
            dc.DrawLine(isStroked ? pen : null, p0, p1);
            dc.Pop();
        }
コード例 #15
0
ファイル: CaretElement.cs プロジェクト: sjyanxin/WPFSource
        /// <summary> 
        /// Performs the actual rendering of the caret on the given context.  Called by
        /// CaretSubElement. 
        /// </summary>
        /// <param name="context">Drawing context</param>
        /// <remarks>This method is on CaretElement instead of CaretSubElement because CaretElement
        /// knows all of the necessary data, and conceptually CaretSubElement only exists to provide 
        /// a rendering surface.</remarks>
        internal void OnRenderCaretSubElement(DrawingContext context) 
        { 
            // [....] up Win32 caret position with Avalon caret position.
            Win32SetCaretPos(); 

            if (_showCaret)
            {
                TextEditorThreadLocalStore threadLocalStore = TextEditor._ThreadLocalStore; 

                Invariant.Assert(!(_italic && this.IsInInterimState), "Assert !(_italic && IsInInterimState)"); 
 
                // Drawing context's pushed count to pop it up
                int contextPushedCount = 0; 

                // Apply internally requested opacity.
                context.PushOpacity(_opacity);
                contextPushedCount++; 

                // Apply italic transformation 
                if (_italic && !(threadLocalStore.Bidi)) 
                {
                    // Rotate transform 20 degree for italic that is the based on 'H' italic degree. 
                    // NOTE: The angle of italic caret is constant. This is Word behavior
                    // established after usability studies with conditional angle dependent
                    // on font properties - they discovered that variations look annoying.
                    // NOTE: We ignore _italic setting in _bidi case. This is Word behavior. 
                    // When flow direction is Right to Left, we need to reverse the caret transform.
                    // 
                    // Get the flow direction which is the flow direction of AdornedElement. 
                    // CaretElement is rendering the caret that based on AdornedElement, so we can
                    // render the right italic caret whatever the text content set the flow direction. 
                    FlowDirection flowDirection = (FlowDirection)AdornedElement.GetValue(FlowDirectionProperty);
                    context.PushTransform(new RotateTransform(
                    flowDirection == FlowDirection.RightToLeft ? -20 : 20,
 
                        0,  _height));
 
                    contextPushedCount++; 
                }
 
                if (this.IsInInterimState || _systemCaretWidth > DefaultNarrowCaretWidth)
                {
                    // Make the block caret partially transparent to avoid obstructing text.
                    context.PushOpacity(CaretOpacity); 
                    contextPushedCount++;
                } 
 
                if (this.IsInInterimState)
                { 
                    // Render the interim block caret as the specified interim block caret width.
                    context.DrawRectangle(_caretBrush, null, new Rect(0, 0, _interimWidth, _height));
                }
                else 
                {
                    // Snap the caret to device pixels. 
                    if (!_italic || threadLocalStore.Bidi) 
                    {
                        GuidelineSet guidelineSet = new GuidelineSet(new double[] { -(_systemCaretWidth / 2), _systemCaretWidth / 2 }, null); 
                        context.PushGuidelineSet(guidelineSet);
                        contextPushedCount++;
                    }
 
                    // If we don't snap, the caret will render as a 2 pixel wide rect, one pixel in each bordering char bounding box.
                    context.DrawRectangle(_caretBrush, null, new Rect(-(_systemCaretWidth / 2), 0, _systemCaretWidth, _height)); 
                } 

                if (threadLocalStore.Bidi) 
                {
                    // Set the Bidi caret indicator width. TextBox/RichTextBox control must have
                    // the enough margin to display BiDi indicator.
                    double bidiCaretIndicatorWidth = BidiCaretIndicatorWidth; 

                    // Get the flow direction which is the flow direction of AdornedElement. 
                    // Because CaretElement is rendering the caret that based on AdornedElement. 
                    // With getting the flow direction, we can render the BiDi caret indicator correctly
                    // whatever AdornedElement's flow direction is set. 
                    FlowDirection flowDirection = (FlowDirection)AdornedElement.GetValue(FlowDirectionProperty);
                    if (flowDirection == FlowDirection.RightToLeft)
                    {
                        // BiDi caret indicator should always direct by the right to left 
                        bidiCaretIndicatorWidth = bidiCaretIndicatorWidth * (-1);
                    } 
 
                    // Draw BIDI caret to indicate the coming input is BIDI characters.
                    // Shape is a little flag oriented to the left - as in Word. 
                    // Orientation does not depend on anything (which seems to be Word behavior).
                    //
                    PathGeometry pathGeometry;
                    PathFigure pathFigure; 

                    pathGeometry = new PathGeometry(); 
                    pathFigure = new PathFigure(); 
                    pathFigure.StartPoint = new Point(0, 0);
                    pathFigure.Segments.Add(new LineSegment(new Point(-bidiCaretIndicatorWidth, 0), true)); 
                    pathFigure.Segments.Add(new LineSegment(new Point(0, _height / BidiIndicatorHeightRatio), true));
                    pathFigure.IsClosed = true;

                    pathGeometry.Figures.Add(pathFigure); 
                    context.DrawGeometry(_caretBrush, null, pathGeometry);
                } 
 
                // Pop the drawing context if pushed for italic or opacity setting
                for (int i = 0; i < contextPushedCount; i++) 
                {
                    context.Pop();
                }
            } 
            else
            { 
                // Destroy Win32 caret. 
                Win32DestroyCaret();
            } 
        }
コード例 #16
0
        private void DrawImage(DrawingContext dc, Rect rect)
        {
            ImageSource source = Image;

            if (source != null)
            {
                double opacity = ImageOpacity;

                if (IsNineGrid)
                {
                    // make sure we don't step out of borders
                    Thickness margin = Clamp(ImageMargin, new Size(source.Width, source.Height), rect.Size);

                    double[] xGuidelines = { 0, margin.Left, rect.Width - margin.Right, rect.Width };
                    double[] yGuidelines = { 0, margin.Top, rect.Height - margin.Bottom, rect.Height };
                    GuidelineSet guidelineSet = new GuidelineSet(xGuidelines, yGuidelines);
                    guidelineSet.Freeze();

                    dc.PushGuidelineSet(guidelineSet);

                    double[] vx = { 0D, margin.Left / source.Width, (source.Width - margin.Right) / source.Width, 1D };
                    double[] vy = { 0D, margin.Top / source.Height, (source.Height - margin.Bottom) / source.Height, 1D };
                    double[] x = { rect.Left, rect.Left + margin.Left, rect.Right - margin.Right, rect.Right };
                    double[] y = { rect.Top, rect.Top + margin.Top, rect.Bottom - margin.Bottom, rect.Bottom };

                    for (int i = 0; i < 3; ++i)
                    {
                        for (int j = 0; j < 3; ++j)
                        {
                            var brush = new ImageBrush(source)
                            {
                                Opacity = opacity,
                                Viewbox = new Rect(vx[j], vy[i], Math.Max(0D, (vx[j + 1] - vx[j])),
                                    Math.Max(0D, (vy[i + 1] - vy[i])))
                            };

                            dc.DrawRectangle(brush, null,
                                new Rect(x[j], y[i], Math.Max(0D, (x[j + 1] - x[j])), Math.Max(0D, (y[i + 1] - y[i]))));
                        }
                    }

                    dc.Pop();
                }
                else
                {
                    var brush = new ImageBrush(source) { Opacity = opacity };

                    dc.DrawRectangle(brush, null, rect);
                }
            }
        }
コード例 #17
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
          
            try
            {
                textView.EnsureVisualLines();
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                bool odd = true;
                if (!G.AppSettings.isFixedBackgroundLines)
                    if (textView.VisualLines.Count>0)
                    if (textView.VisualLines[0].FirstDocumentLine.LineNumber % 2 == 0)
                        odd = false;
                for (int i = 0; i < textView.VisualLines.Count; i++)
                {
                    var segment2 = new TextSegment
                    {
                        StartOffset = textView.VisualLines[i].FirstDocumentLine.Offset,
                        EndOffset = textView.VisualLines[i].LastDocumentLine.EndOffset
                    };
                    foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, segment2))
                    {
                        if (!odd)
                            drawingContext.DrawRectangle(scbEven, border,
                                                           new Rect(r.Location, new Size(textView.ActualWidth, r.Height)));//draw even line
                        else drawingContext.DrawRectangle(scbOdd, border,
                                                                new Rect(r.Location, new Size(textView.ActualWidth, r.Height)));//draw odd line
                        if (G.AppSettings.isShowUnderline)
                        {
                            string str = editor.Document.GetText(textView.VisualLines[i].FirstDocumentLine.Offset, textView.VisualLines[i].FirstDocumentLine.Length);
                            //if (str.Contains("<frame_end>") || str.Contains("<bmp_end>"))
                            if (Contains(str, G.AppSettings.underlineThisWords))
                            {
                                double halfPenWidth = lpen.Thickness / 2;
                                GuidelineSet guidelines = new GuidelineSet();
                                guidelines.GuidelinesX.Add(r.Left + halfPenWidth);
                                guidelines.GuidelinesX.Add(r.Right + halfPenWidth);
                                guidelines.GuidelinesY.Add(r.Top + halfPenWidth);
                                guidelines.GuidelinesY.Add(r.Bottom + halfPenWidth);
                                drawingContext.PushGuidelineSet(guidelines);
                                drawingContext.DrawLine(lpen, new Point(r.Left, r.Bottom), new Point(textView.ActualWidth, r.Bottom)); //draw underline                            
                            }
                        }
                        if (odd) odd = false; else odd = true;
                    }     //foreach
                }    //for
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                var line = editor.Document.GetLineByOffset(editor.CaretOffset);
                var segment = new TextSegment { StartOffset = line.Offset, EndOffset = line.EndOffset };
                foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, segment))
                {
                    drawingContext.DrawRectangle(lgbLine, border,
                                                 new Rect(r.Location, new Size(textView.ActualWidth, r.Height))); //Draw current cursor line
                    if (G.AppSettings.isShowUnderline)
                    {
                        string str2 = editor.Document.GetText(segment);

                        if (Contains(str2, G.AppSettings.underlineThisWords))
                        {
                            double halfPenWidth = lpen.Thickness / 2;
                            GuidelineSet guidelines = new GuidelineSet();
                            guidelines.GuidelinesX.Add(r.Left + halfPenWidth);
                            guidelines.GuidelinesX.Add(r.Right + halfPenWidth);
                            guidelines.GuidelinesY.Add(r.Top + halfPenWidth);
                            guidelines.GuidelinesY.Add(r.Bottom + halfPenWidth);
                            drawingContext.PushGuidelineSet(guidelines);
                            drawingContext.DrawLine(lpen, new Point(r.Left, r.Bottom), new Point(textView.ActualWidth, r.Bottom)); //correct underline
                        }
                    }
                }
            }
            catch (Exception ex) { new wException(ex).ShowDialog(); }
        }//Draw end
コード例 #18
0
        protected override void OnRender(DrawingContext ctx)
        {
            base.OnRender(ctx);
            if (ctx != null)
            {
                // only solid brush is supported now
                var brush = (IsContentActive ? ActiveBorderBrush : InactiveBorderBrush) as SolidColorBrush;
                if (brush != null)
                {
                    Rect rClient = new Rect(0, 0, this.ActualWidth, this.ActualHeight);

                    var thick = BorderThickness;
                    var clientW = rClient.Width - thick.Right - thick.Left;// -1;
                    var clientH = rClient.Height - thick.Top - thick.Bottom;// -1;

                    if (clientW > 1 && clientH > 1)
                    {
                        rClient.X += thick.Left;
                        rClient.Y += thick.Top;
                        rClient.Width = clientW;
                        rClient.Height = clientH;

                        var rTop = new Rect(rClient.Left, 0, rClient.Width, thick.Top);
                        var rTopLeft = new Rect(0, 0, thick.Left, thick.Top);
                        var rTopRight = new Rect(rClient.Right, 0, thick.Right, thick.Top);

                        var rBottom = new Rect(rClient.Left, rClient.Bottom, rClient.Width, thick.Bottom);
                        var rBottomLeft = new Rect(0, rClient.Bottom, thick.Left, thick.Bottom);
                        var rBottomRight = new Rect(rClient.Right, rClient.Bottom, thick.Right, thick.Bottom);

                        var rLeft = new Rect(0, rClient.Top, thick.Left, rClient.Height);
                        var rRight = new Rect(rClient.Right, rClient.Top, thick.Right, rClient.Height);

                        var brushes = GetShadowBrushes(brush.Color);//, (thick.Top + thick.Bottom + thick.Right + thick.Left) / 4);
                        ctx.DrawRectangle(brushes[(int)BorderSide.TopLeft], null, rTopLeft);
                        ctx.DrawRectangle(brushes[(int)BorderSide.TopRight], null, rTopRight);
                        ctx.DrawRectangle(brushes[(int)BorderSide.Top], null, rTop);
                        ctx.DrawRectangle(brushes[(int)BorderSide.BottomLeft], null, rBottomLeft);
                        ctx.DrawRectangle(brushes[(int)BorderSide.BottomRight], null, rBottomRight);
                        ctx.DrawRectangle(brushes[(int)BorderSide.Bottom], null, rBottom);
                        ctx.DrawRectangle(brushes[(int)BorderSide.Left], null, rLeft);
                        ctx.DrawRectangle(brushes[(int)BorderSide.Right], null, rRight);

                        Pen borderPen = new Pen(brush, 1);

                        // from http://wpftutorial.net/DrawOnPhysicalDevicePixels.html
                        double halfPenWidth = borderPen.Thickness / 2;

                        // Create a guidelines set
                        GuidelineSet guidelines = new GuidelineSet();
                        guidelines.GuidelinesX.Add(rClient.Left + halfPenWidth);
                        guidelines.GuidelinesX.Add(rClient.Right + halfPenWidth);
                        guidelines.GuidelinesY.Add(rClient.Top + halfPenWidth);
                        guidelines.GuidelinesY.Add(rClient.Bottom + halfPenWidth);

                        ctx.PushGuidelineSet(guidelines);

                        rClient.X -= 1;
                        rClient.Y -= 1;
                        rClient.Width += 1;
                        rClient.Height += 1;
                        ctx.DrawRectangle(null, borderPen, rClient);
                        //ctx.DrawRectangle(null, new Pen(Brushes.Red, 1), rect);
                    }
                }
            }
        }
コード例 #19
0
ファイル: WpfRenderer.cs プロジェクト: Core2D/Core2D
        private static void DrawPathGeometryInternal(DrawingContext dc, double half, Brush brush, Pen pen, bool isStroked, bool isFilled, PathGeometry pg)
        {
            if (!isStroked && !isFilled)
                return;

            var gs = new GuidelineSet(
                new double[]
                    {
                        pg.Bounds.TopLeft.X + half,
                        pg.Bounds.BottomRight.X + half
                    },
                new double[]
                    {
                        pg.Bounds.TopLeft.Y + half,
                        pg.Bounds.BottomRight.Y + half
                    });
            dc.PushGuidelineSet(gs);
            dc.DrawGeometry(isFilled ? brush : null, isStroked ? pen : null, pg);
            dc.Pop();
        }
コード例 #20
0
        /// <summary>
        /// OnRender method.
        /// </summary>
        /// <param name="drawingContext">Drawing context.</param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (TimeAxis.ZoomMode == ZoomMode.FrameLevel)
            {
                GuidelineSet gs = new GuidelineSet();
                Pen pen = new Pen(Brushes.LightGray, 1);
                double halfPen = pen.Thickness / 2;
                
                // draw time line for each frame
                for (int i = 0; i <= ActualWidth / ViewHelper.TimespanToPixel(TimeAxis.SampleInterval, TimeAxis.ZoomScale); ++i)
                {
                    double x = ViewHelper.TimespanToPixel(TimeAxis.SampleInterval * (double)i, TimeAxis.ZoomScale);
                    gs.GuidelinesX.Clear();
                    gs.GuidelinesX.Add(x - halfPen);
                    gs.GuidelinesX.Add(x + halfPen);
                    drawingContext.PushGuidelineSet(gs.Clone());
                    drawingContext.DrawLine(pen, new Point(x, 0), new Point(x, Height));
                    drawingContext.Pop();
                }
            }
        }
コード例 #21
0
ファイル: YAxis.cs プロジェクト: HammerZhao/Chart
 private void RenderMarker(DrawingContext dc)
 {
     dc.PushGuidelineSet(new GuidelineSet(new double[] { 0 }, new double[] { 0.5 }));
     foreach(var m in _Markers)
     {
         dc.DrawLine(new Pen(Brushes.White, 1), m.StartPoint, m.EndPoint);
         dc.DrawText(m.Value, m.TextPoint);
     }
     dc.Pop();
 }
コード例 #22
0
ファイル: TimeScale.cs プロジェクト: nnikos123/Aurio
        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();
        }
コード例 #23
0
ファイル: Needle.cs プロジェクト: josh2112/ruler-wpf
        protected override void OnRender( DrawingContext ctx )
        {
            base.OnRender( ctx );

            var thinPen = new Pen( this.Foreground, 1 );
            var thickPen = new Pen( this.Foreground, 3 );

            var halfPenWidth = thinPen.Thickness / 2;

            var guidelines = new GuidelineSet();
            guidelines.GuidelinesX.Add( 0 + halfPenWidth );
            guidelines.GuidelinesY.Add( 0 + halfPenWidth );
            ctx.PushGuidelineSet( guidelines );

            Point pt1, pt2, pt3;
            if( Orientation == Orientation.Horizontal )
            {
                pt1 = new Point( MousePosition, RenderSize.Height );
                pt2 = new Point( MousePosition, RenderSize.Height - ToothSize );
                pt3 = new Point( MousePosition, RenderSize.Height - ToothSize - NeedleSize );
            }
            else
            {
                pt1 = new Point( 0, MousePosition );
                pt2 = new Point( ToothSize, MousePosition );
                pt3 = new Point( ToothSize + NeedleSize, MousePosition );
            }

            ctx.DrawLine( new Pen( Brushes.White, 3 ), pt1, pt2 );
            ctx.DrawLine( thinPen, pt1, pt2 );
            ctx.DrawLine( thickPen, pt2, pt3 );

               // var axisLabel = new FormattedText( MousePosition.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
               //         tooltipTypeface, FontSize, Foreground );

            //ctx.DrawText( axisLabel, new Point( ToothSize + MinorTickSize + 3, y - 2 ) );;
        }
コード例 #24
0
    DrawPixelAlignedRectangle
    (
        DrawingContext drawingContext,
        Brush brush,
        Pen pen,
        Rect rect
    )
    {
        Debug.Assert(drawingContext != null);
        Debug.Assert(pen != null);

        // This technique was described at "Draw lines excactly on physical
        // device pixels," by Christian Mosers, at
        // http://wpftutorial.net/DrawOnPhysicalDevicePixels.html.

        Double dHalfPenWidth = pen.Thickness / 2.0;
 
        GuidelineSet oGuidelineSet = new GuidelineSet();
        DoubleCollection oGuidelinesX = oGuidelineSet.GuidelinesX;
        DoubleCollection oGuidelinesY = oGuidelineSet.GuidelinesY;

        oGuidelinesX.Add(rect.Left + dHalfPenWidth);
        oGuidelinesX.Add(rect.Right + dHalfPenWidth);
        oGuidelinesY.Add(rect.Top + dHalfPenWidth);
        oGuidelinesY.Add(rect.Bottom + dHalfPenWidth);
 
        drawingContext.PushGuidelineSet(oGuidelineSet);
        drawingContext.DrawRectangle(brush, pen, rect);
        drawingContext.Pop();
    }
コード例 #25
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            double dpiFactor = 1;

            // If there's no LabelTemplate, there's no label to place.
            // If there's no label to place, there's no connecting lines that need to be drawn.
            // Additionally, if there is no brush or if the line is too small to render
            // we can't draw the connectors
            if (LabelTemplate == null || (LeaderThickness) < 0.25)
            {
                return;
            }

            // If possible, find the factor to adjust the pen width to device pixels
            PresentationSource source = PresentationSource.FromVisual(this);
            if (source != null && source.CompositionTarget != null)
            {
                // PresentationSource and CompositionTarget should never be null at this point,
                // but we still need to check to see if they are since the API doesn't guarantee
                // the return value is not null.
                Matrix matrix = source.CompositionTarget.TransformToDevice;
                dpiFactor = 1 / matrix.M11;
            }

            foreach (
                FrameworkElement element in
                    InternalChildren.OfType<FrameworkElement>().Where(child => !GetIsLabel(child)))
            {
                FrameworkElement label = GetLabelPresenter(element);

                if (label == null || !label.IsVisible || !element.IsVisible)
                {
                    // Don't draw any lines when there are no labels for an element, or if either the label
                    // or the element are not visible
                    continue;
                }

                Brush leaderBrush = GetLabelBrush(element);

                if (leaderBrush == null || Equals(leaderBrush, Brushes.Transparent))
                {
                    // If the color is transparent, don't waste processing time drawing a leader
                    // that won't be seen anyway.
                    continue;
                }

                leaderBrush.Freeze();
                Pen linePen = new Pen(leaderBrush, LeaderThickness * dpiFactor);
                linePen.Freeze();

                Rect objectRect = new Rect(element.TranslatePoint(new Point(), this), element.RenderSize);
                Rect labelRect = new Rect(label.TranslatePoint(new Point(), this), label.RenderSize);

                double halfPenWidth = linePen.Thickness / 2;

                // Set up snap to pixels
                GuidelineSet guidelines = new GuidelineSet();
                guidelines.GuidelinesX.Add(objectRect.Right + halfPenWidth);
                guidelines.GuidelinesX.Add(labelRect.Left + halfPenWidth);
                guidelines.GuidelinesY.Add(objectRect.Top + halfPenWidth);
                guidelines.GuidelinesY.Add(labelRect.Top + halfPenWidth);

                // Do snap to pixels work.
                drawingContext.PushGuidelineSet(guidelines);

                if (objectRect.Width > 0 && labelRect.Width > 0)
                {
                    Point startPoint = new Point(objectRect.Right + linePen.Thickness,
                                objectRect.Top + (objectRect.Height / 2));
                    Point endPoint = new Point(labelRect.Left, labelRect.Top + (labelRect.Height / 2));
                    drawingContext.DrawLine(linePen, startPoint, endPoint);
                    drawingContext.DrawLine(linePen, labelRect.TopLeft, labelRect.BottomLeft);
                }

                drawingContext.Pop();
            }
        }
コード例 #26
0
ファイル: WpfRenderer.cs プロジェクト: Core2D/Core2D
        private static void DrawRectangleInternal(DrawingContext dc, double half, Brush brush, Pen pen, bool isStroked, bool isFilled, ref Rect rect)
        {
            if (!isStroked && !isFilled)
                return;

            var gs = new GuidelineSet(
                new double[]
                    {
                        rect.TopLeft.X + half,
                        rect.BottomRight.X + half
                    },
                new double[]
                    {
                        rect.TopLeft.Y + half,
                        rect.BottomRight.Y + half
                    });
            dc.PushGuidelineSet(gs);
            dc.DrawRectangle(isFilled ? brush : null, isStroked ? pen : null, rect);
            dc.Pop();
        }
コード例 #27
0
ファイル: SymbolControl.cs プロジェクト: alexbv16/LiveSPICE
        public static void DrawLayout(
            Circuit.SymbolLayout Layout,
            DrawingContext Context, Matrix Tx, 
            Pen Pen, FontFamily FontFamily, FontWeight FontWeight, double FontSize)
        {
            Context.PushGuidelineSet(Guidelines);

            foreach (Circuit.SymbolLayout.Shape i in Layout.Lines)
                Context.DrawLine(
                    Pen != null ? Pen : MapToPen(i.Edge),
                    T(Tx, i.x1),
                    T(Tx, i.x2));
            foreach (Circuit.SymbolLayout.Shape i in Layout.Rectangles)
                Context.DrawRectangle(
                    (i.Fill && Pen == null) ? MapToBrush(i.Edge) : null,
                    Pen != null ? Pen : MapToPen(i.Edge),
                    new Rect(T(Tx, i.x1), T(Tx, i.x2)));
            foreach (Circuit.SymbolLayout.Shape i in Layout.Ellipses)
            {
                Brush brush = (i.Fill && Pen == null) ? MapToBrush(i.Edge) : null;
                Pen pen = Pen != null ? Pen : MapToPen(i.Edge);
                Point p1 = T(Tx, i.x1);
                Point p2 = T(Tx, i.x2);

                Context.DrawEllipse(
                    brush, pen,
                    new Point((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2), (p2.X - p1.X) / 2, (p2.Y - p1.Y) / 2);
            }
            foreach (Circuit.SymbolLayout.Curve i in Layout.Curves)
            {
                IEnumerator<Circuit.Point> e = i.x.AsEnumerable().GetEnumerator();
                if (!e.MoveNext())
                    return;

                Pen pen = Pen != null ? Pen : MapToPen(i.Edge);
                Point x1 = T(Tx, e.Current);
                while (e.MoveNext())
                {
                    Point x2 = T(Tx, e.Current);
                    Context.DrawLine(pen, x1, x2);
                    x1 = x2;
                }
            }

            if (FontFamily != null)
            {
                // Not sure if this matrix has row or column vectors... want the y axis scaling here.
                double scale = Math.Sqrt(Tx.M11 * Tx.M11 + Tx.M21 * Tx.M21);

                foreach (Circuit.SymbolLayout.Text i in Layout.Texts)
                {
                    double size;
                    switch (i.Size)
                    {
                        case Circuit.Size.Small: size = 0.5; break;
                        case Circuit.Size.Large: size = 1.5; break;
                        default: size = 1.0; break;
                    }
                    FormattedText text = new FormattedText(
                        i.String,
                        CultureInfo.CurrentUICulture, FlowDirection.LeftToRight,
                        new Typeface(FontFamily, FontStyles.Normal, FontWeight, FontStretches.Normal), FontSize * scale * size,
                        Brushes.Black);

                    Point p = T(Tx, i.x);
                    Vector p1 = T(Tx, new Circuit.Point(i.x.x - MapAlignment(i.HorizontalAlign), i.x.y + (1 - MapAlignment(i.VerticalAlign)))) - p;
                    Vector p2 = T(Tx, new Circuit.Point(i.x.x - (1 - MapAlignment(i.HorizontalAlign)), i.x.y + MapAlignment(i.VerticalAlign))) - p;

                    p1.X *= text.Width; p2.X *= text.Width;
                    p1.Y *= text.Height; p2.Y *= text.Height;

                    Rect rc = new Rect(
                        Math.Min(p.X + p1.X, p.X - p2.X),
                        Math.Min(p.Y + p1.Y, p.Y - p2.Y),
                        text.Width,
                        text.Height);
                    if (TextOutline != null)
                        Context.DrawRectangle(null, TextOutline, rc);

                    Context.DrawText(text, rc.TopLeft);
                }
            }

            foreach (Circuit.Terminal i in Layout.Terminals)
                DrawTerminal(Context, T(Tx, Layout.MapTerminal(i)), i.ConnectedTo != null);

            Context.Pop();
        }
コード例 #28
0
ファイル: WpfRenderer.cs プロジェクト: Core2D/Core2D
        private static void DrawEllipseInternal(DrawingContext dc, double half, Brush brush, Pen pen, bool isStroked, bool isFilled, ref Point center, double rx, double ry)
        {
            if (!isStroked && !isFilled)
                return;

            var gs = new GuidelineSet(
                new double[]
                    {
                        center.X - rx + half,
                        center.X + rx + half
                    },
                new double[]
                    {
                        center.Y - ry + half,
                        center.Y + ry + half
                    });
            dc.PushGuidelineSet(gs);
            dc.DrawEllipse(isFilled ? brush : null, isStroked ? pen : null, center, rx, ry);
            dc.Pop();
        }
コード例 #29
0
ファイル: SymbolControl.cs プロジェクト: alexbv16/LiveSPICE
        protected override void OnRender(DrawingContext drawingContext)
        {
            Matrix transform = Transform;

            dc = drawingContext;
            dc.PushGuidelineSet(SymbolControl.Guidelines);

            DrawLayout(layout, dc, transform, Pen, ShowText ? FontFamily : null, FontWeight, FontSize);

            Rect bounds = new Rect(T(transform, layout.LowerBound), T(transform, layout.UpperBound));
            if (Selected)
                dc.DrawRectangle(null, SelectedPen, bounds);
            else if (Highlighted)
                dc.DrawRectangle(null, HighlightPen, bounds);

            dc.Pop();
            dc = null;
        }
コード例 #30
0
    protected override void OnRender( DrawingContext drawingContext )
    {
      if( this.ConnectionLinePen != null )
      {
        bool left = false;
        bool top = false;
        bool middle = false;

        switch( this.ConnectionLineAlignment )
        {
          case ConnectionLineAlignment.LeftToBottom:
            left = true;
            break;

          case ConnectionLineAlignment.RightToTop:
            top = true;
            break;

          case ConnectionLineAlignment.LeftToTop:
            left = true;
            top = true;
            break;

          case ConnectionLineAlignment.CenterToCenter:
            middle = true;
            break;

          case ConnectionLineAlignment.RightToBottom:
          default:
            break;
        }

        //cycling with count -1 because we don't want to draw a ligne after last item
        for( int i = 0; i < this.InternalChildren.Count - 1; i++ )
        {
          UIElement startItem = this.InternalChildren[ i ];
          UIElement endItem = this.InternalChildren[ i + 1 ];

          Vector startOffset = VisualTreeHelper.GetOffset( startItem );
          Vector endOffset = VisualTreeHelper.GetOffset( endItem );

          Size startSize = startItem.RenderSize;
          Size endSize = endItem.RenderSize;

          double startPointX = 0.0d;
          double startPointY = 0.0d;
          double endPointX = 0.0d;
          double endPointY = 0.0d;

          List<PathSegment> myPathSegments = null;

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

          if( middle == true )
          {
            startPointX = startOffset.X + startSize.Width + this.ConnectionLineOffset;

            startPointY = startOffset.Y + ( startSize.Height / 2 );

            endPointY = endOffset.Y + ( endSize.Height / 2 );

            endPointX = endOffset.X - this.ConnectionLineOffset;

            double deltaX = ( endPointX - startPointX );

            guidelineSet.GuidelinesX.Add( startPointX );
            guidelineSet.GuidelinesX.Add( startPointX + ( deltaX / 2 ) + 0.5d );
            guidelineSet.GuidelinesX.Add( startPointX + deltaX );
            guidelineSet.GuidelinesY.Add( startPointY );
            guidelineSet.GuidelinesY.Add( endPointY );

            myPathSegments = new List<PathSegment>( 4 ); //we know there are going be only 4 segments
            myPathSegments.Add( new LineSegment( new Point( startPointX, startPointY ), true ) );
            myPathSegments.Add( new LineSegment( new Point( startPointX + ( deltaX / 2 ), startPointY ), true ) );
            myPathSegments.Add( new LineSegment( new Point( startPointX + ( deltaX / 2 ), endPointY ), true ) );
            myPathSegments.Add( new LineSegment( new Point( startPointX + deltaX, endPointY ), true ) );

          }
          else
          {
            if( left == true )
            {
              startPointX = startOffset.X + this.ConnectionLineOffset;
            }
            else
            {
              startPointX = startOffset.X + startSize.Width - this.ConnectionLineOffset;
            }

            startPointY = startOffset.Y + startSize.Height;

            if( top == true )
            {
              endPointY = endOffset.Y + this.ConnectionLineOffset;
            }
            else
            {
              endPointY = endOffset.Y + endSize.Height - this.ConnectionLineOffset;
            }

            endPointX = endOffset.X;

            guidelineSet.GuidelinesX.Add( startPointX );
            guidelineSet.GuidelinesX.Add( endPointX );
            guidelineSet.GuidelinesY.Add( startPointY );
            guidelineSet.GuidelinesY.Add( endPointY );

            myPathSegments = new List<PathSegment>( 2 ); //we know there are going be only 2 segments
            myPathSegments.Add( new LineSegment( new Point( startPointX, endPointY ), true ) );
            myPathSegments.Add( new LineSegment( new Point( endPointX, endPointY ), true ) );
          }

          PathFigure myPathFigure = new PathFigure( new Point( startPointX, startPointY ), myPathSegments, false );

          PathGeometry myPathGeometry = new PathGeometry();
          myPathGeometry.Figures.Add( myPathFigure );

          drawingContext.DrawGeometry( null, this.ConnectionLinePen, myPathGeometry );

          // pop the context to remove the GuidelineSet
          drawingContext.Pop();
        }
      }

      base.OnRender( drawingContext );
    }
コード例 #31
0
        /// <summary>
        /// Render callback.  
        /// </summary>
        protected override void OnRender(DrawingContext drawingContext)
        {
            CornerRadius cornerRadius = CornerRadius;

            Rect shadowBounds = new Rect(new Point(ShadowDepth, ShadowDepth),
                             new Size(RenderSize.Width, RenderSize.Height));
            Color color = Color;

            if (shadowBounds.Width > 0 && shadowBounds.Height > 0 && color.A > 0)
            {
                // The shadow is drawn with a dark center the size of the shadow bounds
                // deflated by shadow depth on each side.
                double centerWidth = shadowBounds.Right - shadowBounds.Left - 2 * ShadowDepth;
                double centerHeight = shadowBounds.Bottom - shadowBounds.Top - 2 * ShadowDepth;

                // Clamp corner radii to be less than 1/2 the side of the inner shadow bounds 
                double maxRadius = Math.Min(centerWidth * 0.5, centerHeight * 0.5);
                cornerRadius.TopLeft = Math.Min(cornerRadius.TopLeft, maxRadius);
                cornerRadius.TopRight = Math.Min(cornerRadius.TopRight, maxRadius);
                cornerRadius.BottomLeft = Math.Min(cornerRadius.BottomLeft, maxRadius);
                cornerRadius.BottomRight = Math.Min(cornerRadius.BottomRight, maxRadius);

                // Get the brushes for the 9 regions
                Brush[] brushes = GetBrushes(color, cornerRadius);

                // Snap grid to device pixels
                double centerTop = shadowBounds.Top + ShadowDepth;
                double centerLeft = shadowBounds.Left + ShadowDepth;
                double centerRight = shadowBounds.Right - ShadowDepth;
                double centerBottom = shadowBounds.Bottom - ShadowDepth;

                // Because of different corner radii there are 6 potential x (or y) lines to snap to
                double[] guidelineSetX = new double[] { centerLeft,
                                                        centerLeft + cornerRadius.TopLeft,
                                                        centerRight - cornerRadius.TopRight,
                                                        centerLeft + cornerRadius.BottomLeft,
                                                        centerRight - cornerRadius.BottomRight,
                                                        centerRight};

                double[] guidelineSetY = new double[] { centerTop,
                                                        centerTop + cornerRadius.TopLeft,
                                                        centerTop + cornerRadius.TopRight,
                                                        centerBottom - cornerRadius.BottomLeft,
                                                        centerBottom - cornerRadius.BottomRight,
                                                        centerBottom};
                
                drawingContext.PushGuidelineSet(new GuidelineSet(guidelineSetX, guidelineSetY));

                // The corner rectangles are drawn drawn ShadowDepth pixels bigger to 
                // account for the blur
                cornerRadius.TopLeft = cornerRadius.TopLeft + ShadowDepth;
                cornerRadius.TopRight = cornerRadius.TopRight + ShadowDepth;
                cornerRadius.BottomLeft = cornerRadius.BottomLeft + ShadowDepth;
                cornerRadius.BottomRight = cornerRadius.BottomRight + ShadowDepth;


                // Draw Top row
                Rect topLeft = new Rect(shadowBounds.Left, shadowBounds.Top, cornerRadius.TopLeft, cornerRadius.TopLeft);
                drawingContext.DrawRectangle(brushes[TopLeft], null, topLeft);

                double topWidth = guidelineSetX[2] - guidelineSetX[1];
                if (topWidth > 0)
                {
                    Rect top = new Rect(guidelineSetX[1], shadowBounds.Top, topWidth, ShadowDepth);
                    drawingContext.DrawRectangle(brushes[Top], null, top);
                }

                Rect topRight = new Rect(guidelineSetX[2], shadowBounds.Top, cornerRadius.TopRight, cornerRadius.TopRight);
                drawingContext.DrawRectangle(brushes[TopRight], null, topRight);

                // Middle row
                double leftHeight = guidelineSetY[3] - guidelineSetY[1];
                if (leftHeight > 0)
                {
                    Rect left = new Rect(shadowBounds.Left, guidelineSetY[1], ShadowDepth, leftHeight);
                    drawingContext.DrawRectangle(brushes[Left], null, left);
                }

                double rightHeight = guidelineSetY[4] - guidelineSetY[2];
                if (rightHeight > 0)
                {
                    Rect right = new Rect(guidelineSetX[5], guidelineSetY[2], ShadowDepth, rightHeight);
                    drawingContext.DrawRectangle(brushes[Right], null, right);
                }

                // Bottom row
                Rect bottomLeft = new Rect(shadowBounds.Left, guidelineSetY[3], cornerRadius.BottomLeft, cornerRadius.BottomLeft);
                drawingContext.DrawRectangle(brushes[BottomLeft], null, bottomLeft);

                double bottomWidth = guidelineSetX[4] - guidelineSetX[3];
                if (bottomWidth > 0)
                {
                    Rect bottom = new Rect(guidelineSetX[3], guidelineSetY[5], bottomWidth, ShadowDepth);
                    drawingContext.DrawRectangle(brushes[Bottom], null, bottom);
                }

                Rect bottomRight = new Rect(guidelineSetX[4], guidelineSetY[4], cornerRadius.BottomRight, cornerRadius.BottomRight);
                drawingContext.DrawRectangle(brushes[BottomRight], null, bottomRight);


                // Fill Center

                // Because the heights of the top/bottom rects and widths of the left/right rects are fixed
                // and the corner rects are drawn with the size of the corner, the center 
                // may not be a square.  In this case, create a path to fill the area

                // When the target object's corner radius is 0, only need to draw one rect
                if (cornerRadius.TopLeft == ShadowDepth &&
                    cornerRadius.TopLeft == cornerRadius.TopRight &&
                    cornerRadius.TopLeft == cornerRadius.BottomLeft &&
                    cornerRadius.TopLeft == cornerRadius.BottomRight)
                {
                    // All corners of target are 0, render one large rectangle
                    Rect center = new Rect(guidelineSetX[0], guidelineSetY[0], centerWidth, centerHeight);
                    drawingContext.DrawRectangle(brushes[Center], null, center);
                }
                else
                {
                    // If the corner radius is TL=2, TR=1, BL=0, BR=2 the following shows the shape that needs to be created.
                    //             _________________
                    //            |                 |_
                    //         _ _|                   |
                    //        |                       |
                    //        |                    _ _|
                    //        |                   |   
                    //        |___________________| 
                    // The missing corners of the shape are filled with the radial gradients drawn above

                    // Define shape counter clockwise
                    PathFigure figure = new PathFigure();

                    if (cornerRadius.TopLeft > ShadowDepth)
                    {
                        figure.StartPoint = new Point(guidelineSetX[1], guidelineSetY[0]);
                        figure.Segments.Add(new LineSegment(new Point(guidelineSetX[1], guidelineSetY[1]), true));
                        figure.Segments.Add(new LineSegment(new Point(guidelineSetX[0], guidelineSetY[1]), true));
                    }
                    else
                    {
                        figure.StartPoint = new Point(guidelineSetX[0], guidelineSetY[0]);
                    }

                    if (cornerRadius.BottomLeft > ShadowDepth)
                    {
                        figure.Segments.Add(new LineSegment(new Point(guidelineSetX[0], guidelineSetY[3]), true));
                        figure.Segments.Add(new LineSegment(new Point(guidelineSetX[3], guidelineSetY[3]), true));
                        figure.Segments.Add(new LineSegment(new Point(guidelineSetX[3], guidelineSetY[5]), true));
                    }
                    else
                    {
                        figure.Segments.Add(new LineSegment(new Point(guidelineSetX[0], guidelineSetY[5]), true));
                    }

                    if (cornerRadius.BottomRight > ShadowDepth)
                    {
                        figure.Segments.Add(new LineSegment(new Point(guidelineSetX[4], guidelineSetY[5]), true));
                        figure.Segments.Add(new LineSegment(new Point(guidelineSetX[4], guidelineSetY[4]), true));
                        figure.Segments.Add(new LineSegment(new Point(guidelineSetX[5], guidelineSetY[4]), true));
                    }
                    else
                    {
                        figure.Segments.Add(new LineSegment(new Point(guidelineSetX[5], guidelineSetY[5]), true));
                    }


                    if (cornerRadius.TopRight > ShadowDepth)
                    {
                        figure.Segments.Add(new LineSegment(new Point(guidelineSetX[5], guidelineSetY[2]), true));
                        figure.Segments.Add(new LineSegment(new Point(guidelineSetX[2], guidelineSetY[2]), true));
                        figure.Segments.Add(new LineSegment(new Point(guidelineSetX[2], guidelineSetY[0]), true));
                    }
                    else
                    {
                        figure.Segments.Add(new LineSegment(new Point(guidelineSetX[5], guidelineSetY[0]), true));
                    }
                    
                    figure.IsClosed = true;
                    figure.Freeze();

                    PathGeometry geometry = new PathGeometry();
                    geometry.Figures.Add(figure);
                    geometry.Freeze();

                    drawingContext.DrawGeometry(brushes[Center], null, geometry);
                }

                drawingContext.Pop();
            }
        }
コード例 #32
0
ファイル: YAxis.cs プロジェクト: HammerZhao/Chart
        private void RenderGridLine(DrawingContext dc)
        {
            SolidColorBrush solidbrush = new SolidColorBrush(Color.FromArgb(0xff, 0xb0, 0xb0, 0xb0)); //#FFB0B0B0
            Pen p = new Pen(solidbrush, 1);
            p.DashStyle = DashStyles.Dash;

            dc.PushGuidelineSet(new GuidelineSet(new double[] {0.5 },new double[] { 0.5}));
            foreach (var m in _Markers)
            {
                dc.DrawLine(p,m.GridStartPoint, m.GridEndPoint);
            }
            dc.Pop();
        }
コード例 #33
0
    protected override void OnRender( DrawingContext drawingContext )
    {
      base.OnRender( drawingContext );

      Brush contentBrush = this.ContentBorderBrush;
      Thickness contentThickness = this.ContentBorderThickness;
      Rect usedSurface = this.UsedSurface;

      if( ( contentBrush != null ) && ( usedSurface != Rect.Empty ) )
      {
        Pen myPen = new Pen( contentBrush, contentThickness.Left );

        GuidelineSet gls = new GuidelineSet();
        gls.GuidelinesX.Add( 0 );
        gls.GuidelinesX.Add( usedSurface.Right );
        gls.GuidelinesY.Add( 0 );
        gls.GuidelinesY.Add( usedSurface.Bottom );

        drawingContext.PushGuidelineSet( gls );

        if( contentThickness.Left > 0 )
        {
          drawingContext.DrawLine( myPen, new Point( 0 + ( contentThickness.Left / 2 ), 0 ), new Point( 0 + ( contentThickness.Left / 2 ), usedSurface.Bottom + contentThickness.Top ) );
        }

        if( contentThickness.Top > 0 )
        {
          if( myPen.Thickness != contentThickness.Top )
          {
            myPen = new Pen( contentBrush, contentThickness.Top );
          }

          drawingContext.DrawLine( myPen, new Point( 0, 0 + ( contentThickness.Top / 2 ) ), new Point( usedSurface.Right + contentThickness.Left, 0 + ( contentThickness.Top / 2 ) ) );
        }

        if( contentThickness.Right > 0 )
        {
          if( myPen.Thickness != contentThickness.Right )
          {
            myPen = new Pen( contentBrush, contentThickness.Right );
          }

          drawingContext.DrawLine( myPen, new Point( usedSurface.Right + ( contentThickness.Right / 2 ), 0 ), new Point( usedSurface.Right + ( contentThickness.Right / 2 ), usedSurface.Bottom + contentThickness.Top ) );
        }

        if( contentThickness.Bottom > 0 )
        {
          if( myPen.Thickness != contentThickness.Bottom )
          {
            myPen = new Pen( contentBrush, contentThickness.Bottom );
          }

          drawingContext.DrawLine( myPen, new Point( 0, usedSurface.Bottom + ( contentThickness.Bottom / 2 ) ), new Point( usedSurface.Right + contentThickness.Left, usedSurface.Bottom + ( contentThickness.Bottom / 2 ) ) );
        }

        drawingContext.Pop();
      }
    }
コード例 #34
0
ファイル: GridRuler.cs プロジェクト: juancampa/Gearset
        protected override void OnRender(DrawingContext dc)
        {
            if (!guidelinesFixed)
            {
                System.Windows.Media.Matrix m = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
                halfDpiX = m.M11 * 0.5;
                halfDpiY = m.M22 * 0.5;
                guidelinesFixed = true;
            }

            // Create a guidelines set
            GuidelineSet guidelines = new GuidelineSet();
            guidelines.GuidelinesX.Add(halfDpiX);
            guidelines.GuidelinesY.Add(halfDpiY);
            dc.PushGuidelineSet(guidelines);

            dc.DrawRectangle(backgroundBrush, null, new Rect(0, 0, ActualWidth, ActualHeight));

            double range;
            double pos = 0;
            double orderOfMag;
            double stepSize = 0.1;

            switch (Orientation)
            {
                case RulerOrientation.Vertical:
                    //// Thin horizontal lines
                    //range = MaxY - MinY;
                    //orderOfMag = Math.Pow(10, Math.Truncate(Math.Log10(range)));
                    //stepSize = 0.1 * orderOfMag;
                    pos = (Math.Truncate(MinY / stepSize) - 0) * stepSize;
                    //DrawGridHorizonalLines(dc, pos, stepSize, gridLinePen);
                    break;
                case RulerOrientation.Horizontal:
                    // Thin vertical lines.
                    //range = MaxX - MinX;
                    //orderOfMag = Math.Pow(10, Math.Truncate(Math.Log10(range)));
                    //stepSize = 0.1 * orderOfMag;
                    pos = Math.Truncate(MinX / stepSize) * stepSize;
                    //DrawGridVerticalLines(dc, pos, stepSize, gridLinePen);

                    // Draw the seek needle
                    var needlePos = new System.Windows.Point(NeedlePosition, 0);
                    needlePos = CurveCoordsToScreen(ref needlePos);
                    dc.PushTransform(new TranslateTransform(needlePos.X, needlePos.Y));
                    dc.DrawDrawing(SeekNeedle);
                    dc.Pop();
                    break;
            }

            dc.Pop();

            switch (Orientation)
            {
                case RulerOrientation.Vertical:
                    DrawHorizontalLinesText(dc, pos, stepSize);
                    break;
                case RulerOrientation.Horizontal:
                    DrawVerticalLinesText(dc, pos, stepSize);
                    break;
            }
            base.OnRender(dc);
        }
コード例 #35
0
ファイル: YAxis.cs プロジェクト: HammerZhao/Chart
 private void RenderLine(DrawingContext dc)
 {
     dc.PushGuidelineSet(new GuidelineSet(new double[] { 0.5 }, new double[] { 0 }));
     dc.DrawLine(new Pen(Brushes.White, 1), StartPoint, EndPoint);
     dc.Pop();
 }