diff --git a/Paint_2/Form1.Designer.cs b/Paint_2/Form1.Designer.cs index 8941f8a..4f53cbb 100644 --- a/Paint_2/Form1.Designer.cs +++ b/Paint_2/Form1.Designer.cs @@ -67,12 +67,12 @@ this.label1 = new System.Windows.Forms.Label(); this.button2 = new System.Windows.Forms.Button(); this.panel3 = new System.Windows.Forms.Panel(); + this.pnlLayers = new System.Windows.Forms.Panel(); this.btnLayerRemove = new System.Windows.Forms.Button(); this.BtnAddLayer = new System.Windows.Forms.Button(); this.label2 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.DebugLabel = new System.Windows.Forms.Label(); - this.pnlLayers = new System.Windows.Forms.Panel(); ((System.ComponentModel.ISupportInitialize)(this.canvas)).BeginInit(); this.panelFile.SuspendLayout(); this.panelDrawing.SuspendLayout(); @@ -95,7 +95,7 @@ this.tbxProjectName.Location = new System.Drawing.Point(11, 3); this.tbxProjectName.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3); this.tbxProjectName.Name = "tbxProjectName"; - this.tbxProjectName.Size = new System.Drawing.Size(253, 32); + this.tbxProjectName.Size = new System.Drawing.Size(253, 38); this.tbxProjectName.TabIndex = 0; this.tbxProjectName.Text = "Untitled Project"; // @@ -146,7 +146,7 @@ this.lblSelectedColor.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.lblSelectedColor.Location = new System.Drawing.Point(7, 28); this.lblSelectedColor.Name = "lblSelectedColor"; - this.lblSelectedColor.Size = new System.Drawing.Size(234, 17); + this.lblSelectedColor.Size = new System.Drawing.Size(288, 20); this.lblSelectedColor.TabIndex = 1; this.lblSelectedColor.Text = "Hex:FFFFFF R:255 G:255 B:255"; // @@ -194,7 +194,7 @@ this.lblHeight.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.lblHeight.Location = new System.Drawing.Point(3, 40); this.lblHeight.Name = "lblHeight"; - this.lblHeight.Size = new System.Drawing.Size(60, 17); + this.lblHeight.Size = new System.Drawing.Size(74, 20); this.lblHeight.TabIndex = 34; this.lblHeight.Text = "H:2000"; // @@ -204,7 +204,7 @@ this.lblWidth.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.lblWidth.Location = new System.Drawing.Point(3, 8); this.lblWidth.Name = "lblWidth"; - this.lblWidth.Size = new System.Drawing.Size(64, 17); + this.lblWidth.Size = new System.Drawing.Size(77, 20); this.lblWidth.TabIndex = 33; this.lblWidth.Text = "W:2000"; // @@ -239,7 +239,7 @@ this.label14.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.label14.Location = new System.Drawing.Point(7, 6); this.label14.Name = "label14"; - this.label14.Size = new System.Drawing.Size(120, 18); + this.label14.Size = new System.Drawing.Size(150, 22); this.label14.TabIndex = 29; this.label14.Text = "Selected color"; // @@ -273,7 +273,7 @@ this.lblHoveringColor.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.lblHoveringColor.Location = new System.Drawing.Point(8, 28); this.lblHoveringColor.Name = "lblHoveringColor"; - this.lblHoveringColor.Size = new System.Drawing.Size(234, 17); + this.lblHoveringColor.Size = new System.Drawing.Size(288, 20); this.lblHoveringColor.TabIndex = 1; this.lblHoveringColor.Text = "Hex:FFFFFF R:255 G:255 B:255"; // @@ -284,7 +284,7 @@ this.label15.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.label15.Location = new System.Drawing.Point(8, 6); this.label15.Name = "label15"; - this.label15.Size = new System.Drawing.Size(120, 18); + this.label15.Size = new System.Drawing.Size(150, 22); this.label15.TabIndex = 29; this.label15.Text = "Hovering color"; // @@ -306,7 +306,7 @@ 0, 0}); this.nupPencilWidth.Name = "nupPencilWidth"; - this.nupPencilWidth.Size = new System.Drawing.Size(71, 27); + this.nupPencilWidth.Size = new System.Drawing.Size(71, 33); this.nupPencilWidth.TabIndex = 17; this.nupPencilWidth.Value = new decimal(new int[] { 10, @@ -361,7 +361,7 @@ this.label4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.label4.Location = new System.Drawing.Point(7, 3); this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(105, 16); + this.label4.Size = new System.Drawing.Size(135, 20); this.label4.TabIndex = 1; this.label4.Text = "Colors history"; // @@ -496,10 +496,10 @@ this.lsbTools.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lsbTools.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.lsbTools.FormattingEnabled = true; - this.lsbTools.ItemHeight = 17; + this.lsbTools.ItemHeight = 20; this.lsbTools.Location = new System.Drawing.Point(10, 33); this.lsbTools.Name = "lsbTools"; - this.lsbTools.Size = new System.Drawing.Size(179, 121); + this.lsbTools.Size = new System.Drawing.Size(179, 102); this.lsbTools.TabIndex = 32; this.lsbTools.SelectedIndexChanged += new System.EventHandler(this.lsbTools_SelectedIndexChanged); // @@ -536,7 +536,7 @@ this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.label1.Location = new System.Drawing.Point(8, 10); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(84, 16); + this.label1.Size = new System.Drawing.Size(108, 20); this.label1.TabIndex = 36; this.label1.Text = "Paint tools"; // @@ -569,10 +569,17 @@ this.panel3.Size = new System.Drawing.Size(200, 175); this.panel3.TabIndex = 37; // + // pnlLayers + // + this.pnlLayers.AutoScroll = true; + this.pnlLayers.Location = new System.Drawing.Point(10, 10); + this.pnlLayers.Name = "pnlLayers"; + this.pnlLayers.Size = new System.Drawing.Size(178, 121); + this.pnlLayers.TabIndex = 39; + // // btnLayerRemove // this.btnLayerRemove.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(59)))), ((int)(((byte)(59)))), ((int)(((byte)(59))))); - this.btnLayerRemove.Enabled = false; this.btnLayerRemove.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.btnLayerRemove.Font = new System.Drawing.Font("Cascadia Code", 10.2F); this.btnLayerRemove.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); @@ -604,7 +611,7 @@ this.label2.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label2.Location = new System.Drawing.Point(8, 10); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(0, 16); + this.label2.Size = new System.Drawing.Size(0, 20); this.label2.TabIndex = 36; // // button1 @@ -626,21 +633,13 @@ this.DebugLabel.AutoSize = true; this.DebugLabel.Location = new System.Drawing.Point(12, 555); this.DebugLabel.Name = "DebugLabel"; - this.DebugLabel.Size = new System.Drawing.Size(54, 17); + this.DebugLabel.Size = new System.Drawing.Size(65, 20); this.DebugLabel.TabIndex = 38; this.DebugLabel.Text = "Debug"; // - // pnlLayers - // - this.pnlLayers.AutoScroll = true; - this.pnlLayers.Location = new System.Drawing.Point(10, 10); - this.pnlLayers.Name = "pnlLayers"; - this.pnlLayers.Size = new System.Drawing.Size(178, 121); - this.pnlLayers.TabIndex = 39; - // // PaintForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 17F); + this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(34)))), ((int)(((byte)(34)))), ((int)(((byte)(34))))); this.ClientSize = new System.Drawing.Size(1132, 655); diff --git a/Paint_2/Form1.cs b/Paint_2/Form1.cs index 0a6dd42..24c8662 100644 --- a/Paint_2/Form1.cs +++ b/Paint_2/Form1.cs @@ -38,19 +38,19 @@ namespace Paint_2 private Color _hoveringColor; private Project _project; private int _selectedLayer; - private List _selectedLayers; + private List _selectedLayers; public Color HoveringColor { get => _hoveringColor; set => _hoveringColor = value; } public Project Project { get => _project; set => _project = value; } public int SelectedLayer { get => _selectedLayer; set => _selectedLayer = value; } - public List SelectedLayers { get => _selectedLayers; set => _selectedLayers = value; } + public List SelectedLayers { get => _selectedLayers; set => _selectedLayers = value; } public PaintForm() { InitializeComponent(); Project = new Project("Untitled project", canvas.Size); - SelectedLayers = new List(); - SelectedLayers.Add(0); + SelectedLayers = new List(); + SelectedLayers.Add(Project.GetAllLayers()[0].Id); RefreshUi(); } private Point MousePositionToCanvasPosition() @@ -62,7 +62,7 @@ namespace Paint_2 Color hoveringColor = GetHoverColor(); Point mousePosition = MousePositionToCanvasPosition(); int toolWidth = (int)nupPencilWidth.Value; - Project.MouseDown(SelectedLayers,hoveringColor, mousePosition, toolWidth); + Project.MouseDown(SelectedLayers, hoveringColor, mousePosition, toolWidth); RefreshUi(); } private void canvas_MouseUp(object sender, MouseEventArgs e) @@ -102,10 +102,8 @@ namespace Paint_2 private void RefreshUi() { lsbTools.DataSource = Project.AvaibleTools; - //DebugLabel.Text = Project.PrintAllLayers(); DebugLabel.Text = ""; - //canvas.Image = Project.PaintAllLayers(); canvas.Image = Project.PaintLayers(); lblSelectedColor.Text = ColorToString(Project.GetCurrentToolColor(SelectedLayers)); @@ -243,23 +241,30 @@ namespace Paint_2 private void PaintForm_Load(object sender, EventArgs e) { - //lsbTools.DataSource = Project.AvaibleTools; - //lsbLayers.DataSource = Project.Layers; - - //lsbLayers.DataSource = Project.Layers[0].ToolList; tmrRefresh.Enabled = true; DisplayLayers(); } private void btnLayerRemove_Click(object sender, EventArgs e) { - //Project.RemoveLayer(lsbLayers.SelectedIndex); - //foreach (int id in SelectedLayers) - for(int id = 0;id < SelectedLayers.Count;id++) + int layersCount = SelectedLayers.Count; + List LayersToRemove = new List(); + foreach (string layer in SelectedLayers) { - SelectedLayers.Remove(id); - Project.RemoveLayer(id); + LayersToRemove.Add(layer); } + for (int id = layersCount -1; id >= 0; id--) + { + if (Project.RemoveLayer(LayersToRemove[id])) + { + SelectedLayers.RemoveAt(id); + } + else + { + Console.WriteLine("Could not delete the layer"); + } + } + DisplayLayers(); RefreshUi(); } @@ -275,17 +280,19 @@ namespace Paint_2 { int Yoffset = 25; int Xoffset = 10; - + int blocsCount = 1; int btnWidth = 75; int labelWidth = 70; int BtnXoffset = labelWidth; - int ChkXOffset = BtnXoffset + btnWidth + Xoffset /2; + int ChkXOffset = BtnXoffset + btnWidth + Xoffset / 2; int ChkWidth = 20; pnlLayers.Controls.Clear(); - foreach (Sketch layer in Project.Layers) + List layers = Project.GetAllLayers(); + + foreach (Sketch layer in layers) { Label name = new Label(); name.AutoSize = false; @@ -293,12 +300,12 @@ namespace Paint_2 name.Text = layer.Name; name.BackColor = Color.Transparent; pnlLayers.Controls.Add(name); - name.Location = new Point(0,blocsCount * Yoffset); + name.Location = new Point(0, blocsCount * Yoffset); Button btn = new Button(); - btn.Name = (blocsCount - 1).ToString(); + btn.Name = "ChkLayerVisible:" + layer.Id; btn.Click += LayerSelection; - if (Project.LayersToPrint.Contains(Convert.ToInt32(btn.Name))) + if (Project.LayersToPrint.Contains(layer.Id)) { btn.Text = "Visible"; } @@ -308,13 +315,13 @@ namespace Paint_2 } pnlLayers.Controls.Add(btn); btn.BackColor = Color.FromArgb(59, 59, 59); - btn.Location = new Point(BtnXoffset,blocsCount * Yoffset); + btn.Location = new Point(BtnXoffset, blocsCount * Yoffset); btn.Width = btnWidth; btn.FlatStyle = FlatStyle.Popup; Button chk = new Button(); chk.Click += LayerCheck; - if (SelectedLayers.Contains(blocsCount-1)) + if (SelectedLayers.Contains(layer.Id)) { chk.BackColor = Color.Green; } @@ -328,7 +335,7 @@ namespace Paint_2 chk.Text = ""; chk.FlatStyle = FlatStyle.Popup; chk.Width = ChkWidth; - chk.Name = "C" + (blocsCount -1).ToString(); + chk.Name = "ChkLayerSelected:" + layer.Id; blocsCount++; } @@ -337,17 +344,19 @@ namespace Paint_2 { //We assume that the id of the layer is the name of the button Button btn = sender as Button; - int id = Convert.ToInt32(btn.Name); + string rawId = btn.Name; + string id = rawId.Replace("ChkLayerVisible:", String.Empty); Project.SwitchLayer(id); DisplayLayers(); } private void LayerCheck(object sender, EventArgs e) { - //We assume that the id of the layer is the name with the 'c' removed + // We should receive "CheckBox:937r9837r893" Button btn = sender as Button; - string cleanedName = btn.Name.Remove(0,1); - int id = Convert.ToInt32(cleanedName); - //MessageBox.Show("Select or Deslect layer "+id); + //MessageBox.Show("Btn " + btn.Name + " pressed"); + string rawId = btn.Name; + string id = rawId.Replace("ChkLayerSelected:", String.Empty); + //MessageBox.Show("Select or Deslect layer n:"+id); if (SelectedLayers.Contains(id)) { SelectedLayers.Remove(id); diff --git a/Paint_2/Project.cs b/Paint_2/Project.cs index 5b58ffc..5c152cb 100644 --- a/Paint_2/Project.cs +++ b/Paint_2/Project.cs @@ -15,8 +15,8 @@ namespace Paint_2 const int DEFAULT_WIDTH = 0; private List _avaibleTools; - private List _selectedLayers; - //private Sketch _currentSketch; + private List _selectedLayers; + private Guid uniqIdGenerator; private List _layers; private bool _eyedropping; private bool _randomColor; @@ -34,7 +34,7 @@ namespace Paint_2 public Random Random { get => _random; set => _random = value; } public bool Drawing { get => _drawing; set => _drawing = value; } public string Name { get => _name; set => _name = value; } - public List LayersToPrint { get => _selectedLayers; set => _selectedLayers = value; } + public List LayersToPrint { get => _selectedLayers; set => _selectedLayers = value; } public Project(string name, Size canvasSize) { @@ -47,11 +47,12 @@ namespace Paint_2 AvaibleTools.Add(new DotPencil("Dotted Line")); AvaibleTools.Add(new BezierPencil("Bezier Generator")); //We create a single first layer with the default toolSet + Layers = new List(); + LayersToPrint = new List(); + AddLayer(); - //CurrentLayer = Layers[0]; - LayersToPrint = new List(); - LayersToPrint.Add(0); + LayersToPrint.Add(Layers[0].Id); } public void AddLayer() { @@ -60,28 +61,53 @@ namespace Paint_2 { newTools.Add((PaintTool)tool.Clone()); } - Layers.Add(new Sketch(String.Concat("Layer", Layers.Count + 1), CanvasSize, newTools)); + uniqIdGenerator = Guid.NewGuid(); + string test = uniqIdGenerator.ToString(); + Layers.Add(new Sketch(String.Concat("Layer", Layers.Count + 1), CanvasSize, newTools, uniqIdGenerator.ToString())); } - public void RemoveLayer(int layerId) + public bool RemoveLayer(string layerId) { - if (layerId >= 0 && layerId < Layers.Count) + Sketch layer = FindSketch(Layers, layerId); + if (layer != null) { - Layers.RemoveAt(layerId); + Layers.Remove(layer); + return true; + } + else + { + return false; } } - /* - public void ChangeLayer(int idLayer) + public Sketch FindSketch(List layers, string id) { - CurrentLayer = Layers[idLayer]; + foreach (Sketch layer in layers) + { + if (layer.Id == id) + { + return layer; + } + } + return null; + } + public bool IsSketchPresent (List layers, string id) + { + foreach (string layer in layers) + { + if (layer == id) + { + return true; + } + } + return false; } - */ public List GetAllLayers() { return Layers; } - public void SwitchLayer(int idLayer) + public void SwitchLayer(string idLayer) { - if (LayersToPrint.Contains(idLayer)) + bool present = IsSketchPresent(LayersToPrint,idLayer); + if (present) { LayersToPrint.Remove(idLayer); } @@ -90,18 +116,19 @@ namespace Paint_2 LayersToPrint.Add(idLayer); } } - public void MouseDown(List selectedLayers, Color hoveringColor, Point mousePosition, int toolWidth) + public void MouseDown(List selectedLayers, Color hoveringColor, Point mousePosition, int toolWidth) { - for (int layer = 0; layer < Layers.Count; layer++) + foreach (string id in selectedLayers) { - if (selectedLayers.Contains(layer)) + Sketch layer = FindSketch(Layers, id); + if (layer != null) { if (Eyedropping) { Color pointedColor = hoveringColor; - if (Layers[layer].CurrentTool.Color != pointedColor) + if (layer.CurrentTool.Color != pointedColor) { - Layers[layer].ChangePaintToolColor(pointedColor); + layer.ChangePaintToolColor(pointedColor); } } else @@ -109,73 +136,78 @@ namespace Paint_2 Drawing = true; if (RandomColor) { - Layers[layer].StartDrawing(mousePosition, Color.FromArgb(Random.Next(0, 256), Random.Next(0, 256), Random.Next(0, 256)), toolWidth); + layer.StartDrawing(mousePosition, Color.FromArgb(Random.Next(0, 256), Random.Next(0, 256), Random.Next(0, 256)), toolWidth); } else { - Layers[layer].StartDrawing(mousePosition, Layers[layer].CurrentTool.Color, toolWidth); + layer.StartDrawing(mousePosition, layer.CurrentTool.Color, toolWidth); } } + } } - } - public void MouseUp(List selectedLayers, Point mousePosition) + public void MouseUp(List selectedLayers, Point mousePosition) { - for (int layer = 0; layer < Layers.Count; layer++) + foreach (string id in selectedLayers) { - if (selectedLayers.Contains(layer)) + Sketch layer = FindSketch(Layers, id); + if (layer != null) { if (!Eyedropping) { - Layers[layer].AddDrawingPoint(mousePosition); + layer.AddDrawingPoint(mousePosition); Drawing = false; - Layers[layer].StopDrawing(); + layer.StopDrawing(); } } } } - public void TimerTick(List selectedLayers, Point mousePosition) + public void TimerTick(List selectedLayers, Point mousePosition) { - for (int layer = 0; layer < Layers.Count; layer++) + foreach (string id in selectedLayers) { - if (selectedLayers.Contains(layer)) + Sketch layer = FindSketch(Layers, id); + if (layer != null) { if (Drawing) { - Layers[layer].AddDrawingPoint(mousePosition); + layer.AddDrawingPoint(mousePosition); } } } } - public void ChangeColor(List selectedLayers, Color newColor) + public void ChangeColor(List selectedLayers, Color newColor) { - for (int layer = 0; layer < Layers.Count; layer++) + foreach (string id in selectedLayers) { - if (selectedLayers.Contains(layer)) + Sketch layer = FindSketch(Layers, id); + if (layer != null) { - Layers[layer].ChangePaintToolColor(newColor); + layer.ChangePaintToolColor(newColor); } } } - public void ChangeWidth(List selectedLayers, int width) + public void ChangeWidth(List selectedLayers, int width) { - for (int layer = 0; layer < Layers.Count; layer++) + foreach (string id in selectedLayers) { - if (selectedLayers.Contains(layer)) + Sketch layer = FindSketch(Layers, id); + if (layer != null) { - Layers[layer].ChangePaintToolWidth(width); + layer.ChangePaintToolWidth(width); } } } - public void ChangeTool(List selectedLayers, int toolId) + public void ChangeTool(List selectedLayers, int toolId) { - for (int layer = 0; layer < Layers.Count; layer++) + foreach (string id in selectedLayers) { - if (selectedLayers.Contains(layer)) + Sketch layer = FindSketch(Layers, id); + if (layer != null) { - Layers[layer].ChangeTool(toolId); + layer.ChangeTool(toolId); } } } @@ -193,11 +225,12 @@ namespace Paint_2 { Bitmap result = new Bitmap(CanvasSize.Width, CanvasSize.Height); Graphics gr = Graphics.FromImage(result); - for (int layer = 0; layer < Layers.Count; layer++) + foreach (string layerId in LayersToPrint) { - if (LayersToPrint.Contains(layer)) + Sketch layer = FindSketch(Layers, layerId); + if (layer != null) { - gr.DrawImage(Layers[layer].ForcePaint(), Point.Empty); + gr.DrawImage(layer.ForcePaint(), Point.Empty); } } return result; @@ -216,11 +249,12 @@ namespace Paint_2 { Bitmap result = new Bitmap(CanvasSize.Width, CanvasSize.Height); Graphics gr = Graphics.FromImage(result); - for (int layer = 0; layer < Layers.Count; layer++) - { - if (LayersToPrint.Contains(layer)) + foreach (string layerId in LayersToPrint) + { + Sketch layer = FindSketch(Layers, layerId); + if (layer != null) { - gr.DrawImage(Layers[layer].Paint(), Point.Empty); + gr.DrawImage(layer.Paint(), Point.Empty); } } return result; @@ -232,37 +266,40 @@ namespace Paint_2 layer.Clear(); } } - public Color GetCurrentToolColor(List selectedLayers) + public Color GetCurrentToolColor(List selectedLayers) { - if(selectedLayers.Count == 0) + if (Layers.Count == 0 || selectedLayers.Count == 0) { return DEFAULT_COLOR; } - Sketch CurrentLayer = Layers[selectedLayers[0]]; - return CurrentLayer.CurrentTool.Color; + else + { + //Sketch CurrentLayer = Layers[selectedLayers[0]; + Sketch CurrentLayer = FindSketch(Layers,selectedLayers[0]); + return CurrentLayer.CurrentTool.Color; + } } - public int GetCurrentToolWidth(List selectedLayers) + public int GetCurrentToolWidth(List selectedLayers) { if (selectedLayers.Count == 0) { return DEFAULT_WIDTH; } - Sketch CurrentLayer = Layers[selectedLayers[0]]; + Sketch CurrentLayer = FindSketch(Layers, selectedLayers[0]); return CurrentLayer.CurrentTool.Width; } - public List GetLayerColorHistory(List selectedLayers,int colorsCount) + public List GetLayerColorHistory(List selectedLayers, int colorsCount) { - if(selectedLayers.Count == 0) + if (selectedLayers.Count == 0) { List result = new List(); - for (int i = 0;i < colorsCount;i++) + for (int i = 0; i < colorsCount; i++) { result.Add(DEFAULT_COLOR); } return result; } - - Sketch CurrentLayer = Layers[selectedLayers[0]]; + Sketch CurrentLayer = FindSketch(Layers, selectedLayers[0]); return CurrentLayer.CurrentTool.GetLastColors(colorsCount); } public void Save(string fileName, Bitmap image) @@ -310,23 +347,25 @@ namespace Paint_2 { Eyedropping = !Eyedropping; } - public void Undo(List selectedLayers) + public void Undo(List selectedLayers) { - for (int layer = 0; layer < Layers.Count; layer++) + foreach (string id in selectedLayers) { - if (selectedLayers.Contains(layer)) + Sketch layer = FindSketch(Layers, id); + if (layer != null) { - Layers[layer].Undo(); + layer.Undo(); } - } + } } - public void Redo(List selectedLayers) + public void Redo(List selectedLayers) { - for (int layer = 0; layer < Layers.Count; layer++) + foreach (string id in selectedLayers) { - if (selectedLayers.Contains(layer)) + Sketch layer = FindSketch(Layers, id); + if (layer != null) { - Layers[layer].Redo(); + layer.Redo(); } } } diff --git a/Paint_2/Sketch.cs b/Paint_2/Sketch.cs index 51b977c..22f6fc9 100644 --- a/Paint_2/Sketch.cs +++ b/Paint_2/Sketch.cs @@ -20,6 +20,7 @@ namespace Paint_2 bool _isDrawing; Bitmap _drawing; Size _sketchSize; + string id; string _name; internal List ToolList { get => _toolList; set => _toolList = value; } public PaintTool CurrentTool { get => _currentTool; set => _currentTool = value; } @@ -27,10 +28,12 @@ namespace Paint_2 public Bitmap Drawing { get => _drawing; set => _drawing = value; } public Size SketchSize { get => _sketchSize; set => _sketchSize = value; } public string Name { get => _name; set => _name = value; } + public string Id { get => id; set => id = value; } - public Sketch(string name,Size sketchSize, List toolList) + public Sketch(string name,Size sketchSize, List toolList,string guid) { IsDrawing = false; + Id = guid; Name = name; SketchSize = sketchSize; Drawing = new Bitmap(SketchSize.Width, SketchSize.Height); @@ -49,7 +52,7 @@ namespace Paint_2 CurrentTool = null; } } - public Sketch(List toolList) : this("Layer 1",new Size(500, 500), toolList) + public Sketch(List toolList,string guid) : this("Layer 1",new Size(500, 500), toolList,guid) { //empty }