Batches Brew.
This commit is contained in:
parent
6e87eed85b
commit
075a6b94e1
@ -5,6 +5,9 @@ using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using System.Drawing;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
||||
|
||||
namespace BlazorCanvas.Data;
|
||||
|
||||
@ -25,7 +28,26 @@ public class CanvasService {
|
||||
|
||||
// TODO: Dessiner à partir des commandes de Franz.
|
||||
|
||||
public async void OnMouseMove(MouseEventArgs eventArgs) {
|
||||
public async void Draw(IEnumerable<CanvasCommand> lscommand)
|
||||
{
|
||||
if (_currentCanvasContext is null)
|
||||
_currentCanvasContext = await myCanvas.CreateCanvas2DAsync();
|
||||
await _currentCanvasContext.BeginBatchAsync();
|
||||
foreach (CanvasCommand command in lscommand) {
|
||||
await _currentCanvasContext.SetFillStyleAsync(command.Color);
|
||||
await _currentCanvasContext.FillRectAsync(command.X, command.Y, command.PointSize, command.PointSize);
|
||||
}
|
||||
await _currentCanvasContext.EndBatchAsync();
|
||||
}
|
||||
|
||||
public async void Draw(CanvasCommand command) {
|
||||
if (_currentCanvasContext is null)
|
||||
_currentCanvasContext = await myCanvas.CreateCanvas2DAsync();
|
||||
await _currentCanvasContext.SetFillStyleAsync(command.Color);
|
||||
await _currentCanvasContext.FillRectAsync(command.X, command.Y, command.PointSize, command.PointSize);
|
||||
}
|
||||
|
||||
public async void HandleMouse(MouseEventArgs eventArgs) {
|
||||
double mouseX = 0, mouseY = 0;
|
||||
|
||||
if (eventArgs.Buttons == 0 || eventArgs.Buttons > 2)
|
||||
@ -42,8 +64,6 @@ public class CanvasService {
|
||||
mouseX = eventArgs.PageX - offsets.Value<double>("offsetLeft");
|
||||
mouseY = eventArgs.PageY - offsets.Value<double>("offsetTop");
|
||||
}
|
||||
if (_currentCanvasContext is null)
|
||||
_currentCanvasContext = await myCanvas.CreateCanvas2DAsync();
|
||||
|
||||
if (eventArgs.Buttons == 1) // Couleur si bouton gauche, blanc si bouton droit
|
||||
color = currentColor;
|
||||
@ -63,8 +83,7 @@ public class CanvasService {
|
||||
|
||||
// TODO: Shipper les commandes à Franz.
|
||||
|
||||
await _currentCanvasContext.SetFillStyleAsync(color);
|
||||
await _currentCanvasContext.FillRectAsync(mouseX, mouseY, pointSize, pointSize);
|
||||
Draw(command);
|
||||
|
||||
_lastCommand = command;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@
|
||||
<label>Magnétisme: </label>
|
||||
<input type="checkbox" @bind="@canvasService.snap"/>
|
||||
</header>
|
||||
<div @ref="canvasService.divCanvas" @onmousedown="canvasService.OnMouseMove" @onmousemove="canvasService.OnMouseMove" style="border:1px dotted #000000;">
|
||||
<div @ref="canvasService.divCanvas" @onmousedown="canvasService.HandleMouse" @onmousemove="canvasService.HandleMouse" style="border:1px dotted #000000;">
|
||||
<BECanvas @ref="canvasService.myCanvas" Height="1080" Width="1920"></BECanvas>
|
||||
</div>
|
||||
<footer>
|
||||
|
Loading…
Reference in New Issue
Block a user