Exemple #1
0
        public GridView()
        {
            InitializeComponent();

            viewModel = new GridViewModel(12, 12);
            DataContext = viewModel;

            content.Content = new TextBlock() {
                Text ="pOUET"
            };
        }
Exemple #2
0
        public GameViewModel(WriteableBitmap img)
        {
            // Invert width and height cause of bmp?
            GridViewModel = new GridViewModel(img.PixelHeight, img.PixelWidth);

            // Get every pixel
            for (int x = 0; x < img.PixelWidth; x++)
            {
                for (int y = 0; y < img.PixelHeight; y++)
                {
                    Color color = img.GetPixel(x, y);

                    float r, g, b, a;

                    if (color.A < 20)
                    {
                        a = 1;
                        r = 1;
                        g = 1;
                        b = 1;
                    }
                    else
                    {
                        a = 1;
                        r = color.R / 255f;
                        g = color.G / 255f;
                        b = color.B / 255f;
                    }

                    // invert x and y
                    GridViewModel.SetPixelData(y, x, new Data.CellColor()
                    {
                        A = a,
                        R = r,
                        G = g,
                        B = b,
                    });
                }
            }

            GridViewModel.SetupGrid();
            GridViewModel.UpdateView(null);
        }
Exemple #3
0
 public void SetGrid(GridViewModel viewModel)
 {
     this.viewModel = viewModel;
     DataContext = viewModel;
 }
Exemple #4
-1
        public GameViewModel(WriteableBitmap img)
        {
            // Invert width and height cause of bmp?
            GridViewModel = new GridViewModel(img.PixelHeight, img.PixelWidth);

            // Get every pixel
            for (int x = 0; x < img.PixelWidth; x++)
            {
                for (int y = 0; y < img.PixelHeight; y++)
                {
                    Color color = img.GetPixel(x, y);

                    float r, g, b, a;

                    if (color.A < 20)
                    {
                        a = 1;
                        r = 1;
                        g = 1;
                        b = 1;
                    }
                    else
                    {
                        a = 1;
                        r = color.R / 255f;
                        g = color.G / 255f;
                        b = color.B / 255f;
                    }

                    // invert x and y
                    GridViewModel.SetPixelData(y, x, new Data.CellColor()
                    {
                        A = a,
                        R = r,
                        G = g,
                        B = b,
                    });
                }
            }

            GridViewModel.SetupGrid();
            GridViewModel.UpdateView(null);
        }