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