protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
    {
        base.OnRender(drawingContext);
        var                root               = Window.GetWindow(this);
        var                adornerLayer       = AdornerLayer.GetAdornerLayer(AdornedElement);
        var                presentationSource = PresentationSource.FromVisual(adornerLayer);
        Matrix             transformToDevice  = presentationSource.CompositionTarget.TransformToDevice;
        var                sizeInPixels       = transformToDevice.Transform((Vector)adornerLayer.RenderSize);
        RenderTargetBitmap rtb           = new RenderTargetBitmap((int)(sizeInPixels.X), (int)(sizeInPixels.Y), 96, 96, PixelFormats.Default);
        var                oldEffect     = root.Effect;
        var                oldVisibility = AdornedElement.Visibility;

        root.Effect = new BlurEffect();
        AdornedElement.SetCurrentValue(FrameworkElement.VisibilityProperty, Visibility.Hidden);
        rtb.Render(root);
        AdornedElement.SetCurrentValue(FrameworkElement.VisibilityProperty, oldVisibility);
        root.Effect = oldEffect;
        drawingContext.DrawImage(rtb, adornerLayer.TransformToVisual(AdornedElement).TransformBounds(new Rect(adornerLayer.RenderSize)));
        drawingContext.DrawRectangle(new SolidColorBrush(Color.FromArgb(22, 0, 0, 0)), null, adornerLayer.TransformToVisual(AdornedElement).TransformBounds(new Rect(adornerLayer.RenderSize)));
        drawingContext.DrawRectangle(new VisualBrush(AdornedElement)
        {
            AlignmentX = AlignmentX.Left, TileMode = TileMode.None, Stretch = Stretch.None
        },
                                     null,
                                     AdornedElement.RenderTransform.TransformBounds(new Rect(AdornedElement.RenderSize)));
    }
        /// <summary>Clear canvas with color according to region</summary>
        public void Clear(float x, float y, float width, float height, Color color)
        {
            var color_ = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb((byte)color.A, (byte)color.R, (byte)color.G, (byte)color.B));
            var rect   = new Rect(x, y, width, height);

            PushRenderStates();
            _drawingContext.DrawRectangle(color_, null, rect);
            PopRenderStates();
        }
Beispiel #3
0
        protected override void InnerDraw(GraphicsDisplay display, GeoStar.Core.TrackCancel cancel)
        {
            if (m_TileList.Count == 0)
            {
                return;
            }

            List <QuadTile> vList = new List <QuadTile>();

            lock (this)
            {
                vList.AddRange(m_TileList);
            }
            System.Windows.Media.DrawingContext dc = display.DrawingContext;
            foreach (var item in vList)
            {
                Box box = m_Pyramid.TileExtent(item.Level, item.Row, item.Col);
                System.Windows.Rect rect = display.DT.FromMapWPF(box);

                dc.DrawRectangle(null,
                                 new System.Windows.Media.Pen(System.Windows.Media.Brushes.Red, 1), rect);

                System.Windows.Media.FormattedText formattedText = new System.Windows.Media.FormattedText(
                    string.Format(" {0},{1},{2}", item.Level, item.Row, item.Col),
                    System.Globalization.CultureInfo.CurrentCulture,
                    System.Windows.FlowDirection.LeftToRight,
                    new  System.Windows.Media.Typeface("微软雅黑"),
                    12,
                    System.Windows.Media.Brushes.Black);


                dc.DrawText(formattedText, rect.Location);
            }
        }
 protected override void OnRender(System.Windows.Media.DrawingContext dc)
 {
     base.OnRender(dc);
     for (int i = 0; i < rects.Count; i++)
     {
         MyRect mRect = rects[i];
         dc.DrawRectangle(mRect.Brush, null, mRect.Rect);
     }
 }
    protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
    {
        Console.WriteLine("OnRender");
        //base.OnRender(drawingContext);
        Rect  bounds = new Rect(0, 0, 100, 100);
        Brush brush  = new SolidColorBrush(Colors.Yellow);

        drawingContext.DrawRectangle(brush, null, bounds);
    }
Beispiel #6
0
        private ToolStripMenuItem SetFonts()
        {
            ToolStripMenuItem menuItem = new ToolStripMenuItem("Insert Font");

            List <string> fonts = new List <string>();

            foreach (System.Windows.Media.FontFamily font in System.Windows.Media.Fonts.SystemFontFamilies) //WPF fonts
            {
                fonts.Add(font.FamilyNames.Values.First());
            }
            fonts.Sort();

            foreach (string fontName in fonts)
            {
                Bitmap bmp = null;
                try
                {
                    int size = 20;
                    //bmp = new Bitmap(4 * size, 5 * size / 4);
                    //Graphics g = Graphics.FromImage(bmp);
                    //g.SmoothingMode = SmoothingMode.HighQuality;
                    //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    //g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    //g.DrawString("Basic", new Font(new FontFamily(fontName), size, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.Black, 1, 1);

                    System.Windows.Media.DrawingVisual dv = new System.Windows.Media.DrawingVisual();
                    using (System.Windows.Media.DrawingContext dc = dv.RenderOpen())
                    {
                        dc.DrawRectangle(System.Windows.Media.Brushes.White, null, new System.Windows.Rect(0, 0, 4 * size, 5 * size / 4));
                        dc.DrawText(new System.Windows.Media.FormattedText("Basic", System.Globalization.CultureInfo.InvariantCulture,
                                                                           System.Windows.FlowDirection.LeftToRight, new System.Windows.Media.Typeface(fontName), size,
                                                                           System.Windows.Media.Brushes.Black), new System.Windows.Point(1, 1));
                    }
                    System.Windows.Media.Imaging.RenderTargetBitmap rtb = new System.Windows.Media.Imaging.RenderTargetBitmap(4 * size, 5 * size / 4, 96, 96, System.Windows.Media.PixelFormats.Pbgra32);
                    rtb.Render(dv);
                    rtb.Freeze();
                    MemoryStream stream = new MemoryStream();
                    System.Windows.Media.Imaging.BitmapEncoder encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder();
                    encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(rtb));
                    encoder.Save(stream);
                    bmp = new Bitmap(stream);
                }
                catch
                {
                }

                ToolStripMenuItem item = new ToolStripMenuItem(fontName, bmp, Insert);
                item.ImageScaling = ToolStripItemImageScaling.None;

                menuItem.DropDownItems.Add(item);
            }

            return(menuItem);
        }
        /// <summary>Draw Rectangle to canvas according to region</summary>
        public void DrawRectangle(float x, float y, float width, float height)
        {
            var draw = (_fillColor.Color.A > 0) || (_strokeColor.Color.A > 0);

            if (draw)
            {
                var clipped = PushRenderStates();

                var rect = new Rect(x, y, width, height);

                if (_fillColor.Color.A > 0)
                {
                    _drawingContext.DrawRectangle(_fillColor, null, rect);
                }

                if (_strokeColor.Color.A > 0)
                {
                    _drawingContext.DrawRectangle(null, _stroke.Clone(), rect);
                }

                PopRenderStates(clipped);
            }
        }
Beispiel #8
0
    protected override void OnRender(System.Windows.Media.DrawingContext dc)
    {
        base.OnRender(dc);
        if (Grid == null || Grid.SelectedItems == null)
        {
            return;
        }
        object[] markers        = Grid.SelectedItems.OfType <object>().ToArray();
        double   translateDelta = ActualHeight / (double)Grid.Items.Count;
        double   width          = ActualWidth;
        double   height         = Math.Max(translateDelta, 4);
        Brush    dBrush         = MarkerBrush;

        for (int i = 0; i < markers.Length; i++)
        {
            double itemIndex = Grid.Items.IndexOf(markers[i]);
            double top       = itemIndex * translateDelta;
            dc.DrawRectangle(dBrush, null, new Rect(0, top, width, height));
        }
    }
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            drawingContext.DrawRectangle(System.Windows.Media.Brushes.Black, null, new Rect(RenderSize));

            if (_initialized)
            {
                Bitmap bitmap = _buffer;

                var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                var data = bitmap.LockBits(rect, ImageLockMode.ReadOnly, bitmap.PixelFormat);
                _writeableBitmap.Lock();
                Utils.CopyMemory(_writeableBitmap.BackBuffer, data.Scan0, (UInt32)(_writeableBitmap.BackBufferStride * bitmap.Height));
                _writeableBitmap.AddDirtyRect(new Int32Rect(0, 0, bitmap.Width, bitmap.Height));
                _writeableBitmap.Unlock();
                bitmap.UnlockBits(data);

                drawingContext.DrawImage(_writeableBitmap, new System.Windows.Rect(0, 0, bitmap.Width, bitmap.Height));
            }
        }
Beispiel #10
0
            protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
            {
                drawingContext.DrawRectangle(new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 255, 0, 0)),
                                             null, new Rect(RenderSize));
                if (this.TextView == null || this.TextView.VisualLinesValid == false)
                {
                    return;
                }
                foreach (VisualLine l in this.TextView.VisualLines)
                {
                    if (_break.Contains(l.FirstDocumentLine.LineNumber))
                    {
                        Point lt = new Point(1, l.VisualTop - this.TextView.VerticalOffset + 1);
                        Point rb = new Point(lt.X + this.RenderSize.Width - 4, lt.Y + l.Height - 2);
                        drawingContext.DrawRoundedRectangle(new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 0, 0)),
                                                            null,
                                                            new Rect(lt, rb), (rb.X - lt.X) / 2, (rb.Y - lt.Y) / 2);
                    }
                }

                //base.OnRender(drawingContext);
            }
Beispiel #11
0
        public static void CreateRemappedRasterFromVector(string xamlFile, System.Windows.Media.Color newColor, System.IO.Stream stream, double height, double width, string dynamicText)
        {
            string remapBase = "ReMapMe_";
            int    max       = 3;
            int    index     = 0;
            int    missed    = 0;
            Object temp      = null;
            string dynamText = "DynamicText";

            System.Windows.Controls.Canvas theVisual = System.Windows.Markup.XamlReader.Load(new System.IO.FileStream(xamlFile, System.IO.FileMode.Open)) as System.Windows.Controls.Canvas;

            if (null == theVisual)
            {
                return;
            }

            System.Windows.Size size = new System.Windows.Size(width, height);

            System.Windows.Media.DrawingVisual drawingVisual = new System.Windows.Media.DrawingVisual();

            System.Windows.Media.VisualBrush visualBrush = new System.Windows.Media.VisualBrush(theVisual);

            System.Windows.Rect rect = new System.Windows.Rect(new System.Windows.Point(), size);

            while (missed < max)
            {
                string elementid = remapBase + index;

                temp = theVisual.FindName(elementid);

                if (null == temp)
                {
                    missed++;
                    index++;
                    continue;
                }

                System.Windows.Media.SolidColorBrush scb = ((temp as System.Windows.Shapes.Path).Fill as System.Windows.Media.SolidColorBrush);

                System.Windows.Media.Color c = scb.Color;
                c.B = newColor.B;
                c.R = newColor.R;
                c.G = newColor.G;

                scb.Color = c;
                index++;
            }

            theVisual.Arrange(rect);
            theVisual.UpdateLayout();

            using (System.Windows.Media.DrawingContext dc = drawingVisual.RenderOpen())
            {
                dc.DrawRectangle(visualBrush, null, rect);
            }

            if (!dynamText.IsNullOrWhitespace())
            {
                temp = theVisual.FindName(dynamText);
                if (null != temp)
                {
                    //do dynamic text shit
                }
            }

            System.Windows.Media.Imaging.RenderTargetBitmap render = new System.Windows.Media.Imaging.RenderTargetBitmap((int)height, (int)width, 96, 96, System.Windows.Media.PixelFormats.Pbgra32);
            render.Render(drawingVisual);

            System.Windows.Media.Imaging.PngBitmapEncoder encoder = new System.Windows.Media.Imaging.PngBitmapEncoder();

            encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(render));

            encoder.Save(stream);

            stream.Flush();
            stream.Close();

            visualBrush   = null;
            drawingVisual = null;
            theVisual     = null;
            render        = null;
            encoder       = null;
        }
Beispiel #12
0
            public override DocumentPage GetPage(int pageNumber)
            {
                // This is called starting at zero, but we are really starting at the given page.
                pageNumber += startingPage;

                if (showProgressDialog)
                {
                    if (outer.controller.UpdateProgressDialog(string.Format(MiscText.PrintingPage, pageNumber + 1, outer.totalPages), (double)pageNumber / (double)outer.totalPages))
                    {
                        throw new Exception(MiscText.CancelledByUser);
                    }
                }

                Margins   margins   = new Margins(this.margins.Left, this.margins.Right, this.margins.Top, this.margins.Bottom);
                bool      landscape = outer.pageSettings.Landscape;
                PaperSize paperSize = outer.pageSettings.PaperSize;
                bool      rotate;

                outer.ChangePageSettings(pageNumber, ref landscape, ref paperSize, margins);
                rotate        = (landscape != outer.pageSettings.Landscape);
                this.pageSize = new System.Windows.Size(HundrethsToPoints(paperSize.Width), HundrethsToPoints(paperSize.Height));
                if (outer.pageSettings.Landscape)
                {
                    this.pageSize = new System.Windows.Size(this.pageSize.Height, this.pageSize.Width);
                }

                // Get margins in terms of normal page orientation, in points.
                double leftMargin   = HundrethsToPoints(rotate ? margins.Bottom : margins.Left);
                double rightMargin  = HundrethsToPoints(rotate ? margins.Top : margins.Right);
                double topMargin    = HundrethsToPoints(rotate ? margins.Left : margins.Top);
                double bottomMargin = HundrethsToPoints(rotate ? margins.Right : margins.Bottom);

                System.Windows.Rect contentRect           = new System.Windows.Rect(leftMargin, topMargin, pageSize.Width - leftMargin - rightMargin, pageSize.Height - topMargin - bottomMargin);
                System.Windows.Rect boundingRect          = new System.Windows.Rect(0, 0, pageSize.Width - leftMargin - rightMargin, pageSize.Height - topMargin - bottomMargin);
                System.Windows.Media.DrawingVisual visual = new System.Windows.Media.DrawingVisual();

                using (System.Windows.Media.DrawingContext dc = visual.RenderOpen()) {
                    if (outer.printingToBitmaps)
                    {
                        // This is kind of hacky way to get the printing to bitmaps white, but much easier than the alternative.
                        dc.DrawRectangle(System.Windows.Media.Brushes.White, null, new System.Windows.Rect(-1, -1, pageSize.Width + 2, pageSize.Height + 2));
                    }

                    // Clip to the bounding rect within margins.
                    dc.PushClip(new System.Windows.Media.RectangleGeometry(boundingRect));

                    if (rotate)
                    {
                        // Rotate and translate to handle landscape mode.
                        dc.PushTransform(new System.Windows.Media.TranslateTransform(0, boundingRect.Height));
                        dc.PushTransform(new System.Windows.Media.RotateTransform(-90));
                    }

                    // Scale to hundreths of an inch instead of points (1/96 of inch).
                    dc.PushTransform(new System.Windows.Media.ScaleTransform(96.0 / 100.0, 96.0 / 100.0));

                    IGraphicsTarget graphicsTarget;
                    if (outer.colorModel == ColorModel.RGB)
                    {
                        graphicsTarget = new WPF_GraphicsTarget(dc);
                    }
                    else if (outer.colorModel == ColorModel.CMYK)
                    {
                        graphicsTarget = new WPF_GraphicsTarget(dc, new WPFSwopColorConverter());
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }

                    using (graphicsTarget) {
                        outer.DrawPage(graphicsTarget, pageNumber, new SizeF((float)contentRect.Width, (float)contentRect.Height), dpi);
                    }
                    graphicsTarget = null;
                }

                return(new DocumentPage(visual, pageSize, contentRect, contentRect));
            }
Beispiel #13
0
        /// <summary>
        /// Border를 그리기 위한 OnRender 재정의
        /// </summary>
        /// <param name="dc"></param>
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            base.OnRender(dc);

            CustomGrid customGrid = this.Parent as CustomGrid;

            if (customGrid == null)
            {
                dc.DrawRectangle(null, line, new Rect(0, 0, this.ActualWidth, this.ActualHeight));
            }

            double linePoint = 0;
            double posFrom   = 0.0;
            double posTo     = 0.0;

            int rowCount    = Math.Max(this.RowDefinitions.Count, 1);
            int columnCount = Math.Max(this.ColumnDefinitions.Count, 1);

            bool[,] rowCellStatus;
            bool[,] columnCellStatus;

            GetRowLineCellStatus(rowCount, columnCount, out rowCellStatus, out columnCellStatus);

            if (this.ColumnDefinitions.Count != 0)
            {
                for (int row = 0; row < rowCount - 1; row++)
                {
                    var r = this.RowDefinitions[row];

                    linePoint += r.ActualHeight;
                    for (int column = 0; column < columnCount; column++)
                    {
                        bool drawLine = rowCellStatus[row + 1, column];
                        posTo += this.ColumnDefinitions[column].ActualWidth;

                        if (drawLine == true)
                        {
                            dc.DrawLine(line, new System.Windows.Point(posFrom, linePoint), new System.Windows.Point(posTo, linePoint));
                        }

                        posFrom = posTo;
                    }

                    posFrom = 0.0;
                    posTo   = 0.0;
                }
            }

            linePoint = 0;
            posFrom   = 0.0;
            posTo     = 0.0;

            if (this.RowDefinitions.Count != 0)
            {
                for (int column = 0; column < columnCount - 1; column++)
                {
                    var r = this.ColumnDefinitions[column];

                    linePoint += r.ActualWidth;
                    for (int row = 0; row < rowCount; row++)
                    {
                        bool drawLine = columnCellStatus[row, column + 1];
                        posTo += this.RowDefinitions[row].ActualHeight;

                        if (drawLine == true)
                        {
                            dc.DrawLine(line, new System.Windows.Point(linePoint, posFrom), new System.Windows.Point(linePoint, posTo));
                        }

                        posFrom = posTo;
                    }

                    posTo   = 0.0;
                    posFrom = 0.0;
                }
            }
        }
Beispiel #14
0
        protected override void ComposeCore(System.Windows.Media.DrawingContext drawingContext, System.Windows.Media.DrawingVisual visual)
        {
            //Text and Caption size
            string tempText     = string.Empty;
            double textWidth    = Utilities.GetTextWidth(this.Text);
            double captionWidth = Utilities.GetTextWidth(this.Caption);

            if (this.Text.Count() > 25)
            {
                tempText  = this.Text.Substring(0, 25);
                tempText += "...";
                textWidth = Utilities.GetTextWidth(tempText);
            }
            else
            {
                tempText = this.Text;
            }

            //Node width
            if (textWidth > captionWidth)
            {
                this.nodeDimension.Width = (int)(Configurations.NodeWidthProperty + textWidth + 1);
            }
            else
            {
                this.nodeDimension.Width = (int)(Configurations.NodeWidthProperty + captionWidth + 1);
            }

            //Node height
            this.nodeDimension.Height = Configurations.NodeHeightProperty;

            base.ComposeCore(drawingContext, visual);

            Rect rect = new Rect(new Point(1, 1), new Size((int)(this.nodeDimension.Width - 1), (int)(this.nodeDimension.Height - 1)));

            drawingContext.DrawRectangle(Configurations.RectGrey, Configurations.NoBorderPen, rect);

            //horizontal Line
            Point p1 = new Point(1, 1);

            p1.Offset(Configurations.TextHorizontalOffset, (int)(this.Height) / 2);
            p1.Offset(0, 0.5);
            Point p2 = p1;

            p2.X = (this.Width - 1) - Configurations.TextHorizontalOffset;
            drawingContext.DrawLine(Configurations.BorderPen, p1, p2);

            //draw caption and text
            p1 = new Point(1, 1);
            p1.Offset(0, Configurations.TextVerticalOffset);
            p1.X = (this.Width / 2) - captionWidth / 2;
            Utilities.DrawText(drawingContext, this.Caption, p1, Configurations.TextNormalColor);
            p1.Y = ((this.Height - 3) / 2) + Configurations.TextVerticalOffset;
            p1.X = (this.Width / 2) - textWidth / 2;
            Utilities.DrawBoldText(drawingContext, tempText, p1);

            //OutputSlot
            p1    = new Point(this.Width, (this.Height / 4));
            p1.Y += (this.Height / 2) - 2;
            DrawingUtilities.DrawDots(drawingContext, DotTypes.TopRight | DotTypes.MiddleRight | DotTypes.BottomRight, p1, AnchorPoint.TopRight, false);
            //OutputSlotHittestPixels
            p1.Y -= (this.Height / 4) - 1;
            drawingContext.DrawRectangle(Configurations.SlotHitTestColor, Configurations.NoBorderPen, new Rect(p1, new Size(Configurations.HittestPixels, this.Height / 2)));

            //NorthEast
            Point p = new Point(0, 0);

            p.Offset(this.Width, Configurations.ContextMenuMargin);
            if (dotsFlag.HasFlag(MenuDots.NorthEast))
            {
                DrawingUtilities.DrawDots(drawingContext, DotTypes.Top | DotTypes.TopRight | DotTypes.MiddleRight, p, AnchorPoint.TopRight, false);
            }

            //NorthWest
            p = new Point(0, 0);
            p.Offset(Configurations.ContextMenuMargin, Configurations.ContextMenuMargin);
            //DrawingUtilities.DrawDots(drawingContext, DotTypes.TopLeft | DotTypes.Top | DotTypes.MiddleLeft, p, AnchorPoint.TopLeft, false);

            //South
            p = new Point(0, 0);
            p.Offset(Configurations.ContextMenuMargin, this.Height);
            //DrawingUtilities.DrawDots(drawingContext, DotTypes.MiddleLeft | DotTypes.BottomLeft | DotTypes.Bottom, p, AnchorPoint.BottomLeft, false);

            //input Slots
            if (this.inputSlots.Count != 0)
            {
                p1    = new Point(-1, 1);
                p1.Y += Configurations.TextVerticalOffset + Configurations.SlotSize / 2;
                Utilities.DrawSlot(drawingContext, p1);
            }

            // Fix: IDE-1616 Geometry property previews are not showing up.
            // Fix: IDE-1623 Preview not coming for the property nodes.
            if (previewBubble != null)
            {
                this.previewBubble.Compose();
            }
        }
Beispiel #15
0
 public override void Draw(System.Windows.Media.DrawingContext drawingContext)
 {
     drawingContext.DrawRectangle(null, Outline, new Rect(StartPoint, EndPoint));
 }