View on GitHub

DSFML

dsfml.window.window



class Window;
Window that serves as a target for OpenGL rendering.

Window is the main class of the Window module.

It defines an OS window that is able to receive an OpenGL rendering.

A Window can create its own new window, or be embedded into an already existing control using the create(handle) function. This can be useful for embedding an OpenGL rendering area into a view which is part of a bigger GUI with existing windows, controls, etc. It can also serve as embedding an OpenGL rendering area into a window created by another (probably richer) GUI library like Qt or wxWidgets.

The Window class provides a simple interface for manipulating the window: move, resize, show/hide, control mouse cursor, etc. It also provides event handling through its pollEvent() and waitEvent() functions.

Note that OpenGL experts can pass their own parameters (antialiasing level, bits for the depth and stencil buffers, etc.) to the OpenGL context attached to the window, with the ContextSettings structure which is passed as an optional argument when creating the window.

this(T)(VideoMode mode, immutable(T)[] title, Style style = Style.DefaultStyle, ref const(ContextSettings) settings = ContextSettings.Default) if (is(T == dchar) || is(T == wchar) || is(T == char));
Construct a new window.

This constructor 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 Style::Fullscreen, then mode must be a valid video mode.





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





Params:
VideoMode mode Video mode to use (defines the width, height and depth of the rendering area of the window).
immutable(T)[] title Title of the window.
Style style Window style.
const(ContextSettings) settings Additional settings for the underlying OpenGL context.

this(WindowHandle handle, ref const(ContextSettings) settings = ContextSettings.Default);
Construct the 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 an optional structure specifying advanced OpenGL context settings such as antialiasing, depth-buffer bits, etc.





Params:
WindowHandle handle Platform-specific handle of the control.
const(ContextSettings) settings Additional settings for the underlying OpenGL context.

@property Vector2i position(Vector2i newPosition);
Get's or set's the window's position.

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).

@property Vector2i position();
Get's or set's the window's position.

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).

@property Vector2u size(Vector2u newSize);
Get's or set's the window's size.

@property Vector2u size();
Get's or set's the window's size.

bool setActive(bool active);
Activate or deactivate the 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.





Params:
bool active True to activate, false to deactivate.

Returns:
True if operation was successful, false otherwise.

void setFramerateLimit(uint 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 display() to ensure that the current frame lasted long enough to match the framerate limit. SFML will try to match the given limit as much as it can, but since it internally uses sf::sleep, whose precision depends on the underlying OS, the results may be a little unprecise as well (for example, you can get 65 FPS when requesting 60).





Params:
uint limit Framerate limit, in frames per seconds (use 0 to disable limit).

void setIcon(uint width, uint height, const(ubyte[]) pixels);
Change the window's icon.

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





The OS default icon is used by default.





Params:
uint width Icon's width, in pixels.
uint height Icon's height, in pixels.
const(ubyte[]) pixels Pointer to the array of pixels in memory.

void setJoystickThreshhold(float threshhold);
Change the joystick threshold.

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





The threshold value is 0.1 by default.





Params:
threshold New threshold, in the range [0, 100].

void setKeyRepeatEnabled(bool enabled);
Enable or disable automatic key-repeat.

If key repeat is enabled, you will receive repeated KeyPressed 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.





Params:
bool enabled True to enable, false to disable.

void setMouseCursorVisible(bool visible);
Show or hide the mouse cursor.

The mouse cursor is visible by default.





Params:
bool visible True to show the mouse cursor, false to hide it.

void setTitle(string newTitle);
Change the title of the window.

Params:
title New title.

void setTitle(wstring newTitle);
Change the title of the window.

Params:
title New title.

void setTitle(dstring newTitle);
Change the title of the window.

Params:
title New title.

void setVisible(bool visible);
Show or hide the window.

The window is shown by default.





Params:
bool visible True to show the window, false to hide it.

void setVerticalSyncEnabled(bool 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).





Vertical synchronization is disabled by default.





Params:
bool enabled True to enable v-sync, false to deactivate it.

const ContextSettings getSettings();
Get the settings of the OpenGL context of the window.

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





Returns:
Structure containing the OpenGL context settings.

const WindowHandle getSystemHandle();
Get the OS-specific handle of the window.

The type of the returned handle is sf::WindowHandle, 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.





Returns:
System handle of the window.

void close();
Close the window and destroy all the attached resources.

After calling this function, the Window instance remains valid and you can call create() to recreate the window. All other functions such as pollEvent() or display() will still work (i.e. you don't have to test isOpen() every time), and will have no effect on closed windows.

void create(VideoMode mode, string title, Style style = Style.DefaultStyle, ref const(ContextSettings) settings = ContextSettings.Default);
Create (or recreate) the window.

If the window was already created, it closes it first. If style contains Style::Fullscreen, then mode must be a valid video mode.





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

void create(VideoMode mode, wstring title, Style style = Style.DefaultStyle, ref const(ContextSettings) settings = ContextSettings.Default);
Create (or recreate) the window.

If the window was already created, it closes it first. If style contains Style::Fullscreen, then mode must be a valid video mode.





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

void create(VideoMode mode, dstring title, Style style = Style.DefaultStyle, ref const(ContextSettings) settings = ContextSettings.Default);
Create (or recreate) the window.

If the window was already created, it closes it first. If style contains Style::Fullscreen, then mode must be a valid video mode.





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

void create(WindowHandle handle, ref const(ContextSettings) settings = ContextSettings.Default);
Create (or recreate) the window from an existing control.

Use this function if you want to create an OpenGL rendering area into an already existing control. If the window was already created, it closes it first.





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

void display();
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.

bool isOpen();
Tell whether or not the window is open.

This function returns whether or not the window exists. Note that a hidden window (setVisible(false)) is open (therefore this function would return true).





Returns:
True if the window is open, false if it has been closed.

bool pollEvent(ref Event event);
Pop the event on top of the 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.





Params:
Event event Event to be returned.

Returns:
True if an event was returned, or false if the event queue was empty.

bool waitEvent(ref Event 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.





Params:
Event event Event to be returned.

Returns:
False if any error occured.