Data Structures | Enumerations | Functions
Window/Window.h File Reference
#include <SFML/Window/Export.h>
#include <SFML/Window/Event.h>
#include <SFML/Window/VideoMode.h>
#include <SFML/Window/WindowHandle.h>
#include <SFML/Window/Types.h>
#include <SFML/System/Vector2.h>

Go to the source code of this file.

Data Structures

struct  sfContextSettings
 Structure defining the window's creation settings. More...
 

Enumerations

enum  sfWindowStyle {
  sfNone = 0,
  sfTitlebar = 1 << 0,
  sfResize = 1 << 1,
  sfClose = 1 << 2,
  sfFullscreen = 1 << 3,
  sfDefaultStyle = sfTitlebar | sfResize | sfClose
}
 Enumeration of window creation styles. More...
 
enum  sfContextAttribute {
  sfContextDefault = 0,
  sfContextCore = 1 << 0,
  sfContextDebug = 1 << 2
}
 Enumeration of the context attribute flags. More...
 

Functions

CSFML_WINDOW_API sfWindowsfWindow_create (sfVideoMode mode, const char *title, sfUint32 style, const sfContextSettings *settings)
 Construct a new window. More...
 
CSFML_WINDOW_API sfWindowsfWindow_createUnicode (sfVideoMode mode, const sfUint32 *title, sfUint32 style, const sfContextSettings *settings)
 Construct a new window (with a UTF-32 title) More...
 
CSFML_WINDOW_API sfWindowsfWindow_createFromHandle (sfWindowHandle handle, const sfContextSettings *settings)
 Construct a window from an existing control. More...
 
CSFML_WINDOW_API void sfWindow_destroy (sfWindow *window)
 Destroy a window. More...
 
CSFML_WINDOW_API void sfWindow_close (sfWindow *window)
 Close a window and destroy all the attached resources. More...
 
CSFML_WINDOW_API sfBool sfWindow_isOpen (const sfWindow *window)
 Tell whether or not a window is opened. More...
 
CSFML_WINDOW_API sfContextSettings sfWindow_getSettings (const sfWindow *window)
 Get the settings of the OpenGL context of a window. More...
 
CSFML_WINDOW_API sfBool sfWindow_pollEvent (sfWindow *window, sfEvent *event)
 Pop the event on top of event queue, if any, and return it. More...
 
CSFML_WINDOW_API sfBool sfWindow_waitEvent (sfWindow *window, sfEvent *event)
 Wait for an event and return it. More...
 
CSFML_WINDOW_API sfVector2i sfWindow_getPosition (const sfWindow *window)
 Get the position of a window. More...
 
CSFML_WINDOW_API void sfWindow_setPosition (sfWindow *window, sfVector2i position)
 Change the position of a window on screen. More...
 
CSFML_WINDOW_API sfVector2u sfWindow_getSize (const sfWindow *window)
 Get the size of the rendering region of a window. More...
 
CSFML_WINDOW_API void sfWindow_setSize (sfWindow *window, sfVector2u size)
 Change the size of the rendering region of a window. More...
 
CSFML_WINDOW_API void sfWindow_setTitle (sfWindow *window, const char *title)
 Change the title of a window. More...
 
CSFML_WINDOW_API void sfWindow_setUnicodeTitle (sfWindow *window, const sfUint32 *title)
 Change the title of a window (with a UTF-32 string) More...
 
CSFML_WINDOW_API void sfWindow_setIcon (sfWindow *window, unsigned int width, unsigned int height, const sfUint8 *pixels)
 Change a window's icon. More...
 
CSFML_WINDOW_API void sfWindow_setVisible (sfWindow *window, sfBool visible)
 Show or hide a window. More...
 
CSFML_WINDOW_API void sfWindow_setVerticalSyncEnabled (sfWindow *window, sfBool enabled)
 Enable or disable vertical synchronization. More...
 
CSFML_WINDOW_API void sfWindow_setMouseCursorVisible (sfWindow *window, sfBool visible)
 Show or hide the mouse cursor. More...
 
CSFML_WINDOW_API void sfWindow_setMouseCursorGrabbed (sfWindow *window, sfBool grabbed)
 Grab or release the mouse cursor. More...
 
CSFML_WINDOW_API void sfWindow_setKeyRepeatEnabled (sfWindow *window, sfBool enabled)
 Enable or disable automatic key-repeat. More...
 
CSFML_WINDOW_API void sfWindow_setFramerateLimit (sfWindow *window, unsigned int limit)
 Limit the framerate to a maximum fixed frequency. More...
 
CSFML_WINDOW_API void sfWindow_setJoystickThreshold (sfWindow *window, float threshold)
 Change the joystick threshold. More...
 
CSFML_WINDOW_API sfBool sfWindow_setActive (sfWindow *window, sfBool active)
 Activate or deactivate a window as the current target for OpenGL rendering. More...
 
CSFML_WINDOW_API void sfWindow_requestFocus (sfWindow *window)
 Request the current window to be made the active foreground window. More...
 
CSFML_WINDOW_API sfBool sfWindow_hasFocus (const sfWindow *window)
 Check whether the window has the input focus. More...
 
CSFML_WINDOW_API void sfWindow_display (sfWindow *window)
 Display on screen what has been rendered to the window so far. More...
 
CSFML_WINDOW_API sfWindowHandle sfWindow_getSystemHandle (const sfWindow *window)
 Get the OS-specific handle of the window. More...
 

Enumeration Type Documentation

◆ sfContextAttribute

Enumeration of the context attribute flags.

Enumerator
sfContextDefault 

Non-debug, compatibility context (this and the core attribute are mutually exclusive)

sfContextCore 

Core attribute.

sfContextDebug 

Debug attribute.

Definition at line 58 of file Window/Window.h.

◆ sfWindowStyle

Enumeration of window creation styles.

Enumerator
sfNone 

No border / title bar (this flag and all others are mutually exclusive)

sfTitlebar 

Title bar + fixed border.

sfResize 

Titlebar + resizable border + maximize button.

sfClose 

Titlebar + close button.

sfFullscreen 

Fullscreen mode (this flag and all others are mutually exclusive)

sfDefaultStyle 

Default window style.

Definition at line 43 of file Window/Window.h.

Function Documentation

◆ sfWindow_close()

CSFML_WINDOW_API void sfWindow_close ( sfWindow window)

Close a window and destroy all the attached resources.

After calling this function, the sfWindow object remains valid, you must call sfWindow_destroy to actually delete it. All other functions such as sfWindow_pollEvent or sfWindow_display will still work (i.e. you don't have to test sfWindow_isOpen every time), and will have no effect on closed windows.

Parameters
windowWindow object

◆ sfWindow_create()

CSFML_WINDOW_API sfWindow* sfWindow_create ( sfVideoMode  mode,
const char *  title,
sfUint32  style,
const sfContextSettings settings 
)

Construct a new window.

This function creates the window with the size and pixel depth defined in mode. An optional style can be passed to customize the look and behaviour of the window (borders, title bar, resizable, closable, ...). If style contains sfFullscreen, then mode must be a valid video mode.

The fourth parameter is a pointer to a structure specifying advanced OpenGL context settings such as antialiasing, depth-buffer bits, etc.

Parameters
modeVideo mode to use (defines the width, height and depth of the rendering area of the window)
titleTitle of the window
styleWindow style
settingsAdditional settings for the underlying OpenGL context
Returns
A new sfWindow object

◆ sfWindow_createFromHandle()

CSFML_WINDOW_API sfWindow* sfWindow_createFromHandle ( sfWindowHandle  handle,
const sfContextSettings settings 
)

Construct a window from an existing control.

Use this constructor if you want to create an OpenGL rendering area into an already existing control.

The second parameter is a pointer to a structure specifying advanced OpenGL context settings such as antialiasing, depth-buffer bits, etc.

Parameters
handlePlatform-specific handle of the control
settingsAdditional settings for the underlying OpenGL context
Returns
A new sfWindow object

◆ sfWindow_createUnicode()

CSFML_WINDOW_API sfWindow* sfWindow_createUnicode ( sfVideoMode  mode,
const sfUint32 title,
sfUint32  style,
const sfContextSettings settings 
)

Construct a new window (with a UTF-32 title)

This function creates the window with the size and pixel depth defined in mode. An optional style can be passed to customize the look and behaviour of the window (borders, title bar, resizable, closable, ...). If style contains sfFullscreen, then mode must be a valid video mode.

The fourth parameter is a pointer to a structure specifying advanced OpenGL context settings such as antialiasing, depth-buffer bits, etc.

Parameters
modeVideo mode to use (defines the width, height and depth of the rendering area of the window)
titleTitle of the window (UTF-32)
styleWindow style
settingsAdditional settings for the underlying OpenGL context
Returns
A new sfWindow object

◆ sfWindow_destroy()

CSFML_WINDOW_API void sfWindow_destroy ( sfWindow window)

Destroy a window.

Parameters
windowWindow to destroy

◆ sfWindow_display()

CSFML_WINDOW_API void sfWindow_display ( sfWindow window)

Display on screen what has been rendered to the window so far.

This function is typically called after all OpenGL rendering has been done for the current frame, in order to show it on screen.

Parameters
windowWindow object

◆ sfWindow_getPosition()

CSFML_WINDOW_API sfVector2i sfWindow_getPosition ( const sfWindow window)

Get the position of a window.

Parameters
windowWindow object
Returns
Position in pixels

◆ sfWindow_getSettings()

CSFML_WINDOW_API sfContextSettings sfWindow_getSettings ( const sfWindow window)

Get the settings of the OpenGL context of a window.

Note that these settings may be different from what was passed to the sfWindow_create function, if one or more settings were not supported. In this case, SFML chose the closest match.

Parameters
windowWindow object
Returns
Structure containing the OpenGL context settings

◆ sfWindow_getSize()

CSFML_WINDOW_API sfVector2u sfWindow_getSize ( const sfWindow window)

Get the size of the rendering region of a window.

The size doesn't include the titlebar and borders of the window.

Parameters
windowWindow object
Returns
Size in pixels

◆ sfWindow_getSystemHandle()

CSFML_WINDOW_API sfWindowHandle sfWindow_getSystemHandle ( const sfWindow window)

Get the OS-specific handle of the window.

The type of the returned handle is sfWindowHandle, which is a typedef to the handle type defined by the OS. You shouldn't need to use this function, unless you have very specific stuff to implement that SFML doesn't support, or implement a temporary workaround until a bug is fixed.

Parameters
windowWindow object
Returns
System handle of the window

◆ sfWindow_hasFocus()

CSFML_WINDOW_API sfBool sfWindow_hasFocus ( const sfWindow window)

Check whether the window has the input focus.

At any given time, only one window may have the input focus to receive input events such as keystrokes or most mouse events.

Returns
True if window has focus, false otherwise

◆ sfWindow_isOpen()

CSFML_WINDOW_API sfBool sfWindow_isOpen ( const sfWindow window)

Tell whether or not a window is opened.

This function returns whether or not the window exists. Note that a hidden window (sfWindow_setVisible(sfFalse)) will return sfTrue.

Parameters
windowWindow object
Returns
sfTrue if the window is opened, sfFalse if it has been closed

◆ sfWindow_pollEvent()

CSFML_WINDOW_API sfBool sfWindow_pollEvent ( sfWindow window,
sfEvent event 
)

Pop the event on top of event queue, if any, and return it.

This function is not blocking: if there's no pending event then it will return false and leave event unmodified. Note that more than one event may be present in the event queue, thus you should always call this function in a loop to make sure that you process every pending event.

Parameters
windowWindow object
eventEvent to be returned
Returns
sfTrue if an event was returned, or sfFalse if the event queue was empty

◆ sfWindow_requestFocus()

CSFML_WINDOW_API void sfWindow_requestFocus ( sfWindow window)

Request the current window to be made the active foreground window.

At any given time, only one window may have the input focus to receive input events such as keystrokes or mouse events. If a window requests focus, it only hints to the operating system, that it would like to be focused. The operating system is free to deny the request. This is not to be confused with sfWindow_setActive().

◆ sfWindow_setActive()

CSFML_WINDOW_API sfBool sfWindow_setActive ( sfWindow window,
sfBool  active 
)

Activate or deactivate a window as the current target for OpenGL rendering.

A window is active only on the current thread, if you want to make it active on another thread you have to deactivate it on the previous thread first if it was active. Only one window can be active on a thread at a time, thus the window previously active (if any) automatically gets deactivated. This is not to be confused with sfWindow_requestFocus().

Parameters
windowWindow object
activesfTrue to activate, sfFalse to deactivate
Returns
sfTrue if operation was successful, sfFalse otherwise

◆ sfWindow_setFramerateLimit()

CSFML_WINDOW_API void sfWindow_setFramerateLimit ( sfWindow window,
unsigned int  limit 
)

Limit the framerate to a maximum fixed frequency.

If a limit is set, the window will use a small delay after each call to sfWindow_display to ensure that the current frame lasted long enough to match the framerate limit.

Parameters
windowWindow object
limitFramerate limit, in frames per seconds (use 0 to disable limit)

◆ sfWindow_setIcon()

CSFML_WINDOW_API void sfWindow_setIcon ( sfWindow window,
unsigned int  width,
unsigned int  height,
const sfUint8 pixels 
)

Change a window's icon.

pixels must be an array of width x height pixels in 32-bits RGBA format.

Parameters
windowWindow object
widthIcon's width, in pixels
heightIcon's height, in pixels
pixelsPointer to the array of pixels in memory

◆ sfWindow_setJoystickThreshold()

CSFML_WINDOW_API void sfWindow_setJoystickThreshold ( sfWindow window,
float  threshold 
)

Change the joystick threshold.

The joystick threshold is the value below which no JoyMoved event will be generated.

Parameters
windowWindow object
thresholdNew threshold, in the range [0, 100]

◆ sfWindow_setKeyRepeatEnabled()

CSFML_WINDOW_API void sfWindow_setKeyRepeatEnabled ( sfWindow window,
sfBool  enabled 
)

Enable or disable automatic key-repeat.

If key repeat is enabled, you will receive repeated KeyPress events while keeping a key pressed. If it is disabled, you will only get a single event when the key is pressed.

Key repeat is enabled by default.

Parameters
windowWindow object
enabledsfTrue to enable, sfFalse to disable

◆ sfWindow_setMouseCursorGrabbed()

CSFML_WINDOW_API void sfWindow_setMouseCursorGrabbed ( sfWindow window,
sfBool  grabbed 
)

Grab or release the mouse cursor.

If set, grabs the mouse cursor inside this window's client area so it may no longer be moved outside its bounds. Note that grabbing is only active while the window has focus and calling this function for fullscreen windows won't have any effect (fullscreen windows always grab the cursor).

Parameters
grabbedsfTrue to enable, sfFalse to disable

◆ sfWindow_setMouseCursorVisible()

CSFML_WINDOW_API void sfWindow_setMouseCursorVisible ( sfWindow window,
sfBool  visible 
)

Show or hide the mouse cursor.

Parameters
windowWindow object
visiblesfTrue to show, sfFalse to hide

◆ sfWindow_setPosition()

CSFML_WINDOW_API void sfWindow_setPosition ( sfWindow window,
sfVector2i  position 
)

Change the position of a window on screen.

This function only works for top-level windows (i.e. it will be ignored for windows created from the handle of a child window/control).

Parameters
windowWindow object
positionNew position of the window, in pixels

◆ sfWindow_setSize()

CSFML_WINDOW_API void sfWindow_setSize ( sfWindow window,
sfVector2u  size 
)

Change the size of the rendering region of a window.

Parameters
windowWindow object
sizeNew size, in pixels

◆ sfWindow_setTitle()

CSFML_WINDOW_API void sfWindow_setTitle ( sfWindow window,
const char *  title 
)

Change the title of a window.

Parameters
windowWindow object
titleNew title

◆ sfWindow_setUnicodeTitle()

CSFML_WINDOW_API void sfWindow_setUnicodeTitle ( sfWindow window,
const sfUint32 title 
)

Change the title of a window (with a UTF-32 string)

Parameters
windowWindow object
titleNew title

◆ sfWindow_setVerticalSyncEnabled()

CSFML_WINDOW_API void sfWindow_setVerticalSyncEnabled ( sfWindow window,
sfBool  enabled 
)

Enable or disable vertical synchronization.

Activating vertical synchronization will limit the number of frames displayed to the refresh rate of the monitor. This can avoid some visual artifacts, and limit the framerate to a good value (but not constant across different computers).

Parameters
windowWindow object
enabledsfTrue to enable v-sync, sfFalse to deactivate

◆ sfWindow_setVisible()

CSFML_WINDOW_API void sfWindow_setVisible ( sfWindow window,
sfBool  visible 
)

Show or hide a window.

Parameters
windowWindow object
visiblesfTrue to show the window, sfFalse to hide it

◆ sfWindow_waitEvent()

CSFML_WINDOW_API sfBool sfWindow_waitEvent ( sfWindow window,
sfEvent event 
)

Wait for an event and return it.

This function is blocking: if there's no pending event then it will wait until an event is received. After this function returns (and no error occured), the event object is always valid and filled properly. This function is typically used when you have a thread that is dedicated to events handling: you want to make this thread sleep as long as no new event is received.

Parameters
windowWindow object
eventEvent to be returned
Returns
sfFalse if any error occured