Class | SFML::Window |
In: |
window/main.cpp
|
Parent: | Object |
SFML::Window is the main class of the Window module.
It defines an OS window that is able to receive an OpenGL rendering.
A SFML::Window can create its own new window, but using an already created window trough a handle is not supported in the ruby bindings yet.
The SFML::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 getEvent() function, and real-time state handling with its attached SFML::Input object (see getInput()).
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 SFML::ContextSettings structure which is passed as an optional argument when creating the window.
Usage example:
# Declare and create a new window window = SFML::Window.new( SFML::VideoMode.new( 800, 600 ), "SFML window" ) # Limit the framerate to 60 frames per second (this step is optional) window.setFramerateLimit( 60 ); # The main loop - ends as soon as the window is closed while window.open? # Event processing while event = window.getEvent # Request for closing the window if event.type == SFML::Event::Closed window.close() end end # Activate the window for OpenGL rendering window.setActive() # OpenGL drawing commands go here... # End the current frame and display its contents on screen window.display() end
getFrameTime | -> | frameTime |
getFrameTime | -> | frame_time |
Close the window and destroy all the attached resources.
After calling this function, the SFML::Window instance remains valid and you can call SFML::Window#create to recreate the window. All other functions such as getEvent or display will still work (i.e. you don‘t have to test isOpened every time), and will have no effect on closed windows.
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.
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.
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.
Pop the event on top of events stack, if any, and return it.
This function is not blocking: if there‘s no pending event then it will return nil. Note that more than the returned event may be present in the events stack, thus you should always call this function in a loop to make sure that you process every pending event.
This input gives access to the real-time state of keyboard, mouse and joysticks for this window
This function returns whether or not the window exists. Note that a hidden window (Show(false)) will return true.
Change the position of the 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).
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.
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.
Change the window‘s icon.
pixels must be an array of width x height pixels in 32-bits RGBA format. In the ruby binding the array will be flattened so you can have array‘s up to 3 dimensions(or more) to represent each pixel component. The size of the array will be assumed to be width * height * 4.
The OS default icon is used by default.
Usage example:
pixels = [ [[255, 0, 0, 255], [0, 0, 255, 255]], [[0, 255, 0, 255], [0, 0, 0, 255]] ] window.setIcon( 2, 2, pixels )
Change the joystick threshold.
The joystick threshold is the value below which no JoyMoved event will be generated.
The threshold value is 0.1 by default. The threshold has to be in the range 0..100
Change the position of the 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).
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.
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.