Class Window
java.lang.Object
com.iragui.Window
Represents a window in the GUI system, managing rendering, input, and audio context.
This class uses GLFW for window creation and input handling, and OpenGL for rendering. It also manages OpenAL contexts for audio playback.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the window's color and depth buffers.void
close()
Closes the window, destroys OpenGL and OpenAL contexts, and terminates GLFW.int
int
int
getSizeX()
int
getSizeY()
long
void
init()
Initializes the GLFW window, OpenGL context, and sets up callbacks.void
Initializes OpenAL audio context for sound playback.void
modifyDisplaySize
(int x, int y) Modifies the display size and recalculates scaling factors.void
render()
Renders the GUI and swaps buffers without clearing first.void
render
(boolean showNextFrame) Renders the GUI and processes events.void
Resets the cursor to the default system cursor.void
setBackground
(float r, float g, float b, float a) Sets the background clear color for OpenGL rendering.void
setCursor
(WrappedBufferedImage cursor) Sets a custom cursor image for the window.void
setPixelSizeX
(int i) void
setPixelSizeY
(int i)
-
Field Details
-
sizeX
protected int sizeX -
sizeY
protected int sizeY
-
-
Constructor Details
-
Window
public Window(String name, int sizeX, int sizeY, int displayX, int displayY, boolean resizable, boolean decorated, boolean maximized, boolean exitOnClose, boolean redrawEveryFrame, GUI gui) Creates a newWindow
with the specified configuration.- Parameters:
name
- the window titlesizeX
- window width in pixelssizeY
- window height in pixelsdisplayX
- display width scalingdisplayY
- display height scalingresizable
- whether the window can be resizeddecorated
- whether the window has decorations (title bar, borders)maximized
- whether the window should start maximizedexitOnClose
- whether to exit the application when closedredrawEveryFrame
- whether to redraw continuously (unused here)gui
- the GUI manager instance
-
-
Method Details
-
getKeyListener
- Returns:
- the key listener associated with this window
-
getWindowListener
- Returns:
- the window listener associated with this window
-
getMouseListener
- Returns:
- the window listener associated with this window
-
getSizeX
public int getSizeX()- Returns:
- the window width in pixels
-
getSizeY
public int getSizeY()- Returns:
- the window height in pixels
-
getWindow
public long getWindow()- Returns:
- the GLFW window handle
-
render
public void render(boolean showNextFrame) Renders the GUI and processes events. Clears the frame ifshowNextFrame
is true.- Parameters:
showNextFrame
- whether to clear and redraw the next frame
-
clear
public void clear()Clears the window's color and depth buffers. -
render
public void render()Renders the GUI and swaps buffers without clearing first. -
init
public void init()Initializes the GLFW window, OpenGL context, and sets up callbacks.- Throws:
IllegalStateException
- if GLFW fails to initializeRuntimeException
- if the window cannot be created
-
initSound
public void initSound()Initializes OpenAL audio context for sound playback.- Throws:
AssertionError
- if the system does not support OpenAL 1.0
-
close
public void close()Closes the window, destroys OpenGL and OpenAL contexts, and terminates GLFW. -
modifyDisplaySize
public void modifyDisplaySize(int x, int y) Modifies the display size and recalculates scaling factors.- Parameters:
x
- new widthy
- new height
-
setBackground
public void setBackground(float r, float g, float b, float a) Sets the background clear color for OpenGL rendering.- Parameters:
r
- red component (0–1)g
- green component (0–1)b
- blue component (0–1)a
- alpha component (0–1)
-
getPixelSizeY
public int getPixelSizeY()- Returns:
- the current pixel height scaling factor
-
getPixelSizeX
public int getPixelSizeX()- Returns:
- the current pixel width scaling factor
-
setPixelSizeY
public void setPixelSizeY(int i) - Parameters:
i
- new pixel height scaling factor
-
setPixelSizeX
public void setPixelSizeX(int i) - Parameters:
i
- new pixel width scaling factor
-
getCursor
- Returns:
- the currently active custom cursor, or null if none
-
resetCursor
public void resetCursor()Resets the cursor to the default system cursor. -
setCursor
Sets a custom cursor image for the window.- Parameters:
cursor
- the wrapped image to use as cursor
-