/// <summary> /// Resizes the container to the specified size /// </summary> /// <param name="newSize">New size to which the container is to be resized</param> /// <param name="justify">Resize justification, which indicates the edge at which widgets are to /// remain in their current positions (i.e. right justification will make the left edge move left/right /// while right edge's location stays constant)</param> public void Resize(MatrixSize newSize, WidgetContainerResizeJustify justify) { if (newSize.RowCount > 256 || newSize.ColumnCount > 256) { throw new ApplicationException(string.Format("Attemp to allocate too much ({0} x {1})", newSize.RowCount, newSize.ColumnCount)); } else if (newSize == this.Bounds.Size) { return; } Validate(); MatrixSize currentSize = this.Size; MatrixSize originShift = currentSize - newSize; if (!justify.HasFlag(WidgetContainerResizeJustify.Bottom)) { originShift.RowCount = 0; } if (!justify.HasFlag(WidgetContainerResizeJustify.Right)) { originShift.ColumnCount = 0; } MatrixRect newContainerBounds = new MatrixRect( _containerBounds.Location + originShift, newSize); // Cells in the intersection of original bounding rectangle and the new bounding // rectangle are the ones that will survive the resize operation. Once we identify // the intersection of the two rectangles, we need to iterate through the original // array and copy those cells into the new array MatrixRect existingCellBounds = _containerBounds.Intersect(newContainerBounds); // normalize existing cell bounding box around 0-based arrays. existingCellBounds.Location = new MatrixLoc(originShift.RowCount > 0 ? originShift.RowCount : 0, originShift.ColumnCount > 0 ? originShift.ColumnCount : 0); Array2D <WidgetData> newArray = new Array2D <WidgetData>(newSize); foreach (var loc in existingCellBounds) { newArray[loc - originShift] = _widgetArray[loc]; } _widgetArray = newArray; _containerBounds = newContainerBounds; this.IsDirty = true; Validate(); OnContainerResized(); Validate(); }
/// <inheritdoc/> protected override void DeserializeFromXml(XmlReader reader) { _containerBounds.Row = XmlConvert.ToInt32(reader.GetAttribute("firstRow")); _containerBounds.Column = XmlConvert.ToInt32(reader.GetAttribute("firstColumn")); MatrixSize size = new MatrixSize( XmlConvert.ToInt32(reader.GetAttribute("rowCount")), XmlConvert.ToInt32(reader.GetAttribute("columnCount"))); Resize(size, 0); if (!reader.Read()) { return; } while (reader.NodeType != XmlNodeType.EndElement) { if (reader.NodeType == XmlNodeType.Element) { if (string.Compare(reader.Name, "Children", true) == 0) { reader.Read(); while (reader.NodeType != XmlNodeType.EndElement) { if (reader.NodeType == XmlNodeType.Element) { WidgetData widget = WidgetData.Create(reader); this[widget.Location] = widget; } else { reader.Read(); } } reader.ReadEndElement(); } else { reader.Skip(); } } else { reader.Read(); } } }
/// <summary> /// Returns a new rectangle which represents the intersection between current rectangle /// and the second one which is passed in /// </summary> /// <param name="other">The other rectangle to test against</param> /// <returns>A rectangle which represents the intersection</returns> public MatrixRect Intersect(MatrixRect other) { MatrixLoc topLeft = new MatrixLoc(Math.Max(this.Row, other.Row), Math.Max(this.Column, other.Column)); MatrixLoc bottomRight = new MatrixLoc(Math.Min(this.LastRow, other.LastRow), Math.Min(this.LastColumn, other.LastColumn)); MatrixSize size = bottomRight - topLeft; if (size.ColumnCount < 0) { size.ColumnCount = 0; } if (size.RowCount < 0) { size.RowCount = 0; } return(new MatrixRect(topLeft, size)); }
/// <summary> /// Initializing constructor. This constructor creates a rectangle whose top-left /// corner is set to location (0,0) /// </summary> /// <param name="size">size of the rectangle</param> public MatrixRect(MatrixSize size) { _location = new MatrixLoc(); _size = size; }
/// <summary> /// Initializing constructor /// </summary> /// <param name="location">Location of top-left corner of a rectangle</param> /// <param name="size">Size of the rectangle</param> public MatrixRect(MatrixLoc location, MatrixSize size) { _location = location; _size = size; }
/// <summary> /// Initializing constructor. Creates pre-allocated two dimensional array of T elements /// </summary> /// <param name="size">Size of the array to initialize</param> public Array2D(MatrixSize size) : this(size.RowCount, size.ColumnCount) { }
public bool Equals(MatrixSize other) { return(this == other); }
/// <summary> /// Initializing constructor /// </summary> /// <param name="row">Location of rectangles top edge</param> /// <param name="column">Location of rectangle left edge</param> /// <param name="rowCount">Number of rows in a rectangle</param> /// <param name="columnCount">Number of columns in a rectangle</param> public MatrixRect(int row, int column, int rowCount, int columnCount) { _location = new MatrixLoc(row, column); _size = new MatrixSize(rowCount, columnCount); }