Exemplo n.º 1
0
        public override void Draw()
        {
            UpdateCellColors();
            Bitmap   point_img    = new Bitmap(point_path);
            Bitmap   top_layer    = NewLayer();
            Bitmap   bottom_layer = NewLayer();
            Bitmap   black_layer  = NewLayer();
            Bitmap   black        = NewIntegerPixelLayer();
            Bitmap   canvas_layer = NewLayer();
            Graphics paint        = Graphics.FromImage(TopCanvas);

            //draw top canvas
            for (int i = 0; i < TopMatrix.GetLength(0); i++)
            {
                for (int j = 0; j < TopMatrix.GetLength(1); j++)
                {
                    if (TopMatrix[i, j] == CellColor.BLACK)
                    {
                        Point position = GetCellCanvasPosition(i, j);
                        paint.DrawImage(point_img, new Rectangle(position.X, position.Y, TetrisStep, TetrisStep), new Rectangle(0, 0, point_img.Width, point_img.Height), GraphicsUnit.Pixel);
                    }
                }
            }
            paint = Graphics.FromImage(top_layer);
            paint.DrawImage(TopCanvas, new RectangleF(TopPosintion.X, TopPosintion.Y, TopSize.Width, TopSize.Height), new Rectangle(0, 0, TopCanvas.Width, TopCanvas.Height), GraphicsUnit.Pixel);

            //draw bottom canvas
            paint = Graphics.FromImage(BottomCanvas);
            for (int i = 0; i < BottomMatrix.GetLength(0); i++)
            {
                for (int j = 0; j < BottomMatrix.GetLength(1); j++)
                {
                    if (BottomMatrix[i, j] == CellColor.BLACK)
                    {
                        Point position = GetCellCanvasPosition(i, j);
                        paint.DrawImage(point_img, new Rectangle(position.X, position.Y, TetrisStep, TetrisStep), new Rectangle(0, 0, point_img.Width, point_img.Height), GraphicsUnit.Pixel);
                    }
                }
            }
            paint = Graphics.FromImage(bottom_layer);
            paint.DrawImage(BottomCanvas, new RectangleF(BottomPosition.X, BottomPosition.Y, BottomSize.Width, BottomSize.Height), new Rectangle(0, 0, BottomCanvas.Width, BottomCanvas.Height), GraphicsUnit.Pixel);

            //draw black layer
            paint = Graphics.FromImage(black);
            var bc = from b in Matrix.CellMatrix.Cast <DataCell>() where b.Color == CellColor.BLACK select b;

            foreach (var b in bc)
            {
                paint.DrawImage(point_img, GetCellRectangle(b.Position.Row, b.Position.Column), new Rectangle(0, 0, point_img.Width, point_img.Height), GraphicsUnit.Pixel);
            }
            paint = Graphics.FromImage(black_layer);
            paint.DrawImage(black, new RectangleF(CodePosition.X, CodePosition.Y, CodeSize.Width, CodeSize.Height), new Rectangle(0, 0, black.Width, black.Height), GraphicsUnit.Pixel);

            //draw canvas
            paint = Graphics.FromImage(canvas_layer);
            paint.FillRectangle(new SolidBrush(canvas_color), new Rectangle(0, 0, Canvas.Width, Canvas.Height));

            MergeLayers(canvas_layer, top_layer, bottom_layer, black_layer);
        }
Exemplo n.º 2
0
        private void UpdateTopCellColors()
        {
            Bitmap   sample       = new Bitmap(top_sample_path);
            Bitmap   sample_back  = new Bitmap(TopCanvas.Width, TopCanvas.Height);
            Graphics sample_paint = Graphics.FromImage(sample_back);

            sample_paint.DrawImage(sample, new Rectangle(0, 0, sample_back.Width, sample_back.Height), new Rectangle(0, 0, sample.Width, sample.Height), GraphicsUnit.Pixel);
            Point center_point;

            for (int i = 0; i < TopMatrix.GetLength(0); i++)
            {
                for (int j = 0; j < TopMatrix.GetLength(1); j++)
                {
                    center_point = GetCellCanvasCenterPosition(i, j);
                    if (sample_back.GetPixel(center_point.X, center_point.Y).A > 128)
                    {
                        TopMatrix[i, j] = CellColor.BLACK;
                    }
                }
            }
        }