本文整理汇总了C++中SDL_PeepEvents函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_PeepEvents函数的具体用法?C++ SDL_PeepEvents怎么用?C++ SDL_PeepEvents使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_PeepEvents函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sdl_ctx_check_window
static void sdl_ctx_check_window(void *data, bool *quit, bool *resize,unsigned *width,
unsigned *height, unsigned frame_count)
{
SDL_Event event;
gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;
SDL_PumpEvents();
#ifdef HAVE_SDL2
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_QUIT, SDL_WINDOWEVENT) > 0)
#else
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_QUITMASK|SDL_VIDEORESIZEMASK) > 0)
#endif
{
switch (event.type)
{
case SDL_QUIT:
#ifdef HAVE_SDL2
case SDL_APP_TERMINATING:
#endif
*quit = true;
break;
#ifdef HAVE_SDL2
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_RESIZED)
{
sdl->g_resized = true;
sdl->g_new_width = event.window.data1;
sdl->g_new_height = event.window.data2;
}
#else
case SDL_VIDEORESIZE:
sdl->g_resized = true;
sdl->g_new_width = event.resize.w;
sdl->g_new_height = event.resize.h;
#endif
break;
default:
break;
}
}
if (sdl->g_resized)
{
*width = sdl->g_new_width;
*height = sdl->g_new_height;
*resize = true;
sdl->g_resized = false;
}
sdl->g_frame_count = frame_count;
}
示例2: sdl_input_poll
static void sdl_input_poll(void *data)
{
sdl_input_t *sdl = (sdl_input_t*)data;
SDL_Event event;
SDL_PumpEvents();
if (sdl->joypad)
sdl->joypad->poll();
sdl_poll_mouse(sdl);
#ifdef HAVE_SDL2
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_KEYDOWN, SDL_MOUSEWHEEL) > 0)
#else
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_KEYEVENTMASK) > 0)
#endif
{
if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
{
uint16_t mod = 0;
unsigned code = input_keymaps_translate_keysym_to_rk(event.key.keysym.sym);
if (event.key.keysym.mod & KMOD_SHIFT)
mod |= RETROKMOD_SHIFT;
if (event.key.keysym.mod & KMOD_CTRL)
mod |= RETROKMOD_CTRL;
if (event.key.keysym.mod & KMOD_ALT)
mod |= RETROKMOD_ALT;
if (event.key.keysym.mod & KMOD_NUM)
mod |= RETROKMOD_NUMLOCK;
if (event.key.keysym.mod & KMOD_CAPS)
mod |= RETROKMOD_CAPSLOCK;
input_keyboard_event(event.type == SDL_KEYDOWN, code, code, mod,
RETRO_DEVICE_KEYBOARD);
}
#ifdef HAVE_SDL2
else if (event.type == SDL_MOUSEWHEEL)
{
sdl->mouse_wu = event.wheel.y < 0;
sdl->mouse_wd = event.wheel.y > 0;
sdl->mouse_wl = event.wheel.x < 0;
sdl->mouse_wr = event.wheel.x > 0;
break;
}
#endif
}
}
示例3: bool
void
EventQueue::Purge(Uint32 mask,
bool (*match)(const SDL_Event &event, void *ctx),
void *ctx)
{
SDL_Event events[256]; // is that enough?
int count = SDL_PeepEvents(events, 256, SDL_GETEVENT, mask);
assert(count >= 0);
for (int i = count - 1; i >= 0; --i)
if (!match(events[i], ctx))
std::copy(events + i + 1, events + count--, events + i);
SDL_PeepEvents(events, count, SDL_ADDEVENT, mask);
}
示例4: SDL_WaitEventTimeout
int
SDL_WaitEventTimeout(SDL_Event * event, int timeout)
{
Uint32 expiration = 0;
if (timeout > 0)
expiration = SDL_GetTicks() + timeout;
for (;;) {
SDL_PumpEvents();
switch (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) {
case -1:
return 0;
case 1:
return 1;
case 0:
if (timeout == 0) {
/* Polling and no events, just return */
return 0;
}
if (timeout > 0 && ((int) (SDL_GetTicks() - expiration) >= 0)) {
/* Timeout expired and no events */
return 0;
}
SDL_Delay(10);
break;
}
}
}
示例5: IN_GobbleMotionEvents
/*
===============
IN_GobbleMotionEvents
===============
*/
static void IN_GobbleMotionEvents( void )
{
SDL_Event dummy[ 1 ];
// Gobble any mouse motion events
SDL_PumpEvents();
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
while ( SDL_PeepEvents( dummy, 1, SDL_GETEVENT,
SDL_MOUSEMOTION, SDL_MOUSEMOTION ) ) { }
#else
while ( SDL_PeepEvents( dummy, 1, SDL_GETEVENT,
SDL_EVENTMASK( SDL_MOUSEMOTION ) ) ) { }
#endif
}
示例6: QString
int SDLEventReader::CheckForEvents()
{
int result = 0;
bool exit = false;
/*Logger::LogInfo(
QString("Gamepad Poll %1").arg(
QTime::currentTime().toString("hh:mm:ss.zzz")),
true, true);
*/
SDL_PumpEvents();
#ifdef USE_SDL_2
switch (SDL_PeepEvents(NULL, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT))
#else
switch (SDL_PeepEvents(NULL, 1, SDL_GETEVENT, 0xFFFF))
#endif
{
case -1:
{
result = 0;
exit = true;
break;
}
case 1:
{
/*Logger::LogInfo(
QString("Gamepad Poll %1").arg(
QTime::currentTime().toString("hh:mm:ss.zzz")),
true, true);
*/
result = 1;
exit = true;
break;
}
case 0:
{
if (!pollRateTimer.isActive())
{
pollRateTimer.start();
}
//exit = true;
//SDL_Delay(10);
break;
}
}
return result;
}
示例7: l_anim_stop
static int l_anim_stop(lua_State *L)
{
l_anim *a;
int i, j;
uint32_t nevents;
uint32_t push;
SDL_Event event[20];
a = l_checkAnim(L, 1);
for (i = 0; i < bta_getNumLoops(a->bta); i++) {
l_loop_t *l = (l_loop_t *)gl_list_get_at(a->loopData, i);
if (SDL_RemoveTimer(l->timer) == SDL_FALSE) {
luaL_error(L, "Error removing animation timer");
}
l->timer = 0;
}
/*
* There could be outstanding animation events in the event
* queue. Loop through the outstanding events and compare with
* each loop pointer of the current animation. If they don't match
* push the event back into the event queue.
*/
nevents = SDL_PeepEvents(event, 20, SDL_GETEVENT,
BT_ANIM_EVENT,
BT_ANIM_EVENT
);
for (i = 0; i < nevents; i++) {
push = 1;
for (j = 0; j < bta_getNumLoops(a->bta); j++) {
if (event[i].user.data2 == gl_list_get_at(a->loopData,j)) {
push = 0;
break;
}
}
if (push) {
SDL_PushEvent(&event[i]);
}
}
nevents = SDL_PeepEvents(event, 20, SDL_GETEVENT,
BT_ANIM_EVENT,
BT_ANIM_EVENT
);
return 0;
}
示例8: SDL_WaitEvent
int SDLApplication::WaitEvent (SDL_Event *event) {
#ifdef HX_MACOS
return SDL_WaitEvent (event);
#else
for(;;) {
SDL_PumpEvents ();
switch (SDL_PeepEvents (event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT)) {
case -1: return 0;
case 1: return 1;
default: SDL_Delay (1);
}
}
#endif
}
示例9: l
void SDLEvents::pollSDL() {
QMutexLocker l( &sdl_mutex );
// consume moar events
SDL_PumpEvents();
int ret = SDL_PeepEvents( event_list, 10, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT );
if( ret < 0 ) {
qCCritical( phxInput, "SDLEvents: unable to retrieve events: %s", SDL_GetError() );
}
if( ret == 0 ) {
return;
}
event_callbacks_mutex.lock();
SDL_Event *event = event_list;
for( int i = 0; i < ret; i++ ) {
foreach( auto cb, event_callbacks ) {
if( ( *cb )( event ) ) {
// callback handled the event, stop the loop
break;
}
}
event++;
}
event_callbacks_mutex.unlock();
}
示例10: SDL_PrivateResize
/* This is global for SDL_eventloop.c */
int SDL_PrivateResize(int w, int h)
{
int posted;
SDL_Event events[32];
/* See if this event would change the video surface */
if ( !w || !h ||
((last_resize.w == w) && (last_resize.h == h)) ) {
return(0);
}
last_resize.w = w;
last_resize.h = h;
if ( ! SDL_VideoSurface ||
((w == SDL_VideoSurface->w) && (h == SDL_VideoSurface->h)) ) {
return(0);
}
/* Pull out all old resize events */
SDL_PeepEvents(events, sizeof(events)/sizeof(events[0]),
SDL_GETEVENT, SDL_VIDEORESIZEMASK);
/* Post the event, if desired */
posted = 0;
if ( SDL_ProcessEvents[SDL_VIDEORESIZE] == SDL_ENABLE ) {
SDL_Event event;
event.type = SDL_VIDEORESIZE;
event.resize.w = w;
event.resize.h = h;
if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) {
posted = 1;
SDL_PushEvent(&event);
}
}
return(posted);
}
示例11: platform_event_init
void platform_event_init(arcan_evctx* ctx)
{
static bool first_init;
SDL_EnableUNICODE(1);
/* OSX hack */
SDL_ShowCursor(0);
SDL_ShowCursor(1);
SDL_ShowCursor(0);
if (!first_init){
platform_event_analogfilter(-1, 0,
-32768, 32767, 0, 1, ARCAN_ANALOGFILTER_AVG);
platform_event_analogfilter(-1, 1,
-32768, 32767, 0, 1, ARCAN_ANALOGFILTER_AVG);
first_init = true;
int r = 0, d = 0;
platform_event_keyrepeat(ctx, &r, &d);
}
/* flush out initial storm */
SDL_Event dummy[1];
while ( SDL_PeepEvents(dummy, 1, SDL_GETEVENT,
SDL_EVENTMASK(SDL_MOUSEMOTION)) );
platform_event_rescan_idev(ctx);
}
示例12: SDL_PumpEvents
//
// ISDL12MouseInputDevice::gatherEvents
//
// Pumps the SDL Event queue and retrieves any mouse events and puts them into
// this instance's event queue.
//
void ISDL12MouseInputDevice::gatherEvents()
{
if (active())
{
// Force SDL to gather events from input devices. This is called
// implicitly from SDL_PollEvent but since we're using SDL_PeepEvents to
// process only mouse events, SDL_PumpEvents is necessary.
SDL_PumpEvents();
// Retrieve chunks of up to 1024 events from SDL
int num_events = 0;
const int max_events = 1024;
SDL_Event sdl_events[max_events];
while ((num_events = SDL_PeepEvents(sdl_events, max_events, SDL_GETEVENT, SDL_MOUSEEVENTMASK)))
{
// insert the SDL_Events into our queue
for (int i = 0; i < num_events; i++)
{
const SDL_Event& sdl_ev = sdl_events[i];
assert(sdl_ev.type == SDL_MOUSEMOTION ||
sdl_ev.type == SDL_MOUSEBUTTONDOWN || sdl_ev.type == SDL_MOUSEBUTTONUP);
event_t ev;
ev.data1 = ev.data2 = ev.data3 = 0;
if (sdl_ev.type == SDL_MOUSEMOTION)
{
ev.type = ev_mouse;
ev.data2 = sdl_ev.motion.xrel;
ev.data3 = -sdl_ev.motion.yrel;
}
else if (sdl_ev.type == SDL_MOUSEBUTTONDOWN || sdl_ev.type == SDL_MOUSEBUTTONUP)
{
ev.type = (sdl_ev.type == SDL_MOUSEBUTTONDOWN) ? ev_keydown : ev_keyup;
if (sdl_ev.button.button == SDL_BUTTON_LEFT)
ev.data1 = KEY_MOUSE1;
else if (sdl_ev.button.button == SDL_BUTTON_RIGHT)
ev.data1 = KEY_MOUSE2;
else if (sdl_ev.button.button == SDL_BUTTON_MIDDLE)
ev.data1 = KEY_MOUSE3;
#if SDL_VERSION_ATLEAST(1, 2, 14)
else if (sdl_ev.button.button == SDL_BUTTON_X1)
ev.data1 = KEY_MOUSE4; // [Xyltol 07/21/2011] - Add support for MOUSE4
else if (sdl_ev.button.button == SDL_BUTTON_X2)
ev.data1 = KEY_MOUSE5; // [Xyltol 07/21/2011] - Add support for MOUSE5
#endif
else if (sdl_ev.button.button == SDL_BUTTON_WHEELUP)
ev.data1 = KEY_MWHEELUP;
else if (sdl_ev.button.button == SDL_BUTTON_WHEELDOWN)
ev.data1 = KEY_MWHEELDOWN;
}
mEvents.push(ev);
}
}
center();
}
}
示例13: es_peepEvents
void es_peepEvents(sdl_data *sd, int len, char *bp)
{
SDL_Event events[256];
int numevents, res;
Uint32 mask;
char *start;
if (len == 0) {
mask = SDL_ALLEVENTS;
numevents = 16;
} else {
mask = * (Uint32 *) bp; bp += sizeof(Uint32);
numevents = *bp++;
}
SDL_PumpEvents();
res = SDL_PeepEvents(events, numevents, SDL_GETEVENT, mask);
if (res > 0) {
int sendlen, i;
bp = start = sdl_get_temp_buff(sd, res*MAX_EVENT_SIZE);
for (i = 0; i < res; i++) {
bp = encode_event(&(events[i]), bp);
}
sendlen = bp - start;
sdl_send(sd, sendlen);
}
}
示例14: SDL_PrivateResize
int SDL_PrivateResize(int w, int h)
{
int posted;
SDL_Event events[32];
if ( !w || !h ||
(( last_resize.w == w ) && ( last_resize.h == h )) ||
!SDL_VideoSurface ) {
return(0);
}
last_resize.w = w;
last_resize.h = h;
SDL_SetMouseRange(w, h);
SDL_PeepEvents(events, sizeof(events)/sizeof(events[0]),
SDL_GETEVENT, SDL_VIDEORESIZEMASK);
posted = 0;
if ( SDL_ProcessEvents[SDL_VIDEORESIZE] == SDL_ENABLE ) {
SDL_Event event;
event.type = SDL_VIDEORESIZE;
event.resize.w = w;
event.resize.h = h;
if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) {
posted = 1;
SDL_PushEvent(&event);
}
}
return(posted);
}
示例15: SDL_PeepEvents
void event_node::fire_event()
{
const int number_of_events = 1;
const Uint32 mask = 0;
SDL_PeepEvents(&event_, number_of_events, SDL_ADDEVENT, mask);
fired_ = true;
}