/// <summary> /// Initializes a new instance of the <see cref="T:MB2D.UI.UIElement"/> class. /// Sets default property values /// </summary> /// <param name="rows"> /// Number of rows this element should span - used only be used for container elements /// </param> /// <param name="cols"> /// Number of columns this element should span - used only be used for container elements. /// </param> protected UIElement(int rows, int cols) { BorderDisplayed = false; BorderColor = Color.Transparent; BorderTopColor = BorderRightColor = BorderBottomColor = BorderLeftColor = BorderColor; BorderWidth = 0; TextColor = Color.White; TextContent = string.Empty; Fill = false; _numRows = rows; _numCols = cols; _grid = new UIContent(1, 1, Rectangle.Empty); Tag = string.Empty; }
/// <summary> /// Sets the size of the element relative to its parent /// </summary> /// <param name="parent">Parent content to align to</param> /// <param name="at">Position element should be set to</param> /// <param name="span">Number of columns/rows the element should span.</param> public void SetRelativeSize(UIContent parent, Point at, Point span) { var x = parent.Rect.X + (parent.Grid.ColSize * at.X); var y = parent.Rect.Y + (parent.Grid.RowSize * at.Y); var width = parent.Grid.ColSize * span.X; var height = parent.Grid.RowSize * span.Y; var rect = new Rectangle(x, y, width, height); if (_grid != null) { _grid = new UIContent(_numRows, _numCols, rect); } _borderRect = rect; _borderRect.Width += parent.Grid.ColSize; _borderRect.Height += parent.Grid.RowSize; ResetBorders(); }
/// <summary> /// Initializes a new instance of the <see cref="T:MB2D.UI.UIView"/> class. /// Divides itself into the number of rows and columns evenly based on the size of the /// current viewport. /// </summary> /// <param name="rows">Number of rows in the view</param> /// <param name="cols">Number of columns in the view</param> public UIView(int rows, int cols) { _grid = new UIContent(rows, cols, MBGame.Graphics.Viewport.Bounds); _elementLookup = new Dictionary <string, UIElement>(); }
/// <summary> /// Sets the size of the element relative to its parent /// </summary> /// <param name="parent">Parent content to align to</param> /// <param name="atRow">Row position the element should align to.</param> /// <param name="atCol">Column position the element should align to.</param> /// <param name="rowSpan">Number of rows in the parent the element should span.</param> /// <param name="colSpan">Number of columns in the parent the element should span.</param> public void SetRelativeSize(UIContent parent, int atRow, int atCol, int rowSpan, int colSpan) { SetRelativeSize( parent, new Point(atCol, atRow), new Point(colSpan, rowSpan) ); }