Struct sfml::graphics::RenderWindow
[−]
[src]
pub struct RenderWindow { /* fields omitted */ }Window that can serve as a target for 2D drawing.
RenderWindow is the main type of the graphics module.
It defines an OS window that can be painted using the other classes
of the graphics module.
Methods
impl RenderWindow[src]
fn new(
mode: VideoMode,
title: &str,
style: Style,
settings: &ContextSettings
) -> Option<RenderWindow>
mode: VideoMode,
title: &str,
style: Style,
settings: &ContextSettings
) -> Option<RenderWindow>
Construct a new render window
This function creates the render 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
FULLSCREEN, 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.
Arguments
- mode - Video mode to use (defines the width, height and depth of the rendering area of the render window)
- title - Title of the render window
- style - Window style
- settings - Additional settings for the underlying OpenGL context
Return Some(RenderWindow) or None
fn set_icon(&mut self, width: u32, height: u32, pixels: &[u8])
Change a render window's icon pixels must be an array of width x height pixels in 32-bits RGBA format.
Arguments
- width - Icon's width, in pixels
- height - Icon's height, in pixels
- pixels - Vector of pixels
fn events(&self) -> Events
Return an iterator over all the event currently in the events queue.
fn poll_event(&mut self) -> Option<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 \a 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.
Return Some(event) if an event was returned, or None if the event queue was empty
fn wait_event(&mut self) -> Option<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.
Return Some(event) or None if an error has occured
fn close(&mut self)
Close a render window and destroy all the attached resources
After calling this method, the Window object remains valid. All other functions such as poll_event or display will still work (i.e. you don't have to test is_open every time), and will have no effect on closed windows.
fn is_open(&self) -> bool
Tell whether or not a window is opened
This function returns whether or not the window exists. Note that a hidden window (set_visible(false)) will return true.
fn display(&mut self)
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.
fn set_framerate_limit(&mut self, limit: u32)
Limit the framerate to a maximum fixed frequency
If a limit is set, the window will use a small delay after
each call to RenderWindow::display to ensure that the current frame
lasted long enough to match the framerate limit.
Arguments
- limit - Framerate limit, in frames per seconds (use 0 to disable limit)
fn settings(&self) -> ContextSettings
Get the settings of the OpenGL context of a window
Note that these settings may be different from what was
passed to the RenderWindow::create function,
if one or more settings were not supported. In this case,
SFML chose the closest match.
Return a structure containing the OpenGL context settings
fn set_title(&mut self, title: &str)
fn set_visible(&mut self, visible: bool)
fn set_mouse_cursor_visible(&mut self, visible: bool)
fn set_mouse_cursor_grabbed(&mut self, grabbed: bool)
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.
fn set_vertical_sync_enabled(&mut self, enabled: bool)
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).
Arguments
- enabled - true to enable v-sync, false to deactivate
fn set_key_repeat_enabled(&mut self, enabled: bool)
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.
Arguments
- enabled - true to enable, false to disable
fn set_active(&mut self, enabled: bool) -> bool
Activate or deactivate a render 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.
Arguments
- active - true to activate, false to deactivate
Return true if operation was successful, false otherwise
fn set_joystick_threshold(&mut self, threshold: f32)
Change the joystick threshold
The joystick threshold is the value below which no JoyMoved event will be generated.
Arguments
- threshold - New threshold, in the range [0, 100]
fn position(&self) -> Vector2i
Get the position of a window
Return the position in pixels
fn set_position(&mut self, position: &Vector2i)
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).
Arguments
- position - New position of the window, in pixels
fn set_size(&mut self, size: &Vector2u)
fn set_size2u(&mut self, size_x: u32, size_y: u32)
Change the size of the rendering region of a window
Arguments
- size_x - New size x, in pixels
- size_y - New size x, in pixels
fn mouse_position(&self) -> Vector2i
Returns the current position of the mouse relative to the window.
fn set_mouse_position(&mut self, position: &Vector2i)
Set the current position of the mouse relatively to a render window
This function sets the current position of the mouse cursor relative to the given render window
Arguments
position- the positon to set
fn touch_position(&self, finger: u32) -> Vector2i
Returns the current position of a touch in window coordinates.
fn has_focus(&self) -> bool
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.
fn request_focus(&self)
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 set_active().
Trait Implementations
impl Raw for RenderWindow[src]
type Raw = *const sfRenderWindow
The raw representation of this type.
fn raw(&self) -> Self::Raw
Acquires the raw representation of this type through &self.
impl RenderTarget for RenderWindow[src]
fn push_gl_states(&mut self)
Save the current OpenGL render states and matrices
This function can be used when you mix SFML drawing and direct OpenGL rendering. Combined with popGLStates, it ensures that: SFML's internal states are not messed up by your OpenGL code and that your OpenGL states are not modified by a call to a SFML function
Note that this function is quite expensive: it saves all the possible OpenGL states and matrices, even the ones you don't care about. Therefore it should be used wisely. It is provided for convenience, but the best results will be achieved if you handle OpenGL states yourself (because you know which states have really changed, and need to be saved and restored). Take a look at the resetGLStates function if you do so.
fn pop_gl_states(&mut self)
Restore the previously saved OpenGL render states and matrices
fn reset_gl_states(&mut self)
Reset the internal OpenGL states so that the target is ready for drawing
This function can be used when you mix SFML drawing and direct OpenGL rendering, if you choose not to use push_gl_states/pop_gl_states. It makes sure that all OpenGL states needed by SFML are set, so that subsequent draw() calls will work as expected.
fn set_view(&mut self, view: &View)
fn view(&self) -> &ViewRef
Get the current active view of a render window
Return the current active view
fn default_view(&self) -> &ViewRef
Get the default view of a render window
Return the default view of the render window
fn map_pixel_to_coords(&self, point: &Vector2i, view: &View) -> Vector2f
Convert a point from window coordinates to world coordinates
This function finds the 2D position that matches the given pixel of the render-window. In other words, it does the inverse of what the graphics card does, to find the initial position of a rendered pixel.
Initially, both coordinate systems (world units and target pixels) match perfectly. But if you define a custom view or resize your render window, this assertion is not true anymore, ie. a point located at (10, 50) in your render-window may map to the point (150, 75) in your 2D world -- if the view is translated by (140, 25).
This function is typically used to find which point (or object) is located below the mouse cursor.
This version uses a custom view for calculations, see the map_pixel_to_coords_current_view function if you want to use the current view of the render-window.
Arguments
- point - Pixel to convert
- view - The view to use for converting the point
Return the converted point, in "world" units
fn map_pixel_to_coords_current_view(&self, point: &Vector2i) -> Vector2f
Convert a point from window coordinates to world coordinates
This function finds the 2D position that matches the given pixel of the render-window. In other words, it does the inverse of what the graphics card does, to find the initial position of a rendered pixel.
Initially, both coordinate systems (world units and target pixels) match perfectly. But if you define a custom view or resize your render window, this assertion is not true anymore, ie. a point located at (10, 50) in your render-window may map to the point (150, 75) in your 2D world -- if the view is translated by (140, 25).
This function is typically used to find which point (or object) is located below the mouse cursor.
This version uses the current view for calculations, see the map_pixel_to_coords function if you want to use a custom view.
Arguments
- point - Pixel to convert
Return the converted point, in "world" units
fn map_coords_to_pixel(&self, point: &Vector2f, view: &View) -> Vector2i
Convert a point from world coordinates to window coordinates
This function finds the pixel of the render-window that matches the given 2D point. In other words, it goes through the same process as the graphics card, to compute the final position of a rendered point.
Initially, both coordinate systems (world units and target pixels) match perfectly. But if you define a custom view or resize your render window, this assertion is not true anymore, ie. a point located at (150, 75) in your 2D world may map to the pixel (10, 50) of your render-window -- if the view is translated by (140, 25).
This version uses a custom view for calculations, see map_coords_to_pixel_current_view if you want to use the current view of the render-window.
Arguments
- point - Point to convert
- view - The view to use for converting the point
fn map_coords_to_pixel_current_view(&self, point: &Vector2f) -> Vector2i
Convert a point from world coordinates to window coordinates
This function finds the pixel of the render-window that matches the given 2D point. In other words, it goes through the same process as the graphics card, to compute the final position of a rendered point.
Initially, both coordinate systems (world units and target pixels) match perfectly. But if you define a custom view or resize your render window, this assertion is not true anymore, ie. a point located at (150, 75) in your 2D world may map to the pixel (10, 50) of your render-window -- if the view is translated by (140, 25).
This version uses the current view for calculations, see map_coords_to_pixel if you want to use a custom view.
Arguments
- point - Point to convert
fn viewport(&self, view: &View) -> IntRect
Get the viewport of a view applied to this target
Arguments
- view - Target view
Return the viewport rectangle, expressed in pixels in the current target
fn size(&self) -> Vector2u
Get the size of the rendering region of a window
The size doesn't include the titlebar and borders of the window.
Return the size in pixels
fn draw(&mut self, object: &Drawable)
fn draw_with_renderstates(
&mut self,
object: &Drawable,
render_states: RenderStates
)
&mut self,
object: &Drawable,
render_states: RenderStates
)
Draw a drawable object to the render-target with a RenderStates
Arguments
- object - Object to draw
- renderStates - The renderStates to associate to the object
fn draw_text(&self, text: &Text, render_states: RenderStates)
Draw a Text with a RenderStates
fn draw_shape(&self, shape: &CustomShape, render_states: RenderStates)
Draw a Shape with a RenderStates
fn draw_sprite(&self, sprite: &Sprite, render_states: RenderStates)
Draw a sprite with a RenderStates
fn draw_circle_shape(
&self,
circle_shape: &CircleShape,
render_states: RenderStates
)
&self,
circle_shape: &CircleShape,
render_states: RenderStates
)
Draw a CircleShape with a RenderStates
fn draw_rectangle_shape(
&self,
rectangle_shape: &RectangleShape,
render_states: RenderStates
)
&self,
rectangle_shape: &RectangleShape,
render_states: RenderStates
)
Draw a RectangleShape with a RenderStates
fn draw_convex_shape(
&self,
convex_shape: &ConvexShape,
render_states: RenderStates
)
&self,
convex_shape: &ConvexShape,
render_states: RenderStates
)
Draw a ConvexShape with a RenderStates
fn draw_vertex_array(
&self,
vertex_array: &VertexArray,
render_states: RenderStates
)
&self,
vertex_array: &VertexArray,
render_states: RenderStates
)
Draw a VertexArray with a RenderStates
fn draw_primitives(
&self,
vertices: &[Vertex],
ty: PrimitiveType,
rs: RenderStates
)
&self,
vertices: &[Vertex],
ty: PrimitiveType,
rs: RenderStates
)
draw primitives
fn clear(&mut self, color: &Color)
Clear window with the given color