Class GLFWWindow

java.lang.Object
com.blackrook.gloop.glfw.GLFWHandle
com.blackrook.gloop.glfw.GLFWWindow

public class GLFWWindow extends GLFWHandle
A GLFW window instance.
Author:
Matthew Tropiano
  • Constructor Details

  • Method Details

    • getHandle

      public long getHandle()
      Specified by:
      getHandle in class GLFWHandle
      Returns:
      this handle's GLFW address handle.
    • isCreated

      public boolean isCreated()
      Specified by:
      isCreated in class GLFWHandle
      Returns:
      true if this handle was allocated, false if not.
    • destroy

      public void destroy()
      Description copied from class: GLFWHandle
      Destroys this handle. Does nothing if already destroyed.
      Specified by:
      destroy in class GLFWHandle
    • addWindowListener

      public void addWindowListener(GLFWWindow.WindowListener listener)
      Adds a GLFWWindow.WindowListener to this window for listening for window events. Events are dispatched to listeners in the order added. This method is thread safe.
      Parameters:
      listener - the listener to add.
    • removeWindowListener

      public void removeWindowListener(GLFWWindow.WindowListener listener)
      Removes a GLFWWindow.WindowListener from this window. This method is thread safe.
      Parameters:
      listener - the listener to remove.
    • addInputListener

      public void addInputListener(GLFWWindow.InputListener listener)
      Adds an GLFWWindow.InputListener to this window for listening for window events. Events are dispatched to listeners in the order added. This method is thread safe.
      Parameters:
      listener - the listener to add.
    • removeInputListener

      public void removeInputListener(GLFWWindow.InputListener listener)
      Removes an GLFWWindow.InputListener from this window. This method is thread safe.
      Parameters:
      listener - the listener to remove.
    • addDropListener

      public void addDropListener(GLFWWindow.DropListener listener)
      Adds a GLFWWindow.DropListener to this window for listening for window events. Events are dispatched to listeners in the order added. This method is thread safe.
      Parameters:
      listener - the listener to add.
    • removeDropListener

      public void removeDropListener(GLFWWindow.DropListener listener)
      Removes a GLFWWindow.DropListener from this window. This method is thread safe.
      Parameters:
      listener - the listener to remove.
    • setMonitor

      public void setMonitor(GLFWMonitor monitor, int xpos, int ypos, int width, int height, int refreshRate)
      Sets the target monitor for this window in fullscreen mode.

      This must only be called from the main thread.

      Parameters:
      monitor - the desired monitor, or null to set windowed mode.
      xpos - the desired x-coordinate of the upper-left corner of the content area.
      ypos - the desired y-coordinate of the upper-left corner of the content area.
      width - the desired width in screen coordinates of the content area or video mode.
      height - the desired height in screen coordinates of the content area or video mode.
      refreshRate - the desired refresh rate in Hz of the video mode, or GLFWWindowHints.DONT_CARE
    • getMonitor

      public GLFWMonitor getMonitor()
      Sets the current monitor for this window.
      Returns:
      the current monitor, or null if none.
    • setTitle

      public void setTitle(String title)
      Sets this window's title.

      This must only be called from the main thread.

      Parameters:
      title - the new title.
    • setIcon

      public void setIcon(BufferedImage icon)
      Sets this window's icon. Only works in non-macOS environments. In macOS, the application bundle icons are used.

      This must only be called from the main thread.

      Parameters:
      icon - the new icon.
    • setCursor

      public void setCursor(GLFWCursor cursor)
      Sets this window's cursor.
      Parameters:
      cursor - the cursor.

      This must only be called from the main thread.

    • setCursorMode

      public void setCursorMode(GLFWWindow.CursorMode cursorMode)
      Sets this window's cursor mode.
      Parameters:
      cursorMode - the cursor mode.

      This must only be called from the main thread.

    • setRawMouseMotion

      public void setRawMouseMotion(boolean enabled)
      Sets if the mouse motion on this window is raw, no acceleration applied. Only works if the cursor mode is GLFWWindow.CursorMode.DISABLED.

      This must only be called from the main thread.

      Parameters:
      enabled - true to enable, false to disable.
    • setStickyKeys

      public void setStickyKeys(boolean enabled)
      Sets if sticky keys is enabled.

      This must only be called from the main thread.

      Parameters:
      enabled - true to enable, false to disable.
    • setStickyMouseButtons

      public void setStickyMouseButtons(boolean enabled)
      Sets if sticky mouse buttons is enabled.

      This must only be called from the main thread.

      Parameters:
      enabled - true to enable, false to disable.
    • setLockKeyMods

      public void setLockKeyMods(boolean enabled)
      Sets if the lock keys pass their modifier bits to the input system.

      This must only be called from the main thread.

      Parameters:
      enabled - true to enable, false to disable.
    • center

      public void center(GLFWMonitor monitor)
      Sets this window's position (upper-left coordinate) to center of the screen using its current size and a monitor.

      This must only be called from the main thread.

      Parameters:
      monitor - the monitor to center on.
      See Also:
    • iconify

      public void iconify()
      Iconifies the window. Fires an event to listeners, but only when GLFW's Poll Events function is called.

      This must only be called from the main thread.

    • restore

      public void restore()
      Restores the window. Fires an event to listeners, but only when GLFW's Poll Events function is called.

      This must only be called from the main thread.

    • maximize

      public void maximize()
      Maximizes the window. Fires an event to listeners, but only when GLFW's Poll Events function is called.

      This must only be called from the main thread.

    • setVisible

      public void setVisible(boolean state)
      Sets the visibility of the window. Fires an event to listeners, but only when GLFW's Poll Events function is called.

      This must only be called from the main thread.

      Parameters:
      state - true to show, false to hide.
    • focus

      public void focus()
      Requests focus on the window. Fires an event to listeners, but only when GLFW's Poll Events function is called.

      This must only be called from the main thread.

    • requestAttention

      public void requestAttention()
      Signals user attention from this window. Fires an event to listeners, but only when GLFW's Poll Events function is called.

      This must only be called from the main thread.

    • isClosing

      public boolean isClosing()
      Checks the closing flag of this window.

      This can be called from any thread.

      Returns:
      true if set, false if not.
    • setClosing

      public void setClosing(boolean state)
      Sets the closing flag of this window (aka "window should close").

      This can be called from any thread.

      Parameters:
      state - the closing state.
    • setPosition

      public void setPosition(int x, int y)
      Sets this window's position (upper-left coordinate).

      This must only be called from the main thread.

      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      See Also:
    • getPosition

      public GLFWWindow.Point getPosition()
      Gets this window's position (upper-left coordinate).

      This must only be called from the main thread.

      Returns:
      a Point representing the current window position.
    • setSize

      public void setSize(int width, int height)
      Sets this window's size.

      This must only be called from the main thread.

      Parameters:
      width - the new width in pixels.
      height - the new height in pixels.
    • getSize

      public GLFWWindow.Dimension getSize()
      Gets this window's size.

      This must only be called from the main thread.

      Returns:
      a Dimension representing the current window size/dimensions.
    • setSizeLimits

      public void setSizeLimits(int minwidth, int minheight, int maxwidth, int maxheight)
      Sets the size limits of the content area of the specified window.

      This must only be called from the main thread.

      Parameters:
      minwidth - the minimum width in screen coordinates of the content area, or GLFWWindowHints.DONT_CARE
      minheight - the minimum height in screen coordinates of the content area, or GLFWWindowHints.DONT_CARE
      maxwidth - the maximum width in screen coordinates of the content area, or GLFWWindowHints.DONT_CARE
      maxheight - the maximum height in screen coordinates of the content area, or GLFWWindowHints.DONT_CARE
    • setOpacity

      public void setOpacity(float scalar)
      Sets the window opacity.

      This must only be called from the main thread.

      Parameters:
      scalar - the new opacity scalar.
    • getOpacity

      public float getOpacity(float scalar)
      Gets the window opacity.

      This must only be called from the main thread.

      Parameters:
      scalar - the new opacity scalar.
      Returns:
      the window opacity.
    • setAspectRatio

      public void setAspectRatio(int numer, int denom)
      Sets this window's aspect ratio limits.

      This must only be called from the main thread.

      Parameters:
      numer - the numerator of the desired aspect ratio, or GLFWWindowHints.DONT_CARE
      denom - the denominator of the desired aspect ratio, or GLFWWindowHints.DONT_CARE
    • setDecorated

      public void setDecorated(boolean value)
      Sets if this window is decorated (has shell bordering).

      This must only be called from the main thread.

      Parameters:
      value - true if so, false if not.
    • setResizable

      public void setResizable(boolean value)
      Sets if this window is resizable (via user, not program).

      This must only be called from the main thread.

      Parameters:
      value - true if so, false if not.
    • setAutoIconified

      public void setAutoIconified(boolean value)
      Sets if this window is iconified on creation.

      This must only be called from the main thread.

      Parameters:
      value - true if so, false if not.
    • setFloating

      public void setFloating(boolean value)
      Sets if this window is floating, or rather, "always on top".

      This must only be called from the main thread.

      Parameters:
      value - true if so, false if not.
    • setFocusOnShow

      public void setFocusOnShow(boolean value)
      Sets if this window requests focus when shown.

      This must only be called from the main thread.

      Parameters:
      value - true if so, false if not.
    • getFramebufferSize

      public GLFWWindow.Dimension getFramebufferSize()
      Gets the frame buffer size.

      This must only be called from the main thread.

      Returns:
      a Dimension that represents the framebuffer size.
    • getFrameSize

      public GLFWWindow.Rectangle getFrameSize()
      Gets the window's frame size.

      This must only be called from the main thread.

      Returns:
      a Rectangle that represents the framebuffer size (x, y, width, height).
    • getContentScale

      public GLFWWindow.PointF getContentScale()
      Gets the content scale for the specified window. The content scale is the ratio between the current DPI and the platform's default DPI. Depends on monitor.
      Returns:
      the scalars.
    • getState

      public GLFWWindow.State getState()
      Gets a window characteristic state that can be fetched outside of the main polling thread. The reference returned is the only instance - the values on this object can change frequently.
      Returns:
      this window's characteristics, set from the last event poll.
    • swapBuffers

      public void swapBuffers()
      Swaps the front and back buffer on the window, redrawing its contents to the foreground. If a swap interval is set, the system may wait for a set of vertical blank signals before this happens, and will block until they occur.

      This is only necessary for OpenGL/GLES contexts.

      This can be called from any thread.

      See Also: