refactor: transformation de dupliqué en fonction

This commit is contained in:
Emi Boucly 2025-03-27 10:13:28 +01:00
parent a464760998
commit f923dba578

View file

@ -371,16 +371,18 @@ public class DrawController implements Initializable {
private void printLine(MouseEvent mouseEvent) { private void printLine(MouseEvent mouseEvent) {
Canvas currentLayer = layerListView.getSelectionModel().getSelectedItem(); Canvas currentLayer = layerListView.getSelectionModel().getSelectedItem();
GraphicsContext gc = currentLayer.getGraphicsContext2D();
if (posX == 0 || posY == 0) {
posX = mouseEvent.getX();
posY = mouseEvent.getY();
}
Stroke stroke = new Stroke(posX, posY, mouseEvent.getX(), mouseEvent.getY(), brushSizeSlider.getValue(), colorPicker.getValue());
strokes.add(stroke);
if (mouseEvent.isPrimaryButtonDown()) { if (mouseEvent.isPrimaryButtonDown()) {
GraphicsContext gc = currentLayer.getGraphicsContext2D();
if (posX == 0 || posY == 0) {
posX = mouseEvent.getX();
posY = mouseEvent.getY();
}
Stroke stroke = new Stroke(posX, posY, mouseEvent.getX(), mouseEvent.getY(), brushSizeSlider.getValue(), colorPicker.getValue());
strokes.add(stroke);
stroke.draw(gc, colorPicker.getValue()); stroke.draw(gc, colorPicker.getValue());
posX = mouseEvent.getX(); posX = mouseEvent.getX();
@ -388,15 +390,6 @@ public class DrawController implements Initializable {
} else if (mouseEvent.isSecondaryButtonDown()) { } else if (mouseEvent.isSecondaryButtonDown()) {
GraphicsContext gc = currentLayer.getGraphicsContext2D();
if (posX == 0 || posY == 0) {
posX = mouseEvent.getX();
posY = mouseEvent.getY();
}
Stroke stroke = new Stroke(posX, posY, mouseEvent.getX(), mouseEvent.getY(), brushSizeSlider.getValue(), colorPicker.getValue());
strokes.add(stroke);
stroke.draw(gc, Color.WHITE); stroke.draw(gc, Color.WHITE);
posX = mouseEvent.getX(); posX = mouseEvent.getX();
@ -447,11 +440,7 @@ public class DrawController implements Initializable {
lines.sort(new Comparator<Line>() { lines.sort(new Comparator<Line>() {
@Override @Override
public int compare(Line o1, Line o2) { public int compare(Line o1, Line o2) {
if (o1.getTimestamp() < o2.getTimestamp()) { return Integer.compare(o2.getTimestamp(), o1.getTimestamp());
return 1;
} else {
return 0;
}
} }
}); });
for (Line line: lines) { for (Line line: lines) {