using Annulus; using Azimuth; using Glass; namespace Konis.Testbed { /// /// Where the testbed's panels sit on a screen, and where the windows that float over them open. Every rect is /// carved from the screen, so a screen too small for a panel squeezes it to what is left. /// public struct ScreenLayout { /// /// The panel of controls down the left edge. /// public Rect Controls; /// /// The row of speed buttons along the top, in the middle of the screen. /// public Rect Speed; /// /// The panel of statistics in the top right corner. /// public Rect Stats; /// /// The status bar, which runs the width of the screen along the bottom. /// public Rect Status; /// /// The tuning window. It opens under the stats panel, or as far up the right edge as it takes to clear the /// status bar when there isn't room there. /// public Rect Tuning; /// /// The space beside the controls, where an editor window opens. /// public Rect EditorArea; /// /// Returns the place an editor window of opens, in the top left of . /// public Rect EditorSlot(Vector size) { Rect area = EditorArea; Rect row = area.NewRow(size.Y, VerticalJustification.Top, 0, Shortfall.UseWhatIsLeft); return row.NewCol(size.X, HorizontalJustification.Left, 0, Shortfall.UseWhatIsLeft); } /// /// Returns the layout of panels of the given sizes on a screen of size , with /// around the edge and between neighbors. The status bar's width is whatever the /// screen leaves, so only its height is asked for. /// public static ScreenLayout Arrange(Vector screen, Vector controls, Vector speed, Vector stats, Scalar statusHeight, Vector tuning, Scalar margin) { const Shortfall tooSmall = Shortfall.UseWhatIsLeft; var returnMe = new ScreenLayout(); Rect remainder = Rect.FromPositionAndSize(Vector.Zero, screen).Erode(new Rect.BorderSize(margin)); // The speed buttons center across the whole screen, so their row is carved before either side is. Rect speedStrip = remainder; returnMe.Speed = speedStrip.NewRow(speed.Y, VerticalJustification.Top, 0, tooSmall); returnMe.Speed.Center(speed, tooSmall); returnMe.Status = remainder.NewRow(statusHeight, VerticalJustification.Bottom, margin, tooSmall); Rect controlsColumn = remainder.NewCol(controls.X, HorizontalJustification.Left, margin, tooSmall); returnMe.Controls = controlsColumn.NewRow(controls.Y, VerticalJustification.Top, 0, tooSmall); returnMe.EditorArea = remainder; // The two right-hand panels have their own widths and both sit at the right edge, so each takes its column // from the same remainder. Rect statsSide = remainder; Rect statsColumn = statsSide.NewCol(stats.X, HorizontalJustification.Right, 0, tooSmall); returnMe.Stats = statsColumn.NewRow(stats.Y, VerticalJustification.Top, 0, tooSmall); Rect tuningSide = remainder; Rect tuningColumn = tuningSide.NewCol(tuning.X, HorizontalJustification.Right, 0, tooSmall); Rect wholeTuningColumn = tuningColumn; // The tuning window goes below the stats panel, so the stats panel's row and its margin are set aside. tuningColumn.NewRow(stats.Y, VerticalJustification.Top, margin, tooSmall); if (tuningColumn.Height >= tuning.Y) { returnMe.Tuning = tuningColumn.NewRow(tuning.Y, VerticalJustification.Top, 0, tooSmall); } else { returnMe.Tuning = wholeTuningColumn.NewRow(tuning.Y, VerticalJustification.Bottom, 0, tooSmall); } return returnMe; } } }