示例#1
0
        private GridButton GridButtonStyler(GridButton btn)
        {
            int x = btn.X;
            int y = btn.Y;

            buttons[x, y].Text = "";
            if (model.getBoard()[x, y] == FieldType.NO_WALL)
            {
                buttons[x, y].BackgroundImage = noWallTexture;
            }
            else if (model.getBoard()[x, y] == FieldType.WALL)
            {
                buttons[x, y].BackgroundImage = WallTexture;
            }
            else if (model.getBoard()[x, y] == FieldType.CANNOT_WALL)
            {
                buttons[x, y].BackgroundImage = cannotWallTexture;
            }
            else if (model.getBoard()[x, y] == FieldType.MAGNET)
            {
                Image imageBackground = noWallTexture;
                int   size            = Convert.ToInt32(imageBackground.Width * 0.8);
                Image imageOverlay    = new Bitmap(magnetTexture, new Size(size, size));

                Image img = new Bitmap(imageBackground.Width, imageBackground.Height);
                using (Graphics gr = Graphics.FromImage(img))
                {
                    gr.DrawImage(imageBackground, new Point(0, 0));
                    gr.DrawImage(imageOverlay, new Point(Convert.ToInt32(imageBackground.Size.Width * 0.1), Convert.ToInt32(imageBackground.Size.Height * 0.1)));
                }

                btn.BackgroundImage = img;
            }


            if (model.getRobotPos().Equals(new Position(x, y)))
            {
                Image imageBackground = (model.getFieldTypeOnRobot() == FieldType.NO_WALL) ? noWallTexture : cannotWallTexture;
                int   size            = Convert.ToInt32(imageBackground.Width * 0.8);
                Image imageOverlay    = new Bitmap(robotTexture, new Size(size, size));

                Image img = new Bitmap(imageBackground.Width, imageBackground.Height);
                using (Graphics gr = Graphics.FromImage(img))
                {
                    gr.DrawImage(imageBackground, new Point(0, 0));
                    gr.DrawImage(imageOverlay, new Point(Convert.ToInt32(imageBackground.Size.Width * 0.1), Convert.ToInt32(imageBackground.Size.Height * 0.1)));
                }

                btn.BackgroundImage = img;
            }


            btn.BackgroundImageLayout = ImageLayout.Stretch;

            return(btn);
        }