From 52266dc517c19140c3f074b52c662cc88b2946a1 Mon Sep 17 00:00:00 2001 From: Hugo Dimitrijevic Date: Thu, 4 Apr 2024 07:50:53 +0200 Subject: [PATCH] ajout bouton reset --- .../java/fr/iutfbleau/sae/ResetButton.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 app/src/main/java/fr/iutfbleau/sae/ResetButton.java diff --git a/app/src/main/java/fr/iutfbleau/sae/ResetButton.java b/app/src/main/java/fr/iutfbleau/sae/ResetButton.java new file mode 100644 index 0000000..ef5a7b7 --- /dev/null +++ b/app/src/main/java/fr/iutfbleau/sae/ResetButton.java @@ -0,0 +1,68 @@ +package fr.iutfbleau.sae; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.util.AttributeSet; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatButton; + +/** + * {@code ResetButton} is a class that represents a button that resets the + * offset of the {@code GameView}. + * + * @autor Alexeï Kadir, Lyanis Souidi, Hugo Dimitrijevic + * @version 1.0 + */ +public class ResetButton extends AppCompatButton { + /** + * The width of the lines that make up the {@code ResetButton}. + */ + private static final int LINE_WIDTH = 8; + + /** + * The paint used to draw the {@code ResetButton}. + */ + private final Paint paint; + + /** + * Constructs a new {@code ResetButton} with the specified context and + * attributes. + * + * @param context The context of the {@code ResetButton}. + * @param attributes The attributes of the {@code ResetButton}. + */ + public ResetButton(Context context, @Nullable AttributeSet attributes) { + super(context, attributes); + + this.paint = new Paint(Paint.ANTI_ALIAS_FLAG); + } + + /** + * Draws the {@code ResetButton}. + * + * @param canvas The {@code Canvas} on which to draw the {@code ResetButton}. + */ + @Override + protected void onDraw(@NonNull Canvas canvas) { + super.onDraw(canvas); + + this.paint.setColor(this.getResources().getColor(R.color.cross)); + this.paint.setStrokeWidth(LINE_WIDTH); + this.paint.setStyle(Paint.Style.STROKE); + + int w = this.getWidth(); + int h = this.getHeight(); + int cx = w / 2; + int cy = h / 2; + + int s = Math.min(w, h) / 3; + + canvas.drawCircle(cx, cy, s - LINE_WIDTH, this.paint); + + canvas.drawLine(cx, cy - s / 2.0F, cx, cy + s / 2.0F, this.paint); + canvas.drawLine(cx - s / 2.0F, cy, cx + s / 2.0F, cy, this.paint); + } +}