Ejemplo n.º 1
0
        private void DrawTrace(IEnumerable <LfS.GestureDatabase.Touch> points, int size, System.Windows.Media.Brush baseFillBrush, System.Windows.Media.Brush StrokeBrush)
        {
            var n = points.Count();

            var opacityStep = 0.8 / n;

            var opacity = 1d;

            //var curFillBrush = baseFillBrush.Clone();

            foreach (var p in points)
            {
                //FillBrush.Opacity = opacity;
                var curFillBrush = baseFillBrush.Clone();
                curFillBrush.Opacity = opacity;
                opacity -= opacityStep;
                var circle = new Ellipse();
                circle.Width  = size * 2;
                circle.Height = size * 2;
                circle.Fill   = curFillBrush;
                //circle.SetValue(Ellipse.FillProperty, FillBrush);
                circle.Stroke = StrokeBrush;
                circle.SetValue(Canvas.LeftProperty, (double)(p.X * 600 - size));
                circle.SetValue(Canvas.TopProperty, (double)(p.Y * 600 - size));

                canvas1.Children.Add(circle);
            }
        }
        public BrushDesignerWindow(object obj, PropertyInfo prop)
        {
            InitializeComponent();
            (GradientGrid.Background as DrawingBrush).RelativeTransform = GGridTrans = new RotateTransform();
            GGridTrans.CenterX = 0.5;
            GGridTrans.CenterY = 0.5;
            isd = new ImageSourceDesigner();

            b = prop.GetValue(obj, null) as Brush;
            setv = (x) => prop.SetValue(obj, x, null);
            if (b.IsFrozen)
            {
                b = b.Clone();
                setv(b);
            }
            if (b is SolidColorBrush)
            {
                cmode = Mode.Solid;
            }
            else if (b is LinearGradientBrush)
            {
                cmode = Mode.LinearGradient;
            }
            else if (b is ImageBrush)
            {
                cmode = Mode.Image;
            }
        }
Ejemplo n.º 3
0
 Brush createFadingBrush(Brush baseBrush, double duration)
 {
     var brush = baseBrush.Clone();
     brush.BeginAnimation(Brush.OpacityProperty, new DoubleAnimation
     {
         From = 0,
         To = 1,
         Duration = TimeSpan.FromMilliseconds(duration)
     });
     return brush;
 }
Ejemplo n.º 4
0
            private void SetOpacity(double newOpacity)
            {
                if (mediaBrush == null)
                {
                    return;
                }

                // Force opcatity to be in bounds
                opacity = Math.Min(100.0, Math.Max(0, newOpacity));

                // Clone any Frozen brush so it can be modified
                if (mediaBrush.IsFrozen)
                {
                    mediaBrush = mediaBrush.Clone();
                }

                // Set Opacity and freeze brush.
                mediaBrush.Opacity = opacity / 100.0;
                mediaBrush.Freeze();
            }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a material with the specified diffuse, emissive and specular brushes.
 /// </summary>
 /// <param name="diffuse">The diffuse.</param>
 /// <param name="emissive">The emissive.</param>
 /// <param name="specular">The specular.</param>
 /// <param name="opacity">The opacity.</param>
 /// <param name="specularPower">The specular power.</param>
 /// <returns></returns>
 public static Material CreateMaterial(Brush diffuse, Brush emissive, Brush specular, double opacity, double specularPower)
 {
     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;
 }
Ejemplo n.º 6
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;

        //    var solidColorBrush = original as SolidColorBrush;
        //    if (solidColorBrush != null)
        //    {
        //        var hsb = HSBColor.FromColor(solidColorBrush.Color);
        //        hsb.B = brightness;
        //        result = new SolidColorBrush(hsb.ToColor());
        //    }
        //    else
        //    {
        //        var gradientBrush = original as LinearGradientBrush;
        //        if (gradientBrush != null)
        //        {
        //            result = gradientBrush.Clone();
        //            // change brightness of every gradient stop
        //            foreach (var gs in ((GradientBrush)result).GradientStops)
        //            {
        //                var hsb = HSBColor.FromColor(gs.Color);
        //                hsb.B = brightness;
        //                gs.Color = hsb.ToColor();
        //            }
        //        }
        //        else
        //        {
        //            result = original.Clone();
        //        }
        //    }

        //    return result;
        //}

        internal static Brush SetLuminance(this Brush original, double luminance)
        {
            Brush result;
            var   solidColorBrush = original as SolidColorBrush;

            if (solidColorBrush != null)
            {
                var clr = Color.FromArgb(solidColorBrush.Color.A, solidColorBrush.Color.R,
                                         solidColorBrush.Color.G,
                                         solidColorBrush.Color.B);
                var hsb = new HSLColor(clr.GetHue(), clr.GetSaturation(), clr.GetBrightness());
                hsb.Lightness *= luminance;
                result         = new SolidColorBrush(hsb.RGBColor().Color);
            }
            else
            {
                var gradientBrush = original as LinearGradientBrush;
                if (gradientBrush != null)
                {
                    result = gradientBrush.Clone();
                    foreach (var gs in ((GradientBrush)result).GradientStops)
                    {
                        var clr = Color.FromArgb(gs.Color.A, gs.Color.R,
                                                 gs.Color.G,
                                                 gs.Color.B);
                        var hsb = new HSLColor(clr.GetHue(), clr.GetSaturation(), clr.GetBrightness());
                        hsb.Lightness *= luminance;
                        gs.Color       = hsb.RGBColor().Color;
                    }
                }
                else
                {
                    return(original.Clone());
                }
            }
            return(result);
        }
Ejemplo n.º 7
0
        private void MakeBitmap()
        {
            while (true)
            {
                _newText.WaitOne();

                GlyphTypeface glyphTypeface = null;
                if (_glyphTypeface != null)
                {
                    lock (_glyphTypeface)
                    {
                        glyphTypeface = _glyphTypeface;
                    }
                }

                if (glyphTypeface != null)
                {
                    if (_lines == null || _lines.Length == 0)
                    {
                        _img = null;
                    }
                    else
                    {
                        if (_lines[0].VobSubMergedPack != null)
                        {
                            var          bitmaps = _lines.Select(l => l.GetImage()).ToArray();
                            int          bw      = bitmaps.Max(b => b.Width);
                            int          bh      = bitmaps.Sum(b => b.Height);
                            BitmapSource bimage  = CreateBitmap((int)bw, (int)bh, 96,
                                                                dc =>
                            {
                                double ypos = 0;
                                for (int lb = 0; lb < bitmaps.Count(); lb++)
                                {
                                    var bs     = bitmaps[lb].ToBitmapSource();
                                    Point bLoc = new Point((bw - bs.Width) / 2, ypos);
                                    Size bSize = new Size(bs.Width, bs.Height);
                                    ypos      += bs.Height;
                                    dc.DrawImage(bs, new Rect(bLoc, bSize));
                                }
                            });
                            bimage.Freeze();
                            _img = bimage;
                        }
                        else
                        {
                            var lines = new List <string>(_lines.Select(l => l.Text).SelectMany(t => t.Split(new string[] { Environment.NewLine }, 10000, StringSplitOptions.None))).ToArray();
                            {
                                ushort[][] glyphIndexes  = new ushort[lines.Length][];
                                double[][] advanceWidths = new double[lines.Length][];

                                double[] totalWidth = new double[lines.Length];

                                int l = 0;
                                foreach (var text in lines)
                                {
                                    glyphIndexes[l]  = new ushort[text.Length];
                                    advanceWidths[l] = new double[text.Length];
                                    for (int n = 0; n < text.Length; n++)
                                    {
                                        if (glyphTypeface.CharacterToGlyphMap.ContainsKey(text[n]))
                                        {
                                            ushort glyphIndex = glyphTypeface.CharacterToGlyphMap[text[n]];
                                            glyphIndexes[l][n] = glyphIndex;

                                            double width = glyphTypeface.AdvanceWidths[glyphIndex] * _fontSize;
                                            advanceWidths[l][n] = width;

                                            totalWidth[l] += width;
                                        }
                                    }
                                    l++;
                                }

                                double w = totalWidth.Max(lw => lw) + _marginLeft + _marginRight;
                                double h = (lines.Length * _fontSize) + _fontSize / 4 + _marginBottom;

                                BitmapSource image = CreateBitmap((int)w, (int)h, 96,
                                                                  dc =>
                                {
                                    int line = 1;
                                    if (_back != Brushes.Transparent)
                                    {
                                        dc.DrawRectangle(_back, null, new Rect(0d, 0d, w, h));
                                    }
                                    foreach (var text in lines)
                                    {
                                        if (string.IsNullOrEmpty(text))
                                        {
                                            line++;
                                            continue;
                                        }
                                        var origin      = new Point((w - totalWidth[line - 1]) / 2, line * _fontSize);
                                        var orig        = ((SolidColorBrush)_stroke.Clone()).Color;
                                        var strokeBrush = new SolidColorBrush
                                        {
                                            Color =
                                                new Color()
                                            {
                                                B = orig.B,
                                                R = orig.R,
                                                G = orig.G,
                                                A = _strokeGlow ? (byte)35 : orig.A
                                            }
                                        };

                                        var glyphRun = new GlyphRun(glyphTypeface, 0, false, _fontSize,
                                                                    glyphIndexes[line - 1], origin,
                                                                    advanceWidths[line - 1], null, null,
                                                                    null, null,
                                                                    null, null);

                                        if (_underline)
                                        {
                                            double y = origin.Y;
                                            y       -= (glyphTypeface.Baseline + _typeface.UnderlinePosition * _fontSize);
                                            for (double i = _strokeThickness; i > 0; i--)
                                            {
                                                dc.DrawLine(
                                                    new Pen(strokeBrush, (_typeface.UnderlineThickness * _fontSize) + i),
                                                    new Point(origin.X - _strokeThickness / 2, y),
                                                    new Point(origin.X + totalWidth[line - 1] + _strokeThickness / 2, y));
                                                if (!_strokeGlow)
                                                {
                                                    break;
                                                }
                                            }
                                        }

                                        var geo = glyphRun.BuildGeometry();
                                        for (double i = _strokeThickness; i > 0; i--)
                                        {
                                            dc.DrawGeometry(null, new Pen(strokeBrush, i), geo);
                                            if (!_strokeGlow)
                                            {
                                                break;
                                            }
                                        }

                                        dc.DrawGlyphRun(_fill, glyphRun);

                                        if (_underline)
                                        {
                                            double y = origin.Y;
                                            y       -= (glyphTypeface.Baseline + _typeface.UnderlinePosition * _fontSize);
                                            dc.DrawLine(new Pen(_fill, _typeface.UnderlineThickness * _fontSize),
                                                        new Point(origin.X, y),
                                                        new Point(origin.X + totalWidth[line - 1], y));
                                        }

                                        line++;
                                    }
                                });

                                image.Freeze();
                                _img = image;
                            }
                        }
                    }
                }
                try
                {
                    _newText.Release();
                }
                catch
                {
                }
                Dispatcher.Invoke(((Action)(() =>
                {
                    _newText.WaitOne(); InvalidateVisual();
                })), DispatcherPriority.Render, new object[] { });
            }
        }
Ejemplo n.º 8
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);
		}
Ejemplo n.º 9
0
        protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
        {
            base.OnRenderSizeChanged(sizeInfo);
            double width = ActualWidth;
            double width005 = width * .005;
            double width015 = width * .015;
            double width02 = width * .02;
            double width995 = width - width005;
            double width985 = width - width015;
            double height = ActualHeight;
            if (Math.Abs(height - 0.0) < double.Epsilon || Math.Abs(width - 0.0) < double.Epsilon)
            {
                return;
            }

            double halfWidth = width / 2;
            double halfHeight = height / 2;
            double quarterWidth = width / 4;
            double baseLine = height * .035;
            fontSize = height / (1024 / 15);
            symbolfontSize = height / (1024 / 70);
            ratioToDisplayAngleMultiplier = width / 360 * RADIAN_TO_ANGLE_MULTIPLIER;
            baselinePen = new Pen(brush, THICKNESS_BASELINE);
            warningPen = new Pen(warningBrush, THICKNESS_BASELINE);
            warning2Pen = new Pen(warning2Brush, THICKNESS_BASELINE);
            gaugeBrush = brush.Clone();
            gaugeBrush.Opacity = .5;
            gaugePen = new Pen(gaugeBrush, THICKNESS_BASELINE);
            falseHorizonBrush = brush.Clone();
            falseHorizonBrush.Opacity = 1;
            falseHorizonPen = new Pen(falseHorizonBrush, THICKNESS_BASELINE);
            compassLines = new GeometryGroup();
            compassText = new GeometryGroup();
            directionTop = new Point(halfWidth, 0);
            directionBottom = new Point(halfWidth, baseLine);
            directionLineTop = new Point(0, 0);
            directionLineLeftBoundTop = new Point(quarterWidth, height * 0);
            directionLineLeftBoundBottom = new Point(quarterWidth, height * .03);
            directionLineRightBoundTop = new Point(halfWidth + quarterWidth, height * 0);
            directionLineRightBoundBottom = new Point(halfWidth + quarterWidth, height * .03);
            directionLine10Bottom = new Point(0, height * .02);
            directionLine90Bottom = new Point(0, height * .03);
            directionLine90TextTop = new Point(0, height * .04);
            directionLine90FormattedText = new[]
                                               {
                                                   new FormattedText("W", CultureInfo.CurrentUICulture,
                                                                     FlowDirection.LeftToRight, typeface,
                                                                     fontSize, brush)
                                                       {
                                                           TextAlignment = TextAlignment.Center
                                                       },
                                                   new FormattedText("N", CultureInfo.CurrentUICulture,
                                                                     FlowDirection.LeftToRight, typeface,
                                                                     fontSize, brush)
                                                       {
                                                           TextAlignment = TextAlignment.Center
                                                       },
                                                   new FormattedText("E", CultureInfo.CurrentUICulture,
                                                                     FlowDirection.LeftToRight, typeface,
                                                                     fontSize, brush)
                                                       {
                                                           TextAlignment = TextAlignment.Center
                                                       },
                                                   new FormattedText("S", CultureInfo.CurrentUICulture,
                                                                     FlowDirection.LeftToRight, typeface,
                                                                     fontSize, brush)
                                                       {
                                                           TextAlignment = TextAlignment.Center
                                                       },
                                                   new FormattedText("W", CultureInfo.CurrentUICulture,
                                                                     FlowDirection.LeftToRight, typeface,
                                                                     fontSize, brush)
                                                       {
                                                           TextAlignment = TextAlignment.Center
                                                       },
                                                   new FormattedText("N", CultureInfo.CurrentUICulture,
                                                                     FlowDirection.LeftToRight, typeface,
                                                                     fontSize, brush)
                                                       {
                                                           TextAlignment = TextAlignment.Center
                                                       },
                                                   new FormattedText("E", CultureInfo.CurrentUICulture,
                                                                     FlowDirection.LeftToRight, typeface,
                                                                     fontSize, brush)
                                                       {
                                                           TextAlignment = TextAlignment.Center
                                                       },
                                                   new FormattedText("S", CultureInfo.CurrentUICulture,
                                                                     FlowDirection.LeftToRight, typeface,
                                                                     fontSize, brush)
                                                       {
                                                           TextAlignment = TextAlignment.Center
                                                       },
                                                   new FormattedText("W", CultureInfo.CurrentUICulture,
                                                                     FlowDirection.LeftToRight, typeface,
                                                                     fontSize, brush)
                                                       {
                                                           TextAlignment = TextAlignment.Center
                                                       }
                                               };
            directionLineSpacing = width / 180;

            Point lineBottom;
            double compassOffset = width / 2 + directionLineSpacing * 7;
            for (int i = 0; i <= 360; i++)
            {
                double spacing = i * directionLineSpacing - compassOffset;
                directionLineTop.X = spacing;
                if ((i % 45) == 0)
                {
                    directionLine90Bottom.X = spacing;
                    lineBottom = directionLine90Bottom;
                    if (directionLine90FormattedText.Length > 0)
                    {
                        directionLine90TextTop.X = spacing;
                        compassText.Children.Add(directionLine90FormattedText[i / 45].BuildGeometry(directionLine90TextTop));
                    }
                }
                else if (i % 5 == 0)
                {
                    directionLine10Bottom.X = spacing;
                    lineBottom = directionLine10Bottom;
                }
                else
                {
                    continue;
                }
                compassLines.Children.Add(new LineGeometry(directionLineTop, lineBottom));
            }
            compass = new DrawingGroup();
            compass.Children.Add(new GeometryDrawing(baselinePen.Brush, baselinePen, compassLines));
            compass.Children.Add(new GeometryDrawing(brush, null, compassText));
            Rect compassClippingRect = new Rect
            {
                Height = directionLine90TextTop.Y + fontSize,
                Width = halfWidth,
                X = halfWidth / 2
            };
            compassClippingRectangle = new RectangleGeometry(compassClippingRect);

            angleLeftLeft = new Point(0, halfHeight);
            angleLeftRight = new Point(baseLine, halfHeight);
            angleRightLeft = new Point(width - baseLine, halfHeight);
            angleRightRight = new Point(width, halfHeight);

            warningFormattedText = new FormattedText("LOW VOLTAGE!", CultureInfo.CurrentUICulture,
                                                      FlowDirection.LeftToRight, typeface, fontSize,
                                                      warningBrush)
            {
                TextAlignment = TextAlignment.Center

            };
            screenshotFormattedText = new FormattedText("Captured!", CultureInfo.CurrentUICulture,
                                                      FlowDirection.LeftToRight, typeface, fontSize,
                                                      screenshotBrush)
            {
                TextAlignment = TextAlignment.Center
            };
            temperatureFormattedText = new FormattedText("Temp C", CultureInfo.CurrentUICulture,
                                                      FlowDirection.LeftToRight, typeface, fontSize,
                                                      brush)
            {
                TextAlignment = TextAlignment.Center
            };
            humidityFormattedText = new FormattedText("Humidity %", CultureInfo.CurrentUICulture,
                                                      FlowDirection.LeftToRight, typeface, fontSize,
                                                      brush)
            {
                TextAlignment = TextAlignment.Center
            };
            currentFormattedText = new FormattedText("Current", CultureInfo.CurrentUICulture, FlowDirection.LeftToRight,
                                                     typeface, fontSize, brush)
            {
                TextAlignment = TextAlignment.Center
            };
            voltageFormattedText = new FormattedText("Voltage", CultureInfo.CurrentUICulture,
                                                     FlowDirection.LeftToRight, typeface, fontSize, brush)
            {
                TextAlignment = TextAlignment.Center
            };
            fpsFormattedText = new FormattedText("FPS", CultureInfo.CurrentUICulture,
                                                    FlowDirection.LeftToRight, new Typeface("Courier"), fontSize, brush)
            {
                TextAlignment = TextAlignment.Center
            };
            thrustFormattedText = new FormattedText("Thrust", CultureInfo.CurrentUICulture,
                                                    FlowDirection.LeftToRight, new Typeface("Courier"), fontSize, brush)
            {
                TextAlignment = TextAlignment.Center
            };
            salinityFormattedText = new FormattedText("Salinity", CultureInfo.CurrentUICulture,
                                                    FlowDirection.LeftToRight, new Typeface("Courier"), fontSize, brush)
            {
                TextAlignment = TextAlignment.Center
            };
            depthFormattedText = new FormattedText("Depth", CultureInfo.CurrentUICulture,
                                                    FlowDirection.LeftToRight, new Typeface("Courier"), fontSize, brush)
            {
                TextAlignment = TextAlignment.Center
            };
            extTempFormattedText = new FormattedText("Ext Temperature", CultureInfo.CurrentUICulture,
                                                    FlowDirection.LeftToRight, new Typeface("Courier"), fontSize, brush)
            {
                TextAlignment = TextAlignment.Center
            };

            falseHorizonCrosshairs.Children.Clear();
            falseHorizonCrosshairs.Children.Add(new GeometryDrawing(falseHorizonBrush, falseHorizonPen, new GeometryGroup
            {
                Children = new GeometryCollection
                                                  {
                                                      new LineGeometry(new Point(0, halfHeight),
                                                                       new Point(width*.1, halfHeight)),
                                                      new LineGeometry(new Point(width*.90, halfHeight),
                                                                       new Point(width, halfHeight)),
                                                      new LineGeometry(new Point(halfWidth - (width*.03), halfHeight),
                                                                       new Point(halfWidth + (width*.03), halfHeight)),
                                                      new LineGeometry(
                                                          new Point(halfWidth,
                                                                    halfHeight - (height*.01)),
                                                          new Point(halfWidth,
                                                                    halfHeight + (height*.01)))
                                                  }
            }));
            falseHorizonCrosshairs.Transform = rollTransform;
            rollTransform.CenterX = halfWidth;
            rollTransform.CenterY = halfHeight;
            invertedRollTransform.CenterX = halfWidth;
            invertedRollTransform.CenterY = halfHeight;

            double pitchGaugeLeftLineStart = width * .15;
            double pitchGaugeLeftLineEnd = width * .17;
            double pitchGaugeRightLineStart = width - pitchGaugeLeftLineEnd;
            double pitchGaugeRightLineEnd = width - pitchGaugeLeftLineStart;
            double pitchGaugeYSpace = height / 10;
            double pitchGaugeCurrentY = pitchGaugeYSpace * -31;
            FormattedText angleText;
            pitchGauge.Children.Clear();
            for (int passes = 3, angle = 0, increment = 10; passes > 0; passes--)
            {
                for (; (passes > 1 && angle > -180) || angle >= 0; angle -= increment)
                {
                    pitchGauge.Children.Add(new GeometryDrawing(falseHorizonBrush, falseHorizonPen, new LineGeometry(
                        new Point(pitchGaugeLeftLineStart, pitchGaugeCurrentY),
                        new Point(pitchGaugeLeftLineEnd, pitchGaugeCurrentY)
                        )
                    ));
                    pitchGauge.Children.Add(new GeometryDrawing(falseHorizonBrush, falseHorizonPen, new LineGeometry(
                        new Point(pitchGaugeRightLineStart, pitchGaugeCurrentY),
                        new Point(pitchGaugeRightLineEnd, pitchGaugeCurrentY)
                        )
                    ));
                    angleText = new FormattedText(angle.ToString(CultureInfo.InvariantCulture) + '°', CultureInfo.CurrentUICulture,
                                                         FlowDirection.LeftToRight, typeface, fontSize, baselinePen.Brush)
                    {
                        TextAlignment = TextAlignment.Center
                    };
                    pitchGauge.Children.Add(new GeometryDrawing(falseHorizonBrush, null, angleText.BuildGeometry(new Point(pitchGaugeRightLineEnd + width02, pitchGaugeCurrentY - (angleText.Height / 2)))));
                    pitchGauge.Children.Add(new GeometryDrawing(falseHorizonBrush, null, angleText.BuildGeometry(new Point(pitchGaugeLeftLineStart - width02, pitchGaugeCurrentY - (angleText.Height / 2)))));
                    pitchGaugeCurrentY += pitchGaugeYSpace;
                }
                angle = 180;
            }
            pitchGauge.Transform = new TransformGroup
            {
                Children = new TransformCollection{
                    pitchTransform,
                    rollTransform
                }
            };
            maxInnerClippingRectangle = new PathGeometry(new PathFigureCollection {
                new PathFigure(new Point(0,0), new PathSegmentCollection{
                    new LineSegment(new Point(0, 0), false),
                    new LineSegment(compassClippingRect.TopLeft, false),
                    new LineSegment(compassClippingRect.BottomLeft, false),
                    new LineSegment(compassClippingRect.BottomRight, false),
                    new LineSegment(compassClippingRect.TopRight, false),
                    new LineSegment(new Point(width, 0), false),
                    new LineSegment(new Point(width, sideGaugeTop), false),
                    new LineSegment(new Point(width - width015, sideGaugeTop), false),
                    new LineSegment(new Point(width - width015, sideGaugeBottom), false),
                    new LineSegment(new Point(width, sideGaugeBottom), false),
                    new LineSegment(new Point(width, height - (fontSize * 3)), false),
                    new LineSegment(new Point(0, height - (fontSize * 3)), false),
                    new LineSegment(new Point(0, sideGaugeBottom), false),
                    new LineSegment(new Point(width015, sideGaugeBottom), false),
                    new LineSegment(new Point(width015, sideGaugeTop), false),
                    new LineSegment(new Point(0, sideGaugeTop), false)
                },
                true)
            });

            mapGeometryGroup.Children.Clear();
            mapRadius = height * 0.05;
            double locationSideLength = 2 * mapRadius * Math.Cos(30);
            Point mapCenter = new Point(halfWidth, height - mapRadius - 5);
            mapBrush = falseHorizonBrush.Clone();
            mapBrush.Opacity = 0.25;
            mapPen = new Pen(mapBrush, baselinePen.Thickness);
            mapGeometryGroup.Children.Add(new EllipseGeometry(mapCenter, mapRadius, mapRadius));
            mapGeometryGroup.Children.Add(new EllipseGeometry(mapCenter, 1, 1));

            locationGeometryGroup.Children.Clear();
            Point locationB = new Point(mapCenter.X - locationSideLength, mapCenter.Y + locationSideLength);
            Point locationC = new Point(mapCenter.X + locationSideLength, mapCenter.Y + locationSideLength);
            locationGeometryGroup.Children.Add(new LineGeometry(mapCenter, locationB));
            locationGeometryGroup.Children.Add(new LineGeometry(mapCenter, locationC));
            locationYawTransform.CenterX = mapCenter.X;
            locationYawTransform.CenterY = mapCenter.Y;
            TransformGroup locationTransformGroup = new TransformGroup();
            locationTransformGroup.Children.Add(locationYawTransform);
            locationTransformGroup.Children.Add(locationTranslateTransform);
            InvalidateVisual();
        }
Ejemplo n.º 10
0
 private static Brush _mapAbsoluteFill(Brush fill, Rect bounds) {
    if (!(fill is LinearGradientBrush)) return fill;
    var brush = (LinearGradientBrush)fill.Clone();
    var stops = brush.GradientStops;
    var max = bounds.Height;
    if (stops == null || max.IsZero()) return fill;
    for (var i = 0; i < stops.Count - 1; i++) {
       var offset = stops[i].Offset;
       if (!(i == 0 && offset.IsZero() || i == stops.Count - 1 && offset.IsOne())) {
          offset = (offset < 0 ? max + offset : offset) / max;
       }
       stops[i] = new GradientStop(stops[i].Color, offset);
    }
    return brush;
 }
Ejemplo n.º 11
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();
		}
Ejemplo n.º 12
0
 private void SetStaticBrushColor(string resourceKey, Brush sourceBrush)
 {
     Resources[resourceKey] = sourceBrush.Clone();
 }
Ejemplo n.º 13
0
Archivo: Icon.cs Proyecto: sbambach/ATF
 /// <summary>
 /// Swap the color of a brush based on a color mapping provided by the ColorCallback</summary>
 /// <param name="brush">Original brush</param>
 /// <param name="colorCallback">Callback to provide the color mapping</param>
 /// <returns>Color-swapped brush</returns>
 public static Brush SwapColors(Brush brush, ColorCallback colorCallback)
 {
     if (colorCallback == null)
     {
         throw new ArgumentNullException("colorCallback");
     }
     Brush brush2 = brush;
     if (brush != null)
     {
         brush2 = brush.Clone();
         SwapColorsWithoutCloning(brush2, colorCallback);
         brush2.Freeze();
     }
     return brush2;
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewActionMenuIcon"/> class.
        /// </summary>
        /// <param name="icon">The icon.</param>
        public ViewActionMenuIcon(Brush icon)
        {
            if (icon == null)
            {
                Background = Brushes.Transparent;
                return;
            }

            var brush = icon.Clone();

            var drawingBrush = brush as DrawingBrush;
            if (drawingBrush != null) drawingBrush.Stretch = Stretch.Uniform;

            var imageBrush = brush as ImageBrush;
            if (imageBrush != null) imageBrush.Stretch = Stretch.Uniform;

            Background = brush;
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Creates a copy of a brush with the specified opacity.
 /// </summary>
 /// <param name="brush">
 /// The brush to copy.
 /// </param>
 /// <param name="opacity">
 /// The opacity.
 /// </param>
 /// <returns>
 /// </returns>
 public static Brush ChangeOpacity(Brush brush, double opacity)
 {
     brush = brush.Clone();
     brush.Opacity = opacity;
     return brush;
 }
Ejemplo n.º 16
0
        private static Pen GetBorderPen(Brush border)
        {
            Pen pen = null;

            if (border != null)
            {
                if (_commonBorderPen == null)   // Common case, if non-null, avoid the lock
                {
                    lock (_resourceAccess)   // If non-null, lock to create the pen for thread safety
                    {
                        if (_commonBorderPen == null)   // Check again in case _pen was created within the last line
                        {
                            // Assume that the first render of Button uses the most common brush for the app.
                            // This breaks down if (a) the first Button is disabled, (b) the first Button is
                            // customized, or (c) BulletChrome becomes more broadly used than just on Button.
                            //
                            // If these cons sufficiently weaken the effectiveness of this cache, then we need
                            // to build a larger brush-to-pen mapping cache.


                            // If the brush is not already frozen, we need to create our own
                            // copy.  Otherwise we will inadvertently freeze the user's
                            // BorderBrush when we freeze the pen below.
                            if (!border.IsFrozen && border.CanFreeze)
                            {
                                border = border.Clone();
                                border.Freeze();
                            }

                            Pen commonPen = new Pen(border, 1);
                            if (commonPen.CanFreeze)
                            {
                                // Only save frozen pens, some brushes such as VisualBrush
                                // can not be frozen
                                commonPen.Freeze();
                                _commonBorderPen = commonPen;
                            }
                        }
                    }
                }

                if (_commonBorderPen != null && border == _commonBorderPen.Brush)
                {

                    pen = _commonBorderPen;
                }
                else
                {
                    if (!border.IsFrozen && border.CanFreeze)
                    {
                        border = border.Clone();
                        border.Freeze();
                    }
                    
                    pen = new Pen(border, 1);
                    if (pen.CanFreeze)
                    {
                        pen.Freeze();
                    }
                }
            }

            return pen;
        }
Ejemplo n.º 17
0
        private Brush CreateCommonBorderPen(Brush borderBrush)
        {
            lock (locker)
            {
                if (_commonBorderPen == null)
                {
                    if (!borderBrush.IsFrozen && borderBrush.CanFreeze)
                    {
                        borderBrush = borderBrush.Clone();
                        borderBrush.Freeze();
                    }

                    var p = new Pen(borderBrush, 1.0);
                    if (p.CanFreeze)
                    {
                        p.Freeze();
                        _commonBorderPen = p;
                    }
                }
            }
            return borderBrush;
        }