SFML-2.3.2.3: SFML bindings

Safe HaskellNone
LanguageHaskell98

SFML.Graphics.RenderWindow

Synopsis

Documentation

createRenderWindow Source

Arguments

:: VideoMode

Video mode to use

-> String

Window title

-> [WindowStyle]

Window style

-> Maybe ContextSettings

Creation settings (Nothing to use default values)

-> IO RenderWindow 

Construct a new render window.

renderWindowFromHandle Source

Arguments

:: WindowHandle

Platform-specific handle of the control

-> Maybe ContextSettings

Creation settings (Nothing to use default values)

-> IO RenderWindow 

Construct a render window from an existing control.

destroy :: SFResource a => a -> IO () Source

Destroy the given SFML resource.

close :: SFWindow a => a -> IO () Source

Close the window.

After calling this function, the window object remains valid; you must call destroy to actually delete it.

isWindowOpen :: SFWindow a => a -> IO Bool Source

Tell whether or not a window is opened

This function returns whether or not the window exists.

Note that a hidden window (setWindowVisible False ) will return True.

getWindowSettings :: SFWindow a => a -> IO ContextSettings Source

Get the settings of the OpenGL context of a window.

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

pollEvent :: SFWindow a => a -> IO (Maybe SFEvent) Source

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 false and leave a event unmodified. Note that more than one 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.

waitEvent :: SFWindow a => a -> IO (Maybe SFEvent) Source

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.

getWindowPosition :: SFWindow a => a -> IO Vec2i Source

Get the position of a window.

setWindowPosition :: SFWindow a => a -> Vec2i -> IO () Source

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

getWindowSize :: SFWindow a => a -> IO Vec2u Source

Get the size of the rendering region of a window.

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

setWindowSize :: SFWindow a => a -> Vec2u -> IO () Source

Change the size of the rendering region of a window.

setWindowTitle :: SFWindow a => a -> String -> IO () Source

Change the title of a window.

setWindowIcon Source

Arguments

:: SFWindow a 
=> a 
-> Int

Icon's width, in pixels

-> Int

Icon's height, in pixels

-> Ptr b

Pixel data

-> IO () 

Change a window's icon.

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

setWindowVisible :: SFWindow a => a -> Bool -> IO () Source

Show or hide a window.

setMouseVisible :: SFWindow a => a -> Bool -> IO () Source

Show or hide the mouse cursor.

setVSync :: SFWindow a => a -> Bool -> IO () Source

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

setKeyRepeat :: SFWindow a => a -> Bool -> IO () Source

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.

setWindowActive :: SFWindow a => a -> Bool -> IO () Source

Activate or deactivate a 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.

requestFocus :: SFWindow a => a -> IO () Source

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

hasFocus :: SFWindow a => a -> IO Bool Source

Check whether the render 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.

display :: SFDisplayable a => a -> IO () Source

Update the target's contents.

setFramerateLimit :: SFWindow a => a -> Int -> IO () Source

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.

setJoystickThreshold :: SFWindow a => a -> Float -> IO () Source

Change the joystick threshold.

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

getSystemHandle :: SFWindow a => a -> IO WindowHandle Source

Get the OS-specific handle of the window.

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

clearRenderWindow Source

Arguments

:: RenderWindow

Render window object

-> Color

Fill color

-> IO () 

Clear a render window with the given color.

setView :: SFViewable a => a -> View -> IO () Source

Change the target's current active view.

getView :: SFViewable a => a -> IO View Source

Get the target's current active view.

getDefaultView :: SFViewable a => a -> IO View Source

Get the target's default view.

getViewport :: SFViewable a => a -> View -> IO IntRect Source

Get the viewport of a view applied to this target, expressed in pixels in the current target.

mapPixelToCoords Source

Arguments

:: SFCoordSpace a 
=> a 
-> Vec2i

Pixel to convert

-> Maybe View

The view to use for converting the point

-> IO Vec2f 

Convert a point to world coordinates

This function finds the 2D position that matches the given pixel of the coord space. 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 coord space, this assertion is not true anymore, ie. a point located at (10, 50) in your coord space may map to the point (150, 75) in your 2D world -- if the view is translated by (140, 25).

This version uses a custom view for calculations, see the other overload of the function if you want to use the current view of the render-texture.

drawSprite Source

Arguments

:: SFRenderTarget a 
=> a 
-> Sprite

Sprite to draw

-> Maybe RenderStates

Render states to use for drawing (Nothing to use the default states)

-> IO () 

Draw a sprite to the render-target.

drawText Source

Arguments

:: SFRenderTarget a 
=> a 
-> Text

Text to draw

-> Maybe RenderStates

Render states to use for drawing (Nothing to use the default states)

-> IO () 

Draw text to the render-target.

drawShape Source

Arguments

:: SFRenderTarget a 
=> a 
-> Shape

Shape to draw

-> Maybe RenderStates

Render states to use for drawing (Nothing to use the default states)

-> IO () 

Draw a sprite to the render-target.

drawCircle Source

Arguments

:: SFRenderTarget a 
=> a 
-> CircleShape

CircleShape to draw

-> Maybe RenderStates

Render states to use for drawing (Nothing to use the default states)

-> IO () 

Draw a sprite to the render-target.

drawConvexShape Source

Arguments

:: SFRenderTarget a 
=> a 
-> ConvexShape

ConvexShape to draw

-> Maybe RenderStates

Render states to use for drawing (Nothing to use the default states)

-> IO () 

Draw a sprite to the render-target.

drawRectangle Source

Arguments

:: SFRenderTarget a 
=> a 
-> RectangleShape

RectangleShape to draw

-> Maybe RenderStates

Render states to use for drawing (Nothing to use the default states)

-> IO () 

Draw a sprite to the render-target.

drawVertexArray Source

Arguments

:: SFRenderTarget a 
=> a 
-> VertexArray

VertexArray to draw

-> Maybe RenderStates

Render states to use for drawing (Nothing to use the default states)

-> IO () 

Draw a sprite to the render-target.

drawPrimitives Source

Arguments

:: SFRenderTarget a 
=> a 
-> [Vertex]

Vertices to render

-> PrimitiveType

Type of primitives to draw

-> Maybe RenderStates

Render states to use for drawing (Nothing to use the default states)

-> IO () 

Draw primitives defined by an array of vertices to a render texture.

drawPrimitives' Source

Arguments

:: SFRenderTarget a 
=> a 
-> Ptr Vertex

Pointer to the vertices

-> Int

Number of vertices in the array

-> PrimitiveType

Type of primitives to draw

-> Maybe RenderStates

Render states to use for drawing (Nothing to use the default states)

-> IO () 

pushGLStates :: SFRenderTarget a => a -> IO () Source

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

popGLStates :: SFRenderTarget a => a -> IO () Source

Restore the previously saved OpenGL render states and matrices.

See the description of pushGLStates to get a detailed description of these functions.

resetGLStates :: SFRenderTarget a => a -> IO () Source

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 pushGLStates or popGLStates. It makes sure that all OpenGL states needed by SFML are set, so that subsequent draw calls will work as expected.

captureRenderWindow :: RenderWindow -> IO Image Source

Copy the current contents of a render window to an image.

This is a slow operation, whose main purpose is to make screenshots of the application. If you want to update an image with the contents of the window and then use it for drawing, you should rather use a Texture and its update(sfWindow*) function.

You can also draw things directly to a texture with the sfRenderWindow class.

getMousePosition :: SFWindow a => Maybe a -> IO Vec2i Source

Get the current position of the mouse

This function returns the current position of the mouse cursor relative to the given window, or desktop if Nothing is passed.

setMousePosition :: SFWindow a => Vec2i -> Maybe a -> IO () Source

Set the current position of the mouse

This function sets the current position of the mouse cursor relative to the given window, or desktop if Nothing is passed.