Пример #1
0
        public static Brush SetBrightness(this Brush original, double brightness)
        {
            if (brightness < 0 || brightness > 1)
            {
                throw new ArgumentOutOfRangeException("brightness", "brightness should be between 0 and 1");
            }

            Brush result;

            if (original is SolidColorBrush)
            {
                HSBColor hsb = HSBColor.FromColor(((SolidColorBrush)original).Color);
                hsb.B  = brightness;
                result = new SolidColorBrush(hsb.ToColor());
            }
            else if (original is GradientBrush)
            {
                result = original.Clone();
                // change brightness of every gradient stop
                foreach (GradientStop gs in ((GradientBrush)result).GradientStops)
                {
                    HSBColor hsb = HSBColor.FromColor(gs.Color);
                    hsb.B    = brightness;
                    gs.Color = hsb.ToColor();
                }
            }
            else
            {
                result = original.Clone();
            }

            return(result);
        }
Пример #2
0
 private static Brush NormalizeBrush(Brush brush, IRectangle layout)
 {
     if (brush is LinearGradientBrush)
     {
         LinearGradientBrush lgb = (LinearGradientBrush)brush.Clone();
         lgb.MultiplyTransform(
             new Matrix(Math.Max(0.1f, (float)layout.Width), 0, 0, Math.Max(0.1f, (float)layout.Height),
                        (float)layout.X, (float)layout.Y), MatrixOrder.Append);
         brush = lgb;
     }
     else if (brush is PathGradientBrush)
     {
         PathGradientBrush pgb = (PathGradientBrush)brush.Clone();
         pgb.MultiplyTransform(
             new Matrix(Math.Max(0.1f, (float)layout.Width), 0, 0, Math.Max(0.1f, (float)layout.Height),
                        (float)layout.X, (float)layout.Y), MatrixOrder.Append);
         brush = pgb;
     }
     else if (brush is TextureBrush)
     {
         TextureBrush tb = (TextureBrush)brush.Clone();
         tb.MultiplyTransform(
             new Matrix(Math.Max(0.1f, (float)layout.Width), 0, 0, Math.Max(0.1f, (float)layout.Height),
                        (float)layout.X, (float)layout.Y), MatrixOrder.Append);
         brush = tb;
     }
     return(brush);
 }
Пример #3
0
        private void FillCanvas()
        {
            cnvDrawArea.Background = uscColorPicker.elpCurrentColor.Fill.Clone();
            nextAction             = NextAction.DRAW;
            btnBucket.Background   = originalButtonColor.Clone();

            var color = ((Color)uscColorPicker.elpCurrentColor.Fill.GetValue(SolidColorBrush.ColorProperty));

            Client.WriteFillMessage(color.ToString());
        }
 public void Kirmizi1()
 {
     btnKirmizi1.Dispatcher.Invoke(() =>
     {
         btnKirmizi1.Background = Brushes.Green;
     });
     Thread.Sleep(500);
     btnKirmizi1.Dispatcher.Invoke(() =>
     {
         btnKirmizi1.Background = Kirmizi.Clone();
     });
 }
Пример #5
0
        static SnapToGridRenderer()
        {
            Brush brush = (Brush) new SolidColorBrush(Color.FromScRgb(1f, 0.125f, 0.125f, 0.125f));

            SnapToGridRenderer.brushOne         = brush.Clone();
            SnapToGridRenderer.brushOne.Opacity = 0.1;
            SnapToGridRenderer.brushOne.Freeze();
            SnapToGridRenderer.brushFive         = brush.Clone();
            SnapToGridRenderer.brushFive.Opacity = 0.25;
            SnapToGridRenderer.brushFive.Freeze();
            SnapToGridRenderer.brushTen         = brush.Clone();
            SnapToGridRenderer.brushTen.Opacity = 0.5;
            SnapToGridRenderer.brushTen.Freeze();
        }
Пример #6
0
 public DrawEventArgs(DrawingMode drawingMode, List <PointLatLng> drawingPoints, Pen stroke, Brush fill)
 {
     DrawingMode = drawingMode;
     if (drawingMode == DrawingMode.Polygon)
     {
         Polygon = new GMapDrawPolygon(drawingPoints, drawingMode.ToString());
         if (fill != null)
         {
             Polygon.Fill = (Brush)fill.Clone();
         }
         if (stroke != null)
         {
             Polygon.Stroke = (Pen)stroke.Clone();
         }
         Polygon.IsHitTestVisible = true;
     }
     else if (drawingMode == DrawingMode.Rectangle)
     {
         Rectangle = new GMapDrawRectangle(drawingPoints, drawingMode.ToString());
         if (fill != null)
         {
             Rectangle.Fill = (Brush)fill.Clone();
         }
         if (stroke != null)
         {
             Rectangle.Stroke = (Pen)stroke.Clone();
         }
         Rectangle.IsHitTestVisible = true;
     }
     else if (drawingMode == DrawingMode.Route)
     {
         Route = new GMapDrawRoute(drawingPoints, drawingMode.ToString());
         if (stroke != null)
         {
             Route.Stroke = (Pen)stroke.Clone();
         }
         Route.IsHitTestVisible = true;
     }
     else if (drawingMode == DrawingMode.Line)
     {
         Line = new GMapDrawLine(drawingPoints, drawingMode.ToString());
         if (stroke != null)
         {
             Line.Stroke = (Pen)stroke.Clone();
         }
         Line.IsHitTestVisible = true;
     }
 }
Пример #7
0
        /// <summary>
        /// Updates properties from a change to the format map. Also forces a redraw of all the time stamped lines.
        /// </summary>
        private void SetFontFromClassification()
        {
            var font = _formatMap.GetTextProperties(_lineNumberClassification);

            _showHours        = _textView.Options.GetOptionValue(TimeStampMarginShowHours.StaticKey);
            _showMilliseconds = _textView.Options.GetOptionValue(TimeStampMarginShowMilliseconds.StaticKey);

            // In the line number margin, we always enforce a 100% opacity.
            // This is to prevent mixing of the line number's background color
            // with its parent's background when the background brush of the
            // line number classified item is not opaque.
            Brush backgroundBrush = font.BackgroundBrush;

            if (backgroundBrush.Opacity != 1.0)
            {
                backgroundBrush         = backgroundBrush.Clone();
                backgroundBrush.Opacity = 1.0;
                backgroundBrush.Freeze();

                font = font.SetBackgroundBrush(backgroundBrush);
            }

            base.Background = backgroundBrush;
            _formatting     = font;
            this.SetClearTypeHint(font);
            this.DetermineMarginWidth();

            // Reformat all the lines
            _translatedCanvas.Children.Clear();
            this.UpdateLineNumbers();
        }
Пример #8
0
    public void setBrush(Brush _brush)
    {
        fillBrush = (Brush)_brush.Clone();
        SolidBrush brush = (SolidBrush)_brush;

        fillColor = brush.Color;
    }
            public Brush InterpolateValue(Brush from, Brush to, double progress)
            {
                Brush result = from.Clone();

                InterpolateResult((TBrush)result, (TBrush)from, (TBrush)to, progress);
                return(result);
            }
            public Brush ScaleValue(Brush value, double factor)
            {
                Brush result = value.Clone();

                ScaleResult((TBrush)result, factor);
                return(result);
            }
            public Brush SubtractValues(Brush a, Brush b)
            {
                Brush result = a.Clone();

                SubtractValuesFromResult((TBrush)result, (TBrush)a, (TBrush)b);
                return(result);
            }
            // For the animations to work, the brushes (each object really) must be cloned,
            // since working on reference types would yield incorrect results.
            // -> These methods clone the brushes, but delegate the actual value
            //    modification to the methods below.
            public Brush AddValues(Brush a, Brush b)
            {
                Brush result = a.Clone();

                AddValuesToResult((TBrush)result, (TBrush)a, (TBrush)b);
                return(result);
            }
Пример #13
0
 /// <summary>
 /// Constructor that creates a <see cref="Brush"/> fill, using a user-supplied, custom
 /// <see cref="Brush"/>.  The brush will be scaled to fit the destination screen object
 /// unless you manually change <see cref="IsScaled"/> to false;
 /// </summary>
 /// <param name="brush">The <see cref="Brush"/> to use for fancy fills.  Typically, this would
 /// be a <see cref="LinearGradientBrush"/> or a <see cref="TextureBrush"/> class</param>
 public Fill(Brush brush)
 {
     Init();
     this.color = Color.White;
     this.brush = (Brush)brush.Clone();
     this.type  = FillType.Brush;
 }
Пример #14
0
 public void SetStroke(Brush brush)
 {
     foreach (var o in objects)
     {
         o.SetStroke(brush.Clone());
     }
 }
Пример #15
0
        /// <summary>
        /// Creates a material with the specified diffuse, emissive and specular brushes.
        /// </summary>
        /// <param name="diffuse">The diffuse color.</param>
        /// <param name="emissive">The emissive color.</param>
        /// <param name="specular">The specular color.</param>
        /// <param name="opacity">The opacity.</param>
        /// <param name="specularPower">The specular power.</param>
        /// <returns>The material.</returns>
        public static Material CreateMaterial(
            Brush diffuse, Brush emissive, Brush specular = null, double opacity = 1, double specularPower = 85)
        {
            var mg = new MaterialGroup();

            if (diffuse != null)
            {
                diffuse         = diffuse.Clone();
                diffuse.Opacity = opacity;
                mg.Children.Add(new DiffuseMaterial(diffuse));
            }

            if (emissive != null)
            {
                emissive         = emissive.Clone();
                emissive.Opacity = opacity;
                mg.Children.Add(new EmissiveMaterial(emissive));
            }

            if (specular != null)
            {
                specular         = specular.Clone();
                specular.Opacity = opacity;
                mg.Children.Add(new SpecularMaterial(specular, specularPower));
            }

            return(mg);
        }
Пример #16
0
        public override void setBrush(int argb, int style)
        {
            byte alpha = (byte)((argb >> 24) & 0xFF);

            if (style == 0)
            {
                if (alpha == 0)
                {
                    _brush = null;
                }
                else
                {
                    if (_brush != null && _brush is SolidColorBrush)
                    {
                        _brush = _brush.Clone();
                        (_brush as SolidColorBrush).Color = toColor(argb);
                    }
                    else
                    {
                        _brush = new SolidColorBrush(toColor(argb));
                    }
                    _brush.Freeze();
                }
            }
        }
Пример #17
0
 private void btnOK_Click(object sender, RoutedEventArgs e)
 {
     CurrentBrush.CurBrushType  = BrushType.Pattern;
     CurrentBrush.Brush         = tempBrush.Clone();
     CurrentBrush.Brush.Opacity = MainWindow.mainWindow.GetSlider().Value / 100;
     this.Close();
 }
Пример #18
0
        void InitializeBrushes(out Brush brush, out Brush overwriteBrush, VSTC.IClassificationType classificationType)
        {
            var props = classificationFormatMap.GetTextProperties(classificationType);

            if (!props.BackgroundBrushEmpty)
            {
                brush = props.BackgroundBrush;
            }
            else
            {
                Debug.Assert(!classificationFormatMap.DefaultTextProperties.ForegroundBrushEmpty);
                brush = classificationFormatMap.DefaultTextProperties.ForegroundBrush;
                if (classificationFormatMap.DefaultTextProperties.ForegroundBrushEmpty)
                {
                    brush = Brushes.Black;
                }
            }
            if (brush.CanFreeze)
            {
                brush.Freeze();
            }

            overwriteBrush         = brush.Clone();
            overwriteBrush.Opacity = 0.5;
            if (overwriteBrush.CanFreeze)
            {
                overwriteBrush.Freeze();
            }
        }
Пример #19
0
 public void Commit()
 {
     if (Brush != null)
     {
         Property.Value = Brush.Clone();
     }
 }
Пример #20
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     base.OnRender(drawingContext);
     Debug.Assert((overwriteCaretBrush == null) == (caretBrush == null));
     if (caretBrush == null)
     {
         caretBrush = classificationFormatMap.DefaultTextProperties.ForegroundBrush;
         Debug.Assert(!classificationFormatMap.DefaultTextProperties.ForegroundBrushEmpty);
         if (classificationFormatMap.DefaultTextProperties.ForegroundBrushEmpty)
         {
             caretBrush = Brushes.Black;
         }
         caretBrush                  = caretBrush.Clone();
         overwriteCaretBrush         = caretBrush.Clone();
         overwriteCaretBrush.Opacity = 0.5;
         if (caretBrush.CanFreeze)
         {
             caretBrush.Freeze();
         }
         if (overwriteCaretBrush.CanFreeze)
         {
             overwriteCaretBrush.Freeze();
         }
     }
     drawingContext.DrawGeometry(caretGeometry.IsOverwriteMode ? overwriteCaretBrush : caretBrush, null, caretGeometry.Geometry);
 }
Пример #21
0
        public static Brush ChangeBrushOpacity(Brush input, double opacity)
        {
            Brush output = input.Clone();

            output.Opacity = opacity;
            return(output);
        }
Пример #22
0
        public override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            if (firstTime && DrawingState == DrawingState.Normal)
            {
                firstTime = false;
                Cbi.License.Log("Polygon");
            }

            RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;
            Stroke outlineStroke = OutlineStroke;

            outlineStroke.RenderTarget = RenderTarget;
            ChartPanel chartPanel = chartControl.ChartPanels[PanelIndex];

            // dont bother with an area brush if we're doing a hit test (software) render pass. we do not render area then.
            // this allows us to select something behind our area brush (like NT7)
            if (!IsInHitTest && AreaBrush != null)
            {
                if (areaBrushDevice.Brush == null)
                {
                    Brush brushCopy = areaBrush.Clone();
                    brushCopy.Opacity     = areaOpacity / 100d;
                    areaBrushDevice.Brush = brushCopy;
                }

                areaBrushDevice.RenderTarget = RenderTarget;
            }
            else
            {
                areaBrushDevice.RenderTarget = null;
                areaBrushDevice.Brush        = null;
            }

            // align to full pixel to avoid unneeded aliasing
            double strokePixAdjust = outlineStroke.Width % 2 == 0 ? 0.5d : 0d;

            // always re-create polygon geometry here
            SharpDX.Direct2D1.PathGeometry polyGeo = CreatePolygonGeometry(chartControl, chartPanel, chartScale, strokePixAdjust);

            if (DrawingState != DrawingState.Building)
            {
                if (!IsInHitTest && areaBrushDevice.BrushDX != null)
                {
                    RenderTarget.FillGeometry(polyGeo, areaBrushDevice.BrushDX);
                }
                else
                {
                    // Polygon can be selected by center anchor point still, so give something for the hit test pass to
                    // detect we want to be hit test there, so draw a rect in center. actual brush doesnt matter
                    Point[] points   = GetPolygonAnchorPoints(chartControl, chartScale, true);
                    Point   centroid = points.Length > 0 ? points.Last() : new Point();
                    RenderTarget.FillRectangle(new SharpDX.RectangleF((float)centroid.X - 5f, (float)centroid.Y - 5f, (float)cursorSensitivity, (float)cursorSensitivity), chartControl.SelectionBrush);
                }
            }

            SharpDX.Direct2D1.Brush tmpBrush = IsInHitTest ? chartControl.SelectionBrush : outlineStroke.BrushDX;
            RenderTarget.DrawGeometry(polyGeo, tmpBrush, outlineStroke.Width, outlineStroke.StrokeStyle);
            polyGeo.Dispose();
        }
Пример #23
0
 public ColorData(Pen pen, Brush brush)
 {
     Pen        = (Pen)pen.Clone();
     Brush      = (Brush)brush.Clone();
     _color     = Pen.Color;
     _width     = (int)Pen.Width;
     _fillColor = ((SolidBrush)Brush).Color;
 }
Пример #24
0
        /// <summary>
        /// Called after the <see cref="CenterLineBrush"/> value has changed.
        /// </summary>
        /// <param name="oldValue">The previous value of <see cref="CenterLineBrush"/></param>
        /// <param name="newValue">The new value of <see cref="CenterLineBrush"/></param>
        protected virtual void OnCenterLineBrushChanged(Brush oldValue, Brush newValue)
        {
            var frozen = newValue.Clone();

            frozen.Freeze();
            centerLine.Stroke = frozen;
            UpdateWaveform();
        }
Пример #25
0
 /// <summary>
 /// Constructor that creates a <see cref="Brush"/> fill, using a user-supplied, custom
 /// <see cref="Brush"/>.  The brush will be scaled to fit the destination screen object
 /// according to the <see paramref="isScaled"/> parameter.
 /// </summary>
 /// <param name="brush">The <see cref="Brush"/> to use for fancy fills.  Typically, this would
 /// be a <see cref="LinearGradientBrush"/> or a <see cref="TextureBrush"/> class</param>
 /// <param name="isScaled">Determines if the brush will be scaled to fit the bounding box
 /// of the destination object.  true to scale it, false to leave it unscaled</param>
 public Fill(Brush brush, bool isScaled)
 {
     Init();
     this.isScaled = isScaled;
     this.color    = Color.White;
     this.brush    = (Brush)brush.Clone();
     this.type     = FillType.Brush;
 }
Пример #26
0
 /// <summary>
 /// Constructor that creates a <see cref="Brush"/> fill, using a user-supplied, custom
 /// <see cref="Brush"/>.  The brush will be scaled to fit the destination screen object
 /// according to the <see paramref="isScaled"/> parameter.
 /// </summary>
 /// <param name="brush">The <see cref="Brush"/> to use for fancy fills.  Typically, this would
 /// be a <see cref="LinearGradientBrush"/> or a <see cref="TextureBrush"/> class</param>
 /// <param name="isScaled">Determines if the brush will be scaled to fit the bounding box
 /// of the destination object.  true to scale it, false to leave it unscaled</param>
 public Fill(Brush brush, bool isScaled)
 {
     Init();
     _isScaled = isScaled;
     _color    = Color.White;
     _brush    = (Brush)brush.Clone();
     _type     = FillType.Brush;
 }
        private void OnForegroundChanged(Brush newValue)
        {
            foregroundBrush = newValue.Clone();
            foregroundBrush.Freeze();

            foregourndPen = new Pen(foregroundBrush, 2);
            foregourndPen.Freeze();
        }
Пример #28
0
 public void SetSingleBrush(Brush brush)
 {
     this.Brushes = new Brush[this.Paths.Length];
     for (int i = 0; i < this.Brushes.Length; i++)
     {
         this.Brushes[i] = (Brush)brush.Clone();
     }
 }
        private void OnActiveForegroundChanged(Brush newValue)
        {
            activeForegourndBrush = newValue.Clone();
            activeForegourndBrush.Freeze();

            activePen = new Pen(activeForegourndBrush, 2);
            activePen.Freeze();
        }
Пример #30
0
 public override object Clone()
 {
     return(new DrawablePath {
         Path = Path?.Clone() as GraphicsPath,
         Brush = Brush?.Clone() as Brush,
         Pen = Pen?.Clone() as Pen
     });
 }