Edited the layers auto generated controls

This commit is contained in:
2022-06-15 14:37:56 +02:00
parent 942185c3b4
commit a464514745
3 changed files with 72 additions and 48 deletions

View File

@@ -303,7 +303,7 @@
this.nupPencilWidth.BorderStyle = System.Windows.Forms.BorderStyle.None; this.nupPencilWidth.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.nupPencilWidth.Font = new System.Drawing.Font("Cascadia Code", 15F); this.nupPencilWidth.Font = new System.Drawing.Font("Cascadia Code", 15F);
this.nupPencilWidth.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.nupPencilWidth.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.nupPencilWidth.Location = new System.Drawing.Point(128, 198); this.nupPencilWidth.Location = new System.Drawing.Point(126, 166);
this.nupPencilWidth.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.nupPencilWidth.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.nupPencilWidth.Maximum = new decimal(new int[] { this.nupPencilWidth.Maximum = new decimal(new int[] {
255, 255,

View File

@@ -21,20 +21,11 @@ namespace Paint_2
public partial class PaintForm : Form public partial class PaintForm : Form
{ {
const int WINDOW_OFFSET = 15; const int WINDOW_OFFSET = 15;
//const string DEFAULT_FILEPATH = "C:/Paint2/Drawings/"; //readonly Font FONT = new Font("Arial", fontSize);
readonly Color FLAT_RED = Color.FromArgb(0xC6, 0x28, 0x28); readonly Color FLAT_RED = Color.FromArgb(0xC6, 0x28, 0x28);
readonly Color FLAT_GREEN = Color.FromArgb(0x00, 0x89, 0x7B); readonly Color FLAT_GREEN = Color.FromArgb(0x00, 0x89, 0x7B);
readonly Color FLAT_GREY1 = Color.FromArgb(0x59, 0x59, 0x59);
//public Sketch sketch;
//List<PaintTool> toolList;
//bool drawing = false;
//bool randomColor = false;
//bool eyeDropping = false;
//Random _random;
private Color _hoveringColor; private Color _hoveringColor;
private Project _project; private Project _project;
private int _selectedLayer; private int _selectedLayer;
@@ -270,22 +261,22 @@ namespace Paint_2
private void BtnAddLayer_Click(object sender, EventArgs e) private void BtnAddLayer_Click(object sender, EventArgs e)
{ {
Project.AddLayer(); SelectedLayers.Add(Project.AddLayer());
DisplayLayers(); DisplayLayers();
RefreshUi(); RefreshUi();
} }
private void DisplayLayers() private void DisplayLayers()
{ {
//I know I know this is not really MVC yet but I will address that int Yoffset = 10;
int Yoffset = 25;
int Xoffset = 10; int Xoffset = 10;
float fontSize = 10;
int blocsCount = 1; Size blocSize = new Size(pnlLayers.Width,pnlLayers.Height/6);
int btnWidth = 75; int blocsCount = 0;
int labelWidth = 70; int btnWidth = (int)(blocSize.Width / 2.7);
int labelWidth = (int)(blocSize.Width / 3.0);
int BtnXoffset = labelWidth; int BtnXoffset = labelWidth;
int ChkXOffset = BtnXoffset + btnWidth + Xoffset / 2; int ChkXOffset = BtnXoffset + btnWidth /*+ Xoffset*/;
int ChkWidth = 20; int ChkWidth = (int)(blocSize.Width / 6.0);
pnlLayers.Controls.Clear(); pnlLayers.Controls.Clear();
@@ -293,32 +284,54 @@ namespace Paint_2
foreach (Sketch layer in layers) foreach (Sketch layer in layers)
{ {
Label name = new Label(); //LABEL LAYER NAME
name.AutoSize = false; Label lblName = new Label();
name.Width = labelWidth; //Style
name.Text = layer.Name; lblName.Name = "lblLayer"+layer.Id;
name.BackColor = Color.Transparent; lblName.Font = new Font("Arial",fontSize);
pnlLayers.Controls.Add(name); lblName.AutoSize = false;
name.Location = new Point(0, blocsCount * Yoffset); lblName.Width = labelWidth;
lblName.Text = layer.Name;
lblName.BackColor = Color.Transparent;
lblName.Location = new Point(0,blocsCount * blocSize.Height + Yoffset);
//Style
//Behaviour
pnlLayers.Controls.Add(lblName);
//Behaviour
Button btn = new Button(); //BUTTON VISIBILITY
btn.Name = "ChkLayerVisible:" + layer.Id; Button BtnVisbility = new Button();
btn.Click += LayerSelection; //Style
BtnVisbility.FlatStyle = FlatStyle.Popup;
BtnVisbility.BackColor = FLAT_GREY1;
BtnVisbility.Location = new Point(BtnXoffset, blocsCount * blocSize.Height + Yoffset / 2);
BtnVisbility.Width = btnWidth;
//Style
//Behaviour
if (Project.LayersToPrint.Contains(layer.Id)) if (Project.LayersToPrint.Contains(layer.Id))
{ {
btn.Text = "Visible"; BtnVisbility.Text = "Visible";
} }
else else
{ {
btn.Text = "Invisible"; BtnVisbility.Text = "Invisible";
} }
pnlLayers.Controls.Add(btn); BtnVisbility.Name = "ChkLayerVisible:" + layer.Id;
btn.BackColor = Color.FromArgb(59, 59, 59); BtnVisbility.Click += LayerSelection;
btn.Location = new Point(BtnXoffset, blocsCount * Yoffset); pnlLayers.Controls.Add(BtnVisbility);
btn.Width = btnWidth; //Behaviour
btn.FlatStyle = FlatStyle.Popup;
//BUTTON LAYER SELECTION
Button chk = new Button(); Button chk = new Button();
//Style
chk.Location = new Point(ChkXOffset, blocsCount * blocSize.Height + Yoffset / 2);
chk.AutoSize = false;
chk.Text = "";
chk.FlatStyle = FlatStyle.Popup;
chk.Width = ChkWidth;
chk.Name = "ChkLayerSelected:" + layer.Id;
//Style
//Behaviour
chk.Click += LayerCheck; chk.Click += LayerCheck;
if (SelectedLayers.Contains(layer.Id)) if (SelectedLayers.Contains(layer.Id))
{ {
@@ -329,19 +342,14 @@ namespace Paint_2
chk.BackColor = Color.Red; chk.BackColor = Color.Red;
} }
pnlLayers.Controls.Add(chk); pnlLayers.Controls.Add(chk);
chk.Location = new Point(ChkXOffset, blocsCount * Yoffset); //Behaviour
chk.AutoSize = false;
chk.Text = "";
chk.FlatStyle = FlatStyle.Popup;
chk.Width = ChkWidth;
chk.Name = "ChkLayerSelected:" + layer.Id;
blocsCount++; blocsCount++;
} }
} }
private void LayerSelection(object sender, EventArgs e) private void LayerSelection(object sender, EventArgs e)
{ {
//We assume that the id of the layer is the name of the button //We know that the button's name is ChkLayerVisible:... ... being the GUID of the layer
Button btn = sender as Button; Button btn = sender as Button;
string rawId = btn.Name; string rawId = btn.Name;
string id = rawId.Replace("ChkLayerVisible:", String.Empty); string id = rawId.Replace("ChkLayerVisible:", String.Empty);
@@ -350,7 +358,7 @@ namespace Paint_2
} }
private void LayerCheck(object sender, EventArgs e) private void LayerCheck(object sender, EventArgs e)
{ {
// We should receive "CheckBox:937r9837r893" //We know that the button's name is ChkLayerSelected:... ... being the GUID of the layer
Button btn = sender as Button; Button btn = sender as Button;
//MessageBox.Show("Btn " + btn.Name + " pressed"); //MessageBox.Show("Btn " + btn.Name + " pressed");
string rawId = btn.Name; string rawId = btn.Name;

View File

@@ -54,7 +54,7 @@ namespace Paint_2
AddLayer(); AddLayer();
LayersToPrint.Add(Layers[0].Id); LayersToPrint.Add(Layers[0].Id);
} }
public void AddLayer() public string AddLayer()
{ {
List<PaintTool> newTools = new List<PaintTool>(); List<PaintTool> newTools = new List<PaintTool>();
foreach (PaintTool tool in AvaibleTools) foreach (PaintTool tool in AvaibleTools)
@@ -63,7 +63,22 @@ namespace Paint_2
} }
uniqIdGenerator = Guid.NewGuid(); uniqIdGenerator = Guid.NewGuid();
string test = uniqIdGenerator.ToString(); string test = uniqIdGenerator.ToString();
Layers.Add(new Sketch(String.Concat("Layer", Layers.Count + 1), CanvasSize, newTools, uniqIdGenerator.ToString())); Sketch newSketch = new Sketch(String.Concat("Layer_", Layers.Count + 1), CanvasSize, newTools, uniqIdGenerator.ToString());
Layers.Add(newSketch);
LayersToPrint.Add(newSketch.Id);
RestoreLayerNames();
return (newSketch.Id);
}
private void RestoreLayerNames()
{
//resets all the names to not have multiple layer 3 for example
for (int i = 0; i < Layers.Count; i++)
{
Layers[i].Name = "Layer_" + (i + 1);
}
} }
public bool RemoveLayer(string layerId) public bool RemoveLayer(string layerId)
{ {
@@ -71,6 +86,7 @@ namespace Paint_2
if (layer != null) if (layer != null)
{ {
Layers.Remove(layer); Layers.Remove(layer);
RestoreLayerNames();
return true; return true;
} }
else else