Package io.github.ocelot.window
Class Window
java.lang.Object
io.github.ocelot.window.Window
- All Implemented Interfaces:
AutoCloseable,org.lwjgl.system.NativeResource
Manages and tracks certain key events for windows. Events are passed to all registered listeners.
In order to use graphics, create the capabilities for the desired API after calling create(CharSequence).
For example, to use LWJGL OpenGL use org.lwjgl.opengl.GL.createCapabilities()
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(WindowEventListener listener) Adds the specified listener to the event list.voidcenter()Centers this window on the current monitor.create(CharSequence title) Creates this window with GLFW.create(CharSequence title, long share) Creates this window with GLFW.Creates the default implementation of key tracking and automatically adds it to the listeners.Creates the default implementation of mouse tracking and automatically adds it to the listeners.voidfree()@Nullable Stringintintlongint@Nullable CharSequencegetTitle()intintintgetX()intgetY()booleanisClosed()booleanbooleanbooleanisVsync()voidremoveListener(WindowEventListener listener) Removes the specified listener to the event list.voidsetClosing(boolean closing) Marks the window as closing or not.voidsetFullscreen(boolean fullscreen) Sets the window fullscreen or not.static voidsetMacIcon(InputStream stream) Reads the icon from the stream and sends it to the OS to set the mac icon.voidsetPosition(int x, int y) Sets the absolute position of the window.voidsetSize(int width, int height) Sets the size of the window.voidsetSwapInterval(int swapInterval) Sets the number of monitor frames to wait before continuing execution whenswapBuffers()is called.voidsetTitle(CharSequence title) Updates the window title to the specified string.voidsetVsync(boolean vsync) Sets the window to use vsync.voidUpdates the contents of the window.voidToggles the fullscreen flag.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.lwjgl.system.NativeResource
close
-
Method Details
-
addListener
Adds the specified listener to the event list.- Parameters:
listener- The listener to add
-
removeListener
Removes the specified listener to the event list.- Parameters:
listener- The listener to add
-
create
Creates this window with GLFW.- Parameters:
title- The title of the window
-
create
Creates this window with GLFW.- Parameters:
title- The title of the windowshare- The id off the window to share context with or0Lto create a new context- See Also:
-
createMouseHandler
Creates the default implementation of mouse tracking and automatically adds it to the listeners.- Returns:
- A new mouse handler that tracks events for this window
-
createKeyboardHandler
Creates the default implementation of key tracking and automatically adds it to the listeners.- Returns:
- A new keyboard handler that tracks events for this window
-
swapBuffers
public void swapBuffers()Updates the contents of the window. Called byWindowManager.update()automatically. -
toggleFullscreen
public void toggleFullscreen()Toggles the fullscreen flag. -
free
public void free()- Specified by:
freein interfaceorg.lwjgl.system.NativeResource
-
getHandle
public long getHandle()- Returns:
- The GLFW id of the window
-
getX
public int getX()- Returns:
- The absolute x position of the window
-
getY
public int getY()- Returns:
- The absolute y position of the window
-
getWindowWidth
public int getWindowWidth()- Returns:
- The width of the physical window.
getFramebufferWidth()should be used for drawing logic
-
getWindowHeight
public int getWindowHeight()- Returns:
- The width of the physical window.
getFramebufferHeight()should be used for drawing logic
-
getFramebufferWidth
public int getFramebufferWidth()- Returns:
- The width of the canvas in the window
-
getFramebufferHeight
public int getFramebufferHeight()- Returns:
- The height of the canvas in the window
-
isFullscreen
public boolean isFullscreen()- Returns:
- Whether the window is currently full screen
-
getSwapInterval
public int getSwapInterval()- Returns:
- The number of monitor frames to wait before continuing execution when
swapBuffers()is called
-
isVsync
public boolean isVsync()- Returns:
- Whether vsync is enabled
-
getTitle
- Returns:
- The title of the window or
nullif the window has not been initialized yet
-
isFocused
public boolean isFocused()- Returns:
- If the window is currently focused
-
isClosed
public boolean isClosed()- Returns:
- If the window is requesting to close
-
getClipboard
- Returns:
- The current string on the clipboard or
nullif there is nothing
-
setFullscreen
public void setFullscreen(boolean fullscreen) Sets the window fullscreen or not. Will automatically handle special mac handling.- Parameters:
fullscreen- Whether to enter fullscreen
-
setSwapInterval
public void setSwapInterval(int swapInterval) Sets the number of monitor frames to wait before continuing execution whenswapBuffers()is called.- Parameters:
swapInterval- The frame count
-
setVsync
public void setVsync(boolean vsync) Sets the window to use vsync.- Parameters:
vsync- Whether vsync should be enabled
-
setTitle
Updates the window title to the specified string.- Parameters:
title- The new window title
-
center
public void center()Centers this window on the current monitor. -
setPosition
public void setPosition(int x, int y) Sets the absolute position of the window.- Parameters:
x- The new x positiony- The new y position
-
setSize
public void setSize(int width, int height) Sets the size of the window.- Parameters:
width- The new x sizeheight- The new y size
-
setClosing
public void setClosing(boolean closing) Marks the window as closing or not.- Parameters:
closing- Whether the window should close
-
toString
-
setMacIcon
Reads the icon from the stream and sends it to the OS to set the mac icon. This should only be called on a mac.- Parameters:
stream- The image file stream- Throws:
IOException- If any error occurs reading the image
-