174 lines
4.9 KiB
C#
174 lines
4.9 KiB
C#
/// file: Sketch.cs
|
|
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
|
/// Brief: This is a layer wich can controll a set of tools and is controlled by the Project
|
|
/// 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
|
|
{
|
|
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; }
|
|
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 string Id { get => id; set => id = value; }
|
|
|
|
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;
|
|
if (toolList[0] != null)
|
|
{
|
|
//Setup default Color
|
|
foreach (PaintTool tool in toolList)
|
|
{
|
|
tool.Color = Color.White;
|
|
}
|
|
CurrentTool = toolList[0];
|
|
}
|
|
else
|
|
{
|
|
CurrentTool = null;
|
|
}
|
|
}
|
|
public Sketch(List<PaintTool> toolList, string guid) : this("Layer 1", new Size(500, 500), toolList, guid)
|
|
{
|
|
//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... " + ex);
|
|
}
|
|
}
|
|
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()
|
|
{
|
|
CurrentTool.Stop();
|
|
}
|
|
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 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);
|
|
foreach (PaintTool tool in ToolList)
|
|
{
|
|
tool.Paint(Drawing);
|
|
}
|
|
return Drawing;
|
|
}
|
|
public Color GetColor(Point location)
|
|
{
|
|
//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;
|
|
}
|
|
}
|
|
}
|