public class Window extends SFMLNativeObject implements WindowStyle
WindowStyle
interface for quick access
to the constants provided by it.CLOSE, DEFAULT, FULLSCREEN, NONE, RESIZE, TITLEBAR
Modifier | Constructor and Description |
---|---|
|
Window()
Constructs a new window without actually creating it (making it visible).
|
protected |
Window(long ptr)
Deprecated.
Use of this method may cause undefined behaviour and is not supported.
|
|
Window(VideoMode mode,
String title)
Constructs a new window and creates it with the specified settings and default
context settings and window style.
|
|
Window(VideoMode mode,
String title,
int style)
Constructs a new window and creates it with the specified settings and default
context settings..
|
|
Window(VideoMode mode,
String title,
int style,
ContextSettings settings)
Constructs a new window and creates it with the specified settings.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the window and destroys all attached resources,
including the OpenGL context provided by it.
|
void |
create(VideoMode mode,
String title)
Creates and opens a window or re-creates it if it was already opened.
|
void |
create(VideoMode mode,
String title,
int style)
Creates and opens a window or re-creates it if it was already opened.
|
void |
create(VideoMode mode,
String title,
int style,
ContextSettings settings)
Creates and opens a window or re-creates it if it was already opened.
|
void |
display()
Flushes the OpenGL pixel buffer to the screen.
|
Vector2i |
getPosition()
Gets the absolute position of the window's top left corner on the screen.
|
ContextSettings |
getSettings()
Retrieves the context settings for the window's OpenGL context.
|
Vector2i |
getSize()
Gets the size of the window.
|
static boolean |
isLegalWindowThread()
Checks whether the current native thread is eligibile for creating a window.
|
boolean |
isOpen()
Checks if the window has been created and is opened.
|
protected long |
nativeCreate()
Deprecated.
|
protected void |
nativeDelete()
Deprecated.
|
protected void |
nativeSetExPtr()
Deprecated.
|
Event |
pollEvent()
Pops the event on top of the event stack, if any, and returns it.
|
Iterable<Event> |
pollEvents()
Returns an
Iterable that consecutively calls pollEvent() and
can be used to process all pending events. |
void |
setActive()
Activates the window as the current OpenGL rendering target.
|
void |
setActive(boolean active)
Activates or deactivates the window as the current OpenGL rendering target.
|
void |
setFramerateLimit(int flimit)
Sets the maximum frame rate in frames per second.
|
void |
setIcon(Image icon)
Sets the icon of the window.
|
void |
setJoystickTreshold(float treshold)
Sets the joystick treshold.
|
void |
setKeyRepeatEnabled(boolean enable)
Determines whether automatic key repeat is enabled.
|
void |
setMouseCursorVisible(boolean show)
Determines whether the mouse cursor, if moved over the window, is visible or not.
|
void |
setPosition(Vector2i position)
Sets the absolute position of the window's top left corner on the screen.
|
void |
setSize(Vector2i size)
Sets the size of the window.
|
void |
setTitle(String title)
Sets the window's title.
|
void |
setVerticalSyncEnabled(boolean enable)
Enables or disables vertical synchronization (VSync).
|
void |
setVisible(boolean show)
Shows or hides the window.
|
Event |
waitEvent()
Pops the event on top of the event stack and returns it, or, if there is none,
waits until an event occurs and then returns it.
|
finalize
public Window()
@Deprecated protected Window(long ptr)
ptr
- the window handle of the parent window.public Window(VideoMode mode, String title, int style, ContextSettings settings)
mode
- the window's video mode.title
- the window title.style
- the window style.settings
- the settings for the OpenGL context.create(VideoMode, String, int, ContextSettings)
public Window(VideoMode mode, String title, int style)
mode
- the window's video mode.title
- the window title.style
- the window style.@Deprecated protected long nativeCreate()
SFMLNativeObject
nativeCreate
in class SFMLNativeObject
@Deprecated protected void nativeSetExPtr()
SFMLNativeObject
nativeSetExPtr
in class SFMLNativeObject
@Deprecated protected void nativeDelete()
SFMLNativeObject
nativeDelete
in class SFMLNativeObject
public static boolean isLegalWindowThread()
-XstartOnFirstThread
command
line parameter.true
if the current native thread may create a window,
false
otherwise.public void create(VideoMode mode, String title, int style, ContextSettings settings)
mode
- the video mode that determines the window's size.
This must be a valid video mode in case WindowStyle.FULLSCREEN
is set.title
- the window title.style
- the style of the window.
This should be a combination (using OR
of the style flags
WindowStyle.TITLEBAR
, WindowStyle.RESIZE
, WindowStyle.CLOSE
and
WindowStyle.FULLSCREEN
, or WindowStyle.NONE
for no style.
WindowStyle.DEFAULT
provides a default combination of style flags.settings
- the context settings for the created OpenGL context.VideoMode.isValid()
,
WindowStyle
,
ContextSettings
public final void create(VideoMode mode, String title, int style)
mode
- the video mode that determines the window's size.
This must be a valid video mode in case WindowStyle.FULLSCREEN
is set.title
- the window title.style
- the style of the window.
This should be a combination (using OR
of the style flags
WindowStyle.TITLEBAR
, WindowStyle.RESIZE
, WindowStyle.CLOSE
and
WindowStyle.FULLSCREEN
, or WindowStyle.NONE
for no style.
WindowStyle.DEFAULT
provides a default combination of style flags.VideoMode.isValid()
,
WindowStyle
public final void create(VideoMode mode, String title)
WindowStyle.DEFAULT
window style will be applied and default
context settings will be used for the OpenGL context.mode
- the video mode that determines the window's size.title
- the window title.public void close()
public boolean isOpen()
Event.Type.CLOSED
and use
the close()
method.true
if the window has been created and is currently open.public Vector2i getPosition()
public void setPosition(Vector2i position)
position
- the new absolute position of the window's top left corner on the screen.public Vector2i getSize()
public void setSize(Vector2i size)
size
- the new size of the window.public ContextSettings getSettings()
public Event pollEvent()
null
if there is none.waitEvent()
public Event waitEvent()
pollEvent()
public Iterable<Event> pollEvents()
Iterable
that consecutively calls pollEvent()
and
can be used to process all pending events.Iterable
over all pending events.pollEvent()
public void setVerticalSyncEnabled(boolean enable)
setFramerateLimit(int)
,
as these two will conflict with one another.
By default, vertical synchronization is disabled.enable
- true
to enable vertical synchronization, false
to disable.public void setMouseCursorVisible(boolean show)
show
- true
to make the cursor visible, false
to hide it.public void setTitle(String title)
title
- the window's new title.public void setVisible(boolean show)
show
- true
to show the window, false
to hide it.public void setKeyRepeatEnabled(boolean enable)
enable
- true
to enable, false
to disabled.public void setIcon(Image icon)
icon
- the icon image.public void setActive(boolean active) throws ContextActivationException
active
- true
to activate, false
to deactivate.ContextActivationException
- in case window activation fails.public final void setActive() throws ContextActivationException
ContextActivationException
- in case window activation fails.public void display()
public void setFramerateLimit(int flimit)
display()
method will block for a short delay time
after flushing the buffer in order to possibly maintain a constant frame rate.
This should not be used in combination with
setVerticalSyncEnabled(boolean)
} as these two will conflict with one another.
By default, there is no frame rate limit.flimit
- the maximum frame rate in frames per second, or 0
to disable
the frame rate limit.public void setJoystickTreshold(float treshold)
treshold
- the joystick treshold, ranging between 0 and 100.JoystickMoveEvent