コード例 #1
0
        public void IsRowsRemovedCorrect()
        {
            //Test setup
            System.Windows.Controls.Canvas canvas = new System.Windows.Controls.Canvas();
            NameScope.SetNameScope(canvas, new NameScope());
            GameLogic        g        = new GameLogic(new PlayerX(), true);
            List <Rectangle> testList = new List <Rectangle>();

            g.CreateGrid(10, 10, canvas, 1);

            //Create a row to delete
            for (int i = 0; i < 10; i++)
            {
                Rectangle newColor = (Rectangle)canvas.FindName("id1" + "X" + i + "Y6");
                newColor.Fill = Brushes.Azure;
            }
            //Expected result
            int expectedRowsRemoved = 1;
        }
コード例 #2
0
        public static void CreateRemappedRasterFromVector(string xamlFile, System.Windows.Media.Color newColor, System.IO.Stream stream, double height, double width, string dynamicText)
        {
            string remapBase = "ReMapMe_";
            int    max       = 3;
            int    index     = 0;
            int    missed    = 0;
            Object temp      = null;
            string dynamText = "DynamicText";

            System.Windows.Controls.Canvas theVisual = System.Windows.Markup.XamlReader.Load(new System.IO.FileStream(xamlFile, System.IO.FileMode.Open)) as System.Windows.Controls.Canvas;

            if (null == theVisual)
            {
                return;
            }

            System.Windows.Size size = new System.Windows.Size(width, height);

            System.Windows.Media.DrawingVisual drawingVisual = new System.Windows.Media.DrawingVisual();

            System.Windows.Media.VisualBrush visualBrush = new System.Windows.Media.VisualBrush(theVisual);

            System.Windows.Rect rect = new System.Windows.Rect(new System.Windows.Point(), size);

            while (missed < max)
            {
                string elementid = remapBase + index;

                temp = theVisual.FindName(elementid);

                if (null == temp)
                {
                    missed++;
                    index++;
                    continue;
                }

                System.Windows.Media.SolidColorBrush scb = ((temp as System.Windows.Shapes.Path).Fill as System.Windows.Media.SolidColorBrush);

                System.Windows.Media.Color c = scb.Color;
                c.B = newColor.B;
                c.R = newColor.R;
                c.G = newColor.G;

                scb.Color = c;
                index++;
            }

            theVisual.Arrange(rect);
            theVisual.UpdateLayout();

            using (System.Windows.Media.DrawingContext dc = drawingVisual.RenderOpen())
            {
                dc.DrawRectangle(visualBrush, null, rect);
            }

            if (!dynamText.IsNullOrWhitespace())
            {
                temp = theVisual.FindName(dynamText);
                if (null != temp)
                {
                    //do dynamic text shit
                }
            }

            System.Windows.Media.Imaging.RenderTargetBitmap render = new System.Windows.Media.Imaging.RenderTargetBitmap((int)height, (int)width, 96, 96, System.Windows.Media.PixelFormats.Pbgra32);
            render.Render(drawingVisual);

            System.Windows.Media.Imaging.PngBitmapEncoder encoder = new System.Windows.Media.Imaging.PngBitmapEncoder();

            encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(render));

            encoder.Save(stream);

            stream.Flush();
            stream.Close();

            visualBrush   = null;
            drawingVisual = null;
            theVisual     = null;
            render        = null;
            encoder       = null;
        }