mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-09-18 11:45:25 -04:00
Added PollEvent()
This commit is contained in:
parent
0da7b3c962
commit
088eaa873c
@ -20,3 +20,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <SDL2pp/EventPolling.hh>
|
#include <SDL2pp/EventPolling.hh>
|
||||||
|
|
||||||
|
namespace SDL2pp {
|
||||||
|
bool PollEvent() {
|
||||||
|
SDL_Event event;
|
||||||
|
auto result = SDL_PollEvent(&event);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -22,8 +22,10 @@
|
|||||||
#ifndef SDL2PP_EVENTPOLLING_HH
|
#ifndef SDL2PP_EVENTPOLLING_HH
|
||||||
#define SDL2PP_EVENTPOLLING_HH
|
#define SDL2PP_EVENTPOLLING_HH
|
||||||
|
|
||||||
namespace SDL2pp {
|
#include <SDL_events.h>
|
||||||
|
|
||||||
|
namespace SDL2pp {
|
||||||
|
bool PollEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,10 +1,37 @@
|
|||||||
#include <SDL_main.h>
|
#include <SDL_main.h>
|
||||||
|
|
||||||
#include <SDL2pp/EventPolling.hh>
|
#include <SDL2pp/EventPolling.hh>
|
||||||
|
#include <SDL2pp/Exception.hh>
|
||||||
|
|
||||||
#include "testing.h"
|
#include "testing.h"
|
||||||
|
|
||||||
using namespace SDL2pp;
|
using namespace SDL2pp;
|
||||||
|
|
||||||
|
inline SDL_Event PushUserEvent(Sint32 userCode = 0, void *data1 = nullptr, void *data2 = nullptr) {
|
||||||
|
SDL_Event event;
|
||||||
|
event.type = SDL_USEREVENT;
|
||||||
|
event.user.code = userCode;
|
||||||
|
event.user.data1 = data1;
|
||||||
|
event.user.data2 = data2;
|
||||||
|
|
||||||
|
if (SDL_PushEvent(&event) < 0) {
|
||||||
|
throw Exception("SDL_PushEvent");
|
||||||
|
}
|
||||||
|
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
BEGIN_TEST(int, char*[])
|
BEGIN_TEST(int, char*[])
|
||||||
|
// With no callback and no polled event
|
||||||
|
{
|
||||||
|
EXPECT_TRUE(PollEvent() == false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// With no callback and a polled event
|
||||||
|
{
|
||||||
|
PushUserEvent();
|
||||||
|
|
||||||
|
EXPECT_TRUE(PollEvent() == true);
|
||||||
|
EXPECT_TRUE(PollEvent() == false);
|
||||||
|
}
|
||||||
END_TEST()
|
END_TEST()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user