FS#65 - Add a blocking WaitEvent function
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1247 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
fd91756a9e
commit
a68ff5713b
28 changed files with 457 additions and 275 deletions
|
@ -280,7 +280,7 @@ WindowHandle WindowImplX11::GetHandle() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplX11::ProcessEvents()
|
||||
void WindowImplX11::ProcessEvents(bool block)
|
||||
{
|
||||
// This function implements a workaround to properly discard
|
||||
// repeated key events when necessary. The problem is that the
|
||||
|
|
|
@ -82,81 +82,83 @@ public :
|
|||
::Display* GetDisplay() const;
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the OS-specific handle of the window
|
||||
///
|
||||
/// \return Handle of the window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual WindowHandle GetHandle() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Process incoming events from operating system
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void ProcessEvents();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Show or hide the mouse cursor
|
||||
///
|
||||
/// \param show True to show, false to hide
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void ShowMouseCursor(bool show);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the position of the mouse cursor
|
||||
///
|
||||
/// \param left Left coordinate of the cursor, relative to the window
|
||||
/// \param top Top coordinate of the cursor, relative to the window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetCursorPosition(unsigned int left, unsigned int top);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the position of the window on screen
|
||||
///
|
||||
/// \param left Left position
|
||||
/// \param top Top position
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetPosition(int left, int top);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the size of the rendering region of the window
|
||||
///
|
||||
/// \param width New width
|
||||
/// \param height New height
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetSize(unsigned int width, unsigned int height);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \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
|
||||
///
|
||||
/// \param width Icon's width, in pixels
|
||||
/// \param height Icon's height, in pixels
|
||||
/// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the OS-specific handle of the window
|
||||
///
|
||||
/// \return Handle of the window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual WindowHandle GetHandle() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Process incoming events from the operating system
|
||||
///
|
||||
/// \param block Use true to block the thread until an event arrives
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void ProcessEvents(bool block);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Show or hide the mouse cursor
|
||||
///
|
||||
/// \param show True to show, false to hide
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void ShowMouseCursor(bool show);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the position of the mouse cursor
|
||||
///
|
||||
/// \param left Left coordinate of the cursor, relative to the window
|
||||
/// \param top Top coordinate of the cursor, relative to the window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetCursorPosition(unsigned int left, unsigned int top);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the position of the window on screen
|
||||
///
|
||||
/// \param left Left position
|
||||
/// \param top Top position
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetPosition(int left, int top);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the size of the rendering region of the window
|
||||
///
|
||||
/// \param width New width
|
||||
/// \param height New height
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetSize(unsigned int width, unsigned int height);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \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
|
||||
///
|
||||
/// \param width Icon's width, in pixels
|
||||
/// \param height Icon's height, in pixels
|
||||
/// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Switch to fullscreen mode
|
||||
|
|
|
@ -202,11 +202,14 @@ WindowHandle WindowImplWin32::GetHandle() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplWin32::ProcessEvents()
|
||||
void WindowImplWin32::ProcessEvents(bool block)
|
||||
{
|
||||
// We update the window only if we own it
|
||||
// We process the window events only if we own it
|
||||
if (!myCallback)
|
||||
{
|
||||
if (block)
|
||||
WaitMessage();
|
||||
|
||||
MSG message;
|
||||
while (PeekMessage(&message, myHandle, 0, 0, PM_REMOVE))
|
||||
{
|
||||
|
|
|
@ -81,10 +81,12 @@ private :
|
|||
virtual WindowHandle GetHandle() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Process incoming events from operating system
|
||||
/// \brief Process incoming events from the operating system
|
||||
///
|
||||
/// \param block Use true to block the thread until an event arrives
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void ProcessEvents();
|
||||
virtual void ProcessEvents(bool block);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Show or hide the mouse cursor
|
||||
|
|
|
@ -211,9 +211,29 @@ bool Window::GetEvent(Event& event)
|
|||
{
|
||||
// Let the window implementation process incoming events if the events queue is empty
|
||||
if (myWindow && myEvents.empty())
|
||||
myWindow->DoEvents();
|
||||
myWindow->DoEvents(false);
|
||||
|
||||
// Pop first event of queue, if not empty
|
||||
// Pop the first event of the queue, if it is not empty
|
||||
if (!myEvents.empty())
|
||||
{
|
||||
event = myEvents.front();
|
||||
myEvents.pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Window::WaitEvent(Event& event)
|
||||
{
|
||||
// Let the window implementation process incoming events if the events queue is empty
|
||||
if (myWindow && myEvents.empty())
|
||||
myWindow->DoEvents(true);
|
||||
|
||||
// Pop the first event of the queue, if it is not empty
|
||||
if (!myEvents.empty())
|
||||
{
|
||||
event = myEvents.front();
|
||||
|
|
|
@ -126,13 +126,13 @@ void WindowImpl::SetJoystickThreshold(float threshold)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImpl::DoEvents()
|
||||
void WindowImpl::DoEvents(bool block)
|
||||
{
|
||||
// Read the joysticks state and generate the appropriate events
|
||||
ProcessJoystickEvents();
|
||||
|
||||
// Let the derived class process other events
|
||||
ProcessEvents();
|
||||
ProcessEvents(block);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -124,10 +124,12 @@ public :
|
|||
void SetJoystickThreshold(float threshold);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Process incoming events from operating system
|
||||
/// \brief Process incoming events from the operating system
|
||||
///
|
||||
/// \param block Use true to block the thread until an event arrives
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void DoEvents();
|
||||
void DoEvents(bool block);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the OS-specific handle of the window
|
||||
|
@ -229,10 +231,12 @@ private :
|
|||
void ProcessJoystickEvents();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Process incoming events from operating system
|
||||
/// \brief Process incoming events from the operating system
|
||||
///
|
||||
/// \param block Use true to block the thread until an event arrives
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void ProcessEvents() = 0;
|
||||
virtual void ProcessEvents(bool block) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Total number of joysticks supported
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue