Window

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

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 render-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
class Object
trait Matchable
class Any
Known subtypes
trait RenderWindow

Members list

Value members

Concrete methods

def close(): Unit
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 unprecise 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

def isOpen(): Boolean

Tell whether or not the window is open.

Tell whether or not the window is open.

This function returns whether or not the window exists.

Attributes

Returns

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

def mouseCursorVisible: Unit
def mouseCursorVisible_=(visible: Boolean): Unit

Show or hide the mouse cursor.

Show or hide the mouse cursor.

The mouse cursor is visible by default.

Value parameters

visible

True to show the mouse cursor, false to hide it

Attributes

def pollEvent(): LazyList[Event]

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

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 the list of events is empty.

val window: Window = ???

for event <- window.pollEvent() do
   event match
       // process event...
       case _ => ()

Value parameters

event

Event to be returned

Attributes

Returns

A lazy list of events

def size: Vector2[Int]

Get the size of the rendering region of the window.

Get the size of the rendering region of the window.

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

Attributes

Returns

Size in pixels

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