当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_PeepEvents函数代码示例

本文整理汇总了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;
}
开发者ID:heuripedes,项目名称:RetroArch,代码行数:52,代码来源:sdl_gl_ctx.c

示例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
   }
}
开发者ID:AkimanBengus,项目名称:RetroArch,代码行数:52,代码来源:sdl_input.c

示例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);
}
开发者ID:davidswelt,项目名称:XCSoar,代码行数:14,代码来源:Event.cpp

示例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;
        }
    }
}
开发者ID:Bergasms,项目名称:N64iOS,代码行数:29,代码来源:SDL_events.c

示例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
}
开发者ID:lmumar,项目名称:Unvanquished,代码行数:19,代码来源:sdl_input.cpp

示例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;
}
开发者ID:est31,项目名称:antimicro,代码行数:50,代码来源:sdleventreader.cpp

示例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;
}
开发者ID:ChrisAubuchon,项目名称:bard,代码行数:50,代码来源:l_anim.c

示例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
		
	}
开发者ID:andresa88,项目名称:lime,代码行数:25,代码来源:SDLApplication.cpp

示例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();
}
开发者ID:bawaaaaah,项目名称:Phoenix,代码行数:30,代码来源:sdlevents.cpp

示例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);
}
开发者ID:Sgt-Nukem,项目名称:chocolate_duke3D,代码行数:36,代码来源:SDL_resize.c

示例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);
}
开发者ID:mewbak,项目名称:arcan,代码行数:27,代码来源:event.c

示例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();
	}
}
开发者ID:davidsgalbraith,项目名称:odamex,代码行数:66,代码来源:i_sdlinput.cpp

示例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);
  }
}
开发者ID:SonOfLilit,项目名称:esdl,代码行数:26,代码来源:esdl_events.c

示例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);
}
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:34,代码来源:SDL_resize.c

示例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;
	}
开发者ID:asimonov-im,项目名称:wesnoth,代码行数:7,代码来源:fake_event_source.cpp


注:本文中的SDL_PeepEvents函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。