1
0

InitClear du canvas

This commit is contained in:
MarcEricMartel 2023-11-12 19:09:24 -05:00
parent 541b1668ba
commit f48a58c8a5
2 changed files with 8 additions and 4 deletions

View File

@ -1,7 +1,5 @@
namespace BlazorCanvas.Data;
// https://www.codeproject.com/Articles/5269947/Drawing-with-the-HTML-Canvas-Element-in-Blazor-Ser
public class CanvasCommand {
public double X { get; set; }
public double Y { get; set; }

View File

@ -11,6 +11,8 @@ using Microsoft.AspNetCore.Mvc.ApplicationModels;
namespace BlazorCanvas.Data;
// https://www.codeproject.com/Articles/5269947/Drawing-with-the-HTML-Canvas-Element-in-Blazor-Ser
public class CanvasService {
private Canvas2DContext? _currentCanvasContext;
private IJSRuntime _jsRuntime;
@ -29,8 +31,10 @@ public class CanvasService {
// TODO: Dessiner à partir des commandes de Franz.
public async void Draw(IEnumerable<CanvasCommand> lscommand) {
if (_currentCanvasContext is null)
if (_currentCanvasContext is null) {
_currentCanvasContext = await myCanvas.CreateCanvas2DAsync();
await _currentCanvasContext.ClearRectAsync(0, 0, 1920, 1080);
}
await _currentCanvasContext.BeginBatchAsync();
foreach (CanvasCommand command in lscommand) {
await _currentCanvasContext.SetFillStyleAsync(command.Color);
@ -40,8 +44,10 @@ public class CanvasService {
}
public async void Draw(CanvasCommand command) {
if (_currentCanvasContext is null)
if (_currentCanvasContext is null) {
_currentCanvasContext = await myCanvas.CreateCanvas2DAsync();
await _currentCanvasContext.ClearRectAsync(0, 0, 1920, 1080);
}
await _currentCanvasContext.SetFillStyleAsync(command.Color);
await _currentCanvasContext.FillRectAsync(command.X, command.Y, command.PointSize, command.PointSize);
}