private class NewGameMenu.ButtonAssembly
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static double |
BUTTON_HEIGHT
Height of the individual buttons.
|
private static double |
BUTTON_WIDTH
Width of the individual buttons.
|
private java.awt.geom.Path2D |
left
The bounds for the left button.
|
private java.util.function.IntConsumer |
listener
Listener called when the selected button changes.
|
private java.awt.geom.Path2D |
middle
The bounds for the middle button.
|
private java.awt.geom.Path2D |
right
The bounds for the right button.
|
private int |
selected
The index of the currently selected button (0~2).
|
private java.lang.String |
title
Title of this assembly.
|
private java.lang.String[] |
values
Button display values.
|
Constructor and Description |
---|
ButtonAssembly(int selected,
java.lang.String title,
java.lang.String... values)
Constructs a new button assembly with the given initially
selected button, assembly title and button values.
|
Modifier and Type | Method and Description |
---|---|
double |
getHeight(java.awt.Graphics2D g)
Gets the height of this button assembly.
|
private java.awt.geom.Path2D |
getSelectedPath()
Gets the bounds of the selected button.
|
double |
getWidth()
Gets the width of this button assembly.
|
private void |
handleMouseClick(java.awt.geom.Point2D loc)
Handles a mouse click on this button assembly.
|
private boolean |
intersectsLeft(java.awt.geom.Point2D point)
Checks if the given point is on the left button.
|
private boolean |
intersectsMiddle(java.awt.geom.Point2D point)
Checks if the given point is on the middle button.
|
private boolean |
intersectsRight(java.awt.geom.Point2D point)
Checks if the given point is on the right button.
|
private void |
render(java.awt.Graphics2D g,
double x,
double y,
double w,
java.awt.geom.Point2D mouseLoc)
Renders this button assembly at the given location.
|
void |
setChangeListener(java.util.function.IntConsumer listener)
Sets the listener called when the selected button changes.
|
void |
setSelected(int selected)
Sets the selected button for this assembly.
|
private static final double BUTTON_WIDTH
private static final double BUTTON_HEIGHT
private java.lang.String title
private java.lang.String[] values
private java.awt.geom.Path2D left
private java.awt.geom.Path2D middle
private java.awt.geom.Path2D right
private int selected
private java.util.function.IntConsumer listener
public ButtonAssembly(int selected, java.lang.String title, java.lang.String... values)
selected
- The initially selected button.title
- The assembly title.values
- The button display values.public void setChangeListener(java.util.function.IntConsumer listener)
listener
- The new change listener.public double getHeight(java.awt.Graphics2D g)
g
- The graphics context to use.public double getWidth()
public void setSelected(int selected)
selected
- The selected button (0~2).private java.awt.geom.Path2D getSelectedPath()
private boolean intersectsLeft(java.awt.geom.Point2D point)
point
- The point to check.private boolean intersectsMiddle(java.awt.geom.Point2D point)
point
- The point to check.private boolean intersectsRight(java.awt.geom.Point2D point)
point
- The point to check.private void render(java.awt.Graphics2D g, double x, double y, double w, java.awt.geom.Point2D mouseLoc)
g
- The graphics context to use.x
- The x coordinate of the top left corner.y
- The y coordinate of the top left corner.w
- The width of the assembly.mouseLoc
- The current cursor location.private void handleMouseClick(java.awt.geom.Point2D loc)
loc
- The clicked location.