Compare commits
37 Commits
6d4ee29a2e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| e243b37884 | |||
| 640796a1b1 | |||
| 44dd8b9f0c | |||
| 95217bb3c5 | |||
| 9b4cfb33bd | |||
| 15a4daf2f7 | |||
| dfc8ca24dd | |||
| 2dc7035f80 | |||
| bbf3b66ed9 | |||
| 2c0ac2979a | |||
| f339c5e411 | |||
| a464514745 | |||
| 942185c3b4 | |||
| bc674dad86 | |||
| 5cac05a9aa | |||
| 47e57db137 | |||
| 97d800af1f | |||
| 44956fbc59 | |||
| f5f6056db1 | |||
| d1d1b4936e | |||
| 0f8cc294e3 | |||
| 35b3fe0f1d | |||
| f334aa7ad1 | |||
| 03fb9f3560 | |||
| 3a6c7531e0 | |||
| 1a468895ad | |||
| 0f4d845fd8 | |||
| 510fc2a351 | |||
| edb119072c | |||
| fbfec9eccf | |||
| 8cdfc0acfa | |||
| dec7669842 | |||
| 17c4c22781 | |||
| 2a4d2ed9ed | |||
| 6614cab8a7 | |||
| f25d3c1bcf | |||
| c3728b01fc |
@@ -0,0 +1,294 @@
|
||||
/// file: BezierPencil.cs
|
||||
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
||||
/// Brief: A unique tool that draws Bezier curves
|
||||
/// Version: 0.1.0
|
||||
/// Date: 17/06/2022
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Paint_2
|
||||
{
|
||||
internal class BezierPencil : PaintTool
|
||||
{
|
||||
private List<List<Point>> _drawings;
|
||||
private List<List<Point>> _drawingsRedo;
|
||||
private bool _needsFullRefresh;
|
||||
private bool _isCtrlPressed;
|
||||
private bool _isShiftPressed;
|
||||
private PaintToolUtils Utils;
|
||||
private List<Color> _colors;
|
||||
private List<Color> _colorsRedo;
|
||||
private List<int> _widths;
|
||||
private List<int> _widthsRedo;
|
||||
private Color _color;
|
||||
private string _name;
|
||||
private int _width;
|
||||
|
||||
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
||||
public List<List<Point>> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; }
|
||||
public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; }
|
||||
public List<Color> Colors { get => _colors; set => _colors = value; }
|
||||
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
||||
public List<int> Widths { get => _widths; set => _widths = value; }
|
||||
public List<int> WidthsRedo { get => _widthsRedo; set => _widthsRedo = value; }
|
||||
public bool IsShiftPressed { get => _isShiftPressed; set => _isShiftPressed = value; }
|
||||
public bool IsCtrlPressed { get => _isCtrlPressed; set => _isCtrlPressed = value; }
|
||||
public Color Color { get => _color; set => _color = value; }
|
||||
public string Name { get => _name; set => _name = value; }
|
||||
public int Width { get => _width; set => _width = value; }
|
||||
|
||||
public BezierPencil(string name)
|
||||
{
|
||||
NeedsFullRefresh = true;
|
||||
Drawings = new List<List<Point>>();
|
||||
DrawingsRedo = new List<List<Point>>();
|
||||
Colors = new List<Color>();
|
||||
ColorsRedo = new List<Color>();
|
||||
Widths = new List<int>();
|
||||
WidthsRedo = new List<int>();
|
||||
Name = name;
|
||||
|
||||
Utils = new PaintToolUtils(this);
|
||||
}
|
||||
public void Add(Point point)
|
||||
{
|
||||
if (Drawings[Drawings.Count - 1].Count == 0)
|
||||
{
|
||||
Drawings[Drawings.Count - 1].Add(point);
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
Utils.StandartClear();
|
||||
}
|
||||
|
||||
public List<Color> GetLastColors(int colorNumber)
|
||||
{
|
||||
return Utils.SandartGetLastColors(colorNumber);
|
||||
}
|
||||
public void Paint(Bitmap canvas)
|
||||
{
|
||||
Graphics gr = Graphics.FromImage(canvas);
|
||||
Size pointSize;
|
||||
List<Point> points = new List<Point>();
|
||||
foreach (List<Point> drawing in Drawings)
|
||||
{
|
||||
if (drawing.Count > 0)
|
||||
{
|
||||
points.Add(drawing[0]);
|
||||
}
|
||||
}
|
||||
if (points.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
{
|
||||
pointSize = new Size(Widths[0] / 2, Widths[0] / 2);
|
||||
//ContinuousBezierGenerator(gr, points, Colors[Colors.Count-1], Widths[Widths.Count -1]);
|
||||
AdjustedBezierGenerator(gr, points, Colors[Colors.Count - 1], Widths[Widths.Count - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void AdjustedBezierGenerator(Graphics gr, List<Point> points, Color color, int width)
|
||||
{
|
||||
foreach (Point p in points)
|
||||
{
|
||||
gr.FillEllipse(new SolidBrush(color), new Rectangle(new Point(p.X - width / 2, p.Y - width / 2), new Size(width,width)));
|
||||
}
|
||||
if (points.Count >= 3)
|
||||
{
|
||||
float precision = 0.01f;
|
||||
for (float t = 0; t <= 1; t += precision)
|
||||
{
|
||||
List<Point> DumpList = new List<Point>();
|
||||
List<Point> WorkingList = new List<Point>();
|
||||
|
||||
foreach (Point p in points)
|
||||
{
|
||||
WorkingList.Add(new Point(p.X, p.Y));
|
||||
}
|
||||
while (WorkingList.Count > 1)
|
||||
{
|
||||
for (int i = 0; i < WorkingList.Count - 1; i++)
|
||||
{
|
||||
Point p1 = WorkingList[i];
|
||||
Point p2 = WorkingList[i + 1];
|
||||
Point tmp = Utils.Lerp(p1, p2, t);
|
||||
DumpList.Add(tmp);
|
||||
}
|
||||
WorkingList.Clear();
|
||||
foreach (Point p in DumpList)
|
||||
{
|
||||
WorkingList.Add(new Point(p.X, p.Y));
|
||||
}
|
||||
DumpList.Clear();
|
||||
}
|
||||
gr.FillEllipse(new SolidBrush(color), new Rectangle(WorkingList[0].X - Widths[0] / 2, WorkingList[0].Y - Widths[0] / 2, width, width));
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ContinuousBezierGenerator(Graphics gr, List<Point> points, Color color, int width)
|
||||
{
|
||||
if (points.Count >= 4 && points.Count % 2 == 0)
|
||||
{
|
||||
float precision = 0.01f;
|
||||
for (float t = 0; t <= 1; t += precision)
|
||||
{
|
||||
List<Point> DumpList = new List<Point>();
|
||||
List<Point> WorkingList = new List<Point>(points);
|
||||
|
||||
while (WorkingList.Count != 1)
|
||||
{
|
||||
if (WorkingList.Count > 1)
|
||||
{
|
||||
for (int pos = 0; pos < WorkingList.Count - 1; pos++)
|
||||
{
|
||||
DumpList.Add(Utils.Lerp(WorkingList[pos], WorkingList[pos + 1], t));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DumpList.Add(Utils.Lerp(WorkingList[0], WorkingList[1], precision));
|
||||
}
|
||||
WorkingList = new List<Point>(DumpList);
|
||||
DumpList = new List<Point>();
|
||||
}
|
||||
gr.FillEllipse(new SolidBrush(color), new Rectangle(WorkingList[0].X - Widths[0] / 2, WorkingList[0].Y - Widths[0] / 2, width, width));
|
||||
}
|
||||
}
|
||||
}
|
||||
public string PaintSVG()
|
||||
{
|
||||
string result = "";
|
||||
string newLine = Environment.NewLine;
|
||||
|
||||
Size pointSize;
|
||||
List<Point> points = new List<Point>();
|
||||
foreach (List<Point> drawing in Drawings)
|
||||
{
|
||||
if (drawing.Count > 0)
|
||||
{
|
||||
points.Add(drawing[0]);
|
||||
}
|
||||
}
|
||||
if (points.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
{
|
||||
pointSize = new Size(Widths[0] / 2, Widths[0] / 2);
|
||||
//Not really usefull in the SVG world because only the last layer will be displayed
|
||||
//result += "<ellipse cx=\"" + points[i].X + "\" cy=\"" + points[i].Y + "\" rx=\"" + pointSize.Width / 2 + "\" ry=\"" + pointSize.Height / 2 + "\" style=\"fill:rgb(" + Colors[i].R + ", " + Colors[i].G + ", " + Colors[i].B + ");\"/>";
|
||||
//result += newLine;
|
||||
result += ContinuousBezierGeneratorSVG(points, Colors[Colors.Count - 1], Widths[Widths.Count - 1]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private string ContinuousBezierGeneratorSVG(List<Point> points, Color color, int width)
|
||||
{
|
||||
string result = "";
|
||||
string newLine = Environment.NewLine;
|
||||
|
||||
if (points.Count >= 3)
|
||||
{
|
||||
float precision = 0.01f;
|
||||
for (float t = 0; t <= 1; t += precision)
|
||||
{
|
||||
List<Point> DumpList = new List<Point>();
|
||||
List<Point> WorkingList = new List<Point>();
|
||||
|
||||
foreach (Point p in points)
|
||||
{
|
||||
WorkingList.Add(new Point(p.X, p.Y));
|
||||
}
|
||||
while (WorkingList.Count > 1)
|
||||
{
|
||||
for (int i = 0; i < WorkingList.Count - 1; i++)
|
||||
{
|
||||
Point p1 = WorkingList[i];
|
||||
Point p2 = WorkingList[i + 1];
|
||||
Point tmp = Utils.Lerp(p1, p2, t);
|
||||
DumpList.Add(tmp);
|
||||
}
|
||||
WorkingList.Clear();
|
||||
foreach (Point p in DumpList)
|
||||
{
|
||||
WorkingList.Add(new Point(p.X, p.Y));
|
||||
}
|
||||
DumpList.Clear();
|
||||
}
|
||||
result += "<ellipse cx=\"" + WorkingList[0].X + "\" cy=\"" + WorkingList[0].Y + "\" rx=\"" + width / 2 + "\" ry=\"" + width / 2 + "\" style=\"fill:rgb(" + color.R + ", " + color.G + ", " + color.B + ");\"/>";
|
||||
result += newLine;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private void BezierGenerator(Graphics gr, Point p1, Point p2, Point p3, Point p4, int i)
|
||||
{
|
||||
gr.DrawLine(new Pen(Colors[i - 4], Widths[i - 4]), p1, p2);
|
||||
gr.DrawLine(new Pen(Colors[i - 3], Widths[i - 3]), p2, p3);
|
||||
gr.DrawLine(new Pen(Colors[i - 2], Widths[i - 2]), p3, p4);
|
||||
|
||||
//float t = 0.5f;
|
||||
float precision = 0.01f;
|
||||
|
||||
for (float t = 0; t <= 1; t += precision)
|
||||
{
|
||||
Point p1_2 = Utils.Lerp(p1, p2, t);
|
||||
Point p2_2 = Utils.Lerp(p2, p3, t);
|
||||
Point p3_2 = Utils.Lerp(p3, p4, t);
|
||||
|
||||
//Drawing the second step of the curve
|
||||
Point p1_3 = Utils.Lerp(p1_2, p2_2, t);
|
||||
Point p2_3 = Utils.Lerp(p2_2, p3_2, t);
|
||||
|
||||
//Drawing the Bezier Point
|
||||
Point p1_4 = Utils.Lerp(p1_3, p2_3, t);
|
||||
|
||||
gr.FillEllipse(new SolidBrush(GetRandomColor()), new Rectangle(p1_4.X - Widths[0] / 2, p1_4.Y - Widths[0] / 2, Widths[0], Widths[0]));
|
||||
}
|
||||
}
|
||||
private Color GetRandomColor()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
return Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
}
|
||||
public void Start(Color color, int width)
|
||||
{
|
||||
Utils.StandartStart(color, width);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
//Empty
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
Utils.StandartUndo();
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
Utils.StandartRedo();
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
BezierPencil result = new BezierPencil(Name);
|
||||
result.Width = Width;
|
||||
result.Color = Color;
|
||||
return (Object)(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+299
@@ -0,0 +1,299 @@
|
||||
namespace Paint_2
|
||||
{
|
||||
partial class ColorPicker
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.pbxColor = new System.Windows.Forms.PictureBox();
|
||||
this.pbxSelectedColor = new System.Windows.Forms.PictureBox();
|
||||
this.nupRed = new System.Windows.Forms.NumericUpDown();
|
||||
this.nupGreen = new System.Windows.Forms.NumericUpDown();
|
||||
this.nupBlue = new System.Windows.Forms.NumericUpDown();
|
||||
this.nupGamma = new System.Windows.Forms.NumericUpDown();
|
||||
this.tbxColorHex = new System.Windows.Forms.TextBox();
|
||||
this.pbxSliderRed = new System.Windows.Forms.PictureBox();
|
||||
this.pbxSliderSaturation = new System.Windows.Forms.PictureBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.tmrRefreshBars = new System.Windows.Forms.Timer(this.components);
|
||||
this.tmrRefreshMain = new System.Windows.Forms.Timer(this.components);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbxColor)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbxSelectedColor)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nupRed)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nupGreen)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nupBlue)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nupGamma)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbxSliderRed)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbxSliderSaturation)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pbxColor
|
||||
//
|
||||
this.pbxColor.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(31)))), ((int)(((byte)(31)))), ((int)(((byte)(31)))));
|
||||
this.pbxColor.Location = new System.Drawing.Point(13, 13);
|
||||
this.pbxColor.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
|
||||
this.pbxColor.Name = "pbxColor";
|
||||
this.pbxColor.Size = new System.Drawing.Size(255, 255);
|
||||
this.pbxColor.TabIndex = 0;
|
||||
this.pbxColor.TabStop = false;
|
||||
this.pbxColor.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pbxColor_MouseDown);
|
||||
this.pbxColor.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pbxColor_MouseUp);
|
||||
//
|
||||
// pbxSelectedColor
|
||||
//
|
||||
this.pbxSelectedColor.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(31)))), ((int)(((byte)(31)))), ((int)(((byte)(31)))));
|
||||
this.pbxSelectedColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.pbxSelectedColor.Location = new System.Drawing.Point(311, 189);
|
||||
this.pbxSelectedColor.Name = "pbxSelectedColor";
|
||||
this.pbxSelectedColor.Size = new System.Drawing.Size(116, 116);
|
||||
this.pbxSelectedColor.TabIndex = 4;
|
||||
this.pbxSelectedColor.TabStop = false;
|
||||
this.pbxSelectedColor.Click += new System.EventHandler(this.pbxSelectedColor_Click);
|
||||
//
|
||||
// nupRed
|
||||
//
|
||||
this.nupRed.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(59)))), ((int)(((byte)(59)))), ((int)(((byte)(59)))));
|
||||
this.nupRed.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.nupRed.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.nupRed.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
|
||||
this.nupRed.Location = new System.Drawing.Point(336, 58);
|
||||
this.nupRed.Maximum = new decimal(new int[] {
|
||||
255,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.nupRed.Name = "nupRed";
|
||||
this.nupRed.Size = new System.Drawing.Size(91, 25);
|
||||
this.nupRed.TabIndex = 11;
|
||||
this.nupRed.ValueChanged += new System.EventHandler(this.nupValueChanged);
|
||||
//
|
||||
// nupGreen
|
||||
//
|
||||
this.nupGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(59)))), ((int)(((byte)(59)))), ((int)(((byte)(59)))));
|
||||
this.nupGreen.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.nupGreen.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.nupGreen.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
|
||||
this.nupGreen.Location = new System.Drawing.Point(336, 89);
|
||||
this.nupGreen.Maximum = new decimal(new int[] {
|
||||
255,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.nupGreen.Name = "nupGreen";
|
||||
this.nupGreen.Size = new System.Drawing.Size(91, 25);
|
||||
this.nupGreen.TabIndex = 16;
|
||||
this.nupGreen.ValueChanged += new System.EventHandler(this.nupValueChanged);
|
||||
//
|
||||
// nupBlue
|
||||
//
|
||||
this.nupBlue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(59)))), ((int)(((byte)(59)))), ((int)(((byte)(59)))));
|
||||
this.nupBlue.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.nupBlue.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.nupBlue.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
|
||||
this.nupBlue.Location = new System.Drawing.Point(336, 120);
|
||||
this.nupBlue.Maximum = new decimal(new int[] {
|
||||
255,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.nupBlue.Name = "nupBlue";
|
||||
this.nupBlue.Size = new System.Drawing.Size(91, 25);
|
||||
this.nupBlue.TabIndex = 17;
|
||||
this.nupBlue.ValueChanged += new System.EventHandler(this.nupValueChanged);
|
||||
//
|
||||
// nupGamma
|
||||
//
|
||||
this.nupGamma.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(59)))), ((int)(((byte)(59)))), ((int)(((byte)(59)))));
|
||||
this.nupGamma.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.nupGamma.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.nupGamma.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
|
||||
this.nupGamma.Location = new System.Drawing.Point(336, 151);
|
||||
this.nupGamma.Maximum = new decimal(new int[] {
|
||||
255,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.nupGamma.Name = "nupGamma";
|
||||
this.nupGamma.Size = new System.Drawing.Size(91, 25);
|
||||
this.nupGamma.TabIndex = 18;
|
||||
this.nupGamma.ValueChanged += new System.EventHandler(this.nupValueChanged);
|
||||
//
|
||||
// tbxColorHex
|
||||
//
|
||||
this.tbxColorHex.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(59)))), ((int)(((byte)(59)))), ((int)(((byte)(59)))));
|
||||
this.tbxColorHex.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.tbxColorHex.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.tbxColorHex.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
|
||||
this.tbxColorHex.Location = new System.Drawing.Point(311, 14);
|
||||
this.tbxColorHex.Name = "tbxColorHex";
|
||||
this.tbxColorHex.Size = new System.Drawing.Size(116, 29);
|
||||
this.tbxColorHex.TabIndex = 20;
|
||||
this.tbxColorHex.Text = "#FFFFFF";
|
||||
this.tbxColorHex.TextChanged += new System.EventHandler(this.tbxColorHex_TextChanged);
|
||||
this.tbxColorHex.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbxColorHex_KeyDown);
|
||||
//
|
||||
// pbxSliderRed
|
||||
//
|
||||
this.pbxSliderRed.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(31)))), ((int)(((byte)(31)))), ((int)(((byte)(31)))));
|
||||
this.pbxSliderRed.Location = new System.Drawing.Point(11, 275);
|
||||
this.pbxSliderRed.Name = "pbxSliderRed";
|
||||
this.pbxSliderRed.Size = new System.Drawing.Size(255, 30);
|
||||
this.pbxSliderRed.TabIndex = 21;
|
||||
this.pbxSliderRed.TabStop = false;
|
||||
this.pbxSliderRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.SliderMouseDown);
|
||||
this.pbxSliderRed.MouseUp += new System.Windows.Forms.MouseEventHandler(this.SliderMouseUp);
|
||||
//
|
||||
// pbxSliderSaturation
|
||||
//
|
||||
this.pbxSliderSaturation.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(31)))), ((int)(((byte)(31)))), ((int)(((byte)(31)))));
|
||||
this.pbxSliderSaturation.Location = new System.Drawing.Point(275, 13);
|
||||
this.pbxSliderSaturation.Name = "pbxSliderSaturation";
|
||||
this.pbxSliderSaturation.Size = new System.Drawing.Size(30, 255);
|
||||
this.pbxSliderSaturation.TabIndex = 22;
|
||||
this.pbxSliderSaturation.TabStop = false;
|
||||
this.pbxSliderSaturation.MouseDown += new System.Windows.Forms.MouseEventHandler(this.SliderMouseDown);
|
||||
this.pbxSliderSaturation.MouseUp += new System.Windows.Forms.MouseEventHandler(this.SliderMouseUp);
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
|
||||
this.label1.Location = new System.Drawing.Point(308, 57);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(24, 22);
|
||||
this.label1.TabIndex = 23;
|
||||
this.label1.Text = "R";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.label2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
|
||||
this.label2.Location = new System.Drawing.Point(307, 88);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(25, 22);
|
||||
this.label2.TabIndex = 24;
|
||||
this.label2.Text = "G";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.label3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
|
||||
this.label3.Location = new System.Drawing.Point(307, 119);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(23, 22);
|
||||
this.label3.TabIndex = 25;
|
||||
this.label3.Text = "B";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.label4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
|
||||
this.label4.Location = new System.Drawing.Point(308, 150);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(23, 22);
|
||||
this.label4.TabIndex = 26;
|
||||
this.label4.Text = "A";
|
||||
//
|
||||
// tmrRefreshBars
|
||||
//
|
||||
this.tmrRefreshBars.Interval = 1;
|
||||
this.tmrRefreshBars.Tick += new System.EventHandler(this.tmrRefresh_Tick);
|
||||
//
|
||||
// tmrRefreshMain
|
||||
//
|
||||
this.tmrRefreshMain.Interval = 1;
|
||||
this.tmrRefreshMain.Tick += new System.EventHandler(this.tmrRefreshMain_Tick);
|
||||
//
|
||||
// ColorPicker
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 18F);
|
||||
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(433, 314);
|
||||
this.Controls.Add(this.label4);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.pbxSliderSaturation);
|
||||
this.Controls.Add(this.pbxSliderRed);
|
||||
this.Controls.Add(this.tbxColorHex);
|
||||
this.Controls.Add(this.nupGamma);
|
||||
this.Controls.Add(this.nupBlue);
|
||||
this.Controls.Add(this.nupGreen);
|
||||
this.Controls.Add(this.nupRed);
|
||||
this.Controls.Add(this.pbxSelectedColor);
|
||||
this.Controls.Add(this.pbxColor);
|
||||
this.DoubleBuffered = true;
|
||||
this.Font = new System.Drawing.Font("Cascadia Code", 10.2F);
|
||||
this.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(214)))), ((int)(((byte)(214)))), ((int)(((byte)(214)))));
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
|
||||
this.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
|
||||
this.MaximizeBox = false;
|
||||
this.Name = "ColorPicker";
|
||||
this.Text = "ColorPicker";
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ColorPicker_FormClosing);
|
||||
this.Load += new System.EventHandler(this.ColorPicker_Load);
|
||||
this.Shown += new System.EventHandler(this.ColorPicker_Shown);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbxColor)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbxSelectedColor)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nupRed)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nupGreen)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nupBlue)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nupGamma)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbxSliderRed)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbxSliderSaturation)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.PictureBox pbxColor;
|
||||
private System.Windows.Forms.PictureBox pbxSelectedColor;
|
||||
private System.Windows.Forms.NumericUpDown nupRed;
|
||||
private System.Windows.Forms.NumericUpDown nupGreen;
|
||||
private System.Windows.Forms.NumericUpDown nupBlue;
|
||||
private System.Windows.Forms.NumericUpDown nupGamma;
|
||||
private System.Windows.Forms.TextBox tbxColorHex;
|
||||
private System.Windows.Forms.PictureBox pbxSliderRed;
|
||||
private System.Windows.Forms.PictureBox pbxSliderSaturation;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.Timer tmrRefreshBars;
|
||||
private System.Windows.Forms.Timer tmrRefreshMain;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
/// file: ColorPicker.cs
|
||||
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
||||
/// Brief: Class that is controlling the color usage
|
||||
/// Version: 0.1.0
|
||||
/// Date: 06/08/2022
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Paint_2
|
||||
{
|
||||
public partial class ColorPicker : Form
|
||||
{
|
||||
public Color SelectedColor;
|
||||
public Point cursorLocation;
|
||||
public PaintForm main;
|
||||
public ColorPicker(PaintForm theMainForm)
|
||||
{
|
||||
InitializeComponent();
|
||||
main = theMainForm;
|
||||
}
|
||||
|
||||
private void ColorPicker_Load(object sender, EventArgs e)
|
||||
{
|
||||
SelectedColor = main.Project.GetCurrentToolColor(main.SelectedLayers);
|
||||
RefreshUi();
|
||||
}
|
||||
private Bitmap RefreshMap(Size size)
|
||||
{
|
||||
Bitmap map = new Bitmap(size.Width, size.Height);
|
||||
Graphics gr = Graphics.FromImage(map);
|
||||
for (int g = 0; g < size.Width; g += 1)
|
||||
{
|
||||
for (int b = 0; b < size.Height; b += 1)
|
||||
{
|
||||
map.SetPixel(g, b, Color.FromArgb(SelectedColor.A, SelectedColor.R, g, b));
|
||||
}
|
||||
}
|
||||
int cursorWidth = 15;
|
||||
gr.DrawEllipse(new Pen(Color.Black, 2), new Rectangle(new Point(SelectedColor.G - cursorWidth / 2, SelectedColor.B - cursorWidth / 2), new Size(cursorWidth, cursorWidth)));
|
||||
gr.FillEllipse(new SolidBrush(SelectedColor), new Rectangle(new Point(SelectedColor.G - cursorWidth / 2, SelectedColor.B - cursorWidth / 2), new Size(cursorWidth, cursorWidth)));
|
||||
return map;
|
||||
}
|
||||
private Bitmap RefreshRedLevel(Size size, bool vertical)
|
||||
{
|
||||
Bitmap map = new Bitmap(size.Width, size.Height);
|
||||
Graphics gr = Graphics.FromImage(map);
|
||||
for (int x = 0; x < size.Width; x += 1)
|
||||
{
|
||||
for (int y = 0; y < size.Height; y += 1)
|
||||
{
|
||||
if (vertical)
|
||||
{
|
||||
map.SetPixel(x, y, Color.FromArgb(SelectedColor.A, y, SelectedColor.G, SelectedColor.B));
|
||||
}
|
||||
else
|
||||
{
|
||||
map.SetPixel(x, y, Color.FromArgb(SelectedColor.A, x, SelectedColor.G, SelectedColor.B));
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle rect;
|
||||
if (vertical)
|
||||
{
|
||||
rect = new Rectangle(0, SelectedColor.R, size.Width / 20, size.Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
rect = new Rectangle(SelectedColor.R, 0, size.Width / 20, size.Height);
|
||||
}
|
||||
gr.FillRectangle(new SolidBrush(Color.FromArgb(214, 214, 214)), rect);
|
||||
gr.DrawRectangle(new Pen(Color.FromArgb(31, 31, 31)), rect);
|
||||
return map;
|
||||
}
|
||||
private Bitmap RefreshGammaLevel(Size size, bool vertical)
|
||||
{
|
||||
Bitmap map = new Bitmap(size.Width, size.Height);
|
||||
Graphics gr = Graphics.FromImage(map);
|
||||
for (int x = 0; x < size.Width; x++)
|
||||
{
|
||||
for (int y = 0; y < size.Height; y++)
|
||||
{
|
||||
if (vertical)
|
||||
{
|
||||
map.SetPixel(x, y, Color.FromArgb(y, y, y, y));
|
||||
}
|
||||
else
|
||||
{
|
||||
map.SetPixel(x, y, Color.FromArgb(x, x, x, x));
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle rect;
|
||||
if (vertical)
|
||||
{
|
||||
rect = new Rectangle(0, SelectedColor.A, size.Width, size.Height / 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
rect = new Rectangle(SelectedColor.A, 0, size.Width / 20, size.Height);
|
||||
}
|
||||
gr.FillRectangle(new SolidBrush(Color.FromArgb(214, 214, 214)), rect);
|
||||
gr.DrawRectangle(new Pen(Color.FromArgb(31, 31, 31)), rect);
|
||||
return map;
|
||||
}
|
||||
private Bitmap RefreshSelectedColorMap(Size size)
|
||||
{
|
||||
Bitmap bmp = new Bitmap(size.Width, size.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
gr.FillRectangle(new SolidBrush(SelectedColor), new Rectangle(0, 0, size.Width, size.Height));
|
||||
return bmp;
|
||||
}
|
||||
private void RefreshUi()
|
||||
{
|
||||
Color Scol = Color.FromArgb(SelectedColor.A, SelectedColor.R, SelectedColor.G, SelectedColor.B);
|
||||
|
||||
pbxColor.Image = RefreshMap(pbxColor.Size);
|
||||
pbxSliderRed.Image = RefreshRedLevel(pbxSliderRed.Size, false);
|
||||
pbxSliderSaturation.Image = RefreshGammaLevel(pbxSliderSaturation.Size, true);
|
||||
pbxSelectedColor.Image = RefreshSelectedColorMap(pbxSelectedColor.Size);
|
||||
|
||||
nupRed.Value = Scol.R;
|
||||
nupGreen.Value = Scol.G;
|
||||
nupBlue.Value = Scol.B;
|
||||
nupGamma.Value = Scol.A;
|
||||
|
||||
tbxColorHex.Text = ColorToHex(Scol);
|
||||
}
|
||||
|
||||
private void tbrRedLevel_Scroll(object sender, EventArgs e)
|
||||
{
|
||||
RefreshUi();
|
||||
}
|
||||
|
||||
private void pbxColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
cursorLocation = pbxColor.PointToClient(MousePosition);
|
||||
if (cursorLocation.X >= 0 && cursorLocation.X < 255 && cursorLocation.Y >= 0 && cursorLocation.Y < 255)
|
||||
{
|
||||
Color newColor = (pbxColor.Image as Bitmap).GetPixel(cursorLocation.X, cursorLocation.Y);
|
||||
if (newColor.R > 0 || newColor.R == 0 && SelectedColor.R < 5) //This is a bad way of fixing a bug where sometimes the mouse inputs are 0,0,0
|
||||
{
|
||||
SelectedColor = newColor;
|
||||
}
|
||||
RefreshUi();
|
||||
}
|
||||
}
|
||||
private void pbxSliderRed_Click(object sender, EventArgs e)
|
||||
{
|
||||
int mouseX = pbxSliderRed.PointToClient(MousePosition).X;
|
||||
if (mouseX >= 0 && mouseX < 255)
|
||||
{
|
||||
SelectedColor = Color.FromArgb(SelectedColor.A, mouseX, SelectedColor.G, SelectedColor.B);
|
||||
}
|
||||
RefreshUi();
|
||||
}
|
||||
private void pbxSliderSaturation_Click(object sender, EventArgs e)
|
||||
{
|
||||
int mouseY = pbxSliderSaturation.PointToClient(MousePosition).Y;
|
||||
if (mouseY >= 0 && mouseY <= 255)
|
||||
{
|
||||
SelectedColor = Color.FromArgb(mouseY, SelectedColor.R, SelectedColor.G, SelectedColor.B);
|
||||
}
|
||||
RefreshUi();
|
||||
}
|
||||
public static Color HexToColor(string rgb)
|
||||
{
|
||||
int toBase = 16;
|
||||
string raw = rgb;
|
||||
string cleaned = raw.Replace("#", String.Empty);
|
||||
Color result;
|
||||
if (cleaned.Length == 6)
|
||||
{
|
||||
try
|
||||
{
|
||||
int r = Convert.ToInt32(String.Concat(cleaned[0], cleaned[1]), toBase);
|
||||
int g = Convert.ToInt32(String.Concat(cleaned[2], cleaned[3]), toBase);
|
||||
int b = Convert.ToInt32(String.Concat(cleaned[4], cleaned[5]), toBase);
|
||||
result = Color.FromArgb(r, g, b);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
result = default;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = default;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static string ColorToHex(Color color)
|
||||
{
|
||||
int toBase = 16;
|
||||
string result = "#";
|
||||
|
||||
if (color.R < toBase)
|
||||
{
|
||||
result += "0";
|
||||
}
|
||||
result += Convert.ToString(color.R, toBase);
|
||||
if (color.G < toBase)
|
||||
{
|
||||
result += "0";
|
||||
}
|
||||
result += Convert.ToString(color.G, toBase);
|
||||
if (color.B < toBase)
|
||||
{
|
||||
result += "0";
|
||||
}
|
||||
result += Convert.ToString(color.B, toBase);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void nupValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
int tmpR = (int)nupRed.Value;
|
||||
int tmpG = (int)nupGreen.Value;
|
||||
int tmpB = (int)nupBlue.Value;
|
||||
int tmpA = (int)nupGamma.Value;
|
||||
|
||||
if (tmpR >= 0 && tmpR <= 255 && tmpG >= 0 && tmpG <= 255 && tmpB >= 0 && tmpB <= 255 && tmpA >= 0 && tmpA <= 255)
|
||||
{
|
||||
Color newColor = Color.FromArgb(tmpA, tmpR, tmpG, tmpB);
|
||||
if (SelectedColor != newColor)
|
||||
{
|
||||
SelectedColor = newColor;
|
||||
RefreshUi();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void tbxColorHex_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
Color tmp = HexToColor(tbxColorHex.Text);
|
||||
if (tmp != null)
|
||||
{
|
||||
if (SelectedColor != tmp)
|
||||
{
|
||||
SelectedColor = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ColorPicker_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
main.Project.ChangeColor(main.SelectedLayers, SelectedColor);
|
||||
}
|
||||
|
||||
private void tbxColorHex_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.Enter)
|
||||
{
|
||||
RefreshUi();
|
||||
}
|
||||
}
|
||||
|
||||
private void ColorPicker_Shown(object sender, EventArgs e)
|
||||
{
|
||||
RefreshUi();
|
||||
}
|
||||
|
||||
private void pbxSelectedColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
main.Project.ChangeColor(main.SelectedLayers, SelectedColor);
|
||||
}
|
||||
|
||||
private void tmrRefresh_Tick(object sender, EventArgs e)
|
||||
{
|
||||
pbxSliderSaturation_Click(sender, e);
|
||||
pbxSliderRed_Click(sender, e);
|
||||
}
|
||||
private void tmrRefreshMain_Tick(object sender, EventArgs e)
|
||||
{
|
||||
pbxColor_Click(sender, e);
|
||||
}
|
||||
|
||||
private void SliderMouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
tmrRefreshBars.Enabled = true;
|
||||
}
|
||||
|
||||
private void SliderMouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
tmrRefreshBars.Enabled = false;
|
||||
}
|
||||
|
||||
private void pbxColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
tmrRefreshMain.Enabled = true;
|
||||
}
|
||||
|
||||
private void pbxColor_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
tmrRefreshMain.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="tmrRefreshBars.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="tmrRefreshMain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>177, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
+83
-68
@@ -2,7 +2,8 @@
|
||||
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
||||
/// Brief: A variant of the default tool
|
||||
/// Version: 0.1.0
|
||||
/// Date: 25/05/2022
|
||||
/// Date: 17/06/2022
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -14,8 +15,14 @@ namespace Paint_2
|
||||
{
|
||||
public class DotPencil : PaintTool
|
||||
{
|
||||
const int POST_PROCESSING_PRECISION = 1;
|
||||
|
||||
private List<List<Point>> _drawings;
|
||||
private List<List<Point>> _drawingsRedo;
|
||||
private bool _needsFullRefresh;
|
||||
private bool _isShiftPressed;
|
||||
private bool _isCtrlPressed;
|
||||
private PaintToolUtils Utils;
|
||||
private List<Color> _colors;
|
||||
private List<Color> _colorsRedo;
|
||||
private List<int> _widths;
|
||||
@@ -26,6 +33,9 @@ namespace Paint_2
|
||||
|
||||
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
||||
public List<List<Point>> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; }
|
||||
public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; }
|
||||
public bool IsShiftPressed { get => _isShiftPressed; set => _isShiftPressed = value; }
|
||||
public bool IsCtrlPressed { get => _isCtrlPressed; set => _isCtrlPressed = value; }
|
||||
public List<Color> Colors { get => _colors; set => _colors = value; }
|
||||
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
||||
public List<int> Widths { get => _widths; set => _widths = value; }
|
||||
@@ -43,6 +53,9 @@ namespace Paint_2
|
||||
Widths = new List<int>();
|
||||
WidthsRedo = new List<int>();
|
||||
Name = name;
|
||||
NeedsFullRefresh = false;
|
||||
|
||||
Utils = new PaintToolUtils(this);
|
||||
}
|
||||
public void Add(Point point)
|
||||
{
|
||||
@@ -59,12 +72,8 @@ namespace Paint_2
|
||||
int pointCounter = 0;
|
||||
foreach (Point p in drawing)
|
||||
{
|
||||
if (pointCounter > 0)
|
||||
{
|
||||
pointSize = new Size(Widths[drawingCounter], Widths[drawingCounter]);
|
||||
gr.FillEllipse(new SolidBrush(Colors[drawingCounter]), new Rectangle(new Point(p.X - pointSize.Width / 2, p.Y - pointSize.Height / 2), pointSize));
|
||||
}
|
||||
|
||||
pointSize = new Size(Widths[drawingCounter], Widths[drawingCounter]);
|
||||
gr.FillEllipse(new SolidBrush(Colors[drawingCounter]), new Rectangle(new Point(p.X - pointSize.Width / 2, p.Y - pointSize.Height / 2), pointSize));
|
||||
pointCounter += 1;
|
||||
}
|
||||
drawingCounter += 1;
|
||||
@@ -72,49 +81,44 @@ namespace Paint_2
|
||||
}
|
||||
public void Start(Color color, int width)
|
||||
{
|
||||
Color = color;
|
||||
Width = width;
|
||||
List<Point> points = new List<Point>();
|
||||
Drawings.Add(points);
|
||||
Colors.Add(Color);
|
||||
Widths.Add(Width);
|
||||
Utils.StandartStart(color, width);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
Drawings = new List<List<Point>>();
|
||||
DrawingsRedo = new List<List<Point>>();
|
||||
Colors = new List<Color>();
|
||||
ColorsRedo = new List<Color>();
|
||||
Widths = new List<int>();
|
||||
WidthsRedo = new List<int>();
|
||||
Utils.StandartClear();
|
||||
}
|
||||
public void Stop(Point point)
|
||||
public void Stop()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
for (int i = 0; i < POST_PROCESSING_PRECISION; i++)
|
||||
{
|
||||
List<Point> Drawing = Drawings[Drawings.Count - 1];
|
||||
Drawings[Drawings.Count - 1] = PostProcessing(Drawing);
|
||||
}
|
||||
}
|
||||
private List<Point> PostProcessing(List<Point> Drawing)
|
||||
{
|
||||
//THIS SHOULD BE REMOVED, IT IS ONLY HERE TO BE EASIER TO DEBUG THE CONCEPT
|
||||
List<Point> NewDrawing = new List<Point>();
|
||||
Point previous = new Point(-1, -1);
|
||||
//Implementing a post processing
|
||||
foreach (Point point in Drawing)
|
||||
{
|
||||
if (previous != new Point(-1, -1))
|
||||
{
|
||||
NewDrawing.Add(new Point((previous.X + point.X) / 2, (previous.Y + point.Y) / 2));
|
||||
previous = point;
|
||||
}
|
||||
else
|
||||
{
|
||||
previous = point;
|
||||
}
|
||||
NewDrawing.Add(point);
|
||||
}
|
||||
return NewDrawing;
|
||||
}
|
||||
public List<Color> GetLastColors(int colorNumber)
|
||||
{
|
||||
List<Color> result = new List<Color>();
|
||||
if (Colors.Count <= colorNumber)
|
||||
{
|
||||
//We need to fill with black color
|
||||
for (int i = Colors.Count; i > 0; i--)
|
||||
{
|
||||
result.Add(Colors[(Colors.Count) - i]);
|
||||
}
|
||||
for (int i = colorNumber - Colors.Count; i > 0; i--)
|
||||
{
|
||||
result.Add(Color.FromArgb(0x00, 0x00, 0x00));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = colorNumber; i > 0; i--)
|
||||
{
|
||||
result.Add(Colors[(Colors.Count) - i]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return Utils.SandartGetLastColors(colorNumber);
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
@@ -123,38 +127,49 @@ namespace Paint_2
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
int last = Drawings.Count - 1;
|
||||
if (Drawings.Count > 1)
|
||||
{
|
||||
DrawingsRedo.Add(Drawings[last]);
|
||||
Drawings.RemoveAt(Drawings.Count - 1);
|
||||
ColorsRedo.Add(Colors[last]);
|
||||
Colors.RemoveAt(Colors.Count - 1);
|
||||
WidthsRedo.Add(Widths[last]);
|
||||
Widths.RemoveAt(Widths.Count - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawingsRedo.Add(Drawings[0]);
|
||||
Drawings.Clear();
|
||||
ColorsRedo.Add(Colors[0]);
|
||||
Colors.Clear();
|
||||
WidthsRedo.Add(Widths[0]);
|
||||
Widths.Clear();
|
||||
}
|
||||
Utils.StandartUndo();
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
if (DrawingsRedo.Count > 0 && WidthsRedo.Count > 0 && ColorsRedo.Count > 0)
|
||||
Utils.StandartRedo();
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
DotPencil result = new DotPencil(Name);
|
||||
result.Width = Width;
|
||||
result.Color = Color;
|
||||
return (Object)(result);
|
||||
}
|
||||
|
||||
public string PaintSVG()
|
||||
{
|
||||
string result = "";
|
||||
string newLine = Environment.NewLine;
|
||||
|
||||
for (int drawCount = 0; drawCount < Drawings.Count; drawCount++)
|
||||
{
|
||||
Drawings.Add(DrawingsRedo[DrawingsRedo.Count - 1]);
|
||||
DrawingsRedo.RemoveAt(DrawingsRedo.Count - 1);
|
||||
Colors.Add(ColorsRedo[ColorsRedo.Count - 1]);
|
||||
ColorsRedo.RemoveAt(ColorsRedo.Count - 1);
|
||||
Widths.Add(WidthsRedo[WidthsRedo.Count - 1]);
|
||||
WidthsRedo.RemoveAt(WidthsRedo.Count - 1);
|
||||
Point p1;
|
||||
Point p2;
|
||||
List<Point> drawing = Drawings[drawCount];
|
||||
Color color = Colors[drawCount];
|
||||
int width = Widths[drawCount];
|
||||
for (int pointIndex = 0; pointIndex < drawing.Count; pointIndex++)
|
||||
{
|
||||
if (pointIndex >= 1)
|
||||
{
|
||||
p1 = drawing[pointIndex - 1];
|
||||
p2 = drawing[pointIndex];
|
||||
|
||||
result += "<ellipse cx=\"" + p2.X + "\" cy=\"" + p2.Y + "\" rx=\"" + width / 2 + "\" ry=\"" + width / 2 + "\" style=\"fill:rgb(" + color.R + ", " + color.G + ", " + color.B + ");\"/>";
|
||||
result += newLine;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
/// file: EllipseBorderPencil.cs
|
||||
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
||||
/// Brief: A tool that paints the outline of an ellipse
|
||||
/// Version: 0.1.0
|
||||
/// Date: 17/06/2022
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Paint_2
|
||||
{
|
||||
internal class EllipseBorderPencil : PaintTool
|
||||
{
|
||||
private List<List<Point>> _drawings;
|
||||
private List<List<Point>> _drawingsRedo;
|
||||
private bool _needsFullRefresh;
|
||||
private bool _isShiftPressed;
|
||||
private bool _isCtrlPressed;
|
||||
private PaintToolUtils Utils;
|
||||
private List<Color> _colors;
|
||||
private List<Color> _colorsRedo;
|
||||
private List<int> _widths;
|
||||
private List<int> _widthsRedo;
|
||||
private Color _color;
|
||||
private string _name;
|
||||
private int _width;
|
||||
|
||||
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
||||
public List<List<Point>> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; }
|
||||
public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; }
|
||||
public List<Color> Colors { get => _colors; set => _colors = value; }
|
||||
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
||||
public List<int> Widths { get => _widths; set => _widths = value; }
|
||||
public List<int> WidthsRedo { get => _widthsRedo; set => _widthsRedo = value; }
|
||||
public bool IsShiftPressed { get => _isShiftPressed; set => _isShiftPressed = value; }
|
||||
public bool IsCtrlPressed { get => _isCtrlPressed; set => _isCtrlPressed = value; }
|
||||
public Color Color { get => _color; set => _color = value; }
|
||||
public string Name { get => _name; set => _name = value; }
|
||||
public int Width { get => _width; set => _width = value; }
|
||||
|
||||
public EllipseBorderPencil(string name)
|
||||
{
|
||||
NeedsFullRefresh = true;
|
||||
Drawings = new List<List<Point>>();
|
||||
DrawingsRedo = new List<List<Point>>();
|
||||
Colors = new List<Color>();
|
||||
ColorsRedo = new List<Color>();
|
||||
Widths = new List<int>();
|
||||
WidthsRedo = new List<int>();
|
||||
Name = name;
|
||||
Utils = new PaintToolUtils(this);
|
||||
}
|
||||
public void Add(Point point)
|
||||
{
|
||||
List<Point> myDrawing = Drawings[Drawings.Count - 1];
|
||||
if (myDrawing.Count == 0 || myDrawing.Count == 1)
|
||||
{
|
||||
myDrawing.Add(point);
|
||||
}
|
||||
else
|
||||
{
|
||||
myDrawing[1] = point;
|
||||
}
|
||||
Drawings[Drawings.Count - 1] = myDrawing;
|
||||
}
|
||||
public string PaintSVG()
|
||||
{
|
||||
string result = "";
|
||||
string newLine = Environment.NewLine;
|
||||
|
||||
int drawingCounter = 0;
|
||||
Size pointSize;
|
||||
|
||||
foreach (List<Point> drawing in Drawings)
|
||||
{
|
||||
if (drawing.Count == 2)
|
||||
{
|
||||
Point start = drawing[0];
|
||||
Point end = drawing[1];
|
||||
|
||||
List<Point> points;
|
||||
if (drawingCounter == Drawings.Count - 1)
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(false, drawing[0], drawing[1]);
|
||||
}
|
||||
|
||||
start = points[0];
|
||||
end = points[1];
|
||||
|
||||
Size size = new Size((end.X - start.X) / 2, (end.Y - start.Y) / 2);
|
||||
result += "<ellipse cx=\"" + (start.X + size.Width) + "\" cy=\"" + (start.Y + size.Height) + "\" rx=\"" + size.Width + "\" ry=\"" + size.Height + "\" style=\"stroke:rgb(" + Colors[drawingCounter].R + ", " + Colors[drawingCounter].G + ", " + Colors[drawingCounter].B + ");\" stroke-width=\"" + Widths[drawingCounter] + "\" fill=\"none\"/>";
|
||||
result += newLine;
|
||||
}
|
||||
drawingCounter++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public void Paint(Bitmap canvas)
|
||||
{
|
||||
Graphics gr = Graphics.FromImage(canvas);
|
||||
int drawingCounter = 0;
|
||||
foreach (List<Point> drawing in Drawings)
|
||||
{
|
||||
if (drawing.Count == 2)
|
||||
{
|
||||
Point start = drawing[0];
|
||||
Point end = drawing[1];
|
||||
|
||||
List<Point> points;
|
||||
if (drawingCounter == Drawings.Count - 1)
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(false, drawing[0], drawing[1]);
|
||||
}
|
||||
|
||||
start = points[0];
|
||||
end = points[1];
|
||||
|
||||
gr.DrawEllipse(new Pen(Colors[drawingCounter], Widths[drawingCounter]), new Rectangle(start, new Size(end.X - start.X, end.Y - start.Y)));
|
||||
}
|
||||
drawingCounter++;
|
||||
}
|
||||
}
|
||||
public void Start(Color color, int width)
|
||||
{
|
||||
Utils.StandartStart(color, width);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
Utils.StandartClear();
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
List<Point> myDrawing = Drawings.Last();
|
||||
Drawings[Drawings.Count - 1] = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, myDrawing[0], myDrawing[1]);
|
||||
}
|
||||
private Bitmap PostProcessing(List<Point> Drawing, Bitmap bmp, int width, Color color)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
public List<Color> GetLastColors(int colorNumber)
|
||||
{
|
||||
return Utils.SandartGetLastColors(colorNumber);
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
Utils.StandartUndo();
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
Utils.StandartRedo();
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
EllipseBorderPencil result = new EllipseBorderPencil(Name);
|
||||
result.Width = Width;
|
||||
result.Color = Color;
|
||||
return (Object)(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/// file: EllipsePencil.cs
|
||||
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
||||
/// Brief: A tool that paints an ellipse
|
||||
/// Version: 0.1.0
|
||||
/// Date: 17/06/2022
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Paint_2
|
||||
{
|
||||
internal class EllipsePencil : PaintTool
|
||||
{
|
||||
private List<List<Point>> _drawings;
|
||||
private List<List<Point>> _drawingsRedo;
|
||||
private bool _needsFullRefresh;
|
||||
private bool _isShiftPressed;
|
||||
private bool _isCtrlPressed;
|
||||
private PaintToolUtils Utils;
|
||||
private List<Color> _colors;
|
||||
private List<Color> _colorsRedo;
|
||||
private List<int> _widths;
|
||||
private List<int> _widthsRedo;
|
||||
private Color _color;
|
||||
private string _name;
|
||||
private int _width;
|
||||
|
||||
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
||||
public List<List<Point>> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; }
|
||||
public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; }
|
||||
public List<Color> Colors { get => _colors; set => _colors = value; }
|
||||
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
||||
public List<int> Widths { get => _widths; set => _widths = value; }
|
||||
public List<int> WidthsRedo { get => _widthsRedo; set => _widthsRedo = value; }
|
||||
public bool IsShiftPressed { get => _isShiftPressed; set => _isShiftPressed = value; }
|
||||
public bool IsCtrlPressed { get => _isCtrlPressed; set => _isCtrlPressed = value; }
|
||||
public Color Color { get => _color; set => _color = value; }
|
||||
public string Name { get => _name; set => _name = value; }
|
||||
public int Width { get => _width; set => _width = value; }
|
||||
|
||||
public EllipsePencil(string name)
|
||||
{
|
||||
NeedsFullRefresh = true;
|
||||
Drawings = new List<List<Point>>();
|
||||
DrawingsRedo = new List<List<Point>>();
|
||||
Colors = new List<Color>();
|
||||
ColorsRedo = new List<Color>();
|
||||
Widths = new List<int>();
|
||||
WidthsRedo = new List<int>();
|
||||
Name = name;
|
||||
Utils = new PaintToolUtils(this);
|
||||
}
|
||||
public void Add(Point point)
|
||||
{
|
||||
List<Point> myDrawing = Drawings[Drawings.Count - 1];
|
||||
if (myDrawing.Count == 0 || myDrawing.Count == 1)
|
||||
{
|
||||
myDrawing.Add(point);
|
||||
}
|
||||
else
|
||||
{
|
||||
myDrawing[1] = point;
|
||||
}
|
||||
Drawings[Drawings.Count - 1] = myDrawing;
|
||||
}
|
||||
public void Paint(Bitmap canvas)
|
||||
{
|
||||
Graphics gr = Graphics.FromImage(canvas);
|
||||
int drawingCounter = 0;
|
||||
Size pointSize;
|
||||
|
||||
foreach (List<Point> drawing in Drawings)
|
||||
{
|
||||
if (drawing.Count == 2)
|
||||
{
|
||||
Point start = drawing[0];
|
||||
Point end = drawing[1];
|
||||
|
||||
List<Point> points;
|
||||
if (drawingCounter == Drawings.Count - 1)
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(false, drawing[0], drawing[1]);
|
||||
}
|
||||
|
||||
start = points[0];
|
||||
end = points[1];
|
||||
|
||||
gr.FillEllipse(new SolidBrush(Colors[drawingCounter]), new Rectangle(start, new Size(end.X - start.X, end.Y - start.Y)));
|
||||
}
|
||||
drawingCounter++;
|
||||
}
|
||||
}
|
||||
public string PaintSVG()
|
||||
{
|
||||
string result = "";
|
||||
string newLine = Environment.NewLine;
|
||||
|
||||
int drawingCounter = 0;
|
||||
Size pointSize;
|
||||
|
||||
foreach (List<Point> drawing in Drawings)
|
||||
{
|
||||
if (drawing.Count == 2)
|
||||
{
|
||||
Point start = drawing[0];
|
||||
Point end = drawing[1];
|
||||
|
||||
List<Point> points;
|
||||
if (drawingCounter == Drawings.Count - 1)
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(false, drawing[0], drawing[1]);
|
||||
}
|
||||
|
||||
start = points[0];
|
||||
end = points[1];
|
||||
|
||||
Size size = new Size((end.X - start.X) / 2, (end.Y - start.Y) / 2);
|
||||
result += "<ellipse cx=\"" + (start.X + size.Width) + "\" cy=\"" + (start.Y + size.Height) + "\" rx=\"" + size.Width + "\" ry=\"" + size.Height + "\" style=\"fill:rgb(" + Colors[drawingCounter].R + ", " + Colors[drawingCounter].G + ", " + Colors[drawingCounter].B + ");\"/>";
|
||||
result += newLine;
|
||||
}
|
||||
drawingCounter++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public void Start(Color color, int width)
|
||||
{
|
||||
Utils.StandartStart(color, width);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
Utils.StandartClear();
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
List<Point> myDrawing = Drawings.Last();
|
||||
Drawings[Drawings.Count - 1] = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, myDrawing[0], myDrawing[1]);
|
||||
}
|
||||
private Bitmap PostProcessing(List<Point> Drawing, Bitmap bmp, int width, Color color)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
public List<Color> GetLastColors(int colorNumber)
|
||||
{
|
||||
return Utils.SandartGetLastColors(colorNumber);
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
Utils.StandartUndo();
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
Utils.StandartRedo();
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
EllipsePencil result = new EllipsePencil(Name);
|
||||
result.Width = Width;
|
||||
result.Color = Color;
|
||||
return (Object)(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+389
-381
File diff suppressed because it is too large
Load Diff
+420
-133
@@ -2,7 +2,8 @@
|
||||
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
||||
/// Brief: Class that is controlling the view
|
||||
/// Version: 0.1.0
|
||||
/// Date: 25/05/2022
|
||||
/// Date: 17/06/2022
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@@ -19,106 +20,241 @@ namespace Paint_2
|
||||
{
|
||||
public partial class PaintForm : Form
|
||||
{
|
||||
const int WINDOW_OFFSET = 10;
|
||||
const string DEFAULT_FILEPATH = "C:/Paint2/Drawings/";
|
||||
Sketch sketch;
|
||||
List<PaintTool> toolList;
|
||||
bool drawing = false;
|
||||
bool randomColor = false;
|
||||
Random rnd;
|
||||
Color hoveringColor;
|
||||
const int WINDOW_OFFSET = 15;
|
||||
//readonly Font FONT = new Font("Arial", fontSize);
|
||||
readonly Color FLAT_RED = Color.FromArgb(0xC6, 0x28, 0x28);
|
||||
readonly Color FLAT_GREEN = Color.FromArgb(0x00, 0x89, 0x7B);
|
||||
readonly Color FLAT_GREY1 = Color.FromArgb(0x59, 0x59, 0x59);
|
||||
|
||||
private Color _hoveringColor;
|
||||
private Project _project;
|
||||
private int _selectedLayer;
|
||||
private List<string> _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<string> SelectedLayers { get => _selectedLayers; set => _selectedLayers = value; }
|
||||
|
||||
public PaintForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
rnd = new Random();
|
||||
toolList = new List<PaintTool>();
|
||||
toolList.Add(new Pencil("Default Pencil"));
|
||||
toolList.Add(new DotPencil("Dotted Line"));
|
||||
sketch = new Sketch(new Size(canvas.Width, canvas.Height), toolList);
|
||||
tmrRefresh.Enabled = true;
|
||||
|
||||
Project = new Project("Untitled project", canvas.Size);
|
||||
SelectedLayers = new List<string>();
|
||||
SelectedLayers.Add(Project.GetAllLayers()[0].Id);
|
||||
this.KeyPreview = true;
|
||||
RefreshUi();
|
||||
}
|
||||
private Point MousePositionToCanvasPosition()
|
||||
{
|
||||
//return new Point(MousePosition.X - canvas.Location.X, MousePosition.Y - canvas.Location.Y);
|
||||
return canvas.PointToClient(MousePosition);
|
||||
}
|
||||
private void canvas_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
drawing = true;
|
||||
if (randomColor)
|
||||
{
|
||||
sketch.StartDrawing(MousePositionToCanvasPosition(), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), (int)nupPencilWidth.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
sketch.StartDrawing(MousePositionToCanvasPosition(), sketch.CurrentTool.Color, (int)nupPencilWidth.Value);
|
||||
}
|
||||
canvas.Focus();
|
||||
Color hoveringColor = GetHoverColor();
|
||||
Point mousePosition = MousePositionToCanvasPosition();
|
||||
int toolWidth = (int)nupPencilWidth.Value;
|
||||
Project.MouseDown(SelectedLayers, hoveringColor, mousePosition, toolWidth);
|
||||
RefreshUi();
|
||||
}
|
||||
private void canvas_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
sketch.AddDrawingPoint(MousePositionToCanvasPosition());
|
||||
drawing = false;
|
||||
Point mousePosition = MousePositionToCanvasPosition();
|
||||
Project.MouseUp(SelectedLayers, mousePosition);
|
||||
RefreshUi();
|
||||
}
|
||||
|
||||
private void tmrRefresh_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if (drawing)
|
||||
{
|
||||
sketch.AddDrawingPoint(MousePositionToCanvasPosition());
|
||||
}
|
||||
Point mousePosition = MousePositionToCanvasPosition();
|
||||
Project.TimerTick(SelectedLayers, mousePosition);
|
||||
RefreshUi();
|
||||
}
|
||||
private void BtnColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
Button button = sender as Button;
|
||||
sketch.ChangePaintToolColor(button.BackColor);
|
||||
Color newColor = (sender as Button).BackColor;
|
||||
Project.ChangeColor(SelectedLayers, newColor);
|
||||
tmrRefresh_Tick(sender, e);
|
||||
}
|
||||
private string ColorToString(Color color)
|
||||
{
|
||||
// Expected Hex:FFFFFF R:255 G:255 B:255
|
||||
string result = "";
|
||||
int toBase = 16;
|
||||
result += "Hex:" + Convert.ToString(color.R, toBase) + Convert.ToString(color.G, toBase) + Convert.ToString(color.B, toBase) + " ";
|
||||
result += "R:" + color.R + " G:" + color.G + " B:" + color.B;
|
||||
result += ColorPicker.ColorToHex(color);
|
||||
result += " ";
|
||||
result += "R:" + color.R + " G:" + color.G + " B:" + color.B + " A:" + color.A;
|
||||
return result;
|
||||
}
|
||||
private void ForceRefresh()
|
||||
{
|
||||
canvas.Image = sketch.ForcePaint();
|
||||
//canvas.Image = Project.ForcePaintAllLayers();
|
||||
canvas.Image = Project.ForcePaintLayers();
|
||||
RefreshUi();
|
||||
}
|
||||
private void RefreshUi()
|
||||
{
|
||||
canvas.Image = sketch.Paint();
|
||||
lblSelectedColor.Text = ColorToString(sketch.CurrentTool.Color);
|
||||
btnSelectedColor.BackColor = sketch.CurrentTool.Color;
|
||||
hoveringColor = GetHoverColor();
|
||||
lblHoveringColor.Text = ColorToString(hoveringColor);
|
||||
btnHoveringColor.BackColor = hoveringColor;
|
||||
lsbTools.DataSource = Project.AvaibleTools;
|
||||
DebugLabel1.Text = "";
|
||||
|
||||
List<Color> colorHistory = sketch.CurrentTool.GetLastColors(4);
|
||||
btnColorHistory1.BackColor = colorHistory[0];
|
||||
btnColorHistory2.BackColor = colorHistory[1];
|
||||
btnColorHistory3.BackColor = colorHistory[2];
|
||||
btnColorHistory4.BackColor = colorHistory[3];
|
||||
|
||||
lsbTools.DataSource = toolList;
|
||||
|
||||
lblWidth.Text = "Width: " + canvas.Width.ToString();
|
||||
lblHeight.Text = "Height: " + canvas.Height.ToString();
|
||||
|
||||
if (randomColor)
|
||||
PaintTool currentTool = Project.GetCurrentTool(SelectedLayers);
|
||||
if (currentTool != null && currentTool.NeedsFullRefresh)
|
||||
{
|
||||
btnRandomColor.ForeColor = Color.Green;
|
||||
canvas.Image = Project.ForcePaintLayers();
|
||||
}
|
||||
else
|
||||
{
|
||||
btnRandomColor.ForeColor = Color.Red;
|
||||
canvas.Image = Project.PaintLayers();
|
||||
}
|
||||
|
||||
|
||||
lblSelectedColor.Text = ColorToString(Project.GetCurrentToolColor(SelectedLayers));
|
||||
btnSelectedColor.BackColor = Project.GetCurrentToolColor(SelectedLayers);
|
||||
HoveringColor = GetHoverColor();
|
||||
lblHoveringColor.Text = ColorToString(HoveringColor);
|
||||
btnHoveringColor.BackColor = HoveringColor;
|
||||
|
||||
List<Color> colorHistory = Project.GetLayerColorHistory(SelectedLayers, 4);
|
||||
|
||||
btnColorHistory1.BackColor = colorHistory[0];
|
||||
btnColorHistory1.ForeColor = colorHistory[0];
|
||||
|
||||
btnColorHistory2.BackColor = colorHistory[1];
|
||||
btnColorHistory2.ForeColor = colorHistory[1];
|
||||
|
||||
btnColorHistory3.BackColor = colorHistory[2];
|
||||
btnColorHistory3.ForeColor = colorHistory[2];
|
||||
|
||||
btnColorHistory4.BackColor = colorHistory[3];
|
||||
btnColorHistory4.ForeColor = colorHistory[3];
|
||||
|
||||
lblWidth.Text = "W: " + canvas.Width.ToString();
|
||||
lblHeight.Text = "H: " + canvas.Height.ToString();
|
||||
|
||||
pbxSample.Image = DrawSample(pbxSample.Size);
|
||||
|
||||
DebugLabel1.Text = "Control";
|
||||
DebugLabel2.Text = "Shift";
|
||||
|
||||
if (Project.GetCurrentTool(SelectedLayers).IsCtrlPressed)
|
||||
{
|
||||
DebugLabel1.ForeColor = Color.Green;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugLabel1.ForeColor = Color.Red;
|
||||
}
|
||||
if (Project.GetCurrentTool(SelectedLayers).IsShiftPressed)
|
||||
{
|
||||
DebugLabel2.ForeColor = Color.Green;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugLabel2.ForeColor = Color.Red;
|
||||
}
|
||||
|
||||
if (Project.RandomColor)
|
||||
{
|
||||
btnRandomColor.BackColor = FLAT_GREEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
btnRandomColor.BackColor = FLAT_RED;
|
||||
}
|
||||
if (Project.Eyedropping)
|
||||
{
|
||||
btnEyeDrop.BackColor = FLAT_GREEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
btnEyeDrop.BackColor = FLAT_RED;
|
||||
}
|
||||
}
|
||||
private Bitmap DrawSample(Size size)
|
||||
{
|
||||
Bitmap map = new Bitmap(size.Width, size.Height);
|
||||
Graphics gr = Graphics.FromImage(map);
|
||||
|
||||
if (Project.GetCurrentTool(SelectedLayers) != null)
|
||||
{
|
||||
PaintTool currentTool = (PaintTool)Project.GetCurrentTool(SelectedLayers).Clone();
|
||||
Color paint_tool_color = Project.GetCurrentToolColor(SelectedLayers);
|
||||
int paint_tool_width = Project.GetCurrentToolWidth(SelectedLayers);
|
||||
|
||||
//Would have loved to use a switch case but I cant
|
||||
if (currentTool is Pencil)
|
||||
{
|
||||
Pencil pencil = currentTool as Pencil;
|
||||
pencil.Start(paint_tool_color, paint_tool_width);
|
||||
pencil.Add(new Point(0, size.Height));
|
||||
pencil.Add(new Point(size.Width, 0));
|
||||
pencil.Stop();
|
||||
pencil.Paint(map);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentTool is DotPencil)
|
||||
{
|
||||
DotPencil pencil = currentTool as DotPencil;
|
||||
pencil.Start(paint_tool_color, paint_tool_width);
|
||||
int precision = 5;
|
||||
for (int i = 0; i <= precision; i++)
|
||||
{
|
||||
Point newPoint = new Point(i * (size.Width / precision), size.Height - (i * (size.Height / precision)));
|
||||
pencil.Add(newPoint);
|
||||
}
|
||||
pencil.Stop();
|
||||
pencil.Paint(map);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentTool is BezierPencil)
|
||||
{
|
||||
BezierPencil pencil = currentTool as BezierPencil;
|
||||
|
||||
Point p1 = new Point(0 - paint_tool_width / 2, 0 - paint_tool_width / 2);
|
||||
Point p2 = new Point(0 - paint_tool_width / 2, size.Height + paint_tool_width / 2);
|
||||
Point p3 = new Point(size.Width / 2 - paint_tool_width / 2, size.Height + paint_tool_width / 2);
|
||||
Point p4 = new Point(size.Width / 2 - paint_tool_width / 2, 0 - paint_tool_width / 2);
|
||||
Point p5 = new Point(size.Width + paint_tool_width / 2, 0 - paint_tool_width / 2);
|
||||
Point p6 = new Point(size.Width + paint_tool_width / 2, size.Height + paint_tool_width / 2);
|
||||
// I KNOW THIS IS HARD CODED BUT ITS ONLY PURPOSE IS TO BE PRETTY so it does'nt matter
|
||||
pencil.Start(paint_tool_color, paint_tool_width);
|
||||
pencil.Add(p1);
|
||||
pencil.Stop();
|
||||
pencil.Start(paint_tool_color, paint_tool_width);
|
||||
pencil.Add(p2);
|
||||
pencil.Stop();
|
||||
pencil.Start(paint_tool_color, paint_tool_width);
|
||||
pencil.Add(p3);
|
||||
pencil.Stop();
|
||||
pencil.Start(paint_tool_color, paint_tool_width);
|
||||
pencil.Add(p4);
|
||||
pencil.Stop();
|
||||
pencil.Start(paint_tool_color, paint_tool_width);
|
||||
pencil.Add(p5);
|
||||
pencil.Stop();
|
||||
pencil.Start(paint_tool_color, paint_tool_width);
|
||||
pencil.Add(p6);
|
||||
pencil.Stop();
|
||||
pencil.Paint(map);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentTool is RectanglePencil || currentTool is RectangleBorderPencil || currentTool is EllipsePencil || currentTool is EllipseBorderPencil)
|
||||
{
|
||||
currentTool.Start(paint_tool_color, paint_tool_width);
|
||||
currentTool.Add(new Point(0 + size.Width / 10, 0 + size.Height / 10));
|
||||
currentTool.Add(new Point(size.Width - size.Width / 10, size.Height - size.Height / 10));
|
||||
currentTool.Stop();
|
||||
currentTool.Paint(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//gr.DrawLine(new Pen(Project.GetCurrentToolColor(SelectedLayers), Project.GetCurrentToolWidth(SelectedLayers)), new Point(0, 0), new Point(size.Width, size.Height));
|
||||
return map;
|
||||
}
|
||||
private Color GetHoverColor()
|
||||
{
|
||||
@@ -138,57 +274,14 @@ namespace Paint_2
|
||||
}
|
||||
private void btnClear_Click(object sender, EventArgs e)
|
||||
{
|
||||
sketch.Clear();
|
||||
Project.Clear();
|
||||
ForceRefresh();
|
||||
}
|
||||
|
||||
private void nupPencilWidth_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
sketch.ChangePaintToolWidth((int)nupPencilWidth.Value);
|
||||
}
|
||||
|
||||
private void btnSetColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
string value = tbxColorHex.Text;
|
||||
int fromBase = 16;
|
||||
value = value.Replace("#", String.Empty);
|
||||
int R, G, B;
|
||||
try
|
||||
{
|
||||
R = Convert.ToInt32(String.Concat(value[0], value[1]), fromBase);
|
||||
G = Convert.ToInt32(String.Concat(value[2], value[3]), fromBase);
|
||||
B = Convert.ToInt32(String.Concat(value[4], value[4]), fromBase);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MessageBox.Show("Please enter a valid hexadecimal value");
|
||||
tbxColorHex.Text = "#FFFFFF";
|
||||
R = 255;
|
||||
G = 255;
|
||||
B = 255;
|
||||
}
|
||||
sketch.ChangePaintToolColor(Color.FromArgb(R, G, B));
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
int R, G, B;
|
||||
R = (int)nupRed.Value;
|
||||
G = (int)nupGreen.Value;
|
||||
B = (int)nupBlue.Value;
|
||||
if (R > 255)
|
||||
{
|
||||
R = 255;
|
||||
}
|
||||
if (G > 255)
|
||||
{
|
||||
G = 25;
|
||||
}
|
||||
if (B > 255)
|
||||
{
|
||||
B = 255;
|
||||
}
|
||||
sketch.ChangePaintToolColor(Color.FromArgb(R, G, B));
|
||||
int newWidth = (int)nupPencilWidth.Value;
|
||||
Project.ChangeWidth(SelectedLayers, newWidth);
|
||||
}
|
||||
|
||||
private void btnSave_Click(object sender, EventArgs e)
|
||||
@@ -196,68 +289,262 @@ namespace Paint_2
|
||||
string fileName = tbxProjectName.Text;
|
||||
Bitmap image = (Bitmap)canvas.Image;
|
||||
|
||||
if (!Directory.Exists(DEFAULT_FILEPATH))
|
||||
{
|
||||
Directory.CreateDirectory(DEFAULT_FILEPATH);
|
||||
}
|
||||
if (!Directory.Exists(DEFAULT_FILEPATH + fileName))
|
||||
{
|
||||
Directory.CreateDirectory(DEFAULT_FILEPATH + fileName);
|
||||
}
|
||||
|
||||
image.Save(DEFAULT_FILEPATH + fileName + "/" + fileName + ".png", System.Drawing.Imaging.ImageFormat.Png);
|
||||
Project.Save(fileName, image);
|
||||
}
|
||||
|
||||
private void btnSaveCopy_Click(object sender, EventArgs e)
|
||||
{
|
||||
string fileName = tbxProjectName.Text;
|
||||
int version = 1;
|
||||
Bitmap image = (Bitmap)canvas.Image;
|
||||
|
||||
if (!Directory.Exists(DEFAULT_FILEPATH))
|
||||
{
|
||||
Directory.CreateDirectory(DEFAULT_FILEPATH);
|
||||
}
|
||||
if (!Directory.Exists(DEFAULT_FILEPATH + fileName))
|
||||
{
|
||||
Directory.CreateDirectory(DEFAULT_FILEPATH + fileName);
|
||||
}
|
||||
while (File.Exists(DEFAULT_FILEPATH + fileName + "/" + fileName + version + ".png"))
|
||||
{
|
||||
version += 1;
|
||||
}
|
||||
image.Save(DEFAULT_FILEPATH + fileName + "/" + fileName + version + ".png", System.Drawing.Imaging.ImageFormat.Png);
|
||||
Project.SaveCopy(fileName, image);
|
||||
}
|
||||
|
||||
private void lsbTools_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
sketch.ChangeTool(lsbTools.SelectedIndex);
|
||||
int toolId = lsbTools.SelectedIndex;
|
||||
Project.ChangeTool(SelectedLayers, toolId);
|
||||
//Yeah that is a little janky but I just want to refresh the tool
|
||||
nupPencilWidth_ValueChanged(sender, e);
|
||||
RefreshUi();
|
||||
}
|
||||
|
||||
private void PaintForm_Resize(object sender, EventArgs e)
|
||||
{
|
||||
canvas.Size = new Size(this.Width - (this.Width - panelTools.Location.X) - canvas.Location.X - WINDOW_OFFSET, this.Height - (this.Height - panelHoverColor.Location.Y) - WINDOW_OFFSET - (panelFile.Location.Y + panelFile.Height));
|
||||
sketch.Resize(canvas.Size);
|
||||
Project.Resize(canvas.Size);
|
||||
RefreshUi();
|
||||
}
|
||||
|
||||
private void btnRandomColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
randomColor = !randomColor;
|
||||
Project.SwitchRandom();
|
||||
RefreshUi();
|
||||
}
|
||||
private void btnEyeDrop_Click(object sender, EventArgs e)
|
||||
{
|
||||
Project.SwitchEyeDrop();
|
||||
RefreshUi();
|
||||
}
|
||||
|
||||
private void btnUndo_Click(object sender, EventArgs e)
|
||||
{
|
||||
sketch.Undo();
|
||||
Project.Undo(SelectedLayers);
|
||||
ForceRefresh();
|
||||
}
|
||||
|
||||
private void btnRedo_Click(object sender, EventArgs e)
|
||||
{
|
||||
sketch.Redo();
|
||||
Project.Redo(SelectedLayers);
|
||||
ForceRefresh();
|
||||
}
|
||||
|
||||
private void btnColorPicker_Click(object sender, EventArgs e)
|
||||
{
|
||||
ColorPicker cp = new ColorPicker(this);
|
||||
cp.Show();
|
||||
}
|
||||
|
||||
private void PaintForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
tmrRefresh.Enabled = true;
|
||||
DisplayLayers();
|
||||
}
|
||||
|
||||
private void btnLayerRemove_Click(object sender, EventArgs e)
|
||||
{
|
||||
int layersCount = SelectedLayers.Count;
|
||||
List<String> LayersToRemove = new List<string>();
|
||||
foreach (string layer in SelectedLayers)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
private void BtnAddLayer_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedLayers.Add(Project.AddLayer());
|
||||
DisplayLayers();
|
||||
RefreshUi();
|
||||
}
|
||||
private void DisplayLayers()
|
||||
{
|
||||
int Yoffset = 10;
|
||||
int Xoffset = 10;
|
||||
float fontSize = 10;
|
||||
Size blocSize = new Size(pnlLayers.Width, pnlLayers.Height / 6);
|
||||
int blocsCount = 0;
|
||||
int btnWidth = (int)(blocSize.Width / 2.7);
|
||||
int labelWidth = (int)(blocSize.Width / 3.0);
|
||||
int BtnXoffset = labelWidth;
|
||||
int ChkXOffset = BtnXoffset + btnWidth /*+ Xoffset*/;
|
||||
int ChkWidth = (int)(blocSize.Width / 6.0);
|
||||
|
||||
pnlLayers.Controls.Clear();
|
||||
|
||||
List<Sketch> layers = Project.GetAllLayers();
|
||||
|
||||
foreach (Sketch layer in layers)
|
||||
{
|
||||
//LABEL LAYER NAME
|
||||
Label lblName = new Label();
|
||||
//Style
|
||||
lblName.Name = "lblLayer" + layer.Id;
|
||||
lblName.Font = new Font("Arial", fontSize);
|
||||
lblName.AutoSize = false;
|
||||
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 VISIBILITY
|
||||
Button BtnVisbility = new Button();
|
||||
//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))
|
||||
{
|
||||
BtnVisbility.Text = "Visible";
|
||||
}
|
||||
else
|
||||
{
|
||||
BtnVisbility.Text = "Invisible";
|
||||
}
|
||||
BtnVisbility.Name = "ChkLayerVisible:" + layer.Id;
|
||||
BtnVisbility.Click += LayerSelection;
|
||||
pnlLayers.Controls.Add(BtnVisbility);
|
||||
//Behaviour
|
||||
|
||||
//BUTTON LAYER SELECTION
|
||||
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;
|
||||
if (SelectedLayers.Contains(layer.Id))
|
||||
{
|
||||
chk.BackColor = Color.Green;
|
||||
}
|
||||
else
|
||||
{
|
||||
chk.BackColor = Color.Red;
|
||||
}
|
||||
pnlLayers.Controls.Add(chk);
|
||||
//Behaviour
|
||||
|
||||
blocsCount++;
|
||||
}
|
||||
}
|
||||
private void LayerSelection(object sender, EventArgs e)
|
||||
{
|
||||
//We know that the button's name is ChkLayerVisible:... ... being the GUID of the layer
|
||||
Button btn = sender as Button;
|
||||
string rawId = btn.Name;
|
||||
string id = rawId.Replace("ChkLayerVisible:", String.Empty);
|
||||
Project.SwitchLayer(id);
|
||||
DisplayLayers();
|
||||
}
|
||||
private void LayerCheck(object sender, EventArgs e)
|
||||
{
|
||||
//We know that the button's name is ChkLayerSelected:... ... being the GUID of the layer
|
||||
Button btn = sender as Button;
|
||||
//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);
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedLayers.Add(id);
|
||||
}
|
||||
DisplayLayers();
|
||||
}
|
||||
|
||||
private void btnSvgExport_Click(object sender, EventArgs e)
|
||||
{
|
||||
FolderBrowserDialog fbd = new FolderBrowserDialog();
|
||||
fbd.Description = "Custom Description";
|
||||
|
||||
if (fbd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string SelectedPath = fbd.SelectedPath;
|
||||
|
||||
if (Project.SaveSvg(SelectedPath, tbxProjectName.Text))
|
||||
{
|
||||
MessageBox.Show("Svg saved at " + SelectedPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Ooops, could not save the SVG in " + SelectedPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PaintForm_KeyPress(object sender, KeyPressEventArgs e)
|
||||
{
|
||||
//empty for now
|
||||
}
|
||||
|
||||
private void PaintForm_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.ControlKey:
|
||||
Project.CtrlDown();
|
||||
break;
|
||||
case Keys.ShiftKey:
|
||||
Project.ShiftDown();
|
||||
break;
|
||||
default:
|
||||
//send the key to the tools
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void PaintForm_KeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.ControlKey:
|
||||
Project.CtrlUp();
|
||||
break;
|
||||
case Keys.ShiftKey:
|
||||
Project.ShiftUp();
|
||||
break;
|
||||
default:
|
||||
//send the key to the tools
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,4 +120,7 @@
|
||||
<metadata name="tmrRefresh.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>47</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -2,7 +2,8 @@
|
||||
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
||||
/// Brief: Interface that is here to define what is a paint tool
|
||||
/// Version: 0.1.0
|
||||
/// Date: 25/05/2022
|
||||
/// Date: 17/06/2022
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -12,7 +13,7 @@ using System.Drawing;
|
||||
|
||||
namespace Paint_2
|
||||
{
|
||||
internal interface PaintTool
|
||||
public interface PaintTool : ICloneable
|
||||
{
|
||||
List<List<Point>> Drawings { get; set; }
|
||||
List<List<Point>> DrawingsRedo { get; set; }
|
||||
@@ -21,17 +22,21 @@ namespace Paint_2
|
||||
Color Color { get; set; }
|
||||
List<int> Widths { get; set; }
|
||||
List<int> WidthsRedo { get; set; }
|
||||
bool NeedsFullRefresh { get; set; }
|
||||
int Width { get; set; }
|
||||
string Name { get; set; }
|
||||
bool IsCtrlPressed { get; set; }
|
||||
bool IsShiftPressed { get; set; }
|
||||
|
||||
void Start(Color color, int width);
|
||||
void Stop(Point point);
|
||||
void Stop();
|
||||
void Add(Point point);
|
||||
void Undo();
|
||||
void Redo();
|
||||
void Clear();
|
||||
List<Color> GetLastColors(int colorNumber);
|
||||
void Paint(Bitmap canvas);
|
||||
string PaintSVG();
|
||||
string ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
/// file: PaintToolUtils.cs
|
||||
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
||||
/// Brief: A class that groups all the frequently used by painttools methods
|
||||
/// Version: 0.1.0
|
||||
/// Date: 17/06/2022
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Paint_2
|
||||
{
|
||||
internal class PaintToolUtils
|
||||
{
|
||||
private PaintTool Target;
|
||||
private Color DEFAULT_COLOR = Color.FromArgb(59, 59, 59);
|
||||
public PaintToolUtils(PaintTool target)
|
||||
{
|
||||
Target = target;
|
||||
}
|
||||
public void StandartStart(Color color, int width)
|
||||
{
|
||||
Target.Color = color;
|
||||
Target.Width = width;
|
||||
List<Point> points = new List<Point>();
|
||||
Target.Drawings.Add(points);
|
||||
Target.Colors.Add(Target.Color);
|
||||
Target.Widths.Add(Target.Width);
|
||||
}
|
||||
public void StandartClear()
|
||||
{
|
||||
Target.Drawings = new List<List<Point>>();
|
||||
Target.DrawingsRedo = new List<List<Point>>();
|
||||
Target.Colors = new List<Color>();
|
||||
Target.ColorsRedo = new List<Color>();
|
||||
Target.Widths = new List<int>();
|
||||
Target.WidthsRedo = new List<int>();
|
||||
}
|
||||
public void StandartUndo()
|
||||
{
|
||||
int last = Target.Drawings.Count - 1;
|
||||
if (Target.Drawings.Count > 1 && Target.Widths.Count > 1 && Target.Colors.Count > 1)
|
||||
{
|
||||
Target.DrawingsRedo.Add(Target.Drawings[last]);
|
||||
Target.Drawings.RemoveAt(Target.Drawings.Count - 1);
|
||||
Target.ColorsRedo.Add(Target.Colors[last]);
|
||||
Target.Colors.RemoveAt(Target.Colors.Count - 1);
|
||||
Target.WidthsRedo.Add(Target.Widths[last]);
|
||||
Target.Widths.RemoveAt(Target.Widths.Count - 1);
|
||||
}
|
||||
else if (Target.Drawings.Count == 1 && Target.Widths.Count == 1 && Target.Colors.Count == 1)
|
||||
{
|
||||
Target.DrawingsRedo.Add(Target.Drawings[0]);
|
||||
Target.Drawings.Clear();
|
||||
Target.ColorsRedo.Add(Target.Colors[0]);
|
||||
Target.Colors.Clear();
|
||||
Target.WidthsRedo.Add(Target.Widths[0]);
|
||||
Target.Widths.Clear();
|
||||
}
|
||||
}
|
||||
public void StandartRedo()
|
||||
{
|
||||
if (Target.DrawingsRedo.Count > 0 && Target.WidthsRedo.Count > 0 && Target.ColorsRedo.Count > 0)
|
||||
{
|
||||
Target.Drawings.Add(Target.DrawingsRedo[Target.DrawingsRedo.Count - 1]);
|
||||
Target.DrawingsRedo.RemoveAt(Target.DrawingsRedo.Count - 1);
|
||||
Target.Colors.Add(Target.ColorsRedo[Target.ColorsRedo.Count - 1]);
|
||||
Target.ColorsRedo.RemoveAt(Target.ColorsRedo.Count - 1);
|
||||
Target.Widths.Add(Target.WidthsRedo[Target.WidthsRedo.Count - 1]);
|
||||
Target.WidthsRedo.RemoveAt(Target.WidthsRedo.Count - 1);
|
||||
}
|
||||
}
|
||||
public List<Color> SandartGetLastColors(int colorNumber)
|
||||
{
|
||||
List<Color> result = new List<Color>();
|
||||
//We need to fill with black color
|
||||
for (int i = Target.Colors.Count; i > 0; i--)
|
||||
{
|
||||
Color targetColor = Target.Colors[(Target.Colors.Count) - i];
|
||||
if (result.Count == 0 || result[result.Count - 1] != targetColor)
|
||||
{
|
||||
result.Add(targetColor);
|
||||
}
|
||||
}
|
||||
for (int i = colorNumber - result.Count; i > 0; i--)
|
||||
{
|
||||
result.Add(DEFAULT_COLOR);
|
||||
}
|
||||
result.Reverse();
|
||||
return result;
|
||||
}
|
||||
public List<Point> ConvertRectangleIntoPositive(bool IsCtrlPressed,Point start, Point end)
|
||||
{
|
||||
Point newStart = new Point(start.X, start.Y);
|
||||
Point newEnd = new Point(end.X, end.Y);
|
||||
|
||||
int xDiff = end.X - start.X;
|
||||
int yDiff = end.Y - start.Y;
|
||||
|
||||
Size size = new Size(xDiff, yDiff);
|
||||
|
||||
if (xDiff < 0)
|
||||
{
|
||||
newStart = new Point(end.X, newStart.Y);
|
||||
}
|
||||
if (yDiff < 0)
|
||||
{
|
||||
newStart = new Point(newStart.X, end.Y);
|
||||
}
|
||||
|
||||
if (IsCtrlPressed)
|
||||
{
|
||||
size = new Size(Math.Max(Math.Abs(xDiff), Math.Abs(yDiff)), Math.Max(Math.Abs(xDiff), Math.Abs(yDiff)));
|
||||
}
|
||||
|
||||
newEnd = new Point(newStart.X + Math.Abs(size.Width), newStart.Y + Math.Abs(size.Height));
|
||||
return new List<Point> { newStart, newEnd };
|
||||
}
|
||||
public Point Lerp(Point start, Point end, float t)
|
||||
{
|
||||
int xDiff = end.X - start.X;
|
||||
int yDiff = end.Y - start.Y;
|
||||
int resultX = start.X + (int)(t * xDiff);
|
||||
int resultY = start.Y + (int)(t * yDiff);
|
||||
Point result = new Point(resultX, resultY);
|
||||
return result;
|
||||
}
|
||||
public string StandartPaintSVG(List<List<Point>> Drawings,List<Color> Colors, List<int> Widths)
|
||||
{
|
||||
return "COUCOU";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,16 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BezierPencil.cs" />
|
||||
<Compile Include="ColorPicker.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ColorPicker.Designer.cs">
|
||||
<DependentUpon>ColorPicker.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="DotPencil.cs" />
|
||||
<Compile Include="EllipseBorderPencil.cs" />
|
||||
<Compile Include="EllipsePencil.cs" />
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@@ -54,10 +63,17 @@
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="PaintTool.cs" />
|
||||
<Compile Include="PaintToolUtils.cs" />
|
||||
<Compile Include="Pencil.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Project.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RectangleBorderPencil.cs" />
|
||||
<Compile Include="RectanglePencil.cs" />
|
||||
<Compile Include="Sketch.cs" />
|
||||
<EmbeddedResource Include="ColorPicker.resx">
|
||||
<DependentUpon>ColorPicker.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
||||
+70
-67
@@ -2,7 +2,8 @@
|
||||
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
||||
/// Brief: Paint tool that is kind of the default tool
|
||||
/// Version: 0.1.0
|
||||
/// Date: 25/05/2022
|
||||
/// Date: 17/06/2022
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
@@ -14,8 +15,14 @@ namespace Paint_2
|
||||
{
|
||||
public class Pencil : PaintTool
|
||||
{
|
||||
const int POST_PROCESSING_PRECISION = 3;
|
||||
|
||||
private List<List<Point>> _drawings;
|
||||
private List<List<Point>> _drawingsRedo;
|
||||
private PaintToolUtils Utils;
|
||||
private bool _needsFullRefresh;
|
||||
private bool _isShiftPressed;
|
||||
private bool _isCtrlPressed;
|
||||
private List<Color> _colors;
|
||||
private List<Color> _colorsRedo;
|
||||
private List<int> _widths;
|
||||
@@ -30,9 +37,12 @@ namespace Paint_2
|
||||
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
||||
public List<int> Widths { get => _widths; set => _widths = value; }
|
||||
public List<int> WidthsRedo { get => _widthsRedo; set => _widthsRedo = value; }
|
||||
public bool IsShiftPressed { get => _isShiftPressed; set => _isShiftPressed = value; }
|
||||
public bool IsCtrlPressed { get => _isCtrlPressed; set => _isCtrlPressed = value; }
|
||||
public Color Color { get => _color; set => _color = value; }
|
||||
public string Name { get => _name; set => _name = value; }
|
||||
public int Width { get => _width; set => _width = value; }
|
||||
public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; }
|
||||
|
||||
public Pencil(string name)
|
||||
{
|
||||
@@ -43,6 +53,8 @@ namespace Paint_2
|
||||
Widths = new List<int>();
|
||||
WidthsRedo = new List<int>();
|
||||
Name = name;
|
||||
Utils = new PaintToolUtils(this);
|
||||
NeedsFullRefresh = false;
|
||||
}
|
||||
public void Add(Point point)
|
||||
{
|
||||
@@ -59,63 +71,70 @@ namespace Paint_2
|
||||
int pointCounter = 0;
|
||||
foreach (Point p in drawing)
|
||||
{
|
||||
pointSize = new Size(Widths[drawingCounter], Widths[drawingCounter]);
|
||||
gr.FillEllipse(new SolidBrush(Colors[drawingCounter]), new Rectangle(new Point(p.X - pointSize.Width / 2, p.Y - pointSize.Height / 2), pointSize));
|
||||
if (pointCounter > 0)
|
||||
{
|
||||
pointSize = new Size(Widths[drawingCounter], Widths[drawingCounter]);
|
||||
gr.FillEllipse(new SolidBrush(Colors[drawingCounter]), new Rectangle(new Point(p.X - pointSize.Width / 2, p.Y - pointSize.Height / 2), pointSize));
|
||||
gr.DrawLine(new Pen(Colors[drawingCounter], Widths[drawingCounter]), drawing[pointCounter - 1], p);
|
||||
}
|
||||
|
||||
pointCounter += 1;
|
||||
}
|
||||
drawingCounter += 1;
|
||||
}
|
||||
}
|
||||
public string PaintSVG()
|
||||
{
|
||||
string result = "";
|
||||
string newLine = Environment.NewLine;
|
||||
|
||||
//foreach (List<Point> drawing in Drawings)
|
||||
for (int drawCount = 0; drawCount < Drawings.Count; drawCount++)
|
||||
{
|
||||
Point p1;
|
||||
Point p2;
|
||||
List<Point> drawing = Drawings[drawCount];
|
||||
Color color = Colors[drawCount];
|
||||
int width = Widths[drawCount];
|
||||
for (int pointIndex = 0; pointIndex < drawing.Count; pointIndex++)
|
||||
{
|
||||
if (pointIndex >= 1)
|
||||
{
|
||||
p1 = drawing[pointIndex - 1];
|
||||
p2 = drawing[pointIndex];
|
||||
|
||||
result += "<ellipse cx=\"" + p2.X + "\" cy=\"" + p2.Y + "\" rx=\"" + width/2 + "\" ry=\"" + width/2 + "\" style=\"fill:rgb(" + color.R + ", " + color.G + ", " + color.B + ");\"/>";
|
||||
result += newLine;
|
||||
result += "<line x1=\"" + p1.X + "\" y1=\"" + p1.Y + "\" x2=\"" + p2.X + "\" y2=\"" + p2.Y + "\" style=\"stroke: rgb(" + color.R + ", " + color.G + ", " + color.B + "); stroke-width:" + width + "\"/>";
|
||||
result += newLine;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
public void Start(Color color, int width)
|
||||
{
|
||||
Color = color;
|
||||
Width = width;
|
||||
List<Point> points = new List<Point>();
|
||||
Drawings.Add(points);
|
||||
Colors.Add(Color);
|
||||
Widths.Add(Width);
|
||||
Utils.StandartStart(color, width);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
Drawings = new List<List<Point>>();
|
||||
DrawingsRedo = new List<List<Point>>();
|
||||
Colors = new List<Color>();
|
||||
ColorsRedo = new List<Color>();
|
||||
Widths = new List<int>();
|
||||
WidthsRedo = new List<int>();
|
||||
Utils.StandartClear();
|
||||
}
|
||||
public void Stop(Point point)
|
||||
public void Stop()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
for (int i = 0; i < Drawings.Count; i++)
|
||||
{
|
||||
List<Point> Drawing = Drawings[i];
|
||||
}
|
||||
}
|
||||
private Bitmap PostProcessing(List<Point> Drawing, Bitmap bmp, int width, Color color)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
public List<Color> GetLastColors(int colorNumber)
|
||||
{
|
||||
List<Color> result = new List<Color>();
|
||||
if (Colors.Count <= colorNumber)
|
||||
{
|
||||
//We need to fill with black color
|
||||
for (int i = Colors.Count; i > 0; i--)
|
||||
{
|
||||
result.Add(Colors[(Colors.Count) - i]);
|
||||
}
|
||||
for (int i = colorNumber - Colors.Count; i > 0; i--)
|
||||
{
|
||||
result.Add(Color.FromArgb(0x00, 0x00, 0x00));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = colorNumber; i > 0; i--)
|
||||
{
|
||||
result.Add(Colors[(Colors.Count) - i]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return Utils.SandartGetLastColors(colorNumber);
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
@@ -124,38 +143,22 @@ namespace Paint_2
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
int last = Drawings.Count - 1;
|
||||
if (Drawings.Count > 1)
|
||||
{
|
||||
DrawingsRedo.Add(Drawings[last]);
|
||||
Drawings.RemoveAt(Drawings.Count - 1);
|
||||
ColorsRedo.Add(Colors[last]);
|
||||
Colors.RemoveAt(Colors.Count - 1);
|
||||
WidthsRedo.Add(Widths[last]);
|
||||
Widths.RemoveAt(Widths.Count - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawingsRedo.Add(Drawings[0]);
|
||||
Drawings.Clear();
|
||||
ColorsRedo.Add(Colors[0]);
|
||||
Colors.Clear();
|
||||
WidthsRedo.Add(Widths[0]);
|
||||
Widths.Clear();
|
||||
}
|
||||
Utils.StandartUndo();
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
if (DrawingsRedo.Count > 0 && WidthsRedo.Count > 0 && ColorsRedo.Count > 0)
|
||||
{
|
||||
Drawings.Add(DrawingsRedo[DrawingsRedo.Count - 1]);
|
||||
DrawingsRedo.RemoveAt(DrawingsRedo.Count - 1);
|
||||
Colors.Add(ColorsRedo[ColorsRedo.Count - 1]);
|
||||
ColorsRedo.RemoveAt(ColorsRedo.Count - 1);
|
||||
Widths.Add(WidthsRedo[WidthsRedo.Count - 1]);
|
||||
WidthsRedo.RemoveAt(WidthsRedo.Count - 1);
|
||||
}
|
||||
Utils.StandartRedo();
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
Pencil result = new Pencil(Name);
|
||||
result.Width = Width;
|
||||
result.Color = Color;
|
||||
return (Object)(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,485 @@
|
||||
/// file: Project.cs
|
||||
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
||||
/// Brief: A controller that manipulates that gives the view all the info it needs and controlls the layers and tools
|
||||
/// Version: 0.1.0
|
||||
/// Date: 17/06/2022
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace Paint_2
|
||||
{
|
||||
public class Project
|
||||
{
|
||||
const string DEFAULT_FILEPATH = "C:/Paint2/Drawings/";
|
||||
readonly Color DEFAULT_COLOR = Color.Firebrick;
|
||||
const int DEFAULT_WIDTH = 0;
|
||||
|
||||
private List<PaintTool> _avaibleTools;
|
||||
private List<string> _selectedLayers;
|
||||
private Guid uniqIdGenerator;
|
||||
private List<Sketch> _layers;
|
||||
private bool _eyedropping;
|
||||
private bool _randomColor;
|
||||
private Size _canvasSize;
|
||||
private Random _random;
|
||||
private bool _drawing;
|
||||
private string _name;
|
||||
|
||||
|
||||
public List<PaintTool> AvaibleTools { get => _avaibleTools; set => _avaibleTools = value; }
|
||||
//public Sketch CurrentLayer { get => _currentSketch; set => _currentSketch = value; }
|
||||
public List<Sketch> Layers { get => _layers; set => _layers = value; }
|
||||
public bool Eyedropping { get => _eyedropping; set => _eyedropping = value; }
|
||||
public bool RandomColor { get => _randomColor; set => _randomColor = value; }
|
||||
public Size CanvasSize { get => _canvasSize; set => _canvasSize = value; }
|
||||
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<string> LayersToPrint { get => _selectedLayers; set => _selectedLayers = value; }
|
||||
|
||||
public Project(string name, Size canvasSize)
|
||||
{
|
||||
Name = name;
|
||||
CanvasSize = canvasSize;
|
||||
Random = new Random();
|
||||
//We set all the avaible tools at first
|
||||
AvaibleTools = new List<PaintTool>();
|
||||
AvaibleTools.Add(new Pencil("Default Pencil"));
|
||||
AvaibleTools.Add(new DotPencil("Dotted Line"));
|
||||
AvaibleTools.Add(new BezierPencil("Bezier Generator"));
|
||||
AvaibleTools.Add(new RectanglePencil("Box tool"));
|
||||
AvaibleTools.Add(new RectangleBorderPencil("Rectangle tool"));
|
||||
AvaibleTools.Add(new EllipsePencil("Ball tool"));
|
||||
AvaibleTools.Add(new EllipseBorderPencil("Ellipse tool"));
|
||||
//We create a single first layer with the default toolSet
|
||||
|
||||
Layers = new List<Sketch>();
|
||||
LayersToPrint = new List<string>();
|
||||
|
||||
AddLayer();
|
||||
LayersToPrint.Add(Layers[0].Id);
|
||||
}
|
||||
public string AddLayer()
|
||||
{
|
||||
List<PaintTool> newTools = new List<PaintTool>();
|
||||
foreach (PaintTool tool in AvaibleTools)
|
||||
{
|
||||
newTools.Add((PaintTool)tool.Clone());
|
||||
}
|
||||
uniqIdGenerator = Guid.NewGuid();
|
||||
string test = 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)
|
||||
{
|
||||
Sketch layer = FindSketch(Layers, layerId);
|
||||
if (layer != null)
|
||||
{
|
||||
Layers.Remove(layer);
|
||||
RestoreLayerNames();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public Sketch FindSketch(List<Sketch> layers, string id)
|
||||
{
|
||||
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()
|
||||
{
|
||||
return Layers;
|
||||
}
|
||||
public void SwitchLayer(string idLayer)
|
||||
{
|
||||
bool present = IsSketchPresent(LayersToPrint,idLayer);
|
||||
if (present)
|
||||
{
|
||||
LayersToPrint.Remove(idLayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
LayersToPrint.Add(idLayer);
|
||||
}
|
||||
}
|
||||
public void MouseDown(List<string> selectedLayers, Color hoveringColor, Point mousePosition, int toolWidth)
|
||||
{
|
||||
foreach (string id in selectedLayers)
|
||||
{
|
||||
Sketch layer = FindSketch(Layers, id);
|
||||
if (layer != null)
|
||||
{
|
||||
if (Eyedropping)
|
||||
{
|
||||
Color pointedColor = hoveringColor;
|
||||
if (layer.CurrentTool.Color != pointedColor)
|
||||
{
|
||||
layer.ChangePaintToolColor(pointedColor);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Drawing = true;
|
||||
if (RandomColor)
|
||||
{
|
||||
layer.StartDrawing(mousePosition, Color.FromArgb(Random.Next(0, 256), Random.Next(0, 256), Random.Next(0, 256)), toolWidth);
|
||||
}
|
||||
else
|
||||
{
|
||||
layer.StartDrawing(mousePosition, layer.CurrentTool.Color, toolWidth);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
public void MouseUp(List<string> selectedLayers, Point mousePosition)
|
||||
{
|
||||
foreach (string id in selectedLayers)
|
||||
{
|
||||
Sketch layer = FindSketch(Layers, id);
|
||||
if (layer != null)
|
||||
{
|
||||
if (!Eyedropping)
|
||||
{
|
||||
layer.AddDrawingPoint(mousePosition);
|
||||
Drawing = false;
|
||||
layer.StopDrawing();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void TimerTick(List<string> selectedLayers, Point mousePosition)
|
||||
{
|
||||
foreach (string id in selectedLayers)
|
||||
{
|
||||
Sketch layer = FindSketch(Layers, id);
|
||||
if (layer != null)
|
||||
{
|
||||
if (Drawing)
|
||||
{
|
||||
layer.AddDrawingPoint(mousePosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public void ChangeColor(List<string> selectedLayers, Color newColor)
|
||||
{
|
||||
foreach (string id in selectedLayers)
|
||||
{
|
||||
Sketch layer = FindSketch(Layers, id);
|
||||
if (layer != null)
|
||||
{
|
||||
layer.ChangePaintToolColor(newColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void ChangeWidth(List<string> selectedLayers, int width)
|
||||
{
|
||||
foreach (string id in selectedLayers)
|
||||
{
|
||||
Sketch layer = FindSketch(Layers, id);
|
||||
if (layer != null)
|
||||
{
|
||||
layer.ChangePaintToolWidth(width);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void ChangeTool(List<string> selectedLayers, int toolId)
|
||||
{
|
||||
foreach (string id in selectedLayers)
|
||||
{
|
||||
Sketch layer = FindSketch(Layers, id);
|
||||
if (layer != null)
|
||||
{
|
||||
layer.ChangeTool(toolId);
|
||||
}
|
||||
}
|
||||
}
|
||||
public Bitmap ForcePaintAllLayers()
|
||||
{
|
||||
Bitmap result = new Bitmap(CanvasSize.Width, CanvasSize.Height);
|
||||
Graphics gr = Graphics.FromImage(result);
|
||||
foreach (Sketch layer in Layers)
|
||||
{
|
||||
gr.DrawImage(layer.ForcePaint(), Point.Empty);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public Bitmap ForcePaintLayers()
|
||||
{
|
||||
Bitmap result = new Bitmap(CanvasSize.Width, CanvasSize.Height);
|
||||
Graphics gr = Graphics.FromImage(result);
|
||||
foreach (string layerId in LayersToPrint)
|
||||
{
|
||||
Sketch layer = FindSketch(Layers, layerId);
|
||||
if (layer != null)
|
||||
{
|
||||
gr.DrawImage(layer.ForcePaint(), Point.Empty);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public Bitmap PaintAllLayers()
|
||||
{
|
||||
Bitmap result = new Bitmap(CanvasSize.Width, CanvasSize.Height);
|
||||
Graphics gr = Graphics.FromImage(result);
|
||||
foreach (Sketch layer in Layers)
|
||||
{
|
||||
gr.DrawImage(layer.Paint(), Point.Empty);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public Bitmap PaintLayers()
|
||||
{
|
||||
Bitmap result = null;
|
||||
if (CanvasSize.Width != 0 && CanvasSize.Height != 0)
|
||||
{
|
||||
result = new Bitmap(CanvasSize.Width, CanvasSize.Height);
|
||||
Graphics gr = Graphics.FromImage(result);
|
||||
foreach (string layerId in LayersToPrint)
|
||||
{
|
||||
Sketch layer = FindSketch(Layers, layerId);
|
||||
if (layer != null)
|
||||
{
|
||||
gr.DrawImage(layer.Paint(), Point.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
foreach (Sketch layer in Layers)
|
||||
{
|
||||
layer.Clear();
|
||||
}
|
||||
}
|
||||
public PaintTool GetCurrentTool(List<string> selectedLayers)
|
||||
{
|
||||
if (Layers.Count == 0 || selectedLayers.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Sketch CurrentLayer = FindSketch(Layers, selectedLayers[0]);
|
||||
return CurrentLayer.CurrentTool;
|
||||
}
|
||||
}
|
||||
public Color GetCurrentToolColor(List<string> selectedLayers)
|
||||
{
|
||||
if (Layers.Count == 0 || selectedLayers.Count == 0)
|
||||
{
|
||||
return DEFAULT_COLOR;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Sketch CurrentLayer = Layers[selectedLayers[0];
|
||||
Sketch CurrentLayer = FindSketch(Layers,selectedLayers[0]);
|
||||
return CurrentLayer.CurrentTool.Color;
|
||||
}
|
||||
}
|
||||
public int GetCurrentToolWidth(List<string> selectedLayers)
|
||||
{
|
||||
if (selectedLayers.Count == 0)
|
||||
{
|
||||
return DEFAULT_WIDTH;
|
||||
}
|
||||
Sketch CurrentLayer = FindSketch(Layers, selectedLayers[0]);
|
||||
return CurrentLayer.CurrentTool.Width;
|
||||
}
|
||||
public List<Color> GetLayerColorHistory(List<string> selectedLayers, int colorsCount)
|
||||
{
|
||||
if (selectedLayers.Count == 0)
|
||||
{
|
||||
List<Color> result = new List<Color>();
|
||||
for (int i = 0; i < colorsCount; i++)
|
||||
{
|
||||
result.Add(DEFAULT_COLOR);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Sketch CurrentLayer = FindSketch(Layers, selectedLayers[0]);
|
||||
return CurrentLayer.CurrentTool.GetLastColors(colorsCount);
|
||||
}
|
||||
public void Save(string fileName, Bitmap image)
|
||||
{
|
||||
if (!Directory.Exists(DEFAULT_FILEPATH))
|
||||
{
|
||||
Directory.CreateDirectory(DEFAULT_FILEPATH);
|
||||
}
|
||||
if (!Directory.Exists(DEFAULT_FILEPATH + fileName))
|
||||
{
|
||||
Directory.CreateDirectory(DEFAULT_FILEPATH + fileName);
|
||||
}
|
||||
image.Save(DEFAULT_FILEPATH + fileName + "/" + fileName + ".png", System.Drawing.Imaging.ImageFormat.Png);
|
||||
}
|
||||
public void SaveCopy(string fileName, Bitmap image)
|
||||
{
|
||||
int version = 1;
|
||||
if (!Directory.Exists(DEFAULT_FILEPATH))
|
||||
{
|
||||
Directory.CreateDirectory(DEFAULT_FILEPATH);
|
||||
}
|
||||
if (!Directory.Exists(DEFAULT_FILEPATH + fileName))
|
||||
{
|
||||
Directory.CreateDirectory(DEFAULT_FILEPATH + fileName);
|
||||
}
|
||||
while (File.Exists(DEFAULT_FILEPATH + fileName + "/" + fileName + version + ".png"))
|
||||
{
|
||||
version += 1;
|
||||
}
|
||||
image.Save(DEFAULT_FILEPATH + fileName + "/" + fileName + version + ".png", System.Drawing.Imaging.ImageFormat.Png);
|
||||
}
|
||||
public void Resize(Size newSize)
|
||||
{
|
||||
CanvasSize = newSize;
|
||||
foreach (Sketch layer in Layers)
|
||||
{
|
||||
layer.Resize(CanvasSize);
|
||||
}
|
||||
}
|
||||
public void SwitchRandom()
|
||||
{
|
||||
RandomColor = !RandomColor;
|
||||
}
|
||||
public void SwitchEyeDrop()
|
||||
{
|
||||
Eyedropping = !Eyedropping;
|
||||
}
|
||||
public void Undo(List<string> selectedLayers)
|
||||
{
|
||||
foreach (string id in selectedLayers)
|
||||
{
|
||||
Sketch layer = FindSketch(Layers, id);
|
||||
if (layer != null)
|
||||
{
|
||||
layer.Undo();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Redo(List<string> selectedLayers)
|
||||
{
|
||||
foreach (string id in selectedLayers)
|
||||
{
|
||||
Sketch layer = FindSketch(Layers, id);
|
||||
if (layer != null)
|
||||
{
|
||||
layer.Redo();
|
||||
}
|
||||
}
|
||||
}
|
||||
public string PrintAllLayers()
|
||||
{
|
||||
string result = "";
|
||||
foreach (Sketch layer in Layers)
|
||||
{
|
||||
result += layer.Name;
|
||||
result += Environment.NewLine;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public void CtrlDown()
|
||||
{
|
||||
foreach (Sketch layer in Layers)
|
||||
{
|
||||
layer.CtrlDown();
|
||||
}
|
||||
}
|
||||
public void CtrlUp()
|
||||
{
|
||||
foreach (Sketch layer in Layers)
|
||||
{
|
||||
layer.CtrlUp();
|
||||
}
|
||||
}
|
||||
public void ShiftDown()
|
||||
{
|
||||
foreach (Sketch layer in Layers)
|
||||
{
|
||||
layer.ShiftDown();
|
||||
}
|
||||
}
|
||||
public void ShiftUp()
|
||||
{
|
||||
foreach (Sketch layer in Layers)
|
||||
{
|
||||
layer.ShiftUp();
|
||||
}
|
||||
}
|
||||
public string ConvertToSVG()
|
||||
{
|
||||
string fileContent = "";
|
||||
string newLine = Environment.NewLine;
|
||||
|
||||
fileContent += "<svg version=\"1.1\" width=\"100%\" viewbox=\"0 0 "+CanvasSize.Width+" "+CanvasSize.Height+"\" xmlns = \"http://www.w3.org/2000/svg\">";
|
||||
fileContent += newLine;
|
||||
|
||||
foreach (Sketch layer in Layers)
|
||||
{
|
||||
fileContent += "<!-- "+layer.Name+" -->";
|
||||
fileContent += newLine;
|
||||
fileContent += layer.PaintSVG();
|
||||
}
|
||||
|
||||
fileContent += newLine;
|
||||
fileContent += "</svg>";
|
||||
return fileContent;
|
||||
}
|
||||
public bool SaveSvg(string path,string fileName)
|
||||
{
|
||||
bool result = false;
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
using (StreamWriter sw = File.CreateText(path + "\\" + fileName + ".svg"))
|
||||
{
|
||||
sw.WriteLine(ConvertToSVG());
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
/// file: RectangleBorderPencil.cs
|
||||
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
||||
/// Brief: A tool that paints the outline of a rectangle
|
||||
/// Version: 0.1.0
|
||||
/// Date: 17/06/2022
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Paint_2
|
||||
{
|
||||
internal class RectangleBorderPencil:PaintTool
|
||||
{
|
||||
private List<List<Point>> _drawings;
|
||||
private List<List<Point>> _drawingsRedo;
|
||||
private bool _needsFullRefresh;
|
||||
private bool _isShiftPressed;
|
||||
private bool _isCtrlPressed;
|
||||
private PaintToolUtils Utils;
|
||||
private List<Color> _colors;
|
||||
private List<Color> _colorsRedo;
|
||||
private List<int> _widths;
|
||||
private List<int> _widthsRedo;
|
||||
private Color _color;
|
||||
private string _name;
|
||||
private int _width;
|
||||
|
||||
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
||||
public List<List<Point>> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; }
|
||||
public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; }
|
||||
public List<Color> Colors { get => _colors; set => _colors = value; }
|
||||
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
||||
public List<int> Widths { get => _widths; set => _widths = value; }
|
||||
public List<int> WidthsRedo { get => _widthsRedo; set => _widthsRedo = value; }
|
||||
public bool IsShiftPressed { get => _isShiftPressed; set => _isShiftPressed = value; }
|
||||
public bool IsCtrlPressed { get => _isCtrlPressed; set => _isCtrlPressed = value; }
|
||||
public Color Color { get => _color; set => _color = value; }
|
||||
public string Name { get => _name; set => _name = value; }
|
||||
public int Width { get => _width; set => _width = value; }
|
||||
|
||||
public RectangleBorderPencil(string name)
|
||||
{
|
||||
NeedsFullRefresh = true;
|
||||
Drawings = new List<List<Point>>();
|
||||
DrawingsRedo = new List<List<Point>>();
|
||||
Colors = new List<Color>();
|
||||
ColorsRedo = new List<Color>();
|
||||
Widths = new List<int>();
|
||||
WidthsRedo = new List<int>();
|
||||
Name = name;
|
||||
Utils = new PaintToolUtils(this);
|
||||
}
|
||||
public void Add(Point point)
|
||||
{
|
||||
List<Point> myDrawing = Drawings[Drawings.Count - 1];
|
||||
if (myDrawing.Count == 0 || myDrawing.Count == 1)
|
||||
{
|
||||
myDrawing.Add(point);
|
||||
}
|
||||
else
|
||||
{
|
||||
myDrawing[1] = point;
|
||||
}
|
||||
Drawings[Drawings.Count - 1] = myDrawing;
|
||||
}
|
||||
public void Paint(Bitmap canvas)
|
||||
{
|
||||
Graphics gr = Graphics.FromImage(canvas);
|
||||
int drawingCounter = 0;
|
||||
Size pointSize;
|
||||
|
||||
foreach (List<Point> drawing in Drawings)
|
||||
{
|
||||
if (drawing.Count == 2)
|
||||
{
|
||||
Point start = drawing[0];
|
||||
Point end = drawing[1];
|
||||
|
||||
List<Point> points;
|
||||
if (drawingCounter == Drawings.Count - 1)
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(false, drawing[0], drawing[1]);
|
||||
}
|
||||
|
||||
start = points[0];
|
||||
end = points[1];
|
||||
|
||||
gr.DrawRectangle(new Pen(Colors[drawingCounter], Widths[drawingCounter]), new Rectangle(start, new Size(end.X - start.X, end.Y - start.Y)));
|
||||
}
|
||||
drawingCounter++;
|
||||
}
|
||||
}
|
||||
public string PaintSVG()
|
||||
{
|
||||
string result = "";
|
||||
string newLine = Environment.NewLine;
|
||||
|
||||
int drawingCounter = 0;
|
||||
Size pointSize;
|
||||
|
||||
foreach (List<Point> drawing in Drawings)
|
||||
{
|
||||
if (drawing.Count == 2)
|
||||
{
|
||||
Point start = drawing[0];
|
||||
Point end = drawing[1];
|
||||
|
||||
List<Point> points;
|
||||
if (drawingCounter == Drawings.Count - 1)
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(false, drawing[0], drawing[1]);
|
||||
}
|
||||
|
||||
result += "<rect x=\"" + start.X + "\" y=\"" + start.Y + "\" width=\"" + (end.X - start.X) + "\" height=\"" + (end.Y - start.Y) + "\" style=\"stroke:rgb(" + Colors[drawingCounter].R + ", " + Colors[drawingCounter].G + ", " + Colors[drawingCounter].B + ");\" stroke-width=\""+ Widths[drawingCounter]+"\" fill=\"none\"/>";
|
||||
result += newLine;
|
||||
}
|
||||
drawingCounter++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public void Start(Color color, int width)
|
||||
{
|
||||
Utils.StandartStart(color, width);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
Utils.StandartClear();
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
List<Point> myDrawing = Drawings.Last();
|
||||
Drawings[Drawings.Count - 1] = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, myDrawing[0], myDrawing[1]);
|
||||
}
|
||||
private Bitmap PostProcessing(List<Point> Drawing, Bitmap bmp, int width, Color color)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
public List<Color> GetLastColors(int colorNumber)
|
||||
{
|
||||
return Utils.SandartGetLastColors(colorNumber);
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
Utils.StandartUndo();
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
Utils.StandartRedo();
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
RectangleBorderPencil result = new RectangleBorderPencil(Name);
|
||||
result.Width = Width;
|
||||
result.Color = Color;
|
||||
return (Object)(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
/// file: RectanglePencil.cs
|
||||
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
||||
/// Brief: A tool that paints a Rectangle
|
||||
/// Version: 0.1.0
|
||||
/// Date: 17/06/2022
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Paint_2
|
||||
{
|
||||
internal class RectanglePencil:PaintTool
|
||||
{
|
||||
private List<List<Point>> _drawings;
|
||||
private List<List<Point>> _drawingsRedo;
|
||||
private bool _needsFullRefresh;
|
||||
private bool _isShiftPressed;
|
||||
private bool _isCtrlPressed;
|
||||
private PaintToolUtils Utils;
|
||||
private List<Color> _colors;
|
||||
private List<Color> _colorsRedo;
|
||||
private List<int> _widths;
|
||||
private List<int> _widthsRedo;
|
||||
private Color _color;
|
||||
private string _name;
|
||||
private int _width;
|
||||
|
||||
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
||||
public List<List<Point>> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; }
|
||||
public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; }
|
||||
public List<Color> Colors { get => _colors; set => _colors = value; }
|
||||
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
||||
public List<int> Widths { get => _widths; set => _widths = value; }
|
||||
public List<int> WidthsRedo { get => _widthsRedo; set => _widthsRedo = value; }
|
||||
public Color Color { get => _color; set => _color = value; }
|
||||
public string Name { get => _name; set => _name = value; }
|
||||
public int Width { get => _width; set => _width = value; }
|
||||
public bool IsShiftPressed { get => _isShiftPressed; set => _isShiftPressed = value; }
|
||||
public bool IsCtrlPressed { get => _isCtrlPressed; set => _isCtrlPressed = value; }
|
||||
|
||||
public RectanglePencil(string name)
|
||||
{
|
||||
NeedsFullRefresh = true;
|
||||
Drawings = new List<List<Point>>();
|
||||
DrawingsRedo = new List<List<Point>>();
|
||||
Colors = new List<Color>();
|
||||
ColorsRedo = new List<Color>();
|
||||
Widths = new List<int>();
|
||||
WidthsRedo = new List<int>();
|
||||
Name = name;
|
||||
Utils = new PaintToolUtils(this);
|
||||
}
|
||||
public void Add(Point point)
|
||||
{
|
||||
|
||||
List<Point> myDrawing = Drawings[Drawings.Count - 1];
|
||||
if (myDrawing.Count == 0 || myDrawing.Count == 1)
|
||||
{
|
||||
myDrawing.Add(point);
|
||||
}
|
||||
else
|
||||
{
|
||||
myDrawing[1] = point;
|
||||
}
|
||||
Drawings[Drawings.Count - 1] = myDrawing;
|
||||
}
|
||||
public void Paint(Bitmap canvas)
|
||||
{
|
||||
Graphics gr = Graphics.FromImage(canvas);
|
||||
int drawingCounter = 0;
|
||||
|
||||
foreach (List<Point> drawing in Drawings)
|
||||
{
|
||||
if (drawing.Count == 2)
|
||||
{
|
||||
List<Point> points;
|
||||
if (drawingCounter == Drawings.Count - 1)
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(false, drawing[0], drawing[1]);
|
||||
}
|
||||
gr.FillRectangle(new SolidBrush(Colors[drawingCounter]), new Rectangle(points[0], new Size(points[1].X - points[0].X, points[1].Y - points[0].Y)));
|
||||
}
|
||||
drawingCounter++;
|
||||
}
|
||||
}
|
||||
public string PaintSVG()
|
||||
{
|
||||
string result = "";
|
||||
string newLine = Environment.NewLine;
|
||||
|
||||
int drawingCounter = 0;
|
||||
|
||||
|
||||
foreach (List<Point> drawing in Drawings)
|
||||
{
|
||||
if (drawing.Count == 2)
|
||||
{
|
||||
List<Point> points;
|
||||
if (drawingCounter == Drawings.Count -1)
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
points = Utils.ConvertRectangleIntoPositive(false, drawing[0], drawing[1]);
|
||||
}
|
||||
Point start = points[0];
|
||||
Point end = points[1];
|
||||
result += "<rect x=\"" + start.X + "\" y=\"" + start.Y + "\" width=\"" + (end.X - start.X) + "\" height=\"" + (end.Y - start.Y) + "\" style=\"fill:rgb(" + Colors[drawingCounter].R + ", " + Colors[drawingCounter].G + ", " + Colors[drawingCounter].B + ");\"/>";
|
||||
result += newLine;
|
||||
}
|
||||
drawingCounter++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public void Start(Color color, int width)
|
||||
{
|
||||
Utils.StandartStart(color, width);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
Utils.StandartClear();
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
List<Point> myDrawing = Drawings.Last();
|
||||
Drawings[Drawings.Count - 1] = Utils.ConvertRectangleIntoPositive(IsCtrlPressed,myDrawing[0], myDrawing[1]);
|
||||
}
|
||||
private Bitmap PostProcessing(List<Point> Drawing, Bitmap bmp, int width, Color color)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
public List<Color> GetLastColors(int colorNumber)
|
||||
{
|
||||
return Utils.SandartGetLastColors(colorNumber);
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
Utils.StandartUndo();
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
Utils.StandartRedo();
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
RectanglePencil result = new RectanglePencil(Name);
|
||||
result.Width = Width;
|
||||
result.Color = Color;
|
||||
return (Object)(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
-8
@@ -1,8 +1,8 @@
|
||||
/// file: Sketch.cs
|
||||
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
||||
/// Brief: Class that is used to store and controll the tools and the bitmap
|
||||
/// Brief: This is a layer wich can controll a set of tools and is controlled by the Project
|
||||
/// Version: 0.1.0
|
||||
/// Date: 25/05/2022
|
||||
/// Date: 17/06/2022
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -13,13 +13,14 @@ using System.Drawing;
|
||||
|
||||
namespace Paint_2
|
||||
{
|
||||
internal class Sketch
|
||||
public class Sketch
|
||||
{
|
||||
List<PaintTool> _toolList;
|
||||
PaintTool _currentTool;
|
||||
bool _isDrawing;
|
||||
Bitmap _drawing;
|
||||
Size _sketchSize;
|
||||
string id;
|
||||
string _name;
|
||||
internal List<PaintTool> ToolList { get => _toolList; set => _toolList = value; }
|
||||
public PaintTool CurrentTool { get => _currentTool; set => _currentTool = value; }
|
||||
@@ -27,10 +28,13 @@ 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(Size sketchSize, List<PaintTool> toolList)
|
||||
public Sketch(string name, Size sketchSize, List<PaintTool> toolList, string guid)
|
||||
{
|
||||
IsDrawing = false;
|
||||
Id = guid;
|
||||
Name = name;
|
||||
SketchSize = sketchSize;
|
||||
Drawing = new Bitmap(SketchSize.Width, SketchSize.Height);
|
||||
ToolList = toolList;
|
||||
@@ -48,7 +52,7 @@ namespace Paint_2
|
||||
CurrentTool = null;
|
||||
}
|
||||
}
|
||||
public Sketch(List<PaintTool> toolList) : this(new Size(500, 500), toolList)
|
||||
public Sketch(List<PaintTool> toolList, string guid) : this("Layer 1", new Size(500, 500), toolList, guid)
|
||||
{
|
||||
//empty
|
||||
}
|
||||
@@ -68,7 +72,7 @@ namespace Paint_2
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Oooops...");
|
||||
Console.WriteLine("Oooops... " + ex);
|
||||
}
|
||||
}
|
||||
public void Undo()
|
||||
@@ -92,9 +96,9 @@ namespace Paint_2
|
||||
{
|
||||
CurrentTool.Start(CurrentTool.Color, width);
|
||||
}
|
||||
public void StopDrawing(Point location)
|
||||
public void StopDrawing()
|
||||
{
|
||||
CurrentTool.Stop(location);
|
||||
CurrentTool.Stop();
|
||||
}
|
||||
public void AddDrawingPoint(Point location)
|
||||
{
|
||||
@@ -112,6 +116,19 @@ namespace Paint_2
|
||||
CurrentTool.Paint(Drawing);
|
||||
return Drawing;
|
||||
}
|
||||
public string PaintSVG()
|
||||
{
|
||||
string result = "";
|
||||
string newLine = Environment.NewLine;
|
||||
|
||||
foreach (PaintTool tool in ToolList)
|
||||
{
|
||||
result += "<!-- " + tool.Name + " -->";
|
||||
result += newLine;
|
||||
result += tool.PaintSVG();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public Bitmap ForcePaint()
|
||||
{
|
||||
Drawing = new Bitmap(SketchSize.Width, SketchSize.Height);
|
||||
@@ -126,5 +143,31 @@ namespace Paint_2
|
||||
//Todo
|
||||
return Color.FromArgb(0x34, 0xF4, 0xFF);
|
||||
}
|
||||
public void CtrlDown()
|
||||
{
|
||||
if (!CurrentTool.IsCtrlPressed)
|
||||
{
|
||||
CurrentTool.IsCtrlPressed = true;
|
||||
}
|
||||
}
|
||||
public void CtrlUp()
|
||||
{
|
||||
CurrentTool.IsCtrlPressed = false;
|
||||
}
|
||||
public void ShiftDown()
|
||||
{
|
||||
if (!CurrentTool.IsShiftPressed)
|
||||
{
|
||||
CurrentTool.IsShiftPressed = true;
|
||||
}
|
||||
}
|
||||
public void ShiftUp()
|
||||
{
|
||||
CurrentTool.IsShiftPressed = false;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user