/// <summary> /// Reset the matrix to the identity matrix /// </summary> public void ResetMatrix() { this.suspendAutoRefresh = true; bool firstInitialization = this.Matrix == null; var previous = Matrix; //do not use the Matrix setter to avoid firing a matrix changed event for nothing each time //(the event will be fired at the end of the reset) _Matrix = new float[5, 5]; GetMatrixSetter()(BuiltinMatrices.Identity); if (!firstInitialization) { RedoStack.Clear(); //any user change reset the redo stack UndoStack.Push(new Transition <float[, ]>(previous, BuiltinMatrices.Identity, GetMatrixSetter())); } this.suspendAutoRefresh = false; }
/// <summary> /// Set the internal matrix of the control to a clone of the given matrix /// </summary> /// <param name="matrix"></param> public void SetMatrix(float[,] matrix) { if (matrix == null) { throw new ArgumentNullException("matrix"); } if (matrix.GetLength(0) != 5 || matrix.GetLength(1) != 5) { throw new ArgumentException("The matrix must be a 5x5 matrix!", "matrix"); } this.suspendAutoRefresh = true; var previous = this.Matrix ?? BuiltinMatrices.Identity; //actually change the matrix (and update the text boxes) GetMatrixSetter()(matrix); RedoStack.Clear(); //any user change reset the redo stack UndoStack.Push(new Transition <float[, ]>(previous, matrix, GetMatrixSetter())); this.suspendAutoRefresh = false; }