Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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
   }
}
Exemplo n.º 3
0
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);
}
Exemplo n.º 4
0
/*
===============
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
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
//------------------------------------------------------------------------------
static bool ProcessMessages()
{
   static const int MaxEvents = 255;
   static const U32 Mask = 
      SDL_QUITMASK | SDL_VIDEORESIZEMASK | SDL_VIDEOEXPOSEMASK |
      SDL_ACTIVEEVENTMASK | SDL_SYSWMEVENTMASK | 
      SDL_EVENTMASK(SDL_USEREVENT);
   static SDL_Event events[MaxEvents];
 
   SDL_PumpEvents();
   S32 numEvents = SDL_PeepEvents(events, MaxEvents, SDL_GETEVENT, Mask);
   if (numEvents == 0)
      return true;
   for (int i = 0; i < numEvents; ++i)
   {
      SDL_Event& event = events[i];
      switch (event.type)
      {
         case SDL_QUIT:
            return false;
            break;
         case SDL_VIDEORESIZE:
         case SDL_VIDEOEXPOSE:
            Game->refreshWindow();
            break;
         case SDL_USEREVENT:
            if (event.user.code == TORQUE_SETVIDEOMODE)
            {
               SetAppState();
               // SDL will send a motion event to restore the mouse position
               // on the new window.  Ignore that if the window is locked.
               if (x86UNIXState->windowLocked())
               {
                  SDL_Event tempEvent;
                  SDL_PeepEvents(&tempEvent, 1, SDL_GETEVENT, 
                     SDL_MOUSEMOTIONMASK);
               }
            }
            break;
         case SDL_ACTIVEEVENT:
            SetAppState();
            break;          
         case SDL_SYSWMEVENT:
            ProcessSYSWMEvent(event);
            break;
      }
   }
   return true;
}
Exemplo n.º 8
0
	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
		
	}
Exemplo n.º 9
0
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();
}
Exemplo n.º 10
0
/* 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);
}
Exemplo n.º 11
0
Arquivo: event.c Projeto: mewbak/arcan
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);
}
Exemplo n.º 12
0
//
// 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();
	}
}
Exemplo n.º 13
0
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);
  }
}
Exemplo n.º 14
0
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);
}
Exemplo n.º 15
0
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;
        }
    }
}
Exemplo n.º 16
0
	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;
	}
Exemplo n.º 17
0
/**
 * \brief Re-read the status of all keys.
 * \pre The caller is an instance of bear::input::system.
 */
void bear::input::finger::refresh()
{
  m_events.clear();

  SDL_Event e;

  // The range of events to process. It includes button up and button down.
  const SDL_EventType event_min( SDL_FINGERDOWN );
  const SDL_EventType event_max( SDL_FINGERMOTION );
  
  while ( SDL_PeepEvents(&e, 1, SDL_GETEVENT, event_min, event_max ) == 1 )
    {
      const SDL_TouchFingerEvent* const evt =
          reinterpret_cast<SDL_TouchFingerEvent*>(&e);
      const position_type position( convert_position( evt->x, evt->y ) );

      if ( e.type == SDL_FINGERDOWN )
        m_events.push_back
          ( finger_event::create_pressed_event( position, evt->fingerId ) );
      else if ( e.type == SDL_FINGERUP )
        m_events.push_back
          ( finger_event::create_released_event( position, evt->fingerId ) );
      else if ( e.type == SDL_FINGERMOTION )
        m_events.push_back
          ( finger_event::create_motion_event
            ( position, evt->fingerId, convert_delta( evt->dx, evt->dy ) ) );
    }
} // finger::refresh()
Exemplo n.º 18
0
const int processEvents( const int number )
{
	assert( number > 0 );

	// Retrieves events
	SDL_Event	* events = new SDL_Event[ number ];
	int			storedNumber;

	SDL_PumpEvents();
	storedNumber = SDL_PeepEvents(
			events,
			number,
			SDL_GETEVENT,
			SDL_JOYAXISMOTION, SDL_JOYBUTTONUP
		);

	// Dispatch events.
	for( int i = 0; i < storedNumber; ++i )
	{
		dispatchEvent( events[i] );
	}

	// Clean-up.
	delete [] events;

	return storedNumber;
}
Exemplo n.º 19
0
/**
 * Main game loop. Each keypress triggers the keypress_callback
 * function passed.
 */
void display_event_loop(void (*keypress_callback)(int key, int shift)) {
	SDL_Event event;
	while (SDL_WaitEvent(&event) >= 0) {
		
		/* Throw away pending keyboard events, or SDL seems to crash(?).
		   This seems to be a nice input loop. */
		SDL_PeepEvents(NULL, 1000, SDL_GETEVENT, SDL_KEYUP | SDL_KEYDOWN);
		
		switch (event.type) {
			
		case SDL_KEYDOWN: /* Handle keypresses. */
            if (event.key.keysym.sym != SDLK_RSHIFT &&
                event.key.keysym.sym != SDLK_LSHIFT) {
                if (keypress_callback != NULL)
                    keypress_callback(event.key.keysym.sym, event.key.keysym.mod & KMOD_SHIFT);
            }
			break;
		case SDL_QUIT:
			exit(0);
			break;
		default:
			break;
		}
	}
}
Exemplo n.º 20
0
void es_peepEvents2(ErlDrvPort port, ErlDrvTermData caller, char *bp)
{  
    SDL_Event events[256];
    int numevents, res, i, sz;
    Uint32 mask;
    char *start;
    ErlDrvBinary * bin;
    ErlDrvTermData rt[8];
    
    mask = * (Uint32 *) bp; bp += sizeof(Uint32);
    numevents = *bp++;
    
    SDL_PumpEvents();
    res = SDL_PeepEvents(events, numevents, SDL_GETEVENT, mask);
    bin = driver_alloc_binary(res*MAX_EVENT_SIZE);
    bp = start = bin->orig_bytes;
    for (i = 0; i < res; i++) {
	bp = encode_event(&(events[i]), bp);
    }
    sz = bp-start;
    rt[0] = ERL_DRV_ATOM; rt[1]=driver_mk_atom((char *) "_esdl_result_");
    rt[2] = ERL_DRV_BINARY; rt[3] = (ErlDrvTermData) bin; rt[4] = sz; rt[5] = 0;
    rt[6] = ERL_DRV_TUPLE; rt[7] = 2;
    driver_send_term(port,caller,rt,8);
    driver_free_binary(bin);
}
Exemplo n.º 21
0
void CLinuxInput::Update(bool bFocus)
{
	
	SDL_PumpEvents();
	m_pPadManager->Update(bFocus);
	CBaseInput::Update(bFocus);
	SDL_Event eventList[32];
	int nEvents;
	nEvents = SDL_PeepEvents(eventList, 32, SDL_GETEVENT, SDL_QUIT,SDL_QUIT);
	if (nEvents == -1)
	{
		gEnv->pLog->LogError("SDL_GETEVENT error: %s", SDL_GetError());
		return;
	}
	for (int i = 0; i < nEvents; ++i)
	{
		if (eventList[i].type == SDL_QUIT) {
			gEnv->pSystem->Quit();
			return;
		}
		else
		{
			// Unexpected event type.
			abort();
		}
	}
}
Exemplo n.º 22
0
void one() {
  SDL_Event event;
  while (SDL_PollEvent(&event)) {
    switch(event.type) {
      case SDL_MOUSEMOTION: {
        SDL_MouseMotionEvent *m = (SDL_MouseMotionEvent*)&event;
        assert(m->state == 0);
        printf("motion : %d,%d  %d,%d\n", m->x, m->y, m->xrel, m->yrel);
#ifdef TEST_SDL_MOUSE_OFFSETS
        assert(eq(m->x, 5) && eq(m->y, 15) && eq(m->xrel, 5) && eq(m->yrel, 15)
          || eq(m->x, 25) && eq(m->y, 65) && eq(m->xrel, 20) && eq(m->yrel, 50));
#else        
        assert(eq(m->x, 10) && eq(m->y, 20) && eq(m->xrel, 10) && eq(m->yrel, 20)
          || eq(m->x, 30) && eq(m->y, 70) && eq(m->xrel, 20) && eq(m->yrel, 50));
#endif
        break;
      }
      case SDL_MOUSEBUTTONDOWN: {
        SDL_MouseButtonEvent *m = (SDL_MouseButtonEvent*)&event;
        if (m->button == 2) {
          REPORT_RESULT(result);
          emscripten_run_script("throw 'done'");
        }
        printf("button down : %d,%d  %d,%d\n", m->button, m->state, m->x, m->y);
#ifdef TEST_SDL_MOUSE_OFFSETS
        assert(eq(m->button, 1) && eq(m->state, 1) && eq(m->x, 5) && eq(m->y, 15));
#else
        assert(eq(m->button, 1) && eq(m->state, 1) && eq(m->x, 10) && eq(m->y, 20));
#endif
        break;
      }
      case SDL_MOUSEBUTTONUP: {
        SDL_MouseButtonEvent *m = (SDL_MouseButtonEvent*)&event;
        printf("button up : %d,%d  %d,%d\n", m->button, m->state, m->x, m->y);
#ifdef TEST_SDL_MOUSE_OFFSETS
        assert(eq(m->button, 1) && eq(m->state, 0) && eq(m->x, 5) && eq(m->y, 15));
#else
        assert(eq(m->button, 1) && eq(m->state, 0) && eq(m->x, 10) && eq(m->y, 20));
#endif
        // Remove another click we want to ignore
        assert(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONDOWN) == 1);
        assert(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEBUTTONUP, SDL_MOUSEBUTTONUP) == 1);
        break;
      }
    }
  }
}
Exemplo n.º 23
0
int processSdlEvents(void) {
    SDL_Event event;

    resetEvents();
    while (SDL_PollEvent(&event)) {
        switch(event.type) {
        case SDL_KEYDOWN:
            switch(event.key.keysym.sym) {
            case SDLK_ESCAPE:
                return 1;
                break;
            default:
                keyboardEvent(&event.key,1);
                break;
            }
            break;
        case SDL_KEYUP:
            keyboardEvent(&event.key,0);
            break;
        case SDL_MOUSEMOTION:
            mouseMovedEvent(event.motion.x,event.motion.y,
                       event.motion.xrel,event.motion.yrel);
            break;
        case SDL_MOUSEBUTTONDOWN:
            mouseButtonEvent(event.button.button,1);
            break;
        case SDL_MOUSEBUTTONUP:
            mouseButtonEvent(event.button.button,0);
            break;
        case SDL_QUIT:
            exit(0);
            break;
        }
        /* If the next event to process is of type KEYUP or
         * MOUSEBUTTONUP we want to stop processing here, so that
         * a fast up/down event be noticed by Lua. */
        if (SDL_PeepEvents(&event,1,SDL_PEEKEVENT,SDL_ALLEVENTS)) {
            if (event.type == SDL_KEYUP ||
                event.type == SDL_MOUSEBUTTONUP)
                break; /* Go to lua before processing more. */
        }
    }

    /* Call the setup function, only the first time. */
    if (l81.epoch == 0) {
        setup();
        if (l81.luaerr) return l81.luaerr;
    }
    /* Call the draw function at every iteration.  */
    draw();
    l81.epoch++;
    /* Refresh the screen */
    if (l81.opt_show_fps) showFPS();
    SDL_Flip(l81.fb->screen);
    /* Wait some time if the frame was produced in less than 1/FPS seconds. */
    SDL_framerateDelay(&l81.fb->fps_mgr);
    /* Stop execution on error */
    return l81.luaerr;
}
Exemplo n.º 24
0
void PeekEvent(Event *event)
{
#if defined(TARGET_SDL)
  SDL_PeepEvents(event, 1, SDL_PEEKEVENT, SDL_ALLEVENTS);
#else
  XPeekEvent(display, event);
#endif
}
Exemplo n.º 25
0
/*
===============
IN_GobbleMotionEvents
===============
*/
static void IN_GobbleMotionEvents() {
    SDL_Event dummy[1];

    // Gobble any mouse motion events
    SDL_PumpEvents();
    while (SDL_PeepEvents(dummy, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION)) {
    }
}
Exemplo n.º 26
0
Uint32 TimerCallback(Uint32 interval)
{
	SDL_Event event;
	event.type = SDL_TIMER_EVENT;

	SDL_PeepEvents( &event, 1, SDL_ADDEVENT, 0 );
	return timerInterval;
}
Exemplo n.º 27
0
uint32 SdlEventSource::obtainUnicode(const SDL_keysym keySym) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
	SDL_Event events[2];

	// Update the event queue here to give SDL a chance to insert TEXTINPUT
	// events for KEYDOWN events. Otherwise we have a high chance that on
	// Windows the TEXTINPUT event is not in the event queue at this point.
	// In this case we will get two events with ascii values due to mapKey
	// and dispatchSDLEvent. This results in nasty double input of characters
	// in the GUI.
	//
	// FIXME: This is all a bit fragile because in mapKey we derive the ascii
	// value from the key code if no unicode value is given. This is legacy
	// behavior and should be removed anyway. If that is removed, we might not
	// even need to do this peeking here but instead can rely on the
	// SDL_TEXTINPUT case in dispatchSDLEvent to introduce keydown/keyup with
	// proper ASCII values (but with KEYCODE_INVALID as keycode).
	SDL_PumpEvents();

	// In SDL2, the unicode field has been removed from the keysym struct.
	// Instead a SDL_TEXTINPUT event is generated on key combinations that
	// generates unicode.
	// Here we peek into the event queue for the event to see if it exists.
	int n = SDL_PeepEvents(events, 2, SDL_PEEKEVENT, SDL_KEYDOWN, SDL_TEXTINPUT);
	// Make sure that the TEXTINPUT event belongs to this KEYDOWN
	// event and not another pending one.
	if ((n > 0 && events[0].type == SDL_TEXTINPUT)
	    || (n > 1 && events[0].type != SDL_KEYDOWN && events[1].type == SDL_TEXTINPUT)) {
		// Remove the text input event we associate with the key press. This
		// makes sure we never get any SDL_TEXTINPUT events which do "belong"
		// to SDL_KEYDOWN events.
		n = SDL_PeepEvents(events, 1, SDL_GETEVENT, SDL_TEXTINPUT, SDL_TEXTINPUT);
		// This is basically a paranoia safety check because we know there
		// must be a text input event in the queue.
		if (n > 0) {
			return convUTF8ToUTF32(events[0].text.text);
		} else {
			return 0;
		}
	} else {
		return 0;
	}
#else
	return keySym.unicode;
#endif
}
Exemplo n.º 28
0
//------------------------------------------------------------------------------
static S32 NumEventsPending()
{
   static const int MaxEvents = 255;
   static SDL_Event events[MaxEvents];

   SDL_PumpEvents();
   return SDL_PeepEvents(events, MaxEvents, SDL_PEEKEVENT, SDL_ALLEVENTS);
}
Exemplo n.º 29
0
int SDL_PollEvent (SDL_Event *event)
{
	SDL_PumpEvents();

	
	if ( SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS) <= 0 )
		return 0;
	return 1;
}
Exemplo n.º 30
0
// events must be empty before calling this function
inline int check_for_events(int mask, SDL_events_vector& events)
{
	SDL_PumpEvents();
	return SDL_PeepEvents(&events[0], max_number_of_events, SDL_GETEVENT, mask
#ifdef MHE_HAS_SDL2
		,mask
#endif
		);
}