/// <summary> /// Gets the columns to remove. /// </summary> /// <param name="shapeModel">The shape model.</param> /// <returns>A list of column indexes</returns> private static List <int> GetColumnsToRemove(this ShapeModel shapeModel) { var columnsToRemove = new List <int>(); for (int col = shapeModel.LastColumn(); col >= 1; col--) { if (shapeModel.GetColumn(col).All(b => b.Color == CGA16Colors.Black.GetColor())) { columnsToRemove.Add(col); } else { break; } } for (int col = 1; col <= shapeModel.LastColumn(); col++) { if (shapeModel.GetColumn(col).All(b => b.Color == CGA16Colors.Black.GetColor())) { columnsToRemove.Add(col); } else { break; } } columnsToRemove.Sort(); columnsToRemove.Reverse(); return(columnsToRemove); }
/// <summary> /// Adds the row to the top /// </summary> /// <param name="shapeModel">The shape model.</param> public static void AddRowTop(this ShapeModel shapeModel) { var maxColumns = shapeModel.LastColumn(); shapeModel.Blocks.ForEach(b => b.Row = b.Row + 1); for (var col = 0; col < maxColumns; col++) { var newBlock = BlockModel.Create(col + 1, 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 column. /// </summary> /// <param name="shapeModel">The shape model.</param> public static void RemoveColumnRight(this ShapeModel shapeModel) { shapeModel.RemoveColumn(shapeModel.LastColumn()); }