Exemple #1
0
        public static System.Windows.Media.SolidColorBrush ToNativeBrush(this SolidColorBrush brush)
        {
            var nativeBrush = new System.Windows.Media.SolidColorBrush(brush.Color.ToNativeColor());

            nativeBrush.Freeze();
            return(nativeBrush);
        }
Exemple #2
0
 // C'tor
 internal Player(Definitions.GameDef g, string name, byte id, ulong pkey)
 {
     // Init fields
     this.name = name; this.Id = id; this.PublicKey = pkey;
     // Register the player
     all.Add(this);
     OnPropertyChanged("Color");
     // Create the color brushes
     solidBrush = new System.Windows.Media.SolidColorBrush(Color);
     solidBrush.Freeze();
     transparentBrush = new System.Windows.Media.SolidColorBrush(Color);
     transparentBrush.Opacity = 0.4;
     transparentBrush.Freeze();
     OnPropertyChanged("Brush");
     OnPropertyChanged("TransparentBrush");
     // Create counters
     counters = new Counter[g.PlayerDefinition.Counters != null ? g.PlayerDefinition.Counters.Length : 0];
     for (int i = 0; i < Counters.Length; i++)
         Counters[i] = new Counter(this, g.PlayerDefinition.Counters[i]);
       // Create variables
       Variables = new Dictionary<string, int>();
       foreach (var varDef in g.Variables.Where(v => !v.Global))
     Variables.Add(varDef.Name, varDef.DefaultValue);
     // Create a hand, if any
     if (g.PlayerDefinition.Hand != null)
         hand = new Hand(this, g.PlayerDefinition.Hand);
     // Create groups
     groups = new Group[g.PlayerDefinition.Groups != null ? g.PlayerDefinition.Groups.Length + 1 : 1];
     groups[0] = hand;
     for (int i = 1; i < IndexedGroups.Length; i++)
         groups[i] = new Pile(this, g.PlayerDefinition.Groups[i - 1]);
     // Raise the event
     if (PlayerAdded != null) PlayerAdded(null, new PlayerEventArgs(this));
 }
 /// <summary>
 /// Gets a solid color brush from the color specified.
 /// </summary>
 /// <param name="color">The color in RGBA format (A is the least significant byte).</param>
 /// <returns>A solid color brush.</returns>
 public System.Windows.Media.Brush GetBrushFromColor(ExCSS.Color color)
 {
     if (!_cachedSolidBrushes.TryGetValue(color, out var brush))
     {
         brush = new System.Windows.Media.SolidColorBrush(ToColor(color));
         brush.Freeze();
         _cachedSolidBrushes.Add(color, brush);
     }
     return(brush);
 }
Exemple #4
0
        public System.Windows.Media.Brush GetMediaBrush()
        {
            if (_mediabrush == null)
            {
                if (type == BrushType.Solid)
                {
                    System.Windows.Media.SolidColorBrush brush = new System.Windows.Media.SolidColorBrush(
                        Utils.ColorUtils.DrawingColorToMediaColor(color_gradients[0.0f])
                        );
                    brush.Freeze();

                    _mediabrush = brush;
                }
                else if (type == BrushType.Linear)
                {
                    System.Windows.Media.GradientStopCollection collection = new System.Windows.Media.GradientStopCollection();

                    foreach (var kvp in color_gradients)
                    {
                        collection.Add(
                            new System.Windows.Media.GradientStop(
                                Utils.ColorUtils.DrawingColorToMediaColor(kvp.Value),
                                kvp.Key)
                            );
                    }

                    System.Windows.Media.LinearGradientBrush brush = new System.Windows.Media.LinearGradientBrush(collection);
                    brush.StartPoint = new System.Windows.Point(start.X, start.Y);
                    brush.EndPoint   = new System.Windows.Point(end.X, end.Y);

                    switch (wrap)
                    {
                    case BrushWrap.None:
                        brush.SpreadMethod = System.Windows.Media.GradientSpreadMethod.Pad;
                        break;

                    case BrushWrap.Repeat:
                        brush.SpreadMethod = System.Windows.Media.GradientSpreadMethod.Repeat;
                        break;

                    case BrushWrap.Reflect:
                        brush.SpreadMethod = System.Windows.Media.GradientSpreadMethod.Reflect;
                        break;
                    }

                    _mediabrush = brush;
                }
                else if (type == BrushType.Radial)
                {
                    System.Windows.Media.GradientStopCollection collection = new System.Windows.Media.GradientStopCollection();

                    foreach (var kvp in color_gradients)
                    {
                        collection.Add(
                            new System.Windows.Media.GradientStop(
                                Utils.ColorUtils.DrawingColorToMediaColor(kvp.Value),
                                kvp.Key)
                            );
                    }

                    System.Windows.Media.RadialGradientBrush brush = new System.Windows.Media.RadialGradientBrush(collection);
                    brush.Center  = new System.Windows.Point(center.X, center.Y);
                    brush.RadiusX = end.X / 2.0;
                    brush.RadiusY = end.Y / 2.0;

                    switch (wrap)
                    {
                    case BrushWrap.None:
                        brush.SpreadMethod = System.Windows.Media.GradientSpreadMethod.Pad;
                        break;

                    case BrushWrap.Repeat:
                        brush.SpreadMethod = System.Windows.Media.GradientSpreadMethod.Repeat;
                        break;

                    case BrushWrap.Reflect:
                        brush.SpreadMethod = System.Windows.Media.GradientSpreadMethod.Reflect;
                        break;
                    }

                    _mediabrush = brush;
                }
                else
                {
                    System.Windows.Media.SolidColorBrush brush = new System.Windows.Media.SolidColorBrush(
                        System.Windows.Media.Color.FromArgb(255, 255, 0, 0)
                        );
                    brush.Freeze();

                    _mediabrush = brush;
                }
            }

            return(_mediabrush);
        }
Exemple #5
0
 private static System.Windows.Media.SolidColorBrush CreateFrozenBrush(System.Windows.Media.Color color)
 {
     System.Windows.Media.SolidColorBrush brush = new System.Windows.Media.SolidColorBrush(color);
     brush.Freeze();
     return(brush);
 }
Exemple #6
0
        public void Draw(TextView textView, System.Windows.Media.DrawingContext drawingContext) {
            if (markers == null || !textView.VisualLinesValid) {
                return;
            }
            var visualLines = textView.VisualLines;
            if (visualLines.Count == 0) {
                return;
            }
            int viewStart = visualLines.First().FirstDocumentLine.Offset;
            int viewEnd = visualLines.Last().LastDocumentLine.EndOffset;
            foreach (TextMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart)) {
                if (marker.BackgroundColor != null) {
                    var geoBuilder = new BackgroundGeometryBuilder { AlignToWholePixels = true, CornerRadius = 3 };
                    geoBuilder.AddSegment(textView, marker);
                    System.Windows.Media.Geometry geometry = geoBuilder.CreateGeometry();
                    if (geometry != null) {
                        System.Windows.Media.Color color = marker.BackgroundColor.Value;
                        var brush = new System.Windows.Media.SolidColorBrush(color);
                        brush.Freeze();
                        drawingContext.DrawGeometry(brush, null, geometry);
                    }
                }
                foreach (System.Windows.Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker)) {
                    var startPoint = r.BottomLeft;
                    var endPoint = r.BottomRight;

                    var usedPen = new System.Windows.Media.Pen(new System.Windows.Media.SolidColorBrush(marker.MarkerColor), 1);
                    usedPen.Freeze();
                    const double offset = 2.5;

                    int count = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4);

                    var geometry = new System.Windows.Media.StreamGeometry();

                    using (System.Windows.Media.StreamGeometryContext ctx = geometry.Open()) {
                        ctx.BeginFigure(startPoint, false, false);
                        ctx.PolyLineTo(CreatePoints(startPoint, endPoint, offset, count).ToArray(), true, false);
                    }

                    geometry.Freeze();

                    drawingContext.DrawGeometry(System.Windows.Media.Brushes.Transparent, usedPen, geometry);
                    break;
                }
            }
        }