Files
Paint2/Paint_2/Sketch.cs

126 lines
3.5 KiB
C#

/// file: Sketch.cs
/// Author: Maxime Rohmer <maxluligames@gmail.com>
/// Brief: Class that is used to store and controll the tools and the bitmap
/// Version: 0.1.0
/// Date: 25/05/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 Sketch
{
List<PaintTool> _toolList;
PaintTool _currentTool;
bool _isDrawing;
Bitmap _drawing;
Size _sketchSize;
string _name;
internal List<PaintTool> ToolList { get => _toolList; set => _toolList = value; }
public PaintTool CurrentTool { get => _currentTool; set => _currentTool = value; }
public bool IsDrawing { get => _isDrawing; set => _isDrawing = value; }
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 Sketch(Size sketchSize, List<PaintTool> toolList)
{
IsDrawing = false;
SketchSize = sketchSize;
Drawing = new Bitmap(SketchSize.Width, SketchSize.Height);
ToolList = toolList;
if (toolList[0] != null)
{
CurrentTool = toolList[0];
}
else
{
CurrentTool = null;
}
}
public Sketch(List<PaintTool> toolList) : this(new Size(500, 500), toolList)
{
//empty
}
public void Resize(Size newSize)
{
if (newSize.Width > 0 && newSize.Height > 0)
{
Drawing = new Bitmap(newSize.Width, newSize.Height);
SketchSize = newSize;
}
}
public void ChangeTool(int toolId)
{
try
{
CurrentTool = ToolList[toolId];
}
catch (Exception ex)
{
Console.WriteLine("Oooops...");
}
}
public void Undo()
{
CurrentTool.Undo();
}
public void Redo()
{
CurrentTool.Redo();
}
public void StartDrawing(Point location, Color color, int width)
{
CurrentTool.Start(color, width);
CurrentTool.Add(location);
}
public void ChangePaintToolColor(Color color)
{
CurrentTool.Start(color, CurrentTool.Width);
}
public void ChangePaintToolWidth(int width)
{
CurrentTool.Start(CurrentTool.Color, width);
}
public void StopDrawing(Point location)
{
CurrentTool.Stop(location);
}
public void AddDrawingPoint(Point location)
{
CurrentTool.Add(location);
}
public void Clear()
{
foreach (PaintTool tool in ToolList)
{
tool.Clear();
}
}
public Bitmap Paint()
{
CurrentTool.Paint(Drawing);
return Drawing;
}
public Bitmap ForcePaint()
{
Drawing = new Bitmap(SketchSize.Width, SketchSize.Height);
foreach (PaintTool tool in ToolList)
{
tool.Paint(Drawing);
}
return Drawing;
}
public Color GetColor(Point location)
{
//Todo
return Color.FromArgb(0x34, 0xF4, 0xFF);
}
}
}