Ready, Francis?
This commit is contained in:
parent
93450a9f49
commit
279247905c
@ -14,7 +14,6 @@ namespace BlazorCanvas.Server.Components.Data;
|
||||
|
||||
public class CanvasService {
|
||||
private Canvas2DContext? _currentCanvasContext;
|
||||
private IJSRuntime _jsRuntime;
|
||||
private IRedisService _redisService;
|
||||
private CanvasCommand _lastCommand = new();
|
||||
private List<CanvasCommand> _lsComms = new();
|
||||
@ -22,8 +21,7 @@ public class CanvasService {
|
||||
_is_started = false,
|
||||
_has_ended = false;
|
||||
|
||||
public CanvasService(IJSRuntime jsRuntime, IRedisService redisService) {
|
||||
_jsRuntime = jsRuntime;
|
||||
public CanvasService(IRedisService redisService) {
|
||||
_redisService = redisService;
|
||||
}
|
||||
|
||||
@ -59,7 +57,6 @@ public class CanvasService {
|
||||
Draw(_lsComms[0]);
|
||||
else if (_lsComms.Count > 0)
|
||||
Draw(_lsComms);
|
||||
Task.Delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +78,9 @@ public class CanvasService {
|
||||
await _currentCanvasContext.SetFillStyleAsync(command.Color);
|
||||
await _currentCanvasContext.FillRectAsync(command.X, command.Y, command.PointSize, command.PointSize);
|
||||
}
|
||||
await _currentCanvasContext.EndBatchAsync();
|
||||
try {
|
||||
await _currentCanvasContext.EndBatchAsync();
|
||||
} catch { } // HAHAHAHA ÇA MARCHE.
|
||||
}
|
||||
|
||||
public async void Draw(CanvasCommand command) {
|
||||
@ -115,16 +114,11 @@ public class CanvasService {
|
||||
return; // Rien faire si aucun bouton est appuyé ou si les deux boutons/ d'autres boutons sont appuyés.
|
||||
|
||||
if (divCanvas.Id?.Length > 0) {
|
||||
string data = await _jsRuntime.InvokeAsync<string>("getDivCanvasOffsets",
|
||||
new object[] { divCanvas });
|
||||
string color = "White";
|
||||
CanvasCommand command = new();
|
||||
JObject? offsets = (JObject?)JsonConvert.DeserializeObject(data);
|
||||
|
||||
if (offsets is not null && offsets.HasValues) { // Translation entre le canvas et la souris.
|
||||
mouseX = eventArgs.PageX - offsets.Value<double>("offsetLeft");
|
||||
mouseY = eventArgs.PageY - offsets.Value<double>("offsetTop");
|
||||
}
|
||||
mouseX = eventArgs.OffsetX - (pointSize / 2);
|
||||
mouseY = eventArgs.OffsetY - (pointSize / 2);
|
||||
|
||||
if (eventArgs.Buttons == 1) // Couleur si bouton gauche, blanc si bouton droit
|
||||
color = currentColor;
|
||||
|
Loading…
Reference in New Issue
Block a user