Added Window::GetPosition, and renamed some setters in Window for better consistency

This commit is contained in:
Laurent Gomila 2012-03-07 23:29:54 +01:00
parent 90854907b5
commit 15e9d999b3
26 changed files with 473 additions and 492 deletions

View File

@ -5,6 +5,7 @@
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp> #include <SFML/OpenGL.hpp>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Entry point of application /// Entry point of application
/// ///
@ -15,7 +16,7 @@ int main()
{ {
// Create the main window // Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL", sf::Style::Default, sf::ContextSettings(32)); sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL", sf::Style::Default, sf::ContextSettings(32));
window.EnableVerticalSync(true); window.SetVerticalSyncEnabled(true);
// Create a sprite for the background // Create a sprite for the background
sf::Texture backgroundTexture; sf::Texture backgroundTexture;
@ -90,8 +91,8 @@ int main()
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
// We get the position of the mouse cursor, so that we can move the box accordingly // We get the position of the mouse cursor, so that we can move the box accordingly
float x = sf::Mouse::GetPosition(window).x * 200.f / window.GetWidth() - 100.f; float x = sf::Mouse::GetPosition(window).x * 200.f / window.GetSize().x - 100.f;
float y = -sf::Mouse::GetPosition(window).y * 200.f / window.GetHeight() + 100.f; float y = -sf::Mouse::GetPosition(window).y * 200.f / window.GetSize().y + 100.f;
// Apply some transformations // Apply some transformations
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);

View File

@ -28,7 +28,7 @@ int main()
// Create the window of the application // Create the window of the application
sf::RenderWindow window(sf::VideoMode(gameWidth, gameHeight, 32), "SFML Pong"); sf::RenderWindow window(sf::VideoMode(gameWidth, gameHeight, 32), "SFML Pong");
window.EnableVerticalSync(true); window.SetVerticalSyncEnabled(true);
// Load the sounds used in the game // Load the sounds used in the game
sf::SoundBuffer ballSoundBuffer; sf::SoundBuffer ballSoundBuffer;

View File

@ -265,7 +265,7 @@ int main()
{ {
// Create the main window // Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader"); sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader");
window.EnableVerticalSync(true); window.SetVerticalSyncEnabled(true);
// Create the effects // Create the effects
std::vector<Effect*> effects; std::vector<Effect*> effects;
@ -348,8 +348,8 @@ int main()
} }
// Update the current example // Update the current example
float x = static_cast<float>(sf::Mouse::GetPosition(window).x) / window.GetWidth(); float x = static_cast<float>(sf::Mouse::GetPosition(window).x) / window.GetSize().x;
float y = static_cast<float>(sf::Mouse::GetPosition(window).y) / window.GetHeight(); float y = static_cast<float>(sf::Mouse::GetPosition(window).y) / window.GetSize().y;
effects[current]->Update(clock.GetElapsedTime().AsSeconds(), x, y); effects[current]->Update(clock.GetElapsedTime().AsSeconds(), x, y);
// Clear the window // Clear the window

View File

@ -200,24 +200,14 @@ public :
PrimitiveType type, const RenderStates& states = RenderStates::Default); PrimitiveType type, const RenderStates& states = RenderStates::Default);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Return the width of the rendering region of the target /// \brief Return the size of the rendering region of the target
/// ///
/// \return Width in pixels /// \return Size in pixels
/// ///
/// \see GetHeight /// \see GetHeight
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual unsigned int GetWidth() const = 0; virtual Vector2u GetSize() const = 0;
////////////////////////////////////////////////////////////
/// \brief Return the height of the rendering region of the target
///
/// \return Height in pixels
///
/// \see GetWidth
///
////////////////////////////////////////////////////////////
virtual unsigned int GetHeight() const = 0;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Save the current OpenGL render states and matrices /// \brief Save the current OpenGL render states and matrices

View File

@ -137,30 +137,15 @@ public :
void Display(); void Display();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Return the width of the rendering region of the texture /// \brief Return the size of the rendering region of the texture
/// ///
/// The returned value is the size that you passed to /// The returned value is the size that you passed to
/// the Create function. /// the Create function.
/// ///
/// \return Width in pixels /// \return Size in pixels
///
/// \return GetHeight
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual unsigned int GetWidth() const; virtual Vector2u GetSize() const;
////////////////////////////////////////////////////////////
/// \brief Return the height of the rendering region of the texture
///
/// The returned value is the size that you passed to
/// the Create function.
///
/// \return Height in pixels
///
/// \return GetWidth
///
////////////////////////////////////////////////////////////
virtual unsigned int GetHeight() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get a read-only reference to the target texture /// \brief Get a read-only reference to the target texture

View File

@ -101,30 +101,15 @@ public :
virtual ~RenderWindow(); virtual ~RenderWindow();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the width of the rendering region of the window /// \brief Get the size of the rendering region of the window
/// ///
/// The width doesn't include the titlebar and borders /// The size doesn't include the titlebar and borders
/// of the window. /// of the window.
/// ///
/// \return Width in pixels /// \return Size in pixels
///
/// \see GetHeight
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual unsigned int GetWidth() const; virtual Vector2u GetSize() const;
////////////////////////////////////////////////////////////
/// Get the height of the rendering region of the window
///
/// The height doesn't include the titlebar and borders
/// of the window.
///
/// \return Height in pixels
///
/// \see GetWidth
///
////////////////////////////////////////////////////////////
virtual unsigned int GetHeight() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Copy the current contents of the window to an image /// \brief Copy the current contents of the window to an image

View File

@ -153,42 +153,17 @@ public :
void Close(); void Close();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Tell whether or not the window is opened /// \brief Tell whether or not the window is open
/// ///
/// This function returns whether or not the window exists. /// This function returns whether or not the window exists.
/// Note that a hidden window (Show(false)) will return true. /// Note that a hidden window (SetVisible(false)) is open
/// (therefore this function would return true).
/// ///
/// \return True if the window is opened, false if it has been closed /// \return True if the window is open, false if it has been closed
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool IsOpen() const; bool IsOpen() const;
////////////////////////////////////////////////////////////
/// \brief Get the width of the rendering region of the window
///
/// The width doesn't include the titlebar and borders
/// of the window.
///
/// \return Width in pixels
///
/// \see GetHeight
///
////////////////////////////////////////////////////////////
unsigned int GetWidth() const;
////////////////////////////////////////////////////////////
/// \brief Get the height of the rendering region of the window
///
/// The height doesn't include the titlebar and borders
/// of the window.
///
/// \return Height in pixels
///
/// \see GetWidth
///
////////////////////////////////////////////////////////////
unsigned int GetHeight() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the settings of the OpenGL context of the window /// \brief Get the settings of the OpenGL context of the window
/// ///
@ -255,29 +230,14 @@ public :
bool WaitEvent(Event& event); bool WaitEvent(Event& event);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Enable or disable vertical synchronization /// \brief Get the position of the window
/// ///
/// Activating vertical synchronization will limit the number /// \return Position of the window, in pixels
/// 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. /// \see SetPosition
///
/// \param enabled True to enable v-sync, false to deactivate
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void EnableVerticalSync(bool enabled); Vector2i GetPosition() const;
////////////////////////////////////////////////////////////
/// \brief Show or hide the mouse cursor
///
/// The mouse cursor is shown by default.
///
/// \param show True to show, false to hide
///
////////////////////////////////////////////////////////////
void ShowMouseCursor(bool show);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the position of the window on screen /// \brief Change the position of the window on screen
@ -286,53 +246,46 @@ public :
/// (i.e. it will be ignored for windows created from /// (i.e. it will be ignored for windows created from
/// the handle of a child window/control). /// the handle of a child window/control).
/// ///
/// \param x Left position /// \param position New position, in pixels
/// \param y Top position ///
/// \see GetPosition
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetPosition(int x, int y); 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 /// \brief Change the size of the rendering region of the window
/// ///
/// \param width New width, in pixels /// \param size New size, in pixels
/// \param height New height, in pixels ///
/// \see GetSize
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetSize(unsigned int width, unsigned int height); void SetSize(const Vector2u size);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the title of the window /// \brief Change the title of the window
/// ///
/// \param title New title /// \param title New title
/// ///
/// \see SetIcon
///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetTitle(const std::string& title); void SetTitle(const std::string& title);
////////////////////////////////////////////////////////////
/// \brief Show or hide the window
///
/// The window is shown by default.
///
/// \param show True to show, false to hide
///
////////////////////////////////////////////////////////////
void Show(bool show);
////////////////////////////////////////////////////////////
/// \brief Enable or disable automatic key-repeat
///
/// If key repeat is enabled, you will receive repeated
/// KeyPress events while keeping a key pressed. If it is disabled,
/// you will only get a single event when the key is pressed.
///
/// Key repeat is enabled by default.
///
/// \param enabled True to enable, false to disable
///
////////////////////////////////////////////////////////////
void EnableKeyRepeat(bool enabled);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the window's icon /// \brief Change the window's icon
/// ///
@ -345,36 +298,59 @@ public :
/// \param height Icon's height, in pixels /// \param height Icon's height, in pixels
/// \param pixels Pointer to the array of pixels in memory /// \param pixels Pointer to the array of pixels in memory
/// ///
/// \see SetTitle
///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels); void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Activate or deactivate the window as the current target /// \brief Show or hide the window
/// for OpenGL rendering
/// ///
/// A window is active only on the current thread, if you want to /// The window is shown by default.
/// 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.
/// ///
/// \param active True to activate, false to deactivate /// \param visible True to show the window, false to hide it
///
/// \return True if operation was successful, false otherwise
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool SetActive(bool active = true) const; void SetVisible(bool visible);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Display on screen what has been rendered to the /// \brief Enable or disable vertical synchronization
/// window so far
/// ///
/// This function is typically called after all OpenGL rendering /// Activating vertical synchronization will limit the number
/// has been done for the current frame, in order to show /// of frames displayed to the refresh rate of the monitor.
/// it on screen. /// 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 Display(); 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 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 /// \brief Limit the framerate to a maximum fixed frequency
@ -406,6 +382,33 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetJoystickThreshold(float threshold); 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.
///
/// \param active True to activate, false to deactivate
///
/// \return True if operation was successful, false otherwise
///
////////////////////////////////////////////////////////////
bool SetActive(bool active = true) 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 /// \brief Get the OS-specific handle of the window
/// ///

View File

@ -87,8 +87,8 @@ const View& RenderTarget::GetDefaultView() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
IntRect RenderTarget::GetViewport(const View& view) const IntRect RenderTarget::GetViewport(const View& view) const
{ {
float width = static_cast<float>(GetWidth()); float width = static_cast<float>(GetSize().x);
float height = static_cast<float>(GetHeight()); float height = static_cast<float>(GetSize().y);
const FloatRect& viewport = view.GetViewport(); const FloatRect& viewport = view.GetViewport();
return IntRect(static_cast<int>(0.5f + width * viewport.Left), return IntRect(static_cast<int>(0.5f + width * viewport.Left),
@ -284,7 +284,7 @@ void RenderTarget::ResetGLStates()
void RenderTarget::Initialize() void RenderTarget::Initialize()
{ {
// Setup the default and current views // Setup the default and current views
myDefaultView.Reset(FloatRect(0, 0, static_cast<float>(GetWidth()), static_cast<float>(GetHeight()))); myDefaultView.Reset(FloatRect(0, 0, static_cast<float>(GetSize().x), static_cast<float>(GetSize().y)));
myView = myDefaultView; myView = myDefaultView;
// Initialize the default OpenGL render-states // Initialize the default OpenGL render-states
@ -297,7 +297,7 @@ void RenderTarget::ApplyCurrentView()
{ {
// Set the viewport // Set the viewport
IntRect viewport = GetViewport(myView); IntRect viewport = GetViewport(myView);
int top = GetHeight() - (viewport.Top + viewport.Height); int top = GetSize().y - (viewport.Top + viewport.Height);
GLCheck(glViewport(viewport.Left, top, viewport.Width, viewport.Height)); GLCheck(glViewport(viewport.Left, top, viewport.Width, viewport.Height));
// Set the projection matrix // Set the projection matrix

View File

@ -119,16 +119,9 @@ void RenderTexture::Display()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int RenderTexture::GetWidth() const Vector2u RenderTexture::GetSize() const
{ {
return myTexture.GetWidth(); return Vector2u(myTexture.GetWidth(), myTexture.GetHeight());
}
////////////////////////////////////////////////////////////
unsigned int RenderTexture::GetHeight() const
{
return myTexture.GetHeight();
} }

View File

@ -69,16 +69,9 @@ bool RenderWindow::Activate(bool active)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int RenderWindow::GetWidth() const Vector2u RenderWindow::GetSize() const
{ {
return Window::GetWidth(); return Window::GetSize();
}
////////////////////////////////////////////////////////////
unsigned int RenderWindow::GetHeight() const
{
return Window::GetHeight();
} }
@ -88,8 +81,8 @@ Image RenderWindow::Capture() const
Image image; Image image;
if (SetActive()) if (SetActive())
{ {
int width = static_cast<int>(GetWidth()); int width = static_cast<int>(GetSize().x);
int height = static_cast<int>(GetHeight()); int height = static_cast<int>(GetSize().y);
// copy rows one by one and flip them (OpenGL's origin is bottom while SFML's origin is top) // copy rows one by one and flip them (OpenGL's origin is bottom while SFML's origin is top)
std::vector<Uint8> pixels(width * height * 4); std::vector<Uint8> pixels(width * height * 4);

View File

@ -369,8 +369,8 @@ void Texture::Update(const Window& window)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Texture::Update(const Window& window, unsigned int x, unsigned int y) void Texture::Update(const Window& window, unsigned int x, unsigned int y)
{ {
assert(x + window.GetWidth() <= myWidth); assert(x + window.GetSize().x <= myWidth);
assert(y + window.GetHeight() <= myHeight); assert(y + window.GetSize().y <= myHeight);
if (myTexture && window.SetActive(true)) if (myTexture && window.SetActive(true))
{ {
@ -379,7 +379,7 @@ void Texture::Update(const Window& window, unsigned int x, unsigned int y)
// Copy pixels from the back-buffer to the texture // Copy pixels from the back-buffer to the texture
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture)); GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 0, 0, window.GetWidth(), window.GetHeight())); GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 0, 0, window.GetSize().x, window.GetSize().y));
myPixelsFlipped = true; myPixelsFlipped = true;
myCacheId = GetUniqueId(); myCacheId = GetUniqueId();
} }

View File

@ -172,7 +172,7 @@ public :
/// \param enabled True to enable v-sync, false to deactivate /// \param enabled True to enable v-sync, false to deactivate
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void EnableVerticalSync(bool enabled) = 0; virtual void SetVerticalSyncEnabled(bool enabled) = 0;
protected : protected :

View File

@ -147,7 +147,7 @@ void GlxContext::Display()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void GlxContext::EnableVerticalSync(bool enabled) void GlxContext::SetVerticalSyncEnabled(bool enabled)
{ {
const GLubyte* name = reinterpret_cast<const GLubyte*>("glXSwapIntervalSGI"); const GLubyte* name = reinterpret_cast<const GLubyte*>("glXSwapIntervalSGI");
PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = reinterpret_cast<PFNGLXSWAPINTERVALSGIPROC>(glXGetProcAddress(name)); PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = reinterpret_cast<PFNGLXSWAPINTERVALSGIPROC>(glXGetProcAddress(name));

View File

@ -107,7 +107,7 @@ public :
/// \param enabled : True to enable v-sync, false to deactivate /// \param enabled : True to enable v-sync, false to deactivate
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void EnableVerticalSync(bool enabled); virtual void SetVerticalSyncEnabled(bool enabled);
private : private :

View File

@ -80,16 +80,6 @@ myKeyRepeat (true)
if (myWindow) if (myWindow)
{ {
// Get the window size
XWindowAttributes windowAttributes;
if (XGetWindowAttributes(myDisplay, myWindow, &windowAttributes) == 0)
{
Err() << "Failed to get the window attributes" << std::endl;
return;
}
myWidth = windowAttributes.width;
myHeight = windowAttributes.height;
// Make sure the window is listening to all the requiered events // Make sure the window is listening to all the requiered events
XSelectInput(myDisplay, myWindow, eventMask & ~ButtonPressMask); XSelectInput(myDisplay, myWindow, eventMask & ~ButtonPressMask);
@ -127,8 +117,8 @@ myKeyRepeat (true)
left = 0; left = 0;
top = 0; top = 0;
} }
int width = myWidth = mode.Width; int width = mode.Width;
int height = myHeight = mode.Height; int height = mode.Height;
// Switch to fullscreen if necessary // Switch to fullscreen if necessary
if (fullscreen) if (fullscreen)
@ -243,7 +233,7 @@ myKeyRepeat (true)
WindowImplX11::~WindowImplX11() WindowImplX11::~WindowImplX11()
{ {
// Cleanup graphical resources // Cleanup graphical resources
CleanUp(); Cleanup();
// Destroy the cursor // Destroy the cursor
if (myHiddenCursor) if (myHiddenCursor)
@ -295,25 +285,35 @@ void WindowImplX11::ProcessEvents()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplX11::ShowMouseCursor(bool show) Vector2i WindowImplX11::GetPosition() const
{ {
XDefineCursor(myDisplay, myWindow, show ? None : myHiddenCursor); XWindowAttributes attributes;
XGetWindowAttributes(myDisplay, myWindow, &attributes);
return Vector2i(attributes.x, attributes.y);
}
////////////////////////////////////////////////////////////
void WindowImplX11::SetPosition(const Vector2i& position)
{
XMoveWindow(myDisplay, myWindow, position.x, position.y);
XFlush(myDisplay); XFlush(myDisplay);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplX11::SetPosition(int x, int y) Vector2u WindowImplX11::GetSize() const
{ {
XMoveWindow(myDisplay, myWindow, x, y); XWindowAttributes attributes;
XFlush(myDisplay); XGetWindowAttributes(myDisplay, myWindow, &attributes);
return Vector2u(attributes.width, attributes.height);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplX11::SetSize(unsigned int width, unsigned int height) void WindowImplX11::SetSize(const Vector2u& size)
{ {
XResizeWindow(myDisplay, myWindow, width, height); XResizeWindow(myDisplay, myWindow, size.x, size.y);
XFlush(myDisplay); XFlush(myDisplay);
} }
@ -325,25 +325,6 @@ void WindowImplX11::SetTitle(const std::string& title)
} }
////////////////////////////////////////////////////////////
void WindowImplX11::Show(bool show)
{
if (show)
XMapWindow(myDisplay, myWindow);
else
XUnmapWindow(myDisplay, myWindow);
XFlush(myDisplay);
}
////////////////////////////////////////////////////////////
void WindowImplX11::EnableKeyRepeat(bool enabled)
{
myKeyRepeat = enabled;
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplX11::SetIcon(unsigned int width, unsigned int height, const Uint8* pixels) void WindowImplX11::SetIcon(unsigned int width, unsigned int height, const Uint8* pixels)
{ {
@ -405,6 +386,33 @@ void WindowImplX11::SetIcon(unsigned int width, unsigned int height, const Uint8
} }
////////////////////////////////////////////////////////////
void WindowImplX11::SetVisible(bool visible)
{
if (visible)
XMapWindow(myDisplay, myWindow);
else
XUnmapWindow(myDisplay, myWindow);
XFlush(myDisplay);
}
////////////////////////////////////////////////////////////
void WindowImplX11::SetMouseCursorVisible(bool visible)
{
XDefineCursor(myDisplay, myWindow, visible ? None : myHiddenCursor);
XFlush(myDisplay);
}
////////////////////////////////////////////////////////////
void WindowImplX11::SetKeyRepeatEnabled(bool enabled)
{
myKeyRepeat = enabled;
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplX11::SwitchToFullscreen(const VideoMode& mode) void WindowImplX11::SwitchToFullscreen(const VideoMode& mode)
{ {
@ -517,7 +525,7 @@ void WindowImplX11::CreateHiddenCursor()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplX11::CleanUp() void WindowImplX11::Cleanup()
{ {
// Restore the previous video mode (in case we were running in fullscreen) // Restore the previous video mode (in case we were running in fullscreen)
if (fullscreenWindow == this) if (fullscreenWindow == this)
@ -542,7 +550,7 @@ void WindowImplX11::CleanUp()
} }
// Unhide the mouse cursor (in case it was hidden) // Unhide the mouse cursor (in case it was hidden)
ShowMouseCursor(true); SetMouseCursorVisible(true);
} }
@ -595,7 +603,7 @@ bool WindowImplX11::ProcessEvent(XEvent windowEvent)
case DestroyNotify : case DestroyNotify :
{ {
// The window is about to be destroyed : we must cleanup resources // The window is about to be destroyed : we must cleanup resources
CleanUp(); Cleanup();
break; break;
} }
@ -628,17 +636,11 @@ bool WindowImplX11::ProcessEvent(XEvent windowEvent)
// Resize event // Resize event
case ConfigureNotify : case ConfigureNotify :
{ {
if ((windowEvent.xconfigure.width != static_cast<int>(myWidth)) || (windowEvent.xconfigure.height != static_cast<int>(myHeight)))
{
myWidth = windowEvent.xconfigure.width;
myHeight = windowEvent.xconfigure.height;
Event event; Event event;
event.Type = Event::Resized; event.Type = Event::Resized;
event.Size.Width = myWidth; event.Size.Width = windowEvent.xconfigure.width;
event.Size.Height = myHeight; event.Size.Height = windowEvent.xconfigure.height;
PushEvent(event); PushEvent(event);
}
break; break;
} }

View File

@ -98,30 +98,36 @@ private :
virtual void ProcessEvents(); virtual void ProcessEvents();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Show or hide the mouse cursor /// \brief Get the position of the window
/// ///
/// \param show True to show, false to hide /// \return Position of the window, in pixels
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void ShowMouseCursor(bool show); virtual Vector2i GetPosition() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the position of the window on screen /// \brief Change the position of the window on screen
/// ///
/// \param x Left position /// \param position New position of the window, in pixels
/// \param y Top position
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetPosition(int x, int y); virtual void SetPosition(const Vector2i& position);
////////////////////////////////////////////////////////////
/// \brief Get the client size of the window
///
/// \return Size of the window, in pixels
///
////////////////////////////////////////////////////////////
virtual Vector2u GetSize() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the size of the rendering region of the window /// \brief Change the size of the rendering region of the window
/// ///
/// \param width New width /// \param size New size, in pixels
/// \param height New height
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetSize(unsigned int width, unsigned int height); virtual void SetSize(const Vector2u& size);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the title of the window /// \brief Change the title of the window
@ -131,22 +137,6 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetTitle(const std::string& title); virtual void SetTitle(const std::string& title);
////////////////////////////////////////////////////////////
/// \brief Show or hide the window
///
/// \param show True to show, false to hide
///
////////////////////////////////////////////////////////////
virtual void Show(bool show);
////////////////////////////////////////////////////////////
/// \brief Enable or disable automatic key-repeat
///
/// \param enabled True to enable, false to disable
///
////////////////////////////////////////////////////////////
virtual void EnableKeyRepeat(bool enabled);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the window's icon /// \brief Change the window's icon
/// ///
@ -157,6 +147,32 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels); virtual void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels);
////////////////////////////////////////////////////////////
/// \brief Show or hide the window
///
/// \param visible True to show, false to hide
///
////////////////////////////////////////////////////////////
virtual void SetVisible(bool visible);
////////////////////////////////////////////////////////////
/// \brief Show or hide the mouse cursor
///
/// \param visible True to show, false to hide
///
////////////////////////////////////////////////////////////
virtual void SetMouseCursorVisible(bool visible);
////////////////////////////////////////////////////////////
/// \brief Enable or disable automatic key-repeat
///
/// \param enabled True to enable, false to disable
///
////////////////////////////////////////////////////////////
virtual void SetKeyRepeatEnabled(bool enabled);
private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Switch to fullscreen mode /// \brief Switch to fullscreen mode
/// ///
@ -181,7 +197,7 @@ private :
/// \brief Cleanup graphical resources attached to the window /// \brief Cleanup graphical resources attached to the window
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void CleanUp(); void Cleanup();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Process an incoming event from the window /// \brief Process an incoming event from the window

View File

@ -120,7 +120,7 @@ public:
/// \param enabled : True to enable v-sync, false to deactivate /// \param enabled : True to enable v-sync, false to deactivate
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void EnableVerticalSync(bool enabled); virtual void SetVerticalSyncEnabled(bool enabled);
protected: protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -124,7 +124,7 @@ void SFContext::Display()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SFContext::EnableVerticalSync(bool enabled) void SFContext::SetVerticalSyncEnabled(bool enabled)
{ {
// Make compiler happy // Make compiler happy
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1060

View File

@ -249,30 +249,36 @@ private:
virtual WindowHandle GetSystemHandle() const; virtual WindowHandle GetSystemHandle() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Show or hide the mouse cursor /// \brief Get the position of the window
/// ///
/// \param show True to show, false to hide /// \return Position of the window, in pixels
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void ShowMouseCursor(bool show); virtual Vector2i GetPosition() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the position of the window on screen /// \brief Change the position of the window on screen
/// ///
/// \param x Left position /// \param position New position of the window, in pixels
/// \param y Top position
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetPosition(int x, int y); virtual void SetPosition(const Vector2i& position);
////////////////////////////////////////////////////////////
/// \brief Get the client size of the window
///
/// \return Size of the window, in pixels
///
////////////////////////////////////////////////////////////
virtual Vector2u GetSize() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the size of the rendering region of the window /// \brief Change the size of the rendering region of the window
/// ///
/// \param width New width /// \param size New size, in pixels
/// \param height New height
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetSize(unsigned int width, unsigned int height); virtual void SetSize(const Vector2u& size);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the title of the window /// \brief Change the title of the window
@ -282,22 +288,6 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetTitle(const std::string& title); virtual void SetTitle(const std::string& title);
////////////////////////////////////////////////////////////
/// \brief Show or hide the window
///
/// \param show True to show, false to hide
///
////////////////////////////////////////////////////////////
virtual void Show(bool show);
////////////////////////////////////////////////////////////
/// \brief Enable or disable automatic key-repeat
///
/// \param enabled True to enable, false to disable
///
////////////////////////////////////////////////////////////
virtual void EnableKeyRepeat(bool enabled);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the window's icon /// \brief Change the window's icon
/// ///
@ -308,6 +298,32 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels); virtual void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels);
////////////////////////////////////////////////////////////
/// \brief Show or hide the window
///
/// \param visible True to show, false to hide
///
////////////////////////////////////////////////////////////
virtual void SetVisible(bool visible);
////////////////////////////////////////////////////////////
/// \brief Show or hide the mouse cursor
///
/// \param visible True to show, false to hide
///
////////////////////////////////////////////////////////////
virtual void SetMouseCursorVisible(bool visible);
////////////////////////////////////////////////////////////
/// \brief Enable or disable automatic key-repeat
///
/// \param enabled True to enable, false to disable
///
////////////////////////////////////////////////////////////
virtual void SetKeyRepeatEnabled(bool enabled);
private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -136,7 +136,7 @@ void WglContext::Display()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WglContext::EnableVerticalSync(bool enabled) void WglContext::SetVerticalSyncEnabled(bool enabled)
{ {
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = reinterpret_cast<PFNWGLSWAPINTERVALEXTPROC>(wglGetProcAddress("wglSwapIntervalEXT")); PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = reinterpret_cast<PFNWGLSWAPINTERVALEXTPROC>(wglGetProcAddress("wglSwapIntervalEXT"));
if (wglSwapIntervalEXT) if (wglSwapIntervalEXT)

View File

@ -107,7 +107,7 @@ public :
/// \param enabled : True to enable v-sync, false to deactivate /// \param enabled : True to enable v-sync, false to deactivate
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void EnableVerticalSync(bool enabled); virtual void SetVerticalSyncEnabled(bool enabled);
private : private :

View File

@ -70,12 +70,6 @@ myIsCursorIn (false)
{ {
if (myHandle) if (myHandle)
{ {
// Get window client size
RECT rectangle;
GetClientRect(myHandle, &rectangle);
myWidth = rectangle.right - rectangle.left;
myHeight = rectangle.bottom - rectangle.top;
// We change the event procedure of the control (it is important to save the old one) // We change the event procedure of the control (it is important to save the old one)
SetWindowLongPtr(myHandle, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); SetWindowLongPtr(myHandle, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
myCallback = SetWindowLongPtr(myHandle, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&WindowImplWin32::GlobalOnEvent)); myCallback = SetWindowLongPtr(myHandle, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&WindowImplWin32::GlobalOnEvent));
@ -100,8 +94,8 @@ myIsCursorIn (false)
HDC screenDC = GetDC(NULL); HDC screenDC = GetDC(NULL);
int left = (GetDeviceCaps(screenDC, HORZRES) - mode.Width) / 2; int left = (GetDeviceCaps(screenDC, HORZRES) - mode.Width) / 2;
int top = (GetDeviceCaps(screenDC, VERTRES) - mode.Height) / 2; int top = (GetDeviceCaps(screenDC, VERTRES) - mode.Height) / 2;
int width = myWidth = mode.Width; int width = mode.Width;
int height = myHeight = mode.Height; int height = mode.Height;
ReleaseDC(NULL, screenDC); ReleaseDC(NULL, screenDC);
// Choose the window style according to the Style parameter // Choose the window style according to the Style parameter
@ -146,13 +140,6 @@ myIsCursorIn (false)
// Increment window count // Increment window count
WindowCount++; WindowCount++;
// Get the actual size of the window, which can be smaller even after the call to AdjustWindowRect
// This happens when the window is bigger than the desktop
RECT actualRectangle;
GetClientRect(myHandle, &actualRectangle);
myWidth = actualRectangle.right - actualRectangle.left;
myHeight = actualRectangle.bottom - actualRectangle.top;
} }
@ -217,33 +204,41 @@ void WindowImplWin32::ProcessEvents()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplWin32::ShowMouseCursor(bool show) Vector2i WindowImplWin32::GetPosition() const
{ {
if (show) RECT rect;
myCursor = LoadCursor(NULL, IDC_ARROW); GetWindowRect(myHandle, &rect);
else
myCursor = NULL;
SetCursor(myCursor); return Vector2i(rect.left, rect.top);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplWin32::SetPosition(int x, int y) void WindowImplWin32::SetPosition(const Vector2i& position)
{ {
SetWindowPos(myHandle, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); SetWindowPos(myHandle, NULL, position.x, position.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplWin32::SetSize(unsigned int width, unsigned int height) Vector2u WindowImplWin32::GetSize() const
{
RECT rect;
GetClientRect(myHandle, &rect);
return Vector2u(rect.right - rect.left, rect.bottom - rect.top);
}
////////////////////////////////////////////////////////////
void WindowImplWin32::SetSize(const Vector2u& size)
{ {
// SetWindowPos wants the total size of the window (including title bar and borders), // SetWindowPos wants the total size of the window (including title bar and borders),
// so we have to compute it // so we have to compute it
RECT rectangle = {0, 0, width, height}; RECT rectangle = {0, 0, size.x, size.y};
AdjustWindowRect(&rectangle, GetWindowLong(myHandle, GWL_STYLE), false); AdjustWindowRect(&rectangle, GetWindowLong(myHandle, GWL_STYLE), false);
width = rectangle.right - rectangle.left; int width = rectangle.right - rectangle.left;
height = rectangle.bottom - rectangle.top; int height = rectangle.bottom - rectangle.top;
SetWindowPos(myHandle, NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER); SetWindowPos(myHandle, NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);
} }
@ -256,20 +251,6 @@ void WindowImplWin32::SetTitle(const std::string& title)
} }
////////////////////////////////////////////////////////////
void WindowImplWin32::Show(bool show)
{
ShowWindow(myHandle, show ? SW_SHOW : SW_HIDE);
}
////////////////////////////////////////////////////////////
void WindowImplWin32::EnableKeyRepeat(bool enabled)
{
myKeyRepeatEnabled = enabled;
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplWin32::SetIcon(unsigned int width, unsigned int height, const Uint8* pixels) void WindowImplWin32::SetIcon(unsigned int width, unsigned int height, const Uint8* pixels)
{ {
@ -277,7 +258,7 @@ void WindowImplWin32::SetIcon(unsigned int width, unsigned int height, const Uin
if (myIcon) if (myIcon)
DestroyIcon(myIcon); DestroyIcon(myIcon);
// Windows wants BGRA pixels : swap red and blue channels // Windows wants BGRA pixels: swap red and blue channels
std::vector<Uint8> iconPixels(width * height * 4); std::vector<Uint8> iconPixels(width * height * 4);
for (std::size_t i = 0; i < iconPixels.size() / 4; ++i) for (std::size_t i = 0; i < iconPixels.size() / 4; ++i)
{ {
@ -303,6 +284,32 @@ void WindowImplWin32::SetIcon(unsigned int width, unsigned int height, const Uin
} }
////////////////////////////////////////////////////////////
void WindowImplWin32::SetVisible(bool visible)
{
ShowWindow(myHandle, visible ? SW_SHOW : SW_HIDE);
}
////////////////////////////////////////////////////////////
void WindowImplWin32::SetMouseCursorVisible(bool visible)
{
if (visible)
myCursor = LoadCursor(NULL, IDC_ARROW);
else
myCursor = NULL;
SetCursor(myCursor);
}
////////////////////////////////////////////////////////////
void WindowImplWin32::SetKeyRepeatEnabled(bool enabled)
{
myKeyRepeatEnabled = enabled;
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplWin32::RegisterWindowClass() void WindowImplWin32::RegisterWindowClass()
{ {
@ -380,7 +387,7 @@ void WindowImplWin32::Cleanup()
} }
// Unhide the mouse cursor (in case it was hidden) // Unhide the mouse cursor (in case it was hidden)
ShowMouseCursor(true); SetMouseCursorVisible(true);
} }
@ -426,16 +433,14 @@ void WindowImplWin32::ProcessEvent(UINT message, WPARAM wParam, LPARAM lParam)
// Ignore size events triggered by a minimize (size == 0 in this case) // Ignore size events triggered by a minimize (size == 0 in this case)
if (wParam != SIZE_MINIMIZED) if (wParam != SIZE_MINIMIZED)
{ {
// Update window size // Get the new size
RECT rectangle; RECT rectangle;
GetClientRect(myHandle, &rectangle); GetClientRect(myHandle, &rectangle);
myWidth = rectangle.right - rectangle.left;
myHeight = rectangle.bottom - rectangle.top;
Event event; Event event;
event.Type = Event::Resized; event.Type = Event::Resized;
event.Size.Width = myWidth; event.Size.Width = rectangle.right - rectangle.left;
event.Size.Height = myHeight; event.Size.Height = rectangle.bottom - rectangle.top;
PushEvent(event); PushEvent(event);
break; break;
} }

View File

@ -87,30 +87,36 @@ private :
virtual void ProcessEvents(); virtual void ProcessEvents();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Show or hide the mouse cursor /// \brief Get the position of the window
/// ///
/// \param show True to show, false to hide /// \return Position of the window, in pixels
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void ShowMouseCursor(bool show); virtual Vector2i GetPosition() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the position of the window on screen /// \brief Change the position of the window on screen
/// ///
/// \param x Left position /// \param position New position of the window, in pixels
/// \param y Top position
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetPosition(int x, int y); virtual void SetPosition(const Vector2i& position);
////////////////////////////////////////////////////////////
/// \brief Get the client size of the window
///
/// \return Size of the window, in pixels
///
////////////////////////////////////////////////////////////
virtual Vector2u GetSize() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the size of the rendering region of the window /// \brief Change the size of the rendering region of the window
/// ///
/// \param width New width /// \param size New size, in pixels
/// \param height New height
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetSize(unsigned int width, unsigned int height); virtual void SetSize(const Vector2u& size);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the title of the window /// \brief Change the title of the window
@ -120,22 +126,6 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetTitle(const std::string& title); virtual void SetTitle(const std::string& title);
////////////////////////////////////////////////////////////
/// \brief Show or hide the window
///
/// \param show True to show, false to hide
///
////////////////////////////////////////////////////////////
virtual void Show(bool show);
////////////////////////////////////////////////////////////
/// \brief Enable or disable automatic key-repeat
///
/// \param enabled True to enable, false to disable
///
////////////////////////////////////////////////////////////
virtual void EnableKeyRepeat(bool enabled);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the window's icon /// \brief Change the window's icon
/// ///
@ -146,6 +136,32 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels); virtual void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels);
////////////////////////////////////////////////////////////
/// \brief Show or hide the window
///
/// \param visible True to show, false to hide
///
////////////////////////////////////////////////////////////
virtual void SetVisible(bool visible);
////////////////////////////////////////////////////////////
/// \brief Show or hide the mouse cursor
///
/// \param visible True to show, false to hide
///
////////////////////////////////////////////////////////////
virtual void SetMouseCursorVisible(bool visible);
////////////////////////////////////////////////////////////
/// \brief Enable or disable automatic key-repeat
///
/// \param enabled True to enable, false to disable
///
////////////////////////////////////////////////////////////
virtual void SetKeyRepeatEnabled(bool enabled);
private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Register the window class /// Register the window class
/// ///

View File

@ -168,20 +168,6 @@ bool Window::IsOpen() const
} }
////////////////////////////////////////////////////////////
unsigned int Window::GetWidth() const
{
return myImpl ? myImpl->GetWidth() : 0;
}
////////////////////////////////////////////////////////////
unsigned int Window::GetHeight() const
{
return myImpl ? myImpl->GetHeight() : 0;
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const ContextSettings& Window::GetSettings() const const ContextSettings& Window::GetSettings() const
{ {
@ -220,34 +206,32 @@ bool Window::WaitEvent(Event& event)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Window::EnableVerticalSync(bool enabled) Vector2i Window::GetPosition() const
{ {
if (SetActive()) return myImpl ? myImpl->GetPosition() : Vector2i();
myContext->EnableVerticalSync(enabled);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Window::ShowMouseCursor(bool show) void Window::SetPosition(const Vector2i& position)
{ {
if (myImpl) if (myImpl)
myImpl->ShowMouseCursor(show); myImpl->SetPosition(position);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Window::SetPosition(int x, int y) Vector2u Window::GetSize() const
{ {
if (myImpl) return myImpl ? myImpl->GetSize() : Vector2u();
myImpl->SetPosition(x, y);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Window::SetSize(unsigned int width, unsigned int height) void Window::SetSize(const Vector2u size)
{ {
if (myImpl) if (myImpl)
myImpl->SetSize(width, height); myImpl->SetSize(size);
} }
@ -259,22 +243,6 @@ void Window::SetTitle(const std::string& title)
} }
////////////////////////////////////////////////////////////
void Window::Show(bool show)
{
if (myImpl)
myImpl->Show(show);
}
////////////////////////////////////////////////////////////
void Window::EnableKeyRepeat(bool enabled)
{
if (myImpl)
myImpl->EnableKeyRepeat(enabled);
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Window::SetIcon(unsigned int width, unsigned int height, const Uint8* pixels) void Window::SetIcon(unsigned int width, unsigned int height, const Uint8* pixels)
{ {
@ -283,6 +251,56 @@ void Window::SetIcon(unsigned int width, unsigned int height, const Uint8* pixel
} }
////////////////////////////////////////////////////////////
void Window::SetVisible(bool visible)
{
if (myImpl)
myImpl->SetVisible(visible);
}
////////////////////////////////////////////////////////////
void Window::SetVerticalSyncEnabled(bool enabled)
{
if (SetActive())
myContext->SetVerticalSyncEnabled(enabled);
}
////////////////////////////////////////////////////////////
void Window::SetMouseCursorVisible(bool visible)
{
if (myImpl)
myImpl->SetMouseCursorVisible(visible);
}
////////////////////////////////////////////////////////////
void Window::SetKeyRepeatEnabled(bool enabled)
{
if (myImpl)
myImpl->SetKeyRepeatEnabled(enabled);
}
////////////////////////////////////////////////////////////
void Window::SetFramerateLimit(unsigned int limit)
{
if (limit > 0)
myFrameTimeLimit = Seconds(1.f / limit);
else
myFrameTimeLimit = Time::Zero;
}
////////////////////////////////////////////////////////////
void Window::SetJoystickThreshold(float threshold)
{
if (myImpl)
myImpl->SetJoystickThreshold(threshold);
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Window::SetActive(bool active) const bool Window::SetActive(bool active) const
{ {
@ -321,24 +339,6 @@ void Window::Display()
} }
////////////////////////////////////////////////////////////
void Window::SetFramerateLimit(unsigned int limit)
{
if (limit > 0)
myFrameTimeLimit = Seconds(1.f / limit);
else
myFrameTimeLimit = Time::Zero;
}
////////////////////////////////////////////////////////////
void Window::SetJoystickThreshold(float threshold)
{
if (myImpl)
myImpl->SetJoystickThreshold(threshold);
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
WindowHandle Window::GetSystemHandle() const WindowHandle Window::GetSystemHandle() const
{ {
@ -375,10 +375,10 @@ bool Window::FilterEvent(const Event& event)
void Window::Initialize() void Window::Initialize()
{ {
// Setup default behaviours (to get a consistent behaviour across different implementations) // Setup default behaviours (to get a consistent behaviour across different implementations)
Show(true); SetVisible(true);
ShowMouseCursor(true); SetMouseCursorVisible(true);
EnableVerticalSync(false); SetVerticalSyncEnabled(false);
EnableKeyRepeat(true); SetKeyRepeatEnabled(true);
// Reset frame time // Reset frame time
myClock.Restart(); myClock.Restart();

View File

@ -70,8 +70,6 @@ WindowImpl* WindowImpl::Create(WindowHandle handle)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
WindowImpl::WindowImpl() : WindowImpl::WindowImpl() :
myWidth (0),
myHeight (0),
myJoyThreshold(0.1f) myJoyThreshold(0.1f)
{ {
// Get the initial joystick states // Get the initial joystick states
@ -88,20 +86,6 @@ WindowImpl::~WindowImpl()
} }
////////////////////////////////////////////////////////////
unsigned int WindowImpl::GetWidth() const
{
return myWidth;
}
////////////////////////////////////////////////////////////
unsigned int WindowImpl::GetHeight() const
{
return myHeight;
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImpl::SetJoystickThreshold(float threshold) void WindowImpl::SetJoystickThreshold(float threshold)
{ {

View File

@ -84,22 +84,6 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual ~WindowImpl(); virtual ~WindowImpl();
////////////////////////////////////////////////////////////
/// \brief Get the client width of the window
///
/// \return Width of the window in pixels
///
////////////////////////////////////////////////////////////
unsigned int GetWidth() const;
////////////////////////////////////////////////////////////
/// \brief Get the client height of the window
///
/// \return Height of the window in pixels
///
////////////////////////////////////////////////////////////
unsigned int GetHeight() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the joystick threshold, ie. the value below which /// \brief Change the joystick threshold, ie. the value below which
/// no move event will be generated /// no move event will be generated
@ -134,30 +118,36 @@ public :
virtual WindowHandle GetSystemHandle() const = 0; virtual WindowHandle GetSystemHandle() const = 0;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Show or hide the mouse cursor /// \brief Get the position of the window
/// ///
/// \param show True to show, false to hide /// \return Position of the window, in pixels
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void ShowMouseCursor(bool show) = 0; virtual Vector2i GetPosition() const = 0;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the position of the window on screen /// \brief Change the position of the window on screen
/// ///
/// \param x Left position /// \param position New position of the window, in pixels
/// \param y Top position
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetPosition(int x, int y) = 0; virtual void SetPosition(const Vector2i& position) = 0;
////////////////////////////////////////////////////////////
/// \brief Get the client size of the window
///
/// \return Size of the window, in pixels
///
////////////////////////////////////////////////////////////
virtual Vector2u GetSize() const = 0;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the size of the rendering region of the window /// \brief Change the size of the rendering region of the window
/// ///
/// \param width New width, in pixels /// \param size New size, in pixels
/// \param height New height, in pixels
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetSize(unsigned int width, unsigned int height) = 0; virtual void SetSize(const Vector2u& size) = 0;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the title of the window /// \brief Change the title of the window
@ -167,22 +157,6 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetTitle(const std::string& title) = 0; virtual void SetTitle(const std::string& title) = 0;
////////////////////////////////////////////////////////////
/// \brief Show or hide the window
///
/// \param show True to show, false to hide
///
////////////////////////////////////////////////////////////
virtual void Show(bool show) = 0;
////////////////////////////////////////////////////////////
/// \brief Enable or disable automatic key-repeat
///
/// \param enabled True to enable, false to disable
///
////////////////////////////////////////////////////////////
virtual void EnableKeyRepeat(bool enabled) = 0;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the window's icon /// \brief Change the window's icon
/// ///
@ -193,6 +167,30 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels) = 0; virtual void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels) = 0;
////////////////////////////////////////////////////////////
/// \brief Show or hide the window
///
/// \param visible True to show, false to hide
///
////////////////////////////////////////////////////////////
virtual void SetVisible(bool visible) = 0;
////////////////////////////////////////////////////////////
/// \brief Show or hide the mouse cursor
///
/// \param visible True to show, false to hide
///
////////////////////////////////////////////////////////////
virtual void SetMouseCursorVisible(bool visible) = 0;
////////////////////////////////////////////////////////////
/// \brief Enable or disable automatic key-repeat
///
/// \param enabled True to enable, false to disable
///
////////////////////////////////////////////////////////////
virtual void SetKeyRepeatEnabled(bool enabled) = 0;
protected : protected :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -213,12 +211,6 @@ protected :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void PushEvent(const Event& event); void PushEvent(const Event& event);
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
unsigned int myWidth; ///< Internal width of the window
unsigned int myHeight; ///< Internal height of the window
private : private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////