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();
        }
Exemple #2
0
        private void SetFontSize(int newFontSizeEm)
        {
            newFontSizeEm = Math.Max(8, Math.Min(72, newFontSizeEm));

            if (this.fontSizeEm == newFontSizeEm)
            {
                return;
            }

            this.fontSizeEm = newFontSizeEm;

            if (!new Typeface("Consolas").TryGetGlyphTypeface(out this.typeface))
            {
                throw new InvalidOperationException("Could not get desired font.");
            }
            this.cellWidth       = this.typeface.AdvanceWidths[0] * this.fontSizeEm;
            this.cellHeight      = this.typeface.Height * this.fontSizeEm;
            this.baselineOrigin  = new Point(0, this.typeface.Baseline * this.fontSizeEm);
            this.underlineY      = this.baselineOrigin.Y - this.typeface.UnderlinePosition * this.fontSizeEm;
            this.underlineHeight = (this.cellHeight * this.typeface.UnderlineThickness);
            this.cellRectangle   = new Rect(new Size(this.cellWidth, this.cellHeight));
            this.cellGuidelines  = new GuidelineSet(
                new[] { this.cellRectangle.Left, this.cellRectangle.Right },
                new[] { this.cellRectangle.Top, this.underlineY, this.underlineY + this.underlineHeight, this.cellRectangle.Bottom });
            this.cellGuidelines.Freeze();

            this.ForceFullRedraw();
            this.Resize();
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="half"></param>
        /// <param name="pen"></param>
        /// <param name="isStroked"></param>
        /// <param name="p0"></param>
        /// <param name="p1"></param>
        private static void DrawLineInternal(
            DrawingContext dc,
            double half,
            Pen pen,
            bool isStroked,
            ref Point p0,
            ref Point p1)
        {
            if (!isStroked)
            {
                return;
            }

            if (_enableGuidelines)
            {
                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);

            if (_enableGuidelines)
            {
                dc.Pop();
            }
        }
Exemple #4
0
        protected override void Draw(DrawingContext drawingContext, double factor)
        {
            var line       = new Pen(Stroke, Math.Round(StrokeThickness * factor, MidpointRounding.AwayFromZero) / factor);
            var lineRadius = line.Thickness / 2D;

            var topCenterY    = StrokeThickness / 2D;          // Y coordinate of top line's center
            var topStartPoint = new Point(0, topCenterY - lineRadius);
            var topEndPoint   = new Point(Width, topCenterY - lineRadius);

            var middleCenterY    = Height / 2D;          // Y coordinate of middle line's center
            var middleStartPoint = new Point(0, middleCenterY - lineRadius);
            var middleEndPoint   = new Point(Width, middleCenterY - lineRadius);

            var bottomCenterY    = Height - (StrokeThickness / 2D);          // Y coordinate of bottom line's center
            var bottomStartPoint = new Point(0, bottomCenterY - lineRadius);
            var bottomEndPoint   = new Point(Width, bottomCenterY - lineRadius);

            // Create a guidelines set.
            var guidelines = new GuidelineSet();

            guidelines.GuidelinesY.Add(topStartPoint.Y);
            guidelines.GuidelinesY.Add(middleStartPoint.Y);
            guidelines.GuidelinesY.Add(bottomStartPoint.Y);

            drawingContext.PushGuidelineSet(guidelines);

            // Draw lines.
            drawingContext.DrawLine(line, topStartPoint, topEndPoint);
            drawingContext.DrawLine(line, middleStartPoint, middleEndPoint);
            drawingContext.DrawLine(line, bottomStartPoint, bottomEndPoint);

            drawingContext.Pop();
        }
        protected override void OnRender(DrawingContext dc)
        {
            GuidelineSet gs = new GuidelineSet(new double[] { 0.5 }, new double[] { 0.5 });

            dc.PushGuidelineSet(gs);

            new VerticalPhysicalAxis(new LinearAxis(0, 71), 300, 10, 50).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 72), 300, 10, 100).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 73), 300, 10, 150).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 74), 300, 10, 200).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 75), 300, 10, 250).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 76), 300, 10, 300).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 77), 300, 10, 350).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 78), 300, 10, 400).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 79), 300, 10, 450).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 80), 300, 10, 500).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 81), 300, 10, 550).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 82), 300, 10, 600).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 83), 300, 10, 650).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 84), 300, 10, 700).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 85), 300, 10, 750).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 86), 300, 10, 800).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 87), 300, 10, 850).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 88), 300, 10, 900).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 89), 300, 10, 950).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 90), 300, 10, 1000).Draw(dc);

            dc.Pop();

            base.OnRender(dc);
        }
Exemple #6
0
        static public void DrawLineGuided(this DrawingContext dc, Pen pen, Point point0, Point point1)
        {
            GuidelineSet gs = new GuidelineSet();

            if (point0.X == point1.X)                   // vertical line
            {
                gs.GuidelinesY.Add(point0.Y);
                gs.GuidelinesY.Add(point1.Y);
                gs.GuidelinesX.Add(point0.X);

                // Middle of the line should be between the points!
                point0.Offset(pen.Thickness / 2, 0);
                point1.Offset(pen.Thickness / 2, 0);
            }
            else if (point0.Y == point1.Y)              // horizontal line
            {
                gs.GuidelinesX.Add(point0.X);
                gs.GuidelinesX.Add(point1.X);
                gs.GuidelinesY.Add(point0.Y);

                // Middle of the line should be between the points!
                point0.Offset(0, pen.Thickness / 2);
                point1.Offset(0, pen.Thickness / 2);
            }
            else
            {
                throw new NotImplementedException();                    // Makes no sense !?
            }
            dc.PushGuidelineSet(gs);
            dc.DrawLine(pen, point0, point1);
            dc.Pop();
        }
        /// <summary>
        /// Draws fallback icon.
        /// </summary>
        /// <param name="drawingContext">DrawingContext of canvas</param>
        /// <param name="factor">Factor from identity DPI</param>
        /// <param name="foreground">Icon foreground Brush</param>
        /// <remarks>This drawing assumes that canvas size is 16x16 by default.</remarks>
        private void Draw(DrawingContext drawingContext, double factor, Brush foreground)
        {
            var pen = new Pen(foreground, Math.Round(1D * factor) / factor);             // 1 is base path thickness.

            var rectChrome = new Rect(3, 4, 10, 8);

            var rectChromeActual = new Rect(
                rectChrome.X + pen.Thickness / 2,
                rectChrome.Y + pen.Thickness / 2,
                rectChrome.Width - pen.Thickness,
                rectChrome.Height - pen.Thickness);

            // Create a guidelines set.
            var guidelines = new GuidelineSet();

            guidelines.GuidelinesX.Add(rectChrome.Left);
            guidelines.GuidelinesX.Add(rectChrome.Right);
            guidelines.GuidelinesY.Add(rectChrome.Top);
            guidelines.GuidelinesY.Add(rectChrome.Bottom);

            drawingContext.PushGuidelineSet(guidelines);

            // Draw rectangles.
            drawingContext.DrawRectangle(null, pen, rectChromeActual);

            drawingContext.Pop();
        }
        /// <summary>
        /// Draws maximize icon.
        /// </summary>
        /// <param name="drawingContext">DrawingContext of Control</param>
        /// <param name="factor">Factor from identity DPI</param>
        /// <param name="foreground">Icon foreground Brush</param>
        /// <remarks>This drawing assumes that its size is 10x10.</remarks>
        protected override void Draw(DrawingContext drawingContext, double factor, Brush foreground)
        {
            var line       = new Pen(foreground, Math.Round(1D * factor) / factor);       // 1 is base path thickness.
            var lineRadius = line.Thickness / 2;

            var rectChrome = new Rect(0, 0, 10, 10);

            var rectChromeActual = new Rect(
                rectChrome.X + lineRadius,
                rectChrome.Y + lineRadius,
                rectChrome.Width - lineRadius,
                rectChrome.Height - lineRadius);

            // Create a guidelines set.
            var guidelines = new GuidelineSet();

            guidelines.GuidelinesX.Add(rectChrome.Left);
            guidelines.GuidelinesX.Add(rectChrome.Right);
            guidelines.GuidelinesY.Add(rectChrome.Top);
            guidelines.GuidelinesY.Add(rectChrome.Bottom);

            drawingContext.PushGuidelineSet(guidelines);

            // Draw rectangles.
            drawingContext.DrawRectangle(null, line, rectChromeActual);

            drawingContext.Pop();
        }
Exemple #9
0
        protected override void OnRender(DrawingContext dc)
        {
            GuidelineSet gs = new GuidelineSet(new double[] { 0.5 }, new double[] { 0.5 });

            dc.PushGuidelineSet(gs);

            new VerticalPhysicalAxis(new LinearAxis(0, 31), 300, 10, 50).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 32), 300, 10, 100).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 33), 300, 10, 150).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 34), 300, 10, 200).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 35), 300, 10, 250).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 36), 300, 10, 300).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 37), 300, 10, 350).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 38), 300, 10, 400).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 39), 300, 10, 450).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 40), 300, 10, 500).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 41), 300, 10, 550).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 42), 300, 10, 600).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 43), 300, 10, 650).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 44), 300, 10, 700).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 45), 300, 10, 750).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 46), 300, 10, 800).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 47), 300, 10, 850).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 48), 300, 10, 900).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 49), 300, 10, 950).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 50), 300, 10, 1000).Draw(dc);

            dc.Pop();

            base.OnRender(dc);
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            // Calculate DPI factor
            Matrix matrix    = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
            double dpiFactor = 1.0 / matrix.M11;

            // Rectangle
            Rect rect          = new Rect(AdornedElement.DesiredSize);
            Rect selectionRect = new Rect(rect.X - 1, rect.Y - 1, rect.Width + 2, rect.Height + 2);

            // Create pen
            Pen pen = new Pen(Brushes.Blue, 1 * dpiFactor);

            // Create a guidelines set for on-pixel drawing
            GuidelineSet guidelines = new GuidelineSet();

            guidelines.GuidelinesX.Add(selectionRect.Left + pen.Thickness / 2);
            guidelines.GuidelinesX.Add(selectionRect.Right + pen.Thickness / 2);
            guidelines.GuidelinesY.Add(selectionRect.Top + pen.Thickness / 2);
            guidelines.GuidelinesY.Add(selectionRect.Bottom + pen.Thickness / 2);

            // Draw
            drawingContext.PushGuidelineSet(guidelines);
            drawingContext.DrawRectangle(null, pen, selectionRect);
            drawingContext.Pop();
        }
        protected override void OnRender(DrawingContext dc)
        {
            GuidelineSet gs = new GuidelineSet(new double[] { 0.5 }, new double[] { 0.5 });

            dc.PushGuidelineSet(gs);

            new VerticalPhysicalAxis(new LinearAxis(0, 10), 300, 10, 50).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 11), 300, 10, 100).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 12), 300, 10, 150).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 13), 300, 10, 200).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 14), 300, 10, 250).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 15), 300, 10, 300).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 16), 300, 10, 350).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 17), 300, 10, 400).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 18), 300, 10, 450).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 19), 300, 10, 500).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 21), 300, 10, 550).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 22), 300, 10, 600).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 23), 300, 10, 650).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 24), 300, 10, 700).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 25), 300, 10, 750).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 26), 300, 10, 800).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 27), 300, 10, 850).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 28), 300, 10, 900).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 29), 300, 10, 950).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 30), 300, 10, 1000).Draw(dc);

            dc.Pop();

            base.OnRender(dc);
        }
Exemple #12
0
        protected override void OnRender(DrawingContext dc)
        {
            GuidelineSet gs = new GuidelineSet(new double[] { 0.5 }, new double[] { 0.5 });

            dc.PushGuidelineSet(gs);

            new VerticalPhysicalAxis(new LinearAxis(0, 91), 300, 10, 50).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 92), 300, 10, 100).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 93), 300, 10, 150).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 94), 300, 10, 200).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 95), 300, 10, 250).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 96), 300, 10, 300).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 97), 300, 10, 350).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 98), 300, 10, 400).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 99), 300, 10, 450).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 100), 300, 10, 500).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 101), 300, 10, 550).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 102), 300, 10, 600).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 103), 300, 10, 650).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 104), 300, 10, 700).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 105), 300, 10, 750).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 106), 300, 10, 800).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 107), 300, 10, 850).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 108), 300, 10, 900).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 109), 300, 10, 950).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 110), 300, 10, 1000).Draw(dc);

            dc.Pop();

            base.OnRender(dc);
        }
Exemple #13
0
        public void DrawLine(object dc, IStyle style, XLine line)
        {
            double thickness = style.Thickness / Zoom;
            double half      = thickness / 2.0;

            var pen = new Pen(
                new SolidColorBrush(
                    Color.FromArgb(
                        (byte)style.Stroke.A,
                        (byte)style.Stroke.R,
                        (byte)style.Stroke.G,
                        (byte)style.Stroke.B)),
                thickness);

            pen.Freeze();

            var gs = new GuidelineSet(
                new double[] { line.X1 + half, line.X2 + half },
                new double[] { line.Y1 + half, line.Y2 + half });

            (dc as DrawingContext).PushGuidelineSet(gs);

            (dc as DrawingContext).DrawLine(
                pen,
                new Point(line.X1, line.Y1),
                new Point(line.X2, line.Y2));

            (dc as DrawingContext).Pop();
        }
Exemple #14
0
        private void Render(DrawingContext drawingContext)
        {
            // Map wasn't set yet - nothing to render
            if (_tab is null || CellSize == 0)
            {
                return;
            }

            // assure pixel perfect drawing
            var halfPenWidth = LineWidth / 2;
            var guidelines   = new GuidelineSet();

            guidelines.GuidelinesX.Add(halfPenWidth);
            guidelines.GuidelinesY.Add(halfPenWidth);
            guidelines.Freeze();
            drawingContext.PushGuidelineSet(guidelines);

            // draw background
            drawingContext.DrawRectangle(Brushes.White, null, new Rect(new Point(), RenderSize));

            RenderGraph(drawingContext);
            RenderGrid(drawingContext);

            if (_rootVM?.RenderPaths ?? false)
            {
                RenderPaths(drawingContext);
            }

            RenderTiles(drawingContext);

            // pop back guidelines set
            drawingContext.Pop();
        }
Exemple #15
0
        /// <summary>
        /// DrawRowLines
        /// </summary>
        /// <param name="drawingContext"></param>
        /// <param name="startIndex"></param>
        /// <param name="rowCount"></param>
        /// <param name="plusOffset">True 为+pen.Thickness/2 False为-pen.Thickness/2</param>
        /// <param name="pen"></param>
        private void DrawRowLines(DrawingContext drawingContext, int startIndex, int rowCount, bool plusOffset, Pen pen)
        {
            var halfPenWidth = pen.Thickness / 2;

            var displayCount = Convert.ToInt32(Math.Floor(Element.RenderSize.Height / Element.RowHeight));

            var point0 = new Point(0, 0);
            var point1 = new Point(Element.RenderSize.Width, 0);

            var guidelines = new GuidelineSet();

            //根据HeadListBox来对齐,减去halfPenHeight

            var y = plusOffset ? halfPenWidth : -(halfPenWidth);

            for (var i = 0; 0 <= startIndex && i < displayCount && startIndex < rowCount; startIndex++, i++)
            {
                y       += Element.RowHeight;
                point0.Y = y;
                point1.Y = y;

                guidelines.GuidelinesY = new DoubleCollection(new[] { y - halfPenWidth, y + halfPenWidth });
                drawingContext.PushGuidelineSet(guidelines);
                drawingContext.DrawLine(pen, point0, point1);
                drawingContext.Pop();
            }
        }
Exemple #16
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (pen == null)
            {
                pen = new Pen(stroke, strokeThickness);
            }
            else
            {
                pen.Brush     = stroke;
                pen.Thickness = strokeThickness;
            }

            Rect   rect = new Rect(start, end);
            double half = pen.Thickness / 2;

            GuidelineSet guidelines = new GuidelineSet();

            guidelines.GuidelinesX.Add(rect.Left + half);
            guidelines.GuidelinesX.Add(rect.Right + half);
            guidelines.GuidelinesY.Add(rect.Top + half);
            guidelines.GuidelinesY.Add(rect.Bottom + half);

            drawingContext.PushGuidelineSet(guidelines);
            drawingContext.DrawRectangle(fill, pen, rect);
            drawingContext.Pop();
        }
        protected override void OnRender(DrawingContext dc)
        {
            GuidelineSet gs = new GuidelineSet(new double[] { 0.5 }, new double[] { 0.5 });

            dc.PushGuidelineSet(gs);

            new VerticalPhysicalAxis(new LinearAxis(0, 51), 300, 10, 50).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 52), 300, 10, 100).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 53), 300, 10, 150).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 54), 300, 10, 200).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 55), 300, 10, 250).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 56), 300, 10, 300).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 57), 300, 10, 350).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 58), 300, 10, 400).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 59), 300, 10, 450).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 60), 300, 10, 500).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 61), 300, 10, 550).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 62), 300, 10, 600).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 63), 300, 10, 650).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 64), 300, 10, 700).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 65), 300, 10, 750).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 66), 300, 10, 800).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 67), 300, 10, 850).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 68), 300, 10, 900).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 69), 300, 10, 950).Draw(dc);
            new VerticalPhysicalAxis(new LinearAxis(0, 70), 300, 10, 1000).Draw(dc);

            dc.Pop();

            base.OnRender(dc);
        }
Exemple #18
0
        protected override void OnRender(DrawingContext dc, double renderWidth)
        {
            // This may be true if the UI for a column hasn't been loaded yet (e.g., restoring multiple tabs from workspace won't load each tab until it's clicked by the user)
            if (gridPen == null)
            {
                if (UiWrapper != null && PresentationSource.FromVisual(UiWrapper) != null)
                {
                    Matrix m         = PresentationSource.FromVisual(UiWrapper).CompositionTarget.TransformToDevice;
                    double dpiFactor = 1 / m.M11;
                    gridPen      = new Pen(Application.Current.TryFindResource("BorderThinBrush") as Brush, 1 * dpiFactor);
                    halfPenWidth = gridPen.Thickness * 0.5;
                }
            }

            this.renderWidth = renderWidth;
            double verticalOffset = -gridPen.Thickness;
            double pixelsPerDip   = VisualTreeHelper.GetDpi(UiWrapper).PixelsPerDip;

            lock (SuperDom.Rows)
                foreach (PriceRow row in SuperDom.Rows)
                {
                    // Draw cell
                    if (this.renderWidth - halfPenWidth >= 0)
                    {
                        Rect rect = new Rect(-halfPenWidth, verticalOffset, this.renderWidth - halfPenWidth, SuperDom.ActualRowHeight);

                        // Create a guidelines set
                        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);

                        dc.PushGuidelineSet(guidelines);
                        dc.DrawRectangle(BackColor, null, rect);
                        dc.DrawLine(gridPen, new Point(-gridPen.Thickness, rect.Bottom), new Point(this.renderWidth - halfPenWidth, rect.Bottom));
                        dc.DrawLine(gridPen, new Point(rect.Right, verticalOffset), new Point(rect.Right, rect.Bottom));
                        // Print APQ value - remember to set MaxTextWidth so text doesn't spill into another column
                        long apq;
                        if (priceApqValues.TryGetValue(row.Price, out apq) && apq > 0)
                        {
                            fontFamily = SuperDom.Font.Family;
                            typeFace   = new Typeface(fontFamily, SuperDom.Font.Italic ? FontStyles.Italic : FontStyles.Normal, SuperDom.Font.Bold ? FontWeights.Bold : FontWeights.Normal, FontStretches.Normal);

                            if (this.renderWidth - 6 > 0)
                            {
                                FormattedText noteText = new FormattedText(apq != long.MinValue ? apq.ToString(Core.Globals.GeneralOptions.CurrentCulture) : "N/A", Core.Globals.GeneralOptions.CurrentCulture, FlowDirection.LeftToRight, typeFace, SuperDom.Font.Size, ForeColor, pixelsPerDip)
                                {
                                    MaxLineCount = 1, MaxTextWidth = this.renderWidth - 6, Trimming = TextTrimming.CharacterEllipsis
                                };
                                dc.DrawText(noteText, new Point(0 + 4, verticalOffset + (SuperDom.ActualRowHeight - noteText.Height) / 2));
                            }
                        }

                        dc.Pop();
                        verticalOffset += SuperDom.ActualRowHeight;
                    }
                }
        }
Exemple #19
0
        private static GuidelineSet CreateGuidelineSet(Pen pen, Rect rect)
        {
            var halfPenWidth = pen.Thickness / 2;
            var guidelines   = new GuidelineSet(new[] { rect.Left - halfPenWidth, rect.Right - halfPenWidth },
                                                new [] { rect.Top - halfPenWidth, rect.Bottom - halfPenWidth });

            return(guidelines);
        }
Exemple #20
0
        private GuidelineSet CreateGuidelineSet(Pen pen)
        {
            GuidelineSet guidelineSet = new GuidelineSet();

            guidelineSet.GuidelinesX.Add(pen.Thickness / 2);
            guidelineSet.GuidelinesY.Add(pen.Thickness / 2);
            return(guidelineSet);
        }
        private void DrawImage(DrawingContext dc, Rect rect)
        {
            if (BackgroundStyle == BackgroundStyle.SolidColor)
            {
                if (this.Background is SolidColorBrush)
                {
                    dc.DrawRectangle(Background, null, rect);
                }
            }
            else if (BackgroundStyle == BackgroundStyle.Image)
            {
                if (this.Background is ImageBrush imageBrush)
                {
                    ImageSource source = imageBrush.ImageSource;
                    if (source != null)
                    {
                        if (IsNineGrid)
                        {
                            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)
                                {
                                    ImageBrush brush = new ImageBrush(source);
                                    brush.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
                        {
                            ImageBrush brush = new ImageBrush(source);
                            dc.DrawRectangle(brush, null, rect);
                        }
                    }
                }
                else
                {
                    Pen p = (Pen)this.FindResource("ERROR_STROKE_PEN");
                    dc.DrawRectangle(null, p, rect);
                    dc.DrawLine(p, new Point(rect.Left, rect.Top), new Point(rect.Right, rect.Bottom));
                    dc.DrawLine(p, new Point(rect.Left, rect.Bottom), new Point(rect.Right, rect.Top));
                }
            }
        }
Exemple #22
0
        protected override void OnRender(DrawingContext dc)
        {
            Pen leftPen   = new Pen(BorderBrush, BorderThickness.Left);
            Pen topPen    = new Pen(BorderBrush, BorderThickness.Top);
            Pen rightPen  = new Pen(BorderBrush, BorderThickness.Right);
            Pen bottomPen = new Pen(BorderBrush, BorderThickness.Bottom);

            double w = RenderSize.Width;
            double h = RenderSize.Height;

            // Top and bottom frills
            double frillStart = 8;
            double frillStop  = w - 8;

            if (frillStop - frillStart - 8 > 0)
            {
                // Top frill
                PathFigure p1 = new PathFigure(new Point(frillStart, 0), new PathSegment[] { }, false);

                p1.Segments.Add(new LineSegment(new Point(frillStart + 4, -4), true));
                p1.Segments.Add(new LineSegment(new Point(frillStop - 4, -4), true));
                p1.Segments.Add(new LineSegment(new Point(frillStop, 0), true));

                GuidelineSet frillGuidelines = new GuidelineSet();
                frillGuidelines.GuidelinesY.Add(-4 - BorderThickness.Top / 2);
                frillGuidelines.GuidelinesY.Add(-4 + BorderThickness.Top / 2);

                PathFigure p2 = new PathFigure(new Point(frillStart, h), new PathSegment[] { }, false);

                p2.Segments.Add(new LineSegment(new Point(frillStart + 4, h + 4), true));
                p2.Segments.Add(new LineSegment(new Point(frillStop - 4, h + 4), true));
                p2.Segments.Add(new LineSegment(new Point(frillStop, h), true));

                frillGuidelines.GuidelinesY.Add(h + 4 - BorderThickness.Top / 2);
                frillGuidelines.GuidelinesY.Add(h + 4 + BorderThickness.Top / 2);

                PathGeometry g = new PathGeometry(new PathFigure[] { p1, p2 });
                dc.PushGuidelineSet(frillGuidelines);
                dc.DrawGeometry(Background, topPen, g);
                dc.Pop();
            }

            // Main border square
            GuidelineSet guidelines = new GuidelineSet();

            guidelines.GuidelinesX.Add(0 - BorderThickness.Left / 2);
            guidelines.GuidelinesX.Add(0 + BorderThickness.Left / 2);
            guidelines.GuidelinesX.Add(w - BorderThickness.Right / 2);
            guidelines.GuidelinesX.Add(w + BorderThickness.Right / 2);
            guidelines.GuidelinesY.Add(0 - BorderThickness.Top / 2);
            guidelines.GuidelinesY.Add(0 + BorderThickness.Top / 2);
            guidelines.GuidelinesY.Add(h - BorderThickness.Bottom / 2);
            guidelines.GuidelinesY.Add(h + BorderThickness.Bottom / 2);
            dc.PushGuidelineSet(guidelines);
            dc.DrawRectangle(Background, topPen, new Rect(0, 0, w, h));
            dc.Pop();
        }
Exemple #23
0
        private void ComposeForegroundVisual()
        {
            if (null == editorCommands || (editorCommands.Count <= 0))
            {
                return; // Nothing to render here...
            }
            // The indices of the current rendered box. The indices are for use in
            // 'editorCommands' so they are relative to the beginning of the list.
            if (null == commandIndices)
            {
                commandIndices = new List <int>();
            }

            int commandIndex = 0;

            commandIndices.Clear();

            using (DrawingContext context = foregroundVisual.RenderOpen())
            {
                double actualWidth  = Math.Floor(this.ActualWidth);
                Rect   clippingRect = new Rect(0, 0, this.ActualWidth, this.ActualHeight);
                context.PushClip(new RectangleGeometry(clippingRect));

                // The number of boxes we can fit in a row.
                boxesPerRow = (int)Math.Floor(actualWidth / (dimension + margin));

                GuidelineSet guidelines   = new GuidelineSet();
                double       halfPenWidth = borderLine.Thickness * 0.5;
                guidelines.GuidelinesX.Add(dimension + halfPenWidth);
                guidelines.GuidelinesY.Add(dimension + halfPenWidth);
                context.PushGuidelineSet(guidelines);

                Rect boxedRegion = new Rect(margin, margin, dimension, dimension);
                foreach (TextEditorCommand command in editorCommands)
                {
                    context.DrawRectangle(null, borderLine, boxedRegion);
                    boxedRegion = AdvanceToNextBlock(boxedRegion, actualWidth);

                    commandIndices.Add(commandIndex);
                    if (null != command.Asserts && (command.Asserts.Count > 0))
                    {
                        foreach (CommandAssert assert in command.Asserts)
                        {
                            commandIndices.Add(commandIndex);
                            context.DrawRectangle(null, borderLine, boxedRegion);
                            context.DrawLine(borderLine, boxedRegion.TopLeft, boxedRegion.BottomRight);
                            boxedRegion = AdvanceToNextBlock(boxedRegion, actualWidth);
                        }
                    }

                    commandIndex = commandIndex + 1;
                }

                context.Pop();
            }
        }
Exemple #24
0
        /// <summary>
        /// 绘制控件
        /// </summary>
        /// <param name="drawingContext"></param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (Child != null)
            {
                Geometry cg    = null;
                Brush    brush = null;
                //DpiScale dpi = base.getd();
                Pen pen = new Pen();

                pen.Brush = this.BorderBrush;
                //pen.Thickness = BorderThickness * 0.5;
                pen.Thickness = UIElementExtension.RoundLayoutValue(BorderThickness.Left, DoubleUtil.DpiScaleX);

                switch (Placement)
                {
                case EnumPlacement.LeftTop:
                case EnumPlacement.LeftBottom:
                case EnumPlacement.LeftCenter:
                    //生成小尾巴在左侧的图形和底色
                    cg    = CreateGeometryTailAtLeft();
                    brush = CreateFillBrush();
                    break;

                case EnumPlacement.RightTop:
                case EnumPlacement.RightCenter:
                case EnumPlacement.RightBottom:
                    //生成小尾巴在右侧的图形和底色
                    cg    = CreateGeometryTailAtRight();
                    brush = CreateFillBrush();
                    break;

                case EnumPlacement.TopLeft:
                case EnumPlacement.TopCenter:
                case EnumPlacement.TopRight:
                    //生成小尾巴在右侧的图形和底色
                    cg    = CreateGeometryTailAtTop();
                    brush = CreateFillBrush();
                    break;

                case EnumPlacement.BottomLeft:
                case EnumPlacement.BottomCenter:
                case EnumPlacement.BottomRight:
                    //生成小尾巴在右侧的图形和底色
                    cg    = CreateGeometryTailAtBottom();
                    brush = CreateFillBrush();
                    break;

                default:
                    break;
                }

                GuidelineSet guideLines = new GuidelineSet();
                drawingContext.PushGuidelineSet(guideLines);
                drawingContext.DrawGeometry(brush, pen, cg);
            }
        }
Exemple #25
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();
            }
        }
Exemple #26
0
        public void DrawLine(double x1, double y1, double x2, double y2, SequenceLineType lineType, SequenceArrowType arrowHead)
        {
            Pen    pen          = lineType == SequenceLineType.Solid ? m_solidLinePen : m_dashedLinePen;
            double halfPenWidth = m_solidLinePen.Thickness / 2;

            GuidelineSet guidelines = new GuidelineSet();

            guidelines.GuidelinesX.Add(x1 + halfPenWidth);
            guidelines.GuidelinesX.Add(x2 + halfPenWidth);
            guidelines.GuidelinesY.Add(y1 + halfPenWidth);
            guidelines.GuidelinesY.Add(y2 + halfPenWidth);

            m_drawingContext.PushGuidelineSet(guidelines);

            // Draw the main line segment
            Point start = new Point(x1, y1);
            Point end   = new Point(x2, y2);

            DrawLine(m_drawingContext, pen, start, end);

            // Draw the arrowhead
            double direction = (x1 > x2) ? 1 : -1;
            Point  arrow0    = new Point(end.X + direction * LineThickness, end.Y);
            Point  arrow1    = new Point(x2 + direction * s_arrowHeadSize.Width, y2 - s_arrowHeadSize.Height);
            Point  arrow2    = new Point(x2 + direction * s_arrowHeadSize.Width, y2 + s_arrowHeadSize.Height);

            switch (arrowHead)
            {
            case SequenceArrowType.Filled:
            {
                var streamGeometry = new StreamGeometry();
                using (StreamGeometryContext geometryContext = streamGeometry.Open())
                {
                    geometryContext.BeginFigure(arrow0, true, true);
                    PointCollection points = new PointCollection {
                        arrow1, arrow2
                    };
                    geometryContext.PolyLineTo(points, true, true);
                }

                streamGeometry.Freeze();
                m_drawingContext.DrawGeometry(m_arrowBrush, m_solidLinePen, streamGeometry);
                break;
            }

            case SequenceArrowType.Open:
            {
                m_drawingContext.DrawLine(m_solidLinePen, arrow0, arrow1);
                m_drawingContext.DrawLine(m_solidLinePen, arrow0, arrow2);
                break;
            }
            }

            m_drawingContext.Pop();
        }
Exemple #27
0
        protected void BeginGuidelineSet(DrawingContext dc)
        {
            var guidelines = new GuidelineSet();

            guidelines.GuidelinesX.Add(this.Fit(1) / 2);
            guidelines.GuidelinesX.Add(this.Fit(1) / 2);
            guidelines.GuidelinesY.Add(this.Fit(1) / 2);
            guidelines.GuidelinesY.Add(this.Fit(1) / 2);

            dc.PushGuidelineSet(guidelines);
        }
Exemple #28
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);
                }
            }
        }
Exemple #29
0
        private void DrawGuideLine(DrawingContext dc, BasicStyleCache cache, GuidePoint point0, GuidePoint point1)
        {
            var gs = new GuidelineSet(
                new double[] { point0.X + cache.HalfThickness, point1.X + cache.HalfThickness },
                new double[] { point0.Y + cache.HalfThickness, point1.Y + cache.HalfThickness });

            gs.Freeze();
            dc.PushGuidelineSet(gs);
            dc.DrawLine(cache.StrokePen, new Point(point0.X, point0.Y), new Point(point1.X, point1.Y));
            dc.Pop();
        }
        public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl)
        {
            var colorConv = ((BrushAdapter)_adapter.GetSolidBrush(color)).Brush;

            bool          glyphRendered = false;
            GlyphTypeface glyphTypeface = ((FontAdapter)font).GlyphTypeface;

            if (glyphTypeface != null)
            {
                double   width  = 0;
                ushort[] glyphs = new ushort[str.Length];
                double[] widths = new double[str.Length];

                int i = 0;
                for (; i < str.Length; i++)
                {
                    ushort glyph;
                    if (!glyphTypeface.CharacterToGlyphMap.TryGetValue(str[i], out glyph))
                    {
                        break;
                    }

                    glyphs[i] = glyph;
                    width    += glyphTypeface.AdvanceWidths[glyph];
                    widths[i] = 96d / 72d * font.Size * glyphTypeface.AdvanceWidths[glyph];
                }

                if (i >= str.Length)
                {
                    point.Y += glyphTypeface.Baseline * font.Size * 96d / 72d;
                    point.X += rtl ? 96d / 72d * font.Size * width : 0;

                    glyphRendered = true;
                    var wpfPoint = Utils.ConvertRound(point);
                    var glyphRun = new GlyphRun(glyphTypeface, rtl ? 1 : 0,
                                                false, 96d / 72d * font.Size, glyphs,
                                                wpfPoint, widths, null, null, null, null, null, null);

                    var guidelines = new GuidelineSet();
                    guidelines.GuidelinesX.Add(wpfPoint.X);
                    guidelines.GuidelinesY.Add(wpfPoint.Y);
                    _g.PushGuidelineSet(guidelines);
                    _g.DrawGlyphRun(colorConv, glyphRun);
                    _g.Pop();
                }
            }

            if (!glyphRendered)
            {
                var formattedText = new FormattedText(str, CultureInfo.CurrentCulture, rtl ? FlowDirection.RightToLeft : FlowDirection.LeftToRight, ((FontAdapter)font).Font, 96d / 72d * font.Size, colorConv);
                point.X += rtl ? formattedText.Width : 0;
                _g.DrawText(formattedText, Utils.ConvertRound(point));
            }
        }