/// <summary> /// Add's a source rectangle into the timeline at a specified position. /// </summary> /// <param name="r">The source rectangle</param> /// <param name="position"> the postion</param> /// <param name="insert">Whether or not to insert or replace.</param> public void AddSourceRectangle(Rectangle r, int position, bool insert) { if (insert) { //resize it var copy = new Rectangle[_sourcerectangles.GetUpperBound(0) + 1]; for (int i = 0; i < _sourcerectangles.GetUpperBound(0); i++) { if (i >= position) i++; copy[i] = _sourcerectangles[i]; } //Copy over the new array _sourcerectangles = (Rectangle[])copy.Clone(); //copy the rectangle _sourcerectangles[position] = r; } else { //if the position is greater than the array size if (position > _sourcerectangles.GetUpperBound(0)) { //resize it var copy = new Rectangle[position]; for (int i = 0; i < _sourcerectangles.GetUpperBound(0); i++) { copy[i] = _sourcerectangles[i]; } //Copy over the new array _sourcerectangles = (Rectangle[])copy.Clone(); } //copy the rectangle _sourcerectangles[position] = r; } }
/// <summary> /// Adds a new source rectagle to the back of the timeline /// </summary> /// <param name="r"></param> public void AddSourceRectangle(Rectangle r) { //Check if out array has yet to be filled if (_sourcerectangles[0] == new Rectangle(0, 0, 0, 0) && _sourcerectangles.Count() == 1) { _sourcerectangles[0] = r; return; } int upper = _sourcerectangles.GetUpperBound(0); var copy = new Rectangle[upper + 2]; for (int i = 0; i <= upper; i++) { copy[i] = _sourcerectangles[i]; } copy[copy.GetUpperBound(0)] = r; //Copy over the new array _sourcerectangles = (Rectangle[])copy.Clone(); }