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
@ -193,6 +193,7 @@ EXPORTS
|
|||||||
sfRenderWindow_GetHeight
|
sfRenderWindow_GetHeight
|
||||||
sfRenderWindow_GetSettings
|
sfRenderWindow_GetSettings
|
||||||
sfRenderWindow_GetEvent
|
sfRenderWindow_GetEvent
|
||||||
|
sfRenderWindow_WaitEvent
|
||||||
sfRenderWindow_UseVerticalSync
|
sfRenderWindow_UseVerticalSync
|
||||||
sfRenderWindow_ShowMouseCursor
|
sfRenderWindow_ShowMouseCursor
|
||||||
sfRenderWindow_SetCursorPosition
|
sfRenderWindow_SetCursorPosition
|
||||||
|
@ -194,6 +194,7 @@ EXPORTS
|
|||||||
sfRenderWindow_GetHeight
|
sfRenderWindow_GetHeight
|
||||||
sfRenderWindow_GetSettings
|
sfRenderWindow_GetSettings
|
||||||
sfRenderWindow_GetEvent
|
sfRenderWindow_GetEvent
|
||||||
|
sfRenderWindow_WaitEvent
|
||||||
sfRenderWindow_UseVerticalSync
|
sfRenderWindow_UseVerticalSync
|
||||||
sfRenderWindow_ShowMouseCursor
|
sfRenderWindow_ShowMouseCursor
|
||||||
sfRenderWindow_SetCursorPosition
|
sfRenderWindow_SetCursorPosition
|
||||||
|
@ -19,6 +19,7 @@ EXPORTS
|
|||||||
sfWindow_GetHeight
|
sfWindow_GetHeight
|
||||||
sfWindow_GetSettings
|
sfWindow_GetSettings
|
||||||
sfWindow_GetEvent
|
sfWindow_GetEvent
|
||||||
|
sfWindow_WaitEvent
|
||||||
sfWindow_UseVerticalSync
|
sfWindow_UseVerticalSync
|
||||||
sfWindow_ShowMouseCursor
|
sfWindow_ShowMouseCursor
|
||||||
sfWindow_SetCursorPosition
|
sfWindow_SetCursorPosition
|
||||||
|
@ -19,6 +19,7 @@ EXPORTS
|
|||||||
sfWindow_GetHeight
|
sfWindow_GetHeight
|
||||||
sfWindow_GetSettings
|
sfWindow_GetSettings
|
||||||
sfWindow_GetEvent
|
sfWindow_GetEvent
|
||||||
|
sfWindow_WaitEvent
|
||||||
sfWindow_UseVerticalSync
|
sfWindow_UseVerticalSync
|
||||||
sfWindow_ShowMouseCursor
|
sfWindow_ShowMouseCursor
|
||||||
sfWindow_SetCursorPosition
|
sfWindow_SetCursorPosition
|
||||||
|
@ -193,6 +193,7 @@ EXPORTS
|
|||||||
sfRenderWindow_GetHeight
|
sfRenderWindow_GetHeight
|
||||||
sfRenderWindow_GetSettings
|
sfRenderWindow_GetSettings
|
||||||
sfRenderWindow_GetEvent
|
sfRenderWindow_GetEvent
|
||||||
|
sfRenderWindow_WaitEvent
|
||||||
sfRenderWindow_UseVerticalSync
|
sfRenderWindow_UseVerticalSync
|
||||||
sfRenderWindow_ShowMouseCursor
|
sfRenderWindow_ShowMouseCursor
|
||||||
sfRenderWindow_SetCursorPosition
|
sfRenderWindow_SetCursorPosition
|
||||||
|
@ -194,6 +194,7 @@ EXPORTS
|
|||||||
sfRenderWindow_GetHeight
|
sfRenderWindow_GetHeight
|
||||||
sfRenderWindow_GetSettings
|
sfRenderWindow_GetSettings
|
||||||
sfRenderWindow_GetEvent
|
sfRenderWindow_GetEvent
|
||||||
|
sfRenderWindow_WaitEvent
|
||||||
sfRenderWindow_UseVerticalSync
|
sfRenderWindow_UseVerticalSync
|
||||||
sfRenderWindow_ShowMouseCursor
|
sfRenderWindow_ShowMouseCursor
|
||||||
sfRenderWindow_SetCursorPosition
|
sfRenderWindow_SetCursorPosition
|
||||||
|
@ -19,6 +19,7 @@ EXPORTS
|
|||||||
sfWindow_GetHeight
|
sfWindow_GetHeight
|
||||||
sfWindow_GetSettings
|
sfWindow_GetSettings
|
||||||
sfWindow_GetEvent
|
sfWindow_GetEvent
|
||||||
|
sfWindow_WaitEvent
|
||||||
sfWindow_UseVerticalSync
|
sfWindow_UseVerticalSync
|
||||||
sfWindow_ShowMouseCursor
|
sfWindow_ShowMouseCursor
|
||||||
sfWindow_SetCursorPosition
|
sfWindow_SetCursorPosition
|
||||||
|
@ -19,6 +19,7 @@ EXPORTS
|
|||||||
sfWindow_GetHeight
|
sfWindow_GetHeight
|
||||||
sfWindow_GetSettings
|
sfWindow_GetSettings
|
||||||
sfWindow_GetEvent
|
sfWindow_GetEvent
|
||||||
|
sfWindow_WaitEvent
|
||||||
sfWindow_UseVerticalSync
|
sfWindow_UseVerticalSync
|
||||||
sfWindow_ShowMouseCursor
|
sfWindow_ShowMouseCursor
|
||||||
sfWindow_SetCursorPosition
|
sfWindow_SetCursorPosition
|
||||||
|
@ -123,6 +123,17 @@ CSFML_API sfContextSettings sfRenderWindow_GetSettings(sfRenderWindow* renderWin
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfBool sfRenderWindow_GetEvent(sfRenderWindow* renderWindow, sfEvent* event);
|
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
|
/// Enable / disable vertical synchronization on a window
|
||||||
///
|
///
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_Shape_H
|
#ifndef SFML_SHAPE_H
|
||||||
#define SFML_Shape_H
|
#define SFML_SHAPE_H
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// 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);
|
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);
|
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
|
/// 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/SpriteStruct.h>
|
||||||
#include <SFML/Graphics/StringStruct.h>
|
#include <SFML/Graphics/StringStruct.h>
|
||||||
#include <SFML/Internal.h>
|
#include <SFML/Internal.h>
|
||||||
|
#include <SFML/ConvertEvent.h>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -150,61 +151,32 @@ sfBool sfRenderWindow_GetEvent(sfRenderWindow* renderWindow, sfEvent* event)
|
|||||||
if (!ret)
|
if (!ret)
|
||||||
return sfFalse;
|
return sfFalse;
|
||||||
|
|
||||||
// Convert its type
|
// Convert the sf::Event event to a sfEvent
|
||||||
event->Type = static_cast<sfEventType>(SFMLEvent.Type);
|
ConvertEvent(SFMLEvent, event);
|
||||||
|
|
||||||
// Fill its fields
|
return sfTrue;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// Wait for an event and return it
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
sfBool sfRenderWindow_WaitEvent(sfRenderWindow* renderWindow, sfEvent* event)
|
||||||
|
{
|
||||||
|
CSFML_CHECK_RETURN(renderWindow, sfFalse);
|
||||||
|
CSFML_CHECK_RETURN(event, sfFalse);
|
||||||
|
|
||||||
|
// Get the event
|
||||||
|
sf::Event SFMLEvent;
|
||||||
|
sfBool ret = renderWindow->This.WaitEvent(SFMLEvent);
|
||||||
|
|
||||||
|
// Error, return
|
||||||
|
if (!ret)
|
||||||
|
return sfFalse;
|
||||||
|
|
||||||
|
// Convert the sf::Event event to a sfEvent
|
||||||
|
ConvertEvent(SFMLEvent, event);
|
||||||
|
|
||||||
return sfTrue;
|
return sfTrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// 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.
|
// 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.
|
// 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
|
// 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);
|
#define CSFML_CALL_PTR_RETURN(Object, Function, Default) (void)Default; return (Object->This->Function);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif // SFML_INTERNAL_H
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <SFML/Window/Window.h>
|
#include <SFML/Window/Window.h>
|
||||||
#include <SFML/Window/WindowStruct.h>
|
#include <SFML/Window/WindowStruct.h>
|
||||||
#include <SFML/Internal.h>
|
#include <SFML/Internal.h>
|
||||||
|
#include <SFML/ConvertEvent.h>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -139,61 +140,32 @@ sfBool sfWindow_GetEvent(sfWindow* window, sfEvent* event)
|
|||||||
if (!ret)
|
if (!ret)
|
||||||
return sfFalse;
|
return sfFalse;
|
||||||
|
|
||||||
// Convert its type
|
// Convert the sf::Event event to a sfEvent
|
||||||
event->Type = static_cast<sfEventType>(SFMLEvent.Type);
|
ConvertEvent(SFMLEvent, event);
|
||||||
|
|
||||||
// Fill its fields
|
return sfTrue;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// Wait for an event and return it
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
sfBool sfWindow_WaitEvent(sfWindow* window, sfEvent* event)
|
||||||
|
{
|
||||||
|
CSFML_CHECK_RETURN(window, sfFalse);
|
||||||
|
CSFML_CHECK_RETURN(event, sfFalse);
|
||||||
|
|
||||||
|
// Get the event
|
||||||
|
sf::Event SFMLEvent;
|
||||||
|
sfBool ret = window->This.WaitEvent(SFMLEvent);
|
||||||
|
|
||||||
|
// Error, return
|
||||||
|
if (!ret)
|
||||||
|
return sfFalse;
|
||||||
|
|
||||||
|
// Convert the sf::Event event to a sfEvent
|
||||||
|
ConvertEvent(SFMLEvent, event);
|
||||||
|
|
||||||
return sfTrue;
|
return sfTrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -436,6 +436,18 @@ namespace SFML
|
|||||||
return sfRenderWindow_GetEvent(This, out eventToFill);
|
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>
|
/// <summary>
|
||||||
/// Handle the destruction of the object
|
/// Handle the destruction of the object
|
||||||
@ -488,6 +500,9 @@ namespace SFML
|
|||||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||||
static extern bool sfRenderWindow_GetEvent(IntPtr This, out Event Evt);
|
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]
|
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||||
static extern void sfRenderWindow_Clear(IntPtr This, Color ClearColor);
|
static extern void sfRenderWindow_Clear(IntPtr This, Color ClearColor);
|
||||||
|
|
||||||
|
@ -340,13 +340,84 @@ namespace SFML
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
public void DispatchEvents()
|
public void DispatchEvents()
|
||||||
{
|
{
|
||||||
Event e;
|
Event e;
|
||||||
while (GetEvent(out e))
|
while (GetEvent(out e))
|
||||||
|
CallEventHandler(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for derived classes
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="thisPtr">Pointer to the internal object</param>
|
||||||
|
/// <param name="dummy">Internal hack :)</param>
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
protected Window(IntPtr thisPtr, int dummy) :
|
||||||
|
base(thisPtr)
|
||||||
|
{
|
||||||
|
// TODO : find a cleaner way of separating this constructor from Window(IntPtr handle)
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// <summary>
|
||||||
|
/// 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>
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
protected virtual bool GetEvent(out Event eventToFill)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
protected override void Destroy(bool disposing)
|
||||||
|
{
|
||||||
|
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)
|
switch (e.Type)
|
||||||
{
|
{
|
||||||
@ -431,43 +502,6 @@ namespace SFML
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor for derived classes
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="thisPtr">Pointer to the internal object</param>
|
|
||||||
/// <param name="dummy">Internal hack :)</param>
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
protected Window(IntPtr thisPtr, int dummy) :
|
|
||||||
base(thisPtr)
|
|
||||||
{
|
|
||||||
// TODO : find a cleaner way of separating this constructor from Window(IntPtr handle)
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// <summary>
|
|
||||||
/// Internal function to get the next event
|
|
||||||
/// </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>
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
protected virtual bool GetEvent(out Event eventToFill)
|
|
||||||
{
|
|
||||||
return sfWindow_GetEvent(This, out eventToFill);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// <summary>
|
|
||||||
/// Handle the destruction of the object
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
protected override void Destroy(bool disposing)
|
|
||||||
{
|
|
||||||
sfWindow_Destroy(This);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Event handler for the Closed event</summary>
|
/// <summary>Event handler for the Closed event</summary>
|
||||||
public event EventHandler Closed = null;
|
public event EventHandler Closed = null;
|
||||||
@ -541,6 +575,9 @@ namespace SFML
|
|||||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||||
static extern bool sfWindow_GetEvent(IntPtr This, out Event Evt);
|
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]
|
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||||
static extern void sfWindow_Display(IntPtr This);
|
static extern void sfWindow_Display(IntPtr This);
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ public :
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Pop the event on top of events stack, if any, and return it
|
/// \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.
|
/// it will return false and leave \a event unmodified.
|
||||||
/// Note that more than event may be present in the events stack,
|
/// Note that more than event may be present in the events stack,
|
||||||
/// thus you should always call this function in a loop
|
/// thus you should always call this function in a loop
|
||||||
@ -212,6 +212,31 @@ public :
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool GetEvent(Event& event);
|
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
|
/// \brief Enable or disable vertical synchronization
|
||||||
///
|
///
|
||||||
|
@ -280,7 +280,7 @@ WindowHandle WindowImplX11::GetHandle() const
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void WindowImplX11::ProcessEvents()
|
void WindowImplX11::ProcessEvents(bool block)
|
||||||
{
|
{
|
||||||
// This function implements a workaround to properly discard
|
// This function implements a workaround to properly discard
|
||||||
// repeated key events when necessary. The problem is that the
|
// repeated key events when necessary. The problem is that the
|
||||||
|
@ -92,10 +92,12 @@ private :
|
|||||||
virtual WindowHandle GetHandle() const;
|
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
|
/// \brief Show or hide the mouse cursor
|
||||||
|
@ -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 (!myCallback)
|
||||||
{
|
{
|
||||||
|
if (block)
|
||||||
|
WaitMessage();
|
||||||
|
|
||||||
MSG message;
|
MSG message;
|
||||||
while (PeekMessage(&message, myHandle, 0, 0, PM_REMOVE))
|
while (PeekMessage(&message, myHandle, 0, 0, PM_REMOVE))
|
||||||
{
|
{
|
||||||
|
@ -81,10 +81,12 @@ private :
|
|||||||
virtual WindowHandle GetHandle() const;
|
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
|
/// \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
|
// Let the window implementation process incoming events if the events queue is empty
|
||||||
if (myWindow && myEvents.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())
|
if (!myEvents.empty())
|
||||||
{
|
{
|
||||||
event = myEvents.front();
|
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
|
// Read the joysticks state and generate the appropriate events
|
||||||
ProcessJoystickEvents();
|
ProcessJoystickEvents();
|
||||||
|
|
||||||
// Let the derived class process other events
|
// Let the derived class process other events
|
||||||
ProcessEvents();
|
ProcessEvents(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,10 +124,12 @@ public :
|
|||||||
void SetJoystickThreshold(float threshold);
|
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
|
/// \brief Get the OS-specific handle of the window
|
||||||
@ -229,10 +231,12 @@ private :
|
|||||||
void ProcessJoystickEvents();
|
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
|
// Total number of joysticks supported
|
||||||
|
Loading…
x
Reference in New Issue
Block a user