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:
LaurentGom 2009-10-27 11:50:11 +00:00
parent fd91756a9e
commit a68ff5713b
28 changed files with 457 additions and 275 deletions

View File

@ -193,6 +193,7 @@ EXPORTS
sfRenderWindow_GetHeight
sfRenderWindow_GetSettings
sfRenderWindow_GetEvent
sfRenderWindow_WaitEvent
sfRenderWindow_UseVerticalSync
sfRenderWindow_ShowMouseCursor
sfRenderWindow_SetCursorPosition

View File

@ -194,6 +194,7 @@ EXPORTS
sfRenderWindow_GetHeight
sfRenderWindow_GetSettings
sfRenderWindow_GetEvent
sfRenderWindow_WaitEvent
sfRenderWindow_UseVerticalSync
sfRenderWindow_ShowMouseCursor
sfRenderWindow_SetCursorPosition

View File

@ -19,6 +19,7 @@ EXPORTS
sfWindow_GetHeight
sfWindow_GetSettings
sfWindow_GetEvent
sfWindow_WaitEvent
sfWindow_UseVerticalSync
sfWindow_ShowMouseCursor
sfWindow_SetCursorPosition

View File

@ -19,6 +19,7 @@ EXPORTS
sfWindow_GetHeight
sfWindow_GetSettings
sfWindow_GetEvent
sfWindow_WaitEvent
sfWindow_UseVerticalSync
sfWindow_ShowMouseCursor
sfWindow_SetCursorPosition

View File

@ -193,6 +193,7 @@ EXPORTS
sfRenderWindow_GetHeight
sfRenderWindow_GetSettings
sfRenderWindow_GetEvent
sfRenderWindow_WaitEvent
sfRenderWindow_UseVerticalSync
sfRenderWindow_ShowMouseCursor
sfRenderWindow_SetCursorPosition

View File

@ -194,6 +194,7 @@ EXPORTS
sfRenderWindow_GetHeight
sfRenderWindow_GetSettings
sfRenderWindow_GetEvent
sfRenderWindow_WaitEvent
sfRenderWindow_UseVerticalSync
sfRenderWindow_ShowMouseCursor
sfRenderWindow_SetCursorPosition

View File

@ -19,6 +19,7 @@ EXPORTS
sfWindow_GetHeight
sfWindow_GetSettings
sfWindow_GetEvent
sfWindow_WaitEvent
sfWindow_UseVerticalSync
sfWindow_ShowMouseCursor
sfWindow_SetCursorPosition

View File

@ -19,6 +19,7 @@ EXPORTS
sfWindow_GetHeight
sfWindow_GetSettings
sfWindow_GetEvent
sfWindow_WaitEvent
sfWindow_UseVerticalSync
sfWindow_ShowMouseCursor
sfWindow_SetCursorPosition

View File

@ -123,6 +123,17 @@ CSFML_API sfContextSettings sfRenderWindow_GetSettings(sfRenderWindow* renderWin
////////////////////////////////////////////////////////////
CSFML_API sfBool sfRenderWindow_GetEvent(sfRenderWindow* renderWindow, sfEvent* event);
////////////////////////////////////////////////////////////
/// Wait for an event and return it
///
/// \param renderWindow : Renderwindow object
/// \param event : Event to fill
///
/// \return sfFalse if an error occured
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfRenderWindow_WaitEvent(sfRenderWindow* renderWindow, sfEvent* event);
////////////////////////////////////////////////////////////
/// Enable / disable vertical synchronization on a window
///

View File

@ -22,8 +22,8 @@
//
////////////////////////////////////////////////////////////
#ifndef SFML_Shape_H
#define SFML_Shape_H
#ifndef SFML_SHAPE_H
#define SFML_SHAPE_H
////////////////////////////////////////////////////////////
// Headers
@ -451,4 +451,4 @@ CSFML_API void sfShape_SetPointColor(sfShape* shape, unsigned int index, sfColor
CSFML_API void sfShape_SetPointOutlineColor(sfShape* shape, unsigned int index, sfColor color);
#endif // SFML_Shape_H
#endif // SFML_SHAPE_H

View File

@ -145,6 +145,17 @@ CSFML_API sfContextSettings sfWindow_GetSettings(sfWindow* window);
////////////////////////////////////////////////////////////
CSFML_API sfBool sfWindow_GetEvent(sfWindow* window, sfEvent* event);
////////////////////////////////////////////////////////////
/// Wait for an event and return it
///
/// \param window : Window object
/// \param event : Event to fill
///
/// \return sfFalse if an error occured
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfWindow_WaitEvent(sfWindow* window, sfEvent* event);
////////////////////////////////////////////////////////////
/// Enable / disable vertical synchronization on a window
///

View File

@ -0,0 +1,96 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_CONVERTEVENT_H
#define SFML_CONVERTEVENT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Event.hpp>
#include <SFML/Window/Event.h>
////////////////////////////////////////////////////////////
// Define a function to convert a sf::Event ot a sfEvent
////////////////////////////////////////////////////////////
inline void ConvertEvent(const sf::Event& SFMLEvent, sfEvent* event)
{
// Convert its type
event->Type = static_cast<sfEventType>(SFMLEvent.Type);
// Fill its fields
switch (event->Type)
{
case sfEvtResized :
event->Size.Width = SFMLEvent.Size.Width;
event->Size.Height = SFMLEvent.Size.Height;
break;
case sfEvtTextEntered :
event->Text.Unicode = SFMLEvent.Text.Unicode;
break;
case sfEvtKeyReleased :
case sfEvtKeyPressed :
event->Key.Code = static_cast<sfKeyCode>(SFMLEvent.Key.Code);
event->Key.Alt = SFMLEvent.Key.Alt ? sfTrue : sfFalse;
event->Key.Control = SFMLEvent.Key.Control ? sfTrue : sfFalse;
event->Key.Shift = SFMLEvent.Key.Shift ? sfTrue : sfFalse;
break;
case sfEvtMouseWheelMoved :
event->MouseWheel.Delta = SFMLEvent.MouseWheel.Delta;
break;
case sfEvtMouseButtonPressed :
case sfEvtMouseButtonReleased :
event->MouseButton.Button = static_cast<sfMouseButton>(SFMLEvent.MouseButton.Button);
event->MouseButton.X = SFMLEvent.MouseButton.X;
event->MouseButton.Y = SFMLEvent.MouseButton.Y;
break;
case sfEvtMouseMoved :
event->MouseMove.X = SFMLEvent.MouseMove.X;
event->MouseMove.Y = SFMLEvent.MouseMove.Y;
break;
case sfEvtJoyButtonPressed :
case sfEvtJoyButtonReleased :
event->JoyButton.JoystickId = SFMLEvent.JoyButton.JoystickId;
event->JoyButton.Button = SFMLEvent.JoyButton.Button;
break;
case sfEvtJoyMoved :
event->JoyMove.JoystickId = SFMLEvent.JoyMove.JoystickId;
event->JoyMove.Axis = static_cast<sfJoyAxis>(SFMLEvent.JoyMove.Axis);
event->JoyMove.Position = SFMLEvent.JoyMove.Position;
break;
default :
break;
}
}
#endif // SFML_CONVERTEVENT_H

View File

@ -33,6 +33,7 @@
#include <SFML/Graphics/SpriteStruct.h>
#include <SFML/Graphics/StringStruct.h>
#include <SFML/Internal.h>
#include <SFML/ConvertEvent.h>
////////////////////////////////////////////////////////////
@ -150,60 +151,31 @@ sfBool sfRenderWindow_GetEvent(sfRenderWindow* renderWindow, sfEvent* event)
if (!ret)
return sfFalse;
// Convert its type
event->Type = static_cast<sfEventType>(SFMLEvent.Type);
// Convert the sf::Event event to a sfEvent
ConvertEvent(SFMLEvent, event);
// Fill its fields
switch (event->Type)
{
case sfEvtResized :
event->Size.Width = SFMLEvent.Size.Width;
event->Size.Height = SFMLEvent.Size.Height;
break;
return sfTrue;
}
case sfEvtTextEntered :
event->Text.Unicode = SFMLEvent.Text.Unicode;
break;
case sfEvtKeyReleased :
case sfEvtKeyPressed :
event->Key.Code = static_cast<sfKeyCode>(SFMLEvent.Key.Code);
event->Key.Alt = SFMLEvent.Key.Alt ? sfTrue : sfFalse;
event->Key.Control = SFMLEvent.Key.Control ? sfTrue : sfFalse;
event->Key.Shift = SFMLEvent.Key.Shift ? sfTrue : sfFalse;
break;
////////////////////////////////////////////////////////////
/// Wait for an event and return it
////////////////////////////////////////////////////////////
sfBool sfRenderWindow_WaitEvent(sfRenderWindow* renderWindow, sfEvent* event)
{
CSFML_CHECK_RETURN(renderWindow, sfFalse);
CSFML_CHECK_RETURN(event, sfFalse);
case sfEvtMouseWheelMoved :
event->MouseWheel.Delta = SFMLEvent.MouseWheel.Delta;
break;
// Get the event
sf::Event SFMLEvent;
sfBool ret = renderWindow->This.WaitEvent(SFMLEvent);
case sfEvtMouseButtonPressed :
case sfEvtMouseButtonReleased :
event->MouseButton.Button = static_cast<sfMouseButton>(SFMLEvent.MouseButton.Button);
event->MouseButton.X = SFMLEvent.MouseButton.X;
event->MouseButton.Y = SFMLEvent.MouseButton.Y;
break;
// Error, return
if (!ret)
return sfFalse;
case sfEvtMouseMoved :
event->MouseMove.X = SFMLEvent.MouseMove.X;
event->MouseMove.Y = SFMLEvent.MouseMove.Y;
break;
case sfEvtJoyButtonPressed :
case sfEvtJoyButtonReleased :
event->JoyButton.JoystickId = SFMLEvent.JoyButton.JoystickId;
event->JoyButton.Button = SFMLEvent.JoyButton.Button;
break;
case sfEvtJoyMoved :
event->JoyMove.JoystickId = SFMLEvent.JoyMove.JoystickId;
event->JoyMove.Axis = static_cast<sfJoyAxis>(SFMLEvent.JoyMove.Axis);
event->JoyMove.Position = SFMLEvent.JoyMove.Position;
break;
default :
break;
}
// Convert the sf::Event event to a sfEvent
ConvertEvent(SFMLEvent, event);
return sfTrue;
}

View File

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
@ -22,6 +22,8 @@
//
////////////////////////////////////////////////////////////
#ifndef SFML_INTERNAL_H
#define SFML_INTERNAL_H
////////////////////////////////////////////////////////////
// Define macros to check the validity of CSFML objects
@ -102,3 +104,5 @@
#define CSFML_CALL_PTR_RETURN(Object, Function, Default) (void)Default; return (Object->This->Function);
#endif
#endif // SFML_INTERNAL_H

View File

@ -28,6 +28,7 @@
#include <SFML/Window/Window.h>
#include <SFML/Window/WindowStruct.h>
#include <SFML/Internal.h>
#include <SFML/ConvertEvent.h>
////////////////////////////////////////////////////////////
@ -139,60 +140,31 @@ sfBool sfWindow_GetEvent(sfWindow* window, sfEvent* event)
if (!ret)
return sfFalse;
// Convert its type
event->Type = static_cast<sfEventType>(SFMLEvent.Type);
// Convert the sf::Event event to a sfEvent
ConvertEvent(SFMLEvent, event);
// Fill its fields
switch (event->Type)
{
case sfEvtResized :
event->Size.Width = SFMLEvent.Size.Width;
event->Size.Height = SFMLEvent.Size.Height;
break;
return sfTrue;
}
case sfEvtTextEntered :
event->Text.Unicode = SFMLEvent.Text.Unicode;
break;
case sfEvtKeyReleased :
case sfEvtKeyPressed :
event->Key.Code = static_cast<sfKeyCode>(SFMLEvent.Key.Code);
event->Key.Alt = SFMLEvent.Key.Alt ? sfTrue : sfFalse;
event->Key.Control = SFMLEvent.Key.Control ? sfTrue : sfFalse;
event->Key.Shift = SFMLEvent.Key.Shift ? sfTrue : sfFalse;
break;
////////////////////////////////////////////////////////////
/// Wait for an event and return it
////////////////////////////////////////////////////////////
sfBool sfWindow_WaitEvent(sfWindow* window, sfEvent* event)
{
CSFML_CHECK_RETURN(window, sfFalse);
CSFML_CHECK_RETURN(event, sfFalse);
case sfEvtMouseWheelMoved :
event->MouseWheel.Delta = SFMLEvent.MouseWheel.Delta;
break;
// Get the event
sf::Event SFMLEvent;
sfBool ret = window->This.WaitEvent(SFMLEvent);
case sfEvtMouseButtonPressed :
case sfEvtMouseButtonReleased :
event->MouseButton.Button = static_cast<sfMouseButton>(SFMLEvent.MouseButton.Button);
event->MouseButton.X = SFMLEvent.MouseButton.X;
event->MouseButton.Y = SFMLEvent.MouseButton.Y;
break;
// Error, return
if (!ret)
return sfFalse;
case sfEvtMouseMoved :
event->MouseMove.X = SFMLEvent.MouseMove.X;
event->MouseMove.Y = SFMLEvent.MouseMove.Y;
break;
case sfEvtJoyButtonPressed :
case sfEvtJoyButtonReleased :
event->JoyButton.JoystickId = SFMLEvent.JoyButton.JoystickId;
event->JoyButton.Button = SFMLEvent.JoyButton.Button;
break;
case sfEvtJoyMoved :
event->JoyMove.JoystickId = SFMLEvent.JoyMove.JoystickId;
event->JoyMove.Axis = static_cast<sfJoyAxis>(SFMLEvent.JoyMove.Axis);
event->JoyMove.Position = SFMLEvent.JoyMove.Position;
break;
default :
break;
}
// Convert the sf::Event event to a sfEvent
ConvertEvent(SFMLEvent, event);
return sfTrue;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -436,6 +436,18 @@ namespace SFML
return sfRenderWindow_GetEvent(This, out eventToFill);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Internal function to get the next event (blocking)
/// </summary>
/// <param name="eventToFill">Variable to fill with the raw pointer to the event structure</param>
/// <returns>False if any error occured</returns>
////////////////////////////////////////////////////////////
protected override bool WaitEvent(out Event eventToFill)
{
return sfRenderWindow_WaitEvent(This, out eventToFill);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Handle the destruction of the object
@ -487,6 +499,9 @@ namespace SFML
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern bool sfRenderWindow_GetEvent(IntPtr This, out Event Evt);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern bool sfRenderWindow_WaitEvent(IntPtr This, out Event Evt);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderWindow_Clear(IntPtr This, Color ClearColor);

View File

@ -340,97 +340,27 @@ namespace SFML
////////////////////////////////////////////////////////////
/// <summary>
/// Call the event handlers for each pending event.
/// Wait for a new event and dispatch it to the corresponding
/// event handler
/// </summary>
////////////////////////////////////////////////////////////
public void WaitAndDispatchEvents()
{
Event e;
if (WaitEvent(out e))
CallEventHandler(e);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Call the event handlers for each pending event
/// </summary>
////////////////////////////////////////////////////////////
public void DispatchEvents()
{
Event e;
while (GetEvent(out e))
{
switch (e.Type)
{
case EventType.Closed :
if (Closed != null)
Closed(this, EventArgs.Empty);
break;
case EventType.GainedFocus :
if (GainedFocus != null)
GainedFocus(this, EventArgs.Empty);
break;
case EventType.JoyButtonPressed :
if (JoyButtonPressed != null)
JoyButtonPressed(this, new JoyButtonEventArgs(e.JoyButton));
break;
case EventType.JoyButtonReleased :
if (JoyButtonReleased != null)
JoyButtonReleased(this, new JoyButtonEventArgs(e.JoyButton));
break;
case EventType.JoyMoved :
if (JoyMoved != null)
JoyMoved(this, new JoyMoveEventArgs(e.JoyMove));
break;
case EventType.KeyPressed :
if (KeyPressed != null)
KeyPressed(this, new KeyEventArgs(e.Key));
break;
case EventType.KeyReleased :
if (KeyReleased != null)
KeyReleased(this, new KeyEventArgs(e.Key));
break;
case EventType.LostFocus :
if (LostFocus != null)
LostFocus(this, EventArgs.Empty);
break;
case EventType.MouseButtonPressed :
if (MouseButtonPressed != null)
MouseButtonPressed(this, new MouseButtonEventArgs(e.MouseButton));
break;
case EventType.MouseButtonReleased :
if (MouseButtonReleased != null)
MouseButtonReleased(this, new MouseButtonEventArgs(e.MouseButton));
break;
case EventType.MouseEntered :
if (MouseEntered != null)
MouseEntered(this, EventArgs.Empty);
break;
case EventType.MouseLeft :
if (MouseLeft != null)
MouseLeft(this, EventArgs.Empty);
break;
case EventType.MouseMoved :
if (MouseMoved != null)
MouseMoved(this, new MouseMoveEventArgs(e.MouseMove));
break;
case EventType.MouseWheelMoved :
if (MouseWheelMoved != null)
MouseWheelMoved(this, new MouseWheelEventArgs(e.MouseWheel));
break;
case EventType.Resized :
if (Resized != null)
Resized(this, new SizeEventArgs(e.Size));
break;
case EventType.TextEntered :
if (TextEntered != null)
TextEntered(this, new TextEventArgs(e.Text));
break;
}
}
CallEventHandler(e);
}
////////////////////////////////////////////////////////////
@ -448,7 +378,7 @@ namespace SFML
////////////////////////////////////////////////////////////
/// <summary>
/// Internal function to get the next event
/// Internal function to get the next event (non-blocking)
/// </summary>
/// <param name="eventToFill">Variable to fill with the raw pointer to the event structure</param>
/// <returns>True if there was an event, false otherwise</returns>
@ -458,6 +388,18 @@ namespace SFML
return sfWindow_GetEvent(This, out eventToFill);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Internal function to get the next event (blocking)
/// </summary>
/// <param name="eventToFill">Variable to fill with the raw pointer to the event structure</param>
/// <returns>False if any error occured</returns>
////////////////////////////////////////////////////////////
protected virtual bool WaitEvent(out Event eventToFill)
{
return sfWindow_WaitEvent(This, out eventToFill);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Handle the destruction of the object
@ -469,6 +411,98 @@ namespace SFML
sfWindow_Destroy(This);
}
////////////////////////////////////////////////////////////
/// <summary>
/// Call the event handler for the given event
/// </summary>
/// <param name="e">Event to dispatch</param>
////////////////////////////////////////////////////////////
private void CallEventHandler(Event e)
{
switch (e.Type)
{
case EventType.Closed :
if (Closed != null)
Closed(this, EventArgs.Empty);
break;
case EventType.GainedFocus :
if (GainedFocus != null)
GainedFocus(this, EventArgs.Empty);
break;
case EventType.JoyButtonPressed :
if (JoyButtonPressed != null)
JoyButtonPressed(this, new JoyButtonEventArgs(e.JoyButton));
break;
case EventType.JoyButtonReleased :
if (JoyButtonReleased != null)
JoyButtonReleased(this, new JoyButtonEventArgs(e.JoyButton));
break;
case EventType.JoyMoved :
if (JoyMoved != null)
JoyMoved(this, new JoyMoveEventArgs(e.JoyMove));
break;
case EventType.KeyPressed :
if (KeyPressed != null)
KeyPressed(this, new KeyEventArgs(e.Key));
break;
case EventType.KeyReleased :
if (KeyReleased != null)
KeyReleased(this, new KeyEventArgs(e.Key));
break;
case EventType.LostFocus :
if (LostFocus != null)
LostFocus(this, EventArgs.Empty);
break;
case EventType.MouseButtonPressed :
if (MouseButtonPressed != null)
MouseButtonPressed(this, new MouseButtonEventArgs(e.MouseButton));
break;
case EventType.MouseButtonReleased :
if (MouseButtonReleased != null)
MouseButtonReleased(this, new MouseButtonEventArgs(e.MouseButton));
break;
case EventType.MouseEntered :
if (MouseEntered != null)
MouseEntered(this, EventArgs.Empty);
break;
case EventType.MouseLeft :
if (MouseLeft != null)
MouseLeft(this, EventArgs.Empty);
break;
case EventType.MouseMoved :
if (MouseMoved != null)
MouseMoved(this, new MouseMoveEventArgs(e.MouseMove));
break;
case EventType.MouseWheelMoved :
if (MouseWheelMoved != null)
MouseWheelMoved(this, new MouseWheelEventArgs(e.MouseWheel));
break;
case EventType.Resized :
if (Resized != null)
Resized(this, new SizeEventArgs(e.Size));
break;
case EventType.TextEntered :
if (TextEntered != null)
TextEntered(this, new TextEventArgs(e.Text));
break;
}
}
/// <summary>Event handler for the Closed event</summary>
public event EventHandler Closed = null;
@ -541,6 +575,9 @@ namespace SFML
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
static extern bool sfWindow_GetEvent(IntPtr This, out Event Evt);
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
static extern bool sfWindow_WaitEvent(IntPtr This, out Event Evt);
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
static extern void sfWindow_Display(IntPtr This);

View File

@ -192,7 +192,7 @@ public :
////////////////////////////////////////////////////////////
/// \brief Pop the event on top of events stack, if any, and return it
///
/// This function is not blocking, if there's no pending event then
/// This function is not blocking: if there's no pending event then
/// it will return false and leave \a event unmodified.
/// Note that more than event may be present in the events stack,
/// thus you should always call this function in a loop
@ -212,6 +212,31 @@ public :
////////////////////////////////////////////////////////////
bool GetEvent(Event& event);
////////////////////////////////////////////////////////////
/// \brief Wait for an event and return it
///
/// This function is blocking: if there's no pending event then
/// it will wait until an event is received.
/// After this function returns (and no error occured),
/// the \a event object is always valid and filled properly.
/// This function is typically used when you have a thread that
/// is dedicated to events handling: you want to make this thread
/// sleep as long as no new event is received.
/// \code
/// sf::Event event;
/// if (window.WaitEvent(event))
/// {
/// // process event...
/// }
/// \endcode
///
/// \param event Event to be returned
///
/// \return False if any error occured
///
////////////////////////////////////////////////////////////
bool WaitEvent(Event& event);
////////////////////////////////////////////////////////////
/// \brief Enable or disable vertical synchronization
///

View File

@ -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

View File

@ -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

View File

@ -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))
{

View File

@ -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

View File

@ -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();

View File

@ -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);
}

View File

@ -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