diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintOnionCanvas.java b/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintOnionCanvas.java index e5fd319..1e252c5 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintOnionCanvas.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintOnionCanvas.java @@ -12,6 +12,7 @@ import androidx.annotation.Nullable; import androidx.lifecycle.ViewModelProvider; +import org.ntlab.acanthus_client.entities.Pen; import org.ntlab.acanthus_client.entities.Position; import org.ntlab.acanthus_client.entities.Stroke; import org.ntlab.acanthus_client.views.paint.page.PageViewModel; @@ -21,14 +22,17 @@ import java.util.ConcurrentModificationException; import java.util.List; + public class PaintOnionCanvas extends View { //----------------------------------------------------------------- - private Path path = new Path(); - private Paint paint = new Paint(); private PaintViewModel paintViewModel; //----------------------------------------------------------------- + private ArrayList paths = new ArrayList<>(); + private ArrayList paints = new ArrayList<>(); + + //----------------------------------------------------------------- //----------------------------------------------------------------- public PaintOnionCanvas(Context context, @Nullable AttributeSet attrs) { super(context, attrs); @@ -38,11 +42,6 @@ // public void init(PaintViewModel paintViewModel) { this.paintViewModel = paintViewModel; - - paint.setColor(Color.argb(40, 255, 0, 0)); - paint.setStyle(Paint.Style.STROKE); - paint.setStrokeWidth(20); - invalidate(); } @@ -50,7 +49,13 @@ @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); - canvas.drawPath(path, paint); + for (int i = 0; i < paths.size(); i++) { + try { + canvas.drawPath(paths.get(i), paints.get(i)); + } catch (IndexOutOfBoundsException ex) { + } + } + //----------------------------------------------------------------- } //----------------------------------------------------------------- @@ -61,12 +66,21 @@ clearCanvas(); for (Stroke s : paintViewModel.getPreStrokes().getValue()) { + + Paint paint = new Paint(); + paint.setColor(Color.argb(Color.alpha(s.getColor()) / 4, Color.red(s.getColor()), Color.green(s.getColor()), Color.blue(s.getColor())));//色の指定 + paint.setStrokeWidth(s.getThickness()); + paint.setStyle(Paint.Style.STROKE); + + paints.add(paint); + paths.add(new Path()); + for (Position p : s.getPositions()) { if (cnt == 0) { - path.moveTo(p.getX(), p.getY()); + paths.get(paths.size() - 1).moveTo(p.getX(), p.getY()); } else { if (p.getX() != -1) - path.lineTo(p.getX(), p.getY()); + paths.get(paths.size() - 1).lineTo(p.getX(), p.getY()); } invalidate(); cnt++; @@ -78,13 +92,13 @@ //----------------------------------------------------------------- // public void clearCanvas() { - path.reset(); + for (Path p : paths) p.reset(); invalidate(); } //----------------------------------------------------------------- // - public void stopUpdate(){ + public void stopUpdate() { paintViewModel.stop(); } //-----------------------------------------------------------------