ajout bouton reset
This commit is contained in:
parent
5f85daa682
commit
52266dc517
68
app/src/main/java/fr/iutfbleau/sae/ResetButton.java
Normal file
68
app/src/main/java/fr/iutfbleau/sae/ResetButton.java
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user