Added layer removal

This commit is contained in:
2022-06-15 10:58:51 +02:00
parent 47e57db137
commit 5cac05a9aa
4 changed files with 179 additions and 129 deletions

View File

@@ -67,12 +67,12 @@
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button();
this.panel3 = new System.Windows.Forms.Panel(); this.panel3 = new System.Windows.Forms.Panel();
this.pnlLayers = new System.Windows.Forms.Panel();
this.btnLayerRemove = new System.Windows.Forms.Button(); this.btnLayerRemove = new System.Windows.Forms.Button();
this.BtnAddLayer = new System.Windows.Forms.Button(); this.BtnAddLayer = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button();
this.DebugLabel = new System.Windows.Forms.Label(); this.DebugLabel = new System.Windows.Forms.Label();
this.pnlLayers = new System.Windows.Forms.Panel();
((System.ComponentModel.ISupportInitialize)(this.canvas)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.canvas)).BeginInit();
this.panelFile.SuspendLayout(); this.panelFile.SuspendLayout();
this.panelDrawing.SuspendLayout(); this.panelDrawing.SuspendLayout();
@@ -95,7 +95,7 @@
this.tbxProjectName.Location = new System.Drawing.Point(11, 3); this.tbxProjectName.Location = new System.Drawing.Point(11, 3);
this.tbxProjectName.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3); this.tbxProjectName.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
this.tbxProjectName.Name = "tbxProjectName"; 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.TabIndex = 0;
this.tbxProjectName.Text = "Untitled Project"; 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.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.Location = new System.Drawing.Point(7, 28);
this.lblSelectedColor.Name = "lblSelectedColor"; 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.TabIndex = 1;
this.lblSelectedColor.Text = "Hex:FFFFFF R:255 G:255 B:255"; 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.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.Location = new System.Drawing.Point(3, 40);
this.lblHeight.Name = "lblHeight"; 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.TabIndex = 34;
this.lblHeight.Text = "H:2000"; 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.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.Location = new System.Drawing.Point(3, 8);
this.lblWidth.Name = "lblWidth"; 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.TabIndex = 33;
this.lblWidth.Text = "W:2000"; 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.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.Location = new System.Drawing.Point(7, 6);
this.label14.Name = "label14"; 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.TabIndex = 29;
this.label14.Text = "Selected color"; 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.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.Location = new System.Drawing.Point(8, 28);
this.lblHoveringColor.Name = "lblHoveringColor"; 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.TabIndex = 1;
this.lblHoveringColor.Text = "Hex:FFFFFF R:255 G:255 B:255"; 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.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.Location = new System.Drawing.Point(8, 6);
this.label15.Name = "label15"; 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.TabIndex = 29;
this.label15.Text = "Hovering color"; this.label15.Text = "Hovering color";
// //
@@ -306,7 +306,7 @@
0, 0,
0}); 0});
this.nupPencilWidth.Name = "nupPencilWidth"; 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.TabIndex = 17;
this.nupPencilWidth.Value = new decimal(new int[] { this.nupPencilWidth.Value = new decimal(new int[] {
10, 10,
@@ -361,7 +361,7 @@
this.label4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); 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.Location = new System.Drawing.Point(7, 3);
this.label4.Name = "label4"; 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.TabIndex = 1;
this.label4.Text = "Colors history"; this.label4.Text = "Colors history";
// //
@@ -496,10 +496,10 @@
this.lsbTools.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 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.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.lsbTools.FormattingEnabled = true; this.lsbTools.FormattingEnabled = true;
this.lsbTools.ItemHeight = 17; this.lsbTools.ItemHeight = 20;
this.lsbTools.Location = new System.Drawing.Point(10, 33); this.lsbTools.Location = new System.Drawing.Point(10, 33);
this.lsbTools.Name = "lsbTools"; 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.TabIndex = 32;
this.lsbTools.SelectedIndexChanged += new System.EventHandler(this.lsbTools_SelectedIndexChanged); 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.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.Location = new System.Drawing.Point(8, 10);
this.label1.Name = "label1"; 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.TabIndex = 36;
this.label1.Text = "Paint tools"; this.label1.Text = "Paint tools";
// //
@@ -569,10 +569,17 @@
this.panel3.Size = new System.Drawing.Size(200, 175); this.panel3.Size = new System.Drawing.Size(200, 175);
this.panel3.TabIndex = 37; 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 // btnLayerRemove
// //
this.btnLayerRemove.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(59)))), ((int)(((byte)(59)))), ((int)(((byte)(59))))); 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.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnLayerRemove.Font = new System.Drawing.Font("Cascadia Code", 10.2F); 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))))); 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.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.Location = new System.Drawing.Point(8, 10);
this.label2.Name = "label2"; 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; this.label2.TabIndex = 36;
// //
// button1 // button1
@@ -626,21 +633,13 @@
this.DebugLabel.AutoSize = true; this.DebugLabel.AutoSize = true;
this.DebugLabel.Location = new System.Drawing.Point(12, 555); this.DebugLabel.Location = new System.Drawing.Point(12, 555);
this.DebugLabel.Name = "DebugLabel"; 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.TabIndex = 38;
this.DebugLabel.Text = "Debug"; 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 // 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.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(34)))), ((int)(((byte)(34)))), ((int)(((byte)(34))))); this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(34)))), ((int)(((byte)(34)))), ((int)(((byte)(34)))));
this.ClientSize = new System.Drawing.Size(1132, 655); this.ClientSize = new System.Drawing.Size(1132, 655);

View File

@@ -38,19 +38,19 @@ namespace Paint_2
private Color _hoveringColor; private Color _hoveringColor;
private Project _project; private Project _project;
private int _selectedLayer; private int _selectedLayer;
private List<int> _selectedLayers; private List<string> _selectedLayers;
public Color HoveringColor { get => _hoveringColor; set => _hoveringColor = value; } public Color HoveringColor { get => _hoveringColor; set => _hoveringColor = value; }
public Project Project { get => _project; set => _project = value; } public Project Project { get => _project; set => _project = value; }
public int SelectedLayer { get => _selectedLayer; set => _selectedLayer = value; } public int SelectedLayer { get => _selectedLayer; set => _selectedLayer = value; }
public List<int> SelectedLayers { get => _selectedLayers; set => _selectedLayers = value; } public List<string> SelectedLayers { get => _selectedLayers; set => _selectedLayers = value; }
public PaintForm() public PaintForm()
{ {
InitializeComponent(); InitializeComponent();
Project = new Project("Untitled project", canvas.Size); Project = new Project("Untitled project", canvas.Size);
SelectedLayers = new List<int>(); SelectedLayers = new List<string>();
SelectedLayers.Add(0); SelectedLayers.Add(Project.GetAllLayers()[0].Id);
RefreshUi(); RefreshUi();
} }
private Point MousePositionToCanvasPosition() private Point MousePositionToCanvasPosition()
@@ -62,7 +62,7 @@ namespace Paint_2
Color hoveringColor = GetHoverColor(); Color hoveringColor = GetHoverColor();
Point mousePosition = MousePositionToCanvasPosition(); Point mousePosition = MousePositionToCanvasPosition();
int toolWidth = (int)nupPencilWidth.Value; int toolWidth = (int)nupPencilWidth.Value;
Project.MouseDown(SelectedLayers,hoveringColor, mousePosition, toolWidth); Project.MouseDown(SelectedLayers, hoveringColor, mousePosition, toolWidth);
RefreshUi(); RefreshUi();
} }
private void canvas_MouseUp(object sender, MouseEventArgs e) private void canvas_MouseUp(object sender, MouseEventArgs e)
@@ -102,10 +102,8 @@ namespace Paint_2
private void RefreshUi() private void RefreshUi()
{ {
lsbTools.DataSource = Project.AvaibleTools; lsbTools.DataSource = Project.AvaibleTools;
//DebugLabel.Text = Project.PrintAllLayers();
DebugLabel.Text = ""; DebugLabel.Text = "";
//canvas.Image = Project.PaintAllLayers();
canvas.Image = Project.PaintLayers(); canvas.Image = Project.PaintLayers();
lblSelectedColor.Text = ColorToString(Project.GetCurrentToolColor(SelectedLayers)); lblSelectedColor.Text = ColorToString(Project.GetCurrentToolColor(SelectedLayers));
@@ -243,23 +241,30 @@ namespace Paint_2
private void PaintForm_Load(object sender, EventArgs e) 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; tmrRefresh.Enabled = true;
DisplayLayers(); DisplayLayers();
} }
private void btnLayerRemove_Click(object sender, EventArgs e) private void btnLayerRemove_Click(object sender, EventArgs e)
{ {
//Project.RemoveLayer(lsbLayers.SelectedIndex); int layersCount = SelectedLayers.Count;
//foreach (int id in SelectedLayers) List<String> LayersToRemove = new List<string>();
for(int id = 0;id < SelectedLayers.Count;id++) foreach (string layer in SelectedLayers)
{ {
SelectedLayers.Remove(id); LayersToRemove.Add(layer);
Project.RemoveLayer(id);
} }
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(); DisplayLayers();
RefreshUi(); RefreshUi();
} }
@@ -275,17 +280,19 @@ namespace Paint_2
{ {
int Yoffset = 25; int Yoffset = 25;
int Xoffset = 10; int Xoffset = 10;
int blocsCount = 1; int blocsCount = 1;
int btnWidth = 75; int btnWidth = 75;
int labelWidth = 70; int labelWidth = 70;
int BtnXoffset = labelWidth; int BtnXoffset = labelWidth;
int ChkXOffset = BtnXoffset + btnWidth + Xoffset /2; int ChkXOffset = BtnXoffset + btnWidth + Xoffset / 2;
int ChkWidth = 20; int ChkWidth = 20;
pnlLayers.Controls.Clear(); pnlLayers.Controls.Clear();
foreach (Sketch layer in Project.Layers) List<Sketch> layers = Project.GetAllLayers();
foreach (Sketch layer in layers)
{ {
Label name = new Label(); Label name = new Label();
name.AutoSize = false; name.AutoSize = false;
@@ -293,12 +300,12 @@ namespace Paint_2
name.Text = layer.Name; name.Text = layer.Name;
name.BackColor = Color.Transparent; name.BackColor = Color.Transparent;
pnlLayers.Controls.Add(name); pnlLayers.Controls.Add(name);
name.Location = new Point(0,blocsCount * Yoffset); name.Location = new Point(0, blocsCount * Yoffset);
Button btn = new Button(); Button btn = new Button();
btn.Name = (blocsCount - 1).ToString(); btn.Name = "ChkLayerVisible:" + layer.Id;
btn.Click += LayerSelection; btn.Click += LayerSelection;
if (Project.LayersToPrint.Contains(Convert.ToInt32(btn.Name))) if (Project.LayersToPrint.Contains(layer.Id))
{ {
btn.Text = "Visible"; btn.Text = "Visible";
} }
@@ -308,13 +315,13 @@ namespace Paint_2
} }
pnlLayers.Controls.Add(btn); pnlLayers.Controls.Add(btn);
btn.BackColor = Color.FromArgb(59, 59, 59); 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.Width = btnWidth;
btn.FlatStyle = FlatStyle.Popup; btn.FlatStyle = FlatStyle.Popup;
Button chk = new Button(); Button chk = new Button();
chk.Click += LayerCheck; chk.Click += LayerCheck;
if (SelectedLayers.Contains(blocsCount-1)) if (SelectedLayers.Contains(layer.Id))
{ {
chk.BackColor = Color.Green; chk.BackColor = Color.Green;
} }
@@ -328,7 +335,7 @@ namespace Paint_2
chk.Text = ""; chk.Text = "";
chk.FlatStyle = FlatStyle.Popup; chk.FlatStyle = FlatStyle.Popup;
chk.Width = ChkWidth; chk.Width = ChkWidth;
chk.Name = "C" + (blocsCount -1).ToString(); chk.Name = "ChkLayerSelected:" + layer.Id;
blocsCount++; blocsCount++;
} }
@@ -337,17 +344,19 @@ namespace Paint_2
{ {
//We assume that the id of the layer is the name of the button //We assume that the id of the layer is the name of the button
Button btn = sender as 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); Project.SwitchLayer(id);
DisplayLayers(); DisplayLayers();
} }
private void LayerCheck(object sender, EventArgs e) 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; Button btn = sender as Button;
string cleanedName = btn.Name.Remove(0,1); //MessageBox.Show("Btn " + btn.Name + " pressed");
int id = Convert.ToInt32(cleanedName); string rawId = btn.Name;
//MessageBox.Show("Select or Deslect layer "+id); string id = rawId.Replace("ChkLayerSelected:", String.Empty);
//MessageBox.Show("Select or Deslect layer n:"+id);
if (SelectedLayers.Contains(id)) if (SelectedLayers.Contains(id))
{ {
SelectedLayers.Remove(id); SelectedLayers.Remove(id);

View File

@@ -15,8 +15,8 @@ namespace Paint_2
const int DEFAULT_WIDTH = 0; const int DEFAULT_WIDTH = 0;
private List<PaintTool> _avaibleTools; private List<PaintTool> _avaibleTools;
private List<int> _selectedLayers; private List<string> _selectedLayers;
//private Sketch _currentSketch; private Guid uniqIdGenerator;
private List<Sketch> _layers; private List<Sketch> _layers;
private bool _eyedropping; private bool _eyedropping;
private bool _randomColor; private bool _randomColor;
@@ -34,7 +34,7 @@ namespace Paint_2
public Random Random { get => _random; set => _random = value; } public Random Random { get => _random; set => _random = value; }
public bool Drawing { get => _drawing; set => _drawing = value; } public bool Drawing { get => _drawing; set => _drawing = value; }
public string Name { get => _name; set => _name = value; } public string Name { get => _name; set => _name = value; }
public List<int> LayersToPrint { get => _selectedLayers; set => _selectedLayers = value; } public List<string> LayersToPrint { get => _selectedLayers; set => _selectedLayers = value; }
public Project(string name, Size canvasSize) public Project(string name, Size canvasSize)
{ {
@@ -47,11 +47,12 @@ namespace Paint_2
AvaibleTools.Add(new DotPencil("Dotted Line")); AvaibleTools.Add(new DotPencil("Dotted Line"));
AvaibleTools.Add(new BezierPencil("Bezier Generator")); AvaibleTools.Add(new BezierPencil("Bezier Generator"));
//We create a single first layer with the default toolSet //We create a single first layer with the default toolSet
Layers = new List<Sketch>(); Layers = new List<Sketch>();
LayersToPrint = new List<string>();
AddLayer(); AddLayer();
//CurrentLayer = Layers[0]; LayersToPrint.Add(Layers[0].Id);
LayersToPrint = new List<int>();
LayersToPrint.Add(0);
} }
public void AddLayer() public void AddLayer()
{ {
@@ -60,28 +61,53 @@ namespace Paint_2
{ {
newTools.Add((PaintTool)tool.Clone()); 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 Sketch FindSketch(List<Sketch> layers, string id)
public void ChangeLayer(int idLayer)
{ {
CurrentLayer = Layers[idLayer]; foreach (Sketch layer in layers)
{
if (layer.Id == id)
{
return layer;
}
}
return null;
}
public bool IsSketchPresent (List<string> layers, string id)
{
foreach (string layer in layers)
{
if (layer == id)
{
return true;
}
}
return false;
} }
*/
public List<Sketch> GetAllLayers() public List<Sketch> GetAllLayers()
{ {
return Layers; 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); LayersToPrint.Remove(idLayer);
} }
@@ -90,18 +116,19 @@ namespace Paint_2
LayersToPrint.Add(idLayer); LayersToPrint.Add(idLayer);
} }
} }
public void MouseDown(List<int> selectedLayers, Color hoveringColor, Point mousePosition, int toolWidth) public void MouseDown(List<string> 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) if (Eyedropping)
{ {
Color pointedColor = hoveringColor; Color pointedColor = hoveringColor;
if (Layers[layer].CurrentTool.Color != pointedColor) if (layer.CurrentTool.Color != pointedColor)
{ {
Layers[layer].ChangePaintToolColor(pointedColor); layer.ChangePaintToolColor(pointedColor);
} }
} }
else else
@@ -109,73 +136,78 @@ namespace Paint_2
Drawing = true; Drawing = true;
if (RandomColor) 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 else
{ {
Layers[layer].StartDrawing(mousePosition, Layers[layer].CurrentTool.Color, toolWidth); layer.StartDrawing(mousePosition, layer.CurrentTool.Color, toolWidth);
} }
} }
} }
} }
} }
public void MouseUp(List<int> selectedLayers, Point mousePosition) public void MouseUp(List<string> 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) if (!Eyedropping)
{ {
Layers[layer].AddDrawingPoint(mousePosition); layer.AddDrawingPoint(mousePosition);
Drawing = false; Drawing = false;
Layers[layer].StopDrawing(); layer.StopDrawing();
} }
} }
} }
} }
public void TimerTick(List<int> selectedLayers, Point mousePosition) public void TimerTick(List<string> 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) if (Drawing)
{ {
Layers[layer].AddDrawingPoint(mousePosition); layer.AddDrawingPoint(mousePosition);
} }
} }
} }
} }
public void ChangeColor(List<int> selectedLayers, Color newColor) public void ChangeColor(List<string> 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<int> selectedLayers, int width) public void ChangeWidth(List<string> 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<int> selectedLayers, int toolId) public void ChangeTool(List<string> 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); Bitmap result = new Bitmap(CanvasSize.Width, CanvasSize.Height);
Graphics gr = Graphics.FromImage(result); 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; return result;
@@ -216,11 +249,12 @@ namespace Paint_2
{ {
Bitmap result = new Bitmap(CanvasSize.Width, CanvasSize.Height); Bitmap result = new Bitmap(CanvasSize.Width, CanvasSize.Height);
Graphics gr = Graphics.FromImage(result); 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].Paint(), Point.Empty); gr.DrawImage(layer.Paint(), Point.Empty);
} }
} }
return result; return result;
@@ -232,37 +266,40 @@ namespace Paint_2
layer.Clear(); layer.Clear();
} }
} }
public Color GetCurrentToolColor(List<int> selectedLayers) public Color GetCurrentToolColor(List<string> selectedLayers)
{ {
if(selectedLayers.Count == 0) if (Layers.Count == 0 || selectedLayers.Count == 0)
{ {
return DEFAULT_COLOR; return DEFAULT_COLOR;
} }
Sketch CurrentLayer = Layers[selectedLayers[0]]; else
return CurrentLayer.CurrentTool.Color; {
//Sketch CurrentLayer = Layers[selectedLayers[0];
Sketch CurrentLayer = FindSketch(Layers,selectedLayers[0]);
return CurrentLayer.CurrentTool.Color;
}
} }
public int GetCurrentToolWidth(List<int> selectedLayers) public int GetCurrentToolWidth(List<string> selectedLayers)
{ {
if (selectedLayers.Count == 0) if (selectedLayers.Count == 0)
{ {
return DEFAULT_WIDTH; return DEFAULT_WIDTH;
} }
Sketch CurrentLayer = Layers[selectedLayers[0]]; Sketch CurrentLayer = FindSketch(Layers, selectedLayers[0]);
return CurrentLayer.CurrentTool.Width; return CurrentLayer.CurrentTool.Width;
} }
public List<Color> GetLayerColorHistory(List<int> selectedLayers,int colorsCount) public List<Color> GetLayerColorHistory(List<string> selectedLayers, int colorsCount)
{ {
if(selectedLayers.Count == 0) if (selectedLayers.Count == 0)
{ {
List<Color> result = new List<Color>(); List<Color> result = new List<Color>();
for (int i = 0;i < colorsCount;i++) for (int i = 0; i < colorsCount; i++)
{ {
result.Add(DEFAULT_COLOR); result.Add(DEFAULT_COLOR);
} }
return result; return result;
} }
Sketch CurrentLayer = FindSketch(Layers, selectedLayers[0]);
Sketch CurrentLayer = Layers[selectedLayers[0]];
return CurrentLayer.CurrentTool.GetLastColors(colorsCount); return CurrentLayer.CurrentTool.GetLastColors(colorsCount);
} }
public void Save(string fileName, Bitmap image) public void Save(string fileName, Bitmap image)
@@ -310,23 +347,25 @@ namespace Paint_2
{ {
Eyedropping = !Eyedropping; Eyedropping = !Eyedropping;
} }
public void Undo(List<int> selectedLayers) public void Undo(List<string> 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<int> selectedLayers) public void Redo(List<string> 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();
} }
} }
} }

View File

@@ -20,6 +20,7 @@ namespace Paint_2
bool _isDrawing; bool _isDrawing;
Bitmap _drawing; Bitmap _drawing;
Size _sketchSize; Size _sketchSize;
string id;
string _name; string _name;
internal List<PaintTool> ToolList { get => _toolList; set => _toolList = value; } internal List<PaintTool> ToolList { get => _toolList; set => _toolList = value; }
public PaintTool CurrentTool { get => _currentTool; set => _currentTool = 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 Bitmap Drawing { get => _drawing; set => _drawing = value; }
public Size SketchSize { get => _sketchSize; set => _sketchSize = value; } public Size SketchSize { get => _sketchSize; set => _sketchSize = value; }
public string Name { get => _name; set => _name = value; } public string Name { get => _name; set => _name = value; }
public string Id { get => id; set => id = value; }
public Sketch(string name,Size sketchSize, List<PaintTool> toolList) public Sketch(string name,Size sketchSize, List<PaintTool> toolList,string guid)
{ {
IsDrawing = false; IsDrawing = false;
Id = guid;
Name = name; Name = name;
SketchSize = sketchSize; SketchSize = sketchSize;
Drawing = new Bitmap(SketchSize.Width, SketchSize.Height); Drawing = new Bitmap(SketchSize.Width, SketchSize.Height);
@@ -49,7 +52,7 @@ namespace Paint_2
CurrentTool = null; CurrentTool = null;
} }
} }
public Sketch(List<PaintTool> toolList) : this("Layer 1",new Size(500, 500), toolList) public Sketch(List<PaintTool> toolList,string guid) : this("Layer 1",new Size(500, 500), toolList,guid)
{ {
//empty //empty
} }