ajout bouton reset

This commit is contained in:
Hugo DIMITRIJEVIC 2024-04-04 07:50:53 +02:00
parent 5f85daa682
commit 52266dc517

View File

@ -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);
}
}