public abstract class Screen
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
BOTTOM_OFFSET
Offset from the bottom to the playfield rectangle.
|
static int |
BOX_HEADER_HEIGHT
Height of a box title header.
|
static int |
BOX_INSETS
Inset into a drawn box and also the corner triangle size.
|
static int |
BOX_SPACING
Space between the boxes.
|
static int |
BOX_TEXT_OFFSET
Text offset from the side of a box.
|
private static int |
BUTTON_HEIGHT
Height of the buttons in the bottom left and right.
|
private static int |
BUTTON_WIDTH
Width of the buttons in the bottom left and right.
|
private ConvexMerger |
context
The active game context.
|
private java.awt.geom.Point2D |
lastLocation
Last mouse location.
|
private java.awt.Polygon |
leftPoly
Bottom left button polygon.
|
private java.awt.Polygon |
rightPoly
Bottom right button polygon.
|
static int |
SIDE_OFFSET
Offset from the side to the playfield rectangle.
|
static double |
SPACING
Spacing between various components.
|
static int |
TOP_MIDDLE_OFFSET
Height of the middle text area attached to the top part.
|
static int |
TOP_MIDDLE_TEXT_OFFSET
Text offset from the bottom in the top middle text area.
|
static int |
TOP_MIDDLE_WIDTH
Width of the middle text area attached to the top part.
|
static int |
TOP_OFFSET
Offset from the score display part of the game panel to the playfield rectangle.
|
static int |
TOP_SIDE_TRIANGLE
Dimensions of the triangles on the left and right side of the top part.
|
static int |
TOP_SPACE
Height of the top score display part of the game panel.
|
Modifier | Constructor and Description |
---|---|
protected |
Screen(ConvexMerger context)
Constructs a new screen with the given game context.
|
Modifier and Type | Method and Description |
---|---|
protected java.awt.geom.Path2D |
computeBox(double x,
double y,
double w,
double h,
double inset)
Computes the bounds of a box if draw according to the given parameters.
|
protected void |
drawBox(java.awt.Graphics2D g,
double x,
double y,
double w,
double h)
Draws a box according to the given parameters.
|
protected java.awt.geom.Path2D |
drawButton(java.awt.Graphics2D g,
java.lang.String text,
double x,
double y,
double w,
double h,
java.awt.geom.Point2D mouseLoc)
Draws a button at the given location with the given text.
|
protected void |
drawTitle(java.awt.Graphics2D g,
int width)
Draws the main screen title.
|
protected void |
drawTitledBox(java.awt.Graphics2D g,
java.awt.Paint gradient,
double x,
double y,
double w,
double h,
java.lang.String title)
Draws a titled box according to the given parameters.
|
protected int |
fillText(java.awt.Graphics2D g,
int rx,
int ry,
int width,
int height,
java.util.List<java.lang.String> text)
Fills the given area with the given text.
|
protected ConvexMerger |
getContext()
Gets the game context this screen is associated with.
|
protected abstract java.lang.String |
getLeftButtonText()
Gets the text for the bottom left button.
|
protected static double |
getMaxWidth(int width,
double ratio,
int max)
Computes how wide the content should be given a screen
width, width usage ratio and maximum width.
|
protected abstract java.lang.String |
getRightButtonText()
Gets the text for the bottom right button.
|
void |
handleKeyPressed(java.awt.event.KeyEvent event)
Handles a key press event.
|
void |
handleKeyReleased(java.awt.event.KeyEvent event)
Handles a key release event.
|
protected abstract void |
handleLeftButtonClick()
Handles the bottom left button being clicked.
|
void |
handleMouseDrag(java.awt.geom.Point2D loc,
int width,
int height)
Handles a mouse move on this screen.
|
void |
handleMouseMove(java.awt.geom.Point2D loc,
int width,
int height)
Handles a mouse move on this screen.
|
void |
handleMousePress(java.awt.geom.Point2D loc,
int width,
int height)
Handles a mouse button press on this screen.
|
void |
handleMouseRelease(java.awt.geom.Point2D loc,
int width,
int height)
Handles a mouse button release on this screen.
|
protected abstract void |
handleRightButtonClick()
Handles the bottom right button being clicked.
|
protected abstract boolean |
isLeftButtonEnabled()
Checks if the bottom left button is enabled.
|
protected abstract boolean |
isRightButtonEnabled()
Checks if the bottom right button is enabled.
|
void |
render(java.awt.Graphics2D g,
int width,
int height)
Renders this screen with the given graphics and dimensions.
|
protected abstract void |
render(java.awt.Graphics2D g,
int width,
int height,
java.awt.geom.Point2D mouseLoc)
Renders the content of this screen with the given graphics.
|
protected void |
renderMainInterface(java.awt.Graphics2D g,
int width,
int height,
GameState state)
Renders the main interface, the top panel and button left and
right buttons.
|
protected void |
renderMenuTitle(java.awt.Graphics2D g,
int width,
java.lang.String title)
Renders a screen sub title.
|
protected void |
switchScene(Screen next)
Switches the context from the current screen to the given screen.
|
public static final int TOP_SPACE
public static final int SIDE_OFFSET
public static final int TOP_OFFSET
public static final int BOTTOM_OFFSET
public static final int TOP_MIDDLE_WIDTH
public static final int TOP_MIDDLE_TEXT_OFFSET
public static final int TOP_SIDE_TRIANGLE
public static final int TOP_MIDDLE_OFFSET
private static final int BUTTON_HEIGHT
private static final int BUTTON_WIDTH
public static final int BOX_SPACING
public static final int BOX_INSETS
public static final int BOX_HEADER_HEIGHT
public static final int BOX_TEXT_OFFSET
public static final double SPACING
private java.awt.Polygon rightPoly
private java.awt.Polygon leftPoly
private java.awt.geom.Point2D lastLocation
private ConvexMerger context
protected Screen(ConvexMerger context)
context
- The game context.protected ConvexMerger getContext()
protected void switchScene(Screen next)
next
- The screen to switch to.public void render(java.awt.Graphics2D g, int width, int height)
g
- The graphics context to use.width
- The width of the screen.height
- The height of the screen.protected abstract void render(java.awt.Graphics2D g, int width, int height, java.awt.geom.Point2D mouseLoc)
g
- The graphics context to use.width
- The width of the screen.height
- The height of the screen.mouseLoc
- The current cursor location.protected static double getMaxWidth(int width, double ratio, int max)
min(ratio * width, max)
.width
- The width of the screen.ratio
- The fraction of the width to use.max
- The maximum width.protected void drawTitle(java.awt.Graphics2D g, int width)
g
- The graphics context to use.width
- The width of the screen.protected void drawTitledBox(java.awt.Graphics2D g, java.awt.Paint gradient, double x, double y, double w, double h, java.lang.String title)
g
- The graphics context to use.gradient
- The gradient to use.x
- The x location of the top left corner of the box.y
- The y location of the top left corner of the box.w
- The width of the box.h
- The height of the box.title
- The header title of the box.protected void drawBox(java.awt.Graphics2D g, double x, double y, double w, double h)
g
- The graphics context to use.x
- The x location of the top left corner of the box.y
- The y location of the top left corner of the box.w
- The width of the box.h
- The height of the box.protected java.awt.geom.Path2D computeBox(double x, double y, double w, double h, double inset)
x
- The x location of the top left corner of the box.y
- The y location of the top left corner of the box.w
- The width of the box.h
- The height of the box.inset
- The box insets, see BOX_INSETS
.protected java.awt.geom.Path2D drawButton(java.awt.Graphics2D g, java.lang.String text, double x, double y, double w, double h, java.awt.geom.Point2D mouseLoc)
g
- The graphics context to use.text
- The button text.x
- The x location of the top left corner of the button.y
- The y location of the top left corner of the button.w
- The width of the button.h
- The height of the button.mouseLoc
- The cursor location or null
.protected void renderMenuTitle(java.awt.Graphics2D g, int width, java.lang.String title)
g
- The graphics context to use.width
- The width of the screen.title
- The sub title to draw.protected int fillText(java.awt.Graphics2D g, int rx, int ry, int width, int height, java.util.List<java.lang.String> text)
g
- The graphics context to use.rx
- The x coordinate of the top left corner of the area.ry
- The y coordinate of the top left corner of the area.width
- The width of the area.height
- The height of the area.text
- The list of words to draw.protected void renderMainInterface(java.awt.Graphics2D g, int width, int height, GameState state)
g
- The graphics context to use.width
- The width of the screen.height
- The height of the screen.state
- The game state to use to determine the gradient
to use, can be null
.public void handleMouseRelease(java.awt.geom.Point2D loc, int width, int height)
loc
- The location that was clicked.width
- The width of the screen.height
- The height of the screen.public void handleMousePress(java.awt.geom.Point2D loc, int width, int height)
loc
- The location that was clicked.width
- The width of the screen.height
- The height of the screen.public void handleMouseMove(java.awt.geom.Point2D loc, int width, int height)
loc
- The current cursor location.width
- The width of the screen.height
- The height of the screen.public void handleMouseDrag(java.awt.geom.Point2D loc, int width, int height)
loc
- The current cursor location.width
- The width of the screen.height
- The height of the screen.public void handleKeyPressed(java.awt.event.KeyEvent event)
event
- The key press event.public void handleKeyReleased(java.awt.event.KeyEvent event)
event
- The key release event.protected abstract boolean isLeftButtonEnabled()
protected abstract boolean isRightButtonEnabled()
protected abstract java.lang.String getLeftButtonText()
protected abstract java.lang.String getRightButtonText()
protected abstract void handleLeftButtonClick()
protected abstract void handleRightButtonClick()