Package org.openpatch.scratch
Class Window
java.lang.Object
org.openpatch.scratch.Window
The Window class represents a singleton window for the application. It provides various
constructors to create a window with different configurations such as dimensions, full screen
mode, and asset paths. The class ensures that only one instance of the window can be created at
any time.
The class also provides methods to interact with the window and the application, such as retrieving the window dimensions, setting the debug mode, managing stages, and exiting the application.
Example usage:
Window window = new Window();
window.setDebug(true);
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionWindow()
Constructs a new Window with default dimensions.Window
(boolean fullScreen) Constructs a new Window.Constructs a new Window instance.Window
(int width, int height) Constructs a new Window with the specified width and height.Constructs a new Window with the specified width, height, and assets path.Constructs a new Window with the specified assets. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Deprecated.since 4.0.0.void
exit()
Exits the application by invoking the `whenExits` method and then calling the `exit` method on the `Applet` instance.double
Gets the seconds passed since the last frame.int
Retrieves the height of the current window.static Window
Returns the singleton instance of the Window class.getStage()
Retrieves the current stage from the Applet instance.int
getWidth()
Retrieves the width of the current window.boolean
isDebug()
Checks if the application is in debug mode.void
removeStage
(String name) Deprecated.since 4.0.0.void
setDebug
(boolean debug) Enables or disables the debug mode for the application.void
setDefaultFont
(String path) Sets the default font for the application.void
Sets the current stage of the application.void
switchStage
(String name) Deprecated.since 4.0.0.void
This method is called when the window exits.
-
Field Details
-
DEBUG_COLOR
public static final int[] DEBUG_COLOR
-
-
Constructor Details
-
Window
public Window()Constructs a new Window with default dimensions. The default width is 480 pixels and the default height is 360 pixels. -
Window
Constructs a new Window with the specified assets. The window will have a default width of 480 pixels and a height of 360 pixels.- Parameters:
assets
- the path to the assets to be used in the window
-
Window
public Window(int width, int height) Constructs a new Window with the specified width and height.- Parameters:
width
- the width of the windowheight
- the height of the window
-
Window
Constructs a new Window with the specified width, height, and assets path. Ensures that only one instance of Window can be created.- Parameters:
width
- the width of the windowheight
- the height of the windowassets
- the path to the assets- Throws:
Error
- if an instance of Window already exists
-
Window
public Window(boolean fullScreen) Constructs a new Window.- Parameters:
fullScreen
- a boolean indicating whether the window should be in full screen mode.
-
Window
Constructs a new Window instance. If an instance of Window already exists, an Error is thrown to ensure only one Window instance is created.- Parameters:
fullScreen
- a boolean indicating whether the window should be in full screen modeassets
- a String specifying the path to the assets- Throws:
Error
- if an instance of Window already exists
-
-
Method Details
-
getInstance
Returns the singleton instance of the Window class.- Returns:
- the singleton instance of Window
-
getDeltaTime
public double getDeltaTime()Gets the seconds passed since the last frame.- Returns:
- seconds since last frame
-
isDebug
public boolean isDebug()Checks if the application is in debug mode.- Returns:
- true if the application is in debug mode, false otherwise.
-
setDebug
public void setDebug(boolean debug) Enables or disables the debug mode for the application.- Parameters:
debug
- a boolean value wheretrue
enables debug mode andfalse
disables it.
-
getWidth
public int getWidth()Retrieves the width of the current window.- Returns:
- the width of the window in pixels
-
getHeight
public int getHeight()Retrieves the height of the current window.- Returns:
- the height of the window in pixels
-
setDefaultFont
Sets the default font for the application.- Parameters:
path
- the file path to the font to be set as default
-
setStage
Sets the current stage of the application.- Parameters:
stage
- the new stage to be set
-
addStage
Deprecated.since 4.0.0. Use setStage instead.- Parameters:
name
- Name of the stagestage
- A stage object
-
switchStage
Deprecated.since 4.0.0. Use setStage instead.- Parameters:
name
- Name of the stage
-
removeStage
Deprecated.since 4.0.0. Use setStage instead.- Parameters:
name
- Name of the stage
-
getStage
Retrieves the current stage from the Applet instance.- Returns:
- the current Stage object
-
exit
public void exit()Exits the application by invoking the `whenExits` method and then calling the `exit` method on the `Applet` instance. -
whenExits
public void whenExits()This method is called when the window exits. Override this method to define custom behavior when the window is closed.
-