Window

sfml.window.Window
See theWindow companion object
trait Window(using ctor: ctor) extends WindowBase

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

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.

// Declare and create a new window
val window = Window(VideoMode((800, 600)), "SFML window")

// Limit the framerate to 60 frames per second (this step is optional)
window.framerateLimit = 60;

// The main loop - ends as soon as the window is closed
while window.isOpen() do
   // Event processing
   for event <- window.pollEvent() do
       event match
           // Request for closing the window
           case Event.Closed() => window.close()
           case _              => ()



   // End the current frame and display its contents on screen
   window.display()

Attributes

Companion
object
Graph
Supertypes
trait WindowBase
class Object
trait Matchable
class Any
Known subtypes
trait RenderWindow

Members list

Value members

Concrete methods

def activate(active: Boolean = ...): Boolean

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

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.

Value parameters

active

true to activate, false to deactivate

Attributes

Returns

true if operation was successful, false otherwise

override def close(): Unit

Attributes

Definition Classes
def display(): Unit

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

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.

Attributes

def framerateLimit: Unit
def framerateLimit_=(limit: Int): Unit

Limit the framerate to a maximum fixed frequency.

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 sleep, whose precision depends on the underlying OS, the results may be a little imprecise as well (for example, you can get 65 FPS when requesting 60).

Value parameters

limit

Framerate limit, in frames per seconds (use 0 to disable limit)

Attributes

Get the settings of the OpenGL context of the window.

Get the settings of the OpenGL context of the window.

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

Attributes

Returns

Structure containing the OpenGL context settings

def verticalSync: Unit
def verticalSync_=(enabled: Boolean): Unit

Enable or disable vertical synchronization.

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.

Value parameters

enabled

true to enable v-sync, false to deactivate it

Attributes

Inherited methods

def hasFocus: Boolean

Attributes

Inherited from:
WindowBase
def isOpen(): Boolean

Attributes

Inherited from:
WindowBase
def pollEvent(): Iterator[Event]

Attributes

Inherited from:
WindowBase
def position: Vector2[Int]

Attributes

Inherited from:
WindowBase
def position_=(position: Immutable[Vector2[Int]]): Unit

Attributes

Inherited from:
WindowBase
def size: Vector2[Int]

Attributes

Inherited from:
WindowBase
def size_=(size: Immutable[Vector2[Int]]): Unit

Attributes

Inherited from:
WindowBase