/// <summary> /// Gets the rows to remove. /// </summary> /// <param name="shapeModel">The shape model.</param> /// <returns>A list of row indexes</returns> private static List <int> GetRowsToRemove(this ShapeModel shapeModel) { var rowsToRemove = new List <int>(); for (int row = shapeModel.LastRow(); row >= 1; row--) { if (shapeModel.GetRow(row).All(b => b.Color == CGA16Colors.Black.GetColor())) { rowsToRemove.Add(row); } else { break; } } for (int row = 1; row <= shapeModel.LastRow(); row++) { if (shapeModel.GetRow(row).All(b => b.Color == CGA16Colors.Black.GetColor())) { rowsToRemove.Add(row); } else { break; } } rowsToRemove.Sort(); rowsToRemove.Reverse(); return(rowsToRemove); }
/// <summary> /// Adds the column. /// </summary> /// <param name="shapeModel">The shape model.</param> public static void AddColumnLeft(this ShapeModel shapeModel) { var maxRow = shapeModel.LastRow(); shapeModel.Blocks.ForEach(b => b.Column = b.Column + 1); for (var row = 0; row < maxRow; row++) { var newBlock = BlockModel.Create(1, row + 1); shapeModel.Blocks.Add(newBlock); } }
/// <summary> /// Adds the row at the bottom /// </summary> /// <param name="shapeModel">The shape model.</param> public static void AddRowBottom(this ShapeModel shapeModel) { var maxRow = shapeModel.LastRow(); var maxColumns = shapeModel.LastColumn(); var newRow = maxRow + 1; for (var col = 0; col < maxColumns; col++) { var newBlock = BlockModel.Create(col + 1, newRow); shapeModel.Blocks.Add(newBlock); } }
/// <summary> /// Adds the column. /// </summary> /// <param name="shapeModel">The shape model.</param> public static void AddColumnRight(this ShapeModel shapeModel) { var maxRow = shapeModel.LastRow(); var maxColumns = shapeModel.LastColumn(); var newColumn = maxColumns + 1; for (var row = 0; row < maxRow; row++) { var newBlock = BlockModel.Create(newColumn, row + 1); shapeModel.Blocks.Add(newBlock); } }
/// <summary> /// Renders the shape to bitmap. /// </summary> /// <param name="shapeModel">The shape model.</param> /// <returns>A bitmap</returns> public static Bitmap RenderShapeToBitmap(ShapeModel shapeModel) { var width = 12 * shapeModel.LastColumn(); var height = 12 * shapeModel.LastRow(); var bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppRgb); var g = Graphics.FromImage(bitmap); var size = 12; foreach (var block in shapeModel.Blocks) { var x = (block.Column - 1) * size; var y = (block.Row - 1) * size; var rect = new Rectangle(x, y, size, size); g.FillRectangle(new SolidBrush(block.Color), rect); } bitmap.MakeTransparent(CGA16Colors.Black.GetColor()); return(bitmap); }
/// <summary> /// Removes the last row. /// </summary> /// <param name="shapeModel">The shape model.</param> public static void RemoveRowBottom(this ShapeModel shapeModel) { shapeModel.RemoveRow(shapeModel.LastRow()); }