Ajout de la bibli SFML (A)

This commit is contained in:
Antoine Mézon 2017-04-26 22:08:14 +02:00
parent 73704e5139
commit cca7498ca2
204 changed files with 26813 additions and 0 deletions

View file

@ -0,0 +1,180 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_CONTEXT_HPP
#define SFML_CONTEXT_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Export.hpp>
#include <SFML/Window/GlResource.hpp>
#include <SFML/Window/ContextSettings.hpp>
#include <SFML/System/NonCopyable.hpp>
namespace sf
{
namespace priv
{
class GlContext;
}
typedef void (*GlFunctionPointer)();
////////////////////////////////////////////////////////////
/// \brief Class holding a valid drawing context
///
////////////////////////////////////////////////////////////
class SFML_WINDOW_API Context : GlResource, NonCopyable
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// The constructor creates and activates the context
///
////////////////////////////////////////////////////////////
Context();
////////////////////////////////////////////////////////////
/// \brief Destructor
///
/// The destructor deactivates and destroys the context
///
////////////////////////////////////////////////////////////
~Context();
////////////////////////////////////////////////////////////
/// \brief Activate or deactivate explicitly the context
///
/// \param active True to activate, false to deactivate
///
/// \return True on success, false on failure
///
////////////////////////////////////////////////////////////
bool setActive(bool active);
////////////////////////////////////////////////////////////
/// \brief Get the settings of the context
///
/// Note that these settings may be different than the ones
/// passed to the constructor; they are indeed adjusted if the
/// original settings are not directly supported by the system.
///
/// \return Structure containing the settings
///
////////////////////////////////////////////////////////////
const ContextSettings& getSettings() const;
////////////////////////////////////////////////////////////
/// \brief Check whether a given OpenGL extension is available
///
/// \param name Name of the extension to check for
///
/// \return True if available, false if unavailable
///
////////////////////////////////////////////////////////////
static bool isExtensionAvailable(const char* name);
////////////////////////////////////////////////////////////
/// \brief Get the address of an OpenGL function
///
/// \param name Name of the function to get the address of
///
/// \return Address of the OpenGL function, 0 on failure
///
////////////////////////////////////////////////////////////
static GlFunctionPointer getFunction(const char* name);
////////////////////////////////////////////////////////////
/// \brief Get the currently active context
///
/// \return The currently active context or NULL if none is active
///
////////////////////////////////////////////////////////////
static const Context* getActiveContext();
////////////////////////////////////////////////////////////
/// \brief Construct a in-memory context
///
/// This constructor is for internal use, you don't need
/// to bother with it.
///
/// \param settings Creation parameters
/// \param width Back buffer width
/// \param height Back buffer height
///
////////////////////////////////////////////////////////////
Context(const ContextSettings& settings, unsigned int width, unsigned int height);
private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
priv::GlContext* m_context; ///< Internal OpenGL context
};
} // namespace sf
#endif // SFML_CONTEXT_HPP
////////////////////////////////////////////////////////////
/// \class sf::Context
/// \ingroup window
///
/// If you need to make OpenGL calls without having an
/// active window (like in a thread), you can use an
/// instance of this class to get a valid context.
///
/// Having a valid context is necessary for *every* OpenGL call.
///
/// Note that a context is only active in its current thread,
/// if you create a new thread it will have no valid context
/// by default.
///
/// To use a sf::Context instance, just construct it and let it
/// live as long as you need a valid context. No explicit activation
/// is needed, all it has to do is to exist. Its destructor
/// will take care of deactivating and freeing all the attached
/// resources.
///
/// Usage example:
/// \code
/// void threadFunction(void*)
/// {
/// sf::Context context;
/// // from now on, you have a valid context
///
/// // you can make OpenGL calls
/// glClear(GL_DEPTH_BUFFER_BIT);
/// }
/// // the context is automatically deactivated and destroyed
/// // by the sf::Context destructor
/// \endcode
///
////////////////////////////////////////////////////////////

View file

@ -0,0 +1,148 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_CONTEXTSETTINGS_HPP
#define SFML_CONTEXTSETTINGS_HPP
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Structure defining the settings of the OpenGL
/// context attached to a window
///
////////////////////////////////////////////////////////////
struct ContextSettings
{
////////////////////////////////////////////////////////////
/// \brief Enumeration of the context attribute flags
///
////////////////////////////////////////////////////////////
enum Attribute
{
Default = 0, ///< Non-debug, compatibility context (this and the core attribute are mutually exclusive)
Core = 1 << 0, ///< Core attribute
Debug = 1 << 2 ///< Debug attribute
};
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// \param depth Depth buffer bits
/// \param stencil Stencil buffer bits
/// \param antialiasing Antialiasing level
/// \param major Major number of the context version
/// \param minor Minor number of the context version
/// \param attributes Attribute flags of the context
/// \param sRgb sRGB capable framebuffer
///
////////////////////////////////////////////////////////////
explicit ContextSettings(unsigned int depth = 0, unsigned int stencil = 0, unsigned int antialiasing = 0, unsigned int major = 1, unsigned int minor = 1, unsigned int attributes = Default, bool sRgb = false) :
depthBits (depth),
stencilBits (stencil),
antialiasingLevel(antialiasing),
majorVersion (major),
minorVersion (minor),
attributeFlags (attributes),
sRgbCapable (sRgb)
{
}
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
unsigned int depthBits; ///< Bits of the depth buffer
unsigned int stencilBits; ///< Bits of the stencil buffer
unsigned int antialiasingLevel; ///< Level of antialiasing
unsigned int majorVersion; ///< Major number of the context version to create
unsigned int minorVersion; ///< Minor number of the context version to create
Uint32 attributeFlags; ///< The attribute flags to create the context with
bool sRgbCapable; ///< Whether the context framebuffer is sRGB capable
};
} // namespace sf
#endif // SFML_CONTEXTSETTINGS_HPP
////////////////////////////////////////////////////////////
/// \class sf::ContextSettings
/// \ingroup window
///
/// ContextSettings allows to define several advanced settings
/// of the OpenGL context attached to a window. All these
/// settings with the exception of the compatibility flag
/// and anti-aliasing level have no impact on the regular
/// SFML rendering (graphics module), so you may need to use
/// this structure only if you're using SFML as a windowing
/// system for custom OpenGL rendering.
///
/// The depthBits and stencilBits members define the number
/// of bits per pixel requested for the (respectively) depth
/// and stencil buffers.
///
/// antialiasingLevel represents the requested number of
/// multisampling levels for anti-aliasing.
///
/// majorVersion and minorVersion define the version of the
/// OpenGL context that you want. Only versions greater or
/// equal to 3.0 are relevant; versions lesser than 3.0 are
/// all handled the same way (i.e. you can use any version
/// < 3.0 if you don't want an OpenGL 3 context).
///
/// When requesting a context with a version greater or equal
/// to 3.2, you have the option of specifying whether the
/// context should follow the core or compatibility profile
/// of all newer (>= 3.2) OpenGL specifications. For versions
/// 3.0 and 3.1 there is only the core profile. By default
/// a compatibility context is created. You only need to specify
/// the core flag if you want a core profile context to use with
/// your own OpenGL rendering.
/// <b>Warning: The graphics module will not function if you
/// request a core profile context. Make sure the attributes are
/// set to Default if you want to use the graphics module.</b>
///
/// Setting the debug attribute flag will request a context with
/// additional debugging features enabled. Depending on the
/// system, this might be required for advanced OpenGL debugging.
/// OpenGL debugging is disabled by default.
///
/// <b>Special Note for OS X:</b>
/// Apple only supports choosing between either a legacy context
/// (OpenGL 2.1) or a core context (OpenGL version depends on the
/// operating system version but is at least 3.2). Compatibility
/// contexts are not supported. Further information is available on the
/// <a href="https://developer.apple.com/opengl/capabilities/index.html">
/// OpenGL Capabilities Tables</a> page. OS X also currently does
/// not support debug contexts.
///
/// Please note that these values are only a hint.
/// No failure will be reported if one or more of these values
/// are not supported by the system; instead, SFML will try to
/// find the closest valid match. You can then retrieve the
/// settings that the window actually used to create its context,
/// with Window::getSettings().
///
////////////////////////////////////////////////////////////

View file

@ -0,0 +1,284 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_EVENT_HPP
#define SFML_EVENT_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#include <SFML/Window/Joystick.hpp>
#include <SFML/Window/Keyboard.hpp>
#include <SFML/Window/Mouse.hpp>
#include <SFML/Window/Sensor.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Defines a system event and its parameters
///
////////////////////////////////////////////////////////////
class Event
{
public:
////////////////////////////////////////////////////////////
/// \brief Size events parameters (Resized)
///
////////////////////////////////////////////////////////////
struct SizeEvent
{
unsigned int width; ///< New width, in pixels
unsigned int height; ///< New height, in pixels
};
////////////////////////////////////////////////////////////
/// \brief Keyboard event parameters (KeyPressed, KeyReleased)
///
////////////////////////////////////////////////////////////
struct KeyEvent
{
Keyboard::Key code; ///< Code of the key that has been pressed
bool alt; ///< Is the Alt key pressed?
bool control; ///< Is the Control key pressed?
bool shift; ///< Is the Shift key pressed?
bool system; ///< Is the System key pressed?
};
////////////////////////////////////////////////////////////
/// \brief Text event parameters (TextEntered)
///
////////////////////////////////////////////////////////////
struct TextEvent
{
Uint32 unicode; ///< UTF-32 Unicode value of the character
};
////////////////////////////////////////////////////////////
/// \brief Mouse move event parameters (MouseMoved)
///
////////////////////////////////////////////////////////////
struct MouseMoveEvent
{
int x; ///< X position of the mouse pointer, relative to the left of the owner window
int y; ///< Y position of the mouse pointer, relative to the top of the owner window
};
////////////////////////////////////////////////////////////
/// \brief Mouse buttons events parameters
/// (MouseButtonPressed, MouseButtonReleased)
///
////////////////////////////////////////////////////////////
struct MouseButtonEvent
{
Mouse::Button button; ///< Code of the button that has been pressed
int x; ///< X position of the mouse pointer, relative to the left of the owner window
int y; ///< Y position of the mouse pointer, relative to the top of the owner window
};
////////////////////////////////////////////////////////////
/// \brief Mouse wheel events parameters (MouseWheelMoved)
///
/// \deprecated This event is deprecated and potentially inaccurate.
/// Use MouseWheelScrollEvent instead.
///
////////////////////////////////////////////////////////////
struct MouseWheelEvent
{
int delta; ///< Number of ticks the wheel has moved (positive is up, negative is down)
int x; ///< X position of the mouse pointer, relative to the left of the owner window
int y; ///< Y position of the mouse pointer, relative to the top of the owner window
};
////////////////////////////////////////////////////////////
/// \brief Mouse wheel events parameters (MouseWheelScrolled)
///
////////////////////////////////////////////////////////////
struct MouseWheelScrollEvent
{
Mouse::Wheel wheel; ///< Which wheel (for mice with multiple ones)
float delta; ///< Wheel offset (positive is up/left, negative is down/right). High-precision mice may use non-integral offsets.
int x; ///< X position of the mouse pointer, relative to the left of the owner window
int y; ///< Y position of the mouse pointer, relative to the top of the owner window
};
////////////////////////////////////////////////////////////
/// \brief Joystick connection events parameters
/// (JoystickConnected, JoystickDisconnected)
///
////////////////////////////////////////////////////////////
struct JoystickConnectEvent
{
unsigned int joystickId; ///< Index of the joystick (in range [0 .. Joystick::Count - 1])
};
////////////////////////////////////////////////////////////
/// \brief Joystick axis move event parameters (JoystickMoved)
///
////////////////////////////////////////////////////////////
struct JoystickMoveEvent
{
unsigned int joystickId; ///< Index of the joystick (in range [0 .. Joystick::Count - 1])
Joystick::Axis axis; ///< Axis on which the joystick moved
float position; ///< New position on the axis (in range [-100 .. 100])
};
////////////////////////////////////////////////////////////
/// \brief Joystick buttons events parameters
/// (JoystickButtonPressed, JoystickButtonReleased)
///
////////////////////////////////////////////////////////////
struct JoystickButtonEvent
{
unsigned int joystickId; ///< Index of the joystick (in range [0 .. Joystick::Count - 1])
unsigned int button; ///< Index of the button that has been pressed (in range [0 .. Joystick::ButtonCount - 1])
};
////////////////////////////////////////////////////////////
/// \brief Touch events parameters (TouchBegan, TouchMoved, TouchEnded)
///
////////////////////////////////////////////////////////////
struct TouchEvent
{
unsigned int finger; ///< Index of the finger in case of multi-touch events
int x; ///< X position of the touch, relative to the left of the owner window
int y; ///< Y position of the touch, relative to the top of the owner window
};
////////////////////////////////////////////////////////////
/// \brief Sensor event parameters (SensorChanged)
///
////////////////////////////////////////////////////////////
struct SensorEvent
{
Sensor::Type type; ///< Type of the sensor
float x; ///< Current value of the sensor on X axis
float y; ///< Current value of the sensor on Y axis
float z; ///< Current value of the sensor on Z axis
};
////////////////////////////////////////////////////////////
/// \brief Enumeration of the different types of events
///
////////////////////////////////////////////////////////////
enum EventType
{
Closed, ///< The window requested to be closed (no data)
Resized, ///< The window was resized (data in event.size)
LostFocus, ///< The window lost the focus (no data)
GainedFocus, ///< The window gained the focus (no data)
TextEntered, ///< A character was entered (data in event.text)
KeyPressed, ///< A key was pressed (data in event.key)
KeyReleased, ///< A key was released (data in event.key)
MouseWheelMoved, ///< The mouse wheel was scrolled (data in event.mouseWheel) (deprecated)
MouseWheelScrolled, ///< The mouse wheel was scrolled (data in event.mouseWheelScroll)
MouseButtonPressed, ///< A mouse button was pressed (data in event.mouseButton)
MouseButtonReleased, ///< A mouse button was released (data in event.mouseButton)
MouseMoved, ///< The mouse cursor moved (data in event.mouseMove)
MouseEntered, ///< The mouse cursor entered the area of the window (no data)
MouseLeft, ///< The mouse cursor left the area of the window (no data)
JoystickButtonPressed, ///< A joystick button was pressed (data in event.joystickButton)
JoystickButtonReleased, ///< A joystick button was released (data in event.joystickButton)
JoystickMoved, ///< The joystick moved along an axis (data in event.joystickMove)
JoystickConnected, ///< A joystick was connected (data in event.joystickConnect)
JoystickDisconnected, ///< A joystick was disconnected (data in event.joystickConnect)
TouchBegan, ///< A touch event began (data in event.touch)
TouchMoved, ///< A touch moved (data in event.touch)
TouchEnded, ///< A touch event ended (data in event.touch)
SensorChanged, ///< A sensor value changed (data in event.sensor)
Count ///< Keep last -- the total number of event types
};
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
EventType type; ///< Type of the event
union
{
SizeEvent size; ///< Size event parameters (Event::Resized)
KeyEvent key; ///< Key event parameters (Event::KeyPressed, Event::KeyReleased)
TextEvent text; ///< Text event parameters (Event::TextEntered)
MouseMoveEvent mouseMove; ///< Mouse move event parameters (Event::MouseMoved)
MouseButtonEvent mouseButton; ///< Mouse button event parameters (Event::MouseButtonPressed, Event::MouseButtonReleased)
MouseWheelEvent mouseWheel; ///< Mouse wheel event parameters (Event::MouseWheelMoved) (deprecated)
MouseWheelScrollEvent mouseWheelScroll; ///< Mouse wheel event parameters (Event::MouseWheelScrolled)
JoystickMoveEvent joystickMove; ///< Joystick move event parameters (Event::JoystickMoved)
JoystickButtonEvent joystickButton; ///< Joystick button event parameters (Event::JoystickButtonPressed, Event::JoystickButtonReleased)
JoystickConnectEvent joystickConnect; ///< Joystick (dis)connect event parameters (Event::JoystickConnected, Event::JoystickDisconnected)
TouchEvent touch; ///< Touch events parameters (Event::TouchBegan, Event::TouchMoved, Event::TouchEnded)
SensorEvent sensor; ///< Sensor event parameters (Event::SensorChanged)
};
};
} // namespace sf
#endif // SFML_EVENT_HPP
////////////////////////////////////////////////////////////
/// \class sf::Event
/// \ingroup window
///
/// sf::Event holds all the informations about a system event
/// that just happened. Events are retrieved using the
/// sf::Window::pollEvent and sf::Window::waitEvent functions.
///
/// A sf::Event instance contains the type of the event
/// (mouse moved, key pressed, window closed, ...) as well
/// as the details about this particular event. Please note that
/// the event parameters are defined in a union, which means that
/// only the member matching the type of the event will be properly
/// filled; all other members will have undefined values and must not
/// be read if the type of the event doesn't match. For example,
/// if you received a KeyPressed event, then you must read the
/// event.key member, all other members such as event.MouseMove
/// or event.text will have undefined values.
///
/// Usage example:
/// \code
/// sf::Event event;
/// while (window.pollEvent(event))
/// {
/// // Request for closing the window
/// if (event.type == sf::Event::Closed)
/// window.close();
///
/// // The escape key was pressed
/// if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
/// window.close();
///
/// // The window was resized
/// if (event.type == sf::Event::Resized)
/// doSomethingWithTheNewSize(event.size.width, event.size.height);
///
/// // etc ...
/// }
/// \endcode
///
////////////////////////////////////////////////////////////

View file

@ -0,0 +1,48 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_WINDOW_EXPORT_HPP
#define SFML_WINDOW_EXPORT_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
////////////////////////////////////////////////////////////
// Define portable import / export macros
////////////////////////////////////////////////////////////
#if defined(SFML_WINDOW_EXPORTS)
#define SFML_WINDOW_API SFML_API_EXPORT
#else
#define SFML_WINDOW_API SFML_API_IMPORT
#endif
#endif // SFML_WINDOW_EXPORT_HPP

View file

@ -0,0 +1,94 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_GLRESOURCE_HPP
#define SFML_GLRESOURCE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Export.hpp>
#include <SFML/System/NonCopyable.hpp>
namespace sf
{
class Context;
////////////////////////////////////////////////////////////
/// \brief Base class for classes that require an OpenGL context
///
////////////////////////////////////////////////////////////
class SFML_WINDOW_API GlResource
{
protected:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
GlResource();
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
~GlResource();
////////////////////////////////////////////////////////////
/// \brief RAII helper class to temporarily lock an available context for use
///
////////////////////////////////////////////////////////////
class SFML_WINDOW_API TransientContextLock : NonCopyable
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
TransientContextLock();
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
~TransientContextLock();
};
};
} // namespace sf
#endif // SFML_GLRESOURCE_HPP
////////////////////////////////////////////////////////////
/// \class sf::GlResource
/// \ingroup window
///
/// This class is for internal use only, it must be the base
/// of every class that requires a valid OpenGL context in
/// order to work.
///
////////////////////////////////////////////////////////////

View file

@ -0,0 +1,227 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_JOYSTICK_HPP
#define SFML_JOYSTICK_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Export.hpp>
#include <SFML/System/String.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Give access to the real-time state of the joysticks
///
////////////////////////////////////////////////////////////
class SFML_WINDOW_API Joystick
{
public:
////////////////////////////////////////////////////////////
/// \brief Constants related to joysticks capabilities
///
////////////////////////////////////////////////////////////
enum
{
Count = 8, ///< Maximum number of supported joysticks
ButtonCount = 32, ///< Maximum number of supported buttons
AxisCount = 8 ///< Maximum number of supported axes
};
////////////////////////////////////////////////////////////
/// \brief Axes supported by SFML joysticks
///
////////////////////////////////////////////////////////////
enum Axis
{
X, ///< The X axis
Y, ///< The Y axis
Z, ///< The Z axis
R, ///< The R axis
U, ///< The U axis
V, ///< The V axis
PovX, ///< The X axis of the point-of-view hat
PovY ///< The Y axis of the point-of-view hat
};
////////////////////////////////////////////////////////////
/// \brief Structure holding a joystick's identification
///
////////////////////////////////////////////////////////////
struct SFML_WINDOW_API Identification
{
Identification();
String name; ///< Name of the joystick
unsigned int vendorId; ///< Manufacturer identifier
unsigned int productId; ///< Product identifier
};
////////////////////////////////////////////////////////////
/// \brief Check if a joystick is connected
///
/// \param joystick Index of the joystick to check
///
/// \return True if the joystick is connected, false otherwise
///
////////////////////////////////////////////////////////////
static bool isConnected(unsigned int joystick);
////////////////////////////////////////////////////////////
/// \brief Return the number of buttons supported by a joystick
///
/// If the joystick is not connected, this function returns 0.
///
/// \param joystick Index of the joystick
///
/// \return Number of buttons supported by the joystick
///
////////////////////////////////////////////////////////////
static unsigned int getButtonCount(unsigned int joystick);
////////////////////////////////////////////////////////////
/// \brief Check if a joystick supports a given axis
///
/// If the joystick is not connected, this function returns false.
///
/// \param joystick Index of the joystick
/// \param axis Axis to check
///
/// \return True if the joystick supports the axis, false otherwise
///
////////////////////////////////////////////////////////////
static bool hasAxis(unsigned int joystick, Axis axis);
////////////////////////////////////////////////////////////
/// \brief Check if a joystick button is pressed
///
/// If the joystick is not connected, this function returns false.
///
/// \param joystick Index of the joystick
/// \param button Button to check
///
/// \return True if the button is pressed, false otherwise
///
////////////////////////////////////////////////////////////
static bool isButtonPressed(unsigned int joystick, unsigned int button);
////////////////////////////////////////////////////////////
/// \brief Get the current position of a joystick axis
///
/// If the joystick is not connected, this function returns 0.
///
/// \param joystick Index of the joystick
/// \param axis Axis to check
///
/// \return Current position of the axis, in range [-100 .. 100]
///
////////////////////////////////////////////////////////////
static float getAxisPosition(unsigned int joystick, Axis axis);
////////////////////////////////////////////////////////////
/// \brief Get the joystick information
///
/// \param joystick Index of the joystick
///
/// \return Structure containing joystick information.
///
////////////////////////////////////////////////////////////
static Identification getIdentification(unsigned int joystick);
////////////////////////////////////////////////////////////
/// \brief Update the states of all joysticks
///
/// This function is used internally by SFML, so you normally
/// don't have to call it explicitly. However, you may need to
/// call it if you have no window yet (or no window at all):
/// in this case the joystick states are not updated automatically.
///
////////////////////////////////////////////////////////////
static void update();
};
} // namespace sf
#endif // SFML_JOYSTICK_HPP
////////////////////////////////////////////////////////////
/// \class sf::Joystick
/// \ingroup window
///
/// sf::Joystick provides an interface to the state of the
/// joysticks. It only contains static functions, so it's not
/// meant to be instantiated. Instead, each joystick is identified
/// by an index that is passed to the functions of this class.
///
/// This class allows users to query the state of joysticks at any
/// time and directly, without having to deal with a window and
/// its events. Compared to the JoystickMoved, JoystickButtonPressed
/// and JoystickButtonReleased events, sf::Joystick can retrieve the
/// state of axes and buttons of joysticks at any time
/// (you don't need to store and update a boolean on your side
/// in order to know if a button is pressed or released), and you
/// always get the real state of joysticks, even if they are
/// moved, pressed or released when your window is out of focus
/// and no event is triggered.
///
/// SFML supports:
/// \li 8 joysticks (sf::Joystick::Count)
/// \li 32 buttons per joystick (sf::Joystick::ButtonCount)
/// \li 8 axes per joystick (sf::Joystick::AxisCount)
///
/// Unlike the keyboard or mouse, the state of joysticks is sometimes
/// not directly available (depending on the OS), therefore an update()
/// function must be called in order to update the current state of
/// joysticks. When you have a window with event handling, this is done
/// automatically, you don't need to call anything. But if you have no
/// window, or if you want to check joysticks state before creating one,
/// you must call sf::Joystick::update explicitly.
///
/// Usage example:
/// \code
/// // Is joystick #0 connected?
/// bool connected = sf::Joystick::isConnected(0);
///
/// // How many buttons does joystick #0 support?
/// unsigned int buttons = sf::Joystick::getButtonCount(0);
///
/// // Does joystick #0 define a X axis?
/// bool hasX = sf::Joystick::hasAxis(0, sf::Joystick::X);
///
/// // Is button #2 pressed on joystick #0?
/// bool pressed = sf::Joystick::isButtonPressed(0, 2);
///
/// // What's the current position of the Y axis on joystick #0?
/// float position = sf::Joystick::getAxisPosition(0, sf::Joystick::Y);
/// \endcode
///
/// \see sf::Keyboard, sf::Mouse
///
////////////////////////////////////////////////////////////

View file

@ -0,0 +1,224 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_KEYBOARD_HPP
#define SFML_KEYBOARD_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Export.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Give access to the real-time state of the keyboard
///
////////////////////////////////////////////////////////////
class SFML_WINDOW_API Keyboard
{
public:
////////////////////////////////////////////////////////////
/// \brief Key codes
///
////////////////////////////////////////////////////////////
enum Key
{
Unknown = -1, ///< Unhandled key
A = 0, ///< The A key
B, ///< The B key
C, ///< The C key
D, ///< The D key
E, ///< The E key
F, ///< The F key
G, ///< The G key
H, ///< The H key
I, ///< The I key
J, ///< The J key
K, ///< The K key
L, ///< The L key
M, ///< The M key
N, ///< The N key
O, ///< The O key
P, ///< The P key
Q, ///< The Q key
R, ///< The R key
S, ///< The S key
T, ///< The T key
U, ///< The U key
V, ///< The V key
W, ///< The W key
X, ///< The X key
Y, ///< The Y key
Z, ///< The Z key
Num0, ///< The 0 key
Num1, ///< The 1 key
Num2, ///< The 2 key
Num3, ///< The 3 key
Num4, ///< The 4 key
Num5, ///< The 5 key
Num6, ///< The 6 key
Num7, ///< The 7 key
Num8, ///< The 8 key
Num9, ///< The 9 key
Escape, ///< The Escape key
LControl, ///< The left Control key
LShift, ///< The left Shift key
LAlt, ///< The left Alt key
LSystem, ///< The left OS specific key: window (Windows and Linux), apple (MacOS X), ...
RControl, ///< The right Control key
RShift, ///< The right Shift key
RAlt, ///< The right Alt key
RSystem, ///< The right OS specific key: window (Windows and Linux), apple (MacOS X), ...
Menu, ///< The Menu key
LBracket, ///< The [ key
RBracket, ///< The ] key
SemiColon, ///< The ; key
Comma, ///< The , key
Period, ///< The . key
Quote, ///< The ' key
Slash, ///< The / key
BackSlash, ///< The \ key
Tilde, ///< The ~ key
Equal, ///< The = key
Dash, ///< The - key
Space, ///< The Space key
Return, ///< The Return key
BackSpace, ///< The Backspace key
Tab, ///< The Tabulation key
PageUp, ///< The Page up key
PageDown, ///< The Page down key
End, ///< The End key
Home, ///< The Home key
Insert, ///< The Insert key
Delete, ///< The Delete key
Add, ///< The + key
Subtract, ///< The - key
Multiply, ///< The * key
Divide, ///< The / key
Left, ///< Left arrow
Right, ///< Right arrow
Up, ///< Up arrow
Down, ///< Down arrow
Numpad0, ///< The numpad 0 key
Numpad1, ///< The numpad 1 key
Numpad2, ///< The numpad 2 key
Numpad3, ///< The numpad 3 key
Numpad4, ///< The numpad 4 key
Numpad5, ///< The numpad 5 key
Numpad6, ///< The numpad 6 key
Numpad7, ///< The numpad 7 key
Numpad8, ///< The numpad 8 key
Numpad9, ///< The numpad 9 key
F1, ///< The F1 key
F2, ///< The F2 key
F3, ///< The F3 key
F4, ///< The F4 key
F5, ///< The F5 key
F6, ///< The F6 key
F7, ///< The F7 key
F8, ///< The F8 key
F9, ///< The F9 key
F10, ///< The F10 key
F11, ///< The F11 key
F12, ///< The F12 key
F13, ///< The F13 key
F14, ///< The F14 key
F15, ///< The F15 key
Pause, ///< The Pause key
KeyCount ///< Keep last -- the total number of keyboard keys
};
////////////////////////////////////////////////////////////
/// \brief Check if a key is pressed
///
/// \param key Key to check
///
/// \return True if the key is pressed, false otherwise
///
////////////////////////////////////////////////////////////
static bool isKeyPressed(Key key);
////////////////////////////////////////////////////////////
/// \brief Show or hide the virtual keyboard
///
/// Warning: the virtual keyboard is not supported on all
/// systems. It will typically be implemented on mobile OSes
/// (Android, iOS) but not on desktop OSes (Windows, Linux, ...).
///
/// If the virtual keyboard is not available, this function does
/// nothing.
///
/// \param visible True to show, false to hide
///
////////////////////////////////////////////////////////////
static void setVirtualKeyboardVisible(bool visible);
};
} // namespace sf
#endif // SFML_KEYBOARD_HPP
////////////////////////////////////////////////////////////
/// \class sf::Keyboard
/// \ingroup window
///
/// sf::Keyboard provides an interface to the state of the
/// keyboard. It only contains static functions (a single
/// keyboard is assumed), so it's not meant to be instantiated.
///
/// This class allows users to query the keyboard state at any
/// time and directly, without having to deal with a window and
/// its events. Compared to the KeyPressed and KeyReleased events,
/// sf::Keyboard can retrieve the state of a key at any time
/// (you don't need to store and update a boolean on your side
/// in order to know if a key is pressed or released), and you
/// always get the real state of the keyboard, even if keys are
/// pressed or released when your window is out of focus and no
/// event is triggered.
///
/// Usage example:
/// \code
/// if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
/// {
/// // move left...
/// }
/// else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
/// {
/// // move right...
/// }
/// else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
/// {
/// // quit...
/// }
/// \endcode
///
/// \see sf::Joystick, sf::Mouse, sf::Touch
///
////////////////////////////////////////////////////////////

View file

@ -0,0 +1,177 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_MOUSE_HPP
#define SFML_MOUSE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Export.hpp>
#include <SFML/System/Vector2.hpp>
namespace sf
{
class Window;
////////////////////////////////////////////////////////////
/// \brief Give access to the real-time state of the mouse
///
////////////////////////////////////////////////////////////
class SFML_WINDOW_API Mouse
{
public:
////////////////////////////////////////////////////////////
/// \brief Mouse buttons
///
////////////////////////////////////////////////////////////
enum Button
{
Left, ///< The left mouse button
Right, ///< The right mouse button
Middle, ///< The middle (wheel) mouse button
XButton1, ///< The first extra mouse button
XButton2, ///< The second extra mouse button
ButtonCount ///< Keep last -- the total number of mouse buttons
};
////////////////////////////////////////////////////////////
/// \brief Mouse wheels
///
////////////////////////////////////////////////////////////
enum Wheel
{
VerticalWheel, ///< The vertical mouse wheel
HorizontalWheel ///< The horizontal mouse wheel
};
////////////////////////////////////////////////////////////
/// \brief Check if a mouse button is pressed
///
/// \param button Button to check
///
/// \return True if the button is pressed, false otherwise
///
////////////////////////////////////////////////////////////
static bool isButtonPressed(Button button);
////////////////////////////////////////////////////////////
/// \brief Get the current position of the mouse in desktop coordinates
///
/// This function returns the global position of the mouse
/// cursor on the desktop.
///
/// \return Current position of the mouse
///
////////////////////////////////////////////////////////////
static Vector2i getPosition();
////////////////////////////////////////////////////////////
/// \brief Get the current position of the mouse in window coordinates
///
/// This function returns the current position of the mouse
/// cursor, relative to the given window.
///
/// \param relativeTo Reference window
///
/// \return Current position of the mouse
///
////////////////////////////////////////////////////////////
static Vector2i getPosition(const Window& relativeTo);
////////////////////////////////////////////////////////////
/// \brief Set the current position of the mouse in desktop coordinates
///
/// This function sets the global position of the mouse
/// cursor on the desktop.
///
/// \param position New position of the mouse
///
////////////////////////////////////////////////////////////
static void setPosition(const Vector2i& position);
////////////////////////////////////////////////////////////
/// \brief Set the current position of the mouse in window coordinates
///
/// This function sets the current position of the mouse
/// cursor, relative to the given window.
///
/// \param position New position of the mouse
/// \param relativeTo Reference window
///
////////////////////////////////////////////////////////////
static void setPosition(const Vector2i& position, const Window& relativeTo);
};
} // namespace sf
#endif // SFML_MOUSE_HPP
////////////////////////////////////////////////////////////
/// \class sf::Mouse
/// \ingroup window
///
/// sf::Mouse provides an interface to the state of the
/// mouse. It only contains static functions (a single
/// mouse is assumed), so it's not meant to be instantiated.
///
/// This class allows users to query the mouse state at any
/// time and directly, without having to deal with a window and
/// its events. Compared to the MouseMoved, MouseButtonPressed
/// and MouseButtonReleased events, sf::Mouse can retrieve the
/// state of the cursor and the buttons at any time
/// (you don't need to store and update a boolean on your side
/// in order to know if a button is pressed or released), and you
/// always get the real state of the mouse, even if it is
/// moved, pressed or released when your window is out of focus
/// and no event is triggered.
///
/// The setPosition and getPosition functions can be used to change
/// or retrieve the current position of the mouse pointer. There are
/// two versions: one that operates in global coordinates (relative
/// to the desktop) and one that operates in window coordinates
/// (relative to a specific window).
///
/// Usage example:
/// \code
/// if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
/// {
/// // left click...
/// }
///
/// // get global mouse position
/// sf::Vector2i position = sf::Mouse::getPosition();
///
/// // set mouse position relative to a window
/// sf::Mouse::setPosition(sf::Vector2i(100, 200), window);
/// \endcode
///
/// \see sf::Joystick, sf::Keyboard, sf::Touch
///
////////////////////////////////////////////////////////////

View file

@ -0,0 +1,150 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SENSOR_HPP
#define SFML_SENSOR_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Export.hpp>
#include <SFML/System/Vector3.hpp>
#include <SFML/System/Time.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Give access to the real-time state of the sensors
///
////////////////////////////////////////////////////////////
class SFML_WINDOW_API Sensor
{
public:
////////////////////////////////////////////////////////////
/// \brief Sensor type
///
////////////////////////////////////////////////////////////
enum Type
{
Accelerometer, ///< Measures the raw acceleration (m/s^2)
Gyroscope, ///< Measures the raw rotation rates (degrees/s)
Magnetometer, ///< Measures the ambient magnetic field (micro-teslas)
Gravity, ///< Measures the direction and intensity of gravity, independent of device acceleration (m/s^2)
UserAcceleration, ///< Measures the direction and intensity of device acceleration, independent of the gravity (m/s^2)
Orientation, ///< Measures the absolute 3D orientation (degrees)
Count ///< Keep last -- the total number of sensor types
};
////////////////////////////////////////////////////////////
/// \brief Check if a sensor is available on the underlying platform
///
/// \param sensor Sensor to check
///
/// \return True if the sensor is available, false otherwise
///
////////////////////////////////////////////////////////////
static bool isAvailable(Type sensor);
////////////////////////////////////////////////////////////
/// \brief Enable or disable a sensor
///
/// All sensors are disabled by default, to avoid consuming too
/// much battery power. Once a sensor is enabled, it starts
/// sending events of the corresponding type.
///
/// This function does nothing if the sensor is unavailable.
///
/// \param sensor Sensor to enable
/// \param enabled True to enable, false to disable
///
////////////////////////////////////////////////////////////
static void setEnabled(Type sensor, bool enabled);
////////////////////////////////////////////////////////////
/// \brief Get the current sensor value
///
/// \param sensor Sensor to read
///
/// \return The current sensor value
///
////////////////////////////////////////////////////////////
static Vector3f getValue(Type sensor);
};
} // namespace sf
#endif // SFML_SENSOR_HPP
////////////////////////////////////////////////////////////
/// \class sf::Sensor
/// \ingroup window
///
/// sf::Sensor provides an interface to the state of the
/// various sensors that a device provides. It only contains static
/// functions, so it's not meant to be instantiated.
///
/// This class allows users to query the sensors values at any
/// time and directly, without having to deal with a window and
/// its events. Compared to the SensorChanged event, sf::Sensor
/// can retrieve the state of a sensor at any time (you don't need to
/// store and update its current value on your side).
///
/// Depending on the OS and hardware of the device (phone, tablet, ...),
/// some sensor types may not be available. You should always check
/// the availability of a sensor before trying to read it, with the
/// sf::Sensor::isAvailable function.
///
/// You may wonder why some sensor types look so similar, for example
/// Accelerometer and Gravity / UserAcceleration. The first one
/// is the raw measurement of the acceleration, and takes into account
/// both the earth gravity and the user movement. The others are
/// more precise: they provide these components separately, which is
/// usually more useful. In fact they are not direct sensors, they
/// are computed internally based on the raw acceleration and other sensors.
/// This is exactly the same for Gyroscope vs Orientation.
///
/// Because sensors consume a non-negligible amount of current, they are
/// all disabled by default. You must call sf::Sensor::setEnabled for each
/// sensor in which you are interested.
///
/// Usage example:
/// \code
/// if (sf::Sensor::isAvailable(sf::Sensor::Gravity))
/// {
/// // gravity sensor is available
/// }
///
/// // enable the gravity sensor
/// sf::Sensor::setEnabled(sf::Sensor::Gravity, true);
///
/// // get the current value of gravity
/// sf::Vector3f gravity = sf::Sensor::getValue(sf::Sensor::Gravity);
/// \endcode
///
////////////////////////////////////////////////////////////

View file

@ -0,0 +1,137 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_TOUCH_HPP
#define SFML_TOUCH_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Export.hpp>
#include <SFML/System/Vector2.hpp>
namespace sf
{
class Window;
////////////////////////////////////////////////////////////
/// \brief Give access to the real-time state of the touches
///
////////////////////////////////////////////////////////////
class SFML_WINDOW_API Touch
{
public:
////////////////////////////////////////////////////////////
/// \brief Check if a touch event is currently down
///
/// \param finger Finger index
///
/// \return True if \a finger is currently touching the screen, false otherwise
///
////////////////////////////////////////////////////////////
static bool isDown(unsigned int finger);
////////////////////////////////////////////////////////////
/// \brief Get the current position of a touch in desktop coordinates
///
/// This function returns the current touch position
/// in global (desktop) coordinates.
///
/// \param finger Finger index
///
/// \return Current position of \a finger, or undefined if it's not down
///
////////////////////////////////////////////////////////////
static Vector2i getPosition(unsigned int finger);
////////////////////////////////////////////////////////////
/// \brief Get the current position of a touch in window coordinates
///
/// This function returns the current touch position
/// relative to the given window.
///
/// \param finger Finger index
/// \param relativeTo Reference window
///
/// \return Current position of \a finger, or undefined if it's not down
///
////////////////////////////////////////////////////////////
static Vector2i getPosition(unsigned int finger, const Window& relativeTo);
};
} // namespace sf
#endif // SFML_TOUCH_HPP
////////////////////////////////////////////////////////////
/// \class sf::Touch
/// \ingroup window
///
/// sf::Touch provides an interface to the state of the
/// touches. It only contains static functions, so it's not
/// meant to be instantiated.
///
/// This class allows users to query the touches state at any
/// time and directly, without having to deal with a window and
/// its events. Compared to the TouchBegan, TouchMoved
/// and TouchEnded events, sf::Touch can retrieve the
/// state of the touches at any time (you don't need to store and
/// update a boolean on your side in order to know if a touch is down),
/// and you always get the real state of the touches, even if they
/// happen when your window is out of focus and no event is triggered.
///
/// The getPosition function can be used to retrieve the current
/// position of a touch. There are two versions: one that operates
/// in global coordinates (relative to the desktop) and one that
/// operates in window coordinates (relative to a specific window).
///
/// Touches are identified by an index (the "finger"), so that in
/// multi-touch events, individual touches can be tracked correctly.
/// As long as a finger touches the screen, it will keep the same index
/// even if other fingers start or stop touching the screen in the
/// meantime. As a consequence, active touch indices may not always be
/// sequential (i.e. touch number 0 may be released while touch number 1
/// is still down).
///
/// Usage example:
/// \code
/// if (sf::Touch::isDown(0))
/// {
/// // touch 0 is down
/// }
///
/// // get global position of touch 1
/// sf::Vector2i globalPos = sf::Touch::getPosition(1);
///
/// // get position of touch 1 relative to a window
/// sf::Vector2i relativePos = sf::Touch::getPosition(1, window);
/// \endcode
///
/// \see sf::Joystick, sf::Keyboard, sf::Mouse
///
////////////////////////////////////////////////////////////

View file

@ -0,0 +1,228 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_VIDEOMODE_HPP
#define SFML_VIDEOMODE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Export.hpp>
#include <vector>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief VideoMode defines a video mode (width, height, bpp)
///
////////////////////////////////////////////////////////////
class SFML_WINDOW_API VideoMode
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// This constructors initializes all members to 0.
///
////////////////////////////////////////////////////////////
VideoMode();
////////////////////////////////////////////////////////////
/// \brief Construct the video mode with its attributes
///
/// \param modeWidth Width in pixels
/// \param modeHeight Height in pixels
/// \param modeBitsPerPixel Pixel depths in bits per pixel
///
////////////////////////////////////////////////////////////
VideoMode(unsigned int modeWidth, unsigned int modeHeight, unsigned int modeBitsPerPixel = 32);
////////////////////////////////////////////////////////////
/// \brief Get the current desktop video mode
///
/// \return Current desktop video mode
///
////////////////////////////////////////////////////////////
static VideoMode getDesktopMode();
////////////////////////////////////////////////////////////
/// \brief Retrieve all the video modes supported in fullscreen mode
///
/// When creating a fullscreen window, the video mode is restricted
/// to be compatible with what the graphics driver and monitor
/// support. This function returns the complete list of all video
/// modes that can be used in fullscreen mode.
/// The returned array is sorted from best to worst, so that
/// the first element will always give the best mode (higher
/// width, height and bits-per-pixel).
///
/// \return Array containing all the supported fullscreen modes
///
////////////////////////////////////////////////////////////
static const std::vector<VideoMode>& getFullscreenModes();
////////////////////////////////////////////////////////////
/// \brief Tell whether or not the video mode is valid
///
/// The validity of video modes is only relevant when using
/// fullscreen windows; otherwise any video mode can be used
/// with no restriction.
///
/// \return True if the video mode is valid for fullscreen mode
///
////////////////////////////////////////////////////////////
bool isValid() const;
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
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
};
////////////////////////////////////////////////////////////
/// \relates VideoMode
/// \brief Overload of == operator to compare two video modes
///
/// \param left Left operand (a video mode)
/// \param right Right operand (a video mode)
///
/// \return True if modes are equal
///
////////////////////////////////////////////////////////////
SFML_WINDOW_API bool operator ==(const VideoMode& left, const VideoMode& right);
////////////////////////////////////////////////////////////
/// \relates VideoMode
/// \brief Overload of != operator to compare two video modes
///
/// \param left Left operand (a video mode)
/// \param right Right operand (a video mode)
///
/// \return True if modes are different
///
////////////////////////////////////////////////////////////
SFML_WINDOW_API bool operator !=(const VideoMode& left, const VideoMode& right);
////////////////////////////////////////////////////////////
/// \relates VideoMode
/// \brief Overload of < operator to compare video modes
///
/// \param left Left operand (a video mode)
/// \param right Right operand (a video mode)
///
/// \return True if \a left is lesser than \a right
///
////////////////////////////////////////////////////////////
SFML_WINDOW_API bool operator <(const VideoMode& left, const VideoMode& right);
////////////////////////////////////////////////////////////
/// \relates VideoMode
/// \brief Overload of > operator to compare video modes
///
/// \param left Left operand (a video mode)
/// \param right Right operand (a video mode)
///
/// \return True if \a left is greater than \a right
///
////////////////////////////////////////////////////////////
SFML_WINDOW_API bool operator >(const VideoMode& left, const VideoMode& right);
////////////////////////////////////////////////////////////
/// \relates VideoMode
/// \brief Overload of <= operator to compare video modes
///
/// \param left Left operand (a video mode)
/// \param right Right operand (a video mode)
///
/// \return True if \a left is lesser or equal than \a right
///
////////////////////////////////////////////////////////////
SFML_WINDOW_API bool operator <=(const VideoMode& left, const VideoMode& right);
////////////////////////////////////////////////////////////
/// \relates VideoMode
/// \brief Overload of >= operator to compare video modes
///
/// \param left Left operand (a video mode)
/// \param right Right operand (a video mode)
///
/// \return True if \a left is greater or equal than \a right
///
////////////////////////////////////////////////////////////
SFML_WINDOW_API bool operator >=(const VideoMode& left, const VideoMode& right);
} // namespace sf
#endif // SFML_VIDEOMODE_HPP
////////////////////////////////////////////////////////////
/// \class sf::VideoMode
/// \ingroup window
///
/// A video mode is defined by a width and a height (in pixels)
/// and a depth (in bits per pixel). Video modes are used to
/// setup windows (sf::Window) at creation time.
///
/// The main usage of video modes is for fullscreen mode:
/// indeed you must use one of the valid video modes
/// allowed by the OS (which are defined by what the monitor
/// and the graphics card support), otherwise your window
/// creation will just fail.
///
/// sf::VideoMode provides a static function for retrieving
/// the list of all the video modes supported by the system:
/// getFullscreenModes().
///
/// A custom video mode can also be checked directly for
/// fullscreen compatibility with its isValid() function.
///
/// Additionally, sf::VideoMode provides a static function
/// to get the mode currently used by the desktop: getDesktopMode().
/// This allows to build windows with the same size or pixel
/// depth as the current resolution.
///
/// Usage example:
/// \code
/// // Display the list of all the video modes available for fullscreen
/// std::vector<sf::VideoMode> modes = sf::VideoMode::getFullscreenModes();
/// for (std::size_t i = 0; i < modes.size(); ++i)
/// {
/// sf::VideoMode mode = modes[i];
/// std::cout << "Mode #" << i << ": "
/// << mode.width << "x" << mode.height << " - "
/// << mode.bitsPerPixel << " bpp" << std::endl;
/// }
///
/// // Create a window with the same pixel depth as the desktop
/// sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
/// window.create(sf::VideoMode(1024, 768, desktop.bitsPerPixel), "SFML window");
/// \endcode
///
////////////////////////////////////////////////////////////

View file

@ -0,0 +1,594 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_WINDOW_HPP
#define SFML_WINDOW_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Export.hpp>
#include <SFML/Window/ContextSettings.hpp>
#include <SFML/Window/VideoMode.hpp>
#include <SFML/Window/WindowHandle.hpp>
#include <SFML/Window/WindowStyle.hpp>
#include <SFML/Window/GlResource.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/System/NonCopyable.hpp>
#include <SFML/System/String.hpp>
namespace sf
{
namespace priv
{
class GlContext;
class WindowImpl;
}
class Event;
////////////////////////////////////////////////////////////
/// \brief Window that serves as a target for OpenGL rendering
///
////////////////////////////////////////////////////////////
class SFML_WINDOW_API Window : GlResource, NonCopyable
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// This constructor doesn't actually create the window,
/// use the other constructors or call create() to do so.
///
////////////////////////////////////////////////////////////
Window();
////////////////////////////////////////////////////////////
/// \brief Construct a new window
///
/// This constructor creates the window with the size and pixel
/// depth defined in \a mode. An optional style can be passed to
/// customize the look and behavior of the window (borders,
/// title bar, resizable, closable, ...). If \a style contains
/// Style::Fullscreen, then \a mode must be a valid video mode.
///
/// The fourth parameter is an optional structure specifying
/// advanced OpenGL context settings such as antialiasing,
/// depth-buffer bits, etc.
///
/// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window)
/// \param title Title of the window
/// \param style %Window style, a bitwise OR combination of sf::Style enumerators
/// \param settings Additional settings for the underlying OpenGL context
///
////////////////////////////////////////////////////////////
Window(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings());
////////////////////////////////////////////////////////////
/// \brief Construct the window from an existing control
///
/// Use this constructor if you want to create an OpenGL
/// rendering area into an already existing control.
///
/// The second parameter is an optional structure specifying
/// advanced OpenGL context settings such as antialiasing,
/// depth-buffer bits, etc.
///
/// \param handle Platform-specific handle of the control
/// \param settings Additional settings for the underlying OpenGL context
///
////////////////////////////////////////////////////////////
explicit Window(WindowHandle handle, const ContextSettings& settings = ContextSettings());
////////////////////////////////////////////////////////////
/// \brief Destructor
///
/// Closes the window and frees all the resources attached to it.
///
////////////////////////////////////////////////////////////
virtual ~Window();
////////////////////////////////////////////////////////////
/// \brief Create (or recreate) the window
///
/// If the window was already created, it closes it first.
/// If \a style contains Style::Fullscreen, then \a mode
/// must be a valid video mode.
///
/// The fourth parameter is an optional structure specifying
/// advanced OpenGL context settings such as antialiasing,
/// depth-buffer bits, etc.
///
/// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window)
/// \param title Title of the window
/// \param style %Window style, a bitwise OR combination of sf::Style enumerators
/// \param settings Additional settings for the underlying OpenGL context
///
////////////////////////////////////////////////////////////
void create(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings());
////////////////////////////////////////////////////////////
/// \brief Create (or recreate) the window from an existing control
///
/// Use this function if you want to create an OpenGL
/// rendering area into an already existing control.
/// If the window was already created, it closes it first.
///
/// The second parameter is an optional structure specifying
/// advanced OpenGL context settings such as antialiasing,
/// depth-buffer bits, etc.
///
/// \param handle Platform-specific handle of the control
/// \param settings Additional settings for the underlying OpenGL context
///
////////////////////////////////////////////////////////////
void create(WindowHandle handle, const ContextSettings& settings = ContextSettings());
////////////////////////////////////////////////////////////
/// \brief Close the window and destroy all the attached resources
///
/// After calling this function, the sf::Window instance remains
/// valid and you can call create() to recreate the window.
/// All other functions such as pollEvent() or display() will
/// still work (i.e. you don't have to test isOpen() every time),
/// and will have no effect on closed windows.
///
////////////////////////////////////////////////////////////
void close();
////////////////////////////////////////////////////////////
/// \brief Tell whether or not the window is open
///
/// This function returns whether or not the window exists.
/// Note that a hidden window (setVisible(false)) is open
/// (therefore this function would return true).
///
/// \return True if the window is open, false if it has been closed
///
////////////////////////////////////////////////////////////
bool isOpen() const;
////////////////////////////////////////////////////////////
/// \brief Get the settings of the OpenGL context of the window
///
/// Note that these settings may be different from what was
/// passed to the constructor or the create() function,
/// if one or more settings were not supported. In this case,
/// SFML chose the closest match.
///
/// \return Structure containing the OpenGL context settings
///
////////////////////////////////////////////////////////////
const ContextSettings& getSettings() const;
////////////////////////////////////////////////////////////
/// \brief Pop the event on top of the event queue, if any, and return it
///
/// This function is not blocking: if there's no pending event then
/// it will return false and leave \a event unmodified.
/// Note that more than one event may be present in the event queue,
/// thus you should always call this function in a loop
/// to make sure that you process every pending event.
/// \code
/// sf::Event event;
/// while (window.pollEvent(event))
/// {
/// // process event...
/// }
/// \endcode
///
/// \param event Event to be returned
///
/// \return True if an event was returned, or false if the event queue was empty
///
/// \see waitEvent
///
////////////////////////////////////////////////////////////
bool pollEvent(Event& event);
////////////////////////////////////////////////////////////
/// \brief Wait for an event and return it
///
/// This function is blocking: if there's no pending event then
/// it will wait until an event is received.
/// After this function returns (and no error occurred),
/// the \a event object is always valid and filled properly.
/// This function is typically used when you have a thread that
/// is dedicated to events handling: you want to make this thread
/// sleep as long as no new event is received.
/// \code
/// sf::Event event;
/// if (window.waitEvent(event))
/// {
/// // process event...
/// }
/// \endcode
///
/// \param event Event to be returned
///
/// \return False if any error occurred
///
/// \see pollEvent
///
////////////////////////////////////////////////////////////
bool waitEvent(Event& event);
////////////////////////////////////////////////////////////
/// \brief Get the position of the window
///
/// \return Position of the window, in pixels
///
/// \see setPosition
///
////////////////////////////////////////////////////////////
Vector2i getPosition() const;
////////////////////////////////////////////////////////////
/// \brief Change the position of the window on screen
///
/// This function only works for top-level windows
/// (i.e. it will be ignored for windows created from
/// the handle of a child window/control).
///
/// \param position New position, in pixels
///
/// \see getPosition
///
////////////////////////////////////////////////////////////
void setPosition(const Vector2i& position);
////////////////////////////////////////////////////////////
/// \brief Get the size of the rendering region of the window
///
/// The size doesn't include the titlebar and borders
/// of the window.
///
/// \return Size in pixels
///
/// \see setSize
///
////////////////////////////////////////////////////////////
Vector2u getSize() const;
////////////////////////////////////////////////////////////
/// \brief Change the size of the rendering region of the window
///
/// \param size New size, in pixels
///
/// \see getSize
///
////////////////////////////////////////////////////////////
void setSize(const Vector2u& size);
////////////////////////////////////////////////////////////
/// \brief Change the title of the window
///
/// \param title New title
///
/// \see setIcon
///
////////////////////////////////////////////////////////////
void setTitle(const String& title);
////////////////////////////////////////////////////////////
/// \brief Change the window's icon
///
/// \a pixels must be an array of \a width x \a height pixels
/// in 32-bits RGBA format.
///
/// The OS default icon is used by default.
///
/// \param width Icon's width, in pixels
/// \param height Icon's height, in pixels
/// \param pixels Pointer to the array of pixels in memory. The
/// pixels are copied, so you need not keep the
/// source alive after calling this function.
///
/// \see setTitle
///
////////////////////////////////////////////////////////////
void setIcon(unsigned int width, unsigned int height, const Uint8* pixels);
////////////////////////////////////////////////////////////
/// \brief Show or hide the window
///
/// The window is shown by default.
///
/// \param visible True to show the window, false to hide it
///
////////////////////////////////////////////////////////////
void setVisible(bool visible);
////////////////////////////////////////////////////////////
/// \brief Enable or disable vertical synchronization
///
/// Activating vertical synchronization will limit the number
/// of frames displayed to the refresh rate of the monitor.
/// This can avoid some visual artifacts, and limit the framerate
/// to a good value (but not constant across different computers).
///
/// Vertical synchronization is disabled by default.
///
/// \param enabled True to enable v-sync, false to deactivate it
///
////////////////////////////////////////////////////////////
void setVerticalSyncEnabled(bool enabled);
////////////////////////////////////////////////////////////
/// \brief Show or hide the mouse cursor
///
/// The mouse cursor is visible by default.
///
/// \param visible True to show the mouse cursor, false to hide it
///
////////////////////////////////////////////////////////////
void setMouseCursorVisible(bool visible);
////////////////////////////////////////////////////////////
/// \brief Grab or release the mouse cursor
///
/// If set, grabs the mouse cursor inside this window's client
/// area so it may no longer be moved outside its bounds.
/// Note that grabbing is only active while the window has
/// focus.
///
/// \param grabbed True to enable, false to disable
///
////////////////////////////////////////////////////////////
void setMouseCursorGrabbed(bool grabbed);
////////////////////////////////////////////////////////////
/// \brief Enable or disable automatic key-repeat
///
/// If key repeat is enabled, you will receive repeated
/// KeyPressed events while keeping a key pressed. If it is disabled,
/// you will only get a single event when the key is pressed.
///
/// Key repeat is enabled by default.
///
/// \param enabled True to enable, false to disable
///
////////////////////////////////////////////////////////////
void setKeyRepeatEnabled(bool enabled);
////////////////////////////////////////////////////////////
/// \brief Limit the framerate to a maximum fixed frequency
///
/// If a limit is set, the window will use a small delay after
/// each call to display() to ensure that the current frame
/// lasted long enough to match the framerate limit.
/// SFML will try to match the given limit as much as it can,
/// but since it internally uses sf::sleep, whose precision
/// depends on the underlying OS, the results may be a little
/// unprecise as well (for example, you can get 65 FPS when
/// requesting 60).
///
/// \param limit Framerate limit, in frames per seconds (use 0 to disable limit)
///
////////////////////////////////////////////////////////////
void setFramerateLimit(unsigned int limit);
////////////////////////////////////////////////////////////
/// \brief Change the joystick threshold
///
/// The joystick threshold is the value below which
/// no JoystickMoved event will be generated.
///
/// The threshold value is 0.1 by default.
///
/// \param threshold New threshold, in the range [0, 100]
///
////////////////////////////////////////////////////////////
void setJoystickThreshold(float threshold);
////////////////////////////////////////////////////////////
/// \brief Activate or deactivate the window as the current target
/// for OpenGL rendering
///
/// A window is active only on the current thread, if you want to
/// make it active on another thread you have to deactivate it
/// on the previous thread first if it was active.
/// Only one window can be active on a thread at a time, thus
/// the window previously active (if any) automatically gets deactivated.
/// This is not to be confused with requestFocus().
///
/// \param active True to activate, false to deactivate
///
/// \return True if operation was successful, false otherwise
///
////////////////////////////////////////////////////////////
bool setActive(bool active = true) const;
////////////////////////////////////////////////////////////
/// \brief Request the current window to be made the active
/// foreground window
///
/// At any given time, only one window may have the input focus
/// to receive input events such as keystrokes or mouse events.
/// If a window requests focus, it only hints to the operating
/// system, that it would like to be focused. The operating system
/// is free to deny the request.
/// This is not to be confused with setActive().
///
/// \see hasFocus
///
////////////////////////////////////////////////////////////
void requestFocus();
////////////////////////////////////////////////////////////
/// \brief Check whether the window has the input focus
///
/// At any given time, only one window may have the input focus
/// to receive input events such as keystrokes or most mouse
/// events.
///
/// \return True if window has focus, false otherwise
/// \see requestFocus
///
////////////////////////////////////////////////////////////
bool hasFocus() const;
////////////////////////////////////////////////////////////
/// \brief Display on screen what has been rendered to the window so far
///
/// This function is typically called after all OpenGL rendering
/// has been done for the current frame, in order to show
/// it on screen.
///
////////////////////////////////////////////////////////////
void display();
////////////////////////////////////////////////////////////
/// \brief Get the OS-specific handle of the window
///
/// The type of the returned handle is sf::WindowHandle,
/// which is a typedef to the handle type defined by the OS.
/// You shouldn't need to use this function, unless you have
/// very specific stuff to implement that SFML doesn't support,
/// or implement a temporary workaround until a bug is fixed.
///
/// \return System handle of the window
///
////////////////////////////////////////////////////////////
WindowHandle getSystemHandle() const;
protected:
////////////////////////////////////////////////////////////
/// \brief Function called after the window has been created
///
/// This function is called so that derived classes can
/// perform their own specific initialization as soon as
/// the window is created.
///
////////////////////////////////////////////////////////////
virtual void onCreate();
////////////////////////////////////////////////////////////
/// \brief Function called after the window has been resized
///
/// This function is called so that derived classes can
/// perform custom actions when the size of the window changes.
///
////////////////////////////////////////////////////////////
virtual void onResize();
private:
////////////////////////////////////////////////////////////
/// \brief Processes an event before it is sent to the user
///
/// This function is called every time an event is received
/// from the internal window (through pollEvent or waitEvent).
/// It filters out unwanted events, and performs whatever internal
/// stuff the window needs before the event is returned to the
/// user.
///
/// \param event Event to filter
///
////////////////////////////////////////////////////////////
bool filterEvent(const Event& event);
////////////////////////////////////////////////////////////
/// \brief Perform some common internal initializations
///
////////////////////////////////////////////////////////////
void initialize();
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
priv::WindowImpl* m_impl; ///< Platform-specific implementation of the window
priv::GlContext* m_context; ///< Platform-specific implementation of the OpenGL context
Clock m_clock; ///< Clock for measuring the elapsed time between frames
Time m_frameTimeLimit; ///< Current framerate limit
Vector2u m_size; ///< Current size of the window
};
} // namespace sf
#endif // SFML_WINDOW_HPP
////////////////////////////////////////////////////////////
/// \class sf::Window
/// \ingroup window
///
/// sf::Window is the main class of the Window module. It defines
/// an OS window that is able to receive an OpenGL rendering.
///
/// A sf::Window can create its own new window, or be embedded into
/// an already existing control using the create(handle) function.
/// This can be useful for embedding an OpenGL rendering area into
/// a view which is part of a bigger GUI with existing windows,
/// controls, etc. It can also serve as embedding an OpenGL rendering
/// area into a window created by another (probably richer) GUI library
/// like Qt or wxWidgets.
///
/// The sf::Window class provides a simple interface for manipulating
/// the window: move, resize, show/hide, control mouse cursor, etc.
/// It also provides event handling through its pollEvent() and waitEvent()
/// functions.
///
/// Note that OpenGL experts can pass their own parameters (antialiasing
/// level, bits for the depth and stencil buffers, etc.) to the
/// OpenGL context attached to the window, with the sf::ContextSettings
/// structure which is passed as an optional argument when creating the
/// window.
///
/// Usage example:
/// \code
/// // Declare and create a new window
/// sf::Window window(sf::VideoMode(800, 600), "SFML window");
///
/// // Limit the framerate to 60 frames per second (this step is optional)
/// window.setFramerateLimit(60);
///
/// // The main loop - ends as soon as the window is closed
/// while (window.isOpen())
/// {
/// // Event processing
/// sf::Event event;
/// while (window.pollEvent(event))
/// {
/// // Request for closing the window
/// if (event.type == sf::Event::Closed)
/// window.close();
/// }
///
/// // Activate the window for OpenGL rendering
/// window.setActive();
///
/// // OpenGL drawing commands go here...
///
/// // End the current frame and display its contents on screen
/// window.display();
/// }
/// \endcode
///
////////////////////////////////////////////////////////////

View file

@ -0,0 +1,101 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_WINDOWHANDLE_HPP
#define SFML_WINDOWHANDLE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
// Windows' HWND is a typedef on struct HWND__*
#if defined(SFML_SYSTEM_WINDOWS)
struct HWND__;
#endif
namespace sf
{
#if defined(SFML_SYSTEM_WINDOWS)
// Window handle is HWND (HWND__*) on Windows
typedef HWND__* WindowHandle;
#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
// Window handle is Window (unsigned long) on Unix - X11
typedef unsigned long WindowHandle;
#elif defined(SFML_SYSTEM_MACOS)
// Window handle is NSWindow or NSView (void*) on Mac OS X - Cocoa
typedef void* WindowHandle;
#elif defined(SFML_SYSTEM_IOS)
// Window handle is UIWindow (void*) on iOS - UIKit
typedef void* WindowHandle;
#elif defined(SFML_SYSTEM_ANDROID)
// Window handle is ANativeWindow* (void*) on Android
typedef void* WindowHandle;
#elif defined(SFML_DOXYGEN)
// Define typedef symbol so that Doxygen can attach some documentation to it
typedef "platformspecific" WindowHandle;
#endif
} // namespace sf
#endif // SFML_WINDOWHANDLE_HPP
////////////////////////////////////////////////////////////
/// \typedef sf::WindowHandle
/// \ingroup window
///
/// Define a low-level window handle type, specific to
/// each platform.
///
/// Platform | Type
/// ----------------|------------------------------------------------------------
/// Windows | \p HWND
/// Linux/FreeBSD | \p %Window
/// Mac OS X | either \p NSWindow* or \p NSView*, disguised as \p void*
/// iOS | \p UIWindow*
/// Android | \p ANativeWindow*
///
/// \par Mac OS X Specification
///
/// On Mac OS X, a sf::Window can be created either from an
/// existing \p NSWindow* or an \p NSView*. When the window
/// is created from a window, SFML will use its content view
/// as the OpenGL area. sf::Window::getSystemHandle() will
/// return the handle that was used to create the window,
/// which is a \p NSWindow* by default.
///
////////////////////////////////////////////////////////////

View file

@ -0,0 +1,53 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_WINDOWSTYLE_HPP
#define SFML_WINDOWSTYLE_HPP
namespace sf
{
namespace Style
{
////////////////////////////////////////////////////////////
/// \ingroup window
/// \brief Enumeration of the window styles
///
////////////////////////////////////////////////////////////
enum
{
None = 0, ///< No border / title bar (this flag and all others are mutually exclusive)
Titlebar = 1 << 0, ///< Title bar + fixed border
Resize = 1 << 1, ///< Title bar + resizable border + maximize button
Close = 1 << 2, ///< Title bar + close button
Fullscreen = 1 << 3, ///< Fullscreen mode (this flag and all others are mutually exclusive)
Default = Titlebar | Resize | Close ///< Default window style
};
}
} // namespace sf
#endif // SFML_WINDOWSTYLE_HPP