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
|
@ -193,6 +193,7 @@ EXPORTS
|
|||
sfRenderWindow_GetHeight
|
||||
sfRenderWindow_GetSettings
|
||||
sfRenderWindow_GetEvent
|
||||
sfRenderWindow_WaitEvent
|
||||
sfRenderWindow_UseVerticalSync
|
||||
sfRenderWindow_ShowMouseCursor
|
||||
sfRenderWindow_SetCursorPosition
|
||||
|
|
|
@ -194,6 +194,7 @@ EXPORTS
|
|||
sfRenderWindow_GetHeight
|
||||
sfRenderWindow_GetSettings
|
||||
sfRenderWindow_GetEvent
|
||||
sfRenderWindow_WaitEvent
|
||||
sfRenderWindow_UseVerticalSync
|
||||
sfRenderWindow_ShowMouseCursor
|
||||
sfRenderWindow_SetCursorPosition
|
||||
|
|
|
@ -19,6 +19,7 @@ EXPORTS
|
|||
sfWindow_GetHeight
|
||||
sfWindow_GetSettings
|
||||
sfWindow_GetEvent
|
||||
sfWindow_WaitEvent
|
||||
sfWindow_UseVerticalSync
|
||||
sfWindow_ShowMouseCursor
|
||||
sfWindow_SetCursorPosition
|
||||
|
|
|
@ -19,6 +19,7 @@ EXPORTS
|
|||
sfWindow_GetHeight
|
||||
sfWindow_GetSettings
|
||||
sfWindow_GetEvent
|
||||
sfWindow_WaitEvent
|
||||
sfWindow_UseVerticalSync
|
||||
sfWindow_ShowMouseCursor
|
||||
sfWindow_SetCursorPosition
|
||||
|
|
|
@ -193,6 +193,7 @@ EXPORTS
|
|||
sfRenderWindow_GetHeight
|
||||
sfRenderWindow_GetSettings
|
||||
sfRenderWindow_GetEvent
|
||||
sfRenderWindow_WaitEvent
|
||||
sfRenderWindow_UseVerticalSync
|
||||
sfRenderWindow_ShowMouseCursor
|
||||
sfRenderWindow_SetCursorPosition
|
||||
|
|
|
@ -194,6 +194,7 @@ EXPORTS
|
|||
sfRenderWindow_GetHeight
|
||||
sfRenderWindow_GetSettings
|
||||
sfRenderWindow_GetEvent
|
||||
sfRenderWindow_WaitEvent
|
||||
sfRenderWindow_UseVerticalSync
|
||||
sfRenderWindow_ShowMouseCursor
|
||||
sfRenderWindow_SetCursorPosition
|
||||
|
|
|
@ -19,6 +19,7 @@ EXPORTS
|
|||
sfWindow_GetHeight
|
||||
sfWindow_GetSettings
|
||||
sfWindow_GetEvent
|
||||
sfWindow_WaitEvent
|
||||
sfWindow_UseVerticalSync
|
||||
sfWindow_ShowMouseCursor
|
||||
sfWindow_SetCursorPosition
|
||||
|
|
|
@ -19,6 +19,7 @@ EXPORTS
|
|||
sfWindow_GetHeight
|
||||
sfWindow_GetSettings
|
||||
sfWindow_GetEvent
|
||||
sfWindow_WaitEvent
|
||||
sfWindow_UseVerticalSync
|
||||
sfWindow_ShowMouseCursor
|
||||
sfWindow_SetCursorPosition
|
||||
|
|
|
@ -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
|
||||
///
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
///
|
||||
|
|
96
CSFML/src/SFML/ConvertEvent.h
Normal file
96
CSFML/src/SFML/ConvertEvent.h
Normal 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
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue