Allow creation of a window without an OpenGL context in order to support use cases where the user wants to render using other graphics APIs.
This commit is contained in:
parent
04131e1607
commit
ae337952a9
24 changed files with 1009 additions and 574 deletions
|
@ -46,7 +46,7 @@ RenderWindow::RenderWindow(VideoMode mode, const String& title, Uint32 style, co
|
|||
m_defaultFrameBuffer(0)
|
||||
{
|
||||
// Don't call the base class constructor because it contains virtual function calls
|
||||
create(mode, title, style, settings);
|
||||
Window::create(mode, title, style, settings);
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,7 +55,7 @@ RenderWindow::RenderWindow(WindowHandle handle, const ContextSettings& settings)
|
|||
m_defaultFrameBuffer(0)
|
||||
{
|
||||
// Don't call the base class constructor because it contains virtual function calls
|
||||
create(handle, settings);
|
||||
Window::create(handle, settings);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ Vector2i InputImpl::getMousePosition()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::getMousePosition(const Window& relativeTo)
|
||||
Vector2i InputImpl::getMousePosition(const WindowBase& relativeTo)
|
||||
{
|
||||
return getMousePosition();
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ void InputImpl::setMousePosition(const Vector2i& position)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::setMousePosition(const Vector2i& position, const Window& relativeTo)
|
||||
void InputImpl::setMousePosition(const Vector2i& position, const WindowBase& relativeTo)
|
||||
{
|
||||
setMousePosition(position);
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int finger)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::getTouchPosition(unsigned int finger, const Window& relativeTo)
|
||||
Vector2i InputImpl::getTouchPosition(unsigned int finger, const WindowBase& relativeTo)
|
||||
{
|
||||
return getTouchPosition(finger);
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public:
|
|||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i getMousePosition(const Window& relativeTo);
|
||||
static Vector2i getMousePosition(const WindowBase& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in desktop coordinates
|
||||
|
@ -120,7 +120,7 @@ public:
|
|||
/// \param relativeTo Reference window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void setMousePosition(const Vector2i& position, const Window& relativeTo);
|
||||
static void setMousePosition(const Vector2i& position, const WindowBase& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a touch event is currently down
|
||||
|
@ -157,7 +157,7 @@ public:
|
|||
/// \return Current position of \a finger, or undefined if it's not down
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i getTouchPosition(unsigned int finger, const Window& relativeTo);
|
||||
static Vector2i getTouchPosition(unsigned int finger, const WindowBase& relativeTo);
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -41,6 +41,8 @@ set(SRC
|
|||
${SRCROOT}/VideoModeImpl.hpp
|
||||
${SRCROOT}/Window.cpp
|
||||
${INCROOT}/Window.hpp
|
||||
${SRCROOT}/WindowBase.cpp
|
||||
${INCROOT}/WindowBase.hpp
|
||||
${INCROOT}/WindowHandle.hpp
|
||||
${SRCROOT}/WindowImpl.cpp
|
||||
${SRCROOT}/WindowImpl.hpp
|
||||
|
|
|
@ -47,7 +47,7 @@ Vector2i Mouse::getPosition()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i Mouse::getPosition(const Window& relativeTo)
|
||||
Vector2i Mouse::getPosition(const WindowBase& relativeTo)
|
||||
{
|
||||
return priv::InputImpl::getMousePosition(relativeTo);
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ void Mouse::setPosition(const Vector2i& position)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Mouse::setPosition(const Vector2i& position, const Window& relativeTo)
|
||||
void Mouse::setPosition(const Vector2i& position, const WindowBase& relativeTo)
|
||||
{
|
||||
priv::InputImpl::setMousePosition(position, relativeTo);
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ public:
|
|||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i getMousePosition(const Window& relativeTo);
|
||||
static Vector2i getMousePosition(const WindowBase& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in desktop coordinates
|
||||
|
@ -121,7 +121,7 @@ public:
|
|||
/// \param relativeTo Reference window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void setMousePosition(const Vector2i& position, const Window& relativeTo);
|
||||
static void setMousePosition(const Vector2i& position, const WindowBase& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a touch event is currently down
|
||||
|
@ -158,7 +158,7 @@ public:
|
|||
/// \return Current position of \a finger, or undefined if it's not down
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i getTouchPosition(unsigned int finger, const Window& relativeTo);
|
||||
static Vector2i getTouchPosition(unsigned int finger, const WindowBase& relativeTo);
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace priv
|
|||
/// \return nil if something went wrong or a SFOpenGLView*.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFOpenGLView* getSFOpenGLViewFromSFMLWindow(const Window& window)
|
||||
SFOpenGLView* getSFOpenGLViewFromSFMLWindow(const WindowBase& window)
|
||||
{
|
||||
id nsHandle = (id)window.getSystemHandle();
|
||||
|
||||
|
@ -158,7 +158,7 @@ Vector2i InputImpl::getMousePosition()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::getMousePosition(const Window& relativeTo)
|
||||
Vector2i InputImpl::getMousePosition(const WindowBase& relativeTo)
|
||||
{
|
||||
SFOpenGLView* view = getSFOpenGLViewFromSFMLWindow(relativeTo);
|
||||
|
||||
|
@ -193,7 +193,7 @@ void InputImpl::setMousePosition(const Vector2i& position)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::setMousePosition(const Vector2i& position, const Window& relativeTo)
|
||||
void InputImpl::setMousePosition(const Vector2i& position, const WindowBase& relativeTo)
|
||||
{
|
||||
SFOpenGLView* view = getSFOpenGLViewFromSFMLWindow(relativeTo);
|
||||
|
||||
|
@ -226,7 +226,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/, const Window& /*relativeTo*/)
|
||||
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/, const WindowBase& /*relativeTo*/)
|
||||
{
|
||||
// Not applicable
|
||||
return Vector2i();
|
||||
|
|
|
@ -46,7 +46,7 @@ Vector2i Touch::getPosition(unsigned int finger)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i Touch::getPosition(unsigned int finger, const Window& relativeTo)
|
||||
Vector2i Touch::getPosition(unsigned int finger, const WindowBase& relativeTo)
|
||||
{
|
||||
return priv::InputImpl::getTouchPosition(finger, relativeTo);
|
||||
}
|
||||
|
|
|
@ -240,7 +240,7 @@ Vector2i InputImpl::getMousePosition()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::getMousePosition(const Window& relativeTo)
|
||||
Vector2i InputImpl::getMousePosition(const WindowBase& relativeTo)
|
||||
{
|
||||
WindowHandle handle = relativeTo.getSystemHandle();
|
||||
if (handle)
|
||||
|
@ -284,7 +284,7 @@ void InputImpl::setMousePosition(const Vector2i& position)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::setMousePosition(const Vector2i& position, const Window& relativeTo)
|
||||
void InputImpl::setMousePosition(const Vector2i& position, const WindowBase& relativeTo)
|
||||
{
|
||||
// Open a connection with the X server
|
||||
Display* display = OpenDisplay();
|
||||
|
@ -318,7 +318,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/, const Window& /*relativeTo*/)
|
||||
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/, const WindowBase& /*relativeTo*/)
|
||||
{
|
||||
// Not applicable
|
||||
return Vector2i();
|
||||
|
|
|
@ -95,7 +95,7 @@ public:
|
|||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i getMousePosition(const Window& relativeTo);
|
||||
static Vector2i getMousePosition(const WindowBase& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in desktop coordinates
|
||||
|
@ -120,7 +120,7 @@ public:
|
|||
/// \param relativeTo Reference window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void setMousePosition(const Vector2i& position, const Window& relativeTo);
|
||||
static void setMousePosition(const Vector2i& position, const WindowBase& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a touch event is currently down
|
||||
|
@ -157,7 +157,7 @@ public:
|
|||
/// \return Current position of \a finger, or undefined if it's not down
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i getTouchPosition(unsigned int finger, const Window& relativeTo);
|
||||
static Vector2i getTouchPosition(unsigned int finger, const WindowBase& relativeTo);
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -572,12 +572,28 @@ m_lastInputTime (0)
|
|||
int width = mode.width;
|
||||
int height = mode.height;
|
||||
|
||||
// Choose the visual according to the context settings
|
||||
XVisualInfo visualInfo = ContextType::selectBestVisual(m_display, mode.bitsPerPixel, settings);
|
||||
Visual* visual = NULL;
|
||||
int depth = 0;
|
||||
|
||||
// Check if the user chose to not create an OpenGL context (settings.attributeFlags will be 0xFFFFFFFF)
|
||||
if (settings.attributeFlags == 0xFFFFFFFF)
|
||||
{
|
||||
// Choose default visual since the user is going to use their own rendering API
|
||||
visual = DefaultVisual(m_display, m_screen);
|
||||
depth = DefaultDepth(m_display, m_screen);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Choose the visual according to the context settings
|
||||
XVisualInfo visualInfo = ContextType::selectBestVisual(m_display, mode.bitsPerPixel, settings);
|
||||
|
||||
visual = visualInfo.visual;
|
||||
depth = visualInfo.depth;
|
||||
}
|
||||
|
||||
// Define the window attributes
|
||||
XSetWindowAttributes attributes;
|
||||
attributes.colormap = XCreateColormap(m_display, DefaultRootWindow(m_display), visualInfo.visual, AllocNone);
|
||||
attributes.colormap = XCreateColormap(m_display, DefaultRootWindow(m_display), visual, AllocNone);
|
||||
attributes.event_mask = eventMask;
|
||||
attributes.override_redirect = (m_fullscreen && !ewmhSupported()) ? True : False;
|
||||
|
||||
|
@ -586,9 +602,9 @@ m_lastInputTime (0)
|
|||
windowPosition.x, windowPosition.y,
|
||||
width, height,
|
||||
0,
|
||||
visualInfo.depth,
|
||||
depth,
|
||||
InputOutput,
|
||||
visualInfo.visual,
|
||||
visual,
|
||||
CWEventMask | CWOverrideRedirect | CWColormap,
|
||||
&attributes);
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ Vector2i InputImpl::getMousePosition()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::getMousePosition(const Window& relativeTo)
|
||||
Vector2i InputImpl::getMousePosition(const WindowBase& relativeTo)
|
||||
{
|
||||
WindowHandle handle = relativeTo.getSystemHandle();
|
||||
if (handle)
|
||||
|
@ -216,7 +216,7 @@ void InputImpl::setMousePosition(const Vector2i& position)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::setMousePosition(const Vector2i& position, const Window& relativeTo)
|
||||
void InputImpl::setMousePosition(const Vector2i& position, const WindowBase& relativeTo)
|
||||
{
|
||||
WindowHandle handle = relativeTo.getSystemHandle();
|
||||
if (handle)
|
||||
|
@ -245,7 +245,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/, const Window& /*relativeTo*/)
|
||||
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/, const WindowBase& /*relativeTo*/)
|
||||
{
|
||||
// Not applicable
|
||||
return Vector2i();
|
||||
|
|
|
@ -95,7 +95,7 @@ public:
|
|||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i getMousePosition(const Window& relativeTo);
|
||||
static Vector2i getMousePosition(const WindowBase& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in desktop coordinates
|
||||
|
@ -120,7 +120,7 @@ public:
|
|||
/// \param relativeTo Reference window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void setMousePosition(const Vector2i& position, const Window& relativeTo);
|
||||
static void setMousePosition(const Vector2i& position, const WindowBase& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a touch event is currently down
|
||||
|
@ -157,7 +157,7 @@ public:
|
|||
/// \return Current position of \a finger, or undefined if it's not down
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i getTouchPosition(unsigned int finger, const Window& relativeTo);
|
||||
static Vector2i getTouchPosition(unsigned int finger, const WindowBase& relativeTo);
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -32,20 +32,12 @@
|
|||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
const sf::Window* fullscreenWindow = NULL;
|
||||
}
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
Window::Window() :
|
||||
m_impl (NULL),
|
||||
m_context (NULL),
|
||||
m_frameTimeLimit(Time::Zero),
|
||||
m_size (0, 0)
|
||||
m_frameTimeLimit(Time::Zero)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -53,23 +45,19 @@ m_size (0, 0)
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
Window::Window(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings) :
|
||||
m_impl (NULL),
|
||||
m_context (NULL),
|
||||
m_frameTimeLimit(Time::Zero),
|
||||
m_size (0, 0)
|
||||
m_frameTimeLimit(Time::Zero)
|
||||
{
|
||||
create(mode, title, style, settings);
|
||||
Window::create(mode, title, style, settings);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Window::Window(WindowHandle handle, const ContextSettings& settings) :
|
||||
m_impl (NULL),
|
||||
m_context (NULL),
|
||||
m_frameTimeLimit(Time::Zero),
|
||||
m_size (0, 0)
|
||||
m_frameTimeLimit(Time::Zero)
|
||||
{
|
||||
create(handle, settings);
|
||||
Window::create(handle, settings);
|
||||
}
|
||||
|
||||
|
||||
|
@ -80,6 +68,13 @@ Window::~Window()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::create(VideoMode mode, const String& title, Uint32 style)
|
||||
{
|
||||
Window::create(mode, title, style, ContextSettings());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::create(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings)
|
||||
{
|
||||
|
@ -90,7 +85,7 @@ void Window::create(VideoMode mode, const String& title, Uint32 style, const Con
|
|||
if (style & Style::Fullscreen)
|
||||
{
|
||||
// Make sure there's not already a fullscreen window (only one is allowed)
|
||||
if (fullscreenWindow)
|
||||
if (getFullscreenWindow())
|
||||
{
|
||||
err() << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl;
|
||||
style &= ~Style::Fullscreen;
|
||||
|
@ -105,7 +100,7 @@ void Window::create(VideoMode mode, const String& title, Uint32 style, const Con
|
|||
}
|
||||
|
||||
// Update the fullscreen window
|
||||
fullscreenWindow = this;
|
||||
setFullscreenWindow(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,6 +126,13 @@ void Window::create(VideoMode mode, const String& title, Uint32 style, const Con
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::create(WindowHandle handle)
|
||||
{
|
||||
Window::create(handle, ContextSettings());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::create(WindowHandle handle, const ContextSettings& settings)
|
||||
{
|
||||
|
@ -138,7 +140,7 @@ void Window::create(WindowHandle handle, const ContextSettings& settings)
|
|||
close();
|
||||
|
||||
// Recreate the window implementation
|
||||
m_impl = priv::WindowImpl::create(handle);
|
||||
WindowBase::create(handle);
|
||||
|
||||
// Recreate the context
|
||||
m_context = priv::GlContext::create(settings, m_impl, VideoMode::getDesktopMode().bitsPerPixel);
|
||||
|
@ -155,20 +157,8 @@ void Window::close()
|
|||
delete m_context;
|
||||
m_context = NULL;
|
||||
|
||||
// Delete the window implementation
|
||||
delete m_impl;
|
||||
m_impl = NULL;
|
||||
|
||||
// Update the fullscreen window
|
||||
if (this == fullscreenWindow)
|
||||
fullscreenWindow = NULL;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Window::isOpen() const
|
||||
{
|
||||
return m_impl != NULL;
|
||||
// Close the base window
|
||||
WindowBase::close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -181,97 +171,6 @@ const ContextSettings& Window::getSettings() const
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Window::pollEvent(Event& event)
|
||||
{
|
||||
if (m_impl && m_impl->popEvent(event, false))
|
||||
{
|
||||
return filterEvent(event);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Window::waitEvent(Event& event)
|
||||
{
|
||||
if (m_impl && m_impl->popEvent(event, true))
|
||||
{
|
||||
return filterEvent(event);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i Window::getPosition() const
|
||||
{
|
||||
return m_impl ? m_impl->getPosition() : Vector2i();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::setPosition(const Vector2i& position)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setPosition(position);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2u Window::getSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::setSize(const Vector2u& size)
|
||||
{
|
||||
if (m_impl)
|
||||
{
|
||||
m_impl->setSize(size);
|
||||
|
||||
// Cache the new size
|
||||
m_size.x = size.x;
|
||||
m_size.y = size.y;
|
||||
|
||||
// Notify the derived class
|
||||
onResize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::setTitle(const String& title)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setTitle(title);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::setIcon(unsigned int width, unsigned int height, const Uint8* pixels)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setIcon(width, height, pixels);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::setVisible(bool visible)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setVisible(visible);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::setVerticalSyncEnabled(bool enabled)
|
||||
{
|
||||
|
@ -280,38 +179,6 @@ void Window::setVerticalSyncEnabled(bool enabled)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::setMouseCursorVisible(bool visible)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setMouseCursorVisible(visible);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::setMouseCursorGrabbed(bool grabbed)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setMouseCursorGrabbed(grabbed);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::setMouseCursor(const Cursor& cursor)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setMouseCursor(cursor.getImpl());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::setKeyRepeatEnabled(bool enabled)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setKeyRepeatEnabled(enabled);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::setFramerateLimit(unsigned int limit)
|
||||
{
|
||||
|
@ -322,14 +189,6 @@ void Window::setFramerateLimit(unsigned int limit)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::setJoystickThreshold(float threshold)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setJoystickThreshold(threshold);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Window::setActive(bool active) const
|
||||
{
|
||||
|
@ -353,22 +212,6 @@ bool Window::setActive(bool active) const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::requestFocus()
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->requestFocus();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Window::hasFocus() const
|
||||
{
|
||||
return m_impl && m_impl->hasFocus();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
void Window::display()
|
||||
{
|
||||
// Display the backbuffer on screen
|
||||
|
@ -384,66 +227,20 @@ void Window::display()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowHandle Window::getSystemHandle() const
|
||||
{
|
||||
return m_impl ? m_impl->getSystemHandle() : 0;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::onCreate()
|
||||
{
|
||||
// Nothing by default
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::onResize()
|
||||
{
|
||||
// Nothing by default
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Window::filterEvent(const Event& event)
|
||||
{
|
||||
// Notify resize events to the derived class
|
||||
if (event.type == Event::Resized)
|
||||
{
|
||||
// Cache the new size
|
||||
m_size.x = event.size.width;
|
||||
m_size.y = event.size.height;
|
||||
|
||||
// Notify the derived class
|
||||
onResize();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::initialize()
|
||||
{
|
||||
// Setup default behaviors (to get a consistent behavior across different implementations)
|
||||
setVisible(true);
|
||||
setMouseCursorVisible(true);
|
||||
setVerticalSyncEnabled(false);
|
||||
setKeyRepeatEnabled(true);
|
||||
setFramerateLimit(0);
|
||||
|
||||
// Get and cache the initial size of the window
|
||||
m_size = m_impl->getSize();
|
||||
|
||||
// Reset frame time
|
||||
m_clock.restart();
|
||||
|
||||
// Activate the window
|
||||
setActive();
|
||||
|
||||
// Notify the derived class
|
||||
onCreate();
|
||||
WindowBase::initialize();
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
372
src/SFML/Window/WindowBase.cpp
Normal file
372
src/SFML/Window/WindowBase.cpp
Normal file
|
@ -0,0 +1,372 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/WindowBase.hpp>
|
||||
#include <SFML/Window/ContextSettings.hpp>
|
||||
#include <SFML/Window/WindowImpl.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
const sf::WindowBase* fullscreenWindow = NULL;
|
||||
}
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowBase::WindowBase() :
|
||||
m_impl (NULL),
|
||||
m_size (0, 0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowBase::WindowBase(VideoMode mode, const String& title, Uint32 style) :
|
||||
m_impl (NULL),
|
||||
m_size (0, 0)
|
||||
{
|
||||
WindowBase::create(mode, title, style);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowBase::WindowBase(WindowHandle handle) :
|
||||
m_impl (NULL),
|
||||
m_size (0, 0)
|
||||
{
|
||||
WindowBase::create(handle);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowBase::~WindowBase()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::create(VideoMode mode, const String& title, Uint32 style)
|
||||
{
|
||||
// Destroy the previous window implementation
|
||||
close();
|
||||
|
||||
// Fullscreen style requires some tests
|
||||
if (style & Style::Fullscreen)
|
||||
{
|
||||
// Make sure there's not already a fullscreen window (only one is allowed)
|
||||
if (getFullscreenWindow())
|
||||
{
|
||||
err() << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl;
|
||||
style &= ~Style::Fullscreen;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Make sure that the chosen video mode is compatible
|
||||
if (!mode.isValid())
|
||||
{
|
||||
err() << "The requested video mode is not available, switching to a valid mode" << std::endl;
|
||||
mode = VideoMode::getFullscreenModes()[0];
|
||||
}
|
||||
|
||||
// Update the fullscreen window
|
||||
setFullscreenWindow(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Check validity of style according to the underlying platform
|
||||
#if defined(SFML_SYSTEM_IOS) || defined(SFML_SYSTEM_ANDROID)
|
||||
if (style & Style::Fullscreen)
|
||||
style &= ~Style::Titlebar;
|
||||
else
|
||||
style |= Style::Titlebar;
|
||||
#else
|
||||
if ((style & Style::Close) || (style & Style::Resize))
|
||||
style |= Style::Titlebar;
|
||||
#endif
|
||||
|
||||
// Recreate the window implementation
|
||||
m_impl = priv::WindowImpl::create(mode, title, style, ContextSettings(0, 0, 0, 0, 0, 0xFFFFFFFF, false));
|
||||
|
||||
// Perform common initializations
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::create(WindowHandle handle)
|
||||
{
|
||||
// Destroy the previous window implementation
|
||||
close();
|
||||
|
||||
// Recreate the window implementation
|
||||
m_impl = priv::WindowImpl::create(handle);
|
||||
|
||||
// Perform common initializations
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::close()
|
||||
{
|
||||
// Delete the window implementation
|
||||
delete m_impl;
|
||||
m_impl = NULL;
|
||||
|
||||
// Update the fullscreen window
|
||||
if (this == getFullscreenWindow())
|
||||
setFullscreenWindow(NULL);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool WindowBase::isOpen() const
|
||||
{
|
||||
return m_impl != NULL;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool WindowBase::pollEvent(Event& event)
|
||||
{
|
||||
if (m_impl && m_impl->popEvent(event, false))
|
||||
{
|
||||
return filterEvent(event);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool WindowBase::waitEvent(Event& event)
|
||||
{
|
||||
if (m_impl && m_impl->popEvent(event, true))
|
||||
{
|
||||
return filterEvent(event);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i WindowBase::getPosition() const
|
||||
{
|
||||
return m_impl ? m_impl->getPosition() : Vector2i();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::setPosition(const Vector2i& position)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setPosition(position);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2u WindowBase::getSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::setSize(const Vector2u& size)
|
||||
{
|
||||
if (m_impl)
|
||||
{
|
||||
m_impl->setSize(size);
|
||||
|
||||
// Cache the new size
|
||||
m_size.x = size.x;
|
||||
m_size.y = size.y;
|
||||
|
||||
// Notify the derived class
|
||||
onResize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::setTitle(const String& title)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setTitle(title);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::setIcon(unsigned int width, unsigned int height, const Uint8* pixels)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setIcon(width, height, pixels);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::setVisible(bool visible)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setVisible(visible);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::setMouseCursorVisible(bool visible)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setMouseCursorVisible(visible);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::setMouseCursorGrabbed(bool grabbed)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setMouseCursorGrabbed(grabbed);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::setMouseCursor(const Cursor& cursor)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setMouseCursor(cursor.getImpl());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::setKeyRepeatEnabled(bool enabled)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setKeyRepeatEnabled(enabled);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::setJoystickThreshold(float threshold)
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->setJoystickThreshold(threshold);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::requestFocus()
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->requestFocus();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool WindowBase::hasFocus() const
|
||||
{
|
||||
return m_impl && m_impl->hasFocus();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowHandle WindowBase::getSystemHandle() const
|
||||
{
|
||||
return m_impl ? m_impl->getSystemHandle() : 0;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::onCreate()
|
||||
{
|
||||
// Nothing by default
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::onResize()
|
||||
{
|
||||
// Nothing by default
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool WindowBase::filterEvent(const Event& event)
|
||||
{
|
||||
// Notify resize events to the derived class
|
||||
if (event.type == Event::Resized)
|
||||
{
|
||||
// Cache the new size
|
||||
m_size.x = event.size.width;
|
||||
m_size.y = event.size.height;
|
||||
|
||||
// Notify the derived class
|
||||
onResize();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::initialize()
|
||||
{
|
||||
// Setup default behaviors (to get a consistent behavior across different implementations)
|
||||
setVisible(true);
|
||||
setMouseCursorVisible(true);
|
||||
setKeyRepeatEnabled(true);
|
||||
|
||||
// Get and cache the initial size of the window
|
||||
m_size = m_impl->getSize();
|
||||
|
||||
// Notify the derived class
|
||||
onCreate();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const WindowBase* WindowBase::getFullscreenWindow()
|
||||
{
|
||||
return fullscreenWindow;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowBase::setFullscreenWindow(const WindowBase* window)
|
||||
{
|
||||
fullscreenWindow = window;
|
||||
}
|
||||
|
||||
} // namespace sf
|
|
@ -95,7 +95,7 @@ public:
|
|||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i getMousePosition(const Window& relativeTo);
|
||||
static Vector2i getMousePosition(const WindowBase& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in desktop coordinates
|
||||
|
@ -120,7 +120,7 @@ public:
|
|||
/// \param relativeTo Reference window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void setMousePosition(const Vector2i& position, const Window& relativeTo);
|
||||
static void setMousePosition(const Vector2i& position, const WindowBase& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a touch event is currently down
|
||||
|
@ -157,7 +157,7 @@ public:
|
|||
/// \return Current position of \a finger, or undefined if it's not down
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i getTouchPosition(unsigned int finger, const Window& relativeTo);
|
||||
static Vector2i getTouchPosition(unsigned int finger, const WindowBase& relativeTo);
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -67,7 +67,7 @@ Vector2i InputImpl::getMousePosition()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::getMousePosition(const Window& relativeTo)
|
||||
Vector2i InputImpl::getMousePosition(const WindowBase& relativeTo)
|
||||
{
|
||||
(void)relativeTo;
|
||||
|
||||
|
@ -83,7 +83,7 @@ void InputImpl::setMousePosition(const Vector2i& position)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::setMousePosition(const Vector2i& position, const Window& relativeTo)
|
||||
void InputImpl::setMousePosition(const Vector2i& position, const WindowBase& relativeTo)
|
||||
{
|
||||
// Not applicable
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int finger)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::getTouchPosition(unsigned int finger, const Window& relativeTo)
|
||||
Vector2i InputImpl::getTouchPosition(unsigned int finger, const WindowBase& relativeTo)
|
||||
{
|
||||
(void)relativeTo;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue