public static AM.Color[] ToSKColors(this Color[] colors)
        {
            var skColors = new AM.Color[colors.Length];

            for (int i = 0; i < colors.Length; i++)
            {
                skColors[i] = colors[i].ToColor();
            }

            return(skColors);
        }
Beispiel #2
0
        private Rectangle NewRectangle(Color color)
        {
            var r = new Rectangle
            {
                Width  = FieldHelper.BlockWidth * 0.9,
                Height = FieldHelper.BlockHeight * 0.9,

                Fill = new SolidColorBrush(color, 1)
            };

            _canvas.Children.Add(r);
            return(r);
        }
Beispiel #3
0
        public DevRender(Enviroment enviroment, int winWidth, int winHeight, params Camera[] cameras)
        {
            Width  = winHeight;
            Height = winHeight;
            Avalonia.Vector dpi         = new Avalonia.Vector(96, 96);
            PixelSize       wbitmapSize = new PixelSize(Width, Height);
            WriteableBitmap wbitmap     = new WriteableBitmap(wbitmapSize, dpi, PixelFormat.Bgra8888);

            Enviroment = enviroment;
            Cameras    = cameras.ToList();
            foreach (var cam in Cameras)
            {
                cam.ScreenWidth  = winWidth;
                cam.ScreenHeight = winHeight;
            }
            Preparer = new BufferPreparer(Cameras, enviroment);
            // RenderForm = new Form1()
            //  {
            //      BackColor = Color.Black,
            //     Width = winWidth,
            //     Height = winHeight
            //  };
            Controller = new Controller(this);


            //RenderForm.KeyDown += (args, e) => Controller.KeyDown(e);
            //  RenderForm.KeyUp += (args, e) => Controller.KeyUp(e);
            //  RenderForm.MouseMove += (args, e) => Controller.HanleMouse(e);
            Timer          = new DispatcherTimer();
            Timer.Interval = new System.TimeSpan(0, 0, 0, 0, 100);
            Timer.Tick    += (args, e) =>
            {
                Controller.ComputeKeys();
                Preparer.PrepareNewBuffer();
                var buffer = Preparer.GetBuffer();
                if (buffer.Width != 1)
                {
                    for (int row = 0; row < Height; row++)
                    {
                        for (int col = 0; col < Width; col++)
                        {
                            System.Drawing.Color colr  = buffer.GetPixel(col, row);
                            Avalonia.Media.Color color = Avalonia.Media.Color.FromArgb(colr.A, colr.R, colr.G, colr.B);
                            wbitmap.SetPixel(col, row, color);
                        }
                    }
                    //RenderForm.BackgroundImage = new Bitmap(buffer , RenderForm.Size);
                }
            };
        }
Beispiel #4
0
        /// <summary>
        /// Refreshes the tile position or draws a new one if it did not exist in the canvas
        /// </summary>
        /// <param name="tileXy"></param>
        /// <returns>Rectangle object mapped to the tile</returns>
        public Rectangle DrawTile(TileXy tileXy)
        {
            if (tileXy.Tile == null)
            {
                return(null);
            }

            Rectangle rectangle;

            if (_tileRectangleMap.ContainsKey(tileXy.Tile))
            {
                rectangle = _tileRectangleMap[tileXy.Tile];
            }
            else
            {
                var color = Color.Parse(tileXy.Tile.Color);
                rectangle = NewRectangle(color);
                _tileRectangleMap.Add(tileXy.Tile, rectangle);
            }
            Canvas.SetLeft(rectangle, tileXy.X * FieldHelper.BlockWidth + 1);
            Canvas.SetTop(rectangle, tileXy.Y * FieldHelper.BlockHeight + 1);

            return(rectangle);
        }
Beispiel #5
0
 public static CSharpMathColor ToCSharpMathColor(this AvaloniaColor color) =>
 new CSharpMathColor(color.R, color.G, color.B, color.A);
Beispiel #6
0
 public static SKColor ToSKColor(this Avalonia.Media.Color color, byte opacity)
 {
     return(new SKColor(color.R, color.G, color.B, (byte)(color.A * opacity / 255d)));
 }
Beispiel #7
0
 public static SKColor ToSKColor(this Avalonia.Media.Color color)
 {
     return(new SKColor(color.R, color.G, color.B, color.A));
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Type typeOfValue = value == null ? null : value.GetType();
            var  pstr        = (string)(parameter.ToString());
            var  ss          = pstr.Split(' ');

            object res     = null;
            string str     = null;
            bool   matches = false;
            var    matchFn = false;

            if (pstr.StartsWith("?"))
            {
                matchFn = true;
                if (pstr.StartsWith("?IsNull "))
                {
                    matches = value == null;
                }
                else if (pstr == "?Darker" || pstr.StartsWith("?Darker "))
                {
                    if (value == null)
                    {
                        return(null);
                    }

                    var brush = value as SolidColorBrush;

                    var col = brush.Color;

                    var f = 0.5;

                    if (ss.Length > 1)
                    {
                        f = double.Parse(ss[1]);
                    }

                    var newCol = Color.FromArgb(col.A,
                                                (byte)(col.R / 255d * f * 255d),
                                                (byte)(col.G / 255d * f * 255d),
                                                (byte)(col.B / 255d * f * 255d));

                    res = new SolidColorBrush(newCol);

                    return(res);
                }
                else if (pstr == "?Lighter" || pstr.StartsWith("?Lighter "))
                {
                    if (value == null)
                    {
                        return(null);
                    }

                    var brush = value as SolidColorBrush;

                    var col = brush.Color;

                    var f = 0.5;

                    if (ss.Length > 1)
                    {
                        f = double.Parse(ss[1]);
                    }

                    var newCol = Color.FromArgb(col.A,
                                                (byte)(col.R + (1d - col.R / 255d) * f * 255d),
                                                (byte)(col.G + (1d - col.G / 255d) * f * 255d),
                                                (byte)(col.B / (1d - col.B / 255d) * f * 255d));

                    res = new SolidColorBrush(newCol);

                    return(res);
                }
                else if (pstr.StartsWith("?Round "))
                {
                    var dec = int.Parse(ss[1]);

                    if (typeOfValue == typeofDecimal)
                    {
                        res = Round((decimal)value, dec);
                    }
                    else if (typeOfValue == typeofFloat)
                    {
                        res = Round((float)value, dec);
                    }
                    else if (typeOfValue == typeofDouble)
                    {
                        res = Round((double)value, dec);
                    }

                    return(System.Convert.ChangeType(res, targetType));
                }
                else
                {
                    matchFn = false;
                }
            }

            if (!matchFn)
            {
                str = (string)(value == null ? "" : value.ToString());

                if (targetType == typeofBoolean || typeOfValue == typeofBoolean)
                {
                    var tl = str.ToLower();
                    if (tl == "true" || tl == "false")
                    {
                        str = tl;
                    }
                }

                matches = str == ss[0].ToLower();
                if (!matches && ss.Length <= 2)
                {
                    return(null);
                }
            }

            var i = matches ? 1 : 2;

            if (targetType == typeofBoolean)
            {
                res = bool.Parse(ss[i]);
            }
            else if (targetType == typeofThickness)
            {
                res = new Thickness(int.Parse(ss[i]));
            }
            else if (targetType == typeofIBrush)
            {
                res = new SolidColorBrush(Color.Parse(ss[i]));
            }
            else if (targetType == typeofDouble)
            {
                res = double.Parse(ss[i]);
            }
            else
            {
                res = System.Convert.ChangeType(ss[i], targetType);
            }

            return(res);
        }
Beispiel #9
0
 internal static System.Drawing.Color ToCSharpMathColor(this AvaloniaColor color) =>
 System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B);
Beispiel #10
0
 public Color(Avalonia.Media.Color color)
     : this(color.A, color.R, color.G, color.B)
 {
 }
Beispiel #11
0
 public static System.Drawing.Color FromNative(this Avalonia.Media.Color color)
 {
     return(System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B));
 }
Beispiel #12
0
 public static SKColor ToSKColor(this Media.Color c)
 {
     return(new SKColor(c.R, c.G, c.B, c.A));
 }
Beispiel #13
0
 /// <summary>
 /// Convert from WPF color to core color.
 /// </summary>
 public static RColor Convert(Color c)
 {
     return RColor.FromArgb(c.A, c.R, c.G, c.B);
 }