A game framework written with osu! in mind.
at master 1.7 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using osu.Framework.Extensions; 5using osu.Framework.Graphics; 6using osu.Framework.Graphics.Containers; 7 8namespace osu.Framework.Testing 9{ 10 /// <summary> 11 /// An abstract test case which exposes small cells arranged in a grid. 12 /// Useful for displaying multiple configurations of a tested component at a glance. 13 /// </summary> 14 public abstract class GridTestScene : TestScene 15 { 16 private readonly Drawable[,] cells; 17 18 /// <summary> 19 /// The amount of rows in the grid. 20 /// </summary> 21 protected readonly int Rows; 22 23 /// <summary> 24 /// The amount of columns in the grid. 25 /// </summary> 26 protected readonly int Cols; 27 28 /// <summary> 29 /// Constructs a grid test case with the given dimensions. 30 /// </summary> 31 protected GridTestScene(int rows, int cols) 32 { 33 Rows = rows; 34 Cols = cols; 35 36 GridContainer testContainer; 37 Add(testContainer = new GridContainer { RelativeSizeAxes = Axes.Both }); 38 39 cells = new Drawable[rows, cols]; 40 41 for (int r = 0; r < rows; r++) 42 { 43 for (int c = 0; c < cols; c++) 44 cells[r, c] = new Container { RelativeSizeAxes = Axes.Both }; 45 } 46 47 testContainer.Content = cells.ToJagged(); 48 } 49 50 protected Container Cell(int index) => (Container)cells[index / Cols, index % Cols]; 51 protected Container Cell(int row, int col) => (Container)cells[row, col]; 52 } 53}