예제 #1
0
        //--------------------------------------------------------------
        #region Methods
        //--------------------------------------------------------------

        private static Pen CreateFrozenPen(SolidColorBrush brush)
        {
            var pen = new Pen(brush, 1);

            pen.Freeze();
            return(pen);
        }
예제 #2
0
 public FloatExpElement()
 {
     pen3 = new Pen(ThemeManager.NoteFillBrushes[0], 3);
     pen2 = new Pen(ThemeManager.NoteFillBrushes[0], 2);
     pen3.Freeze();
     pen2.Freeze();
 }
예제 #3
0
        /// <summary>
        /// WPF RenderTargetBitmap(Freezeあり、ブラシキャッシュあり)
        /// ※即時描画
        /// </summary>
        private void Button_Click_WPF4(object sender, RoutedEventArgs e)
        {
            var stopwatch = Stopwatch.StartNew();

            var visual = new DrawingVisual();

            using (var dc = visual.RenderOpen())
            {
                var random = new Random();

                var pen = new Pen();
                pen.Thickness = 1;
                pen.Freeze();

                foreach (var point in _points)
                {
                    var brush = _brushes[random.Next(255)];

                    var rect = new Rect(point, new Size(10.0, 10.0));

                    dc.DrawRectangle(brush, pen, rect);
                }
            }

            var bitmapSource = new RenderTargetBitmap(500, 500, 96.0, 96.0, PixelFormats.Default);

            bitmapSource.Render(visual);
            bitmapSource.Freeze();

            _image.Source = bitmapSource;

            _elapse.Content = stopwatch.Elapsed.TotalSeconds.ToString();
        }
예제 #4
0
        protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)
        {
            base.DrawCore(drawingContext, drawingAttributes);

            Pen Pen = new Pen(new SolidColorBrush(Colors.Black), 1);

            Pen.Freeze();

            Point topLeft     = new Point(Math.Min(this.StylusPoints[0].X, this.StylusPoints[1].X), Math.Min(this.StylusPoints[0].Y, this.StylusPoints[1].Y));
            Point bottomRight = new Point(Math.Max(this.StylusPoints[0].X, this.StylusPoints[1].X), Math.Max(this.StylusPoints[0].Y, this.StylusPoints[1].Y));
            int   wordSize    = 17;

            drawingContext.PushTransform(new RotateTransform(Rotation, Center.X, Center.Y));

            int line = 0;

            textContent.ForEach(textLine =>
            {
                var point = topLeft;
                point.Y  += wordSize * 1.5 * line;
                if (point.Y + wordSize * 1.5 > bottomRight.Y)
                {
                    return;
                }

                FormattedText text = new FormattedText(textLine, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), wordSize, Brushes.Black);
                text.MaxTextWidth  = bottomRight.X - topLeft.X;
                text.MaxTextHeight = bottomRight.Y - point.Y;
                drawingContext.DrawText(text, point);
                line += ((int)text.Height % wordSize) / 3;
            });

            drawingContext.Pop();
        }
예제 #5
0
        // Create the pen and triangle in a static constructor and freeze them to improve performance.
        static InsertionAdorner()
        {
            Pen = new Pen {
                Brush = Brushes.Gray, Thickness = 2
            };
            Pen.Freeze();

            var firstLine = new LineSegment(new Point(0, -5), false);

            firstLine.Freeze();
            var secondLine = new LineSegment(new Point(0, 5), false);

            secondLine.Freeze();

            var figure = new PathFigure {
                StartPoint = new Point(5, 0)
            };

            figure.Segments.Add(firstLine);
            figure.Segments.Add(secondLine);
            figure.Freeze();

            Triangle = new PathGeometry();
            Triangle.Figures.Add(figure);
            Triangle.Freeze();
        }
예제 #6
0
        /// <summary>
        /// WPF DrawingImage(Freezeあり、ブラシキャッシュあり)
        /// ※遅延描画(計測外でも描画)
        /// </summary>
        private void Button_Click_WPF3(object sender, RoutedEventArgs e)
        {
            var stopwatch = Stopwatch.StartNew();

            var dg = new DrawingGroup();

            using (var dc = dg.Open())
            {
                var random = new Random();

                var pen = new Pen();
                pen.Thickness = 1;
                pen.Freeze();

                foreach (var point in _points)
                {
                    var brush = _brushes[random.Next(255)];                                             // 気持ち早くなる

                    var rect = new Rect(point, new Size(10.0, 10.0));

                    dc.DrawRectangle(brush, pen, rect);
                }
            }

            var imageSouce = new DrawingImage(dg);

            imageSouce.Freeze();

            _image.Source = imageSouce;

            _elapse.Content = stopwatch.Elapsed.TotalSeconds.ToString();
        }
예제 #7
0
        Pen GetPen(ResourceDictionary props)
        {
            Color?          color;
            SolidColorBrush scBrush;

            Pen newPen;

            if ((color = props[EditorFormatDefinition.ForegroundColorId] as Color?) != null)
            {
                var brush = new SolidColorBrush(color.Value);
                brush.Freeze();
                newPen = new Pen(brush, PEN_THICKNESS);
                newPen.Freeze();
            }
            else if ((scBrush = props[EditorFormatDefinition.ForegroundBrushId] as SolidColorBrush) != null)
            {
                if (scBrush.CanFreeze)
                {
                    scBrush.Freeze();
                }
                newPen = new Pen(scBrush, PEN_THICKNESS);
                newPen.Freeze();
            }
            else if ((newPen = props[MarkerFormatDefinition.BorderId] as Pen) != null)
            {
                if (newPen.CanFreeze)
                {
                    newPen.Freeze();
                }
            }

            return(newPen);
        }
예제 #8
0
 private void UpdateResources()
 {
     _brush = new SolidColorBrush(_color);
     _brush.Freeze();
     _pen = new Pen(_brush, _thickness);
     _pen.Freeze();
 }
 static ErrorsAdorner()
 {
     ErrorBrush = Brushes.Red;
     TextBrush  = Brushes.White;
     BorderPen  = new Pen(ErrorBrush, 1d);
     BorderPen.Freeze();
 }
예제 #10
0
        public BasicStyleCache(BasicStyle style)
        {
            if (style == null)
            {
                return;
            }

            Thickness     = style.Thickness;
            HalfThickness = Thickness / 2.0;

            if (style.Fill != null)
            {
                FillBrush = ToBrush(style.Fill);
                FillBrush.Freeze();
            }

            if (style.Stroke != null)
            {
                StrokeBrush = ToBrush(style.Stroke);
                StrokeBrush.Freeze();

                StrokePen = new Pen(StrokeBrush, Thickness);
                StrokePen.Freeze();
            }
        }
예제 #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="style"></param>
        /// <param name="thickness"></param>
        /// <returns></returns>
        private static Pen CreatePen(BaseStyle style, double thickness)
        {
            var brush = CreateBrush(style.Stroke);
            var pen   = new Pen(brush, thickness);

            switch (style.LineCap)
            {
            case LineCap.Flat:
                pen.StartLineCap = PenLineCap.Flat;
                pen.EndLineCap   = PenLineCap.Flat;
                pen.DashCap      = PenLineCap.Flat;
                break;

            case LineCap.Square:
                pen.StartLineCap = PenLineCap.Square;
                pen.EndLineCap   = PenLineCap.Square;
                pen.DashCap      = PenLineCap.Square;
                break;

            case LineCap.Round:
                pen.StartLineCap = PenLineCap.Round;
                pen.EndLineCap   = PenLineCap.Round;
                pen.DashCap      = PenLineCap.Round;
                break;
            }
            pen.DashStyle        = new DashStyle(style.Dashes, style.DashOffset);
            pen.DashStyle.Offset = style.DashOffset;
            pen.Freeze();
            return(pen);
        }
예제 #12
0
        protected override void OnRender(DrawingContext dc)
        {
            double leftOffset = 0;
            double topOffset  = 0;
            Pen    pen        = new Pen(Brushes.Black, 2);

            pen.Freeze();

            foreach (RowDefinition row in this.RowDefinitions)
            {
                dc.DrawLine(pen, new Point(0, topOffset), new Point(this.ActualWidth, topOffset));
                topOffset += row.ActualHeight;
            }
            // draw last line at the bottom
            dc.DrawLine(pen, new Point(0, topOffset), new Point(this.ActualWidth, topOffset));

            foreach (ColumnDefinition column in this.ColumnDefinitions)
            {
                dc.DrawLine(pen, new Point(leftOffset, 0), new Point(leftOffset, this.ActualHeight));
                leftOffset += column.ActualWidth;
            }
            //draw last line on the right
            dc.DrawLine(pen, new Point(leftOffset, 0), new Point(leftOffset, this.ActualHeight));

            base.OnRender(dc);
        }
예제 #13
0
파일: Game.cs 프로젝트: JieGou/Inspired.IO
 private void SetTheme(IClientTheme clientTheme)
 {
     _BackgroundBrush = clientTheme.Background;
     _BackgroundBrush.Freeze();
     _BorderPen = clientTheme.BorderPen;
     _BorderPen.Freeze();
     _BrushBomb = clientTheme.Bomb;
     _BrushBomb.Freeze();
     _BrushInvader1 = clientTheme.Invader1;
     _BrushInvader1.Freeze();
     _BrushInvader2 = clientTheme.Invader2;
     _BrushInvader2.Freeze();
     _BrushInvader3 = clientTheme.Invader3;
     _BrushInvader3.Freeze();
     _BrushMissile = clientTheme.Missile;
     _BrushMissile.Freeze();
     _BrushPlayer = clientTheme.Player;
     _BrushPlayer.Freeze();
     _BrushSaucer = clientTheme.Saucer;
     _BrushSaucer.Freeze();
     _BrushShield = clientTheme.Shield;
     _BrushShield.Freeze();
     _BrushTextGameOver = clientTheme.TextGameOver;
     _BrushTextGameOver.Freeze();
     _BrushTextTitle = clientTheme.TextTitle;
     _BrushTextTitle.Freeze();
     _BrushTextValue = clientTheme.TextValue;
     _BrushTextValue.Freeze();
 }
예제 #14
0
        protected override void OnRender(DrawingContext dc)
        {
            if (Guideline)
            {
                double leftOffset = 0;
                double topOffset  = 0;

                Pen pen = new Pen(Brushes.Black, 3);
                pen.Freeze();

                foreach (var row in gridPanel.RowDefinitions)
                {
                    dc.DrawLine(pen, new Point(0, topOffset), new Point(ActualWidth, topOffset));
                    topOffset += row.ActualHeight;
                }
                dc.DrawLine(pen, new Point(0, topOffset), new Point(ActualWidth, topOffset));

                foreach (var column in gridPanel.ColumnDefinitions)
                {
                    dc.DrawLine(pen, new Point(leftOffset, 0), new Point(leftOffset, ActualHeight));
                    leftOffset += column.ActualWidth;
                }
                dc.DrawLine(pen, new Point(leftOffset, 0), new Point(leftOffset, ActualHeight));
            }

            base.OnRender(dc);
        }
예제 #15
0
        public VolumeChartElement()
        {
            ToolTip tt = new ToolTip()
            {
                FontSize = CandleChart.ToolTipFontSize, BorderBrush = Brushes.Beige
            };

            tt.Content = "";
            ToolTip    = tt;

            // Зададим время задержки появления подсказок здесь, а расположение подсказок (если его нужно поменять) зададим в XAML:
            ToolTipService.SetShowDuration(this, int.MaxValue);
            ToolTipService.SetInitialShowDelay(this, 0);

            if (bullishBarPen == null)
            {
                bullishBarPen = new Pen(CandleChart.DefaultBullishVolumeBarFill, 1);
                if (!bullishBarPen.IsFrozen)
                {
                    bullishBarPen.Freeze();
                }
            }

            if (bearishBarPen == null)
            {
                bearishBarPen = new Pen(CandleChart.DefaultBearishVolumeBarFill, 1);
                if (!bearishBarPen.IsFrozen)
                {
                    bearishBarPen.Freeze();
                }
            }
        }
예제 #16
0
        private static Pen GetPen(Brush brush, BorderStyle borderStyle, double thickness, double dpi, bool useLayoutRounding)
        {
            var pen = new Pen
            {
                Brush     = brush,
                DashCap   = PenLineCap.Flat,
                Thickness = useLayoutRounding ? UIElementUtil.RoundLayoutValue(thickness, dpi) : thickness,
            };

            switch (borderStyle)
            {
            case BorderStyle.Dotted:
                pen.DashStyle = new DashStyle(new double[] { 1 }, 0d);
                break;

            case BorderStyle.Dashed:
                pen.DashStyle = new DashStyle(new double[] { 4, 2 }, 0d);
                break;

            default:
                break;
            }

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

            return(pen);
        }
예제 #17
0
        private GridModel GetThirdNestedGridWithSharedRowsModel()
        {
            GridModel model = new GridModel();

            Pen gridLinePen = new Pen(Brushes.DarkGray, 1);

            gridLinePen.Freeze();

            model.Options.AllowSelection       = GridSelectionFlags.Cell;
            model.ColumnWidths.DefaultLineSize = 35;
            model.ColumnWidths.HeaderLineCount = 1;
            model.ColumnCount = 4;

            model.RowHeights.HeaderLineCount = 1;
            model.RowHeights.FooterLineCount = 1;
            model.RowCount = 31; // make sure this matched covered cell size ...

            Color clr         = Color.FromArgb(128, 0, 128, 128);
            Brush headerBrush = new SolidColorBrush(clr);

            headerBrush.Freeze();

            Color clr2        = Color.FromArgb(128, 128, 128, 0);
            Brush footerBrush = new SolidColorBrush(clr2);

            footerBrush.Freeze();

            for (int n = 0; n < model.RowCount; n++)
            {
                for (int c = 0; c < model.ColumnCount; c++)
                {
                    GridStyleInfo ci = new GridStyleInfo();
                    ci.CellType             = "TextBox";
                    ci.CellValue            = String.Format("{0}:{1}", n, c);
                    ci.BorderMargins.Top    = gridLinePen.Thickness;
                    ci.BorderMargins.Left   = gridLinePen.Thickness;
                    ci.BorderMargins.Right  = gridLinePen.Thickness / 2;
                    ci.BorderMargins.Bottom = gridLinePen.Thickness / 2;
                    ci.Borders.Right        = gridLinePen;
                    ci.Background           = null;// Brushes.White;
                    ci.Borders.Bottom       = gridLinePen;
                    model.Data[n, c]        = ci.Store;

                    if (c == 0 || n == 0)
                    {
                        ci.CellType   = "Static";
                        ci.Background = headerBrush;
                    }

                    if (n == model.RowCount - 1)
                    {
                        ci.CellType   = "Static";
                        ci.Background = footerBrush;
                    }
                }
            }
            model.SelectedCells = GridRangeInfo.Empty;

            return(model);
        }
예제 #18
0
        public override void Render(DrawingContext dc)
        {
            var strokeBrush = new SolidColorBrush(StrokeColor);

            strokeBrush.Freeze();

            var pen = new Pen(strokeBrush, StrokeThickness);

            pen.Freeze();

            var geom = new StreamGeometry();

            using (StreamGeometryContext ctx = geom.Open())
            {
                var startVertex = Canvas.CoordinateSystem.ToScreenSpace(StartPoint);
                ctx.BeginFigure(new System.Windows.Point(startVertex[0], startVertex[1]), false, false);
                ctx.PolyLineTo(Points.Skip(1).Select(p =>
                {
                    var vertex = Canvas.CoordinateSystem.ToScreenSpace(p);
                    return(new System.Windows.Point(vertex[0], vertex[1]));
                }).ToList(),

                               true /* is stroked */, true /* is smooth join */);
            }
            geom.Freeze();

            dc.DrawGeometry(null, pen, geom);
        }
        static DropTargetInsertionAdorner()
        {
            const int triangleSize = 3;

            ScaleFactor = 1.0d;

            Pen = new Pen(Brushes.Gray, 2);
            Pen.Freeze();

            var firstLine  = new LineSegment(new Point(0, -triangleSize), false);
            var secondLine = new LineSegment(new Point(0, triangleSize), false);

            firstLine.Freeze();
            secondLine.Freeze();

            var figure = new PathFigure {
                StartPoint = new Point(triangleSize, 0)
            };

            figure.Segments.Add(firstLine);
            figure.Segments.Add(secondLine);
            figure.Freeze();

            Triangle = new PathGeometry();
            Triangle.Figures.Add(figure);
            Triangle.Freeze();
        }
예제 #20
0
        public MainWindow()
        {
            InitializeComponent();
            this.AreGridEnabledButton.IsChecked = true;
            settings = new WPFCanvasChartSettings();
            settings.MaxXZoomStep = 200.0f;
            settings.MaxYZoomStep = 200.0f;
            pen.Freeze();
            brush.Freeze();
            this.Loaded += (sender, e) =>
            {
                // chart must created after all UI elements are loaded (canvas, scroll bars, etc...)
                settings.HandleSizeChanged = false;
                settings.FontSize          = 4;
                settings.PenForGrid        = new Pen((Brush) new BrushConverter().ConvertFromString("#66000000"), 0.3);
                settings.PenForAxis        = new Pen((Brush) new BrushConverter().ConvertFromString("#CC000000"), 0.5);
                xAxisInterpolator          = new WPFCanvasChartIntInterpolator();
                yAxisInterpolator          = new WPFCanvasChartFloatInterpolator();
                cc = new WPFCanvasChartComponent();
                cc.Init(this.Canvas, HorizScroll, VertScroll, this, settings, xAxisInterpolator, yAxisInterpolator);
                cc.SetMinMax(-5, 5, 10, 20);
                cc.DrawChart();
            };

            this.Closed += (sender, e) =>
            {
                cc.Dispose();
            };
        }
        private void OnForegroundChanged(Brush newValue)
        {
            foregroundBrush = newValue.Clone();
            foregroundBrush.Freeze();

            foregourndPen = new Pen(foregroundBrush, 2);
            foregourndPen.Freeze();
        }
        private void OnActiveForegroundChanged(Brush newValue)
        {
            activeForegourndBrush = newValue.Clone();
            activeForegourndBrush.Freeze();

            activePen = new Pen(activeForegourndBrush, 2);
            activePen.Freeze();
        }
예제 #23
0
 private void UpdateLinePen()
 {
     linePen = new Pen(LineBrush, LineThickness);
     if (linePen.CanFreeze)
     {
         linePen.Freeze();
     }
 }
예제 #24
0
            static Pen CreateBorderPen()
            {
                Pen p = new Pen(Brushes.Black, 1);

                p.DashStyle = DashStyles.Dot;
                p.Freeze();
                return(p);
            }
예제 #25
0
        public GraphLoader(IEnumerable <Node> Nodes, IEnumerable <Edge> Edges, double [] BoundingBox = null, BitmapFrame Frame = null, double PenSize = 0)
        {
            outline = new Pen(Brushes.Blue, 0.02 + (Frame != null ? PenSize : 0));
            outline.Freeze();
            graph = new DrawingVisual();

            LoadGraph(Nodes, Edges, Frame, (Frame != null ? PenSize : 0), BoundingBox);
        }
예제 #26
0
 private void ExprValueChanged(object sender, EventArgs eventArgs)
 {
     Brush = new SolidColorBrush(GetColor());
     Brush.Freeze();
     Pen = new Pen(Brush, 2);
     Pen.Freeze();
     StringExpr = _r.ExprString + ";" + _g.ExprString + ";" + _b.ExprString + ";" + _a.ExprString;
 }
예제 #27
0
        private Pen GetPen()
        {
            var pen = new Pen(LineBrush, LineThickness * GetDpiFactor());

            pen.Freeze();

            return(pen);
        }
예제 #28
0
 static EdgeTemplate()
 {
     DefaultPen = new Pen()
     {
         Brush = Brushes.Black, Thickness = 1.0
     };
     DefaultPen.Freeze();
 }
예제 #29
0
 public MainWindow()
 {
     InitializeComponent();
     if (boxStroke.CanFreeze)
     {
         boxStroke.Freeze();
     }
 }
        public void UpdateColors(Color background, Color foreground)
        {
            _borderPen = new Pen(new SolidColorBrush(foreground), 1);
            _borderPen.Freeze();

            _backgroundBrush = new SolidColorBrush(background);
            _backgroundBrush.Freeze();
        }
예제 #31
0
 static Pen GetPen(object lockObj, Dictionary<double, Pen> penDictionary, double thickness, PenLineJoin lineJoin, Brush brush=null)
 {
     lock (lockObj)
     {
         thickness = Math.Round(thickness, 1);
         if (!penDictionary.ContainsKey(thickness))
         {
             Pen pen = new Pen(brush ?? Brushes.Black, thickness);
             pen.LineJoin = lineJoin;
             pen.Freeze();
             penDictionary.Add(thickness, pen);
         }
         return penDictionary[thickness];
     }
 }
예제 #32
0
        // Create a solid pen
        public static Pen CreateSolidPen(Color color, float thickness, LineStyle style)
        {
            #if false
            Pen pen = new Pen(new SolidColorBrush(color), thickness);
            if (style == LineStyle.Rounded) {
                pen.StartLineCap = pen.EndLineCap = PenLineCap.Round;
                pen.LineJoin = PenLineJoin.Round;
            }
            else if (style == LineStyle.Beveled) {
                pen.StartLineCap = pen.EndLineCap = PenLineCap.Flat;
                pen.LineJoin = PenLineJoin.Bevel;
            }
            else if (style == LineStyle.Mitered) {
                pen.StartLineCap = pen.EndLineCap = PenLineCap.Flat;
                pen.LineJoin = PenLineJoin.Miter;
                pen.MiterLimit = MITER_LIMIT;
            }
            else if (style == LineStyle.FlatRounded) {
                pen.StartLineCap = pen.EndLineCap = PenLineCap.Flat;
                pen.LineJoin = PenLineJoin.Round;
            }

            pen.Freeze();
            return pen;
            #else
            Pen pen = new Pen(color, thickness);
            if (style == LineStyle.Rounded) {
                pen.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Flat);
                pen.LineJoin = LineJoin.Round;
            }
            else if (style == LineStyle.Beveled) {
                pen.SetLineCap(LineCap.Flat, LineCap.Flat, DashCap.Flat);
                pen.LineJoin = LineJoin.Bevel;
            }
            else if (style == LineStyle.Mitered) {
                pen.SetLineCap(LineCap.Flat, LineCap.Flat, DashCap.Flat);
                pen.LineJoin = LineJoin.Miter;
                pen.MiterLimit = MITER_LIMIT;
            }
            else if (style == LineStyle.FlatRounded) {
                pen.SetLineCap(LineCap.Flat, LineCap.Flat, DashCap.Flat);
                pen.LineJoin = LineJoin.Round;
            }

            return pen;
            #endif
        }