SFML - Simple and Fast Multimedia Library

  • Main Page
  • Namespaces
  • Classes
  • Files

SFML Documentation

1.6

Welcome

Welcome to the official SFML documentation. Here you will find a detailed view of all the SFML classes, as well as source files.
If you are looking for tutorials, you can visit the official website at www.sfml-dev.org.

Short example

Here is a short example, to show you how simple it is to use SFML :

 #include <SFML/Audio.hpp>
 #include <SFML/Graphics.hpp>

 int main()
 {
     // Create the main window
     sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");

     // Load a sprite to display
     sf::Image Image;
     if (!Image.LoadFromFile("cute_image.jpg"))
         return EXIT_FAILURE;
     sf::Sprite Sprite(Image);

     // Create a graphical string to display
     sf::Font Arial;
     if (!Arial.LoadFromFile("arial.ttf"))
         return EXIT_FAILURE;
     sf::String Text("Hello SFML", Arial, 50);

     // Load a music to play
     sf::Music Music;
     if (!Music.OpenFromFile("nice_music.ogg"))
         return EXIT_FAILURE;

     // Play the music
     Music.Play();

     // Start the game loop
     while (App.IsOpened())
     {
         // Process events
         sf::Event Event;
         while (App.GetEvent(Event))
         {
             // Close window : exit
             if (Event.Type == sf::Event::Closed)
                 App.Close();
         }

         // Clear screen
         App.Clear();

         // Draw the sprite
         App.Draw(Sprite);

         // Draw the string
         App.Draw(Text);

         // Update the window
         App.Display();
     }

     return EXIT_SUCCESS;
 }

:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::


  • Files
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members

Class List

Here are the classes, structs, unions and interfaces with brief descriptions:
sf::AudioResource | Abstract base class for every class that owns a device-dependant resource -- allow them to initialize / shutdown even when the audio context is not created
sf::Clock | Clock is an utility class for manipulating time
sf::Color | Color is an utility class for manipulating 32-bits RGBA colors
sf::Context | Class wrapping an OpenGL context
sf::Drawable | Abstract base class for every object that can be drawn into a render window
sf::Event | Event defines a system event and its parameters
sf::Event::Event::JoyButtonEvent | Joystick buttons events parameters
sf::Event::Event::JoyMoveEvent | Joystick axis move event parameters
sf::Event::Event::KeyEvent | Keyboard event parameters
sf::Event::Event::MouseButtonEvent | Mouse buttons events parameters
sf::Event::Event::MouseMoveEvent | Mouse move event parameters
sf::Event::Event::MouseWheelEvent | Mouse wheel events parameters
sf::Event::Event::SizeEvent | Size events parameters
sf::Event::Event::TextEvent | Text event parameters
sf::Font | Font is the low-level class for loading and manipulating character fonts
sf::Ftp | This class provides methods for manipulating the FTP protocol (described in RFC 959)
sf::Ftp::Ftp::DirectoryResponse | Specialization of FTP response returning a directory
sf::Ftp::Ftp::ListingResponse | Specialization of FTP response returning a filename lisiting
sf::Ftp::Ftp::Response This class wraps a FTP response, which is basically :
  • a status code
  • a message
sf::Glyph | Structure describing a glyph (a visual character)
sf::Http | This class provides methods for manipulating the HTTP protocol (described in RFC 1945)
sf::Http::Http::Request This class wraps an HTTP request, which is basically :
  • a header with a method, a target URI, and a set of field/value pairs
  • an optional body (for POST requests)
sf::Http::Http::Response This class wraps an HTTP response, which is basically :
  • a header with a status code and a set of field/value pairs
  • a body (the content of the requested resource)
sf::Image | Image is the low-level class for loading and manipulating images
sf::Input | Input handles real-time input from keyboard and mouse
sf::IPAddress | IPAddress provides easy manipulation of IP v4 addresses
sf::Listener | Listener is a global interface for defining the audio listener properties ; the audio listener is the point in the scene from where all the sounds are heard
sf::Lock | Lock is an exception-safe automatic wrapper for locking and unlocking mutexes
sf::Matrix3 | Utility class to manipulate 3x3 matrices representing 2D transformations
sf::Music | Music defines a big sound played using streaming, so usually what we call a music :)
sf::Mutex | Mutex defines a mutex (MUTual EXclusion) object, that allows a thread to lock critical instructions to avoid simultaneous access with other threads
sf::NonCopyable | Utility base class to easily declare non-copyable classes
sf::Packet | Packet wraps data to send / to receive through the network
sf::PostFX | PostFX is used to apply a post effect to a window
sf::Randomizer | Randomizer is an utility class for generating pseudo-random numbers
sf::Rect< T > | Rect is an utility class for manipulating rectangles
sf::RenderTarget | Base class for all render targets (window, image,
sf::RenderWindow | Simple wrapper for sf::Window that allows easy 2D rendering
sf::Resource< T > | Base class for every resource that needs to notify dependent classes about its destruction
sf::ResourcePtr< T > | Safe pointer to a T resource (inheriting from sf::Resource<T>), its pointer is automatically reseted when the resource is destroyed
sf::Selector< Type > | Selector allow reading from multiple sockets without blocking
sf::SelectorBase | Private base class for selectors
sf::Shape | Shape defines a drawable convex shape ; it also defines helper functions to draw simple shapes like lines, rectangles, circles, etc
sf::SocketHelper | This class defines helper functions to do all the non-portable socket stuff
sf::SocketTCP | SocketTCP wraps a socket using TCP protocol to send data safely (but a bit slower)
sf::SocketUDP | SocketUDP wraps a socket using UDP protocol to send data fastly (but with less safety)
sf::Sound | Sound defines the properties of a sound such as position, volume, pitch, etc
sf::SoundBuffer | SoundBuffer is the low-level for loading and manipulating sound buffers
sf::SoundBufferRecorder | Specialized SoundRecorder which saves the captured audio data into a sound buffer
sf::SoundRecorder | SoundRecorder is an interface for capturing sound data, it is meant to be used as a base class
sf::SoundStream | SoundStream is a streamed sound, ie samples are acquired while the sound is playing
sf::SoundStream::SoundStream::Chunk | Structure defining a chunk of audio data to stream
sf::Sprite | Sprite defines a sprite : texture, transformations, color, and draw on screen
sf::String | String defines a graphical 2D text, that can be drawn on screen
sf::Thread | Thread defines an easy way to manipulate a thread
sf::Unicode | Provides utility functions to convert from and to any unicode and ASCII encoding
sf::Unicode::Unicode::Text | This class is an abstract definition of a unicode text, it can be converted from and to any kind of string and encoding
sf::Vector2< T > | Vector2 is an utility class for manipulating 2 dimensional vectors
sf::Vector3< T > | Vector3 is an utility class for manipulating 3 dimensional vectors
sf::VideoMode | VideoMode defines a video mode (width, height, bpp, frequency) and provides static functions for getting modes supported by the display device
sf::View | This class defines a view (position, size, etc
sf::Window | Window is a rendering window ; it can create a new window or connect to an existing one
sf::WindowListener | Base class for classes that want to receive events from a window (for internal use only)
sf::WindowSettings | Structure defining the creation settings of windows


  • Class Members
sf::AudioResource

sf::AudioResource Class Reference

Abstract base class for every class that owns a device-dependant resource -- allow them to initialize / shutdown even when the audio context is not created. More...

#include <AudioResource.hpp>

Inheritance diagram for sf::AudioResource:

sf::Sound sf::SoundBuffer sf::SoundStream sf::Music

List of all members.

Protected Member Functions

AudioResource ()
Default constructor.
AudioResource (const AudioResource &)
Copy constructor.
virtual ~AudioResource ()
Destructor.

Detailed Description

Abstract base class for every class that owns a device-dependant resource -- allow them to initialize / shutdown even when the audio context is not created.

Definition at line 41 of file AudioResource.hpp.

Constructor & Destructor Documentation

sf::AudioResource::AudioResource ( ) [protected]

Default constructor.

Definition at line 37 of file AudioResource.cpp.

sf::AudioResource::AudioResource ( const AudioResource & ) [protected]

Copy constructor.

Definition at line 46 of file AudioResource.cpp.

sf::AudioResource::~AudioResource ( ) [protected, virtual]

Destructor.

Definition at line 55 of file AudioResource.cpp.

The documentation for this class was generated from the following files:
  • AudioResource.hpp
  • AudioResource.cpp


sf::AudioResource Member List

This is the complete list of members for sf::AudioResource, including all inherited members.

AudioResource() | sf::AudioResource | [protected]
AudioResource(const AudioResource &) | sf::AudioResource | [protected]
~AudioResource() | sf::AudioResource | [protected, virtual]


sf::Clock

sf::Clock Class Reference

Clock is an utility class for manipulating time. More...

#include <Clock.hpp>

List of all members.

Public Member Functions

Clock ()
Default constructor.
float | GetElapsedTime () const
Get the time elapsed since last reset.
void | Reset ()
Restart the timer.

Detailed Description

Clock is an utility class for manipulating time.

Definition at line 39 of file Clock.hpp.

Constructor & Destructor Documentation

sf::Clock::Clock ( )

Default constructor.

Definition at line 37 of file Clock.cpp.

Member Function Documentation

float sf::Clock::GetElapsedTime ( ) const

Get the time elapsed since last reset.

Returns:
Time elapsed, in seconds

Definition at line 46 of file Clock.cpp.

void sf::Clock::Reset ( )

Restart the timer.

Definition at line 55 of file Clock.cpp.

The documentation for this class was generated from the following files:
  • Clock.hpp
  • Clock.cpp


sf::Clock Member List

This is the complete list of members for sf::Clock, including all inherited members.

Clock() | sf::Clock
GetElapsedTime() const | sf::Clock
Reset() | sf::Clock


sf::Color

sf::Color Class Reference

Color is an utility class for manipulating 32-bits RGBA colors. More...

#include <Color.hpp>

List of all members.

Public Member Functions

Color ()
Default constructor.
Color (Uint8 R, Uint8 G, Uint8 B, Uint8 A=255)
Construct the color from its 4 RGBA components.
Color & | operator+= (const Color &Other)
Operator += overload to add a color.
Color & | operator*= (const Color &Other)
Operator *= overload to modulate a color.
bool | operator== (const Color &Other) const
Compare two colors (for equality).
bool | operator!= (const Color &Other) const
Compare two colors (for difference).

Public Attributes

Uint8 | r
Red component.
Uint8 | g
Green component.
Uint8 | b
Blue component.
Uint8 | a
Alpha (transparency) component.

Static Public Attributes

static const Color | Black
Black predefined color.
static const Color | White
White predefined color.
static const Color | Red
Red predefined color.
static const Color | Green
Green predefined color.
static const Color | Blue
Blue predefined color.
static const Color | Yellow
Yellow predefined color.
static const Color | Magenta
Magenta predefined color.
static const Color | Cyan
Cyan predefined color.

Detailed Description

Color is an utility class for manipulating 32-bits RGBA colors.

Definition at line 40 of file Color.hpp.

Constructor & Destructor Documentation

sf::Color::Color ( )

Default constructor.

Definition at line 50 of file Color.cpp.

sf::Color::Color | ( | Uint8 | R,
 |  | Uint8 | G,
 |  | Uint8 | B,
 |  | Uint8 | A = 255
 | ) |  |

Construct the color from its 4 RGBA components.

Parameters:
R | : Red component (0 .. 255)
G | : Green component (0 .. 255)
B | : Blue component (0 .. 255)
A | : Alpha component (0 .. 255) (255 by default)

Definition at line 63 of file Color.cpp.

Member Function Documentation

bool sf::Color::operator!= ( const Color & Other ) const

Compare two colors (for difference).

Parameters:
Other : Color to compare
Returns:
True if colors are different

Definition at line 113 of file Color.cpp.

Color & sf::Color::operator*= ( const Color & Other )

Operator *= overload to modulate a color.

Parameters:
Other : Color to modulate
Returns:
Component-wise multiplication of the two colors

Definition at line 90 of file Color.cpp.

Color & sf::Color::operator+= ( const Color & Other )

Operator += overload to add a color.

Parameters:
Other : Color to add
Returns:
Component-wise saturated addition of the two colors

Definition at line 76 of file Color.cpp.

bool sf::Color::operator== ( const Color & Other ) const

Compare two colors (for equality).

Parameters:
Other : Color to compare
Returns:
True if colors are equal

Definition at line 104 of file Color.cpp.

Member Data Documentation

Uint8 sf::Color::a

Alpha (transparency) component.

Definition at line 119 of file Color.hpp.

Uint8 sf::Color::b

Blue component.

Definition at line 118 of file Color.hpp.

const Color sf::Color::Black [static]

Black predefined color.

Definition at line 104 of file Color.hpp.

const Color sf::Color::Blue [static]

Blue predefined color.

Definition at line 108 of file Color.hpp.

const Color sf::Color::Cyan [static]

Cyan predefined color.

Definition at line 111 of file Color.hpp.

Uint8 sf::Color::g

Green component.

Definition at line 117 of file Color.hpp.

const Color sf::Color::Green [static]

Green predefined color.

Definition at line 107 of file Color.hpp.

const Color sf::Color::Magenta [static]

Magenta predefined color.

Definition at line 110 of file Color.hpp.

Uint8 sf::Color::r

Red component.

Definition at line 116 of file Color.hpp.

const Color sf::Color::Red [static]

Red predefined color.

Definition at line 106 of file Color.hpp.

const Color sf::Color::White [static]

White predefined color.

Definition at line 105 of file Color.hpp.

const Color sf::Color::Yellow [static]

Yellow predefined color.

Definition at line 109 of file Color.hpp.

The documentation for this class was generated from the following files:
  • Color.hpp
  • Color.cpp


sf::Color Member List

This is the complete list of members for sf::Color, including all inherited members.

a | sf::Color |
b | sf::Color |
Black | sf::Color | [static]
Blue | sf::Color | [static]
Color() | sf::Color |
Color(Uint8 R, Uint8 G, Uint8 B, Uint8 A=255) | sf::Color |
Cyan | sf::Color | [static]
g | sf::Color |
Green | sf::Color | [static]
Magenta | sf::Color | [static]
operator!=(const Color &Other) const | sf::Color |
operator*=(const Color &Other) | sf::Color |
operator+=(const Color &Other) | sf::Color |
operator==(const Color &Other) const | sf::Color |
r | sf::Color |
Red | sf::Color | [static]
White | sf::Color | [static]
Yellow | sf::Color | [static]


sf::Context

sf::Context Class Reference

Class wrapping an OpenGL context. More...

#include <Context.hpp>

Inheritance diagram for sf::Context:

sf::NonCopyable

List of all members.

Public Member Functions

Context ()
Default constructor, create the context.
~Context ()
Destructor, destroy the context.
void | SetActive (bool Active)
Activate or deactivate the context.

Static Public Member Functions

static bool | IsContextActive ()
Check if there's a context bound to the current thread.
static Context & | GetGlobal ()
Get the global context.

Detailed Description

Class wrapping an OpenGL context.

All SFML windows already have their own context, so this class is more a helper for specific issues involving OpenGL and multi-threading. It's meant to be used internally.

Definition at line 49 of file Context.hpp.

Constructor & Destructor Documentation

sf::Context::Context ( )

Default constructor, create the context.

Definition at line 44 of file Context.cpp.

sf::Context::~Context ( )

Destructor, destroy the context.

Definition at line 53 of file Context.cpp.

Member Function Documentation

Context & sf::Context::GetGlobal ( ) [static]

Get the global context.

Returns:
Reference to the global context

Definition at line 80 of file Context.cpp.

bool sf::Context::IsContextActive ( ) [static]

Check if there's a context bound to the current thread.

Returns:
True if there's a context bound to the current thread

Definition at line 71 of file Context.cpp.

void sf::Context::SetActive ( bool Active )

Activate or deactivate the context.

Parameters:
Active : True to activate the context, false to deactivate it

Definition at line 62 of file Context.cpp.

The documentation for this class was generated from the following files:
  • Context.hpp
  • Context.cpp


sf::Context Member List

This is the complete list of members for sf::Context, including all inherited members.

Context() | sf::Context |
GetGlobal() | sf::Context | [static]
IsContextActive() | sf::Context | [static]
NonCopyable() | sf::NonCopyable | [inline, private]
SetActive(bool Active) | sf::Context |
~Context() | sf::Context |


sf::Drawable

sf::Drawable Class Reference

Abstract base class for every object that can be drawn into a render window. More...

#include <Drawable.hpp>

Inheritance diagram for sf::Drawable:

sf::PostFX sf::Shape sf::Sprite sf::String

List of all members.

Public Member Functions

Drawable (const Vector2f &Position=Vector2f(0, 0), const Vector2f &Scale=Vector2f(1, 1), float Rotation=0.f, const Color &Col=Color(255, 255, 255, 255))
Default constructor.
virtual | ~Drawable ()
Virtual destructor.
void | SetPosition (float X, float Y)
Set the position of the object (take 2 values).
void | SetPosition (const Vector2f &Position)
Set the position of the object (take a 2D vector).
void | SetX (float X)
Set the X position of the object.
void | SetY (float Y)
Set the Y position of the object.
void | SetScale (float ScaleX, float ScaleY)
Set the scale of the object (take 2 values).
void | SetScale (const Vector2f &Scale)
Set the scale of the object (take a 2D vector).
void | SetScaleX (float FactorX)
Set the X scale factor of the object.
void | SetScaleY (float FactorY)
Set the Y scale factor of the object.
void | SetCenter (float CenterX, float CenterY)
Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).
void | SetCenter (const Vector2f &Center)
Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).
void | SetRotation (float Rotation)
Set the orientation of the object.
void | SetColor (const Color &Col)
Set the color of the object.
void | SetBlendMode (Blend::Mode Mode)
Set the blending mode for the object.
const Vector2f & | GetPosition () const
Get the position of the object.
const Vector2f & | GetScale () const
Get the current scale of the object.
const Vector2f & | GetCenter () const
Get the center of the object.
float | GetRotation () const
Get the orientation of the object.
const Color & | GetColor () const
Get the color of the object.
Blend::Mode | GetBlendMode () const
Get the current blending mode.
void | Move (float OffsetX, float OffsetY)
Move the object of a given offset (take 2 values).
void | Move (const Vector2f &Offset)
Move the object of a given offset (take a 2D vector).
void | Scale (float FactorX, float FactorY)
Scale the object (take 2 values).
void | Scale (const Vector2f &Factor)
Scale the object (take a 2D vector).
void | Rotate (float Angle)
Rotate the object.
sf::Vector2f | TransformToLocal (const sf::Vector2f &Point) const
Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).
sf::Vector2f | TransformToGlobal (const sf::Vector2f &Point) const
Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Protected Member Functions

const Matrix3 & | GetMatrix () const
Get the transform matrix of the drawable.
const Matrix3 & | GetInverseMatrix () const
Get the inverse transform matrix of the drawable.

Friends

class | RenderTarget

Detailed Description

Abstract base class for every object that can be drawn into a render window.

Definition at line 58 of file Drawable.hpp.

Constructor & Destructor Documentation

sf::Drawable::Drawable | ( | const Vector2f & | Position = Vector2f(0, 0),
 |  | const Vector2f & | Scale = Vector2f(1, 1),
 |  | float | Rotation = 0.f,
 |  | const Color & | Col = Color(255, 255, 255, 255)
 | ) |  |

Default constructor.

Parameters:
Position | : Position of the object (0, 0 by default)
Scale | : Scale factor (1, 1 by default)
Rotation | : Orientation, in degrees (0 by default)
Col | : Color of the object (white by default)

Definition at line 39 of file Drawable.cpp.

sf::Drawable::~Drawable ( ) [virtual]

Virtual destructor.

Definition at line 56 of file Drawable.cpp.

Member Function Documentation

Blend::Mode sf::Drawable::GetBlendMode ( ) const

Get the current blending mode.

Returns:
Current blending mode

Definition at line 258 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetCenter ( ) const

Get the center of the object.

Returns:
Current position of the center

Definition at line 231 of file Drawable.cpp.

const Color & sf::Drawable::GetColor ( ) const

Get the color of the object.

Returns:
Current color

Definition at line 249 of file Drawable.cpp.

const Matrix3 & sf::Drawable::GetInverseMatrix ( ) const [protected]

Get the inverse transform matrix of the drawable.

Returns:
Inverse transform matrix

Definition at line 350 of file Drawable.cpp.

const Matrix3 & sf::Drawable::GetMatrix ( ) const [protected]

Get the transform matrix of the drawable.

Returns:
Transform matrix

Definition at line 334 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetPosition ( ) const

Get the position of the object.

Returns:
Current position

Definition at line 213 of file Drawable.cpp.

float sf::Drawable::GetRotation ( ) const

Get the orientation of the object.

Rotation is always in the range [0, 360]

Returns:
Current rotation, in degrees

Definition at line 240 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetScale ( ) const

Get the current scale of the object.

Returns:
Current scale factor (always positive)

Definition at line 222 of file Drawable.cpp.

void sf::Drawable::Move ( const Vector2f & Offset )

Move the object of a given offset (take a 2D vector).

Parameters:
Offset : Amount of units to move the object of

Definition at line 278 of file Drawable.cpp.

void sf::Drawable::Move | ( | float | OffsetX,
 |  | float | OffsetY
 | ) |  |

Move the object of a given offset (take 2 values).

Parameters:
OffsetX | : X offset
OffsetY | : Y offset

Definition at line 268 of file Drawable.cpp.

void sf::Drawable::Rotate ( float Angle )

Rotate the object.

Parameters:
Angle : Angle of rotation, in degrees

Definition at line 306 of file Drawable.cpp.

void sf::Drawable::Scale ( const Vector2f & Factor )

Scale the object (take a 2D vector).

Parameters:
Factor : Scaling factors (both values must be strictly positive)

Definition at line 297 of file Drawable.cpp.

void sf::Drawable::Scale | ( | float | FactorX,
 |  | float | FactorY
 | ) |  |

Scale the object (take 2 values).

Parameters:
FactorX | : Scaling factor on X (must be strictly positive)
FactorY | : Scaling factor on Y (must be strictly positive)

Definition at line 287 of file Drawable.cpp.

void sf::Drawable::SetBlendMode ( Blend::Mode Mode )

Set the blending mode for the object.

The default blend mode is Blend::Alpha

Parameters:
Mode : New blending mode
The default blend mode is Blend::Alpha

Definition at line 204 of file Drawable.cpp.

void sf::Drawable::SetCenter ( const Vector2f & Center )

Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).

Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).

The default center is (0, 0)

Parameters:
Center : New center
The default center is (0, 0)

Definition at line 171 of file Drawable.cpp.

void sf::Drawable::SetCenter | ( | float | CenterX,
 |  | float | CenterY
 | ) |  |

Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).

Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).

The default center is (0, 0)

Parameters:
CenterX | : X coordinate of the center
CenterY | : Y coordinate of the center
The default center is (0, 0)

Definition at line 157 of file Drawable.cpp.

void sf::Drawable::SetColor ( const Color & Col )

Set the color of the object.

The default color is white

Parameters:
Col : New color
The default color is white

Definition at line 194 of file Drawable.cpp.

void sf::Drawable::SetPosition ( const Vector2f & Position )

Set the position of the object (take a 2D vector).

Parameters:
Position : New position

Definition at line 75 of file Drawable.cpp.

void sf::Drawable::SetPosition | ( | float | X,
 |  | float | Y
 | ) |  |

Set the position of the object (take 2 values).

Parameters:
X | : New X coordinate
Y | : New Y coordinate

Definition at line 65 of file Drawable.cpp.

void sf::Drawable::SetRotation ( float Rotation )

Set the orientation of the object.

Parameters:
Rotation : Angle of rotation, in degrees

Definition at line 180 of file Drawable.cpp.

void sf::Drawable::SetScale ( const Vector2f & Scale )

Set the scale of the object (take a 2D vector).

Parameters:
Scale : New scale (both values must be strictly positive)

Definition at line 117 of file Drawable.cpp.

void sf::Drawable::SetScale | ( | float | ScaleX,
 |  | float | ScaleY
 | ) |  |

Set the scale of the object (take 2 values).

Parameters:
ScaleX | : New horizontal scale (must be strictly positive)
ScaleY | : New vertical scale (must be strictly positive)

Definition at line 107 of file Drawable.cpp.

void sf::Drawable::SetScaleX ( float FactorX )

Set the X scale factor of the object.

Parameters:
X : New X scale factor

Definition at line 127 of file Drawable.cpp.

void sf::Drawable::SetScaleY ( float FactorY )

Set the Y scale factor of the object.

Parameters:
Y : New Y scale factor

Definition at line 141 of file Drawable.cpp.

void sf::Drawable::SetX ( float X )

Set the X position of the object.

Parameters:
X : New X coordinate

Definition at line 85 of file Drawable.cpp.

void sf::Drawable::SetY ( float Y )

Set the Y position of the object.

Parameters:
Y : New Y coordinate

Definition at line 96 of file Drawable.cpp.

sf::Vector2f sf::Drawable::TransformToGlobal ( const sf::Vector2f & Point ) const

Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Parameters:
Point : Point to transform
Returns:
Transformed point

Definition at line 325 of file Drawable.cpp.

sf::Vector2f sf::Drawable::TransformToLocal ( const sf::Vector2f & Point ) const

Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).

Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).

Parameters:
Point : Point to transform
Returns:
Transformed point

Definition at line 316 of file Drawable.cpp.

The documentation for this class was generated from the following files:
  • Drawable.hpp
  • Drawable.cpp


sf::Drawable Member List

This is the complete list of members for sf::Drawable, including all inherited members.

Drawable(const Vector2f &Position=Vector2f(0, 0), const Vector2f &Scale=Vector2f(1, 1), float Rotation=0.f, const Color &Col=Color(255, 255, 255, 255)) | sf::Drawable |
GetBlendMode() const | sf::Drawable |
GetCenter() const | sf::Drawable |
GetColor() const | sf::Drawable |
GetInverseMatrix() const | sf::Drawable | [protected]
GetMatrix() const | sf::Drawable | [protected]
GetPosition() const | sf::Drawable |
GetRotation() const | sf::Drawable |
GetScale() const | sf::Drawable |
Move(float OffsetX, float OffsetY) | sf::Drawable |
Move(const Vector2f &Offset) | sf::Drawable |
RenderTarget (defined in sf::Drawable) | sf::Drawable | [friend]
Rotate(float Angle) | sf::Drawable |
Scale(float FactorX, float FactorY) | sf::Drawable |
Scale(const Vector2f &Factor) | sf::Drawable |
SetBlendMode(Blend::Mode Mode) | sf::Drawable |
SetCenter(float CenterX, float CenterY) | sf::Drawable |
SetCenter(const Vector2f &Center) | sf::Drawable |
SetColor(const Color &Col) | sf::Drawable |
SetPosition(float X, float Y) | sf::Drawable |
SetPosition(const Vector2f &Position) | sf::Drawable |
SetRotation(float Rotation) | sf::Drawable |
SetScale(float ScaleX, float ScaleY) | sf::Drawable |
SetScale(const Vector2f &Scale) | sf::Drawable |
SetScaleX(float FactorX) | sf::Drawable |
SetScaleY(float FactorY) | sf::Drawable |
SetX(float X) | sf::Drawable |
SetY(float Y) | sf::Drawable |
TransformToGlobal(const sf::Vector2f &Point) const | sf::Drawable |
TransformToLocal(const sf::Vector2f &Point) const | sf::Drawable |
~Drawable() | sf::Drawable | [virtual]


sf::Event

sf::Event Class Reference

Event defines a system event and its parameters. More...

#include <Event.hpp>

List of all members.

Classes

struct | JoyButtonEvent
Joystick buttons events parameters. More...
struct | JoyMoveEvent
Joystick axis move event parameters. More...
struct | KeyEvent
Keyboard event parameters. More...
struct | MouseButtonEvent
Mouse buttons events parameters. More...
struct | MouseMoveEvent
Mouse move event parameters. More...
struct | MouseWheelEvent
Mouse wheel events parameters. More...
struct | SizeEvent
Size events parameters. More...
struct | TextEvent
Text event parameters. More...

Public Types

enum EventType {
Closed,
Resized,
LostFocus,
GainedFocus,
TextEntered,
KeyPressed,
KeyReleased,
MouseWheelMoved,
MouseButtonPressed,
MouseButtonReleased,
MouseMoved,
MouseEntered,
MouseLeft,
JoyButtonPressed,
JoyButtonReleased,
JoyMoved,
Count
}
Enumeration of the different types of events. More...

Public Attributes

EventType Type
Type of the event.
union {
KeyEvent Key
TextEvent Text
MouseMoveEvent MouseMove
MouseButtonEvent MouseButton
MouseWheelEvent MouseWheel
JoyMoveEvent JoyMove
JoyButtonEvent JoyButton
SizeEvent Size
};

Detailed Description

Event defines a system event and its parameters.

Definition at line 197 of file Event.hpp.

Member Enumeration Documentation

enum sf::Event::EventType

Enumeration of the different types of events.

Definition at line 278 of file Event.hpp.

Member Data Documentation

EventType sf::Event::Type

Type of the event.

Definition at line 303 of file Event.hpp.

The documentation for this class was generated from the following file:
  • Event.hpp


sf::Event Member List

This is the complete list of members for sf::Event, including all inherited members.

Closed enum value (defined in sf::Event) | sf::Event
Count enum value (defined in sf::Event) | sf::Event
EventType enum name | sf::Event
GainedFocus enum value (defined in sf::Event) | sf::Event
JoyButton (defined in sf::Event) | sf::Event
JoyButtonPressed enum value (defined in sf::Event) | sf::Event
JoyButtonReleased enum value (defined in sf::Event) | sf::Event
JoyMove (defined in sf::Event) | sf::Event
JoyMoved enum value (defined in sf::Event) | sf::Event
Key (defined in sf::Event) | sf::Event
KeyPressed enum value (defined in sf::Event) | sf::Event
KeyReleased enum value (defined in sf::Event) | sf::Event
LostFocus enum value (defined in sf::Event) | sf::Event
MouseButton (defined in sf::Event) | sf::Event
MouseButtonPressed enum value (defined in sf::Event) | sf::Event
MouseButtonReleased enum value (defined in sf::Event) | sf::Event
MouseEntered enum value (defined in sf::Event) | sf::Event
MouseLeft enum value (defined in sf::Event) | sf::Event
MouseMove (defined in sf::Event) | sf::Event
MouseMoved enum value (defined in sf::Event) | sf::Event
MouseWheel (defined in sf::Event) | sf::Event
MouseWheelMoved enum value (defined in sf::Event) | sf::Event
Resized enum value (defined in sf::Event) | sf::Event
Size (defined in sf::Event) | sf::Event
Text (defined in sf::Event) | sf::Event
TextEntered enum value (defined in sf::Event) | sf::Event
Type | sf::Event


sf::Event::JoyButtonEvent

sf::Event::Event::JoyButtonEvent Struct Reference

Joystick buttons events parameters. More...

#include <Event.hpp>

List of all members.

Public Attributes

unsigned int | JoystickId
unsigned int | Button

Detailed Description

Joystick buttons events parameters.

Definition at line 260 of file Event.hpp.

The documentation for this struct was generated from the following file:
  • Event.hpp


sf::Event::Event::JoyButtonEvent Member List

This is the complete list of members for sf::Event::Event::JoyButtonEvent, including all inherited members.

Button (defined in sf::Event::Event::JoyButtonEvent) | sf::Event::Event::JoyButtonEvent
JoystickId (defined in sf::Event::Event::JoyButtonEvent) | sf::Event::Event::JoyButtonEvent


sf::Event::JoyMoveEvent

sf::Event::Event::JoyMoveEvent Struct Reference

Joystick axis move event parameters. More...

#include <Event.hpp>

List of all members.

Public Attributes

unsigned int | JoystickId
Joy::Axis | Axis
float | Position

Detailed Description

Joystick axis move event parameters.

Definition at line 250 of file Event.hpp.

The documentation for this struct was generated from the following file:
  • Event.hpp


sf::Event::Event::JoyMoveEvent Member List

This is the complete list of members for sf::Event::Event::JoyMoveEvent, including all inherited members.

Axis (defined in sf::Event::Event::JoyMoveEvent) | sf::Event::Event::JoyMoveEvent
JoystickId (defined in sf::Event::Event::JoyMoveEvent) | sf::Event::Event::JoyMoveEvent
Position (defined in sf::Event::Event::JoyMoveEvent) | sf::Event::Event::JoyMoveEvent


sf::Event::KeyEvent

sf::Event::Event::KeyEvent Struct Reference

Keyboard event parameters. More...

#include <Event.hpp>

List of all members.

Public Attributes

Key::Code | Code
bool | Alt
bool | Control
bool | Shift

Detailed Description

Keyboard event parameters.

Definition at line 204 of file Event.hpp.

The documentation for this struct was generated from the following file:
  • Event.hpp


sf::Event::Event::KeyEvent Member List

This is the complete list of members for sf::Event::Event::KeyEvent, including all inherited members.

Alt (defined in sf::Event::Event::KeyEvent) | sf::Event::Event::KeyEvent
Code (defined in sf::Event::Event::KeyEvent) | sf::Event::Event::KeyEvent
Control (defined in sf::Event::Event::KeyEvent) | sf::Event::Event::KeyEvent
Shift (defined in sf::Event::Event::KeyEvent) | sf::Event::Event::KeyEvent


sf::Event::MouseButtonEvent

sf::Event::Event::MouseButtonEvent Struct Reference

Mouse buttons events parameters. More...

#include <Event.hpp>

List of all members.

Public Attributes

Mouse::Button | Button
int | X
int | Y

Detailed Description

Mouse buttons events parameters.

Definition at line 232 of file Event.hpp.

The documentation for this struct was generated from the following file:
  • Event.hpp


sf::Event::Event::MouseButtonEvent Member List

This is the complete list of members for sf::Event::Event::MouseButtonEvent, including all inherited members.

Button (defined in sf::Event::Event::MouseButtonEvent) | sf::Event::Event::MouseButtonEvent
X (defined in sf::Event::Event::MouseButtonEvent) | sf::Event::Event::MouseButtonEvent
Y (defined in sf::Event::Event::MouseButtonEvent) | sf::Event::Event::MouseButtonEvent


sf::Event::MouseMoveEvent

sf::Event::Event::MouseMoveEvent Struct Reference

Mouse move event parameters. More...

#include <Event.hpp>

List of all members.

Public Attributes

int | X
int | Y

Detailed Description

Mouse move event parameters.

Definition at line 223 of file Event.hpp.

The documentation for this struct was generated from the following file:
  • Event.hpp


sf::Event::Event::MouseMoveEvent Member List

This is the complete list of members for sf::Event::Event::MouseMoveEvent, including all inherited members.

X (defined in sf::Event::Event::MouseMoveEvent) | sf::Event::Event::MouseMoveEvent
Y (defined in sf::Event::Event::MouseMoveEvent) | sf::Event::Event::MouseMoveEvent


sf::Event::MouseWheelEvent

sf::Event::Event::MouseWheelEvent Struct Reference

Mouse wheel events parameters. More...

#include <Event.hpp>

List of all members.

Public Attributes

int Delta

Detailed Description

Mouse wheel events parameters.

Definition at line 242 of file Event.hpp.

The documentation for this struct was generated from the following file:
  • Event.hpp


sf::Event::Event::MouseWheelEvent Member List

This is the complete list of members for sf::Event::Event::MouseWheelEvent, including all inherited members.

Delta (defined in sf::Event::Event::MouseWheelEvent) sf::Event::Event::MouseWheelEvent


sf::Event::SizeEvent

sf::Event::Event::SizeEvent Struct Reference

Size events parameters. More...

#include <Event.hpp>

List of all members.

Public Attributes

unsigned int | Width
unsigned int | Height

Detailed Description

Size events parameters.

Definition at line 269 of file Event.hpp.

The documentation for this struct was generated from the following file:
  • Event.hpp


sf::Event::Event::SizeEvent Member List

This is the complete list of members for sf::Event::Event::SizeEvent, including all inherited members.

Height (defined in sf::Event::Event::SizeEvent) | sf::Event::Event::SizeEvent
Width (defined in sf::Event::Event::SizeEvent) | sf::Event::Event::SizeEvent


sf::Event::TextEvent

sf::Event::Event::TextEvent Struct Reference

Text event parameters. More...

#include <Event.hpp>

List of all members.

Public Attributes

Uint32 Unicode

Detailed Description

Text event parameters.

Definition at line 215 of file Event.hpp.

The documentation for this struct was generated from the following file:
  • Event.hpp


sf::Event::Event::TextEvent Member List

This is the complete list of members for sf::Event::Event::TextEvent, including all inherited members.

Unicode (defined in sf::Event::Event::TextEvent) sf::Event::Event::TextEvent


sf::Font

sf::Font Class Reference

Font is the low-level class for loading and manipulating character fonts. More...

#include <Font.hpp>

Inheritance diagram for sf::Font:

sf::Resource< Font >

List of all members.

Public Member Functions

Font ()
Default constructor.
bool | LoadFromFile (const std::string &Filename, unsigned int CharSize=30, const Unicode::Text &Charset=ourDefaultCharset)
Load the font from a file.
bool | LoadFromMemory (const char *Data, std::size_t SizeInBytes, unsigned int CharSize=30, const Unicode::Text &Charset=ourDefaultCharset)
Load the font from a file in memory.
unsigned int | GetCharacterSize () const
Get the base size of characters in the font; All glyphs dimensions are based on this value.
const Glyph & | GetGlyph (Uint32 CodePoint) const
Get the description of a glyph (character) given by its unicode value.
const Image & | GetImage () const
Get the image containing the rendered characters (glyphs).

Static Public Member Functions

static const Font & | GetDefaultFont ()
Get the SFML default built-in font (Arial).

Detailed Description

Font is the low-level class for loading and manipulating character fonts.

This class is meant to be used by sf::String

Definition at line 54 of file Font.hpp.

Constructor & Destructor Documentation

sf::Font::Font ( )

Default constructor.

Definition at line 64 of file Font.cpp.

Member Function Documentation

unsigned int sf::Font::GetCharacterSize ( ) const

Get the base size of characters in the font; All glyphs dimensions are based on this value.

Get the base size of characters in the font; All glyphs dimensions are based on this value.

Returns:
Base size of characters

Definition at line 120 of file Font.cpp.

const Font & sf::Font::GetDefaultFont ( ) [static]

Get the SFML default built-in font (Arial).

Returns:
Instance of the default font

Definition at line 159 of file Font.cpp.

const Glyph & sf::Font::GetGlyph ( Uint32 CodePoint ) const

Get the description of a glyph (character) given by its unicode value.

Get the description of a glyph (character) given by its unicode value.

Parameters:
CodePoint : Unicode value of the character to get
Returns:
Glyph's visual settings, or an invalid glyph if character not found

Definition at line 130 of file Font.cpp.

const Image & sf::Font::GetImage ( ) const

Get the image containing the rendered characters (glyphs).

Returns:
Image containing glyphs

Definition at line 150 of file Font.cpp.

bool sf::Font::LoadFromFile | ( | const std::string & | Filename,
 |  | unsigned int | CharSize = 30,
 |  | const Unicode::Text & | Charset = ourDefaultCharset
 | ) |  |

Load the font from a file.

Parameters:
Filename | : Font file to load
CharSize | : Size of characters in bitmap - the bigger, the higher quality (30 by default)
Charset | : Characters set to generate (by default, contains the ISO-8859-1 printable characters)
Returns:
True if loading was successful

Definition at line 74 of file Font.cpp.

bool sf::Font::LoadFromMemory | ( | const char * | Data,
 |  | std::size_t | SizeInBytes,
 |  | unsigned int | CharSize = 30,
 |  | const Unicode::Text & | Charset = ourDefaultCharset
 | ) |  |

Load the font from a file in memory.

Parameters:
Data | : Pointer to the data to load
SizeInBytes | : Size of the data, in bytes
CharSize | : Size of characters in bitmap - the bigger, the higher quality (30 by default)
Charset | : Characters set to generate (by default, contains the ISO-8859-1 printable characters)
Returns:
True if loading was successful

Definition at line 93 of file Font.cpp.

The documentation for this class was generated from the following files:
  • Font.hpp
  • Font.cpp


sf::Font Member List

This is the complete list of members for sf::Font, including all inherited members.

Font() | sf::Font |
GetCharacterSize() const | sf::Font |
GetDefaultFont() | sf::Font | [static]
GetGlyph(Uint32 CodePoint) const | sf::Font |
GetImage() const | sf::Font |
LoadFromFile(const std::string &Filename, unsigned int CharSize=30, const Unicode::Text &Charset=ourDefaultCharset) | sf::Font |
LoadFromMemory(const char *Data, std::size_t SizeInBytes, unsigned int CharSize=30, const Unicode::Text &Charset=ourDefaultCharset) | sf::Font |
operator=(const Resource< Font > &Other) | sf::Resource< Font > | [protected]
Resource() | sf::Resource< Font > | [protected]
Resource(const Resource< Font > &Copy) | sf::Resource< Font > | [protected]
~Resource() | sf::Resource< Font > | [protected]


sf::Ftp

sf::Ftp Class Reference

This class provides methods for manipulating the FTP protocol (described in RFC 959). More...

#include <Ftp.hpp>

Inheritance diagram for sf::Ftp:

sf::NonCopyable

List of all members.

Classes

class | DataChannel
class | DirectoryResponse
Specialization of FTP response returning a directory. More...
class | ListingResponse
Specialization of FTP response returning a filename lisiting. More...
class | Response
This class wraps a FTP response, which is basically :
  • a status code
  • a message.
More...

Public Types

enum TransferMode {
Binary,
Ascii,
Ebcdic
}
Enumeration of transfer modes. More...

Public Member Functions

~Ftp ()
Destructor -- close the connection with the server.
Response | Connect (const IPAddress &Server, unsigned short Port=21, float Timeout=0.f)
Connect to the specified FTP server.
Response Login ()
Log in using anonymous account.
Response | Login (const std::string &UserName, const std::string &Password)
Log in using a username and a password.
Response Disconnect ()
Close the connection with FTP server.
Response KeepAlive ()
Send a null command just to prevent from being disconnected.
DirectoryResponse GetWorkingDirectory ()
Get the current working directory.
ListingResponse | GetDirectoryListing (const std::string &Directory="")
Get the contents of the given directory (subdirectories and files).
Response | ChangeDirectory (const std::string &Directory)
Change the current working directory.
Response ParentDirectory ()
Go to the parent directory of the current one.
Response | MakeDirectory (const std::string &Name)
Create a new directory.
Response | DeleteDirectory (const std::string &Name)
Remove an existing directory.
Response | RenameFile (const std::string &File, const std::string &NewName)
Rename a file.
Response | DeleteFile (const std::string &Name)
Remove an existing file.
Response | Download (const std::string &DistantFile, const std::string &DestPath, TransferMode Mode=Binary)
Download a file from the server.
Response | Upload (const std::string &LocalFile, const std::string &DestPath, TransferMode Mode=Binary)
Upload a file to the server.

Friends

class | DataChannel

Detailed Description

This class provides methods for manipulating the FTP protocol (described in RFC 959).

It provides easy access and transfers to remote directories and files on a FTP server

Definition at line 47 of file Ftp.hpp.

Member Enumeration Documentation

enum sf::Ftp::TransferMode

Enumeration of transfer modes.

Enumerator:
Binary | Binary mode (file is transfered as a sequence of bytes).
Ascii | Text mode using ASCII encoding.
Ebcdic | Text mode using EBCDIC encoding.

Definition at line 54 of file Ftp.hpp.

Constructor & Destructor Documentation

sf::Ftp::~Ftp ( )

Destructor -- close the connection with the server.

Definition at line 186 of file Ftp.cpp.

Member Function Documentation

Ftp::Response sf::Ftp::ChangeDirectory ( const std::string & Directory )

Change the current working directory.

Parameters:
Directory : New directory, relative to the current one
Returns:
Server response to the request

Definition at line 291 of file Ftp.cpp.

Ftp::Response sf::Ftp::Connect | ( | const IPAddress & | Server,
 |  | unsigned short | Port = 21,
 |  | float | Timeout = 0.f
 | ) |  |

Connect to the specified FTP server.

Parameters:
Server | : FTP server to connect to
Port | : Port used for connection (21 by default, standard FTP port)
Timeout | : Maximum time to wait, in seconds (0 by default, means no timeout)
Returns:
Server response to the request

Definition at line 195 of file Ftp.cpp.

Ftp::Response sf::Ftp::DeleteDirectory ( const std::string & Name )

Remove an existing directory.

Parameters:
Name : Name of the directory to remove
Returns:
Server response to the request

Definition at line 318 of file Ftp.cpp.

Ftp::Response sf::Ftp::DeleteFile ( const std::string & Name )

Remove an existing file.

Parameters:
Name : File to remove
Returns:
Server response to the request

Definition at line 340 of file Ftp.cpp.

Ftp::Response sf::Ftp::Disconnect ( )

Close the connection with FTP server.

Returns:
Server response to the request

Definition at line 231 of file Ftp.cpp.

Ftp::Response sf::Ftp::Download | ( | const std::string & | DistantFile,
 |  | const std::string & | DestPath,
 |  | TransferMode | Mode = Binary
 | ) |  |

Download a file from the server.

Parameters:
DistantFile | : Path of the distant file to download
DestPath | : Where to put to file on the local computer
Mode | : Transfer mode (binary by default)
Returns:
Server response to the request

Definition at line 349 of file Ftp.cpp.

Ftp::ListingResponse sf::Ftp::GetDirectoryListing ( const std::string & Directory = "" )

Get the contents of the given directory (subdirectories and files).

Get the contents of the given directory (subdirectories and files).

Parameters:
Directory : Directory to list ("" by default, the current one)
Returns:
Server response to the request

Definition at line 264 of file Ftp.cpp.

Ftp::DirectoryResponse sf::Ftp::GetWorkingDirectory ( )

Get the current working directory.

Returns:
Server response to the request

Definition at line 254 of file Ftp.cpp.

Ftp::Response sf::Ftp::KeepAlive ( )

Send a null command just to prevent from being disconnected.

Returns:
Server response to the request

Definition at line 245 of file Ftp.cpp.

Ftp::Response sf::Ftp::Login | ( | const std::string & | UserName,
 |  | const std::string & | Password
 | ) |  |

Log in using a username and a password.

Parameters:
UserName | : User name
Password | : Password
Returns:
Server response to the request

Definition at line 218 of file Ftp.cpp.

Ftp::Response sf::Ftp::Login ( )

Log in using anonymous account.

Returns:
Server response to the request

Definition at line 209 of file Ftp.cpp.

Ftp::Response sf::Ftp::MakeDirectory ( const std::string & Name )

Create a new directory.

Parameters:
Name : Name of the directory to create
Returns:
Server response to the request

Definition at line 309 of file Ftp.cpp.

Ftp::Response sf::Ftp::ParentDirectory ( )

Go to the parent directory of the current one.

Returns:
Server response to the request

Definition at line 300 of file Ftp.cpp.

Ftp::Response sf::Ftp::RenameFile | ( | const std::string & | File,
 |  | const std::string & | NewName
 | ) |  |

Rename a file.

Parameters:
File | : File to rename
NewName | : New name
Returns:
Server response to the request

Definition at line 327 of file Ftp.cpp.

Ftp::Response sf::Ftp::Upload | ( | const std::string & | LocalFile,
 |  | const std::string & | DestPath,
 |  | TransferMode | Mode = Binary
 | ) |  |

Upload a file to the server.

Parameters:
LocalFile | : Path of the local file to upload
DestPath | : Where to put to file on the server
Mode | : Transfer mode (binary by default)
Returns:
Server response to the request

Definition at line 396 of file Ftp.cpp.

The documentation for this class was generated from the following files:
  • Ftp.hpp
  • Ftp.cpp


sf::Ftp Member List

This is the complete list of members for sf::Ftp, including all inherited members.

Ascii enum value | sf::Ftp |
Binary enum value | sf::Ftp |
ChangeDirectory(const std::string &Directory) | sf::Ftp |
Connect(const IPAddress &Server, unsigned short Port=21, float Timeout=0.f) | sf::Ftp |
DataChannel (defined in sf::Ftp) | sf::Ftp | [friend]
DeleteDirectory(const std::string &Name) | sf::Ftp |
DeleteFile(const std::string &Name) | sf::Ftp |
Disconnect() | sf::Ftp |
Download(const std::string &DistantFile, const std::string &DestPath, TransferMode Mode=Binary) | sf::Ftp |
Ebcdic enum value | sf::Ftp |
GetDirectoryListing(const std::string &Directory="") | sf::Ftp |
GetWorkingDirectory() | sf::Ftp |
KeepAlive() | sf::Ftp |
Login() | sf::Ftp |
Login(const std::string &UserName, const std::string &Password) | sf::Ftp |
MakeDirectory(const std::string &Name) | sf::Ftp |
NonCopyable() | sf::NonCopyable | [inline, private]
ParentDirectory() | sf::Ftp |
RenameFile(const std::string &File, const std::string &NewName) | sf::Ftp |
TransferMode enum name | sf::Ftp |
Upload(const std::string &LocalFile, const std::string &DestPath, TransferMode Mode=Binary) | sf::Ftp |
~Ftp() | sf::Ftp |


sf::Ftp::DirectoryResponse

sf::Ftp::Ftp::DirectoryResponse Class Reference

Specialization of FTP response returning a directory. More...

#include <Ftp.hpp>

Inheritance diagram for sf::Ftp::Ftp::DirectoryResponse:

sf::Ftp::Ftp::Response

List of all members.

Public Types

enum Status {
RestartMarkerReply = 110,
ServiceReadySoon = 120,
DataConnectionAlreadyOpened = 125,
OpeningDataConnection = 150,
Ok = 200,
PointlessCommand = 202,
SystemStatus = 211,
DirectoryStatus = 212,
FileStatus = 213,
HelpMessage = 214,
SystemType = 215,
ServiceReady = 220,
ClosingConnection = 221,
DataConnectionOpened = 225,
ClosingDataConnection = 226,
EnteringPassiveMode = 227,
LoggedIn = 230,
FileActionOk = 250,
DirectoryOk = 257,
NeedPassword = 331,
NeedAccountToLogIn = 332,
NeedInformation = 350,
ServiceUnavailable = 421,
DataConnectionUnavailable = 425,
TransferAborted = 426,
FileActionAborted = 450,
LocalError = 451,
InsufficientStorageSpace = 452,
CommandUnknown = 500,
ParametersUnknown = 501,
CommandNotImplemented = 502,
BadCommandSequence = 503,
ParameterNotImplemented = 504,
NotLoggedIn = 530,
NeedAccountToStore = 532,
FileUnavailable = 550,
PageTypeUnknown = 551,
NotEnoughMemory = 552,
FilenameNotAllowed = 553,
InvalidResponse = 1000,
ConnectionFailed = 1001,
ConnectionClosed = 1002,
InvalidFile = 1003
}
Enumerate all the valid status codes returned in a FTP response. More...

Public Member Functions

DirectoryResponse (Response Resp)
Default constructor.
const std::string & | GetDirectory () const
Get the directory returned in the response.
bool | IsOk () const
Convenience function to check if the response status code means a success.
Status | GetStatus () const
Get the response status code.
const std::string & | GetMessage () const
Get the full message contained in the response.

Detailed Description

Specialization of FTP response returning a directory.

Definition at line 182 of file Ftp.hpp.

Member Enumeration Documentation

enum sf::Ftp::Response::Status [inherited]

Enumerate all the valid status codes returned in a FTP response.

Enumerator:
RestartMarkerReply | Restart marker reply.
ServiceReadySoon | Service ready in N minutes.
DataConnectionAlreadyOpened | Data connection already opened, transfer starting.
OpeningDataConnection | File status ok, about to open data connection.
Ok | Command ok.
PointlessCommand | Command not implemented.
SystemStatus | System status, or system help reply.
DirectoryStatus | Directory status.
FileStatus | File status.
HelpMessage | Help message.
SystemType | NAME system type, where NAME is an official system name from the list in the Assigned Numbers document.
ServiceReady | Service ready for new user.
ClosingConnection | Service closing control connection.
DataConnectionOpened | Data connection open, no transfer in progress.
ClosingDataConnection | Closing data connection, requested file action successful.
EnteringPassiveMode | Entering passive mode.
LoggedIn | User logged in, proceed. Logged out if appropriate.
FileActionOk | Requested file action ok.
DirectoryOk | PATHNAME created.
NeedPassword | User name ok, need password.
NeedAccountToLogIn | Need account for login.
NeedInformation | Requested file action pending further information.
ServiceUnavailable | Service not available, closing control connection.
DataConnectionUnavailable | Can't open data connection.
TransferAborted | Connection closed, transfer aborted.
FileActionAborted | Requested file action not taken.
LocalError | Requested action aborted, local error in processing.
InsufficientStorageSpace | Requested action not taken; insufficient storage space in system, file unavailable.
CommandUnknown | Syntax error, command unrecognized.
ParametersUnknown | Syntax error in parameters or arguments.
CommandNotImplemented | Command not implemented.
BadCommandSequence | Bad sequence of commands.
ParameterNotImplemented | Command not implemented for that parameter.
NotLoggedIn | Not logged in.
NeedAccountToStore | Need account for storing files.
FileUnavailable | Requested action not taken, file unavailable.
PageTypeUnknown | Requested action aborted, page type unknown.
NotEnoughMemory | Requested file action aborted, exceeded storage allocation.
FilenameNotAllowed | Requested action not taken, file name not allowed.
InvalidResponse | Response is not a valid FTP one.
ConnectionFailed | Connection with server failed.
ConnectionClosed | Connection with server closed.
InvalidFile | Invalid file to upload / download.

Definition at line 74 of file Ftp.hpp.

Constructor & Destructor Documentation

sf::Ftp::Ftp::DirectoryResponse::DirectoryResponse ( Ftp::Response Resp )

Default constructor.

Parameters:
Resp : Source response

Definition at line 123 of file Ftp.cpp.

Member Function Documentation

const std::string & sf::Ftp::Ftp::DirectoryResponse::GetDirectory ( ) const

Get the directory returned in the response.

Returns:
Directory name

Definition at line 139 of file Ftp.cpp.

const std::string & sf::Ftp::Ftp::Response::GetMessage ( ) const [inherited]

Get the full message contained in the response.

Returns:
The response message

Definition at line 114 of file Ftp.cpp.

Ftp::Response::Status sf::Ftp::Ftp::Response::GetStatus ( ) const [inherited]

Get the response status code.

Returns:
Status code

Definition at line 105 of file Ftp.cpp.

bool sf::Ftp::Ftp::Response::IsOk ( ) const [inherited]

Convenience function to check if the response status code means a success.

Convenience function to check if the response status code means a success.

Returns:
True if status is success (code < 400)

Definition at line 96 of file Ftp.cpp.

The documentation for this class was generated from the following files:
  • Ftp.hpp
  • Ftp.cpp


sf::Ftp::Ftp::DirectoryResponse Member List

This is the complete list of members for sf::Ftp::Ftp::DirectoryResponse, including all inherited members.

BadCommandSequence enum value | sf::Ftp::Ftp::Response
ClosingConnection enum value | sf::Ftp::Ftp::Response
ClosingDataConnection enum value | sf::Ftp::Ftp::Response
CommandNotImplemented enum value | sf::Ftp::Ftp::Response
CommandUnknown enum value | sf::Ftp::Ftp::Response
ConnectionClosed enum value | sf::Ftp::Ftp::Response
ConnectionFailed enum value | sf::Ftp::Ftp::Response
DataConnectionAlreadyOpened enum value | sf::Ftp::Ftp::Response
DataConnectionOpened enum value | sf::Ftp::Ftp::Response
DataConnectionUnavailable enum value | sf::Ftp::Ftp::Response
DirectoryOk enum value | sf::Ftp::Ftp::Response
DirectoryResponse(Response Resp) | sf::Ftp::Ftp::DirectoryResponse
DirectoryStatus enum value | sf::Ftp::Ftp::Response
EnteringPassiveMode enum value | sf::Ftp::Ftp::Response
FileActionAborted enum value | sf::Ftp::Ftp::Response
FileActionOk enum value | sf::Ftp::Ftp::Response
FilenameNotAllowed enum value | sf::Ftp::Ftp::Response
FileStatus enum value | sf::Ftp::Ftp::Response
FileUnavailable enum value | sf::Ftp::Ftp::Response
GetDirectory() const | sf::Ftp::Ftp::DirectoryResponse
GetMessage() const | sf::Ftp::Ftp::Response
GetStatus() const | sf::Ftp::Ftp::Response
HelpMessage enum value | sf::Ftp::Ftp::Response
InsufficientStorageSpace enum value | sf::Ftp::Ftp::Response
InvalidFile enum value | sf::Ftp::Ftp::Response
InvalidResponse enum value | sf::Ftp::Ftp::Response
IsOk() const | sf::Ftp::Ftp::Response
LocalError enum value | sf::Ftp::Ftp::Response
LoggedIn enum value | sf::Ftp::Ftp::Response
NeedAccountToLogIn enum value | sf::Ftp::Ftp::Response
NeedAccountToStore enum value | sf::Ftp::Ftp::Response
NeedInformation enum value | sf::Ftp::Ftp::Response
NeedPassword enum value | sf::Ftp::Ftp::Response
NotEnoughMemory enum value | sf::Ftp::Ftp::Response
NotLoggedIn enum value | sf::Ftp::Ftp::Response
Ok enum value | sf::Ftp::Ftp::Response
OpeningDataConnection enum value | sf::Ftp::Ftp::Response
PageTypeUnknown enum value | sf::Ftp::Ftp::Response
ParameterNotImplemented enum value | sf::Ftp::Ftp::Response
ParametersUnknown enum value | sf::Ftp::Ftp::Response
PointlessCommand enum value | sf::Ftp::Ftp::Response
Response(Status Code=InvalidResponse, const std::string &Message="") | sf::Ftp::Ftp::Response
RestartMarkerReply enum value | sf::Ftp::Ftp::Response
ServiceReady enum value | sf::Ftp::Ftp::Response
ServiceReadySoon enum value | sf::Ftp::Ftp::Response
ServiceUnavailable enum value | sf::Ftp::Ftp::Response
Status enum name | sf::Ftp::Ftp::Response
SystemStatus enum value | sf::Ftp::Ftp::Response
SystemType enum value | sf::Ftp::Ftp::Response
TransferAborted enum value | sf::Ftp::Ftp::Response


sf::Ftp::ListingResponse

sf::Ftp::Ftp::ListingResponse Class Reference

Specialization of FTP response returning a filename lisiting. More...

#include <Ftp.hpp>

Inheritance diagram for sf::Ftp::Ftp::ListingResponse:

sf::Ftp::Ftp::Response

List of all members.

Public Types

enum Status {
RestartMarkerReply = 110,
ServiceReadySoon = 120,
DataConnectionAlreadyOpened = 125,
OpeningDataConnection = 150,
Ok = 200,
PointlessCommand = 202,
SystemStatus = 211,
DirectoryStatus = 212,
FileStatus = 213,
HelpMessage = 214,
SystemType = 215,
ServiceReady = 220,
ClosingConnection = 221,
DataConnectionOpened = 225,
ClosingDataConnection = 226,
EnteringPassiveMode = 227,
LoggedIn = 230,
FileActionOk = 250,
DirectoryOk = 257,
NeedPassword = 331,
NeedAccountToLogIn = 332,
NeedInformation = 350,
ServiceUnavailable = 421,
DataConnectionUnavailable = 425,
TransferAborted = 426,
FileActionAborted = 450,
LocalError = 451,
InsufficientStorageSpace = 452,
CommandUnknown = 500,
ParametersUnknown = 501,
CommandNotImplemented = 502,
BadCommandSequence = 503,
ParameterNotImplemented = 504,
NotLoggedIn = 530,
NeedAccountToStore = 532,
FileUnavailable = 550,
PageTypeUnknown = 551,
NotEnoughMemory = 552,
FilenameNotAllowed = 553,
InvalidResponse = 1000,
ConnectionFailed = 1001,
ConnectionClosed = 1002,
InvalidFile = 1003
}
Enumerate all the valid status codes returned in a FTP response. More...

Public Member Functions

ListingResponse (Response Resp, const std::vector< char > &Data)
Default constructor.
std::size_t | GetCount () const
Get the number of filenames in the listing.
const std::string & | GetFilename (std::size_t Index) const
Get the Index-th filename in the directory.
bool | IsOk () const
Convenience function to check if the response status code means a success.
Status | GetStatus () const
Get the response status code.
const std::string & | GetMessage () const
Get the full message contained in the response.

Detailed Description

Specialization of FTP response returning a filename lisiting.

Definition at line 214 of file Ftp.hpp.

Member Enumeration Documentation

enum sf::Ftp::Response::Status [inherited]

Enumerate all the valid status codes returned in a FTP response.

Enumerator:
RestartMarkerReply | Restart marker reply.
ServiceReadySoon | Service ready in N minutes.
DataConnectionAlreadyOpened | Data connection already opened, transfer starting.
OpeningDataConnection | File status ok, about to open data connection.
Ok | Command ok.
PointlessCommand | Command not implemented.
SystemStatus | System status, or system help reply.
DirectoryStatus | Directory status.
FileStatus | File status.
HelpMessage | Help message.
SystemType | NAME system type, where NAME is an official system name from the list in the Assigned Numbers document.
ServiceReady | Service ready for new user.
ClosingConnection | Service closing control connection.
DataConnectionOpened | Data connection open, no transfer in progress.
ClosingDataConnection | Closing data connection, requested file action successful.
EnteringPassiveMode | Entering passive mode.
LoggedIn | User logged in, proceed. Logged out if appropriate.
FileActionOk | Requested file action ok.
DirectoryOk | PATHNAME created.
NeedPassword | User name ok, need password.
NeedAccountToLogIn | Need account for login.
NeedInformation | Requested file action pending further information.
ServiceUnavailable | Service not available, closing control connection.
DataConnectionUnavailable | Can't open data connection.
TransferAborted | Connection closed, transfer aborted.
FileActionAborted | Requested file action not taken.
LocalError | Requested action aborted, local error in processing.
InsufficientStorageSpace | Requested action not taken; insufficient storage space in system, file unavailable.
CommandUnknown | Syntax error, command unrecognized.
ParametersUnknown | Syntax error in parameters or arguments.
CommandNotImplemented | Command not implemented.
BadCommandSequence | Bad sequence of commands.
ParameterNotImplemented | Command not implemented for that parameter.
NotLoggedIn | Not logged in.
NeedAccountToStore | Need account for storing files.
FileUnavailable | Requested action not taken, file unavailable.
PageTypeUnknown | Requested action aborted, page type unknown.
NotEnoughMemory | Requested file action aborted, exceeded storage allocation.
FilenameNotAllowed | Requested action not taken, file name not allowed.
InvalidResponse | Response is not a valid FTP one.
ConnectionFailed | Connection with server failed.
ConnectionClosed | Connection with server closed.
InvalidFile | Invalid file to upload / download.

Definition at line 74 of file Ftp.hpp.

Constructor & Destructor Documentation

sf::Ftp::Ftp::ListingResponse::ListingResponse | ( | Ftp::Response | Resp,
 |  | const std::vector< char > & | Data
 | ) |  |

Default constructor.

Parameters:
Resp | : Source response
Data | : Data containing the raw listing

Definition at line 148 of file Ftp.cpp.

Member Function Documentation

std::size_t sf::Ftp::Ftp::ListingResponse::GetCount ( ) const

Get the number of filenames in the listing.

Returns:
Total number of filenames

Definition at line 168 of file Ftp.cpp.

const std::string & sf::Ftp::Ftp::ListingResponse::GetFilename ( std::size_t Index ) const

Get the Index-th filename in the directory.

Parameters:
Index : Index of the filename to get
Returns:
Index-th filename

Definition at line 177 of file Ftp.cpp.

const std::string & sf::Ftp::Ftp::Response::GetMessage ( ) const [inherited]

Get the full message contained in the response.

Returns:
The response message

Definition at line 114 of file Ftp.cpp.

Ftp::Response::Status sf::Ftp::Ftp::Response::GetStatus ( ) const [inherited]

Get the response status code.

Returns:
Status code

Definition at line 105 of file Ftp.cpp.

bool sf::Ftp::Ftp::Response::IsOk ( ) const [inherited]

Convenience function to check if the response status code means a success.

Convenience function to check if the response status code means a success.

Returns:
True if status is success (code < 400)

Definition at line 96 of file Ftp.cpp.

The documentation for this class was generated from the following files:
  • Ftp.hpp
  • Ftp.cpp


sf::Ftp::Ftp::ListingResponse Member List

This is the complete list of members for sf::Ftp::Ftp::ListingResponse, including all inherited members.

BadCommandSequence enum value | sf::Ftp::Ftp::Response
ClosingConnection enum value | sf::Ftp::Ftp::Response
ClosingDataConnection enum value | sf::Ftp::Ftp::Response
CommandNotImplemented enum value | sf::Ftp::Ftp::Response
CommandUnknown enum value | sf::Ftp::Ftp::Response
ConnectionClosed enum value | sf::Ftp::Ftp::Response
ConnectionFailed enum value | sf::Ftp::Ftp::Response
DataConnectionAlreadyOpened enum value | sf::Ftp::Ftp::Response
DataConnectionOpened enum value | sf::Ftp::Ftp::Response
DataConnectionUnavailable enum value | sf::Ftp::Ftp::Response
DirectoryOk enum value | sf::Ftp::Ftp::Response
DirectoryStatus enum value | sf::Ftp::Ftp::Response
EnteringPassiveMode enum value | sf::Ftp::Ftp::Response
FileActionAborted enum value | sf::Ftp::Ftp::Response
FileActionOk enum value | sf::Ftp::Ftp::Response
FilenameNotAllowed enum value | sf::Ftp::Ftp::Response
FileStatus enum value | sf::Ftp::Ftp::Response
FileUnavailable enum value | sf::Ftp::Ftp::Response
GetCount() const | sf::Ftp::Ftp::ListingResponse
GetFilename(std::size_t Index) const | sf::Ftp::Ftp::ListingResponse
GetMessage() const | sf::Ftp::Ftp::Response
GetStatus() const | sf::Ftp::Ftp::Response
HelpMessage enum value | sf::Ftp::Ftp::Response
InsufficientStorageSpace enum value | sf::Ftp::Ftp::Response
InvalidFile enum value | sf::Ftp::Ftp::Response
InvalidResponse enum value | sf::Ftp::Ftp::Response
IsOk() const | sf::Ftp::Ftp::Response
ListingResponse(Response Resp, const std::vector< char > &Data) | sf::Ftp::Ftp::ListingResponse
LocalError enum value | sf::Ftp::Ftp::Response
LoggedIn enum value | sf::Ftp::Ftp::Response
NeedAccountToLogIn enum value | sf::Ftp::Ftp::Response
NeedAccountToStore enum value | sf::Ftp::Ftp::Response
NeedInformation enum value | sf::Ftp::Ftp::Response
NeedPassword enum value | sf::Ftp::Ftp::Response
NotEnoughMemory enum value | sf::Ftp::Ftp::Response
NotLoggedIn enum value | sf::Ftp::Ftp::Response
Ok enum value | sf::Ftp::Ftp::Response
OpeningDataConnection enum value | sf::Ftp::Ftp::Response
PageTypeUnknown enum value | sf::Ftp::Ftp::Response
ParameterNotImplemented enum value | sf::Ftp::Ftp::Response
ParametersUnknown enum value | sf::Ftp::Ftp::Response
PointlessCommand enum value | sf::Ftp::Ftp::Response
Response(Status Code=InvalidResponse, const std::string &Message="") | sf::Ftp::Ftp::Response
RestartMarkerReply enum value | sf::Ftp::Ftp::Response
ServiceReady enum value | sf::Ftp::Ftp::Response
ServiceReadySoon enum value | sf::Ftp::Ftp::Response
ServiceUnavailable enum value | sf::Ftp::Ftp::Response
Status enum name | sf::Ftp::Ftp::Response
SystemStatus enum value | sf::Ftp::Ftp::Response
SystemType enum value | sf::Ftp::Ftp::Response
TransferAborted enum value | sf::Ftp::Ftp::Response


sf::Ftp::Response

sf::Ftp::Ftp::Response Class Reference

This class wraps a FTP response, which is basically :
  • a status code
  • a message.
More...

#include <Ftp.hpp>

Inheritance diagram for sf::Ftp::Ftp::Response:

sf::Ftp::Ftp::DirectoryResponse sf::Ftp::Ftp::ListingResponse

List of all members.

Public Types

enum Status {
RestartMarkerReply = 110,
ServiceReadySoon = 120,
DataConnectionAlreadyOpened = 125,
OpeningDataConnection = 150,
Ok = 200,
PointlessCommand = 202,
SystemStatus = 211,
DirectoryStatus = 212,
FileStatus = 213,
HelpMessage = 214,
SystemType = 215,
ServiceReady = 220,
ClosingConnection = 221,
DataConnectionOpened = 225,
ClosingDataConnection = 226,
EnteringPassiveMode = 227,
LoggedIn = 230,
FileActionOk = 250,
DirectoryOk = 257,
NeedPassword = 331,
NeedAccountToLogIn = 332,
NeedInformation = 350,
ServiceUnavailable = 421,
DataConnectionUnavailable = 425,
TransferAborted = 426,
FileActionAborted = 450,
LocalError = 451,
InsufficientStorageSpace = 452,
CommandUnknown = 500,
ParametersUnknown = 501,
CommandNotImplemented = 502,
BadCommandSequence = 503,
ParameterNotImplemented = 504,
NotLoggedIn = 530,
NeedAccountToStore = 532,
FileUnavailable = 550,
PageTypeUnknown = 551,
NotEnoughMemory = 552,
FilenameNotAllowed = 553,
InvalidResponse = 1000,
ConnectionFailed = 1001,
ConnectionClosed = 1002,
InvalidFile = 1003
}
Enumerate all the valid status codes returned in a FTP response. More...

Public Member Functions

Response (Status Code=InvalidResponse, const std::string &Message="")
Default constructor.
bool | IsOk () const
Convenience function to check if the response status code means a success.
Status | GetStatus () const
Get the response status code.
const std::string & | GetMessage () const
Get the full message contained in the response.

Detailed Description

This class wraps a FTP response, which is basically :
  • a status code
  • a message.

Definition at line 66 of file Ftp.hpp.

Member Enumeration Documentation

enum sf::Ftp::Response::Status

Enumerate all the valid status codes returned in a FTP response.

Enumerator:
RestartMarkerReply | Restart marker reply.
ServiceReadySoon | Service ready in N minutes.
DataConnectionAlreadyOpened | Data connection already opened, transfer starting.
OpeningDataConnection | File status ok, about to open data connection.
Ok | Command ok.
PointlessCommand | Command not implemented.
SystemStatus | System status, or system help reply.
DirectoryStatus | Directory status.
FileStatus | File status.
HelpMessage | Help message.
SystemType | NAME system type, where NAME is an official system name from the list in the Assigned Numbers document.
ServiceReady | Service ready for new user.
ClosingConnection | Service closing control connection.
DataConnectionOpened | Data connection open, no transfer in progress.
ClosingDataConnection | Closing data connection, requested file action successful.
EnteringPassiveMode | Entering passive mode.
LoggedIn | User logged in, proceed. Logged out if appropriate.
FileActionOk | Requested file action ok.
DirectoryOk | PATHNAME created.
NeedPassword | User name ok, need password.
NeedAccountToLogIn | Need account for login.
NeedInformation | Requested file action pending further information.
ServiceUnavailable | Service not available, closing control connection.
DataConnectionUnavailable | Can't open data connection.
TransferAborted | Connection closed, transfer aborted.
FileActionAborted | Requested file action not taken.
LocalError | Requested action aborted, local error in processing.
InsufficientStorageSpace | Requested action not taken; insufficient storage space in system, file unavailable.
CommandUnknown | Syntax error, command unrecognized.
ParametersUnknown | Syntax error in parameters or arguments.
CommandNotImplemented | Command not implemented.
BadCommandSequence | Bad sequence of commands.
ParameterNotImplemented | Command not implemented for that parameter.
NotLoggedIn | Not logged in.
NeedAccountToStore | Need account for storing files.
FileUnavailable | Requested action not taken, file unavailable.
PageTypeUnknown | Requested action aborted, page type unknown.
NotEnoughMemory | Requested file action aborted, exceeded storage allocation.
FilenameNotAllowed | Requested action not taken, file name not allowed.
InvalidResponse | Response is not a valid FTP one.
ConnectionFailed | Connection with server failed.
ConnectionClosed | Connection with server closed.
InvalidFile | Invalid file to upload / download.

Definition at line 74 of file Ftp.hpp.

Constructor & Destructor Documentation

sf::Ftp::Ftp::Response::Response | ( | Status | Code = InvalidResponse,
 |  | const std::string & | Message = ""
 | ) |  |

Default constructor.

Parameters:
Code | : Response status code (InvalidResponse by default)
Message | : Response message (empty by default)

Definition at line 84 of file Ftp.cpp.

Member Function Documentation

const std::string & sf::Ftp::Ftp::Response::GetMessage ( ) const

Get the full message contained in the response.

Returns:
The response message

Definition at line 114 of file Ftp.cpp.

Ftp::Response::Status sf::Ftp::Ftp::Response::GetStatus ( ) const

Get the response status code.

Returns:
Status code

Definition at line 105 of file Ftp.cpp.

bool sf::Ftp::Ftp::Response::IsOk ( ) const

Convenience function to check if the response status code means a success.

Convenience function to check if the response status code means a success.

Returns:
True if status is success (code < 400)

Definition at line 96 of file Ftp.cpp.

The documentation for this class was generated from the following files:
  • Ftp.hpp
  • Ftp.cpp


sf::Ftp::Ftp::Response Member List

This is the complete list of members for sf::Ftp::Ftp::Response, including all inherited members.

BadCommandSequence enum value | sf::Ftp::Ftp::Response
ClosingConnection enum value | sf::Ftp::Ftp::Response
ClosingDataConnection enum value | sf::Ftp::Ftp::Response
CommandNotImplemented enum value | sf::Ftp::Ftp::Response
CommandUnknown enum value | sf::Ftp::Ftp::Response
ConnectionClosed enum value | sf::Ftp::Ftp::Response
ConnectionFailed enum value | sf::Ftp::Ftp::Response
DataConnectionAlreadyOpened enum value | sf::Ftp::Ftp::Response
DataConnectionOpened enum value | sf::Ftp::Ftp::Response
DataConnectionUnavailable enum value | sf::Ftp::Ftp::Response
DirectoryOk enum value | sf::Ftp::Ftp::Response
DirectoryStatus enum value | sf::Ftp::Ftp::Response
EnteringPassiveMode enum value | sf::Ftp::Ftp::Response
FileActionAborted enum value | sf::Ftp::Ftp::Response
FileActionOk enum value | sf::Ftp::Ftp::Response
FilenameNotAllowed enum value | sf::Ftp::Ftp::Response
FileStatus enum value | sf::Ftp::Ftp::Response
FileUnavailable enum value | sf::Ftp::Ftp::Response
GetMessage() const | sf::Ftp::Ftp::Response
GetStatus() const | sf::Ftp::Ftp::Response
HelpMessage enum value | sf::Ftp::Ftp::Response
InsufficientStorageSpace enum value | sf::Ftp::Ftp::Response
InvalidFile enum value | sf::Ftp::Ftp::Response
InvalidResponse enum value | sf::Ftp::Ftp::Response
IsOk() const | sf::Ftp::Ftp::Response
LocalError enum value | sf::Ftp::Ftp::Response
LoggedIn enum value | sf::Ftp::Ftp::Response
NeedAccountToLogIn enum value | sf::Ftp::Ftp::Response
NeedAccountToStore enum value | sf::Ftp::Ftp::Response
NeedInformation enum value | sf::Ftp::Ftp::Response
NeedPassword enum value | sf::Ftp::Ftp::Response
NotEnoughMemory enum value | sf::Ftp::Ftp::Response
NotLoggedIn enum value | sf::Ftp::Ftp::Response
Ok enum value | sf::Ftp::Ftp::Response
OpeningDataConnection enum value | sf::Ftp::Ftp::Response
PageTypeUnknown enum value | sf::Ftp::Ftp::Response
ParameterNotImplemented enum value | sf::Ftp::Ftp::Response
ParametersUnknown enum value | sf::Ftp::Ftp::Response
PointlessCommand enum value | sf::Ftp::Ftp::Response
Response(Status Code=InvalidResponse, const std::string &Message="") | sf::Ftp::Ftp::Response
RestartMarkerReply enum value | sf::Ftp::Ftp::Response
ServiceReady enum value | sf::Ftp::Ftp::Response
ServiceReadySoon enum value | sf::Ftp::Ftp::Response
ServiceUnavailable enum value | sf::Ftp::Ftp::Response
Status enum name | sf::Ftp::Ftp::Response
SystemStatus enum value | sf::Ftp::Ftp::Response
SystemType enum value | sf::Ftp::Ftp::Response
TransferAborted enum value | sf::Ftp::Ftp::Response


sf::Glyph

sf::Glyph Class Reference

Structure describing a glyph (a visual character). More...

#include <Glyph.hpp>

List of all members.

Public Member Functions

Glyph ()
Default constructor.

Public Attributes

int Advance
Offset to move horizontically to the next character.
IntRect Rectangle
Bounding rectangle of the glyph, in relative coordinates.
FloatRect TexCoords
Texture coordinates of the glyph inside the bitmap font.

Detailed Description

Structure describing a glyph (a visual character).

Definition at line 40 of file Glyph.hpp.

Constructor & Destructor Documentation

sf::Glyph::Glyph ( ) [inline]

Default constructor.

Definition at line 48 of file Glyph.hpp.

Member Data Documentation

int sf::Glyph::Advance

Offset to move horizontically to the next character.

Definition at line 53 of file Glyph.hpp.

IntRect sf::Glyph::Rectangle

Bounding rectangle of the glyph, in relative coordinates.

Definition at line 54 of file Glyph.hpp.

FloatRect sf::Glyph::TexCoords

Texture coordinates of the glyph inside the bitmap font.

Definition at line 55 of file Glyph.hpp.

The documentation for this class was generated from the following file:
  • Glyph.hpp


sf::Glyph Member List

This is the complete list of members for sf::Glyph, including all inherited members.

Advance | sf::Glyph |
Glyph() | sf::Glyph | [inline]
Rectangle | sf::Glyph |
TexCoords | sf::Glyph |


sf::Http

sf::Http Class Reference

This class provides methods for manipulating the HTTP protocol (described in RFC 1945). More...

#include <Http.hpp>

Inheritance diagram for sf::Http:

sf::NonCopyable

List of all members.

Classes

class | Request
This class wraps an HTTP request, which is basically :
  • a header with a method, a target URI, and a set of field/value pairs
  • an optional body (for POST requests).
More...
class | Response
This class wraps an HTTP response, which is basically :
  • a header with a status code and a set of field/value pairs
  • a body (the content of the requested resource).
More...

Public Member Functions

Http ()
Default constructor.
Http (const std::string &Host, unsigned short Port=0)
Construct the Http instance with the target host.
void | SetHost (const std::string &Host, unsigned short Port=0)
Set the target host.
Response | SendRequest (const Request &Req, float Timeout=0.f)
Send a HTTP request and return the server's response.

Detailed Description

This class provides methods for manipulating the HTTP protocol (described in RFC 1945).

It can connect to a website, get its files, send requests, etc.

Definition at line 45 of file Http.hpp.

Constructor & Destructor Documentation

sf::Http::Http ( )

Default constructor.

Definition at line 307 of file Http.cpp.

sf::Http::Http | ( | const std::string & | Host,
 |  | unsigned short | Port = 0
 | ) |  |

Construct the Http instance with the target host.

Parameters:
Host | : Web server to connect to
Port | : Port to use for connection (0 by default -- use the standard port of the protocol used)

Definition at line 318 of file Http.cpp.

Member Function Documentation

Http::Response sf::Http::SendRequest | ( | const Request & | Req,
 |  | float | Timeout = 0.f
 | ) |  |

Send a HTTP request and return the server's response.

You must be connected to a host before sending requests. Any missing mandatory header field will be added with an appropriate value. Warning : this function waits for the server's response and may not return instantly; use a thread if you don't want to block your application.

Parameters:
Req | : Request to send
Timeout | : Maximum time to wait, in seconds (0 by default, means no timeout)
Returns:
Server's response
You must be connected to a host before sending requests. Any missing mandatory header field will be added with an appropriate value. Warning : this function waits for the server's response and may not return instantly; use a thread if you don't want to block your application.

Definition at line 366 of file Http.cpp.

void sf::Http::SetHost | ( | const std::string & | Host,
 |  | unsigned short | Port = 0
 | ) |  |

Set the target host.

Parameters:
Host | : Web server to connect to
Port | : Port to use for connection (0 by default -- use the standard port of the protocol used)

Definition at line 327 of file Http.cpp.

The documentation for this class was generated from the following files:
  • Http.hpp
  • Http.cpp


sf::Http Member List

This is the complete list of members for sf::Http, including all inherited members.

Http() | sf::Http |
Http(const std::string &Host, unsigned short Port=0) | sf::Http |
NonCopyable() | sf::NonCopyable | [inline, private]
SendRequest(const Request &Req, float Timeout=0.f) | sf::Http |
SetHost(const std::string &Host, unsigned short Port=0) | sf::Http |


sf::Http::Request

sf::Http::Http::Request Class Reference

This class wraps an HTTP request, which is basically :
  • a header with a method, a target URI, and a set of field/value pairs
  • an optional body (for POST requests).
More...

#include <Http.hpp>

List of all members.

Public Types

enum Method {
Get,
Post,
Head
}
Enumerate the available HTTP methods for a request. More...

Public Member Functions

Request (Method RequestMethod=Get, const std::string &URI="/", const std::string &Body="")
Default constructor.
void | SetField (const std::string &Field, const std::string &Value)
Set the value of a field; the field is added if it doesn't exist.
void | SetMethod (Method RequestMethod)
Set the request method.
void | SetURI (const std::string &URI)
Set the target URI of the request.
void | SetHttpVersion (unsigned int Major, unsigned int Minor)
Set the HTTP version of the request.
void | SetBody (const std::string &Body)
Set the body of the request.

Friends

class | Http

Detailed Description

This class wraps an HTTP request, which is basically :
  • a header with a method, a target URI, and a set of field/value pairs
  • an optional body (for POST requests).

Definition at line 54 of file Http.hpp.

Member Enumeration Documentation

enum sf::Http::Request::Method

Enumerate the available HTTP methods for a request.

Enumerator:
Get | Request in get mode, standard method to retrieve a page.
Post | Request in post mode, usually to send data to a page.
Head | Request a page's header only.

Definition at line 61 of file Http.hpp.

Constructor & Destructor Documentation

sf::Http::Http::Request::Request | ( | Method | RequestMethod = Get,
 |  | const std::string & | URI = "/",
 |  | const std::string & | Body = ""
 | ) |  |

Default constructor.

Parameters:
RequestMethod | : Method to use for the request (Get by default)
URI | : Target URI ("/" by default -- index page)
Body | : Content of the request's body (empty by default)

Definition at line 56 of file Http.cpp.

Member Function Documentation

void sf::Http::Http::Request::SetBody ( const std::string & Body )

Set the body of the request.

This parameter is optional and makes sense only for POST requests. This parameter is empty by default

Parameters:
Body : Content of the request body
This parameter is optional and makes sense only for POST requests. This parameter is empty by default

Definition at line 114 of file Http.cpp.

void sf::Http::Http::Request::SetField | ( | const std::string & | Field,
 |  | const std::string & | Value
 | ) |  |

Set the value of a field; the field is added if it doesn't exist.

Parameters:
Field | : Name of the field to set (case-insensitive)
Value | : Value of the field

Definition at line 68 of file Http.cpp.

void sf::Http::Http::Request::SetHttpVersion | ( | unsigned int | Major,
 |  | unsigned int | Minor
 | ) |  |

Set the HTTP version of the request.

This parameter is 1.0 by default

Parameters:
Major | : Major version number
Minor | : Minor version number
This parameter is 1.0 by default

Definition at line 102 of file Http.cpp.

void sf::Http::Http::Request::SetMethod ( Method RequestMethod )

Set the request method.

This parameter is Http::Request::Get by default

Parameters:
RequestMethod : Method to use for the request
This parameter is Get by default

Definition at line 78 of file Http.cpp.

void sf::Http::Http::Request::SetURI ( const std::string & URI )

Set the target URI of the request.

This parameter is "/" by default

Parameters:
URI : URI to request, local to the host
This parameter is "/" by default

Definition at line 88 of file Http.cpp.

The documentation for this class was generated from the following files:
  • Http.hpp
  • Http.cpp


sf::Http::Http::Request Member List

This is the complete list of members for sf::Http::Http::Request, including all inherited members.

Get enum value | sf::Http::Http::Request |
Head enum value | sf::Http::Http::Request |
Http (defined in sf::Http::Http::Request) | sf::Http::Http::Request | [friend]
Method enum name | sf::Http::Http::Request |
Post enum value | sf::Http::Http::Request |
Request(Method RequestMethod=Get, const std::string &URI="/", const std::string &Body="") | sf::Http::Http::Request |
SetBody(const std::string &Body) | sf::Http::Http::Request |
SetField(const std::string &Field, const std::string &Value) | sf::Http::Http::Request |
SetHttpVersion(unsigned int Major, unsigned int Minor) | sf::Http::Http::Request |
SetMethod(Method RequestMethod) | sf::Http::Http::Request |
SetURI(const std::string &URI) | sf::Http::Http::Request |


sf::Http::Response

sf::Http::Http::Response Class Reference

This class wraps an HTTP response, which is basically :
  • a header with a status code and a set of field/value pairs
  • a body (the content of the requested resource).
More...

#include <Http.hpp>

List of all members.

Public Types

enum Status {
Ok = 200,
Created = 201,
Accepted = 202,
NoContent = 204,
MultipleChoices = 300,
MovedPermanently = 301,
MovedTemporarily = 302,
NotModified = 304,
BadRequest = 400,
Unauthorized = 401,
Forbidden = 403,
NotFound = 404,
InternalServerError = 500,
NotImplemented = 501,
BadGateway = 502,
ServiceNotAvailable = 503,
InvalidResponse = 1000,
ConnectionFailed = 1001
}
Enumerate all the valid status codes returned in a HTTP response. More...

Public Member Functions

Response ()
Default constructor.
const std::string & | GetField (const std::string &Field) const
Get the value of a field.
Status | GetStatus () const
Get the header's status code.
unsigned int | GetMajorHttpVersion () const
Get the major HTTP version number of the response.
unsigned int | GetMinorHttpVersion () const
Get the major HTTP version number of the response.
const std::string & | GetBody () const
Get the body of the response.

Friends

class | Http

Detailed Description

This class wraps an HTTP response, which is basically :
  • a header with a status code and a set of field/value pairs
  • a body (the content of the requested resource).

Definition at line 168 of file Http.hpp.

Member Enumeration Documentation

enum sf::Http::Response::Status

Enumerate all the valid status codes returned in a HTTP response.

Enumerator:
Ok | Most common code returned when operation was successful.
Created | The resource has successfully been created.
Accepted | The request has been accepted, but will be processed later by the server.
NoContent | Sent when the server didn't send any data in return.
MultipleChoices | The requested page can be accessed from several locations.
MovedPermanently | The requested page has permanently moved to a new location.
MovedTemporarily | The requested page has temporarily moved to a new location.
NotModified | For conditionnal requests, means the requested page hasn't changed and doesn't need to be refreshed.
BadRequest | The server couldn't understand the request (syntax error).
Unauthorized | The requested page needs an authentification to be accessed.
Forbidden | The requested page cannot be accessed at all, even with authentification.
NotFound | The requested page doesn't exist.
InternalServerError | The server encountered an unexpected error.
NotImplemented | The server doesn't implement a requested feature.
BadGateway | The gateway server has received an error from the source server.
ServiceNotAvailable | The server is temporarily unavailable (overloaded, in maintenance, ...).
InvalidResponse | Response is not a valid HTTP one.
ConnectionFailed | Connection with server failed.

Definition at line 176 of file Http.hpp.

Constructor & Destructor Documentation

sf::Http::Http::Response::Response ( )

Default constructor.

Definition at line 169 of file Http.cpp.

Member Function Documentation

const std::string & sf::Http::Http::Response::GetBody ( ) const

Get the body of the response.

The body can contain :

  • the requested page (for GET requests)
  • a response from the server (for POST requests)
  • nothing (for HEAD requests)
  • an error message (in case of an error)

Returns:
The response body
The body can contain :
  • the requested page (for GET requests)
  • a response from the server (for POST requests)
  • nothing (for HEAD requests)
  • an error message (in case of an error)

Definition at line 230 of file Http.cpp.

const std::string & sf::Http::Http::Response::GetField ( const std::string & Field ) const

Get the value of a field.

Parameters:
Field : Name of the field to get (case-insensitive)
Returns:
Value of the field, or empty string if not found

Definition at line 181 of file Http.cpp.

unsigned int sf::Http::Http::Response::GetMajorHttpVersion ( ) const

Get the major HTTP version number of the response.

Returns:
Major version number

Definition at line 208 of file Http.cpp.

unsigned int sf::Http::Http::Response::GetMinorHttpVersion ( ) const

Get the major HTTP version number of the response.

Returns:
Major version number

Definition at line 217 of file Http.cpp.

Http::Response::Status sf::Http::Http::Response::GetStatus ( ) const

Get the header's status code.

Returns:
Header's status code

Definition at line 199 of file Http.cpp.

The documentation for this class was generated from the following files:
  • Http.hpp
  • Http.cpp


sf::Http::Http::Response Member List

This is the complete list of members for sf::Http::Http::Response, including all inherited members.

Accepted enum value | sf::Http::Http::Response |
BadGateway enum value | sf::Http::Http::Response |
BadRequest enum value | sf::Http::Http::Response |
ConnectionFailed enum value | sf::Http::Http::Response |
Created enum value | sf::Http::Http::Response |
Forbidden enum value | sf::Http::Http::Response |
GetBody() const | sf::Http::Http::Response |
GetField(const std::string &Field) const | sf::Http::Http::Response |
GetMajorHttpVersion() const | sf::Http::Http::Response |
GetMinorHttpVersion() const | sf::Http::Http::Response |
GetStatus() const | sf::Http::Http::Response |
Http (defined in sf::Http::Http::Response) | sf::Http::Http::Response | [friend]
InternalServerError enum value | sf::Http::Http::Response |
InvalidResponse enum value | sf::Http::Http::Response |
MovedPermanently enum value | sf::Http::Http::Response |
MovedTemporarily enum value | sf::Http::Http::Response |
MultipleChoices enum value | sf::Http::Http::Response |
NoContent enum value | sf::Http::Http::Response |
NotFound enum value | sf::Http::Http::Response |
NotImplemented enum value | sf::Http::Http::Response |
NotModified enum value | sf::Http::Http::Response |
Ok enum value | sf::Http::Http::Response |
Response() | sf::Http::Http::Response |
ServiceNotAvailable enum value | sf::Http::Http::Response |
Status enum name | sf::Http::Http::Response |
Unauthorized enum value | sf::Http::Http::Response |


sf::Image

sf::Image Class Reference

Image is the low-level class for loading and manipulating images. More...

#include <Image.hpp>

Inheritance diagram for sf::Image:

sf::Resource< Image >

List of all members.

Public Member Functions

Image ()
Default constructor.
Image (const Image &Copy)
Copy constructor.
Image (unsigned int Width, unsigned int Height, const Color &Col=Color(0, 0, 0, 255))
Construct an empty image.
Image (unsigned int Width, unsigned int Height, const Uint8 *Data)
Construct the image from pixels in memory.
~Image ()
Destructor.
bool | LoadFromFile (const std::string &Filename)
Load the image from a file.
bool | LoadFromMemory (const char *Data, std::size_t SizeInBytes)
Load the image from a file in memory.
bool | LoadFromPixels (unsigned int Width, unsigned int Height, const Uint8 *Data)
Load the image directly from an array of pixels.
bool | SaveToFile (const std::string &Filename) const
Save the content of the image to a file.
bool | Create (unsigned int Width, unsigned int Height, Color Col=Color(0, 0, 0, 255))
Create an empty image.
void | CreateMaskFromColor (Color ColorKey, Uint8 Alpha=0)
Create transparency mask from a specified colorkey.
void | Copy (const Image &Source, unsigned int DestX, unsigned int DestY, const IntRect &SourceRect=IntRect(0, 0, 0, 0), bool ApplyAlpha=false)
Copy pixels from another image onto this one.
bool | CopyScreen (RenderWindow &Window, const IntRect &SourceRect=IntRect(0, 0, 0, 0))
Create the image from the current contents of the given window.
void | SetPixel (unsigned int X, unsigned int Y, const Color &Col)
Change the color of a pixel.
const Color & | GetPixel (unsigned int X, unsigned int Y) const
Get a pixel from the image.
const Uint8 * | GetPixelsPtr () const
Get a read-only pointer to the array of pixels (RGBA 8 bits integers components) Array size is GetWidth() x GetHeight() x 4 This pointer becomes invalid if you reload or resize the image.
void | Bind () const
Bind the image for rendering.
void | SetSmooth (bool Smooth)
Enable or disable image smooth filter.
unsigned int | GetWidth () const
Return the width of the image.
unsigned int | GetHeight () const
Return the height of the image.
bool | IsSmooth () const
Tells whether the smooth filtering is enabled or not.
FloatRect | GetTexCoords (const IntRect &Rect) const
Convert a subrect expressed in pixels, into float texture coordinates.
Image & | operator= (const Image &Other)
Assignment operator.

Static Public Member Functions

static unsigned int | GetValidTextureSize (unsigned int Size)
Get a valid texture size according to hardware support.

Detailed Description

Image is the low-level class for loading and manipulating images.

Definition at line 46 of file Image.hpp.

Constructor & Destructor Documentation

sf::Image::Image ( )

Default constructor.

Definition at line 43 of file Image.cpp.

sf::Image::Image ( const Image & Copy )

Copy constructor.

Parameters:
Copy : instance to copy

Definition at line 60 of file Image.cpp.

sf::Image::Image | ( | unsigned int | Width,
 |  | unsigned int | Height,
 |  | const Color & | Col = Color(0, 0, 0, 255)
 | ) |  |

Construct an empty image.

Parameters:
Width | : Image width
Height | : Image height
Col | : Image color (black by default)

Definition at line 79 of file Image.cpp.

sf::Image::Image | ( | unsigned int | Width,
 |  | unsigned int | Height,
 |  | const Uint8 * | Data
 | ) |  |

Construct the image from pixels in memory.

Parameters:
Width | : Image width
Height | : Image height
Data | : Pointer to the pixels in memory (assumed format is RGBA)

Definition at line 96 of file Image.cpp.

sf::Image::~Image ( )

Destructor.

Definition at line 113 of file Image.cpp.

Member Function Documentation

void sf::Image::Bind ( ) const

Bind the image for rendering.

Definition at line 473 of file Image.cpp.

void sf::Image::Copy | ( | const Image & | Source,
 |  | unsigned int | DestX,
 |  | unsigned int | DestY,
 |  | const IntRect & | SourceRect = IntRect(0, 0, 0, 0),
 |  | bool | ApplyAlpha = false
 | ) |  |

Copy pixels from another image onto this one.

This function does a slow pixel copy and should only be used at initialization time

Parameters:
Source | : Source image to copy
DestX | : X coordinate of the destination position
DestY | : Y coordinate of the destination position
SourceRect | : Sub-rectangle of the source image to copy (empty by default - entire image)
ApplyAlpha | : Should the copy take in account the source transparency? (false by default)
This function does a slow pixel copy and should only be used at initialization time

Definition at line 270 of file Image.cpp.

bool sf::Image::CopyScreen | ( | RenderWindow & | Window,
 |  | const IntRect & | SourceRect = IntRect(0, 0, 0, 0)
 | ) |  |

Create the image from the current contents of the given window.

Create the image from the current contents of the given window.

Parameters:
Window | : Window to capture
SourceRect | : Sub-rectangle of the screen to copy (empty by default - entire image)
Returns:
True if copy was successful

Definition at line 358 of file Image.cpp.

bool sf::Image::Create | ( | unsigned int | Width,
 |  | unsigned int | Height,
 |  | Color | Col = Color(0, 0, 0, 255)
 | ) |  |

Create an empty image.

Parameters:
Width | : Image width
Height | : Image height
Col | : Image color (black by default)
Returns:
True if creation was successful

Definition at line 222 of file Image.cpp.

void sf::Image::CreateMaskFromColor | ( | Color | ColorKey,
 |  | Uint8 | Alpha = 0
 | ) |  |

Create transparency mask from a specified colorkey.

Parameters:
ColorKey | : Color to become transparent
Alpha | : Alpha value to use for transparent pixels (0 by default)

Definition at line 249 of file Image.cpp.

unsigned int sf::Image::GetHeight ( ) const

Return the height of the image.

Returns:
Height in pixels

Definition at line 526 of file Image.cpp.

const Color & sf::Image::GetPixel | ( | unsigned int | X,
 |  | unsigned int | Y |
 | ) |  |  | const

Get a pixel from the image.

Parameters:
X | : X coordinate of pixel in the image
Y | : Y coordinate of pixel in the image
Returns:
Color of pixel (X, Y)

Definition at line 431 of file Image.cpp.

const Uint8 * sf::Image::GetPixelsPtr ( ) const

Get a read-only pointer to the array of pixels (RGBA 8 bits integers components) Array size is GetWidth() x GetHeight() x 4 This pointer becomes invalid if you reload or resize the image.

Get a read-only pointer to the array of pixels (RGBA 8 bits integers components) Array size is GetWidth() x GetHeight() x 4 This pointer becomes invalid if you reload or resize the image.

Returns:
Const pointer to the array of pixels

Definition at line 453 of file Image.cpp.

FloatRect sf::Image::GetTexCoords ( const IntRect & Rect ) const

Convert a subrect expressed in pixels, into float texture coordinates.

Convert a subrect expressed in pixels, into float texture coordinates.

Parameters:
Rect : Sub-rectangle of image to convert
Returns:
Texture coordinates corresponding to the sub-rectangle

Definition at line 545 of file Image.cpp.

unsigned int sf::Image::GetValidTextureSize ( unsigned int Size ) [static]

Get a valid texture size according to hardware support.

Parameters:
Size : Size to convert
Returns:
Valid nearest size (greater than or equal to specified size)

Definition at line 560 of file Image.cpp.

unsigned int sf::Image::GetWidth ( ) const

Return the width of the image.

Returns:
Width in pixels

Definition at line 517 of file Image.cpp.

bool sf::Image::IsSmooth ( ) const

Tells whether the smooth filtering is enabled or not.

Returns:
True if image smoothing is enabled

Definition at line 535 of file Image.cpp.

bool sf::Image::LoadFromFile ( const std::string & Filename )

Load the image from a file.

Parameters:
Filename : Path of the image file to load
Returns:
True if loading was successful

Definition at line 123 of file Image.cpp.

bool sf::Image::LoadFromMemory | ( | const char * | Data,
 |  | std::size_t | SizeInBytes
 | ) |  |

Load the image from a file in memory.

Parameters:
Data | : Pointer to the file data in memory
SizeInBytes | : Size of the data to load, in bytes
Returns:
True if loading was successful

Definition at line 145 of file Image.cpp.

bool sf::Image::LoadFromPixels | ( | unsigned int | Width,
 |  | unsigned int | Height,
 |  | const Uint8 * | Data
 | ) |  |

Load the image directly from an array of pixels.

Parameters:
Width | : Image width
Height | : Image height
Data | : Pointer to the pixels in memory (assumed format is RGBA)
Returns:
True if loading was successful

Definition at line 174 of file Image.cpp.

Image & sf::Image::operator= ( const Image & Other )

Assignment operator.

Parameters:
Other : instance to assign
Returns:
Reference to the image

Definition at line 585 of file Image.cpp.

bool sf::Image::SaveToFile ( const std::string & Filename ) const

Save the content of the image to a file.

Parameters:
Filename : Path of the file to save (overwritten if already exist)
Returns:
True if saving was successful

Definition at line 209 of file Image.cpp.

void sf::Image::SetPixel | ( | unsigned int | X,
 |  | unsigned int | Y,
 |  | const Color & | Col
 | ) |  |

Change the color of a pixel.

Parameters:
X | : X coordinate of pixel in the image
Y | : Y coordinate of pixel in the image
Col | : New color for pixel (X, Y)

Definition at line 408 of file Image.cpp.

void sf::Image::SetSmooth ( bool Smooth )

Enable or disable image smooth filter.

Enable or disable image smoothing filter.

This parameter is enabled by default

Parameters:
Smooth : True to enable smoothing filter, false to disable it

Definition at line 490 of file Image.cpp.

The documentation for this class was generated from the following files:
  • Image.hpp
  • Image.cpp


sf::Image Member List

This is the complete list of members for sf::Image, including all inherited members.

Bind() const | sf::Image |
Copy(const Image &Source, unsigned int DestX, unsigned int DestY, const IntRect &SourceRect=IntRect(0, 0, 0, 0), bool ApplyAlpha=false) | sf::Image |
CopyScreen(RenderWindow &Window, const IntRect &SourceRect=IntRect(0, 0, 0, 0)) | sf::Image |
Create(unsigned int Width, unsigned int Height, Color Col=Color(0, 0, 0, 255)) | sf::Image |
CreateMaskFromColor(Color ColorKey, Uint8 Alpha=0) | sf::Image |
GetHeight() const | sf::Image |
GetPixel(unsigned int X, unsigned int Y) const | sf::Image |
GetPixelsPtr() const | sf::Image |
GetTexCoords(const IntRect &Rect) const | sf::Image |
GetValidTextureSize(unsigned int Size) | sf::Image | [static]
GetWidth() const | sf::Image |
Image() | sf::Image |
Image(const Image &Copy) | sf::Image |
Image(unsigned int Width, unsigned int Height, const Color &Col=Color(0, 0, 0, 255)) | sf::Image |
Image(unsigned int Width, unsigned int Height, const Uint8 *Data) | sf::Image |
IsSmooth() const | sf::Image |
LoadFromFile(const std::string &Filename) | sf::Image |
LoadFromMemory(const char *Data, std::size_t SizeInBytes) | sf::Image |
LoadFromPixels(unsigned int Width, unsigned int Height, const Uint8 *Data) | sf::Image |
operator=(const Image &Other) | sf::Image |
Resource< Image >::operator=(const Resource< Image > &Other) | sf::Resource< Image > | [protected]
Resource() | sf::Resource< Image > | [protected]
Resource(const Resource< Image > &Copy) | sf::Resource< Image > | [protected]
SaveToFile(const std::string &Filename) const | sf::Image |
SetPixel(unsigned int X, unsigned int Y, const Color &Col) | sf::Image |
SetSmooth(bool Smooth) | sf::Image |
~Image() | sf::Image |
~Resource() | sf::Resource< Image > | [protected]


sf::Input

sf::Input Class Reference

Input handles real-time input from keyboard and mouse. More...

#include <Input.hpp>

Inheritance diagram for sf::Input:

sf::WindowListener sf::NonCopyable

List of all members.

Public Member Functions

Input ()
Default constructor.
bool | IsKeyDown (Key::Code KeyCode) const
Get the state of a key.
bool | IsMouseButtonDown (Mouse::Button Button) const
Get the state of a mouse button.
bool | IsJoystickButtonDown (unsigned int JoyId, unsigned int Button) const
Get the state of a joystick button.
int | GetMouseX () const
Get the mouse X position.
int | GetMouseY () const
Get the mouse Y position.
float | GetJoystickAxis (unsigned int JoyId, Joy::Axis Axis) const
Get a joystick axis position.

Detailed Description

Input handles real-time input from keyboard and mouse.

Use it instead of events to handle continuous moves and more game-friendly inputs

Definition at line 44 of file Input.hpp.

Constructor & Destructor Documentation

sf::Input::Input ( )

Default constructor.

Definition at line 36 of file Input.cpp.

Member Function Documentation

float sf::Input::GetJoystickAxis | ( | unsigned int | JoyId,
 |  | Joy::Axis | Axis |
 | ) |  |  | const

Get a joystick axis position.

Parameters:
JoyId | : Identifier of the joystick to check (0 or 1)
Axis | : Axis to get
Returns:
Current axis position, in the range [-100, 100] (except for POV, which is [0, 360])

Definition at line 95 of file Input.cpp.

int sf::Input::GetMouseX ( ) const

Get the mouse X position.

Get the mouse left position.

Returns:
Current mouse left position, relative to owner window

Definition at line 77 of file Input.cpp.

int sf::Input::GetMouseY ( ) const

Get the mouse Y position.

Get the mouse top position.

Returns:
Current mouse top position, relative to owner window

Definition at line 86 of file Input.cpp.

bool sf::Input::IsJoystickButtonDown | ( | unsigned int | JoyId,
 |  | unsigned int | Button |
 | ) |  |  | const

Get the state of a joystick button.

Parameters:
JoyId | : Identifier of the joystick to check (0 or 1)
Button | : Button to check
Returns:
True if button is down, false if button is up

Definition at line 65 of file Input.cpp.

bool sf::Input::IsKeyDown ( Key::Code KeyCode ) const

Get the state of a key.

Parameters:
KeyCode : Key to check
Returns:
True if key is down, false if key is up

Definition at line 47 of file Input.cpp.

bool sf::Input::IsMouseButtonDown ( Mouse::Button Button ) const

Get the state of a mouse button.

Parameters:
Button : Button to check
Returns:
True if button is down, false if button is up

Definition at line 56 of file Input.cpp.

The documentation for this class was generated from the following files:
  • Input.hpp
  • Input.cpp


sf::Input Member List

This is the complete list of members for sf::Input, including all inherited members.

GetJoystickAxis(unsigned int JoyId, Joy::Axis Axis) const | sf::Input |
GetMouseX() const | sf::Input |
GetMouseY() const | sf::Input |
Input() | sf::Input |
IsJoystickButtonDown(unsigned int JoyId, unsigned int Button) const | sf::Input |
IsKeyDown(Key::Code KeyCode) const | sf::Input |
IsMouseButtonDown(Mouse::Button Button) const | sf::Input |
NonCopyable() | sf::NonCopyable | [inline, private]
~WindowListener() | sf::WindowListener | [inline, protected, virtual]


sf::IPAddress

sf::IPAddress Class Reference

IPAddress provides easy manipulation of IP v4 addresses. More...

#include <IPAddress.hpp>

List of all members.

Public Member Functions

IPAddress ()
Default constructor -- constructs an invalid address.
IPAddress (const std::string &Address)
Construct the address from a string.
IPAddress (const char *Address)
Construct the address from a C-style string ; Needed for implicit conversions from literal strings to IPAddress to work.
IPAddress (Uint8 Byte0, Uint8 Byte1, Uint8 Byte2, Uint8 Byte3)
Construct the address from 4 bytes.
IPAddress (Uint32 Address)
Construct the address from a 32-bits integer.
bool | IsValid () const
Tell if the address is a valid one.
std::string | ToString () const
Get a string representation of the address.
Uint32 | ToInteger () const
Get an integer representation of the address.
bool | operator== (const IPAddress &Other) const
Comparison operator ==.
bool | operator!= (const IPAddress &Other) const
Comparison operator !=.
bool | operator< (const IPAddress &Other) const
Comparison operator <.
bool | operator> (const IPAddress &Other) const
Comparison operator >.
bool | operator<= (const IPAddress &Other) const
Comparison operator <=.
bool | operator>= (const IPAddress &Other) const
Comparison operator >=.

Static Public Member Functions

static IPAddress | GetLocalAddress ()
Get the computer's local IP address (from the LAN point of view).
static IPAddress | GetPublicAddress (float Timeout=0.f)
Get the computer's public IP address (from the web point of view).

Static Public Attributes

static const IPAddress | LocalHost
Local host address (to connect to the same computer).

Detailed Description

IPAddress provides easy manipulation of IP v4 addresses.

Definition at line 42 of file IPAddress.hpp.

Constructor & Destructor Documentation

sf::IPAddress::IPAddress ( )

Default constructor -- constructs an invalid address.

Default constructor.

Definition at line 45 of file IPAddress.cpp.

sf::IPAddress::IPAddress ( const std::string & Address )

Construct the address from a string.

Parameters:
Address : IP address ("xxx.xxx.xxx.xxx") or network name

Definition at line 55 of file IPAddress.cpp.

sf::IPAddress::IPAddress ( const char * Address )

Construct the address from a C-style string ; Needed for implicit conversions from literal strings to IPAddress to work.

Construct the address from a C-style string ; Needed for implicit conversions from literal strings to IPAddress to work.

Parameters:
Address : IP address ("xxx.xxx.xxx.xxx") or network name

Definition at line 82 of file IPAddress.cpp.

sf::IPAddress::IPAddress | ( | Uint8 | Byte0,
 |  | Uint8 | Byte1,
 |  | Uint8 | Byte2,
 |  | Uint8 | Byte3
 | ) |  |

Construct the address from 4 bytes.

Parameters:
Byte0 | : First byte of the address
Byte1 | : Second byte of the address
Byte2 | : Third byte of the address
Byte3 | : Fourth byte of the address

Definition at line 108 of file IPAddress.cpp.

sf::IPAddress::IPAddress ( Uint32 Address )

Construct the address from a 32-bits integer.

Parameters:
Address : 4 bytes of the address packed into a 32-bits integer

Definition at line 117 of file IPAddress.cpp.

Member Function Documentation

IPAddress sf::IPAddress::GetLocalAddress ( ) [static]

Get the computer's local IP address (from the LAN point of view).

Returns:
Local IP address

Definition at line 156 of file IPAddress.cpp.

IPAddress sf::IPAddress::GetPublicAddress ( float Timeout = 0.f ) [static]

Get the computer's public IP address (from the web point of view).

The only way to get a public address is to ask it to a distant website ; as a consequence, this function may be very slow -- use it as few as possible !

Parameters:
Timeout : Maximum time to wait, in seconds (0 by default : no timeout)
Returns:
Public IP address

Definition at line 204 of file IPAddress.cpp.

bool sf::IPAddress::IsValid ( ) const

Tell if the address is a valid one.

Returns:
True if address has a valid syntax

Definition at line 126 of file IPAddress.cpp.

bool sf::IPAddress::operator!= ( const IPAddress & Other ) const

Comparison operator !=.

Parameters:
Other : Address to compare
Returns:
True if *this != Other

Definition at line 235 of file IPAddress.cpp.

bool sf::IPAddress::operator< ( const IPAddress & Other ) const

Comparison operator <.

Parameters:
Other : Address to compare
Returns:
True if *this < Other

Definition at line 244 of file IPAddress.cpp.

bool sf::IPAddress::operator<= ( const IPAddress & Other ) const

Comparison operator <=.

Parameters:
Other : Address to compare
Returns:
True if *this <= Other

Definition at line 262 of file IPAddress.cpp.

bool sf::IPAddress::operator== ( const IPAddress & Other ) const

Comparison operator ==.

Parameters:
Other : Address to compare
Returns:
True if *this == Other

Definition at line 226 of file IPAddress.cpp.

bool sf::IPAddress::operator> ( const IPAddress & Other ) const

Comparison operator >.

Parameters:
Other : Address to compare
Returns:
True if *this > Other

Definition at line 253 of file IPAddress.cpp.

bool sf::IPAddress::operator>= ( const IPAddress & Other ) const

Comparison operator >=.

Parameters:
Other : Address to compare
Returns:
True if *this >= Other

Definition at line 271 of file IPAddress.cpp.

Uint32 sf::IPAddress::ToInteger ( ) const

Get an integer representation of the address.

Returns:
32-bits integer containing the 4 bytes of the address, in system endianness

Definition at line 147 of file IPAddress.cpp.

std::string sf::IPAddress::ToString ( ) const

Get a string representation of the address.

Returns:
String representation of the IP address ("xxx.xxx.xxx.xxx")

Definition at line 135 of file IPAddress.cpp.

Member Data Documentation

const IPAddress sf::IPAddress::LocalHost [static]

Local host address (to connect to the same computer).

Static member data.

Definition at line 196 of file IPAddress.hpp.

The documentation for this class was generated from the following files:
  • IPAddress.hpp
  • IPAddress.cpp


sf::IPAddress Member List

This is the complete list of members for sf::IPAddress, including all inherited members.

GetLocalAddress() | sf::IPAddress | [static]
GetPublicAddress(float Timeout=0.f) | sf::IPAddress | [static]
IPAddress() | sf::IPAddress |
IPAddress(const std::string &Address) | sf::IPAddress |
IPAddress(const char *Address) | sf::IPAddress |
IPAddress(Uint8 Byte0, Uint8 Byte1, Uint8 Byte2, Uint8 Byte3) | sf::IPAddress |
IPAddress(Uint32 Address) | sf::IPAddress |
IsValid() const | sf::IPAddress |
LocalHost | sf::IPAddress | [static]
operator!=(const IPAddress &Other) const | sf::IPAddress |
operator<(const IPAddress &Other) const | sf::IPAddress |
operator<=(const IPAddress &Other) const | sf::IPAddress |
operator==(const IPAddress &Other) const | sf::IPAddress |
operator>(const IPAddress &Other) const | sf::IPAddress |
operator>=(const IPAddress &Other) const | sf::IPAddress |
ToInteger() const | sf::IPAddress |
ToString() const | sf::IPAddress |


sf::Listener

sf::Listener Class Reference

Listener is a global interface for defining the audio listener properties ; the audio listener is the point in the scene from where all the sounds are heard. More...

#include <Listener.hpp>

List of all members.

Static Public Member Functions

static void | SetGlobalVolume (float Volume)
Change the global volume of all the sounds.
static float | GetGlobalVolume ()
Get the current value of the global volume of all the sounds.
static void | SetPosition (float X, float Y, float Z)
Change the position of the listener (take 3 values).
static void | SetPosition (const Vector3f &Position)
Change the position of the listener (take a 3D vector).
static Vector3f | GetPosition ()
Get the current position of the listener.
static void | SetTarget (float X, float Y, float Z)
Change the orientation of the listener (the point he must look at) (take 3 values).
static void | SetTarget (const Vector3f &Target)
Change the orientation of the listener (the point he must look at) (take a 3D vector).
static Vector3f | GetTarget ()
Get the current orientation of the listener (the point he's looking at).

Detailed Description

Listener is a global interface for defining the audio listener properties ; the audio listener is the point in the scene from where all the sounds are heard.

Definition at line 42 of file Listener.hpp.

Member Function Documentation

float sf::Listener::GetGlobalVolume ( ) [static]

Get the current value of the global volume of all the sounds.

Returns:
Current global volume, in the range [0, 100]

Definition at line 46 of file Listener.cpp.

Vector3f sf::Listener::GetPosition ( ) [static]

Get the current position of the listener.

Returns:
Position of the listener in the world

Definition at line 76 of file Listener.cpp.

Vector3f sf::Listener::GetTarget ( ) [static]

Get the current orientation of the listener (the point he's looking at).

Get the current orientation of the listener (the point he's looking at).

Returns:
: Position of the point the listener is looking at

Definition at line 110 of file Listener.cpp.

void sf::Listener::SetGlobalVolume ( float Volume ) [static]

Change the global volume of all the sounds.

The default volume is 100

Parameters:
Volume : New global volume, in the range [0, 100]

Definition at line 37 of file Listener.cpp.

void sf::Listener::SetPosition ( const Vector3f & Position ) [static]

Change the position of the listener (take a 3D vector).

The default position is (0, 0, 0)

Parameters:
Position : Position of the listener in the world

Definition at line 67 of file Listener.cpp.

void sf::Listener::SetPosition | ( | float | X,
 |  | float | Y,
 |  | float | Z |
 | ) |  |  | [static]

Change the position of the listener (take 3 values).

The default position is (0, 0, 0)

Parameters:
X,Y,Z : Position of the listener in the world

Definition at line 58 of file Listener.cpp.

void sf::Listener::SetTarget ( const Vector3f & Target ) [static]

Change the orientation of the listener (the point he must look at) (take a 3D vector).

Change the orientation of the listener (the point he must look at) (take a 3D vector).

The default target is (0, 0, -1)

Parameters:
Target : Position of the point the listener must look at

Definition at line 100 of file Listener.cpp.

void sf::Listener::SetTarget | ( | float | X,
 |  | float | Y,
 |  | float | Z |
 | ) |  |  | [static]

Change the orientation of the listener (the point he must look at) (take 3 values).

Change the orientation of the listener (the point he must look at) (take 3 values).

The default target is (0, 0, -1)

Parameters:
X,Y,Z : Position of the point the listener must look at

Definition at line 89 of file Listener.cpp.

The documentation for this class was generated from the following files:
  • Listener.hpp
  • Listener.cpp


sf::Listener Member List

This is the complete list of members for sf::Listener, including all inherited members.

GetGlobalVolume() | sf::Listener | [static]
GetPosition() | sf::Listener | [static]
GetTarget() | sf::Listener | [static]
SetGlobalVolume(float Volume) | sf::Listener | [static]
SetPosition(float X, float Y, float Z) | sf::Listener | [static]
SetPosition(const Vector3f &Position) | sf::Listener | [static]
SetTarget(float X, float Y, float Z) | sf::Listener | [static]
SetTarget(const Vector3f &Target) | sf::Listener | [static]


sf::Lock

sf::Lock Class Reference

Lock is an exception-safe automatic wrapper for locking and unlocking mutexes. More...

#include <Lock.hpp>

Inheritance diagram for sf::Lock:

sf::NonCopyable

List of all members.

Public Member Functions

Lock (Mutex &Mutex)
Construct the lock with a target mutex (lock it).
~Lock ()
Destructor (unlocks the mutex).

Detailed Description

Lock is an exception-safe automatic wrapper for locking and unlocking mutexes.

Definition at line 42 of file Lock.hpp.

Constructor & Destructor Documentation

sf::Lock::Lock ( Mutex & Mutex )

Construct the lock with a target mutex (lock it).

Parameters:
Mutex : Mutex to lock

Definition at line 37 of file Lock.cpp.

sf::Lock::~Lock ( )

Destructor (unlocks the mutex).

Definition at line 47 of file Lock.cpp.

The documentation for this class was generated from the following files:
  • Lock.hpp
  • Lock.cpp


sf::Lock Member List

This is the complete list of members for sf::Lock, including all inherited members.

Lock(Mutex &Mutex) | sf::Lock |
NonCopyable() | sf::NonCopyable | [inline, private]
~Lock() | sf::Lock |


sf::Matrix3

sf::Matrix3 Class Reference

Utility class to manipulate 3x3 matrices representing 2D transformations. More...

#include <Matrix3.hpp>

List of all members.

Public Member Functions

Matrix3 ()
Default constructor (builds an identity matrix).
Matrix3 (float a00, float a01, float a02, float a10, float a11, float a12, float a20, float a21, float a22)
Construct a matrix from its 9 elements.
void | SetFromTransformations (const Vector2f &Center, const Vector2f &Translation, float Rotation, const Vector2f &Scale)
Build a matrix from a set of transformations.
Vector2f | Transform (const Vector2f &Point) const
Transform a point by the matrix.
Matrix3 | GetInverse () const
Return the inverse of the matrix.
const float * | Get4x4Elements () const
Return the elements of the matrix as a 4x4, in an array of 16 floats.
float | operator() (unsigned int Row, unsigned int Col) const
Operator () overloads to access the matrix elements.
float & | operator() (unsigned int Row, unsigned int Col)
Matrix3 | operator* (const Matrix3 &Mat) const
Operator * overload to multiply two matrices.
Matrix3 & | operator*= (const Matrix3 &Mat)
Operator *= overload to multiply-assign two matrices.

Static Public Attributes

static const Matrix3 | Identity
Identity matrix.

Detailed Description

Utility class to manipulate 3x3 matrices representing 2D transformations.

Definition at line 42 of file Matrix3.hpp.

Constructor & Destructor Documentation

sf::Matrix3::Matrix3 ( )

Default constructor (builds an identity matrix).

sf::Matrix3::Matrix3 | ( | float | a00,
 |  | float | a01,
 |  | float | a02,
 |  | float | a10,
 |  | float | a11,
 |  | float | a12,
 |  | float | a20,
 |  | float | a21,
 |  | float | a22
 | ) |  |

Construct a matrix from its 9 elements.

Member Function Documentation

const float* sf::Matrix3::Get4x4Elements ( ) const

Return the elements of the matrix as a 4x4, in an array of 16 floats.

Returns:
Pointer to the 4x4 matrix elements

Matrix3 sf::Matrix3::GetInverse ( ) const

Return the inverse of the matrix.

Returns:
A new matrix which is the inverse of this

float sf::Matrix3::operator() | ( | unsigned int | Row,
 |  | unsigned int | Col |
 | ) |  |  | const

Operator () overloads to access the matrix elements.

Parameters:
Row | : Element row (0 based)
Col | : Element column (0 based)
Returns:
Matrix element (Row, Col)

Matrix3 sf::Matrix3::operator* ( const Matrix3 & Mat ) const

Operator * overload to multiply two matrices.

Parameters:
Mat : Matrix to multiply
Returns:
this * Mat

Matrix3& sf::Matrix3::operator*= ( const Matrix3 & Mat )

Operator *= overload to multiply-assign two matrices.

Parameters:
Mat : Matrix to multiply
Returns:
this * Mat

void sf::Matrix3::SetFromTransformations | ( | const Vector2f & | Center,
 |  | const Vector2f & | Translation,
 |  | float | Rotation,
 |  | const Vector2f & | Scale
 | ) |  |

Build a matrix from a set of transformations.

Parameters:
Center | : Origin for the transformations
Translation | : Translation offset
Rotation | : Rotation angle in degrees
Scale | : Scaling factors

Vector2f sf::Matrix3::Transform ( const Vector2f & Point ) const

Transform a point by the matrix.

Parameters:
Point : Point to transform
Returns:
Transformed point

Member Data Documentation

const Matrix3 sf::Matrix3::Identity [static]

Identity matrix.

Definition at line 133 of file Matrix3.hpp.

The documentation for this class was generated from the following files:
  • Matrix3.hpp
  • Matrix3.cpp


sf::Matrix3 Member List

This is the complete list of members for sf::Matrix3, including all inherited members.

Get4x4Elements() const | sf::Matrix3 |
GetInverse() const | sf::Matrix3 |
Identity | sf::Matrix3 | [static]
Matrix3() | sf::Matrix3 |
Matrix3(float a00, float a01, float a02, float a10, float a11, float a12, float a20, float a21, float a22) | sf::Matrix3 |
operator()(unsigned int Row, unsigned int Col) const | sf::Matrix3 |
operator()(unsigned int Row, unsigned int Col) (defined in sf::Matrix3) | sf::Matrix3 |
operator*(const Matrix3 &Mat) const | sf::Matrix3 |
operator*=(const Matrix3 &Mat) | sf::Matrix3 |
SetFromTransformations(const Vector2f &Center, const Vector2f &Translation, float Rotation, const Vector2f &Scale) | sf::Matrix3 |
Transform(const Vector2f &Point) const | sf::Matrix3 |


sf::Music

sf::Music Class Reference

Music defines a big sound played using streaming, so usually what we call a music :). More...

#include <Music.hpp>

Inheritance diagram for sf::Music:

sf::SoundStream sf::Thread sf::Sound

List of all members.

Public Types

enum | Status
Enumeration of the sound states. More...

Public Member Functions

Music (std::size_t BufferSize=44100)
Construct the music with a buffer size.
~Music ()
Destructor.
bool | OpenFromFile (const std::string &Filename)
Open a music file (doesn't play it -- call Play() for that).
bool | OpenFromMemory (const char *Data, std::size_t SizeInBytes)
Open a music file from memory (doesn't play it -- call Play() for that).
float | GetDuration () const
Get the music duration.
void | Play ()
Start playing the audio stream.
void | Stop ()
Stop playing the audio stream.
unsigned int | GetChannelsCount () const
Return the number of channels (1 = mono, 2 = stereo).
unsigned int | GetSampleRate () const
Get the stream sample rate.
Status | GetStatus () const
Get the status of the stream (stopped, paused, playing).
float | GetPlayingOffset () const
Get the current playing position of the stream.
void | SetLoop (bool Loop)
Set the stream loop state.
bool | GetLoop () const
Tell whether or not the stream is looping.

Protected Member Functions

void | Initialize (unsigned int ChannelsCount, unsigned int SampleRate)
Set the audio stream parameters, you must call it before Play().

Detailed Description

Music defines a big sound played using streaming, so usually what we call a music :).

Definition at line 47 of file Music.hpp.

Member Enumeration Documentation

enum sf::Sound::Status [inherited]

Enumeration of the sound states.

Definition at line 52 of file Sound.hpp.

Constructor & Destructor Documentation

sf::Music::Music ( std::size_t BufferSize = 44100 ) [explicit]

Construct the music with a buffer size.

Parameters:
BufferSize : Size of the internal buffer, expressed in number of samples (ie. size taken by the music in memory) (44100 by default)

Definition at line 40 of file Music.cpp.

sf::Music::~Music ( )

Destructor.

Definition at line 52 of file Music.cpp.

Member Function Documentation

unsigned int sf::SoundStream::GetChannelsCount ( ) const [inherited]

Return the number of channels (1 = mono, 2 = stereo).

Return the number of channels (1 = mono, 2 = stereo, .

Returns:
Number of channels
..)

Definition at line 126 of file SoundStream.cpp.

float sf::Music::GetDuration ( ) const

Get the music duration.

Get the sound duration.

Returns:
Music duration, in seconds

Definition at line 148 of file Music.cpp.

bool sf::SoundStream::GetLoop ( ) const [inherited]

Tell whether or not the stream is looping.

Tell whether or not the music is looping.

Returns:
True if the music is looping, false otherwise

Reimplemented from sf::Sound.

Definition at line 180 of file SoundStream.cpp.

float sf::SoundStream::GetPlayingOffset ( ) const [inherited]

Get the current playing position of the stream.

Returns:
Current playing position, expressed in seconds

Current playing position, expressed in seconds

Reimplemented from sf::Sound.

Definition at line 162 of file SoundStream.cpp.

unsigned int sf::SoundStream::GetSampleRate ( ) const [inherited]

Get the stream sample rate.

Get the sound frequency (sample rate).

Returns:
Stream frequency (number of samples per second)

Definition at line 135 of file SoundStream.cpp.

Sound::Status sf::SoundStream::GetStatus ( ) const [inherited]

Get the status of the stream (stopped, paused, playing).

Get the status of the sound (stopped, paused, playing).

Returns:
Current status of the sound

Reimplemented from sf::Sound.

Definition at line 144 of file SoundStream.cpp.

void sf::SoundStream::Initialize | ( | unsigned int | ChannelsCount,
 |  | unsigned int | SampleRate |
 | ) |  |  | [protected, inherited]

Set the audio stream parameters, you must call it before Play().

Parameters:
ChannelsCount | : Number of channels
SampleRate | : Sample rate

Definition at line 64 of file SoundStream.cpp.

bool sf::Music::OpenFromFile ( const std::string & Filename )

Open a music file (doesn't play it -- call Play() for that).

Parameters:
Filename : Path of the music file to open
Returns:
True if loading has been successful

Definition at line 64 of file Music.cpp.

bool sf::Music::OpenFromMemory | ( | const char * | Data,
 |  | std::size_t | SizeInBytes
 | ) |  |

Open a music file from memory (doesn't play it -- call Play() for that).

Parameters:
Data | : Pointer to the file data in memory
SizeInBytes | : Size of the data to load, in bytes
Returns:
True if loading has been successful

Definition at line 91 of file Music.cpp.

void sf::SoundStream::Play ( ) [inherited]

Start playing the audio stream.

Reimplemented from sf::Sound.

Definition at line 85 of file SoundStream.cpp.

void sf::SoundStream::SetLoop ( bool Loop ) [inherited]

Set the stream loop state.

Set the music loop state.

This parameter is disabled by default

Parameters:
Loop : True to play in loop, false to play once

Reimplemented from sf::Sound.

Definition at line 171 of file SoundStream.cpp.

void sf::SoundStream::Stop ( ) [inherited]

Stop playing the audio stream.

Reimplemented from sf::Sound.

Definition at line 115 of file SoundStream.cpp.

The documentation for this class was generated from the following files:
  • Music.hpp
  • Music.cpp


sf::Music Member List

This is the complete list of members for sf::Music, including all inherited members.

GetChannelsCount() const | sf::SoundStream |
GetDuration() const | sf::Music |
GetLoop() const | sf::SoundStream |
GetPlayingOffset() const | sf::SoundStream |
GetSampleRate() const | sf::SoundStream |
GetStatus() const | sf::SoundStream |
Initialize(unsigned int ChannelsCount, unsigned int SampleRate) | sf::SoundStream | [protected]
Music(std::size_t BufferSize=44100) | sf::Music | [explicit]
OpenFromFile(const std::string &Filename) | sf::Music |
OpenFromMemory(const char *Data, std::size_t SizeInBytes) | sf::Music |
Play() | sf::SoundStream |
SetLoop(bool Loop) | sf::SoundStream |
SoundStream() | sf::SoundStream | [protected]
Status enum name | sf::SoundStream |
Stop() | sf::SoundStream |
~Music() | sf::Music |
~SoundStream() | sf::SoundStream | [virtual]


sf::Mutex

sf::Mutex Class Reference

Mutex defines a mutex (MUTual EXclusion) object, that allows a thread to lock critical instructions to avoid simultaneous access with other threads. More...

#include <Mutex.hpp>

Inheritance diagram for sf::Mutex:

sf::NonCopyable

List of all members.

Public Member Functions

Mutex ()
Default constructor.
~Mutex ()
Destructor.
void | Lock ()
Lock the mutex.
void | Unlock ()
Unlock the mutex.

Detailed Description

Mutex defines a mutex (MUTual EXclusion) object, that allows a thread to lock critical instructions to avoid simultaneous access with other threads.

The Win32 version uses critical sections, as it is faster than mutexes.
See Lock for an efficient way of using it.

Definition at line 45 of file Win32/Mutex.hpp.

Constructor & Destructor Documentation

sf::Mutex::Mutex ( )

Default constructor.

Definition at line 36 of file Mutex.cpp.

sf::Mutex::~Mutex ( )

Destructor.

Definition at line 45 of file Mutex.cpp.

Member Function Documentation

void sf::Mutex::Lock ( )

Lock the mutex.

Definition at line 54 of file Mutex.cpp.

void sf::Mutex::Unlock ( )

Unlock the mutex.

Definition at line 63 of file Mutex.cpp.

The documentation for this class was generated from the following files:
  • Win32/Mutex.hpp
  • Mutex.cpp


sf::Mutex Member List

This is the complete list of members for sf::Mutex, including all inherited members.

Lock() | sf::Mutex |
Mutex() | sf::Mutex |
NonCopyable() | sf::NonCopyable | [inline, private]
Unlock() | sf::Mutex |
~Mutex() | sf::Mutex |


sf::NonCopyable

sf::NonCopyable Struct Reference

Utility base class to easily declare non-copyable classes. More...

#include <NonCopyable.hpp>

Inheritance diagram for sf::NonCopyable:

sf::Context sf::Ftp sf::Http sf::Input sf::Lock sf::Mutex sf::Thread sf::Window

List of all members.

Protected Member Functions

NonCopyable ()
The default constructor won't be generated, so provide it.

Detailed Description

Utility base class to easily declare non-copyable classes.

Just inherit from NonCopyable to get a non-copyable class

Definition at line 40 of file NonCopyable.hpp.

Constructor & Destructor Documentation

sf::NonCopyable::NonCopyable ( ) [inline, protected]

The default constructor won't be generated, so provide it.

Definition at line 48 of file NonCopyable.hpp.

The documentation for this struct was generated from the following file:
  • NonCopyable.hpp


sf::NonCopyable Member List

This is the complete list of members for sf::NonCopyable, including all inherited members.

NonCopyable() sf::NonCopyable [inline, protected]


sf::Packet

sf::Packet Class Reference

Packet wraps data to send / to receive through the network. More...

#include <Packet.hpp>

List of all members.

Public Member Functions

Packet ()
Default constructor.
virtual | ~Packet ()
Virtual destructor.
void | Append (const void *Data, std::size_t SizeInBytes)
Append data to the end of the packet.
void | Clear ()
Clear the packet data.
const char * | GetData () const
Get a pointer to the data contained in the packet Warning : the returned pointer may be invalid after you append data to the packet.
std::size_t | GetDataSize () const
Get the size of the data contained in the packet.
bool | EndOfPacket () const
Tell if the reading position has reached the end of the packet.
operator bool () const
Return the validity of packet.
Packet & | operator>> (bool &Data)
Operator >> overloads to extract data from the packet.
Packet & | operator>> (Int8 &Data)
Packet & | operator>> (Uint8 &Data)
Packet & | operator>> (Int16 &Data)
Packet & | operator>> (Uint16 &Data)
Packet & | operator>> (Int32 &Data)
Packet & | operator>> (Uint32 &Data)
Packet & | operator>> (float &Data)
Packet & | operator>> (double &Data)
Packet & | operator>> (char *Data)
Packet & | operator>> (std::string &Data)
Packet & | operator>> (wchar_t *Data)
Packet & | operator>> (std::wstring &Data)
Packet & | operator<< (bool Data)
Operator << overloads to put data into the packet.
Packet & | operator<< (Int8 Data)
Packet & | operator<< (Uint8 Data)
Packet & | operator<< (Int16 Data)
Packet & | operator<< (Uint16 Data)
Packet & | operator<< (Int32 Data)
Packet & | operator<< (Uint32 Data)
Packet & | operator<< (float Data)
Packet & | operator<< (double Data)
Packet & | operator<< (const char *Data)
Packet & | operator<< (const std::string &Data)
Packet & | operator<< (const wchar_t *Data)
Packet & | operator<< (const std::wstring &Data)

Friends

class | SocketTCP
class | SocketUDP

Detailed Description

Packet wraps data to send / to receive through the network.

Definition at line 41 of file Packet.hpp.

Constructor & Destructor Documentation

sf::Packet::Packet ( )

Default constructor.

Definition at line 38 of file Packet.cpp.

sf::Packet::~Packet ( ) [virtual]

Virtual destructor.

Definition at line 49 of file Packet.cpp.

Member Function Documentation

void sf::Packet::Append | ( | const void * | Data,
 |  | std::size_t | SizeInBytes
 | ) |  |

Append data to the end of the packet.

Parameters:
Data | : Pointer to the bytes to append
SizeInBytes | : Number of bytes to append

Definition at line 58 of file Packet.cpp.

void sf::Packet::Clear ( )

Clear the packet data.

Definition at line 72 of file Packet.cpp.

bool sf::Packet::EndOfPacket ( ) const

Tell if the reading position has reached the end of the packet.

Returns:
True if all data have been read into the packet

Definition at line 103 of file Packet.cpp.

const char * sf::Packet::GetData ( ) const

Get a pointer to the data contained in the packet Warning : the returned pointer may be invalid after you append data to the packet.

Get a pointer to the data contained in the packet Warning : the returned pointer may be invalid after you append data to the packet.

Returns:
Pointer to the data

Definition at line 85 of file Packet.cpp.

std::size_t sf::Packet::GetDataSize ( ) const

Get the size of the data contained in the packet.

Returns:
Data size, in bytes

Definition at line 94 of file Packet.cpp.

sf::Packet::operator bool ( ) const

Return the validity of packet.

Tell if the packet is valid for reading.

Returns:
True if last data extraction from packet was successful

Definition at line 112 of file Packet.cpp.

Packet & sf::Packet::operator<< ( bool Data )

Operator << overloads to put data into the packet.

Definition at line 290 of file Packet.cpp.

Packet & sf::Packet::operator>> ( bool & Data )

Operator >> overloads to extract data from the packet.

Definition at line 121 of file Packet.cpp.

The documentation for this class was generated from the following files:
  • Packet.hpp
  • Packet.cpp


sf::Packet Member List

This is the complete list of members for sf::Packet, including all inherited members.

Append(const void *Data, std::size_t SizeInBytes) | sf::Packet |
Clear() | sf::Packet |
EndOfPacket() const | sf::Packet |
GetData() const | sf::Packet |
GetDataSize() const | sf::Packet |
operator bool() const | sf::Packet |
operator<<(bool Data) | sf::Packet |
operator<<(Int8 Data) (defined in sf::Packet) | sf::Packet |
operator<<(Uint8 Data) (defined in sf::Packet) | sf::Packet |
operator<<(Int16 Data) (defined in sf::Packet) | sf::Packet |
operator<<(Uint16 Data) (defined in sf::Packet) | sf::Packet |
operator<<(Int32 Data) (defined in sf::Packet) | sf::Packet |
operator<<(Uint32 Data) (defined in sf::Packet) | sf::Packet |
operator<<(float Data) (defined in sf::Packet) | sf::Packet |
operator<<(double Data) (defined in sf::Packet) | sf::Packet |
operator<<(const char *Data) (defined in sf::Packet) | sf::Packet |
operator<<(const std::string &Data) (defined in sf::Packet) | sf::Packet |
operator<<(const wchar_t *Data) (defined in sf::Packet) | sf::Packet |
operator<<(const std::wstring &Data) (defined in sf::Packet) | sf::Packet |
operator>>(bool &Data) | sf::Packet |
operator>>(Int8 &Data) (defined in sf::Packet) | sf::Packet |
operator>>(Uint8 &Data) (defined in sf::Packet) | sf::Packet |
operator>>(Int16 &Data) (defined in sf::Packet) | sf::Packet |
operator>>(Uint16 &Data) (defined in sf::Packet) | sf::Packet |
operator>>(Int32 &Data) (defined in sf::Packet) | sf::Packet |
operator>>(Uint32 &Data) (defined in sf::Packet) | sf::Packet |
operator>>(float &Data) (defined in sf::Packet) | sf::Packet |
operator>>(double &Data) (defined in sf::Packet) | sf::Packet |
operator>>(char *Data) (defined in sf::Packet) | sf::Packet |
operator>>(std::string &Data) (defined in sf::Packet) | sf::Packet |
operator>>(wchar_t *Data) (defined in sf::Packet) | sf::Packet |
operator>>(std::wstring &Data) (defined in sf::Packet) | sf::Packet |
Packet() | sf::Packet |
SocketTCP (defined in sf::Packet) | sf::Packet | [friend]
SocketUDP (defined in sf::Packet) | sf::Packet | [friend]
~Packet() | sf::Packet | [virtual]


sf::PostFX

sf::PostFX Class Reference

PostFX is used to apply a post effect to a window. More...

#include <PostFX.hpp>

Inheritance diagram for sf::PostFX:

sf::Drawable

List of all members.

Public Member Functions

PostFX ()
Default constructor.
PostFX (const PostFX &Copy)
Copy constructor.
~PostFX ()
Destructor.
bool | LoadFromFile (const std::string &Filename)
Load the effect from a file.
bool | LoadFromMemory (const std::string &Effect)
Load the effect from a text in memory.
void | SetParameter (const std::string &Name, float X)
Change a parameter of the effect (1 float).
void | SetParameter (const std::string &Name, float X, float Y)
Change a parameter of the effect (2 floats).
void | SetParameter (const std::string &Name, float X, float Y, float Z)
Change a parameter of the effect (3 floats).
void | SetParameter (const std::string &Name, float X, float Y, float Z, float W)
Change a parameter of the effect (4 floats).
void | SetTexture (const std::string &Name, Image *Texture)
Set a texture parameter.
PostFX & | operator= (const PostFX &Other)
Assignment operator.
void | SetPosition (float X, float Y)
Set the position of the object (take 2 values).
void | SetPosition (const Vector2f &Position)
Set the position of the object (take a 2D vector).
void | SetX (float X)
Set the X position of the object.
void | SetY (float Y)
Set the Y position of the object.
void | SetScale (float ScaleX, float ScaleY)
Set the scale of the object (take 2 values).
void | SetScale (const Vector2f &Scale)
Set the scale of the object (take a 2D vector).
void | SetScaleX (float FactorX)
Set the X scale factor of the object.
void | SetScaleY (float FactorY)
Set the Y scale factor of the object.
void | SetCenter (float CenterX, float CenterY)
Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).
void | SetCenter (const Vector2f &Center)
Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).
void | SetRotation (float Rotation)
Set the orientation of the object.
void | SetColor (const Color &Col)
Set the color of the object.
void | SetBlendMode (Blend::Mode Mode)
Set the blending mode for the object.
const Vector2f & | GetPosition () const
Get the position of the object.
const Vector2f & | GetScale () const
Get the current scale of the object.
const Vector2f & | GetCenter () const
Get the center of the object.
float | GetRotation () const
Get the orientation of the object.
const Color & | GetColor () const
Get the color of the object.
Blend::Mode | GetBlendMode () const
Get the current blending mode.
void | Move (float OffsetX, float OffsetY)
Move the object of a given offset (take 2 values).
void | Move (const Vector2f &Offset)
Move the object of a given offset (take a 2D vector).
void | Scale (float FactorX, float FactorY)
Scale the object (take 2 values).
void | Scale (const Vector2f &Factor)
Scale the object (take a 2D vector).
void | Rotate (float Angle)
Rotate the object.
sf::Vector2f | TransformToLocal (const sf::Vector2f &Point) const
Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).
sf::Vector2f | TransformToGlobal (const sf::Vector2f &Point) const
Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Static Public Member Functions

static bool | CanUsePostFX ()
Tell whether or not the system supports post-effects.

Protected Member Functions

virtual void | Render (RenderTarget &Target) const
/see Drawable::Render
const Matrix3 & | GetMatrix () const
Get the transform matrix of the drawable.
const Matrix3 & | GetInverseMatrix () const
Get the inverse transform matrix of the drawable.

Detailed Description

PostFX is used to apply a post effect to a window.

Definition at line 43 of file PostFX.hpp.

Constructor & Destructor Documentation

sf::PostFX::PostFX ( )

Default constructor.

Definition at line 43 of file PostFX.cpp.

sf::PostFX::PostFX ( const PostFX & Copy )

Copy constructor.

Parameters:
Copy : Instance to copy

Definition at line 54 of file PostFX.cpp.

sf::PostFX::~PostFX ( )

Destructor.

Definition at line 73 of file PostFX.cpp.

Member Function Documentation

bool sf::PostFX::CanUsePostFX ( ) [static]

Tell whether or not the system supports post-effects.

Returns:
True if the system can use post-effects

Definition at line 265 of file PostFX.cpp.

Blend::Mode sf::Drawable::GetBlendMode ( ) const [inherited]

Get the current blending mode.

Returns:
Current blending mode

Definition at line 258 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetCenter ( ) const [inherited]

Get the center of the object.

Returns:
Current position of the center

Definition at line 231 of file Drawable.cpp.

const Color & sf::Drawable::GetColor ( ) const [inherited]

Get the color of the object.

Returns:
Current color

Definition at line 249 of file Drawable.cpp.

const Matrix3 & sf::Drawable::GetInverseMatrix ( ) const [protected, inherited]

Get the inverse transform matrix of the drawable.

Returns:
Inverse transform matrix

Definition at line 350 of file Drawable.cpp.

const Matrix3 & sf::Drawable::GetMatrix ( ) const [protected, inherited]

Get the transform matrix of the drawable.

Returns:
Transform matrix

Definition at line 334 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetPosition ( ) const [inherited]

Get the position of the object.

Returns:
Current position

Definition at line 213 of file Drawable.cpp.

float sf::Drawable::GetRotation ( ) const [inherited]

Get the orientation of the object.

Rotation is always in the range [0, 360]

Returns:
Current rotation, in degrees

Definition at line 240 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetScale ( ) const [inherited]

Get the current scale of the object.

Returns:
Current scale factor (always positive)

Definition at line 222 of file Drawable.cpp.

bool sf::PostFX::LoadFromFile ( const std::string & Filename )

Load the effect from a file.

Parameters:
Filename : Path of the effect file to load
Returns:
True on success

Definition at line 89 of file PostFX.cpp.

bool sf::PostFX::LoadFromMemory ( const std::string & Effect )

Load the effect from a text in memory.

Parameters:
Effect : String containing the effect code
Returns:
True on success

Definition at line 112 of file PostFX.cpp.

void sf::Drawable::Move ( const Vector2f & Offset ) [inherited]

Move the object of a given offset (take a 2D vector).

Parameters:
Offset : Amount of units to move the object of

Definition at line 278 of file Drawable.cpp.

void sf::Drawable::Move | ( | float | OffsetX,
 |  | float | OffsetY |
 | ) |  |  | [inherited]

Move the object of a given offset (take 2 values).

Parameters:
OffsetX | : X offset
OffsetY | : Y offset

Definition at line 268 of file Drawable.cpp.

PostFX & sf::PostFX::operator= ( const PostFX & Other )

Assignment operator.

Parameters:
Other : Instance to assign
Returns:
Reference to the post-effect

Definition at line 249 of file PostFX.cpp.

void sf::PostFX::Render ( RenderTarget & Target ) const [protected, virtual]

/see Drawable::Render

Implements sf::Drawable.

Definition at line 280 of file PostFX.cpp.

void sf::Drawable::Rotate ( float Angle ) [inherited]

Rotate the object.

Parameters:
Angle : Angle of rotation, in degrees

Definition at line 306 of file Drawable.cpp.

void sf::Drawable::Scale ( const Vector2f & Factor ) [inherited]

Scale the object (take a 2D vector).

Parameters:
Factor : Scaling factors (both values must be strictly positive)

Definition at line 297 of file Drawable.cpp.

void sf::Drawable::Scale | ( | float | FactorX,
 |  | float | FactorY |
 | ) |  |  | [inherited]

Scale the object (take 2 values).

Parameters:
FactorX | : Scaling factor on X (must be strictly positive)
FactorY | : Scaling factor on Y (must be strictly positive)

Definition at line 287 of file Drawable.cpp.

void sf::Drawable::SetBlendMode ( Blend::Mode Mode ) [inherited]

Set the blending mode for the object.

The default blend mode is Blend::Alpha

Parameters:
Mode : New blending mode
The default blend mode is Blend::Alpha

Definition at line 204 of file Drawable.cpp.

void sf::Drawable::SetCenter ( const Vector2f & Center ) [inherited]

Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).

Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).

The default center is (0, 0)

Parameters:
Center : New center
The default center is (0, 0)

Definition at line 171 of file Drawable.cpp.

void sf::Drawable::SetCenter | ( | float | CenterX,
 |  | float | CenterY |
 | ) |  |  | [inherited]

Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).

Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).

The default center is (0, 0)

Parameters:
CenterX | : X coordinate of the center
CenterY | : Y coordinate of the center
The default center is (0, 0)

Definition at line 157 of file Drawable.cpp.

void sf::Drawable::SetColor ( const Color & Col ) [inherited]

Set the color of the object.

The default color is white

Parameters:
Col : New color
The default color is white

Definition at line 194 of file Drawable.cpp.

void sf::PostFX::SetParameter | ( | const std::string & | Name,
 |  | float | X,
 |  | float | Y,
 |  | float | Z,
 |  | float | W
 | ) |  |

Change a parameter of the effect (4 floats).

Parameters:
Name | : Parameter name in the effect
X,Y,Z,W | : Values to assign

Definition at line 199 of file PostFX.cpp.

void sf::PostFX::SetParameter | ( | const std::string & | Name,
 |  | float | X,
 |  | float | Y,
 |  | float | Z
 | ) |  |

Change a parameter of the effect (3 floats).

Parameters:
Name | : Parameter name in the effect
X,Y,Z | : Values to assign

Definition at line 176 of file PostFX.cpp.

void sf::PostFX::SetParameter | ( | const std::string & | Name,
 |  | float | X,
 |  | float | Y
 | ) |  |

Change a parameter of the effect (2 floats).

Parameters:
Name | : Parameter name in the effect
X,Y | : Values to assign

Definition at line 153 of file PostFX.cpp.

void sf::PostFX::SetParameter | ( | const std::string & | Name,
 |  | float | X
 | ) |  |

Change a parameter of the effect (1 float).

Parameters:
Name | : Parameter name in the effect
X | : Value to assign

Definition at line 130 of file PostFX.cpp.

void sf::Drawable::SetPosition ( const Vector2f & Position ) [inherited]

Set the position of the object (take a 2D vector).

Parameters:
Position : New position

Definition at line 75 of file Drawable.cpp.

void sf::Drawable::SetPosition | ( | float | X,
 |  | float | Y |
 | ) |  |  | [inherited]

Set the position of the object (take 2 values).

Parameters:
X | : New X coordinate
Y | : New Y coordinate

Definition at line 65 of file Drawable.cpp.

void sf::Drawable::SetRotation ( float Rotation ) [inherited]

Set the orientation of the object.

Parameters:
Rotation : Angle of rotation, in degrees

Definition at line 180 of file Drawable.cpp.

void sf::Drawable::SetScale ( const Vector2f & Scale ) [inherited]

Set the scale of the object (take a 2D vector).

Parameters:
Scale : New scale (both values must be strictly positive)

Definition at line 117 of file Drawable.cpp.

void sf::Drawable::SetScale | ( | float | ScaleX,
 |  | float | ScaleY |
 | ) |  |  | [inherited]

Set the scale of the object (take 2 values).

Parameters:
ScaleX | : New horizontal scale (must be strictly positive)
ScaleY | : New vertical scale (must be strictly positive)

Definition at line 107 of file Drawable.cpp.

void sf::Drawable::SetScaleX ( float FactorX ) [inherited]

Set the X scale factor of the object.

Parameters:
X : New X scale factor

Definition at line 127 of file Drawable.cpp.

void sf::Drawable::SetScaleY ( float FactorY ) [inherited]

Set the Y scale factor of the object.

Parameters:
Y : New Y scale factor

Definition at line 141 of file Drawable.cpp.

void sf::PostFX::SetTexture | ( | const std::string & | Name,
 |  | Image * | Texture
 | ) |  |

Set a texture parameter.

Parameters:
Name | : Texture name in the effect
Texture | : Image to set (pass NULL to use content of current framebuffer)

Definition at line 222 of file PostFX.cpp.

void sf::Drawable::SetX ( float X ) [inherited]

Set the X position of the object.

Parameters:
X : New X coordinate

Definition at line 85 of file Drawable.cpp.

void sf::Drawable::SetY ( float Y ) [inherited]

Set the Y position of the object.

Parameters:
Y : New Y coordinate

Definition at line 96 of file Drawable.cpp.

sf::Vector2f sf::Drawable::TransformToGlobal ( const sf::Vector2f & Point ) const [inherited]

Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Parameters:
Point : Point to transform
Returns:
Transformed point

Definition at line 325 of file Drawable.cpp.

sf::Vector2f sf::Drawable::TransformToLocal ( const sf::Vector2f & Point ) const [inherited]

Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).

Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).

Parameters:
Point : Point to transform
Returns:
Transformed point

Definition at line 316 of file Drawable.cpp.

The documentation for this class was generated from the following files:
  • PostFX.hpp
  • PostFX.cpp


sf::PostFX Member List

This is the complete list of members for sf::PostFX, including all inherited members.

CanUsePostFX() | sf::PostFX | [static]
Drawable(const Vector2f &Position=Vector2f(0, 0), const Vector2f &Scale=Vector2f(1, 1), float Rotation=0.f, const Color &Col=Color(255, 255, 255, 255)) | sf::Drawable |
GetBlendMode() const | sf::Drawable |
GetCenter() const | sf::Drawable |
GetColor() const | sf::Drawable |
GetInverseMatrix() const | sf::Drawable | [protected]
GetMatrix() const | sf::Drawable | [protected]
GetPosition() const | sf::Drawable |
GetRotation() const | sf::Drawable |
GetScale() const | sf::Drawable |
LoadFromFile(const std::string &Filename) | sf::PostFX |
LoadFromMemory(const std::string &Effect) | sf::PostFX |
Move(float OffsetX, float OffsetY) | sf::Drawable |
Move(const Vector2f &Offset) | sf::Drawable |
operator=(const PostFX &Other) | sf::PostFX |
PostFX() | sf::PostFX |
PostFX(const PostFX &Copy) | sf::PostFX |
Render(RenderTarget &Target) const | sf::PostFX | [protected, virtual]
Rotate(float Angle) | sf::Drawable |
Scale(float FactorX, float FactorY) | sf::Drawable |
Scale(const Vector2f &Factor) | sf::Drawable |
SetBlendMode(Blend::Mode Mode) | sf::Drawable |
SetCenter(float CenterX, float CenterY) | sf::Drawable |
SetCenter(const Vector2f &Center) | sf::Drawable |
SetColor(const Color &Col) | sf::Drawable |
SetParameter(const std::string &Name, float X) | sf::PostFX |
SetParameter(const std::string &Name, float X, float Y) | sf::PostFX |
SetParameter(const std::string &Name, float X, float Y, float Z) | sf::PostFX |
SetParameter(const std::string &Name, float X, float Y, float Z, float W) | sf::PostFX |
SetPosition(float X, float Y) | sf::Drawable |
SetPosition(const Vector2f &Position) | sf::Drawable |
SetRotation(float Rotation) | sf::Drawable |
SetScale(float ScaleX, float ScaleY) | sf::Drawable |
SetScale(const Vector2f &Scale) | sf::Drawable |
SetScaleX(float FactorX) | sf::Drawable |
SetScaleY(float FactorY) | sf::Drawable |
SetTexture(const std::string &Name, Image *Texture) | sf::PostFX |
SetX(float X) | sf::Drawable |
SetY(float Y) | sf::Drawable |
TransformToGlobal(const sf::Vector2f &Point) const | sf::Drawable |
TransformToLocal(const sf::Vector2f &Point) const | sf::Drawable |
~Drawable() | sf::Drawable | [virtual]
~PostFX() | sf::PostFX |


sf::Randomizer

sf::Randomizer Class Reference

Randomizer is an utility class for generating pseudo-random numbers. More...

#include <Randomizer.hpp>

List of all members.

Static Public Member Functions

static void | SetSeed (unsigned int Seed)
Set the seed for the generator.
static unsigned int | GetSeed ()
Get the seed used to generate random numbers the generator.
static float | Random (float Begin, float End)
Get a random float number in a given range.
static int | Random (int Begin, int End)
Get a random integer number in a given range.

Detailed Description

Randomizer is an utility class for generating pseudo-random numbers.

Definition at line 40 of file Randomizer.hpp.

Member Function Documentation

unsigned int sf::Randomizer::GetSeed ( ) [static]

Get the seed used to generate random numbers the generator.

Returns:
Current seed

Definition at line 67 of file Randomizer.cpp.

int sf::Randomizer::Random | ( | int | Begin,
 |  | int | End |
 | ) |  |  | [static]

Get a random integer number in a given range.

Returns:
Start : Start of the range

End : End of the range

Random number in [Begin, End]

Definition at line 88 of file Randomizer.cpp.

float sf::Randomizer::Random | ( | float | Begin,
 |  | float | End |
 | ) |  |  | [static]

Get a random float number in a given range.

Returns:
Start : Start of the range

End : End of the range

Random number in [Begin, End]

Definition at line 76 of file Randomizer.cpp.

void sf::Randomizer::SetSeed ( unsigned int Seed ) [static]

Set the seed for the generator.

Using a known seed allows you to reproduce the same sequence of random number

Parameters:
Seed : Number to use as the seed
Using a known seed allows you to reproduce the same sequence of random number

Definition at line 57 of file Randomizer.cpp.

The documentation for this class was generated from the following files:
  • Randomizer.hpp
  • Randomizer.cpp


sf::Randomizer Member List

This is the complete list of members for sf::Randomizer, including all inherited members.

GetSeed() | sf::Randomizer | [static]
Random(float Begin, float End) | sf::Randomizer | [static]
Random(int Begin, int End) | sf::Randomizer | [static]
SetSeed(unsigned int Seed) | sf::Randomizer | [static]


sf::Rect

sf::Rect< T > Class Template Reference

Rect is an utility class for manipulating rectangles. More...

#include <Rect.hpp>

List of all members.

Public Member Functions

Rect ()
Default constructor.
Rect (T LeftCoord, T TopCoord, T RightCoord, T BottomCoord)
Construct the rectangle from its coordinates.
T | GetWidth () const
Get the width of the rectangle.
T | GetHeight () const
Get the height of the rectangle.
void | Offset (T OffsetX, T OffsetY)
Move the whole rectangle by the given offset.
bool | Contains (T X, T Y) const
Check if a point is inside the rectangle's area.
bool | Intersects (const Rect< T > &Rectangle, Rect< T > *OverlappingRect=NULL) const
Check intersection between two rectangles.

Public Attributes

T | Left
Left coordinate of the rectangle.
T | Top
Top coordinate of the rectangle.
T | Right
Right coordinate of the rectangle.
T | Bottom
Bottom coordinate of the rectangle.

Detailed Description

template<typename T>
class sf::Rect< T >

Rect is an utility class for manipulating rectangles.

Template parameter defines the type of coordinates (integer, float, ...)

Definition at line 41 of file Rect.hpp.

Constructor & Destructor Documentation

template<typename T>
sf::Rect< T >::Rect ( )

Default constructor.

template<typename T>
sf::Rect< T >::Rect | ( | T | LeftCoord,
 |  | T | TopCoord,
 |  | T | RightCoord,
 |  | T | BottomCoord
 | ) |  |

Construct the rectangle from its coordinates.

Parameters:
LeftCoord | : Left coordinate of the rectangle
TopCoord | : Top coordinate of the rectangle
RightCoord | : Right coordinate of the rectangle
BottomCoord | : Bottom coordinate of the rectangle

Member Function Documentation

template<typename T>
bool sf::Rect< T >::Contains | ( | T | X,
 |  | T | Y |
 | ) |  |  | const

Check if a point is inside the rectangle's area.

Parameters:
X | : X coordinate of the point to test
Y | : Y coordinate of the point to test
Returns:
True if the point is inside

template<typename T>
T sf::Rect< T >::GetHeight ( ) const

Get the height of the rectangle.

Returns:
Height of rectangle

template<typename T>
T sf::Rect< T >::GetWidth ( ) const

Get the width of the rectangle.

Returns:
Width of rectangle

template<typename T>
bool sf::Rect< T >::Intersects | ( | const Rect< T > & | Rectangle,
 |  | Rect< T > * | OverlappingRect = NULL |
 | ) |  |  | const

Check intersection between two rectangles.

Parameters:
Rectangle | : Rectangle to test
OverlappingRect | : Rectangle to be filled with overlapping rect (NULL by default)
Returns:
True if rectangles overlap

template<typename T>
void sf::Rect< T >::Offset | ( | T | OffsetX,
 |  | T | OffsetY
 | ) |  |

Move the whole rectangle by the given offset.

Parameters:
OffsetX | : Horizontal offset
OffsetY | : Vertical offset

Member Data Documentation

template<typename T>
T sf::Rect< T >::Bottom

Bottom coordinate of the rectangle.

Definition at line 115 of file Rect.hpp.

template<typename T>
T sf::Rect< T >::Left

Left coordinate of the rectangle.

Definition at line 112 of file Rect.hpp.

template<typename T>
T sf::Rect< T >::Right

Right coordinate of the rectangle.

Definition at line 114 of file Rect.hpp.

template<typename T>
T sf::Rect< T >::Top

Top coordinate of the rectangle.

Definition at line 113 of file Rect.hpp.

The documentation for this class was generated from the following file:
  • Rect.hpp


sf::Rect< T > Member List

This is the complete list of members for sf::Rect< T >, including all inherited members.

Bottom | sf::Rect< T >
Contains(T X, T Y) const | sf::Rect< T >
GetHeight() const | sf::Rect< T >
GetWidth() const | sf::Rect< T >
Intersects(const Rect< T > &Rectangle, Rect< T > *OverlappingRect=NULL) const | sf::Rect< T >
Left | sf::Rect< T >
Offset(T OffsetX, T OffsetY) | sf::Rect< T >
Rect() | sf::Rect< T >
Rect(T LeftCoord, T TopCoord, T RightCoord, T BottomCoord) | sf::Rect< T >
Right | sf::Rect< T >
Top | sf::Rect< T >


sf::RenderTarget

sf::RenderTarget Class Reference

Base class for all render targets (window, image, . More...

#include <RenderTarget.hpp>

Inheritance diagram for sf::RenderTarget:

sf::RenderWindow

List of all members.

Public Member Functions

virtual | ~RenderTarget ()
Destructor.
void | Clear (const Color &FillColor=Color(0, 0, 0))
Clear the entire target with a single color.
virtual void | Draw (const Drawable &Object)
Draw something into the target.
virtual unsigned int | GetWidth () const =0
Get the width of the rendering region of the target.
virtual unsigned int | GetHeight () const =0
Get the height of the rendering region of the target.
void | SetView (const View &NewView)
Change the current active view.
const View & | GetView () const
Get the current view.
View & GetDefaultView ()
Get the default view of the window for read / write.
void | PreserveOpenGLStates (bool Preserve)
Tell SFML to preserve external OpenGL states, at the expense of more CPU charge.

Protected Member Functions

RenderTarget ()
Default constructor.
void | Initialize ()
Called by the derived class when it's ready to be initialized.

Detailed Description

Base class for all render targets (window, image, .

..)

Definition at line 43 of file RenderTarget.hpp.

Constructor & Destructor Documentation

sf::RenderTarget::~RenderTarget ( ) [virtual]

Destructor.

Definition at line 51 of file RenderTarget.cpp.

sf::RenderTarget::RenderTarget ( ) [protected]

Default constructor.

Definition at line 39 of file RenderTarget.cpp.

Member Function Documentation

void sf::RenderTarget::Clear ( const Color & FillColor = Color(0, 0, 0) )

Clear the entire target with a single color.

Parameters:
FillColor : Color to use to clear the render target

Definition at line 60 of file RenderTarget.cpp.

void sf::RenderTarget::Draw ( const Drawable & Object ) [virtual]

Draw something into the target.

Draw something on the window.

Parameters:
Object : Object to draw

Definition at line 76 of file RenderTarget.cpp.

View & sf::RenderTarget::GetDefaultView ( )

Get the default view of the window for read / write.

Returns:
Default view

Definition at line 147 of file RenderTarget.cpp.

virtual unsigned int sf::RenderTarget::GetHeight ( ) const [pure virtual]

Get the height of the rendering region of the target.

Returns:
Height in pixels

Implemented in sf::RenderWindow.

const View & sf::RenderTarget::GetView ( ) const

Get the current view.

Returns:
Current view active in the window

Definition at line 138 of file RenderTarget.cpp.

virtual unsigned int sf::RenderTarget::GetWidth ( ) const [pure virtual]

Get the width of the rendering region of the target.

Returns:
Width in pixels

Implemented in sf::RenderWindow.

void sf::RenderTarget::Initialize ( ) [protected]

Called by the derived class when it's ready to be initialized.

Definition at line 170 of file RenderTarget.cpp.

void sf::RenderTarget::PreserveOpenGLStates ( bool Preserve )

Tell SFML to preserve external OpenGL states, at the expense of more CPU charge.

Tell SFML to preserve external OpenGL states, at the expense of more CPU charge.

Use this function if you don't want SFML to mess up your own OpenGL states (if any). Don't enable state preservation if not needed, as it will allow SFML to do internal optimizations and improve performances. This parameter is false by default

Parameters:
Preserve : True to preserve OpenGL states, false to let SFML optimize
Use this function if you don't want SFML to mess up your own OpenGL states (if any). Don't enable state preservation if not needed, as it will allow SFML to do internal optimizations and improve performances. This parameter is false by default

Definition at line 161 of file RenderTarget.cpp.

void sf::RenderTarget::SetView ( const View & NewView )

Change the current active view.

Parameters:
NewView : New view to use (pass GetDefaultView() to set the default view)

Definition at line 129 of file RenderTarget.cpp.

The documentation for this class was generated from the following files:
  • RenderTarget.hpp
  • RenderTarget.cpp


sf::RenderTarget Member List

This is the complete list of members for sf::RenderTarget, including all inherited members.

Clear(const Color &FillColor=Color(0, 0, 0)) | sf::RenderTarget |
Draw(const Drawable &Object) | sf::RenderTarget | [virtual]
GetDefaultView() | sf::RenderTarget |
GetHeight() const =0 | sf::RenderTarget | [pure virtual]
GetView() const | sf::RenderTarget |
GetWidth() const =0 | sf::RenderTarget | [pure virtual]
Initialize() | sf::RenderTarget | [protected]
PreserveOpenGLStates(bool Preserve) | sf::RenderTarget |
RenderTarget() | sf::RenderTarget | [protected]
SetView(const View &NewView) | sf::RenderTarget |
~RenderTarget() | sf::RenderTarget | [virtual]


sf::RenderWindow

sf::RenderWindow Class Reference

Simple wrapper for sf::Window that allows easy 2D rendering. More...

#include <RenderWindow.hpp>

Inheritance diagram for sf::RenderWindow:

sf::Window sf::RenderTarget sf::WindowListener sf::NonCopyable

List of all members.

Public Member Functions

RenderWindow ()
Default constructor.
RenderWindow (VideoMode Mode, const std::string &Title, unsigned long WindowStyle=Style::Resize|Style::Close, const WindowSettings &Params=WindowSettings())
Construct the window.
RenderWindow (WindowHandle Handle, const WindowSettings &Params=WindowSettings())
Construct the window from an existing control.
virtual | ~RenderWindow ()
Destructor.
virtual unsigned int | GetWidth () const
Get the width of the rendering region of the window.
virtual unsigned int | GetHeight () const
Get the height of the rendering region of the window.
Image | Capture () const
Save the content of the window to an image.
sf::Vector2f | ConvertCoords (unsigned int WindowX, unsigned int WindowY, const View *TargetView=NULL) const
Convert a point in window coordinates into view coordinates.
void | Create (VideoMode Mode, const std::string &Title, unsigned long WindowStyle=Style::Resize|Style::Close, const WindowSettings &Params=WindowSettings())
Create (or recreate) the window.
void | Create (WindowHandle Handle, const WindowSettings &Params=WindowSettings())
Create (or recreate) the window from an existing control.
void | Close ()
Close (destroy) the window.
bool | IsOpened () const
Tell whether or not the window is opened (ie.
const WindowSettings & | GetSettings () const
Get the creation settings of the window.
bool | GetEvent (Event &EventReceived)
Get the event on top of events stack, if any, and pop it.
void | UseVerticalSync (bool Enabled)
Enable / disable vertical synchronization.
void | ShowMouseCursor (bool Show)
Show or hide the mouse cursor.
void | SetCursorPosition (unsigned int Left, unsigned int Top)
Change the position of the mouse cursor.
void | SetPosition (int Left, int Top)
Change the position of the window on screen.
void | SetSize (unsigned int Width, unsigned int Height)
Change the size of the rendering region of the window.
void | Show (bool State)
Show or hide the window.
void | EnableKeyRepeat (bool Enabled)
Enable or disable automatic key-repeat.
void | SetIcon (unsigned int Width, unsigned int Height, const Uint8 *Pixels)
Change the window's icon.
bool | SetActive (bool Active=true) const
Activate of deactivate the window as the current target for rendering.
void | Display ()
Display the window on screen.
const Input & | GetInput () const
Get the input manager of the window.
void | SetFramerateLimit (unsigned int Limit)
Limit the framerate to a maximum fixed frequency.
float | GetFrameTime () const
Get time elapsed since last frame.
void | SetJoystickThreshold (float Threshold)
Change the joystick threshold, ie.
void | Clear (const Color &FillColor=Color(0, 0, 0))
Clear the entire target with a single color.
virtual void | Draw (const Drawable &Object)
Draw something into the target.
void | SetView (const View &NewView)
Change the current active view.
const View & | GetView () const
Get the current view.
View & GetDefaultView ()
Get the default view of the window for read / write.
void | PreserveOpenGLStates (bool Preserve)
Tell SFML to preserve external OpenGL states, at the expense of more CPU charge.

Protected Member Functions

void | Initialize ()
Called by the derived class when it's ready to be initialized.

Detailed Description

Simple wrapper for sf::Window that allows easy 2D rendering.

Definition at line 45 of file RenderWindow.hpp.

Constructor & Destructor Documentation

sf::RenderWindow::RenderWindow ( )

Default constructor.

Definition at line 40 of file RenderWindow.cpp.

sf::RenderWindow::RenderWindow | ( | VideoMode | Mode,
 |  | const std::string & | Title,
 |  | unsigned long | WindowStyle = Style::Resize | Style::Close,
 |  | const WindowSettings & | Params = WindowSettings()
 | ) |  |

Construct the window.

Parameters:
Mode | : Video mode to use
Title | : Title of the window
WindowStyle | : Window style, see sf::Style (Resize | Close by default)
Params | : Creation parameters (see default constructor for default values)

Definition at line 49 of file RenderWindow.cpp.

sf::RenderWindow::RenderWindow | ( | WindowHandle | Handle,
 |  | const WindowSettings & | Params = WindowSettings()
 | ) |  |

Construct the window from an existing control.

Parameters:
Handle | : Platform-specific handle of the control
Params | : Creation parameters (see default constructor for default values)

Definition at line 58 of file RenderWindow.cpp.

sf::RenderWindow::~RenderWindow ( ) [virtual]

Destructor.

Definition at line 67 of file RenderWindow.cpp.

Member Function Documentation

Image sf::RenderWindow::Capture ( ) const

Save the content of the window to an image.

Returns:
Image instance containing the contents of the screen

Definition at line 107 of file RenderWindow.cpp.

void sf::RenderTarget::Clear ( const Color & FillColor = Color(0, 0, 0) ) [inherited]

Clear the entire target with a single color.

Parameters:
FillColor : Color to use to clear the render target

Definition at line 60 of file RenderTarget.cpp.

void sf::Window::Close ( ) [inherited]

Close (destroy) the window.

The sf::Window instance remains valid and you can call Create to recreate the window

The sf::Window instance remains valid and you can call Create to recreate the window

Definition at line 165 of file Window.cpp.

sf::Vector2f sf::RenderWindow::ConvertCoords | ( | unsigned int | WindowX,
 |  | unsigned int | WindowY,
 |  | const View * | TargetView = NULL |
 | ) |  |  | const

Convert a point in window coordinates into view coordinates.

Parameters:
WindowX | : X coordinate of the point to convert, relative to the window
WindowY | : Y coordinate of the point to convert, relative to the window
TargetView | : Target view to convert the point to (NULL by default -- uses the current view)
Returns:
Converted point

Definition at line 142 of file RenderWindow.cpp.

void sf::Window::Create | ( | WindowHandle | Handle,
 |  | const WindowSettings & | Params = WindowSettings() |
 | ) |  |  | [inherited]

Create (or recreate) the window from an existing control.

Create the window from an existing control.

Parameters:
Handle | : Platform-specific handle of the control
Params | : Creation parameters (see default constructor for default values)

Definition at line 147 of file Window.cpp.

void sf::Window::Create | ( | VideoMode | Mode,
 |  | const std::string & | Title,
 |  | unsigned long | WindowStyle = Style::Resize | Style::Close,
 |  | const WindowSettings & | Params = WindowSettings() |
 | ) |  |  | [inherited]

Create (or recreate) the window.

Create the window.

Parameters:
Mode | : Video mode to use
Title | : Title of the window
WindowStyle | : Window style, see sf::Style (Resize | Close by default)
Params | : Creation parameters (see default constructor for default values)

Definition at line 104 of file Window.cpp.

void sf::Window::Display ( ) [inherited]

Display the window on screen.

Definition at line 353 of file Window.cpp.

void sf::RenderTarget::Draw ( const Drawable & Object ) [virtual, inherited]

Draw something into the target.

Draw something on the window.

Parameters:
Object : Object to draw

Definition at line 76 of file RenderTarget.cpp.

void sf::Window::EnableKeyRepeat ( bool Enabled ) [inherited]

Enable or disable automatic key-repeat.

Automatic key-repeat is enabled by default

Parameters:
Enabled : True to enable, false to disable
Automatic key-repeat is enabled by default

Definition at line 317 of file Window.cpp.

View & sf::RenderTarget::GetDefaultView ( ) [inherited]

Get the default view of the window for read / write.

Returns:
Default view

Definition at line 147 of file RenderTarget.cpp.

bool sf::Window::GetEvent ( Event & EventReceived ) [inherited]

Get the event on top of events stack, if any, and pop it.

Get the event on top of events stack, if any.

Parameters:
EventReceived : Event to fill, if any
Returns:
True if an event was returned, false if events stack was empty

Definition at line 218 of file Window.cpp.

float sf::Window::GetFrameTime ( ) const [inherited]

Get time elapsed since last frame.

Returns:
Time elapsed, in seconds

Definition at line 394 of file Window.cpp.

unsigned int sf::RenderWindow::GetHeight ( ) const [virtual]

Get the height of the rendering region of the window.

Returns:
Height in pixels

Implements sf::RenderTarget.

Definition at line 98 of file RenderWindow.cpp.

const Input & sf::Window::GetInput ( ) const [inherited]

Get the input manager of the window.

Returns:
Reference to the input

Definition at line 376 of file Window.cpp.

const WindowSettings & sf::Window::GetSettings ( ) const [inherited]

Get the creation settings of the window.

Returns:
Structure containing the creation settings

Definition at line 209 of file Window.cpp.

const View & sf::RenderTarget::GetView ( ) const [inherited]

Get the current view.

Returns:
Current view active in the window

Definition at line 138 of file RenderTarget.cpp.

unsigned int sf::RenderWindow::GetWidth ( ) const [virtual]

Get the width of the rendering region of the window.

Returns:
Width in pixels

Implements sf::RenderTarget.

Definition at line 89 of file RenderWindow.cpp.

void sf::RenderTarget::Initialize ( ) [protected, inherited]

Called by the derived class when it's ready to be initialized.

Definition at line 170 of file RenderTarget.cpp.

bool sf::Window::IsOpened ( ) const [inherited]

Tell whether or not the window is opened (ie.

has been created). Note that a hidden window (Show(false)) will still return true

Returns:
True if the window is opened
has been created). Note that a hidden window (Show(false)) will still return true

Definition at line 182 of file Window.cpp.

void sf::RenderTarget::PreserveOpenGLStates ( bool Preserve ) [inherited]

Tell SFML to preserve external OpenGL states, at the expense of more CPU charge.

Tell SFML to preserve external OpenGL states, at the expense of more CPU charge.

Use this function if you don't want SFML to mess up your own OpenGL states (if any). Don't enable state preservation if not needed, as it will allow SFML to do internal optimizations and improve performances. This parameter is false by default

Parameters:
Preserve : True to preserve OpenGL states, false to let SFML optimize
Use this function if you don't want SFML to mess up your own OpenGL states (if any). Don't enable state preservation if not needed, as it will allow SFML to do internal optimizations and improve performances. This parameter is false by default

Definition at line 161 of file RenderTarget.cpp.

bool sf::Window::SetActive ( bool Active = true ) const [inherited]

Activate of deactivate the window as the current target for rendering.

Activate of deactivate the window as the current target for rendering.

Parameters:
Active : True to activate, false to deactivate (true by default)
Returns:
True if operation was successful, false otherwise

Definition at line 338 of file Window.cpp.

void sf::Window::SetCursorPosition | ( | unsigned int | Left,
 |  | unsigned int | Top |
 | ) |  |  | [inherited]

Change the position of the mouse cursor.

Parameters:
Left | : Left coordinate of the cursor, relative to the window
Top | : Top coordinate of the cursor, relative to the window

Definition at line 260 of file Window.cpp.

void sf::Window::SetFramerateLimit ( unsigned int Limit ) [inherited]

Limit the framerate to a maximum fixed frequency.

Set the framerate at a fixed frequency.

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

Definition at line 385 of file Window.cpp.

void sf::Window::SetIcon | ( | unsigned int | Width,
 |  | unsigned int | Height,
 |  | const Uint8 * | Pixels |
 | ) |  |  | [inherited]

Change the window's icon.

Parameters:
Width | : Icon's width, in pixels
Height | : Icon's height, in pixels
Pixels | : Pointer to the pixels in memory, format must be RGBA 32 bits

Definition at line 327 of file Window.cpp.

void sf::Window::SetJoystickThreshold ( float Threshold ) [inherited]

Change the joystick threshold, ie.

the value below which no move event will be generated

Parameters:
Threshold : New threshold, in range [0, 100]
the value below which no move event will be generated

Definition at line 404 of file Window.cpp.

void sf::Window::SetPosition | ( | int | Left,
 |  | int | Top |
 | ) |  |  | [inherited]

Change the position of the window on screen.

Only works for top-level windows

Parameters:
Left | : Left position
Top | : Top position

Definition at line 276 of file Window.cpp.

void sf::Window::SetSize | ( | unsigned int | Width,
 |  | unsigned int | Height |
 | ) |  |  | [inherited]

Change the size of the rendering region of the window.

Parameters:
Width | : New width
Height | : New height

Definition at line 293 of file Window.cpp.

void sf::RenderTarget::SetView ( const View & NewView ) [inherited]

Change the current active view.

Parameters:
NewView : New view to use (pass GetDefaultView() to set the default view)

Definition at line 129 of file RenderTarget.cpp.

void sf::Window::Show ( bool State ) [inherited]

Show or hide the window.

Parameters:
State : True to show, false to hide

Definition at line 303 of file Window.cpp.

void sf::Window::ShowMouseCursor ( bool Show ) [inherited]

Show or hide the mouse cursor.

Parameters:
Show : True to show, false to hide

Definition at line 250 of file Window.cpp.

void sf::Window::UseVerticalSync ( bool Enabled ) [inherited]

Enable / disable vertical synchronization.

Parameters:
Enabled : True to enable v-sync, false to deactivate

Definition at line 240 of file Window.cpp.

The documentation for this class was generated from the following files:
  • RenderWindow.hpp
  • RenderWindow.cpp


sf::RenderWindow Member List

This is the complete list of members for sf::RenderWindow, including all inherited members.

Capture() const | sf::RenderWindow |
Clear(const Color &FillColor=Color(0, 0, 0)) | sf::RenderTarget |
Close() | sf::Window |
ConvertCoords(unsigned int WindowX, unsigned int WindowY, const View *TargetView=NULL) const | sf::RenderWindow |
Create(VideoMode Mode, const std::string &Title, unsigned long WindowStyle=Style::Resize|Style::Close, const WindowSettings &Params=WindowSettings()) | sf::Window |
Create(WindowHandle Handle, const WindowSettings &Params=WindowSettings()) | sf::Window |
Display() | sf::Window |
Draw(const Drawable &Object) | sf::RenderTarget | [virtual]
EnableKeyRepeat(bool Enabled) | sf::Window |
GetDefaultView() | sf::RenderTarget |
GetEvent(Event &EventReceived) | sf::Window |
GetFrameTime() const | sf::Window |
GetHeight() const | sf::RenderWindow | [virtual]
GetInput() const | sf::Window |
GetSettings() const | sf::Window |
GetView() const | sf::RenderTarget |
GetWidth() const | sf::RenderWindow | [virtual]
Initialize() | sf::RenderTarget | [protected]
IsOpened() const | sf::Window |
PreserveOpenGLStates(bool Preserve) | sf::RenderTarget |
RenderTarget() | sf::RenderTarget | [protected]
RenderWindow() | sf::RenderWindow |
RenderWindow(VideoMode Mode, const std::string &Title, unsigned long WindowStyle=Style::Resize|Style::Close, const WindowSettings &Params=WindowSettings()) | sf::RenderWindow |
RenderWindow(WindowHandle Handle, const WindowSettings &Params=WindowSettings()) | sf::RenderWindow |
SetActive(bool Active=true) const | sf::Window |
SetCursorPosition(unsigned int Left, unsigned int Top) | sf::Window |
SetFramerateLimit(unsigned int Limit) | sf::Window |
SetIcon(unsigned int Width, unsigned int Height, const Uint8 *Pixels) | sf::Window |
SetJoystickThreshold(float Threshold) | sf::Window |
SetPosition(int Left, int Top) | sf::Window |
SetSize(unsigned int Width, unsigned int Height) | sf::Window |
SetView(const View &NewView) | sf::RenderTarget |
Show(bool State) | sf::Window |
ShowMouseCursor(bool Show) | sf::Window |
UseVerticalSync(bool Enabled) | sf::Window |
Window() | sf::Window |
Window(VideoMode Mode, const std::string &Title, unsigned long WindowStyle=Style::Resize|Style::Close, const WindowSettings &Params=WindowSettings()) | sf::Window |
Window(WindowHandle Handle, const WindowSettings &Params=WindowSettings()) | sf::Window |
~RenderTarget() | sf::RenderTarget | [virtual]
~RenderWindow() | sf::RenderWindow | [virtual]
~Window() | sf::Window | [virtual]
~WindowListener() | sf::WindowListener | [inline, protected, virtual]


sf::Resource

sf::Resource< T > Class Template Reference

Base class for every resource that needs to notify dependent classes about its destruction. More...

#include <Resource.hpp>

List of all members.

Protected Member Functions

Resource ()
Default constructor.
Resource (const Resource< T > &Copy)
Copy constructor.
~Resource ()
Destructor.
Resource< T > & | operator= (const Resource< T > &Other)
Assignment operator.

Friends

class | ResourcePtr< T >

Detailed Description

template<typename T>
class sf::Resource< T >

Base class for every resource that needs to notify dependent classes about its destruction.

Definition at line 50 of file Resource.hpp.

Constructor & Destructor Documentation

template<typename T>
sf::Resource< T >::Resource ( ) [protected]

Default constructor.

template<typename T>
sf::Resource< T >::Resource ( const Resource< T > & Copy ) [protected]

Copy constructor.

Parameters:
Copy : Resource to copy

template<typename T>
sf::Resource< T >::~Resource ( ) [protected]

Destructor.

Member Function Documentation

template<typename T>
Resource<T>& sf::Resource< T >::operator= ( const Resource< T > & Other ) [protected]

Assignment operator.

Parameters:
Other : Resource to copy
Returns:
Reference to this

The documentation for this class was generated from the following file:
  • Resource.hpp


sf::Resource< T > Member List

This is the complete list of members for sf::Resource< T >, including all inherited members.

operator=(const Resource< T > &Other) | sf::Resource< T > | [protected]
Resource() | sf::Resource< T > | [protected]
Resource(const Resource< T > &Copy) | sf::Resource< T > | [protected]
ResourcePtr< T > (defined in sf::Resource< T >) | sf::Resource< T > | [friend]
~Resource() | sf::Resource< T > | [protected]


sf::ResourcePtr

sf::ResourcePtr< T > Class Template Reference

Safe pointer to a T resource (inheriting from sf::Resource<T>), its pointer is automatically reseted when the resource is destroyed. More...

#include <Resource.hpp>

List of all members.

Public Member Functions

ResourcePtr ()
Default constructor.
ResourcePtr (const T *Resource)
Construct from a raw resource.
ResourcePtr (const ResourcePtr< T > &Copy)
Copy constructor.
~ResourcePtr ()
Destructor.
ResourcePtr< T > & | operator= (const ResourcePtr< T > &Other)
Assignment operator from another ResourcePtr.
ResourcePtr< T > & | operator= (const T *Resource)
Assignment operator from a raw resource.
operator const T * () const
Cast operator to implicitely convert the resource pointer to its raw pointer type.
const T & | operator* () const
Operator * overload to return a reference to the actual resource.
const T * | operator-> () const
Operator -> overload to return a pointer to the actual resource.
void | OnResourceDestroyed ()
Function called when the observed resource is about to be destroyed.

Detailed Description

template<typename T>
class sf::ResourcePtr< T >

Safe pointer to a T resource (inheriting from sf::Resource<T>), its pointer is automatically reseted when the resource is destroyed.

Definition at line 116 of file Resource.hpp.

Constructor & Destructor Documentation

template<typename T>
sf::ResourcePtr< T >::ResourcePtr ( )

Default constructor.

template<typename T>
sf::ResourcePtr< T >::ResourcePtr ( const T * Resource )

Construct from a raw resource.

Parameters:
Resource : Internal resource

template<typename T>
sf::ResourcePtr< T >::ResourcePtr ( const ResourcePtr< T > & Copy )

Copy constructor.

Parameters:
Copy : Instance to copy

template<typename T>
sf::ResourcePtr< T >::~ResourcePtr ( )

Destructor.

Member Function Documentation

template<typename T>
void sf::ResourcePtr< T >::OnResourceDestroyed ( )

Function called when the observed resource is about to be destroyed.

template<typename T>
sf::ResourcePtr< T >::operator const T * ( ) const

Cast operator to implicitely convert the resource pointer to its raw pointer type.

This might be dangerous in the general case, but in this context it is safe enough to define this operator

Returns:
Pointer to the actual resource

template<typename T>
const T& sf::ResourcePtr< T >::operator* ( ) const

Operator * overload to return a reference to the actual resource.

Returns:
Reference to the internal resource

template<typename T>
const T* sf::ResourcePtr< T >::operator-> ( ) const

Operator -> overload to return a pointer to the actual resource.

Returns:
Pointer to the internal resource

template<typename T>
ResourcePtr<T>& sf::ResourcePtr< T >::operator= ( const T * Resource )

Assignment operator from a raw resource.

Parameters:
Resource : Resource to assign
Returns:
Reference to this

template<typename T>
ResourcePtr<T>& sf::ResourcePtr< T >::operator= ( const ResourcePtr< T > & Other )

Assignment operator from another ResourcePtr.

Parameters:
Other : Resource pointer to assign
Returns:
Reference to this

The documentation for this class was generated from the following file:
  • Resource.hpp


sf::ResourcePtr< T > Member List

This is the complete list of members for sf::ResourcePtr< T >, including all inherited members.

OnResourceDestroyed() | sf::ResourcePtr< T >
operator const T *() const | sf::ResourcePtr< T >
operator*() const | sf::ResourcePtr< T >
operator->() const | sf::ResourcePtr< T >
operator=(const ResourcePtr< T > &Other) | sf::ResourcePtr< T >
operator=(const T *Resource) | sf::ResourcePtr< T >
ResourcePtr() | sf::ResourcePtr< T >
ResourcePtr(const T *Resource) | sf::ResourcePtr< T >
ResourcePtr(const ResourcePtr< T > &Copy) | sf::ResourcePtr< T >
~ResourcePtr() | sf::ResourcePtr< T >


sf::Selector

sf::Selector< Type > Class Template Reference

Selector allow reading from multiple sockets without blocking. More...

#include <Selector.hpp>

Inheritance diagram for sf::Selector< Type >:

sf::SelectorBase

List of all members.

Public Member Functions

void | Add (Type Socket)
Add a socket to watch.
void | Remove (Type Socket)
Remove a socket.
void | Clear ()
Remove all sockets.
unsigned int | Wait (float Timeout=0.f)
Wait and collect sockets which are ready for reading.
Type | GetSocketReady (unsigned int Index)
After a call to Wait(), get the Index-th socket which is ready for reading.

Private Member Functions

void | Add (SocketHelper::SocketType Socket)
Add a socket to watch.
void | Remove (SocketHelper::SocketType Socket)
Remove a socket.

Detailed Description

template<typename Type>
class sf::Selector< Type >

Selector allow reading from multiple sockets without blocking.

It's a kind of multiplexer

Definition at line 44 of file Selector.hpp.

Member Function Documentation

template<typename Type >
void sf::Selector< Type >::Add ( Type Socket )

Add a socket to watch.

Parameters:
Socket : Socket to add

template<typename Type >
void sf::Selector< Type >::Clear ( )

Remove all sockets.

Reimplemented from sf::SelectorBase.

template<typename Type >
Type sf::Selector< Type >::GetSocketReady ( unsigned int Index )

After a call to Wait(), get the Index-th socket which is ready for reading.

The total number of sockets ready is the integer returned by the previous call to Wait()

Parameters:
Index : Index of the socket to get
Returns:
The Index-th socket

Reimplemented from sf::SelectorBase.

template<typename Type >
void sf::Selector< Type >::Remove ( Type Socket )

Remove a socket.

Parameters:
Socket : Socket to remove

template<typename Type >
unsigned int sf::Selector< Type >::Wait ( float Timeout = 0.f )

Wait and collect sockets which are ready for reading.

This functions will return either when at least one socket is ready, or when the given time is out

Parameters:
Timeout : Timeout, in seconds (0 by default : no timeout)
Returns:
Number of sockets ready to be read

Reimplemented from sf::SelectorBase.

The documentation for this class was generated from the following file:
  • Selector.hpp


sf::Selector< Type > Member List

This is the complete list of members for sf::Selector< Type >, including all inherited members.

Add(Type Socket) | sf::Selector< Type > |
sf::SelectorBase::Add(SocketHelper::SocketType Socket) | sf::SelectorBase | [private]
Clear() | sf::Selector< Type > |
GetSocketReady(unsigned int Index) | sf::Selector< Type > |
Remove(Type Socket) | sf::Selector< Type > |
sf::SelectorBase::Remove(SocketHelper::SocketType Socket) | sf::SelectorBase | [private]
SelectorBase() | sf::SelectorBase | [private]
Wait(float Timeout=0.f) | sf::Selector< Type > |


sf::SelectorBase

sf::SelectorBase Class Reference

Private base class for selectors. More...

#include <SelectorBase.hpp>

Inheritance diagram for sf::SelectorBase:

sf::Selector< Type >

List of all members.

Public Member Functions

SelectorBase ()
Default constructor.
void | Add (SocketHelper::SocketType Socket)
Add a socket to watch.
void | Remove (SocketHelper::SocketType Socket)
Remove a socket.
void | Clear ()
Remove all sockets.
unsigned int | Wait (float Timeout=0.f)
Wait and collect sockets which are ready for reading.
SocketHelper::SocketType | GetSocketReady (unsigned int Index)
After a call to Wait(), get the Index-th socket which is ready for reading.

Detailed Description

Private base class for selectors.

As Selector is a template class, this base is needed so that every system call get compiled in SFML (not inlined)

Definition at line 43 of file SelectorBase.hpp.

Constructor & Destructor Documentation

sf::SelectorBase::SelectorBase ( )

Default constructor.

Definition at line 40 of file SelectorBase.cpp.

Member Function Documentation

void sf::SelectorBase::Add ( SocketHelper::SocketType Socket )

Add a socket to watch.

Parameters:
Socket : Socket to add

Definition at line 50 of file SelectorBase.cpp.

void sf::SelectorBase::Clear ( )

Remove all sockets.

Reimplemented in sf::Selector< Type >.

Definition at line 72 of file SelectorBase.cpp.

SocketHelper::SocketType sf::SelectorBase::GetSocketReady ( unsigned int Index )

After a call to Wait(), get the Index-th socket which is ready for reading.

After a call to Wait(), get the Index-th socket which is ready for reading.

The total number of sockets ready is the integer returned by the previous call to Wait()

Parameters:
Index : Index of the socket to get
Returns:
The Index-th socket
The total number of sockets ready is the integer returned by the previous call to Wait()

Reimplemented in sf::Selector< Type >.

Definition at line 108 of file SelectorBase.cpp.

void sf::SelectorBase::Remove ( SocketHelper::SocketType Socket )

Remove a socket.

Parameters:
Socket : Socket to remove

Definition at line 63 of file SelectorBase.cpp.

unsigned int sf::SelectorBase::Wait ( float Timeout = 0.f )

Wait and collect sockets which are ready for reading.

This functions will return either when at least one socket is ready, or when the given time is out

Parameters:
Timeout : Timeout, in seconds (0 by default : no timeout)
Returns:
Number of sockets ready to be read
This functions will return either when at least one socket is ready, or when the given time is out

Reimplemented in sf::Selector< Type >.

Definition at line 86 of file SelectorBase.cpp.

The documentation for this class was generated from the following files:
  • SelectorBase.hpp
  • SelectorBase.cpp


sf::SelectorBase Member List

This is the complete list of members for sf::SelectorBase, including all inherited members.

Add(SocketHelper::SocketType Socket) | sf::SelectorBase
Clear() | sf::SelectorBase
GetSocketReady(unsigned int Index) | sf::SelectorBase
Remove(SocketHelper::SocketType Socket) | sf::SelectorBase
SelectorBase() | sf::SelectorBase
Wait(float Timeout=0.f) | sf::SelectorBase


sf::Shape

sf::Shape Class Reference

Shape defines a drawable convex shape ; it also defines helper functions to draw simple shapes like lines, rectangles, circles, etc. More...

#include <Shape.hpp>

Inheritance diagram for sf::Shape:

sf::Drawable

List of all members.

Classes

struct | Point
Defines a simple 2D point.

Public Member Functions

Shape ()
Default constructor.
void | AddPoint (float X, float Y, const Color &Col=Color(255, 255, 255), const Color &OutlineCol=Color(0, 0, 0))
Add a point to the shape.
void | AddPoint (const Vector2f &Position, const Color &Col=Color(255, 255, 255), const Color &OutlineCol=Color(0, 0, 0))
Add a point to the shape.
unsigned int | GetNbPoints () const
Get the number of points composing the shape.
void | EnableFill (bool Enable)
Enable or disable filling the shape.
void | EnableOutline (bool Enable)
Enable or disable drawing the shape outline.
void | SetPointPosition (unsigned int Index, const Vector2f &Position)
Set the position of a point.
void | SetPointPosition (unsigned int Index, float X, float Y)
Set the position of a point.
void | SetPointColor (unsigned int Index, const Color &Col)
Set the color of a point.
void | SetPointOutlineColor (unsigned int Index, const Color &OutlineCol)
Set the outline color of a point.
void | SetOutlineWidth (float Width)
Change the width of the shape outline.
const Vector2f & | GetPointPosition (unsigned int Index) const
Get the position of a point.
const Color & | GetPointColor (unsigned int Index) const
Get the color of a point.
const Color & | GetPointOutlineColor (unsigned int Index) const
Get the outline color of a point.
float | GetOutlineWidth () const
Get the width of the shape outline.
void | SetPosition (float X, float Y)
Set the position of the object (take 2 values).
void | SetPosition (const Vector2f &Position)
Set the position of the object (take a 2D vector).
void | SetX (float X)
Set the X position of the object.
void | SetY (float Y)
Set the Y position of the object.
void | SetScale (float ScaleX, float ScaleY)
Set the scale of the object (take 2 values).
void | SetScale (const Vector2f &Scale)
Set the scale of the object (take a 2D vector).
void | SetScaleX (float FactorX)
Set the X scale factor of the object.
void | SetScaleY (float FactorY)
Set the Y scale factor of the object.
void | SetCenter (float CenterX, float CenterY)
Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).
void | SetCenter (const Vector2f &Center)
Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).
void | SetRotation (float Rotation)
Set the orientation of the object.
void | SetColor (const Color &Col)
Set the color of the object.
void | SetBlendMode (Blend::Mode Mode)
Set the blending mode for the object.
const Vector2f & | GetPosition () const
Get the position of the object.
const Vector2f & | GetScale () const
Get the current scale of the object.
const Vector2f & | GetCenter () const
Get the center of the object.
float | GetRotation () const
Get the orientation of the object.
const Color & | GetColor () const
Get the color of the object.
Blend::Mode | GetBlendMode () const
Get the current blending mode.
void | Move (float OffsetX, float OffsetY)
Move the object of a given offset (take 2 values).
void | Move (const Vector2f &Offset)
Move the object of a given offset (take a 2D vector).
void | Scale (float FactorX, float FactorY)
Scale the object (take 2 values).
void | Scale (const Vector2f &Factor)
Scale the object (take a 2D vector).
void | Rotate (float Angle)
Rotate the object.
sf::Vector2f | TransformToLocal (const sf::Vector2f &Point) const
Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).
sf::Vector2f | TransformToGlobal (const sf::Vector2f &Point) const
Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Static Public Member Functions

static Shape | Line (float P1X, float P1Y, float P2X, float P2Y, float Thickness, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0))
Create a shape made of a single line (use floats).
static Shape | Line (const Vector2f &P1, const Vector2f &P2, float Thickness, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0))
Create a shape made of a single line (use vectors).
static Shape | Rectangle (float P1X, float P1Y, float P2X, float P2Y, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0))
Create a shape made of a single rectangle (use floats).
static Shape | Rectangle (const Vector2f &P1, const Vector2f &P2, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0))
Create a shape made of a single rectangle (use vectors).
static Shape | Circle (float X, float Y, float Radius, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0))
Create a shape made of a single circle (use floats).
static Shape | Circle (const Vector2f &Center, float Radius, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0))
Create a shape made of a single circle (use vectors).

Protected Member Functions

virtual void | Render (RenderTarget &Target) const
/see Drawable::Render
const Matrix3 & | GetMatrix () const
Get the transform matrix of the drawable.
const Matrix3 & | GetInverseMatrix () const
Get the inverse transform matrix of the drawable.

Detailed Description

Shape defines a drawable convex shape ; it also defines helper functions to draw simple shapes like lines, rectangles, circles, etc.

Definition at line 43 of file Shape.hpp.

Constructor & Destructor Documentation

sf::Shape::Shape ( )

Default constructor.

Definition at line 38 of file Shape.cpp.

Member Function Documentation

void sf::Shape::AddPoint | ( | const Vector2f & | Position,
 |  | const Color & | Col = Color(255, 255, 255),
 |  | const Color & | OutlineCol = Color(0, 0, 0)
 | ) |  |

Add a point to the shape.

Parameters:
Position | : Position of the point
Col | : Color of the point (white by default)
OutlineCol | : Outline color of the point (black by default)

Definition at line 61 of file Shape.cpp.

void sf::Shape::AddPoint | ( | float | X,
 |  | float | Y,
 |  | const Color & | Col = Color(255, 255, 255),
 |  | const Color & | OutlineCol = Color(0, 0, 0)
 | ) |  |

Add a point to the shape.

Parameters:
X,Y | : Position of the point
Col | : Color of the point (white by default)
OutlineCol | : Outline color of the point (black by default)

Definition at line 52 of file Shape.cpp.

Shape sf::Shape::Circle | ( | const Vector2f & | Center,
 |  | float | Radius,
 |  | const Color & | Col,
 |  | float | Outline = 0.f,
 |  | const Color & | OutlineCol = sf::Color(0, 0, 0) |
 | ) |  |  | [static]

Create a shape made of a single circle (use vectors).

Parameters:
Center | : Position of the center
Radius | : Radius
Col | : Color used to fill the circle
Outline | : Outline width (0 by default)
OutlineCol | : Color used to draw the outline (black by default)

Definition at line 276 of file Shape.cpp.

Shape sf::Shape::Circle | ( | float | X,
 |  | float | Y,
 |  | float | Radius,
 |  | const Color & | Col,
 |  | float | Outline = 0.f,
 |  | const Color & | OutlineCol = sf::Color(0, 0, 0) |
 | ) |  |  | [static]

Create a shape made of a single circle (use floats).

Create a shape made of a single circle.

Parameters:
X,Y | : Position of the center
Radius | : Radius
Col | : Color used to fill the circle
Outline | : Outline width (0 by default)
OutlineCol | : Color used to draw the outline (black by default)

Definition at line 250 of file Shape.cpp.

void sf::Shape::EnableFill ( bool Enable )

Enable or disable filling the shape.

Fill is enabled by default

Parameters:
Enable : True to enable, false to disable
Fill is enabled by default

Definition at line 81 of file Shape.cpp.

void sf::Shape::EnableOutline ( bool Enable )

Enable or disable drawing the shape outline.

Outline is enabled by default

Parameters:
Enable : True to enable, false to disable
Outline is enabled by default

Definition at line 91 of file Shape.cpp.

Blend::Mode sf::Drawable::GetBlendMode ( ) const [inherited]

Get the current blending mode.

Returns:
Current blending mode

Definition at line 258 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetCenter ( ) const [inherited]

Get the center of the object.

Returns:
Current position of the center

Definition at line 231 of file Drawable.cpp.

const Color & sf::Drawable::GetColor ( ) const [inherited]

Get the color of the object.

Returns:
Current color

Definition at line 249 of file Drawable.cpp.

const Matrix3 & sf::Drawable::GetInverseMatrix ( ) const [protected, inherited]

Get the inverse transform matrix of the drawable.

Returns:
Inverse transform matrix

Definition at line 350 of file Drawable.cpp.

const Matrix3 & sf::Drawable::GetMatrix ( ) const [protected, inherited]

Get the transform matrix of the drawable.

Returns:
Transform matrix

Definition at line 334 of file Drawable.cpp.

unsigned int sf::Shape::GetNbPoints ( ) const

Get the number of points composing the shape.

Parameters:
Total number of points

Definition at line 71 of file Shape.cpp.

float sf::Shape::GetOutlineWidth ( ) const

Get the width of the shape outline.

Returns:
Current outline width

Definition at line 175 of file Shape.cpp.

const Color & sf::Shape::GetPointColor ( unsigned int Index ) const

Get the color of a point.

Parameters:
Index : Index of the point, in range [0, GetNbPoints() - 1]
Returns:
Color of the Index-th point

Definition at line 157 of file Shape.cpp.

const Color & sf::Shape::GetPointOutlineColor ( unsigned int Index ) const

Get the outline color of a point.

Parameters:
Index : Index of the point, in range [0, GetNbPoints() - 1]
Returns:
Outline color of the Index-th point

Definition at line 166 of file Shape.cpp.

const Vector2f & sf::Shape::GetPointPosition ( unsigned int Index ) const

Get the position of a point.

Parameters:
Index : Index of the point, in range [0, GetNbPoints() - 1]
Returns:
Position of the Index-th point

Definition at line 148 of file Shape.cpp.

const Vector2f & sf::Drawable::GetPosition ( ) const [inherited]

Get the position of the object.

Returns:
Current position

Definition at line 213 of file Drawable.cpp.

float sf::Drawable::GetRotation ( ) const [inherited]

Get the orientation of the object.

Rotation is always in the range [0, 360]

Returns:
Current rotation, in degrees

Definition at line 240 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetScale ( ) const [inherited]

Get the current scale of the object.

Returns:
Current scale factor (always positive)

Definition at line 222 of file Drawable.cpp.

Shape sf::Shape::Line | ( | const Vector2f & | P1,
 |  | const Vector2f & | P2,
 |  | float | Thickness,
 |  | const Color & | Col,
 |  | float | Outline = 0.f,
 |  | const Color & | OutlineCol = sf::Color(0, 0, 0) |
 | ) |  |  | [static]

Create a shape made of a single line (use vectors).

Parameters:
P1X,P1Y | : Position of the first point
P2X,P2Y | : Position second point
Thickness | : Line thickness
Col | : Color used to draw the line
Outline | : Outline width (0 by default)
OutlineCol | : Color used to draw the outline (black by default)

Definition at line 212 of file Shape.cpp.

Shape sf::Shape::Line | ( | float | P1X,
 |  | float | P1Y,
 |  | float | P2X,
 |  | float | P2Y,
 |  | float | Thickness,
 |  | const Color & | Col,
 |  | float | Outline = 0.f,
 |  | const Color & | OutlineCol = sf::Color(0, 0, 0) |
 | ) |  |  | [static]

Create a shape made of a single line (use floats).

Create a shape made of a single line.

Parameters:
P1X,P1Y | : Position of the first point
P2X,P2Y | : Position second point
Thickness | : Line thickness
Col | : Color used to draw the line
Outline | : Outline width (0 by default)
OutlineCol | : Color used to draw the outline (black by default)

Definition at line 184 of file Shape.cpp.

void sf::Drawable::Move ( const Vector2f & Offset ) [inherited]

Move the object of a given offset (take a 2D vector).

Parameters:
Offset : Amount of units to move the object of

Definition at line 278 of file Drawable.cpp.

void sf::Drawable::Move | ( | float | OffsetX,
 |  | float | OffsetY |
 | ) |  |  | [inherited]

Move the object of a given offset (take 2 values).

Parameters:
OffsetX | : X offset
OffsetY | : Y offset

Definition at line 268 of file Drawable.cpp.

Shape sf::Shape::Rectangle | ( | const Vector2f & | P1,
 |  | const Vector2f & | P2,
 |  | const Color & | Col,
 |  | float | Outline = 0.f,
 |  | const Color & | OutlineCol = sf::Color(0, 0, 0) |
 | ) |  |  | [static]

Create a shape made of a single rectangle (use vectors).

Parameters:
P1 | : Position of the first point
P2 | : Position second point
Col | : Color used to fill the rectangle
Outline | : Outline width (0 by default)
OutlineCol | : Color used to draw the outline (black by default)

Definition at line 241 of file Shape.cpp.

Shape sf::Shape::Rectangle | ( | float | P1X,
 |  | float | P1Y,
 |  | float | P2X,
 |  | float | P2Y,
 |  | const Color & | Col,
 |  | float | Outline = 0.f,
 |  | const Color & | OutlineCol = sf::Color(0, 0, 0) |
 | ) |  |  | [static]

Create a shape made of a single rectangle (use floats).

Create a shape made of a single rectangle.

Parameters:
P1X,P1Y | : Position of the first point
P2X,P2Y | : Position second point
Col | : Color used to fill the rectangle
Outline | : Outline width (0 by default)
OutlineCol | : Color used to draw the outline (black by default)

Definition at line 221 of file Shape.cpp.

void sf::Shape::Render ( RenderTarget & Target ) const [protected, virtual]

/see Drawable::Render

Implements sf::Drawable.

Definition at line 285 of file Shape.cpp.

void sf::Drawable::Rotate ( float Angle ) [inherited]

Rotate the object.

Parameters:
Angle : Angle of rotation, in degrees

Definition at line 306 of file Drawable.cpp.

void sf::Drawable::Scale ( const Vector2f & Factor ) [inherited]

Scale the object (take a 2D vector).

Parameters:
Factor : Scaling factors (both values must be strictly positive)

Definition at line 297 of file Drawable.cpp.

void sf::Drawable::Scale | ( | float | FactorX,
 |  | float | FactorY |
 | ) |  |  | [inherited]

Scale the object (take 2 values).

Parameters:
FactorX | : Scaling factor on X (must be strictly positive)
FactorY | : Scaling factor on Y (must be strictly positive)

Definition at line 287 of file Drawable.cpp.

void sf::Drawable::SetBlendMode ( Blend::Mode Mode ) [inherited]

Set the blending mode for the object.

The default blend mode is Blend::Alpha

Parameters:
Mode : New blending mode
The default blend mode is Blend::Alpha

Definition at line 204 of file Drawable.cpp.

void sf::Drawable::SetCenter ( const Vector2f & Center ) [inherited]

Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).

Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).

The default center is (0, 0)

Parameters:
Center : New center
The default center is (0, 0)

Definition at line 171 of file Drawable.cpp.

void sf::Drawable::SetCenter | ( | float | CenterX,
 |  | float | CenterY |
 | ) |  |  | [inherited]

Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).

Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).

The default center is (0, 0)

Parameters:
CenterX | : X coordinate of the center
CenterY | : Y coordinate of the center
The default center is (0, 0)

Definition at line 157 of file Drawable.cpp.

void sf::Drawable::SetColor ( const Color & Col ) [inherited]

Set the color of the object.

The default color is white

Parameters:
Col : New color
The default color is white

Definition at line 194 of file Drawable.cpp.

void sf::Shape::SetOutlineWidth ( float Width )

Change the width of the shape outline.

Parameters:
Width : New width

Definition at line 139 of file Shape.cpp.

void sf::Shape::SetPointColor | ( | unsigned int | Index,
 |  | const Color & | Col
 | ) |  |

Set the color of a point.

Parameters:
Index | : Index of the point, in range [0, GetNbPoints() - 1]
Col | : New color of the Index-th point

Definition at line 119 of file Shape.cpp.

void sf::Shape::SetPointOutlineColor | ( | unsigned int | Index,
 |  | const Color & | OutlineCol
 | ) |  |

Set the outline color of a point.

Parameters:
Index | : Index of the point, in range [0, GetNbPoints() - 1]
OutlineCol | : New outline color of the Index-th point

Definition at line 129 of file Shape.cpp.

void sf::Shape::SetPointPosition | ( | unsigned int | Index,
 |  | float | X,
 |  | float | Y
 | ) |  |

Set the position of a point.

Parameters:
Index | : Index of the point, in range [0, GetNbPoints() - 1]
X | : New X coordinate of the Index-th point
Y | : New Y coordinate of the Index-th point

Definition at line 110 of file Shape.cpp.

void sf::Shape::SetPointPosition | ( | unsigned int | Index,
 |  | const Vector2f & | Position
 | ) |  |

Set the position of a point.

Parameters:
Index | : Index of the point, in range [0, GetNbPoints() - 1]
Position | : New position of the Index-th point

Definition at line 100 of file Shape.cpp.

void sf::Drawable::SetPosition ( const Vector2f & Position ) [inherited]

Set the position of the object (take a 2D vector).

Parameters:
Position : New position

Definition at line 75 of file Drawable.cpp.

void sf::Drawable::SetPosition | ( | float | X,
 |  | float | Y |
 | ) |  |  | [inherited]

Set the position of the object (take 2 values).

Parameters:
X | : New X coordinate
Y | : New Y coordinate

Definition at line 65 of file Drawable.cpp.

void sf::Drawable::SetRotation ( float Rotation ) [inherited]

Set the orientation of the object.

Parameters:
Rotation : Angle of rotation, in degrees

Definition at line 180 of file Drawable.cpp.

void sf::Drawable::SetScale ( const Vector2f & Scale ) [inherited]

Set the scale of the object (take a 2D vector).

Parameters:
Scale : New scale (both values must be strictly positive)

Definition at line 117 of file Drawable.cpp.

void sf::Drawable::SetScale | ( | float | ScaleX,
 |  | float | ScaleY |
 | ) |  |  | [inherited]

Set the scale of the object (take 2 values).

Parameters:
ScaleX | : New horizontal scale (must be strictly positive)
ScaleY | : New vertical scale (must be strictly positive)

Definition at line 107 of file Drawable.cpp.

void sf::Drawable::SetScaleX ( float FactorX ) [inherited]

Set the X scale factor of the object.

Parameters:
X : New X scale factor

Definition at line 127 of file Drawable.cpp.

void sf::Drawable::SetScaleY ( float FactorY ) [inherited]

Set the Y scale factor of the object.

Parameters:
Y : New Y scale factor

Definition at line 141 of file Drawable.cpp.

void sf::Drawable::SetX ( float X ) [inherited]

Set the X position of the object.

Parameters:
X : New X coordinate

Definition at line 85 of file Drawable.cpp.

void sf::Drawable::SetY ( float Y ) [inherited]

Set the Y position of the object.

Parameters:
Y : New Y coordinate

Definition at line 96 of file Drawable.cpp.

sf::Vector2f sf::Drawable::TransformToGlobal ( const sf::Vector2f & Point ) const [inherited]

Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Parameters:
Point : Point to transform
Returns:
Transformed point

Definition at line 325 of file Drawable.cpp.

sf::Vector2f sf::Drawable::TransformToLocal ( const sf::Vector2f & Point ) const [inherited]

Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).

Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).

Parameters:
Point : Point to transform
Returns:
Transformed point

Definition at line 316 of file Drawable.cpp.

The documentation for this class was generated from the following files:
  • Shape.hpp
  • Shape.cpp


sf::Shape Member List

This is the complete list of members for sf::Shape, including all inherited members.

AddPoint(float X, float Y, const Color &Col=Color(255, 255, 255), const Color &OutlineCol=Color(0, 0, 0)) | sf::Shape |
AddPoint(const Vector2f &Position, const Color &Col=Color(255, 255, 255), const Color &OutlineCol=Color(0, 0, 0)) | sf::Shape |
Circle(float X, float Y, float Radius, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0)) | sf::Shape | [static]
Circle(const Vector2f &Center, float Radius, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0)) | sf::Shape | [static]
Drawable(const Vector2f &Position=Vector2f(0, 0), const Vector2f &Scale=Vector2f(1, 1), float Rotation=0.f, const Color &Col=Color(255, 255, 255, 255)) | sf::Drawable |
EnableFill(bool Enable) | sf::Shape |
EnableOutline(bool Enable) | sf::Shape |
GetBlendMode() const | sf::Drawable |
GetCenter() const | sf::Drawable |
GetColor() const | sf::Drawable |
GetInverseMatrix() const | sf::Drawable | [protected]
GetMatrix() const | sf::Drawable | [protected]
GetNbPoints() const | sf::Shape |
GetOutlineWidth() const | sf::Shape |
GetPointColor(unsigned int Index) const | sf::Shape |
GetPointOutlineColor(unsigned int Index) const | sf::Shape |
GetPointPosition(unsigned int Index) const | sf::Shape |
GetPosition() const | sf::Drawable |
GetRotation() const | sf::Drawable |
GetScale() const | sf::Drawable |
Line(float P1X, float P1Y, float P2X, float P2Y, float Thickness, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0)) | sf::Shape | [static]
Line(const Vector2f &P1, const Vector2f &P2, float Thickness, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0)) | sf::Shape | [static]
Move(float OffsetX, float OffsetY) | sf::Drawable |
Move(const Vector2f &Offset) | sf::Drawable |
Rectangle(float P1X, float P1Y, float P2X, float P2Y, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0)) | sf::Shape | [static]
Rectangle(const Vector2f &P1, const Vector2f &P2, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0)) | sf::Shape | [static]
Render(RenderTarget &Target) const | sf::Shape | [protected, virtual]
Rotate(float Angle) | sf::Drawable |
Scale(float FactorX, float FactorY) | sf::Drawable |
Scale(const Vector2f &Factor) | sf::Drawable |
SetBlendMode(Blend::Mode Mode) | sf::Drawable |
SetCenter(float CenterX, float CenterY) | sf::Drawable |
SetCenter(const Vector2f &Center) | sf::Drawable |
SetColor(const Color &Col) | sf::Drawable |
SetOutlineWidth(float Width) | sf::Shape |
SetPointColor(unsigned int Index, const Color &Col) | sf::Shape |
SetPointOutlineColor(unsigned int Index, const Color &OutlineCol) | sf::Shape |
SetPointPosition(unsigned int Index, const Vector2f &Position) | sf::Shape |
SetPointPosition(unsigned int Index, float X, float Y) | sf::Shape |
SetPosition(float X, float Y) | sf::Drawable |
SetPosition(const Vector2f &Position) | sf::Drawable |
SetRotation(float Rotation) | sf::Drawable |
SetScale(float ScaleX, float ScaleY) | sf::Drawable |
SetScale(const Vector2f &Scale) | sf::Drawable |
SetScaleX(float FactorX) | sf::Drawable |
SetScaleY(float FactorY) | sf::Drawable |
SetX(float X) | sf::Drawable |
SetY(float Y) | sf::Drawable |
Shape() | sf::Shape |
TransformToGlobal(const sf::Vector2f &Point) const | sf::Drawable |
TransformToLocal(const sf::Vector2f &Point) const | sf::Drawable |
~Drawable() | sf::Drawable | [virtual]


sf::SocketHelper

sf::SocketHelper Class Reference

This class defines helper functions to do all the non-portable socket stuff. More...

#include <SocketHelper.hpp>

List of all members.

Public Types

typedef SOCKET | SocketType
typedef int | LengthType

Static Public Member Functions

static SocketType | InvalidSocket ()
Return the value of the invalid socket.
static bool | Close (SocketType Socket)
Close / destroy a socket.
static void | SetBlocking (SocketType Socket, bool Block)
Set a socket as blocking or non-blocking.
static Socket::Status | GetErrorStatus ()
Get the last socket error status.

Detailed Description

This class defines helper functions to do all the non-portable socket stuff.

This class is meant for internal use only

Definition at line 41 of file Win32/SocketHelper.hpp.

Member Function Documentation

bool sf::SocketHelper::Close ( SocketHelper::SocketType Socket ) [static]

Close / destroy a socket.

Parameters:
Socket : Socket to close
Returns:
True on success

Definition at line 45 of file SocketHelper.cpp.

Socket::Status sf::SocketHelper::GetErrorStatus ( ) [static]

Get the last socket error status.

Returns:
Status corresponding to the last socket error

Definition at line 64 of file SocketHelper.cpp.

SocketHelper::SocketType sf::SocketHelper::InvalidSocket ( ) [static]

Return the value of the invalid socket.

Returns:
Unique value of the invalid socket

Definition at line 36 of file SocketHelper.cpp.

void sf::SocketHelper::SetBlocking | ( | SocketHelper::SocketType | Socket,
 |  | bool | Block |
 | ) |  |  | [static]

Set a socket as blocking or non-blocking.

Parameters:
Socket | : Socket to modify
Block | : New blocking state of the socket

Definition at line 54 of file SocketHelper.cpp.

The documentation for this class was generated from the following files:
  • Win32/SocketHelper.hpp
  • SocketHelper.cpp


sf::SocketHelper Member List

This is the complete list of members for sf::SocketHelper, including all inherited members.

Close(SocketType Socket) | sf::SocketHelper | [static]
GetErrorStatus() | sf::SocketHelper | [static]
InvalidSocket() | sf::SocketHelper | [static]
LengthType typedef (defined in sf::SocketHelper) | sf::SocketHelper |
SetBlocking(SocketType Socket, bool Block) | sf::SocketHelper | [static]
SocketType typedef (defined in sf::SocketHelper) | sf::SocketHelper |


sf::SocketTCP

sf::SocketTCP Class Reference

SocketTCP wraps a socket using TCP protocol to send data safely (but a bit slower). More...

#include <SocketTCP.hpp>

List of all members.

Public Member Functions

SocketTCP ()
Default constructor.
void | SetBlocking (bool Blocking)
Change the blocking state of the socket.
Socket::Status | Connect (unsigned short Port, const IPAddress &HostAddress, float Timeout=0.f)
Connect to another computer on a specified port.
bool | Listen (unsigned short Port)
Listen to a specified port for incoming data or connections.
Socket::Status | Accept (SocketTCP &Connected, IPAddress *Address=NULL)
Wait for a connection (must be listening to a port).
Socket::Status | Send (const char *Data, std::size_t Size)
Send an array of bytes to the host (must be connected first).
Socket::Status | Receive (char *Data, std::size_t MaxSize, std::size_t &SizeReceived)
Receive an array of bytes from the host (must be connected first).
Socket::Status | Send (Packet &PacketToSend)
Send a packet of data to the host (must be connected first).
Socket::Status | Receive (Packet &PacketToReceive)
Receive a packet from the host (must be connected first).
bool | Close ()
Close the socket.
bool | IsValid () const
Check if the socket is in a valid state ; this function can be called any time to check if the socket is OK.
bool | operator== (const SocketTCP &Other) const
Comparison operator ==.
bool | operator!= (const SocketTCP &Other) const
Comparison operator !=.
bool | operator< (const SocketTCP &Other) const
Comparison operator <.

Friends

class | Selector< SocketTCP >

Detailed Description

SocketTCP wraps a socket using TCP protocol to send data safely (but a bit slower).

Definition at line 45 of file SocketTCP.hpp.

Constructor & Destructor Documentation

sf::SocketTCP::SocketTCP ( )

Default constructor.

Definition at line 47 of file SocketTCP.cpp.

Member Function Documentation

Socket::Status sf::SocketTCP::Accept | ( | SocketTCP & | Connected,
 |  | IPAddress * | Address = NULL
 | ) |  |

Wait for a connection (must be listening to a port).

This function will block if the socket is blocking

Parameters:
Connected | : Socket containing the connection with the connected client
Address | : Pointer to an address to fill with client infos (NULL by default)
Returns:
Status code
This function will block if the socket is blocking

Definition at line 206 of file SocketTCP.cpp.

bool sf::SocketTCP::Close ( )

Close the socket.

Returns:
True if operation has been successful

Definition at line 406 of file SocketTCP.cpp.

Socket::Status sf::SocketTCP::Connect | ( | unsigned short | Port,
 |  | const IPAddress & | HostAddress,
 |  | float | Timeout = 0.f
 | ) |  |

Connect to another computer on a specified port.

Parameters:
Port | : Port to use for transfers (warning : ports < 1024 are reserved)
HostAddress | : IP Address of the host to connect to
Timeout | : Maximum time to wait, in seconds (0 by default : no timeout) (this parameter is ignored for non-blocking sockets)
Returns:
True if operation has been successful

Definition at line 70 of file SocketTCP.cpp.

bool sf::SocketTCP::IsValid ( ) const

Check if the socket is in a valid state ; this function can be called any time to check if the socket is OK.

Check if the socket is in a valid state ; this function can be called any time to check if the socket is OK.

Returns:
True if the socket is valid

Definition at line 429 of file SocketTCP.cpp.

bool sf::SocketTCP::Listen ( unsigned short Port )

Listen to a specified port for incoming data or connections.

Parameters:
Port : Port to listen to
Returns:
True if operation has been successful

Definition at line 169 of file SocketTCP.cpp.

bool sf::SocketTCP::operator!= ( const SocketTCP & Other ) const

Comparison operator !=.

Parameters:
Other : Socket to compare
Returns:
True if *this != Other

Definition at line 447 of file SocketTCP.cpp.

bool sf::SocketTCP::operator< ( const SocketTCP & Other ) const

Comparison operator <.

Provided for compatibility with standard containers, as comparing two sockets doesn't make much sense...

Parameters:
Other : Socket to compare
Returns:
True if *this < Other
Provided for compatibility with standard containers, as comparing two sockets doesn't make much sense...

Definition at line 458 of file SocketTCP.cpp.

bool sf::SocketTCP::operator== ( const SocketTCP & Other ) const

Comparison operator ==.

Parameters:
Other : Socket to compare
Returns:
True if *this == Other

Definition at line 438 of file SocketTCP.cpp.

Socket::Status sf::SocketTCP::Receive ( Packet & PacketToReceive )

Receive a packet from the host (must be connected first).

This function will block if the socket is blocking

Parameters:
PacketToReceive : Packet to fill with received data
Returns:
Status code
This function will block if the socket is blocking

Definition at line 340 of file SocketTCP.cpp.

Socket::Status sf::SocketTCP::Receive | ( | char * | Data,
 |  | std::size_t | MaxSize,
 |  | std::size_t & | SizeReceived
 | ) |  |

Receive an array of bytes from the host (must be connected first).

This function will block if the socket is blocking

Parameters:
Data | : Pointer to a byte array to fill (make sure it is big enough)
MaxSize | : Maximum number of bytes to read
SizeReceived | : Number of bytes received
Returns:
Status code
This function will block if the socket is blocking

Definition at line 272 of file SocketTCP.cpp.

Socket::Status sf::SocketTCP::Send ( Packet & PacketToSend )

Send a packet of data to the host (must be connected first).

Parameters:
PacketToSend : Packet to send
Returns:
Status code

Definition at line 314 of file SocketTCP.cpp.

Socket::Status sf::SocketTCP::Send | ( | const char * | Data,
 |  | std::size_t | Size
 | ) |  |

Send an array of bytes to the host (must be connected first).

Parameters:
Data | : Pointer to the bytes to send
Size | : Number of bytes to send
Returns:
Status code

Definition at line 235 of file SocketTCP.cpp.

void sf::SocketTCP::SetBlocking ( bool Blocking )

Change the blocking state of the socket.

The default behaviour of a socket is blocking

Parameters:
Blocking : Pass true to set the socket as blocking, or false for non-blocking

Definition at line 56 of file SocketTCP.cpp.

The documentation for this class was generated from the following files:
  • SocketTCP.hpp
  • SocketTCP.cpp


sf::SocketTCP Member List

This is the complete list of members for sf::SocketTCP, including all inherited members.

Accept(SocketTCP &Connected, IPAddress *Address=NULL) | sf::SocketTCP |
Close() | sf::SocketTCP |
Connect(unsigned short Port, const IPAddress &HostAddress, float Timeout=0.f) | sf::SocketTCP |
IsValid() const | sf::SocketTCP |
Listen(unsigned short Port) | sf::SocketTCP |
operator!=(const SocketTCP &Other) const | sf::SocketTCP |
operator<(const SocketTCP &Other) const | sf::SocketTCP |
operator==(const SocketTCP &Other) const | sf::SocketTCP |
Receive(char *Data, std::size_t MaxSize, std::size_t &SizeReceived) | sf::SocketTCP |
Receive(Packet &PacketToReceive) | sf::SocketTCP |
Selector< SocketTCP > (defined in sf::SocketTCP) | sf::SocketTCP | [friend]
Send(const char *Data, std::size_t Size) | sf::SocketTCP |
Send(Packet &PacketToSend) | sf::SocketTCP |
SetBlocking(bool Blocking) | sf::SocketTCP |
SocketTCP() | sf::SocketTCP |


sf::SocketUDP

sf::SocketUDP Class Reference

SocketUDP wraps a socket using UDP protocol to send data fastly (but with less safety). More...

#include <SocketUDP.hpp>

List of all members.

Public Member Functions

SocketUDP ()
Default constructor.
void | SetBlocking (bool Blocking)
Change the blocking state of the socket.
bool | Bind (unsigned short Port)
Bind the socket to a specific port.
bool | Unbind ()
Unbind the socket from its previous port, if any.
Socket::Status | Send (const char *Data, std::size_t Size, const IPAddress &Address, unsigned short Port)
Send an array of bytes.
Socket::Status | Receive (char *Data, std::size_t MaxSize, std::size_t &SizeReceived, IPAddress &Address, unsigned short &Port)
Receive an array of bytes.
Socket::Status | Send (Packet &PacketToSend, const IPAddress &Address, unsigned short Port)
Send a packet of data.
Socket::Status | Receive (Packet &PacketToReceive, IPAddress &Address, unsigned short &Port)
Receive a packet.
bool | Close ()
Close the socket.
bool | IsValid () const
Check if the socket is in a valid state ; this function can be called any time to check if the socket is OK.
unsigned short | GetPort () const
Get the port the socket is currently bound to.
bool | operator== (const SocketUDP &Other) const
Comparison operator ==.
bool | operator!= (const SocketUDP &Other) const
Comparison operator !=.
bool | operator< (const SocketUDP &Other) const
Comparison operator <.

Friends

class | Selector< SocketUDP >

Detailed Description

SocketUDP wraps a socket using UDP protocol to send data fastly (but with less safety).

Definition at line 45 of file SocketUDP.hpp.

Constructor & Destructor Documentation

sf::SocketUDP::SocketUDP ( )

Default constructor.

Definition at line 41 of file SocketUDP.cpp.

Member Function Documentation

bool sf::SocketUDP::Bind ( unsigned short Port )

Bind the socket to a specific port.

Parameters:
Port : Port to bind the socket to
Returns:
True if operation has been successful

Definition at line 64 of file SocketUDP.cpp.

bool sf::SocketUDP::Close ( )

Close the socket.

Returns:
True if operation has been successful

Definition at line 316 of file SocketUDP.cpp.

unsigned short sf::SocketUDP::GetPort ( ) const

Get the port the socket is currently bound to.

Returns:
Current port (0 means the socket is not bound)

Definition at line 349 of file SocketUDP.cpp.

bool sf::SocketUDP::IsValid ( ) const

Check if the socket is in a valid state ; this function can be called any time to check if the socket is OK.

Check if the socket is in a valid state ; this function can be called any time to check if the socket is OK.

Returns:
True if the socket is valid

Definition at line 340 of file SocketUDP.cpp.

bool sf::SocketUDP::operator!= ( const SocketUDP & Other ) const

Comparison operator !=.

Parameters:
Other : Socket to compare
Returns:
True if *this != Other

Definition at line 367 of file SocketUDP.cpp.

bool sf::SocketUDP::operator< ( const SocketUDP & Other ) const

Comparison operator <.

Provided for compatibility with standard containers, as comparing two sockets doesn't make much sense...

Parameters:
Other : Socket to compare
Returns:
True if *this < Other
Provided for compatibility with standard containers, as comparing two sockets doesn't make much sense...

Definition at line 378 of file SocketUDP.cpp.

bool sf::SocketUDP::operator== ( const SocketUDP & Other ) const

Comparison operator ==.

Parameters:
Other : Socket to compare
Returns:
True if *this == Other

Definition at line 358 of file SocketUDP.cpp.

Socket::Status sf::SocketUDP::Receive | ( | Packet & | PacketToReceive,
 |  | IPAddress & | Address,
 |  | unsigned short & | Port
 | ) |  |

Receive a packet.

This function will block if the socket is blocking

Parameters:
PacketToReceive | : Packet to fill with received data
Address | : Address of the computer which sent the packet
Port | : Port on which the remote computer sent the data
Returns:
Status code
This function will block if the socket is blocking

Definition at line 245 of file SocketUDP.cpp.

Socket::Status sf::SocketUDP::Receive | ( | char * | Data,
 |  | std::size_t | MaxSize,
 |  | std::size_t & | SizeReceived,
 |  | IPAddress & | Address,
 |  | unsigned short & | Port
 | ) |  |

Receive an array of bytes.

This function will block if the socket is blocking

Parameters:
Data | : Pointer to a byte array to fill (make sure it is big enough)
MaxSize | : Maximum number of bytes to read
SizeReceived | : Number of bytes received
Address | : Address of the computer which sent the data
Port | : Port on which the remote computer sent the data
Returns:
Status code
This function will block if the socket is blocking

Definition at line 162 of file SocketUDP.cpp.

Socket::Status sf::SocketUDP::Send | ( | Packet & | PacketToSend,
 |  | const IPAddress & | Address,
 |  | unsigned short | Port
 | ) |  |

Send a packet of data.

Parameters:
PacketToSend | : Packet to send
Address | : Address of the computer to send the packet to
Port | : Port to send the data to
Returns:
Status code

Definition at line 219 of file SocketUDP.cpp.

Socket::Status sf::SocketUDP::Send | ( | const char * | Data,
 |  | std::size_t | Size,
 |  | const IPAddress & | Address,
 |  | unsigned short | Port
 | ) |  |

Send an array of bytes.

Parameters:
Data | : Pointer to the bytes to send
Size | : Number of bytes to send
Address | : Address of the computer to send the packet to
Port | : Port to send the data to
Returns:
Status code

Definition at line 118 of file SocketUDP.cpp.

void sf::SocketUDP::SetBlocking ( bool Blocking )

Change the blocking state of the socket.

The default behaviour of a socket is blocking

Parameters:
Blocking : Pass true to set the socket as blocking, or false for non-blocking

Definition at line 50 of file SocketUDP.cpp.

bool sf::SocketUDP::Unbind ( )

Unbind the socket from its previous port, if any.

Unbind the socket to its previous port.

Returns:
True if operation has been successful

Definition at line 101 of file SocketUDP.cpp.

The documentation for this class was generated from the following files:
  • SocketUDP.hpp
  • SocketUDP.cpp


sf::SocketUDP Member List

This is the complete list of members for sf::SocketUDP, including all inherited members.

Bind(unsigned short Port) | sf::SocketUDP |
Close() | sf::SocketUDP |
GetPort() const | sf::SocketUDP |
IsValid() const | sf::SocketUDP |
operator!=(const SocketUDP &Other) const | sf::SocketUDP |
operator<(const SocketUDP &Other) const | sf::SocketUDP |
operator==(const SocketUDP &Other) const | sf::SocketUDP |
Receive(char *Data, std::size_t MaxSize, std::size_t &SizeReceived, IPAddress &Address, unsigned short &Port) | sf::SocketUDP |
Receive(Packet &PacketToReceive, IPAddress &Address, unsigned short &Port) | sf::SocketUDP |
Selector< SocketUDP > (defined in sf::SocketUDP) | sf::SocketUDP | [friend]
Send(const char *Data, std::size_t Size, const IPAddress &Address, unsigned short Port) | sf::SocketUDP |
Send(Packet &PacketToSend, const IPAddress &Address, unsigned short Port) | sf::SocketUDP |
SetBlocking(bool Blocking) | sf::SocketUDP |
SocketUDP() | sf::SocketUDP |
Unbind() | sf::SocketUDP |


sf::Sound

sf::Sound Class Reference

Sound defines the properties of a sound such as position, volume, pitch, etc. More...

#include <Sound.hpp>

Inheritance diagram for sf::Sound:

sf::AudioResource sf::SoundStream sf::Music

List of all members.

Public Types

enum Status {
Stopped,
Paused,
Playing
}
Enumeration of the sound states. More...

Public Member Functions

Sound ()
Default constructor.
Sound (const SoundBuffer &Buffer, bool Loop=false, float Pitch=1.f, float Volume=100.f, const Vector3f &Position=Vector3f(0, 0, 0))
Construct the sound from its parameters.
Sound (const Sound &Copy)
Copy constructor.
~Sound ()
Destructor.
void | Play ()
Play the sound.
void | Pause ()
Pause the sound.
void | Stop ()
Stop the sound.
void | SetBuffer (const SoundBuffer &Buffer)
Set the source buffer.
void | SetLoop (bool Loop)
Set the sound loop state.
void | SetPitch (float Pitch)
Set the sound pitch.
void | SetVolume (float Volume)
Set the sound volume.
void | SetPosition (float X, float Y, float Z)
Set the sound position (take 3 values).
void | SetPosition (const Vector3f &Position)
Set the sound position (take a 3D vector).
void | SetRelativeToListener (bool Relative)
Make the sound's position relative to the listener's position, or absolute.
void | SetMinDistance (float MinDistance)
Set the minimum distance - closer than this distance, the listener will hear the sound at its maximum volume.
void | SetAttenuation (float Attenuation)
Set the attenuation factor - the higher the attenuation, the more the sound will be attenuated with distance from listener.
void | SetPlayingOffset (float TimeOffset)
Set the current playing position of the sound.
const SoundBuffer * | GetBuffer () const
Get the source buffer.
bool | GetLoop () const
Tell whether or not the sound is looping.
float | GetPitch () const
Get the pitch.
float | GetVolume () const
Get the volume.
Vector3f | GetPosition () const
Get the sound position.
bool | IsRelativeToListener () const
Tell if the sound's position is relative to the listener's position, or if it's absolute.
float | GetMinDistance () const
Get the minimum distance.
float | GetAttenuation () const
Get the attenuation factor.
Status | GetStatus () const
Get the status of the sound (stopped, paused, playing).
float | GetPlayingOffset () const
Get the current playing position of the sound.
Sound & | operator= (const Sound &Other)
Assignment operator.
void | ResetBuffer ()
Reset the internal buffer.

Friends

class | SoundStream

Detailed Description

Sound defines the properties of a sound such as position, volume, pitch, etc.

Definition at line 45 of file Sound.hpp.

Member Enumeration Documentation

enum sf::Sound::Status

Enumeration of the sound states.

Enumerator:
Stopped | Sound is not playing.
Paused | Sound is paused.
Playing | Sound is playing.

Definition at line 52 of file Sound.hpp.

Constructor & Destructor Documentation

sf::Sound::Sound ( )

Default constructor.

Definition at line 38 of file Sound.cpp.

sf::Sound::Sound | ( | const SoundBuffer & | Buffer,
 |  | bool | Loop = false,
 |  | float | Pitch = 1.f,
 |  | float | Volume = 100.f,
 |  | const Vector3f & | Position = Vector3f(0, 0, 0) |
 | ) |  |  | [explicit]

Construct the sound from its parameters.

Parameters:
Buffer | : Sound buffer to play (NULL by default)
Loop | : Loop flag (false by default)
Pitch | : Value of the pitch (1 by default)
Volume | : Volume (100 by default)
Position | : Position (0, 0, 0 by default)

Definition at line 48 of file Sound.cpp.

sf::Sound::Sound ( const Sound & Copy )

Copy constructor.

Parameters:
Copy : Instance to copy

Definition at line 64 of file Sound.cpp.

sf::Sound::~Sound ( )

Destructor.

Definition at line 85 of file Sound.cpp.

Member Function Documentation

float sf::Sound::GetAttenuation ( ) const

Get the attenuation factor.

Returns:
Attenuation factor of the sound

Definition at line 319 of file Sound.cpp.

const SoundBuffer * sf::Sound::GetBuffer ( ) const

Get the source buffer.

Returns:
Sound buffer bound to the sound (can be NULL)

Definition at line 237 of file Sound.cpp.

bool sf::Sound::GetLoop ( ) const

Tell whether or not the sound is looping.

Returns:
True if the sound is looping, false otherwise

Reimplemented in sf::SoundStream.

Definition at line 246 of file Sound.cpp.

float sf::Sound::GetMinDistance ( ) const

Get the minimum distance.

Returns:
Minimum distance for the sound

Definition at line 307 of file Sound.cpp.

float sf::Sound::GetPitch ( ) const

Get the pitch.

Returns:
Pitch value

Definition at line 258 of file Sound.cpp.

float sf::Sound::GetPlayingOffset ( ) const

Get the current playing position of the sound.

Returns:
Current playing position, expressed in seconds

Reimplemented in sf::SoundStream.

Definition at line 331 of file Sound.cpp.

Vector3f sf::Sound::GetPosition ( ) const

Get the sound position.

Returns:
Position of the sound in the world

Definition at line 282 of file Sound.cpp.

Sound::Status sf::Sound::GetStatus ( ) const

Get the status of the sound (stopped, paused, playing).

Returns:
Current status of the sound

Reimplemented in sf::SoundStream.

Definition at line 343 of file Sound.cpp.

float sf::Sound::GetVolume ( ) const

Get the volume.

Returns:
Volume value (in range [1, 100])

Definition at line 270 of file Sound.cpp.

bool sf::Sound::IsRelativeToListener ( ) const

Tell if the sound's position is relative to the listener's position, or if it's absolute.

Tell if the sound's position is relative to the listener's position, or if it's absolute.

Returns:
True if the position is relative, false if it's absolute

Definition at line 295 of file Sound.cpp.

Sound & sf::Sound::operator= ( const Sound & Other )

Assignment operator.

Parameters:
Other : Instance to assign
Returns:
Reference to the sound

Definition at line 363 of file Sound.cpp.

void sf::Sound::Pause ( )

Pause the sound.

Definition at line 112 of file Sound.cpp.

void sf::Sound::Play ( )

Play the sound.

Reimplemented in sf::SoundStream.

Definition at line 103 of file Sound.cpp.

void sf::Sound::ResetBuffer ( )

Reset the internal buffer.

This function is for internal use only, you don't have to use it.

Definition at line 394 of file Sound.cpp.

void sf::Sound::SetAttenuation ( float Attenuation )

Set the attenuation factor - the higher the attenuation, the more the sound will be attenuated with distance from listener.

Set the attenuation factor - the higher the attenuation, the more the sound will be attenuated with distance from listener.

The default attenuation factor 1.0

Parameters:
Attenuation : New attenuation factor for the sound
The default attenuation factor 1.0

Definition at line 219 of file Sound.cpp.

void sf::Sound::SetBuffer ( const SoundBuffer & Buffer )

Set the source buffer.

Parameters:
Buffer : New sound buffer to bind to the sound

Definition at line 130 of file Sound.cpp.

void sf::Sound::SetLoop ( bool Loop )

Set the sound loop state.

This parameter is disabled by default

Parameters:
Loop : True to play in loop, false to play once

Reimplemented in sf::SoundStream.

Definition at line 149 of file Sound.cpp.

void sf::Sound::SetMinDistance ( float MinDistance )

Set the minimum distance - closer than this distance, the listener will hear the sound at its maximum volume.

Set the minimum distance - closer than this distance, the listener will hear the sound at its maximum volume.

The default minimum distance is 1.0

Parameters:
MinDistance : New minimum distance for the sound
The default minimum distance is 1.0

Definition at line 208 of file Sound.cpp.

void sf::Sound::SetPitch ( float Pitch )

Set the sound pitch.

The default pitch is 1

Parameters:
Pitch : New pitch

Definition at line 158 of file Sound.cpp.

void sf::Sound::SetPlayingOffset ( float TimeOffset )

Set the current playing position of the sound.

Parameters:
TimeOffset : New playing position, expressed in seconds

Definition at line 228 of file Sound.cpp.

void sf::Sound::SetPosition ( const Vector3f & Position )

Set the sound position (take a 3D vector).

The default position is (0, 0, 0)

Parameters:
Position : Position of the sound in the world
The default position is (0, 0, 0)

Definition at line 186 of file Sound.cpp.

void sf::Sound::SetPosition | ( | float | X,
 |  | float | Y,
 |  | float | Z
 | ) |  |

Set the sound position (take 3 values).

The default position is (0, 0, 0)

Parameters:
X,Y,Z : Position of the sound in the world
The default position is (0, 0, 0)

Definition at line 176 of file Sound.cpp.

void sf::Sound::SetRelativeToListener ( bool Relative )

Make the sound's position relative to the listener's position, or absolute.

Make the sound's position relative to the listener's position, or absolute.

The default value is false (absolute)

Parameters:
Relative : True to set the position relative, false to set it absolute
The default value is false (absolute)

Definition at line 197 of file Sound.cpp.

void sf::Sound::SetVolume ( float Volume )

Set the sound volume.

The default volume is 100

Parameters:
Volume : Volume (in range [0, 100])

Definition at line 167 of file Sound.cpp.

void sf::Sound::Stop ( )

Stop the sound.

Reimplemented in sf::SoundStream.

Definition at line 121 of file Sound.cpp.

The documentation for this class was generated from the following files:
  • Sound.hpp
  • Sound.cpp


sf::Sound Member List

This is the complete list of members for sf::Sound, including all inherited members.

AudioResource() | sf::AudioResource | [protected]
AudioResource(const AudioResource &) | sf::AudioResource | [protected]
GetAttenuation() const | sf::Sound |
GetBuffer() const | sf::Sound |
GetLoop() const | sf::Sound |
GetMinDistance() const | sf::Sound |
GetPitch() const | sf::Sound |
GetPlayingOffset() const | sf::Sound |
GetPosition() const | sf::Sound |
GetStatus() const | sf::Sound |
GetVolume() const | sf::Sound |
IsRelativeToListener() const | sf::Sound |
operator=(const Sound &Other) | sf::Sound |
Pause() | sf::Sound |
Paused enum value | sf::Sound |
Play() | sf::Sound |
Playing enum value | sf::Sound |
ResetBuffer() | sf::Sound |
SetAttenuation(float Attenuation) | sf::Sound |
SetBuffer(const SoundBuffer &Buffer) | sf::Sound |
SetLoop(bool Loop) | sf::Sound |
SetMinDistance(float MinDistance) | sf::Sound |
SetPitch(float Pitch) | sf::Sound |
SetPlayingOffset(float TimeOffset) | sf::Sound |
SetPosition(float X, float Y, float Z) | sf::Sound |
SetPosition(const Vector3f &Position) | sf::Sound |
SetRelativeToListener(bool Relative) | sf::Sound |
SetVolume(float Volume) | sf::Sound |
Sound() | sf::Sound |
Sound(const SoundBuffer &Buffer, bool Loop=false, float Pitch=1.f, float Volume=100.f, const Vector3f &Position=Vector3f(0, 0, 0)) | sf::Sound | [explicit]
Sound(const Sound &Copy) | sf::Sound |
SoundStream (defined in sf::Sound) | sf::Sound | [friend]
Status enum name | sf::Sound |
Stop() | sf::Sound |
Stopped enum value | sf::Sound |
~AudioResource() | sf::AudioResource | [protected, virtual]
~Sound() | sf::Sound |


sf::SoundBuffer

sf::SoundBuffer Class Reference

SoundBuffer is the low-level for loading and manipulating sound buffers. More...

#include <SoundBuffer.hpp>

Inheritance diagram for sf::SoundBuffer:

sf::AudioResource sf::Resource< SoundBuffer >

List of all members.

Public Member Functions

SoundBuffer ()
Default constructor.
SoundBuffer (const SoundBuffer &Copy)
Copy constructor.
~SoundBuffer ()
Destructor.
bool | LoadFromFile (const std::string &Filename)
Load the sound buffer from a file.
bool | LoadFromMemory (const char *Data, std::size_t SizeInBytes)
Load the sound buffer from a file in memory.
bool | LoadFromSamples (const Int16 *Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate)
Load the sound buffer from an array of samples - assumed format for samples is 16 bits signed integer.
bool | SaveToFile (const std::string &Filename) const
Save the sound buffer to a file.
const Int16 * | GetSamples () const
Return the sound samples.
std::size_t | GetSamplesCount () const
Return the samples count.
unsigned int | GetSampleRate () const
Get the sample rate.
unsigned int | GetChannelsCount () const
Return the number of channels (1 = mono, 2 = stereo, .
float | GetDuration () const
Get the sound duration.
SoundBuffer & | operator= (const SoundBuffer &Other)
Assignment operator.

Friends

class | Sound

Detailed Description

SoundBuffer is the low-level for loading and manipulating sound buffers.

Definition at line 46 of file SoundBuffer.hpp.

Constructor & Destructor Documentation

sf::SoundBuffer::SoundBuffer ( )

Default constructor.

Definition at line 42 of file SoundBuffer.cpp.

sf::SoundBuffer::SoundBuffer ( const SoundBuffer & Copy )

Copy constructor.

Parameters:
Copy : Instance to copy

Definition at line 54 of file SoundBuffer.cpp.

sf::SoundBuffer::~SoundBuffer ( )

Destructor.

Definition at line 73 of file SoundBuffer.cpp.

Member Function Documentation

unsigned int sf::SoundBuffer::GetChannelsCount ( ) const

Return the number of channels (1 = mono, 2 = stereo, .

..)

Returns:
Number of channels
..)

Definition at line 253 of file SoundBuffer.cpp.

float sf::SoundBuffer::GetDuration ( ) const

Get the sound duration.

Returns:
Sound duration, in seconds

Definition at line 265 of file SoundBuffer.cpp.

unsigned int sf::SoundBuffer::GetSampleRate ( ) const

Get the sample rate.

Returns:
Sound frequency (number of samples per second)

Definition at line 241 of file SoundBuffer.cpp.

const Int16 * sf::SoundBuffer::GetSamples ( ) const

Return the sound samples.

Returns:
Pointer to the array of sound samples, in 16 bits signed integer format

Definition at line 223 of file SoundBuffer.cpp.

std::size_t sf::SoundBuffer::GetSamplesCount ( ) const

Return the samples count.

Returns:
Number of samples

Definition at line 232 of file SoundBuffer.cpp.

bool sf::SoundBuffer::LoadFromFile ( const std::string & Filename )

Load the sound buffer from a file.

Parameters:
Filename : Path of the sound file to load
Returns:
True if loading has been successful

Definition at line 88 of file SoundBuffer.cpp.

bool sf::SoundBuffer::LoadFromMemory | ( | const char * | Data,
 |  | std::size_t | SizeInBytes
 | ) |  |

Load the sound buffer from a file in memory.

Parameters:
Data | : Pointer to the file data in memory
SizeInBytes | : Size of the data to load, in bytes
Returns:
True if loading has been successful

Definition at line 129 of file SoundBuffer.cpp.

bool sf::SoundBuffer::LoadFromSamples | ( | const Int16 * | Samples,
 |  | std::size_t | SamplesCount,
 |  | unsigned int | ChannelsCount,
 |  | unsigned int | SampleRate
 | ) |  |

Load the sound buffer from an array of samples - assumed format for samples is 16 bits signed integer.

Load the sound buffer from an array of samples - assumed format for samples is 16 bits signed integer.

Parameters:
Samples | : Pointer to the samples in memory
SamplesCount | : Number of samples pointed by Samples
ChannelsCount | : Number of channels (1 = mono, 2 = stereo, ...)
SampleRate | : Frequency (number of samples to play per second)
Returns:
True if loading has been successful

Definition at line 171 of file SoundBuffer.cpp.

SoundBuffer & sf::SoundBuffer::operator= ( const SoundBuffer & Other )

Assignment operator.

Parameters:
Other : Instance to assign
Returns:
Reference to the sound buffer

Definition at line 274 of file SoundBuffer.cpp.

bool sf::SoundBuffer::SaveToFile ( const std::string & Filename ) const

Save the sound buffer to a file.

Parameters:
Filename : Path of the sound file to write
Returns:
True if saving has been successful

Definition at line 199 of file SoundBuffer.cpp.

The documentation for this class was generated from the following files:
  • SoundBuffer.hpp
  • SoundBuffer.cpp


sf::SoundBuffer Member List

This is the complete list of members for sf::SoundBuffer, including all inherited members.

AudioResource() | sf::AudioResource | [protected]
AudioResource(const AudioResource &) | sf::AudioResource | [protected]
GetChannelsCount() const | sf::SoundBuffer |
GetDuration() const | sf::SoundBuffer |
GetSampleRate() const | sf::SoundBuffer |
GetSamples() const | sf::SoundBuffer |
GetSamplesCount() const | sf::SoundBuffer |
LoadFromFile(const std::string &Filename) | sf::SoundBuffer |
LoadFromMemory(const char *Data, std::size_t SizeInBytes) | sf::SoundBuffer |
LoadFromSamples(const Int16 *Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate) | sf::SoundBuffer |
operator=(const SoundBuffer &Other) | sf::SoundBuffer |
Resource< SoundBuffer >::operator=(const Resource< SoundBuffer > &Other) | sf::Resource< SoundBuffer > | [protected]
Resource() | sf::Resource< SoundBuffer > | [protected]
Resource(const Resource< SoundBuffer > &Copy) | sf::Resource< SoundBuffer > | [protected]
SaveToFile(const std::string &Filename) const | sf::SoundBuffer |
Sound (defined in sf::SoundBuffer) | sf::SoundBuffer | [friend]
SoundBuffer() | sf::SoundBuffer |
SoundBuffer(const SoundBuffer &Copy) | sf::SoundBuffer |
~AudioResource() | sf::AudioResource | [protected, virtual]
~Resource() | sf::Resource< SoundBuffer > | [protected]
~SoundBuffer() | sf::SoundBuffer |


sf::SoundBufferRecorder

sf::SoundBufferRecorder Class Reference

Specialized SoundRecorder which saves the captured audio data into a sound buffer. More...

#include <SoundBufferRecorder.hpp>

Inheritance diagram for sf::SoundBufferRecorder:

sf::SoundRecorder sf::Thread

List of all members.

Public Member Functions

const SoundBuffer & | GetBuffer () const
Get the sound buffer containing the captured audio data.
void | Start (unsigned int SampleRate=44100)
Start the capture.
void | Stop ()
Stop the capture.
unsigned int | GetSampleRate () const
Get the sample rate.

Static Public Member Functions

static bool | CanCapture ()
Tell if the system supports sound capture.

Detailed Description

Specialized SoundRecorder which saves the captured audio data into a sound buffer.

Definition at line 42 of file SoundBufferRecorder.hpp.

Member Function Documentation

bool sf::SoundRecorder::CanCapture ( ) [static, inherited]

Tell if the system supports sound capture.

If not, this class won't be usable

Returns:
True if audio capture is supported
If not, this class won't be usable

Definition at line 136 of file SoundRecorder.cpp.

const SoundBuffer & sf::SoundBufferRecorder::GetBuffer ( ) const

Get the sound buffer containing the captured audio data.

Returns:
Constant reference to the sound buffer

Definition at line 70 of file SoundBufferRecorder.cpp.

unsigned int sf::SoundRecorder::GetSampleRate ( ) const [inherited]

Get the sample rate.

Returns:
Frequency, in samples per second

Definition at line 126 of file SoundRecorder.cpp.

void sf::SoundRecorder::Start ( unsigned int SampleRate = 44100 ) [inherited]

Start the capture.

Warning : only one capture can happen at the same time

Parameters:
SampleRate : Sound frequency (the more samples, the higher the quality) (44100 by default = CD quality)
Warning : only one capture can happen at the same time

Definition at line 69 of file SoundRecorder.cpp.

void sf::SoundRecorder::Stop ( ) [inherited]

Stop the capture.

Definition at line 115 of file SoundRecorder.cpp.

The documentation for this class was generated from the following files:
  • SoundBufferRecorder.hpp
  • SoundBufferRecorder.cpp


sf::SoundBufferRecorder Member List

This is the complete list of members for sf::SoundBufferRecorder, including all inherited members.

CanCapture() | sf::SoundRecorder | [static]
GetBuffer() const | sf::SoundBufferRecorder |
GetSampleRate() const | sf::SoundRecorder |
SoundRecorder() | sf::SoundRecorder | [protected]
Start(unsigned int SampleRate=44100) | sf::SoundRecorder |
Stop() | sf::SoundRecorder |
~SoundRecorder() | sf::SoundRecorder | [virtual]


sf::SoundRecorder

sf::SoundRecorder Class Reference

SoundRecorder is an interface for capturing sound data, it is meant to be used as a base class. More...

#include <SoundRecorder.hpp>

Inheritance diagram for sf::SoundRecorder:

sf::Thread sf::SoundBufferRecorder

List of all members.

Public Member Functions

virtual | ~SoundRecorder ()
Virtual destructor.
void | Start (unsigned int SampleRate=44100)
Start the capture.
void | Stop ()
Stop the capture.
unsigned int | GetSampleRate () const
Get the sample rate.

Static Public Member Functions

static bool | CanCapture ()
Tell if the system supports sound capture.

Protected Member Functions

SoundRecorder ()
Default constructor.

Private Types

typedef void(* | FuncType )(void *)

Private Member Functions

void | Launch ()
Create and run the thread.
void | Wait ()
Wait until the thread finishes.
void | Terminate ()
Terminate the thread Terminating a thread with this function is not safe, you should rather try to make the thread function terminate by itself.

Detailed Description

SoundRecorder is an interface for capturing sound data, it is meant to be used as a base class.

Definition at line 41 of file SoundRecorder.hpp.

Constructor & Destructor Documentation

sf::SoundRecorder::~SoundRecorder ( ) [virtual]

Virtual destructor.

Definition at line 59 of file SoundRecorder.cpp.

sf::SoundRecorder::SoundRecorder ( ) [protected]

Default constructor.

Definition at line 48 of file SoundRecorder.cpp.

Member Function Documentation

bool sf::SoundRecorder::CanCapture ( ) [static]

Tell if the system supports sound capture.

If not, this class won't be usable

Returns:
True if audio capture is supported
If not, this class won't be usable

Definition at line 136 of file SoundRecorder.cpp.

unsigned int sf::SoundRecorder::GetSampleRate ( ) const

Get the sample rate.

Returns:
Frequency, in samples per second

Definition at line 126 of file SoundRecorder.cpp.

void sf::SoundRecorder::Start ( unsigned int SampleRate = 44100 )

Start the capture.

Warning : only one capture can happen at the same time

Parameters:
SampleRate : Sound frequency (the more samples, the higher the quality) (44100 by default = CD quality)
Warning : only one capture can happen at the same time

Definition at line 69 of file SoundRecorder.cpp.

void sf::SoundRecorder::Stop ( )

Stop the capture.

Definition at line 115 of file SoundRecorder.cpp.

The documentation for this class was generated from the following files:
  • SoundRecorder.hpp
  • SoundRecorder.cpp


sf::SoundRecorder Member List

This is the complete list of members for sf::SoundRecorder, including all inherited members.

CanCapture() | sf::SoundRecorder | [static]
FuncType typedef (defined in sf::Thread) | sf::Thread | [private]
GetSampleRate() const | sf::SoundRecorder |
Launch() | sf::Thread | [private]
SoundRecorder() | sf::SoundRecorder | [protected]
Start(unsigned int SampleRate=44100) | sf::SoundRecorder |
Stop() | sf::SoundRecorder |
Terminate() | sf::Thread | [private]
Thread(FuncType Function, void *UserData=NULL) | sf::Thread | [private]
Thread() | sf::Thread | [private]
Wait() | sf::Thread | [private]
~SoundRecorder() | sf::SoundRecorder | [virtual]
~Thread() | sf::Thread | [private, virtual]


sf::SoundStream

sf::SoundStream Class Reference

SoundStream is a streamed sound, ie samples are acquired while the sound is playing. More...

#include <SoundStream.hpp>

Inheritance diagram for sf::SoundStream:

sf::Thread sf::Sound sf::Music

List of all members.

Classes

struct | Chunk
Structure defining a chunk of audio data to stream. More...

Public Types

enum | Status
Enumeration of the sound states. More...

Public Member Functions

virtual | ~SoundStream ()
Virtual destructor.
void | Play ()
Start playing the audio stream.
void | Stop ()
Stop playing the audio stream.
unsigned int | GetChannelsCount () const
Return the number of channels (1 = mono, 2 = stereo).
unsigned int | GetSampleRate () const
Get the stream sample rate.
Status | GetStatus () const
Get the status of the stream (stopped, paused, playing).
float | GetPlayingOffset () const
Get the current playing position of the stream.
void | SetLoop (bool Loop)
Set the stream loop state.
bool | GetLoop () const
Tell whether or not the stream is looping.

Protected Member Functions

SoundStream ()
Default constructor.
void | Initialize (unsigned int ChannelsCount, unsigned int SampleRate)
Set the audio stream parameters, you must call it before Play().

Private Types

typedef void(* | FuncType )(void *)

Private Member Functions

void | Launch ()
Create and run the thread.
void | Wait ()
Wait until the thread finishes.
void | Terminate ()
Terminate the thread Terminating a thread with this function is not safe, you should rather try to make the thread function terminate by itself.
void | Pause ()
Pause the sound.
void | SetBuffer (const SoundBuffer &Buffer)
Set the source buffer.
void | SetPitch (float Pitch)
Set the sound pitch.
void | SetVolume (float Volume)
Set the sound volume.
void | SetPosition (float X, float Y, float Z)
Set the sound position (take 3 values).
void | SetPosition (const Vector3f &Position)
Set the sound position (take a 3D vector).
void | SetRelativeToListener (bool Relative)
Make the sound's position relative to the listener's position, or absolute.
void | SetMinDistance (float MinDistance)
Set the minimum distance - closer than this distance, the listener will hear the sound at its maximum volume.
void | SetAttenuation (float Attenuation)
Set the attenuation factor - the higher the attenuation, the more the sound will be attenuated with distance from listener.
void | SetPlayingOffset (float TimeOffset)
Set the current playing position of the sound.
const SoundBuffer * | GetBuffer () const
Get the source buffer.
float | GetPitch () const
Get the pitch.
float | GetVolume () const
Get the volume.
Vector3f | GetPosition () const
Get the sound position.
bool | IsRelativeToListener () const
Tell if the sound's position is relative to the listener's position, or if it's absolute.
float | GetMinDistance () const
Get the minimum distance.
float | GetAttenuation () const
Get the attenuation factor.
void | ResetBuffer ()
Reset the internal buffer.

Detailed Description

SoundStream is a streamed sound, ie samples are acquired while the sound is playing.

Use it for big sounds that would require hundreds of MB in memory (see Music), or for streaming sound from the network

Definition at line 44 of file SoundStream.hpp.

Member Enumeration Documentation

enum sf::Sound::Status

Enumeration of the sound states.

Definition at line 52 of file Sound.hpp.

Constructor & Destructor Documentation

sf::SoundStream::~SoundStream ( ) [virtual]

Virtual destructor.

Definition at line 54 of file SoundStream.cpp.

sf::SoundStream::SoundStream ( ) [protected]

Default constructor.

Definition at line 39 of file SoundStream.cpp.

Member Function Documentation

unsigned int sf::SoundStream::GetChannelsCount ( ) const

Return the number of channels (1 = mono, 2 = stereo).

Return the number of channels (1 = mono, 2 = stereo, .

Returns:
Number of channels
..)

Definition at line 126 of file SoundStream.cpp.

bool sf::SoundStream::GetLoop ( ) const

Tell whether or not the stream is looping.

Tell whether or not the music is looping.

Returns:
True if the music is looping, false otherwise

Reimplemented from sf::Sound.

Definition at line 180 of file SoundStream.cpp.

float sf::SoundStream::GetPlayingOffset ( ) const

Get the current playing position of the stream.

Returns:
Current playing position, expressed in seconds

Current playing position, expressed in seconds

Reimplemented from sf::Sound.

Definition at line 162 of file SoundStream.cpp.

unsigned int sf::SoundStream::GetSampleRate ( ) const

Get the stream sample rate.

Get the sound frequency (sample rate).

Returns:
Stream frequency (number of samples per second)

Definition at line 135 of file SoundStream.cpp.

Sound::Status sf::SoundStream::GetStatus ( ) const

Get the status of the stream (stopped, paused, playing).

Get the status of the sound (stopped, paused, playing).

Returns:
Current status of the sound

Reimplemented from sf::Sound.

Definition at line 144 of file SoundStream.cpp.

void sf::SoundStream::Initialize | ( | unsigned int | ChannelsCount,
 |  | unsigned int | SampleRate |
 | ) |  |  | [protected]

Set the audio stream parameters, you must call it before Play().

Parameters:
ChannelsCount | : Number of channels
SampleRate | : Sample rate

Definition at line 64 of file SoundStream.cpp.

void sf::SoundStream::Play ( )

Start playing the audio stream.

Reimplemented from sf::Sound.

Definition at line 85 of file SoundStream.cpp.

void sf::SoundStream::SetLoop ( bool Loop )

Set the stream loop state.

Set the music loop state.

This parameter is disabled by default

Parameters:
Loop : True to play in loop, false to play once

Reimplemented from sf::Sound.

Definition at line 171 of file SoundStream.cpp.

void sf::SoundStream::Stop ( )

Stop playing the audio stream.

Reimplemented from sf::Sound.

Definition at line 115 of file SoundStream.cpp.

The documentation for this class was generated from the following files:
  • SoundStream.hpp
  • SoundStream.cpp


sf::SoundStream Member List

This is the complete list of members for sf::SoundStream, including all inherited members.

AudioResource() | sf::AudioResource | [private]
AudioResource(const AudioResource &) | sf::AudioResource | [private]
FuncType typedef (defined in sf::Thread) | sf::Thread | [private]
GetAttenuation() const | sf::Sound | [private]
GetBuffer() const | sf::Sound | [private]
GetChannelsCount() const | sf::SoundStream |
GetLoop() const | sf::SoundStream |
GetMinDistance() const | sf::Sound | [private]
GetPitch() const | sf::Sound | [private]
GetPlayingOffset() const | sf::SoundStream |
GetPosition() const | sf::Sound | [private]
GetSampleRate() const | sf::SoundStream |
GetStatus() const | sf::SoundStream |
GetVolume() const | sf::Sound | [private]
Initialize(unsigned int ChannelsCount, unsigned int SampleRate) | sf::SoundStream | [protected]
IsRelativeToListener() const | sf::Sound | [private]
Launch() | sf::Thread | [private]
operator=(const Sound &Other) | sf::Sound | [private]
Pause() | sf::Sound | [private]
Paused enum value | sf::Sound | [private]
Play() | sf::SoundStream |
Playing enum value | sf::Sound | [private]
ResetBuffer() | sf::Sound | [private]
SetAttenuation(float Attenuation) | sf::Sound | [private]
SetBuffer(const SoundBuffer &Buffer) | sf::Sound | [private]
SetLoop(bool Loop) | sf::SoundStream |
SetMinDistance(float MinDistance) | sf::Sound | [private]
SetPitch(float Pitch) | sf::Sound | [private]
SetPlayingOffset(float TimeOffset) | sf::Sound | [private]
SetPosition(float X, float Y, float Z) | sf::Sound | [private]
SetPosition(const Vector3f &Position) | sf::Sound | [private]
SetRelativeToListener(bool Relative) | sf::Sound | [private]
SetVolume(float Volume) | sf::Sound | [private]
Sound() | sf::Sound | [private]
Sound(const SoundBuffer &Buffer, bool Loop=false, float Pitch=1.f, float Volume=100.f, const Vector3f &Position=Vector3f(0, 0, 0)) | sf::Sound | [explicit, private]
Sound(const Sound &Copy) | sf::Sound | [private]
SoundStream() | sf::SoundStream | [protected]
Status enum name | sf::SoundStream |
Stop() | sf::SoundStream |
Stopped enum value | sf::Sound | [private]
Terminate() | sf::Thread | [private]
Thread(FuncType Function, void *UserData=NULL) | sf::Thread | [private]
Thread() | sf::Thread | [private]
Wait() | sf::Thread | [private]
~AudioResource() | sf::AudioResource | [private, virtual]
~Sound() | sf::Sound | [private]
~SoundStream() | sf::SoundStream | [virtual]
~Thread() | sf::Thread | [private, virtual]


sf::SoundStream::Chunk

sf::SoundStream::SoundStream::Chunk Struct Reference

Structure defining a chunk of audio data to stream. More...

#include <SoundStream.hpp>

List of all members.

Public Attributes

const Int16 * | Samples
Pointer to the audio samples.
std::size_t | NbSamples
Number of samples pointed by Samples.

Detailed Description

Structure defining a chunk of audio data to stream.

Definition at line 69 of file SoundStream.hpp.

Member Data Documentation

std::size_t sf::SoundStream::SoundStream::Chunk::NbSamples

Number of samples pointed by Samples.

Definition at line 72 of file SoundStream.hpp.

const Int16* sf::SoundStream::SoundStream::Chunk::Samples

Pointer to the audio samples.

Definition at line 71 of file SoundStream.hpp.

The documentation for this struct was generated from the following file:
  • SoundStream.hpp


sf::SoundStream::SoundStream::Chunk Member List

This is the complete list of members for sf::SoundStream::SoundStream::Chunk, including all inherited members.

NbSamples | sf::SoundStream::SoundStream::Chunk
Samples | sf::SoundStream::SoundStream::Chunk


sf::Sprite

sf::Sprite Class Reference

Sprite defines a sprite : texture, transformations, color, and draw on screen. More...

#include <Sprite.hpp>

Inheritance diagram for sf::Sprite:

sf::Drawable

List of all members.

Public Member Functions

Sprite ()
Default constructor.
Sprite (const Image &Img, const Vector2f &Position=Vector2f(0, 0), const Vector2f &Scale=Vector2f(1, 1), float Rotation=0.f, const Color &Col=Color(255, 255, 255, 255))
Construct the sprite from a source image.
void | SetImage (const Image &Img)
Change the image of the sprite.
void | SetSubRect (const IntRect &SubRect)
Set the sub-rectangle of the sprite inside the source image.
void | Resize (float Width, float Height)
Resize the sprite (by changing its scale factors) (take 2 values).
void | Resize (const Vector2f &Size)
Resize the sprite (by changing its scale factors) (take a 2D vector).
void | FlipX (bool Flipped)
Flip the sprite horizontally.
void | FlipY (bool Flipped)
Flip the sprite vertically.
const Image * | GetImage () const
Get the source image of the sprite.
const IntRect & | GetSubRect () const
Get the sub-rectangle of the sprite inside the source image.
Vector2f | GetSize () const
Get the sprite size.
Color | GetPixel (unsigned int X, unsigned int Y) const
Get the color of a given pixel in the sprite (point is in local coordinates).
void | SetPosition (float X, float Y)
Set the position of the object (take 2 values).
void | SetPosition (const Vector2f &Position)
Set the position of the object (take a 2D vector).
void | SetX (float X)
Set the X position of the object.
void | SetY (float Y)
Set the Y position of the object.
void | SetScale (float ScaleX, float ScaleY)
Set the scale of the object (take 2 values).
void | SetScale (const Vector2f &Scale)
Set the scale of the object (take a 2D vector).
void | SetScaleX (float FactorX)
Set the X scale factor of the object.
void | SetScaleY (float FactorY)
Set the Y scale factor of the object.
void | SetCenter (float CenterX, float CenterY)
Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).
void | SetCenter (const Vector2f &Center)
Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).
void | SetRotation (float Rotation)
Set the orientation of the object.
void | SetColor (const Color &Col)
Set the color of the object.
void | SetBlendMode (Blend::Mode Mode)
Set the blending mode for the object.
const Vector2f & | GetPosition () const
Get the position of the object.
const Vector2f & | GetScale () const
Get the current scale of the object.
const Vector2f & | GetCenter () const
Get the center of the object.
float | GetRotation () const
Get the orientation of the object.
const Color & | GetColor () const
Get the color of the object.
Blend::Mode | GetBlendMode () const
Get the current blending mode.
void | Move (float OffsetX, float OffsetY)
Move the object of a given offset (take 2 values).
void | Move (const Vector2f &Offset)
Move the object of a given offset (take a 2D vector).
void | Scale (float FactorX, float FactorY)
Scale the object (take 2 values).
void | Scale (const Vector2f &Factor)
Scale the object (take a 2D vector).
void | Rotate (float Angle)
Rotate the object.
sf::Vector2f | TransformToLocal (const sf::Vector2f &Point) const
Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).
sf::Vector2f | TransformToGlobal (const sf::Vector2f &Point) const
Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Protected Member Functions

virtual void | Render (RenderTarget &Target) const
/see Drawable::Render
const Matrix3 & | GetMatrix () const
Get the transform matrix of the drawable.
const Matrix3 & | GetInverseMatrix () const
Get the inverse transform matrix of the drawable.

Detailed Description

Sprite defines a sprite : texture, transformations, color, and draw on screen.

Definition at line 44 of file Sprite.hpp.

Constructor & Destructor Documentation

sf::Sprite::Sprite ( )

Default constructor.

Definition at line 38 of file Sprite.cpp.

sf::Sprite::Sprite | ( | const Image & | Img,
 |  | const Vector2f & | Position = Vector2f(0, 0),
 |  | const Vector2f & | Scale = Vector2f(1, 1),
 |  | float | Rotation = 0.f,
 |  | const Color & | Col = Color(255, 255, 255, 255) |
 | ) |  |  | [explicit]

Construct the sprite from a source image.

Parameters:
Img | : Image of the sprite
Position | : Position of the sprite (0, 0 by default)
Scale | : Scale factor (1, 1 by default)
Rotation | : Orientation, in degrees (0 by default)
Col | : Color of the sprite (white by default)

Definition at line 50 of file Sprite.cpp.

Member Function Documentation

void sf::Sprite::FlipX ( bool Flipped )

Flip the sprite horizontally.

Parameters:
Flipped : True to flip the sprite

Definition at line 112 of file Sprite.cpp.

void sf::Sprite::FlipY ( bool Flipped )

Flip the sprite vertically.

Parameters:
Flipped : True to flip the sprite

Definition at line 121 of file Sprite.cpp.

Blend::Mode sf::Drawable::GetBlendMode ( ) const [inherited]

Get the current blending mode.

Returns:
Current blending mode

Definition at line 258 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetCenter ( ) const [inherited]

Get the center of the object.

Returns:
Current position of the center

Definition at line 231 of file Drawable.cpp.

const Color & sf::Drawable::GetColor ( ) const [inherited]

Get the color of the object.

Returns:
Current color

Definition at line 249 of file Drawable.cpp.

const Image * sf::Sprite::GetImage ( ) const

Get the source image of the sprite.

Returns:
Pointer to the image (can be NULL)

Definition at line 130 of file Sprite.cpp.

const Matrix3 & sf::Drawable::GetInverseMatrix ( ) const [protected, inherited]

Get the inverse transform matrix of the drawable.

Returns:
Inverse transform matrix

Definition at line 350 of file Drawable.cpp.

const Matrix3 & sf::Drawable::GetMatrix ( ) const [protected, inherited]

Get the transform matrix of the drawable.

Returns:
Transform matrix

Definition at line 334 of file Drawable.cpp.

Color sf::Sprite::GetPixel | ( | unsigned int | X,
 |  | unsigned int | Y |
 | ) |  |  | const

Get the color of a given pixel in the sprite (point is in local coordinates).

Get the color of a given pixel in the sprite (point is in local coordinates).

Parameters:
X | : X coordinate of the pixel to get
Y | : Y coordinate of the pixel to get
Returns:
Color of pixel (X, Y)

Definition at line 158 of file Sprite.cpp.

const Vector2f & sf::Drawable::GetPosition ( ) const [inherited]

Get the position of the object.

Returns:
Current position

Definition at line 213 of file Drawable.cpp.

float sf::Drawable::GetRotation ( ) const [inherited]

Get the orientation of the object.

Rotation is always in the range [0, 360]

Returns:
Current rotation, in degrees

Definition at line 240 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetScale ( ) const [inherited]

Get the current scale of the object.

Returns:
Current scale factor (always positive)

Definition at line 222 of file Drawable.cpp.

Vector2f sf::Sprite::GetSize ( ) const

Get the sprite size.

Returns:
Size of the sprite

Definition at line 148 of file Sprite.cpp.

const IntRect & sf::Sprite::GetSubRect ( ) const

Get the sub-rectangle of the sprite inside the source image.

Returns:
Sub-rectangle

Definition at line 139 of file Sprite.cpp.

void sf::Drawable::Move ( const Vector2f & Offset ) [inherited]

Move the object of a given offset (take a 2D vector).

Parameters:
Offset : Amount of units to move the object of

Definition at line 278 of file Drawable.cpp.

void sf::Drawable::Move | ( | float | OffsetX,
 |  | float | OffsetY |
 | ) |  |  | [inherited]

Move the object of a given offset (take 2 values).

Parameters:
OffsetX | : X offset
OffsetY | : Y offset

Definition at line 268 of file Drawable.cpp.

void sf::Sprite::Render ( RenderTarget & Target ) const [protected, virtual]

/see Drawable::Render

/see sfDrawable::Render

Implements sf::Drawable.

Definition at line 180 of file Sprite.cpp.

void sf::Sprite::Resize ( const Vector2f & Size )

Resize the sprite (by changing its scale factors) (take a 2D vector).

Resize the object (by changing its scale factors) (take a 2D vector) The default size is defined by the subrect.

The default size is defined by the subrect

Parameters:
Size : New size (both coordinates must be strictly positive)

Definition at line 103 of file Sprite.cpp.

void sf::Sprite::Resize | ( | float | Width,
 |  | float | Height
 | ) |  |

Resize the sprite (by changing its scale factors) (take 2 values).

The default size is defined by the subrect

Parameters:
Width | : New width (must be strictly positive)
Height | : New height (must be strictly positive)
The default size is defined by the subrect

Definition at line 89 of file Sprite.cpp.

void sf::Drawable::Rotate ( float Angle ) [inherited]

Rotate the object.

Parameters:
Angle : Angle of rotation, in degrees

Definition at line 306 of file Drawable.cpp.

void sf::Drawable::Scale ( const Vector2f & Factor ) [inherited]

Scale the object (take a 2D vector).

Parameters:
Factor : Scaling factors (both values must be strictly positive)

Definition at line 297 of file Drawable.cpp.

void sf::Drawable::Scale | ( | float | FactorX,
 |  | float | FactorY |
 | ) |  |  | [inherited]

Scale the object (take 2 values).

Parameters:
FactorX | : Scaling factor on X (must be strictly positive)
FactorY | : Scaling factor on Y (must be strictly positive)

Definition at line 287 of file Drawable.cpp.

void sf::Drawable::SetBlendMode ( Blend::Mode Mode ) [inherited]

Set the blending mode for the object.

The default blend mode is Blend::Alpha

Parameters:
Mode : New blending mode
The default blend mode is Blend::Alpha

Definition at line 204 of file Drawable.cpp.

void sf::Drawable::SetCenter ( const Vector2f & Center ) [inherited]

Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).

Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).

The default center is (0, 0)

Parameters:
Center : New center
The default center is (0, 0)

Definition at line 171 of file Drawable.cpp.

void sf::Drawable::SetCenter | ( | float | CenterX,
 |  | float | CenterY |
 | ) |  |  | [inherited]

Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).

Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).

The default center is (0, 0)

Parameters:
CenterX | : X coordinate of the center
CenterY | : Y coordinate of the center
The default center is (0, 0)

Definition at line 157 of file Drawable.cpp.

void sf::Drawable::SetColor ( const Color & Col ) [inherited]

Set the color of the object.

The default color is white

Parameters:
Col : New color
The default color is white

Definition at line 194 of file Drawable.cpp.

void sf::Sprite::SetImage ( const Image & Img )

Change the image of the sprite.

Set the image of the sprite.

Parameters:
Img : New image

Definition at line 63 of file Sprite.cpp.

void sf::Drawable::SetPosition ( const Vector2f & Position ) [inherited]

Set the position of the object (take a 2D vector).

Parameters:
Position : New position

Definition at line 75 of file Drawable.cpp.

void sf::Drawable::SetPosition | ( | float | X,
 |  | float | Y |
 | ) |  |  | [inherited]

Set the position of the object (take 2 values).

Parameters:
X | : New X coordinate
Y | : New Y coordinate

Definition at line 65 of file Drawable.cpp.

void sf::Drawable::SetRotation ( float Rotation ) [inherited]

Set the orientation of the object.

Parameters:
Rotation : Angle of rotation, in degrees

Definition at line 180 of file Drawable.cpp.

void sf::Drawable::SetScale ( const Vector2f & Scale ) [inherited]

Set the scale of the object (take a 2D vector).

Parameters:
Scale : New scale (both values must be strictly positive)

Definition at line 117 of file Drawable.cpp.

void sf::Drawable::SetScale | ( | float | ScaleX,
 |  | float | ScaleY |
 | ) |  |  | [inherited]

Set the scale of the object (take 2 values).

Parameters:
ScaleX | : New horizontal scale (must be strictly positive)
ScaleY | : New vertical scale (must be strictly positive)

Definition at line 107 of file Drawable.cpp.

void sf::Drawable::SetScaleX ( float FactorX ) [inherited]

Set the X scale factor of the object.

Parameters:
X : New X scale factor

Definition at line 127 of file Drawable.cpp.

void sf::Drawable::SetScaleY ( float FactorY ) [inherited]

Set the Y scale factor of the object.

Parameters:
Y : New Y scale factor

Definition at line 141 of file Drawable.cpp.

void sf::Sprite::SetSubRect ( const IntRect & SubRect )

Set the sub-rectangle of the sprite inside the source image.

By default, the subrect covers the entire source image

Parameters:
SubRect : New sub-rectangle

Definition at line 79 of file Sprite.cpp.

void sf::Drawable::SetX ( float X ) [inherited]

Set the X position of the object.

Parameters:
X : New X coordinate

Definition at line 85 of file Drawable.cpp.

void sf::Drawable::SetY ( float Y ) [inherited]

Set the Y position of the object.

Parameters:
Y : New Y coordinate

Definition at line 96 of file Drawable.cpp.

sf::Vector2f sf::Drawable::TransformToGlobal ( const sf::Vector2f & Point ) const [inherited]

Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Parameters:
Point : Point to transform
Returns:
Transformed point

Definition at line 325 of file Drawable.cpp.

sf::Vector2f sf::Drawable::TransformToLocal ( const sf::Vector2f & Point ) const [inherited]

Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).

Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).

Parameters:
Point : Point to transform
Returns:
Transformed point

Definition at line 316 of file Drawable.cpp.

The documentation for this class was generated from the following files:
  • Sprite.hpp
  • Sprite.cpp


sf::Sprite Member List

This is the complete list of members for sf::Sprite, including all inherited members.

Drawable(const Vector2f &Position=Vector2f(0, 0), const Vector2f &Scale=Vector2f(1, 1), float Rotation=0.f, const Color &Col=Color(255, 255, 255, 255)) | sf::Drawable |
FlipX(bool Flipped) | sf::Sprite |
FlipY(bool Flipped) | sf::Sprite |
GetBlendMode() const | sf::Drawable |
GetCenter() const | sf::Drawable |
GetColor() const | sf::Drawable |
GetImage() const | sf::Sprite |
GetInverseMatrix() const | sf::Drawable | [protected]
GetMatrix() const | sf::Drawable | [protected]
GetPixel(unsigned int X, unsigned int Y) const | sf::Sprite |
GetPosition() const | sf::Drawable |
GetRotation() const | sf::Drawable |
GetScale() const | sf::Drawable |
GetSize() const | sf::Sprite |
GetSubRect() const | sf::Sprite |
Move(float OffsetX, float OffsetY) | sf::Drawable |
Move(const Vector2f &Offset) | sf::Drawable |
Render(RenderTarget &Target) const | sf::Sprite | [protected, virtual]
Resize(float Width, float Height) | sf::Sprite |
Resize(const Vector2f &Size) | sf::Sprite |
Rotate(float Angle) | sf::Drawable |
Scale(float FactorX, float FactorY) | sf::Drawable |
Scale(const Vector2f &Factor) | sf::Drawable |
SetBlendMode(Blend::Mode Mode) | sf::Drawable |
SetCenter(float CenterX, float CenterY) | sf::Drawable |
SetCenter(const Vector2f &Center) | sf::Drawable |
SetColor(const Color &Col) | sf::Drawable |
SetImage(const Image &Img) | sf::Sprite |
SetPosition(float X, float Y) | sf::Drawable |
SetPosition(const Vector2f &Position) | sf::Drawable |
SetRotation(float Rotation) | sf::Drawable |
SetScale(float ScaleX, float ScaleY) | sf::Drawable |
SetScale(const Vector2f &Scale) | sf::Drawable |
SetScaleX(float FactorX) | sf::Drawable |
SetScaleY(float FactorY) | sf::Drawable |
SetSubRect(const IntRect &SubRect) | sf::Sprite |
SetX(float X) | sf::Drawable |
SetY(float Y) | sf::Drawable |
Sprite() | sf::Sprite |
Sprite(const Image &Img, const Vector2f &Position=Vector2f(0, 0), const Vector2f &Scale=Vector2f(1, 1), float Rotation=0.f, const Color &Col=Color(255, 255, 255, 255)) | sf::Sprite | [explicit]
TransformToGlobal(const sf::Vector2f &Point) const | sf::Drawable |
TransformToLocal(const sf::Vector2f &Point) const | sf::Drawable |
~Drawable() | sf::Drawable | [virtual]


sf::String

sf::String Class Reference

String defines a graphical 2D text, that can be drawn on screen. More...

#include <String.hpp>

Inheritance diagram for sf::String:

sf::Drawable

List of all members.

Public Types

enum Style {
Regular = 0,
Bold = 1 << 0,
Italic = 1 << 1,
Underlined = 1 << 2
}
Enumerate the string drawing styles. More...

Public Member Functions

String ()
Default constructor.
String (const Unicode::Text &Text, const Font &CharFont=Font::GetDefaultFont(), float Size=30.f)
Construct the string from any kind of text.
void | SetText (const Unicode::Text &Text)
Set the text (from any kind of string).
void | SetFont (const Font &CharFont)
Set the font of the string.
void | SetSize (float Size)
Set the size of the string The default size is 30.
void | SetStyle (unsigned long TextStyle)
Set the style of the text The default style is Regular.
const Unicode::Text & | GetText () const
Get the text (the returned text can be converted implicitely to any kind of string).
const Font & | GetFont () const
Get the font used by the string.
float | GetSize () const
Get the size of the characters.
unsigned long | GetStyle () const
Get the style of the text.
sf::Vector2f | GetCharacterPos (std::size_t Index) const
Return the visual position of the Index-th character of the string, in coordinates relative to the string (note : translation, center, rotation and scale are not applied).
FloatRect | GetRect () const
Get the string rectangle on screen.
void | SetPosition (float X, float Y)
Set the position of the object (take 2 values).
void | SetPosition (const Vector2f &Position)
Set the position of the object (take a 2D vector).
void | SetX (float X)
Set the X position of the object.
void | SetY (float Y)
Set the Y position of the object.
void | SetScale (float ScaleX, float ScaleY)
Set the scale of the object (take 2 values).
void | SetScale (const Vector2f &Scale)
Set the scale of the object (take a 2D vector).
void | SetScaleX (float FactorX)
Set the X scale factor of the object.
void | SetScaleY (float FactorY)
Set the Y scale factor of the object.
void | SetCenter (float CenterX, float CenterY)
Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).
void | SetCenter (const Vector2f &Center)
Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).
void | SetRotation (float Rotation)
Set the orientation of the object.
void | SetColor (const Color &Col)
Set the color of the object.
void | SetBlendMode (Blend::Mode Mode)
Set the blending mode for the object.
const Vector2f & | GetPosition () const
Get the position of the object.
const Vector2f & | GetScale () const
Get the current scale of the object.
const Vector2f & | GetCenter () const
Get the center of the object.
float | GetRotation () const
Get the orientation of the object.
const Color & | GetColor () const
Get the color of the object.
Blend::Mode | GetBlendMode () const
Get the current blending mode.
void | Move (float OffsetX, float OffsetY)
Move the object of a given offset (take 2 values).
void | Move (const Vector2f &Offset)
Move the object of a given offset (take a 2D vector).
void | Scale (float FactorX, float FactorY)
Scale the object (take 2 values).
void | Scale (const Vector2f &Factor)
Scale the object (take a 2D vector).
void | Rotate (float Angle)
Rotate the object.
sf::Vector2f | TransformToLocal (const sf::Vector2f &Point) const
Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).
sf::Vector2f | TransformToGlobal (const sf::Vector2f &Point) const
Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Protected Member Functions

virtual void | Render (RenderTarget &Target) const
/see Drawable::Render
const Matrix3 & | GetMatrix () const
Get the transform matrix of the drawable.
const Matrix3 & | GetInverseMatrix () const
Get the inverse transform matrix of the drawable.

Detailed Description

String defines a graphical 2D text, that can be drawn on screen.

Definition at line 44 of file String.hpp.

Member Enumeration Documentation

enum sf::String::Style

Enumerate the string drawing styles.

Enumerator:
Regular | Regular characters, no style.
Bold | Characters are bold.
Italic | Characters are in italic.
Underlined | Characters are underlined.

Definition at line 51 of file String.hpp.

Constructor & Destructor Documentation

sf::String::String ( )

Default constructor.

Definition at line 39 of file String.cpp.

sf::String::String | ( | const Unicode::Text & | Text,
 |  | const Font & | CharFont = Font::GetDefaultFont(),
 |  | float | Size = 30.f |
 | ) |  |  | [explicit]

Construct the string from any kind of text.

Parameters:
Text | : Text assigned to the string
Font | : Font used to draw the string (SFML built-in font by default)
Size | : Characters size (30 by default)

Definition at line 52 of file String.cpp.

Member Function Documentation

Blend::Mode sf::Drawable::GetBlendMode ( ) const [inherited]

Get the current blending mode.

Returns:
Current blending mode

Definition at line 258 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetCenter ( ) const [inherited]

Get the center of the object.

Returns:
Current position of the center

Definition at line 231 of file Drawable.cpp.

sf::Vector2f sf::String::GetCharacterPos ( std::size_t Index ) const

Return the visual position of the Index-th character of the string, in coordinates relative to the string (note : translation, center, rotation and scale are not applied).

Return the visual position of the Index-th character of the string, in coordinates relative to the string (note : translation, center, rotation and scale are not applied).

Parameters:
Index : Index of the character
Returns:
Position of the Index-th character (end of string if Index is out of range)

Definition at line 153 of file String.cpp.

const Color & sf::Drawable::GetColor ( ) const [inherited]

Get the color of the object.

Returns:
Current color

Definition at line 249 of file Drawable.cpp.

const Font & sf::String::GetFont ( ) const

Get the font used by the string.

Returns:
Font used

Definition at line 124 of file String.cpp.

const Matrix3 & sf::Drawable::GetInverseMatrix ( ) const [protected, inherited]

Get the inverse transform matrix of the drawable.

Returns:
Inverse transform matrix

Definition at line 350 of file Drawable.cpp.

const Matrix3 & sf::Drawable::GetMatrix ( ) const [protected, inherited]

Get the transform matrix of the drawable.

Returns:
Transform matrix

Definition at line 334 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetPosition ( ) const [inherited]

Get the position of the object.

Returns:
Current position

Definition at line 213 of file Drawable.cpp.

FloatRect sf::String::GetRect ( ) const

Get the string rectangle on screen.

Returns:
Rectangle contaning the string in screen coordinates

Definition at line 195 of file String.cpp.

float sf::Drawable::GetRotation ( ) const [inherited]

Get the orientation of the object.

Rotation is always in the range [0, 360]

Returns:
Current rotation, in degrees

Definition at line 240 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetScale ( ) const [inherited]

Get the current scale of the object.

Returns:
Current scale factor (always positive)

Definition at line 222 of file Drawable.cpp.

float sf::String::GetSize ( ) const

Get the size of the characters.

Returns:
Size of the characters

Definition at line 133 of file String.cpp.

unsigned long sf::String::GetStyle ( ) const

Get the style of the text.

Returns:
Current string style (combination of Style enum values)

Definition at line 142 of file String.cpp.

const Unicode::Text & sf::String::GetText ( ) const

Get the text (the returned text can be converted implicitely to any kind of string).

Returns:
String's text

Definition at line 115 of file String.cpp.

void sf::Drawable::Move ( const Vector2f & Offset ) [inherited]

Move the object of a given offset (take a 2D vector).

Parameters:
Offset : Amount of units to move the object of

Definition at line 278 of file Drawable.cpp.

void sf::Drawable::Move | ( | float | OffsetX,
 |  | float | OffsetY |
 | ) |  |  | [inherited]

Move the object of a given offset (take 2 values).

Parameters:
OffsetX | : X offset
OffsetY | : Y offset

Definition at line 268 of file Drawable.cpp.

void sf::String::Render ( RenderTarget & Target ) const [protected, virtual]

/see Drawable::Render

/see sfDrawable::Render

Implements sf::Drawable.

Definition at line 213 of file String.cpp.

void sf::Drawable::Rotate ( float Angle ) [inherited]

Rotate the object.

Parameters:
Angle : Angle of rotation, in degrees

Definition at line 306 of file Drawable.cpp.

void sf::Drawable::Scale ( const Vector2f & Factor ) [inherited]

Scale the object (take a 2D vector).

Parameters:
Factor : Scaling factors (both values must be strictly positive)

Definition at line 297 of file Drawable.cpp.

void sf::Drawable::Scale | ( | float | FactorX,
 |  | float | FactorY |
 | ) |  |  | [inherited]

Scale the object (take 2 values).

Parameters:
FactorX | : Scaling factor on X (must be strictly positive)
FactorY | : Scaling factor on Y (must be strictly positive)

Definition at line 287 of file Drawable.cpp.

void sf::Drawable::SetBlendMode ( Blend::Mode Mode ) [inherited]

Set the blending mode for the object.

The default blend mode is Blend::Alpha

Parameters:
Mode : New blending mode
The default blend mode is Blend::Alpha

Definition at line 204 of file Drawable.cpp.

void sf::Drawable::SetCenter ( const Vector2f & Center ) [inherited]

Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).

Set the center of the object, in coordinates relative to the top-left of the object (take a 2D vector).

The default center is (0, 0)

Parameters:
Center : New center
The default center is (0, 0)

Definition at line 171 of file Drawable.cpp.

void sf::Drawable::SetCenter | ( | float | CenterX,
 |  | float | CenterY |
 | ) |  |  | [inherited]

Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).

Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).

The default center is (0, 0)

Parameters:
CenterX | : X coordinate of the center
CenterY | : Y coordinate of the center
The default center is (0, 0)

Definition at line 157 of file Drawable.cpp.

void sf::Drawable::SetColor ( const Color & Col ) [inherited]

Set the color of the object.

The default color is white

Parameters:
Col : New color
The default color is white

Definition at line 194 of file Drawable.cpp.

void sf::String::SetFont ( const Font & CharFont )

Set the font of the string.

Parameters:
Font : Font to use

Definition at line 75 of file String.cpp.

void sf::Drawable::SetPosition ( const Vector2f & Position ) [inherited]

Set the position of the object (take a 2D vector).

Parameters:
Position : New position

Definition at line 75 of file Drawable.cpp.

void sf::Drawable::SetPosition | ( | float | X,
 |  | float | Y |
 | ) |  |  | [inherited]

Set the position of the object (take 2 values).

Parameters:
X | : New X coordinate
Y | : New Y coordinate

Definition at line 65 of file Drawable.cpp.

void sf::Drawable::SetRotation ( float Rotation ) [inherited]

Set the orientation of the object.

Parameters:
Rotation : Angle of rotation, in degrees

Definition at line 180 of file Drawable.cpp.

void sf::Drawable::SetScale ( const Vector2f & Scale ) [inherited]

Set the scale of the object (take a 2D vector).

Parameters:
Scale : New scale (both values must be strictly positive)

Definition at line 117 of file Drawable.cpp.

void sf::Drawable::SetScale | ( | float | ScaleX,
 |  | float | ScaleY |
 | ) |  |  | [inherited]

Set the scale of the object (take 2 values).

Parameters:
ScaleX | : New horizontal scale (must be strictly positive)
ScaleY | : New vertical scale (must be strictly positive)

Definition at line 107 of file Drawable.cpp.

void sf::Drawable::SetScaleX ( float FactorX ) [inherited]

Set the X scale factor of the object.

Parameters:
X : New X scale factor

Definition at line 127 of file Drawable.cpp.

void sf::Drawable::SetScaleY ( float FactorY ) [inherited]

Set the Y scale factor of the object.

Parameters:
Y : New Y scale factor

Definition at line 141 of file Drawable.cpp.

void sf::String::SetSize ( float Size )

Set the size of the string The default size is 30.

Set the size of the string.

Parameters:
Size : New size, in pixels

Definition at line 88 of file String.cpp.

void sf::String::SetStyle ( unsigned long TextStyle )

Set the style of the text The default style is Regular.

Set the style of the text The default style is Regular.

Parameters:
TextStyle : New text style, (combination of Style enum values)

Definition at line 102 of file String.cpp.

void sf::String::SetText ( const Unicode::Text & Text )

Set the text (from any kind of string).

Parameters:
Text : New text

Definition at line 65 of file String.cpp.

void sf::Drawable::SetX ( float X ) [inherited]

Set the X position of the object.

Parameters:
X : New X coordinate

Definition at line 85 of file Drawable.cpp.

void sf::Drawable::SetY ( float Y ) [inherited]

Set the Y position of the object.

Parameters:
Y : New Y coordinate

Definition at line 96 of file Drawable.cpp.

sf::Vector2f sf::Drawable::TransformToGlobal ( const sf::Vector2f & Point ) const [inherited]

Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point).

Parameters:
Point : Point to transform
Returns:
Transformed point

Definition at line 325 of file Drawable.cpp.

sf::Vector2f sf::Drawable::TransformToLocal ( const sf::Vector2f & Point ) const [inherited]

Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).

Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point).

Parameters:
Point : Point to transform
Returns:
Transformed point

Definition at line 316 of file Drawable.cpp.

The documentation for this class was generated from the following files:
  • String.hpp
  • String.cpp


sf::String Member List

This is the complete list of members for sf::String, including all inherited members.

Bold enum value | sf::String |
Drawable(const Vector2f &Position=Vector2f(0, 0), const Vector2f &Scale=Vector2f(1, 1), float Rotation=0.f, const Color &Col=Color(255, 255, 255, 255)) | sf::Drawable |
GetBlendMode() const | sf::Drawable |
GetCenter() const | sf::Drawable |
GetCharacterPos(std::size_t Index) const | sf::String |
GetColor() const | sf::Drawable |
GetFont() const | sf::String |
GetInverseMatrix() const | sf::Drawable | [protected]
GetMatrix() const | sf::Drawable | [protected]
GetPosition() const | sf::Drawable |
GetRect() const | sf::String |
GetRotation() const | sf::Drawable |
GetScale() const | sf::Drawable |
GetSize() const | sf::String |
GetStyle() const | sf::String |
GetText() const | sf::String |
Italic enum value | sf::String |
Move(float OffsetX, float OffsetY) | sf::Drawable |
Move(const Vector2f &Offset) | sf::Drawable |
Regular enum value | sf::String |
Render(RenderTarget &Target) const | sf::String | [protected, virtual]
Rotate(float Angle) | sf::Drawable |
Scale(float FactorX, float FactorY) | sf::Drawable |
Scale(const Vector2f &Factor) | sf::Drawable |
SetBlendMode(Blend::Mode Mode) | sf::Drawable |
SetCenter(float CenterX, float CenterY) | sf::Drawable |
SetCenter(const Vector2f &Center) | sf::Drawable |
SetColor(const Color &Col) | sf::Drawable |
SetFont(const Font &CharFont) | sf::String |
SetPosition(float X, float Y) | sf::Drawable |
SetPosition(const Vector2f &Position) | sf::Drawable |
SetRotation(float Rotation) | sf::Drawable |
SetScale(float ScaleX, float ScaleY) | sf::Drawable |
SetScale(const Vector2f &Scale) | sf::Drawable |
SetScaleX(float FactorX) | sf::Drawable |
SetScaleY(float FactorY) | sf::Drawable |
SetSize(float Size) | sf::String |
SetStyle(unsigned long TextStyle) | sf::String |
SetText(const Unicode::Text &Text) | sf::String |
SetX(float X) | sf::Drawable |
SetY(float Y) | sf::Drawable |
String() | sf::String |
String(const Unicode::Text &Text, const Font &CharFont=Font::GetDefaultFont(), float Size=30.f) | sf::String | [explicit]
Style enum name | sf::String |
TransformToGlobal(const sf::Vector2f &Point) const | sf::Drawable |
TransformToLocal(const sf::Vector2f &Point) const | sf::Drawable |
Underlined enum value | sf::String |
~Drawable() | sf::Drawable | [virtual]


sf::Thread

sf::Thread Class Reference

Thread defines an easy way to manipulate a thread. More...

#include <Thread.hpp>

Inheritance diagram for sf::Thread:

sf::NonCopyable sf::SoundRecorder sf::SoundStream sf::SoundBufferRecorder sf::Music

List of all members.

Public Types

typedef void(* | FuncType )(void *)

Public Member Functions

Thread (FuncType Function, void *UserData=NULL)
Construct the thread from a function pointer.
virtual | ~Thread ()
Virtual destructor.
void | Launch ()
Create and run the thread.
void | Wait ()
Wait until the thread finishes.
void | Terminate ()
Terminate the thread Terminating a thread with this function is not safe, you should rather try to make the thread function terminate by itself.

Protected Member Functions

Thread ()
Default constructor.

Detailed Description

Thread defines an easy way to manipulate a thread.

There are two ways to use Thread :

  • Inherit from it and override the Run() virtual function
  • Construct a Thread instance and pass it a function pointer to call

Definition at line 44 of file Win32/Thread.hpp.

Constructor & Destructor Documentation

sf::Thread::Thread | ( | Thread::FuncType | Function,
 |  | void * | UserData = NULL
 | ) |  |

Construct the thread from a function pointer.

Parameters:
Function | : Entry point of the thread
UserData | : Data to pass to the thread function (NULL by default)

Definition at line 50 of file Thread.cpp.

sf::Thread::~Thread ( ) [virtual]

Virtual destructor.

Definition at line 62 of file Thread.cpp.

sf::Thread::Thread ( ) [protected]

Default constructor.

Definition at line 38 of file Thread.cpp.

Member Function Documentation

void sf::Thread::Launch ( )

Create and run the thread.

Definition at line 72 of file Thread.cpp.

void sf::Thread::Terminate ( )

Terminate the thread Terminating a thread with this function is not safe, you should rather try to make the thread function terminate by itself.

Terminate the thread Terminating a thread with this function is not safe, you should rather try to make the thread function terminate by itself.

Definition at line 109 of file Thread.cpp.

void sf::Thread::Wait ( )

Wait until the thread finishes.

Definition at line 89 of file Thread.cpp.

The documentation for this class was generated from the following files:
  • Win32/Thread.hpp
  • Thread.cpp


sf::Thread Member List

This is the complete list of members for sf::Thread, including all inherited members.

FuncType typedef (defined in sf::Thread) | sf::Thread |
Launch() | sf::Thread |
NonCopyable() | sf::NonCopyable | [inline, private]
Terminate() | sf::Thread |
Thread(FuncType Function, void *UserData=NULL) | sf::Thread |
Thread() | sf::Thread | [protected]
Wait() | sf::Thread |
~Thread() | sf::Thread | [virtual]


sf::Unicode

sf::Unicode Class Reference

Provides utility functions to convert from and to any unicode and ASCII encoding. More...

#include <Unicode.hpp>

List of all members.

Classes

class | Text
This class is an abstract definition of a unicode text, it can be converted from and to any kind of string and encoding. More...

Public Types

typedef std::basic_string< Uint8 > | UTF8String
Define a string type for each encoding Warning : in UTF8 and UTF16 strings, one element doesn't necessarily maps to one character ; only an UTF32 element is wide enough to hold all possible unicode values.
typedef std::basic_string< Uint16 > | UTF16String
typedef std::basic_string< Uint32 > | UTF32String

Public Member Functions

template<typename In , typename Out >
Out | UTF32ToANSI (In Begin, In End, Out Output, char Replacement, const std::locale &Locale)
Generic function to convert an UTF-32 characters range to an ANSI characters range, using the given locale.
template<typename In , typename Out >
Out | ANSIToUTF32 (In Begin, In End, Out Output, const std::locale &Locale)
Generic function to convert an ANSI characters range to an UTF-32 characters range, using the given locale.
template<typename In , typename Out >
Out | UTF8ToUTF16 (In Begin, In End, Out Output, Uint16 Replacement)
Generic function to convert an UTF-8 characters range to an UTF-16 characters range, using the given locale.
template<typename In , typename Out >
Out | UTF8ToUTF32 (In Begin, In End, Out Output, Uint32 Replacement)
Generic function to convert an UTF-8 characters range to an UTF-32 characters range, using the given locale.
template<typename In , typename Out >
Out | UTF16ToUTF8 (In Begin, In End, Out Output, Uint8 Replacement)
Generic function to convert an UTF-16 characters range to an UTF-8 characters range, using the given locale.
template<typename In , typename Out >
Out | UTF16ToUTF32 (In Begin, In End, Out Output, Uint32 Replacement)
Generic function to convert an UTF-16 characters range to an UTF-32 characters range, using the given locale.
template<typename In , typename Out >
Out | UTF32ToUTF8 (In Begin, In End, Out Output, Uint8 Replacement)
Generic function to convert an UTF-32 characters range to an UTF-8 characters range, using the given locale.
template<typename In , typename Out >
Out | UTF32ToUTF16 (In Begin, In End, Out Output, Uint16 Replacement)
Generic function to convert an UTF-32 characters range to an UTF-16 characters range, using the given locale.
template<typename In >
std::size_t | GetUTF8Length (In Begin, In End)
Get the number of characters composing an UTF-8 string.
template<typename In >
std::size_t | GetUTF16Length (In Begin, In End)
Get the number of characters composing an UTF-16 string.
template<typename In >
std::size_t | GetUTF32Length (In Begin, In End)
Get the number of characters composing an UTF-32 string.

Static Public Member Functions

template<typename In , typename Out >
static Out | UTF32ToANSI (In Begin, In End, Out Output, char Replacement= '?', const std::locale &Locale=GetDefaultLocale())
Generic function to convert an UTF-32 characters range to an ANSI characters range, using the given locale.
template<typename In , typename Out >
static Out | ANSIToUTF32 (In Begin, In End, Out Output, const std::locale &Locale=GetDefaultLocale())
Generic function to convert an ANSI characters range to an UTF-32 characters range, using the given locale.
template<typename In , typename Out >
static Out | UTF8ToUTF16 (In Begin, In End, Out Output, Uint16 Replacement= '?')
Generic function to convert an UTF-8 characters range to an UTF-16 characters range, using the given locale.
template<typename In , typename Out >
static Out | UTF8ToUTF32 (In Begin, In End, Out Output, Uint32 Replacement= '?')
Generic function to convert an UTF-8 characters range to an UTF-32 characters range, using the given locale.
template<typename In , typename Out >
static Out | UTF16ToUTF8 (In Begin, In End, Out Output, Uint8 Replacement= '?')
Generic function to convert an UTF-16 characters range to an UTF-8 characters range, using the given locale.
template<typename In , typename Out >
static Out | UTF16ToUTF32 (In Begin, In End, Out Output, Uint32 Replacement= '?')
Generic function to convert an UTF-16 characters range to an UTF-32 characters range, using the given locale.
template<typename In , typename Out >
static Out | UTF32ToUTF8 (In Begin, In End, Out Output, Uint8 Replacement= '?')
Generic function to convert an UTF-32 characters range to an UTF-8 characters range, using the given locale.
template<typename In , typename Out >
static Out | UTF32ToUTF16 (In Begin, In End, Out Output, Uint16 Replacement= '?')
Generic function to convert an UTF-32 characters range to an UTF-16 characters range, using the given locale.
template<typename In >
static std::size_t | GetUTF8Length (In Begin, In End)
Get the number of characters composing an UTF-8 string.
template<typename In >
static std::size_t | GetUTF16Length (In Begin, In End)
Get the number of characters composing an UTF-16 string.
template<typename In >
static std::size_t | GetUTF32Length (In Begin, In End)
Get the number of characters composing an UTF-32 string.

Detailed Description

Provides utility functions to convert from and to any unicode and ASCII encoding.

Definition at line 44 of file Unicode.hpp.

Member Typedef Documentation

typedef std::basic_string<Uint8> sf::Unicode::UTF8String

Define a string type for each encoding Warning : in UTF8 and UTF16 strings, one element doesn't necessarily maps to one character ; only an UTF32 element is wide enough to hold all possible unicode values.

Definition at line 54 of file Unicode.hpp.

Member Function Documentation

template<typename In , typename Out >
Out sf::Unicode::ANSIToUTF32 | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | const std::locale & | Locale |
 | ) |  |  | [inline]

Generic function to convert an ANSI characters range to an UTF-32 characters range, using the given locale.

Definition at line 67 of file Unicode.inl.

template<typename In , typename Out >
static Out sf::Unicode::ANSIToUTF32 | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | const std::locale & | Locale = GetDefaultLocale() |
 | ) |  |  | [inline, static]

Generic function to convert an ANSI characters range to an UTF-32 characters range, using the given locale.

Parameters:
Begin | : Iterator pointing to the beginning of the input sequence
End | : Iterator pointing to the end of the input sequence
Output | : Iterator pointing to the beginning of the output sequence
Locale | : Locale to use for conversion (uses the current one by default)
Returns:
Iterator to the end of the output sequence which has been written

template<typename In >
std::size_t sf::Unicode::GetUTF16Length | ( | In | Begin,
 |  | In | End |
 | ) |  |  | [inline]

Get the number of characters composing an UTF-16 string.

Definition at line 442 of file Unicode.inl.

template<typename In >
static std::size_t sf::Unicode::GetUTF16Length | ( | In | Begin,
 |  | In | End |
 | ) |  |  | [inline, static]

Get the number of characters composing an UTF-16 string.

Parameters:
Begin | : Iterator pointing to the beginning of the input sequence
End | : Iterator pointing to the end of the input sequence
Returns:
Count of the characters in the string

template<typename In >
std::size_t sf::Unicode::GetUTF32Length | ( | In | Begin,
 |  | In | End |
 | ) |  |  | [inline]

Get the number of characters composing an UTF-32 string.

Definition at line 471 of file Unicode.inl.

template<typename In >
static std::size_t sf::Unicode::GetUTF32Length | ( | In | Begin,
 |  | In | End |
 | ) |  |  | [inline, static]

Get the number of characters composing an UTF-32 string.

Parameters:
Begin | : Iterator pointing to the beginning of the input sequence
End | : Iterator pointing to the end of the input sequence
Returns:
Count of the characters in the string

template<typename In >
std::size_t sf::Unicode::GetUTF8Length | ( | In | Begin,
 |  | In | End |
 | ) |  |  | [inline]

Get the number of characters composing an UTF-8 string.

Definition at line 422 of file Unicode.inl.

template<typename In >
static std::size_t sf::Unicode::GetUTF8Length | ( | In | Begin,
 |  | In | End |
 | ) |  |  | [inline, static]

Get the number of characters composing an UTF-8 string.

Parameters:
Begin | : Iterator pointing to the beginning of the input sequence
End | : Iterator pointing to the end of the input sequence
Returns:
Count of the characters in the string

template<typename In , typename Out >
Out sf::Unicode::UTF16ToUTF32 | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | Uint32 | Replacement |
 | ) |  |  | [inline]

Generic function to convert an UTF-16 characters range to an UTF-32 characters range, using the given locale.

Definition at line 280 of file Unicode.inl.

template<typename In , typename Out >
static Out sf::Unicode::UTF16ToUTF32 | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | Uint32 | Replacement = '?' |
 | ) |  |  | [inline, static]

Generic function to convert an UTF-16 characters range to an UTF-32 characters range, using the given locale.

Parameters:
Begin | : Iterator pointing to the beginning of the input sequence
End | : Iterator pointing to the end of the input sequence
Output | : Iterator pointing to the beginning of the output sequence
Replacement | : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
Returns:
Iterator to the end of the output sequence which has been written

template<typename In , typename Out >
Out sf::Unicode::UTF16ToUTF8 | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | Uint8 | Replacement |
 | ) |  |  | [inline]

Generic function to convert an UTF-16 characters range to an UTF-8 characters range, using the given locale.

Definition at line 207 of file Unicode.inl.

template<typename In , typename Out >
static Out sf::Unicode::UTF16ToUTF8 | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | Uint8 | Replacement = '?' |
 | ) |  |  | [inline, static]

Generic function to convert an UTF-16 characters range to an UTF-8 characters range, using the given locale.

Parameters:
Begin | : Iterator pointing to the beginning of the input sequence
End | : Iterator pointing to the end of the input sequence
Output | : Iterator pointing to the beginning of the output sequence
Replacement | : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
Returns:
Iterator to the end of the output sequence which has been written

template<typename In , typename Out >
Out sf::Unicode::UTF32ToANSI | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | char | Replacement,
 |  | const std::locale & | Locale |
 | ) |  |  | [inline]

Generic function to convert an UTF-32 characters range to an ANSI characters range, using the given locale.

Definition at line 31 of file Unicode.inl.

template<typename In , typename Out >
static Out sf::Unicode::UTF32ToANSI | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | char | Replacement = '?',
 |  | const std::locale & | Locale = GetDefaultLocale() |
 | ) |  |  | [inline, static]

Generic function to convert an UTF-32 characters range to an ANSI characters range, using the given locale.

Parameters:
Begin | : Iterator pointing to the beginning of the input sequence
End | : Iterator pointing to the end of the input sequence
Output | : Iterator pointing to the beginning of the output sequence
Replacement | : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
Locale | : Locale to use for conversion (uses the current one by default)
Returns:
Iterator to the end of the output sequence which has been written

template<typename In , typename Out >
Out sf::Unicode::UTF32ToUTF16 | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | Uint16 | Replacement |
 | ) |  |  | [inline]

Generic function to convert an UTF-32 characters range to an UTF-16 characters range, using the given locale.

Definition at line 379 of file Unicode.inl.

template<typename In , typename Out >
static Out sf::Unicode::UTF32ToUTF16 | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | Uint16 | Replacement = '?' |
 | ) |  |  | [inline, static]

Generic function to convert an UTF-32 characters range to an UTF-16 characters range, using the given locale.

Parameters:
Begin | : Iterator pointing to the beginning of the input sequence
End | : Iterator pointing to the end of the input sequence
Output | : Iterator pointing to the beginning of the output sequence
Replacement | : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
Returns:
Iterator to the end of the output sequence which has been written

template<typename In , typename Out >
Out sf::Unicode::UTF32ToUTF8 | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | Uint8 | Replacement |
 | ) |  |  | [inline]

Generic function to convert an UTF-32 characters range to an UTF-8 characters range, using the given locale.

Definition at line 326 of file Unicode.inl.

template<typename In , typename Out >
static Out sf::Unicode::UTF32ToUTF8 | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | Uint8 | Replacement = '?' |
 | ) |  |  | [inline, static]

Generic function to convert an UTF-32 characters range to an UTF-8 characters range, using the given locale.

Parameters:
Begin | : Iterator pointing to the beginning of the input sequence
End | : Iterator pointing to the end of the input sequence
Output | : Iterator pointing to the beginning of the output sequence
Replacement | : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
Returns:
Iterator to the end of the output sequence which has been written

template<typename In , typename Out >
Out sf::Unicode::UTF8ToUTF16 | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | Uint16 | Replacement |
 | ) |  |  | [inline]

Generic function to convert an UTF-8 characters range to an UTF-16 characters range, using the given locale.

Definition at line 102 of file Unicode.inl.

template<typename In , typename Out >
static Out sf::Unicode::UTF8ToUTF16 | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | Uint16 | Replacement = '?' |
 | ) |  |  | [inline, static]

Generic function to convert an UTF-8 characters range to an UTF-16 characters range, using the given locale.

Parameters:
Begin | : Iterator pointing to the beginning of the input sequence
End | : Iterator pointing to the end of the input sequence
Output | : Iterator pointing to the beginning of the output sequence
Replacement | : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
Returns:
Iterator to the end of the output sequence which has been written

template<typename In , typename Out >
Out sf::Unicode::UTF8ToUTF32 | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | Uint32 | Replacement |
 | ) |  |  | [inline]

Generic function to convert an UTF-8 characters range to an UTF-32 characters range, using the given locale.

Definition at line 163 of file Unicode.inl.

template<typename In , typename Out >
static Out sf::Unicode::UTF8ToUTF32 | ( | In | Begin,
 |  | In | End,
 |  | Out | Output,
 |  | Uint32 | Replacement = '?' |
 | ) |  |  | [inline, static]

Generic function to convert an UTF-8 characters range to an UTF-32 characters range, using the given locale.

Parameters:
Begin | : Iterator pointing to the beginning of the input sequence
End | : Iterator pointing to the end of the input sequence
Output | : Iterator pointing to the beginning of the output sequence
Replacement | : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
Returns:
Iterator to the end of the output sequence which has been written

The documentation for this class was generated from the following files:
  • Unicode.hpp
  • Unicode.inl
  • Unicode.cpp


sf::Unicode Member List

This is the complete list of members for sf::Unicode, including all inherited members.

ANSIToUTF32(In Begin, In End, Out Output, const std::locale &Locale=GetDefaultLocale()) | sf::Unicode | [inline, static]
ANSIToUTF32(In Begin, In End, Out Output, const std::locale &Locale) | sf::Unicode | [inline]
GetUTF16Length(In Begin, In End) | sf::Unicode | [inline, static]
GetUTF16Length(In Begin, In End) | sf::Unicode | [inline]
GetUTF32Length(In Begin, In End) | sf::Unicode | [inline, static]
GetUTF32Length(In Begin, In End) | sf::Unicode | [inline]
GetUTF8Length(In Begin, In End) | sf::Unicode | [inline, static]
GetUTF8Length(In Begin, In End) | sf::Unicode | [inline]
UTF16String typedef (defined in sf::Unicode) | sf::Unicode |
UTF16ToUTF32(In Begin, In End, Out Output, Uint32 Replacement= '?') | sf::Unicode | [inline, static]
UTF16ToUTF32(In Begin, In End, Out Output, Uint32 Replacement) | sf::Unicode | [inline]
UTF16ToUTF8(In Begin, In End, Out Output, Uint8 Replacement= '?') | sf::Unicode | [inline, static]
UTF16ToUTF8(In Begin, In End, Out Output, Uint8 Replacement) | sf::Unicode | [inline]
UTF32String typedef (defined in sf::Unicode) | sf::Unicode |
UTF32ToANSI(In Begin, In End, Out Output, char Replacement= '?', const std::locale &Locale=GetDefaultLocale()) | sf::Unicode | [inline, static]
UTF32ToANSI(In Begin, In End, Out Output, char Replacement, const std::locale &Locale) | sf::Unicode | [inline]
UTF32ToUTF16(In Begin, In End, Out Output, Uint16 Replacement= '?') | sf::Unicode | [inline, static]
UTF32ToUTF16(In Begin, In End, Out Output, Uint16 Replacement) | sf::Unicode | [inline]
UTF32ToUTF8(In Begin, In End, Out Output, Uint8 Replacement= '?') | sf::Unicode | [inline, static]
UTF32ToUTF8(In Begin, In End, Out Output, Uint8 Replacement) | sf::Unicode | [inline]
UTF8String typedef | sf::Unicode |
UTF8ToUTF16(In Begin, In End, Out Output, Uint16 Replacement= '?') | sf::Unicode | [inline, static]
UTF8ToUTF16(In Begin, In End, Out Output, Uint16 Replacement) | sf::Unicode | [inline]
UTF8ToUTF32(In Begin, In End, Out Output, Uint32 Replacement= '?') | sf::Unicode | [inline, static]
UTF8ToUTF32(In Begin, In End, Out Output, Uint32 Replacement) | sf::Unicode | [inline]


sf::Unicode::Text

sf::Unicode::Unicode::Text Class Reference

This class is an abstract definition of a unicode text, it can be converted from and to any kind of string and encoding. More...

#include <Unicode.hpp>

List of all members.

Public Member Functions

Text ()
Default constructor (empty text).
Text (const char *Str)
Construct the unicode text from any type of string.
Text (const wchar_t *Str)
Text (const Uint8 *Str)
Text (const Uint16 *Str)
Text (const Uint32 *Str)
Text (const std::string &Str)
Text (const std::wstring &Str)
Text (const Unicode::UTF8String &Str)
Text (const Unicode::UTF16String &Str)
Text (const Unicode::UTF32String &Str)
operator std::string () const
Operator to cast the text to any type of string.
operator std::wstring () const
operator Unicode::UTF8String () const
operator Unicode::UTF16String () const
operator const Unicode::UTF32String & () const

Detailed Description

This class is an abstract definition of a unicode text, it can be converted from and to any kind of string and encoding.

Definition at line 63 of file Unicode.hpp.

Constructor & Destructor Documentation

sf::Unicode::Unicode::Text::Text ( )

Default constructor (empty text).

Definition at line 105 of file Unicode.cpp.

sf::Unicode::Unicode::Text::Text ( const char * Str )

Construct the unicode text from any type of string.

Parameters:
Str : String to convert

Definition at line 114 of file Unicode.cpp.

Member Function Documentation

sf::Unicode::Unicode::Text::operator std::string ( ) const

Operator to cast the text to any type of string.

Returns:
Converted string

Definition at line 227 of file Unicode.cpp.

The documentation for this class was generated from the following files:
  • Unicode.hpp
  • Unicode.cpp


sf::Unicode::Unicode::Text Member List

This is the complete list of members for sf::Unicode::Unicode::Text, including all inherited members.

operator const Unicode::UTF32String &() const (defined in sf::Unicode::Unicode::Text) | sf::Unicode::Unicode::Text
operator std::string() const | sf::Unicode::Unicode::Text
operator std::wstring() const (defined in sf::Unicode::Unicode::Text) | sf::Unicode::Unicode::Text
operator Unicode::UTF16String() const (defined in sf::Unicode::Unicode::Text) | sf::Unicode::Unicode::Text
operator Unicode::UTF8String() const (defined in sf::Unicode::Unicode::Text) | sf::Unicode::Unicode::Text
Text() | sf::Unicode::Unicode::Text
Text(const char *Str) | sf::Unicode::Unicode::Text
Text(const wchar_t *Str) (defined in sf::Unicode::Unicode::Text) | sf::Unicode::Unicode::Text
Text(const Uint8 *Str) (defined in sf::Unicode::Unicode::Text) | sf::Unicode::Unicode::Text
Text(const Uint16 *Str) (defined in sf::Unicode::Unicode::Text) | sf::Unicode::Unicode::Text
Text(const Uint32 *Str) (defined in sf::Unicode::Unicode::Text) | sf::Unicode::Unicode::Text
Text(const std::string &Str) (defined in sf::Unicode::Unicode::Text) | sf::Unicode::Unicode::Text
Text(const std::wstring &Str) (defined in sf::Unicode::Unicode::Text) | sf::Unicode::Unicode::Text
Text(const Unicode::UTF8String &Str) (defined in sf::Unicode::Unicode::Text) | sf::Unicode::Unicode::Text
Text(const Unicode::UTF16String &Str) (defined in sf::Unicode::Unicode::Text) | sf::Unicode::Unicode::Text
Text(const Unicode::UTF32String &Str) (defined in sf::Unicode::Unicode::Text) | sf::Unicode::Unicode::Text


sf::Vector2

sf::Vector2< T > Class Template Reference

Vector2 is an utility class for manipulating 2 dimensional vectors. More...

#include <Vector2.hpp>

List of all members.

Public Member Functions

Vector2 ()
Default constructor.
Vector2 (T X, T Y)
Construct the vector from its coordinates.

Public Attributes

T | x
X coordinate of the vector.
T | y
Y coordinate of the vector.

Detailed Description

template<typename T>
class sf::Vector2< T >

Vector2 is an utility class for manipulating 2 dimensional vectors.

Template parameter defines the type of coordinates (integer, float, ...)

Definition at line 37 of file Vector2.hpp.

Constructor & Destructor Documentation

template<typename T>
sf::Vector2< T >::Vector2 ( )

Default constructor.

template<typename T>
sf::Vector2< T >::Vector2 | ( | T | X,
 |  | T | Y
 | ) |  |

Construct the vector from its coordinates.

Parameters:
X | : X coordinate
Y | : Y coordinate

Member Data Documentation

template<typename T>
T sf::Vector2< T >::x

X coordinate of the vector.

Definition at line 59 of file Vector2.hpp.

template<typename T>
T sf::Vector2< T >::y

Y coordinate of the vector.

Definition at line 60 of file Vector2.hpp.

The documentation for this class was generated from the following file:
  • Vector2.hpp


sf::Vector2< T > Member List

This is the complete list of members for sf::Vector2< T >, including all inherited members.

Vector2() | sf::Vector2< T >
Vector2(T X, T Y) | sf::Vector2< T >
x | sf::Vector2< T >
y | sf::Vector2< T >


sf::Vector3

sf::Vector3< T > Class Template Reference

Vector3 is an utility class for manipulating 3 dimensional vectors. More...

#include <Vector3.hpp>

List of all members.

Public Member Functions

Vector3 ()
Default constructor.
Vector3 (T X, T Y, T Z)
Construct the vector from its coordinates.

Public Attributes

T | x
X coordinate of the vector.
T | y
Y coordinate of the vector.
T | z
Z coordinate of the vector.

Detailed Description

template<typename T>
class sf::Vector3< T >

Vector3 is an utility class for manipulating 3 dimensional vectors.

Template parameter defines the type of coordinates (integer, float, ...)

Definition at line 37 of file Vector3.hpp.

Constructor & Destructor Documentation

template<typename T>
sf::Vector3< T >::Vector3 ( )

Default constructor.

template<typename T>
sf::Vector3< T >::Vector3 | ( | T | X,
 |  | T | Y,
 |  | T | Z
 | ) |  |

Construct the vector from its coordinates.

Parameters:
X | : X coordinate
Y | : Y coordinate
Z | : Z coordinate

Member Data Documentation

template<typename T>
T sf::Vector3< T >::x

X coordinate of the vector.

Definition at line 60 of file Vector3.hpp.

template<typename T>
T sf::Vector3< T >::y

Y coordinate of the vector.

Definition at line 61 of file Vector3.hpp.

template<typename T>
T sf::Vector3< T >::z

Z coordinate of the vector.

Definition at line 62 of file Vector3.hpp.

The documentation for this class was generated from the following file:
  • Vector3.hpp


sf::Vector3< T > Member List

This is the complete list of members for sf::Vector3< T >, including all inherited members.

Vector3() | sf::Vector3< T >
Vector3(T X, T Y, T Z) | sf::Vector3< T >
x | sf::Vector3< T >
y | sf::Vector3< T >
z | sf::Vector3< T >


sf::VideoMode

sf::VideoMode Class Reference

VideoMode defines a video mode (width, height, bpp, frequency) and provides static functions for getting modes supported by the display device. More...

#include <VideoMode.hpp>

List of all members.

Public Member Functions

VideoMode ()
Default constructor.
VideoMode (unsigned int ModeWidth, unsigned int ModeHeight, unsigned int ModeBpp=32)
Construct the video mode with its attributes.
bool | IsValid () const
Tell whether or not the video mode is supported.
bool | operator== (const VideoMode &Other) const
Comparison operator overload -- tell if two video modes are equal.
bool | operator!= (const VideoMode &Other) const
Comparison operator overload -- tell if two video modes are different.

Static Public Member Functions

static VideoMode | GetDesktopMode ()
Get the current desktop video mode.
static VideoMode | GetMode (std::size_t Index)
Get a valid video mode Index must be in range [0, GetModesCount()[ Modes are sorted from best to worst.
static std::size_t | GetModesCount ()
Get valid video modes count.

Public Attributes

unsigned int | Width
Video mode width, in pixels.
unsigned int | Height
Video mode height, in pixels.
unsigned int | BitsPerPixel
Video mode pixel depth, in bits per pixels.

Detailed Description

VideoMode defines a video mode (width, height, bpp, frequency) and provides static functions for getting modes supported by the display device.

Definition at line 42 of file VideoMode.hpp.

Constructor & Destructor Documentation

sf::VideoMode::VideoMode ( )

Default constructor.

Definition at line 67 of file VideoMode.cpp.

sf::VideoMode::VideoMode | ( | unsigned int | ModeWidth,
 |  | unsigned int | ModeHeight,
 |  | unsigned int | ModeBpp = 32
 | ) |  |

Construct the video mode with its attributes.

Parameters:
ModeWidth | : Width in pixels
ModeHeight | : Height in pixels
ModeBpp | : Pixel depths in bits per pixel (32 by default)

Definition at line 79 of file VideoMode.cpp.

Member Function Documentation

VideoMode sf::VideoMode::GetDesktopMode ( ) [static]

Get the current desktop video mode.

Returns:
Current desktop video mode

Definition at line 91 of file VideoMode.cpp.

VideoMode sf::VideoMode::GetMode ( std::size_t Index ) [static]

Get a valid video mode Index must be in range [0, GetModesCount()[ Modes are sorted from best to worst.

Get a valid video mode Index must be in range [0, GetModesCount()[.

Parameters:
Index : Index of video mode to get
Returns:
Corresponding video mode (invalid mode if index is out of range)

Definition at line 102 of file VideoMode.cpp.

std::size_t sf::VideoMode::GetModesCount ( ) [static]

Get valid video modes count.

Returns:
Number of valid video modes available

Definition at line 117 of file VideoMode.cpp.

bool sf::VideoMode::IsValid ( ) const

Tell whether or not the video mode is supported.

Returns:
True if video mode is supported, false otherwise

Definition at line 129 of file VideoMode.cpp.

bool sf::VideoMode::operator!= ( const VideoMode & Other ) const

Comparison operator overload -- tell if two video modes are different.

Parameters:
Other : Video mode to compare
Returns:
True if modes are different

Definition at line 152 of file VideoMode.cpp.

bool sf::VideoMode::operator== ( const VideoMode & Other ) const

Comparison operator overload -- tell if two video modes are equal.

Parameters:
Other : Video mode to compare
Returns:
True if modes are equal

Definition at line 141 of file VideoMode.cpp.

Member Data Documentation

unsigned int sf::VideoMode::BitsPerPixel

Video mode pixel depth, in bits per pixels.

Definition at line 123 of file VideoMode.hpp.

unsigned int sf::VideoMode::Height

Video mode height, in pixels.

Definition at line 122 of file VideoMode.hpp.

unsigned int sf::VideoMode::Width

Video mode width, in pixels.

Definition at line 121 of file VideoMode.hpp.

The documentation for this class was generated from the following files:
  • VideoMode.hpp
  • VideoMode.cpp


sf::VideoMode Member List

This is the complete list of members for sf::VideoMode, including all inherited members.

BitsPerPixel | sf::VideoMode |
GetDesktopMode() | sf::VideoMode | [static]
GetMode(std::size_t Index) | sf::VideoMode | [static]
GetModesCount() | sf::VideoMode | [static]
Height | sf::VideoMode |
IsValid() const | sf::VideoMode |
operator!=(const VideoMode &Other) const | sf::VideoMode |
operator==(const VideoMode &Other) const | sf::VideoMode |
VideoMode() | sf::VideoMode |
VideoMode(unsigned int ModeWidth, unsigned int ModeHeight, unsigned int ModeBpp=32) | sf::VideoMode |
Width | sf::VideoMode |


sf::View

sf::View Class Reference

This class defines a view (position, size, etc. More...

#include <View.hpp>

List of all members.

Public Member Functions

View (const FloatRect &ViewRect=FloatRect(0, 0, 1000, 1000))
Construct the view from a rectangle.
View (const sf::Vector2f &Center, const sf::Vector2f &HalfSize)
Construct the view from its center and half-size.
void | SetCenter (float X, float Y)
Change the center of the view (take 2 values).
void | SetCenter (const sf::Vector2f &Center)
Change the center of the view (take a vector).
void | SetHalfSize (float HalfWidth, float HalfHeight)
Change the half-size of the view (take 2 values).
void | SetHalfSize (const sf::Vector2f &HalfSize)
Change the half-size of the view (take a vector).
void | SetFromRect (const FloatRect &ViewRect)
Rebuild the view from a rectangle.
const sf::Vector2f & | GetCenter () const
Get the center of the view.
const sf::Vector2f & | GetHalfSize () const
Get the half-size of the view.
const sf::FloatRect & | GetRect () const
Get the bounding rectangle of the view.
void | Move (float OffsetX, float OffsetY)
Move the view (take 2 values).
void | Move (const sf::Vector2f &Offset)
Move the view (take a vector).
void | Zoom (float Factor)
Resize the view rectangle to simulate a zoom / unzoom effect.

Friends

class | RenderTarget

Detailed Description

This class defines a view (position, size, etc.

) ; you can consider it as a 2D camera

Definition at line 45 of file View.hpp.

Constructor & Destructor Documentation

sf::View::View ( const FloatRect & ViewRect = FloatRect(0, 0, 1000, 1000) ) [explicit]

Construct the view from a rectangle.

Parameters:
ViewRect : Rectangle defining the position and size of the view (1000x1000 by default)

Definition at line 37 of file View.cpp.

sf::View::View | ( | const sf::Vector2f & | Center,
 |  | const sf::Vector2f & | HalfSize
 | ) |  |

Construct the view from its center and half-size.

Parameters:
Center | : Center of the view
HalfSize | : Half-size of the view (from center to corner)

Definition at line 46 of file View.cpp.

Member Function Documentation

const sf::Vector2f & sf::View::GetCenter ( ) const

Get the center of the view.

Returns:
Center of the view

Definition at line 108 of file View.cpp.

const sf::Vector2f & sf::View::GetHalfSize ( ) const

Get the half-size of the view.

Returns:
Half-size of the view

Definition at line 117 of file View.cpp.

const sf::FloatRect & sf::View::GetRect ( ) const

Get the bounding rectangle of the view.

Returns:
Bounding rectangle of the view

Definition at line 126 of file View.cpp.

void sf::View::Move ( const sf::Vector2f & Offset )

Move the view (take a vector).

Parameters:
Offset : Offset to move the view

Definition at line 150 of file View.cpp.

void sf::View::Move | ( | float | OffsetX,
 |  | float | OffsetY
 | ) |  |

Move the view (take 2 values).

Parameters:
OffsetX | : Offset to move the view, on X axis
OffsetY | : Offset to move the view, on Y axis

Definition at line 139 of file View.cpp.

void sf::View::SetCenter ( const sf::Vector2f & Center )

Change the center of the view (take a vector).

Parameters:
Center : New center

Definition at line 69 of file View.cpp.

void sf::View::SetCenter | ( | float | X,
 |  | float | Y
 | ) |  |

Change the center of the view (take 2 values).

Parameters:
X | : X coordinate of the new center
Y | : Y coordinate of the new center

Definition at line 58 of file View.cpp.

void sf::View::SetFromRect ( const FloatRect & ViewRect )

Rebuild the view from a rectangle.

Parameters:
ViewRect : Rectangle defining the position and size of the view

Definition at line 98 of file View.cpp.

void sf::View::SetHalfSize ( const sf::Vector2f & HalfSize )

Change the half-size of the view (take a vector).

Parameters:
HalfSize : New half-size

Definition at line 89 of file View.cpp.

void sf::View::SetHalfSize | ( | float | HalfWidth,
 |  | float | HalfHeight
 | ) |  |

Change the half-size of the view (take 2 values).

Parameters:
HalfWidth | : New half-width
HalfHeight | : New half-height

Definition at line 78 of file View.cpp.

void sf::View::Zoom ( float Factor )

Resize the view rectangle to simulate a zoom / unzoom effect.

Parameters:
Factor : Zoom factor to apply, relative to the current zoom

Definition at line 159 of file View.cpp.

The documentation for this class was generated from the following files:
  • View.hpp
  • View.cpp


sf::View Member List

This is the complete list of members for sf::View, including all inherited members.

GetCenter() const | sf::View |
GetHalfSize() const | sf::View |
GetRect() const | sf::View |
Move(float OffsetX, float OffsetY) | sf::View |
Move(const sf::Vector2f &Offset) | sf::View |
RenderTarget (defined in sf::View) | sf::View | [friend]
SetCenter(float X, float Y) | sf::View |
SetCenter(const sf::Vector2f &Center) | sf::View |
SetFromRect(const FloatRect &ViewRect) | sf::View |
SetHalfSize(float HalfWidth, float HalfHeight) | sf::View |
SetHalfSize(const sf::Vector2f &HalfSize) | sf::View |
View(const FloatRect &ViewRect=FloatRect(0, 0, 1000, 1000)) | sf::View | [explicit]
View(const sf::Vector2f &Center, const sf::Vector2f &HalfSize) | sf::View |
Zoom(float Factor) | sf::View |


sf::Window

sf::Window Class Reference

Window is a rendering window ; it can create a new window or connect to an existing one. More...

#include <Window.hpp>

Inheritance diagram for sf::Window:

sf::WindowListener sf::NonCopyable sf::RenderWindow

List of all members.

Public Member Functions

Window ()
Default constructor.
Window (VideoMode Mode, const std::string &Title, unsigned long WindowStyle=Style::Resize|Style::Close, const WindowSettings &Params=WindowSettings())
Construct a new window.
Window (WindowHandle Handle, const WindowSettings &Params=WindowSettings())
Construct the window from an existing control.
virtual | ~Window ()
Destructor.
void | Create (VideoMode Mode, const std::string &Title, unsigned long WindowStyle=Style::Resize|Style::Close, const WindowSettings &Params=WindowSettings())
Create (or recreate) the window.
void | Create (WindowHandle Handle, const WindowSettings &Params=WindowSettings())
Create (or recreate) the window from an existing control.
void | Close ()
Close (destroy) the window.
bool | IsOpened () const
Tell whether or not the window is opened (ie.
unsigned int | GetWidth () const
Get the width of the rendering region of the window.
unsigned int | GetHeight () const
Get the height of the rendering region of the window.
const WindowSettings & | GetSettings () const
Get the creation settings of the window.
bool | GetEvent (Event &EventReceived)
Get the event on top of events stack, if any, and pop it.
void | UseVerticalSync (bool Enabled)
Enable / disable vertical synchronization.
void | ShowMouseCursor (bool Show)
Show or hide the mouse cursor.
void | SetCursorPosition (unsigned int Left, unsigned int Top)
Change the position of the mouse cursor.
void | SetPosition (int Left, int Top)
Change the position of the window on screen.
void | SetSize (unsigned int Width, unsigned int Height)
Change the size of the rendering region of the window.
void | Show (bool State)
Show or hide the window.
void | EnableKeyRepeat (bool Enabled)
Enable or disable automatic key-repeat.
void | SetIcon (unsigned int Width, unsigned int Height, const Uint8 *Pixels)
Change the window's icon.
bool | SetActive (bool Active=true) const
Activate of deactivate the window as the current target for rendering.
void | Display ()
Display the window on screen.
const Input & | GetInput () const
Get the input manager of the window.
void | SetFramerateLimit (unsigned int Limit)
Limit the framerate to a maximum fixed frequency.
float | GetFrameTime () const
Get time elapsed since last frame.
void | SetJoystickThreshold (float Threshold)
Change the joystick threshold, ie.

Detailed Description

Window is a rendering window ; it can create a new window or connect to an existing one.

Definition at line 55 of file Window/Window.hpp.

Constructor & Destructor Documentation

sf::Window::Window ( )

Default constructor.

Definition at line 49 of file Window.cpp.

sf::Window::Window | ( | VideoMode | Mode,
 |  | const std::string & | Title,
 |  | unsigned long | WindowStyle = Style::Resize | Style::Close,
 |  | const WindowSettings & | Params = WindowSettings()
 | ) |  |

Construct a new window.

Parameters:
Mode | : Video mode to use
Title | : Title of the window
WindowStyle | : Window style, see sf::Style (Resize | Close by default)
Params | : Creation parameters (see default constructor for default values)

Definition at line 64 of file Window.cpp.

sf::Window::Window | ( | WindowHandle | Handle,
 |  | const WindowSettings & | Params = WindowSettings()
 | ) |  |

Construct the window from an existing control.

Parameters:
Handle | : Platform-specific handle of the control
Params | : Creation parameters (see default constructor for default values)

Definition at line 79 of file Window.cpp.

sf::Window::~Window ( ) [virtual]

Destructor.

Definition at line 94 of file Window.cpp.

Member Function Documentation

void sf::Window::Close ( )

Close (destroy) the window.

The sf::Window instance remains valid and you can call Create to recreate the window

The sf::Window instance remains valid and you can call Create to recreate the window

Definition at line 165 of file Window.cpp.

void sf::Window::Create | ( | WindowHandle | Handle,
 |  | const WindowSettings & | Params = WindowSettings()
 | ) |  |

Create (or recreate) the window from an existing control.

Create the window from an existing control.

Parameters:
Handle | : Platform-specific handle of the control
Params | : Creation parameters (see default constructor for default values)

Definition at line 147 of file Window.cpp.

void sf::Window::Create | ( | VideoMode | Mode,
 |  | const std::string & | Title,
 |  | unsigned long | WindowStyle = Style::Resize | Style::Close,
 |  | const WindowSettings & | Params = WindowSettings()
 | ) |  |

Create (or recreate) the window.

Create the window.

Parameters:
Mode | : Video mode to use
Title | : Title of the window
WindowStyle | : Window style, see sf::Style (Resize | Close by default)
Params | : Creation parameters (see default constructor for default values)

Definition at line 104 of file Window.cpp.

void sf::Window::Display ( )

Display the window on screen.

Definition at line 353 of file Window.cpp.

void sf::Window::EnableKeyRepeat ( bool Enabled )

Enable or disable automatic key-repeat.

Automatic key-repeat is enabled by default

Parameters:
Enabled : True to enable, false to disable
Automatic key-repeat is enabled by default

Definition at line 317 of file Window.cpp.

bool sf::Window::GetEvent ( Event & EventReceived )

Get the event on top of events stack, if any, and pop it.

Get the event on top of events stack, if any.

Parameters:
EventReceived : Event to fill, if any
Returns:
True if an event was returned, false if events stack was empty

Definition at line 218 of file Window.cpp.

float sf::Window::GetFrameTime ( ) const

Get time elapsed since last frame.

Returns:
Time elapsed, in seconds

Definition at line 394 of file Window.cpp.

unsigned int sf::Window::GetHeight ( ) const

Get the height of the rendering region of the window.

Returns:
Height in pixels

Reimplemented in sf::RenderWindow.

Definition at line 200 of file Window.cpp.

const Input & sf::Window::GetInput ( ) const

Get the input manager of the window.

Returns:
Reference to the input

Definition at line 376 of file Window.cpp.

const WindowSettings & sf::Window::GetSettings ( ) const

Get the creation settings of the window.

Returns:
Structure containing the creation settings

Definition at line 209 of file Window.cpp.

unsigned int sf::Window::GetWidth ( ) const

Get the width of the rendering region of the window.

Returns:
Width in pixels

Reimplemented in sf::RenderWindow.

Definition at line 191 of file Window.cpp.

bool sf::Window::IsOpened ( ) const

Tell whether or not the window is opened (ie.

has been created). Note that a hidden window (Show(false)) will still return true

Returns:
True if the window is opened
has been created). Note that a hidden window (Show(false)) will still return true

Definition at line 182 of file Window.cpp.

bool sf::Window::SetActive ( bool Active = true ) const

Activate of deactivate the window as the current target for rendering.

Activate of deactivate the window as the current target for rendering.

Parameters:
Active : True to activate, false to deactivate (true by default)
Returns:
True if operation was successful, false otherwise

Definition at line 338 of file Window.cpp.

void sf::Window::SetCursorPosition | ( | unsigned int | Left,
 |  | unsigned int | Top
 | ) |  |

Change the position of the mouse cursor.

Parameters:
Left | : Left coordinate of the cursor, relative to the window
Top | : Top coordinate of the cursor, relative to the window

Definition at line 260 of file Window.cpp.

void sf::Window::SetFramerateLimit ( unsigned int Limit )

Limit the framerate to a maximum fixed frequency.

Set the framerate at a fixed frequency.

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

Definition at line 385 of file Window.cpp.

void sf::Window::SetIcon | ( | unsigned int | Width,
 |  | unsigned int | Height,
 |  | const Uint8 * | Pixels
 | ) |  |

Change the window's icon.

Parameters:
Width | : Icon's width, in pixels
Height | : Icon's height, in pixels
Pixels | : Pointer to the pixels in memory, format must be RGBA 32 bits

Definition at line 327 of file Window.cpp.

void sf::Window::SetJoystickThreshold ( float Threshold )

Change the joystick threshold, ie.

the value below which no move event will be generated

Parameters:
Threshold : New threshold, in range [0, 100]
the value below which no move event will be generated

Definition at line 404 of file Window.cpp.

void sf::Window::SetPosition | ( | int | Left,
 |  | int | Top
 | ) |  |

Change the position of the window on screen.

Only works for top-level windows

Parameters:
Left | : Left position
Top | : Top position

Definition at line 276 of file Window.cpp.

void sf::Window::SetSize | ( | unsigned int | Width,
 |  | unsigned int | Height
 | ) |  |

Change the size of the rendering region of the window.

Parameters:
Width | : New width
Height | : New height

Definition at line 293 of file Window.cpp.

void sf::Window::Show ( bool State )

Show or hide the window.

Parameters:
State : True to show, false to hide

Definition at line 303 of file Window.cpp.

void sf::Window::ShowMouseCursor ( bool Show )

Show or hide the mouse cursor.

Parameters:
Show : True to show, false to hide

Definition at line 250 of file Window.cpp.

void sf::Window::UseVerticalSync ( bool Enabled )

Enable / disable vertical synchronization.

Parameters:
Enabled : True to enable v-sync, false to deactivate

Definition at line 240 of file Window.cpp.

The documentation for this class was generated from the following files:
  • Window/Window.hpp
  • Window.cpp


sf::Window Member List

This is the complete list of members for sf::Window, including all inherited members.

Close() | sf::Window |
Create(VideoMode Mode, const std::string &Title, unsigned long WindowStyle=Style::Resize|Style::Close, const WindowSettings &Params=WindowSettings()) | sf::Window |
Create(WindowHandle Handle, const WindowSettings &Params=WindowSettings()) | sf::Window |
Display() | sf::Window |
EnableKeyRepeat(bool Enabled) | sf::Window |
GetEvent(Event &EventReceived) | sf::Window |
GetFrameTime() const | sf::Window |
GetHeight() const | sf::Window |
GetInput() const | sf::Window |
GetSettings() const | sf::Window |
GetWidth() const | sf::Window |
IsOpened() const | sf::Window |
NonCopyable() | sf::NonCopyable | [inline, private]
SetActive(bool Active=true) const | sf::Window |
SetCursorPosition(unsigned int Left, unsigned int Top) | sf::Window |
SetFramerateLimit(unsigned int Limit) | sf::Window |
SetIcon(unsigned int Width, unsigned int Height, const Uint8 *Pixels) | sf::Window |
SetJoystickThreshold(float Threshold) | sf::Window |
SetPosition(int Left, int Top) | sf::Window |
SetSize(unsigned int Width, unsigned int Height) | sf::Window |
Show(bool State) | sf::Window |
ShowMouseCursor(bool Show) | sf::Window |
UseVerticalSync(bool Enabled) | sf::Window |
Window() | sf::Window |
Window(VideoMode Mode, const std::string &Title, unsigned long WindowStyle=Style::Resize|Style::Close, const WindowSettings &Params=WindowSettings()) | sf::Window |
Window(WindowHandle Handle, const WindowSettings &Params=WindowSettings()) | sf::Window |
~Window() | sf::Window | [virtual]
~WindowListener() | sf::WindowListener | [inline, protected, virtual]


sf::WindowListener

sf::WindowListener Class Reference

Base class for classes that want to receive events from a window (for internal use only). More...

#include <WindowListener.hpp>

Inheritance diagram for sf::WindowListener:

sf::Input sf::Window sf::RenderWindow

List of all members.

Public Member Functions

virtual void | OnEvent (const Event &EventReceived)=0
Called each time an event is received from attached window.

Protected Member Functions

virtual | ~WindowListener ()
Destructor.

Detailed Description

Base class for classes that want to receive events from a window (for internal use only).

Definition at line 42 of file WindowListener.hpp.

Constructor & Destructor Documentation

virtual sf::WindowListener::~WindowListener ( ) [inline, protected, virtual]

Destructor.

Definition at line 60 of file WindowListener.hpp.

Member Function Documentation

virtual void sf::WindowListener::OnEvent ( const Event & EventReceived ) [pure virtual]

Called each time an event is received from attached window.

Parameters:
EventReceived : Event received

The documentation for this class was generated from the following file:
  • WindowListener.hpp


sf::WindowListener Member List

This is the complete list of members for sf::WindowListener, including all inherited members.

OnEvent(const Event &EventReceived)=0 | sf::WindowListener | [pure virtual]
~WindowListener() | sf::WindowListener | [inline, protected, virtual]


sf::WindowSettings

sf::WindowSettings Struct Reference

Structure defining the creation settings of windows. More...

#include <WindowSettings.hpp>

List of all members.

Public Member Functions

WindowSettings (unsigned int Depth=24, unsigned int Stencil=8, unsigned int Antialiasing=0)
Default constructor.

Public Attributes

unsigned int | DepthBits
Bits of the depth buffer.
unsigned int | StencilBits
Bits of the stencil buffer.
unsigned int | AntialiasingLevel
Level of antialiasing.

Detailed Description

Structure defining the creation settings of windows.

Definition at line 34 of file WindowSettings.hpp.

Constructor & Destructor Documentation

sf::WindowSettings::WindowSettings | ( | unsigned int | Depth = 24,
 |  | unsigned int | Stencil = 8,
 |  | unsigned int | Antialiasing = 0 |
 | ) |  |  | [inline, explicit]

Default constructor.

Parameters:
Depth | : Depth buffer bits (24 by default)
Stencil | : Stencil buffer bits (8 by default)
Antialiasing | : Antialiasing level (0 by default)

Definition at line 44 of file WindowSettings.hpp.

Member Data Documentation

unsigned int sf::WindowSettings::AntialiasingLevel

Level of antialiasing.

Definition at line 56 of file WindowSettings.hpp.

unsigned int sf::WindowSettings::DepthBits

Bits of the depth buffer.

Definition at line 54 of file WindowSettings.hpp.

unsigned int sf::WindowSettings::StencilBits

Bits of the stencil buffer.

Definition at line 55 of file WindowSettings.hpp.

The documentation for this struct was generated from the following file:
  • WindowSettings.hpp


sf::WindowSettings Member List

This is the complete list of members for sf::WindowSettings, including all inherited members.

AntialiasingLevel | sf::WindowSettings |
DepthBits | sf::WindowSettings |
StencilBits | sf::WindowSettings |
WindowSettings(unsigned int Depth=24, unsigned int Stencil=8, unsigned int Antialiasing=0) | sf::WindowSettings | [inline, explicit]


Class Hierarchy

This inheritance list is sorted roughly, but not completely, alphabetically:
  • sf::AudioResource
    • sf::Sound
      • sf::SoundStream
        • sf::Music
    • sf::SoundBuffer
  • sf::Clock
  • sf::Color
  • sf::Drawable
    • sf::PostFX
    • sf::Shape
    • sf::Sprite
    • sf::String
  • sf::Event
  • sf::Event::Event::JoyButtonEvent
  • sf::Event::Event::JoyMoveEvent
  • sf::Event::Event::KeyEvent
  • sf::Event::Event::MouseButtonEvent
  • sf::Event::Event::MouseMoveEvent
  • sf::Event::Event::MouseWheelEvent
  • sf::Event::Event::SizeEvent
  • sf::Event::Event::TextEvent
  • sf::Ftp::Ftp::Response
    • sf::Ftp::Ftp::DirectoryResponse
    • sf::Ftp::Ftp::ListingResponse
  • sf::Glyph
  • sf::Http::Http::Request
  • sf::Http::Http::Response
  • sf::IPAddress
  • sf::Listener
  • sf::Matrix3
  • sf::NonCopyable
    • sf::Context
    • sf::Ftp
    • sf::Http
    • sf::Input
    • sf::Lock
    • sf::Mutex
    • sf::Thread
      • sf::SoundRecorder
        • sf::SoundBufferRecorder
      • sf::SoundStream
    • sf::Window
      • sf::RenderWindow
  • sf::Packet
  • sf::Randomizer
  • sf::Rect< T >
  • sf::RenderTarget
    • sf::RenderWindow
  • sf::Resource< T >
  • sf::Resource< Font >
    • sf::Font
  • sf::Resource< Image >
    • sf::Image
  • sf::Resource< SoundBuffer >
    • sf::SoundBuffer
  • sf::ResourcePtr< T >
  • sf::SelectorBase
    • sf::Selector< Type >
  • sf::SocketHelper
  • sf::SocketTCP
  • sf::SocketUDP
  • sf::SoundStream::SoundStream::Chunk
  • sf::Unicode
  • sf::Unicode::Unicode::Text
  • sf::Vector2< T >
  • sf::Vector3< T >
  • sf::VideoMode
  • sf::View
  • sf::WindowListener
    • sf::Input
    • sf::Window
  • sf::WindowSettings


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- a -

  • a : sf::Color
  • Accept() : sf::SocketTCP
  • Accepted : sf::Http::Http::Response
  • Add()
: sf::Selector< Type >
, sf::SelectorBase
  • AddPoint() : sf::Shape
  • Advance : sf::Glyph
  • ANSIToUTF32() : sf::Unicode
  • AntialiasingLevel : sf::WindowSettings
  • Append() : sf::Packet
  • Ascii : sf::Ftp
  • AudioResource() : sf::AudioResource


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- k -

  • KeepAlive() : sf::Ftp


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- l -

  • Launch() : sf::Thread
  • Left : sf::Rect< T >
  • Line() : sf::Shape
  • Listen() : sf::SocketTCP
  • ListingResponse() : sf::Ftp::Ftp::ListingResponse
  • LoadFromFile()
: sf::Font
, sf::Image
, sf::PostFX
, sf::SoundBuffer
  • LoadFromMemory()
: sf::SoundBuffer
, sf::Font
, sf::Image
, sf::PostFX
  • LoadFromPixels() : sf::Image
  • LoadFromSamples() : sf::SoundBuffer
  • LocalError : sf::Ftp::Ftp::Response
  • LocalHost : sf::IPAddress
  • Lock()
: sf::Lock
, sf::Mutex
  • LoggedIn : sf::Ftp::Ftp::Response
  • Login() : sf::Ftp


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- m -

  • Magenta : sf::Color
  • MakeDirectory() : sf::Ftp
  • Matrix3() : sf::Matrix3
  • Method : sf::Http::Http::Request
  • Move()
: sf::View
, sf::Drawable
  • MovedPermanently : sf::Http::Http::Response
  • MovedTemporarily : sf::Http::Http::Response
  • MultipleChoices : sf::Http::Http::Response
  • Music() : sf::Music
  • Mutex() : sf::Mutex


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- n -

  • NbSamples : sf::SoundStream::SoundStream::Chunk
  • NeedAccountToLogIn : sf::Ftp::Ftp::Response
  • NeedAccountToStore : sf::Ftp::Ftp::Response
  • NeedInformation : sf::Ftp::Ftp::Response
  • NeedPassword : sf::Ftp::Ftp::Response
  • NoContent : sf::Http::Http::Response
  • NonCopyable() : sf::NonCopyable
  • NotEnoughMemory : sf::Ftp::Ftp::Response
  • NotFound : sf::Http::Http::Response
  • NotImplemented : sf::Http::Http::Response
  • NotLoggedIn : sf::Ftp::Ftp::Response
  • NotModified : sf::Http::Http::Response


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- o -

  • Offset() : sf::Rect< T >
  • Ok : sf::Ftp::Ftp::Response , sf::Http::Http::Response
  • OnEvent() : sf::WindowListener
  • OnResourceDestroyed() : sf::ResourcePtr< T >
  • OpenFromFile() : sf::Music
  • OpenFromMemory() : sf::Music
  • OpeningDataConnection : sf::Ftp::Ftp::Response
  • operator bool() : sf::Packet
  • operator const T *() : sf::ResourcePtr< T >
  • operator std::string() : sf::Unicode::Unicode::Text
  • operator!=()
: sf::VideoMode
, sf::Color
, sf::IPAddress
, sf::SocketTCP
, sf::SocketUDP
  • operator()() : sf::Matrix3
  • operator*() : sf::Matrix3 , sf::ResourcePtr< T >
  • operator*=()
: sf::Color
, sf::Matrix3
  • operator+=() : sf::Color
  • operator->() : sf::ResourcePtr< T >
  • operator<()
: sf::IPAddress
, sf::SocketTCP
, sf::SocketUDP
  • operator<<() : sf::Packet
  • operator<=() : sf::IPAddress
  • operator=()
: sf::PostFX
, sf::Image
, sf::Resource< T >
, sf::ResourcePtr< T >
, sf::Sound
, sf::SoundBuffer
  • operator==()
: sf::IPAddress
, sf::SocketUDP
, sf::SocketTCP
, sf::Color
, sf::VideoMode
  • operator>() : sf::IPAddress
  • operator>=() : sf::IPAddress
  • operator>>() : sf::Packet


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- z -

  • z : sf::Vector3< T >
  • Zoom() : sf::View


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- ~ -

  • ~AudioResource() : sf::AudioResource
  • ~Context() : sf::Context
  • ~Drawable() : sf::Drawable
  • ~Ftp() : sf::Ftp
  • ~Image() : sf::Image
  • ~Lock() : sf::Lock
  • ~Music() : sf::Music
  • ~Mutex() : sf::Mutex
  • ~Packet() : sf::Packet
  • ~PostFX() : sf::PostFX
  • ~RenderTarget() : sf::RenderTarget
  • ~RenderWindow() : sf::RenderWindow
  • ~Resource() : sf::Resource< T >
  • ~ResourcePtr() : sf::ResourcePtr< T >
  • ~Sound() : sf::Sound
  • ~SoundBuffer() : sf::SoundBuffer
  • ~SoundRecorder() : sf::SoundRecorder
  • ~SoundStream() : sf::SoundStream
  • ~Thread() : sf::Thread
  • ~Window() : sf::Window
  • ~WindowListener() : sf::WindowListener


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- b -

  • b : sf::Color
  • BadCommandSequence : sf::Ftp::Ftp::Response
  • BadGateway : sf::Http::Http::Response
  • BadRequest : sf::Http::Http::Response
  • Binary : sf::Ftp
  • Bind()
: sf::Image
, sf::SocketUDP
  • BitsPerPixel : sf::VideoMode
  • Black : sf::Color
  • Blue : sf::Color
  • Bold : sf::String
  • Bottom : sf::Rect< T >


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- c -

  • CanCapture() : sf::SoundRecorder
  • CanUsePostFX() : sf::PostFX
  • Capture() : sf::RenderWindow
  • ChangeDirectory() : sf::Ftp
  • Circle() : sf::Shape
  • Clear()
: sf::Packet
, sf::Selector< Type >
, sf::SelectorBase
, sf::RenderTarget
  • Clock() : sf::Clock
  • Close()
: sf::SocketTCP
, sf::SocketUDP
, sf::SocketHelper
, sf::Window
  • ClosingConnection : sf::Ftp::Ftp::Response
  • ClosingDataConnection : sf::Ftp::Ftp::Response
  • Color() : sf::Color
  • CommandNotImplemented : sf::Ftp::Ftp::Response
  • CommandUnknown : sf::Ftp::Ftp::Response
  • Connect()
: sf::SocketTCP
, sf::Ftp
  • ConnectionClosed : sf::Ftp::Ftp::Response
  • ConnectionFailed : sf::Ftp::Ftp::Response , sf::Http::Http::Response
  • Contains() : sf::Rect< T >
  • Context() : sf::Context
  • ConvertCoords() : sf::RenderWindow
  • Copy() : sf::Image
  • CopyScreen() : sf::Image
  • Create()
: sf::Window
, sf::Image
, sf::Window
  • Created : sf::Http::Http::Response
  • CreateMaskFromColor() : sf::Image
  • Cyan : sf::Color


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- d -

  • DataConnectionAlreadyOpened : sf::Ftp::Ftp::Response
  • DataConnectionOpened : sf::Ftp::Ftp::Response
  • DataConnectionUnavailable : sf::Ftp::Ftp::Response
  • DeleteDirectory() : sf::Ftp
  • DeleteFile() : sf::Ftp
  • DepthBits : sf::WindowSettings
  • DirectoryOk : sf::Ftp::Ftp::Response
  • DirectoryResponse() : sf::Ftp::Ftp::DirectoryResponse
  • DirectoryStatus : sf::Ftp::Ftp::Response
  • Disconnect() : sf::Ftp
  • Display() : sf::Window
  • Download() : sf::Ftp
  • Draw() : sf::RenderTarget
  • Drawable() : sf::Drawable


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- e -

  • Ebcdic : sf::Ftp
  • EnableFill() : sf::Shape
  • EnableKeyRepeat() : sf::Window
  • EnableOutline() : sf::Shape
  • EndOfPacket() : sf::Packet
  • EnteringPassiveMode : sf::Ftp::Ftp::Response
  • EventType : sf::Event


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- f -

  • FileActionAborted : sf::Ftp::Ftp::Response
  • FileActionOk : sf::Ftp::Ftp::Response
  • FilenameNotAllowed : sf::Ftp::Ftp::Response
  • FileStatus : sf::Ftp::Ftp::Response
  • FileUnavailable : sf::Ftp::Ftp::Response
  • FlipX() : sf::Sprite
  • FlipY() : sf::Sprite
  • Font() : sf::Font
  • Forbidden : sf::Http::Http::Response


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- g -

  • g : sf::Color
  • Get : sf::Http::Http::Request
  • Get4x4Elements() : sf::Matrix3
  • GetAttenuation() : sf::Sound
  • GetBlendMode() : sf::Drawable
  • GetBody() : sf::Http::Http::Response
  • GetBuffer()
: sf::SoundBufferRecorder
, sf::Sound
  • GetCenter()
: sf::Drawable
, sf::View
  • GetChannelsCount()
: sf::SoundBuffer
, sf::SoundStream
  • GetCharacterPos() : sf::String
  • GetCharacterSize() : sf::Font
  • GetColor() : sf::Drawable
  • GetCount() : sf::Ftp::Ftp::ListingResponse
  • GetData() : sf::Packet
  • GetDataSize() : sf::Packet
  • GetDefaultFont() : sf::Font
  • GetDefaultView() : sf::RenderTarget
  • GetDesktopMode() : sf::VideoMode
  • GetDirectory() : sf::Ftp::Ftp::DirectoryResponse
  • GetDirectoryListing() : sf::Ftp
  • GetDuration()
: sf::Music
, sf::SoundBuffer
  • GetElapsedTime() : sf::Clock
  • GetErrorStatus() : sf::SocketHelper
  • GetEvent() : sf::Window
  • GetField() : sf::Http::Http::Response
  • GetFilename() : sf::Ftp::Ftp::ListingResponse
  • GetFont() : sf::String
  • GetFrameTime() : sf::Window
  • GetGlobal() : sf::Context
  • GetGlobalVolume() : sf::Listener
  • GetGlyph() : sf::Font
  • GetHalfSize() : sf::View
  • GetHeight()
: sf::Image
, sf::Rect< T >
, sf::RenderTarget
, sf::RenderWindow
, sf::Window
  • GetImage()
: sf::Font
, sf::Sprite
  • GetInput() : sf::Window
  • GetInverse() : sf::Matrix3
  • GetInverseMatrix() : sf::Drawable
  • GetJoystickAxis() : sf::Input
  • GetLocalAddress() : sf::IPAddress
  • GetLoop()
: sf::Sound
, sf::SoundStream
  • GetMajorHttpVersion() : sf::Http::Http::Response
  • GetMatrix() : sf::Drawable
  • GetMessage() : sf::Ftp::Ftp::Response
  • GetMinDistance() : sf::Sound
  • GetMinorHttpVersion() : sf::Http::Http::Response
  • GetMode() : sf::VideoMode
  • GetModesCount() : sf::VideoMode
  • GetMouseX() : sf::Input
  • GetMouseY() : sf::Input
  • GetNbPoints() : sf::Shape
  • GetOutlineWidth() : sf::Shape
  • GetPitch() : sf::Sound
  • GetPixel()
: sf::Sprite
, sf::Image
  • GetPixelsPtr() : sf::Image
  • GetPlayingOffset()
: sf::Sound
, sf::SoundStream
  • GetPointColor() : sf::Shape
  • GetPointOutlineColor() : sf::Shape
  • GetPointPosition() : sf::Shape
  • GetPort() : sf::SocketUDP
  • GetPosition()
: sf::Listener
, sf::Sound
, sf::Drawable
  • GetPublicAddress() : sf::IPAddress
  • GetRect()
: sf::String
, sf::View
  • GetRotation() : sf::Drawable
  • GetSampleRate()
: sf::SoundRecorder
, sf::SoundStream
, sf::SoundBuffer
  • GetSamples() : sf::SoundBuffer
  • GetSamplesCount() : sf::SoundBuffer
  • GetScale() : sf::Drawable
  • GetSeed() : sf::Randomizer
  • GetSettings() : sf::Window
  • GetSize()
: sf::String
, sf::Sprite
  • GetSocketReady()
: sf::SelectorBase
, sf::Selector< Type >
  • GetStatus()
: sf::SoundStream
, sf::Ftp::Ftp::Response
, sf::Http::Http::Response
, sf::Sound
  • GetStyle() : sf::String
  • GetSubRect() : sf::Sprite
  • GetTarget() : sf::Listener
  • GetTexCoords() : sf::Image
  • GetText() : sf::String
  • GetUTF16Length() : sf::Unicode
  • GetUTF32Length() : sf::Unicode
  • GetUTF8Length() : sf::Unicode
  • GetValidTextureSize() : sf::Image
  • GetView() : sf::RenderTarget
  • GetVolume() : sf::Sound
  • GetWidth()
: sf::Window
, sf::Rect< T >
, sf::Image
, sf::RenderWindow
, sf::RenderTarget
  • GetWorkingDirectory() : sf::Ftp
  • Glyph() : sf::Glyph
  • Green : sf::Color


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- h -

  • Head : sf::Http::Http::Request
  • Height : sf::VideoMode
  • HelpMessage : sf::Ftp::Ftp::Response
  • Http() : sf::Http


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- i -

  • Identity : sf::Matrix3
  • Image() : sf::Image
  • Initialize()
: sf::SoundStream
, sf::RenderTarget
  • Input() : sf::Input
  • InsufficientStorageSpace : sf::Ftp::Ftp::Response
  • InternalServerError : sf::Http::Http::Response
  • Intersects() : sf::Rect< T >
  • InvalidFile : sf::Ftp::Ftp::Response
  • InvalidResponse : sf::Ftp::Ftp::Response , sf::Http::Http::Response
  • InvalidSocket() : sf::SocketHelper
  • IPAddress() : sf::IPAddress
  • IsContextActive() : sf::Context
  • IsJoystickButtonDown() : sf::Input
  • IsKeyDown() : sf::Input
  • IsMouseButtonDown() : sf::Input
  • IsOk() : sf::Ftp::Ftp::Response
  • IsOpened() : sf::Window
  • IsRelativeToListener() : sf::Sound
  • IsSmooth() : sf::Image
  • IsValid()
: sf::IPAddress
, sf::SocketTCP
, sf::SocketUDP
, sf::VideoMode
  • Italic : sf::String


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- p -

  • Packet() : sf::Packet
  • PageTypeUnknown : sf::Ftp::Ftp::Response
  • ParameterNotImplemented : sf::Ftp::Ftp::Response
  • ParametersUnknown : sf::Ftp::Ftp::Response
  • ParentDirectory() : sf::Ftp
  • Pause() : sf::Sound
  • Paused : sf::Sound
  • Play()
: sf::Sound
, sf::SoundStream
  • Playing : sf::Sound
  • PointlessCommand : sf::Ftp::Ftp::Response
  • Post : sf::Http::Http::Request
  • PostFX() : sf::PostFX
  • PreserveOpenGLStates() : sf::RenderTarget


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- r -

  • r : sf::Color
  • Random() : sf::Randomizer
  • Receive()
: sf::SocketTCP
, sf::SocketUDP
  • Rect() : sf::Rect< T >
  • Rectangle : sf::Glyph , sf::Shape
  • Red : sf::Color
  • Regular : sf::String
  • Remove()
: sf::SelectorBase
, sf::Selector< Type >
  • RenameFile() : sf::Ftp
  • Render()
: sf::PostFX
, sf::Shape
, sf::Sprite
, sf::String
  • RenderTarget() : sf::RenderTarget
  • RenderWindow() : sf::RenderWindow
  • Request() : sf::Http::Http::Request
  • Reset() : sf::Clock
  • ResetBuffer() : sf::Sound
  • Resize() : sf::Sprite
  • Resource() : sf::Resource< T >
  • ResourcePtr() : sf::ResourcePtr< T >
  • Response()
: sf::Ftp::Ftp::Response
, sf::Http::Http::Response
  • RestartMarkerReply : sf::Ftp::Ftp::Response
  • Right : sf::Rect< T >
  • Rotate() : sf::Drawable


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- s -

  • Samples : sf::SoundStream::SoundStream::Chunk
  • SaveToFile()
: sf::SoundBuffer
, sf::Image
  • Scale() : sf::Drawable
  • SelectorBase() : sf::SelectorBase
  • Send()
: sf::SocketTCP
, sf::SocketUDP
, sf::SocketTCP
  • SendRequest() : sf::Http
  • ServiceNotAvailable : sf::Http::Http::Response
  • ServiceReady : sf::Ftp::Ftp::Response
  • ServiceReadySoon : sf::Ftp::Ftp::Response
  • ServiceUnavailable : sf::Ftp::Ftp::Response
  • SetActive()
: sf::Context
, sf::Window
  • SetAttenuation() : sf::Sound
  • SetBlendMode() : sf::Drawable
  • SetBlocking()
: sf::SocketTCP
, sf::SocketUDP
, sf::SocketHelper
  • SetBody() : sf::Http::Http::Request
  • SetBuffer() : sf::Sound
  • SetCenter()
: sf::Drawable
, sf::View
  • SetColor() : sf::Drawable
  • SetCursorPosition() : sf::Window
  • SetField() : sf::Http::Http::Request
  • SetFont() : sf::String
  • SetFramerateLimit() : sf::Window
  • SetFromRect() : sf::View
  • SetFromTransformations() : sf::Matrix3
  • SetGlobalVolume() : sf::Listener
  • SetHalfSize() : sf::View
  • SetHost() : sf::Http
  • SetHttpVersion() : sf::Http::Http::Request
  • SetIcon() : sf::Window
  • SetImage() : sf::Sprite
  • SetJoystickThreshold() : sf::Window
  • SetLoop()
: sf::Sound
, sf::SoundStream
  • SetMethod() : sf::Http::Http::Request
  • SetMinDistance() : sf::Sound
  • SetOutlineWidth() : sf::Shape
  • SetParameter() : sf::PostFX
  • SetPitch() : sf::Sound
  • SetPixel() : sf::Image
  • SetPlayingOffset() : sf::Sound
  • SetPointColor() : sf::Shape
  • SetPointOutlineColor() : sf::Shape
  • SetPointPosition() : sf::Shape
  • SetPosition()
: sf::Drawable
, sf::Window
, sf::Sound
, sf::Listener
, sf::Sound
  • SetRelativeToListener() : sf::Sound
  • SetRotation() : sf::Drawable
  • SetScale() : sf::Drawable
  • SetScaleX() : sf::Drawable
  • SetScaleY() : sf::Drawable
  • SetSeed() : sf::Randomizer
  • SetSize()
: sf::String
, sf::Window
  • SetSmooth() : sf::Image
  • SetStyle() : sf::String
  • SetSubRect() : sf::Sprite
  • SetTarget() : sf::Listener
  • SetText() : sf::String
  • SetTexture() : sf::PostFX
  • SetURI() : sf::Http::Http::Request
  • SetView() : sf::RenderTarget
  • SetVolume() : sf::Sound
  • SetX() : sf::Drawable
  • SetY() : sf::Drawable
  • Shape() : sf::Shape
  • Show() : sf::Window
  • ShowMouseCursor() : sf::Window
  • SocketTCP() : sf::SocketTCP
  • SocketUDP() : sf::SocketUDP
  • Sound() : sf::Sound
  • SoundBuffer() : sf::SoundBuffer
  • SoundRecorder() : sf::SoundRecorder
  • SoundStream() : sf::SoundStream
  • Sprite() : sf::Sprite
  • Start() : sf::SoundRecorder
  • Status
: sf::Http::Http::Response
, sf::Sound
, sf::Ftp::Ftp::Response
  • StencilBits : sf::WindowSettings
  • Stop()
: sf::SoundStream
, sf::SoundRecorder
, sf::Sound
  • Stopped : sf::Sound
  • String() : sf::String
  • Style : sf::String
  • SystemStatus : sf::Ftp::Ftp::Response
  • SystemType : sf::Ftp::Ftp::Response


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- t -

  • Terminate() : sf::Thread
  • TexCoords : sf::Glyph
  • Text() : sf::Unicode::Unicode::Text
  • Thread() : sf::Thread
  • ToInteger() : sf::IPAddress
  • Top : sf::Rect< T >
  • ToString() : sf::IPAddress
  • TransferAborted : sf::Ftp::Ftp::Response
  • TransferMode : sf::Ftp
  • Transform() : sf::Matrix3
  • TransformToGlobal() : sf::Drawable
  • TransformToLocal() : sf::Drawable
  • Type : sf::Event


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- u -

  • Unauthorized : sf::Http::Http::Response
  • Unbind() : sf::SocketUDP
  • Underlined : sf::String
  • Unlock() : sf::Mutex
  • Upload() : sf::Ftp
  • UseVerticalSync() : sf::Window
  • UTF16ToUTF32() : sf::Unicode
  • UTF16ToUTF8() : sf::Unicode
  • UTF32ToANSI() : sf::Unicode
  • UTF32ToUTF16() : sf::Unicode
  • UTF32ToUTF8() : sf::Unicode
  • UTF8String : sf::Unicode
  • UTF8ToUTF16() : sf::Unicode
  • UTF8ToUTF32() : sf::Unicode


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- v -

  • Vector2() : sf::Vector2< T >
  • Vector3() : sf::Vector3< T >
  • VideoMode() : sf::VideoMode
  • View() : sf::View


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- w -

  • Wait()
: sf::Selector< Type >
, sf::SelectorBase
, sf::Thread
  • White : sf::Color
  • Width : sf::VideoMode
  • Window() : sf::Window
  • WindowSettings() : sf::WindowSettings


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- x -

  • x : sf::Vector2< T > , sf::Vector3< T >


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • ~
Here is a list of all documented class members with links to the class documentation for each member:

- y -

  • y : sf::Vector2< T > , sf::Vector3< T >
  • Yellow : sf::Color


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator

  • EventType : sf::Event
  • Method : sf::Http::Http::Request
  • Status
: sf::Sound
, sf::Ftp::Ftp::Response
, sf::Http::Http::Response
  • Style : sf::String
  • TransferMode : sf::Ftp


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u

- a -

  • Accepted : sf::Http::Http::Response
  • Ascii : sf::Ftp

- b -

  • BadCommandSequence : sf::Ftp::Ftp::Response
  • BadGateway : sf::Http::Http::Response
  • BadRequest : sf::Http::Http::Response
  • Binary : sf::Ftp
  • Bold : sf::String

- c -

  • ClosingConnection : sf::Ftp::Ftp::Response
  • ClosingDataConnection : sf::Ftp::Ftp::Response
  • CommandNotImplemented : sf::Ftp::Ftp::Response
  • CommandUnknown : sf::Ftp::Ftp::Response
  • ConnectionClosed : sf::Ftp::Ftp::Response
  • ConnectionFailed : sf::Ftp::Ftp::Response , sf::Http::Http::Response
  • Created : sf::Http::Http::Response

- d -

  • DataConnectionAlreadyOpened : sf::Ftp::Ftp::Response
  • DataConnectionOpened : sf::Ftp::Ftp::Response
  • DataConnectionUnavailable : sf::Ftp::Ftp::Response
  • DirectoryOk : sf::Ftp::Ftp::Response
  • DirectoryStatus : sf::Ftp::Ftp::Response

- e -

  • Ebcdic : sf::Ftp
  • EnteringPassiveMode : sf::Ftp::Ftp::Response

- f -

  • FileActionAborted : sf::Ftp::Ftp::Response
  • FileActionOk : sf::Ftp::Ftp::Response
  • FilenameNotAllowed : sf::Ftp::Ftp::Response
  • FileStatus : sf::Ftp::Ftp::Response
  • FileUnavailable : sf::Ftp::Ftp::Response
  • Forbidden : sf::Http::Http::Response

- g -

  • Get : sf::Http::Http::Request

- h -

  • Head : sf::Http::Http::Request
  • HelpMessage : sf::Ftp::Ftp::Response

- i -

  • InsufficientStorageSpace : sf::Ftp::Ftp::Response
  • InternalServerError : sf::Http::Http::Response
  • InvalidFile : sf::Ftp::Ftp::Response
  • InvalidResponse : sf::Ftp::Ftp::Response , sf::Http::Http::Response
  • Italic : sf::String

- l -

  • LocalError : sf::Ftp::Ftp::Response
  • LoggedIn : sf::Ftp::Ftp::Response

- m -

  • MovedPermanently : sf::Http::Http::Response
  • MovedTemporarily : sf::Http::Http::Response
  • MultipleChoices : sf::Http::Http::Response

- n -

  • NeedAccountToLogIn : sf::Ftp::Ftp::Response
  • NeedAccountToStore : sf::Ftp::Ftp::Response
  • NeedInformation : sf::Ftp::Ftp::Response
  • NeedPassword : sf::Ftp::Ftp::Response
  • NoContent : sf::Http::Http::Response
  • NotEnoughMemory : sf::Ftp::Ftp::Response
  • NotFound : sf::Http::Http::Response
  • NotImplemented : sf::Http::Http::Response
  • NotLoggedIn : sf::Ftp::Ftp::Response
  • NotModified : sf::Http::Http::Response

- o -

  • Ok : sf::Ftp::Ftp::Response , sf::Http::Http::Response
  • OpeningDataConnection : sf::Ftp::Ftp::Response

- p -

  • PageTypeUnknown : sf::Ftp::Ftp::Response
  • ParameterNotImplemented : sf::Ftp::Ftp::Response
  • ParametersUnknown : sf::Ftp::Ftp::Response
  • Paused : sf::Sound
  • Playing : sf::Sound
  • PointlessCommand : sf::Ftp::Ftp::Response
  • Post : sf::Http::Http::Request

- r -

  • Regular : sf::String
  • RestartMarkerReply : sf::Ftp::Ftp::Response

- s -

  • ServiceNotAvailable : sf::Http::Http::Response
  • ServiceReady : sf::Ftp::Ftp::Response
  • ServiceReadySoon : sf::Ftp::Ftp::Response
  • ServiceUnavailable : sf::Ftp::Ftp::Response
  • Stopped : sf::Sound
  • SystemStatus : sf::Ftp::Ftp::Response
  • SystemType : sf::Ftp::Ftp::Response

- t -

  • TransferAborted : sf::Ftp::Ftp::Response

- u -

  • Unauthorized : sf::Http::Http::Response
  • Underlined : sf::String


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- a -

  • Accept() : sf::SocketTCP
  • Add()
: sf::Selector< Type >
, sf::SelectorBase
  • AddPoint() : sf::Shape
  • ANSIToUTF32() : sf::Unicode
  • Append() : sf::Packet
  • AudioResource() : sf::AudioResource


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- k -

  • KeepAlive() : sf::Ftp


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- l -

  • Launch() : sf::Thread
  • Line() : sf::Shape
  • Listen() : sf::SocketTCP
  • ListingResponse() : sf::Ftp::Ftp::ListingResponse
  • LoadFromFile()
: sf::Image
, sf::PostFX
, sf::SoundBuffer
, sf::Font
  • LoadFromMemory()
: sf::SoundBuffer
, sf::Font
, sf::Image
, sf::PostFX
  • LoadFromPixels() : sf::Image
  • LoadFromSamples() : sf::SoundBuffer
  • Lock()
: sf::Mutex
, sf::Lock
  • Login() : sf::Ftp


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- m -

  • MakeDirectory() : sf::Ftp
  • Matrix3() : sf::Matrix3
  • Move()
: sf::View
, sf::Drawable
, sf::View
  • Music() : sf::Music
  • Mutex() : sf::Mutex


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- n -

  • NonCopyable() : sf::NonCopyable


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- o -

  • Offset() : sf::Rect< T >
  • OnEvent() : sf::WindowListener
  • OnResourceDestroyed() : sf::ResourcePtr< T >
  • OpenFromFile() : sf::Music
  • OpenFromMemory() : sf::Music
  • operator bool() : sf::Packet
  • operator const T *() : sf::ResourcePtr< T >
  • operator std::string() : sf::Unicode::Unicode::Text
  • operator!=()
: sf::Color
, sf::IPAddress
, sf::SocketTCP
, sf::SocketUDP
, sf::VideoMode
  • operator()() : sf::Matrix3
  • operator*() : sf::ResourcePtr< T > , sf::Matrix3
  • operator*=()
: sf::Color
, sf::Matrix3
  • operator+=() : sf::Color
  • operator->() : sf::ResourcePtr< T >
  • operator<()
: sf::SocketUDP
, sf::IPAddress
, sf::SocketTCP
  • operator<<() : sf::Packet
  • operator<=() : sf::IPAddress
  • operator=()
: sf::ResourcePtr< T >
, sf::PostFX
, sf::ResourcePtr< T >
, sf::SoundBuffer
, sf::Resource< T >
, sf::Sound
, sf::Image
  • operator==()
: sf::IPAddress
, sf::SocketUDP
, sf::SocketTCP
, sf::Color
, sf::VideoMode
  • operator>() : sf::IPAddress
  • operator>=() : sf::IPAddress
  • operator>>() : sf::Packet


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- z -

  • Zoom() : sf::View


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- ~ -

  • ~AudioResource() : sf::AudioResource
  • ~Context() : sf::Context
  • ~Drawable() : sf::Drawable
  • ~Ftp() : sf::Ftp
  • ~Image() : sf::Image
  • ~Lock() : sf::Lock
  • ~Music() : sf::Music
  • ~Mutex() : sf::Mutex
  • ~Packet() : sf::Packet
  • ~PostFX() : sf::PostFX
  • ~RenderTarget() : sf::RenderTarget
  • ~RenderWindow() : sf::RenderWindow
  • ~Resource() : sf::Resource< T >
  • ~ResourcePtr() : sf::ResourcePtr< T >
  • ~Sound() : sf::Sound
  • ~SoundBuffer() : sf::SoundBuffer
  • ~SoundRecorder() : sf::SoundRecorder
  • ~SoundStream() : sf::SoundStream
  • ~Thread() : sf::Thread
  • ~Window() : sf::Window
  • ~WindowListener() : sf::WindowListener


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- b -

  • Bind()
: sf::Image
, sf::SocketUDP


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- c -

  • CanCapture() : sf::SoundRecorder
  • CanUsePostFX() : sf::PostFX
  • Capture() : sf::RenderWindow
  • ChangeDirectory() : sf::Ftp
  • Circle() : sf::Shape
  • Clear()
: sf::Packet
, sf::Selector< Type >
, sf::SelectorBase
, sf::RenderTarget
  • Clock() : sf::Clock
  • Close()
: sf::SocketTCP
, sf::SocketUDP
, sf::SocketHelper
, sf::Window
  • Color() : sf::Color
  • Connect()
: sf::SocketTCP
, sf::Ftp
  • Contains() : sf::Rect< T >
  • Context() : sf::Context
  • ConvertCoords() : sf::RenderWindow
  • Copy() : sf::Image
  • CopyScreen() : sf::Image
  • Create()
: sf::Window
, sf::Image
, sf::Window
  • CreateMaskFromColor() : sf::Image


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- d -

  • DeleteDirectory() : sf::Ftp
  • DeleteFile() : sf::Ftp
  • DirectoryResponse() : sf::Ftp::Ftp::DirectoryResponse
  • Disconnect() : sf::Ftp
  • Display() : sf::Window
  • Download() : sf::Ftp
  • Draw() : sf::RenderTarget
  • Drawable() : sf::Drawable


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- e -

  • EnableFill() : sf::Shape
  • EnableKeyRepeat() : sf::Window
  • EnableOutline() : sf::Shape
  • EndOfPacket() : sf::Packet


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- f -

  • FlipX() : sf::Sprite
  • FlipY() : sf::Sprite
  • Font() : sf::Font


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- g -

  • Get4x4Elements() : sf::Matrix3
  • GetAttenuation() : sf::Sound
  • GetBlendMode() : sf::Drawable
  • GetBody() : sf::Http::Http::Response
  • GetBuffer()
: sf::Sound
, sf::SoundBufferRecorder
  • GetCenter()
: sf::View
, sf::Drawable
  • GetChannelsCount()
: sf::SoundBuffer
, sf::SoundStream
  • GetCharacterPos() : sf::String
  • GetCharacterSize() : sf::Font
  • GetColor() : sf::Drawable
  • GetCount() : sf::Ftp::Ftp::ListingResponse
  • GetData() : sf::Packet
  • GetDataSize() : sf::Packet
  • GetDefaultFont() : sf::Font
  • GetDefaultView() : sf::RenderTarget
  • GetDesktopMode() : sf::VideoMode
  • GetDirectory() : sf::Ftp::Ftp::DirectoryResponse
  • GetDirectoryListing() : sf::Ftp
  • GetDuration()
: sf::Music
, sf::SoundBuffer
  • GetElapsedTime() : sf::Clock
  • GetErrorStatus() : sf::SocketHelper
  • GetEvent() : sf::Window
  • GetField() : sf::Http::Http::Response
  • GetFilename() : sf::Ftp::Ftp::ListingResponse
  • GetFont() : sf::String
  • GetFrameTime() : sf::Window
  • GetGlobal() : sf::Context
  • GetGlobalVolume() : sf::Listener
  • GetGlyph() : sf::Font
  • GetHalfSize() : sf::View
  • GetHeight()
: sf::Image
, sf::Rect< T >
, sf::RenderTarget
, sf::RenderWindow
, sf::Window
  • GetImage()
: sf::Font
, sf::Sprite
  • GetInput() : sf::Window
  • GetInverse() : sf::Matrix3
  • GetInverseMatrix() : sf::Drawable
  • GetJoystickAxis() : sf::Input
  • GetLocalAddress() : sf::IPAddress
  • GetLoop()
: sf::Sound
, sf::SoundStream
  • GetMajorHttpVersion() : sf::Http::Http::Response
  • GetMatrix() : sf::Drawable
  • GetMessage() : sf::Ftp::Ftp::Response
  • GetMinDistance() : sf::Sound
  • GetMinorHttpVersion() : sf::Http::Http::Response
  • GetMode() : sf::VideoMode
  • GetModesCount() : sf::VideoMode
  • GetMouseX() : sf::Input
  • GetMouseY() : sf::Input
  • GetNbPoints() : sf::Shape
  • GetOutlineWidth() : sf::Shape
  • GetPitch() : sf::Sound
  • GetPixel()
: sf::Image
, sf::Sprite
  • GetPixelsPtr() : sf::Image
  • GetPlayingOffset()
: sf::Sound
, sf::SoundStream
  • GetPointColor() : sf::Shape
  • GetPointOutlineColor() : sf::Shape
  • GetPointPosition() : sf::Shape
  • GetPort() : sf::SocketUDP
  • GetPosition()
: sf::Listener
, sf::Drawable
, sf::Sound
  • GetPublicAddress() : sf::IPAddress
  • GetRect()
: sf::String
, sf::View
  • GetRotation() : sf::Drawable
  • GetSampleRate()
: sf::SoundBuffer
, sf::SoundStream
, sf::SoundRecorder
  • GetSamples() : sf::SoundBuffer
  • GetSamplesCount() : sf::SoundBuffer
  • GetScale() : sf::Drawable
  • GetSeed() : sf::Randomizer
  • GetSettings() : sf::Window
  • GetSize()
: sf::String
, sf::Sprite
  • GetSocketReady()
: sf::SelectorBase
, sf::Selector< Type >
  • GetStatus()
: sf::SoundStream
, sf::Http::Http::Response
, sf::Sound
, sf::Ftp::Ftp::Response
  • GetStyle() : sf::String
  • GetSubRect() : sf::Sprite
  • GetTarget() : sf::Listener
  • GetTexCoords() : sf::Image
  • GetText() : sf::String
  • GetUTF16Length() : sf::Unicode
  • GetUTF32Length() : sf::Unicode
  • GetUTF8Length() : sf::Unicode
  • GetValidTextureSize() : sf::Image
  • GetView() : sf::RenderTarget
  • GetVolume() : sf::Sound
  • GetWidth()
: sf::Window
, sf::RenderTarget
, sf::Rect< T >
, sf::Image
, sf::RenderWindow
  • GetWorkingDirectory() : sf::Ftp
  • Glyph() : sf::Glyph


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- h -

  • Http() : sf::Http


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- i -

  • Image() : sf::Image
  • Initialize()
: sf::SoundStream
, sf::RenderTarget
  • Input() : sf::Input
  • Intersects() : sf::Rect< T >
  • InvalidSocket() : sf::SocketHelper
  • IPAddress() : sf::IPAddress
  • IsContextActive() : sf::Context
  • IsJoystickButtonDown() : sf::Input
  • IsKeyDown() : sf::Input
  • IsMouseButtonDown() : sf::Input
  • IsOk() : sf::Ftp::Ftp::Response
  • IsOpened() : sf::Window
  • IsRelativeToListener() : sf::Sound
  • IsSmooth() : sf::Image
  • IsValid()
: sf::SocketTCP
, sf::IPAddress
, sf::VideoMode
, sf::SocketUDP


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- p -

  • Packet() : sf::Packet
  • ParentDirectory() : sf::Ftp
  • Pause() : sf::Sound
  • Play()
: sf::Sound
, sf::SoundStream
  • PostFX() : sf::PostFX
  • PreserveOpenGLStates() : sf::RenderTarget


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- r -

  • Random() : sf::Randomizer
  • Receive()
: sf::SocketTCP
, sf::SocketUDP
, sf::SocketTCP
, sf::SocketUDP
  • Rect() : sf::Rect< T >
  • Rectangle() : sf::Shape
  • Remove()
: sf::Selector< Type >
, sf::SelectorBase
  • RenameFile() : sf::Ftp
  • Render()
: sf::Sprite
, sf::String
, sf::PostFX
, sf::Shape
  • RenderTarget() : sf::RenderTarget
  • RenderWindow() : sf::RenderWindow
  • Request() : sf::Http::Http::Request
  • Reset() : sf::Clock
  • ResetBuffer() : sf::Sound
  • Resize() : sf::Sprite
  • Resource() : sf::Resource< T >
  • ResourcePtr() : sf::ResourcePtr< T >
  • Response()
: sf::Ftp::Ftp::Response
, sf::Http::Http::Response
  • Rotate() : sf::Drawable


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- s -

  • SaveToFile()
: sf::SoundBuffer
, sf::Image
  • Scale() : sf::Drawable
  • SelectorBase() : sf::SelectorBase
  • Send()
: sf::SocketUDP
, sf::SocketTCP
  • SendRequest() : sf::Http
  • SetActive()
: sf::Context
, sf::Window
  • SetAttenuation() : sf::Sound
  • SetBlendMode() : sf::Drawable
  • SetBlocking()
: sf::SocketUDP
, sf::SocketHelper
, sf::SocketTCP
  • SetBody() : sf::Http::Http::Request
  • SetBuffer() : sf::Sound
  • SetCenter()
: sf::Drawable
, sf::View
  • SetColor() : sf::Drawable
  • SetCursorPosition() : sf::Window
  • SetField() : sf::Http::Http::Request
  • SetFont() : sf::String
  • SetFramerateLimit() : sf::Window
  • SetFromRect() : sf::View
  • SetFromTransformations() : sf::Matrix3
  • SetGlobalVolume() : sf::Listener
  • SetHalfSize() : sf::View
  • SetHost() : sf::Http
  • SetHttpVersion() : sf::Http::Http::Request
  • SetIcon() : sf::Window
  • SetImage() : sf::Sprite
  • SetJoystickThreshold() : sf::Window
  • SetLoop()
: sf::Sound
, sf::SoundStream
  • SetMethod() : sf::Http::Http::Request
  • SetMinDistance() : sf::Sound
  • SetOutlineWidth() : sf::Shape
  • SetParameter() : sf::PostFX
  • SetPitch() : sf::Sound
  • SetPixel() : sf::Image
  • SetPlayingOffset() : sf::Sound
  • SetPointColor() : sf::Shape
  • SetPointOutlineColor() : sf::Shape
  • SetPointPosition() : sf::Shape
  • SetPosition()
: sf::Drawable
, sf::Listener
, sf::Sound
, sf::Drawable
, sf::Window
  • SetRelativeToListener() : sf::Sound
  • SetRotation() : sf::Drawable
  • SetScale() : sf::Drawable
  • SetScaleX() : sf::Drawable
  • SetScaleY() : sf::Drawable
  • SetSeed() : sf::Randomizer
  • SetSize()
: sf::String
, sf::Window
  • SetSmooth() : sf::Image
  • SetStyle() : sf::String
  • SetSubRect() : sf::Sprite
  • SetTarget() : sf::Listener
  • SetText() : sf::String
  • SetTexture() : sf::PostFX
  • SetURI() : sf::Http::Http::Request
  • SetView() : sf::RenderTarget
  • SetVolume() : sf::Sound
  • SetX() : sf::Drawable
  • SetY() : sf::Drawable
  • Shape() : sf::Shape
  • Show() : sf::Window
  • ShowMouseCursor() : sf::Window
  • SocketTCP() : sf::SocketTCP
  • SocketUDP() : sf::SocketUDP
  • Sound() : sf::Sound
  • SoundBuffer() : sf::SoundBuffer
  • SoundRecorder() : sf::SoundRecorder
  • SoundStream() : sf::SoundStream
  • Sprite() : sf::Sprite
  • Start() : sf::SoundRecorder
  • Stop()
: sf::Sound
, sf::SoundStream
, sf::SoundRecorder
  • String() : sf::String


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- t -

  • Terminate() : sf::Thread
  • Text() : sf::Unicode::Unicode::Text
  • Thread() : sf::Thread
  • ToInteger() : sf::IPAddress
  • ToString() : sf::IPAddress
  • Transform() : sf::Matrix3
  • TransformToGlobal() : sf::Drawable
  • TransformToLocal() : sf::Drawable


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- u -

  • Unbind() : sf::SocketUDP
  • Unlock() : sf::Mutex
  • Upload() : sf::Ftp
  • UseVerticalSync() : sf::Window
  • UTF16ToUTF32() : sf::Unicode
  • UTF16ToUTF8() : sf::Unicode
  • UTF32ToANSI() : sf::Unicode
  • UTF32ToUTF16() : sf::Unicode
  • UTF32ToUTF8() : sf::Unicode
  • UTF8ToUTF16() : sf::Unicode
  • UTF8ToUTF32() : sf::Unicode


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- v -

  • Vector2() : sf::Vector2< T >
  • Vector3() : sf::Vector3< T >
  • VideoMode() : sf::VideoMode
  • View() : sf::View


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • k
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • z
  • ~

- w -

  • Wait()
: sf::Selector< Type >
, sf::SelectorBase
, sf::Thread
  • Window() : sf::Window
  • WindowSettings() : sf::WindowSettings


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator

  • UTF8String : sf::Unicode


  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • g
  • h
  • i
  • l
  • m
  • n
  • r
  • s
  • t
  • w
  • x
  • y
  • z

- a -

  • a : sf::Color
  • Advance : sf::Glyph
  • AntialiasingLevel : sf::WindowSettings

- b -

  • b : sf::Color
  • BitsPerPixel : sf::VideoMode
  • Black : sf::Color
  • Blue : sf::Color
  • Bottom : sf::Rect< T >

- c -

  • Cyan : sf::Color

- d -

  • DepthBits : sf::WindowSettings

- g -

  • g : sf::Color
  • Green : sf::Color

- h -

  • Height : sf::VideoMode

- i -

  • Identity : sf::Matrix3

- l -

  • Left : sf::Rect< T >
  • LocalHost : sf::IPAddress

- m -

  • Magenta : sf::Color

- n -

  • NbSamples : sf::SoundStream::SoundStream::Chunk

- r -

  • r : sf::Color
  • Rectangle : sf::Glyph
  • Red : sf::Color
  • Right : sf::Rect< T >

- s -

  • Samples : sf::SoundStream::SoundStream::Chunk
  • StencilBits : sf::WindowSettings

- t -

  • TexCoords : sf::Glyph
  • Top : sf::Rect< T >
  • Type : sf::Event

- w -

  • White : sf::Color
  • Width : sf::VideoMode

- x -

  • x : sf::Vector2< T > , sf::Vector3< T >

- y -

  • y : sf::Vector2< T > , sf::Vector3< T >
  • Yellow : sf::Color

- z -

  • z : sf::Vector3< T >


  • Namespace List
  • Namespace Members

Namespace List

Here is a list of all documented namespaces with brief descriptions:
sf::Blend | Enumerate the blending modes for drawable objects
sf::Joy | Definition of joystick axis for joystick events
sf::Key | Definition of key codes for keyboard events
sf::Mouse | Definition of button codes for mouse events
sf::Style | Enumeration of window creation styles


  • Namespace List
  • Namespace Members
sf::Blend

sf::Blend Namespace Reference

Enumerate the blending modes for drawable objects. More...

Enumerations

enum Mode {
Alpha,
Add,
Multiply,
None
}

Detailed Description

Enumerate the blending modes for drawable objects.

Enumeration Type Documentation

enum sf::Blend::Mode

Enumerator:
Alpha | Pixel = Src * a + Dest * (1 - a).
Add | Pixel = Src + Dest.
Multiply | Pixel = Src * Dest.
None | No blending.

Definition at line 45 of file Drawable.hpp.


  • Namespace List
  • Namespace Members
sf::Joy

sf::Joy Namespace Reference

Definition of joystick axis for joystick events. More...

Enumerations

enum Axis {
AxisX,
AxisY,
AxisZ,
AxisR,
AxisU,
AxisV,
AxisPOV,
AxisCount
}
enum {
Count = 4,
ButtonCount = 32
}

Detailed Description

Definition of joystick axis for joystick events.

Enumeration Type Documentation

anonymous enum

Enumerator:
Count | Total number of supported joysticks.
ButtonCount | Total number of supported joystick buttons.

Definition at line 186 of file Event.hpp.


  • Namespace List
  • Namespace Members
sf::Key

sf::Key Namespace Reference

Definition of key codes for keyboard events. More...

Enumerations

enum Code {
A = 'a',
B = 'b',
C = 'c',
D = 'd',
E = 'e',
F = 'f',
G = 'g',
H = 'h',
I = 'i',
J = 'j',
K = 'k',
L = 'l',
M = 'm',
N = 'n',
O = 'o',
P = 'p',
Q = 'q',
R = 'r',
S = 's',
T = 't',
U = 'u',
V = 'v',
W = 'w',
X = 'x',
Y = 'y',
Z = 'z',
Num0 = '0',
Num1 = '1',
Num2 = '2',
Num3 = '3',
Num4 = '4',
Num5 = '5',
Num6 = '6',
Num7 = '7',
Num8 = '8',
Num9 = '9',
Escape = 256,
LControl,
LShift,
LAlt,
LSystem,
RControl,
RShift,
RAlt,
RSystem,
Menu,
LBracket,
RBracket,
SemiColon,
Comma,
Period,
Quote,
Slash,
BackSlash,
Tilde,
Equal,
Dash,
Space,
Return,
Back,
Tab,
PageUp,
PageDown,
End,
Home,
Insert,
Delete,
Add,
Subtract,
Multiply,
Divide,
Left,
Right,
Up,
Down,
Numpad0,
Numpad1,
Numpad2,
Numpad3,
Numpad4,
Numpad5,
Numpad6,
Numpad7,
Numpad8,
Numpad9,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
Pause,
Count
}

Detailed Description

Definition of key codes for keyboard events.

Enumeration Type Documentation

enum sf::Key::Code

Enumerator:
LSystem | OS specific key (left side) : windows (Win and Linux), apple (MacOS), ...
RSystem | OS specific key (right side) : windows (Win and Linux), apple (MacOS), ...
LBracket [
RBracket ]
SemiColon ;
Comma ,
Period
Quote '
Slash /
Tilde ~
Equal =
Dash
Add +
Subtract
Multiply *
Divide /
Left | Left arrow.
Right | Right arrow.
Up | Up arrow.
Down | Down arrow.

Definition at line 41 of file Event.hpp.


  • Namespace List
  • Namespace Members
sf::Mouse

sf::Mouse Namespace Reference

Definition of button codes for mouse events. More...

Enumerations

enum Button {
Left,
Right,
Middle,
XButton1,
XButton2,
ButtonCount
}

Detailed Description

Definition of button codes for mouse events.


  • Namespace List
  • Namespace Members
sf::Style

sf::Style Namespace Reference

Enumeration of window creation styles. More...

Enumerations

enum {
None = 0,
Titlebar = 1 << 0,
Resize = 1 << 1,
Close = 1 << 2,
Fullscreen = 1 << 3
}

Detailed Description

Enumeration of window creation styles.

Enumeration Type Documentation

anonymous enum

Enumerator:
None | No border / title bar (this flag and all others are mutually exclusive).
Titlebar | Title bar + fixed border.
Resize | Titlebar + resizable border + maximize button.
Close | Titlebar + close button.
Fullscreen | Fullscreen mode (this flag and all others are mutually exclusive).

Definition at line 37 of file WindowStyle.hpp.


  • Namespace List
  • Namespace Members
  • All
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • l
  • m
  • n
  • p
  • q
  • r
  • s
  • t
  • u
Here is a list of all documented namespace members with links to the namespaces they belong to:

- a -

  • Add : sf::Blend , sf::Key
  • Alpha : sf::Blend

- b -

  • ButtonCount : sf::Joy

- c -

  • Close : sf::Style
  • Code : sf::Key
  • Comma : sf::Key
  • Count : sf::Joy

- d -

  • Dash : sf::Key
  • Divide : sf::Key
  • Down : sf::Key

- e -

  • Equal : sf::Key

- f -

  • Fullscreen : sf::Style

- l -

  • LBracket : sf::Key
  • Left : sf::Key
  • LSystem : sf::Key

- m -

  • Mode : sf::Blend
  • Multiply : sf::Key , sf::Blend

- n -

  • None : sf::Blend , sf::Style

- p -

  • Period : sf::Key

- q -

  • Quote : sf::Key

- r -

  • RBracket : sf::Key
  • Resize : sf::Style
  • Right : sf::Key
  • RSystem : sf::Key

- s -

  • SemiColon : sf::Key
  • Slash : sf::Key
  • Subtract : sf::Key

- t -

  • Tilde : sf::Key
  • Titlebar : sf::Style

- u -

  • Up : sf::Key


  • Namespace List
  • Namespace Members
  • All
  • Enumerations
  • Enumerator

  • Code : sf::Key
  • Mode : sf::Blend


  • Namespace List
  • Namespace Members
  • All
  • Enumerations
  • Enumerator
  • a
  • b
  • c
  • d
  • e
  • f
  • l
  • m
  • n
  • p
  • q
  • r
  • s
  • t
  • u

- a -

  • Add : sf::Blend , sf::Key
  • Alpha : sf::Blend

- b -

  • ButtonCount : sf::Joy

- c -

  • Close : sf::Style
  • Comma : sf::Key
  • Count : sf::Joy

- d -

  • Dash : sf::Key
  • Divide : sf::Key
  • Down : sf::Key

- e -

  • Equal : sf::Key

- f -

  • Fullscreen : sf::Style

- l -

  • LBracket : sf::Key
  • Left : sf::Key
  • LSystem : sf::Key

- m -

  • Multiply : sf::Blend , sf::Key

- n -

  • None : sf::Blend , sf::Style

- p -

  • Period : sf::Key

- q -

  • Quote : sf::Key

- r -

  • RBracket : sf::Key
  • Resize : sf::Style
  • Right : sf::Key
  • RSystem : sf::Key

- s -

  • SemiColon : sf::Key
  • Slash : sf::Key
  • Subtract : sf::Key

- t -

  • Tilde : sf::Key
  • Titlebar : sf::Style

- u -

  • Up : sf::Key


  • File List

File List

Here is a list of all documented files with brief descriptions:
Arial.hpp [code]
Audio.hpp [code]
AudioDevice.cpp [code]
AudioDevice.hpp [code]
AudioResource.cpp [code]
AudioResource.hpp [code]
Clock.cpp [code]
Clock.hpp [code]
Color.cpp [code]
Color.hpp [code]
Config.hpp [code]
Context.cpp [code]
Context.hpp [code]
Doxygen.hpp [code]
Drawable.cpp [code]
Drawable.hpp [code]
Event.hpp [code]
Font.cpp [code]
Font.hpp [code]
FontLoader.cpp [code]
FontLoader.hpp [code]
Ftp.cpp [code]
Ftp.hpp [code]
Glyph.hpp [code]
Graphics.hpp [code]
GraphicsContext.cpp [code]
GraphicsContext.hpp [code]
Http.cpp [code]
Http.hpp [code]
Image.cpp [code]
Image.hpp [code]
ImageLoader.cpp [code]
ImageLoader.hpp [code]
Input.cpp [code]
Input.hpp [code]
IPAddress.cpp [code]
IPAddress.hpp [code]
Cocoa/Joystick.cpp [code]
Template for new ports/Joystick.cpp [code]
Win32/Joystick.cpp [code]
Cocoa/Joystick.hpp [code]
Joystick.hpp [code]
Template for new ports/Joystick.hpp [code]
Win32/Joystick.hpp [code]
Listener.cpp [code]
Listener.hpp [code]
Lock.cpp [code]
Lock.hpp [code]
Matrix3.cpp [code]
Matrix3.hpp [code]
Matrix3.inl [code]
Music.cpp [code]
Music.hpp [code]
Mutex.cpp [code]
Mutex.hpp [code]
Win32/Mutex.hpp [code]
Network.hpp [code]
NonCopyable.hpp [code]
OpenAL.hpp [code]
OpenGL.hpp [code]
Packet.cpp [code]
Packet.hpp [code]
Platform.cpp [code]
Platform.hpp [code]
Win32/Platform.hpp [code]
PostFX.cpp [code]
PostFX.hpp [code]
Randomizer.cpp [code]
Randomizer.hpp [code]
Rect.hpp [code]
Rect.inl [code]
RenderTarget.cpp [code]
RenderTarget.hpp [code]
RenderWindow.cpp [code]
RenderWindow.hpp [code]
Resource.hpp [code]
Resource.inl [code]
ResourcePtr.inl [code]
Selector.hpp [code]
Selector.inl [code]
SelectorBase.cpp [code]
SelectorBase.hpp [code]
SFML_Main.cpp [code]
Shape.cpp [code]
Shape.hpp [code]
Sleep.cpp [code]
Sleep.hpp [code]
SocketHelper.cpp [code]
SocketHelper.hpp [code]
Win32/SocketHelper.hpp [code]
Sockets.hpp [code]
SocketTCP.cpp [code]
SocketTCP.hpp [code]
SocketUDP.cpp [code]
SocketUDP.hpp [code]
Sound.cpp [code]
Sound.hpp [code]
SoundBuffer.cpp [code]
SoundBuffer.hpp [code]
SoundBufferRecorder.cpp [code]
SoundBufferRecorder.hpp [code]
SoundFile.cpp [code]
SoundFile.hpp [code]
SoundFileDefault.cpp [code]
SoundFileDefault.hpp [code]
SoundFileOgg.cpp [code]
SoundFileOgg.hpp [code]
SoundRecorder.cpp [code]
SoundRecorder.hpp [code]
SoundStream.cpp [code]
SoundStream.hpp [code]
Sprite.cpp [code]
Sprite.hpp [code]
String.cpp [code]
String.hpp [code]
System.hpp [code]
Thread.cpp [code]
Thread.hpp [code]
Win32/Thread.hpp [code]
Unicode.cpp [code]
Unicode.hpp [code]
Unicode.inl [code]
Vector2.hpp [code]
Vector2.inl [code]
Vector3.hpp [code]
Vector3.inl [code]
VideoMode.cpp [code]
VideoMode.hpp [code]
Cocoa/VideoModeSupport.cpp [code]
Template for new ports/VideoModeSupport.cpp [code]
Win32/VideoModeSupport.cpp [code]
Cocoa/VideoModeSupport.hpp [code]
Template for new ports/VideoModeSupport.hpp [code]
VideoModeSupport.hpp [code]
Win32/VideoModeSupport.hpp [code]
View.cpp [code]
View.hpp [code]
Window.cpp [code]
Window/Window.hpp [code]
Window.hpp [code]
WindowHandle.hpp [code]
WindowImpl.cpp [code]
WindowImpl.hpp [code]
WindowImplCocoa.hpp [code]
WindowImplWin32.cpp [code]
WindowImplWin32.hpp [code]
WindowImplXXX.cpp [code]
WindowImplXXX.hpp [code]
WindowListener.hpp [code]
WindowSettings.hpp [code]
WindowStyle.hpp [code]


  • File List

Audio.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_AUDIO_HPP
00026 #define SFML_AUDIO_HPP
00027
00029 // Headers
00031
00032 #include <SFML/System.hpp>
00033 #include <SFML/Audio/Listener.hpp>
00034 #include <SFML/Audio/Music.hpp>
00035 #include <SFML/Audio/Sound.hpp>
00036 #include <SFML/Audio/SoundBuffer.hpp>
00037 #include <SFML/Audio/SoundBufferRecorder.hpp>
00038 #include <SFML/Audio/SoundRecorder.hpp>
00039 #include <SFML/Audio/SoundStream.hpp>
00040
00041
00042 #endif // SFML_AUDIO_HPP


  • File List

AudioDevice.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Audio/AudioDevice.hpp>
00029 #include <SFML/Audio/AudioResource.hpp>
00030 #include <SFML/Audio/Listener.hpp>
00031 #include <algorithm>
00032 #include <iostream>
00033
00034
00035 namespace sf
00036 {
00037 namespace priv
00038 {
00040 // Static member data
00042 AudioDevice* AudioDevice::ourInstance;
00043
00044
00048 AudioDevice::AudioDevice() :
00049 myRefCount(0)
00050 {
00051     // Create the device
00052     myDevice = alcOpenDevice(NULL);
00053
00054     if (myDevice)
00055     {
00056         // Create the context
00057         myContext = alcCreateContext(myDevice, NULL);
00058
00059         if (myContext)
00060         {
00061             // Set the context as the current one (we'll only need one)
00062             alcMakeContextCurrent(myContext);
00063
00064             // Initialize the listener, located at the origin and looking along the Z axis
00065             Listener::SetPosition(0.f, 0.f, 0.f);
00066             Listener::SetTarget(0.f, 0.f, -1.f);
00067         }
00068         else
00069         {
00070             std::cerr << "Failed to create the audio context" << std::endl;
00071         }
00072     }
00073     else
00074     {
00075         std::cerr << "Failed to open the audio device" << std::endl;
00076     }
00077 }
00078
00079
00083 AudioDevice::~AudioDevice()
00084 {
00085     // Destroy the context
00086     alcMakeContextCurrent(NULL);
00087     if (myContext)
00088         alcDestroyContext(myContext);
00089
00090     // Destroy the device
00091     if (myDevice)
00092         alcCloseDevice(myDevice);
00093 }
00094
00095
00099 AudioDevice& AudioDevice::GetInstance()
00100 {
00101     // Create the audio device if it doesn't exist
00102     if (!ourInstance)
00103         ourInstance = new AudioDevice;
00104
00105     return *ourInstance;
00106 }
00107
00108
00112 void AudioDevice::AddReference()
00113 {
00114     // Create the audio device if it doesn't exist
00115     if (!ourInstance)
00116         ourInstance = new AudioDevice;
00117
00118     // Increase the references count
00119     ourInstance->myRefCount++;
00120 }
00121
00122
00126 void AudioDevice::RemoveReference()
00127 {
00128     // Decrease the references count
00129     ourInstance->myRefCount--;
00130
00131     // Destroy the audio device if the references count reaches 0
00132     if (ourInstance->myRefCount == 0)
00133     {
00134         delete ourInstance;
00135         ourInstance = NULL;
00136     }
00137 }
00138
00139
00143 ALCdevice* AudioDevice::GetDevice() const
00144 {
00145     return myDevice;
00146 }
00147
00148
00152 ALenum AudioDevice::GetFormatFromChannelsCount(unsigned int ChannelsCount) const
00153 {
00154     // Find the good format according to the number of channels
00155     switch (ChannelsCount)
00156     {
00157         case 1 : return AL_FORMAT_MONO16;
00158         case 2 : return AL_FORMAT_STEREO16;
00159         case 4 : return alGetEnumValue("AL_FORMAT_QUAD16");
00160         case 6 : return alGetEnumValue("AL_FORMAT_51CHN16");
00161         case 7 : return alGetEnumValue("AL_FORMAT_61CHN16");
00162         case 8 : return alGetEnumValue("AL_FORMAT_71CHN16");
00163     }
00164
00165     return 0;
00166 }
00167
00168 } // namespace priv
00169
00170 } // namespace sf


  • File List

AudioDevice.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_AUDIODEVICE_HPP
00026 #define SFML_AUDIODEVICE_HPP
00027
00029 // Headers
00031 #include <SFML/Audio/OpenAL.hpp>
00032 #include <set>
00033 #include <string>
00034
00035
00036 namespace sf
00037 {
00038 class AudioResource;
00039
00040 namespace priv
00041 {
00042
00048 class AudioDevice
00049 {
00050 public :
00051
00058     static AudioDevice& GetInstance();
00059
00064     static void AddReference();
00065
00070     static void RemoveReference();
00071
00078     ALCdevice* GetDevice() const;
00079
00088     ALenum GetFormatFromChannelsCount(unsigned int ChannelsCount) const;
00089
00090 private :
00091
00096     AudioDevice();
00097
00102     ~AudioDevice();
00103
00105     // Static member data
00107     static AudioDevice* ourInstance;
00108
00110     // Member data
00112     ALCdevice*   myDevice;
00113     ALCcontext*  myContext;
00114     unsigned int myRefCount;
00115 };
00116
00117 } // namespace priv
00118
00119 } // namespace sf
00120
00121
00122 #endif // SFML_AUDIODEVICE_HPP


  • File List

AudioResource.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Audio/AudioResource.hpp>
00029 #include <SFML/Audio/AudioDevice.hpp>
00030
00031
00032 namespace sf
00033 {
00037 AudioResource::AudioResource()
00038 {
00039     priv::AudioDevice::AddReference();
00040 }
00041
00042
00046 AudioResource::AudioResource(const AudioResource&)
00047 {
00048     priv::AudioDevice::AddReference();
00049 }
00050
00051
00055 AudioResource::~AudioResource()
00056 {
00057     priv::AudioDevice::RemoveReference();
00058 }
00059
00060 } // namespace sf


  • File List

AudioResource.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_AUDIORESOURCE_HPP
00026 #define SFML_AUDIORESOURCE_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 namespace sf
00035 {
00041 class SFML_API AudioResource
00042 {
00043 protected :
00044
00049     AudioResource();
00050
00055     AudioResource(const AudioResource&);
00056
00061     virtual ~AudioResource();
00062 };
00063
00064 } // namespace sf
00065
00066
00067 #endif // SFML_AUDIORESOURCE_HPP


Class Index

A | C | D | E | F | G | H | I | L | M | N | P | R | S | T | U | V | W

A
Event::TextEvent (sf)
L
RenderWindow (sf) Sprite (sf)
AudioResource (sf)
F
Listener (sf) Resource (sf) String (sf)
C
Font (sf) Lock (sf) ResourcePtr (sf)
T
Clock (sf) Ftp (sf)
M
S
Thread (sf)
Color (sf) Ftp::DirectoryResponse (sf) Matrix3 (sf) Selector (sf)
U
Context (sf) | Ftp::ListingResponse (sf) | Music (sf) | SelectorBase (sf) | Unicode (sf)
D
Ftp::Response (sf) Mutex (sf) Shape (sf) Unicode::Text (sf)
Drawable (sf)
G
N
SocketHelper (sf)
V
E
Glyph (sf) NonCopyable (sf) SocketTCP (sf) Vector2 (sf)
Event (sf)
H
P
SocketUDP (sf) Vector3 (sf)
Event::JoyButtonEvent (sf) | Http (sf) | Packet (sf) | Sound (sf) | VideoMode (sf)
Event::JoyMoveEvent (sf) | Http::Request (sf) | PostFX (sf) | SoundBuffer (sf) | View (sf)
Event::KeyEvent (sf) Http::Response (sf)
R
SoundBufferRecorder (sf)
W
Event::MouseButtonEvent (sf)
I
Randomizer (sf) SoundRecorder (sf) Window (sf)
Event::MouseMoveEvent (sf) | Image (sf) | Rect (sf) | SoundStream (sf) | WindowListener (sf)
Event::MouseWheelEvent (sf) | Input (sf) | RenderTarget (sf) | SoundStream::Chunk (sf) | WindowSettings (sf)
Event::SizeEvent (sf) | IPAddress (sf)

A | C | D | E | F | G | H | I | L | M | N | P | R | S | T | U | V | W


  • File List

Clock.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/System/Clock.hpp>
00029 #include <SFML/System/Platform.hpp>
00030
00031
00032 namespace sf
00033 {
00037 Clock::Clock()
00038 {
00039     Reset();
00040 }
00041
00042
00046 float Clock::GetElapsedTime() const
00047 {
00048     return static_cast<float>(sf::priv::Platform::GetSystemTime() - myStartTime);
00049 }
00050
00051
00055 void Clock::Reset()
00056 {
00057     myStartTime = sf::priv::Platform::GetSystemTime();
00058 }
00059
00060 } // namespace sf


  • File List

Clock.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_CLOCK_HPP
00026 #define SFML_CLOCK_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 namespace sf
00035 {
00039 class SFML_API Clock
00040 {
00041 public :
00042
00047     Clock();
00048
00055     float GetElapsedTime() const;
00056
00061     void Reset();
00062
00063 private :
00064
00066     // Member data
00068     double myStartTime;
00069 };
00070
00071 } // namespace sf
00072
00073
00074 #endif // SFML_CLOCK_HPP


  • File List

Joystick.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Window/Joystick.hpp>
00029
00030
00031 namespace sf
00032 {
00033 namespace priv
00034 {
00038 void Joystick::Initialize(unsigned int Index)
00039 {
00040     // Reset the joystick state
00041
00042     // Initialize the Index-th available joystick
00043 }
00044
00045
00049 JoystickState Joystick::UpdateState()
00050 {
00051     // Fill a JoystickState instance with the current joystick state
00052     JoystickState s;
00053     return s;
00054 }
00055
00056
00060 bool Joystick::HasAxis(Joy::Axis Axis) const
00061 {
00062     return false;
00063 }
00064
00065
00069 unsigned int Joystick::GetButtonsCount() const
00070 {
00071     // Return number of supported buttons
00072     return 0;
00073 }
00074
00075 } // namespace priv
00076
00077 } // namespace sf


  • File List

Joystick.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_JOYSTICKCARBON_HPP
00026 #define SFML_JOYSTICKCARBON_HPP
00027
00029 // Headers
00031
00032
00033 namespace sf
00034 {
00035 namespace priv
00036 {
00040 class Joystick
00041 {
00042 public :
00043
00050     void Initialize(unsigned int Index);
00051
00058     JoystickState UpdateState();
00059
00068     bool HasAxis(Joy::Axis Axis) const;
00069
00076     unsigned int GetButtonsCount() const;
00077 };
00078
00079 } // namespace priv
00080
00081 } // namespace sf
00082
00083
00084 #endif // SFML_JOYSTICKCARBON_HPP


  • File List

VideoModeSupport.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Window/Cocoa/VideoModeSupport.hpp>
00029 #include <ApplicationServices/ApplicationServices.h>
00030 #include <algorithm>
00031
00032 namespace sf
00033 {
00034 namespace priv
00035 {
00039 void VideoModeSupport::GetSupportedVideoModes(std::vector<VideoMode>& Modes)
00040 {
00041     // Ceylo -- using same implementation as in OSXCarbon
00042
00043     // First, clear array to fill
00044     Modes.clear();
00045
00046     // Enumerate all available video modes for primary display adapter
00047     CFArrayRef DisplayModes = CGDisplayAvailableModes( kCGDirectMainDisplay );
00048     CFIndex DisplayModeCount = CFArrayGetCount( DisplayModes );
00049     CFDictionaryRef CurrentMode;
00050
00051     for (int Count = 0; Count < DisplayModeCount; ++Count)
00052     {
00053         CurrentMode = (CFDictionaryRef)CFArrayGetValueAtIndex( DisplayModes, Count );
00054
00055         VideoMode Mode;
00056
00057         CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentMode, kCGDisplayWidth), kCFNumberIntType, &(Mode.Width));
00058         CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentMode, kCGDisplayHeight), kCFNumberIntType, &(Mode.Height));
00059         CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentMode, kCGDisplayBitsPerPixel), kCFNumberIntType, &(Mode.BitsPerPixel));
00060
00061         // Add it only if it is not already in the array
00062         if (std::find(Modes.begin(), Modes.end(), Mode) == Modes.end())
00063             Modes.push_back(Mode);
00064     }
00065 }
00066
00067
00071 VideoMode VideoModeSupport::GetDesktopVideoMode()
00072 {
00073     // Ceylo -- using same implementation as in OSXCarbon
00074
00075     CFDictionaryRef CurrentVideoMode = CGDisplayCurrentMode(kCGDirectMainDisplay);
00076
00077     VideoMode DesktopMode;
00078
00079
00080     // Get video mode width
00081     CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentVideoMode, kCGDisplayWidth),
00082                      kCFNumberIntType,
00083                      &(DesktopMode.Width));
00084
00085     // Get video mode height
00086     CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentVideoMode, kCGDisplayHeight),
00087                      kCFNumberIntType,
00088                      &(DesktopMode.Height));
00089
00090     // Get video mode depth
00091     CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentVideoMode, kCGDisplayBitsPerPixel),
00092                      kCFNumberIntType,
00093                      &(DesktopMode.BitsPerPixel));
00094
00095
00096     return DesktopMode;
00097 }
00098
00099 } // namespace priv
00100
00101 } // namespace sf


  • File List

VideoModeSupport.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_VIDEOMODESUPPORTCOCOA_HPP
00026 #define SFML_VIDEOMODESUPPORTCOCOA_HPP
00027
00029 // Headers
00031 #include <SFML/Window/VideoMode.hpp>
00032 #include <vector>
00033
00034
00035 namespace sf
00036 {
00037 namespace priv
00038 {
00043 class VideoModeSupport
00044 {
00045 public :
00046
00053     static void GetSupportedVideoModes(std::vector<VideoMode>& Modes);
00054
00061     static VideoMode GetDesktopVideoMode();
00062 };
00063
00064 } // namespace priv
00065
00066 } // namespace sf
00067
00068
00069 #endif // SFML_VIDEOMODESUPPORTCOCOA_HPP


  • File List

Color.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Graphics/Color.hpp>
00029 #include <algorithm>
00030
00031
00032 namespace sf
00033 {
00035 // Static member data
00037 const Color Color::Black(0, 0, 0);
00038 const Color Color::White(255, 255, 255);
00039 const Color Color::Red(255, 0, 0);
00040 const Color Color::Green(0, 255, 0);
00041 const Color Color::Blue(0, 0, 255);
00042 const Color Color::Yellow(255, 255, 0);
00043 const Color Color::Magenta(255, 0, 255);
00044 const Color Color::Cyan(0, 255, 255);
00045
00046
00050 Color::Color() :
00051 r(0),
00052 g(0),
00053 b(0),
00054 a(255)
00055 {
00056
00057 }
00058
00059
00063 Color::Color(Uint8 R, Uint8 G, Uint8 B, Uint8 A) :
00064 r(R),
00065 g(G),
00066 b(B),
00067 a(A)
00068 {
00069
00070 }
00071
00072
00076 Color& Color::operator +=(const Color& Other)
00077 {
00078     r = static_cast<Uint8>(std::min(r + Other.r, 255));
00079     g = static_cast<Uint8>(std::min(g + Other.g, 255));
00080     b = static_cast<Uint8>(std::min(b + Other.b, 255));
00081     a = static_cast<Uint8>(std::min(a + Other.a, 255));
00082
00083     return *this;
00084 }
00085
00086
00090 Color& Color::operator *=(const Color& Other)
00091 {
00092     r = static_cast<Uint8>(r * Other.r / 255);
00093     g = static_cast<Uint8>(g * Other.g / 255);
00094     b = static_cast<Uint8>(b * Other.b / 255);
00095     a = static_cast<Uint8>(a * Other.a / 255);
00096
00097     return *this;
00098 }
00099
00100
00104 bool Color::operator ==(const Color& Other) const
00105 {
00106     return (r == Other.r) && (g == Other.g) && (b == Other.b) && (a == Other.a);
00107 }
00108
00109
00113 bool Color::operator !=(const Color& Other) const
00114 {
00115     return (r != Other.r) || (g != Other.g) || (b != Other.b) || (a != Other.a);
00116 }
00117
00118
00122 Color operator +(const Color& Color1, const Color& Color2)
00123 {
00124     Color c = Color1;
00125     c += Color2;
00126
00127     return c;
00128 }
00129
00130
00134 Color operator *(const Color& Color1, const Color& Color2)
00135 {
00136     Color c = Color1;
00137     c *= Color2;
00138
00139     return c;
00140 }
00141
00142 } // namespace sf


  • File List

Color.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_COLOR_HPP
00026 #define SFML_COLOR_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 namespace sf
00035 {
00040 class SFML_API Color
00041 {
00042 public :
00043
00048     Color();
00049
00059     Color(Uint8 R, Uint8 G, Uint8 B, Uint8 A = 255);
00060
00069     Color& operator +=(const Color& Other);
00070
00079     Color& operator *=(const Color& Other);
00080
00089     bool operator ==(const Color& Other) const;
00090
00099     bool operator !=(const Color& Other) const;
00100
00102     // Static member data
00104     static const Color Black;
00105     static const Color White;
00106     static const Color Red;
00107     static const Color Green;
00108     static const Color Blue;
00109     static const Color Yellow;
00110     static const Color Magenta;
00111     static const Color Cyan;
00112
00114     // Member data
00116     Uint8 r;
00117     Uint8 g;
00118     Uint8 b;
00119     Uint8 a;
00120 };
00121
00131 SFML_API Color operator +(const Color& Color1, const Color& Color2);
00132
00142 SFML_API Color operator *(const Color& Color1, const Color& Color2);
00143
00144 } // namespace sf
00145
00146
00147 #endif // SFML_COLOR_HPP


  • File List

Config.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_CONFIG_HPP
00026 #define SFML_CONFIG_HPP
00027
00029 // Identify the operating system
00031 #if defined(_WIN32) || defined(__WIN32__)
00032
00033     // Windows
00034     #define SFML_SYSTEM_WINDOWS
00035     #ifndef WIN32_LEAN_AND_MEAN
00036         #define WIN32_LEAN_AND_MEAN
00037     #endif
00038     #ifndef NOMINMAX
00039         #define NOMINMAX
00040     #endif
00041
00042 #elif defined(linux) || defined(__linux)
00043
00044     // Linux
00045     #define SFML_SYSTEM_LINUX
00046
00047 #elif defined(__APPLE__) || defined(MACOSX) || defined(macintosh) || defined(Macintosh)
00048
00049     // MacOS
00050     #define SFML_SYSTEM_MACOS
00051
00052 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
00053
00054     // FreeBSD
00055     #define SFML_SYSTEM_FREEBSD
00056
00057 #else
00058
00059     // Unsupported system
00060     #error This operating system is not supported by SFML library
00061
00062 #endif
00063
00064
00066 // Define a portable debug macro
00068 #if !defined(NDEBUG)
00069
00070     #define SFML_DEBUG
00071
00072 #endif
00073
00074
00076 // Define portable import / export macros
00078 #if defined(SFML_SYSTEM_WINDOWS)
00079
00080     #ifdef SFML_DYNAMIC
00081
00082         // Windows platforms
00083         #ifdef SFML_EXPORTS
00084
00085             // From DLL side, we must export
00086             #define SFML_API __declspec(dllexport)
00087
00088         #else
00089
00090             // From client application side, we must import
00091             #define SFML_API __declspec(dllimport)
00092
00093         #endif
00094
00095         // For Visual C++ compilers, we also need to turn off this annoying C4251 warning.
00096         // You can read lots ot different things about it, but the point is the code will
00097         // just work fine, and so the simplest way to get rid of this warning is to disable it
00098         #ifdef _MSC_VER
00099
00100             #pragma warning(disable : 4251)
00101
00102         #endif
00103
00104     #else
00105
00106         // No specific directive needed for static build
00107         #define SFML_API
00108
00109     #endif
00110
00111 #else
00112
00113     // Other platforms don't need to define anything
00114     #define SFML_API
00115
00116 #endif
00117
00118
00120 // Define portable fixed-size types
00122 #include <climits>
00123
00124 namespace sf
00125 {
00126     // 8 bits integer types
00127     #if UCHAR_MAX == 0xFF
00128         typedef signed   char Int8;
00129         typedef unsigned char Uint8;
00130     #else
00131         #error No 8 bits integer type for this platform
00132     #endif
00133
00134     // 16 bits integer types
00135     #if USHRT_MAX == 0xFFFF
00136         typedef signed   short Int16;
00137         typedef unsigned short Uint16;
00138     #elif UINT_MAX == 0xFFFF
00139         typedef signed   int Int16;
00140         typedef unsigned int Uint16;
00141     #elif ULONG_MAX == 0xFFFF
00142         typedef signed   long Int16;
00143         typedef unsigned long Uint16;
00144     #else
00145         #error No 16 bits integer type for this platform
00146     #endif
00147
00148     // 32 bits integer types
00149     #if USHRT_MAX == 0xFFFFFFFF
00150         typedef signed   short Int32;
00151         typedef unsigned short Uint32;
00152     #elif UINT_MAX == 0xFFFFFFFF
00153         typedef signed   int Int32;
00154         typedef unsigned int Uint32;
00155     #elif ULONG_MAX == 0xFFFFFFFF
00156         typedef signed   long Int32;
00157         typedef unsigned long Uint32;
00158     #else
00159         #error No 32 bits integer type for this platform
00160     #endif
00161
00162 } // namespace sf
00163
00164
00165 #endif // SFML_CONFIG_HPP


  • File List

Context.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Window/Context.hpp>
00029 #include <SFML/Window/WindowImpl.hpp>
00030
00031
00032 namespace
00033 {
00034     // Make sure the dummy context is created at global startup
00035     sf::Context& Dummy = sf::Context::GetGlobal();
00036 }
00037
00038
00039 namespace sf
00040 {
00044 Context::Context()
00045 {
00046     myDummyWindow = priv::WindowImpl::New();
00047 }
00048
00049
00053 Context::~Context()
00054 {
00055     delete myDummyWindow;
00056 }
00057
00058
00062 void Context::SetActive(bool Active)
00063 {
00064     myDummyWindow->SetActive(Active);
00065 }
00066
00067
00071 bool Context::IsContextActive()
00072 {
00073     return priv::WindowImpl::IsContextActive();
00074 }
00075
00076
00080 Context& Context::GetGlobal()
00081 {
00082     static Context* GlobalContext = new Context; // Never deleted, on purpose
00083
00084     return *GlobalContext;
00085 }
00086
00087 } // namespace sf


  • File List

Context.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_CONTEXT_HPP
00026 #define SFML_CONTEXT_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <SFML/System/NonCopyable.hpp>
00033
00034
00035 namespace sf
00036 {
00037 namespace priv
00038 {
00039     class WindowImpl;
00040 }
00041
00049 class SFML_API Context : NonCopyable
00050 {
00051 public :
00052
00057     Context();
00058
00063     ~Context();
00064
00071     void SetActive(bool Active);
00072
00079     static bool IsContextActive();
00080
00087     static Context& GetGlobal();
00088
00089 private :
00090
00092     // Member data
00094     priv::WindowImpl* myDummyWindow;
00095 };
00096
00097 } // namespace sf
00098
00099
00100 #endif // SFML_CONTEXT_HPP


  • File List

Doxygen.hpp

00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072


  • File List

Drawable.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Graphics/Drawable.hpp>
00029 #include <SFML/Graphics/GraphicsContext.hpp>
00030 #include <SFML/Window/Window.hpp>
00031 #include <math.h>
00032
00033
00034 namespace sf
00035 {
00039 Drawable::Drawable(const Vector2f& Position, const Vector2f& Scale, float Rotation, const Color& Col) :
00040 myPosition     (Position),
00041 myScale        (Scale),
00042 myCenter       (0, 0),
00043 myRotation     (Rotation),
00044 myColor        (Col),
00045 myBlendMode    (Blend::Alpha),
00046 myNeedUpdate   (true),
00047 myInvNeedUpdate(true)
00048 {
00049
00050 }
00051
00052
00056 Drawable::~Drawable()
00057 {
00058     // Nothing to do
00059 }
00060
00061
00065 void Drawable::SetPosition(float X, float Y)
00066 {
00067     SetX(X);
00068     SetY(Y);
00069 }
00070
00071
00075 void Drawable::SetPosition(const Vector2f& Position)
00076 {
00077     SetX(Position.x);
00078     SetY(Position.y);
00079 }
00080
00081
00085 void Drawable::SetX(float X)
00086 {
00087     myPosition.x    = X;
00088     myNeedUpdate    = true;
00089     myInvNeedUpdate = true;
00090 }
00091
00092
00096 void Drawable::SetY(float Y)
00097 {
00098     myPosition.y    = Y;
00099     myNeedUpdate    = true;
00100     myInvNeedUpdate = true;
00101 }
00102
00103
00107 void Drawable::SetScale(float ScaleX, float ScaleY)
00108 {
00109     SetScaleX(ScaleX);
00110     SetScaleY(ScaleY);
00111 }
00112
00113
00117 void Drawable::SetScale(const Vector2f& Scale)
00118 {
00119     SetScaleX(Scale.x);
00120     SetScaleY(Scale.y);
00121 }
00122
00123
00127 void Drawable::SetScaleX(float FactorX)
00128 {
00129     if (FactorX > 0)
00130     {
00131         myScale.x       = FactorX;
00132         myNeedUpdate    = true;
00133         myInvNeedUpdate = true;
00134     }
00135 }
00136
00137
00141 void Drawable::SetScaleY(float FactorY)
00142 {
00143     if (FactorY > 0)
00144     {
00145         myScale.y       = FactorY;
00146         myNeedUpdate    = true;
00147         myInvNeedUpdate = true;
00148     }
00149 }
00150
00151
00157 void Drawable::SetCenter(float CenterX, float CenterY)
00158 {
00159     myCenter.x      = CenterX;
00160     myCenter.y      = CenterY;
00161     myNeedUpdate    = true;
00162     myInvNeedUpdate = true;
00163 }
00164
00165
00171 void Drawable::SetCenter(const Vector2f& Center)
00172 {
00173     SetCenter(Center.x, Center.y);
00174 }
00175
00176
00180 void Drawable::SetRotation(float Rotation)
00181 {
00182     myRotation = static_cast<float>(fmod(Rotation, 360));
00183     if (myRotation < 0)
00184         myRotation += 360.f;
00185     myNeedUpdate    = true;
00186     myInvNeedUpdate = true;
00187 }
00188
00189
00194 void Drawable::SetColor(const Color& Col)
00195 {
00196     myColor = Col;
00197 }
00198
00199
00204 void Drawable::SetBlendMode(Blend::Mode Mode)
00205 {
00206     myBlendMode = Mode;
00207 }
00208
00209
00213 const Vector2f& Drawable::GetPosition() const
00214 {
00215     return myPosition;
00216 }
00217
00218
00222 const Vector2f& Drawable::GetScale() const
00223 {
00224     return myScale;
00225 }
00226
00227
00231 const Vector2f& Drawable::GetCenter() const
00232 {
00233     return myCenter;
00234 }
00235
00236
00240 float Drawable::GetRotation() const
00241 {
00242     return myRotation;
00243 }
00244
00245
00249 const Color& Drawable::GetColor() const
00250 {
00251     return myColor;
00252 }
00253
00254
00258 Blend::Mode Drawable::GetBlendMode() const
00259 {
00260     return myBlendMode;
00261 }
00262
00263
00268 void Drawable::Move(float OffsetX, float OffsetY)
00269 {
00270     SetX(myPosition.x + OffsetX);
00271     SetY(myPosition.y + OffsetY);
00272 }
00273
00274
00278 void Drawable::Move(const Vector2f& Offset)
00279 {
00280     Move(Offset.x, Offset.y);
00281 }
00282
00283
00287 void Drawable::Scale(float FactorX, float FactorY)
00288 {
00289     SetScaleX(myScale.x * FactorX);
00290     SetScaleY(myScale.y * FactorY);
00291 }
00292
00293
00297 void Drawable::Scale(const Vector2f& Factor)
00298 {
00299     Scale(Factor.x, Factor.y);
00300 }
00301
00302
00306 void Drawable::Rotate(float Angle)
00307 {
00308     SetRotation(myRotation + Angle);
00309 }
00310
00311
00316 sf::Vector2f Drawable::TransformToLocal(const sf::Vector2f& Point) const
00317 {
00318     return GetInverseMatrix().Transform(Point);
00319 }
00320
00325 sf::Vector2f Drawable::TransformToGlobal(const sf::Vector2f& Point) const
00326 {
00327     return GetMatrix().Transform(Point);
00328 }
00329
00330
00334 const Matrix3& Drawable::GetMatrix() const
00335 {
00336     // First recompute it if needed
00337     if (myNeedUpdate)
00338     {
00339         myMatrix.SetFromTransformations(myCenter, myPosition, myRotation, myScale);
00340         myNeedUpdate = false;
00341     }
00342
00343     return myMatrix;
00344 }
00345
00346
00350 const Matrix3& Drawable::GetInverseMatrix() const
00351 {
00352     // First recompute it if needed
00353     if (myInvNeedUpdate)
00354     {
00355         myInvMatrix     = GetMatrix().GetInverse();
00356         myInvNeedUpdate = false;
00357     }
00358
00359     return myInvMatrix;
00360 }
00361
00362
00366 void Drawable::Draw(RenderTarget& Target) const
00367 {
00368     // Save the current modelview matrix and set the new one
00369     GLCheck(glMatrixMode(GL_MODELVIEW));
00370     GLCheck(glPushMatrix());
00371     GLCheck(glMultMatrixf(GetMatrix().Get4x4Elements()));
00372
00373     // Setup alpha-blending
00374     if (myBlendMode == Blend::None)
00375     {
00376         GLCheck(glDisable(GL_BLEND));
00377     }
00378     else
00379     {
00380         GLCheck(glEnable(GL_BLEND));
00381
00382         switch (myBlendMode)
00383         {
00384             case Blend::Alpha :    GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); break;
00385             case Blend::Add :      GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE));                 break;
00386             case Blend::Multiply : GLCheck(glBlendFunc(GL_DST_COLOR, GL_ZERO));                break;
00387             default :                                                                          break;
00388         }
00389     }
00390
00391     // Set color
00392     GLCheck(glColor4f(myColor.r / 255.f, myColor.g / 255.f, myColor.b / 255.f, myColor.a / 255.f));
00393
00394     // Let the derived class render the object geometry
00395     Render(Target);
00396
00397     // Restore the previous modelview matrix
00398     GLCheck(glMatrixMode(GL_MODELVIEW));
00399     GLCheck(glPopMatrix());
00400 }
00401
00402 } // namespace sf


  • File List

Drawable.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_DRAWABLE_HPP
00026 #define SFML_DRAWABLE_HPP
00027
00029 // Headers
00031 #include <SFML/System/Vector2.hpp>
00032 #include <SFML/Graphics/Color.hpp>
00033 #include <SFML/Graphics/Matrix3.hpp>
00034
00035
00036 namespace sf
00037 {
00038 class RenderTarget;
00039
00043 namespace Blend
00044 {
00045     enum Mode
00046     {
00047         Alpha,
00048         Add,
00049         Multiply,
00050         None
00051     };
00052 }
00053
00058 class SFML_API Drawable
00059 {
00060 public :
00061
00071     Drawable(const Vector2f& Position = Vector2f(0, 0), const Vector2f& Scale = Vector2f(1, 1), float Rotation = 0.f, const Color& Col = Color(255, 255, 255, 255));
00072
00077     virtual ~Drawable();
00078
00086     void SetPosition(float X, float Y);
00087
00094     void SetPosition(const Vector2f& Position);
00095
00102     void SetX(float X);
00103
00110     void SetY(float Y);
00111
00119     void SetScale(float ScaleX, float ScaleY);
00120
00127     void SetScale(const Vector2f& Scale);
00128
00135     void SetScaleX(float FactorX);
00136
00143     void SetScaleY(float FactorY);
00144
00154     void SetCenter(float CenterX, float CenterY);
00155
00164     void SetCenter(const Vector2f& Center);
00165
00172     void SetRotation(float Rotation);
00173
00181     void SetColor(const Color& Col);
00182
00190     void SetBlendMode(Blend::Mode Mode);
00191
00198     const Vector2f& GetPosition() const;
00199
00206     const Vector2f& GetScale() const;
00207
00214     const Vector2f& GetCenter() const;
00215
00223     float GetRotation() const;
00224
00231     const Color& GetColor() const;
00232
00239     Blend::Mode GetBlendMode() const;
00240
00248     void Move(float OffsetX, float OffsetY);
00249
00256     void Move(const Vector2f& Offset);
00257
00265     void Scale(float FactorX, float FactorY);
00266
00273     void Scale(const Vector2f& Factor);
00274
00281     void Rotate(float Angle);
00282
00292     sf::Vector2f TransformToLocal(const sf::Vector2f& Point) const;
00293
00303     sf::Vector2f TransformToGlobal(const sf::Vector2f& Point) const;
00304
00305 protected :
00306
00313     const Matrix3& GetMatrix() const;
00314
00321     const Matrix3& GetInverseMatrix() const;
00322
00323 private :
00324
00325     friend class RenderTarget;
00326
00333     void Draw(RenderTarget& Target) const;
00334
00341     virtual void Render(RenderTarget& Target) const = 0;
00342
00344     // Member data
00346     Vector2f        myPosition;
00347     Vector2f        myScale;
00348     Vector2f        myCenter;
00349     float           myRotation;
00350     Color           myColor;
00351     Blend::Mode     myBlendMode;
00352     mutable bool    myNeedUpdate;
00353     mutable bool    myInvNeedUpdate;
00354     mutable Matrix3 myMatrix;
00355     mutable Matrix3 myInvMatrix;
00356 };
00357
00358 } // namespace sf
00359
00360
00361 #endif // SFML_DRAWABLE_HPP


  • File List

Event.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_EVENT_HPP
00026 #define SFML_EVENT_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 namespace sf
00035 {
00039 namespace Key
00040 {
00041     enum Code
00042     {
00043         A = 'a',
00044         B = 'b',
00045         C = 'c',
00046         D = 'd',
00047         E = 'e',
00048         F = 'f',
00049         G = 'g',
00050         H = 'h',
00051         I = 'i',
00052         J = 'j',
00053         K = 'k',
00054         L = 'l',
00055         M = 'm',
00056         N = 'n',
00057         O = 'o',
00058         P = 'p',
00059         Q = 'q',
00060         R = 'r',
00061         S = 's',
00062         T = 't',
00063         U = 'u',
00064         V = 'v',
00065         W = 'w',
00066         X = 'x',
00067         Y = 'y',
00068         Z = 'z',
00069         Num0 = '0',
00070         Num1 = '1',
00071         Num2 = '2',
00072         Num3 = '3',
00073         Num4 = '4',
00074         Num5 = '5',
00075         Num6 = '6',
00076         Num7 = '7',
00077         Num8 = '8',
00078         Num9 = '9',
00079         Escape = 256,
00080         LControl,
00081         LShift,
00082         LAlt,
00083         LSystem,
00084         RControl,
00085         RShift,
00086         RAlt,
00087         RSystem,
00088         Menu,
00089         LBracket,
00090         RBracket,
00091         SemiColon,
00092         Comma,
00093         Period,
00094         Quote,
00095         Slash,
00096         BackSlash,
00097         Tilde,
00098         Equal,
00099         Dash,
00100         Space,
00101         Return,
00102         Back,
00103         Tab,
00104         PageUp,
00105         PageDown,
00106         End,
00107         Home,
00108         Insert,
00109         Delete,
00110         Add,
00111         Subtract,
00112         Multiply,
00113         Divide,
00114         Left,
00115         Right,
00116         Up,
00117         Down,
00118         Numpad0,
00119         Numpad1,
00120         Numpad2,
00121         Numpad3,
00122         Numpad4,
00123         Numpad5,
00124         Numpad6,
00125         Numpad7,
00126         Numpad8,
00127         Numpad9,
00128         F1,
00129         F2,
00130         F3,
00131         F4,
00132         F5,
00133         F6,
00134         F7,
00135         F8,
00136         F9,
00137         F10,
00138         F11,
00139         F12,
00140         F13,
00141         F14,
00142         F15,
00143         Pause,
00144
00145         Count // Keep last -- total number of keyboard keys
00146     };
00147 }
00148
00149
00153 namespace Mouse
00154 {
00155     enum Button
00156     {
00157         Left,
00158         Right,
00159         Middle,
00160         XButton1,
00161         XButton2,
00162
00163         ButtonCount // Keep last -- total number of mouse buttons
00164     };
00165 }
00166
00167
00171 namespace Joy
00172 {
00173     enum Axis
00174     {
00175         AxisX,
00176         AxisY,
00177         AxisZ,
00178         AxisR,
00179         AxisU,
00180         AxisV,
00181         AxisPOV,
00182
00183         AxisCount // Keep last -- total number of joystick axis
00184     };
00185
00186     enum
00187     {
00188         Count       = 4,
00189         ButtonCount = 32
00190     };
00191 }
00192
00193
00197 class Event
00198 {
00199 public :
00200
00204     struct KeyEvent
00205     {
00206         Key::Code Code;
00207         bool      Alt;
00208         bool      Control;
00209         bool      Shift;
00210     };
00211
00215     struct TextEvent
00216     {
00217         Uint32 Unicode;
00218     };
00219
00223     struct MouseMoveEvent
00224     {
00225         int X;
00226         int Y;
00227     };
00228
00232     struct MouseButtonEvent
00233     {
00234         Mouse::Button Button;
00235         int           X;
00236         int           Y;
00237     };
00238
00242     struct MouseWheelEvent
00243     {
00244         int Delta;
00245     };
00246
00250     struct JoyMoveEvent
00251     {
00252         unsigned int JoystickId;
00253         Joy::Axis    Axis;
00254         float        Position;
00255     };
00256
00260     struct JoyButtonEvent
00261     {
00262         unsigned int JoystickId;
00263         unsigned int Button;
00264     };
00265
00269     struct SizeEvent
00270     {
00271         unsigned int Width;
00272         unsigned int Height;
00273     };
00274
00278     enum EventType
00279     {
00280         Closed,
00281         Resized,
00282         LostFocus,
00283         GainedFocus,
00284         TextEntered,
00285         KeyPressed,
00286         KeyReleased,
00287         MouseWheelMoved,
00288         MouseButtonPressed,
00289         MouseButtonReleased,
00290         MouseMoved,
00291         MouseEntered,
00292         MouseLeft,
00293         JoyButtonPressed,
00294         JoyButtonReleased,
00295         JoyMoved,
00296
00297         Count // Keep last -- total number of event types
00298     };
00299
00301     // Member data
00303     EventType Type;
00304
00305     union
00306     {
00307         KeyEvent         Key;
00308         TextEvent        Text;
00309         MouseMoveEvent   MouseMove;
00310         MouseButtonEvent MouseButton;
00311         MouseWheelEvent  MouseWheel;
00312         JoyMoveEvent     JoyMove;
00313         JoyButtonEvent   JoyButton;
00314         SizeEvent        Size;
00315     };
00316 };
00317
00318 } // namespace sf
00319
00320
00321 #endif // SFML_EVENT_HPP


  • File List

Font.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Graphics/Font.hpp>
00029 #include <SFML/Graphics/FontLoader.hpp>
00030 #include <iostream>
00031
00032
00033 namespace sf
00034 {
00036 // Static member data
00038 Uint32 Font::ourDefaultCharset[] =
00039 {
00040     // Printable characters in ASCII range
00041     0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
00042     0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
00043     0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
00044     0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
00045     0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
00046     0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E,
00047
00048     // Printable characters in extended ASCII range
00049     0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0x2A, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
00050     0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
00051     0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
00052     0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
00053     0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
00054     0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE,
00055
00056     // To make it a valid string
00057     0x00
00058 };
00059
00060
00064 Font::Font() :
00065 myCharSize(0)
00066 {
00067
00068 }
00069
00070
00074 bool Font::LoadFromFile(const std::string& Filename, unsigned int CharSize, const Unicode::Text& Charset)
00075 {
00076     // Clear the previous character map
00077     myGlyphs.clear();
00078
00079     // Always add these special characters
00080     Unicode::UTF32String UTFCharset = Charset;
00081     if (UTFCharset.find(L' ')  != Unicode::UTF32String::npos) UTFCharset += L' ';
00082     if (UTFCharset.find(L'\n') != Unicode::UTF32String::npos) UTFCharset += L'\n';
00083     if (UTFCharset.find(L'\v') != Unicode::UTF32String::npos) UTFCharset += L'\v';
00084     if (UTFCharset.find(L'\t') != Unicode::UTF32String::npos) UTFCharset += L'\t';
00085
00086     return priv::FontLoader::GetInstance().LoadFontFromFile(Filename, CharSize, UTFCharset, *this);
00087 }
00088
00089
00093 bool Font::LoadFromMemory(const char* Data, std::size_t SizeInBytes, unsigned int CharSize, const Unicode::Text& Charset)
00094 {
00095     // Clear the previous character map
00096     myGlyphs.clear();
00097
00098     // Check parameters
00099     if (!Data || (SizeInBytes == 0))
00100     {
00101         std::cerr << "Failed to load font from memory, no data provided" << std::endl;
00102         return false;
00103     }
00104
00105     // Always add these special characters
00106     Unicode::UTF32String UTFCharset = Charset;
00107     if (UTFCharset.find(L' ')  != Unicode::UTF32String::npos) UTFCharset += L' ';
00108     if (UTFCharset.find(L'\n') != Unicode::UTF32String::npos) UTFCharset += L'\n';
00109     if (UTFCharset.find(L'\v') != Unicode::UTF32String::npos) UTFCharset += L'\v';
00110     if (UTFCharset.find(L'\t') != Unicode::UTF32String::npos) UTFCharset += L'\t';
00111
00112     return priv::FontLoader::GetInstance().LoadFontFromMemory(Data, SizeInBytes, CharSize, UTFCharset, *this);
00113 }
00114
00115
00120 unsigned int Font::GetCharacterSize() const
00121 {
00122     return myCharSize;
00123 }
00124
00125
00130 const Glyph& Font::GetGlyph(Uint32 CodePoint) const
00131 {
00132     std::map<Uint32, Glyph>::const_iterator It = myGlyphs.find(CodePoint);
00133     if (It != myGlyphs.end())
00134     {
00135         // Valid glyph
00136         return It->second;
00137     }
00138     else
00139     {
00140         // Invalid glyph -- return an invalid glyph
00141         static const Glyph InvalidGlyph;
00142         return InvalidGlyph;
00143     }
00144 }
00145
00146
00150 const Image& Font::GetImage() const
00151 {
00152     return myTexture;
00153 }
00154
00155
00159 const Font& Font::GetDefaultFont()
00160 {
00161 #if defined(SFML_SYSTEM_WINDOWS) && defined(SFML_DYNAMIC)
00162
00163     // On Windows dynamic build, the default font causes a crash at global exit.
00164     // This is a temporary workaround that turns the crash into a memory leak.
00165     // Note that this bug doesn't exist anymore in SFML 2.
00166     static Font* DefaultFontPtr = new Font;
00167     Font& DefaultFont = *DefaultFontPtr;
00168
00169 #else
00170
00171     static Font DefaultFont;
00172
00173 #endif
00174
00175     // Get the raw data of the Arial font file into an array, so that we can load it into the font
00176     static const char DefaultFontData[] =
00177     {
00178         #include <SFML/Graphics/Arial.hpp>
00179     };
00180
00181     // Load the default font on first call
00182     static bool DefaultFontLoaded = false;
00183     if (!DefaultFontLoaded)
00184     {
00185         DefaultFont.LoadFromMemory(DefaultFontData, sizeof(DefaultFontData), 30);
00186         DefaultFontLoaded = true;
00187     }
00188
00189     return DefaultFont;
00190 }
00191
00192 } // namespace sf


  • File List

Font.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_FONT_HPP
00026 #define SFML_FONT_HPP
00027
00029 // Headers
00031 #include <SFML/System/Resource.hpp>
00032 #include <SFML/System/Vector2.hpp>
00033 #include <SFML/System/Unicode.hpp>
00034 #include <SFML/Graphics/Glyph.hpp>
00035 #include <SFML/Graphics/Image.hpp>
00036 #include <SFML/Graphics/Rect.hpp>
00037 #include <map>
00038 #include <string>
00039
00040
00041 namespace sf
00042 {
00043 class String;
00044
00045 namespace priv
00046 {
00047 class FontLoader;
00048 }
00054 class SFML_API Font : public Resource<Font>
00055 {
00056 public :
00057
00062     Font();
00063
00074     bool LoadFromFile(const std::string& Filename, unsigned int CharSize = 30, const Unicode::Text& Charset = ourDefaultCharset);
00075
00087     bool LoadFromMemory(const char* Data, std::size_t SizeInBytes, unsigned int CharSize = 30, const Unicode::Text& Charset = ourDefaultCharset);
00088
00096     unsigned int GetCharacterSize() const;
00097
00107     const Glyph& GetGlyph(Uint32 CodePoint) const;
00108
00115     const Image& GetImage() const;
00116
00123     static const Font& GetDefaultFont();
00124
00125 private :
00126
00127     friend class priv::FontLoader;
00128
00130     // Static member data
00132     static Uint32 ourDefaultCharset[];
00133
00135     // Member data
00137     Image                   myTexture;
00138     unsigned int            myCharSize;
00139     std::map<Uint32, Glyph> myGlyphs;
00140 };
00141
00142 } // namespace sf
00143
00144
00145 #endif // SFML_FONT_HPP


  • File List

FontLoader.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Graphics/FontLoader.hpp>
00029 #include <SFML/Graphics/Color.hpp>
00030 #include <SFML/Graphics/Font.hpp>
00031 #include <SFML/Graphics/Image.hpp>
00032 #include <SFML/Graphics/GraphicsContext.hpp>
00033 #include FT_GLYPH_H
00034 #include <iostream>
00035 #include <map>
00036 #include <vector>
00037 #include <math.h>
00038
00039
00040 namespace
00041 {
00043     // Functor to sort glyphs by size
00045     struct SizeCompare
00046     {
00047         bool operator ()(FT_BitmapGlyph Glyph1, FT_BitmapGlyph Glyph2) const
00048         {
00049             return Glyph2->bitmap.rows < Glyph1->bitmap.rows;
00050         }
00051     };
00052 }
00053
00054 namespace sf
00055 {
00056 namespace priv
00057 {
00061 FontLoader& FontLoader::GetInstance()
00062 {
00063     static FontLoader Instance;
00064
00065     return Instance;
00066 }
00067
00068
00072 FontLoader::FontLoader()
00073 {
00074     // Initialize FreeType library
00075     FT_Error Error = FT_Init_FreeType(&myLibrary);
00076     if (Error)
00077     {
00078         std::cerr << "Failed to initialize FreeType library (error code : " << Error << ")" << std::endl;
00079         return;
00080     }
00081 }
00082
00083
00087 FontLoader::~FontLoader()
00088 {
00089     // Shutdown FreeType library
00090     if (myLibrary)
00091         FT_Done_FreeType(myLibrary);
00092 }
00093
00094
00098 bool FontLoader::LoadFontFromFile(const std::string& Filename, unsigned int CharSize, const Unicode::UTF32String& Charset, Font& LoadedFont)
00099 {
00100     // Check if Freetype is correctly initialized
00101     if (!myLibrary)
00102     {
00103         std::cerr << "Failed to load font \"" << Filename << "\", FreeType has not been initialized" << std::endl;
00104         return false;
00105     }
00106
00107     // Create a new font face from the specified file
00108     FT_Face FontFace;
00109     FT_Error Error = FT_New_Face(myLibrary, Filename.c_str(), 0, &FontFace);
00110     if (Error)
00111     {
00112         std::cerr << "Failed to load font \"" << Filename << "\" (" << GetErrorDesc(Error) << ")" << std::endl;
00113         return false;
00114     }
00115
00116     // Create the bitmap font
00117     Error = CreateBitmapFont(FontFace, CharSize, Charset, LoadedFont);
00118     if (Error)
00119         std::cerr << "Failed to load font \"" << Filename << "\" (" << GetErrorDesc(Error) << ")" << std::endl;
00120
00121     // Delete the font
00122     FT_Done_Face(FontFace);
00123
00124     return Error == 0;
00125 }
00126
00127
00131 bool FontLoader::LoadFontFromMemory(const char* Data, std::size_t SizeInBytes, unsigned int CharSize, const Unicode::UTF32String& Charset, Font& LoadedFont)
00132 {
00133     // Check if Freetype is correctly initialized
00134     if (!myLibrary)
00135     {
00136         std::cerr << "Failed to load font from memory, FreeType has not been initialized" << std::endl;
00137         return false;
00138     }
00139
00140     // Create a new font face from the specified memory data
00141     FT_Face FontFace;
00142     FT_Error Error = FT_New_Memory_Face(myLibrary, reinterpret_cast<const FT_Byte*>(Data), static_cast<FT_Long>(SizeInBytes), 0, &FontFace);
00143     if (Error)
00144     {
00145         std::cerr << "Failed to load font from memory (" << GetErrorDesc(Error) << ")" << std::endl;
00146         return false;
00147     }
00148
00149     // Create the bitmap font
00150     Error = CreateBitmapFont(FontFace, CharSize, Charset, LoadedFont);
00151     if (Error)
00152         std::cerr << "Failed to load font from memory (" << GetErrorDesc(Error) << ")" << std::endl;
00153
00154     // Delete the font
00155     FT_Done_Face(FontFace);
00156
00157     return Error == 0;
00158 }
00159
00160
00164 FT_Error FontLoader::CreateBitmapFont(FT_Face FontFace, unsigned int CharSize, const Unicode::UTF32String& Charset, Font& LoadedFont)
00165 {
00166     // Make sure we have a valid context
00167     priv::GraphicsContext Ctx;
00168
00169     // Let's find how many characters to put in each row to make them fit into a squared texture
00170     GLint MaxSize;
00171     GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxSize));
00172     int NbChars = static_cast<int>(sqrt(static_cast<double>(Charset.length())) * 0.75);
00173
00174     // Clamp the character size to make sure we won't create a texture too big
00175     if (NbChars * CharSize >= static_cast<unsigned int>(MaxSize))
00176         CharSize = MaxSize / NbChars;
00177
00178     // Initialize the dimensions
00179     unsigned int Left      = 0;
00180     unsigned int Top       = 0;
00181     unsigned int TexWidth  = Image::GetValidTextureSize(CharSize * NbChars);
00182     unsigned int TexHeight = CharSize * NbChars;
00183     std::vector<unsigned int> Tops(TexWidth, 0);
00184
00185     // Create a pixel buffer for rendering every glyph
00186     std::vector<Uint8> GlyphsBuffer(TexWidth * TexHeight * 4);
00187
00188     // Setup the font size
00189     FT_Error Error = FT_Set_Pixel_Sizes(FontFace, CharSize, CharSize);
00190     if (Error)
00191         return Error;
00192
00193     // Select the unicode character map
00194     Error = FT_Select_Charmap(FontFace, FT_ENCODING_UNICODE);
00195     if (Error)
00196         return Error;
00197
00198     // Render all glyphs and sort them by size to optimize texture space
00199     typedef std::multimap<FT_BitmapGlyph, Uint32, SizeCompare> GlyphTable;
00200     GlyphTable Glyphs;
00201     for (std::size_t i = 0; i < Charset.length(); ++i)
00202     {
00203         // Load the glyph corresponding to the current character
00204         Error = FT_Load_Char(FontFace, Charset[i], FT_LOAD_TARGET_NORMAL);
00205         if (Error)
00206             return Error;
00207
00208         // Convert the glyph to a bitmap (ie. rasterize it)
00209         FT_Glyph Glyph;
00210         Error = FT_Get_Glyph(FontFace->glyph, &Glyph);
00211         if (Error)
00212             return Error;
00213         FT_Glyph_To_Bitmap(&Glyph, FT_RENDER_MODE_NORMAL, 0, 1);
00214         FT_BitmapGlyph BitmapGlyph = (FT_BitmapGlyph)Glyph;
00215
00216         // Add it to the sorted table of glyphs
00217         Glyphs.insert(std::make_pair(BitmapGlyph, Charset[i]));
00218     }
00219
00220     // Copy the rendered glyphs into the texture
00221     unsigned int MaxHeight = 0;
00222     std::map<Uint32, IntRect> Coords;
00223     for (GlyphTable::const_iterator i = Glyphs.begin(); i != Glyphs.end(); ++i)
00224     {
00225         // Get the bitmap of the current glyph
00226         Glyph&         CurGlyph    = LoadedFont.myGlyphs[i->second];
00227         FT_BitmapGlyph BitmapGlyph = i->first;
00228         FT_Bitmap&     Bitmap      = BitmapGlyph->bitmap;
00229
00230         // Make sure we don't go over the texture width
00231         if (Left + Bitmap.width + 1 >= TexWidth)
00232             Left = 0;
00233
00234         // Compute the top coordinate
00235         Top = Tops[Left];
00236         for (int x = 0; x < Bitmap.width + 1; ++x)
00237             Top = std::max(Top, Tops[Left + x]);
00238         Top++;
00239
00240         // Make sure we don't go over the texture height -- resize it if we need more space
00241         if (Top + Bitmap.rows + 1 >= TexHeight)
00242         {
00243             TexHeight *= 2;
00244             GlyphsBuffer.resize(TexWidth * TexHeight * 4);
00245         }
00246
00247         // Store the character's position and size
00248         CurGlyph.Rectangle.Left   = BitmapGlyph->left;
00249         CurGlyph.Rectangle.Top    = -BitmapGlyph->top;
00250         CurGlyph.Rectangle.Right  = CurGlyph.Rectangle.Left + Bitmap.width;
00251         CurGlyph.Rectangle.Bottom = Bitmap.rows - BitmapGlyph->top;
00252         CurGlyph.Advance          = BitmapGlyph->root.advance.x >> 16;
00253
00254         // Texture size may change, so let the texture coordinates be calculated later
00255         Coords[i->second] = IntRect(Left + 1, Top + 1, Left + Bitmap.width + 1, Top + Bitmap.rows + 1);
00256
00257         // Draw the glyph into our bitmap font
00258         const Uint8* Pixels = Bitmap.buffer;
00259         for (int y = 0; y < Bitmap.rows; ++y)
00260         {
00261             for (int x = 0; x < Bitmap.width; ++x)
00262             {
00263                 std::size_t Index = x + Left + 1 + (y + Top + 1) * TexWidth;
00264                 GlyphsBuffer[Index * 4 + 0] = 255;
00265                 GlyphsBuffer[Index * 4 + 1] = 255;
00266                 GlyphsBuffer[Index * 4 + 2] = 255;
00267                 GlyphsBuffer[Index * 4 + 3] = Pixels[x];
00268             }
00269             Pixels += Bitmap.pitch;
00270         }
00271
00272         // Update the rendering coordinates
00273         for (int x = 0; x < Bitmap.width + 1; ++x)
00274             Tops[Left + x] = Top + Bitmap.rows;
00275         Left += Bitmap.width + 1;
00276         if (Top + Bitmap.rows > MaxHeight)
00277             MaxHeight = Top + Bitmap.rows;
00278
00279         // Delete the glyph
00280         FT_Done_Glyph((FT_Glyph)BitmapGlyph);
00281     }
00282
00283     // Create the font's texture
00284     TexHeight = MaxHeight + 1;
00285     GlyphsBuffer.resize(TexWidth * TexHeight * 4);
00286     LoadedFont.myTexture.LoadFromPixels(TexWidth, TexHeight, &GlyphsBuffer[0]);
00287
00288     // Now that the texture is created, we can precompute texture coordinates
00289     for (std::size_t i = 0; i < Charset.size(); ++i)
00290     {
00291         Uint32 CurChar = Charset[i];
00292         LoadedFont.myGlyphs[CurChar].TexCoords = LoadedFont.myTexture.GetTexCoords(Coords[CurChar]);
00293     }
00294
00295     // Update the character size (it may have been changed by the function)
00296     LoadedFont.myCharSize = CharSize;
00297
00298     return 0;
00299 }
00300
00301
00305 std::string FontLoader::GetErrorDesc(FT_Error Error)
00306 {
00307     switch (Error)
00308     {
00309         // Generic errors
00310         case FT_Err_Cannot_Open_Resource :      return "cannot open resource";
00311         case FT_Err_Unknown_File_Format :       return "unknown file format";
00312         case FT_Err_Invalid_File_Format :       return "broken file";
00313         case FT_Err_Invalid_Version :           return "invalid FreeType version";
00314         case FT_Err_Lower_Module_Version :      return "module version is too low";
00315         case FT_Err_Invalid_Argument :          return "invalid argument";
00316         case FT_Err_Unimplemented_Feature :     return "unimplemented feature";
00317         case FT_Err_Invalid_Table :             return "broken table";
00318         case FT_Err_Invalid_Offset :            return "broken offset within table";
00319
00320         // Glyph / character errors
00321         case FT_Err_Invalid_Glyph_Index :       return "invalid glyph index";
00322         case FT_Err_Invalid_Character_Code :    return "invalid character code";
00323         case FT_Err_Invalid_Glyph_Format :      return "unsupported glyph image format";
00324         case FT_Err_Cannot_Render_Glyph :       return "cannot render this glyph format";
00325         case FT_Err_Invalid_Outline :           return "invalid outline";
00326         case FT_Err_Invalid_Composite :         return "invalid composite glyph";
00327         case FT_Err_Too_Many_Hints :            return "too many hints";
00328         case FT_Err_Invalid_Pixel_Size :        return "invalid pixel size";
00329
00330         // Handle errors
00331         case FT_Err_Invalid_Handle :            return "invalid object handle";
00332         case FT_Err_Invalid_Library_Handle :    return "invalid library handle";
00333         case FT_Err_Invalid_Driver_Handle :     return "invalid module handle";
00334         case FT_Err_Invalid_Face_Handle :       return "invalid face handle";
00335         case FT_Err_Invalid_Size_Handle :       return "invalid size handle";
00336         case FT_Err_Invalid_Slot_Handle :       return "invalid glyph slot handle";
00337         case FT_Err_Invalid_CharMap_Handle :    return "invalid charmap handle";
00338         case FT_Err_Invalid_Cache_Handle :      return "invalid cache manager handle";
00339         case FT_Err_Invalid_Stream_Handle :     return "invalid stream handle";
00340
00341         // Driver errors
00342         case FT_Err_Too_Many_Drivers :          return "too many modules";
00343         case FT_Err_Too_Many_Extensions :       return "too many extensions";
00344
00345         // Memory errors
00346         case FT_Err_Out_Of_Memory :             return "out of memory";
00347         case FT_Err_Unlisted_Object :           return "unlisted object";
00348
00349         // Stream errors
00350         case FT_Err_Cannot_Open_Stream :        return "cannot open stream";
00351         case FT_Err_Invalid_Stream_Seek :       return "invalid stream seek";
00352         case FT_Err_Invalid_Stream_Skip :       return "invalid stream skip";
00353         case FT_Err_Invalid_Stream_Read :       return "invalid stream read";
00354         case FT_Err_Invalid_Stream_Operation :  return "invalid stream operation";
00355         case FT_Err_Invalid_Frame_Operation :   return "invalid frame operation";
00356         case FT_Err_Nested_Frame_Access :       return "nested frame access";
00357         case FT_Err_Invalid_Frame_Read :        return "invalid frame read";
00358
00359         // Raster errors
00360         case FT_Err_Raster_Uninitialized :      return "raster uninitialized";
00361         case FT_Err_Raster_Corrupted :          return "raster corrupted";
00362         case FT_Err_Raster_Overflow :           return "raster overflow";
00363         case FT_Err_Raster_Negative_Height :    return "negative height while rastering";
00364
00365         // Cache errors
00366         case FT_Err_Too_Many_Caches :           return "too many registered caches";
00367
00368         // TrueType and SFNT errors
00369         case FT_Err_Invalid_Opcode :            return "invalid opcode";
00370         case FT_Err_Too_Few_Arguments :         return "too few arguments";
00371         case FT_Err_Stack_Overflow :            return "stack overflow";
00372         case FT_Err_Code_Overflow :             return "code overflow";
00373         case FT_Err_Bad_Argument :              return "bad argument";
00374         case FT_Err_Divide_By_Zero :            return "division by zero";
00375         case FT_Err_Invalid_Reference :         return "invalid reference";
00376         case FT_Err_Debug_OpCode :              return "found debug opcode";
00377         case FT_Err_ENDF_In_Exec_Stream :       return "found ENDF opcode in execution stream";
00378         case FT_Err_Nested_DEFS :               return "nested DEFS";
00379         case FT_Err_Invalid_CodeRange :         return "invalid code range";
00380         case FT_Err_Execution_Too_Long :        return "execution context too long";
00381         case FT_Err_Too_Many_Function_Defs :    return "too many function definitions";
00382         case FT_Err_Too_Many_Instruction_Defs : return "too many instruction definitions";
00383         case FT_Err_Table_Missing :             return "SFNT font table missing";
00384         case FT_Err_Horiz_Header_Missing :      return "horizontal header (hhea) table missing";
00385         case FT_Err_Locations_Missing :         return "locations (loca) table missing";
00386         case FT_Err_Name_Table_Missing :        return "name table missing";
00387         case FT_Err_CMap_Table_Missing :        return "character map (cmap) table missing";
00388         case FT_Err_Hmtx_Table_Missing :        return "horizontal metrics (hmtx) table missing";
00389         case FT_Err_Post_Table_Missing :        return "PostScript (post) table missing";
00390         case FT_Err_Invalid_Horiz_Metrics :     return "invalid horizontal metrics";
00391         case FT_Err_Invalid_CharMap_Format :    return "invalid character map (cmap) format";
00392         case FT_Err_Invalid_PPem :              return "invalid ppem value";
00393         case FT_Err_Invalid_Vert_Metrics :      return "invalid vertical metrics";
00394         case FT_Err_Could_Not_Find_Context :    return "could not find context";
00395         case FT_Err_Invalid_Post_Table_Format : return "invalid PostScript (post) table format";
00396         case FT_Err_Invalid_Post_Table :        return "invalid PostScript (post) table";
00397
00398         // CCF, CID and Type 1 errors
00399         case FT_Err_Syntax_Error :              return "opcode syntax error";
00400         case FT_Err_Stack_Underflow :           return "argument stack underflow";
00401         case FT_Err_Ignore :                    return "ignore";
00402
00403         // BDF errors
00404         case FT_Err_Missing_Startfont_Field :   return "`STARTFONT' field missing";
00405         case FT_Err_Missing_Font_Field :        return "`FONT' field missing";
00406         case FT_Err_Missing_Size_Field :        return "`SIZE' field missing";
00407         case FT_Err_Missing_Chars_Field :       return "`CHARS' field missing";
00408         case FT_Err_Missing_Startchar_Field :   return "`STARTCHAR' field missing";
00409         case FT_Err_Missing_Encoding_Field :    return "`ENCODING' field missing";
00410         case FT_Err_Missing_Bbx_Field :         return "`BBX' field missing";
00411     }
00412
00413     return "unknown error";
00414 }
00415
00416 } // namespace priv
00417
00418 } // namespace sf
00419


  • File List

FontLoader.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_FONTLOADER_HPP
00026 #define SFML_FONTLOADER_HPP
00027
00029 // Headers
00031 #include <SFML/System/NonCopyable.hpp>
00032 #include <SFML/System/Unicode.hpp>
00033 #include <ft2build.h>
00034 #include FT_FREETYPE_H
00035 #include <string>
00036
00037
00038 namespace sf
00039 {
00040 class Font;
00041
00042 namespace priv
00043 {
00047 class FontLoader : NonCopyable
00048 {
00049 public :
00050
00057     static FontLoader& GetInstance();
00058
00070     bool LoadFontFromFile(const std::string& Filename, unsigned int CharSize, const Unicode::UTF32String& Charset, Font& LoadedFont);
00071
00084     bool LoadFontFromMemory(const char* Data, std::size_t SizeInBytes, unsigned int CharSize, const Unicode::UTF32String& Charset, Font& LoadedFont);
00085
00086 private :
00087
00092     FontLoader();
00093
00098     ~FontLoader();
00099
00109     FT_Error CreateBitmapFont(FT_Face FontFace, unsigned int CharSize, const Unicode::UTF32String& Charset, Font& LoadedFont);
00110
00119     static std::string GetErrorDesc(FT_Error Error);
00120
00122     // Member data
00124     FT_Library myLibrary;
00125 };
00126
00127 } // namespace priv
00128
00129 } // namespace sf
00130
00131
00132 #endif // SFML_FONTLOADER_HPP


  • File List

Ftp.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Network/Ftp.hpp>
00029 #include <SFML/Network/IPAddress.hpp>
00030 #include <algorithm>
00031 #include <fstream>
00032 #include <iterator>
00033 #include <sstream>
00034
00035
00036 namespace sf
00037 {
00039 // Utility class for exchanging stuff with the server
00040 // on the data channel
00042 class Ftp::DataChannel : NonCopyable
00043 {
00044 public :
00045
00047     // Constructor
00049     DataChannel(Ftp& Owner);
00050
00052     // Destructor
00054     ~DataChannel();
00055
00057     // Open the data channel using the specified mode and port
00059     Ftp::Response Open(Ftp::TransferMode Mode);
00060
00062     // Send data on the data channel
00064     void Send(const std::vector<char>& Data);
00065
00067     // Receive data on the data channel until it is closed
00069     void Receive(std::vector<char>& Data);
00070
00071 private :
00072
00074     // Member data
00076     Ftp&      myFtp;
00077     SocketTCP myDataSocket;
00078 };
00079
00080
00084 Ftp::Response::Response(Status Code, const std::string& Message) :
00085 myStatus (Code),
00086 myMessage(Message)
00087 {
00088
00089 }
00090
00091
00096 bool Ftp::Response::IsOk() const
00097 {
00098     return myStatus < 400;
00099 }
00100
00101
00105 Ftp::Response::Status Ftp::Response::GetStatus() const
00106 {
00107     return myStatus;
00108 }
00109
00110
00114 const std::string& Ftp::Response::GetMessage() const
00115 {
00116     return myMessage;
00117 }
00118
00119
00123 Ftp::DirectoryResponse::DirectoryResponse(Ftp::Response Resp) :
00124 Ftp::Response(Resp)
00125 {
00126     if (IsOk())
00127     {
00128         // Extract the directory from the server response
00129         std::string::size_type Begin = Resp.GetMessage().find('"', 0);
00130         std::string::size_type End   = Resp.GetMessage().find('"', Begin + 1);
00131         myDirectory = Resp.GetMessage().substr(Begin + 1, End - Begin - 1);
00132     }
00133 }
00134
00135
00139 const std::string& Ftp::DirectoryResponse::GetDirectory() const
00140 {
00141     return myDirectory;
00142 }
00143
00144
00148 Ftp::ListingResponse::ListingResponse(Ftp::Response Resp, const std::vector<char>& Data) :
00149 Ftp::Response(Resp)
00150 {
00151     if (IsOk())
00152     {
00153         // Fill the array of strings
00154         std::string Paths(Data.begin(), Data.end());
00155         std::string::size_type LastPos = 0;
00156         for (std::string::size_type Pos = Paths.find("\r\n"); Pos != std::string::npos; Pos = Paths.find("\r\n", LastPos))
00157         {
00158             myFilenames.push_back(Paths.substr(LastPos, Pos - LastPos));
00159             LastPos = Pos + 2;
00160         }
00161     }
00162 }
00163
00164
00168 std::size_t Ftp::ListingResponse::GetCount() const
00169 {
00170     return myFilenames.size();
00171 }
00172
00173
00177 const std::string& Ftp::ListingResponse::GetFilename(std::size_t Index) const
00178 {
00179     return myFilenames[Index];
00180 }
00181
00182
00186 Ftp::~Ftp()
00187 {
00188     Disconnect();
00189 }
00190
00191
00195 Ftp::Response Ftp::Connect(const IPAddress& Server, unsigned short Port, float Timeout)
00196 {
00197     // Connect to the server
00198     if (myCommandSocket.Connect(Port, Server, Timeout) != Socket::Done)
00199         return Response(Response::ConnectionFailed);
00200
00201     // Get the response to the connection
00202     return GetResponse();
00203 }
00204
00205
00209 Ftp::Response Ftp::Login()
00210 {
00211     return Login("anonymous", "user@sfml-dev.org");
00212 }
00213
00214
00218 Ftp::Response Ftp::Login(const std::string& UserName, const std::string& Password)
00219 {
00220     Response Resp = SendCommand("USER", UserName);
00221     if (Resp.IsOk())
00222         Resp = SendCommand("PASS", Password);
00223
00224     return Resp;
00225 }
00226
00227
00231 Ftp::Response Ftp::Disconnect()
00232 {
00233     // Send the exit command
00234     Response Resp = SendCommand("QUIT");
00235     if (Resp.IsOk())
00236         myCommandSocket.Close();
00237
00238     return Resp;
00239 }
00240
00241
00245 Ftp::Response Ftp::KeepAlive()
00246 {
00247     return SendCommand("NOOP");
00248 }
00249
00250
00254 Ftp::DirectoryResponse Ftp::GetWorkingDirectory()
00255 {
00256     return DirectoryResponse(SendCommand("PWD"));
00257 }
00258
00259
00264 Ftp::ListingResponse Ftp::GetDirectoryListing(const std::string& Directory)
00265 {
00266     // Open a data channel on default port (20) using ASCII transfer mode
00267     std::vector<char> DirData;
00268     DataChannel Data(*this);
00269     Response Resp = Data.Open(Ascii);
00270     if (Resp.IsOk())
00271     {
00272         // Tell the server to send us the listing
00273         Resp = SendCommand("NLST", Directory);
00274         if (Resp.IsOk())
00275         {
00276             // Receive the listing
00277             Data.Receive(DirData);
00278
00279             // Get the response from the server
00280             Resp = GetResponse();
00281         }
00282     }
00283
00284     return ListingResponse(Resp, DirData);
00285 }
00286
00287
00291 Ftp::Response Ftp::ChangeDirectory(const std::string& Directory)
00292 {
00293     return SendCommand("CWD", Directory);
00294 }
00295
00296
00300 Ftp::Response Ftp::ParentDirectory()
00301 {
00302     return SendCommand("CDUP");
00303 }
00304
00305
00309 Ftp::Response Ftp::MakeDirectory(const std::string& Name)
00310 {
00311     return SendCommand("MKD", Name);
00312 }
00313
00314
00318 Ftp::Response Ftp::DeleteDirectory(const std::string& Name)
00319 {
00320     return SendCommand("RMD", Name);
00321 }
00322
00323
00327 Ftp::Response Ftp::RenameFile(const std::string& File, const std::string& NewName)
00328 {
00329     Response Resp = SendCommand("RNFR", File);
00330     if (Resp.IsOk())
00331        Resp = SendCommand("RNTO", NewName);
00332
00333     return Resp;
00334 }
00335
00336
00340 Ftp::Response Ftp::DeleteFile(const std::string& Name)
00341 {
00342     return SendCommand("DELE", Name);
00343 }
00344
00345
00349 Ftp::Response Ftp::Download(const std::string& DistantFile, const std::string& DestPath, TransferMode Mode)
00350 {
00351     // Open a data channel using the given transfer mode
00352     DataChannel Data(*this);
00353     Response Resp = Data.Open(Mode);
00354     if (Resp.IsOk())
00355     {
00356         // Tell the server to start the transfer
00357         Resp = SendCommand("RETR", DistantFile);
00358         if (Resp.IsOk())
00359         {
00360             // Receive the file data
00361             std::vector<char> FileData;
00362             Data.Receive(FileData);
00363
00364             // Get the response from the server
00365             Resp = GetResponse();
00366             if (Resp.IsOk())
00367             {
00368                 // Extract the filename from the file path
00369                 std::string Filename = DistantFile;
00370                 std::string::size_type Pos = Filename.find_last_of("/\\");
00371                 if (Pos != std::string::npos)
00372                     Filename = Filename.substr(Pos + 1);
00373
00374                 // Make sure the destination path ends with a slash
00375                 std::string Path = DestPath;
00376                 if (!Path.empty() && (Path[Path.size() - 1] != '\\') && (Path[Path.size() - 1] != '/'))
00377                     Path += "/";
00378
00379                 // Create the file and copy the received data into it
00380                 std::ofstream File((Path + Filename).c_str(), std::ios_base::binary);
00381                 if (!File)
00382                     return Response(Response::InvalidFile);
00383                 if (!FileData.empty())
00384                     File.write(&FileData[0], static_cast<std::streamsize>(FileData.size()));
00385             }
00386         }
00387     }
00388
00389     return Resp;
00390 }
00391
00392
00396 Ftp::Response Ftp::Upload(const std::string& LocalFile, const std::string& DestPath, TransferMode Mode)
00397 {
00398     // Get the contents of the file to send
00399     std::ifstream File(LocalFile.c_str(), std::ios_base::binary);
00400     if (!File)
00401         return Response(Response::InvalidFile);
00402     File.seekg(0, std::ios::end);
00403     std::size_t Length = File.tellg();
00404     File.seekg(0, std::ios::beg);
00405     std::vector<char> FileData(Length);
00406     if (Length > 0)
00407         File.read(&FileData[0], static_cast<std::streamsize>(Length));
00408
00409     // Extract the filename from the file path
00410     std::string Filename = LocalFile;
00411     std::string::size_type Pos = Filename.find_last_of("/\\");
00412     if (Pos != std::string::npos)
00413         Filename = Filename.substr(Pos + 1);
00414
00415     // Make sure the destination path ends with a slash
00416     std::string Path = DestPath;
00417     if (!Path.empty() && (Path[Path.size() - 1] != '\\') && (Path[Path.size() - 1] != '/'))
00418         Path += "/";
00419
00420     // Open a data channel using the given transfer mode
00421     DataChannel Data(*this);
00422     Response Resp = Data.Open(Mode);
00423     if (Resp.IsOk())
00424     {
00425         // Tell the server to start the transfer
00426         Resp = SendCommand("STOR", Path + Filename);
00427         if (Resp.IsOk())
00428         {
00429             // Send the file data
00430             Data.Send(FileData);
00431
00432             // Get the response from the server
00433             Resp = GetResponse();
00434         }
00435     }
00436
00437     return Resp;
00438 }
00439
00440
00444 Ftp::Response Ftp::SendCommand(const std::string& Command, const std::string& Parameter)
00445 {
00446     // Build the command string
00447     std::string CommandStr;
00448     if (Parameter != "")
00449         CommandStr = Command + " " + Parameter + "\r\n";
00450     else
00451         CommandStr = Command + "\r\n";
00452
00453     // Send it to the server
00454     if (myCommandSocket.Send(CommandStr.c_str(), CommandStr.length()) != sf::Socket::Done)
00455         return Response(Response::ConnectionClosed);
00456
00457     // Get the response
00458     return GetResponse();
00459 }
00460
00461
00466 Ftp::Response Ftp::GetResponse()
00467 {
00468     // We'll use a variable to keep track of the last valid code.
00469     // It is useful in case of multi-lines responses, because the end of such a response
00470     // will start by the same code
00471     unsigned int LastCode  = 0;
00472     bool IsInsideMultiline = false;
00473     std::string Message;
00474
00475     for (;;)
00476     {
00477         // Receive the response from the server
00478         char Buffer[1024];
00479         std::size_t Length;
00480         if (myCommandSocket.Receive(Buffer, sizeof(Buffer), Length) != sf::Socket::Done)
00481             return Response(Response::ConnectionClosed);
00482
00483         // There can be several lines inside the received buffer, extract them all
00484         std::istringstream In(std::string(Buffer, Length), std::ios_base::binary);
00485         while (In)
00486         {
00487             // Try to extract the code
00488             unsigned int Code;
00489             if (In >> Code)
00490             {
00491                 // Extract the separator
00492                 char Sep;
00493                 In.get(Sep);
00494
00495                 // The '-' character means a multiline response
00496                 if ((Sep == '-') && !IsInsideMultiline)
00497                 {
00498                     // Set the multiline flag
00499                     IsInsideMultiline = true;
00500
00501                     // Keep track of the code
00502                     if (LastCode == 0)
00503                         LastCode = Code;
00504
00505                     // Extract the line
00506                     std::getline(In, Message);
00507
00508                     // Remove the ending '\r' (all lines are terminated by "\r\n")
00509                     Message.erase(Message.length() - 1);
00510                     Message = Sep + Message + "\n";
00511                 }
00512                 else
00513                 {
00514                     // We must make sure that the code is the same, otherwise it means
00515                     // we haven't reached the end of the multiline response
00516                     if ((Sep != '-') && ((Code == LastCode) || (LastCode == 0)))
00517                     {
00518                         // Clear the multiline flag
00519                         IsInsideMultiline = false;
00520
00521                         // Extract the line
00522                         std::string Line;
00523                         std::getline(In, Line);
00524
00525                         // Remove the ending '\r' (all lines are terminated by "\r\n")
00526                         Line.erase(Line.length() - 1);
00527
00528                         // Append it to the message
00529                         if (Code == LastCode)
00530                         {
00531                             std::ostringstream Out;
00532                             Out << Code << Sep << Line;
00533                             Message += Out.str();
00534                         }
00535                         else
00536                         {
00537                             Message = Sep + Line;
00538                         }
00539
00540                         // Return the response code and message
00541                         return Response(static_cast<Response::Status>(Code), Message);
00542                     }
00543                     else
00544                     {
00545                         // The line we just read was actually not a response,
00546                         // only a new part of the current multiline response
00547
00548                         // Extract the line
00549                         std::string Line;
00550                         std::getline(In, Line);
00551
00552                         if (!Line.empty())
00553                         {
00554                             // Remove the ending '\r' (all lines are terminated by "\r\n")
00555                             Line.erase(Line.length() - 1);
00556
00557                             // Append it to the current message
00558                             std::ostringstream Out;
00559                             Out << Code << Sep << Line << "\n";
00560                             Message += Out.str();
00561                         }
00562                     }
00563                 }
00564             }
00565             else if (LastCode != 0)
00566             {
00567                 // It seems we are in the middle of a multiline response
00568
00569                 // Clear the error bits of the stream
00570                 In.clear();
00571
00572                 // Extract the line
00573                 std::string Line;
00574                 std::getline(In, Line);
00575
00576                 if (!Line.empty())
00577                 {
00578                     // Remove the ending '\r' (all lines are terminated by "\r\n")
00579                     Line.erase(Line.length() - 1);
00580
00581                     // Append it to the current message
00582                     Message += Line + "\n";
00583                 }
00584             }
00585             else
00586             {
00587                 // Error : cannot extract the code, and we are not in a multiline response
00588                 return Response(Response::InvalidResponse);
00589             }
00590         }
00591     }
00592
00593     // We never reach there
00594 }
00595
00596
00600 Ftp::DataChannel::DataChannel(Ftp& Owner) :
00601 myFtp(Owner)
00602 {
00603
00604 }
00605
00606
00610 Ftp::DataChannel::~DataChannel()
00611 {
00612     // Close the data socket
00613     myDataSocket.Close();
00614 }
00615
00616
00620 Ftp::Response Ftp::DataChannel::Open(Ftp::TransferMode Mode)
00621 {
00622     // Open a data connection in active mode (we connect to the server)
00623     Ftp::Response Resp = myFtp.SendCommand("PASV");
00624     if (Resp.IsOk())
00625     {
00626         // Extract the connection address and port from the response
00627         std::string::size_type begin = Resp.GetMessage().find_first_of("0123456789");
00628         if (begin != std::string::npos)
00629         {
00630             sf::Uint8 Data[6] = {0, 0, 0, 0, 0, 0};
00631             std::string Str = Resp.GetMessage().substr(begin);
00632             std::size_t Index = 0;
00633             for (int i = 0; i < 6; ++i)
00634             {
00635                 // Extract the current number
00636                 while (isdigit(Str[Index]))
00637                 {
00638                     Data[i] = Data[i] * 10 + (Str[Index] - '0');
00639                     Index++;
00640                 }
00641
00642                 // Skip separator
00643                 Index++;
00644             }
00645
00646             // Reconstruct connection port and address
00647             unsigned short Port = Data[4] * 256 + Data[5];
00648             sf::IPAddress Address(static_cast<sf::Uint8>(Data[0]),
00649                                   static_cast<sf::Uint8>(Data[1]),
00650                                   static_cast<sf::Uint8>(Data[2]),
00651                                   static_cast<sf::Uint8>(Data[3]));
00652
00653             // Connect the data channel to the server
00654             if (myDataSocket.Connect(Port, Address) == Socket::Done)
00655             {
00656                 // Translate the transfer mode to the corresponding FTP parameter
00657                 std::string ModeStr;
00658                 switch (Mode)
00659                 {
00660                     case Ftp::Binary : ModeStr = "I"; break;
00661                     case Ftp::Ascii :  ModeStr = "A"; break;
00662                     case Ftp::Ebcdic : ModeStr = "E"; break;
00663                 }
00664
00665                 // Set the transfer mode
00666                 Resp = myFtp.SendCommand("TYPE", ModeStr);
00667             }
00668             else
00669             {
00670                 // Failed to connect to the server
00671                 Resp = Ftp::Response(Ftp::Response::ConnectionFailed);
00672             }
00673         }
00674     }
00675
00676     return Resp;
00677 }
00678
00679
00683 void Ftp::DataChannel::Receive(std::vector<char>& Data)
00684 {
00685     // Receive data
00686     Data.clear();
00687     char Buffer[1024];
00688     std::size_t Received;
00689     while (myDataSocket.Receive(Buffer, sizeof(Buffer), Received) == sf::Socket::Done)
00690     {
00691         std::copy(Buffer, Buffer + Received, std::back_inserter(Data));
00692     }
00693
00694     // Close the data socket
00695     myDataSocket.Close();
00696 }
00697
00698
00702 void Ftp::DataChannel::Send(const std::vector<char>& Data)
00703 {
00704     // Send data
00705     if (!Data.empty())
00706         myDataSocket.Send(&Data[0], Data.size());
00707
00708     // Close the data socket
00709     myDataSocket.Close();
00710 }
00711
00712 } // namespace sf


  • File List

Ftp.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_FTP_HPP
00026 #define SFML_FTP_HPP
00027
00029 // Headers
00031 #include <SFML/System/NonCopyable.hpp>
00032 #include <SFML/Network/SocketTCP.hpp>
00033 #include <string>
00034 #include <vector>
00035
00036
00037 namespace sf
00038 {
00039 class IPAddress;
00040
00047 class SFML_API Ftp : NonCopyable
00048 {
00049 public :
00050
00054     enum TransferMode
00055     {
00056         Binary,
00057         Ascii,
00058         Ebcdic
00059     };
00060
00066     class SFML_API Response
00067     {
00068     public :
00069
00074         enum Status
00075         {
00076             // 1xx: the requested action is being initiated,
00077             // expect another reply before proceeding with a new command
00078             RestartMarkerReply          = 110,
00079             ServiceReadySoon            = 120,
00080             DataConnectionAlreadyOpened = 125,
00081             OpeningDataConnection       = 150,
00082
00083             // 2xx: the requested action has been successfully completed
00084             Ok                    = 200,
00085             PointlessCommand      = 202,
00086             SystemStatus          = 211,
00087             DirectoryStatus       = 212,
00088             FileStatus            = 213,
00089             HelpMessage           = 214,
00090             SystemType            = 215,
00091             ServiceReady          = 220,
00092             ClosingConnection     = 221,
00093             DataConnectionOpened  = 225,
00094             ClosingDataConnection = 226,
00095             EnteringPassiveMode   = 227,
00096             LoggedIn              = 230,
00097             FileActionOk          = 250,
00098             DirectoryOk           = 257,
00099
00100             // 3xx: the command has been accepted, but the requested action
00101             // is dormant, pending receipt of further information
00102             NeedPassword       = 331,
00103             NeedAccountToLogIn = 332,
00104             NeedInformation    = 350,
00105
00106             // 4xx: the command was not accepted and the requested action did not take place,
00107             // but the error condition is temporary and the action may be requested again
00108             ServiceUnavailable        = 421,
00109             DataConnectionUnavailable = 425,
00110             TransferAborted           = 426,
00111             FileActionAborted         = 450,
00112             LocalError                = 451,
00113             InsufficientStorageSpace  = 452,
00114
00115             // 5xx: the command was not accepted and
00116             // the requested action did not take place
00117             CommandUnknown          = 500,
00118             ParametersUnknown       = 501,
00119             CommandNotImplemented   = 502,
00120             BadCommandSequence      = 503,
00121             ParameterNotImplemented = 504,
00122             NotLoggedIn             = 530,
00123             NeedAccountToStore      = 532,
00124             FileUnavailable         = 550,
00125             PageTypeUnknown         = 551,
00126             NotEnoughMemory         = 552,
00127             FilenameNotAllowed      = 553,
00128
00129             // 10xx: SFML custom codes
00130             InvalidResponse  = 1000,
00131             ConnectionFailed = 1001,
00132             ConnectionClosed = 1002,
00133             InvalidFile      = 1003
00134         };
00135
00143         Response(Status Code = InvalidResponse, const std::string& Message = "");
00144
00152         bool IsOk() const;
00153
00160         Status GetStatus() const;
00161
00168         const std::string& GetMessage() const;
00169
00170     private :
00171
00173         // Member data
00175         Status      myStatus;
00176         std::string myMessage;
00177     };
00178
00182     class SFML_API DirectoryResponse : public Response
00183     {
00184     public :
00185
00192         DirectoryResponse(Response Resp);
00193
00200         const std::string& GetDirectory() const;
00201
00202     private :
00203
00205         // Member data
00207         std::string myDirectory;
00208     };
00209
00210
00214     class SFML_API ListingResponse : public Response
00215     {
00216     public :
00217
00225         ListingResponse(Response Resp, const std::vector<char>& Data);
00226
00233         std::size_t GetCount() const;
00234
00243         const std::string& GetFilename(std::size_t Index) const;
00244
00245     private :
00246
00248         // Member data
00250         std::vector<std::string> myFilenames;
00251     };
00252
00253
00258     ~Ftp();
00259
00270     Response Connect(const IPAddress& Server, unsigned short Port = 21, float Timeout = 0.f);
00271
00278     Response Login();
00279
00289     Response Login(const std::string& UserName, const std::string& Password);
00290
00297     Response Disconnect();
00298
00305     Response KeepAlive();
00306
00313     DirectoryResponse GetWorkingDirectory();
00314
00324     ListingResponse GetDirectoryListing(const std::string& Directory = "");
00325
00334     Response ChangeDirectory(const std::string& Directory);
00335
00342     Response ParentDirectory();
00343
00352     Response MakeDirectory(const std::string& Name);
00353
00362     Response DeleteDirectory(const std::string& Name);
00363
00373     Response RenameFile(const std::string& File, const std::string& NewName);
00374
00383     Response DeleteFile(const std::string& Name);
00384
00395     Response Download(const std::string& DistantFile, const std::string& DestPath, TransferMode Mode = Binary);
00396
00407     Response Upload(const std::string& LocalFile, const std::string& DestPath, TransferMode Mode = Binary);
00408
00409 private :
00410
00420     Response SendCommand(const std::string& Command, const std::string& Parameter = "");
00421
00429     Response GetResponse();
00430
00435     class DataChannel;
00436
00437     friend class DataChannel;
00438
00440     // Member data
00442     SocketTCP myCommandSocket;
00443 };
00444
00445 } // namespace sf
00446
00447
00448 #endif // SFML_FTP_HPP


  • File List

Glyph.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_GLYPH_HPP
00026 #define SFML_GLYPH_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <SFML/Graphics/Rect.hpp>
00033
00034
00035 namespace sf
00036 {
00040 class SFML_API Glyph
00041 {
00042 public :
00043
00048     Glyph() : Advance(0) {}
00049
00051     // Member data
00053     int       Advance;
00054     IntRect   Rectangle;
00055     FloatRect TexCoords;
00056 };
00057
00058 } // namespace sf
00059
00060
00061 #endif // SFML_GLYPH_HPP


  • File List

Graphics.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_GRAPHICS_HPP
00026 #define SFML_GRAPHICS_HPP
00027
00029 // Headers
00031
00032 #include <SFML/Window.hpp>
00033 #include <SFML/Graphics/Color.hpp>
00034 #include <SFML/Graphics/Font.hpp>
00035 #include <SFML/Graphics/Glyph.hpp>
00036 #include <SFML/Graphics/Image.hpp>
00037 #include <SFML/Graphics/PostFX.hpp>
00038 #include <SFML/Graphics/RenderWindow.hpp>
00039 #include <SFML/Graphics/Shape.hpp>
00040 #include <SFML/Graphics/Sprite.hpp>
00041 #include <SFML/Graphics/String.hpp>
00042 #include <SFML/Graphics/View.hpp>
00043
00044
00045 #endif // SFML_GRAPHICS_HPP


  • File List

GraphicsContext.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Graphics/GraphicsContext.hpp>
00029 #include <SFML/Window/Context.hpp>
00030
00031
00032 namespace
00033 {
00035     // One time initialization of 3rd party libraries.
00036     // We use a global function with a static boolean rather
00037     // than directly a global boolean, to avoid the randomness
00038     // of global variables initializations across compile units.
00040     void InitGraphicsLibs()
00041     {
00042         static bool InitDone = false;
00043         if (!InitDone)
00044         {
00045             // Initialize GLEW
00046             glewInit();
00047
00048             InitDone = true;
00049         }
00050     }
00051
00052 }
00053
00054
00055 namespace sf
00056 {
00057 namespace priv
00058 {
00063 GraphicsContext::GraphicsContext()
00064 {
00065     // Activate the global context
00066     if (!Context::IsContextActive())
00067     {
00068         Context::GetGlobal().SetActive(true);
00069         myActivated = true;
00070     }
00071     else
00072     {
00073         myActivated = false;
00074     }
00075
00076     // Make sure third party libraries are initialized
00077     InitGraphicsLibs();
00078 }
00079
00080
00085 GraphicsContext::~GraphicsContext()
00086 {
00087     // Deactivate the global context
00088     if (myActivated)
00089         Context::GetGlobal().SetActive(false);
00090 }
00091
00092 } // namespace priv
00093
00094 } // namespace sf


  • File List

GraphicsContext.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_GRAPHICSCONTEXT_HPP
00026 #define SFML_GRAPHICSCONTEXT_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <SFML/System/NonCopyable.hpp>
00033 #include <SFML/Graphics/GLEW/glew.h>
00034 #include <iostream>
00035 #include <string>
00036
00037
00038 namespace sf
00039 {
00040 class Context;
00041
00042 namespace priv
00043 {
00052 class GraphicsContext : NonCopyable
00053 {
00054 public :
00055
00061     GraphicsContext();
00062
00068     ~GraphicsContext();
00069
00070 private :
00071
00073     // Member data
00075     bool myActivated;
00076 };
00077
00078 } // namespace priv
00079
00080
00085 #ifdef SFML_DEBUG
00086
00087     // In debug mode, perform a test on every OpenGL call
00088     #define GLCheck(Func) ((Func), GLCheckError(__FILE__, __LINE__))
00089
00090 #else
00091
00092     // Else, we don't add any overhead
00093     #define GLCheck(Func) (Func)
00094
00095 #endif
00096
00097
00102 inline void GLCheckError(const std::string& File, unsigned int Line)
00103 {
00104     // Get the last error
00105     GLenum ErrorCode = glGetError();
00106
00107     if (ErrorCode != GL_NO_ERROR)
00108     {
00109         std::string Error = "unknown error";
00110         std::string Desc  = "no description";
00111
00112         // Decode the error code
00113         switch (ErrorCode)
00114         {
00115             case GL_INVALID_ENUM :
00116             {
00117                 Error = "GL_INVALID_ENUM";
00118                 Desc  = "an unacceptable value has been specified for an enumerated argument";
00119                 break;
00120             }
00121
00122             case GL_INVALID_VALUE :
00123             {
00124                 Error = "GL_INVALID_VALUE";
00125                 Desc  = "a numeric argument is out of range";
00126                 break;
00127             }
00128
00129             case GL_INVALID_OPERATION :
00130             {
00131                 Error = "GL_INVALID_OPERATION";
00132                 Desc  = "the specified operation is not allowed in the current state";
00133                 break;
00134             }
00135
00136             case GL_STACK_OVERFLOW :
00137             {
00138                 Error = "GL_STACK_OVERFLOW";
00139                 Desc  = "this command would cause a stack overflow";
00140                 break;
00141             }
00142
00143             case GL_STACK_UNDERFLOW :
00144             {
00145                 Error = "GL_STACK_UNDERFLOW";
00146                 Desc  = "this command would cause a stack underflow";
00147                 break;
00148             }
00149
00150             case GL_OUT_OF_MEMORY :
00151             {
00152                 Error = "GL_OUT_OF_MEMORY";
00153                 Desc  = "there is not enough memory left to execute the command";
00154                 break;
00155             }
00156
00157             case GL_INVALID_FRAMEBUFFER_OPERATION_EXT :
00158             {
00159                 Error = "GL_INVALID_FRAMEBUFFER_OPERATION_EXT";
00160                 Desc  = "the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\"";
00161                 break;
00162             }
00163         }
00164
00165         // Log the error
00166         std::cerr << "An internal OpenGL call failed in "
00167                   << File.substr(File.find_last_of("\\/") + 1) << " (" << Line << ") : "
00168                   << Error << ", " << Desc
00169                   << std::endl;
00170     }
00171 }
00172
00173 } // namespace sf
00174
00175
00176 #endif // SFML_GRAPHICSCONTEXT_HPP


  • File List

Http.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Network/Http.hpp>
00029 #include <ctype.h>
00030 #include <algorithm>
00031 #include <iterator>
00032 #include <sstream>
00033
00034
00035 namespace
00036 {
00038     // Convenience function to convert a string to lower case
00040     std::string ToLower(const std::string& Str)
00041     {
00042         std::string Ret = Str;
00043         for (std::string::iterator i = Ret.begin(); i != Ret.end(); ++i)
00044             *i = static_cast<char>(tolower(*i));
00045
00046         return Ret;
00047     }
00048 }
00049
00050
00051 namespace sf
00052 {
00056 Http::Request::Request(Method RequestMethod, const std::string& URI, const std::string& Body)
00057 {
00058     SetMethod(RequestMethod);
00059     SetURI(URI);
00060     SetHttpVersion(1, 0);
00061     SetBody(Body);
00062 }
00063
00064
00068 void Http::Request::SetField(const std::string& Field, const std::string& Value)
00069 {
00070     myFields[ToLower(Field)] = Value;
00071 }
00072
00073
00078 void Http::Request::SetMethod(Http::Request::Method RequestMethod)
00079 {
00080     myMethod = RequestMethod;
00081 }
00082
00083
00088 void Http::Request::SetURI(const std::string& URI)
00089 {
00090     myURI = URI;
00091
00092     // Make sure it starts with a '/'
00093     if (myURI.empty() || (myURI[0] != '/'))
00094         myURI.insert(0, "/");
00095 }
00096
00097
00102 void Http::Request::SetHttpVersion(unsigned int Major, unsigned int Minor)
00103 {
00104     myMajorVersion = Major;
00105     myMinorVersion = Minor;
00106 }
00107
00108
00114 void Http::Request::SetBody(const std::string& Body)
00115 {
00116     myBody = Body;
00117 }
00118
00119
00123 std::string Http::Request::ToString() const
00124 {
00125     std::ostringstream Out;
00126
00127     // Convert the method to its string representation
00128     std::string RequestMethod;
00129     switch (myMethod)
00130     {
00131         default :
00132         case Get :  RequestMethod = "GET";  break;
00133         case Post : RequestMethod = "POST"; break;
00134         case Head : RequestMethod = "HEAD"; break;
00135     }
00136
00137     // Write the first line containing the request type
00138     Out << RequestMethod << " " << myURI << " ";
00139     Out << "HTTP/" << myMajorVersion << "." << myMinorVersion << "\r\n";
00140
00141     // Write fields
00142     for (FieldTable::const_iterator i = myFields.begin(); i != myFields.end(); ++i)
00143     {
00144         Out << i->first << ": " << i->second << "\r\n";
00145     }
00146
00147     // Use an extra \r\n to separate the header from the body
00148     Out << "\r\n";
00149
00150     // Add the body
00151     Out << myBody;
00152
00153     return Out.str();
00154 }
00155
00156
00160 bool Http::Request::HasField(const std::string& Field) const
00161 {
00162     return myFields.find(Field) != myFields.end();
00163 }
00164
00165
00169 Http::Response::Response() :
00170 myStatus      (ConnectionFailed),
00171 myMajorVersion(0),
00172 myMinorVersion(0)
00173 {
00174
00175 }
00176
00177
00181 const std::string& Http::Response::GetField(const std::string& Field) const
00182 {
00183     FieldTable::const_iterator It = myFields.find(ToLower(Field));
00184     if (It != myFields.end())
00185     {
00186         return It->second;
00187     }
00188     else
00189     {
00190         static const std::string Empty = "";
00191         return Empty;
00192     }
00193 }
00194
00195
00199 Http::Response::Status Http::Response::GetStatus() const
00200 {
00201     return myStatus;
00202 }
00203
00204
00208 unsigned int Http::Response::GetMajorHttpVersion() const
00209 {
00210     return myMajorVersion;
00211 }
00212
00213
00217 unsigned int Http::Response::GetMinorHttpVersion() const
00218 {
00219     return myMinorVersion;
00220 }
00221
00222
00230 const std::string& Http::Response::GetBody() const
00231 {
00232     return myBody;
00233 }
00234
00235
00239 void Http::Response::FromString(const std::string& Data)
00240 {
00241     std::istringstream In(Data);
00242
00243     // Extract the HTTP version from the first line
00244     std::string Version;
00245     if (In >> Version)
00246     {
00247         if ((Version.size() >= 8) && (Version[6] == '.') &&
00248             (ToLower(Version.substr(0, 5)) == "http/")   &&
00249              isdigit(Version[5]) && isdigit(Version[7]))
00250         {
00251             myMajorVersion = Version[5] - '0';
00252             myMinorVersion = Version[7] - '0';
00253         }
00254         else
00255         {
00256             // Invalid HTTP version
00257             myStatus = InvalidResponse;
00258             return;
00259         }
00260     }
00261
00262     // Extract the status code from the first line
00263     int StatusCode;
00264     if (In >> StatusCode)
00265     {
00266         myStatus = static_cast<Status>(StatusCode);
00267     }
00268     else
00269     {
00270         // Invalid status code
00271         myStatus = InvalidResponse;
00272         return;
00273     }
00274
00275     // Ignore the end of the first line
00276     In.ignore(10000, '\n');
00277
00278     // Parse the other lines, which contain fields, one by one
00279     std::string Line;
00280     while (std::getline(In, Line) && (Line.size() > 2))
00281     {
00282         std::string::size_type Pos = Line.find(": ");
00283         if (Pos != std::string::npos)
00284         {
00285             // Extract the field name and its value
00286             std::string Field = Line.substr(0, Pos);
00287             std::string Value = Line.substr(Pos + 2);
00288
00289             // Remove any trailing \r
00290             if (!Value.empty() && (*Value.rbegin() == '\r'))
00291                 Value.erase(Value.size() - 1);
00292
00293             // Add the field
00294             myFields[ToLower(Field)] = Value;
00295         }
00296     }
00297
00298     // Finally extract the body
00299     myBody.clear();
00300     std::copy(std::istreambuf_iterator<char>(In), std::istreambuf_iterator<char>(), std::back_inserter(myBody));
00301 }
00302
00303
00307 Http::Http() :
00308 myHost(),
00309 myPort(0)
00310 {
00311
00312 }
00313
00314
00318 Http::Http(const std::string& Host, unsigned short Port)
00319 {
00320     SetHost(Host, Port);
00321 }
00322
00323
00327 void Http::SetHost(const std::string& Host, unsigned short Port)
00328 {
00329     // Detect the protocol used
00330     std::string Protocol = ToLower(Host.substr(0, 8));
00331     if (Protocol.substr(0, 7) == "http://")
00332     {
00333         // HTTP protocol
00334         myHostName = Host.substr(7);
00335         myPort     = (Port != 0 ? Port : 80);
00336     }
00337     else if (Protocol == "https://")
00338     {
00339         // HTTPS protocol
00340         myHostName = Host.substr(8);
00341         myPort     = (Port != 0 ? Port : 443);
00342     }
00343     else
00344     {
00345         // Undefined protocol - use HTTP
00346         myHostName = Host;
00347         myPort     = (Port != 0 ? Port : 80);
00348     }
00349
00350     // Remove any trailing '/' from the host name
00351     if (!myHostName.empty() && (*myHostName.rbegin() == '/'))
00352         myHostName.erase(myHostName.size() - 1);
00353
00354     myHost = sf::IPAddress(myHostName);
00355 }
00356
00357
00366 Http::Response Http::SendRequest(const Http::Request& Req, float Timeout)
00367 {
00368     // First make sure the request is valid -- add missing mandatory fields
00369     Request ToSend(Req);
00370     if (!ToSend.HasField("From"))
00371     {
00372         ToSend.SetField("From", "user@sfml-dev.org");
00373     }
00374     if (!ToSend.HasField("User-Agent"))
00375     {
00376         ToSend.SetField("User-Agent", "libsfml-network/1.x");
00377     }
00378     if (!ToSend.HasField("Host"))
00379     {
00380         ToSend.SetField("Host", myHostName);
00381     }
00382     if (!ToSend.HasField("Content-Length"))
00383     {
00384         std::ostringstream Out;
00385         Out << ToSend.myBody.size();
00386         ToSend.SetField("Content-Length", Out.str());
00387     }
00388     if ((ToSend.myMethod == Request::Post) && !ToSend.HasField("Content-Type"))
00389     {
00390         ToSend.SetField("Content-Type", "application/x-www-form-urlencoded");
00391     }
00392     if ((ToSend.myMajorVersion * 10 + ToSend.myMinorVersion >= 11) && !ToSend.HasField("Connection"))
00393     {
00394         ToSend.SetField("Connection", "close");
00395     }
00396
00397     // Prepare the response
00398     Response Received;
00399
00400     // Connect the socket to the host
00401     if (myConnection.Connect(myPort, myHost, Timeout) == Socket::Done)
00402     {
00403         // Convert the request to string and send it through the connected socket
00404         std::string RequestStr = ToSend.ToString();
00405
00406         if (!RequestStr.empty())
00407         {
00408             // Send it through the socket
00409             if (myConnection.Send(RequestStr.c_str(), RequestStr.size()) == sf::Socket::Done)
00410             {
00411                 // Wait for the server's response
00412                 std::string ReceivedStr;
00413                 std::size_t Size = 0;
00414                 char Buffer[1024];
00415                 while (myConnection.Receive(Buffer, sizeof(Buffer), Size) == sf::Socket::Done)
00416                 {
00417                     ReceivedStr.append(Buffer, Buffer + Size);
00418                 }
00419
00420                 // Build the Response object from the received data
00421                 Received.FromString(ReceivedStr);
00422             }
00423         }
00424
00425         // Close the connection
00426         myConnection.Close();
00427     }
00428
00429     return Received;
00430 }
00431
00432 } // namespace sf


  • File List

Http.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_HTTP_HPP
00026 #define SFML_HTTP_HPP
00027
00029 // Headers
00031 #include <SFML/System/NonCopyable.hpp>
00032 #include <SFML/Network/IPAddress.hpp>
00033 #include <SFML/Network/SocketTCP.hpp>
00034 #include <map>
00035 #include <string>
00036
00037
00038 namespace sf
00039 {
00045 class SFML_API Http : NonCopyable
00046 {
00047 public :
00048
00054     class SFML_API Request
00055     {
00056     public :
00057
00061         enum Method
00062         {
00063             Get,
00064             Post,
00065             Head
00066         };
00067
00076         Request(Method RequestMethod = Get, const std::string& URI = "/", const std::string& Body = "");
00077
00085         void SetField(const std::string& Field, const std::string& Value);
00086
00094         void SetMethod(Method RequestMethod);
00095
00103         void SetURI(const std::string& URI);
00104
00113         void SetHttpVersion(unsigned int Major, unsigned int Minor);
00114
00123         void SetBody(const std::string& Body);
00124
00125     private :
00126
00127         friend class Http;
00128
00135         std::string ToString() const;
00136
00145         bool HasField(const std::string& Field) const;
00146
00148         // Types
00150         typedef std::map<std::string, std::string> FieldTable;
00151
00153         // Member data
00155         FieldTable   myFields;
00156         Method       myMethod;
00157         std::string  myURI;
00158         unsigned int myMajorVersion;
00159         unsigned int myMinorVersion;
00160         std::string  myBody;
00161     };
00162
00168     class SFML_API Response
00169     {
00170     public :
00171
00176         enum Status
00177         {
00178             // 2xx: success
00179             Ok        = 200,
00180             Created   = 201,
00181             Accepted  = 202,
00182             NoContent = 204,
00183
00184             // 3xx: redirection
00185             MultipleChoices  = 300,
00186             MovedPermanently = 301,
00187             MovedTemporarily = 302,
00188             NotModified      = 304,
00189
00190             // 4xx: client error
00191             BadRequest   = 400,
00192             Unauthorized = 401,
00193             Forbidden    = 403,
00194             NotFound     = 404,
00195
00196             // 5xx: server error
00197             InternalServerError = 500,
00198             NotImplemented      = 501,
00199             BadGateway          = 502,
00200             ServiceNotAvailable = 503,
00201
00202             // 10xx: SFML custom codes
00203             InvalidResponse  = 1000,
00204             ConnectionFailed = 1001
00205         };
00206
00211         Response();
00212
00221         const std::string& GetField(const std::string& Field) const;
00222
00229         Status GetStatus() const;
00230
00237         unsigned int GetMajorHttpVersion() const;
00238
00245         unsigned int GetMinorHttpVersion() const;
00246
00257         const std::string& GetBody() const;
00258
00259     private :
00260
00261         friend class Http;
00262
00269         void FromString(const std::string& Data);
00270
00272         // Types
00274         typedef std::map<std::string, std::string> FieldTable;
00275
00277         // Member data
00279         FieldTable   myFields;
00280         Status       myStatus;
00281         unsigned int myMajorVersion;
00282         unsigned int myMinorVersion;
00283         std::string  myBody;
00284     };
00285
00290     Http();
00291
00299     Http(const std::string& Host, unsigned short Port = 0);
00300
00308     void SetHost(const std::string& Host, unsigned short Port = 0);
00309
00324     Response SendRequest(const Request& Req, float Timeout = 0.f);
00325
00326 private :
00327
00329     // Member data
00331     SocketTCP      myConnection;
00332     IPAddress      myHost;
00333     std::string    myHostName;
00334     unsigned short myPort;
00335 };
00336
00337 } // namespace sf
00338
00339
00340 #endif // SFML_HTTP_HPP


  • File List

Image.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Graphics/Image.hpp>
00029 #include <SFML/Graphics/ImageLoader.hpp>
00030 #include <SFML/Graphics/RenderWindow.hpp>
00031 #include <SFML/Graphics/GraphicsContext.hpp>
00032 #include <algorithm>
00033 #include <iostream>
00034 #include <vector>
00035 #include <string.h>
00036
00037
00038 namespace sf
00039 {
00043 Image::Image() :
00044 myWidth            (0),
00045 myHeight           (0),
00046 myTextureWidth     (0),
00047 myTextureHeight    (0),
00048 myTexture          (0),
00049 myIsSmooth         (true),
00050 myNeedTextureUpdate(false),
00051 myNeedArrayUpdate  (false)
00052 {
00053
00054 }
00055
00056
00060 Image::Image(const Image& Copy) :
00061 Resource<Image>    (Copy),
00062 myWidth            (Copy.myWidth),
00063 myHeight           (Copy.myHeight),
00064 myTextureWidth     (Copy.myTextureWidth),
00065 myTextureHeight    (Copy.myTextureHeight),
00066 myTexture          (0),
00067 myIsSmooth         (Copy.myIsSmooth),
00068 myPixels           (Copy.myPixels),
00069 myNeedTextureUpdate(false),
00070 myNeedArrayUpdate  (false)
00071 {
00072     CreateTexture();
00073 }
00074
00075
00079 Image::Image(unsigned int Width, unsigned int Height, const Color& Col) :
00080 myWidth            (0),
00081 myHeight           (0),
00082 myTextureWidth     (0),
00083 myTextureHeight    (0),
00084 myTexture          (0),
00085 myIsSmooth         (true),
00086 myNeedTextureUpdate(false),
00087 myNeedArrayUpdate  (false)
00088 {
00089     Create(Width, Height, Col);
00090 }
00091
00092
00096 Image::Image(unsigned int Width, unsigned int Height, const Uint8* Data) :
00097 myWidth            (0),
00098 myHeight           (0),
00099 myTextureWidth     (0),
00100 myTextureHeight    (0),
00101 myTexture          (0),
00102 myIsSmooth         (true),
00103 myNeedTextureUpdate(false),
00104 myNeedArrayUpdate  (false)
00105 {
00106     LoadFromPixels(Width, Height, Data);
00107 }
00108
00109
00113 Image::~Image()
00114 {
00115     // Destroy the OpenGL texture
00116     DestroyTexture();
00117 }
00118
00119
00123 bool Image::LoadFromFile(const std::string& Filename)
00124 {
00125     // Let the image loader load the image into our pixel array
00126     bool Success = priv::ImageLoader::GetInstance().LoadImageFromFile(Filename, myPixels, myWidth, myHeight);
00127
00128     if (Success)
00129     {
00130         // Loading succeeded : we can create the texture
00131         if (CreateTexture())
00132             return true;
00133     }
00134
00135     // Oops... something failed
00136     Reset();
00137
00138     return false;
00139 }
00140
00141
00145 bool Image::LoadFromMemory(const char* Data, std::size_t SizeInBytes)
00146 {
00147     // Check parameters
00148     if (!Data || (SizeInBytes == 0))
00149     {
00150         std::cerr << "Failed to image font from memory, no data provided" << std::endl;
00151         return false;
00152     }
00153
00154     // Let the image loader load the image into our pixel array
00155     bool Success = priv::ImageLoader::GetInstance().LoadImageFromMemory(Data, SizeInBytes, myPixels, myWidth, myHeight);
00156
00157     if (Success)
00158     {
00159         // Loading succeeded : we can create the texture
00160         if (CreateTexture())
00161             return true;
00162     }
00163
00164     // Oops... something failed
00165     Reset();
00166
00167     return false;
00168 }
00169
00170
00174 bool Image::LoadFromPixels(unsigned int Width, unsigned int Height, const Uint8* Data)
00175 {
00176     if (Data)
00177     {
00178         // Store the texture dimensions
00179         myWidth  = Width;
00180         myHeight = Height;
00181
00182         // Fill the pixel buffer with the specified raw data
00183         const Color* Ptr = reinterpret_cast<const Color*>(Data);
00184         myPixels.assign(Ptr, Ptr + Width * Height);
00185
00186         // We can create the texture
00187         if (CreateTexture())
00188         {
00189             return true;
00190         }
00191         else
00192         {
00193             // Oops... something failed
00194             Reset();
00195             return false;
00196         }
00197     }
00198     else
00199     {
00200         // No data provided : create a white image
00201         return Create(Width, Height, Color(255, 255, 255, 255));
00202     }
00203 }
00204
00205
00209 bool Image::SaveToFile(const std::string& Filename) const
00210 {
00211     // Check if the array of pixels needs to be updated
00212     EnsureArrayUpdate();
00213
00214     // Let the image loader save our pixel array into the image
00215     return priv::ImageLoader::GetInstance().SaveImageToFile(Filename, myPixels, myWidth, myHeight);
00216 }
00217
00218
00222 bool Image::Create(unsigned int Width, unsigned int Height, Color Col)
00223 {
00224     // Store the texture dimensions
00225     myWidth  = Width;
00226     myHeight = Height;
00227
00228     // Recreate the pixel buffer and fill it with the specified color
00229     myPixels.clear();
00230     myPixels.resize(Width * Height, Col);
00231
00232     // We can create the texture
00233     if (CreateTexture())
00234     {
00235         return true;
00236     }
00237     else
00238     {
00239         // Oops... something failed
00240         Reset();
00241         return false;
00242     }
00243 }
00244
00245
00249 void Image::CreateMaskFromColor(Color ColorKey, Uint8 Alpha)
00250 {
00251     // Check if the array of pixels needs to be updated
00252     EnsureArrayUpdate();
00253
00254     // Calculate the new color (old color with no alpha)
00255     Color NewColor(ColorKey.r, ColorKey.g, ColorKey.b, Alpha);
00256
00257     // Replace the old color by the new one
00258     std::replace(myPixels.begin(), myPixels.end(), ColorKey, NewColor);
00259
00260     // The texture will need to be updated
00261     myNeedTextureUpdate = true;
00262 }
00263
00264
00270 void Image::Copy(const Image& Source, unsigned int DestX, unsigned int DestY, const IntRect& SourceRect, bool ApplyAlpha)
00271 {
00272     // Make sure both images are valid
00273     if ((Source.myWidth == 0) || (Source.myHeight == 0) || (myWidth == 0) || (myHeight == 0))
00274         return;
00275
00276     // Make sure both images have up-to-date arrays
00277     EnsureArrayUpdate();
00278     Source.EnsureArrayUpdate();
00279
00280     // Adjust the source rectangle
00281     IntRect SrcRect = SourceRect;
00282     if (SrcRect.GetWidth() == 0 || (SrcRect.GetHeight() == 0))
00283     {
00284         SrcRect.Left   = 0;
00285         SrcRect.Top    = 0;
00286         SrcRect.Right  = Source.myWidth;
00287         SrcRect.Bottom = Source.myHeight;
00288     }
00289     else
00290     {
00291         if (SrcRect.Left   < 0) SrcRect.Left = 0;
00292         if (SrcRect.Top    < 0) SrcRect.Top  = 0;
00293         if (SrcRect.Right  > static_cast<int>(Source.myWidth))  SrcRect.Right  = Source.myWidth;
00294         if (SrcRect.Bottom > static_cast<int>(Source.myHeight)) SrcRect.Bottom = Source.myHeight;
00295     }
00296
00297     // Then find the valid bounds of the destination rectangle
00298     int Width  = SrcRect.GetWidth();
00299     int Height = SrcRect.GetHeight();
00300     if (DestX + Width  > myWidth)  Width  = myWidth  - DestX;
00301     if (DestY + Height > myHeight) Height = myHeight - DestY;
00302
00303     // Make sure the destination area is valid
00304     if ((Width <= 0) || (Height <= 0))
00305         return;
00306
00307     // Precompute as much as possible
00308     int          Pitch     = Width * 4;
00309     int          Rows      = Height;
00310     int          SrcStride = Source.myWidth * 4;
00311     int          DstStride = myWidth * 4;
00312     const Uint8* SrcPixels = Source.GetPixelsPtr() + (SrcRect.Left + SrcRect.Top * Source.myWidth) * 4;
00313     Uint8*       DstPixels = reinterpret_cast<Uint8*>(&myPixels[0]) + (DestX + DestY * myWidth) * 4;
00314
00315     // Copy the pixels
00316     if (ApplyAlpha)
00317     {
00318         // Interpolation using alpha values, pixel by pixel (slower)
00319         for (int i = 0; i < Rows; ++i)
00320         {
00321             for (int j = 0; j < Width; ++j)
00322             {
00323                 // Get a direct pointer to the components of the current pixel
00324                 const Uint8* Src   = SrcPixels + j * 4;
00325                 Uint8*       Dst   = DstPixels + j * 4;
00326
00327                 // Interpolate RGB components using the alpha value of the source pixel
00328                 Uint8 Alpha = Src[3];
00329                 Dst[0] = (Src[0] * Alpha + Dst[0] * (255 - Alpha)) / 255;
00330                 Dst[1] = (Src[1] * Alpha + Dst[1] * (255 - Alpha)) / 255;
00331                 Dst[2] = (Src[2] * Alpha + Dst[2] * (255 - Alpha)) / 255;
00332             }
00333
00334             SrcPixels += SrcStride;
00335             DstPixels += DstStride;
00336         }
00337     }
00338     else
00339     {
00340         // Optimized copy ignoring alpha values, row by row (faster)
00341         for (int i = 0; i < Rows; ++i)
00342         {
00343             memcpy(DstPixels, SrcPixels, Pitch);
00344             SrcPixels += SrcStride;
00345             DstPixels += DstStride;
00346         }
00347     }
00348
00349     // The texture will need an update
00350     myNeedTextureUpdate = true;
00351 }
00352
00353
00358 bool Image::CopyScreen(RenderWindow& Window, const IntRect& SourceRect)
00359 {
00360     // Adjust the source rectangle
00361     IntRect SrcRect = SourceRect;
00362     if (SrcRect.GetWidth() == 0 || (SrcRect.GetHeight() == 0))
00363     {
00364         SrcRect.Left   = 0;
00365         SrcRect.Top    = 0;
00366         SrcRect.Right  = Window.GetWidth();
00367         SrcRect.Bottom = Window.GetHeight();
00368     }
00369     else
00370     {
00371         if (SrcRect.Left   < 0) SrcRect.Left = 0;
00372         if (SrcRect.Top    < 0) SrcRect.Top  = 0;
00373         if (SrcRect.Right  > static_cast<int>(Window.GetWidth()))  SrcRect.Right  = Window.GetWidth();
00374         if (SrcRect.Bottom > static_cast<int>(Window.GetHeight())) SrcRect.Bottom = Window.GetHeight();
00375     }
00376
00377     // Store the texture dimensions
00378     myWidth  = SrcRect.GetWidth();
00379     myHeight = SrcRect.GetHeight();
00380
00381     // We can then create the texture
00382     if (Window.SetActive() && CreateTexture())
00383     {
00384         GLint PreviousTexture;
00385         GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture));
00386
00387         GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
00388         GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, SrcRect.Left, SrcRect.Top, myWidth, myHeight));
00389
00390         GLCheck(glBindTexture(GL_TEXTURE_2D, PreviousTexture));
00391
00392         myNeedTextureUpdate = false;
00393         myNeedArrayUpdate = true;
00394
00395         return true;
00396     }
00397     else
00398     {
00399         Reset();
00400         return false;
00401     }
00402 }
00403
00404
00408 void Image::SetPixel(unsigned int X, unsigned int Y, const Color& Col)
00409 {
00410     // First check if the array of pixels needs to be updated
00411     EnsureArrayUpdate();
00412
00413     // Check if pixel is whithin the image bounds
00414     if ((X >= myWidth) || (Y >= myHeight))
00415     {
00416         std::cerr << "Cannot set pixel (" << X << "," << Y << ") for image "
00417                   << "(width = " << myWidth << ", height = " << myHeight << ")" << std::endl;
00418         return;
00419     }
00420
00421     myPixels[X + Y * myWidth] = Col;
00422
00423     // The texture will need to be updated
00424     myNeedTextureUpdate = true;
00425 }
00426
00427
00431 const Color& Image::GetPixel(unsigned int X, unsigned int Y) const
00432 {
00433     // First check if the array of pixels needs to be updated
00434     EnsureArrayUpdate();
00435
00436     // Check if pixel is whithin the image bounds
00437     if ((X >= myWidth) || (Y >= myHeight))
00438     {
00439         std::cerr << "Cannot get pixel (" << X << "," << Y << ") for image "
00440                   << "(width = " << myWidth << ", height = " << myHeight << ")" << std::endl;
00441         return Color::Black;
00442     }
00443
00444     return myPixels[X + Y * myWidth];
00445 }
00446
00447
00453 const Uint8* Image::GetPixelsPtr() const
00454 {
00455     // First check if the array of pixels needs to be updated
00456     EnsureArrayUpdate();
00457
00458     if (!myPixels.empty())
00459     {
00460         return reinterpret_cast<const Uint8*>(&myPixels[0]);
00461     }
00462     else
00463     {
00464         std::cerr << "Trying to access the pixels of an empty image" << std::endl;
00465         return NULL;
00466     }
00467 }
00468
00469
00473 void Image::Bind() const
00474 {
00475     // First check if the texture needs to be updated
00476     EnsureTextureUpdate();
00477
00478     // Bind it
00479     if (myTexture)
00480     {
00481         GLCheck(glEnable(GL_TEXTURE_2D));
00482         GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
00483     }
00484 }
00485
00486
00490 void Image::SetSmooth(bool Smooth)
00491 {
00492     if (Smooth != myIsSmooth)
00493     {
00494         myIsSmooth = Smooth;
00495
00496         if (myTexture)
00497         {
00498             // Make sure we have a valid context
00499             priv::GraphicsContext Ctx;
00500
00501             GLint PreviousTexture;
00502             GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture));
00503
00504             GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
00505             GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST));
00506             GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST));
00507
00508             GLCheck(glBindTexture(GL_TEXTURE_2D, PreviousTexture));
00509         }
00510     }
00511 }
00512
00513
00517 unsigned int Image::GetWidth() const
00518 {
00519     return myWidth;
00520 }
00521
00522
00526 unsigned int Image::GetHeight() const
00527 {
00528     return myHeight;
00529 }
00530
00531
00535 bool Image::IsSmooth() const
00536 {
00537     return myIsSmooth;
00538 }
00539
00540
00545 FloatRect Image::GetTexCoords(const IntRect& Rect) const
00546 {
00547     float Width  = static_cast<float>(myTextureWidth);
00548     float Height = static_cast<float>(myTextureHeight);
00549
00550     return FloatRect(Rect.Left   / Width,
00551                      Rect.Top    / Height,
00552                      Rect.Right  / Width,
00553                      Rect.Bottom / Height);
00554 }
00555
00556
00560 unsigned int Image::GetValidTextureSize(unsigned int Size)
00561 {
00562     // Make sure we have a valid context
00563     priv::GraphicsContext Ctx;
00564
00565     if (glewIsSupported("GL_ARB_texture_non_power_of_two") != 0)
00566     {
00567         // If hardware supports NPOT textures, then just return the unmodified size
00568         return Size;
00569     }
00570     else
00571     {
00572         // If hardware doesn't support NPOT textures, we calculate the nearest power of two
00573         unsigned int PowerOfTwo = 1;
00574         while (PowerOfTwo < Size)
00575             PowerOfTwo *= 2;
00576
00577         return PowerOfTwo;
00578     }
00579 }
00580
00581
00585 Image& Image::operator =(const Image& Other)
00586 {
00587     Image Temp(Other);
00588
00589     std::swap(myWidth,             Temp.myWidth);
00590     std::swap(myHeight,            Temp.myHeight);
00591     std::swap(myTextureWidth,      Temp.myTextureWidth);
00592     std::swap(myTextureHeight,     Temp.myTextureHeight);
00593     std::swap(myTexture,           Temp.myTexture);
00594     std::swap(myIsSmooth,          Temp.myIsSmooth);
00595     std::swap(myNeedArrayUpdate,   Temp.myNeedArrayUpdate);
00596     std::swap(myNeedTextureUpdate, Temp.myNeedTextureUpdate);
00597     myPixels.swap(Temp.myPixels);
00598
00599     return *this;
00600 }
00601
00602
00606 bool Image::CreateTexture()
00607 {
00608     // Check if texture parameters are valid before creating it
00609     if (!myWidth || !myHeight)
00610         return false;
00611
00612     // Make sure we have a valid context
00613     priv::GraphicsContext Ctx;
00614
00615     // Adjust internal texture dimensions depending on NPOT textures support
00616     unsigned int TextureWidth  = GetValidTextureSize(myWidth);
00617     unsigned int TextureHeight = GetValidTextureSize(myHeight);
00618
00619     // Check the maximum texture size
00620     GLint MaxSize;
00621     GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxSize));
00622     if ((TextureWidth > static_cast<unsigned int>(MaxSize)) || (TextureHeight > static_cast<unsigned int>(MaxSize)))
00623     {
00624         std::cerr << "Failed to create image, its internal size is too high (" << TextureWidth << "x" << TextureHeight << ")" << std::endl;
00625         return false;
00626     }
00627
00628     // Destroy the previous OpenGL texture if it already exists with another size
00629     if ((TextureWidth != myTextureWidth) || (TextureHeight != myTextureHeight))
00630     {
00631         DestroyTexture();
00632         myTextureWidth  = TextureWidth;
00633         myTextureHeight = TextureHeight;
00634     }
00635
00636     // Create the OpenGL texture
00637     if (!myTexture)
00638     {
00639         GLint PreviousTexture;
00640         GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture));
00641
00642         GLuint Texture = 0;
00643         GLCheck(glGenTextures(1, &Texture));
00644         GLCheck(glBindTexture(GL_TEXTURE_2D, Texture));
00645         GLCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, myTextureWidth, myTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
00646         GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP));
00647         GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP));
00648         GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST));
00649         GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST));
00650         myTexture = static_cast<unsigned int>(Texture);
00651
00652         GLCheck(glBindTexture(GL_TEXTURE_2D, PreviousTexture));
00653     }
00654
00655     myNeedTextureUpdate = true;
00656
00657     return true;
00658 }
00659
00660
00665 void Image::EnsureTextureUpdate() const
00666 {
00667     if (myNeedTextureUpdate)
00668     {
00669         // Copy the pixels
00670         if (myTexture && !myPixels.empty())
00671         {
00672             GLint PreviousTexture;
00673             GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture));
00674
00675             // Update the texture with the pixels array in RAM
00676             GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
00677             GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, myWidth, myHeight, GL_RGBA, GL_UNSIGNED_BYTE, &myPixels[0]));
00678
00679             GLCheck(glBindTexture(GL_TEXTURE_2D, PreviousTexture));
00680         }
00681
00682         myNeedTextureUpdate = false;
00683     }
00684 }
00685
00686
00691 void Image::EnsureArrayUpdate() const
00692 {
00693     if (myNeedArrayUpdate)
00694     {
00695         // Save the previous texture
00696         GLint PreviousTexture;
00697         GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture));
00698
00699         // Resize the destination array of pixels
00700         myPixels.resize(myWidth * myHeight);
00701
00702         if ((myWidth == myTextureWidth) && (myHeight == myTextureHeight))
00703         {
00704             // Texture and array have the same size, we can use a direct copy
00705
00706             // Copy pixels from texture to array
00707             GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
00708             GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &myPixels[0]));
00709         }
00710         else
00711         {
00712             // Texture and array don't have the same size, we have to use a slower algorithm
00713
00714             // All the pixels will first be copied to a temporary array
00715             std::vector<Color> AllPixels(myTextureWidth * myTextureHeight);
00716             GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
00717             GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &AllPixels[0]));
00718
00719             // The we copy the useful pixels from the temporary array to the final one
00720             const Color* Src = &AllPixels[0];
00721             Color* Dst = &myPixels[0];
00722             for (unsigned int i = 0; i < myHeight; ++i)
00723             {
00724                 std::copy(Src, Src + myWidth, Dst);
00725                 Src += myTextureWidth;
00726                 Dst += myWidth;
00727             }
00728         }
00729
00730         // Restore the previous texture
00731         GLCheck(glBindTexture(GL_TEXTURE_2D, PreviousTexture));
00732
00733         myNeedArrayUpdate = false;
00734     }
00735 }
00736
00737
00741 void Image::Reset()
00742 {
00743     DestroyTexture();
00744
00745     myWidth             = 0;
00746     myHeight            = 0;
00747     myTextureWidth      = 0;
00748     myTextureHeight     = 0;
00749     myTexture           = 0;
00750     myIsSmooth          = true;
00751     myNeedTextureUpdate = false;
00752     myNeedArrayUpdate   = false;
00753     myPixels.clear();
00754 }
00755
00756
00760 void Image::DestroyTexture()
00761 {
00762     // Destroy the internal texture
00763     if (myTexture)
00764     {
00765         // Make sure we have a valid context
00766         priv::GraphicsContext Ctx;
00767
00768         GLuint Texture = static_cast<GLuint>(myTexture);
00769         GLCheck(glDeleteTextures(1, &Texture));
00770         myTexture           = 0;
00771         myNeedTextureUpdate = false;
00772         myNeedArrayUpdate   = false;
00773     }
00774 }
00775
00776 } // namespace sf


  • File List

Image.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_IMAGE_HPP
00026 #define SFML_IMAGE_HPP
00027
00029 // Headers
00031 #include <SFML/System/Resource.hpp>
00032 #include <SFML/Graphics/Color.hpp>
00033 #include <SFML/Graphics/Rect.hpp>
00034 #include <string>
00035 #include <vector>
00036
00037
00038 namespace sf
00039 {
00040 class RenderWindow;
00041
00046 class SFML_API Image : public Resource<Image>
00047 {
00048 public :
00049
00054     Image();
00055
00062     Image(const Image& Copy);
00063
00072     Image(unsigned int Width, unsigned int Height, const Color& Col = Color(0, 0, 0, 255));
00073
00082     Image(unsigned int Width, unsigned int Height, const Uint8* Data);
00083
00088     ~Image();
00089
00098     bool LoadFromFile(const std::string& Filename);
00099
00109     bool LoadFromMemory(const char* Data, std::size_t SizeInBytes);
00110
00121     bool LoadFromPixels(unsigned int Width, unsigned int Height, const Uint8* Data);
00122
00131     bool SaveToFile(const std::string& Filename) const;
00132
00143     bool Create(unsigned int Width, unsigned int Height, Color Col = Color(0, 0, 0, 255));
00144
00152     void CreateMaskFromColor(Color ColorKey, Uint8 Alpha = 0);
00153
00166     void Copy(const Image& Source, unsigned int DestX, unsigned int DestY, const IntRect& SourceRect = IntRect(0, 0, 0, 0), bool ApplyAlpha = false);
00167
00178     bool CopyScreen(RenderWindow& Window, const IntRect& SourceRect = IntRect(0, 0, 0, 0));
00179
00188     void SetPixel(unsigned int X, unsigned int Y, const Color& Col);
00189
00199     const Color& GetPixel(unsigned int X, unsigned int Y) const;
00200
00209     const Uint8* GetPixelsPtr() const;
00210
00215     void Bind() const;
00216
00224     void SetSmooth(bool Smooth);
00225
00232     unsigned int GetWidth() const;
00233
00240     unsigned int GetHeight() const;
00241
00248     bool IsSmooth() const;
00249
00259     FloatRect GetTexCoords(const IntRect& Rect) const;
00260
00269     static unsigned int GetValidTextureSize(unsigned int Size);
00270
00279     Image& operator =(const Image& Other);
00280
00281 private :
00282
00289     bool CreateTexture();
00290
00295     void EnsureTextureUpdate() const;
00296
00301     void EnsureArrayUpdate() const;
00302
00307     void Reset();
00308
00313     void DestroyTexture();
00314
00316     // Member data
00318     unsigned int               myWidth;
00319     unsigned int               myHeight;
00320     unsigned int               myTextureWidth;
00321     unsigned int               myTextureHeight;
00322     unsigned int               myTexture;
00323     bool                       myIsSmooth;
00324     mutable std::vector<Color> myPixels;
00325     mutable bool               myNeedTextureUpdate;
00326     mutable bool               myNeedArrayUpdate;
00327 };
00328
00329 } // namespace sf
00330
00331
00332 #endif // SFML_IMAGE_HPP


  • File List

ImageLoader.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Graphics/ImageLoader.hpp>
00029 extern "C"
00030 {
00031     #include <SFML/Graphics/libjpeg/jpeglib.h>
00032     #include <SFML/Graphics/libjpeg/jerror.h>
00033 }
00034 #include <SFML/Graphics/libpng/png.h>
00035 #include <SFML/Graphics/SOIL/SOIL.h>
00036 #include <iostream>
00037
00038
00039 namespace
00040 {
00044     void PngErrorHandler(png_structp Png, png_const_charp Message)
00045     {
00046         std::cerr << "Failed to write PNG image. Reason : " << Message << std::endl;
00047         longjmp(Png->jmpbuf, 1);
00048     }
00049 }
00050
00051
00052 namespace sf
00053 {
00054 namespace priv
00055 {
00059 ImageLoader& ImageLoader::GetInstance()
00060 {
00061     static ImageLoader Instance;
00062
00063     return Instance;
00064 }
00065
00066
00070 ImageLoader::ImageLoader()
00071 {
00072     // Nothing to do
00073 }
00074
00075
00079 ImageLoader::~ImageLoader()
00080 {
00081     // Nothing to do
00082 }
00083
00084
00088 bool ImageLoader::LoadImageFromFile(const std::string& Filename, std::vector<Color>& Pixels, unsigned int& Width, unsigned int& Height)
00089 {
00090     // Clear the array (just in case)
00091     Pixels.clear();
00092
00093     // Load the image and get a pointer to the pixels in memory
00094     int ImgWidth, ImgHeight, ImgChannels;
00095     unsigned char* PixelsPtr = SOIL_load_image(Filename.c_str(), &ImgWidth, &ImgHeight, &ImgChannels, SOIL_LOAD_RGBA);
00096
00097     if (PixelsPtr)
00098     {
00099         // Assign the image properties
00100         Width  = ImgWidth;
00101         Height = ImgHeight;
00102
00103         // Copy the loaded pixels to the pixel buffer
00104         Pixels.resize(Width * Height);
00105         memcpy(&Pixels[0], PixelsPtr, Width * Height * 4);
00106
00107         // Free the loaded pixels (they are now in our own pixel buffer)
00108         SOIL_free_image_data(PixelsPtr);
00109
00110         return true;
00111     }
00112     else
00113     {
00114         // Error, failed to load the image
00115         std::cerr << "Failed to load image \"" << Filename << "\". Reason : " << SOIL_last_result() << std::endl;
00116
00117         return false;
00118     }
00119 }
00120
00121
00125 bool ImageLoader::LoadImageFromMemory(const char* Data, std::size_t SizeInBytes, std::vector<Color>& Pixels, unsigned int& Width, unsigned int& Height)
00126 {
00127     // Clear the array (just in case)
00128     Pixels.clear();
00129
00130     // Load the image and get a pointer to the pixels in memory
00131     const unsigned char* Buffer = reinterpret_cast<const unsigned char*>(Data);
00132     int Size = static_cast<int>(SizeInBytes);
00133     int ImgWidth, ImgHeight, ImgChannels;
00134     unsigned char* PixelsPtr = SOIL_load_image_from_memory(Buffer, Size, &ImgWidth, &ImgHeight, &ImgChannels, SOIL_LOAD_RGBA);
00135
00136     if (PixelsPtr)
00137     {
00138         // Assign the image properties
00139         Width  = ImgWidth;
00140         Height = ImgHeight;
00141
00142         // Copy the loaded pixels to the pixel buffer
00143         Pixels.resize(Width * Height);
00144         memcpy(&Pixels[0], PixelsPtr, Width * Height * 4);
00145
00146         // Free the loaded pixels (they are now in our own pixel buffer)
00147         SOIL_free_image_data(PixelsPtr);
00148
00149         return true;
00150     }
00151     else
00152     {
00153         // Error, failed to load the image
00154         std::cerr << "Failed to load image from memory. Reason : " << SOIL_last_result() << std::endl;
00155
00156         return false;
00157     }
00158 }
00159
00160
00164 bool ImageLoader::SaveImageToFile(const std::string& Filename, const std::vector<Color>& Pixels, unsigned int Width, unsigned int Height)
00165 {
00166     // Deduce the image type from its extension
00167     int Type = -1;
00168     if (Filename.size() > 3)
00169     {
00170         std::string Extension = Filename.substr(Filename.size() - 3);
00171         if      (Extension == "bmp" || Extension == "BMP") Type = SOIL_SAVE_TYPE_BMP;
00172         else if (Extension == "tga" || Extension == "TGA") Type = SOIL_SAVE_TYPE_TGA;
00173         else if (Extension == "dds" || Extension == "DDS") Type = SOIL_SAVE_TYPE_DDS;
00174
00175         // Special handling for PNG and JPG -- not handled by SOIL
00176         else if (Extension == "png" || Extension == "PNG") return WritePng(Filename, Pixels, Width, Height);
00177         else if (Extension == "jpg" || Extension == "JPG") return WriteJpg(Filename, Pixels, Width, Height);
00178     }
00179
00180     if (Type == -1)
00181     {
00182         // Error, incompatible type
00183         std::cerr << "Failed to save image \"" << Filename << "\". Reason : this image format is not supported" << std::endl;
00184         return false;
00185     }
00186
00187     // Finally save the image
00188     const unsigned char* PixelsPtr = reinterpret_cast<const unsigned char*>(&Pixels[0]);
00189     if (!SOIL_save_image(Filename.c_str(), Type, static_cast<int>(Width), static_cast<int>(Height), 4, PixelsPtr))
00190     {
00191         // Error, failed to save the image
00192         std::cerr << "Failed to save image \"" << Filename << "\". Reason : " << SOIL_last_result() << std::endl;
00193         return false;
00194     }
00195
00196     return true;
00197 }
00198
00199
00203 bool ImageLoader::WriteJpg(const std::string& Filename, const std::vector<Color>& Pixels, unsigned int Width, unsigned int Height)
00204 {
00205     // Open the file to write in
00206     FILE* File = fopen(Filename.c_str(), "wb");
00207     if (!File)
00208     {
00209         std::cerr << "Failed to save image file \"" << Filename << "\". Reason : cannot open file" << std::endl;
00210         return false;
00211     }
00212
00213     // Initialize the error handler
00214     jpeg_compress_struct CompressInfo;
00215     jpeg_error_mgr ErrorManager;
00216     CompressInfo.err = jpeg_std_error(&ErrorManager);
00217
00218     // Initialize all the writing and compression infos
00219     jpeg_create_compress(&CompressInfo);
00220     CompressInfo.image_width      = Width;
00221     CompressInfo.image_height     = Height;
00222     CompressInfo.input_components = 3;
00223     CompressInfo.in_color_space   = JCS_RGB;
00224     jpeg_stdio_dest(&CompressInfo, File);
00225     jpeg_set_defaults(&CompressInfo);
00226     jpeg_set_quality(&CompressInfo, 90, TRUE);
00227
00228     // Get rid of the aplha channel
00229     std::vector<Uint8> PixelsBuffer(Width * Height * 3);
00230     for (std::size_t i = 0; i < Pixels.size(); ++i)
00231     {
00232         PixelsBuffer[i * 3 + 0] = Pixels[i].r;
00233         PixelsBuffer[i * 3 + 1] = Pixels[i].g;
00234         PixelsBuffer[i * 3 + 2] = Pixels[i].b;
00235     }
00236     Uint8* PixelsPtr = &PixelsBuffer[0];
00237
00238     // Start compression
00239     jpeg_start_compress(&CompressInfo, TRUE);
00240
00241     // Write each row of the image
00242     while (CompressInfo.next_scanline < CompressInfo.image_height)
00243     {
00244         JSAMPROW RowPointer = PixelsPtr + (CompressInfo.next_scanline * Width * 3);
00245         jpeg_write_scanlines(&CompressInfo, &RowPointer, 1);
00246     }
00247
00248     // Finish compression
00249     jpeg_finish_compress(&CompressInfo);
00250     jpeg_destroy_compress(&CompressInfo);
00251
00252     // Close the file
00253     fclose(File);
00254
00255     return true;
00256 }
00257
00258
00262 bool ImageLoader::WritePng(const std::string& Filename, const std::vector<Color>& Pixels, unsigned int Width, unsigned int Height)
00263 {
00264     // Open the file to write in
00265     FILE* File = fopen(Filename.c_str(), "wb");
00266     if (!File)
00267     {
00268         std::cerr << "Failed to save image file \"" << Filename << "\". Reason : cannot open file" << std::endl;
00269         return false;
00270     }
00271
00272     // Create the main PNG structure
00273     png_structp Png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, &PngErrorHandler, NULL);
00274     if (!Png)
00275     {
00276         fclose(File);
00277         std::cerr << "Failed to save image file \"" << Filename << "\". Reason : cannot allocate PNG write structure" << std::endl;
00278         return false;
00279     }
00280
00281     // Initialize the image informations
00282     png_infop PngInfo = png_create_info_struct(Png);
00283     if (!PngInfo)
00284     {
00285         fclose(File);
00286         png_destroy_write_struct(&Png, NULL);
00287         std::cerr << "Failed to save image file \"" << Filename << "\". Reason : cannot allocate PNG info structure" << std::endl;
00288         return false;
00289     }
00290
00291     // For proper error handling...
00292     if (setjmp(Png->jmpbuf))
00293     {
00294         png_destroy_write_struct(&Png, &PngInfo);
00295         return false;
00296     }
00297
00298     // Link the file to the PNG structure
00299     png_init_io(Png, File);
00300
00301     // Set the image informations
00302     png_set_IHDR(Png, PngInfo, Width, Height, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
00303
00304     // Write the header
00305     png_write_info(Png, PngInfo);
00306
00307     // Get the pointers to the pixels rows into an array
00308     png_byte* PixelsPtr = (png_byte*)&Pixels[0];
00309     std::vector<png_byte*> RowPointers(Height);
00310     for (unsigned int i = 0; i < Height; ++i)
00311     {
00312         RowPointers[i] = PixelsPtr;
00313         PixelsPtr += Width * 4;
00314     }
00315
00316     // Write pixels row by row
00317     png_set_rows(Png, PngInfo, &RowPointers[0]);
00318     png_write_png(Png, PngInfo, PNG_TRANSFORM_IDENTITY, NULL);
00319
00320     // Finish writing the file
00321     png_write_end(Png, PngInfo);
00322
00323     // Cleanup resources
00324     png_destroy_write_struct(&Png, &PngInfo);
00325     fclose(File);
00326
00327     return true;
00328 }
00329
00330 } // namespace priv
00331
00332 } // namespace sf


  • File List

ImageLoader.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_IMAGELOADER_HPP
00026 #define SFML_IMAGELOADER_HPP
00027
00029 // Headers
00031 #include <SFML/Graphics/Color.hpp>
00032 #include <SFML/System/NonCopyable.hpp>
00033 #include <string>
00034 #include <vector>
00035
00036
00037 namespace sf
00038 {
00039 namespace priv
00040 {
00045 class ImageLoader : NonCopyable
00046 {
00047 public :
00048
00055     static ImageLoader& GetInstance();
00056
00068     bool LoadImageFromFile(const std::string& Filename, std::vector<Color>& Pixels, unsigned int& Width, unsigned int& Height);
00069
00082     bool LoadImageFromMemory(const char* Data, std::size_t SizeInBytes, std::vector<Color>& Pixels, unsigned int& Width, unsigned int& Height);
00083
00095     bool SaveImageToFile(const std::string& Filename, const std::vector<Color>& Pixels, unsigned int Width, unsigned int Height);
00096
00097 private :
00098
00103     ImageLoader();
00104
00109     ~ImageLoader();
00110
00122     bool WriteJpg(const std::string& Filename, const std::vector<Color>& Pixels, unsigned int Width, unsigned int Height);
00123
00135     bool WritePng(const std::string& Filename, const std::vector<Color>& Pixels, unsigned int Width, unsigned int Height);
00136 };
00137
00138 } // namespace priv
00139
00140 } // namespace sf
00141
00142
00143 #endif // SFML_IMAGELOADER_HPP


  • File List

Input.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Window/Input.hpp>
00029
00030
00031 namespace sf
00032 {
00036 Input::Input() :
00037 myMouseX(0),
00038 myMouseY(0)
00039 {
00040     ResetStates();
00041 }
00042
00043
00047 bool Input::IsKeyDown(Key::Code KeyCode) const
00048 {
00049     return myKeys[KeyCode];
00050 }
00051
00052
00056 bool Input::IsMouseButtonDown(Mouse::Button Button) const
00057 {
00058     return myMouseButtons[Button];
00059 }
00060
00061
00065 bool Input::IsJoystickButtonDown(unsigned int JoyId, unsigned int Button) const
00066 {
00067     if ((JoyId < Joy::Count) && (Button < Joy::ButtonCount))
00068         return myJoystickButtons[JoyId][Button];
00069     else
00070         return false;
00071 }
00072
00073
00077 int Input::GetMouseX() const
00078 {
00079     return myMouseX;
00080 }
00081
00082
00086 int Input::GetMouseY() const
00087 {
00088     return myMouseY;
00089 }
00090
00091
00095 float Input::GetJoystickAxis(unsigned int JoyId, Joy::Axis Axis) const
00096 {
00097     if (JoyId < Joy::Count)
00098         return myJoystickAxis[JoyId][Axis];
00099     else
00100         return 0.f;
00101 }
00102
00103
00107 void Input::OnEvent(const Event& EventReceived)
00108 {
00109     switch (EventReceived.Type)
00110     {
00111         // Key events
00112         case Event::KeyPressed :  myKeys[EventReceived.Key.Code] = true;  break;
00113         case Event::KeyReleased : myKeys[EventReceived.Key.Code] = false; break;
00114
00115         // Mouse event
00116         case Event::MouseButtonPressed :  myMouseButtons[EventReceived.MouseButton.Button] = true;  break;
00117         case Event::MouseButtonReleased : myMouseButtons[EventReceived.MouseButton.Button] = false; break;
00118
00119         // Mouse move event
00120         case Event::MouseMoved :
00121             myMouseX = EventReceived.MouseMove.X;
00122             myMouseY = EventReceived.MouseMove.Y;
00123             break;
00124
00125         // Joystick button events
00126         case Event::JoyButtonPressed :  myJoystickButtons[EventReceived.JoyButton.JoystickId][EventReceived.JoyButton.Button] = true;  break;
00127         case Event::JoyButtonReleased : myJoystickButtons[EventReceived.JoyButton.JoystickId][EventReceived.JoyButton.Button] = false; break;
00128
00129         // Joystick move event
00130         case Event::JoyMoved :
00131             myJoystickAxis[EventReceived.JoyMove.JoystickId][EventReceived.JoyMove.Axis] = EventReceived.JoyMove.Position;
00132             break;
00133
00134         // Lost focus event : we must reset all persistent states
00135         case Event::LostFocus :
00136         {
00137             ResetStates();
00138             break;
00139         }
00140
00141         default :
00142             break;
00143     }
00144 }
00145
00146
00150 void Input::ResetStates()
00151 {
00152     for (int i = 0; i < Key::Count; ++i)
00153         myKeys[i] = false;
00154
00155     for (int i = 0; i < Mouse::ButtonCount; ++i)
00156         myMouseButtons[i] = false;
00157
00158     for (int i = 0; i < Joy::Count; ++i)
00159     {
00160         for (int j = 0; j < Joy::ButtonCount; ++j)
00161             myJoystickButtons[i][j] = false;
00162
00163         for (int j = 0; j < Joy::AxisCount; ++j)
00164             myJoystickAxis[i][j] = 0.f;
00165         myJoystickAxis[i][Joy::AxisPOV] = -1.f;
00166     }
00167 }
00168
00169 } // namespace sf


  • File List

Input.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_INPUT_HPP
00026 #define SFML_INPUT_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <SFML/System/NonCopyable.hpp>
00033 #include <SFML/Window/Event.hpp>
00034 #include <SFML/Window/WindowListener.hpp>
00035
00036
00037 namespace sf
00038 {
00044 class SFML_API Input : public WindowListener, NonCopyable
00045 {
00046 public :
00047
00052     Input();
00053
00062     bool IsKeyDown(Key::Code KeyCode) const;
00063
00072     bool IsMouseButtonDown(Mouse::Button Button) const;
00073
00083     bool IsJoystickButtonDown(unsigned int JoyId, unsigned int Button) const;
00084
00091     int GetMouseX() const;
00092
00099     int GetMouseY() const;
00100
00110     float GetJoystickAxis(unsigned int JoyId, Joy::Axis Axis) const;
00111
00112 private :
00113
00118     virtual void OnEvent(const Event& EventReceived);
00119
00124     void ResetStates();
00125
00127     // Member data
00129     bool  myKeys[Key::Count];
00130     bool  myMouseButtons[Mouse::ButtonCount];
00131     int   myMouseX;
00132     int   myMouseY;
00133     bool  myJoystickButtons[Joy::Count][Joy::ButtonCount];
00134     float myJoystickAxis[Joy::Count][Joy::AxisCount];
00135 };
00136
00137 } // namespace sf
00138
00139
00140 #endif // SFML_INPUT_HPP


  • File List

IPAddress.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Network/IPAddress.hpp>
00029 #include <SFML/Network/Http.hpp>
00030 #include <SFML/Network/SocketHelper.hpp>
00031 #include <string.h>
00032
00033
00034 namespace sf
00035 {
00039 const IPAddress IPAddress::LocalHost("127.0.0.1");
00040
00041
00045 IPAddress::IPAddress() :
00046 myAddress(INADDR_NONE)
00047 {
00048
00049 }
00050
00051
00055 IPAddress::IPAddress(const std::string& Address)
00056 {
00057     // First try to convert it as a byte representation ("xxx.xxx.xxx.xxx")
00058     myAddress = inet_addr(Address.c_str());
00059
00060     // If not successful, try to convert it as a host name
00061     if (!IsValid())
00062     {
00063         hostent* Host = gethostbyname(Address.c_str());
00064         if (Host)
00065         {
00066             // Host found, extract its IP address
00067             myAddress = reinterpret_cast<in_addr*>(Host->h_addr)->s_addr;
00068         }
00069         else
00070         {
00071             // Host name not found on the network
00072             myAddress = INADDR_NONE;
00073         }
00074     }
00075 }
00076
00077
00082 IPAddress::IPAddress(const char* Address)
00083 {
00084     // First try to convert it as a byte representation ("xxx.xxx.xxx.xxx")
00085     myAddress = inet_addr(Address);
00086
00087     // If not successful, try to convert it as a host name
00088     if (!IsValid())
00089     {
00090         hostent* Host = gethostbyname(Address);
00091         if (Host)
00092         {
00093             // Host found, extract its IP address
00094             myAddress = reinterpret_cast<in_addr*>(Host->h_addr)->s_addr;
00095         }
00096         else
00097         {
00098             // Host name not found on the network
00099             myAddress = INADDR_NONE;
00100         }
00101     }
00102 }
00103
00104
00108 IPAddress::IPAddress(Uint8 Byte0, Uint8 Byte1, Uint8 Byte2, Uint8 Byte3)
00109 {
00110     myAddress = htonl((Byte0 << 24) | (Byte1 << 16) | (Byte2 << 8) | Byte3);
00111 }
00112
00113
00117 IPAddress::IPAddress(Uint32 Address)
00118 {
00119     myAddress = htonl(Address);
00120 }
00121
00122
00126 bool IPAddress::IsValid() const
00127 {
00128     return myAddress != INADDR_NONE;
00129 }
00130
00131
00135 std::string IPAddress::ToString() const
00136 {
00137     in_addr InAddr;
00138     InAddr.s_addr = myAddress;
00139
00140     return inet_ntoa(InAddr);
00141 }
00142
00143
00147 Uint32 IPAddress::ToInteger() const
00148 {
00149     return ntohl(myAddress);
00150 }
00151
00152
00156 IPAddress IPAddress::GetLocalAddress()
00157 {
00158     // The method here is to connect a UDP socket to anyone (here to localhost),
00159     // and get the local socket address with the getsockname function.
00160     // UDP connection will not send anything to the network, so this function won't cause any overhead.
00161
00162     IPAddress LocalAddress;
00163
00164     // Create the socket
00165     SocketHelper::SocketType Socket = socket(PF_INET, SOCK_DGRAM, 0);
00166     if (Socket == SocketHelper::InvalidSocket())
00167         return LocalAddress;
00168
00169     // Build the host address (use a random port)
00170     sockaddr_in SockAddr;
00171     memset(SockAddr.sin_zero, 0, sizeof(SockAddr.sin_zero));
00172     SockAddr.sin_addr.s_addr = INADDR_LOOPBACK;
00173     SockAddr.sin_family      = AF_INET;
00174     SockAddr.sin_port        = htons(4567);
00175
00176     // Connect the socket
00177     if (connect(Socket, reinterpret_cast<sockaddr*>(&SockAddr), sizeof(SockAddr)) == -1)
00178     {
00179         SocketHelper::Close(Socket);
00180         return LocalAddress;
00181     }
00182
00183     // Get the local address of the socket connection
00184     SocketHelper::LengthType Size = sizeof(SockAddr);
00185     if (getsockname(Socket, reinterpret_cast<sockaddr*>(&SockAddr), &Size) == -1)
00186     {
00187         SocketHelper::Close(Socket);
00188         return LocalAddress;
00189     }
00190
00191     // Close the socket
00192     SocketHelper::Close(Socket);
00193
00194     // Finally build the IP address
00195     LocalAddress.myAddress = SockAddr.sin_addr.s_addr;
00196
00197     return LocalAddress;
00198 }
00199
00200
00204 IPAddress IPAddress::GetPublicAddress(float Timeout)
00205 {
00206     // The trick here is more complicated, because the only way
00207     // to get our public IP address is to get it from a distant computer.
00208     // Here we get the web page from http://www.sfml-dev.org/ip-provider.php
00209     // and parse the result to extract our IP address
00210     // (not very hard : the web page contains only our IP address).
00211
00212     Http Server("www.sfml-dev.org");
00213     Http::Request Request(Http::Request::Get, "/ip-provider.php");
00214     Http::Response Page = Server.SendRequest(Request, Timeout);
00215     if (Page.GetStatus() == Http::Response::Ok)
00216         return IPAddress(Page.GetBody());
00217
00218     // Something failed: return an invalid address
00219     return IPAddress();
00220 }
00221
00222
00226 bool IPAddress::operator ==(const IPAddress& Other) const
00227 {
00228     return myAddress == Other.myAddress;
00229 }
00230
00231
00235 bool IPAddress::operator !=(const IPAddress& Other) const
00236 {
00237     return myAddress != Other.myAddress;
00238 }
00239
00240
00244 bool IPAddress::operator <(const IPAddress& Other) const
00245 {
00246     return myAddress < Other.myAddress;
00247 }
00248
00249
00253 bool IPAddress::operator >(const IPAddress& Other) const
00254 {
00255     return myAddress > Other.myAddress;
00256 }
00257
00258
00262 bool IPAddress::operator <=(const IPAddress& Other) const
00263 {
00264     return myAddress <= Other.myAddress;
00265 }
00266
00267
00271 bool IPAddress::operator >=(const IPAddress& Other) const
00272 {
00273     return myAddress >= Other.myAddress;
00274 }
00275
00276
00280 std::istream& operator >>(std::istream& Stream, IPAddress& Address)
00281 {
00282     std::string Str;
00283     Stream >> Str;
00284     Address = IPAddress(Str);
00285
00286     return Stream;
00287 }
00288
00289
00293 std::ostream& operator <<(std::ostream& Stream, const IPAddress& Address)
00294 {
00295     return Stream << Address.ToString();
00296 }
00297
00298 } // namespace sf


  • File List

IPAddress.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_IPADDRESS_HPP
00026 #define SFML_IPADDRESS_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <istream>
00033 #include <ostream>
00034 #include <string>
00035
00036
00037 namespace sf
00038 {
00042 class SFML_API IPAddress
00043 {
00044 public :
00045
00050     IPAddress();
00051
00058     IPAddress(const std::string& Address);
00059
00067     IPAddress(const char* Address);
00068
00078     IPAddress(Uint8 Byte0, Uint8 Byte1, Uint8 Byte2, Uint8 Byte3);
00079
00086     IPAddress(Uint32 Address);
00087
00094     bool IsValid() const;
00095
00102     std::string ToString() const;
00103
00110     Uint32 ToInteger() const;
00111
00118     static IPAddress GetLocalAddress();
00119
00131     static IPAddress GetPublicAddress(float Timeout = 0.f);
00132
00141     bool operator ==(const IPAddress& Other) const;
00142
00151     bool operator !=(const IPAddress& Other) const;
00152
00161     bool operator <(const IPAddress& Other) const;
00162
00171     bool operator >(const IPAddress& Other) const;
00172
00181     bool operator <=(const IPAddress& Other) const;
00182
00191     bool operator >=(const IPAddress& Other) const;
00192
00194     // Static member data
00196     static const IPAddress LocalHost;
00197
00198 private :
00199
00201     // Member data
00203     Uint32 myAddress;
00204 };
00205
00215 SFML_API std::istream& operator >>(std::istream& Stream, IPAddress& Address);
00216
00226 SFML_API std::ostream& operator <<(std::ostream& Stream, const IPAddress& Address);
00227
00228 } // namespace sf
00229
00230
00231 #endif // SFML_IPADDRESS_HPP


  • File List

Joystick.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_JOYSTICK_HPP
00026 #define SFML_JOYSTICK_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <SFML/Window/Event.hpp>
00033
00034
00035 namespace sf
00036 {
00037 namespace priv
00038 {
00042 struct JoystickState
00043 {
00044     JoystickState()
00045     {
00046         // Default value for axes
00047         for (int i = 0; i < Joy::AxisCount; ++i)
00048             Axis[i] = 0.f;
00049         Axis[Joy::AxisPOV] = -1.f;
00050
00051         // Default value for buttons
00052         for (int i = 0; i < Joy::ButtonCount; ++i)
00053             Buttons[i] = false;
00054     }
00055
00056     float Axis[Joy::AxisCount];
00057     bool  Buttons[Joy::ButtonCount];
00058 };
00059
00060 } // namespace priv
00061
00062 } // namespace sf
00063
00064
00065 #if defined(SFML_SYSTEM_WINDOWS)
00066
00067     #include <SFML/Window/Win32/Joystick.hpp>
00068
00069 #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
00070
00071     #include <SFML/Window/Linux/Joystick.hpp>
00072
00073 #elif defined(SFML_SYSTEM_MACOS)
00074
00075     #include <SFML/Window/Cocoa/Joystick.hpp>
00076
00077 #endif
00078
00079
00080 #endif // SFML_JOYSTICK_HPP


  • File List

Listener.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Audio/Listener.hpp>
00029 #include <SFML/Audio/OpenAL.hpp>
00030
00031
00032 namespace sf
00033 {
00037 void Listener::SetGlobalVolume(float Volume)
00038 {
00039     ALCheck(alListenerf(AL_GAIN, Volume * 0.01f));
00040 }
00041
00042
00046 float Listener::GetGlobalVolume()
00047 {
00048     float Volume = 0.f;
00049     ALCheck(alGetListenerf(AL_GAIN, &Volume));
00050
00051     return Volume;
00052 }
00053
00054
00058 void Listener::SetPosition(float X, float Y, float Z)
00059 {
00060     ALCheck(alListener3f(AL_POSITION, X, Y, Z));
00061 }
00062
00063
00067 void Listener::SetPosition(const Vector3f& Position)
00068 {
00069     SetPosition(Position.x, Position.y, Position.z);
00070 }
00071
00072
00076 Vector3f Listener::GetPosition()
00077 {
00078     Vector3f Position;
00079     ALCheck(alGetListener3f(AL_POSITION, &Position.x, &Position.y, &Position.z));
00080
00081     return Position;
00082 }
00083
00084
00089 void Listener::SetTarget(float X, float Y, float Z)
00090 {
00091     float Orientation[] = {X, Y, Z, 0.f, 1.f, 0.f};
00092     ALCheck(alListenerfv(AL_ORIENTATION, Orientation));
00093 }
00094
00095
00100 void Listener::SetTarget(const Vector3f& Target)
00101 {
00102     SetTarget(Target.x, Target.y, Target.z);
00103 }
00104
00105
00110 Vector3f Listener::GetTarget()
00111 {
00112     float Orientation[6];
00113     ALCheck(alGetListenerfv(AL_ORIENTATION, Orientation));
00114
00115     return Vector3f(Orientation[0], Orientation[1], Orientation[2]);
00116 }
00117
00118 } // namespace sf


  • File List

Listener.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_LISTENER_HPP
00026 #define SFML_LISTENER_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <SFML/System/Vector3.hpp>
00033
00034
00035 namespace sf
00036 {
00042 class SFML_API Listener
00043 {
00044 public :
00045
00053     static void SetGlobalVolume(float Volume);
00054
00061     static float GetGlobalVolume();
00062
00070     static void SetPosition(float X, float Y, float Z);
00071
00079     static void SetPosition(const Vector3f& Position);
00080
00087     static Vector3f GetPosition();
00088
00097     static void SetTarget(float X, float Y, float Z);
00098
00107     static void SetTarget(const Vector3f& Target);
00108
00116     static Vector3f GetTarget();
00117 };
00118
00119 } // namespace sf
00120
00121
00122 #endif // SFML_LISTENER_HPP


  • File List

Lock.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/System/Lock.hpp>
00029 #include <SFML/System/Mutex.hpp>
00030
00031
00032 namespace sf
00033 {
00037 Lock::Lock(Mutex& Mutex) :
00038 myMutex(Mutex)
00039 {
00040     myMutex.Lock();
00041 }
00042
00043
00047 Lock::~Lock()
00048 {
00049     myMutex.Unlock();
00050 }
00051
00052 } // namespace sf


  • File List

Lock.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_LOCK_HPP
00026 #define SFML_LOCK_HPP
00027
00029 // Headers
00031 #include <SFML/System/NonCopyable.hpp>
00032
00033
00034 namespace sf
00035 {
00036 class Mutex;
00037
00042 class SFML_API Lock : NonCopyable
00043 {
00044 public :
00045
00052     Lock(Mutex& Mutex);
00053
00058     ~Lock();
00059
00060 private :
00061
00063     // Member data
00065     Mutex& myMutex;
00066 };
00067
00068 } // namespace sf
00069
00070
00071 #endif // SFML_LOCK_HPP


  • File List

Matrix3.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Graphics/Matrix3.hpp>
00029
00030
00031 namespace sf
00032 {
00034 // Static member data
00036 const Matrix3 Matrix3::Identity(1, 0, 0,
00037                                 0, 1, 0,
00038                                 0, 0, 1);
00039
00040 } // namespace sf


  • File List

Matrix3.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_MATRIX3_HPP
00026 #define SFML_MATRIX3_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <SFML/System/Vector2.hpp>
00033 #include <math.h>
00034
00035
00036 namespace sf
00037 {
00042 class SFML_API Matrix3
00043 {
00044 public :
00045
00050     Matrix3();
00051
00056     Matrix3(float a00, float a01, float a02,
00057             float a10, float a11, float a12,
00058             float a20, float a21, float a22);
00059
00069     void SetFromTransformations(const Vector2f& Center, const Vector2f& Translation, float Rotation, const Vector2f& Scale);
00070
00079     Vector2f Transform(const Vector2f& Point) const;
00080
00087     Matrix3 GetInverse() const;
00088
00096     const float* Get4x4Elements() const;
00097
00107     float  operator ()(unsigned int Row, unsigned int Col) const;
00108     float& operator ()(unsigned int Row, unsigned int Col);
00109
00118     Matrix3 operator *(const Matrix3& Mat) const;
00119
00128     Matrix3& operator *=(const Matrix3& Mat);
00129
00131     // Static member data
00133     static const Matrix3 Identity;
00134
00135 private :
00136
00138     // Member data
00140     float myData[16];
00141 };
00142
00143 #include <SFML/Graphics/Matrix3.inl>
00144
00145 } // namespace sf
00146
00147
00148 #endif // SFML_MATRIX3_HPP


  • File List

Matrix3.inl

00001
00002 //
00003 // SFGE - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025
00029 inline Matrix3::Matrix3()
00030 {
00031     myData[0] = 1.f; myData[4] = 0.f; myData[8]  = 0.f; myData[12] = 0.f;
00032     myData[1] = 0.f; myData[5] = 1.f; myData[9]  = 0.f; myData[13] = 0.f;
00033     myData[2] = 0.f; myData[6] = 0.f; myData[10] = 1.f; myData[14] = 0.f;
00034     myData[3] = 0.f; myData[7] = 0.f; myData[11] = 0.f; myData[15] = 1.f;
00035 }
00036
00037
00041 inline Matrix3::Matrix3(float a00, float a01, float a02,
00042                         float a10, float a11, float a12,
00043                         float a20, float a21, float a22)
00044 {
00045     myData[0] = a00; myData[4] = a01; myData[8]  = 0.f; myData[12] = a02;
00046     myData[1] = a10; myData[5] = a11; myData[9]  = 0.f; myData[13] = a12;
00047     myData[2] = 0.f; myData[6] = 0.f; myData[10] = 1.f; myData[14] = 0.f;
00048     myData[3] = a20; myData[7] = a21; myData[11] = 0.f; myData[15] = a22;
00049 }
00050
00051
00055 inline void Matrix3::SetFromTransformations(const Vector2f& Center, const Vector2f& Translation, float Rotation, const Vector2f& Scale)
00056 {
00057     float Angle = Rotation * 3.141592654f / 180.f;
00058     float Cos   = static_cast<float>(cos(Angle));
00059     float Sin   = static_cast<float>(sin(Angle));
00060     float SxCos = Scale.x * Cos;
00061     float SyCos = Scale.y * Cos;
00062     float SxSin = Scale.x * Sin;
00063     float SySin = Scale.y * Sin;
00064     float Tx    = -Center.x * SxCos - Center.y * SySin + Translation.x;
00065     float Ty    =  Center.x * SxSin - Center.y * SyCos + Translation.y;
00066
00067     myData[0] =  SxCos; myData[4] = SySin; myData[8]  = 0.f; myData[12] = Tx;
00068     myData[1] = -SxSin; myData[5] = SyCos; myData[9]  = 0.f; myData[13] = Ty;
00069     myData[2] =  0.f;   myData[6] = 0.f;   myData[10] = 1.f; myData[14] = 0.f;
00070     myData[3] =  0.f;   myData[7] = 0.f;   myData[11] = 0.f; myData[15] = 1.f;
00071 }
00072
00073
00077 inline Vector2f Matrix3::Transform(const Vector2f& Point) const
00078 {
00079     return Vector2f(myData[0] * Point.x + myData[4] * Point.y + myData[12],
00080                     myData[1] * Point.x + myData[5] * Point.y + myData[13]);
00081 }
00082
00083
00087 inline Matrix3 Matrix3::GetInverse() const
00088 {
00089     // Compute the determinant
00090     float Det = myData[0] * (myData[15] * myData[5] - myData[7] * myData[13]) -
00091                 myData[1] * (myData[15] * myData[4] - myData[7] * myData[12]) +
00092                 myData[3] * (myData[13] * myData[4] - myData[5] * myData[12]);
00093
00094     // Compute the inverse if determinant is not zero
00095     if ((Det < -1E-7f) || (Det > 1E-7f))
00096     {
00097         return Matrix3( (myData[15] * myData[5] - myData[7] * myData[13]) / Det,
00098                        -(myData[15] * myData[4] - myData[7] * myData[12]) / Det,
00099                         (myData[13] * myData[4] - myData[5] * myData[12]) / Det,
00100                        -(myData[15] * myData[1] - myData[3] * myData[13]) / Det,
00101                         (myData[15] * myData[0] - myData[3] * myData[12]) / Det,
00102                        -(myData[13] * myData[0] - myData[1] * myData[12]) / Det,
00103                         (myData[7]  * myData[1] - myData[3] * myData[5])  / Det,
00104                        -(myData[7]  * myData[0] - myData[3] * myData[4])  / Det,
00105                         (myData[5]  * myData[0] - myData[1] * myData[4])  / Det);
00106     }
00107     else
00108     {
00109         return Identity;
00110     }
00111 }
00112
00113
00118 inline const float* Matrix3::Get4x4Elements() const
00119 {
00120     return myData;
00121 }
00122
00123
00127 inline float Matrix3::operator ()(unsigned int Row, unsigned int Col) const
00128 {
00129     switch (Row + Col * 3)
00130     {
00131         case 0 : return myData[0];
00132         case 1 : return myData[1];
00133         case 2 : return myData[3];
00134         case 3 : return myData[4];
00135         case 4 : return myData[5];
00136         case 5 : return myData[7];
00137         case 6 : return myData[12];
00138         case 7 : return myData[13];
00139         case 8 : return myData[15];
00140
00141         default : return myData[0];
00142     }
00143 }
00144 inline float& Matrix3::operator ()(unsigned int Row, unsigned int Col)
00145 {
00146     switch (Row + Col * 3)
00147     {
00148         case 0 : return myData[0];
00149         case 1 : return myData[1];
00150         case 2 : return myData[3];
00151         case 3 : return myData[4];
00152         case 4 : return myData[5];
00153         case 5 : return myData[7];
00154         case 6 : return myData[12];
00155         case 7 : return myData[13];
00156         case 8 : return myData[15];
00157
00158         default : return myData[0];
00159     }
00160 }
00161
00162
00166 inline Matrix3 Matrix3::operator *(const Matrix3& Mat) const
00167 {
00168     return Matrix3(myData[0] * Mat.myData[0]  + myData[4] * Mat.myData[1]  + myData[12] * Mat.myData[3],
00169                    myData[0] * Mat.myData[4]  + myData[4] * Mat.myData[5]  + myData[12] * Mat.myData[7],
00170                    myData[0] * Mat.myData[12] + myData[4] * Mat.myData[13] + myData[12] * Mat.myData[15],
00171                    myData[1] * Mat.myData[0]  + myData[5] * Mat.myData[1]  + myData[13] * Mat.myData[3],
00172                    myData[1] * Mat.myData[4]  + myData[5] * Mat.myData[5]  + myData[13] * Mat.myData[7],
00173                    myData[1] * Mat.myData[12] + myData[5] * Mat.myData[13] + myData[13] * Mat.myData[15],
00174                    myData[3] * Mat.myData[0]  + myData[7] * Mat.myData[1]  + myData[15] * Mat.myData[3],
00175                    myData[3] * Mat.myData[4]  + myData[7] * Mat.myData[5]  + myData[15] * Mat.myData[7],
00176                    myData[3] * Mat.myData[12] + myData[7] * Mat.myData[13] + myData[15] * Mat.myData[15]);
00177 }
00178
00179
00183 inline Matrix3& Matrix3::operator *=(const Matrix3& Mat)
00184 {
00185     return *this = *this * Mat;
00186 }


  • File List

Music.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Audio/Music.hpp>
00029 #include <SFML/Audio/OpenAL.hpp>
00030 #include <SFML/Audio/SoundFile.hpp>
00031 #include <fstream>
00032 #include <iostream>
00033
00034
00035 namespace sf
00036 {
00040 Music::Music(std::size_t BufferSize) :
00041 myFile    (NULL),
00042 myDuration(0.f),
00043 mySamples (BufferSize)
00044 {
00045
00046 }
00047
00048
00052 Music::~Music()
00053 {
00054     // We must stop before destroying the file :)
00055     Stop();
00056
00057     delete myFile;
00058 }
00059
00060
00064 bool Music::OpenFromFile(const std::string& Filename)
00065 {
00066     // First stop the music if it was already running
00067     Stop();
00068
00069     // Create the sound file implementation, and open it in read mode
00070     delete myFile;
00071     myFile = priv::SoundFile::CreateRead(Filename);
00072     if (!myFile)
00073     {
00074         std::cerr << "Failed to open \"" << Filename << "\" for reading" << std::endl;
00075         return false;
00076     }
00077
00078     // Compute the duration
00079     myDuration = static_cast<float>(myFile->GetSamplesCount()) / myFile->GetSampleRate() / myFile->GetChannelsCount();
00080
00081     // Initialize the stream
00082     Initialize(myFile->GetChannelsCount(), myFile->GetSampleRate());
00083
00084     return true;
00085 }
00086
00087
00091 bool Music::OpenFromMemory(const char* Data, std::size_t SizeInBytes)
00092 {
00093     // First stop the music if it was already running
00094     Stop();
00095
00096     // Create the sound file implementation, and open it in read mode
00097     delete myFile;
00098     myFile = priv::SoundFile::CreateRead(Data, SizeInBytes);
00099     if (!myFile)
00100     {
00101         std::cerr << "Failed to open music from memory for reading" << std::endl;
00102         return false;
00103     }
00104
00105     // Compute the duration
00106     myDuration = static_cast<float>(myFile->GetSamplesCount()) / myFile->GetSampleRate();
00107
00108     // Initialize the stream
00109     Initialize(myFile->GetChannelsCount(), myFile->GetSampleRate());
00110
00111     return true;
00112 }
00113
00114
00118 bool Music::OnStart()
00119 {
00120     return myFile && myFile->Restart();
00121 }
00122
00123
00127 bool Music::OnGetData(SoundStream::Chunk& Data)
00128 {
00129     if (myFile)
00130     {
00131         // Fill the chunk parameters
00132         Data.Samples   = &mySamples[0];
00133         Data.NbSamples = myFile->Read(&mySamples[0], mySamples.size());
00134
00135         // Check if we have reached the end of the audio file
00136         return Data.NbSamples == mySamples.size();
00137     }
00138     else
00139     {
00140         return false;
00141     }
00142 }
00143
00144
00148 float Music::GetDuration() const
00149 {
00150     return myDuration;
00151 }
00152
00153 } // namespace sf


  • File List

Music.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_MUSIC_HPP
00026 #define SFML_MUSIC_HPP
00027
00029 // Headers
00031 #include <SFML/Audio/SoundStream.hpp>
00032 #include <string>
00033 #include <vector>
00034
00035
00036 namespace sf
00037 {
00038 namespace priv
00039 {
00040     class SoundFile;
00041 }
00042
00047 class SFML_API Music : public SoundStream
00048 {
00049 public :
00050
00058     explicit Music(std::size_t BufferSize = 44100);
00059
00064     ~Music();
00065
00074     bool OpenFromFile(const std::string& Filename);
00075
00085     bool OpenFromMemory(const char* Data, std::size_t SizeInBytes);
00086
00093     float GetDuration() const;
00094
00095 private :
00096
00101     virtual bool OnStart();
00102
00107     virtual bool OnGetData(Chunk& Data);
00108
00110     // Member data
00112     priv::SoundFile*   myFile;
00113     float              myDuration;
00114     std::vector<Int16> mySamples;
00115 };
00116
00117 } // namespace sf
00118
00119
00120 #endif // SFML_MUSIC_HPP


  • File List

Mutex.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/System/Win32/Mutex.hpp>
00029
00030
00031 namespace sf
00032 {
00036 Mutex::Mutex()
00037 {
00038     InitializeCriticalSection(&myHandle);
00039 }
00040
00041
00045 Mutex::~Mutex()
00046 {
00047     DeleteCriticalSection(&myHandle);
00048 }
00049
00050
00054 void Mutex::Lock()
00055 {
00056     EnterCriticalSection(&myHandle);
00057 }
00058
00059
00063 void Mutex::Unlock()
00064 {
00065     LeaveCriticalSection(&myHandle);
00066 }
00067
00068 } // namespace sf


  • File List

Mutex.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_MUTEX_HPP
00026 #define SFML_MUTEX_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 #ifdef SFML_SYSTEM_WINDOWS
00035
00036     #include <SFML/System/Win32/Mutex.hpp>
00037
00038 #else
00039
00040     #include <SFML/System/Unix/Mutex.hpp>
00041
00042 #endif
00043
00044
00045 #endif // SFML_MUTEX_HPP


  • File List

Network.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_NETWORK_HPP
00026 #define SFML_NETWORK_HPP
00027
00029 // Headers
00031
00032 #include <SFML/System.hpp>
00033 #include <SFML/Network/Ftp.hpp>
00034 #include <SFML/Network/Http.hpp>
00035 #include <SFML/Network/IPAddress.hpp>
00036 #include <SFML/Network/Packet.hpp>
00037 #include <SFML/Network/Selector.hpp>
00038 #include <SFML/Network/SocketTCP.hpp>
00039 #include <SFML/Network/SocketUDP.hpp>
00040
00041
00042 #endif // SFML_NETWORK_HPP


  • File List

NonCopyable.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_NONCOPYABLE_HPP
00026 #define SFML_NONCOPYABLE_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 namespace sf
00035 {
00040 struct SFML_API NonCopyable
00041 {
00042 protected :
00043
00048     NonCopyable() {}
00049
00050 private :
00051
00057     NonCopyable(const NonCopyable&);
00058
00064     NonCopyable& operator =(const NonCopyable&);
00065 };
00066
00067 } // namespace sf
00068
00069
00070 #endif // SFML_NONCOPYABLE_HPP


  • File List

OpenAL.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_OPENAL_HPP
00026 #define SFML_OPENAL_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033 #if defined(SFML_SYSTEM_MACOS)
00034 #include <OpenAL/al.h>
00035 #include <OpenAL/alc.h>
00036 #else
00037 #include <AL/al.h>
00038 #include <AL/alc.h>
00039 #endif
00040
00041 #include <iostream>
00042 #include <string>
00043
00044
00045 namespace sf
00046 {
00047 namespace priv
00048 {
00054 #ifdef SFML_DEBUG
00055
00056     // If in debug mode, perform a test on every call
00057     #define ALCheck(Func) ((Func), priv::ALCheckError(__FILE__, __LINE__))
00058
00059 #else
00060
00061     // Else, we don't add any overhead
00062     #define ALCheck(Func) (Func)
00063
00064 #endif
00065
00066
00071 inline void ALCheckError(const std::string& File, unsigned int Line)
00072 {
00073     // Get the last error
00074     ALenum ErrorCode = alGetError();
00075
00076     if (ErrorCode != AL_NO_ERROR)
00077     {
00078         std::string Error, Desc;
00079
00080         // Decode the error code
00081         switch (ErrorCode)
00082         {
00083             case AL_INVALID_NAME :
00084             {
00085                 Error = "AL_INVALID_NAME";
00086                 Desc  = "an unacceptable name has been specified";
00087                 break;
00088             }
00089
00090             case AL_INVALID_ENUM :
00091             {
00092                 Error = "AL_INVALID_ENUM";
00093                 Desc  = "an unacceptable value has been specified for an enumerated argument";
00094                 break;
00095             }
00096
00097             case AL_INVALID_VALUE :
00098             {
00099                 Error = "AL_INVALID_VALUE";
00100                 Desc  = "a numeric argument is out of range";
00101                 break;
00102             }
00103
00104             case AL_INVALID_OPERATION :
00105             {
00106                 Error = "AL_INVALID_OPERATION";
00107                 Desc  = "the specified operation is not allowed in the current state";
00108                 break;
00109             }
00110
00111             case AL_OUT_OF_MEMORY :
00112             {
00113                 Error = "AL_OUT_OF_MEMORY";
00114                 Desc  = "there is not enough memory left to execute the command";
00115                 break;
00116             }
00117         }
00118
00119         // Log the error
00120         std::cerr << "An internal OpenAL call failed in "
00121                   << File.substr(File.find_last_of("\\/") + 1) << " (" << Line << ") : "
00122                   << Error << ", " << Desc
00123                   << std::endl;
00124     }
00125 }
00126
00127 } // namespace priv
00128
00129 } // namespace sf
00130
00131
00132 #endif // SFML_OPENAL_HPP


  • File List

OpenGL.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_OPENGL_HPP
00026 #define SFML_OPENGL_HPP
00027
00028
00032 #include <SFML/Config.hpp>
00033
00034
00039 #if defined(SFML_SYSTEM_WINDOWS)
00040
00041     #include <windows.h>
00042     #include <GL/gl.h>
00043     #include <GL/glu.h>
00044
00045 #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
00046
00047     #include <GL/gl.h>
00048     #include <GL/glu.h>
00049
00050 #elif defined(SFML_SYSTEM_MACOS)
00051
00052     #include <OpenGL/gl.h>
00053     #include <OpenGL/glu.h>
00054
00055 #endif
00056
00057
00058 #endif // SFML_OPENGL_HPP
00059


  • File List

Packet.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Network/Packet.hpp>
00029 #include <SFML/Network/SocketHelper.hpp>
00030 #include <string.h>
00031
00032
00033 namespace sf
00034 {
00038 Packet::Packet() :
00039 myReadPos(0),
00040 myIsValid(true)
00041 {
00042
00043 }
00044
00045
00049 Packet::~Packet()
00050 {
00051
00052 }
00053
00054
00058 void Packet::Append(const void* Data, std::size_t SizeInBytes)
00059 {
00060     if (Data && (SizeInBytes > 0))
00061     {
00062         std::size_t Start = myData.size();
00063         myData.resize(Start + SizeInBytes);
00064         memcpy(&myData[Start], Data, SizeInBytes);
00065     }
00066 }
00067
00068
00072 void Packet::Clear()
00073 {
00074     myData.clear();
00075     myReadPos = 0;
00076     myIsValid = true;
00077 }
00078
00079
00085 const char* Packet::GetData() const
00086 {
00087     return !myData.empty() ? &myData[0] : NULL;
00088 }
00089
00090
00094 std::size_t Packet::GetDataSize() const
00095 {
00096     return myData.size();
00097 }
00098
00099
00103 bool Packet::EndOfPacket() const
00104 {
00105     return myReadPos >= myData.size();
00106 }
00107
00108
00112 Packet::operator bool() const
00113 {
00114     return myIsValid;
00115 }
00116
00117
00121 Packet& Packet::operator >>(bool& Data)
00122 {
00123     Uint8 Value;
00124     if (*this >> Value)
00125         Data = (Value != 0);
00126
00127     return *this;
00128 }
00129 Packet& Packet::operator >>(Int8& Data)
00130 {
00131     if (CheckSize(sizeof(Data)))
00132     {
00133         Data = *reinterpret_cast<const Int8*>(GetData() + myReadPos);
00134         myReadPos += sizeof(Data);
00135     }
00136
00137     return *this;
00138 }
00139 Packet& Packet::operator >>(Uint8& Data)
00140 {
00141     if (CheckSize(sizeof(Data)))
00142     {
00143         Data = *reinterpret_cast<const Uint8*>(GetData() + myReadPos);
00144         myReadPos += sizeof(Data);
00145     }
00146
00147     return *this;
00148 }
00149 Packet& Packet::operator >>(Int16& Data)
00150 {
00151     if (CheckSize(sizeof(Data)))
00152     {
00153         Data = ntohs(*reinterpret_cast<const Int16*>(GetData() + myReadPos));
00154         myReadPos += sizeof(Data);
00155     }
00156
00157     return *this;
00158 }
00159 Packet& Packet::operator >>(Uint16& Data)
00160 {
00161     if (CheckSize(sizeof(Data)))
00162     {
00163         Data = ntohs(*reinterpret_cast<const Uint16*>(GetData() + myReadPos));
00164         myReadPos += sizeof(Data);
00165     }
00166
00167     return *this;
00168 }
00169 Packet& Packet::operator >>(Int32& Data)
00170 {
00171     if (CheckSize(sizeof(Data)))
00172     {
00173         Data = ntohl(*reinterpret_cast<const Int32*>(GetData() + myReadPos));
00174         myReadPos += sizeof(Data);
00175     }
00176
00177     return *this;
00178 }
00179 Packet& Packet::operator >>(Uint32& Data)
00180 {
00181     if (CheckSize(sizeof(Data)))
00182     {
00183         Data = ntohl(*reinterpret_cast<const Uint32*>(GetData() + myReadPos));
00184         myReadPos += sizeof(Data);
00185     }
00186
00187     return *this;
00188 }
00189 Packet& Packet::operator >>(float& Data)
00190 {
00191     if (CheckSize(sizeof(Data)))
00192     {
00193         Data = *reinterpret_cast<const float*>(GetData() + myReadPos);
00194         myReadPos += sizeof(Data);
00195     }
00196
00197     return *this;
00198 }
00199 Packet& Packet::operator >>(double& Data)
00200 {
00201     if (CheckSize(sizeof(Data)))
00202     {
00203         Data = *reinterpret_cast<const double*>(GetData() + myReadPos);
00204         myReadPos += sizeof(Data);
00205     }
00206
00207     return *this;
00208 }
00209 Packet& Packet::operator >>(char* Data)
00210 {
00211     // First extract string length
00212     Uint32 Length;
00213     *this >> Length;
00214
00215     if ((Length > 0) && CheckSize(Length))
00216     {
00217         // Then extract characters
00218         memcpy(Data, GetData() + myReadPos, Length);
00219         Data[Length] = '\0';
00220
00221         // Update reading position
00222         myReadPos += Length;
00223     }
00224
00225     return *this;
00226 }
00227 Packet& Packet::operator >>(std::string& Data)
00228 {
00229     // First extract string length
00230     Uint32 Length;
00231     *this >> Length;
00232
00233     Data.clear();
00234     if ((Length > 0) && CheckSize(Length))
00235     {
00236         // Then extract characters
00237         Data.assign(GetData() + myReadPos, Length);
00238
00239         // Update reading position
00240         myReadPos += Length;
00241     }
00242
00243     return *this;
00244 }
00245 Packet& Packet::operator >>(wchar_t* Data)
00246 {
00247     // First extract string length
00248     Uint32 Length;
00249     *this >> Length;
00250
00251     if ((Length > 0) && CheckSize(Length * sizeof(Int32)))
00252     {
00253         // Then extract characters
00254         for (Uint32 i = 0; i < Length; ++i)
00255         {
00256             Uint32 c;
00257             *this >> c;
00258             Data[i] = static_cast<wchar_t>(c);
00259         }
00260         Data[Length] = L'\0';
00261     }
00262
00263     return *this;
00264 }
00265 Packet& Packet::operator >>(std::wstring& Data)
00266 {
00267     // First extract string length
00268     Uint32 Length;
00269     *this >> Length;
00270
00271     Data.clear();
00272     if ((Length > 0) && CheckSize(Length * sizeof(Int32)))
00273     {
00274         // Then extract characters
00275         for (Uint32 i = 0; i < Length; ++i)
00276         {
00277             Uint32 c;
00278             *this >> c;
00279             Data += static_cast<wchar_t>(c);
00280         }
00281     }
00282
00283     return *this;
00284 }
00285
00286
00290 Packet& Packet::operator <<(bool Data)
00291 {
00292     *this << static_cast<Uint8>(Data);
00293     return *this;
00294 }
00295 Packet& Packet::operator <<(Int8 Data)
00296 {
00297     Append(&Data, sizeof(Data));
00298     return *this;
00299 }
00300 Packet& Packet::operator <<(Uint8 Data)
00301 {
00302     Append(&Data, sizeof(Data));
00303     return *this;
00304 }
00305 Packet& Packet::operator <<(Int16 Data)
00306 {
00307     Int16 ToWrite = htons(Data);
00308     Append(&ToWrite, sizeof(ToWrite));
00309     return *this;
00310 }
00311 Packet& Packet::operator <<(Uint16 Data)
00312 {
00313     Uint16 ToWrite = htons(Data);
00314     Append(&ToWrite, sizeof(ToWrite));
00315     return *this;
00316 }
00317 Packet& Packet::operator <<(Int32 Data)
00318 {
00319     Int32 ToWrite = htonl(Data);
00320     Append(&ToWrite, sizeof(ToWrite));
00321     return *this;
00322 }
00323 Packet& Packet::operator <<(Uint32 Data)
00324 {
00325     Uint32 ToWrite = htonl(Data);
00326     Append(&ToWrite, sizeof(ToWrite));
00327     return *this;
00328 }
00329 Packet& Packet::operator <<(float Data)
00330 {
00331     Append(&Data, sizeof(Data));
00332     return *this;
00333 }
00334 Packet& Packet::operator <<(double Data)
00335 {
00336     Append(&Data, sizeof(Data));
00337     return *this;
00338 }
00339 Packet& Packet::operator <<(const char* Data)
00340 {
00341     // First insert string length
00342     Uint32 Length = 0;
00343     for (const char* c = Data; *c != '\0'; ++c)
00344         ++Length;
00345     *this << Length;
00346
00347     // Then insert characters
00348     Append(Data, Length * sizeof(char));
00349
00350     return *this;
00351 }
00352 Packet& Packet::operator <<(const std::string& Data)
00353 {
00354     // First insert string length
00355     Uint32 Length = static_cast<Uint32>(Data.size());
00356     *this << Length;
00357
00358     // Then insert characters
00359     if (Length > 0)
00360     {
00361         Append(Data.c_str(), Length * sizeof(std::string::value_type));
00362     }
00363
00364     return *this;
00365 }
00366 Packet& Packet::operator <<(const wchar_t* Data)
00367 {
00368     // First insert string length
00369     Uint32 Length = 0;
00370     for (const wchar_t* c = Data; *c != L'\0'; ++c)
00371         ++Length;
00372     *this << Length;
00373
00374     // Then insert characters
00375     for (const wchar_t* c = Data; *c != L'\0'; ++c)
00376         *this << static_cast<Int32>(*c);
00377
00378     return *this;
00379 }
00380 Packet& Packet::operator <<(const std::wstring& Data)
00381 {
00382     // First insert string length
00383     Uint32 Length = static_cast<Uint32>(Data.size());
00384     *this << Length;
00385
00386     // Then insert characters
00387     if (Length > 0)
00388     {
00389         for (std::wstring::const_iterator c = Data.begin(); c != Data.end(); ++c)
00390             *this << static_cast<Int32>(*c);
00391     }
00392
00393     return *this;
00394 }
00395
00396
00400 bool Packet::CheckSize(std::size_t Size)
00401 {
00402     myIsValid = myIsValid && (myReadPos + Size <= myData.size());
00403
00404     return myIsValid;
00405 }
00406
00407
00411 const char* Packet::OnSend(std::size_t& DataSize)
00412 {
00413     DataSize = GetDataSize();
00414     return GetData();
00415 }
00416
00417
00421 void Packet::OnReceive(const char* Data, std::size_t DataSize)
00422 {
00423     Append(Data, DataSize);
00424 }
00425
00426 } // namespace sf


  • File List

Packet.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_PACKET_HPP
00026 #define SFML_PACKET_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <string>
00033 #include <vector>
00034
00035
00036 namespace sf
00037 {
00041 class SFML_API Packet
00042 {
00043 public :
00044
00049     Packet();
00050
00055     virtual ~Packet();
00056
00064     void Append(const void* Data, std::size_t SizeInBytes);
00065
00070     void Clear();
00071
00080     const char* GetData() const;
00081
00088     std::size_t GetDataSize() const;
00089
00096     bool EndOfPacket() const;
00097
00104     operator bool() const;
00105
00110     Packet& operator >>(bool&         Data);
00111     Packet& operator >>(Int8&         Data);
00112     Packet& operator >>(Uint8&        Data);
00113     Packet& operator >>(Int16&        Data);
00114     Packet& operator >>(Uint16&       Data);
00115     Packet& operator >>(Int32&        Data);
00116     Packet& operator >>(Uint32&       Data);
00117     Packet& operator >>(float&        Data);
00118     Packet& operator >>(double&       Data);
00119     Packet& operator >>(char*         Data);
00120     Packet& operator >>(std::string&  Data);
00121     Packet& operator >>(wchar_t*      Data);
00122     Packet& operator >>(std::wstring& Data);
00123
00128     Packet& operator <<(bool                Data);
00129     Packet& operator <<(Int8                Data);
00130     Packet& operator <<(Uint8               Data);
00131     Packet& operator <<(Int16               Data);
00132     Packet& operator <<(Uint16              Data);
00133     Packet& operator <<(Int32               Data);
00134     Packet& operator <<(Uint32              Data);
00135     Packet& operator <<(float               Data);
00136     Packet& operator <<(double              Data);
00137     Packet& operator <<(const char*         Data);
00138     Packet& operator <<(const std::string&  Data);
00139     Packet& operator <<(const wchar_t*      Data);
00140     Packet& operator <<(const std::wstring& Data);
00141
00142 private :
00143
00144     friend class SocketTCP;
00145     friend class SocketUDP;
00146
00155     bool CheckSize(std::size_t Size);
00156
00165     virtual const char* OnSend(std::size_t& DataSize);
00166
00174     virtual void OnReceive(const char* Data, std::size_t DataSize);
00175
00177     // Member data
00179     std::vector<char> myData;
00180     std::size_t       myReadPos;
00181     bool              myIsValid;
00182 };
00183
00184 } // namespace sf
00185
00186
00187 #endif // SFML_PACKET_HPP


  • File List

Platform.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/System/Win32/Platform.hpp>
00029 #include <windows.h>
00030
00031
00032 namespace sf
00033 {
00034 namespace priv
00035 {
00039 double Platform::GetSystemTime()
00040 {
00041     static LARGE_INTEGER Frequency;
00042     static BOOL          UseHighPerformanceTimer = QueryPerformanceFrequency(&Frequency);
00043
00044     if (UseHighPerformanceTimer)
00045     {
00046         // High performance counter available : use it
00047         LARGE_INTEGER CurrentTime;
00048         QueryPerformanceCounter(&CurrentTime);
00049
00050         return static_cast<double>(CurrentTime.QuadPart) / Frequency.QuadPart;
00051     }
00052     else
00053     {
00054         // High performance counter not available : use GetTickCount (less accurate)
00055         return GetTickCount() * 0.001;
00056     }
00057 }
00058
00059
00063 void Platform::Sleep(float Time)
00064 {
00065     ::Sleep(static_cast<DWORD>(Time * 1000));
00066 }
00067
00068 } // namespace priv
00069
00070 } // namespace sf


  • File List

Platform.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_PLATFORM_HPP
00026 #define SFML_PLATFORM_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 #if defined(SFML_SYSTEM_WINDOWS)
00035
00036     #include <SFML/System/Win32/Platform.hpp>
00037
00038 #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_FREEBSD)
00039
00040     #include <SFML/System/Unix/Platform.hpp>
00041
00042 #endif
00043
00044
00045 #endif // SFML_PLATFORM_HPP


  • File List

PostFX.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025
00027 // Headers
00029 #include <SFML/Graphics/PostFX.hpp>
00030 #include <SFML/Graphics/RenderWindow.hpp>
00031 #include <SFML/Graphics/GraphicsContext.hpp>
00032 #include <fstream>
00033 #include <iostream>
00034 #include <set>
00035 #include <sstream>
00036
00037
00038 namespace sf
00039 {
00043 PostFX::PostFX() :
00044 myShaderProgram(0)
00045 {
00046     // No filtering on frame buffer
00047     myFrameBuffer.SetSmooth(false);
00048 }
00049
00050
00054 PostFX::PostFX(const PostFX& Copy) :
00055 Drawable        (Copy),
00056 myShaderProgram (0),
00057 myTextures      (Copy.myTextures),
00058 myFragmentShader(Copy.myFragmentShader),
00059 myFrameBuffer   (Copy.myFrameBuffer)
00060 {
00061     // No filtering on frame buffer
00062     myFrameBuffer.SetSmooth(false);
00063
00064     // Create the shaders and the program
00065     if (Copy.myShaderProgram)
00066         CreateProgram();
00067 }
00068
00069
00073 PostFX::~PostFX()
00074 {
00075     // Destroy effect program
00076     if (myShaderProgram)
00077     {
00078         // Make sure we have a valid context
00079         priv::GraphicsContext Ctx;
00080
00081         GLCheck(glDeleteObjectARB(myShaderProgram));
00082     }
00083 }
00084
00085
00089 bool PostFX::LoadFromFile(const std::string& Filename)
00090 {
00091     // Open the file
00092     std::ifstream File(Filename.c_str());
00093     if (!File)
00094     {
00095         std::cerr << "Failed to open effect file \"" << Filename << "\"" << std::endl;
00096         return false;
00097     }
00098
00099     // Apply the preprocessing pass to the fragment shader code
00100     myFragmentShader = PreprocessEffect(File);
00101
00102     // Create the shaders and the program
00103     CreateProgram();
00104
00105     return myShaderProgram != 0;
00106 }
00107
00108
00112 bool PostFX::LoadFromMemory(const std::string& Effect)
00113 {
00114     // Open a stream and copy the effect code
00115     std::istringstream Stream(Effect.c_str());
00116
00117     // Apply the preprocessing pass to the fragment shader code
00118     myFragmentShader = PreprocessEffect(Stream);
00119
00120     // Create the shaders and the program
00121     CreateProgram();
00122
00123     return myShaderProgram != 0;
00124 }
00125
00126
00130 void PostFX::SetParameter(const std::string& Name, float X)
00131 {
00132     if (myShaderProgram)
00133     {
00134         // Enable program
00135         GLCheck(glUseProgramObjectARB(myShaderProgram));
00136
00137         // Get parameter location and assign it new values
00138         GLint Location = glGetUniformLocationARB(myShaderProgram, Name.c_str());
00139         if (Location != -1)
00140             GLCheck(glUniform1fARB(Location, X));
00141         else
00142             std::cerr << "Parameter \"" << Name << "\" not found in post-effect" << std::endl;
00143
00144         // Disable program
00145         GLCheck(glUseProgramObjectARB(0));
00146     }
00147 }
00148
00149
00153 void PostFX::SetParameter(const std::string& Name, float X, float Y)
00154 {
00155     if (myShaderProgram)
00156     {
00157         // Enable program
00158         GLCheck(glUseProgramObjectARB(myShaderProgram));
00159
00160         // Get parameter location and assign it new values
00161         GLint Location = glGetUniformLocationARB(myShaderProgram, Name.c_str());
00162         if (Location != -1)
00163             GLCheck(glUniform2fARB(Location, X, Y));
00164         else
00165             std::cerr << "Parameter \"" << Name << "\" not found in post-effect" << std::endl;
00166
00167         // Disable program
00168         GLCheck(glUseProgramObjectARB(0));
00169     }
00170 }
00171
00172
00176 void PostFX::SetParameter(const std::string& Name, float X, float Y, float Z)
00177 {
00178     if (myShaderProgram)
00179     {
00180         // Enable program
00181         GLCheck(glUseProgramObjectARB(myShaderProgram));
00182
00183         // Get parameter location and assign it new values
00184         GLint Location = glGetUniformLocationARB(myShaderProgram, Name.c_str());
00185         if (Location != -1)
00186             GLCheck(glUniform3fARB(Location, X, Y, Z));
00187         else
00188             std::cerr << "Parameter \"" << Name << "\" not found in post-effect" << std::endl;
00189
00190         // Disable program
00191         GLCheck(glUseProgramObjectARB(0));
00192     }
00193 }
00194
00195
00199 void PostFX::SetParameter(const std::string& Name, float X, float Y, float Z, float W)
00200 {
00201     if (myShaderProgram)
00202     {
00203         // Enable program
00204         GLCheck(glUseProgramObjectARB(myShaderProgram));
00205
00206         // Get parameter location and assign it new values
00207         GLint Location = glGetUniformLocationARB(myShaderProgram, Name.c_str());
00208         if (Location != -1)
00209             GLCheck(glUniform4fARB(Location, X, Y, Z, W));
00210         else
00211             std::cerr << "Parameter \"" << Name << "\" not found in post-effect" << std::endl;
00212
00213         // Disable program
00214         GLCheck(glUseProgramObjectARB(0));
00215     }
00216 }
00217
00218
00222 void PostFX::SetTexture(const std::string& Name, Image* Texture)
00223 {
00224     // Check that the current texture unit is available
00225     GLint MaxUnits;
00226     GLCheck(glGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, &MaxUnits));
00227     if (myTextures.size() >= static_cast<std::size_t>(MaxUnits))
00228     {
00229         std::cerr << "Impossible to use texture \"" << Name << "\" for post-effect : all available texture units are used" << std::endl;
00230         return;
00231     }
00232
00233     // Make sure the given name is a valid variable in the effect
00234     int Location = glGetUniformLocationARB(myShaderProgram, Name.c_str());
00235     if (Location == -1)
00236     {
00237         std::cerr << "Texture \"" << Name << "\" not found in post-effect" << std::endl;
00238         return;
00239     }
00240
00241     // Store the texture for later use
00242     myTextures[Name] = Texture ? Texture : &myFrameBuffer;
00243 }
00244
00245
00249 PostFX& PostFX::operator =(const PostFX& Other)
00250 {
00251     PostFX Temp(Other);
00252
00253     std::swap(myShaderProgram,  Temp.myShaderProgram);
00254     std::swap(myTextures,       Temp.myTextures);
00255     std::swap(myFragmentShader, Temp.myFragmentShader);
00256     std::swap(myFrameBuffer,    Temp.myFrameBuffer);
00257
00258     return *this;
00259 }
00260
00261
00265 bool PostFX::CanUsePostFX()
00266 {
00267     // Make sure we have a valid context
00268     priv::GraphicsContext Ctx;
00269
00270     return glewIsSupported("GL_ARB_shading_language_100") != 0 &&
00271            glewIsSupported("GL_ARB_shader_objects")       != 0 &&
00272            glewIsSupported("GL_ARB_vertex_shader")        != 0 &&
00273            glewIsSupported("GL_ARB_fragment_shader")      != 0;
00274 }
00275
00276
00280 void PostFX::Render(RenderTarget& Target) const
00281 {
00282     // Check that we have a valid program
00283     if (!myShaderProgram)
00284         return;
00285
00286     // Copy the current framebuffer pixels to our frame buffer texture
00287     // The ugly cast is temporary until PostFx are rewritten :)
00288     myFrameBuffer.CopyScreen((RenderWindow&)Target);
00289
00290     // Enable program
00291     GLCheck(glUseProgramObjectARB(myShaderProgram));
00292
00293     // Bind textures
00294     TextureTable::const_iterator ItTex = myTextures.begin();
00295     for (std::size_t i = 0; i < myTextures.size(); ++i)
00296     {
00297         int Location = glGetUniformLocationARB(myShaderProgram, ItTex->first.c_str());
00298         GLCheck(glUniform1iARB(Location, static_cast<GLint>(i)));
00299         GLCheck(glActiveTextureARB(static_cast<GLenum>(GL_TEXTURE0_ARB + i)));
00300         ItTex->second->Bind();
00301         ItTex++;
00302     }
00303
00304     // Compute the texture coordinates (in case the texture is larger than the screen, or flipped)
00305     IntRect FrameBufferRect(0, 0, myFrameBuffer.GetWidth(), myFrameBuffer.GetHeight());
00306     FloatRect TexCoords = myFrameBuffer.GetTexCoords(FrameBufferRect);
00307
00308     // Render a fullscreen quad using the effect on our framebuffer
00309     FloatRect Screen = Target.GetView().GetRect();
00310     glBegin(GL_QUADS);
00311          glTexCoord2f(TexCoords.Left,  TexCoords.Top);    glVertex2f(Screen.Left,  Screen.Bottom);
00312          glTexCoord2f(TexCoords.Right, TexCoords.Top);    glVertex2f(Screen.Right, Screen.Bottom);
00313          glTexCoord2f(TexCoords.Right, TexCoords.Bottom); glVertex2f(Screen.Right, Screen.Top);
00314          glTexCoord2f(TexCoords.Left,  TexCoords.Bottom); glVertex2f(Screen.Left,  Screen.Top);
00315     glEnd();
00316
00317     // Disable program
00318     GLCheck(glUseProgramObjectARB(0));
00319
00320     // Disable texture units
00321     for (std::size_t i = 0; i < myTextures.size(); ++i)
00322     {
00323         GLCheck(glActiveTextureARB(static_cast<GLenum>(GL_TEXTURE0_ARB + i)));
00324         GLCheck(glBindTexture(GL_TEXTURE_2D, 0));
00325     }
00326     GLCheck(glActiveTextureARB(GL_TEXTURE0_ARB));
00327 }
00328
00329
00334 std::string PostFX::PreprocessEffect(std::istream& File)
00335 {
00336     // Initialize output string
00337     std::set<std::string> myTextures;
00338     std::string Out = "";
00339
00340     // Variable declarations
00341     std::string Line;
00342     while (std::getline(File, Line) && (Line.substr(0, 6) != "effect"))
00343     {
00344         // Remove the ending '\r', if any
00345         if (!Line.empty() && (Line[Line.size() - 1] == '\r'))
00346             Line.erase(Line.size() - 1);
00347
00348         // Skip empty lines
00349         if (Line == "")
00350             continue;
00351
00352         // Extract variables type and name and convert them
00353         std::string Type, Name;
00354         std::istringstream iss(Line);
00355         if (!(iss >> Type >> Name))
00356         {
00357             std::cerr << "Post-effect error : invalid declaration (should be \"[type][name]\")" << std::endl
00358                       << "> " << Line << std::endl;
00359             return "";
00360         }
00361
00362         if (Type == "texture")
00363         {
00364             // Textures need some checking and conversion
00365             if (myTextures.find(Name) != myTextures.end())
00366             {
00367                 std::cerr << "Post-effect error : texture \"" << Name << "\" already exists" << std::endl;
00368                 return "";
00369             }
00370
00371             Out += "uniform sampler2D " + Name + ";\n";
00372             myTextures.insert(Name);
00373         }
00374         else
00375         {
00376             // Other types are just copied to output with "uniform" prefix
00377             Out += "uniform " + Type + " " + Name + ";\n";
00378         }
00379     }
00380
00381     // Effect code
00382     Out += "void main()\n";
00383     while (std::getline(File, Line))
00384     {
00385         // Replace any texture lookup "T(" by "texture2D(T, "
00386         for (std::set<std::string>::const_iterator i = myTextures.begin(); i != myTextures.end(); ++i)
00387         {
00388             std::string::size_type Pos = Line.find(*i);
00389             if (Pos != std::string::npos)
00390                 Line.replace(Pos, i->size() + 1, "texture2D(" + *i + ", ");
00391         }
00392
00393         // Replace "_in" by "gl_TexCoord[0].xy"
00394         for (std::string::size_type Pos = Line.find("_in"); Pos != std::string::npos; Pos = Line.find("_in"))
00395             Line.replace(Pos, 3, "gl_TexCoord[0].xy");
00396
00397         // Replace "_out" by "gl_FragColor"
00398         for (std::string::size_type Pos = Line.find("_out"); Pos != std::string::npos; Pos = Line.find("_out"))
00399             Line.replace(Pos, 4, "gl_FragColor");
00400
00401         // Write modified line to output string
00402         Out += Line + "\n";
00403     }
00404
00405     return Out;
00406 }
00407
00408
00412 void PostFX::CreateProgram()
00413 {
00414     // Make sure we have a valid context
00415     priv::GraphicsContext Ctx;
00416
00417     // Check that we can use post-FX !
00418     if (!CanUsePostFX())
00419     {
00420         std::cerr << "Failed to create a PostFX : your system doesn't support effects" << std::endl;
00421         return;
00422     }
00423
00424     // Destroy effect program if it was already created
00425     if (myShaderProgram)
00426         GLCheck(glDeleteObjectARB(myShaderProgram));
00427
00428     // Define vertex shader source (we provide it directly as it doesn't have to change)
00429     static const std::string VertexShaderSrc =
00430         "void main()"
00431         "{"
00432         "    gl_TexCoord[0] = gl_MultiTexCoord0;"
00433         "    gl_Position = ftransform();"
00434         "}";
00435
00436     // Create the program
00437     myShaderProgram = glCreateProgramObjectARB();
00438
00439     // Create the shaders
00440     GLhandleARB VertexShader   = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
00441     GLhandleARB FragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
00442
00443     // Compile them
00444     const char* VertexSrc   = VertexShaderSrc.c_str();
00445     const char* FragmentSrc = myFragmentShader.c_str();
00446     GLCheck(glShaderSourceARB(VertexShader,   1, &VertexSrc,   NULL));
00447     GLCheck(glShaderSourceARB(FragmentShader, 1, &FragmentSrc, NULL));
00448     GLCheck(glCompileShaderARB(VertexShader));
00449     GLCheck(glCompileShaderARB(FragmentShader));
00450
00451     // Check the compile logs
00452     GLint Success;
00453     GLCheck(glGetObjectParameterivARB(VertexShader, GL_OBJECT_COMPILE_STATUS_ARB, &Success));
00454     if (Success == GL_FALSE)
00455     {
00456         char CompileLog[1024];
00457         GLCheck(glGetInfoLogARB(VertexShader, sizeof(CompileLog), 0, CompileLog));
00458         std::cerr << "Failed to compile post-effect :" << std::endl
00459                   << CompileLog << std::endl;
00460         GLCheck(glDeleteObjectARB(VertexShader));
00461         GLCheck(glDeleteObjectARB(FragmentShader));
00462         GLCheck(glDeleteObjectARB(myShaderProgram));
00463         myShaderProgram = 0;
00464         return;
00465     }
00466     GLCheck(glGetObjectParameterivARB(FragmentShader, GL_OBJECT_COMPILE_STATUS_ARB, &Success));
00467     if (Success == GL_FALSE)
00468     {
00469         char CompileLog[1024];
00470         GLCheck(glGetInfoLogARB(FragmentShader, sizeof(CompileLog), 0, CompileLog));
00471         std::cerr << "Failed to compile post-effect :" << std::endl
00472                   << CompileLog << std::endl;
00473         GLCheck(glDeleteObjectARB(VertexShader));
00474         GLCheck(glDeleteObjectARB(FragmentShader));
00475         GLCheck(glDeleteObjectARB(myShaderProgram));
00476         myShaderProgram = 0;
00477         return;
00478     }
00479
00480     // Attach the shaders to the program
00481     GLCheck(glAttachObjectARB(myShaderProgram, VertexShader));
00482     GLCheck(glAttachObjectARB(myShaderProgram, FragmentShader));
00483
00484     // We can now delete the shaders
00485     GLCheck(glDeleteObjectARB(VertexShader));
00486     GLCheck(glDeleteObjectARB(FragmentShader));
00487
00488     // Link the program
00489     GLCheck(glLinkProgramARB(myShaderProgram));
00490
00491     // Get link log
00492     GLCheck(glGetObjectParameterivARB(myShaderProgram, GL_OBJECT_LINK_STATUS_ARB, &Success));
00493     if (Success == GL_FALSE)
00494     {
00495         // Oops... link errors
00496         char LinkLog[1024];
00497         GLCheck(glGetInfoLogARB(myShaderProgram, sizeof(LinkLog), 0, LinkLog));
00498         std::cerr << "Failed to link post-effect :" << std::endl
00499                   << LinkLog << std::endl;
00500         GLCheck(glDeleteObjectARB(myShaderProgram));
00501         myShaderProgram = 0;
00502         return;
00503     }
00504 }
00505
00506 } // namespace sf


  • File List

PostFX.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_POSTFX_HPP
00026 #define SFML_POSTFX_HPP
00027
00029 // Headers
00031 #include <SFML/Graphics/Drawable.hpp>
00032 #include <SFML/Graphics/Image.hpp>
00033 #include <istream>
00034 #include <map>
00035 #include <string>
00036
00037
00038 namespace sf
00039 {
00043 class SFML_API PostFX : public Drawable
00044 {
00045 public :
00046
00051     PostFX();
00052
00059     PostFX(const PostFX& Copy);
00060
00065     ~PostFX();
00066
00075     bool LoadFromFile(const std::string& Filename);
00076
00085     bool LoadFromMemory(const std::string& Effect);
00086
00094     void SetParameter(const std::string& Name, float X);
00095
00103     void SetParameter(const std::string& Name, float X, float Y);
00104
00112     void SetParameter(const std::string& Name, float X, float Y, float Z);
00113
00121     void SetParameter(const std::string& Name, float X, float Y, float Z, float W);
00122
00130     void SetTexture(const std::string& Name, Image* Texture);
00131
00140     PostFX& operator =(const PostFX& Other);
00141
00148     static bool CanUsePostFX();
00149
00150 protected :
00151
00156     virtual void Render(RenderTarget& Target) const;
00157
00158 private :
00159
00169     static std::string PreprocessEffect(std::istream& File);
00170
00175     void CreateProgram();
00176
00178     // Types
00180     typedef std::map<std::string, const Image*> TextureTable;
00181
00183     // Member data
00185     unsigned int  myShaderProgram;
00186     TextureTable  myTextures;
00187     std::string   myFragmentShader;
00188     mutable Image myFrameBuffer;
00189 };
00190
00191 } // namespace sf
00192
00193
00194 #endif // SFML_POSTFX_HPP


  • File List

Randomizer.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/System/Randomizer.hpp>
00029 #include <stdlib.h>
00030 #include <time.h>
00031
00032
00033 namespace
00034 {
00035     // Set the random numbers sequence seed with the current system time, so that it is always different
00036     unsigned int SetRandomSeed()
00037     {
00038         unsigned int Seed = static_cast<unsigned int>(time(NULL));
00039         srand(Seed);
00040         return Seed;
00041     }
00042 }
00043
00044
00045 namespace sf
00046 {
00048 // Static member variables
00050 unsigned int Randomizer::ourSeed = SetRandomSeed();
00051
00052
00057 void Randomizer::SetSeed(unsigned int Seed)
00058 {
00059     srand(Seed);
00060     ourSeed = Seed;
00061 }
00062
00063
00067 unsigned int Randomizer::GetSeed()
00068 {
00069     return ourSeed;
00070 }
00071
00072
00076 float Randomizer::Random(float Begin, float End)
00077 {
00078     // This is not the best algorithm, but it is fast and will be enough in most cases
00079     // (see Google for best approaches)
00080
00081     return static_cast<float>(rand()) / RAND_MAX * (End - Begin) + Begin;
00082 }
00083
00084
00088 int Randomizer::Random(int Begin, int End)
00089 {
00090     // This is not the best algorithm, but it is fast and will be enough in most cases
00091     // (see Google for best approaches)
00092
00093     return rand() % (End - Begin + 1) + Begin;
00094 }
00095
00096 } // namespace sf


  • File List

Randomizer.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_RANDOMIZER_HPP
00026 #define SFML_RANDOMIZER_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 namespace sf
00035 {
00040 class SFML_API Randomizer
00041 {
00042 public :
00043
00051     static void SetSeed(unsigned int Seed);
00052
00059     static unsigned int GetSeed();
00060
00070     static float Random(float Begin, float End);
00071
00081     static int Random(int Begin, int End);
00082
00083 private :
00084
00086     // Static member variables
00088     static unsigned int ourSeed;
00089 };
00090
00091 } // namespace sf
00092
00093
00094 #endif // SFML_RANDOMIZER_HPP


  • File List

Rect.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_RECT_HPP
00026 #define SFML_RECT_HPP
00027
00029 // Headers
00031 #include <algorithm>
00032
00033
00034 namespace sf
00035 {
00040 template <typename T>
00041 class Rect
00042 {
00043 public :
00044
00049     Rect();
00050
00060     Rect(T LeftCoord, T TopCoord, T RightCoord, T BottomCoord);
00061
00068     T GetWidth() const;
00069
00076     T GetHeight() const;
00077
00085     void Offset(T OffsetX, T OffsetY);
00086
00096     bool Contains(T X, T Y) const;
00097
00107     bool Intersects(const Rect<T>& Rectangle, Rect<T>* OverlappingRect = NULL) const;
00108
00110     // Member data
00112     T Left;
00113     T Top;
00114     T Right;
00115     T Bottom;
00116 };
00117
00118 #include <SFML/Graphics/Rect.inl>
00119
00120 // Define the most common types
00121 typedef Rect<int>   IntRect;
00122 typedef Rect<float> FloatRect;
00123
00124 } // namespace sf
00125
00126
00127 #endif // SFML_RECT_HPP


  • File List

Rect.inl

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025
00029 template <typename T>
00030 Rect<T>::Rect() :
00031 Left  (0),
00032 Top   (0),
00033 Right (0),
00034 Bottom(0)
00035 {
00036
00037 }
00038
00039
00043 template <typename T>
00044 Rect<T>::Rect(T LeftCoord, T TopCoord, T RightCoord, T BottomCoord) :
00045 Left  (LeftCoord),
00046 Top   (TopCoord),
00047 Right (RightCoord),
00048 Bottom(BottomCoord)
00049 {
00050
00051 }
00052
00053
00057 template <typename T>
00058 T Rect<T>::GetWidth() const
00059 {
00060     return Right - Left;
00061 }
00062
00063
00067 template <typename T>
00068 T Rect<T>::GetHeight() const
00069 {
00070     return Bottom - Top;
00071 }
00072
00073
00077 template <typename T>
00078 void Rect<T>::Offset(T OffsetX, T OffsetY)
00079 {
00080     Left   += OffsetX;
00081     Right  += OffsetX;
00082     Top    += OffsetY;
00083     Bottom += OffsetY;
00084 }
00085
00086
00090 template <typename T>
00091 bool Rect<T>::Contains(T X, T Y) const
00092 {
00093     return (X >= Left) && (X <= Right) && (Y >= Top) && (Y <= Bottom);
00094 }
00095
00096
00100 template <typename T>
00101 bool Rect<T>::Intersects(const Rect<T>& Rectangle, Rect<T>* OverlappingRect) const
00102 {
00103     // Compute overlapping rect
00104     Rect Overlapping(std::max(Left,   Rectangle.Left),
00105                      std::max(Top,    Rectangle.Top),
00106                      std::min(Right,  Rectangle.Right),
00107                      std::min(Bottom, Rectangle.Bottom));
00108
00109     // If overlapping rect is valid, then there is intersection
00110     if ((Overlapping.Left < Overlapping.Right) && (Overlapping.Top < Overlapping.Bottom))
00111     {
00112         if (OverlappingRect)
00113             *OverlappingRect = Overlapping;
00114         return true;
00115     }
00116     else
00117     {
00118         if (OverlappingRect)
00119             *OverlappingRect = Rect(0, 0, 0, 0);
00120         return false;
00121     }
00122 }


  • File List

RenderTarget.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Graphics/RenderTarget.hpp>
00029 #include <SFML/Graphics/Drawable.hpp>
00030 #include <SFML/Graphics/GraphicsContext.hpp>
00031 #include <iostream>
00032
00033
00034 namespace sf
00035 {
00039 RenderTarget::RenderTarget() :
00040 myCurrentView   (&myDefaultView),
00041 myPreserveStates(false),
00042 myIsDrawing     (false)
00043 {
00044
00045 }
00046
00047
00051 RenderTarget::~RenderTarget()
00052 {
00053     // Nothing to do
00054 }
00055
00056
00060 void RenderTarget::Clear(const Color& FillColor)
00061 {
00062     if (Activate(true))
00063     {
00064         // Clear the frame buffer
00065         GLCheck(glClearColor(FillColor.r / 255.f, FillColor.g / 255.f, FillColor.b / 255.f, FillColor.a / 255.f));
00066         GLCheck(glClear(GL_COLOR_BUFFER_BIT));
00067
00068         Activate(false);
00069     }
00070 }
00071
00072
00076 void RenderTarget::Draw(const Drawable& Object)
00077 {
00078     // Check whether we are called from the outside or from a previous call to Draw
00079     if (!myIsDrawing)
00080     {
00081         myIsDrawing = true;
00082
00083         // Set our target as the current target for rendering
00084         if (Activate(true))
00085         {
00086             // Save the current render states and set the SFML ones
00087             if (myPreserveStates)
00088             {
00089                 GLCheck(glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT   | GL_ENABLE_BIT  |
00090                                      GL_TEXTURE_BIT      | GL_TRANSFORM_BIT | GL_VIEWPORT_BIT));
00091                 GLCheck(glMatrixMode(GL_MODELVIEW));  GLCheck(glPushMatrix());
00092                 GLCheck(glMatrixMode(GL_PROJECTION)); GLCheck(glPushMatrix());
00093                 SetRenderStates();
00094             }
00095
00096             // Set the window viewport and transform matrices
00097             GLCheck(glViewport(0, 0, GetWidth(), GetHeight()));
00098             GLCheck(glMatrixMode(GL_PROJECTION)); GLCheck(glLoadMatrixf(myCurrentView->GetMatrix().Get4x4Elements()));
00099             GLCheck(glMatrixMode(GL_MODELVIEW));  GLCheck(glLoadIdentity());
00100
00101             // Let the object draw itself
00102             Object.Draw(*this);
00103
00104             // Restore render states
00105             if (myPreserveStates)
00106             {
00107                 GLCheck(glMatrixMode(GL_PROJECTION)); GLCheck(glPopMatrix());
00108                 GLCheck(glMatrixMode(GL_MODELVIEW));  GLCheck(glPopMatrix());
00109                 GLCheck(glPopAttrib());
00110             }
00111
00112             // Deactivate rendering on this target
00113             Activate(false);
00114         }
00115
00116         myIsDrawing = false;
00117     }
00118     else
00119     {
00120         // We are already called from a previous Draw : we don't need to set the states again, just draw the object
00121         Object.Draw(*this);
00122     }
00123 }
00124
00125
00129 void RenderTarget::SetView(const View& NewView)
00130 {
00131     myCurrentView = &NewView;
00132 }
00133
00134
00138 const View& RenderTarget::GetView() const
00139 {
00140     return *myCurrentView;
00141 }
00142
00143
00147 View& RenderTarget::GetDefaultView()
00148 {
00149     return myDefaultView;
00150 }
00151
00152
00161 void RenderTarget::PreserveOpenGLStates(bool Preserve)
00162 {
00163     myPreserveStates = Preserve;
00164 }
00165
00166
00170 void RenderTarget::Initialize()
00171 {
00172     // Set the default rendering states
00173     SetRenderStates();
00174
00175     // Setup the default view
00176     myDefaultView.SetFromRect(FloatRect(0, 0, static_cast<float>(GetWidth()), static_cast<float>(GetHeight())));
00177     SetView(myDefaultView);
00178 }
00179
00180
00184 void RenderTarget::SetRenderStates()
00185 {
00186     GLCheck(glDisable(GL_ALPHA_TEST));
00187     GLCheck(glDisable(GL_DEPTH_TEST));
00188     GLCheck(glDisable(GL_LIGHTING));
00189 }
00190
00191 } // namespace sf


  • File List

RenderTarget.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_RENDERTARGET_HPP
00026 #define SFML_RENDERTARGET_HPP
00027
00029 // Headers
00031 #include <SFML/Graphics/Color.hpp>
00032 #include <SFML/Graphics/View.hpp>
00033 #include <SFML/Graphics/Rect.hpp>
00034
00035
00036 namespace sf
00037 {
00038 class Drawable;
00039
00043 class SFML_API RenderTarget
00044 {
00045 public :
00046
00051     virtual ~RenderTarget();
00052
00059     void Clear(const Color& FillColor = Color(0, 0, 0));
00060
00067     virtual void Draw(const Drawable& Object);
00068
00075     virtual unsigned int GetWidth() const = 0;
00076
00083     virtual unsigned int GetHeight() const = 0;
00084
00091     void SetView(const View& NewView);
00092
00099     const View& GetView() const;
00100
00107     View& GetDefaultView();
00108
00120     void PreserveOpenGLStates(bool Preserve);
00121
00122 protected :
00123
00128     RenderTarget();
00129
00134     void Initialize();
00135
00136 private :
00137
00146     virtual bool Activate(bool Active) = 0;
00147
00152     void SetRenderStates();
00153
00155     // Member data
00157     View        myDefaultView;
00158     const View* myCurrentView;
00159     bool        myPreserveStates;
00160     bool        myIsDrawing;
00161 };
00162
00163 } // namespace sf
00164
00165
00166 #endif // SFML_RENDERTARGET_HPP


  • File List

RenderWindow.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Graphics/RenderWindow.hpp>
00029 #include <SFML/Graphics/Drawable.hpp>
00030 #include <SFML/Graphics/Image.hpp>
00031 #include <SFML/Graphics/GraphicsContext.hpp>
00032 #include <iostream>
00033
00034
00035 namespace sf
00036 {
00040 RenderWindow::RenderWindow()
00041 {
00042     // Nothing to do
00043 }
00044
00045
00049 RenderWindow::RenderWindow(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, const WindowSettings& Params)
00050 {
00051     Create(Mode, Title, WindowStyle, Params);
00052 }
00053
00054
00058 RenderWindow::RenderWindow(WindowHandle Handle, const WindowSettings& Params)
00059 {
00060     Create(Handle, Params);
00061 }
00062
00063
00067 RenderWindow::~RenderWindow()
00068 {
00069     // Nothing to do
00070 }
00071
00072
00076 bool RenderWindow::Activate(bool Active)
00077 {
00078     // For performances and consistency reasons, we only handle activation
00079     if (Active)
00080         return SetActive();
00081     else
00082         return true;
00083 }
00084
00085
00089 unsigned int RenderWindow::GetWidth() const
00090 {
00091     return sf::Window::GetWidth();
00092 }
00093
00094
00098 unsigned int RenderWindow::GetHeight() const
00099 {
00100     return sf::Window::GetHeight();
00101 }
00102
00103
00107 Image RenderWindow::Capture() const
00108 {
00109     // Get the window dimensions
00110     const unsigned int Width  = GetWidth();
00111     const unsigned int Height = GetHeight();
00112
00113     // Set our window as the current target for rendering
00114     if (SetActive())
00115     {
00116         // Make sure we have a valid context
00117         priv::GraphicsContext Ctx;
00118
00119         // Get pixels from the backbuffer
00120         std::vector<Uint8> Pixels(Width * Height * 4);
00121         Uint8* PixelsPtr = &Pixels[0];
00122         GLCheck(glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, PixelsPtr));
00123
00124         // Flip the pixels
00125         unsigned int Pitch = Width * 4;
00126         for (unsigned int y = 0; y < Height / 2; ++y)
00127             std::swap_ranges(PixelsPtr + y * Pitch, PixelsPtr + (y + 1) * Pitch, PixelsPtr + (Height - y - 1) * Pitch);
00128
00129         // Create an image from the pixel buffer and return it
00130         return Image(Width, Height, PixelsPtr);
00131     }
00132     else
00133     {
00134         return Image(Width, Height, Color::White);
00135     }
00136 }
00137
00138
00142 sf::Vector2f RenderWindow::ConvertCoords(unsigned int WindowX, unsigned int WindowY, const View* TargetView) const
00143 {
00144     // Use the current view if none has been passed
00145     if (!TargetView)
00146         TargetView = &GetView();
00147
00148     float Left   = TargetView->GetCenter().x - TargetView->GetHalfSize().x;
00149     float Top    = TargetView->GetCenter().y - TargetView->GetHalfSize().y;
00150     float Right  = TargetView->GetCenter().x + TargetView->GetHalfSize().x;
00151     float Bottom = TargetView->GetCenter().y + TargetView->GetHalfSize().y;
00152
00153     return sf::Vector2f(Left + WindowX * (Right - Left) / GetWidth(),
00154                         Top  + WindowY * (Bottom - Top) / GetHeight());
00155 }
00156
00157
00161 void RenderWindow::OnCreate()
00162 {
00163     // We can now initialize the render target part
00164     RenderTarget::Initialize();
00165 }
00166
00167 } // namespace sf


  • File List

RenderWindow.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_RENDERWINDOW_HPP
00026 #define SFML_RENDERWINDOW_HPP
00027
00029 // Headers
00031 #include <SFML/Graphics/Image.hpp>
00032 #include <SFML/Graphics/RenderTarget.hpp>
00033 #include <SFML/Window/Window.hpp>
00034 #include <string>
00035
00036
00037 namespace sf
00038 {
00039 class Drawable;
00040
00045 class SFML_API RenderWindow : public Window, public RenderTarget
00046 {
00047 public :
00048
00053     RenderWindow();
00054
00064     RenderWindow(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings());
00065
00073     RenderWindow(WindowHandle Handle, const WindowSettings& Params = WindowSettings());
00074
00079     virtual ~RenderWindow();
00080
00087     virtual unsigned int GetWidth() const;
00088
00095     virtual unsigned int GetHeight() const;
00096
00103     Image Capture() const;
00104
00115     sf::Vector2f ConvertCoords(unsigned int WindowX, unsigned int WindowY, const View* TargetView = NULL) const;
00116
00117 private :
00118
00123     virtual void OnCreate();
00124
00129     virtual bool Activate(bool Active);
00130 };
00131
00132 } // namespace sf
00133
00134
00135 #endif // SFML_RENDERWINDOW_HPP


  • File List

Resource.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_RESOURCE_HPP
00026 #define SFML_RESOURCE_HPP
00027
00029 // Headers
00031 #include <set>
00032
00033
00034 namespace sf
00035 {
00037 // These two classes are defined in the same header because
00038 // they depend on each other. And as they're template classes,
00039 // they must be entirely defined in header files, which
00040 // prevents from proper separate compiling
00042
00043 template <typename> class ResourcePtr;
00044
00049 template <typename T>
00050 class Resource
00051 {
00052 protected :
00053
00058     Resource();
00059
00066     Resource(const Resource<T>& Copy);
00067
00072     ~Resource();
00073
00082     Resource<T>& operator =(const Resource<T>& Other);
00083
00084 private :
00085
00086     friend class ResourcePtr<T>;
00087
00094     void Connect(ResourcePtr<T>& Observer) const;
00095
00102     void Disconnect(ResourcePtr<T>& Observer) const;
00103
00105     // Member data
00107     mutable std::set<ResourcePtr<T>*> myObservers;
00108 };
00109
00110
00115 template <typename T>
00116 class ResourcePtr
00117 {
00118 public :
00119
00124     ResourcePtr();
00125
00132     ResourcePtr(const T* Resource);
00133
00140     ResourcePtr(const ResourcePtr<T>& Copy);
00141
00146     ~ResourcePtr();
00147
00156     ResourcePtr<T>& operator =(const ResourcePtr<T>& Other);
00157
00166     ResourcePtr<T>& operator =(const T* Resource);
00167
00177     operator const T*() const;
00178
00185     const T& operator *() const;
00186
00193     const T* operator ->() const;
00194
00200     void OnResourceDestroyed();
00201
00202 private :
00203
00205     // Member data
00207     const T* myResource;
00208 };
00209
00210 #include <SFML/System/Resource.inl>
00211 #include <SFML/System/ResourcePtr.inl>
00212
00213 } // namespace sf
00214
00215
00216 #endif // SFML_RESOURCE_HPP


  • File List

Resource.inl

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025
00029 template <typename T>
00030 Resource<T>::Resource()
00031 {
00032     // Nothing to do
00033 }
00034
00035
00039 template <typename T>
00040 Resource<T>::Resource(const Resource<T>&)
00041 {
00042     // Nothing to do, we don't want to copy observers
00043 }
00044
00045
00049 template <typename T>
00050 Resource<T>::~Resource()
00051 {
00052     // Notify all observers
00053     for (typename std::set<ResourcePtr<T>*>::iterator i = myObservers.begin(); i != myObservers.end(); ++i)
00054     {
00055         (*i)->OnResourceDestroyed();
00056     }
00057 }
00058
00059
00063 template <typename T>
00064 Resource<T>& Resource<T>::operator =(const Resource<T>&)
00065 {
00066     // Nothing to do, we don't want to copy observers
00067     return *this;
00068 }
00069
00070
00074 template <typename T>
00075 void Resource<T>::Connect(ResourcePtr<T>& Observer) const
00076 {
00077     myObservers.insert(&Observer);
00078 }
00079
00080
00084 template <typename T>
00085 void Resource<T>::Disconnect(ResourcePtr<T>& Observer) const
00086 {
00087     myObservers.erase(&Observer);
00088 }


  • File List

ResourcePtr.inl

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025
00029 template <typename T>
00030 ResourcePtr<T>::ResourcePtr() :
00031 myResource(NULL)
00032 {
00033
00034 }
00035
00036
00040 template <typename T>
00041 ResourcePtr<T>::ResourcePtr(const T* Resource) :
00042 myResource(Resource)
00043 {
00044     if (myResource)
00045         myResource->Connect(*this);
00046 }
00047
00048
00052 template <typename T>
00053 ResourcePtr<T>::ResourcePtr(const ResourcePtr<T>& Copy) :
00054 myResource(Copy.myResource)
00055 {
00056     if (myResource)
00057         myResource->Connect(*this);
00058 }
00059
00060
00064 template <typename T>
00065 ResourcePtr<T>::~ResourcePtr()
00066 {
00067     if (myResource)
00068         myResource->Disconnect(*this);
00069 }
00070
00071
00075 template <typename T>
00076 ResourcePtr<T>& ResourcePtr<T>::operator =(const ResourcePtr<T>& Other)
00077 {
00078     if (myResource)
00079         myResource->Disconnect(*this);
00080
00081     myResource = Other.myResource;
00082
00083     if (myResource)
00084         myResource->Connect(*this);
00085
00086     return *this;
00087 }
00088
00089
00093 template <typename T>
00094 ResourcePtr<T>& ResourcePtr<T>::operator =(const T* Resource)
00095 {
00096     if (myResource)
00097         myResource->Disconnect(*this);
00098
00099     myResource = Resource;
00100
00101     if (myResource)
00102         myResource->Connect(*this);
00103
00104     return *this;
00105 }
00106
00107
00114 template <typename T>
00115 ResourcePtr<T>::operator const T*() const
00116 {
00117     return myResource;
00118 }
00119
00120
00124 template <typename T>
00125 const T& ResourcePtr<T>::operator *() const
00126 {
00127     return *myResource;
00128 }
00129
00130
00134 template <typename T>
00135 const T* ResourcePtr<T>::operator ->() const
00136 {
00137     return myResource;
00138 }
00139
00140
00145 template <typename T>
00146 void ResourcePtr<T>::OnResourceDestroyed()
00147 {
00148     myResource = NULL;
00149 }


  • File List

Selector.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SELECTOR_HPP
00026 #define SFML_SELECTOR_HPP
00027
00029 // Headers
00031 #include <SFML/Network/SocketUDP.hpp>
00032 #include <SFML/Network/SocketTCP.hpp>
00033 #include <SFML/Network/SelectorBase.hpp>
00034 #include <map>
00035
00036
00037 namespace sf
00038 {
00043 template <typename Type>
00044 class Selector : private SelectorBase
00045 {
00046 public :
00047
00054     void Add(Type Socket);
00055
00062     void Remove(Type Socket);
00063
00068     void Clear();
00069
00080     unsigned int Wait(float Timeout = 0.f);
00081
00092     Type GetSocketReady(unsigned int Index);
00093
00094 private :
00095
00097     // Types
00099     typedef std::map<SocketHelper::SocketType, Type> SocketTable;
00100
00102     // Member data
00104     SocketTable mySockets;
00105 };
00106
00107 #include <SFML/Network/Selector.inl>
00108
00109 // Let's define the two only valid types of Selector
00110 typedef Selector<SocketUDP> SelectorUDP;
00111 typedef Selector<SocketTCP> SelectorTCP;
00112
00113 } // namespace sf
00114
00115
00116 #endif // SFML_SELECTOR_HPP


  • File List

Selector.inl

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025
00029 template <typename Type>
00030 void Selector<Type>::Add(Type Socket)
00031 {
00032     if (Socket.IsValid())
00033     {
00034         SelectorBase::Add(Socket.mySocket);
00035         mySockets[Socket.mySocket] = Socket;
00036     }
00037 }
00038
00039
00043 template <typename Type>
00044 void Selector<Type>::Remove(Type Socket)
00045 {
00046     typename SocketTable::iterator It = mySockets.find(Socket.mySocket);
00047     if (It != mySockets.end())
00048     {
00049         SelectorBase::Remove(Socket.mySocket);
00050         mySockets.erase(It);
00051     }
00052 }
00053
00054
00058 template <typename Type>
00059 void Selector<Type>::Clear()
00060 {
00061     SelectorBase::Clear();
00062     mySockets.clear();
00063 }
00064
00065
00071 template <typename Type>
00072 unsigned int Selector<Type>::Wait(float Timeout)
00073 {
00074     // No socket in the selector : return 0
00075     if (mySockets.empty())
00076         return 0;
00077
00078     return SelectorBase::Wait(Timeout);
00079 }
00080
00081
00087 template <typename Type>
00088 Type Selector<Type>::GetSocketReady(unsigned int Index)
00089 {
00090     SocketHelper::SocketType Socket = SelectorBase::GetSocketReady(Index);
00091
00092     typename SocketTable::const_iterator It = mySockets.find(Socket);
00093     if (It != mySockets.end())
00094         return It->second;
00095     else
00096         return Type(Socket);
00097 }


  • File List

SelectorBase.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifdef _MSC_VER
00026     #pragma warning(disable : 4127) // "conditional expression is constant" generated by the FD_SET macro
00027 #endif
00028
00030 // Headers
00032 #include <SFML/Network/SelectorBase.hpp>
00033
00034
00035 namespace sf
00036 {
00040 SelectorBase::SelectorBase() :
00041 myMaxSocket(0)
00042 {
00043     Clear();
00044 }
00045
00046
00050 void SelectorBase::Add(SocketHelper::SocketType Socket)
00051 {
00052     FD_SET(Socket, &mySet);
00053
00054     int Size = static_cast<int>(Socket);
00055     if (Size > myMaxSocket)
00056         myMaxSocket = Size;
00057 }
00058
00059
00063 void SelectorBase::Remove(SocketHelper::SocketType Socket)
00064 {
00065     FD_CLR(Socket, &mySet);
00066 }
00067
00068
00072 void SelectorBase::Clear()
00073 {
00074     FD_ZERO(&mySet);
00075     FD_ZERO(&mySetReady);
00076
00077     myMaxSocket = 0;
00078 }
00079
00080
00086 unsigned int SelectorBase::Wait(float Timeout)
00087 {
00088     // Setup the timeout structure
00089     timeval Time;
00090     Time.tv_sec  = static_cast<long>(Timeout);
00091     Time.tv_usec = (static_cast<long>(Timeout * 1000) % 1000) * 1000;
00092
00093     // Prepare the set of sockets to return
00094     mySetReady = mySet;
00095
00096     // Wait until one of the sockets is ready for reading, or timeout is reached
00097     int NbSockets = select(myMaxSocket + 1, &mySetReady, NULL, NULL, Timeout > 0 ? &Time : NULL);
00098
00099     return NbSockets >= 0 ? static_cast<unsigned int>(NbSockets) : 0;
00100 }
00101
00102
00108 SocketHelper::SocketType SelectorBase::GetSocketReady(unsigned int Index)
00109 {
00110     // The standard FD_xxx interface doesn't define a direct access,
00111     // so we must go through the whole set to find the socket we're looking for
00112     for (int i = 0; i < myMaxSocket + 1; ++i)
00113     {
00114         if (FD_ISSET(i, &mySetReady))
00115         {
00116             // Current socket is ready, but is it the Index-th one ?
00117             if (Index > 0)
00118             {
00119                 Index--;
00120             }
00121             else
00122             {
00123                 return static_cast<SocketHelper::SocketType>(i);
00124             }
00125         }
00126     }
00127
00128     // Invalid index : return an invalid socket
00129     return SocketHelper::InvalidSocket();
00130 }
00131
00132 } // namespace sf


  • File List

SelectorBase.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SELECTORBASE_HPP
00026 #define SFML_SELECTORBASE_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <SFML/Network/SocketHelper.hpp>
00033 #include <map>
00034
00035
00036 namespace sf
00037 {
00043 class SFML_API SelectorBase
00044 {
00045 public :
00046
00051     SelectorBase();
00052
00059     void Add(SocketHelper::SocketType Socket);
00060
00067     void Remove(SocketHelper::SocketType Socket);
00068
00073     void Clear();
00074
00085     unsigned int Wait(float Timeout = 0.f);
00086
00097     SocketHelper::SocketType GetSocketReady(unsigned int Index);
00098
00099 private :
00100
00102     // Member data
00104     fd_set mySet;
00105     fd_set mySetReady;
00106     int    myMaxSocket;
00107 };
00108
00109 } // namespace sf
00110
00111
00112 #endif // SFML_SELECTORBASE_HPP


  • File List

SFML_Main.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025
00027 // Windows specific : defines the WinMain entry function,
00028 // so that developers can use the standard main function
00029 // even in a Win32 Application project, and keep a portable code
00031
00032
00033 #if defined(_WIN32)
00034
00035     #include <windows.h>
00036
00037     extern int main(int argc, char* argv[]);
00038
00039     int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
00040     {
00041         return main(__argc, __argv);
00042     }
00043
00044 #endif // _WIN32


  • File List

Shape.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Graphics/Shape.hpp>
00029 #include <SFML/Graphics/GraphicsContext.hpp>
00030 #include <math.h>
00031
00032
00033 namespace sf
00034 {
00038 Shape::Shape() :
00039 myOutline         (0.f),
00040 myIsFillEnabled   (true),
00041 myIsOutlineEnabled(true),
00042 myIsCompiled      (false)
00043 {
00044     // Put a placeholder for the center of the shape
00045     myPoints.push_back(Point());
00046 }
00047
00048
00052 void Shape::AddPoint(float X, float Y, const Color& Col, const Color& OutlineCol)
00053 {
00054     AddPoint(Vector2f(X, Y), Col, OutlineCol);
00055 }
00056
00057
00061 void Shape::AddPoint(const Vector2f& Position, const Color& Col, const Color& OutlineCol)
00062 {
00063     myPoints.push_back(Point(Position, Col, OutlineCol));
00064     myIsCompiled = false;
00065 }
00066
00067
00071 unsigned int Shape::GetNbPoints() const
00072 {
00073     return static_cast<unsigned int>(myPoints.size() - 1);
00074 }
00075
00076
00081 void Shape::EnableFill(bool Enable)
00082 {
00083     myIsFillEnabled = Enable;
00084 }
00085
00086
00091 void Shape::EnableOutline(bool Enable)
00092 {
00093     myIsOutlineEnabled = Enable;
00094 }
00095
00096
00100 void Shape::SetPointPosition(unsigned int Index, const Vector2f& Position)
00101 {
00102     myPoints[Index + 1].Position = Position;
00103     myIsCompiled = false;
00104 }
00105
00106
00110 void Shape::SetPointPosition(unsigned int Index, float X, float Y)
00111 {
00112     SetPointPosition(Index, Vector2f(X, Y));
00113 }
00114
00115
00119 void Shape::SetPointColor(unsigned int Index, const Color& Col)
00120 {
00121     myPoints[Index + 1].Col = Col;
00122     myIsCompiled = false;
00123 }
00124
00125
00129 void Shape::SetPointOutlineColor(unsigned int Index, const Color& OutlineCol)
00130 {
00131     myPoints[Index + 1].OutlineCol = OutlineCol;
00132     myIsCompiled = false;
00133 }
00134
00135
00139 void Shape::SetOutlineWidth(float Width)
00140 {
00141     myOutline = Width;
00142 }
00143
00144
00148 const Vector2f& Shape::GetPointPosition(unsigned int Index) const
00149 {
00150     return myPoints[Index + 1].Position;
00151 }
00152
00153
00157 const Color& Shape::GetPointColor(unsigned int Index) const
00158 {
00159     return myPoints[Index + 1].Col;
00160 }
00161
00162
00166 const Color& Shape::GetPointOutlineColor(unsigned int Index) const
00167 {
00168     return myPoints[Index + 1].OutlineCol;
00169 }
00170
00171
00175 float Shape::GetOutlineWidth() const
00176 {
00177     return myOutline;
00178 }
00179
00180
00184 Shape Shape::Line(float P1X, float P1Y, float P2X, float P2Y, float Thickness, const Color& Col, float Outline, const Color& OutlineCol)
00185 {
00186     Vector2f P1(P1X, P1Y);
00187     Vector2f P2(P2X, P2Y);
00188
00189     // Compute the extrusion direction
00190     Vector2f Normal;
00191     ComputeNormal(P1, P2, Normal);
00192     Normal *= Thickness / 2;
00193
00194     // Create the shape's points
00195     Shape S;
00196     S.AddPoint(P1 - Normal, Col, OutlineCol);
00197     S.AddPoint(P2 - Normal, Col, OutlineCol);
00198     S.AddPoint(P2 + Normal, Col, OutlineCol);
00199     S.AddPoint(P1 + Normal, Col, OutlineCol);
00200     S.SetOutlineWidth(Outline);
00201
00202     // Compile it
00203     S.Compile();
00204
00205     return S;
00206 }
00207
00208
00212 Shape Shape::Line(const Vector2f& P1, const Vector2f& P2, float Thickness, const Color& Col, float Outline, const Color& OutlineCol)
00213 {
00214     return Shape::Line(P1.x, P1.y, P2.x, P2.y, Thickness, Col, Outline, OutlineCol);
00215 }
00216
00217
00221 Shape Shape::Rectangle(float P1X, float P1Y, float P2X, float P2Y, const Color& Col, float Outline, const Color& OutlineCol)
00222 {
00223     // Create the shape's points
00224     Shape S;
00225     S.AddPoint(Vector2f(P1X, P1Y), Col, OutlineCol);
00226     S.AddPoint(Vector2f(P2X, P1Y), Col, OutlineCol);
00227     S.AddPoint(Vector2f(P2X, P2Y), Col, OutlineCol);
00228     S.AddPoint(Vector2f(P1X, P2Y), Col, OutlineCol);
00229     S.SetOutlineWidth(Outline);
00230
00231     // Compile it
00232     S.Compile();
00233
00234     return S;
00235 }
00236
00237
00241 Shape Shape::Rectangle(const Vector2f& P1, const Vector2f& P2, const Color& Col, float Outline, const Color& OutlineCol)
00242 {
00243     return Shape::Rectangle(P1.x, P1.y, P2.x, P2.y, Col, Outline, OutlineCol);
00244 }
00245
00246
00250 Shape Shape::Circle(float X, float Y, float Radius, const Color& Col, float Outline, const Color& OutlineCol)
00251 {
00252     static const int NbSegments = 40;
00253
00254     // Create the points set
00255     Shape S;
00256     Vector2f Center(X, Y);
00257     for (int i = 0; i < NbSegments; ++i)
00258     {
00259         float Angle = i * 2 * 3.141592654f / NbSegments;
00260         Vector2f Offset(cos(Angle), sin(Angle));
00261
00262         S.AddPoint(Center + Offset * Radius, Col, OutlineCol);
00263     }
00264
00265     // Compile it
00266     S.SetOutlineWidth(Outline);
00267     S.Compile();
00268
00269     return S;
00270 }
00271
00272
00276 Shape Shape::Circle(const Vector2f& Center, float Radius, const Color& Col, float Outline, const Color& OutlineCol)
00277 {
00278     return Shape::Circle(Center.x, Center.y, Radius, Col, Outline, OutlineCol);
00279 }
00280
00281
00285 void Shape::Render(RenderTarget&) const
00286 {
00287     // Make sure the shape has at least 3 points (4 if we count the center)
00288     if (myPoints.size() < 4)
00289         return;
00290
00291     // Make sure the shape is compiled
00292     if (!myIsCompiled)
00293         const_cast<Shape*>(this)->Compile();
00294
00295     // Shapes only use color, no texture
00296     GLCheck(glDisable(GL_TEXTURE_2D));
00297
00298     // Draw the shape
00299     if (myIsFillEnabled)
00300     {
00301         glBegin(GL_TRIANGLE_FAN);
00302         {
00303             for (std::vector<Point>::const_iterator i = myPoints.begin(); i != myPoints.end(); ++i)
00304             {
00305                 Color PointColor = i->Col * GetColor();
00306                 glColor4f(PointColor.r / 255.f, PointColor.g / 255.f, PointColor.b / 255.f, PointColor.a / 255.f);
00307                 glVertex2f(i->Position.x, i->Position.y);
00308             }
00309
00310             // Close the shape by duplicating the first point at the end
00311             Color PointColor = myPoints[1].Col * GetColor();
00312             glColor4f(PointColor.r / 255.f, PointColor.g / 255.f, PointColor.b / 255.f, PointColor.a / 255.f);
00313             glVertex2f(myPoints[1].Position.x, myPoints[1].Position.y);
00314         }
00315         glEnd();
00316     }
00317
00318     // Draw the outline
00319     if (myIsOutlineEnabled)
00320     {
00321         glBegin(GL_TRIANGLE_STRIP);
00322         {
00323             for (std::size_t i = 1; i < myPoints.size(); ++i)
00324             {
00325                 Color PointColor = myPoints[i].OutlineCol * GetColor();
00326                 glColor4f(PointColor.r / 255.f, PointColor.g / 255.f, PointColor.b / 255.f, PointColor.a / 255.f);
00327                 glVertex2f(myPoints[i].Position.x, myPoints[i].Position.y);
00328                 glColor4f(PointColor.r / 255.f, PointColor.g / 255.f, PointColor.b / 255.f, PointColor.a / 255.f);
00329                 glVertex2f(myPoints[i].Position.x + myPoints[i].Normal.x * myOutline, myPoints[i].Position.y + myPoints[i].Normal.y * myOutline);
00330             }
00331
00332             // Close the shape by duplicating the first point at the end
00333             Color PointColor = myPoints[1].OutlineCol * GetColor();
00334             glColor4f(PointColor.r / 255.f, PointColor.g / 255.f, PointColor.b / 255.f, PointColor.a / 255.f);
00335             glVertex2f(myPoints[1].Position.x, myPoints[1].Position.y);
00336             glColor4f(PointColor.r / 255.f, PointColor.g / 255.f, PointColor.b / 255.f, PointColor.a / 255.f);
00337             glVertex2f(myPoints[1].Position.x + myPoints[1].Normal.x * myOutline, myPoints[1].Position.y + myPoints[1].Normal.y * myOutline);
00338         }
00339         glEnd();
00340     }
00341 }
00342
00343
00347 void Shape::Compile()
00348 {
00349     // Compute the center
00350     float NbPoints = static_cast<float>(myPoints.size() - 1);
00351     float R = 0, G = 0, B = 0, A = 0;
00352     Point Center(Vector2f(0, 0), Color(0, 0, 0, 0));
00353     for (std::size_t i = 1; i < myPoints.size(); ++i)
00354     {
00355         Center.Position += myPoints[i].Position / NbPoints;
00356         R += myPoints[i].Col.r / NbPoints;
00357         G += myPoints[i].Col.g / NbPoints;
00358         B += myPoints[i].Col.b / NbPoints;
00359         A += myPoints[i].Col.a / NbPoints;
00360     }
00361     Center.Col.r = static_cast<Uint8>(R);
00362     Center.Col.g = static_cast<Uint8>(G);
00363     Center.Col.b = static_cast<Uint8>(B);
00364     Center.Col.a = static_cast<Uint8>(A);
00365     myPoints[0] = Center;
00366
00367     // Compute the outline
00368     for (std::size_t i = 1; i < myPoints.size(); ++i)
00369     {
00370         // Get the two segments shared by the current point
00371         Point& P0 = (i == 1) ? myPoints[myPoints.size() - 1] : myPoints[i - 1];
00372         Point& P1 = myPoints[i];
00373         Point& P2 = (i == myPoints.size() - 1) ? myPoints[1] : myPoints[i + 1];
00374
00375         // Compute their normal
00376         Vector2f Normal1, Normal2;
00377         if (!ComputeNormal(P0.Position, P1.Position, Normal1) || !ComputeNormal(P1.Position, P2.Position, Normal2))
00378             continue;
00379
00380         // Add them to get the extrusion direction
00381         float Factor = 1.f + (Normal1.x * Normal2.x + Normal1.y * Normal2.y);
00382         P1.Normal = (Normal1 + Normal2) / Factor;
00383
00384         // Make sure it points towards the outside of the shape
00385         float Dot = (P1.Position.x - Center.Position.x) * P1.Normal.x + (P1.Position.y - Center.Position.y) * P1.Normal.y;
00386         if (Dot < 0)
00387             P1.Normal = -P1.Normal;
00388     }
00389
00390     myIsCompiled = true;
00391 }
00392
00393
00397 bool Shape::ComputeNormal(const Vector2f& P1, const Vector2f& P2, Vector2f& Normal)
00398 {
00399     Normal.x = P1.y - P2.y;
00400     Normal.y = P2.x - P1.x;
00401
00402     float Len = sqrt(Normal.x * Normal.x + Normal.y * Normal.y);
00403     if (Len == 0.f)
00404         return false;
00405
00406     Normal.x /= Len;
00407     Normal.y /= Len;
00408
00409     return true;
00410 }
00411
00412
00416 Shape::Point::Point(const Vector2f& Pos, const Color& C, const Color& OutlineC) :
00417 Position  (Pos),
00418 Normal    (0.f, 0.f),
00419 Col       (C),
00420 OutlineCol(OutlineC)
00421 {
00422
00423 }
00424
00425 } // namespace sf


  • File List

Shape.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SHAPE_HPP
00026 #define SFML_SHAPE_HPP
00027
00029 // Headers
00031 #include <SFML/Graphics/Drawable.hpp>
00032 #include <SFML/System/Vector2.hpp>
00033 #include <vector>
00034
00035
00036 namespace sf
00037 {
00043 class SFML_API Shape : public sf::Drawable
00044 {
00045 public :
00046
00051     Shape();
00052
00061     void AddPoint(float X, float Y, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0));
00062
00071     void AddPoint(const Vector2f& Position, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0));
00072
00079     unsigned int GetNbPoints() const;
00080
00088     void EnableFill(bool Enable);
00089
00097     void EnableOutline(bool Enable);
00098
00106     void SetPointPosition(unsigned int Index, const Vector2f& Position);
00107
00116     void SetPointPosition(unsigned int Index, float X, float Y);
00117
00125     void SetPointColor(unsigned int Index, const Color& Col);
00126
00134     void SetPointOutlineColor(unsigned int Index, const Color& OutlineCol);
00135
00142     void SetOutlineWidth(float Width);
00143
00152     const Vector2f& GetPointPosition(unsigned int Index) const;
00153
00162     const Color& GetPointColor(unsigned int Index) const;
00163
00172     const Color& GetPointOutlineColor(unsigned int Index) const;
00173
00180     float GetOutlineWidth() const;
00181
00193     static Shape Line(float P1X, float P1Y, float P2X, float P2Y, float Thickness, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
00194
00206     static Shape Line(const Vector2f& P1, const Vector2f& P2, float Thickness, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
00207
00218     static Shape Rectangle(float P1X, float P1Y, float P2X, float P2Y, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
00219
00230     static Shape Rectangle(const Vector2f& P1, const Vector2f& P2, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
00231
00242     static Shape Circle(float X, float Y, float Radius, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
00243
00254     static Shape Circle(const Vector2f& Center, float Radius, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
00255
00256 protected :
00257
00262     virtual void Render(RenderTarget& Target) const;
00263
00264 private :
00265
00270     void Compile();
00271
00282     static bool ComputeNormal(const Vector2f& P1, const Vector2f& P2, Vector2f& Normal);
00283
00287     struct Point
00288     {
00289         Point(const Vector2f& Pos = Vector2f(0, 0), const Color& C = Color(255, 255, 255), const Color& OutlineC = Color(255, 255, 255));
00290
00291         Vector2f Position;
00292         Vector2f Normal;
00293         Color    Col;
00294         Color    OutlineCol;
00295     };
00296
00298     // Member data
00300     std::vector<Point> myPoints;
00301     float              myOutline;
00302     bool               myIsFillEnabled;
00303     bool               myIsOutlineEnabled;
00304     bool               myIsCompiled;
00305 };
00306
00307 } // namespace sf
00308
00309
00310 #endif // SFML_SHAPE_HPP


  • File List

Sleep.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/System/Sleep.hpp>
00029 #include <SFML/System/Platform.hpp>
00030
00031
00032 namespace sf
00033 {
00037 void Sleep(float Duration)
00038 {
00039     if (Duration >= 0)
00040         priv::Platform::Sleep(Duration);
00041 }
00042
00043 } // namespace sf


  • File List

Sleep.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SLEEP_HPP
00026 #define SFML_SLEEP_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 namespace sf
00035 {
00042     void SFML_API Sleep(float Duration);
00043
00044 } // namespace sf
00045
00046
00047 #endif // SFML_SLEEP_HPP


  • File List

SocketHelper.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Network/SocketHelper.hpp>
00029
00030
00031 namespace sf
00032 {
00036 SocketHelper::SocketType SocketHelper::InvalidSocket()
00037 {
00038     return INVALID_SOCKET;
00039 }
00040
00041
00045 bool SocketHelper::Close(SocketHelper::SocketType Socket)
00046 {
00047     return closesocket(Socket) != -1;
00048 }
00049
00050
00054 void SocketHelper::SetBlocking(SocketHelper::SocketType Socket, bool Block)
00055 {
00056     unsigned long Blocking = Block ? 0 : 1;
00057     ioctlsocket(Socket, FIONBIO, &Blocking);
00058 }
00059
00060
00064 Socket::Status SocketHelper::GetErrorStatus()
00065 {
00066     switch (WSAGetLastError())
00067     {
00068         case WSAEWOULDBLOCK :  return Socket::NotReady;
00069         case WSAECONNABORTED : return Socket::Disconnected;
00070         case WSAECONNRESET :   return Socket::Disconnected;
00071         case WSAETIMEDOUT :    return Socket::Disconnected;
00072         case WSAENETRESET :    return Socket::Disconnected;
00073         case WSAENOTCONN :     return Socket::Disconnected;
00074         default :              return Socket::Error;
00075     }
00076 }
00077
00078
00080 // Windows needs some initialization and cleanup to get
00081 // sockets working properly... so let's create a class that will
00082 // do it automatically
00084 struct SocketInitializer
00085 {
00086     SocketInitializer()
00087     {
00088         WSADATA InitData;
00089         WSAStartup(MAKEWORD(2,2), &InitData);
00090     }
00091
00092     ~SocketInitializer()
00093     {
00094         WSACleanup();
00095     }
00096 };
00097
00098 SocketInitializer GlobalInitializer;
00099
00100 } // namespace sf


  • File List

SocketHelper.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SOCKETHELPER_HPP
00026 #define SFML_SOCKETHELPER_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 namespace sf
00035 {
00036 namespace Socket
00037 {
00041     enum Status
00042     {
00043         Done,
00044         NotReady,
00045         Disconnected,
00046         Error
00047     };
00048 }
00049
00050 } // namespace sf
00051
00052
00053 #ifdef SFML_SYSTEM_WINDOWS
00054
00055     #include <SFML/Network/Win32/SocketHelper.hpp>
00056
00057 #else
00058
00059     #include <SFML/Network/Unix/SocketHelper.hpp>
00060
00061 #endif
00062
00063
00064 #endif // SFML_SOCKETHELPER_HPP


  • File List

Sockets.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SOCKETS_HPP
00026 #define SFML_SOCKETS_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 #ifdef SFML_SYSTEM_WINDOWS
00035
00036     #include <SFML/Network/Win32/Sockets.hpp>
00037
00038 #else
00039
00040     #include <SFML/Network/Unix/Sockets.hpp>
00041
00042 #endif
00043
00044
00045 #endif // SFML_SOCKETS_HPP


  • File List

SocketTCP.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Network/SocketTCP.hpp>
00029 #include <SFML/Network/IPAddress.hpp>
00030 #include <SFML/Network/Packet.hpp>
00031 #include <SFML/Network/SocketHelper.hpp>
00032 #include <algorithm>
00033 #include <iostream>
00034 #include <string.h>
00035
00036
00037 #ifdef _MSC_VER
00038     #pragma warning(disable : 4127) // "conditional expression is constant" generated by the FD_SET macro
00039 #endif
00040
00041
00042 namespace sf
00043 {
00047 SocketTCP::SocketTCP()
00048 {
00049     Create(SocketHelper::InvalidSocket());
00050 }
00051
00052
00056 void SocketTCP::SetBlocking(bool Blocking)
00057 {
00058     // Make sure our socket is valid
00059     if (!IsValid())
00060         Create();
00061
00062     SocketHelper::SetBlocking(mySocket, Blocking);
00063     myIsBlocking = Blocking;
00064 }
00065
00066
00070 Socket::Status SocketTCP::Connect(unsigned short Port, const IPAddress& HostAddress, float Timeout)
00071 {
00072     // Make sure our socket is valid
00073     if (!IsValid())
00074         Create();
00075
00076     // Build the host address
00077     sockaddr_in SockAddr;
00078     memset(SockAddr.sin_zero, 0, sizeof(SockAddr.sin_zero));
00079     SockAddr.sin_addr.s_addr = inet_addr(HostAddress.ToString().c_str());
00080     SockAddr.sin_family      = AF_INET;
00081     SockAddr.sin_port        = htons(Port);
00082
00083     if (Timeout <= 0)
00084     {
00085         // ----- We're not using a timeout : just try to connect -----
00086
00087         if (connect(mySocket, reinterpret_cast<sockaddr*>(&SockAddr), sizeof(SockAddr)) == -1)
00088         {
00089             // Failed to connect
00090             return SocketHelper::GetErrorStatus();
00091         }
00092
00093         // Connection succeeded
00094         return Socket::Done;
00095     }
00096     else
00097     {
00098         // ----- We're using a timeout : we'll need a few tricks to make it work -----
00099
00100         // Save the previous blocking state
00101         bool IsBlocking = myIsBlocking;
00102
00103         // Switch to non-blocking to enable our connection timeout
00104         if (IsBlocking)
00105             SetBlocking(false);
00106
00107         // Try to connect to host
00108         if (connect(mySocket, reinterpret_cast<sockaddr*>(&SockAddr), sizeof(SockAddr)) >= 0)
00109         {
00110             // We got instantly connected! (it may no happen a lot...)
00111             return Socket::Done;
00112         }
00113
00114         // Get the error status
00115         Socket::Status Status = SocketHelper::GetErrorStatus();
00116
00117         // If we were in non-blocking mode, return immediatly
00118         if (!IsBlocking)
00119             return Status;
00120
00121         // Otherwise, wait until something happens to our socket (success, timeout or error)
00122         if (Status == Socket::NotReady)
00123         {
00124             // Setup the selector
00125             fd_set Selector;
00126             FD_ZERO(&Selector);
00127             FD_SET(mySocket, &Selector);
00128
00129             // Setup the timeout
00130             timeval Time;
00131             Time.tv_sec  = static_cast<long>(Timeout);
00132             Time.tv_usec = (static_cast<long>(Timeout * 1000) % 1000) * 1000;
00133
00134             // Wait for something to write on our socket (which means that the connection request has returned)
00135             if (select(static_cast<int>(mySocket + 1), NULL, &Selector, NULL, &Time) > 0)
00136             {
00137                 // At this point the connection may have been either accepted or refused.
00138                 // To know whether it's a success or a failure, we try to retrieve the name of the connected peer
00139                 SocketHelper::LengthType Size = sizeof(SockAddr);
00140                 if (getpeername(mySocket, reinterpret_cast<sockaddr*>(&SockAddr), &Size) != -1)
00141                 {
00142                     // Connection accepted
00143                     Status = Socket::Done;
00144                 }
00145                 else
00146                 {
00147                     // Connection failed
00148                     Status = SocketHelper::GetErrorStatus();
00149                 }
00150             }
00151             else
00152             {
00153                 // Failed to connect before timeout is over
00154                 Status = SocketHelper::GetErrorStatus();
00155             }
00156         }
00157
00158         // Switch back to blocking mode
00159         SetBlocking(true);
00160
00161         return Status;
00162     }
00163 }
00164
00165
00169 bool SocketTCP::Listen(unsigned short Port)
00170 {
00171     // Make sure our socket is valid
00172     if (!IsValid())
00173         Create();
00174
00175     // Build the address
00176     sockaddr_in SockAddr;
00177     memset(SockAddr.sin_zero, 0, sizeof(SockAddr.sin_zero));
00178     SockAddr.sin_addr.s_addr = htonl(INADDR_ANY);
00179     SockAddr.sin_family      = AF_INET;
00180     SockAddr.sin_port        = htons(Port);
00181
00182     // Bind the socket to the specified port
00183     if (bind(mySocket, reinterpret_cast<sockaddr*>(&SockAddr), sizeof(SockAddr)) == -1)
00184     {
00185         // Not likely to happen, but...
00186         std::cerr << "Failed to bind socket to port " << Port << std::endl;
00187         return false;
00188     }
00189
00190     // Listen to the bound port
00191     if (listen(mySocket, 0) == -1)
00192     {
00193         // Oops, socket is deaf
00194         std::cerr << "Failed to listen to port " << Port << std::endl;
00195         return false;
00196     }
00197
00198     return true;
00199 }
00200
00201
00206 Socket::Status SocketTCP::Accept(SocketTCP& Connected, IPAddress* Address)
00207 {
00208     // Address that will be filled with client informations
00209     sockaddr_in ClientAddress;
00210     SocketHelper::LengthType Length = sizeof(ClientAddress);
00211
00212     // Accept a new connection
00213     Connected = accept(mySocket, reinterpret_cast<sockaddr*>(&ClientAddress), &Length);
00214
00215     // Check errors
00216     if (!Connected.IsValid())
00217     {
00218         if (Address)
00219             *Address = IPAddress();
00220
00221         return SocketHelper::GetErrorStatus();
00222     }
00223
00224     // Fill address if requested
00225     if (Address)
00226         *Address = IPAddress(inet_ntoa(ClientAddress.sin_addr));
00227
00228     return Socket::Done;
00229 }
00230
00231
00235 Socket::Status SocketTCP::Send(const char* Data, std::size_t Size)
00236 {
00237     // First check that socket is valid
00238     if (!IsValid())
00239         return Socket::Error;
00240
00241     // Check parameters
00242     if (Data && Size)
00243     {
00244         // Loop until every byte has been sent
00245         int Sent = 0;
00246         int SizeToSend = static_cast<int>(Size);
00247         for (int Length = 0; Length < SizeToSend; Length += Sent)
00248         {
00249             // Send a chunk of data
00250             Sent = send(mySocket, Data + Length, SizeToSend - Length, 0);
00251
00252             // Check if an error occured
00253             if (Sent <= 0)
00254                 return SocketHelper::GetErrorStatus();
00255         }
00256
00257         return Socket::Done;
00258     }
00259     else
00260     {
00261         // Error...
00262         std::cerr << "Cannot send data over the network (invalid parameters)" << std::endl;
00263         return Socket::Error;
00264     }
00265 }
00266
00267
00272 Socket::Status SocketTCP::Receive(char* Data, std::size_t MaxSize, std::size_t& SizeReceived)
00273 {
00274     // First clear the size received
00275     SizeReceived = 0;
00276
00277     // Check that socket is valid
00278     if (!IsValid())
00279         return Socket::Error;
00280
00281     // Check parameters
00282     if (Data && MaxSize)
00283     {
00284         // Receive a chunk of bytes
00285         int Received = recv(mySocket, Data, static_cast<int>(MaxSize), 0);
00286
00287         // Check the number of bytes received
00288         if (Received > 0)
00289         {
00290             SizeReceived = static_cast<std::size_t>(Received);
00291             return Socket::Done;
00292         }
00293         else if (Received == 0)
00294         {
00295             return Socket::Disconnected;
00296         }
00297         else
00298         {
00299             return SocketHelper::GetErrorStatus();
00300         }
00301     }
00302     else
00303     {
00304         // Error...
00305         std::cerr << "Cannot receive data from the network (invalid parameters)" << std::endl;
00306         return Socket::Error;
00307     }
00308 }
00309
00310
00314 Socket::Status SocketTCP::Send(Packet& PacketToSend)
00315 {
00316     // Get the data to send from the packet
00317     std::size_t DataSize = 0;
00318     const char* Data = PacketToSend.OnSend(DataSize);
00319
00320     // Send the packet size
00321     Uint32 PacketSize = htonl(static_cast<unsigned long>(DataSize));
00322     Send(reinterpret_cast<const char*>(&PacketSize), sizeof(PacketSize));
00323
00324     // Send the packet data
00325     if (PacketSize > 0)
00326     {
00327         return Send(Data, DataSize);
00328     }
00329     else
00330     {
00331         return Socket::Done;
00332     }
00333 }
00334
00335
00340 Socket::Status SocketTCP::Receive(Packet& PacketToReceive)
00341 {
00342     // We start by getting the size of the incoming packet
00343     Uint32      PacketSize = 0;
00344     std::size_t Received   = 0;
00345     if (myPendingPacketSize < 0)
00346     {
00347         // Loop until we've received the entire size of the packet
00348         // (even a 4 bytes variable may be received in more than one call)
00349         while (myPendingHeaderSize < sizeof(myPendingHeader))
00350         {
00351             char* Data = reinterpret_cast<char*>(&myPendingHeader) + myPendingHeaderSize;
00352             Socket::Status Status = Receive(Data, sizeof(myPendingHeader) - myPendingHeaderSize, Received);
00353             myPendingHeaderSize += Received;
00354
00355             if (Status != Socket::Done)
00356                 return Status;
00357         }
00358
00359         PacketSize = ntohl(myPendingHeader);
00360         myPendingHeaderSize = 0;
00361     }
00362     else
00363     {
00364         // There is a pending packet : we already know its size
00365         PacketSize = myPendingPacketSize;
00366     }
00367
00368     // Then loop until we receive all the packet data
00369     char Buffer[1024];
00370     while (myPendingPacket.size() < PacketSize)
00371     {
00372         // Receive a chunk of data
00373         std::size_t SizeToGet = std::min(static_cast<std::size_t>(PacketSize - myPendingPacket.size()), sizeof(Buffer));
00374         Socket::Status Status = Receive(Buffer, SizeToGet, Received);
00375         if (Status != Socket::Done)
00376         {
00377             // We must save the size of the pending packet until we can receive its content
00378             if (Status == Socket::NotReady)
00379                 myPendingPacketSize = PacketSize;
00380             return Status;
00381         }
00382
00383         // Append it into the packet
00384         if (Received > 0)
00385         {
00386             myPendingPacket.resize(myPendingPacket.size() + Received);
00387             char* Begin = &myPendingPacket[0] + myPendingPacket.size() - Received;
00388             memcpy(Begin, Buffer, Received);
00389         }
00390     }
00391
00392     // We have received all the datas : we can copy it to the user packet, and clear our internal packet
00393     PacketToReceive.Clear();
00394     if (!myPendingPacket.empty())
00395         PacketToReceive.OnReceive(&myPendingPacket[0], myPendingPacket.size());
00396     myPendingPacket.clear();
00397     myPendingPacketSize = -1;
00398
00399     return Socket::Done;
00400 }
00401
00402
00406 bool SocketTCP::Close()
00407 {
00408     if (IsValid())
00409     {
00410         if (!SocketHelper::Close(mySocket))
00411         {
00412             std::cerr << "Failed to close socket" << std::endl;
00413             return false;
00414         }
00415
00416         mySocket = SocketHelper::InvalidSocket();
00417     }
00418
00419     myIsBlocking = true;
00420
00421     return true;
00422 }
00423
00424
00429 bool SocketTCP::IsValid() const
00430 {
00431     return mySocket != SocketHelper::InvalidSocket();
00432 }
00433
00434
00438 bool SocketTCP::operator ==(const SocketTCP& Other) const
00439 {
00440     return mySocket == Other.mySocket;
00441 }
00442
00443
00447 bool SocketTCP::operator !=(const SocketTCP& Other) const
00448 {
00449     return mySocket != Other.mySocket;
00450 }
00451
00452
00458 bool SocketTCP::operator <(const SocketTCP& Other) const
00459 {
00460     return mySocket < Other.mySocket;
00461 }
00462
00463
00468 SocketTCP::SocketTCP(SocketHelper::SocketType Descriptor)
00469 {
00470     Create(Descriptor);
00471 }
00472
00473
00477 void SocketTCP::Create(SocketHelper::SocketType Descriptor)
00478 {
00479     // Use the given socket descriptor, or get a new one
00480     mySocket = Descriptor ? Descriptor : socket(PF_INET, SOCK_STREAM, 0);
00481     myIsBlocking = true;
00482
00483     // Reset the pending packet
00484     myPendingHeaderSize = 0;
00485     myPendingPacket.clear();
00486     myPendingPacketSize = -1;
00487
00488     // Setup default options
00489     if (IsValid())
00490     {
00491         // To avoid the "Address already in use" error message when trying to bind to the same port
00492         int Yes = 1;
00493         if (setsockopt(mySocket, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&Yes), sizeof(Yes)) == -1)
00494         {
00495             std::cerr << "Failed to set socket option \"SO_REUSEADDR\" ; "
00496                       << "binding to a same port may fail if too fast" << std::endl;
00497         }
00498
00499         // Disable the Nagle algorithm (ie. removes buffering of TCP packets)
00500         if (setsockopt(mySocket, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>(&Yes), sizeof(Yes)) == -1)
00501         {
00502             std::cerr << "Failed to set socket option \"TCP_NODELAY\" ; "
00503                       << "all your TCP packets will be buffered" << std::endl;
00504         }
00505
00506         // Set blocking by default (should always be the case anyway)
00507         SetBlocking(true);
00508     }
00509 }
00510
00511 } // namespace sf


  • File List

SocketTCP.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SOCKETTCP_HPP
00026 #define SFML_SOCKETTCP_HPP
00027
00029 // Headers
00031 #include <SFML/Network/SocketHelper.hpp>
00032 #include <vector>
00033
00034
00035 namespace sf
00036 {
00037 class Packet;
00038 class IPAddress;
00039 template <typename> class Selector;
00040
00045 class SFML_API SocketTCP
00046 {
00047 public :
00048
00053     SocketTCP();
00054
00062     void SetBlocking(bool Blocking);
00063
00074     Socket::Status Connect(unsigned short Port, const IPAddress& HostAddress, float Timeout = 0.f);
00075
00084     bool Listen(unsigned short Port);
00085
00096     Socket::Status Accept(SocketTCP& Connected, IPAddress* Address = NULL);
00097
00107     Socket::Status Send(const char* Data, std::size_t Size);
00108
00120     Socket::Status Receive(char* Data, std::size_t MaxSize, std::size_t& SizeReceived);
00121
00130     Socket::Status Send(Packet& PacketToSend);
00131
00141     Socket::Status Receive(Packet& PacketToReceive);
00142
00149     bool Close();
00150
00158     bool IsValid() const;
00159
00168     bool operator ==(const SocketTCP& Other) const;
00169
00178     bool operator !=(const SocketTCP& Other) const;
00179
00190     bool operator <(const SocketTCP& Other) const;
00191
00192 private :
00193
00194     friend class Selector<SocketTCP>;
00195
00203     SocketTCP(SocketHelper::SocketType Descriptor);
00204
00211     void Create(SocketHelper::SocketType Descriptor = 0);
00212
00214     // Member data
00216     SocketHelper::SocketType mySocket;
00217     Uint32                   myPendingHeader;
00218     Uint32                   myPendingHeaderSize;
00219     std::vector<char>        myPendingPacket;
00220     Int32                    myPendingPacketSize;
00221     bool                     myIsBlocking;
00222 };
00223
00224 } // namespace sf
00225
00226
00227 #endif // SFML_SOCKETTCP_HPP


  • File List

SocketUDP.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Network/SocketUDP.hpp>
00029 #include <SFML/Network/IPAddress.hpp>
00030 #include <SFML/Network/Packet.hpp>
00031 #include <algorithm>
00032 #include <iostream>
00033 #include <string.h>
00034
00035
00036 namespace sf
00037 {
00041 SocketUDP::SocketUDP()
00042 {
00043     Create();
00044 }
00045
00046
00050 void SocketUDP::SetBlocking(bool Blocking)
00051 {
00052     // Make sure our socket is valid
00053     if (!IsValid())
00054         Create();
00055
00056     SocketHelper::SetBlocking(mySocket, Blocking);
00057     myIsBlocking = Blocking;
00058 }
00059
00060
00064 bool SocketUDP::Bind(unsigned short Port)
00065 {
00066     // Check if the socket is already bound to the specified port
00067     if (myPort != Port)
00068     {
00069         // If the socket was previously bound to another port, we need to unbind it first
00070         Unbind();
00071
00072         if (Port != 0)
00073         {
00074             // Build an address with the specified port
00075             sockaddr_in Addr;
00076             Addr.sin_family      = AF_INET;
00077             Addr.sin_port        = htons(Port);
00078             Addr.sin_addr.s_addr = INADDR_ANY;
00079             memset(Addr.sin_zero, 0, sizeof(Addr.sin_zero));
00080
00081             // Bind the socket to the port
00082             if (bind(mySocket, reinterpret_cast<sockaddr*>(&Addr), sizeof(Addr)) == -1)
00083             {
00084                 std::cerr << "Failed to bind the socket to port " << Port << std::endl;
00085                 myPort = 0;
00086                 return false;
00087             }
00088         }
00089
00090         // Save the new port
00091         myPort = Port;
00092     }
00093
00094     return true;
00095 }
00096
00097
00101 bool SocketUDP::Unbind()
00102 {
00103     // To unbind the socket, we just recreate it
00104     if (myPort != 0)
00105     {
00106         Close();
00107         Create();
00108         myPort = 0;
00109     }
00110
00111     return true;
00112 }
00113
00114
00118 Socket::Status SocketUDP::Send(const char* Data, std::size_t Size, const IPAddress& Address, unsigned short Port)
00119 {
00120     // Make sure the socket is valid
00121     if (!IsValid())
00122         Create();
00123
00124     // Check parameters
00125     if (Data && Size)
00126     {
00127         // Build the target address
00128         sockaddr_in Target;
00129         Target.sin_family      = AF_INET;
00130         Target.sin_port        = htons(Port);
00131         Target.sin_addr.s_addr = inet_addr(Address.ToString().c_str());
00132         memset(Target.sin_zero, 0, sizeof(Target.sin_zero));
00133
00134         // Loop until every byte has been sent
00135         int Sent = 0;
00136         int SizeToSend = static_cast<int>(Size);
00137         for (int Length = 0; Length < SizeToSend; Length += Sent)
00138         {
00139             // Send a chunk of data
00140             Sent = sendto(mySocket, Data + Length, SizeToSend - Length, 0, reinterpret_cast<sockaddr*>(&Target), sizeof(Target));
00141
00142             // Check errors
00143             if (Sent <= 0)
00144                 return SocketHelper::GetErrorStatus();
00145         }
00146
00147         return Socket::Done;
00148     }
00149     else
00150     {
00151         // Error...
00152         std::cerr << "Cannot send data over the network (invalid parameters)" << std::endl;
00153         return Socket::Error;
00154     }
00155 }
00156
00157
00162 Socket::Status SocketUDP::Receive(char* Data, std::size_t MaxSize, std::size_t& SizeReceived, IPAddress& Address, unsigned short& Port)
00163 {
00164     // First clear the size received
00165     SizeReceived = 0;
00166
00167     // Make sure the socket is bound to a port
00168     if (myPort == 0)
00169     {
00170         std::cerr << "Failed to receive data ; the UDP socket first needs to be bound to a port" << std::endl;
00171         return Socket::Error;
00172     }
00173
00174     // Make sure the socket is valid
00175     if (!IsValid())
00176         Create();
00177
00178     // Check parameters
00179     if (Data && MaxSize)
00180     {
00181         // Data that will be filled with the other computer's address
00182         sockaddr_in Sender;
00183         Sender.sin_family      = AF_INET;
00184         Sender.sin_port        = 0;
00185         Sender.sin_addr.s_addr = INADDR_ANY;
00186         memset(Sender.sin_zero, 0, sizeof(Sender.sin_zero));
00187         SocketHelper::LengthType SenderSize = sizeof(Sender);
00188
00189         // Receive a chunk of bytes
00190         int Received = recvfrom(mySocket, Data, static_cast<int>(MaxSize), 0, reinterpret_cast<sockaddr*>(&Sender), &SenderSize);
00191
00192         // Check the number of bytes received
00193         if (Received > 0)
00194         {
00195             Address = IPAddress(inet_ntoa(Sender.sin_addr));
00196             Port = ntohs(Sender.sin_port);
00197             SizeReceived = static_cast<std::size_t>(Received);
00198             return Socket::Done;
00199         }
00200         else
00201         {
00202             Address = IPAddress();
00203             Port = 0;
00204             return Received == 0 ? Socket::Disconnected : SocketHelper::GetErrorStatus();
00205         }
00206     }
00207     else
00208     {
00209         // Error...
00210         std::cerr << "Cannot receive data from the network (invalid parameters)" << std::endl;
00211         return Socket::Error;
00212     }
00213 }
00214
00215
00219 Socket::Status SocketUDP::Send(Packet& PacketToSend, const IPAddress& Address, unsigned short Port)
00220 {
00221     // Get the data to send from the packet
00222     std::size_t DataSize = 0;
00223     const char* Data = PacketToSend.OnSend(DataSize);
00224
00225     // Send the packet size
00226     Uint32 PacketSize = htonl(static_cast<unsigned long>(DataSize));
00227     Send(reinterpret_cast<const char*>(&PacketSize), sizeof(PacketSize), Address, Port);
00228
00229     // Send the packet data
00230     if (PacketSize > 0)
00231     {
00232         return Send(Data, DataSize, Address, Port);
00233     }
00234     else
00235     {
00236         return Socket::Done;
00237     }
00238 }
00239
00240
00245 Socket::Status SocketUDP::Receive(Packet& PacketToReceive, IPAddress& Address, unsigned short& Port)
00246 {
00247     // We start by getting the size of the incoming packet
00248     Uint32      PacketSize = 0;
00249     std::size_t Received   = 0;
00250     if (myPendingPacketSize < 0)
00251     {
00252         // Loop until we've received the entire size of the packet
00253         // (even a 4 bytes variable may be received in more than one call)
00254         while (myPendingHeaderSize < sizeof(myPendingHeader))
00255         {
00256             char* Data = reinterpret_cast<char*>(&myPendingHeader) + myPendingHeaderSize;
00257             Socket::Status Status = Receive(Data, sizeof(myPendingHeader) - myPendingHeaderSize, Received, Address, Port);
00258             myPendingHeaderSize += Received;
00259
00260             if (Status != Socket::Done)
00261                 return Status;
00262         }
00263
00264         PacketSize = ntohl(myPendingHeader);
00265         myPendingHeaderSize = 0;
00266     }
00267     else
00268     {
00269         // There is a pending packet : we already know its size
00270         PacketSize = myPendingPacketSize;
00271     }
00272
00273     // Use another address instance for receiving the packet data ;
00274     // chunks of data coming from a different sender will be discarded (and lost...)
00275     IPAddress Sender;
00276     unsigned short SenderPort;
00277
00278     // Then loop until we receive all the packet data
00279     char Buffer[1024];
00280     while (myPendingPacket.size() < PacketSize)
00281     {
00282         // Receive a chunk of data
00283         std::size_t SizeToGet = std::min(static_cast<std::size_t>(PacketSize - myPendingPacket.size()), sizeof(Buffer));
00284         Socket::Status Status = Receive(Buffer, SizeToGet, Received, Sender, SenderPort);
00285         if (Status != Socket::Done)
00286         {
00287             // We must save the size of the pending packet until we can receive its content
00288             if (Status == Socket::NotReady)
00289                 myPendingPacketSize = PacketSize;
00290             return Status;
00291         }
00292
00293         // Append it into the packet
00294         if ((Sender == Address) && (SenderPort == Port) && (Received > 0))
00295         {
00296             myPendingPacket.resize(myPendingPacket.size() + Received);
00297             char* Begin = &myPendingPacket[0] + myPendingPacket.size() - Received;
00298             memcpy(Begin, Buffer, Received);
00299         }
00300     }
00301
00302     // We have received all the datas : we can copy it to the user packet, and clear our internal packet
00303     PacketToReceive.Clear();
00304     if (!myPendingPacket.empty())
00305         PacketToReceive.OnReceive(&myPendingPacket[0], myPendingPacket.size());
00306     myPendingPacket.clear();
00307     myPendingPacketSize = -1;
00308
00309     return Socket::Done;
00310 }
00311
00312
00316 bool SocketUDP::Close()
00317 {
00318     if (IsValid())
00319     {
00320         if (!SocketHelper::Close(mySocket))
00321         {
00322             std::cerr << "Failed to close socket" << std::endl;
00323             return false;
00324         }
00325
00326         mySocket = SocketHelper::InvalidSocket();
00327     }
00328
00329     myPort       = 0;
00330     myIsBlocking = true;
00331
00332     return true;
00333 }
00334
00335
00340 bool SocketUDP::IsValid() const
00341 {
00342     return mySocket != SocketHelper::InvalidSocket();
00343 }
00344
00345
00349 unsigned short SocketUDP::GetPort() const
00350 {
00351     return myPort;
00352 }
00353
00354
00358 bool SocketUDP::operator ==(const SocketUDP& Other) const
00359 {
00360     return mySocket == Other.mySocket;
00361 }
00362
00363
00367 bool SocketUDP::operator !=(const SocketUDP& Other) const
00368 {
00369     return mySocket != Other.mySocket;
00370 }
00371
00372
00378 bool SocketUDP::operator <(const SocketUDP& Other) const
00379 {
00380     return mySocket < Other.mySocket;
00381 }
00382
00383
00388 SocketUDP::SocketUDP(SocketHelper::SocketType Descriptor)
00389 {
00390     Create(Descriptor);
00391 }
00392
00393
00397 void SocketUDP::Create(SocketHelper::SocketType Descriptor)
00398 {
00399     // Use the given socket descriptor, or get a new one
00400     mySocket = Descriptor ? Descriptor : socket(PF_INET, SOCK_DGRAM, 0);
00401     myIsBlocking = true;
00402
00403     // Clear the last port used
00404     myPort = 0;
00405
00406     // Reset the pending packet
00407     myPendingHeaderSize = 0;
00408     myPendingPacket.clear();
00409     myPendingPacketSize = -1;
00410
00411     // Setup default options
00412     if (IsValid())
00413     {
00414         // To avoid the "Address already in use" error message when trying to bind to the same port
00415         int Yes = 1;
00416         if (setsockopt(mySocket, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&Yes), sizeof(Yes)) == -1)
00417         {
00418             std::cerr << "Failed to set socket option \"reuse address\" ; "
00419                       << "binding to a same port may fail if too fast" << std::endl;
00420         }
00421
00422         // Enable broadcast by default
00423         if (setsockopt(mySocket, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<char*>(&Yes), sizeof(Yes)) == -1)
00424         {
00425             std::cerr << "Failed to enable broadcast on UDP socket" << std::endl;
00426         }
00427
00428         // Set blocking by default (should always be the case anyway)
00429         SetBlocking(true);
00430     }
00431 }
00432
00433 } // namespace sf


  • File List

SocketUDP.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SOCKETUDP_HPP
00026 #define SFML_SOCKETUDP_HPP
00027
00029 // Headers
00031 #include <SFML/Network/SocketHelper.hpp>
00032 #include <vector>
00033
00034
00035 namespace sf
00036 {
00037 class Packet;
00038 class IPAddress;
00039 template <typename> class Selector;
00040
00045 class SFML_API SocketUDP
00046 {
00047 public :
00048
00053     SocketUDP();
00054
00062     void SetBlocking(bool Blocking);
00063
00072     bool Bind(unsigned short Port);
00073
00080     bool Unbind();
00081
00093     Socket::Status Send(const char* Data, std::size_t Size, const IPAddress& Address, unsigned short Port);
00094
00108     Socket::Status Receive(char* Data, std::size_t MaxSize, std::size_t& SizeReceived, IPAddress& Address, unsigned short& Port);
00109
00120     Socket::Status Send(Packet& PacketToSend, const IPAddress& Address, unsigned short Port);
00121
00133     Socket::Status Receive(Packet& PacketToReceive, IPAddress& Address, unsigned short& Port);
00134
00141     bool Close();
00142
00150     bool IsValid() const;
00151
00158     unsigned short GetPort() const;
00159
00168     bool operator ==(const SocketUDP& Other) const;
00169
00178     bool operator !=(const SocketUDP& Other) const;
00179
00190     bool operator <(const SocketUDP& Other) const;
00191
00192 private :
00193
00194     friend class Selector<SocketUDP>;
00195
00203     SocketUDP(SocketHelper::SocketType Descriptor);
00204
00211     void Create(SocketHelper::SocketType Descriptor = 0);
00212
00214     // Member data
00216     SocketHelper::SocketType mySocket;
00217     unsigned short           myPort;
00218     Uint32                   myPendingHeader;
00219     Uint32                   myPendingHeaderSize;
00220     std::vector<char>        myPendingPacket;
00221     Int32                    myPendingPacketSize;
00222     bool                     myIsBlocking;
00223 };
00224
00225 } // namespace sf
00226
00227
00228 #endif // SFML_SOCKETUDP_HPP


  • File List

Sound.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Audio/Sound.hpp>
00029 #include <SFML/Audio/SoundBuffer.hpp>
00030 #include <SFML/Audio/OpenAL.hpp>
00031
00032
00033 namespace sf
00034 {
00038 Sound::Sound()
00039 {
00040     ALCheck(alGenSources(1, &mySource));
00041     ALCheck(alSourcei(mySource, AL_BUFFER, 0));
00042 }
00043
00044
00048 Sound::Sound(const SoundBuffer& Buffer, bool Loop, float Pitch, float Volume, const Vector3f& Position) :
00049 myBuffer(NULL)
00050 {
00051     ALCheck(alGenSources(1, &mySource));
00052
00053     SetBuffer(Buffer);
00054     SetLoop(Loop);
00055     SetPitch(Pitch);
00056     SetVolume(Volume);
00057     SetPosition(Position);
00058 }
00059
00060
00064 Sound::Sound(const Sound& Copy) :
00065 AudioResource(Copy),
00066 myBuffer(NULL)
00067 {
00068     ALCheck(alGenSources(1, &mySource));
00069
00070     if (Copy.myBuffer)
00071         SetBuffer(*Copy.myBuffer);
00072     SetLoop(Copy.GetLoop());
00073     SetPitch(Copy.GetPitch());
00074     SetVolume(Copy.GetVolume());
00075     SetPosition(Copy.GetPosition());
00076     SetRelativeToListener(Copy.IsRelativeToListener());
00077     SetMinDistance(Copy.GetMinDistance());
00078     SetAttenuation(Copy.GetAttenuation());
00079 }
00080
00081
00085 Sound::~Sound()
00086 {
00087     if (mySource)
00088     {
00089         if (myBuffer)
00090         {
00091             Stop();
00092             ALCheck(alSourcei(mySource, AL_BUFFER, 0));
00093             myBuffer->DetachSound(this);
00094         }
00095         ALCheck(alDeleteSources(1, &mySource));
00096     }
00097 }
00098
00099
00103 void Sound::Play()
00104 {
00105     ALCheck(alSourcePlay(mySource));
00106 }
00107
00108
00112 void Sound::Pause()
00113 {
00114     ALCheck(alSourcePause(mySource));
00115 }
00116
00117
00121 void Sound::Stop()
00122 {
00123     ALCheck(alSourceStop(mySource));
00124 }
00125
00126
00130 void Sound::SetBuffer(const SoundBuffer& Buffer)
00131 {
00132     // First detach from the previous buffer
00133     if (myBuffer)
00134     {
00135         Stop();
00136         myBuffer->DetachSound(this);
00137     }
00138
00139     // Assign and use the new buffer
00140     myBuffer = &Buffer;
00141     myBuffer->AttachSound(this);
00142     ALCheck(alSourcei(mySource, AL_BUFFER, myBuffer->myBuffer));
00143 }
00144
00145
00149 void Sound::SetLoop(bool Loop)
00150 {
00151     ALCheck(alSourcei(mySource, AL_LOOPING, Loop));
00152 }
00153
00154
00158 void Sound::SetPitch(float Pitch)
00159 {
00160     ALCheck(alSourcef(mySource, AL_PITCH, Pitch));
00161 }
00162
00163
00167 void Sound::SetVolume(float Volume)
00168 {
00169     ALCheck(alSourcef(mySource, AL_GAIN, Volume * 0.01f));
00170 }
00171
00176 void Sound::SetPosition(float X, float Y, float Z)
00177 {
00178     ALCheck(alSource3f(mySource, AL_POSITION, X, Y, Z));
00179 }
00180
00181
00186 void Sound::SetPosition(const Vector3f& Position)
00187 {
00188     SetPosition(Position.x, Position.y, Position.z);
00189 }
00190
00191
00197 void Sound::SetRelativeToListener(bool Relative)
00198 {
00199     ALCheck(alSourcei(mySource, AL_SOURCE_RELATIVE, Relative));
00200 }
00201
00202
00208 void Sound::SetMinDistance(float MinDistance)
00209 {
00210     ALCheck(alSourcef(mySource, AL_REFERENCE_DISTANCE, MinDistance));
00211 }
00212
00213
00219 void Sound::SetAttenuation(float Attenuation)
00220 {
00221     ALCheck(alSourcef(mySource, AL_ROLLOFF_FACTOR, Attenuation));
00222 }
00223
00224
00228 void Sound::SetPlayingOffset(float TimeOffset)
00229 {
00230     ALCheck(alSourcef(mySource, AL_SEC_OFFSET, TimeOffset));
00231 }
00232
00233
00237 const SoundBuffer* Sound::GetBuffer() const
00238 {
00239     return myBuffer;
00240 }
00241
00242
00246 bool Sound::GetLoop() const
00247 {
00248     ALint Loop;
00249     ALCheck(alGetSourcei(mySource, AL_LOOPING, &Loop));
00250
00251     return Loop != 0;
00252 }
00253
00254
00258 float Sound::GetPitch() const
00259 {
00260     ALfloat Pitch;
00261     ALCheck(alGetSourcef(mySource, AL_PITCH, &Pitch));
00262
00263     return Pitch;
00264 }
00265
00266
00270 float Sound::GetVolume() const
00271 {
00272     ALfloat Gain;
00273     ALCheck(alGetSourcef(mySource, AL_GAIN, &Gain));
00274
00275     return Gain * 100.f;
00276 }
00277
00278
00282 Vector3f Sound::GetPosition() const
00283 {
00284     Vector3f Position;
00285     ALCheck(alGetSource3f(mySource, AL_POSITION, &Position.x, &Position.y, &Position.z));
00286
00287     return Position;
00288 }
00289
00290
00295 bool Sound::IsRelativeToListener() const
00296 {
00297     ALint Relative;
00298     ALCheck(alGetSourcei(mySource, AL_SOURCE_RELATIVE, &Relative));
00299
00300     return Relative != 0;
00301 }
00302
00303
00307 float Sound::GetMinDistance() const
00308 {
00309     ALfloat MinDistance;
00310     ALCheck(alGetSourcef(mySource, AL_REFERENCE_DISTANCE, &MinDistance));
00311
00312     return MinDistance;
00313 }
00314
00315
00319 float Sound::GetAttenuation() const
00320 {
00321     ALfloat Attenuation;
00322     ALCheck(alGetSourcef(mySource, AL_ROLLOFF_FACTOR, &Attenuation));
00323
00324     return Attenuation;
00325 }
00326
00327
00331 float Sound::GetPlayingOffset() const
00332 {
00333     ALfloat Seconds = 0.f;
00334     ALCheck(alGetSourcef(mySource, AL_SEC_OFFSET, &Seconds));
00335
00336     return Seconds;
00337 }
00338
00339
00343 Sound::Status Sound::GetStatus() const
00344 {
00345     ALint State;
00346     ALCheck(alGetSourcei(mySource, AL_SOURCE_STATE, &State));
00347
00348     switch (State)
00349     {
00350         case AL_INITIAL :
00351         case AL_STOPPED : return Stopped;
00352         case AL_PAUSED :  return Paused;
00353         case AL_PLAYING : return Playing;
00354     }
00355
00356     return Stopped;
00357 }
00358
00359
00363 Sound& Sound::operator =(const Sound& Other)
00364 {
00365     // Here we don't use the copy-and-swap idiom, because it would mess up
00366     // the list of sound instances contained in the buffers
00367
00368     // Detach the sound instance from the previous buffer (if any)
00369     if (myBuffer)
00370     {
00371         Stop();
00372         myBuffer->DetachSound(this);
00373         myBuffer = NULL;
00374     }
00375
00376     // Copy the sound attributes
00377     if (Other.myBuffer)
00378         SetBuffer(*Other.myBuffer);
00379     SetLoop(Other.GetLoop());
00380     SetPitch(Other.GetPitch());
00381     SetVolume(Other.GetVolume());
00382     SetPosition(Other.GetPosition());
00383     SetRelativeToListener(Other.IsRelativeToListener());
00384     SetMinDistance(Other.GetMinDistance());
00385     SetAttenuation(Other.GetAttenuation());
00386
00387     return *this;
00388 }
00389
00390
00394 void Sound::ResetBuffer()
00395 {
00396     // First stop the sound in case it is playing
00397     Stop();
00398
00399     // Detach the buffer
00400     ALCheck(alSourcei(mySource, AL_BUFFER, 0));
00401     myBuffer = NULL;
00402 }
00403
00404 } // namespace sf


  • File List

Sound.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SOUND_HPP
00026 #define SFML_SOUND_HPP
00027
00029 // Headers
00031 #include <SFML/System/Resource.hpp>
00032 #include <SFML/System/Vector3.hpp>
00033 #include <SFML/Audio/AudioResource.hpp>
00034 #include <cstdlib>
00035
00036
00037 namespace sf
00038 {
00039 class SoundBuffer;
00040
00045 class SFML_API Sound : public AudioResource
00046 {
00047 public :
00048
00052     enum Status
00053     {
00054         Stopped,
00055         Paused,
00056         Playing
00057     };
00058
00063     Sound();
00064
00075     explicit Sound(const SoundBuffer& Buffer, bool Loop = false, float Pitch = 1.f, float Volume = 100.f, const Vector3f& Position = Vector3f(0, 0, 0));
00076
00083     Sound(const Sound& Copy);
00084
00089     ~Sound();
00090
00095     void Play();
00096
00101     void Pause();
00102
00107     void Stop();
00108
00115     void SetBuffer(const SoundBuffer& Buffer);
00116
00124     void SetLoop(bool Loop);
00125
00133     void SetPitch(float Pitch);
00134
00142     void SetVolume(float Volume);
00143
00151     void SetPosition(float X, float Y, float Z);
00152
00160     void SetPosition(const Vector3f& Position);
00161
00170     void SetRelativeToListener(bool Relative);
00171
00180     void SetMinDistance(float MinDistance);
00181
00190     void SetAttenuation(float Attenuation);
00191
00198     void SetPlayingOffset(float TimeOffset);
00199
00206     const SoundBuffer* GetBuffer() const;
00207
00214     bool GetLoop() const;
00215
00222     float GetPitch() const;
00223
00230     float GetVolume() const;
00231
00238     Vector3f GetPosition() const;
00239
00247     bool IsRelativeToListener() const;
00248
00255     float GetMinDistance() const;
00256
00263     float GetAttenuation() const;
00264
00271     Status GetStatus() const;
00272
00279     float GetPlayingOffset() const;
00280
00289     Sound& operator =(const Sound& Other);
00290
00298     void ResetBuffer();
00299
00300 private :
00301
00302     friend class SoundStream;
00303
00305     // Member data
00307     unsigned int             mySource;
00308     ResourcePtr<SoundBuffer> myBuffer;
00309 };
00310
00311 } // namespace sf
00312
00313
00314 #endif // SFML_SOUND_HPP


  • File List

SoundBuffer.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Audio/SoundBuffer.hpp>
00029 #include <SFML/Audio/SoundFile.hpp>
00030 #include <SFML/Audio/Sound.hpp>
00031 #include <SFML/Audio/AudioDevice.hpp>
00032 #include <SFML/Audio/OpenAL.hpp>
00033 #include <iostream>
00034 #include <memory>
00035
00036
00037 namespace sf
00038 {
00042 SoundBuffer::SoundBuffer() :
00043 myBuffer  (0),
00044 myDuration(0.f)
00045 {
00046     // Create the buffer
00047     ALCheck(alGenBuffers(1, &myBuffer));
00048 }
00049
00050
00054 SoundBuffer::SoundBuffer(const SoundBuffer& Copy) :
00055 AudioResource        (Copy),
00056 Resource<SoundBuffer>(Copy),
00057 myBuffer             (0),
00058 mySamples            (Copy.mySamples),
00059 myDuration           (Copy.myDuration),
00060 mySounds             () // don't copy the attached sounds
00061 {
00062     // Create the buffer
00063     ALCheck(alGenBuffers(1, &myBuffer));
00064
00065     // Update the internal buffer with the new samples
00066     Update(Copy.GetChannelsCount(), Copy.GetSampleRate());
00067 }
00068
00069
00073 SoundBuffer::~SoundBuffer()
00074 {
00075     // First detach the buffer from the sounds that use it (to avoid OpenAL errors)
00076     for (SoundList::const_iterator it = mySounds.begin(); it != mySounds.end(); ++it)
00077         (*it)->ResetBuffer();
00078
00079     // Destroy the buffer
00080     if (myBuffer)
00081         ALCheck(alDeleteBuffers(1, &myBuffer));
00082 }
00083
00084
00088 bool SoundBuffer::LoadFromFile(const std::string& Filename)
00089 {
00090     // Create the sound file
00091     std::auto_ptr<priv::SoundFile> File(priv::SoundFile::CreateRead(Filename));
00092
00093     // Open the sound file
00094     if (File.get())
00095     {
00096         // Get the sound parameters
00097         std::size_t  NbSamples     = File->GetSamplesCount();
00098         unsigned int ChannelsCount = File->GetChannelsCount();
00099         unsigned int SampleRate    = File->GetSampleRate();
00100
00101         // Read the samples from the opened file
00102         mySamples.resize(NbSamples);
00103         if (File->Read(&mySamples[0], NbSamples) == NbSamples)
00104         {
00105             // Update the internal buffer with the new samples
00106             return Update(ChannelsCount, SampleRate);
00107         }
00108         else
00109         {
00110             // Error...
00111             std::cerr << "Failed to read audio data from file \"" << Filename << "\"" << std::endl;
00112
00113             return false;
00114         }
00115     }
00116     else
00117     {
00118         // Error...
00119         std::cerr << "Failed to load sound buffer from file \"" << Filename << "\"" << std::endl;
00120
00121         return false;
00122     }
00123 }
00124
00125
00129 bool SoundBuffer::LoadFromMemory(const char* Data, std::size_t SizeInBytes)
00130 {
00131     // Create the sound file
00132     std::auto_ptr<priv::SoundFile> File(priv::SoundFile::CreateRead(Data, SizeInBytes));
00133
00134     // Open the sound file
00135     if (File.get())
00136     {
00137         // Get the sound parameters
00138         std::size_t  NbSamples     = File->GetSamplesCount();
00139         unsigned int ChannelsCount = File->GetChannelsCount();
00140         unsigned int SampleRate    = File->GetSampleRate();
00141
00142         // Read the samples from the opened file
00143         mySamples.resize(NbSamples);
00144         if (File->Read(&mySamples[0], NbSamples) == NbSamples)
00145         {
00146             // Update the internal buffer with the new samples
00147             return Update(ChannelsCount, SampleRate);
00148         }
00149         else
00150         {
00151             // Error...
00152             std::cerr << "Failed to read audio data from file in memory" << std::endl;
00153
00154             return false;
00155         }
00156     }
00157     else
00158     {
00159         // Error...
00160         std::cerr << "Failed to load sound buffer from file in memory" << std::endl;
00161
00162         return false;
00163     }
00164 }
00165
00166
00171 bool SoundBuffer::LoadFromSamples(const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate)
00172 {
00173     if (Samples && SamplesCount && ChannelsCount && SampleRate)
00174     {
00175         // Copy the new audio samples
00176         mySamples.assign(Samples, Samples + SamplesCount);
00177
00178         // Update the internal buffer with the new samples
00179         return Update(ChannelsCount, SampleRate);
00180     }
00181     else
00182     {
00183         // Error...
00184         std::cerr << "Failed to load sound buffer from memory ("
00185                   << "Samples : "        << Samples       << ", "
00186                   << "Samples count : "  << SamplesCount  << ", "
00187                   << "Channels count : " << ChannelsCount << ", "
00188                   << "Sample rate : "    << SampleRate    << ")"
00189                   << std::endl;
00190
00191         return false;
00192     }
00193 }
00194
00195
00199 bool SoundBuffer::SaveToFile(const std::string& Filename) const
00200 {
00201     // Create the sound file in write mode
00202     std::auto_ptr<priv::SoundFile> File(priv::SoundFile::CreateWrite(Filename, GetChannelsCount(), GetSampleRate()));
00203     if (File.get())
00204     {
00205         // Write the samples to the opened file
00206         File->Write(&mySamples[0], mySamples.size());
00207
00208         return true;
00209     }
00210     else
00211     {
00212         // Error...
00213         std::cerr << "Failed to save sound buffer to file \"" << Filename << "\"" << std::endl;
00214
00215         return false;
00216     }
00217 }
00218
00219
00223 const Int16* SoundBuffer::GetSamples() const
00224 {
00225     return mySamples.empty() ? NULL : &mySamples[0];
00226 }
00227
00228
00232 std::size_t SoundBuffer::GetSamplesCount() const
00233 {
00234     return mySamples.size();
00235 }
00236
00237
00241 unsigned int SoundBuffer::GetSampleRate() const
00242 {
00243     ALint SampleRate;
00244     ALCheck(alGetBufferi(myBuffer, AL_FREQUENCY, &SampleRate));
00245
00246     return SampleRate;
00247 }
00248
00249
00253 unsigned int SoundBuffer::GetChannelsCount() const
00254 {
00255     ALint ChannelsCount;
00256     ALCheck(alGetBufferi(myBuffer, AL_CHANNELS, &ChannelsCount));
00257
00258     return ChannelsCount;
00259 }
00260
00261
00265 float SoundBuffer::GetDuration() const
00266 {
00267     return myDuration;
00268 }
00269
00270
00274 SoundBuffer& SoundBuffer::operator =(const SoundBuffer& Other)
00275 {
00276     SoundBuffer Temp(Other);
00277
00278     std::swap(mySamples,  Temp.mySamples);
00279     std::swap(myBuffer,   Temp.myBuffer);
00280     std::swap(myDuration, Temp.myDuration);
00281     std::swap(mySounds,   Temp.mySounds); // swap sounds too, so that they are detached when Temp is destroyed
00282
00283     return *this;
00284 }
00285
00286
00290 bool SoundBuffer::Update(unsigned int ChannelsCount, unsigned int SampleRate)
00291 {
00292     // Check parameters
00293     if (!SampleRate || !ChannelsCount || mySamples.empty())
00294         return false;
00295
00296     // Find the good format according to the number of channels
00297     ALenum Format = priv::AudioDevice::GetInstance().GetFormatFromChannelsCount(ChannelsCount);
00298
00299     // Check if the format is valid
00300     if (Format == 0)
00301     {
00302         std::cerr << "Unsupported number of channels (" << ChannelsCount << ")" << std::endl;
00303         return false;
00304     }
00305
00306     // Fill the buffer
00307     ALsizei Size = static_cast<ALsizei>(mySamples.size()) * sizeof(Int16);
00308     ALCheck(alBufferData(myBuffer, Format, &mySamples[0], Size, SampleRate));
00309
00310     // Compute the duration
00311     myDuration = static_cast<float>(mySamples.size()) / SampleRate / ChannelsCount;
00312
00313     return true;
00314 }
00315
00316
00320 void SoundBuffer::AttachSound(Sound* Instance) const
00321 {
00322     mySounds.insert(Instance);
00323 }
00324
00325
00329 void SoundBuffer::DetachSound(Sound* Instance) const
00330 {
00331     mySounds.erase(Instance);
00332 }
00333
00334 } // namespace sf


  • File List

SoundBuffer.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SOUNDBUFFER_HPP
00026 #define SFML_SOUNDBUFFER_HPP
00027
00029 // Headers
00031 #include <SFML/System/Resource.hpp>
00032 #include <SFML/Audio/AudioResource.hpp>
00033 #include <string>
00034 #include <vector>
00035 #include <set>
00036
00037
00038 namespace sf
00039 {
00040 class Sound;
00041
00046 class SFML_API SoundBuffer : public AudioResource, public Resource<SoundBuffer>
00047 {
00048 public :
00049
00054     SoundBuffer();
00055
00062     SoundBuffer(const SoundBuffer& Copy);
00063
00068     ~SoundBuffer();
00069
00078     bool LoadFromFile(const std::string& Filename);
00079
00089     bool LoadFromMemory(const char* Data, std::size_t SizeInBytes);
00090
00103     bool LoadFromSamples(const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate);
00104
00113     bool SaveToFile(const std::string& Filename) const;
00114
00121     const Int16* GetSamples() const;
00122
00129     std::size_t GetSamplesCount() const;
00130
00137     unsigned int GetSampleRate() const;
00138
00145     unsigned int GetChannelsCount() const;
00146
00153     float GetDuration() const;
00154
00163     SoundBuffer& operator =(const SoundBuffer& Other);
00164
00165 private :
00166
00167     friend class Sound;
00168
00178     bool Update(unsigned int ChannelsCount, unsigned int SampleRate);
00179
00186     void AttachSound(Sound* Instance) const;
00187
00194     void DetachSound(Sound* Instance) const;
00195
00197     // Types
00199     typedef std::set<Sound*> SoundList;
00200
00202     // Member data
00204     unsigned int       myBuffer;
00205     std::vector<Int16> mySamples;
00206     float              myDuration;
00207     mutable SoundList  mySounds;
00208 };
00209
00210 } // namespace sf
00211
00212
00213 #endif // SFML_SOUNDBUFFER_HPP


  • File List

SoundBufferRecorder.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Audio/SoundBufferRecorder.hpp>
00029 #include <algorithm>
00030 #include <iterator>
00031
00032
00033 namespace sf
00034 {
00038 bool SoundBufferRecorder::OnStart()
00039 {
00040     mySamples.clear();
00041
00042     return true;
00043 }
00044
00045
00049 bool SoundBufferRecorder::OnProcessSamples(const Int16* Samples, std::size_t SamplesCount)
00050 {
00051     std::copy(Samples, Samples + SamplesCount, std::back_inserter(mySamples));
00052
00053     return true;
00054 }
00055
00056
00060 void SoundBufferRecorder::OnStop()
00061 {
00062     if (!mySamples.empty())
00063         myBuffer.LoadFromSamples(&mySamples[0], mySamples.size(), 1, GetSampleRate());
00064 }
00065
00066
00070 const SoundBuffer& SoundBufferRecorder::GetBuffer() const
00071 {
00072     return myBuffer;
00073 }
00074
00075 } // namespace sf


  • File List

SoundBufferRecorder.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SOUNDBUFFERRECORDER_HPP
00026 #define SFML_SOUNDBUFFERRECORDER_HPP
00027
00029 // Headers
00031 #include <SFML/Audio/SoundBuffer.hpp>
00032 #include <SFML/Audio/SoundRecorder.hpp>
00033 #include <vector>
00034
00035
00036 namespace sf
00037 {
00042 class SFML_API SoundBufferRecorder : public SoundRecorder
00043 {
00044 public :
00045
00052     const SoundBuffer& GetBuffer() const;
00053
00054 private :
00055
00060     virtual bool OnStart();
00061
00066     virtual bool OnProcessSamples(const Int16* Samples, std::size_t SamplesCount);
00067
00072     virtual void OnStop();
00073
00075     // Member data
00077     std::vector<Int16> mySamples;
00078     SoundBuffer        myBuffer;
00079 };
00080
00081 } // namespace sf
00082
00083 #endif // SFML_SOUNDBUFFERRECORDER_HPP


  • File List

SoundFile.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Audio/SoundFile.hpp>
00029 #include <SFML/Audio/SoundFileDefault.hpp>
00030 #include <SFML/Audio/SoundFileOgg.hpp>
00031 #include <iostream>
00032
00033
00034 namespace sf
00035 {
00036 namespace priv
00037 {
00041 SoundFile* SoundFile::CreateRead(const std::string& Filename)
00042 {
00043     // Create the file according to its type
00044     SoundFile* File = NULL;
00045     if      (SoundFileOgg::IsFileSupported(Filename, true))     File = new SoundFileOgg;
00046     else if (SoundFileDefault::IsFileSupported(Filename, true)) File = new SoundFileDefault;
00047
00048     // Open it for reading
00049     if (File)
00050     {
00051         std::size_t  SamplesCount;
00052         unsigned int ChannelsCount;
00053         unsigned int SampleRate;
00054
00055         if (File->OpenRead(Filename, SamplesCount, ChannelsCount, SampleRate))
00056         {
00057             File->myFilename      = Filename;
00058             File->myData          = NULL;
00059             File->mySize          = 0;
00060             File->myNbSamples     = SamplesCount;
00061             File->myChannelsCount = ChannelsCount;
00062             File->mySampleRate    = SampleRate;
00063         }
00064         else
00065         {
00066             delete File;
00067             File = NULL;
00068         }
00069     }
00070
00071     return File;
00072 }
00073
00074
00078 SoundFile* SoundFile::CreateRead(const char* Data, std::size_t SizeInMemory)
00079 {
00080     // Create the file according to its type
00081     SoundFile* File = NULL;
00082     if      (SoundFileOgg::IsFileSupported(Data, SizeInMemory))     File = new SoundFileOgg;
00083     else if (SoundFileDefault::IsFileSupported(Data, SizeInMemory)) File = new SoundFileDefault;
00084
00085     // Open it for reading
00086     if (File)
00087     {
00088         std::size_t  SamplesCount;
00089         unsigned int ChannelsCount;
00090         unsigned int SampleRate;
00091
00092         if (File->OpenRead(Data, SizeInMemory, SamplesCount, ChannelsCount, SampleRate))
00093         {
00094             File->myFilename      = "";
00095             File->myData          = Data;
00096             File->mySize          = SizeInMemory;
00097             File->myNbSamples     = SamplesCount;
00098             File->myChannelsCount = ChannelsCount;
00099             File->mySampleRate    = SampleRate;
00100         }
00101         else
00102         {
00103             delete File;
00104             File = NULL;
00105         }
00106     }
00107
00108     return File;
00109 }
00110
00111
00115 SoundFile* SoundFile::CreateWrite(const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate)
00116 {
00117     // Create the file according to its type
00118     SoundFile* File = NULL;
00119     if      (SoundFileOgg::IsFileSupported(Filename, false))     File = new SoundFileOgg;
00120     else if (SoundFileDefault::IsFileSupported(Filename, false)) File = new SoundFileDefault;
00121
00122     // Open it for writing
00123     if (File)
00124     {
00125         if (File->OpenWrite(Filename, ChannelsCount, SampleRate))
00126         {
00127             File->myFilename      = "";
00128             File->myData          = NULL;
00129             File->mySize          = 0;
00130             File->myNbSamples     = 0;
00131             File->myChannelsCount = ChannelsCount;
00132             File->mySampleRate    = SampleRate;
00133         }
00134         else
00135         {
00136             delete File;
00137             File = NULL;
00138         }
00139     }
00140
00141     return File;
00142 }
00143
00144
00148 SoundFile::SoundFile() :
00149 myNbSamples    (0),
00150 myChannelsCount(0),
00151 mySampleRate   (0)
00152 {
00153
00154 }
00155
00156
00160 SoundFile::~SoundFile()
00161 {
00162     // Nothing to do
00163 }
00164
00165
00169 std::size_t SoundFile::GetSamplesCount() const
00170 {
00171     return myNbSamples;
00172 }
00173
00174
00178 unsigned int SoundFile::GetChannelsCount() const
00179 {
00180     return myChannelsCount;
00181 }
00182
00183
00187 unsigned int SoundFile::GetSampleRate() const
00188 {
00189     return mySampleRate;
00190 }
00191
00192
00196 bool SoundFile::Restart()
00197 {
00198     if (myData)
00199     {
00200         // Reopen from memory
00201         return OpenRead(myData, mySize, myNbSamples, myChannelsCount, mySampleRate);
00202     }
00203     else if (myFilename != "")
00204     {
00205         // Reopen from file
00206         return OpenRead(myFilename, myNbSamples, myChannelsCount, mySampleRate);
00207     }
00208     else
00209     {
00210         // Trying to reopen a file opened in write mode... error
00211         std::cerr << "Warning : trying to restart a sound opened in write mode, which is not allowed" << std::endl;
00212         return false;
00213     }
00214 }
00215
00216
00220 bool SoundFile::OpenRead(const std::string& Filename, std::size_t&, unsigned int&, unsigned int&)
00221 {
00222     std::cerr << "Failed to open sound file \"" << Filename << "\", format is not supported by SFML" << std::endl;
00223
00224     return false;
00225 }
00226
00227
00231 bool SoundFile::OpenRead(const char*, std::size_t, std::size_t&, unsigned int&, unsigned int&)
00232 {
00233     std::cerr << "Failed to open sound file from memory, format is not supported by SFML" << std::endl;
00234
00235     return false;
00236 }
00237
00238
00242 bool SoundFile::OpenWrite(const std::string& Filename, unsigned int, unsigned int)
00243 {
00244     std::cerr << "Failed to open sound file \"" << Filename << "\", format is not supported by SFML" << std::endl;
00245
00246     return false;
00247 }
00248
00249
00253 std::size_t SoundFile::Read(Int16*, std::size_t)
00254 {
00255     std::cerr << "Failed to read from sound file (not supported)" << std::endl;
00256
00257     return 0;
00258 }
00259
00260
00264 void SoundFile::Write(const Int16*, std::size_t)
00265 {
00266     std::cerr << "Failed to write to sound file (not supported)" << std::endl;
00267 }
00268
00269 } // namespace priv
00270
00271 } // namespace sf


  • File List

SoundFile.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SOUNDFILE_HPP
00026 #define SFML_SOUNDFILE_HPP
00027
00029 // Headers
00031 #include <SFML/System/NonCopyable.hpp>
00032 #include <string>
00033
00034
00035 namespace sf
00036 {
00037 namespace priv
00038 {
00043 class SoundFile : NonCopyable
00044 {
00045 public :
00046
00058     static SoundFile* CreateRead(const std::string& Filename);
00059
00072     static SoundFile* CreateRead(const char* Data, std::size_t SizeInBytes);
00073
00084     static SoundFile* CreateWrite(const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate);
00085
00090     virtual ~SoundFile();
00091
00098     std::size_t GetSamplesCount() const;
00099
00106     unsigned int GetChannelsCount() const;
00107
00114     unsigned int GetSampleRate() const;
00115
00122     bool Restart();
00123
00133     virtual std::size_t Read(Int16* Data, std::size_t NbSamples);
00134
00142     virtual void Write(const Int16* Data, std::size_t NbSamples);
00143
00144 protected :
00145
00150     SoundFile();
00151
00152 private :
00153
00165     virtual bool OpenRead(const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
00166
00179     virtual bool OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
00180
00191     virtual bool OpenWrite(const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate);
00192
00194     // Member data
00196     std::size_t  myNbSamples;
00197     unsigned int myChannelsCount;
00198     unsigned int mySampleRate;
00199     std::string  myFilename;
00200     const char*  myData;
00201     std::size_t  mySize;
00202 };
00203
00204 } // namespace priv
00205
00206 } // namespace sf
00207
00208
00209 #endif // SFML_SOUNDFILE_HPP


  • File List

SoundFileDefault.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Audio/SoundFileDefault.hpp>
00029 #include <iostream>
00030 #include <string.h>
00031
00032
00033 namespace sf
00034 {
00035 namespace priv
00036 {
00040 SoundFileDefault::SoundFileDefault() :
00041 myFile(NULL)
00042 {
00043
00044 }
00045
00046
00050 SoundFileDefault::~SoundFileDefault()
00051 {
00052     if (myFile)
00053         sf_close(myFile);
00054 }
00055
00056
00060 bool SoundFileDefault::IsFileSupported(const std::string& Filename, bool Read)
00061 {
00062     if (Read)
00063     {
00064         // Open the sound file
00065         SF_INFO FileInfos;
00066         SNDFILE* File = sf_open(Filename.c_str(), SFM_READ, &FileInfos);
00067
00068         if (File)
00069         {
00070             sf_close(File);
00071             return true;
00072         }
00073         else
00074         {
00075             return false;
00076         }
00077     }
00078     else
00079     {
00080         // Check the extension
00081         return GetFormatFromFilename(Filename) != -1;
00082     }
00083 }
00084
00085
00089 bool SoundFileDefault::IsFileSupported(const char* Data, std::size_t SizeInBytes)
00090 {
00091     // Define the I/O custom functions for reading from memory
00092     SF_VIRTUAL_IO VirtualIO;
00093     VirtualIO.get_filelen = &SoundFileDefault::MemoryGetLength;
00094     VirtualIO.read        = &SoundFileDefault::MemoryRead;
00095     VirtualIO.seek        = &SoundFileDefault::MemorySeek;
00096     VirtualIO.tell        = &SoundFileDefault::MemoryTell;
00097     VirtualIO.write       = &SoundFileDefault::MemoryWrite;
00098
00099     // Initialize the memory data
00100     MemoryInfos Memory;
00101     Memory.DataStart = Data;
00102     Memory.DataPtr   = Data;
00103     Memory.TotalSize = SizeInBytes;
00104
00105     // Open the sound file
00106     SF_INFO FileInfos;
00107     SNDFILE* File = sf_open_virtual(&VirtualIO, SFM_READ, &FileInfos, &Memory);
00108
00109     if (File)
00110     {
00111         sf_close(File);
00112         return true;
00113     }
00114     else
00115     {
00116         return false;
00117     }
00118 }
00119
00120
00124 bool SoundFileDefault::OpenRead(const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate)
00125 {
00126     // If the file is already opened, first close it
00127     if (myFile)
00128         sf_close(myFile);
00129
00130     // Open the sound file
00131     SF_INFO FileInfos;
00132     myFile = sf_open(Filename.c_str(), SFM_READ, &FileInfos);
00133     if (!myFile)
00134     {
00135         std::cerr << "Failed to read sound file \"" << Filename << "\"" << std::endl;
00136         return false;
00137     }
00138
00139     // Set the sound parameters
00140     ChannelsCount = FileInfos.channels;
00141     SampleRate    = FileInfos.samplerate;
00142     NbSamples     = static_cast<std::size_t>(FileInfos.frames) * ChannelsCount;
00143
00144     return true;
00145 }
00146
00147
00151 bool SoundFileDefault::OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate)
00152 {
00153     // If the file is already opened, first close it
00154     if (myFile)
00155         sf_close(myFile);
00156
00157     // Define the I/O custom functions for reading from memory
00158     SF_VIRTUAL_IO VirtualIO;
00159     VirtualIO.get_filelen = &SoundFileDefault::MemoryGetLength;
00160     VirtualIO.read        = &SoundFileDefault::MemoryRead;
00161     VirtualIO.seek        = &SoundFileDefault::MemorySeek;
00162     VirtualIO.tell        = &SoundFileDefault::MemoryTell;
00163     VirtualIO.write       = &SoundFileDefault::MemoryWrite;
00164
00165     // Initialize the memory data
00166     myMemory.DataStart = Data;
00167     myMemory.DataPtr   = Data;
00168     myMemory.TotalSize = SizeInBytes;
00169
00170     // Open the sound file
00171     SF_INFO FileInfos;
00172     myFile = sf_open_virtual(&VirtualIO, SFM_READ, &FileInfos, &myMemory);
00173     if (!myFile)
00174     {
00175         std::cerr << "Failed to read sound file from memory" << std::endl;
00176         return false;
00177     }
00178
00179     // Set the sound parameters
00180     ChannelsCount = FileInfos.channels;
00181     SampleRate    = FileInfos.samplerate;
00182     NbSamples     = static_cast<std::size_t>(FileInfos.frames) * ChannelsCount;
00183
00184     return true;
00185 }
00186
00187
00191 bool SoundFileDefault::OpenWrite(const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate)
00192 {
00193     // If the file is already opened, first close it
00194     if (myFile)
00195         sf_close(myFile);
00196
00197     // Find the right format according to the file extension
00198     int Format = GetFormatFromFilename(Filename);
00199     if (Format == -1)
00200     {
00201         // Error : unrecognized extension
00202         std::cerr << "Failed to create sound file \"" << Filename << "\" : unknown format" << std::endl;
00203         return false;
00204     }
00205
00206     // Fill the sound infos with parameters
00207     SF_INFO FileInfos;
00208     FileInfos.channels   = ChannelsCount;
00209     FileInfos.samplerate = SampleRate;
00210     FileInfos.format     = Format | SF_FORMAT_PCM_16;
00211
00212     // Open the sound file for writing
00213     myFile = sf_open(Filename.c_str(), SFM_WRITE, &FileInfos);
00214     if (!myFile)
00215     {
00216         std::cerr << "Failed to create sound file \"" << Filename << "\"" << std::endl;
00217         return false;
00218     }
00219
00220     return true;
00221 }
00222
00223
00227 std::size_t SoundFileDefault::Read(Int16* Data, std::size_t NbSamples)
00228 {
00229     if (myFile && Data && NbSamples)
00230         return static_cast<std::size_t>(sf_read_short(myFile, Data, NbSamples));
00231     else
00232         return 0;
00233 }
00234
00235
00239 void SoundFileDefault::Write(const Int16* Data, std::size_t NbSamples)
00240 {
00241     if (myFile && Data && NbSamples)
00242         sf_write_short(myFile, Data, NbSamples);
00243 }
00244
00245
00250 int SoundFileDefault::GetFormatFromFilename(const std::string& Filename)
00251 {
00252     // Extract the extension
00253     std::string Ext = "wav";
00254     std::string::size_type Pos = Filename.find_last_of(".");
00255     if (Pos != std::string::npos)
00256         Ext = Filename.substr(Pos + 1);
00257
00258     // Match every supported extension with its format constant
00259     if (Ext == "wav"  || Ext == "WAV" ) return SF_FORMAT_WAV;
00260     if (Ext == "aif"  || Ext == "AIF" ) return SF_FORMAT_AIFF;
00261     if (Ext == "aiff" || Ext == "AIFF") return SF_FORMAT_AIFF;
00262     if (Ext == "au"   || Ext == "AU"  ) return SF_FORMAT_AU;
00263     if (Ext == "raw"  || Ext == "RAW" ) return SF_FORMAT_RAW;
00264     if (Ext == "paf"  || Ext == "PAF" ) return SF_FORMAT_PAF;
00265     if (Ext == "svx"  || Ext == "SVX" ) return SF_FORMAT_SVX;
00266     if (Ext == "voc"  || Ext == "VOC" ) return SF_FORMAT_VOC;
00267     if (Ext == "sf"   || Ext == "SF"  ) return SF_FORMAT_IRCAM;
00268     if (Ext == "w64"  || Ext == "W64" ) return SF_FORMAT_W64;
00269     if (Ext == "mat4" || Ext == "MAT4") return SF_FORMAT_MAT4;
00270     if (Ext == "mat5" || Ext == "MAT5") return SF_FORMAT_MAT5;
00271     if (Ext == "pvf"  || Ext == "PVF" ) return SF_FORMAT_PVF;
00272     if (Ext == "htk"  || Ext == "HTK" ) return SF_FORMAT_HTK;
00273     if (Ext == "caf"  || Ext == "CAF" ) return SF_FORMAT_CAF;
00274     if (Ext == "nist" || Ext == "NIST") return SF_FORMAT_NIST; // SUPPORTED ?
00275     if (Ext == "sds"  || Ext == "SDS" ) return SF_FORMAT_SDS;  // SUPPORTED ?
00276     if (Ext == "avr"  || Ext == "AVR" ) return SF_FORMAT_AVR;  // SUPPORTED ?
00277     if (Ext == "sd2"  || Ext == "SD2" ) return SF_FORMAT_SD2;  // SUPPORTED ?
00278     if (Ext == "flac" || Ext == "FLAC") return SF_FORMAT_FLAC; // SUPPORTED ?
00279
00280     return -1;
00281 }
00282
00283
00288 sf_count_t SoundFileDefault::MemoryGetLength(void* UserData)
00289 {
00290     MemoryInfos* Memory = static_cast<MemoryInfos*>(UserData);
00291
00292     return Memory->TotalSize;
00293 }
00294 sf_count_t SoundFileDefault::MemoryRead(void* Ptr, sf_count_t Count, void* UserData)
00295 {
00296     MemoryInfos* Memory = static_cast<MemoryInfos*>(UserData);
00297
00298     sf_count_t Position = Memory->DataPtr - Memory->DataStart;
00299     if (Position + Count >= Memory->TotalSize)
00300         Count = Memory->TotalSize - Position;
00301
00302     memcpy(Ptr, Memory->DataPtr, static_cast<std::size_t>(Count));
00303
00304     Memory->DataPtr += Count;
00305
00306     return Count;
00307 }
00308 sf_count_t SoundFileDefault::MemorySeek(sf_count_t Offset, int Whence, void* UserData)
00309 {
00310     MemoryInfos* Memory = static_cast<MemoryInfos*>(UserData);
00311
00312     sf_count_t Position = 0;
00313     switch (Whence)
00314     {
00315         case SEEK_SET :
00316             Position = Offset;
00317             break;
00318         case SEEK_CUR :
00319             Position = Memory->DataPtr - Memory->DataStart + Offset;
00320             break;
00321         case SEEK_END :
00322             Position = Memory->TotalSize - Offset;
00323             break;
00324         default :
00325             Position = 0;
00326             break;
00327     }
00328
00329     if (Position >= Memory->TotalSize)
00330         Position = Memory->TotalSize - 1;
00331     else if (Position < 0)
00332         Position = 0;
00333
00334     Memory->DataPtr = Memory->DataStart + Position;
00335
00336     return Position;
00337 }
00338 sf_count_t SoundFileDefault::MemoryTell(void* UserData)
00339 {
00340     MemoryInfos* Memory = static_cast<MemoryInfos*>(UserData);
00341
00342     return Memory->DataPtr - Memory->DataStart;
00343 }
00344 sf_count_t SoundFileDefault::MemoryWrite(const void*, sf_count_t, void*)
00345 {
00346     return 0;
00347 }
00348
00349
00350 } // namespace priv
00351
00352 } // namespace sf


  • File List

SoundFileDefault.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SOUNDFILEDEFAULT_HPP
00026 #define SFML_SOUNDFILEDEFAULT_HPP
00027
00029 // Headers
00031 #include <SFML/Audio/SoundFile.hpp>
00032 #include <sndfile.h>
00033
00034
00035 namespace sf
00036 {
00037 namespace priv
00038 {
00043 class SoundFileDefault : public SoundFile
00044 {
00045 public :
00046
00051     SoundFileDefault();
00052
00057     ~SoundFileDefault();
00058
00068     static bool IsFileSupported(const std::string& Filename, bool Read);
00069
00079     static bool IsFileSupported(const char* Data, std::size_t SizeInBytes);
00080
00085     virtual std::size_t Read(Int16* Data, std::size_t NbSamples);
00086
00091     virtual void Write(const Int16* Data, std::size_t NbSamples);
00092
00093 private :
00094
00099     virtual bool OpenRead(const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
00100
00105     virtual bool OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
00106
00111     virtual bool OpenWrite(const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate);
00112
00122     static int GetFormatFromFilename(const std::string& Filename);
00123
00128     static sf_count_t MemoryGetLength(void* UserData);
00129     static sf_count_t MemoryRead(void* Ptr, sf_count_t Count, void* UserData);
00130     static sf_count_t MemorySeek(sf_count_t Offset, int Whence, void* UserData);
00131     static sf_count_t MemoryTell(void* UserData);
00132     static sf_count_t MemoryWrite(const void* Ptr, sf_count_t Count, void* UserData);
00133
00137     struct MemoryInfos
00138     {
00139         const char* DataStart;
00140         const char* DataPtr;
00141         sf_count_t  TotalSize;
00142     };
00143
00145     // Member data
00147     SNDFILE*    myFile;
00148     MemoryInfos myMemory;
00149 };
00150
00151 } // namespace priv
00152
00153 } // namespace sf
00154
00155
00156 #endif // SFML_SOUNDFILEDEFAULT_HPP


  • File List

SoundFileOgg.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Audio/SoundFileOgg.hpp>
00029 #include <SFML/Audio/stb_vorbis/stb_vorbis.h>
00030 #include <iostream>
00031
00032
00033 namespace sf
00034 {
00035 namespace priv
00036 {
00040 SoundFileOgg::SoundFileOgg() :
00041 myStream       (NULL),
00042 myChannelsCount(0)
00043 {
00044
00045 }
00046
00047
00051 SoundFileOgg::~SoundFileOgg()
00052 {
00053     if (myStream)
00054         stb_vorbis_close(myStream);
00055 }
00056
00057
00061 bool SoundFileOgg::IsFileSupported(const std::string& Filename, bool Read)
00062 {
00063     if (Read)
00064     {
00065         // Open the vorbis stream
00066         stb_vorbis* Stream = stb_vorbis_open_filename(const_cast<char*>(Filename.c_str()), NULL, NULL);
00067
00068         if (Stream)
00069         {
00070             stb_vorbis_close(Stream);
00071             return true;
00072         }
00073         else
00074         {
00075             return false;
00076         }
00077     }
00078     else
00079     {
00080         // No support for writing ogg files yet...
00081         return false;
00082     }
00083 }
00084
00085
00089 bool SoundFileOgg::IsFileSupported(const char* Data, std::size_t SizeInBytes)
00090 {
00091     // Open the vorbis stream
00092     unsigned char* Buffer = reinterpret_cast<unsigned char*>(const_cast<char*>(Data));
00093     int Length = static_cast<int>(SizeInBytes);
00094     stb_vorbis* Stream = stb_vorbis_open_memory(Buffer, Length, NULL, NULL);
00095
00096     if (Stream)
00097     {
00098         stb_vorbis_close(Stream);
00099         return true;
00100     }
00101     else
00102     {
00103         return false;
00104     }
00105 }
00106
00107
00111 bool SoundFileOgg::OpenRead(const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate)
00112 {
00113     // Close the file if already opened
00114     if (myStream)
00115         stb_vorbis_close(myStream);
00116
00117     // Open the vorbis stream
00118     myStream = stb_vorbis_open_filename(const_cast<char*>(Filename.c_str()), NULL, NULL);
00119     if (myStream == NULL)
00120     {
00121         std::cerr << "Failed to read sound file \"" << Filename << "\" (cannot open the file)" << std::endl;
00122         return false;
00123     }
00124
00125     // Get the music parameters
00126     stb_vorbis_info Infos = stb_vorbis_get_info(myStream);
00127     ChannelsCount = myChannelsCount = Infos.channels;
00128     SampleRate    = Infos.sample_rate;
00129     NbSamples     = static_cast<std::size_t>(stb_vorbis_stream_length_in_samples(myStream) * ChannelsCount);
00130
00131     return true;
00132 }
00133
00134
00138 bool SoundFileOgg::OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate)
00139 {
00140     // Close the file if already opened
00141     if (myStream)
00142         stb_vorbis_close(myStream);
00143
00144     // Open the vorbis stream
00145     unsigned char* Buffer = reinterpret_cast<unsigned char*>(const_cast<char*>(Data));
00146     int Length = static_cast<int>(SizeInBytes);
00147     myStream = stb_vorbis_open_memory(Buffer, Length, NULL, NULL);
00148     if (myStream == NULL)
00149     {
00150         std::cerr << "Failed to read sound file from memory (cannot open the file)" << std::endl;
00151         return false;
00152     }
00153
00154     // Get the music parameters
00155     stb_vorbis_info Infos = stb_vorbis_get_info(myStream);
00156     ChannelsCount = myChannelsCount = Infos.channels;
00157     SampleRate    = Infos.sample_rate;
00158     NbSamples     = static_cast<std::size_t>(stb_vorbis_stream_length_in_samples(myStream) * ChannelsCount);
00159
00160     return true;
00161 }
00162
00163
00167 std::size_t SoundFileOgg::Read(Int16* Data, std::size_t NbSamples)
00168 {
00169     if (myStream && Data && NbSamples)
00170     {
00171         int Read = stb_vorbis_get_samples_short_interleaved(myStream, myChannelsCount, Data, static_cast<int>(NbSamples));
00172         return static_cast<std::size_t>(Read * myChannelsCount);
00173     }
00174     else
00175     {
00176         return 0;
00177     }
00178 }
00179
00180 } // namespace priv
00181
00182 } // namespace sf


  • File List

SoundFileOgg.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SOUNDFILEOGG_HPP
00026 #define SFML_SOUNDFILEOGG_HPP
00027
00029 // Headers
00031 #include <SFML/Audio/SoundFile.hpp>
00032
00033 struct stb_vorbis;
00034
00035
00036 namespace sf
00037 {
00038 namespace priv
00039 {
00044 class SoundFileOgg : public SoundFile
00045 {
00046 public :
00047
00052     SoundFileOgg();
00053
00058     ~SoundFileOgg();
00059
00069     static bool IsFileSupported(const std::string& Filename, bool Read);
00070
00080     static bool IsFileSupported(const char* Data, std::size_t SizeInBytes);
00081
00086     virtual std::size_t Read(Int16* Data, std::size_t NbSamples);
00087
00088 private :
00089
00094     virtual bool OpenRead(const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
00095
00100     virtual bool OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
00101
00103     // Member data
00105     stb_vorbis*  myStream;
00106     unsigned int myChannelsCount;
00107 };
00108
00109 } // namespace priv
00110
00111 } // namespace sf
00112
00113
00114 #endif // SFML_SOUNDFILEOGG_HPP


  • File List

SoundRecorder.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Audio/SoundRecorder.hpp>
00029 #include <SFML/Audio/AudioDevice.hpp>
00030 #include <SFML/Audio/OpenAL.hpp>
00031 #include <SFML/System/Sleep.hpp>
00032 #include <iostream>
00033
00034
00036 // Private data
00038 namespace
00039 {
00040     ALCdevice* CaptureDevice = NULL;
00041 }
00042
00043 namespace sf
00044 {
00048 SoundRecorder::SoundRecorder() :
00049 mySampleRate (0),
00050 myIsCapturing(false)
00051 {
00052
00053 }
00054
00055
00059 SoundRecorder::~SoundRecorder()
00060 {
00061     // Nothing to do
00062 }
00063
00064
00069 void SoundRecorder::Start(unsigned int SampleRate)
00070 {
00071     // Check if the device can do audio capture
00072     if (!CanCapture())
00073     {
00074         std::cerr << "Failed to start capture : your system cannot capture audio data (call SoundRecorder::CanCapture to check it)" << std::endl;
00075         return;
00076     }
00077
00078     // Check that another capture is not already running
00079     if (CaptureDevice)
00080     {
00081         std::cerr << "Trying to start audio capture, but another capture is already running" << std::endl;
00082         return;
00083     }
00084
00085     // Open the capture device for capturing 16 bits mono samples
00086     CaptureDevice = alcCaptureOpenDevice(NULL, SampleRate, AL_FORMAT_MONO16, SampleRate);
00087     if (!CaptureDevice)
00088     {
00089         std::cerr << "Failed to open the audio capture device" << std::endl;
00090         return;
00091     }
00092
00093     // Clear the sample array
00094     mySamples.clear();
00095
00096     // Store the sample rate
00097     mySampleRate = SampleRate;
00098
00099     // Notify derived class
00100     if (OnStart())
00101     {
00102         // Start the capture
00103         alcCaptureStart(CaptureDevice);
00104
00105         // Start the capture in a new thread, to avoid blocking the main thread
00106         myIsCapturing = true;
00107         Launch();
00108     }
00109 }
00110
00111
00115 void SoundRecorder::Stop()
00116 {
00117     // Stop the capturing thread
00118     myIsCapturing = false;
00119     Wait();
00120 }
00121
00122
00126 unsigned int SoundRecorder::GetSampleRate() const
00127 {
00128     return mySampleRate;
00129 }
00130
00131
00136 bool SoundRecorder::CanCapture()
00137 {
00138     ALCdevice* Device = priv::AudioDevice::GetInstance().GetDevice();
00139
00140     return (alcIsExtensionPresent(Device, "ALC_EXT_CAPTURE") != AL_FALSE) ||
00141            (alcIsExtensionPresent(Device, "ALC_EXT_capture") != AL_FALSE); // "bug" in Mac OS X 10.5 and 10.6
00142 }
00143
00144
00148 bool SoundRecorder::OnStart()
00149 {
00150     // Nothing to do
00151     return true;
00152 }
00153
00154
00158 void SoundRecorder::OnStop()
00159 {
00160     // Nothing to do
00161 }
00162
00163
00167 void SoundRecorder::Run()
00168 {
00169     while (myIsCapturing)
00170     {
00171         // Process available samples
00172         ProcessCapturedSamples();
00173
00174         // Don't bother the CPU while waiting for more captured data
00175         Sleep(0.1f);
00176     }
00177
00178     // Capture is finished : clean up everything
00179     CleanUp();
00180
00181     // Notify derived class
00182     OnStop();
00183 }
00184
00185
00189 void SoundRecorder::ProcessCapturedSamples()
00190 {
00191     // Get the number of samples available
00192     ALCint SamplesAvailable;
00193     alcGetIntegerv(CaptureDevice, ALC_CAPTURE_SAMPLES, 1, &SamplesAvailable);
00194
00195     if (SamplesAvailable > 0)
00196     {
00197         // Get the recorded samples
00198         mySamples.resize(SamplesAvailable);
00199         alcCaptureSamples(CaptureDevice, &mySamples[0], SamplesAvailable);
00200
00201         // Forward them to the derived class
00202         if (!OnProcessSamples(&mySamples[0], mySamples.size()))
00203         {
00204             // The user wants to stop the capture
00205             myIsCapturing = false;
00206         }
00207     }
00208 }
00209
00210
00214 void SoundRecorder::CleanUp()
00215 {
00216     // Stop the capture
00217     alcCaptureStop(CaptureDevice);
00218
00219     // Get the samples left in the buffer
00220     ProcessCapturedSamples();
00221
00222     // Close the device
00223     alcCaptureCloseDevice(CaptureDevice);
00224     CaptureDevice = NULL;
00225 }
00226
00227 } // namespace sf


  • File List

SoundRecorder.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SOUNDRECORDER_HPP
00026 #define SFML_SOUNDRECORDER_HPP
00027
00029 // Headers
00031 #include <SFML/System/Thread.hpp>
00032 #include <vector>
00033
00034
00035 namespace sf
00036 {
00041 class SFML_API SoundRecorder : private Thread
00042 {
00043 public :
00044
00049     virtual ~SoundRecorder();
00050
00059     void Start(unsigned int SampleRate = 44100);
00060
00065     void Stop();
00066
00073     unsigned int GetSampleRate() const;
00074
00082     static bool CanCapture();
00083
00084 protected :
00085
00090     SoundRecorder();
00091
00092 private :
00093
00100     virtual bool OnStart();
00101
00111     virtual bool OnProcessSamples(const Int16* Samples, std::size_t SamplesCount) = 0;
00112
00117     virtual void OnStop();
00118
00123     virtual void Run();
00124
00129     void ProcessCapturedSamples();
00130
00135     void CleanUp();
00136
00138     // Member data
00140     std::vector<Int16> mySamples;
00141     unsigned int       mySampleRate;
00142     bool               myIsCapturing;
00143 };
00144
00145 } // namespace sf
00146
00147
00148 #endif // SFML_SOUNDRECORDER_HPP


  • File List

SoundStream.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Audio/SoundStream.hpp>
00029 #include <SFML/Audio/AudioDevice.hpp>
00030 #include <SFML/Audio/OpenAL.hpp>
00031 #include <SFML/System/Sleep.hpp>
00032
00033
00034 namespace sf
00035 {
00039 SoundStream::SoundStream() :
00040 myIsStreaming     (false),
00041 myChannelsCount   (0),
00042 mySampleRate      (0),
00043 myFormat          (0),
00044 myLoop            (false),
00045 mySamplesProcessed(0)
00046 {
00047
00048 }
00049
00050
00054 SoundStream::~SoundStream()
00055 {
00056     // Stop the sound if it was playing
00057     Stop();
00058 }
00059
00060
00064 void SoundStream::Initialize(unsigned int ChannelsCount, unsigned int SampleRate)
00065 {
00066     myChannelsCount = ChannelsCount;
00067     mySampleRate    = SampleRate;
00068
00069     // Deduce the format from the number of channels
00070     myFormat = priv::AudioDevice::GetInstance().GetFormatFromChannelsCount(ChannelsCount);
00071
00072     // Check if the format is valid
00073     if (myFormat == 0)
00074     {
00075         myChannelsCount = 0;
00076         mySampleRate    = 0;
00077         std::cerr << "Unsupported number of channels (" << myChannelsCount << ")" << std::endl;
00078     }
00079 }
00080
00081
00085 void SoundStream::Play()
00086 {
00087     // Check if the sound parameters have been set
00088     if (myFormat == 0)
00089     {
00090         std::cerr << "Failed to play audio stream : sound parameters have not been initialized (call Initialize first)" << std::endl;
00091         return;
00092     }
00093
00094     // If the sound is already playing (probably paused), just resume it
00095     if (myIsStreaming)
00096     {
00097         Sound::Play();
00098         return;
00099     }
00100
00101     // Notify the derived class
00102     if (OnStart())
00103     {
00104         // Start updating the stream in a separate thread to avoid blocking the application
00105         mySamplesProcessed = 0;
00106         myIsStreaming = true;
00107         Launch();
00108     }
00109 }
00110
00111
00115 void SoundStream::Stop()
00116 {
00117     // Wait for the thread to terminate
00118     myIsStreaming = false;
00119     Wait();
00120 }
00121
00122
00126 unsigned int SoundStream::GetChannelsCount() const
00127 {
00128     return myChannelsCount;
00129 }
00130
00131
00135 unsigned int SoundStream::GetSampleRate() const
00136 {
00137     return mySampleRate;
00138 }
00139
00140
00144 Sound::Status SoundStream::GetStatus() const
00145 {
00146     Status Status = Sound::GetStatus();
00147
00148     // To compensate for the lag between Play() and alSourcePlay()
00149     if ((Status == Stopped) && myIsStreaming)
00150         Status = Playing;
00151
00152     return Status;
00153 }
00154
00155
00162 float SoundStream::GetPlayingOffset() const
00163 {
00164     return Sound::GetPlayingOffset() + static_cast<float>(mySamplesProcessed) / mySampleRate / myChannelsCount;
00165 }
00166
00167
00171 void SoundStream::SetLoop(bool Loop)
00172 {
00173     myLoop = Loop;
00174 }
00175
00176
00180 bool SoundStream::GetLoop() const
00181 {
00182     return myLoop;
00183 }
00184
00185
00189 void SoundStream::Run()
00190 {
00191     // Create the buffers
00192     ALCheck(alGenBuffers(BuffersCount, myBuffers));
00193     for (int i = 0; i < BuffersCount; ++i)
00194         myEndBuffers[i] = false;
00195
00196     // Fill the queue
00197     bool RequestStop = FillQueue();
00198
00199     // Play the sound
00200     Sound::Play();
00201
00202     while (myIsStreaming)
00203     {
00204         // The stream has been interrupted !
00205         if (Sound::GetStatus() == Stopped)
00206         {
00207             if (!RequestStop)
00208             {
00209                 // Just continue
00210                 Sound::Play();
00211             }
00212             else
00213             {
00214                 // End streaming
00215                 myIsStreaming = false;
00216             }
00217         }
00218
00219         // Get the number of buffers that have been processed (ie. ready for reuse)
00220         ALint NbProcessed;
00221         ALCheck(alGetSourcei(Sound::mySource, AL_BUFFERS_PROCESSED, &NbProcessed));
00222
00223         while (NbProcessed--)
00224         {
00225             // Pop the first unused buffer from the queue
00226             ALuint Buffer;
00227             ALCheck(alSourceUnqueueBuffers(Sound::mySource, 1, &Buffer));
00228
00229             // Find its number
00230             unsigned int BufferNum = 0;
00231             for (int i = 0; i < BuffersCount; ++i)
00232                 if (myBuffers[i] == Buffer)
00233                 {
00234                     BufferNum = i;
00235                     break;
00236                 }
00237
00238             // Retrieve its size and add it to the samples count
00239             if (myEndBuffers[BufferNum])
00240             {
00241                 // This was the last buffer: reset the sample count
00242                 mySamplesProcessed = 0;
00243                 myEndBuffers[BufferNum] = false;
00244             }
00245             else
00246             {
00247                 ALint Size;
00248                 ALCheck(alGetBufferi(Buffer, AL_SIZE, &Size));
00249                 mySamplesProcessed += Size / sizeof(Int16);
00250             }
00251
00252             // Fill it and push it back into the playing queue
00253             if (!RequestStop)
00254             {
00255                 if (FillAndPushBuffer(BufferNum))
00256                     RequestStop = true;
00257             }
00258         }
00259
00260         // Leave some time for the other threads if the stream is still playing
00261         if (Sound::GetStatus() != Stopped)
00262             Sleep(0.1f);
00263     }
00264
00265     // Stop the playback
00266     Sound::Stop();
00267
00268     // Unqueue any buffer left in the queue
00269     ClearQueue();
00270
00271     // Delete the buffers
00272     ALCheck(alSourcei(Sound::mySource, AL_BUFFER, 0));
00273     ALCheck(alDeleteBuffers(BuffersCount, myBuffers));
00274 }
00275
00276
00281 bool SoundStream::FillAndPushBuffer(unsigned int BufferNum)
00282 {
00283     bool RequestStop = false;
00284
00285     // Acquire audio data
00286     Chunk Data = {NULL, 0};
00287     if (!OnGetData(Data))
00288     {
00289         // Mark the buffer as the last one (so that we know when to reset the playing position)
00290         myEndBuffers[BufferNum] = true;
00291
00292         // Check if the stream must loop or stop
00293         if (myLoop && OnStart())
00294         {
00295             // If we succeeded to restart and we previously had no data, try to fill the buffer once again
00296             if (!Data.Samples || (Data.NbSamples == 0))
00297             {
00298                 return FillAndPushBuffer(BufferNum);
00299             }
00300         }
00301         else
00302         {
00303             // Not looping or restart failed: request stop
00304             RequestStop = true;
00305         }
00306     }
00307
00308     // Fill the buffer if some data was returned
00309     if (Data.Samples && Data.NbSamples)
00310     {
00311         unsigned int Buffer = myBuffers[BufferNum];
00312
00313         // Fill the buffer
00314         ALsizei Size = static_cast<ALsizei>(Data.NbSamples) * sizeof(Int16);
00315         ALCheck(alBufferData(Buffer, myFormat, Data.Samples, Size, mySampleRate));
00316
00317         // Push it into the sound queue
00318         ALCheck(alSourceQueueBuffers(Sound::mySource, 1, &Buffer));
00319     }
00320
00321     return RequestStop;
00322 }
00323
00324
00328 bool SoundStream::FillQueue()
00329 {
00330     // Fill and enqueue all the available buffers
00331     bool RequestStop = false;
00332     for (int i = 0; (i < BuffersCount) && !RequestStop; ++i)
00333     {
00334         if (FillAndPushBuffer(i))
00335             RequestStop = true;
00336     }
00337
00338     return RequestStop;
00339 }
00340
00341
00345 void SoundStream::ClearQueue()
00346 {
00347     // Get the number of buffers still in the queue
00348     ALint NbQueued;
00349     ALCheck(alGetSourcei(Sound::mySource, AL_BUFFERS_QUEUED, &NbQueued));
00350
00351     // Unqueue them all
00352     ALuint Buffer;
00353     for (ALint i = 0; i < NbQueued; ++i)
00354         ALCheck(alSourceUnqueueBuffers(Sound::mySource, 1, &Buffer));
00355 }
00356
00357
00361 bool SoundStream::OnStart()
00362 {
00363     // Does nothing by default
00364
00365     return true;
00366 }
00367
00368 } // namespace sf


  • File List

SoundStream.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SOUNDSTREAM_HPP
00026 #define SFML_SOUNDSTREAM_HPP
00027
00029 // Headers
00031 #include <SFML/Audio/Sound.hpp>
00032 #include <SFML/System/Thread.hpp>
00033 #include <cstdlib>
00034
00035
00036 namespace sf
00037 {
00044 class SFML_API SoundStream : private Thread, private Sound
00045 {
00046 public :
00047
00048     using Sound::Status;
00049     using Sound::Stopped;
00050     using Sound::Paused;
00051     using Sound::Playing;
00052     using Sound::Pause;
00053     using Sound::SetPitch;
00054     using Sound::SetVolume;
00055     using Sound::SetPosition;
00056     using Sound::SetRelativeToListener;
00057     using Sound::SetMinDistance;
00058     using Sound::SetAttenuation;
00059     using Sound::GetPitch;
00060     using Sound::GetVolume;
00061     using Sound::GetPosition;
00062     using Sound::IsRelativeToListener;
00063     using Sound::GetMinDistance;
00064     using Sound::GetAttenuation;
00065
00069     struct Chunk
00070     {
00071         const Int16* Samples;
00072         std::size_t  NbSamples;
00073     };
00074
00079     virtual ~SoundStream();
00080
00085     void Play();
00086
00091     void Stop();
00092
00099     unsigned int GetChannelsCount() const;
00100
00107     unsigned int GetSampleRate() const;
00108
00115     Status GetStatus() const;
00116
00123     float GetPlayingOffset() const;
00124
00132     void SetLoop(bool Loop);
00133
00140     bool GetLoop() const;
00141
00142 protected :
00143
00148     SoundStream();
00149
00157     void Initialize(unsigned int ChannelsCount, unsigned int SampleRate);
00158
00159 private :
00160
00165     virtual void Run();
00166
00173     virtual bool OnStart();
00174
00183     virtual bool OnGetData(Chunk& Data) = 0;
00184
00194     bool FillAndPushBuffer(unsigned int BufferNum);
00195
00202     bool FillQueue();
00203
00208     void ClearQueue();
00209
00210     enum {BuffersCount = 3};
00211
00213     // Member data
00215     bool          myIsStreaming;
00216     unsigned int  myBuffers[BuffersCount];
00217     unsigned int  myChannelsCount;
00218     unsigned int  mySampleRate;
00219     unsigned long myFormat;
00220     bool          myLoop;
00221     unsigned int  mySamplesProcessed;
00222     bool          myEndBuffers[BuffersCount];
00223 };
00224
00225 } // namespace sf
00226
00227
00228 #endif // SFML_SOUNDSTREAM_HPP


  • File List

Sprite.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Graphics/Sprite.hpp>
00029 #include <SFML/Graphics/Image.hpp>
00030 #include <SFML/Graphics/GraphicsContext.hpp>
00031
00032
00033 namespace sf
00034 {
00038 Sprite::Sprite() :
00039 mySubRect   (0, 0, 1, 1),
00040 myIsFlippedX(false),
00041 myIsFlippedY(false)
00042 {
00043
00044 }
00045
00046
00050 Sprite::Sprite(const Image& Img, const Vector2f& Position, const Vector2f& Scale, float Rotation, const Color& Col) :
00051 Drawable    (Position, Scale, Rotation, Col),
00052 mySubRect   (0, 0, 1, 1),
00053 myIsFlippedX(false),
00054 myIsFlippedY(false)
00055 {
00056     SetImage(Img);
00057 }
00058
00059
00063 void Sprite::SetImage(const Image& Img)
00064 {
00065     // If there was no source image before and the new image is valid, adjust the source rectangle
00066     if (!myImage && (Img.GetWidth() > 0) && (Img.GetHeight() > 0))
00067     {
00068         SetSubRect(IntRect(0, 0, Img.GetWidth(), Img.GetHeight()));
00069     }
00070
00071     // Assign the new image
00072     myImage = &Img;
00073 }
00074
00075
00079 void Sprite::SetSubRect(const IntRect& SubRect)
00080 {
00081     mySubRect = SubRect;
00082 }
00083
00084
00089 void Sprite::Resize(float Width, float Height)
00090 {
00091     int LocalWidth  = mySubRect.GetWidth();
00092     int LocalHeight = mySubRect.GetHeight();
00093
00094     if ((LocalWidth > 0) && (LocalHeight > 0))
00095         SetScale(Width / LocalWidth, Height / LocalHeight);
00096 }
00097
00098
00103 void Sprite::Resize(const Vector2f& Size)
00104 {
00105     Resize(Size.x, Size.y);
00106 }
00107
00108
00112 void Sprite::FlipX(bool Flipped)
00113 {
00114     myIsFlippedX = Flipped;
00115 }
00116
00117
00121 void Sprite::FlipY(bool Flipped)
00122 {
00123     myIsFlippedY = Flipped;
00124 }
00125
00126
00130 const Image* Sprite::GetImage() const
00131 {
00132     return myImage;
00133 }
00134
00135
00139 const IntRect& Sprite::GetSubRect() const
00140 {
00141     return mySubRect;
00142 }
00143
00144
00148 Vector2f Sprite::GetSize() const
00149 {
00150     return Vector2f(mySubRect.GetWidth() * GetScale().x, mySubRect.GetHeight() * GetScale().y);
00151 }
00152
00153
00158 Color Sprite::GetPixel(unsigned int X, unsigned int Y) const
00159 {
00160     if (myImage)
00161     {
00162         unsigned int ImageX = mySubRect.Left + X;
00163         unsigned int ImageY = mySubRect.Top  + Y;
00164
00165         if (myIsFlippedX) ImageX = mySubRect.GetWidth()  - ImageX - 1;
00166         if (myIsFlippedY) ImageY = mySubRect.GetHeight() - ImageY - 1;
00167
00168         return myImage->GetPixel(ImageX, ImageY) * GetColor();
00169     }
00170     else
00171     {
00172         return GetColor();
00173     }
00174 }
00175
00176
00180 void Sprite::Render(RenderTarget&) const
00181 {
00182     // Get the sprite size
00183     float Width  = static_cast<float>(mySubRect.GetWidth());
00184     float Height = static_cast<float>(mySubRect.GetHeight());
00185
00186     // Check if the image is valid
00187     if (myImage && (myImage->GetWidth() > 0) && (myImage->GetHeight() > 0))
00188     {
00189         // Use the "offset trick" to get pixel-perfect rendering
00190         // see http://www.opengl.org/resources/faq/technical/transformations.htm#tran0030
00191         GLCheck(glTranslatef(0.375f, 0.375f, 0.f));
00192
00193         // Bind the texture
00194         myImage->Bind();
00195
00196         // Calculate the texture coordinates
00197         FloatRect TexCoords = myImage->GetTexCoords(mySubRect);
00198         FloatRect Rect(myIsFlippedX ? TexCoords.Right  : TexCoords.Left,
00199                        myIsFlippedY ? TexCoords.Bottom : TexCoords.Top,
00200                        myIsFlippedX ? TexCoords.Left   : TexCoords.Right,
00201                        myIsFlippedY ? TexCoords.Top    : TexCoords.Bottom);
00202
00203         // Draw the sprite's triangles
00204         glBegin(GL_QUADS);
00205             glTexCoord2f(Rect.Left,  Rect.Top);    glVertex2f(0,     0);
00206             glTexCoord2f(Rect.Left,  Rect.Bottom); glVertex2f(0,     Height);
00207             glTexCoord2f(Rect.Right, Rect.Bottom); glVertex2f(Width, Height);
00208             glTexCoord2f(Rect.Right, Rect.Top);    glVertex2f(Width, 0) ;
00209         glEnd();
00210     }
00211     else
00212     {
00213         // Disable texturing
00214         GLCheck(glDisable(GL_TEXTURE_2D));
00215
00216         // Draw the sprite's triangles
00217         glBegin(GL_QUADS);
00218             glVertex2f(0,     0);
00219             glVertex2f(0,     Height);
00220             glVertex2f(Width, Height);
00221             glVertex2f(Width, 0);
00222         glEnd();
00223     }
00224 }
00225
00226 } // namespace sf


  • File List

Sprite.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SPRITE_HPP
00026 #define SFML_SPRITE_HPP
00027
00029 // Headers
00031 #include <SFML/System/Resource.hpp>
00032 #include <SFML/Graphics/Drawable.hpp>
00033 #include <SFML/Graphics/Rect.hpp>
00034
00035
00036 namespace sf
00037 {
00038 class Image;
00039
00044 class SFML_API Sprite : public Drawable
00045 {
00046 public :
00047
00052     Sprite();
00053
00064     explicit Sprite(const Image& Img, const Vector2f& Position = Vector2f(0, 0), const Vector2f& Scale = Vector2f(1, 1), float Rotation = 0.f, const Color& Col = Color(255, 255, 255, 255));
00065
00072     void SetImage(const Image& Img);
00073
00081     void SetSubRect(const IntRect& SubRect);
00082
00091     void Resize(float Width, float Height);
00092
00100     void Resize(const Vector2f& Size);
00101
00108     void FlipX(bool Flipped);
00109
00116     void FlipY(bool Flipped);
00117
00124     const Image* GetImage() const;
00125
00132     const IntRect& GetSubRect() const;
00133
00140     Vector2f GetSize() const;
00141
00152     Color GetPixel(unsigned int X, unsigned int Y) const;
00153
00154 protected :
00155
00160     virtual void Render(RenderTarget& Target) const;
00161
00162 private :
00163
00165     // Member data
00167     ResourcePtr<Image> myImage;
00168     IntRect            mySubRect;
00169     bool               myIsFlippedX;
00170     bool               myIsFlippedY;
00171 };
00172
00173 } // namespace sf
00174
00175
00176 #endif // SFML_SPRITE_HPP


  • File List

String.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Graphics/String.hpp>
00029 #include <SFML/Graphics/Image.hpp>
00030 #include <SFML/Graphics/GraphicsContext.hpp>
00031 #include <locale>
00032
00033
00034 namespace sf
00035 {
00039 String::String() :
00040 myFont          (&Font::GetDefaultFont()),
00041 mySize          (30.f),
00042 myStyle         (Regular),
00043 myNeedRectUpdate(true)
00044 {
00045
00046 }
00047
00048
00052 String::String(const Unicode::Text& Text, const Font& CharFont, float Size) :
00053 myFont          (&CharFont),
00054 mySize          (Size),
00055 myStyle         (Regular),
00056 myNeedRectUpdate(true)
00057 {
00058     SetText(Text);
00059 }
00060
00061
00065 void String::SetText(const Unicode::Text& Text)
00066 {
00067     myNeedRectUpdate = true;
00068     myText = Text;
00069 }
00070
00071
00075 void String::SetFont(const Font& CharFont)
00076 {
00077     if (myFont != &CharFont)
00078     {
00079         myNeedRectUpdate = true;
00080         myFont = &CharFont;
00081     }
00082 }
00083
00084
00088 void String::SetSize(float Size)
00089 {
00090     if (mySize != Size)
00091     {
00092         myNeedRectUpdate = true;
00093         mySize = Size;
00094     }
00095 }
00096
00097
00102 void String::SetStyle(unsigned long TextStyle)
00103 {
00104     if (myStyle != TextStyle)
00105     {
00106         myNeedRectUpdate = true;
00107         myStyle = TextStyle;
00108     }
00109 }
00110
00111
00115 const Unicode::Text& String::GetText() const
00116 {
00117     return myText;
00118 }
00119
00120
00124 const Font& String::GetFont() const
00125 {
00126     return *myFont;
00127 }
00128
00129
00133 float String::GetSize() const
00134 {
00135     return mySize;
00136 }
00137
00138
00142 unsigned long String::GetStyle() const
00143 {
00144     return myStyle;
00145 }
00146
00147
00153 sf::Vector2f String::GetCharacterPos(std::size_t Index) const
00154 {
00155     // First get the UTF32 representation of the text
00156     const Unicode::UTF32String& Text = myText;
00157
00158     // Adjust the index if it's out of range
00159     if (Index > Text.length())
00160         Index = Text.length();
00161
00162     // The final size is based on the text size
00163     float FactorX  = mySize / myFont->GetCharacterSize();
00164     float AdvanceY = mySize;
00165
00166     // Compute the position
00167     sf::Vector2f Position;
00168     for (std::size_t i = 0; i < Index; ++i)
00169     {
00170         // Get the current character and its corresponding glyph
00171         Uint32       CurChar  = Text[i];
00172         const Glyph& CurGlyph = myFont->GetGlyph(CurChar);
00173         float        AdvanceX = CurGlyph.Advance * FactorX;
00174
00175         switch (CurChar)
00176         {
00177             // Handle special characters
00178             case L' ' :  Position.x += AdvanceX;                 break;
00179             case L'\t' : Position.x += AdvanceX * 4;             break;
00180             case L'\v' : Position.y += AdvanceY * 4;             break;
00181             case L'\n' : Position.y += AdvanceY; Position.x = 0; break;
00182
00183             // Regular character : just add its advance value
00184             default : Position.x += AdvanceX; break;
00185         }
00186     }
00187
00188     return Position;
00189 }
00190
00191
00195 FloatRect String::GetRect() const
00196 {
00197     if (myNeedRectUpdate)
00198         const_cast<String*>(this)->RecomputeRect();
00199
00200     FloatRect Rect;
00201     Rect.Left   = (myBaseRect.Left   - GetCenter().x) * GetScale().x + GetPosition().x;
00202     Rect.Top    = (myBaseRect.Top    - GetCenter().y) * GetScale().y + GetPosition().y;
00203     Rect.Right  = (myBaseRect.Right  - GetCenter().x) * GetScale().x + GetPosition().x;
00204     Rect.Bottom = (myBaseRect.Bottom - GetCenter().y) * GetScale().y + GetPosition().y;
00205
00206     return Rect;
00207 }
00208
00209
00213 void String::Render(RenderTarget&) const
00214 {
00215     // First get the internal UTF-32 string of the text
00216     const Unicode::UTF32String& Text = myText;
00217
00218     // No text, no rendering :)
00219     if (Text.empty())
00220         return;
00221
00222     // Set the scaling factor to get the actual size
00223     float CharSize =  static_cast<float>(myFont->GetCharacterSize());
00224     float Factor   = mySize / CharSize;
00225     GLCheck(glScalef(Factor, Factor, 1.f));
00226
00227     // Bind the font texture
00228     myFont->GetImage().Bind();
00229
00230     // Initialize the rendering coordinates
00231     float X = 0.f;
00232     float Y = CharSize;
00233
00234     // Holds the lines to draw later, for underlined style
00235     std::vector<float> UnderlineCoords;
00236     UnderlineCoords.reserve(16);
00237
00238     // Compute the shearing to apply if we're using the italic style
00239     float ItalicCoeff = (myStyle & Italic) ? 0.208f : 0.f; // 12 degrees
00240
00241     // Draw one quad for each character
00242     glBegin(GL_QUADS);
00243     for (std::size_t i = 0; i < Text.size(); ++i)
00244     {
00245         // Get the current character and its corresponding glyph
00246         Uint32           CurChar  = Text[i];
00247         const Glyph&     CurGlyph = myFont->GetGlyph(CurChar);
00248         int              Advance  = CurGlyph.Advance;
00249         const IntRect&   Rect     = CurGlyph.Rectangle;
00250         const FloatRect& Coord    = CurGlyph.TexCoords;
00251
00252         // If we're using the underlined style and there's a new line,
00253         // we keep track of the previous line to draw it later
00254         if ((CurChar == L'\n') && (myStyle & Underlined))
00255         {
00256             UnderlineCoords.push_back(X);
00257             UnderlineCoords.push_back(Y + 2);
00258         }
00259
00260         // Handle special characters
00261         switch (CurChar)
00262         {
00263             case L' ' :  X += Advance;         continue;
00264             case L'\n' : Y += CharSize; X = 0; continue;
00265             case L'\t' : X += Advance  * 4;    continue;
00266             case L'\v' : Y += CharSize * 4;    continue;
00267         }
00268
00269         // Draw a textured quad for the current character
00270         glTexCoord2f(Coord.Left,  Coord.Top);    glVertex2f(X + Rect.Left  - ItalicCoeff * Rect.Top,    Y + Rect.Top);
00271         glTexCoord2f(Coord.Left,  Coord.Bottom); glVertex2f(X + Rect.Left  - ItalicCoeff * Rect.Bottom, Y + Rect.Bottom);
00272         glTexCoord2f(Coord.Right, Coord.Bottom); glVertex2f(X + Rect.Right - ItalicCoeff * Rect.Bottom, Y + Rect.Bottom);
00273         glTexCoord2f(Coord.Right, Coord.Top);    glVertex2f(X + Rect.Right - ItalicCoeff * Rect.Top,    Y + Rect.Top);
00274
00275         // If we're using the bold style, we must render the character 4 more times,
00276         // slightly offseted, to simulate a higher weight
00277         if (myStyle & Bold)
00278         {
00279             static const float OffsetsX[] = {-0.5f, 0.5f, 0.f, 0.f};
00280             static const float OffsetsY[] = {0.f, 0.f, -0.5f, 0.5f};
00281
00282             for (int j = 0; j < 4; ++j)
00283             {
00284                 glTexCoord2f(Coord.Left,  Coord.Top);    glVertex2f(X + OffsetsX[j] + Rect.Left  - ItalicCoeff * Rect.Top,    Y + OffsetsY[j] + Rect.Top);
00285                 glTexCoord2f(Coord.Left,  Coord.Bottom); glVertex2f(X + OffsetsX[j] + Rect.Left  - ItalicCoeff * Rect.Bottom, Y + OffsetsY[j] + Rect.Bottom);
00286                 glTexCoord2f(Coord.Right, Coord.Bottom); glVertex2f(X + OffsetsX[j] + Rect.Right - ItalicCoeff * Rect.Bottom, Y + OffsetsY[j] + Rect.Bottom);
00287                 glTexCoord2f(Coord.Right, Coord.Top);    glVertex2f(X + OffsetsX[j] + Rect.Right - ItalicCoeff * Rect.Top,    Y + OffsetsY[j] + Rect.Top);
00288             }
00289         }
00290
00291         // Advance to the next character
00292         X += Advance;
00293     }
00294     glEnd();
00295
00296     // Draw the underlines if needed
00297     if (myStyle & Underlined)
00298     {
00299         // Compute the line thickness
00300         float Thickness = (myStyle & Bold) ? 3.f : 2.f;
00301
00302         // Add the last line (which was not finished with a \n)
00303         UnderlineCoords.push_back(X);
00304         UnderlineCoords.push_back(Y + 2);
00305
00306         // Draw the underlines as quads
00307         GLCheck(glDisable(GL_TEXTURE_2D));
00308         glBegin(GL_QUADS);
00309         for (std::size_t i = 0; i < UnderlineCoords.size(); i += 2)
00310         {
00311             glVertex2f(0,                  UnderlineCoords[i + 1]);
00312             glVertex2f(0,                  UnderlineCoords[i + 1] + Thickness);
00313             glVertex2f(UnderlineCoords[i], UnderlineCoords[i + 1] + Thickness);
00314             glVertex2f(UnderlineCoords[i], UnderlineCoords[i + 1]);
00315         }
00316         glEnd();
00317     }
00318 }
00319
00320
00324 void String::RecomputeRect()
00325 {
00326     // First get the internal UTF-32 string of the text
00327     const Unicode::UTF32String& Text = myText;
00328
00329     // Reset the "need update" state
00330     myNeedRectUpdate = false;
00331
00332     // No text, empty box :)
00333     if (Text.empty())
00334     {
00335         myBaseRect = FloatRect(0, 0, 0, 0);
00336         return;
00337     }
00338
00339     // Initial values
00340     float CurWidth  = 0;
00341     float CurHeight = 0;
00342     float Width     = 0;
00343     float Height    = 0;
00344     float Factor    = mySize / myFont->GetCharacterSize();
00345
00346     // Go through each character
00347     for (std::size_t i = 0; i < Text.size(); ++i)
00348     {
00349         // Get the current character and its corresponding glyph
00350         Uint32         CurChar  = Text[i];
00351         const Glyph&   CurGlyph = myFont->GetGlyph(CurChar);
00352         float          Advance  = CurGlyph.Advance * Factor;
00353         const IntRect& Rect     = CurGlyph.Rectangle;
00354
00355         // Handle special characters
00356         switch (CurChar)
00357         {
00358             case L' ' :  CurWidth += Advance;                    continue;
00359             case L'\t' : CurWidth += Advance * 4;                continue;
00360             case L'\v' : Height   += mySize  * 4; CurHeight = 0; continue;
00361
00362             case L'\n' :
00363                 Height += mySize;
00364                 CurHeight = 0;
00365                 if (CurWidth > Width)
00366                     Width = CurWidth;
00367                 CurWidth = 0;
00368                 continue;
00369         }
00370
00371         // Advance to the next character
00372         CurWidth += Advance;
00373
00374         // Update the maximum height
00375         float CharHeight = (myFont->GetCharacterSize() + Rect.Bottom) * Factor;
00376         if (CharHeight > CurHeight)
00377             CurHeight = CharHeight;
00378     }
00379
00380     // Update the last line
00381     if (CurWidth > Width)
00382         Width = CurWidth;
00383     Height += CurHeight;
00384
00385     // Add a slight width / height if we're using the bold style
00386     if (myStyle & Bold)
00387     {
00388         Width  += 1 * Factor;
00389         Height += 1 * Factor;
00390     }
00391
00392     // Add a slight width if we're using the italic style
00393     if (myStyle & Italic)
00394     {
00395         Width += 0.208f * mySize;
00396     }
00397
00398     // Add a slight height if we're using the underlined style
00399     if (myStyle & Underlined)
00400     {
00401         if (CurHeight < mySize + 4 * Factor)
00402             Height += 4 * Factor;
00403     }
00404
00405     // Finally update the rectangle
00406     myBaseRect.Left   = 0;
00407     myBaseRect.Top    = 0;
00408     myBaseRect.Right  = Width;
00409     myBaseRect.Bottom = Height;
00410 }
00411
00412 } // namespace sf


  • File List

String.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_STRING_HPP
00026 #define SFML_STRING_HPP
00027
00029 // Headers
00031 #include <SFML/System/Resource.hpp>
00032 #include <SFML/System/Unicode.hpp>
00033 #include <SFML/Graphics/Drawable.hpp>
00034 #include <SFML/Graphics/Font.hpp>
00035 #include <SFML/Graphics/Rect.hpp>
00036 #include <string>
00037
00038
00039 namespace sf
00040 {
00044 class SFML_API String : public Drawable
00045 {
00046 public :
00047
00051     enum Style
00052     {
00053         Regular    = 0,
00054         Bold       = 1 << 0,
00055         Italic     = 1 << 1,
00056         Underlined = 1 << 2
00057     };
00058
00063     String();
00064
00073     explicit String(const Unicode::Text& Text, const Font& CharFont = Font::GetDefaultFont(), float Size = 30.f);
00074
00081     void SetText(const Unicode::Text& Text);
00082
00089     void SetFont(const Font& CharFont);
00090
00098     void SetSize(float Size);
00099
00107     void SetStyle(unsigned long TextStyle);
00108
00115     const Unicode::Text& GetText() const;
00116
00123     const Font& GetFont() const;
00124
00131     float GetSize() const;
00132
00139     unsigned long GetStyle() const;
00140
00151     sf::Vector2f GetCharacterPos(std::size_t Index) const;
00152
00159     FloatRect GetRect() const;
00160
00161 protected :
00162
00167     virtual void Render(RenderTarget& Target) const;
00168
00169 private :
00170
00175     void RecomputeRect();
00176
00178     // Member data
00180     Unicode::Text     myText;
00181     ResourcePtr<Font> myFont;
00182     float             mySize;
00183     unsigned long     myStyle;
00184     FloatRect         myBaseRect;
00185     bool              myNeedRectUpdate;
00186 };
00187
00188 } // namespace sf
00189
00190
00191 #endif // SFML_STRING_HPP


  • File List

System.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SYSTEM_HPP
00026 #define SFML_SYSTEM_HPP
00027
00029 // Headers
00031
00032 #include <SFML/Config.hpp>
00033 #include <SFML/System/Clock.hpp>
00034 #include <SFML/System/Lock.hpp>
00035 #include <SFML/System/Mutex.hpp>
00036 #include <SFML/System/Randomizer.hpp>
00037 #include <SFML/System/Sleep.hpp>
00038 #include <SFML/System/Thread.hpp>
00039 #include <SFML/System/Unicode.hpp>
00040 #include <SFML/System/Vector2.hpp>
00041 #include <SFML/System/Vector3.hpp>
00042
00043 #endif // SFML_SYSTEM_HPP


  • File List

Joystick.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/xxx/Joystick.hpp>
00029
00030
00031 namespace sf
00032 {
00033 namespace priv
00034 {
00038 void Joystick::Initialize(unsigned int Index)
00039 {
00040     // Reset the joystick state
00041
00042     // Initialize the Index-th available joystick
00043 }
00044
00045
00049 JoystickState Joystick::UpdateState()
00050 {
00051     // Fill a JoystickState instance with the current joystick state
00052 }
00053
00054
00058 unsigned int Joystick::GetAxesCount() const
00059 {
00060     // Return number of supported axes
00061 }
00062
00063
00067 unsigned int Joystick::GetButtonsCount() const
00068 {
00069     // Return number of supported buttons
00070 }
00071
00072 } // namespace priv
00073
00074 } // namespace sf


  • File List

Joystick.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_JOYSTICKXXX_HPP
00026 #define SFML_JOYSTICKXXX_HPP
00027
00029 // Headers
00031
00032
00033 namespace sf
00034 {
00035 namespace priv
00036 {
00040 class Joystick
00041 {
00042 public :
00043
00050     void Initialize(unsigned int Index);
00051
00058     JoystickState UpdateState();
00059
00066     unsigned int GetAxesCount() const;
00067
00074     unsigned int GetButtonsCount() const;
00075 };
00076
00077 } // namespace priv
00078
00079 } // namespace sf
00080
00081
00082 #endif // SFML_JOYSTICKXXX_HPP


  • File List

VideoModeSupport.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Window/XXX/VideoModeSupport.hpp>
00029
00030
00031 namespace sf
00032 {
00033 namespace priv
00034 {
00038 void VideoModeSupport::GetSupportedVideoModes(std::vector<VideoMode>& Modes)
00039 {
00040     // Get all the supported fullscreen modes and put them in Modes array
00041
00042     // Just care about width, height and bpp (ignore frequency and other attributes)
00043
00044     // You must remove duplicates
00045
00046     // Order doesn't matter (the array will be sorted later)
00047 }
00048
00049
00053 VideoMode VideoModeSupport::GetDesktopVideoMode()
00054 {
00055     // Return the current desktop video mode
00056 }
00057
00058 } // namespace priv
00059
00060 } // namespace sf


  • File List

VideoModeSupport.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_VIDEOMODESUPPORTXXX_HPP
00026 #define SFML_VIDEOMODESUPPORTXXX_HPP
00027
00029 // Headers
00031 #include <SFML/Window/VideoMode.hpp>
00032 #include <vector>
00033
00034
00035 namespace sf
00036 {
00037 namespace priv
00038 {
00043 class VideoModeSupport
00044 {
00045 public :
00046
00053     static void GetSupportedVideoModes(std::vector<VideoMode>& Modes);
00054
00061     static VideoMode GetDesktopVideoMode();
00062 };
00063
00064 } // namespace priv
00065
00066 } // namespace sf
00067
00068
00069 #endif // SFML_VIDEOMODESUPPORTXXX_HPP


  • File List

Thread.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/System/Win32/Thread.hpp>
00029 #include <process.h>
00030 #include <iostream>
00031
00032
00033 namespace sf
00034 {
00038 Thread::Thread() :
00039 myHandle  (NULL),
00040 myFunction(NULL),
00041 myUserData(NULL)
00042 {
00043
00044 }
00045
00046
00050 Thread::Thread(Thread::FuncType Function, void* UserData) :
00051 myHandle  (NULL),
00052 myFunction(Function),
00053 myUserData(UserData)
00054 {
00055
00056 }
00057
00058
00062 Thread::~Thread()
00063 {
00064     // Wait for the thread to finish before destroying the instance
00065     Wait();
00066 }
00067
00068
00072 void Thread::Launch()
00073 {
00074     // Wait for the thread to finish, in case it was already running
00075     Wait();
00076
00077     // Create the thread
00078     myHandle = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &Thread::ThreadFunc, this, 0, NULL));
00079
00080     // Error ?
00081     if (myHandle == NULL)
00082         std::cerr << "Failed to create thread" << std::endl;
00083 }
00084
00085
00089 void Thread::Wait()
00090 {
00091     if (myHandle)
00092     {
00093         // Wait for the thread to finish, no timeout
00094         WaitForSingleObject(myHandle, INFINITE);
00095
00096         // Don't forget to close the thread handle (__endthreadex doesn't do it)
00097         CloseHandle(myHandle);
00098         myHandle = NULL;
00099     }
00100 }
00101
00102
00109 void Thread::Terminate()
00110 {
00111     if (myHandle)
00112     {
00113         TerminateThread(myHandle, 0);
00114         myHandle = NULL;
00115     }
00116 }
00117
00118
00122 void Thread::Run()
00123 {
00124     if (myFunction)
00125         myFunction(myUserData);
00126 }
00127
00128
00132 unsigned int __stdcall Thread::ThreadFunc(void* UserData)
00133 {
00134     // The Thread instance is stored in the user data
00135     Thread* ThreadInstance = reinterpret_cast<Thread*>(UserData);
00136
00137     // Forward to the instance
00138     ThreadInstance->Run();
00139
00140     // Optional, but it is cleaner
00141     _endthreadex(0);
00142
00143     return 0;
00144 }
00145
00146 } // namespace sf


  • File List

Thread.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_THREAD_HPP
00026 #define SFML_THREAD_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 #ifdef SFML_SYSTEM_WINDOWS
00035
00036     #include <SFML/System/Win32/Thread.hpp>
00037
00038 #else
00039
00040     #include <SFML/System/Unix/Thread.hpp>
00041
00042 #endif
00043
00044
00045 #endif // SFML_THREAD_HPP


  • File List

Unicode.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/System/Unicode.hpp>
00029 #include <stdexcept>
00030 #include <string.h>
00031
00032
00034 // References :
00035 //
00036 // http://www.unicode.org/
00037 // http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c
00038 // http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.h
00039 // http://people.w3.org/rishida/scripts/uniview/conversion
00040 //
00042
00043 namespace
00044 {
00046     // Generic utility function to compute the number
00047     // of characters in a null-terminated string of any type
00049     template <typename T>
00050     std::size_t StrLen(const T* Str)
00051     {
00052         std::size_t Length = 0;
00053         while (*Str++) Length++;
00054         return Length;
00055     }
00056
00058     // Get the current system locale
00060     std::locale GetCurrentLocale()
00061     {
00062         try
00063         {
00064             return std::locale("");
00065         }
00066         catch (std::runtime_error&)
00067         {
00068             // It seems some implementations don't know the "" locale
00069             // (Mac OS, MinGW)
00070
00071             return std::locale();
00072         }
00073     }
00074 }
00075
00076 namespace sf
00077 {
00079 // Static member data
00081 const int Unicode::UTF8TrailingBytes[256] =
00082 {
00083     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00084     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00085     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00086     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00087     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00088     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00089     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00090     2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5
00091 };
00092 const Uint32 Unicode::UTF8Offsets[6] =
00093 {
00094     0x00000000, 0x00003080, 0x000E2080, 0x03C82080, 0xFA082080, 0x82082080
00095 };
00096 const Uint8 Unicode::UTF8FirstBytes[7] =
00097 {
00098     0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
00099 };
00100
00101
00105 Unicode::Text::Text()
00106 {
00107     // Nothing to do
00108 }
00109
00110
00114 Unicode::Text::Text(const char* Str)
00115 {
00116     if (Str)
00117     {
00118         std::size_t Length = StrLen(Str);
00119         if (Length > 0)
00120         {
00121             myUTF32String.reserve(Length + 1);
00122             Unicode::ANSIToUTF32(Str, Str + Length, std::back_inserter(myUTF32String));
00123         }
00124     }
00125 }
00126 Unicode::Text::Text(const wchar_t* Str)
00127 {
00128     if (Str)
00129     {
00130         std::size_t Length = StrLen(Str);
00131         if (Length > 0)
00132         {
00133             // See comments below, in Unicode::Text::Text(const std::wstring&)
00134             myUTF32String.reserve(Length + 1);
00135             switch (sizeof(wchar_t))
00136             {
00137                 case 2 : Unicode::UTF16ToUTF32(Str, Str + Length, std::back_inserter(myUTF32String), 0); break;
00138                 case 4 : std::copy(Str, Str + Length, std::back_inserter(myUTF32String));                break;
00139                 default : break;
00140             }
00141         }
00142     }
00143 }
00144 Unicode::Text::Text(const Uint8* Str)
00145 {
00146     if (Str)
00147     {
00148         std::size_t Length = StrLen(Str);
00149         if (Length > 0)
00150         {
00151             myUTF32String.reserve(Length + 1);
00152             Unicode::UTF8ToUTF32(Str, Str + Length, std::back_inserter(myUTF32String), 0);
00153         }
00154     }
00155 }
00156 Unicode::Text::Text(const Uint16* Str)
00157 {
00158     if (Str)
00159     {
00160         std::size_t Length = StrLen(Str);
00161         if (Length > 0)
00162         {
00163             myUTF32String.reserve(Length+ 1);
00164             Unicode::UTF16ToUTF32(Str, Str + Length, std::back_inserter(myUTF32String), 0);
00165         }
00166     }
00167 }
00168 Unicode::Text::Text(const Uint32* Str)
00169 {
00170     if (Str)
00171         myUTF32String = Str;
00172 }
00173 Unicode::Text::Text(const std::string& Str)
00174 {
00175     myUTF32String.reserve(Str.length() + 1);
00176     Unicode::ANSIToUTF32(Str.begin(), Str.end(), std::back_inserter(myUTF32String));
00177 }
00178 Unicode::Text::Text(const std::wstring& Str)
00179 {
00180     // This function assumes that 2-byte large wchar_t are encoded in UTF-16 (Windows), and
00181     // 4-byte large wchar_t are encoded using UTF-32 (Unix)
00182     // Is that always true ? (some platforms may use JIS Japanese encoding)
00183     // The macro __STDC_ISO_10646__ should help identifying UTF-32 compliant implementations
00184
00185     myUTF32String.reserve(Str.length() + 1);
00186
00187     // Select the proper function according to the (supposed) wchar_t system encoding
00188     switch (sizeof(wchar_t))
00189     {
00190         // wchar_t uses UTF-16 -- need a conversion
00191         case 2 :
00192         {
00193             Unicode::UTF16ToUTF32(Str.begin(), Str.end(), std::back_inserter(myUTF32String), 0);
00194             break;
00195         }
00196
00197         // wchar_t uses UTF-32 -- direct copy
00198         case 4 :
00199         {
00200             std::copy(Str.begin(), Str.end(), std::back_inserter(myUTF32String));
00201             break;
00202         }
00203
00204         // This should never happen
00205         default : break;
00206     }
00207 }
00208 Unicode::Text::Text(const Unicode::UTF8String& Str)
00209 {
00210     myUTF32String.reserve(Str.length() + 1);
00211     Unicode::UTF8ToUTF32(Str.begin(), Str.end(), std::back_inserter(myUTF32String), 0);
00212 }
00213 Unicode::Text::Text(const Unicode::UTF16String& Str)
00214 {
00215     myUTF32String.reserve(Str.length() + 1);
00216     Unicode::UTF16ToUTF32(Str.begin(), Str.end(), std::back_inserter(myUTF32String), 0);
00217 }
00218 Unicode::Text::Text(const Unicode::UTF32String& Str)
00219 {
00220     myUTF32String = Str;
00221 }
00222
00223
00227 Unicode::Text::operator std::string() const
00228 {
00229     std::string Output;
00230     Output.reserve(myUTF32String.length() + 1);
00231     Unicode::UTF32ToANSI(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0, Unicode::GetDefaultLocale());
00232     return Output;
00233 }
00234 Unicode::Text::operator std::wstring() const
00235 {
00236     // This function assumes that 2-byte large wchar_t are encoded in UTF-16 (Windows), and
00237     // 4-byte large wchar_t are encoded using UTF-32 (Unix)
00238     // Is that always true ? (some platforms may use JIS Japanese encoding)
00239     // The macro __STDC_ISO_10646__ should help identifying UTF-32 compliant implementations
00240
00241     std::wstring Output;
00242     Output.reserve(myUTF32String.length() + 1);
00243
00244     // Select the proper function according to the (supposed) wchar_t system encoding
00245     switch (sizeof(wchar_t))
00246     {
00247         // wchar_t uses UTF-16 -- need a conversion
00248         case 2 :
00249         {
00250             UTF32ToUTF16(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0);
00251             break;
00252         }
00253
00254         // wchar_t uses UTF-32 -- direct copy
00255         case 4 :
00256         {
00257             std::copy(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output));
00258             break;
00259         }
00260
00261         // This should never happen
00262         default : break;
00263     }
00264     return Output;
00265 }
00266 Unicode::Text::operator sf::Unicode::UTF8String() const
00267 {
00268     Unicode::UTF8String Output;
00269     Output.reserve(myUTF32String.length() * 4 + 1);
00270     Unicode::UTF32ToUTF8(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0);
00271     return Output;
00272 }
00273 Unicode::Text::operator sf::Unicode::UTF16String() const
00274 {
00275     Unicode::UTF16String Output;
00276     Output.reserve(myUTF32String.length() * 2 + 1);
00277     Unicode::UTF32ToUTF16(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0);
00278     return Output;
00279 }
00280 Unicode::Text::operator const sf::Unicode::UTF32String&() const
00281 {
00282     return myUTF32String;
00283 }
00284
00285
00289 const std::locale& Unicode::GetDefaultLocale()
00290 {
00291     // It seems getting the default locale is a very expensive operation,
00292     // so we only do it once and then store the locale for reuse.
00293     // Warning : this code won't be aware of any change of the default locale during runtime
00294
00295     static std::locale DefaultLocale = GetCurrentLocale();
00296
00297     return DefaultLocale;
00298 }
00299
00300 } // namespace sf


  • File List

Unicode.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_UNICODE_HPP
00026 #define SFML_UNICODE_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <iterator>
00033 #include <locale>
00034 #include <string>
00035 #include <stdlib.h>
00036
00037
00038 namespace sf
00039 {
00044 class SFML_API Unicode
00045 {
00046 public :
00047
00054     typedef std::basic_string<Uint8>  UTF8String;
00055     typedef std::basic_string<Uint16> UTF16String;
00056     typedef std::basic_string<Uint32> UTF32String;
00057
00063     class SFML_API Text
00064     {
00065     public :
00066
00071         Text();
00072
00079         Text(const char*                 Str);
00080         Text(const wchar_t*              Str);
00081         Text(const Uint8*                Str);
00082         Text(const Uint16*               Str);
00083         Text(const Uint32*               Str);
00084         Text(const std::string&          Str);
00085         Text(const std::wstring&         Str);
00086         Text(const Unicode::UTF8String&  Str);
00087         Text(const Unicode::UTF16String& Str);
00088         Text(const Unicode::UTF32String& Str);
00089
00096         operator       std::string          () const;
00097         operator       std::wstring         () const;
00098         operator       Unicode::UTF8String  () const;
00099         operator       Unicode::UTF16String () const;
00100         operator const Unicode::UTF32String&() const;
00101
00102     private :
00103
00105         // Data member
00107         sf::Unicode::UTF32String myUTF32String;
00108     };
00109
00123     template <typename In, typename Out>
00124     static Out UTF32ToANSI(In Begin, In End, Out Output, char Replacement = '?', const std::locale& Locale = GetDefaultLocale());
00125
00138     template <typename In, typename Out>
00139     static Out ANSIToUTF32(In Begin, In End, Out Output, const std::locale& Locale = GetDefaultLocale());
00140
00153     template <typename In, typename Out>
00154     static Out UTF8ToUTF16(In Begin, In End, Out Output, Uint16 Replacement = '?');
00155
00168     template <typename In, typename Out>
00169     static Out UTF8ToUTF32(In Begin, In End, Out Output, Uint32 Replacement = '?');
00170
00183     template <typename In, typename Out>
00184     static Out UTF16ToUTF8(In Begin, In End, Out Output, Uint8 Replacement = '?');
00185
00198     template <typename In, typename Out>
00199     static Out UTF16ToUTF32(In Begin, In End, Out Output, Uint32 Replacement = '?');
00200
00213     template <typename In, typename Out>
00214     static Out UTF32ToUTF8(In Begin, In End, Out Output, Uint8 Replacement = '?');
00215
00228     template <typename In, typename Out>
00229     static Out UTF32ToUTF16(In Begin, In End, Out Output, Uint16 Replacement = '?');
00230
00240     template <typename In>
00241     static std::size_t GetUTF8Length(In Begin, In End);
00242
00252     template <typename In>
00253     static std::size_t GetUTF16Length(In Begin, In End);
00254
00264     template <typename In>
00265     static std::size_t GetUTF32Length(In Begin, In End);
00266
00267 private :
00268
00275     static const std::locale& GetDefaultLocale();
00276
00278     // Static member data
00280     static const int    UTF8TrailingBytes[256];
00281     static const Uint32 UTF8Offsets[6];
00282     static const Uint8  UTF8FirstBytes[7];
00283 };
00284
00285 #include <SFML/System/Unicode.inl>
00286
00287 } // namespace sf
00288
00289
00290 #endif // SFML_UNICODE_HPP


  • File List

Unicode.inl

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025
00030 template <typename In, typename Out>
00031 inline Out Unicode::UTF32ToANSI(In Begin, In End, Out Output, char Replacement, const std::locale& Locale)
00032 {
00033     #ifdef __MINGW32__
00034
00035         // MinGW has a almost no support for unicode stuff
00036         // As a consequence, the MinGW version of this function can only use the default locale
00037         // and ignores the one passed as parameter
00038         while (Begin < End)
00039         {
00040             char Char = 0;
00041             if (wctomb(&Char, static_cast<wchar_t>(*Begin++)) >= 0)
00042                 *Output++ = Char;
00043             else if (Replacement)
00044                 *Output++ = Replacement;
00045         }
00046
00047     #else
00048
00049         // Get the facet of the locale which deals with character conversion
00050         const std::ctype<wchar_t>& Facet = std::use_facet< std::ctype<wchar_t> >(Locale);
00051
00052         // Use the facet to convert each character of the input string
00053         while (Begin < End)
00054             *Output++ = Facet.narrow(static_cast<wchar_t>(*Begin++), Replacement);
00055
00056     #endif
00057
00058     return Output;
00059 }
00060
00061
00066 template <typename In, typename Out>
00067 inline Out Unicode::ANSIToUTF32(In Begin, In End, Out Output, const std::locale& Locale)
00068 {
00069     #ifdef __MINGW32__
00070
00071         // MinGW has a almost no support for unicode stuff
00072         // As a consequence, the MinGW version of this function can only use the default locale
00073         // and ignores the one passed as parameter
00074         while (Begin < End)
00075         {
00076             wchar_t Char = 0;
00077             mbtowc(&Char, &*Begin, 1);
00078             Begin++;
00079             *Output++ = static_cast<Uint32>(Char);
00080         }
00081
00082     #else
00083
00084         // Get the facet of the locale which deals with character conversion
00085         const std::ctype<wchar_t>& Facet = std::use_facet< std::ctype<wchar_t> >(Locale);
00086
00087         // Use the facet to convert each character of the input string
00088         while (Begin < End)
00089             *Output++ = static_cast<Uint32>(Facet.widen(*Begin++));
00090
00091     #endif
00092
00093     return Output;
00094 }
00095
00096
00101 template <typename In, typename Out>
00102 inline Out Unicode::UTF8ToUTF16(In Begin, In End, Out Output, Uint16 Replacement)
00103 {
00104     while (Begin < End)
00105     {
00106         Uint32 c = 0;
00107         int TrailingBytes = UTF8TrailingBytes[static_cast<int>(*Begin)];
00108         if (Begin + TrailingBytes < End)
00109         {
00110             // First decode the UTF-8 character
00111             switch (TrailingBytes)
00112             {
00113                 case 5 : c += *Begin++; c <<= 6;
00114                 case 4 : c += *Begin++; c <<= 6;
00115                 case 3 : c += *Begin++; c <<= 6;
00116                 case 2 : c += *Begin++; c <<= 6;
00117                 case 1 : c += *Begin++; c <<= 6;
00118                 case 0 : c += *Begin++;
00119             }
00120             c -= UTF8Offsets[TrailingBytes];
00121
00122             // Then encode it in UTF-16
00123             if (c < 0xFFFF)
00124             {
00125                 // Character can be converted directly to 16 bits, just need to check it's in the valid range
00126                 if ((c >= 0xD800) && (c <= 0xDFFF))
00127                 {
00128                     // Invalid character (this range is reserved)
00129                     if (Replacement)
00130                         *Output++ = Replacement;
00131                 }
00132                 else
00133                 {
00134                     // Valid character directly convertible to 16 bits
00135                     *Output++ = static_cast<Uint16>(c);
00136                 }
00137             }
00138             else if (c > 0x0010FFFF)
00139             {
00140                 // Invalid character (greater than the maximum unicode value)
00141                 if (Replacement)
00142                     *Output++ = Replacement;
00143             }
00144             else
00145             {
00146                 // Character will be converted to 2 UTF-16 elements
00147                 c -= 0x0010000;
00148                 *Output++ = static_cast<Uint16>((c >> 10)     + 0xD800);
00149                 *Output++ = static_cast<Uint16>((c & 0x3FFUL) + 0xDC00);
00150             }
00151         }
00152     }
00153
00154     return Output;
00155 }
00156
00157
00162 template <typename In, typename Out>
00163 inline Out Unicode::UTF8ToUTF32(In Begin, In End, Out Output, Uint32 Replacement)
00164 {
00165     while (Begin < End)
00166     {
00167         Uint32 c = 0;
00168         int TrailingBytes = UTF8TrailingBytes[static_cast<int>(*Begin)];
00169         if (Begin + TrailingBytes < End)
00170         {
00171             // First decode the UTF-8 character
00172             switch (TrailingBytes)
00173             {
00174                 case 5 : c += *Begin++; c <<= 6;
00175                 case 4 : c += *Begin++; c <<= 6;
00176                 case 3 : c += *Begin++; c <<= 6;
00177                 case 2 : c += *Begin++; c <<= 6;
00178                 case 1 : c += *Begin++; c <<= 6;
00179                 case 0 : c += *Begin++;
00180             }
00181             c -= UTF8Offsets[TrailingBytes];
00182
00183             // Then write it if valid
00184             if ((c < 0xD800) || (c > 0xDFFF))
00185             {
00186                 // Valid UTF-32 character
00187                 *Output++ = c;
00188             }
00189             else
00190             {
00191                 // Invalid UTF-32 character
00192                 if (Replacement)
00193                     *Output++ = Replacement;
00194             }
00195         }
00196     }
00197
00198     return Output;
00199 }
00200
00201
00206 template <typename In, typename Out>
00207 inline Out Unicode::UTF16ToUTF8(In Begin, In End, Out Output, Uint8 Replacement)
00208 {
00209     while (Begin < End)
00210     {
00211         Uint32 c = *Begin++;
00212
00213         // If it's a surrogate pair, first convert to a single UTF-32 character
00214         if ((c >= 0xD800) && (c <= 0xDBFF))
00215         {
00216             if (Begin < End)
00217             {
00218                 // The second element is valid : convert the two elements to a UTF-32 character
00219                 Uint32 d = *Begin++;
00220                 if ((d >= 0xDC00) && (d <= 0xDFFF))
00221                     c = static_cast<Uint32>(((c - 0xD800) << 10) + (d - 0xDC00) + 0x0010000);
00222             }
00223             else
00224             {
00225                 // Invalid second element
00226                 if (Replacement)
00227                     *Output++ = Replacement;
00228             }
00229         }
00230
00231         // Then convert to UTF-8
00232         if (c > 0x0010FFFF)
00233         {
00234             // Invalid character (greater than the maximum unicode value)
00235             if (Replacement)
00236                 *Output++ = Replacement;
00237         }
00238         else
00239         {
00240             // Valid character
00241
00242             // Get number of bytes to write
00243             int BytesToWrite = 1;
00244             if      (c <  0x80)       BytesToWrite = 1;
00245             else if (c <  0x800)      BytesToWrite = 2;
00246             else if (c <  0x10000)    BytesToWrite = 3;
00247             else if (c <= 0x0010FFFF) BytesToWrite = 4;
00248
00249             // Extract bytes to write
00250             Uint8 Bytes[4];
00251             switch (BytesToWrite)
00252             {
00253                 case 4 : Bytes[3] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;
00254                 case 3 : Bytes[2] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;
00255                 case 2 : Bytes[1] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;
00256                 case 1 : Bytes[0] = static_cast<Uint8> (c | UTF8FirstBytes[BytesToWrite]);
00257             }
00258
00259             // Add them to the output
00260             const Uint8* CurByte = Bytes;
00261             switch (BytesToWrite)
00262             {
00263                 case 4 : *Output++ = *CurByte++;
00264                 case 3 : *Output++ = *CurByte++;
00265                 case 2 : *Output++ = *CurByte++;
00266                 case 1 : *Output++ = *CurByte++;
00267             }
00268         }
00269     }
00270
00271     return Output;
00272 }
00273
00274
00279 template <typename In, typename Out>
00280 inline Out Unicode::UTF16ToUTF32(In Begin, In End, Out Output, Uint32 Replacement)
00281 {
00282     while (Begin < End)
00283     {
00284         Uint16 c = *Begin++;
00285         if ((c >= 0xD800) && (c <= 0xDBFF))
00286         {
00287             // We have a surrogate pair, ie. a character composed of two elements
00288             if (Begin < End)
00289             {
00290                 Uint16 d = *Begin++;
00291                 if ((d >= 0xDC00) && (d <= 0xDFFF))
00292                 {
00293                     // The second element is valid : convert the two elements to a UTF-32 character
00294                     *Output++ = static_cast<Uint32>(((c - 0xD800) << 10) + (d - 0xDC00) + 0x0010000);
00295                 }
00296                 else
00297                 {
00298                     // Invalid second element
00299                     if (Replacement)
00300                         *Output++ = Replacement;
00301                 }
00302             }
00303         }
00304         else if ((c >= 0xDC00) && (c <= 0xDFFF))
00305         {
00306             // Invalid character
00307             if (Replacement)
00308                 *Output++ = Replacement;
00309         }
00310         else
00311         {
00312             // Valid character directly convertible to UTF-32
00313             *Output++ = static_cast<Uint32>(c);
00314         }
00315     }
00316
00317     return Output;
00318 }
00319
00320
00325 template <typename In, typename Out>
00326 inline Out Unicode::UTF32ToUTF8(In Begin, In End, Out Output, Uint8 Replacement)
00327 {
00328     while (Begin < End)
00329     {
00330         Uint32 c = *Begin++;
00331         if (c > 0x0010FFFF)
00332         {
00333             // Invalid character (greater than the maximum unicode value)
00334             if (Replacement)
00335                 *Output++ = Replacement;
00336         }
00337         else
00338         {
00339             // Valid character
00340
00341             // Get number of bytes to write
00342             int BytesToWrite = 1;
00343             if      (c <  0x80)       BytesToWrite = 1;
00344             else if (c <  0x800)      BytesToWrite = 2;
00345             else if (c <  0x10000)    BytesToWrite = 3;
00346             else if (c <= 0x0010FFFF) BytesToWrite = 4;
00347
00348             // Extract bytes to write
00349             Uint8 Bytes[4];
00350             switch (BytesToWrite)
00351             {
00352                 case 4 : Bytes[3] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;
00353                 case 3 : Bytes[2] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;
00354                 case 2 : Bytes[1] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;
00355                 case 1 : Bytes[0] = static_cast<Uint8> (c | UTF8FirstBytes[BytesToWrite]);
00356             }
00357
00358             // Add them to the output
00359             const Uint8* CurByte = Bytes;
00360             switch (BytesToWrite)
00361             {
00362                 case 4 : *Output++ = *CurByte++;
00363                 case 3 : *Output++ = *CurByte++;
00364                 case 2 : *Output++ = *CurByte++;
00365                 case 1 : *Output++ = *CurByte++;
00366             }
00367         }
00368     }
00369
00370     return Output;
00371 }
00372
00373
00378 template <typename In, typename Out>
00379 inline Out Unicode::UTF32ToUTF16(In Begin, In End, Out Output, Uint16 Replacement)
00380 {
00381     while (Begin < End)
00382     {
00383         Uint32 c = *Begin++;
00384         if (c < 0xFFFF)
00385         {
00386             // Character can be converted directly to 16 bits, just need to check it's in the valid range
00387             if ((c >= 0xD800) && (c <= 0xDFFF))
00388             {
00389                 // Invalid character (this range is reserved)
00390                 if (Replacement)
00391                     *Output++ = Replacement;
00392             }
00393             else
00394             {
00395                 // Valid character directly convertible to 16 bits
00396                 *Output++ = static_cast<Uint16>(c);
00397             }
00398         }
00399         else if (c > 0x0010FFFF)
00400         {
00401             // Invalid character (greater than the maximum unicode value)
00402             if (Replacement)
00403                 *Output++ = Replacement;
00404         }
00405         else
00406         {
00407             // Character will be converted to 2 UTF-16 elements
00408             c -= 0x0010000;
00409             *Output++ = static_cast<Uint16>((c >> 10)     + 0xD800);
00410             *Output++ = static_cast<Uint16>((c & 0x3FFUL) + 0xDC00);
00411         }
00412     }
00413
00414     return Output;
00415 }
00416
00417
00421 template <typename In>
00422 inline std::size_t Unicode::GetUTF8Length(In Begin, In End)
00423 {
00424     std::size_t Length = 0;
00425     while (Begin < End)
00426     {
00427         int NbBytes = UTF8TrailingBytes[static_cast<int>(*Begin)];
00428         if (Begin + NbBytes < End)
00429             ++Length;
00430
00431         Begin += NbBytes + 1;
00432     }
00433
00434     return Length;
00435 }
00436
00437
00441 template <typename In>
00442 inline std::size_t Unicode::GetUTF16Length(In Begin, In End)
00443 {
00444     std::size_t Length = 0;
00445     while (Begin < End)
00446     {
00447         if ((*Begin >= 0xD800) && (*Begin <= 0xDBFF))
00448         {
00449             ++Begin;
00450             if ((Begin < End) && ((*Begin >= 0xDC00) && (*Begin <= 0xDFFF)))
00451             {
00452                 ++Length;
00453             }
00454         }
00455         else
00456         {
00457             ++Length;
00458         }
00459
00460         ++Begin;
00461     }
00462
00463     return Length;
00464 }
00465
00466
00470 template <typename In>
00471 inline std::size_t Unicode::GetUTF32Length(In Begin, In End)
00472 {
00473     return End - Begin;
00474 }


  • File List

Vector2.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_VECTOR2_HPP
00026 #define SFML_VECTOR2_HPP
00027
00028
00029 namespace sf
00030 {
00036 template <typename T>
00037 class Vector2
00038 {
00039 public :
00040
00045     Vector2();
00046
00054     Vector2(T X, T Y);
00055
00057     // Member data
00059     T x;
00060     T y;
00061 };
00062
00071 template <typename T>
00072 Vector2<T> operator -(const Vector2<T>& V);
00073
00083 template <typename T>
00084 Vector2<T>& operator +=(Vector2<T>& V1, const Vector2<T>& V2);
00085
00095 template <typename T>
00096 Vector2<T>& operator -=(Vector2<T>& V1, const Vector2<T>& V2);
00097
00107 template <typename T>
00108 Vector2<T> operator +(const Vector2<T>& V1, const Vector2<T>& V2);
00109
00119 template <typename T>
00120 Vector2<T> operator -(const Vector2<T>& V1, const Vector2<T>& V2);
00121
00131 template <typename T>
00132 Vector2<T> operator *(const Vector2<T>& V, T X);
00133
00143 template <typename T>
00144 Vector2<T> operator *(T X, const Vector2<T>& V);
00145
00155 template <typename T>
00156 Vector2<T>& operator *=(Vector2<T>& V, T X);
00157
00167 template <typename T>
00168 Vector2<T> operator /(const Vector2<T>& V, T X);
00169
00179 template <typename T>
00180 Vector2<T>& operator /=(Vector2<T>& V, T X);
00181
00191 template <typename T>
00192 bool operator ==(const Vector2<T>& V1, const Vector2<T>& V2);
00193
00203 template <typename T>
00204 bool operator !=(const Vector2<T>& V1, const Vector2<T>& V2);
00205
00206 #include <SFML/System/Vector2.inl>
00207
00208 // Define the most common types
00209 typedef Vector2<int>   Vector2i;
00210 typedef Vector2<float> Vector2f;
00211
00212 } // namespace sf
00213
00214
00215 #endif // SFML_VECTOR2_HPP


  • File List

Vector2.inl

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025
00029 template <typename T>
00030 Vector2<T>::Vector2() :
00031 x(0),
00032 y(0)
00033 {
00034
00035 }
00036
00037
00041 template <typename T>
00042 Vector2<T>::Vector2(T X, T Y) :
00043 x(X),
00044 y(Y)
00045 {
00046
00047 }
00048
00049
00053 template <typename T>
00054 Vector2<T> operator -(const Vector2<T>& V)
00055 {
00056     return Vector2<T>(-V.x, -V.y);
00057 }
00058
00059
00063 template <typename T>
00064 Vector2<T>& operator +=(Vector2<T>& V1, const Vector2<T>& V2)
00065 {
00066     V1.x += V2.x;
00067     V1.y += V2.y;
00068
00069     return V1;
00070 }
00071
00072
00076 template <typename T>
00077 Vector2<T>& operator -=(Vector2<T>& V1, const Vector2<T>& V2)
00078 {
00079     V1.x -= V2.x;
00080     V1.y -= V2.y;
00081
00082     return V1;
00083 }
00084
00085
00089 template <typename T>
00090 Vector2<T> operator +(const Vector2<T>& V1, const Vector2<T>& V2)
00091 {
00092     return Vector2<T>(V1.x + V2.x, V1.y + V2.y);
00093 }
00094
00095
00099 template <typename T>
00100 Vector2<T> operator -(const Vector2<T>& V1, const Vector2<T>& V2)
00101 {
00102     return Vector2<T>(V1.x - V2.x, V1.y - V2.y);
00103 }
00104
00105
00109 template <typename T>
00110 Vector2<T> operator *(const Vector2<T>& V, T X)
00111 {
00112     return Vector2<T>(V.x * X, V.y * X);
00113 }
00114
00115
00119 template <typename T>
00120 Vector2<T> operator *(T X, const Vector2<T>& V)
00121 {
00122     return Vector2<T>(V.x * X, V.y * X);
00123 }
00124
00125
00129 template <typename T>
00130 Vector2<T>& operator *=(Vector2<T>& V, T X)
00131 {
00132     V.x *= X;
00133     V.y *= X;
00134
00135     return V;
00136 }
00137
00138
00142 template <typename T>
00143 Vector2<T> operator /(const Vector2<T>& V, T X)
00144 {
00145     return Vector2<T>(V.x / X, V.y / X);
00146 }
00147
00148
00152 template <typename T>
00153 Vector2<T>& operator /=(Vector2<T>& V, T X)
00154 {
00155     V.x /= X;
00156     V.y /= X;
00157
00158     return V;
00159 }
00160
00161
00165 template <typename T>
00166 bool operator ==(const Vector2<T>& V1, const Vector2<T>& V2)
00167 {
00168     return (V1.x == V2.x) && (V1.y == V2.y);
00169 }
00170
00171
00175 template <typename T>
00176 bool operator !=(const Vector2<T>& V1, const Vector2<T>& V2)
00177 {
00178     return (V1.x != V2.x) || (V1.y != V2.y);
00179 }


  • File List

Vector3.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_VECTOR3_HPP
00026 #define SFML_VECTOR3_HPP
00027
00028
00029 namespace sf
00030 {
00036 template <typename T>
00037 class Vector3
00038 {
00039 public :
00040
00045     Vector3();
00046
00055     Vector3(T X, T Y, T Z);
00056
00058     // Member data
00060     T x;
00061     T y;
00062     T z;
00063 };
00064
00073 template <typename T>
00074 Vector3<T> operator -(const Vector3<T>& V);
00075
00085 template <typename T>
00086 Vector3<T>& operator +=(Vector3<T>& V1, const Vector3<T>& V2);
00087
00097 template <typename T>
00098 Vector3<T>& operator -=(Vector3<T>& V1, const Vector3<T>& V2);
00099
00109 template <typename T>
00110 Vector3<T> operator +(const Vector3<T>& V1, const Vector3<T>& V2);
00111
00121 template <typename T>
00122 Vector3<T> operator -(const Vector3<T>& V1, const Vector3<T>& V2);
00123
00133 template <typename T>
00134 Vector3<T> operator *(const Vector3<T>& V, T X);
00135
00145 template <typename T>
00146 Vector3<T> operator *(T X, const Vector3<T>& V);
00147
00157 template <typename T>
00158 Vector3<T>& operator *=(Vector3<T>& V, T X);
00159
00169 template <typename T>
00170 Vector3<T> operator /(const Vector3<T>& V, T X);
00171
00181 template <typename T>
00182 Vector3<T>& operator /=(Vector3<T>& V, T X);
00183
00193 template <typename T>
00194 bool operator ==(const Vector3<T>& V1, const Vector3<T>& V2);
00195
00205 template <typename T>
00206 bool operator !=(const Vector3<T>& V1, const Vector3<T>& V2);
00207
00208 #include <SFML/System/Vector3.inl>
00209
00210 // Define the most common types
00211 typedef Vector3<int>   Vector3i;
00212 typedef Vector3<float> Vector3f;
00213
00214 } // namespace sf
00215
00216
00217 #endif // SFML_VECTOR3_HPP


  • File List

Vector3.inl

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025
00029 template <typename T>
00030 Vector3<T>::Vector3() :
00031 x(0),
00032 y(0),
00033 z(0)
00034 {
00035
00036 }
00037
00038
00042 template <typename T>
00043 Vector3<T>::Vector3(T X, T Y, T Z) :
00044 x(X),
00045 y(Y),
00046 z(Z)
00047 {
00048
00049 }
00050
00051
00055 template <typename T>
00056 Vector3<T> operator -(const Vector3<T>& V)
00057 {
00058     return Vector3<T>(-V.x, -V.y, -V.z);
00059 }
00060
00061
00065 template <typename T>
00066 Vector3<T>& operator +=(Vector3<T>& V1, const Vector3<T>& V2)
00067 {
00068     V1.x += V2.x;
00069     V1.y += V2.y;
00070     V1.z += V2.z;
00071
00072     return V1;
00073 }
00074
00075
00079 template <typename T>
00080 Vector3<T>& operator -=(Vector3<T>& V1, const Vector3<T>& V2)
00081 {
00082     V1.x -= V2.x;
00083     V1.y -= V2.y;
00084     V1.z -= V2.z;
00085
00086     return V1;
00087 }
00088
00089
00093 template <typename T>
00094 Vector3<T> operator +(const Vector3<T>& V1, const Vector3<T>& V2)
00095 {
00096     return Vector3<T>(V1.x + V2.x, V1.y + V2.y, V1.z + V2.z);
00097 }
00098
00099
00103 template <typename T>
00104 Vector3<T> operator -(const Vector3<T>& V1, const Vector3<T>& V2)
00105 {
00106     return Vector3<T>(V1.x - V2.x, V1.y - V2.y, V1.z - V2.z);
00107 }
00108
00109
00113 template <typename T>
00114 Vector3<T> operator *(const Vector3<T>& V, T X)
00115 {
00116     return Vector3<T>(V.x * X, V.y * X, V.z * X);
00117 }
00118
00119
00123 template <typename T>
00124 Vector3<T> operator *(T X, const Vector3<T>& V)
00125 {
00126     return Vector3<T>(V.x * X, V.y * X, V.z * X);
00127 }
00128
00129
00133 template <typename T>
00134 Vector3<T>& operator *=(Vector3<T>& V, T X)
00135 {
00136     V.x *= X;
00137     V.y *= X;
00138     V.z *= X;
00139
00140     return V;
00141 }
00142
00143
00147 template <typename T>
00148 Vector3<T> operator /(const Vector3<T>& V, T X)
00149 {
00150     return Vector3<T>(V.x / X, V.y / X, V.z / X);
00151 }
00152
00153
00157 template <typename T>
00158 Vector3<T>& operator /=(Vector3<T>& V, T X)
00159 {
00160     V.x /= X;
00161     V.y /= X;
00162     V.z /= X;
00163
00164     return V;
00165 }
00166
00167
00171 template <typename T>
00172 bool operator ==(const Vector3<T>& V1, const Vector3<T>& V2)
00173 {
00174     return (V1.x == V2.x) && (V1.y == V2.y) && (V1.z == V2.z);
00175 }
00176
00177
00181 template <typename T>
00182 bool operator !=(const Vector3<T>& V1, const Vector3<T>& V2)
00183 {
00184     return (V1.x != V2.x) || (V1.y != V2.y) || (V1.z != V2.z);
00185 }


  • File List

VideoMode.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Window/VideoMode.hpp>
00029 #include <SFML/Window/VideoModeSupport.hpp>
00030 #include <algorithm>
00031 #include <vector>
00032
00033
00037 namespace
00038 {
00039     // Global array of supported video modes
00040     std::vector<sf::VideoMode> SupportedModes;
00041
00042     // Functor for sorting modes from highest to lowest
00043     struct CompareModes
00044     {
00045         bool operator ()(const sf::VideoMode& v1, const sf::VideoMode& v2) const
00046         {
00047             if (v1.BitsPerPixel > v2.BitsPerPixel)
00048                 return true;
00049             else if (v1.BitsPerPixel < v2.BitsPerPixel)
00050                 return false;
00051             else if (v1.Width > v2.Width)
00052                 return true;
00053             else if (v1.Width < v2.Width)
00054                 return false;
00055             else
00056                 return (v1.Height > v2.Height);
00057         }
00058     };
00059 }
00060
00061
00062 namespace sf
00063 {
00067 VideoMode::VideoMode() :
00068 Width       (0),
00069 Height      (0),
00070 BitsPerPixel(0)
00071 {
00072
00073 }
00074
00075
00079 VideoMode::VideoMode(unsigned int ModeWidth, unsigned int ModeHeight, unsigned int ModeBpp) :
00080 Width       (ModeWidth),
00081 Height      (ModeHeight),
00082 BitsPerPixel(ModeBpp)
00083 {
00084
00085 }
00086
00087
00091 VideoMode VideoMode::GetDesktopMode()
00092 {
00093     // Directly forward to the video mode support
00094     return priv::VideoModeSupport::GetDesktopVideoMode();
00095 }
00096
00097
00102 VideoMode VideoMode::GetMode(std::size_t Index)
00103 {
00104     if (SupportedModes.empty())
00105         InitializeModes();
00106
00107     if (Index < GetModesCount())
00108         return SupportedModes[Index];
00109     else
00110         return VideoMode();
00111 }
00112
00113
00117 std::size_t VideoMode::GetModesCount()
00118 {
00119     if (SupportedModes.empty())
00120         InitializeModes();
00121
00122     return SupportedModes.size();
00123 }
00124
00125
00129 bool VideoMode::IsValid() const
00130 {
00131     if (SupportedModes.empty())
00132         InitializeModes();
00133
00134     return std::find(SupportedModes.begin(), SupportedModes.end(), *this) != SupportedModes.end();
00135 }
00136
00137
00141 bool VideoMode::operator ==(const VideoMode& Other) const
00142 {
00143     return (Width        == Other.Width)        &&
00144            (Height       == Other.Height)       &&
00145            (BitsPerPixel == Other.BitsPerPixel);
00146 }
00147
00148
00152 bool VideoMode::operator !=(const VideoMode& Other) const
00153 {
00154     return !(*this == Other);
00155 }
00156
00157
00161 void VideoMode::InitializeModes()
00162 {
00163     // We request the array of valid modes
00164     priv::VideoModeSupport::GetSupportedVideoModes(SupportedModes);
00165
00166     // And we sort them from highest to lowest (so that number 0 is the best)
00167     std::sort(SupportedModes.begin(), SupportedModes.end(), CompareModes());
00168 }
00169
00170 } // namespace sf


  • File List

VideoMode.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_VIDEOMODE_HPP
00026 #define SFML_VIDEOMODE_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <cstdlib>
00033
00034
00035 namespace sf
00036 {
00042 class SFML_API VideoMode
00043 {
00044 public :
00045
00050     VideoMode();
00051
00060     VideoMode(unsigned int ModeWidth, unsigned int ModeHeight, unsigned int ModeBpp = 32);
00061
00068     static VideoMode GetDesktopMode();
00069
00080     static VideoMode GetMode(std::size_t Index);
00081
00088     static std::size_t GetModesCount();
00089
00096     bool IsValid() const;
00097
00106     bool operator ==(const VideoMode& Other) const;
00107
00116     bool operator !=(const VideoMode& Other) const;
00117
00119     // Member data
00121     unsigned int Width;
00122     unsigned int Height;
00123     unsigned int BitsPerPixel;
00124
00125 private :
00126
00130     static void InitializeModes();
00131 };
00132
00133 } // namespace sf
00134
00135
00136 #endif // SFML_VIDEOMODE_HPP


  • File List

VideoModeSupport.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_VIDEOMODESUPPORT_HPP
00026 #define SFML_VIDEOMODESUPPORT_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 #if defined(SFML_SYSTEM_WINDOWS)
00035
00036     #include <SFML/Window/Win32/VideoModeSupport.hpp>
00037
00038 #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
00039
00040     #include <SFML/Window/Linux/VideoModeSupport.hpp>
00041
00042 #elif defined(SFML_SYSTEM_MACOS)
00043
00044     #include <SFML/Window/Cocoa/VideoModeSupport.hpp>
00045
00046 #endif
00047
00048
00049 #endif // SFML_VIDEOMODESUPPORT_HPP


  • File List

View.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Graphics/View.hpp>
00029 #include <algorithm>
00030
00031
00032 namespace sf
00033 {
00037 View::View(const FloatRect& ViewRect)
00038 {
00039     SetFromRect(ViewRect);
00040 }
00041
00042
00046 View::View(const sf::Vector2f& Center, const sf::Vector2f& HalfSize) :
00047 myCenter    (Center),
00048 myHalfSize  (HalfSize),
00049 myNeedUpdate(true)
00050 {
00051
00052 }
00053
00054
00058 void View::SetCenter(float X, float Y)
00059 {
00060     myCenter.x   = X;
00061     myCenter.y   = Y;
00062     myNeedUpdate = true;
00063 }
00064
00065
00069 void View::SetCenter(const sf::Vector2f& Center)
00070 {
00071     SetCenter(Center.x, Center.y);
00072 }
00073
00074
00078 void View::SetHalfSize(float HalfWidth, float HalfHeight)
00079 {
00080     myHalfSize.x = HalfWidth;
00081     myHalfSize.y = HalfHeight;
00082     myNeedUpdate = true;
00083 }
00084
00085
00089 void View::SetHalfSize(const sf::Vector2f& HalfSize)
00090 {
00091     SetHalfSize(HalfSize.x, HalfSize.y);
00092 }
00093
00094
00098 void View::SetFromRect(const FloatRect& ViewRect)
00099 {
00100     SetCenter(  (ViewRect.Right + ViewRect.Left) / 2, (ViewRect.Bottom + ViewRect.Top) / 2);
00101     SetHalfSize((ViewRect.Right - ViewRect.Left) / 2, (ViewRect.Bottom - ViewRect.Top) / 2);
00102 }
00103
00104
00108 const sf::Vector2f& View::GetCenter() const
00109 {
00110     return myCenter;
00111 }
00112
00113
00117 const sf::Vector2f& View::GetHalfSize() const
00118 {
00119     return myHalfSize;
00120 }
00121
00122
00126 const sf::FloatRect& View::GetRect() const
00127 {
00128     // Recompute it if needed
00129     if (myNeedUpdate)
00130         const_cast<View*>(this)->RecomputeMatrix();
00131
00132     return myRect;
00133 }
00134
00135
00139 void View::Move(float OffsetX, float OffsetY)
00140 {
00141     myCenter.x  += OffsetX;
00142     myCenter.y  += OffsetY;
00143     myNeedUpdate = true;
00144 }
00145
00146
00150 void View::Move(const sf::Vector2f& Offset)
00151 {
00152     Move(Offset.x, Offset.y);
00153 }
00154
00155
00159 void View::Zoom(float Factor)
00160 {
00161     if (Factor != 0)
00162     {
00163         myHalfSize  /= Factor;
00164         myNeedUpdate = true;
00165     }
00166 }
00167
00168
00172 const Matrix3& View::GetMatrix() const
00173 {
00174     // Recompute the matrix if needed
00175     if (myNeedUpdate)
00176         const_cast<View*>(this)->RecomputeMatrix();
00177
00178     return myMatrix;
00179 }
00180
00181
00185 void View::RecomputeMatrix()
00186 {
00187     // Compute the 4 corners of the view
00188     float Left   = myCenter.x - myHalfSize.x;
00189     float Top    = myCenter.y - myHalfSize.y;
00190     float Right  = myCenter.x + myHalfSize.x;
00191     float Bottom = myCenter.y + myHalfSize.y;
00192
00193     // Update the view rectangle - be careful, reversed views are allowed !
00194     myRect.Left   = std::min(Left, Right);
00195     myRect.Top    = std::min(Top, Bottom);
00196     myRect.Right  = std::max(Left, Right);
00197     myRect.Bottom = std::max(Top, Bottom);
00198
00199     // Update the projection matrix
00200     myMatrix(0, 0) = 2.f / (Right - Left);
00201     myMatrix(1, 1) = 2.f / (Top - Bottom);
00202     myMatrix(0, 2) = (Left + Right) / (Left - Right);
00203     myMatrix(1, 2) = (Bottom + Top) / (Bottom - Top);
00204
00205     myNeedUpdate = false;
00206 }
00207
00208 } // namespace sf


  • File List

View.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_VIEW_HPP
00026 #define SFML_VIEW_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <SFML/Graphics/Rect.hpp>
00033 #include <SFML/Graphics/Matrix3.hpp>
00034 #include <SFML/System/Vector2.hpp>
00035
00036
00037 namespace sf
00038 {
00039 class RenderTarget;
00040
00045 class SFML_API View
00046 {
00047 public :
00048
00055     explicit View(const FloatRect& ViewRect = FloatRect(0, 0, 1000, 1000));
00056
00064     View(const sf::Vector2f& Center, const sf::Vector2f& HalfSize);
00065
00073     void SetCenter(float X, float Y);
00074
00081     void SetCenter(const sf::Vector2f& Center);
00082
00090     void SetHalfSize(float HalfWidth, float HalfHeight);
00091
00098     void SetHalfSize(const sf::Vector2f& HalfSize);
00099
00106     void SetFromRect(const FloatRect& ViewRect);
00107
00114     const sf::Vector2f& GetCenter() const;
00115
00122     const sf::Vector2f& GetHalfSize() const;
00123
00130     const sf::FloatRect& GetRect() const;
00131
00139     void Move(float OffsetX, float OffsetY);
00140
00147     void Move(const sf::Vector2f& Offset);
00148
00155     void Zoom(float Factor);
00156
00157 private :
00158
00159     friend class RenderTarget;
00160
00167     const Matrix3& GetMatrix() const;
00168
00173     void RecomputeMatrix();
00174
00176     // Member data
00178     sf::Vector2f myCenter;
00179     sf::Vector2f myHalfSize;
00180     FloatRect    myRect;
00181     Matrix3      myMatrix;
00182     bool         myNeedUpdate;
00183 };
00184
00185 } // namespace sf
00186
00187
00188 #endif // SFML_VIEW_HPP


  • File List

Joystick.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #define _WIN32_WINDOWS 0x0501
00029 #define _WIN32_WINNT   0x0501
00030 #include <SFML/Window/Joystick.hpp>
00031 #include <windows.h>
00032 #include <mmsystem.h>
00033
00034
00035 namespace sf
00036 {
00037 namespace priv
00038 {
00042 void Joystick::Initialize(unsigned int Index)
00043 {
00044     // Reset state
00045     myIndex            = JOYSTICKID1;
00046     myNbButtons        = 0;
00047     myIsConnected      = false;
00048     myHasContinuousPOV = false;
00049     for (int i = 0; i < Joy::AxisCount; ++i)
00050         myAxes[i] = false;
00051
00052     // Get the Index-th connected joystick
00053     MMRESULT Error;
00054     JOYINFOEX JoyInfo;
00055     JoyInfo.dwSize = sizeof(JoyInfo);
00056     JoyInfo.dwFlags = JOY_RETURNALL;
00057     for (unsigned int NbFound = 0; (Error = joyGetPosEx(myIndex, &JoyInfo)) != JOYERR_PARMS; myIndex++)
00058     {
00059         // Check if the current joystick is connected
00060         if (Error == JOYERR_NOERROR)
00061         {
00062             // Check if it's the required index
00063             if (NbFound == Index)
00064             {
00065                 // Ok : store its parameters and return
00066                 myIsConnected = true;
00067                 JOYCAPS Caps;
00068                 joyGetDevCaps(myIndex, &Caps, sizeof(Caps));
00069                 myNbButtons = Caps.wNumButtons;
00070                 if (myNbButtons > Joy::ButtonCount)
00071                     myNbButtons = Joy::ButtonCount;
00072
00073                 myAxes[Joy::AxisX]   = true;
00074                 myAxes[Joy::AxisY]   = true;
00075                 myAxes[Joy::AxisZ]   = (Caps.wCaps & JOYCAPS_HASZ) != 0;
00076                 myAxes[Joy::AxisR]   = (Caps.wCaps & JOYCAPS_HASR) != 0;
00077                 myAxes[Joy::AxisU]   = (Caps.wCaps & JOYCAPS_HASU) != 0;
00078                 myAxes[Joy::AxisV]   = (Caps.wCaps & JOYCAPS_HASV) != 0;
00079                 myAxes[Joy::AxisPOV] = (Caps.wCaps & JOYCAPS_HASPOV) != 0;
00080                 myHasContinuousPOV   = (Caps.wCaps & JOYCAPS_POVCTS) != 0;
00081
00082                 return;
00083             }
00084
00085             // Go to the next valid joystick
00086             ++NbFound;
00087         }
00088     }
00089 }
00090
00091
00095 JoystickState Joystick::UpdateState()
00096 {
00097     JoystickState State;
00098
00099     if (myIsConnected)
00100     {
00101         // Get the joystick caps (for range conversions)
00102         JOYCAPS Caps;
00103         if (joyGetDevCaps(myIndex, &Caps, sizeof(Caps)) == JOYERR_NOERROR)
00104         {
00105             // Get the current joystick state
00106             JOYINFOEX Pos;
00107             Pos.dwFlags  = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ | JOY_RETURNR | JOY_RETURNU | JOY_RETURNV | JOY_RETURNBUTTONS;
00108             Pos.dwFlags |= myHasContinuousPOV ? JOY_RETURNPOVCTS : JOY_RETURNPOV;
00109             Pos.dwSize   = sizeof(JOYINFOEX);
00110             if (joyGetPosEx(myIndex, &Pos) == JOYERR_NOERROR)
00111             {
00112                 // Axes
00113                 State.Axis[Joy::AxisX] = (Pos.dwXpos - (Caps.wXmax + Caps.wXmin) / 2.f) * 200.f / (Caps.wXmax - Caps.wXmin);
00114                 State.Axis[Joy::AxisY] = (Pos.dwYpos - (Caps.wYmax + Caps.wYmin) / 2.f) * 200.f / (Caps.wYmax - Caps.wYmin);
00115                 State.Axis[Joy::AxisZ] = (Pos.dwZpos - (Caps.wZmax + Caps.wZmin) / 2.f) * 200.f / (Caps.wZmax - Caps.wZmin);
00116                 State.Axis[Joy::AxisR] = (Pos.dwRpos - (Caps.wRmax + Caps.wRmin) / 2.f) * 200.f / (Caps.wRmax - Caps.wRmin);
00117                 State.Axis[Joy::AxisU] = (Pos.dwUpos - (Caps.wUmax + Caps.wUmin) / 2.f) * 200.f / (Caps.wUmax - Caps.wUmin);
00118                 State.Axis[Joy::AxisV] = (Pos.dwVpos - (Caps.wVmax + Caps.wVmin) / 2.f) * 200.f / (Caps.wVmax - Caps.wVmin);
00119
00120                 // POV
00121                 if (Pos.dwPOV != 0xFFFF)
00122                     State.Axis[Joy::AxisPOV] = Pos.dwPOV / 100.f;
00123                 else
00124                     State.Axis[Joy::AxisPOV] = -1.f;
00125
00126                 // Buttons
00127                 for (unsigned int i = 0; i < GetButtonsCount(); ++i)
00128                     State.Buttons[i] = (Pos.dwButtons & (1 << i)) != 0;
00129             }
00130         }
00131     }
00132
00133     return State;
00134 }
00135
00136
00140 bool Joystick::HasAxis(Joy::Axis Axis) const
00141 {
00142     return myAxes[Axis];
00143 }
00144
00145
00149 unsigned int Joystick::GetButtonsCount() const
00150 {
00151     return myNbButtons;
00152 }
00153
00154
00155 } // namespace priv
00156
00157 } // namespace sf


  • File List

Joystick.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_JOYSTICKWIN32_HPP
00026 #define SFML_JOYSTICKWIN32_HPP
00027
00029 // Headers
00031
00032
00033 namespace sf
00034 {
00035 namespace priv
00036 {
00040 class Joystick
00041 {
00042 public :
00043
00050     void Initialize(unsigned int Index);
00051
00058     JoystickState UpdateState();
00059
00068     bool HasAxis(Joy::Axis Axis) const;
00069
00076     unsigned int GetButtonsCount() const;
00077
00078 private :
00079
00081     // Member data
00083     bool         myIsConnected;
00084     unsigned int myIndex;
00085     unsigned int myNbButtons;
00086     bool         myAxes[Joy::AxisCount];
00087     bool         myHasContinuousPOV;
00088 };
00089
00090 } // namespace priv
00091
00092 } // namespace sf
00093
00094
00095 #endif // SFML_JOYSTICKWIN32_HPP


  • File List

Mutex.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_MUTEXWIN32_HPP
00026 #define SFML_MUTEXWIN32_HPP
00027
00029 // Headers
00031 #include <SFML/System/NonCopyable.hpp>
00032 #include <windows.h>
00033
00034
00035 namespace sf
00036 {
00045 class SFML_API Mutex : NonCopyable
00046 {
00047 public :
00048
00053     Mutex();
00054
00059     ~Mutex();
00060
00065     void Lock();
00066
00071     void Unlock();
00072
00073 private :
00074
00076     // Member data
00078     CRITICAL_SECTION myHandle;
00079 };
00080
00081 } // namespace sf
00082
00083
00084 #endif // SFML_MUTEXWIN32_HPP


  • File List

Platform.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_PLATFORMWIN32_HPP
00026 #define SFML_PLATFORMWIN32_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <vector>
00033
00034
00035 namespace sf
00036 {
00037 namespace priv
00038 {
00043 class Platform
00044 {
00045 public :
00046
00053     static double GetSystemTime();
00054
00061     static void Sleep(float Time);
00062 };
00063
00064 } // namespace priv
00065
00066 } // namespace sf
00067
00068
00069 #endif // SFML_PLATFORMWIN32_HPP


  • File List

SocketHelper.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SOCKETHELPERWIN32_HPP
00026 #define SFML_SOCKETHELPERWIN32_HPP
00027
00029 // Headers
00031 #include <winsock2.h>
00032
00033
00034 namespace sf
00035 {
00041 class SFML_API SocketHelper
00042 {
00043 public :
00044
00046     // Define some socket types
00048     typedef SOCKET SocketType;
00049     typedef int    LengthType;
00050
00057     static SocketType InvalidSocket();
00058
00067     static bool Close(SocketType Socket);
00068
00076     static void SetBlocking(SocketType Socket, bool Block);
00077
00084     static Socket::Status GetErrorStatus();
00085 };
00086
00087 } // namespace sf
00088
00089
00090 #endif // SFML_SOCKETHELPERWIN32_HPP


  • File List

Thread.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_THREADWIN32_HPP
00026 #define SFML_THREADWIN32_HPP
00027
00029 // Headers
00031 #include <SFML/System/NonCopyable.hpp>
00032 #include <windows.h>
00033
00034
00035 namespace sf
00036 {
00044 class SFML_API Thread : NonCopyable
00045 {
00046 public :
00047
00048     typedef void (*FuncType)(void*);
00049
00057     Thread(FuncType Function, void* UserData = NULL);
00058
00063     virtual ~Thread();
00064
00069     void Launch();
00070
00075     void Wait();
00076
00084     void Terminate();
00085
00086 protected :
00087
00092     Thread();
00093
00094 private :
00095
00100     virtual void Run();
00101
00110     static unsigned int __stdcall ThreadFunc(void* UserData);
00111
00113     // Member data
00115     HANDLE   myHandle;
00116     FuncType myFunction;
00117     void*    myUserData;
00118 };
00119
00120 } // namespace sf
00121
00122
00123 #endif // SFML_THREADWIN32_HPP


  • File List

VideoModeSupport.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Window/Win32/VideoModeSupport.hpp>
00029 #include <windows.h>
00030 #include <algorithm>
00031
00032
00033 namespace sf
00034 {
00035 namespace priv
00036 {
00040 void VideoModeSupport::GetSupportedVideoModes(std::vector<VideoMode>& Modes)
00041 {
00042     // First, clear array to fill
00043     Modes.clear();
00044
00045     // Enumerate all available video modes for primary display adapter
00046     DEVMODE Win32Mode;
00047     Win32Mode.dmSize = sizeof(DEVMODE);
00048     for (int Count = 0; EnumDisplaySettings(NULL, Count, &Win32Mode); ++Count)
00049     {
00050         // Convert to sfVideoMode
00051         VideoMode Mode(Win32Mode.dmPelsWidth, Win32Mode.dmPelsHeight, Win32Mode.dmBitsPerPel);
00052
00053         // Add it only if it is not already in the array
00054         if (std::find(Modes.begin(), Modes.end(), Mode) == Modes.end())
00055             Modes.push_back(Mode);
00056     }
00057 }
00058
00059
00063 VideoMode VideoModeSupport::GetDesktopVideoMode()
00064 {
00065     DEVMODE Win32Mode;
00066     Win32Mode.dmSize = sizeof(DEVMODE);
00067     EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &Win32Mode);
00068
00069     return VideoMode(Win32Mode.dmPelsWidth, Win32Mode.dmPelsHeight, Win32Mode.dmBitsPerPel);
00070 }
00071
00072 } // namespace priv
00073
00074 } // namespace sf


  • File List

VideoModeSupport.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_VIDEOMODESUPPORTWIN32_HPP
00026 #define SFML_VIDEOMODESUPPORTWIN32_HPP
00027
00029 // Headers
00031 #include <SFML/Window/VideoMode.hpp>
00032 #include <vector>
00033
00034
00035 namespace sf
00036 {
00037 namespace priv
00038 {
00043 class VideoModeSupport
00044 {
00045 public :
00046
00053     static void GetSupportedVideoModes(std::vector<VideoMode>& Modes);
00054
00061     static VideoMode GetDesktopVideoMode();
00062 };
00063
00064 } // namespace priv
00065
00066 } // namespace sf
00067
00068
00069 #endif // SFML_VIDEOMODESUPPORTWIN32_HPP


  • File List

Window.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_WINDOW_HPP
00026 #define SFML_WINDOW_HPP
00027
00029 // Headers
00031 #include <SFML/Window/Event.hpp>
00032 #include <SFML/Window/Input.hpp>
00033 #include <SFML/Window/VideoMode.hpp>
00034 #include <SFML/Window/WindowHandle.hpp>
00035 #include <SFML/Window/WindowListener.hpp>
00036 #include <SFML/Window/WindowSettings.hpp>
00037 #include <SFML/Window/WindowStyle.hpp>
00038 #include <SFML/System/Clock.hpp>
00039 #include <SFML/System/NonCopyable.hpp>
00040 #include <queue>
00041 #include <string>
00042
00043
00044 namespace sf
00045 {
00046 namespace priv
00047 {
00048     class WindowImpl;
00049 }
00050
00055 class SFML_API Window : public WindowListener, NonCopyable
00056 {
00057 public :
00058
00063     Window();
00064
00074     Window(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings());
00075
00083     Window(WindowHandle Handle, const WindowSettings& Params = WindowSettings());
00084
00089     virtual ~Window();
00090
00100     void Create(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings());
00101
00109     void Create(WindowHandle Handle, const WindowSettings& Params = WindowSettings());
00110
00117     void Close();
00118
00127     bool IsOpened() const;
00128
00135     unsigned int GetWidth() const;
00136
00143     unsigned int GetHeight() const;
00144
00151     const WindowSettings& GetSettings() const;
00152
00161     bool GetEvent(Event& EventReceived);
00162
00169     void UseVerticalSync(bool Enabled);
00170
00177     void ShowMouseCursor(bool Show);
00178
00186     void SetCursorPosition(unsigned int Left, unsigned int Top);
00187
00196     void SetPosition(int Left, int Top);
00197
00205     void SetSize(unsigned int Width, unsigned int Height);
00206
00213     void Show(bool State);
00214
00222     void EnableKeyRepeat(bool Enabled);
00223
00232     void SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels);
00233
00243     bool SetActive(bool Active = true) const;
00244
00249     void Display();
00250
00257     const Input& GetInput() const;
00258
00265     void SetFramerateLimit(unsigned int Limit);
00266
00273     float GetFrameTime() const;
00274
00282     void SetJoystickThreshold(float Threshold);
00283
00284 private :
00285
00290     virtual void OnCreate();
00291
00298     virtual void OnEvent(const Event& EventReceived);
00299
00306     void Initialize(priv::WindowImpl* Impl);
00307
00309     // Member data
00311     priv::WindowImpl* myWindow;
00312     std::queue<Event> myEvents;
00313     Input             myInput;
00314     Clock             myClock;
00315     WindowSettings    mySettings;
00316     float             myLastFrameTime;
00317     bool              myIsExternal;
00318     unsigned int      myFramerateLimit;
00319     int               mySetCursorPosX;
00320     int               mySetCursorPosY;
00321 };
00322
00323 } // namespace sf
00324
00325
00326 #endif // SFML_WINDOW_HPP


  • File List

Window.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Window/Window.hpp>
00029 #include <SFML/Window/Context.hpp>
00030 #include <SFML/Window/WindowImpl.hpp>
00031 #include <SFML/System/Sleep.hpp>
00032 #include <iostream>
00033
00034
00036 // Private data
00038 namespace
00039 {
00040     const sf::Window* FullscreenWindow = NULL;
00041 }
00042
00043
00044 namespace sf
00045 {
00049 Window::Window() :
00050 myWindow        (NULL),
00051 myLastFrameTime (0.f),
00052 myIsExternal    (false),
00053 myFramerateLimit(0),
00054 mySetCursorPosX (0xFFFF),
00055 mySetCursorPosY (0xFFFF)
00056 {
00057
00058 }
00059
00060
00064 Window::Window(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, const WindowSettings& Params) :
00065 myWindow        (NULL),
00066 myLastFrameTime (0.f),
00067 myIsExternal    (false),
00068 myFramerateLimit(0),
00069 mySetCursorPosX (0xFFFF),
00070 mySetCursorPosY (0xFFFF)
00071 {
00072     Create(Mode, Title, WindowStyle, Params);
00073 }
00074
00075
00079 Window::Window(WindowHandle Handle, const WindowSettings& Params) :
00080 myWindow        (NULL),
00081 myLastFrameTime (0.f),
00082 myIsExternal    (true),
00083 myFramerateLimit(0),
00084 mySetCursorPosX (0xFFFF),
00085 mySetCursorPosY (0xFFFF)
00086 {
00087     Create(Handle, Params);
00088 }
00089
00090
00094 Window::~Window()
00095 {
00096     // Close the window
00097     Close();
00098 }
00099
00100
00104 void Window::Create(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, const WindowSettings& Params)
00105 {
00106     // Destroy the previous window implementation
00107     Close();
00108
00109     // Fullscreen style requires some tests
00110     if (WindowStyle & Style::Fullscreen)
00111     {
00112         // Make sure there's not already a fullscreen window (only one is allowed)
00113         if (FullscreenWindow)
00114         {
00115             std::cerr << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl;
00116             WindowStyle &= ~Style::Fullscreen;
00117         }
00118         else
00119         {
00120             // Make sure the chosen video mode is compatible
00121             if (!Mode.IsValid())
00122             {
00123                 std::cerr << "The requested video mode is not available, switching to a valid mode" << std::endl;
00124                 Mode = VideoMode::GetMode(0);
00125             }
00126
00127             // Update the fullscreen window
00128             FullscreenWindow = this;
00129         }
00130     }
00131
00132     // Check validity of style
00133     if ((WindowStyle & Style::Close) || (WindowStyle & Style::Resize))
00134         WindowStyle |= Style::Titlebar;
00135
00136     // Activate the global context
00137     Context::GetGlobal().SetActive(true);
00138
00139     mySettings = Params;
00140     Initialize(priv::WindowImpl::New(Mode, Title, WindowStyle, mySettings));
00141 }
00142
00143
00147 void Window::Create(WindowHandle Handle, const WindowSettings& Params)
00148 {
00149     // Destroy the previous window implementation
00150     Close();
00151
00152     // Activate the global context
00153     Context::GetGlobal().SetActive(true);
00154
00155     mySettings = Params;
00156     Initialize(priv::WindowImpl::New(Handle, mySettings));
00157 }
00158
00159
00165 void Window::Close()
00166 {
00167     // Delete the window implementation
00168     delete myWindow;
00169     myWindow = NULL;
00170
00171     // Update the fullscreen window
00172     if (this == FullscreenWindow)
00173         FullscreenWindow = NULL;
00174 }
00175
00176
00182 bool Window::IsOpened() const
00183 {
00184     return myWindow != NULL;
00185 }
00186
00187
00191 unsigned int Window::GetWidth() const
00192 {
00193     return myWindow ? myWindow->GetWidth() : 0;
00194 }
00195
00196
00200 unsigned int Window::GetHeight() const
00201 {
00202     return myWindow ? myWindow->GetHeight() : 0;
00203 }
00204
00205
00209 const WindowSettings& Window::GetSettings() const
00210 {
00211     return mySettings;
00212 }
00213
00214
00218 bool Window::GetEvent(Event& EventReceived)
00219 {
00220     // Let the window implementation process incoming events if the events queue is empty
00221     if (myWindow && myEvents.empty())
00222         myWindow->DoEvents();
00223
00224     // Pop first event of queue, if not empty
00225     if (!myEvents.empty())
00226     {
00227         EventReceived = myEvents.front();
00228         myEvents.pop();
00229
00230         return true;
00231     }
00232
00233     return false;
00234 }
00235
00236
00240 void Window::UseVerticalSync(bool Enabled)
00241 {
00242     if (SetActive())
00243         myWindow->UseVerticalSync(Enabled);
00244 }
00245
00246
00250 void Window::ShowMouseCursor(bool Show)
00251 {
00252     if (myWindow)
00253         myWindow->ShowMouseCursor(Show);
00254 }
00255
00256
00260 void Window::SetCursorPosition(unsigned int Left, unsigned int Top)
00261 {
00262     if (myWindow)
00263     {
00264         // Keep coordinates for later checking (to reject the generated MouseMoved event)
00265         mySetCursorPosX = Left;
00266         mySetCursorPosY = Top;
00267
00268         myWindow->SetCursorPosition(Left, Top);
00269     }
00270 }
00271
00272
00276 void Window::SetPosition(int Left, int Top)
00277 {
00278     if (!myIsExternal)
00279     {
00280         if (myWindow)
00281             myWindow->SetPosition(Left, Top);
00282     }
00283     else
00284     {
00285         std::cerr << "Warning : trying to change the position of an external SFML window, which is not allowed" << std::endl;
00286     }
00287 }
00288
00289
00293 void Window::SetSize(unsigned int Width, unsigned int Height)
00294 {
00295     if (myWindow)
00296         myWindow->SetSize(Width, Height);
00297 }
00298
00299
00303 void Window::Show(bool State)
00304 {
00305     if (!myIsExternal)
00306     {
00307         if (myWindow)
00308             myWindow->Show(State);
00309     }
00310 }
00311
00312
00317 void Window::EnableKeyRepeat(bool Enabled)
00318 {
00319     if (myWindow)
00320         myWindow->EnableKeyRepeat(Enabled);
00321 }
00322
00323
00327 void Window::SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels)
00328 {
00329     if (myWindow)
00330         myWindow->SetIcon(Width, Height, Pixels);
00331 }
00332
00333
00338 bool Window::SetActive(bool Active) const
00339 {
00340     if (myWindow)
00341     {
00342         myWindow->SetActive(Active);
00343         return true;
00344     }
00345
00346     return false;
00347 }
00348
00349
00353 void Window::Display()
00354 {
00355     // Limit the framerate if needed
00356     if (myFramerateLimit > 0)
00357     {
00358         float RemainingTime = 1.f / myFramerateLimit - myClock.GetElapsedTime();
00359         if (RemainingTime > 0)
00360             Sleep(RemainingTime);
00361     }
00362
00363     // Measure the time elapsed since last frame
00364     myLastFrameTime = myClock.GetElapsedTime();
00365     myClock.Reset();
00366
00367     // Display the backbuffer on screen
00368     if (SetActive())
00369         myWindow->Display();
00370 }
00371
00372
00376 const Input& Window::GetInput() const
00377 {
00378     return myInput;
00379 }
00380
00381
00385 void Window::SetFramerateLimit(unsigned int Limit)
00386 {
00387     myFramerateLimit = Limit;
00388 }
00389
00390
00394 float Window::GetFrameTime() const
00395 {
00396     return myLastFrameTime;
00397 }
00398
00399
00404 void Window::SetJoystickThreshold(float Threshold)
00405 {
00406     if (myWindow)
00407         myWindow->SetJoystickThreshold(Threshold);
00408 }
00409
00410
00414 void Window::OnCreate()
00415 {
00416     // Nothing by default
00417 }
00418
00419
00423 void Window::OnEvent(const Event& EventReceived)
00424 {
00425     // Discard MouseMove events generated by SetCursorPosition
00426     if ((EventReceived.Type        == Event::MouseMoved) &&
00427         (EventReceived.MouseMove.X == mySetCursorPosX)   &&
00428         (EventReceived.MouseMove.Y == mySetCursorPosY))
00429     {
00430         mySetCursorPosX = 0xFFFF;
00431         mySetCursorPosY = 0xFFFF;
00432         return;
00433     }
00434
00435     myEvents.push(EventReceived);
00436 }
00437
00438
00442 void Window::Initialize(priv::WindowImpl* Window)
00443 {
00444     // Assign and initialize the new window
00445     myWindow = Window;
00446     myWindow->Initialize();
00447
00448     // Clear the event queue
00449     while (!myEvents.empty())
00450         myEvents.pop();
00451
00452     // Listen to events from the new window
00453     myWindow->AddListener(this);
00454     myWindow->AddListener(&myInput);
00455
00456     // Setup default behaviours (to get a consistent behaviour across different implementations)
00457     Show(true);
00458     UseVerticalSync(false);
00459     ShowMouseCursor(true);
00460     EnableKeyRepeat(true);
00461
00462     // Reset frame time
00463     myClock.Reset();
00464     myLastFrameTime = 0.f;
00465
00466     // Activate the window
00467     SetActive(true);
00468
00469     // Notify the derived class
00470     OnCreate();
00471 }
00472
00473 } // namespace sf


  • File List

Window.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_SFML_WINDOW_HPP
00026 #define SFML_SFML_WINDOW_HPP
00027
00029 // Headers
00031
00032 #include <SFML/System.hpp>
00033 #include <SFML/Window/Context.hpp>
00034 #include <SFML/Window/Event.hpp>
00035 #include <SFML/Window/Input.hpp>
00036 #include <SFML/Window/VideoMode.hpp>
00037 #include <SFML/Window/Window.hpp>
00038 #include <SFML/Window/WindowListener.hpp>
00039 #include <SFML/Window/WindowStyle.hpp>
00040 #include <SFML/Window/OpenGL.hpp>
00041
00042
00043 #endif // SFML_SFML_WINDOW_HPP


  • File List

WindowHandle.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_WINDOWHANDLE_HPP
00026 #define SFML_WINDOWHANDLE_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 namespace sf
00035 {
00040 #if defined(SFML_SYSTEM_WINDOWS)
00041
00042     // Windows defines a void* handle (HWND)
00043     typedef void* WindowHandle;
00044
00045 #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
00046
00047     // Unix - X11 defines an unsigned integer handle (Window)
00048     typedef unsigned long WindowHandle;
00049
00050 #elif defined(SFML_SYSTEM_MACOS)
00051
00052     // Mac OS X defines a void* handle (NSWindow)
00053     typedef void* WindowHandle;
00054
00055 #endif
00056
00057 } // namespace sf
00058
00059
00060 #endif // SFML_WINDOWHANDLE_HPP


  • File List

WindowImpl.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Window/WindowImpl.hpp>
00029 #include <SFML/Window/Event.hpp>
00030 #include <SFML/Window/WindowListener.hpp>
00031 #include <algorithm>
00032 #include <cmath>
00033
00034 #if defined(SFML_SYSTEM_WINDOWS)
00035
00036     #include <SFML/Window/Win32/WindowImplWin32.hpp>
00037     typedef sf::priv::WindowImplWin32 WindowImplType;
00038
00039 #elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
00040
00041     #include <SFML/Window/Linux/WindowImplX11.hpp>
00042     typedef sf::priv::WindowImplX11 WindowImplType;
00043
00044 #elif defined(SFML_SYSTEM_MACOS)
00045
00046     #include <SFML/Window/Cocoa/WindowImplCocoa.hpp>
00047     typedef sf::priv::WindowImplCocoa WindowImplType;
00048
00049 #endif
00050
00051
00052 namespace sf
00053 {
00054 namespace priv
00055 {
00059 WindowImpl* WindowImpl::New()
00060 {
00061     return new WindowImplType();
00062 }
00063
00064
00068 WindowImpl* WindowImpl::New(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, WindowSettings& Params)
00069 {
00070     return new WindowImplType(Mode, Title, WindowStyle, Params);
00071 }
00072
00073
00077 WindowImpl* WindowImpl::New(WindowHandle Handle, WindowSettings& Params)
00078 {
00079     return new WindowImplType(Handle, Params);
00080 }
00081
00082
00086 WindowImpl::WindowImpl() :
00087 myWidth       (0),
00088 myHeight      (0),
00089 myJoyThreshold(0.1f)
00090 {
00091 }
00092
00093
00097 WindowImpl::~WindowImpl()
00098 {
00099     // Nothing to do
00100 }
00101
00102
00106 void WindowImpl::AddListener(WindowListener* Listener)
00107 {
00108     if (Listener)
00109         myListeners.insert(Listener);
00110 }
00111
00112
00116 void WindowImpl::RemoveListener(WindowListener* Listener)
00117 {
00118     myListeners.erase(Listener);
00119 }
00120
00121
00125 void WindowImpl::Initialize()
00126 {
00127     // Initialize the joysticks
00128     for (unsigned int i = 0; i < Joy::Count; ++i)
00129     {
00130         myJoysticks[i].Initialize(i);
00131         myJoyStates[i] = myJoysticks[i].UpdateState();
00132     }
00133 }
00134
00135
00139 unsigned int WindowImpl::GetWidth() const
00140 {
00141     return myWidth;
00142 }
00143
00144
00148 unsigned int WindowImpl::GetHeight() const
00149 {
00150     return myHeight;
00151 }
00152
00153
00158 void WindowImpl::SetJoystickThreshold(float Threshold)
00159 {
00160     myJoyThreshold = Threshold;
00161 }
00162
00163
00167 void WindowImpl::DoEvents()
00168 {
00169     // Read the joysticks state and generate the appropriate events
00170     ProcessJoystickEvents();
00171
00172     // Let the derived class process other events
00173     ProcessEvents();
00174 }
00175
00176
00180 bool WindowImpl::IsContextActive()
00181 {
00182     return WindowImplType::IsContextActive();
00183 }
00184
00185
00189 void WindowImpl::SendEvent(const Event& EventToSend)
00190 {
00191     for (std::set<WindowListener*>::iterator i = myListeners.begin(); i != myListeners.end(); ++i)
00192     {
00193         (*i)->OnEvent(EventToSend);
00194     }
00195 }
00196
00197
00203 int WindowImpl::EvaluateConfig(const VideoMode& Mode, const WindowSettings& Settings, int ColorBits, int DepthBits, int StencilBits, int Antialiasing)
00204 {
00205     return abs(static_cast<int>(Mode.BitsPerPixel          - ColorBits))   +
00206            abs(static_cast<int>(Settings.DepthBits         - DepthBits))   +
00207            abs(static_cast<int>(Settings.StencilBits       - StencilBits)) +
00208            abs(static_cast<int>(Settings.AntialiasingLevel - Antialiasing));
00209 }
00210
00211
00215 void WindowImpl::ProcessJoystickEvents()
00216 {
00217     for (unsigned int i = 0; i < Joy::Count; ++i)
00218     {
00219         // Copy the previous state of the joystick and get the new one
00220         JoystickState PreviousState = myJoyStates[i];
00221         myJoyStates[i] = myJoysticks[i].UpdateState();
00222
00223         // Axis
00224         for (unsigned int j = 0; j < Joy::AxisCount; ++j)
00225         {
00226             Joy::Axis Axis = static_cast<Joy::Axis>(j);
00227             if (myJoysticks[i].HasAxis(Axis))
00228             {
00229                 float PrevPos = PreviousState.Axis[j];
00230                 float CurrPos = myJoyStates[i].Axis[j];
00231                 if (fabs(CurrPos - PrevPos) >= myJoyThreshold)
00232                 {
00233                     Event Event;
00234                     Event.Type               = Event::JoyMoved;
00235                     Event.JoyMove.JoystickId = i;
00236                     Event.JoyMove.Axis       = Axis;
00237                     Event.JoyMove.Position   = CurrPos;
00238                     SendEvent(Event);
00239                 }
00240             }
00241         }
00242
00243         // Buttons
00244         for (unsigned int j = 0; j < myJoysticks[i].GetButtonsCount(); ++j)
00245         {
00246             bool PrevPressed = PreviousState.Buttons[j];
00247             bool CurrPressed = myJoyStates[i].Buttons[j];
00248
00249             if ((!PrevPressed && CurrPressed) || (PrevPressed && !CurrPressed))
00250             {
00251                 Event Event;
00252                 Event.Type                 = CurrPressed ? Event::JoyButtonPressed : Event::JoyButtonReleased;
00253                 Event.JoyButton.JoystickId = i;
00254                 Event.JoyButton.Button     = j;
00255                 SendEvent(Event);
00256             }
00257         }
00258     }
00259 }
00260
00261
00262 } // namespace priv
00263
00264 } // namespace sf


  • File List

WindowImpl.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_WINDOWIMPL_HPP
00026 #define SFML_WINDOWIMPL_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <SFML/System/NonCopyable.hpp>
00033 #include <SFML/Window/Joystick.hpp>
00034 #include <SFML/Window/VideoMode.hpp>
00035 #include <SFML/Window/WindowHandle.hpp>
00036 #include <SFML/Window/WindowSettings.hpp>
00037 #include <set>
00038 #include <string>
00039
00040
00041 namespace sf
00042 {
00043 class Event;
00044 class WindowListener;
00045
00046 namespace priv
00047 {
00051 class WindowImpl : NonCopyable
00052 {
00053 public :
00054
00061     static WindowImpl* New();
00062
00074     static WindowImpl* New(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, WindowSettings& Params);
00075
00085     static WindowImpl* New(WindowHandle Handle, WindowSettings& Params);
00086
00087 public :
00088
00093     virtual ~WindowImpl();
00094
00101     void AddListener(WindowListener* Listener);
00102
00109     void RemoveListener(WindowListener* Listener);
00110
00115     void Initialize();
00116
00123     unsigned int GetWidth() const;
00124
00131     unsigned int GetHeight() const;
00132
00140     virtual void SetActive(bool Active = true) const = 0;
00141
00149     void SetJoystickThreshold(float Threshold);
00150
00155     void DoEvents();
00156
00163     static bool IsContextActive();
00164
00169     virtual void Display() = 0;
00170
00177     virtual void UseVerticalSync(bool Enabled) = 0;
00178
00185     virtual void ShowMouseCursor(bool Show) = 0;
00186
00194     virtual void SetCursorPosition(unsigned int Left, unsigned int Top) = 0;
00195
00203     virtual void SetPosition(int Left, int Top) = 0;
00204
00212     virtual void SetSize(unsigned int Width, unsigned int Height) = 0;
00213
00220     virtual void Show(bool State) = 0;
00221
00228     virtual void EnableKeyRepeat(bool Enabled) = 0;
00229
00238     virtual void SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels) = 0;
00239
00240 protected :
00241
00246     WindowImpl();
00247
00254     void SendEvent(const Event& EventToSend);
00255
00271     static int EvaluateConfig(const VideoMode& Mode, const WindowSettings& Settings, int ColorBits, int DepthBits, int StencilBits, int Antialiasing);
00272
00274     // Member data
00276     unsigned int myWidth;
00277     unsigned int myHeight;
00278
00279 private :
00280
00285     void ProcessJoystickEvents();
00286
00291     virtual void ProcessEvents() = 0;
00292
00294     // Member data
00296     std::set<WindowListener*> myListeners;
00297     Joystick                  myJoysticks[Joy::Count];
00298     JoystickState             myJoyStates[Joy::Count];
00299     float                     myJoyThreshold;
00300 };
00301
00302 } // namespace priv
00303
00304 } // namespace sf
00305
00306
00307 #endif // SFML_WINDOWIMPL_HPP


  • File List

WindowImplCocoa.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Lucas Soltic (ceylow@gmail.com) and Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_WINDOWIMPLCOCOA_HPP
00026 #define SFML_WINDOWIMPLCOCOA_HPP
00027
00029 // Headers
00031 #include <SFML/Window/Event.hpp>
00032 #include <SFML/Window/WindowImpl.hpp>
00033 #include <string>
00034
00035 #ifdef __OBJC__
00036 @class sfPrivWindow;
00037 typedef sfPrivWindow* sfPrivWindowRef;
00038 #else
00039 typedef void* sfPrivWindowRef;
00040 #endif
00041
00042 namespace sf
00043 {
00044 namespace priv
00045 {
00046
00050 class WindowImplCocoa : public WindowImpl
00051 {
00052 public :
00053
00059     WindowImplCocoa();
00060
00069     WindowImplCocoa(WindowHandle Handle, WindowSettings& params);
00070
00080     WindowImplCocoa(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, WindowSettings& params);
00081
00086     ~WindowImplCocoa();
00087
00094     static bool IsContextActive();
00095
00099     void HandleNotifiedEvent(Event& eventRef);
00100
00105     void HandleKeyDown(void *eventRef);
00106     void HandleKeyUp(void *eventRef);
00107     void HandleModifierKey(void *eventRef);
00108     void HandleMouseDown(void *eventRef);
00109     void HandleMouseUp(void *eventRef);
00110     void HandleMouseMove(void *eventRef);
00111     void HandleMouseWheel(void *eventRef);
00112
00116     static bool IsTextEvent(void *event);
00117 private :
00118
00123     virtual void Display();
00124
00129     virtual void ProcessEvents();
00130
00135     virtual void SetActive(bool Active = true) const;
00136
00141     virtual void UseVerticalSync(bool Enabled);
00142
00147     virtual void ShowMouseCursor(bool Show);
00148
00153     virtual void SetCursorPosition(unsigned int Left, unsigned int Top);
00154
00159     virtual void SetPosition(int Left, int Top);
00160
00165     virtual void SetSize(unsigned int Width, unsigned int Height);
00166
00171     virtual void Show(bool State);
00172
00177     virtual void EnableKeyRepeat(bool Enabled);
00178
00183     virtual void SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels);
00184
00185
00186
00190
00191
00193     // Member data
00195     sfPrivWindowRef myWrapper;
00196     bool myUseKeyRepeat;
00197     bool myMouseIn;
00198     float myWheelStatus;
00199 };
00200
00201 } // namespace priv
00202
00203 } // namespace sf
00204
00205 #endif // SFML_WINDOWIMPLCOCOA_HPP


  • File List

WindowImplWin32.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #define _WIN32_WINDOWS 0x0501
00029 #define _WIN32_WINNT   0x0501
00030 #include <SFML/Window/Win32/WindowImplWin32.hpp>
00031 #include <SFML/Window/WindowSettings.hpp>
00032 #include <SFML/Window/WindowStyle.hpp>
00033 #include <GL/gl.h>
00034 #include <SFML/Window/glext/wglext.h>
00035 #include <SFML/Window/glext/glext.h>
00036 #include <iostream>
00037 #include <vector>
00038
00039 // MinGW lacks the definition of some Win32 constants
00040 #ifndef XBUTTON1
00041     #define XBUTTON1 0x0001
00042 #endif
00043 #ifndef XBUTTON2
00044     #define XBUTTON2 0x0002
00045 #endif
00046 #ifndef MAPVK_VK_TO_VSC
00047     #define MAPVK_VK_TO_VSC (0)
00048 #endif
00049
00050
00051 namespace sf
00052 {
00053 namespace priv
00054 {
00056 // Static member data
00058 unsigned int     WindowImplWin32::ourWindowCount      = 0;
00059 const char*      WindowImplWin32::ourClassNameA       = "SFML_Window";
00060 const wchar_t*   WindowImplWin32::ourClassNameW       = L"SFML_Window";
00061 WindowImplWin32* WindowImplWin32::ourFullscreenWindow = NULL;
00062
00063
00068 WindowImplWin32::WindowImplWin32() :
00069 myHandle          (NULL),
00070 myCallback        (0),
00071 myCursor          (NULL),
00072 myIcon            (NULL),
00073 myKeyRepeatEnabled(true),
00074 myIsCursorIn      (false)
00075 {
00076     // Register the window class at first call
00077     if (ourWindowCount == 0)
00078         RegisterWindowClass();
00079
00080     // Use small dimensions
00081     myWidth  = 1;
00082     myHeight = 1;
00083
00084     // Create a dummy window (disabled and hidden)
00085     if (HasUnicodeSupport())
00086     {
00087         myHandle = CreateWindowW(ourClassNameW, L"", WS_POPUP | WS_DISABLED, 0, 0, myWidth, myHeight, NULL, NULL, GetModuleHandle(NULL), NULL);
00088     }
00089     else
00090     {
00091         myHandle = CreateWindowA(ourClassNameA, "", WS_POPUP | WS_DISABLED, 0, 0, myWidth, myHeight, NULL, NULL, GetModuleHandle(NULL), NULL);
00092     }
00093     ShowWindow(myHandle, SW_HIDE);
00094
00095     // Create the rendering context
00096     if (myHandle)
00097     {
00098         WindowSettings Params(0, 0, 0);
00099         CreateContext(VideoMode(myWidth, myHeight, 32), Params);
00100
00101         // Don't activate by default
00102         SetActive(false);
00103     }
00104 }
00105
00106
00110 WindowImplWin32::WindowImplWin32(WindowHandle Handle, WindowSettings& Params) :
00111 myHandle          (NULL),
00112 myCallback        (0),
00113 myCursor          (NULL),
00114 myIcon            (NULL),
00115 myKeyRepeatEnabled(true),
00116 myIsCursorIn      (false)
00117 {
00118     // Save window handle
00119     myHandle = static_cast<HWND>(Handle);
00120
00121     if (myHandle)
00122     {
00123         // Get window client size
00124         RECT Rect;
00125         GetClientRect(myHandle, &Rect);
00126         myWidth  = Rect.right - Rect.left;
00127         myHeight = Rect.bottom - Rect.top;
00128
00129         // Create the rendering context
00130         VideoMode Mode(myWidth, myHeight, VideoMode::GetDesktopMode().BitsPerPixel);
00131         CreateContext(Mode, Params);
00132
00133         // We change the event procedure of the control (it is important to save the old one)
00134         SetWindowLongPtr(myHandle, GWLP_USERDATA, reinterpret_cast<long>(this));
00135         myCallback = SetWindowLongPtr(myHandle, GWLP_WNDPROC, reinterpret_cast<long>(&WindowImplWin32::GlobalOnEvent));
00136     }
00137 }
00138
00139
00143 WindowImplWin32::WindowImplWin32(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, WindowSettings& Params) :
00144 myHandle          (NULL),
00145 myCallback        (0),
00146 myCursor          (NULL),
00147 myIcon            (NULL),
00148 myKeyRepeatEnabled(true),
00149 myIsCursorIn      (false)
00150 {
00151     // Register the window class at first call
00152     if (ourWindowCount == 0)
00153         RegisterWindowClass();
00154
00155     // Compute position and size
00156     HDC ScreenDC = GetDC(NULL);
00157     int Left   = (GetDeviceCaps(ScreenDC, HORZRES) - Mode.Width)  / 2;
00158     int Top    = (GetDeviceCaps(ScreenDC, VERTRES) - Mode.Height) / 2;
00159     int Width  = myWidth  = Mode.Width;
00160     int Height = myHeight = Mode.Height;
00161     ReleaseDC(NULL, ScreenDC);
00162
00163     // Choose the window style according to the Style parameter
00164     DWORD Win32Style = WS_VISIBLE;
00165     if (WindowStyle == Style::None)
00166     {
00167         Win32Style |= WS_POPUP;
00168     }
00169     else
00170     {
00171         if (WindowStyle & Style::Titlebar) Win32Style |= WS_CAPTION | WS_MINIMIZEBOX;
00172         if (WindowStyle & Style::Resize)   Win32Style |= WS_THICKFRAME | WS_MAXIMIZEBOX;
00173         if (WindowStyle & Style::Close)    Win32Style |= WS_SYSMENU;
00174     }
00175
00176     // In windowed mode, adjust width and height so that window will have the requested client area
00177     bool Fullscreen = (WindowStyle & Style::Fullscreen) != 0;
00178     if (!Fullscreen)
00179     {
00180         RECT Rect = {0, 0, Width, Height};
00181         AdjustWindowRect(&Rect, Win32Style, false);
00182         Width  = Rect.right - Rect.left;
00183         Height = Rect.bottom - Rect.top;
00184     }
00185
00186     // Create the window
00187     if (HasUnicodeSupport())
00188     {
00189         wchar_t WTitle[256];
00190         int NbChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, Title.c_str(), static_cast<int>(Title.size()), WTitle, sizeof(WTitle) / sizeof(*WTitle));
00191         WTitle[NbChars] = L'\0';
00192         myHandle = CreateWindowW(ourClassNameW, WTitle, Win32Style, Left, Top, Width, Height, NULL, NULL, GetModuleHandle(NULL), this);
00193     }
00194     else
00195     {
00196         myHandle = CreateWindowA(ourClassNameA, Title.c_str(), Win32Style, Left, Top, Width, Height, NULL, NULL, GetModuleHandle(NULL), this);
00197     }
00198
00199     // Switch to fullscreen if requested
00200     if (Fullscreen)
00201         SwitchToFullscreen(Mode);
00202
00203     // Create the rendering context
00204     if (myHandle)
00205         CreateContext(Mode, Params);
00206
00207     // Increment window count
00208     ourWindowCount++;
00209
00210     // Get the actual size of the window, which can be smaller even after the call to AdjustWindowRect
00211     // This happens when the window is bigger than the desktop
00212     RECT ActualRect;
00213     GetClientRect(myHandle, &ActualRect);
00214     myWidth  = ActualRect.right - ActualRect.left;
00215     myHeight = ActualRect.bottom - ActualRect.top;
00216 }
00217
00218
00222 WindowImplWin32::~WindowImplWin32()
00223 {
00224     // Destroy the custom icon, if any
00225     if (myIcon)
00226         DestroyIcon(myIcon);
00227
00228     if (!myCallback)
00229     {
00230         // Destroy the window
00231         if (myHandle)
00232             DestroyWindow(myHandle);
00233
00234         // Decrement the window count
00235         ourWindowCount--;
00236
00237         // Unregister window class if we were the last window
00238         if (ourWindowCount == 0)
00239         {
00240             if (HasUnicodeSupport())
00241             {
00242                 UnregisterClassW(ourClassNameW, GetModuleHandle(NULL));
00243             }
00244             else
00245             {
00246                 UnregisterClassA(ourClassNameA, GetModuleHandle(NULL));
00247             }
00248         }
00249     }
00250     else
00251     {
00252         // The window is external : remove the hook on its message callback
00253         SetWindowLongPtr(myHandle, GWLP_WNDPROC, myCallback);
00254     }
00255 }
00256
00257
00261 bool WindowImplWin32::IsContextActive()
00262 {
00263     return wglGetCurrentContext() != NULL;
00264 }
00265
00266
00270 void WindowImplWin32::ProcessEvents()
00271 {
00272     // We update the window only if we own it
00273     if (!myCallback)
00274     {
00275         MSG Message;
00276         while (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE))
00277         {
00278             TranslateMessage(&Message);
00279             DispatchMessage(&Message);
00280         }
00281     }
00282 }
00283
00284
00288 void WindowImplWin32::Display()
00289 {
00290     if (myDeviceContext && myGLContext)
00291         SwapBuffers(myDeviceContext);
00292 }
00293
00294
00298 void WindowImplWin32::SetActive(bool Active) const
00299 {
00300     if (Active)
00301     {
00302         if (myDeviceContext && myGLContext && (wglGetCurrentContext() != myGLContext))
00303             wglMakeCurrent(myDeviceContext, myGLContext);
00304     }
00305     else
00306     {
00307         if (wglGetCurrentContext() == myGLContext)
00308             wglMakeCurrent(NULL, NULL);
00309     }
00310 }
00311
00312
00316 void WindowImplWin32::UseVerticalSync(bool Enabled)
00317 {
00318     PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = reinterpret_cast<PFNWGLSWAPINTERVALEXTPROC>(wglGetProcAddress("wglSwapIntervalEXT"));
00319     if (wglSwapIntervalEXT)
00320         wglSwapIntervalEXT(Enabled ? 1 : 0);
00321 }
00322
00323
00327 void WindowImplWin32::ShowMouseCursor(bool Show)
00328 {
00329     if (Show)
00330         myCursor = LoadCursor(NULL, IDC_ARROW);
00331     else
00332         myCursor = NULL;
00333
00334     SetCursor(myCursor);
00335 }
00336
00337
00341 void WindowImplWin32::SetCursorPosition(unsigned int Left, unsigned int Top)
00342 {
00343     POINT Pos = {Left, Top};
00344     ClientToScreen(myHandle, &Pos);
00345     SetCursorPos(Pos.x, Pos.y);
00346 }
00347
00348
00352 void WindowImplWin32::SetPosition(int Left, int Top)
00353 {
00354     SetWindowPos(myHandle, NULL, Left, Top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
00355 }
00356
00357
00361 void WindowImplWin32::SetSize(unsigned int Width, unsigned int Height)
00362 {
00363     // SetWindowPos wants the total size of the window (including title bar and borders),
00364     // so we have to compute it
00365     RECT Rect = {0, 0, Width, Height};
00366     AdjustWindowRect(&Rect, GetWindowLong(myHandle, GWL_STYLE), false);
00367     Width  = Rect.right - Rect.left;
00368     Height = Rect.bottom - Rect.top;
00369
00370     SetWindowPos(myHandle, NULL, 0, 0, Width, Height, SWP_NOMOVE | SWP_NOZORDER);
00371 }
00372
00373
00377 void WindowImplWin32::Show(bool State)
00378 {
00379     ShowWindow(myHandle, State ? SW_SHOW : SW_HIDE);
00380 }
00381
00382
00386 void WindowImplWin32::EnableKeyRepeat(bool Enabled)
00387 {
00388     myKeyRepeatEnabled = Enabled;
00389 }
00390
00391
00395 void WindowImplWin32::SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels)
00396 {
00397     // First destroy the previous one
00398     if (myIcon)
00399         DestroyIcon(myIcon);
00400
00401     // Windows wants BGRA pixels : swap red and blue channels
00402     std::vector<Uint8> IconPixels(Width * Height * 4);
00403     for (std::size_t i = 0; i < IconPixels.size() / 4; ++i)
00404     {
00405         IconPixels[i * 4 + 0] = Pixels[i * 4 + 2];
00406         IconPixels[i * 4 + 1] = Pixels[i * 4 + 1];
00407         IconPixels[i * 4 + 2] = Pixels[i * 4 + 0];
00408         IconPixels[i * 4 + 3] = Pixels[i * 4 + 3];
00409     }
00410
00411     // Create the icon from the pixels array
00412     myIcon = CreateIcon(GetModuleHandle(NULL), Width, Height, 1, 32, NULL, &IconPixels[0]);
00413
00414     // Set it as both big and small icon of the window
00415     if (myIcon)
00416     {
00417         SendMessage(myHandle, WM_SETICON, ICON_BIG,   (LPARAM)myIcon);
00418         SendMessage(myHandle, WM_SETICON, ICON_SMALL, (LPARAM)myIcon);
00419     }
00420     else
00421     {
00422         std::cerr << "Failed to set the window's icon" << std::endl;
00423     }
00424 }
00425
00426
00430 void WindowImplWin32::RegisterWindowClass()
00431 {
00432     if (HasUnicodeSupport())
00433     {
00434         WNDCLASSW WindowClass;
00435         WindowClass.style         = 0;
00436         WindowClass.lpfnWndProc   = &WindowImplWin32::GlobalOnEvent;
00437         WindowClass.cbClsExtra    = 0;
00438         WindowClass.cbWndExtra    = 0;
00439         WindowClass.hInstance     = GetModuleHandle(NULL);
00440         WindowClass.hIcon         = NULL;
00441         WindowClass.hCursor       = 0;
00442         WindowClass.hbrBackground = 0;
00443         WindowClass.lpszMenuName  = NULL;
00444         WindowClass.lpszClassName = ourClassNameW;
00445         RegisterClassW(&WindowClass);
00446     }
00447     else
00448     {
00449         WNDCLASSA WindowClass;
00450         WindowClass.style         = 0;
00451         WindowClass.lpfnWndProc   = &WindowImplWin32::GlobalOnEvent;
00452         WindowClass.cbClsExtra    = 0;
00453         WindowClass.cbWndExtra    = 0;
00454         WindowClass.hInstance     = GetModuleHandle(NULL);
00455         WindowClass.hIcon         = NULL;
00456         WindowClass.hCursor       = 0;
00457         WindowClass.hbrBackground = 0;
00458         WindowClass.lpszMenuName  = NULL;
00459         WindowClass.lpszClassName = ourClassNameA;
00460         RegisterClassA(&WindowClass);
00461     }
00462 }
00463
00464
00468 void WindowImplWin32::SwitchToFullscreen(const VideoMode& Mode)
00469 {
00470     DEVMODE DevMode;
00471     DevMode.dmSize       = sizeof(DEVMODE);
00472     DevMode.dmPelsWidth  = Mode.Width;
00473     DevMode.dmPelsHeight = Mode.Height;
00474     DevMode.dmBitsPerPel = Mode.BitsPerPixel;
00475     DevMode.dmFields     = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
00476
00477     // Apply fullscreen mode
00478     if (ChangeDisplaySettings(&DevMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
00479     {
00480         std::cerr << "Failed to change display mode for fullscreen" << std::endl;
00481         return;
00482     }
00483
00484     // Make the window flags compatible with fullscreen mode
00485     SetWindowLong(myHandle, GWL_STYLE, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
00486     SetWindowLong(myHandle, GWL_EXSTYLE, WS_EX_APPWINDOW);
00487
00488     // Resize the window so that it fits the entire screen
00489     SetWindowPos(myHandle, HWND_TOP, 0, 0, Mode.Width, Mode.Height, SWP_FRAMECHANGED);
00490     ShowWindow(myHandle, SW_SHOW);
00491
00492     // Set "this" as the current fullscreen window
00493     ourFullscreenWindow = this;
00494 }
00495
00496
00500 void WindowImplWin32::CreateContext(const VideoMode& Mode, WindowSettings& Params)
00501 {
00502     // Get the device context attached to the window
00503     myDeviceContext = GetDC(myHandle);
00504     if (myDeviceContext == NULL)
00505     {
00506         std::cerr << "Failed to get device context of window -- cannot create OpenGL context" << std::endl;
00507         return;
00508     }
00509
00510     // Let's find a suitable pixel format -- first try with antialiasing
00511     int BestFormat = 0;
00512     if (Params.AntialiasingLevel > 0)
00513     {
00514         // Get the wglChoosePixelFormatARB function (it is an extension)
00515         PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = reinterpret_cast<PFNWGLCHOOSEPIXELFORMATARBPROC>(wglGetProcAddress("wglChoosePixelFormatARB"));
00516         if (wglChoosePixelFormatARB)
00517         {
00518             // Define the basic attributes we want for our window
00519             int IntAttributes[] =
00520             {
00521                 WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
00522                 WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
00523                 WGL_ACCELERATION_ARB,   WGL_FULL_ACCELERATION_ARB,
00524                 WGL_DOUBLE_BUFFER_ARB,  GL_TRUE,
00525                 WGL_SAMPLE_BUFFERS_ARB, (Params.AntialiasingLevel ? GL_TRUE : GL_FALSE),
00526                 WGL_SAMPLES_ARB,        Params.AntialiasingLevel,
00527                 0,                      0
00528             };
00529
00530             // Let's check how many formats are supporting our requirements
00531             int   Formats[128];
00532             UINT  NbFormats;
00533             float FloatAttributes[] = {0, 0};
00534             bool  IsValid = wglChoosePixelFormatARB(myDeviceContext, IntAttributes, FloatAttributes, sizeof(Formats) / sizeof(*Formats), Formats, &NbFormats) != 0;
00535             if (!IsValid || (NbFormats == 0))
00536             {
00537                 if (Params.AntialiasingLevel > 2)
00538                 {
00539                     // No format matching our needs : reduce the multisampling level
00540                     std::cerr << "Failed to find a pixel format supporting "
00541                               << Params.AntialiasingLevel << " antialiasing levels ; trying with 2 levels" << std::endl;
00542
00543                     Params.AntialiasingLevel = IntAttributes[11] = 2;
00544                     IsValid = wglChoosePixelFormatARB(myDeviceContext, IntAttributes, FloatAttributes, sizeof(Formats) / sizeof(*Formats), Formats, &NbFormats) != 0;
00545                 }
00546
00547                 if (!IsValid || (NbFormats == 0))
00548                 {
00549                     // Cannot find any pixel format supporting multisampling ; disabling antialiasing
00550                     std::cerr << "Failed to find a pixel format supporting antialiasing ; antialiasing will be disabled" << std::endl;
00551                     Params.AntialiasingLevel = 0;
00552                 }
00553             }
00554
00555             // Get the best format among the returned ones
00556             if (IsValid && (NbFormats > 0))
00557             {
00558                 int BestScore = 0xFFFF;
00559                 for (UINT i = 0; i < NbFormats; ++i)
00560                 {
00561                     // Get the current format's attributes
00562                     PIXELFORMATDESCRIPTOR Attribs;
00563                     Attribs.nSize    = sizeof(PIXELFORMATDESCRIPTOR);
00564                     Attribs.nVersion = 1;
00565                     DescribePixelFormat(myDeviceContext, Formats[i], sizeof(PIXELFORMATDESCRIPTOR), &Attribs);
00566
00567                     // Evaluate the current configuration
00568                     int Color = Attribs.cRedBits + Attribs.cGreenBits + Attribs.cBlueBits + Attribs.cAlphaBits;
00569                     int Score = EvaluateConfig(Mode, Params, Color, Attribs.cDepthBits, Attribs.cStencilBits, Params.AntialiasingLevel);
00570
00571                     // Keep it if it's better than the current best
00572                     if (Score < BestScore)
00573                     {
00574                         BestScore  = Score;
00575                         BestFormat = Formats[i];
00576                     }
00577                 }
00578             }
00579         }
00580         else
00581         {
00582             // wglChoosePixelFormatARB not supported ; disabling antialiasing
00583             std::cerr << "Antialiasing is not supported ; it will be disabled" << std::endl;
00584             Params.AntialiasingLevel = 0;
00585         }
00586     }
00587
00588     // Find a pixel format with no antialiasing, if not needed or not supported
00589     if (BestFormat == 0)
00590     {
00591         // Setup a pixel format descriptor from the rendering settings
00592         PIXELFORMATDESCRIPTOR PixelDescriptor;
00593         ZeroMemory(&PixelDescriptor, sizeof(PIXELFORMATDESCRIPTOR));
00594         PixelDescriptor.nSize        = sizeof(PIXELFORMATDESCRIPTOR);
00595         PixelDescriptor.nVersion     = 1;
00596         PixelDescriptor.iLayerType   = PFD_MAIN_PLANE;
00597         PixelDescriptor.dwFlags      = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
00598         PixelDescriptor.iPixelType   = PFD_TYPE_RGBA;
00599         PixelDescriptor.cColorBits   = static_cast<BYTE>(Mode.BitsPerPixel);
00600         PixelDescriptor.cDepthBits   = static_cast<BYTE>(Params.DepthBits);
00601         PixelDescriptor.cStencilBits = static_cast<BYTE>(Params.StencilBits);
00602         PixelDescriptor.cAlphaBits   = Mode.BitsPerPixel == 32 ? 8 : 0;
00603
00604         // Get the pixel format that best matches our requirements
00605         BestFormat = ChoosePixelFormat(myDeviceContext, &PixelDescriptor);
00606         if (BestFormat == 0)
00607         {
00608             std::cerr << "Failed to find a suitable pixel format for device context -- cannot create OpenGL context" << std::endl;
00609             return;
00610         }
00611     }
00612
00613     // Extract the depth and stencil bits from the chosen format
00614     PIXELFORMATDESCRIPTOR ActualFormat;
00615     ActualFormat.nSize    = sizeof(PIXELFORMATDESCRIPTOR);
00616     ActualFormat.nVersion = 1;
00617     DescribePixelFormat(myDeviceContext, BestFormat, sizeof(PIXELFORMATDESCRIPTOR), &ActualFormat);
00618     Params.DepthBits   = ActualFormat.cDepthBits;
00619     Params.StencilBits = ActualFormat.cStencilBits;
00620
00621     // Set the chosen pixel format
00622     if (!SetPixelFormat(myDeviceContext, BestFormat, &ActualFormat))
00623     {
00624         std::cerr << "Failed to set pixel format for device context -- cannot create OpenGL context" << std::endl;
00625         return;
00626     }
00627
00628     // Create the OpenGL context from the device context
00629     myGLContext = wglCreateContext(myDeviceContext);
00630     if (myGLContext == NULL)
00631     {
00632         std::cerr << "Failed to create an OpenGL context for this window" << std::endl;
00633         return;
00634     }
00635
00636     // Share display lists with other contexts
00637     HGLRC CurrentContext = wglGetCurrentContext();
00638     if (CurrentContext)
00639         wglShareLists(CurrentContext, myGLContext);
00640
00641     // Activate the context
00642     SetActive(true);
00643
00644     // Enable multisampling
00645     if (Params.AntialiasingLevel > 0)
00646         glEnable(GL_MULTISAMPLE_ARB);
00647 }
00648
00649
00653 void WindowImplWin32::Cleanup()
00654 {
00655     // Restore the previous video mode (in case we were running in fullscreen)
00656     if (ourFullscreenWindow == this)
00657     {
00658         ChangeDisplaySettings(NULL, 0);
00659         ourFullscreenWindow = NULL;
00660     }
00661
00662     // Unhide the mouse cursor (in case it was hidden)
00663     ShowMouseCursor(true);
00664
00665     // Destroy the OpenGL context
00666     if (myGLContext)
00667     {
00668         // Unbind the context before destroying it
00669         SetActive(false);
00670
00671         wglDeleteContext(myGLContext);
00672         myGLContext = NULL;
00673     }
00674     if (myDeviceContext)
00675     {
00676         ReleaseDC(myHandle, myDeviceContext);
00677         myDeviceContext = NULL;
00678     }
00679 }
00680
00681
00685 void WindowImplWin32::ProcessEvent(UINT Message, WPARAM WParam, LPARAM LParam)
00686 {
00687     // Don't process any message until window is created
00688     if (myHandle == NULL)
00689         return;
00690
00691     switch (Message)
00692     {
00693         // Destroy event
00694         case WM_DESTROY :
00695         {
00696             // Here we must cleanup resources !
00697             Cleanup();
00698             break;
00699         }
00700
00701         // Set cursor event
00702         case WM_SETCURSOR :
00703         {
00704             // The mouse has moved, if the cursor is in our window we must refresh the cursor
00705             if (LOWORD(LParam) == HTCLIENT)
00706                 SetCursor(myCursor);
00707
00708             break;
00709         }
00710
00711         // Close event
00712         case WM_CLOSE :
00713         {
00714             Event Evt;
00715             Evt.Type = Event::Closed;
00716             SendEvent(Evt);
00717             break;
00718         }
00719
00720         // Resize event
00721         case WM_SIZE :
00722         {
00723             // Update window size
00724             RECT Rect;
00725             GetClientRect(myHandle, &Rect);
00726             myWidth  = Rect.right - Rect.left;
00727             myHeight = Rect.bottom - Rect.top;
00728
00729             Event Evt;
00730             Evt.Type        = Event::Resized;
00731             Evt.Size.Width  = myWidth;
00732             Evt.Size.Height = myHeight;
00733             SendEvent(Evt);
00734             break;
00735         }
00736
00737         // Gain focus event
00738         case WM_SETFOCUS :
00739         {
00740             Event Evt;
00741             Evt.Type = Event::GainedFocus;
00742             SendEvent(Evt);
00743             break;
00744         }
00745
00746         // Lost focus event
00747         case WM_KILLFOCUS :
00748         {
00749             Event Evt;
00750             Evt.Type = Event::LostFocus;
00751             SendEvent(Evt);
00752             break;
00753         }
00754
00755         // Text event
00756         case WM_CHAR :
00757         {
00758             if (myKeyRepeatEnabled || ((LParam & (1 << 30)) == 0))
00759             {
00760                 Event Evt;
00761                 Evt.Type = Event::TextEntered;
00762                 Evt.Text.Unicode = static_cast<Uint32>(WParam);
00763                 SendEvent(Evt);
00764             }
00765             break;
00766         }
00767
00768         // Keydown event
00769         case WM_KEYDOWN :
00770         case WM_SYSKEYDOWN :
00771         {
00772             if (myKeyRepeatEnabled || ((HIWORD(LParam) & KF_REPEAT) == 0))
00773             {
00774                 Event Evt;
00775                 Evt.Type        = Event::KeyPressed;
00776                 Evt.Key.Alt     = HIWORD(GetAsyncKeyState(VK_MENU))    != 0;
00777                 Evt.Key.Control = HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0;
00778                 Evt.Key.Shift   = HIWORD(GetAsyncKeyState(VK_SHIFT))   != 0;
00779                 Evt.Key.Code    = VirtualKeyCodeToSF(WParam, LParam);
00780                 SendEvent(Evt);
00781             }
00782             break;
00783         }
00784
00785         // Keyup event
00786         case WM_KEYUP :
00787         case WM_SYSKEYUP :
00788         {
00789             Event Evt;
00790             Evt.Type        = Event::KeyReleased;
00791             Evt.Key.Alt     = HIWORD(GetAsyncKeyState(VK_MENU))    != 0;
00792             Evt.Key.Control = HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0;
00793             Evt.Key.Shift   = HIWORD(GetAsyncKeyState(VK_SHIFT))   != 0;
00794             Evt.Key.Code    = VirtualKeyCodeToSF(WParam, LParam);
00795             SendEvent(Evt);
00796
00797             break;
00798         }
00799
00800         // Mouse wheel event
00801         case WM_MOUSEWHEEL :
00802         {
00803             Event Evt;
00804             Evt.Type = Event::MouseWheelMoved;
00805             Evt.MouseWheel.Delta = static_cast<Int16>(HIWORD(WParam)) / 120;
00806             SendEvent(Evt);
00807             break;
00808         }
00809
00810         // Mouse left button down event
00811         case WM_LBUTTONDOWN :
00812         {
00813             Event Evt;
00814             Evt.Type               = Event::MouseButtonPressed;
00815             Evt.MouseButton.Button = Mouse::Left;
00816             Evt.MouseButton.X      = LOWORD(LParam);
00817             Evt.MouseButton.Y      = HIWORD(LParam);
00818             SendEvent(Evt);
00819             break;
00820         }
00821
00822         // Mouse left button up event
00823         case WM_LBUTTONUP :
00824         {
00825             Event Evt;
00826             Evt.Type               = Event::MouseButtonReleased;
00827             Evt.MouseButton.Button = Mouse::Left;
00828             Evt.MouseButton.X      = LOWORD(LParam);
00829             Evt.MouseButton.Y      = HIWORD(LParam);
00830             SendEvent(Evt);
00831             break;
00832         }
00833
00834         // Mouse right button down event
00835         case WM_RBUTTONDOWN :
00836         {
00837             Event Evt;
00838             Evt.Type               = Event::MouseButtonPressed;
00839             Evt.MouseButton.Button = Mouse::Right;
00840             Evt.MouseButton.X      = LOWORD(LParam);
00841             Evt.MouseButton.Y      = HIWORD(LParam);
00842             SendEvent(Evt);
00843             break;
00844         }
00845
00846         // Mouse right button up event
00847         case WM_RBUTTONUP :
00848         {
00849             Event Evt;
00850             Evt.Type               = Event::MouseButtonReleased;
00851             Evt.MouseButton.Button = Mouse::Right;
00852             Evt.MouseButton.X      = LOWORD(LParam);
00853             Evt.MouseButton.Y      = HIWORD(LParam);
00854             SendEvent(Evt);
00855             break;
00856         }
00857
00858         // Mouse wheel button down event
00859         case WM_MBUTTONDOWN :
00860         {
00861             Event Evt;
00862             Evt.Type               = Event::MouseButtonPressed;
00863             Evt.MouseButton.Button = Mouse::Middle;
00864             Evt.MouseButton.X      = LOWORD(LParam);
00865             Evt.MouseButton.Y      = HIWORD(LParam);
00866             SendEvent(Evt);
00867             break;
00868         }
00869
00870         // Mouse wheel button up event
00871         case WM_MBUTTONUP :
00872         {
00873             Event Evt;
00874             Evt.Type               = Event::MouseButtonReleased;
00875             Evt.MouseButton.Button = Mouse::Middle;
00876             Evt.MouseButton.X      = LOWORD(LParam);
00877             Evt.MouseButton.Y      = HIWORD(LParam);
00878             SendEvent(Evt);
00879             break;
00880         }
00881
00882         // Mouse X button down event
00883         case WM_XBUTTONDOWN :
00884         {
00885             Event Evt;
00886             Evt.Type               = Event::MouseButtonPressed;
00887             Evt.MouseButton.Button = HIWORD(WParam) == XBUTTON1 ? Mouse::XButton1 : Mouse::XButton2;
00888             Evt.MouseButton.X      = LOWORD(LParam);
00889             Evt.MouseButton.Y      = HIWORD(LParam);
00890             SendEvent(Evt);
00891             break;
00892         }
00893
00894         // Mouse X button up event
00895         case WM_XBUTTONUP :
00896         {
00897             Event Evt;
00898             Evt.Type               = Event::MouseButtonReleased;
00899             Evt.MouseButton.Button = HIWORD(WParam) == XBUTTON1 ? Mouse::XButton1 : Mouse::XButton2;
00900             Evt.MouseButton.X      = LOWORD(LParam);
00901             Evt.MouseButton.Y      = HIWORD(LParam);
00902             SendEvent(Evt);
00903             break;
00904         }
00905
00906         // Mouse move event
00907         case WM_MOUSEMOVE :
00908         {
00909             // Check if we need to generate a MouseEntered event
00910             if (!myIsCursorIn)
00911             {
00912                 TRACKMOUSEEVENT MouseEvent;
00913                 MouseEvent.cbSize    = sizeof(TRACKMOUSEEVENT);
00914                 MouseEvent.hwndTrack = myHandle;
00915                 MouseEvent.dwFlags   = TME_LEAVE;
00916                 TrackMouseEvent(&MouseEvent);
00917
00918                 myIsCursorIn = true;
00919
00920                 Event Evt;
00921                 Evt.Type = Event::MouseEntered;
00922                 SendEvent(Evt);
00923             }
00924
00925             Event Evt;
00926             Evt.Type        = Event::MouseMoved;
00927             Evt.MouseMove.X = LOWORD(LParam);
00928             Evt.MouseMove.Y = HIWORD(LParam);
00929             SendEvent(Evt);
00930             break;
00931         }
00932
00933         // Mouse leave event
00934         case WM_MOUSELEAVE :
00935         {
00936             myIsCursorIn = false;
00937
00938             Event Evt;
00939             Evt.Type = Event::MouseLeft;
00940             SendEvent(Evt);
00941             break;
00942         }
00943     }
00944 }
00945
00946
00950 Key::Code WindowImplWin32::VirtualKeyCodeToSF(WPARAM VirtualKey, LPARAM Flags)
00951 {
00952     switch (VirtualKey)
00953     {
00954         // Check the scancode to distinguish between left and right shift
00955         case VK_SHIFT :
00956         {
00957             static UINT LShift = MapVirtualKey(VK_LSHIFT, MAPVK_VK_TO_VSC);
00958             UINT scancode = (Flags & (0xFF << 16)) >> 16;
00959             return scancode == LShift ? Key::LShift : Key::RShift;
00960         }
00961
00962         // Check the "extended" flag to distinguish between left and right alt
00963         case VK_MENU : return (HIWORD(Flags) & KF_EXTENDED) ? Key::RAlt : Key::LAlt;
00964
00965         // Check the "extended" flag to distinguish between left and right control
00966         case VK_CONTROL : return (HIWORD(Flags) & KF_EXTENDED) ? Key::RControl : Key::LControl;
00967
00968         // Other keys are reported properly
00969         case VK_LWIN :       return Key::LSystem;
00970         case VK_RWIN :       return Key::RSystem;
00971         case VK_APPS :       return Key::Menu;
00972         case VK_OEM_1 :      return Key::SemiColon;
00973         case VK_OEM_2 :      return Key::Slash;
00974         case VK_OEM_PLUS :   return Key::Equal;
00975         case VK_OEM_MINUS :  return Key::Dash;
00976         case VK_OEM_4 :      return Key::LBracket;
00977         case VK_OEM_6 :      return Key::RBracket;
00978         case VK_OEM_COMMA :  return Key::Comma;
00979         case VK_OEM_PERIOD : return Key::Period;
00980         case VK_OEM_7 :      return Key::Quote;
00981         case VK_OEM_5 :      return Key::BackSlash;
00982         case VK_OEM_3 :      return Key::Tilde;
00983         case VK_ESCAPE :     return Key::Escape;
00984         case VK_SPACE :      return Key::Space;
00985         case VK_RETURN :     return Key::Return;
00986         case VK_BACK :       return Key::Back;
00987         case VK_TAB :        return Key::Tab;
00988         case VK_PRIOR :      return Key::PageUp;
00989         case VK_NEXT :       return Key::PageDown;
00990         case VK_END :        return Key::End;
00991         case VK_HOME :       return Key::Home;
00992         case VK_INSERT :     return Key::Insert;
00993         case VK_DELETE :     return Key::Delete;
00994         case VK_ADD :        return Key::Add;
00995         case VK_SUBTRACT :   return Key::Subtract;
00996         case VK_MULTIPLY :   return Key::Multiply;
00997         case VK_DIVIDE :     return Key::Divide;
00998         case VK_PAUSE :      return Key::Pause;
00999         case VK_F1 :         return Key::F1;
01000         case VK_F2 :         return Key::F2;
01001         case VK_F3 :         return Key::F3;
01002         case VK_F4 :         return Key::F4;
01003         case VK_F5 :         return Key::F5;
01004         case VK_F6 :         return Key::F6;
01005         case VK_F7 :         return Key::F7;
01006         case VK_F8 :         return Key::F8;
01007         case VK_F9 :         return Key::F9;
01008         case VK_F10 :        return Key::F10;
01009         case VK_F11 :        return Key::F11;
01010         case VK_F12 :        return Key::F12;
01011         case VK_F13 :        return Key::F13;
01012         case VK_F14 :        return Key::F14;
01013         case VK_F15 :        return Key::F15;
01014         case VK_LEFT :       return Key::Left;
01015         case VK_RIGHT :      return Key::Right;
01016         case VK_UP :         return Key::Up;
01017         case VK_DOWN :       return Key::Down;
01018         case VK_NUMPAD0 :    return Key::Numpad0;
01019         case VK_NUMPAD1 :    return Key::Numpad1;
01020         case VK_NUMPAD2 :    return Key::Numpad2;
01021         case VK_NUMPAD3 :    return Key::Numpad3;
01022         case VK_NUMPAD4 :    return Key::Numpad4;
01023         case VK_NUMPAD5 :    return Key::Numpad5;
01024         case VK_NUMPAD6 :    return Key::Numpad6;
01025         case VK_NUMPAD7 :    return Key::Numpad7;
01026         case VK_NUMPAD8 :    return Key::Numpad8;
01027         case VK_NUMPAD9 :    return Key::Numpad9;
01028         case 'A' :           return Key::A;
01029         case 'Z' :           return Key::Z;
01030         case 'E' :           return Key::E;
01031         case 'R' :           return Key::R;
01032         case 'T' :           return Key::T;
01033         case 'Y' :           return Key::Y;
01034         case 'U' :           return Key::U;
01035         case 'I' :           return Key::I;
01036         case 'O' :           return Key::O;
01037         case 'P' :           return Key::P;
01038         case 'Q' :           return Key::Q;
01039         case 'S' :           return Key::S;
01040         case 'D' :           return Key::D;
01041         case 'F' :           return Key::F;
01042         case 'G' :           return Key::G;
01043         case 'H' :           return Key::H;
01044         case 'J' :           return Key::J;
01045         case 'K' :           return Key::K;
01046         case 'L' :           return Key::L;
01047         case 'M' :           return Key::M;
01048         case 'W' :           return Key::W;
01049         case 'X' :           return Key::X;
01050         case 'C' :           return Key::C;
01051         case 'V' :           return Key::V;
01052         case 'B' :           return Key::B;
01053         case 'N' :           return Key::N;
01054         case '0' :           return Key::Num0;
01055         case '1' :           return Key::Num1;
01056         case '2' :           return Key::Num2;
01057         case '3' :           return Key::Num3;
01058         case '4' :           return Key::Num4;
01059         case '5' :           return Key::Num5;
01060         case '6' :           return Key::Num6;
01061         case '7' :           return Key::Num7;
01062         case '8' :           return Key::Num8;
01063         case '9' :           return Key::Num9;
01064     }
01065
01066     return Key::Code(0);
01067 }
01068
01069
01075 bool WindowImplWin32::HasUnicodeSupport()
01076 {
01077     OSVERSIONINFO VersionInfo;
01078     ZeroMemory(&VersionInfo, sizeof(VersionInfo));
01079     VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
01080
01081     if (GetVersionEx(&VersionInfo))
01082     {
01083         return VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;
01084     }
01085     else
01086     {
01087         return false;
01088     }
01089 }
01090
01091
01095 LRESULT CALLBACK WindowImplWin32::GlobalOnEvent(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam)
01096 {
01097     // Associate handle and Window instance when the creation message is received
01098     if (Message == WM_CREATE)
01099     {
01100         // Get WindowImplWin32 instance (it was passed as the last argument of CreateWindow)
01101         long This = reinterpret_cast<long>(reinterpret_cast<CREATESTRUCT*>(LParam)->lpCreateParams);
01102
01103         // Set as the "user data" parameter of the window
01104         SetWindowLongPtr(Handle, GWLP_USERDATA, This);
01105     }
01106
01107     // Get the WindowImpl instance corresponding to the window handle
01108     WindowImplWin32* Window = reinterpret_cast<WindowImplWin32*>(GetWindowLongPtr(Handle, GWLP_USERDATA));
01109
01110     // Forward the event to the appropriate function
01111     if (Window)
01112     {
01113         Window->ProcessEvent(Message, WParam, LParam);
01114
01115         if (Window->myCallback)
01116             return CallWindowProc(reinterpret_cast<WNDPROC>(Window->myCallback), Handle, Message, WParam, LParam);
01117     }
01118
01119     // We don't forward the WM_CLOSE message to prevent the OS from automatically destroying the window
01120     if (Message == WM_CLOSE)
01121         return 0;
01122
01123     static const bool HasUnicode = HasUnicodeSupport();
01124     return HasUnicode ? DefWindowProcW(Handle, Message, WParam, LParam) :
01125                         DefWindowProcA(Handle, Message, WParam, LParam);
01126 }
01127
01128 } // namespace priv
01129
01130 } // namespace sf


  • File List

WindowImplWin32.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_WINDOWIMPLWIN32_HPP
00026 #define SFML_WINDOWIMPLWIN32_HPP
00027
00029 // Headers
00031 #include <SFML/Window/Event.hpp>
00032 #include <SFML/Window/WindowImpl.hpp>
00033 #include <windows.h>
00034 #include <string>
00035
00036
00037 namespace sf
00038 {
00039 namespace priv
00040 {
00044 class WindowImplWin32 : public WindowImpl
00045 {
00046 public :
00047
00053     WindowImplWin32();
00054
00062     WindowImplWin32(WindowHandle Handle, WindowSettings& Params);
00063
00073     WindowImplWin32(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, WindowSettings& Params);
00074
00079     ~WindowImplWin32();
00080
00087     static bool IsContextActive();
00088
00089 private :
00090
00095     virtual void ProcessEvents();
00096
00101     virtual void Display();
00102
00107     virtual void SetActive(bool Active = true) const;
00108
00113     virtual void UseVerticalSync(bool Enabled);
00114
00119     virtual void ShowMouseCursor(bool Show);
00120
00125     virtual void SetCursorPosition(unsigned int Left, unsigned int Top);
00126
00131     virtual void SetPosition(int Left, int Top);
00132
00137     virtual void SetSize(unsigned int Width, unsigned int Height);
00138
00143     virtual void Show(bool State);
00144
00149     virtual void EnableKeyRepeat(bool Enabled);
00150
00155     virtual void SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels);
00156
00161     void RegisterWindowClass();
00162
00169     void SwitchToFullscreen(const VideoMode& Mode);
00170
00178     void CreateContext(const VideoMode& Mode, WindowSettings& Params);
00179
00184     void Cleanup();
00185
00194     void ProcessEvent(UINT Message, WPARAM WParam, LPARAM LParam);
00195
00205     static Key::Code VirtualKeyCodeToSF(WPARAM VirtualKey, LPARAM Flags);
00206
00215     static bool HasUnicodeSupport();
00216
00228     static LRESULT CALLBACK GlobalOnEvent(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam);
00229
00231     // Static member data
00233     static unsigned int     ourWindowCount;
00234     static const char*      ourClassNameA;
00235     static const wchar_t*   ourClassNameW;
00236     static WindowImplWin32* ourFullscreenWindow;
00237
00239     // Member data
00241     HWND          myHandle;
00242     long          myCallback;
00243     HCURSOR       myCursor;
00244     HICON         myIcon;
00245     bool          myKeyRepeatEnabled;
00246     bool          myIsCursorIn;
00247     HDC           myDeviceContext;
00248     HGLRC         myGLContext;
00249 };
00250
00251 } // namespace priv
00252
00253 } // namespace sf
00254
00255 #endif // SFML_WINDOWIMPLWIN32_HPP


  • File List

WindowImplXXX.cpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00026 // Headers
00028 #include <SFML/Window/XXX/WindowImplXXX.hpp>
00029 #include <SFML/Window/WindowStyle.hpp>
00030 #include <GL/gl.h>
00031
00032
00033 namespace sf
00034 {
00035 namespace priv
00036 {
00041 WindowImplXXX::WindowImplXXX()
00042 {
00043     // Create a dummy window (with the fewest attributes -- it's just to have a valid support for an OpenGL context)
00044
00045     // Initialize myWidth and myHeight members from base class with the window size
00046
00047     // Create an OpenGL context in this window and DO NOT make it active
00048 }
00049
00050
00054 WindowImplXXX::WindowImplXXX(WindowHandle Handle, WindowSettings& Params)
00055 {
00056     // Make sure we'll be able to catch all the events of the given window
00057
00058     // Initialize myWidth and myHeight members from base class with the window size
00059
00060     // Create an OpenGL context in this window and make it active
00061 }
00062
00063
00067 WindowImplXXX::WindowImplXXX(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, WindowSettings& Params) :
00068 {
00069     // Create a new window with given size, title and style
00070
00071     // Initialize myWidth and myHeight members from base class with the window size
00072
00073     // Create an OpenGL context in this window and make it active
00074 }
00075
00076
00080 WindowImplXXX::~WindowImplXXX()
00081 {
00082     // Destroy the OpenGL context, the window and every resource allocated by this class
00083 }
00084
00085
00089 bool WindowImplXXX::IsContextActive()
00090 {
00091     // Should return whether xxxGetCurrentContext() is NULL or not;
00092 }
00093
00094
00098 void WindowImplXXX::Display()
00099 {
00100     // Swap OpenGL buffers (should be a call to xxxSwapBuffers)
00101 }
00102
00103
00107 void WindowImplXXX::ProcessEvents()
00108 {
00109     // Process every event for this window
00110
00111     // Generate a sf::Event and call SendEvent(Evt) for each event
00112 }
00113
00114
00118 void WindowImplXXX::SetActive(bool Active) const
00119 {
00120     // Bind / unbind OpenGL context (should be a call to xxxMakeCurrent)
00121 }
00122
00123
00127 void WindowImplXXX::UseVerticalSync(bool Enabled)
00128 {
00129     // Activate / deactivate vertical synchronization
00130     // usually using an OpenGL extension (should be a call to xxxSwapInterval)
00131 }
00132
00133
00137 void WindowImplXXX::ShowMouseCursor(bool Show)
00138 {
00139     // Show or hide the system cursor in this window
00140 }
00141
00142
00146 void WindowImplXXX::SetCursorPosition(unsigned int Left, unsigned int Top)
00147 {
00148     // Change the cursor position (Left and Top are relative to this window)
00149 }
00150
00151
00155 void WindowImplXXX::SetPosition(int Left, int Top)
00156 {
00157     // Change the window position
00158 }
00159
00160
00164 void WindowImplWin32::SetSize(unsigned int Width, unsigned int Height)
00165 {
00166     // Change the window size
00167 }
00168
00169
00173 void WindowImplXXX::Show(bool State)
00174 {
00175     // Show or hide the window
00176 }
00177
00181 void WindowImplXXX::EnableKeyRepeat(bool Enabled)
00182 {
00183     // Enable or disable automatic key-repeat for keydown events
00184 }
00185
00186
00190 void WindowImplXXX::SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels)
00191 {
00192     // Change all the necessary icons of the window (titlebar, task bar, ...) with the
00193     // provided array of 32 bits RGBA pixels
00194 }
00195
00196
00197 /*===========================================================
00198             STRATEGY FOR OPENGL CONTEXT CREATION
00199
00200 - If the requested level of anti-aliasing is not supported and is greater than 2, try with 2
00201   --> if level 2 fails, disable anti-aliasing
00202   --> it's important not to generate an error if anti-aliasing is not supported
00203
00204 - Use a matching pixel mode, or the best of all available pixel modes if no perfect match ;
00205   You should use the function EvaluateConfig to get a score for a given configuration
00206
00207 - Don't forget to fill Params (see constructors) back with the actual parameters we got from the chosen pixel format
00208
00209 - IMPORTANT : all OpenGL contexts must be shared (usually a call to xxxShareLists)
00210
00211 ===========================================================*/
00212
00213
00214 /*===========================================================
00215                STRATEGY FOR EVENT HANDLING
00216
00217 - Process any event matching with the ones in sf::Event::EventType
00218   --> Create a sf::Event, fill the members corresponding to the event type
00219   --> No need to handle joystick events, they are handled by WindowImpl::ProcessJoystickEvents
00220   --> Event::TextEntered must provide UTF-16 characters
00221       (see http://www.unicode.org/Public/PROGRAMS/CVTUTF/ for unicode conversions)
00222   --> Don't forget to process any destroy-like event (ie. when the window is destroyed externally)
00223
00224 - Use SendEvent function from base class to propagate the created events
00225
00226 ===========================================================*/
00227
00228
00229 } // namespace priv
00230
00231 } // namespace sf


  • File List

WindowImplXXX.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_WINDOWIMPLXXX_HPP
00026 #define SFML_WINDOWIMPLXXX_HPP
00027
00029 // Headers
00031 #include <SFML/Window/Event.hpp>
00032 #include <SFML/Window/WindowImpl.hpp>
00033 #include <string>
00034
00035
00036 namespace sf
00037 {
00038 namespace priv
00039 {
00043 class WindowImplXXX : public WindowImpl
00044 {
00045 public :
00046
00052     WindowImplXXX();
00053
00061     WindowImplXXX(WindowHandle Handle, WindowSettings& Params);
00062
00072     WindowImplXXX(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, WindowSettings& Params);
00073
00078     ~WindowImplXXX();
00079
00086     static bool IsContextActive();
00087
00088 private :
00089
00094     virtual void Display();
00095
00100     virtual void ProcessEvents();
00101
00106     virtual void SetActive(bool Active = true) const;
00107
00112     virtual bool IsActive() const;
00113
00118     virtual void UseVerticalSync(bool Enabled);
00119
00124     virtual void ShowMouseCursor(bool Show);
00125
00130     virtual void SetCursorPosition(unsigned int Left, unsigned int Top);
00131
00136     virtual void SetPosition(int Left, int Top);
00137
00142     virtual void SetSize(unsigned int Width, unsigned int Height);
00143
00148     virtual void Show(bool State);
00149
00154     virtual void EnableKeyRepeat(bool Enabled);
00155
00160     virtual void SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels);
00161 };
00162
00163 } // namespace priv
00164
00165 } // namespace sf
00166
00167 #endif // SFML_WINDOWIMPLXXX_HPP


  • File List

WindowListener.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_WINDOWLISTENER_HPP
00026 #define SFML_WINDOWLISTENER_HPP
00027
00029 // Headers
00031 #include <SFML/Config.hpp>
00032
00033
00034 namespace sf
00035 {
00036 class Event;
00037
00042 class SFML_API WindowListener
00043 {
00044 public :
00045
00052     virtual void OnEvent(const Event& EventReceived) = 0;
00053
00054 protected :
00055
00060     virtual ~WindowListener() {}
00061 };
00062
00063 } // namespace sf
00064
00065
00066 #endif // SFML_WINDOWLISTENER_HPP


  • File List

WindowSettings.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_WINDOWSETTINGS_HPP
00026 #define SFML_WINDOWSETTINGS_HPP
00027
00028
00029 namespace sf
00030 {
00034 struct WindowSettings
00035 {
00044     explicit WindowSettings(unsigned int Depth = 24, unsigned int Stencil = 8, unsigned int Antialiasing = 0) :
00045     DepthBits        (Depth),
00046     StencilBits      (Stencil),
00047     AntialiasingLevel(Antialiasing)
00048     {
00049     }
00050
00052     // Member data
00054     unsigned int DepthBits;
00055     unsigned int StencilBits;
00056     unsigned int AntialiasingLevel;
00057 };
00058
00059 } // namespace sf
00060
00061
00062 #endif // SFML_WINDOWSETTINGS_HPP


  • File List

WindowStyle.hpp

00001
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024
00025 #ifndef SFML_WINDOWSTYLE_HPP
00026 #define SFML_WINDOWSTYLE_HPP
00027
00028
00029 namespace sf
00030 {
00031
00035 namespace Style
00036 {
00037     enum
00038     {
00039         None       = 0,
00040         Titlebar   = 1 << 0,
00041         Resize     = 1 << 1,
00042         Close      = 1 << 2,
00043         Fullscreen = 1 << 3
00044     };
00045 }
00046
00047
00048 } // namespace sf
00049
00050
00051 #endif // SFML_WINDOWSTYLE_HPP