Class Window

java.lang.Object
com.iragui.Window

public class Window extends Object
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 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 new Window with the specified configuration.
      Parameters:
      name - the window title
      sizeX - window width in pixels
      sizeY - window height in pixels
      displayX - display width scaling
      displayY - display height scaling
      resizable - whether the window can be resized
      decorated - whether the window has decorations (title bar, borders)
      maximized - whether the window should start maximized
      exitOnClose - whether to exit the application when closed
      redrawEveryFrame - whether to redraw continuously (unused here)
      gui - the GUI manager instance
  • Method Details

    • getKeyListener

      public KeyListener getKeyListener()
      Returns:
      the key listener associated with this window
    • getWindowListener

      public WindowListener getWindowListener()
      Returns:
      the window listener associated with this window
    • getMouseListener

      public MouseListener 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 if showNextFrame 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 initialize
      RuntimeException - 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 width
      y - 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

      public WrappedBufferedImage getCursor()
      Returns:
      the currently active custom cursor, or null if none
    • resetCursor

      public void resetCursor()
      Resets the cursor to the default system cursor.
    • setCursor

      public void setCursor(WrappedBufferedImage cursor)
      Sets a custom cursor image for the window.
      Parameters:
      cursor - the wrapped image to use as cursor