mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Added Window::GetPosition, and renamed some setters in Window for better consistency
This commit is contained in:
parent
90854907b5
commit
15e9d999b3
@ -5,6 +5,7 @@
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/OpenGL.hpp>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
@ -15,7 +16,7 @@ int main()
|
||||
{
|
||||
// Create the main window
|
||||
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
|
||||
sf::Texture backgroundTexture;
|
||||
@ -90,8 +91,8 @@ int main()
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// 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 y = -sf::Mouse::GetPosition(window).y * 200.f / window.GetHeight() + 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.GetSize().y + 100.f;
|
||||
|
||||
// Apply some transformations
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
@ -28,7 +28,7 @@ int main()
|
||||
|
||||
// Create the window of the application
|
||||
sf::RenderWindow window(sf::VideoMode(gameWidth, gameHeight, 32), "SFML Pong");
|
||||
window.EnableVerticalSync(true);
|
||||
window.SetVerticalSyncEnabled(true);
|
||||
|
||||
// Load the sounds used in the game
|
||||
sf::SoundBuffer ballSoundBuffer;
|
||||
|
@ -265,7 +265,7 @@ int main()
|
||||
{
|
||||
// Create the main window
|
||||
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader");
|
||||
window.EnableVerticalSync(true);
|
||||
window.SetVerticalSyncEnabled(true);
|
||||
|
||||
// Create the effects
|
||||
std::vector<Effect*> effects;
|
||||
@ -348,8 +348,8 @@ int main()
|
||||
}
|
||||
|
||||
// Update the current example
|
||||
float x = static_cast<float>(sf::Mouse::GetPosition(window).x) / window.GetWidth();
|
||||
float y = static_cast<float>(sf::Mouse::GetPosition(window).y) / window.GetHeight();
|
||||
float x = static_cast<float>(sf::Mouse::GetPosition(window).x) / window.GetSize().x;
|
||||
float y = static_cast<float>(sf::Mouse::GetPosition(window).y) / window.GetSize().y;
|
||||
effects[current]->Update(clock.GetElapsedTime().AsSeconds(), x, y);
|
||||
|
||||
// Clear the window
|
||||
|
@ -200,24 +200,14 @@ public :
|
||||
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
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual unsigned int GetWidth() 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;
|
||||
virtual Vector2u GetSize() const = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Save the current OpenGL render states and matrices
|
||||
|
@ -137,30 +137,15 @@ public :
|
||||
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 Create function.
|
||||
///
|
||||
/// \return Width in pixels
|
||||
///
|
||||
/// \return GetHeight
|
||||
/// \return Size in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual unsigned int GetWidth() 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;
|
||||
virtual Vector2u GetSize() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a read-only reference to the target texture
|
||||
|
@ -101,30 +101,15 @@ public :
|
||||
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.
|
||||
///
|
||||
/// \return Width in pixels
|
||||
///
|
||||
/// \see GetHeight
|
||||
/// \return Size in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual unsigned int GetWidth() 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;
|
||||
virtual Vector2u GetSize() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy the current contents of the window to an image
|
||||
|
@ -153,42 +153,17 @@ public :
|
||||
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.
|
||||
/// 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;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \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
|
||||
///
|
||||
@ -255,29 +230,14 @@ public :
|
||||
bool WaitEvent(Event& event);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enable or disable vertical synchronization
|
||||
/// \brief Get the position of the window
|
||||
///
|
||||
/// Activating vertical synchronization will limit the number
|
||||
/// of frames displayed to the refresh rate of the monitor.
|
||||
/// This can avoid some visual artifacts, and limit the framerate
|
||||
/// to a good value (but not constant across different computers).
|
||||
/// \return Position of the window, in pixels
|
||||
///
|
||||
/// Vertical synchronization is disabled by default.
|
||||
///
|
||||
/// \param enabled True to enable v-sync, false to deactivate
|
||||
/// \see SetPosition
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void EnableVerticalSync(bool enabled);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \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);
|
||||
Vector2i GetPosition() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the position of the window on screen
|
||||
@ -286,53 +246,46 @@ public :
|
||||
/// (i.e. it will be ignored for windows created from
|
||||
/// the handle of a child window/control).
|
||||
///
|
||||
/// \param x Left position
|
||||
/// \param y Top position
|
||||
/// \param position New position, in pixels
|
||||
///
|
||||
/// \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
|
||||
///
|
||||
/// \param width New width, in pixels
|
||||
/// \param height New height, in pixels
|
||||
/// \param size New size, in pixels
|
||||
///
|
||||
/// \see GetSize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SetSize(unsigned int width, unsigned int height);
|
||||
void SetSize(const Vector2u size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the title of the window
|
||||
///
|
||||
/// \param title New title
|
||||
///
|
||||
/// \see SetIcon
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
@ -345,36 +298,59 @@ public :
|
||||
/// \param height Icon's height, in pixels
|
||||
/// \param pixels Pointer to the array of pixels in memory
|
||||
///
|
||||
/// \see SetTitle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Activate or deactivate the window as the current target
|
||||
/// for OpenGL rendering
|
||||
/// \brief Show or hide the window
|
||||
///
|
||||
/// 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.
|
||||
/// The window is shown by default.
|
||||
///
|
||||
/// \param active True to activate, false to deactivate
|
||||
///
|
||||
/// \return True if operation was successful, false otherwise
|
||||
/// \param visible True to show the window, false to hide it
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SetActive(bool active = true) const;
|
||||
void SetVisible(bool visible);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Display on screen what has been rendered to the
|
||||
/// window so far
|
||||
/// \brief Enable or disable vertical synchronization
|
||||
///
|
||||
/// This function is typically called after all OpenGL rendering
|
||||
/// has been done for the current frame, in order to show
|
||||
/// it on screen.
|
||||
/// Activating vertical synchronization will limit the number
|
||||
/// of frames displayed to the refresh rate of the monitor.
|
||||
/// This can avoid some visual artifacts, and limit the framerate
|
||||
/// to a good value (but not constant across different computers).
|
||||
///
|
||||
/// Vertical synchronization is disabled by default.
|
||||
///
|
||||
/// \param enabled True to enable v-sync, false to deactivate it
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void 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
|
||||
@ -406,6 +382,33 @@ public :
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
|
@ -87,8 +87,8 @@ const View& RenderTarget::GetDefaultView() const
|
||||
////////////////////////////////////////////////////////////
|
||||
IntRect RenderTarget::GetViewport(const View& view) const
|
||||
{
|
||||
float width = static_cast<float>(GetWidth());
|
||||
float height = static_cast<float>(GetHeight());
|
||||
float width = static_cast<float>(GetSize().x);
|
||||
float height = static_cast<float>(GetSize().y);
|
||||
const FloatRect& viewport = view.GetViewport();
|
||||
|
||||
return IntRect(static_cast<int>(0.5f + width * viewport.Left),
|
||||
@ -284,7 +284,7 @@ void RenderTarget::ResetGLStates()
|
||||
void RenderTarget::Initialize()
|
||||
{
|
||||
// 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;
|
||||
|
||||
// Initialize the default OpenGL render-states
|
||||
@ -297,7 +297,7 @@ void RenderTarget::ApplyCurrentView()
|
||||
{
|
||||
// Set the viewport
|
||||
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));
|
||||
|
||||
// Set the projection matrix
|
||||
|
@ -119,16 +119,9 @@ void RenderTexture::Display()
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int RenderTexture::GetWidth() const
|
||||
Vector2u RenderTexture::GetSize() const
|
||||
{
|
||||
return myTexture.GetWidth();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int RenderTexture::GetHeight() const
|
||||
{
|
||||
return myTexture.GetHeight();
|
||||
return Vector2u(myTexture.GetWidth(), myTexture.GetHeight());
|
||||
}
|
||||
|
||||
|
||||
|
@ -69,16 +69,9 @@ bool RenderWindow::Activate(bool active)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int RenderWindow::GetWidth() const
|
||||
Vector2u RenderWindow::GetSize() const
|
||||
{
|
||||
return Window::GetWidth();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int RenderWindow::GetHeight() const
|
||||
{
|
||||
return Window::GetHeight();
|
||||
return Window::GetSize();
|
||||
}
|
||||
|
||||
|
||||
@ -88,8 +81,8 @@ Image RenderWindow::Capture() const
|
||||
Image image;
|
||||
if (SetActive())
|
||||
{
|
||||
int width = static_cast<int>(GetWidth());
|
||||
int height = static_cast<int>(GetHeight());
|
||||
int width = static_cast<int>(GetSize().x);
|
||||
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)
|
||||
std::vector<Uint8> pixels(width * height * 4);
|
||||
|
@ -369,8 +369,8 @@ void Texture::Update(const Window& window)
|
||||
////////////////////////////////////////////////////////////
|
||||
void Texture::Update(const Window& window, unsigned int x, unsigned int y)
|
||||
{
|
||||
assert(x + window.GetWidth() <= myWidth);
|
||||
assert(y + window.GetHeight() <= myHeight);
|
||||
assert(x + window.GetSize().x <= myWidth);
|
||||
assert(y + window.GetSize().y <= myHeight);
|
||||
|
||||
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
|
||||
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;
|
||||
myCacheId = GetUniqueId();
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ public :
|
||||
/// \param enabled True to enable v-sync, false to deactivate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void EnableVerticalSync(bool enabled) = 0;
|
||||
virtual void SetVerticalSyncEnabled(bool enabled) = 0;
|
||||
|
||||
protected :
|
||||
|
||||
|
@ -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");
|
||||
PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = reinterpret_cast<PFNGLXSWAPINTERVALSGIPROC>(glXGetProcAddress(name));
|
||||
|
@ -107,7 +107,7 @@ public :
|
||||
/// \param enabled : True to enable v-sync, false to deactivate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void EnableVerticalSync(bool enabled);
|
||||
virtual void SetVerticalSyncEnabled(bool enabled);
|
||||
|
||||
private :
|
||||
|
||||
|
@ -80,16 +80,6 @@ myKeyRepeat (true)
|
||||
|
||||
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
|
||||
XSelectInput(myDisplay, myWindow, eventMask & ~ButtonPressMask);
|
||||
|
||||
@ -127,8 +117,8 @@ myKeyRepeat (true)
|
||||
left = 0;
|
||||
top = 0;
|
||||
}
|
||||
int width = myWidth = mode.Width;
|
||||
int height = myHeight = mode.Height;
|
||||
int width = mode.Width;
|
||||
int height = mode.Height;
|
||||
|
||||
// Switch to fullscreen if necessary
|
||||
if (fullscreen)
|
||||
@ -243,7 +233,7 @@ myKeyRepeat (true)
|
||||
WindowImplX11::~WindowImplX11()
|
||||
{
|
||||
// Cleanup graphical resources
|
||||
CleanUp();
|
||||
Cleanup();
|
||||
|
||||
// Destroy the cursor
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplX11::SetPosition(int x, int y)
|
||||
Vector2u WindowImplX11::GetSize() const
|
||||
{
|
||||
XMoveWindow(myDisplay, myWindow, x, y);
|
||||
XFlush(myDisplay);
|
||||
XWindowAttributes attributes;
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
@ -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)
|
||||
{
|
||||
@ -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)
|
||||
if (fullscreenWindow == this)
|
||||
@ -542,7 +550,7 @@ void WindowImplX11::CleanUp()
|
||||
}
|
||||
|
||||
// Unhide the mouse cursor (in case it was hidden)
|
||||
ShowMouseCursor(true);
|
||||
SetMouseCursorVisible(true);
|
||||
}
|
||||
|
||||
|
||||
@ -595,7 +603,7 @@ bool WindowImplX11::ProcessEvent(XEvent windowEvent)
|
||||
case DestroyNotify :
|
||||
{
|
||||
// The window is about to be destroyed : we must cleanup resources
|
||||
CleanUp();
|
||||
Cleanup();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -628,17 +636,11 @@ bool WindowImplX11::ProcessEvent(XEvent windowEvent)
|
||||
// Resize event
|
||||
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.Type = Event::Resized;
|
||||
event.Size.Width = myWidth;
|
||||
event.Size.Height = myHeight;
|
||||
PushEvent(event);
|
||||
}
|
||||
Event event;
|
||||
event.Type = Event::Resized;
|
||||
event.Size.Width = windowEvent.xconfigure.width;
|
||||
event.Size.Height = windowEvent.xconfigure.height;
|
||||
PushEvent(event);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -98,30 +98,36 @@ private :
|
||||
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
|
||||
///
|
||||
/// \param x Left position
|
||||
/// \param y Top position
|
||||
/// \param position New position of the window, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
/// \param width New width
|
||||
/// \param height New height
|
||||
/// \param size New size, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetSize(unsigned int width, unsigned int height);
|
||||
virtual void SetSize(const Vector2u& size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the title of the window
|
||||
@ -131,22 +137,6 @@ private :
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
@ -157,6 +147,32 @@ private :
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
@ -181,7 +197,7 @@ private :
|
||||
/// \brief Cleanup graphical resources attached to the window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void CleanUp();
|
||||
void Cleanup();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Process an incoming event from the window
|
||||
|
@ -120,7 +120,7 @@ public:
|
||||
/// \param enabled : True to enable v-sync, false to deactivate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void EnableVerticalSync(bool enabled);
|
||||
virtual void SetVerticalSyncEnabled(bool enabled);
|
||||
|
||||
protected:
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -124,7 +124,7 @@ void SFContext::Display()
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SFContext::EnableVerticalSync(bool enabled)
|
||||
void SFContext::SetVerticalSyncEnabled(bool enabled)
|
||||
{
|
||||
// Make compiler happy
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
|
||||
|
@ -249,31 +249,37 @@ private:
|
||||
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
|
||||
///
|
||||
/// \param x Left position
|
||||
/// \param y Top position
|
||||
/// \param position New position of the window, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
/// \param width New width
|
||||
/// \param height New height
|
||||
/// \param size New size, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetSize(unsigned int width, unsigned int height);
|
||||
|
||||
virtual void SetSize(const Vector2u& size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the title of the window
|
||||
///
|
||||
@ -281,23 +287,7 @@ private:
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
@ -307,7 +297,33 @@ private:
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -136,7 +136,7 @@ void WglContext::Display()
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WglContext::EnableVerticalSync(bool enabled)
|
||||
void WglContext::SetVerticalSyncEnabled(bool enabled)
|
||||
{
|
||||
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = reinterpret_cast<PFNWGLSWAPINTERVALEXTPROC>(wglGetProcAddress("wglSwapIntervalEXT"));
|
||||
if (wglSwapIntervalEXT)
|
||||
|
@ -107,7 +107,7 @@ public :
|
||||
/// \param enabled : True to enable v-sync, false to deactivate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void EnableVerticalSync(bool enabled);
|
||||
virtual void SetVerticalSyncEnabled(bool enabled);
|
||||
|
||||
private :
|
||||
|
||||
|
@ -70,12 +70,6 @@ myIsCursorIn (false)
|
||||
{
|
||||
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)
|
||||
SetWindowLongPtr(myHandle, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
|
||||
myCallback = SetWindowLongPtr(myHandle, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&WindowImplWin32::GlobalOnEvent));
|
||||
@ -100,8 +94,8 @@ myIsCursorIn (false)
|
||||
HDC screenDC = GetDC(NULL);
|
||||
int left = (GetDeviceCaps(screenDC, HORZRES) - mode.Width) / 2;
|
||||
int top = (GetDeviceCaps(screenDC, VERTRES) - mode.Height) / 2;
|
||||
int width = myWidth = mode.Width;
|
||||
int height = myHeight = mode.Height;
|
||||
int width = mode.Width;
|
||||
int height = mode.Height;
|
||||
ReleaseDC(NULL, screenDC);
|
||||
|
||||
// Choose the window style according to the Style parameter
|
||||
@ -146,13 +140,6 @@ myIsCursorIn (false)
|
||||
|
||||
// Increment window count
|
||||
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)
|
||||
myCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
else
|
||||
myCursor = NULL;
|
||||
RECT rect;
|
||||
GetWindowRect(myHandle, &rect);
|
||||
|
||||
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),
|
||||
// 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);
|
||||
width = rectangle.right - rectangle.left;
|
||||
height = rectangle.bottom - rectangle.top;
|
||||
int width = rectangle.right - rectangle.left;
|
||||
int height = rectangle.bottom - rectangle.top;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -277,7 +258,7 @@ void WindowImplWin32::SetIcon(unsigned int width, unsigned int height, const Uin
|
||||
if (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);
|
||||
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()
|
||||
{
|
||||
@ -380,7 +387,7 @@ void WindowImplWin32::Cleanup()
|
||||
}
|
||||
|
||||
// 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)
|
||||
if (wParam != SIZE_MINIMIZED)
|
||||
{
|
||||
// Update window size
|
||||
// Get the new size
|
||||
RECT rectangle;
|
||||
GetClientRect(myHandle, &rectangle);
|
||||
myWidth = rectangle.right - rectangle.left;
|
||||
myHeight = rectangle.bottom - rectangle.top;
|
||||
|
||||
Event event;
|
||||
event.Type = Event::Resized;
|
||||
event.Size.Width = myWidth;
|
||||
event.Size.Height = myHeight;
|
||||
event.Size.Width = rectangle.right - rectangle.left;
|
||||
event.Size.Height = rectangle.bottom - rectangle.top;
|
||||
PushEvent(event);
|
||||
break;
|
||||
}
|
||||
|
@ -87,30 +87,36 @@ private :
|
||||
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
|
||||
///
|
||||
/// \param x Left position
|
||||
/// \param y Top position
|
||||
/// \param position New position of the window, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
/// \param width New width
|
||||
/// \param height New height
|
||||
/// \param size New size, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetSize(unsigned int width, unsigned int height);
|
||||
virtual void SetSize(const Vector2u& size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the title of the window
|
||||
@ -120,22 +126,6 @@ private :
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
@ -146,6 +136,32 @@ private :
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
|
@ -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
|
||||
{
|
||||
@ -220,34 +206,32 @@ bool Window::WaitEvent(Event& event)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::EnableVerticalSync(bool enabled)
|
||||
Vector2i Window::GetPosition() const
|
||||
{
|
||||
if (SetActive())
|
||||
myContext->EnableVerticalSync(enabled);
|
||||
return myImpl ? myImpl->GetPosition() : Vector2i();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::ShowMouseCursor(bool show)
|
||||
void Window::SetPosition(const Vector2i& position)
|
||||
{
|
||||
if (myImpl)
|
||||
myImpl->ShowMouseCursor(show);
|
||||
myImpl->SetPosition(position);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::SetPosition(int x, int y)
|
||||
Vector2u Window::GetSize() const
|
||||
{
|
||||
if (myImpl)
|
||||
myImpl->SetPosition(x, y);
|
||||
return myImpl ? myImpl->GetSize() : Vector2u();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::SetSize(unsigned int width, unsigned int height)
|
||||
void Window::SetSize(const Vector2u size)
|
||||
{
|
||||
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)
|
||||
{
|
||||
@ -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
|
||||
{
|
||||
@ -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
|
||||
{
|
||||
@ -375,10 +375,10 @@ bool Window::FilterEvent(const Event& event)
|
||||
void Window::Initialize()
|
||||
{
|
||||
// Setup default behaviours (to get a consistent behaviour across different implementations)
|
||||
Show(true);
|
||||
ShowMouseCursor(true);
|
||||
EnableVerticalSync(false);
|
||||
EnableKeyRepeat(true);
|
||||
SetVisible(true);
|
||||
SetMouseCursorVisible(true);
|
||||
SetVerticalSyncEnabled(false);
|
||||
SetKeyRepeatEnabled(true);
|
||||
|
||||
// Reset frame time
|
||||
myClock.Restart();
|
||||
|
@ -70,8 +70,6 @@ WindowImpl* WindowImpl::Create(WindowHandle handle)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImpl::WindowImpl() :
|
||||
myWidth (0),
|
||||
myHeight (0),
|
||||
myJoyThreshold(0.1f)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
|
@ -84,22 +84,6 @@ public :
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
/// no move event will be generated
|
||||
@ -134,30 +118,36 @@ public :
|
||||
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
|
||||
///
|
||||
/// \param x Left position
|
||||
/// \param y Top position
|
||||
/// \param position New position of the window, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
/// \param width New width, in pixels
|
||||
/// \param height New height, in pixels
|
||||
/// \param size New size, 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
|
||||
@ -167,22 +157,6 @@ public :
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
@ -193,6 +167,30 @@ public :
|
||||
////////////////////////////////////////////////////////////
|
||||
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 :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -213,12 +211,6 @@ protected :
|
||||
////////////////////////////////////////////////////////////
|
||||
void PushEvent(const Event& event);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int myWidth; ///< Internal width of the window
|
||||
unsigned int myHeight; ///< Internal height of the window
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user