Example #1
0
/* The handler for updateevents
   Removes _all_ pending updateevents
 */
int updatehandler_eh(SDL_Event * event)
{
    /* This is used to discard all update
       events on the queue, only necessary to perform once
    */
    static SDL_Event events[10];

    /* No updatefunction warrants an abort */
    assert(perform_update != NULL);
    assert(event != NULL);

#if 0
    {
	int retval = SDL_PeepEvents(events, 10, SDL_GETEVENT,
				SDL_EVENTMASK(SDL_USEREVENT));
	if (retval)
	    fprintf(stderr, "updatehandler_eh: Removed %d updateevents\n", retval);
    }
#else
    SDL_PeepEvents(events, 10, SDL_GETEVENT, SDL_EVENTMASK(SDL_USEREVENT));
#endif
   
    perform_update();

    return TRUE;
}
Example #2
0
int
mouse_poll(MOUSE_Event *ev) {
	int mask = 0, ret = 0;
	SDL_Event sdl_ev;

	if (ev) {
		ev->type   = MOUSE_EVENT_TYPE_NONE;
		ev->state  = MOUSE_EVENT_STATE_NONE;
		ev->button = 0;
		ev->x      = 0;
		ev->y      = 0;
	}

	SDL_PumpEvents();

	mask = (SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN) |
	        SDL_EVENTMASK(SDL_MOUSEBUTTONUP)   |
	        SDL_EVENTMASK(SDL_MOUSEMOTION));

	if (SDL_PeepEvents(&sdl_ev, 1, SDL_GETEVENT, mask) == 1) {
		if (ev) {
			switch (sdl_ev.type) {
				case SDL_MOUSEMOTION:
					ev->type = MOUSE_EVENT_TYPE_MOTION;

					ev->x = sdl_ev.motion.x;
					ev->y = sdl_ev.motion.y;
				break;

				case SDL_MOUSEBUTTONDOWN:
				case SDL_MOUSEBUTTONUP:
					ev->type = MOUSE_EVENT_TYPE_BUTTON;

					if (sdl_ev.button.state == SDL_PRESSED)  ev->state = MOUSE_EVENT_STATE_PRESSED;
					if (sdl_ev.button.state == SDL_RELEASED) ev->state = MOUSE_EVENT_STATE_RELEASED;

					ev->button = sdl_ev.button.button;

					ev->x = sdl_ev.button.x;
					ev->y = sdl_ev.button.y;
				break;
			}

			ret = (ev->state != MOUSE_EVENT_TYPE_NONE);
		}
	}

	return (ret);
}
Example #3
0
File: event.c Project: 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);
}
Example #4
0
void input_uevents(void)
{
    SDL_Event peek;
#if SDL_VERSION_ATLEAST(1,3,0)
    while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_USEREVENT, SDL_USEREVENT) > 0) {
#else
    while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_USEREVENT)) > 0) {
#endif
        void (*p) (void*) = (void (*)(void*)) peek.user.data1;
        p(peek.user.data2);
    }
}

#if SDL_VERSION_ATLEAST(1,3,0)
static void key_compat(struct inp_event *inp)
{
    if (!strcmp(inp->sym, "pageup"))
        strcpy(inp->sym, "page up");
    else if (!strcmp(inp->sym, "pagedown"))
        strcpy(inp->sym, "page down");
}
#endif
#ifdef IOS
static unsigned long touch_stamp = 0;
static int touch_num = 0;
#endif
int finger_pos(const char *finger, int *x, int *y, float *pressure)
{
#if SDL_VERSION_ATLEAST(2,0,0)
    SDL_TouchID tid;
    SDL_FingerID fid;
    SDL_Finger *f;
    int i, n;
#ifndef PRIx64
    if (sscanf(finger, "%llx:%llx", &fid, &tid) != 2)
        return -1;
#else
    if (sscanf(finger, "%"PRIx64":%"PRIx64, &fid, &tid) != 2)
        return -1;
#endif
    n = SDL_GetNumTouchFingers(tid);
    if (n <= 0)
        return -1;
    for (i = 0; i < n; i++) {
        f = SDL_GetTouchFinger(tid, i);
        if (f->id == fid) {
            if (pressure)
                *pressure = f->pressure;
            gfx_finger_pos_scale(f->x, f->y, x, y);
            return 0;
        }
    }
    return -1;
#else
    return -1;
#endif
}
void ONScripter::removeEvent(int type)
{
    SDL_Event event;
#if SDL_VERSION_ATLEAST(1, 3, 0)
    while(SDL_PeepEvents( &event, 1, SDL_GETEVENT, type, type) > 0);
#else
    while(SDL_PeepEvents( &event, 1, SDL_GETEVENT, SDL_EVENTMASK(type) ) > 0 );
#endif
}
Example #6
0
/*
===============
IN_GobbleMotionEvents
===============
*/
static void IN_GobbleMotionEvents( void )
{
	SDL_Event dummy[ 1 ];

	// Gobble any mouse motion events
	SDL_PumpEvents( );
	while( SDL_PeepEvents( dummy, 1, SDL_GETEVENT,
		SDL_EVENTMASK( SDL_MOUSEMOTION ) ) ) { }
}
Example #7
0
void SDLMouse::update()
{
  SDL_Event event;

	SDL_PumpEvents();

  while ( SDL_PeepEvents(&event, 1, SDL_GETEVENT, ( SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN) | SDL_EVENTMASK(SDL_MOUSEBUTTONUP) | SDL_EVENTMASK(SDL_MOUSEMOTION) ) ) > 0  )
  {
    if ( event.type == SDL_MOUSEBUTTONDOWN ) {
			cout << endl << " [EE] Mouse Pressed";
			if ( gui() != NULL ) {
				cout << " gui";
        gui()->mousePressed( event.button.x, event.button.y, translateMouseButtons( event.button.button ) );
			}
			cout << endl;
      onMousePressed( event.button.x, event.button.y, translateMouseButtons( event.button.button ) );

    } else if ( event.type == SDL_MOUSEBUTTONUP ) {
			cout << " [EE] Mouse Released" << endl << endl;
			if ( gui() != NULL ) {
				cout << " gui";
				gui()->mouseReleased( event.button.x, event.button.y, translateMouseButtons( event.button.button ) );
			}
			cout << endl;
			onMouseReleased( event.button.x, event.button.y, translateMouseButtons( event.button.button ) );

    } else if ( event.type == SDL_MOUSEMOTION ) {
      if ( gui() != NULL )
        gui()->mouseMove( event.button.x, event.button.y, translateMouseButtons( event.button.button ) );
      onMouseMove( event.button.x, event.button.y, translateMouseButtons( event.button.button ) );

    }

  }
	if ( gui() != NULL ) {
		Widget* w = gui()->lastMouseOverWidget();
		if ( w != NULL ) {
			int x, y;
			mousePos( x, y );
			MouseCursor* mc = w->getCursor( x - w->absoluteXPos(), y - w->absoluteYPos() );
			if ( mc != (MouseCursor*)pCursor ) {
				setCursor( mc );
			}
		}
/*		if ( gui()->lastMouseOverWidget() != pLastMouseOver ) {
			pLastMouseOver = gui()->lastMouseOverWidget();
			if ( pLastMouseOver != NULL ) {
				if ( (MouseCursor*)pCursor != pLastMouseOver->cursor() )
					setCursor( pLastMouseOver->cursor() );
			}
	}*/
	}

}
Example #8
0
CAMLprim value mlsdlevent_get_enabled(value unit)
{
  Uint32 mask = 0;
  register int i;
  for(i=0; i<SDL_TABLESIZE(evt_type_of_val); i++) {
    Uint8 type = evt_type_of_val[i];
    if(SDL_EventState(type, SDL_QUERY))
      mask |= SDL_EVENTMASK(type);
  }
  return Val_int(mask);
}
Example #9
0
CAMLprim value mlsdlevent_set_state_by_mask(value mask, value state)
{
  int c_state = ( state == Val_true ? SDL_ENABLE : SDL_DISABLE ) ;
  Uint32 c_mask = Int_val(mask);
  int i;
  for(i=0; i<SDL_TABLESIZE(evt_type_of_val); i++) {
    Uint8 type = evt_type_of_val[i];
    if(SDL_EVENTMASK(type) & c_mask)
      SDL_EventState(type, c_state);
  }
  return Val_unit;
}
InputHandler_SDL::InputHandler_SDL()
{
	SDL_InitSubSystem( SDL_INIT_JOYSTICK );

#ifdef _XBOX
	//strange hardware timing issue with 3rd party controllers
	Sleep(750);
#endif

	SDL_EnableKeyRepeat( 0, 0 );

	/* We can do this to get Unicode values in the key struct, which (with
	 * a little more work) will make us work better on international keyboards.
	 * Not all archs support this well. */
	// SDL_EnableUNICODE( 1 );

	//
	// Init joysticks
	//
	int iNumJoySticks = min( SDL_NumJoysticks(), NUM_JOYSTICKS );
	LOG->Info( "Found %d joysticks", iNumJoySticks );
	int i;
	for( i=0; i<iNumJoySticks; i++ )
	{
		SDL_Joystick *pJoystick = SDL_JoystickOpen( i );

		if(pJoystick == NULL) {
			LOG->Info("   %d: '%s' Error opening: %s",
				i, SDL_JoystickName(i), SDL_GetError());
			continue;
		}

		LOG->Info( "   %d: '%s' axes: %d, hats: %d, buttons: %d",
			i,
			SDL_JoystickName(i),
			SDL_JoystickNumAxes(pJoystick),
			SDL_JoystickNumHats(pJoystick),
			SDL_JoystickNumButtons(pJoystick) );

		/* For some weird reason, we won't get any joystick events at all
		 * if we don't keep the joystick open.  (Why?  The joystick event
		 * API is completely separate from the SDL_Joystick polling API ...) */
		Joysticks.push_back(pJoystick);
	}

	for(i = 0; Handled_SDL_Events[i] != -1; ++i)
	{
		mySDL_EventState(Handled_SDL_Events[i], SDL_ENABLE);
		SDL_EventMask2 |= SDL_EVENTMASK(Handled_SDL_Events[i]);
	}
}
Example #11
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
}
Example #12
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;
}
Example #13
0
void
EventQueue::Purge(Uint32 event,
                  bool (*match)(const SDL_Event &event, void *ctx),
                  void *ctx)
{
  SDL_Event events[256]; // is that enough?
#if SDL_VERSION_ATLEAST(1,3,0)
  int count = SDL_PeepEvents(events, 256, SDL_GETEVENT, event, event);
#else
  int count = SDL_PeepEvents(events, 256, SDL_GETEVENT, SDL_EVENTMASK(event));
#endif
  assert(count >= 0);

  SDL_Event *dest = events;
  for (const SDL_Event *src = events, *end = src + count; src != end; ++src)
    if (!match(*src, ctx))
      *dest++ = *src;

#if SDL_VERSION_ATLEAST(1,3,0)
  SDL_PeepEvents(events, dest - events, SDL_ADDEVENT, event, event);
#else
  SDL_PeepEvents(events, dest - events, SDL_ADDEVENT, SDL_EVENTMASK(event));
#endif
}
Example #14
0
/* Lock the event queue, take a peep at it, and unlock it */
int
SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
               Uint32 mask)
{
    int i, used;

    /* Don't look after we've quit */
    if (!SDL_EventQ.active) {
        return (-1);
    }
    /* Lock the event queue */
    used = 0;
    if (SDL_mutexP(SDL_EventQ.lock) == 0) {
        if (action == SDL_ADDEVENT) {
            for (i = 0; i < numevents; ++i) {
                used += SDL_AddEvent(&events[i]);
            }
        } else {
            SDL_Event tmpevent;
            int spot;

            /* If 'events' is NULL, just see if they exist */
            if (events == NULL) {
                action = SDL_PEEKEVENT;
                numevents = 1;
                events = &tmpevent;
            }
            spot = SDL_EventQ.head;
            while ((used < numevents) && (spot != SDL_EventQ.tail)) {
                if (mask & SDL_EVENTMASK(SDL_EventQ.event[spot].type)) {
                    events[used++] = SDL_EventQ.event[spot];
                    if (action == SDL_GETEVENT) {
                        spot = SDL_CutEvent(spot);
                    } else {
                        spot = (spot + 1) % MAXEVENTS;
                    }
                } else {
                    spot = (spot + 1) % MAXEVENTS;
                }
            }
        }
        SDL_mutexV(SDL_EventQ.lock);
    } else {
        SDL_SetError("Couldn't lock event queue");
        used = -1;
    }
    return (used);
}
Example #15
0
static void discard(Uint32 event_mask)
{
	SDL_Event temp_event;
	std::vector< SDL_Event > keepers;
	SDL_Delay(10);
	while(SDL_PollEvent(&temp_event) > 0) {
		if((SDL_EVENTMASK(temp_event.type) & event_mask) == 0) {
			keepers.push_back( temp_event );
		}
	}

	//FIXME: there is a chance new events are added before kept events are replaced
	for (unsigned int i=0; i < keepers.size(); ++i)
	{
		if(SDL_PushEvent(&keepers[i]) != 0) {
			ERR_GEN << "failed to return an event to the queue.";
		}
	}
}
Example #16
0
void menu::handle_event(const SDL_Event& event)
{
	scrollarea::handle_event(event);
	if (height()==0 || hidden())
		return;

	if(event.type == SDL_KEYDOWN) {
		// Only pass key events if we have the focus
		if (focus(&event))
			key_press(event.key.keysym.sym);
	} else if(!mouse_locked() && ((event.type == SDL_MOUSEBUTTONDOWN &&
	         (event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT)) ||
	         event.type == DOUBLE_CLICK_EVENT)) {

		int x = 0;
		int y = 0;
		if(event.type == SDL_MOUSEBUTTONDOWN) {
			x = event.button.x;
			y = event.button.y;
		} else {
			x = reinterpret_cast<long>(event.user.data1);
			y = reinterpret_cast<long>(event.user.data2);
		}

		const int item = hit(x,y);
		if(item != -1) {
			set_focus(true);
			move_selection_to(item);

			if(click_selects_) {
				show_result_ = true;
			}

			if(event.type == DOUBLE_CLICK_EVENT) {
				if (ignore_next_doubleclick_) {
					ignore_next_doubleclick_ = false;
				} else {
					double_clicked_ = true;
					last_was_doubleclick_ = true;
					if(!silent_) {
						sound::play_UI_sound(game_config::sounds::button_press);
					}
				}
			} else if (last_was_doubleclick_) {
				// If we have a double click as the next event, it means
				// this double click was generated from a click that
				// already has helped in generating a double click.
				SDL_Event ev;
				SDL_PeepEvents(&ev, 1, SDL_PEEKEVENT,
							   SDL_EVENTMASK(DOUBLE_CLICK_EVENT));
				if (ev.type == DOUBLE_CLICK_EVENT) {
					ignore_next_doubleclick_ = true;
				}
				last_was_doubleclick_ = false;
			}
		}


		if(sorter_ != NULL) {
			const int heading = hit_heading(x,y);
			if(heading >= 0 && sorter_->column_sortable(heading)) {
				sort_by(heading);
			}
		}
	} else if(!mouse_locked() && event.type == SDL_MOUSEMOTION) {
		if(click_selects_) {
			const int item = hit(event.motion.x,event.motion.y);
			const bool out = (item == -1);
			if (out_ != out) {
					out_ = out;
					invalidate_row_pos(selected_);
			}
			if (item != -1) {
				move_selection_to(item);
			}
		}

		const int heading_item = hit_heading(event.motion.x,event.motion.y);
		if(heading_item != highlight_heading_) {
			highlight_heading_ = heading_item;
			invalidate_heading();
		}
	}
}
Example #17
0
void
EventQueue::Purge(EventLoop::Callback callback, void *ctx)
{
  MatchCallbackData data { (void *)callback, ctx };
  Purge(SDL_EVENTMASK(EVENT_CALLBACK), MatchCallback, (void *)&data);
}
Example #18
0
void
EventQueue::Purge(Window &window)
{
  Purge(SDL_EVENTMASK(EVENT_USER),
        match_window, (void *)&window);
}
Example #19
0
void controller_base::handle_event(const SDL_Event& event)
{
	if(gui::in_dialog()) {
		return;
	}
	static const hotkey::hotkey_command& quit_hotkey = hotkey::hotkey_command::get_command_by_command(hotkey::HOTKEY_QUIT_GAME);

	switch(event.type) {
	case SDL_KEYDOWN:
		// Detect key press events, unless there something that has keyboard focus
		// in which case the key press events should go only to it.
		if(have_keyboard_focus()) {
			if(event.key.keysym.sym == SDLK_ESCAPE) {
				hotkey::execute_command(get_display(), quit_hotkey, get_hotkey_command_executor());
				break;
			}

			process_keydown_event(event);
			hotkey::key_event(get_display(), event, get_hotkey_command_executor());
		} else {
			process_focus_keydown_event(event);
			break;
		}
		// intentionally fall-through
	case SDL_KEYUP:
		process_keyup_event(event);
		break;
	case SDL_JOYBUTTONDOWN:
		process_keydown_event(event);
		hotkey::jbutton_event(get_display(), event, get_hotkey_command_executor());
		break;
	case SDL_JOYHATMOTION:
		process_keydown_event(event);
		hotkey::jhat_event(get_display(), event, get_hotkey_command_executor());
		break;
	case SDL_MOUSEMOTION:
		// Ignore old mouse motion events in the event queue
		SDL_Event new_event;
		if(SDL_PeepEvents(&new_event,1,SDL_GETEVENT,
					SDL_EVENTMASK(SDL_MOUSEMOTION)) > 0) {
			while(SDL_PeepEvents(&new_event,1,SDL_GETEVENT,
						SDL_EVENTMASK(SDL_MOUSEMOTION)) > 0) {};
			get_mouse_handler_base().mouse_motion_event(new_event.motion, is_browsing());
		} else {
			get_mouse_handler_base().mouse_motion_event(event.motion, is_browsing());
		}
		break;
	case SDL_MOUSEBUTTONDOWN:
		process_keydown_event(event);
		get_mouse_handler_base().mouse_press(event.button, is_browsing());
		if (get_mouse_handler_base().get_show_menu()){
			show_menu(get_display().get_theme().context_menu()->items(),event.button.x,event.button.y,true, get_display());
		}
		hotkey::mbutton_event(get_display(), event, get_hotkey_command_executor());
		break;
	case SDL_MOUSEBUTTONUP:
		get_mouse_handler_base().mouse_press(event.button, is_browsing());
		if (get_mouse_handler_base().get_show_menu()){
			show_menu(get_display().get_theme().context_menu()->items(),event.button.x,event.button.y,true, get_display());
		}
		break;
#if !SDL_VERSION_ATLEAST(2, 0, 0)
	case SDL_ACTIVEEVENT:
		if (event.active.state == SDL_APPMOUSEFOCUS && event.active.gain == 0) {
			if (get_mouse_handler_base().is_dragging()) {
				//simulate mouse button up when the app has lost mouse focus
				//this should be a general fix for the issue when the mouse
				//is dragged out of the game window and then the button is released
				int x, y;
				Uint8 mouse_flags = SDL_GetMouseState(&x, &y);
				if ((mouse_flags & SDL_BUTTON_LEFT) == 0) {
					get_mouse_handler_base().mouse_press(event.button, is_browsing());
				}
			}
		}
		break;
#endif
#if SDL_VERSION_ATLEAST(2,0,0)
	case SDL_MOUSEWHEEL:
		get_mouse_handler_base().mouse_wheel(event.wheel.x, event.wheel.y, is_browsing());
		break;
#endif
	default:
		break;
	}
}
Example #20
0
void controller_base::handle_event(const SDL_Event& event)
{
	if(gui::in_dialog()) {
		return;
	}

	switch(event.type) {
	case SDL_KEYDOWN:
		// Detect key press events, unless there something that has keyboard focus
		// in which case the key press events should go only to it.
		if(have_keyboard_focus()) {
			process_keydown_event(event);
			hotkey::key_event(get_display(), event.key,this);
		} else {
			process_focus_keydown_event(event);
			break;
		}
		// intentionally fall-through
	case SDL_KEYUP:
		process_keyup_event(event);
		break;
	case SDL_JOYBUTTONDOWN:
		process_keydown_event(event);
		hotkey::jbutton_event(get_display(), event.jbutton, this);
		break;
	case SDL_JOYHATMOTION:
		process_keydown_event(event);
		hotkey::jhat_event(get_display(), event.jhat, this);
		break;
	case SDL_MOUSEMOTION:
		// Ignore old mouse motion events in the event queue
		SDL_Event new_event;
		if(SDL_PeepEvents(&new_event,1,SDL_GETEVENT,
					SDL_EVENTMASK(SDL_MOUSEMOTION)) > 0) {
			while(SDL_PeepEvents(&new_event,1,SDL_GETEVENT,
						SDL_EVENTMASK(SDL_MOUSEMOTION)) > 0) {};
			get_mouse_handler_base().mouse_motion_event(new_event.motion, browse_);
		} else {
			get_mouse_handler_base().mouse_motion_event(event.motion, browse_);
		}
		break;
	case SDL_MOUSEBUTTONDOWN:
		process_keydown_event(event);
		hotkey::mbutton_event(get_display(), event.button, this);
		// intentionally fall-through
	case SDL_MOUSEBUTTONUP:
		get_mouse_handler_base().mouse_press(event.button, browse_);
		if (get_mouse_handler_base().get_show_menu()){
			show_menu(get_display().get_theme().context_menu()->items(),event.button.x,event.button.y,true);
		}
		break;
	case SDL_ACTIVEEVENT:
		if (event.active.state == SDL_APPMOUSEFOCUS && event.active.gain == 0) {
			if (get_mouse_handler_base().is_dragging()) {
				//simulate mouse button up when the app has lost mouse focus
				//this should be a general fix for the issue when the mouse
				//is dragged out of the game window and then the button is released
				int x, y;
				Uint8 mouse_flags = SDL_GetMouseState(&x, &y);
				if ((mouse_flags & SDL_BUTTON_LEFT) == 0) {
					get_mouse_handler_base().mouse_press(event.button, browse_);
				}
			}
		}
		break;
	default:
		break;
	}
}
Example #21
0
void pump()
{
	SDL_PumpEvents();

	pump_info info;

	//used to keep track of double click events
	static int last_mouse_down = -1;
	static int last_click_x = -1, last_click_y = -1;

	SDL_Event temp_event;
	int poll_count = 0;
	int begin_ignoring = 0;
	std::vector< SDL_Event > events;
	while(SDL_PollEvent(&temp_event)) {
		++poll_count;
		if(!begin_ignoring && temp_event.type == SDL_ACTIVEEVENT) {
			begin_ignoring = poll_count;
		} else if(begin_ignoring > 0 && SDL_EVENTMASK(temp_event.type)&INPUT_MASK) {
			//ignore user input events that occurred after the window was activated
			continue;
		}
		events.push_back(temp_event);
	}
	std::vector<SDL_Event>::iterator ev_it = events.begin();
	for(int i=1; i < begin_ignoring; ++i){
		if(SDL_EVENTMASK(ev_it->type)&INPUT_MASK) {
			//ignore user input events that occurred before the window was activated
			ev_it = events.erase(ev_it);
		} else {
			++ev_it;
		}
	}
	std::vector<SDL_Event>::iterator ev_end = events.end();
	for(ev_it = events.begin(); ev_it != ev_end; ++ev_it){
		SDL_Event &event = *ev_it;
		switch(event.type) {

			case SDL_ACTIVEEVENT: {
				SDL_ActiveEvent& ae = reinterpret_cast<SDL_ActiveEvent&>(event);
				if((ae.state & SDL_APPMOUSEFOCUS) != 0 || (ae.state & SDL_APPINPUTFOCUS) != 0) {
					cursor::set_focus(ae.gain != 0);
				}
				break;
			}

			//if the window must be redrawn, update the entire screen
			case SDL_VIDEOEXPOSE: {
				update_whole_screen();
				break;
			}

			case SDL_VIDEORESIZE: {
				const SDL_ResizeEvent* const resize = reinterpret_cast<SDL_ResizeEvent*>(&event);
				info.resize_dimensions.first = resize->w;
				info.resize_dimensions.second = resize->h;
				break;
			}

			case SDL_MOUSEMOTION: {
				//always make sure a cursor is displayed if the
				//mouse moves or if the user clicks
				cursor::set_focus(true);
				raise_help_string_event(event.motion.x,event.motion.y);
				break;
			}

			case SDL_MOUSEBUTTONDOWN: {
				//always make sure a cursor is displayed if the
				//mouse moves or if the user clicks
				cursor::set_focus(true);
				if(event.button.button == SDL_BUTTON_LEFT) {
					static const int DoubleClickTime = 500;
					static const int DoubleClickMaxMove = 3;
					if(last_mouse_down >= 0 && info.ticks() - last_mouse_down < DoubleClickTime &&
					   abs(event.button.x - last_click_x) < DoubleClickMaxMove &&
					   abs(event.button.y - last_click_y) < DoubleClickMaxMove) {
						SDL_UserEvent user_event;
						user_event.type = DOUBLE_CLICK_EVENT;
						user_event.code = 0;
						user_event.data1 = reinterpret_cast<void*>(event.button.x);
						user_event.data2 = reinterpret_cast<void*>(event.button.y);
						::SDL_PushEvent(reinterpret_cast<SDL_Event*>(&user_event));
					}
					last_mouse_down = info.ticks();
					last_click_x = event.button.x;
					last_click_y = event.button.y;
				}
				break;
			}

#if defined(_X11) && !defined(__APPLE__)
			case SDL_SYSWMEVENT: {
				//clipboard support for X11
				handle_system_event(event);
				break;
			}
#endif

			case SDL_QUIT: {
				throw CVideo::quit();
			}
		}

		if(event_contexts.empty() == false) {

			const std::vector<handler*>& event_handlers = event_contexts.back().handlers;

			//events may cause more event handlers to be added and/or removed,
			//so we must use indexes instead of iterators here.
			for(size_t i1 = 0, i2 = event_handlers.size(); i1 != i2 && i1 < event_handlers.size(); ++i1) {
				event_handlers[i1]->handle_event(event);
			}
		}
	}

	//inform the pump monitors that an events::pump() has occurred
	for(size_t i1 = 0, i2 = pump_monitors.size(); i1 != i2 && i1 < pump_monitors.size(); ++i1) {
		pump_monitors[i1]->process(info);
	}
}
Example #22
0
void SDL_FlushEvent(Uint32 type)
{
	events::discard(SDL_EVENTMASK(type));
}
int main_loop(SDL_Surface *screen,GUI::TimerSDL *timer,unsigned int flags,MainWindow *main_window) {
	GUI::KeycodesSDL keycode_sdl_translator;
	
	bool done=false;
	
	SDL_Event event;
	Uint32 last_click_tick=0;
	bool can_dblclick=false;
	while((!done) && (SDL_WaitEvent(&event))) {
		
		
		switch(event.type) {
			//case SDL_USEREVENT:
		//		HandleUserEvents(&event);
	//			break;
			case SDL_VIDEORESIZE:
				printf("??\n");	
	
				screen = SDL_SetVideoMode  (event.resize.w,event.resize.h, 32, flags);
				main_window->set_size( GUI::Size(event.resize.w,event.resize.h ) );
				
				main_window->redraw_all();
				main_window->update();
				
				break;
			case SDL_KEYUP:
			case SDL_KEYDOWN: {
                // Handle any key presses here.
		
				unsigned int mod=0;
				
				if (  event.key.keysym.mod & (KMOD_LSHIFT|KMOD_RSHIFT))
					mod|=GUI::KEY_MASK_SHIFT;
				
				if (  event.key.keysym.mod & (KMOD_LALT|KMOD_RALT))
					mod|=GUI::KEY_MASK_ALT;
				
				if (  event.key.keysym.mod & (KMOD_LCTRL|KMOD_RCTRL))
					mod|=GUI::KEY_MASK_CTRL;
								  

				if (  event.key.keysym.mod & (KMOD_LMETA|KMOD_RMETA)) {
#ifdef META_AS_ALT					
					mod|=GUI::KEY_MASK_ALT;
#else
					
					mod|=GUI::KEY_MASK_META;
#endif
				}
			

			
				main_window->key( event.key.keysym.unicode, keycode_sdl_translator.get_code(event.key.keysym.sym), event.key.state==SDL_PRESSED,false, mod );
				
				
				if (event.key.keysym.sym==SDLK_F12) {

					main_window->get_painter()->draw_fill_rect( GUI::Point() , GUI::Size( screen->w , screen->h ), GUI::Color(100,20,33) );
					SDL_UpdateRect(screen, 0,0,0,0);
				}

				//if (event.key.keysym.sym==SDLK_F2) {

				//painter->update_screen();
				//}

				if ((event.key.keysym.mod&KMOD_LSHIFT) && event.key.keysym.sym==SDLK_F12) {
					
					printf("DeadLocking Audio Thread on Purpose! (shift-f12)!!\n");
					SDL_LockAudio();
				}
				
//				printf("Pressed Key %s, unicode %i\n",Keyboard::get_code_name( keycode_sdl_translator.get_code(event.key.keysym.sym)).ascii().get_data(),event.key.keysym.unicode);
			} break;

			case SDL_MOUSEBUTTONUP:
			case SDL_MOUSEBUTTONDOWN: {
				
				
				do {
					
					Uint32 last_click_delta=0;
					
					
					if (event.button.type==SDL_MOUSEBUTTONDOWN && event.button.button==GUI::BUTTON_LEFT) {
						
						last_click_delta=SDL_GetTicks()-last_click_tick;
						last_click_tick=SDL_GetTicks();
					}
					
																
					SDLMod	mod_state=SDL_GetModState();
	
					unsigned int mod=0;
					
					if (  mod_state & (KMOD_LSHIFT|KMOD_RSHIFT))
						mod|=GUI::KEY_MASK_SHIFT;
					
					if (  mod_state & (KMOD_LALT|KMOD_RALT))
						mod|=GUI::KEY_MASK_ALT;
					
					if (  mod_state & (KMOD_LCTRL|KMOD_RCTRL))
						mod|=GUI::KEY_MASK_CTRL;
									
					if (  mod_state & (KMOD_LMETA|KMOD_RMETA))
						mod|=GUI::KEY_MASK_META;
					
					
					main_window->mouse_button( GUI::Point( event.button.x, event.button.y ), event.button.button, event.button.type==SDL_MOUSEBUTTONDOWN, mod );
					
					if (can_dblclick && last_click_delta<250 && event.button.type==SDL_MOUSEBUTTONDOWN && event.button.button==GUI::BUTTON_LEFT) {
						main_window->mouse_doubleclick( GUI::Point( event.button.x, event.button.y ), mod );
						can_dblclick=false;
	
					} else
						can_dblclick=true;
					
				} while (SDL_PeepEvents(&event,1,SDL_GETEVENT,SDL_EVENTMASK(SDL_MOUSEMOTION))>0);

					
				
				
			} break;
				
			case SDL_MOUSEMOTION: {

				can_dblclick=false; //can't doubleclick! wah wah wah
				/* Motion compensation, in case there are MANY motion events pending */
				SDL_Event compensator;
				
				while (SDL_PeepEvents(&compensator,1,SDL_GETEVENT,SDL_EVENTMASK(SDL_MOUSEMOTION))>0) {
					
					event.motion.xrel+=compensator.motion.xrel;
					event.motion.yrel+=compensator.motion.yrel;
					event.motion.state=compensator.motion.state;
					event.motion.x=compensator.motion.x;
					event.motion.y=compensator.motion.y;
				}

				
				int state=event.motion.state&0xFF;
				SDLMod	mod_state=SDL_GetModState();

				if (  mod_state & (KMOD_LSHIFT|KMOD_RSHIFT))
					state|=GUI::KEY_MASK_SHIFT;
				
				if (  mod_state & (KMOD_LALT|KMOD_RALT))
					state|=GUI::KEY_MASK_ALT;
				
				if (  mod_state & (KMOD_LCTRL|KMOD_RCTRL))
					state|=GUI::KEY_MASK_CTRL;
								
				if (  mod_state & (KMOD_LMETA|KMOD_RMETA))
					state|=GUI::KEY_MASK_META;

				
				main_window->mouse_motion( GUI::Point( event.motion.x, event.motion.y ), GUI::Point( event.motion.xrel, event.motion.yrel ), state );
			} break;
				
			case SDL_USEREVENT: {
				
				if (event.user.code!=GUI::TimerSDL::SDL_TIMER_EVENT_CODE)
					break;
				
				GUI::TimerID *timer_id=(GUI::TimerID*)event.user.data1;
				timer->call(*timer_id);
			} break; 
			case SDL_QUIT:
				main_window->quit_request();
				break;

			default: {}
				break;

		}   // End switch
            

//		printf("check updates! - %i\n",i++);
		timer->loop_iterate();
		main_window->check_for_updates();
		//SDL_UpdateGUI::Rect   (screen, 0, 0, 0, 0);
		
		done=main_window->must_quit();
	}   // End while
        	
	return 0;
	
}
Example #24
0
bool is_input(const SDL_Event& event)
{
	return SDL_EVENTMASK(event.type) & INPUT_MASK;
}
Example #25
0
void
EventQueue::Purge(Notify &notify)
{
  Purge(SDL_EVENTMASK(EVENT_NOTIFY), match_notify, (void *)&notify);
}
Example #26
0
int PLATFORM_Keyboard(void)
{
	int shiftctrl = 0;
	SDL_Event event;

#if HAVE_WINDOWS_H
	/* Used to delay resize events on Windows 7, see above. */
	enum { RESIZE_INTERVAL = 500 };
	static int resize_delayed = FALSE;
	static int resize_needed = FALSE;
	static int resize_w, resize_h;
#endif /* HAVE_WINDOWS_H */

	/* Very ugly fix for SDL CAPSLOCK brokenness.  This will let the user
	 * press CAPSLOCK and get a brief keypress on the Atari but it is not
	 * possible to emulate holding down CAPSLOCK for longer periods with
	 * the broken SDL*/
	if (lastkey == SDLK_CAPSLOCK) {
		lastkey = SDLK_UNKNOWN;
	   	key_pressed = 0;
 		lastuni = 0;
	}

	if (SDL_PollEvent(&event)) {
		switch (event.type) {
		case SDL_KEYDOWN:
			lastkey = event.key.keysym.sym;
 			lastuni = event.key.keysym.unicode;
			key_pressed = 1;
			break;
		case SDL_KEYUP:
			lastkey = event.key.keysym.sym;
 			lastuni = 0; /* event.key.keysym.unicode is not defined for KEYUP */
			key_pressed = 0;
			/* ugly hack to fix broken SDL CAPSLOCK*/
			/* Because SDL is only sending Keydown and keyup for every change
			 * of state of the CAPSLOCK status, rather than the actual key.*/
			if(lastkey == SDLK_CAPSLOCK) {
				key_pressed = 1;
			}
			break;
		case SDL_VIDEORESIZE:
#if HAVE_WINDOWS_H
			/* Delay resize events on Windows 7, see above. */
			if (resize_delayed) {
				resize_w = event.resize.w;
				resize_h = event.resize.h;
				resize_needed = TRUE;
			} else {
				VIDEOMODE_SetWindowSize(event.resize.w, event.resize.h);
				resize_delayed = TRUE;
				if (SDL_AddTimer(RESIZE_INTERVAL, &ResizeDelayCallback, NULL) == NULL) {
					Log_print("Error: SDL_AddTimer failed: %s", SDL_GetError());
					Log_flushlog();
					exit(-1);
				}
			}
#else
			VIDEOMODE_SetWindowSize(event.resize.w, event.resize.h);
#endif /* HAVE_WINDOWS_H */
			break;
		case SDL_VIDEOEXPOSE:
			/* When window is "uncovered", and we are in the emulator's menu,
			   we need to refresh display manually. */
			PLATFORM_DisplayScreen();
			break;
		case SDL_QUIT:
			return AKEY_EXIT;
			break;
#if HAVE_WINDOWS_H
		case SDL_USEREVENT:
			/* Process delayed video resize on Windows 7, see above. */
			if (event.user.code == USER_EVENT_RESIZE_DELAY) {
				if (resize_needed) {
					SDL_Event events[1];
					resize_needed = FALSE;
					/* If there's a resize event in the queue,
					   wait for it and don't resize now. */
					if (SDL_PeepEvents(events, 1, SDL_PEEKEVENT, SDL_EVENTMASK(SDL_VIDEORESIZE)) != 0)
						resize_delayed = FALSE;
					else {
						VIDEOMODE_SetWindowSize(resize_w, resize_h);
						if (SDL_AddTimer(RESIZE_INTERVAL, &ResizeDelayCallback, NULL) == NULL) {
							Log_print("Error: SDL_AddTimer failed: %s", SDL_GetError());
							Log_flushlog();
							exit(-1);
						}
					}
				} else
					resize_delayed = FALSE;
			}
			break;
#endif /* HAVE_WINDOWS_H */
		}
	}
	else if (!key_pressed)
		return AKEY_NONE;

	kbhits = SDL_GetKeyState(NULL);

	if (kbhits == NULL) {
		Log_print("oops, kbhits is NULL!");
		Log_flushlog();
		exit(-1);
	}

	UI_alt_function = -1;
	if (kbhits[SDLK_LALT]) {
		if (key_pressed) {
			switch (lastkey) {
			case SDLK_f:
				key_pressed = 0;
				VIDEOMODE_ToggleWindowed();
				break;
			case SDLK_x:
				if (INPUT_key_shift) {
					key_pressed = 0;
					VIDEOMODE_Toggle80Column();
				}
				break;
			case SDLK_g:
				key_pressed = 0;
				VIDEOMODE_ToggleHorizontalArea();
				break;
			case SDLK_j:
				key_pressed = 0;
				SwapJoysticks();
				break;
			case SDLK_r:
				UI_alt_function = UI_MENU_RUN;
				break;
			case SDLK_y:
				UI_alt_function = UI_MENU_SYSTEM;
				break;
			case SDLK_o:
				UI_alt_function = UI_MENU_SOUND;
				break;
			case SDLK_w:
				UI_alt_function = UI_MENU_SOUND_RECORDING;
				break;
			case SDLK_a:
				UI_alt_function = UI_MENU_ABOUT;
				break;
			case SDLK_s:
				UI_alt_function = UI_MENU_SAVESTATE;
				break;
			case SDLK_d:
				UI_alt_function = UI_MENU_DISK;
				break;
			case SDLK_l:
				UI_alt_function = UI_MENU_LOADSTATE;
				break;
			case SDLK_c:
				UI_alt_function = UI_MENU_CARTRIDGE;
				break;
			case SDLK_BACKSLASH:
				return AKEY_PBI_BB_MENU;
			case SDLK_m:
				grab_mouse = !grab_mouse;
				SDL_WM_GrabInput(grab_mouse ? SDL_GRAB_ON : SDL_GRAB_OFF);
				key_pressed = 0;
				break;
			case SDLK_1:
				key_pressed = 0;
				if (Atari800_tv_mode == Atari800_TV_NTSC) {
					if (kbhits[SDLK_LSHIFT]) {
						if (COLOURS_NTSC_specific_setup.hue > COLOURS_NTSC_HUE_MIN)
							COLOURS_NTSC_specific_setup.hue -= 0.02;
					} else {
						if (COLOURS_NTSC_specific_setup.hue < COLOURS_NTSC_HUE_MAX)
							COLOURS_NTSC_specific_setup.hue += 0.02;
					}
					Colours_Update();
				}
				break;
			case SDLK_2:
				key_pressed = 0;
				if (kbhits[SDLK_LSHIFT]) {
					if (Colours_setup->saturation > COLOURS_SATURATION_MIN)
						Colours_setup->saturation -= 0.02;
				} else {
					if (Colours_setup->saturation < COLOURS_SATURATION_MAX)
						Colours_setup->saturation += 0.02;
				}
				Colours_Update();
				break;
			case SDLK_3:
				key_pressed = 0;
				if (kbhits[SDLK_LSHIFT]) {
					if (Colours_setup->contrast > COLOURS_CONTRAST_MIN)
						Colours_setup->contrast -= 0.04;
				} else {
					if (Colours_setup->contrast < COLOURS_CONTRAST_MAX)
					Colours_setup->contrast += 0.04;
				}
				Colours_Update();
				break;
			case SDLK_4:
				key_pressed = 0;
				if (kbhits[SDLK_LSHIFT]) {
					if (Colours_setup->brightness > COLOURS_BRIGHTNESS_MIN)
						Colours_setup->brightness -= 0.04;
				} else {
					if (Colours_setup->brightness < COLOURS_BRIGHTNESS_MAX)
						Colours_setup->brightness += 0.04;
				}
				Colours_Update();
				break;
			case SDLK_5:
				key_pressed = 0;
				if (kbhits[SDLK_LSHIFT]) {
					if (Colours_setup->gamma > COLOURS_GAMMA_MIN)
						Colours_setup->gamma -= 0.02;
				} else {
					if (Colours_setup->gamma < COLOURS_GAMMA_MAX)
						Colours_setup->gamma += 0.02;
				}
				Colours_Update();
				break;
			case SDLK_6:
				key_pressed = 0;
				if (Atari800_tv_mode == Atari800_TV_NTSC) {
					if (kbhits[SDLK_LSHIFT]) {
						if (COLOURS_NTSC_specific_setup.color_delay > COLOURS_NTSC_DELAY_MIN)
							COLOURS_NTSC_specific_setup.color_delay -= 0.1;
					} else {
						if (COLOURS_NTSC_specific_setup.color_delay < COLOURS_NTSC_DELAY_MAX)
							COLOURS_NTSC_specific_setup.color_delay += 0.1;
					}
					Colours_Update();
				}
				break;
			case SDLK_LEFTBRACKET:
				key_pressed = 0;
				if (kbhits[SDLK_LSHIFT])
					SDL_VIDEO_SetScanlinesPercentage(SDL_VIDEO_scanlines_percentage - 5);
				else
					SDL_VIDEO_SetScanlinesPercentage(SDL_VIDEO_scanlines_percentage + 5);
				break;
			default:
				if(FILTER_NTSC_emu != NULL){
					switch(lastkey){
					case SDLK_7:
						key_pressed = 0;
						if (kbhits[SDLK_LSHIFT]) {
							if (FILTER_NTSC_setup.sharpness > FILTER_NTSC_SHARPNESS_MIN)
								FILTER_NTSC_setup.sharpness -= 0.02;
						} else {
							if (FILTER_NTSC_setup.sharpness < FILTER_NTSC_SHARPNESS_MAX)
								FILTER_NTSC_setup.sharpness += 0.02;
						}
						FILTER_NTSC_Update(FILTER_NTSC_emu);
						break;
					case SDLK_8:
						key_pressed = 0;
						if (kbhits[SDLK_LSHIFT]) {
							if (FILTER_NTSC_setup.resolution > FILTER_NTSC_RESOLUTION_MIN)
								FILTER_NTSC_setup.resolution -= 0.02;
						} else {
							if (FILTER_NTSC_setup.resolution < FILTER_NTSC_RESOLUTION_MAX)
								FILTER_NTSC_setup.resolution += 0.02;
						}
						FILTER_NTSC_Update(FILTER_NTSC_emu);
						break;
					case SDLK_9:
						key_pressed = 0;
						if (kbhits[SDLK_LSHIFT]) {
							if (FILTER_NTSC_setup.artifacts > FILTER_NTSC_ARTIFACTS_MIN)
								FILTER_NTSC_setup.artifacts -= 0.02;
						} else {
							if (FILTER_NTSC_setup.artifacts < FILTER_NTSC_ARTIFACTS_MAX)
								FILTER_NTSC_setup.artifacts += 0.02;
						}
						FILTER_NTSC_Update(FILTER_NTSC_emu);
						break;
					case SDLK_0:
						key_pressed = 0;
						if (kbhits[SDLK_LSHIFT]) {
							if (FILTER_NTSC_setup.fringing > FILTER_NTSC_FRINGING_MIN)
								FILTER_NTSC_setup.fringing -= 0.02;
						} else {
							if (FILTER_NTSC_setup.fringing < FILTER_NTSC_FRINGING_MAX)
								FILTER_NTSC_setup.fringing += 0.02;
						}
						FILTER_NTSC_Update(FILTER_NTSC_emu);
						break;
					case SDLK_MINUS:
						key_pressed = 0;
						if (kbhits[SDLK_LSHIFT]) {
							if (FILTER_NTSC_setup.bleed > FILTER_NTSC_BLEED_MIN)
								FILTER_NTSC_setup.bleed -= 0.02;
						} else {
							if (FILTER_NTSC_setup.bleed < FILTER_NTSC_BLEED_MAX)
								FILTER_NTSC_setup.bleed += 0.02;
						}
						FILTER_NTSC_Update(FILTER_NTSC_emu);
						break;
					case SDLK_EQUALS:
						key_pressed = 0;
						if (kbhits[SDLK_LSHIFT]) {
							if (FILTER_NTSC_setup.burst_phase > FILTER_NTSC_BURST_PHASE_MIN)
								FILTER_NTSC_setup.burst_phase -= 0.02;
						} else {
							if (FILTER_NTSC_setup.burst_phase < FILTER_NTSC_BURST_PHASE_MAX)
								FILTER_NTSC_setup.burst_phase += 0.02;
						}
						FILTER_NTSC_Update(FILTER_NTSC_emu);
						break;
					case SDLK_RIGHTBRACKET:
						key_pressed = 0;
						FILTER_NTSC_NextPreset();
						FILTER_NTSC_Update(FILTER_NTSC_emu);
						break;
					}
				}
			break;
			}
		}
	}

	/* SHIFT STATE */
	if ((kbhits[SDLK_LSHIFT]) || (kbhits[SDLK_RSHIFT]))
		INPUT_key_shift = 1;
	else
		INPUT_key_shift = 0;

    /* CONTROL STATE */
	if ((kbhits[SDLK_LCTRL]) || (kbhits[SDLK_RCTRL]))
		key_control = 1;
	else
		key_control = 0;

	/*
	if (event.type == 2 || event.type == 3) {
		Log_print("E:%x S:%x C:%x K:%x U:%x M:%x",event.type,INPUT_key_shift,key_control,lastkey,event.key.keysym.unicode,event.key.keysym.mod);
	}
	*/

	/* OPTION / SELECT / START keys */
	INPUT_key_consol = INPUT_CONSOL_NONE;
	if (kbhits[SDLK_F2])
		INPUT_key_consol &= (~INPUT_CONSOL_OPTION);
	if (kbhits[SDLK_F3])
		INPUT_key_consol &= (~INPUT_CONSOL_SELECT);
	if (kbhits[SDLK_F4])
		INPUT_key_consol &= (~INPUT_CONSOL_START);

	if (key_pressed == 0)
		return AKEY_NONE;

	/* Handle movement and special keys. */
	switch (lastkey) {
	case SDLK_F1:
		key_pressed = 0;
		return AKEY_UI;
	case SDLK_F5:
		key_pressed = 0;
		return INPUT_key_shift ? AKEY_COLDSTART : AKEY_WARMSTART;
	case SDLK_F8:
		UI_alt_function = UI_MENU_MONITOR;
		break;
	case SDLK_F9:
		return AKEY_EXIT;
	case SDLK_F10:
		key_pressed = 0;
		return INPUT_key_shift ? AKEY_SCREENSHOT_INTERLACE : AKEY_SCREENSHOT_INTERLACE;
	case SDLK_F12:
		key_pressed = 0;
		return AKEY_TURBO;
	}

	if (UI_alt_function != -1) {
		key_pressed = 0;
		return AKEY_UI;
	}

	/* keyboard joysticks: don't pass the keypresses to emulation
	 * as some games pause on a keypress (River Raid, Bruce Lee)
	 */
	if (!UI_is_active && PLATFORM_kbd_joy_0_enabled) {
		if (lastkey == KBD_STICK_0_LEFT || lastkey == KBD_STICK_0_RIGHT ||
			lastkey == KBD_STICK_0_UP || lastkey == KBD_STICK_0_DOWN || lastkey == KBD_TRIG_0) {
			key_pressed = 0;
			return AKEY_NONE;
		}
	}

	if (!UI_is_active && PLATFORM_kbd_joy_1_enabled) {
		if (lastkey == KBD_STICK_1_LEFT || lastkey == KBD_STICK_1_RIGHT ||
			lastkey == KBD_STICK_1_UP || lastkey == KBD_STICK_1_DOWN || lastkey == KBD_TRIG_1) {
			key_pressed = 0;
			return AKEY_NONE;
		}
	}

	if (INPUT_key_shift)
		shiftctrl ^= AKEY_SHFT;

	if (Atari800_machine_type == Atari800_MACHINE_5200 && !UI_is_active) {
		if (lastkey == SDLK_F4)
			return AKEY_5200_START ^ shiftctrl;
		switch (lastuni) {
		case 'p':
			return AKEY_5200_PAUSE ^ shiftctrl;
		case 'r':
			return AKEY_5200_RESET ^ shiftctrl;
		case '0':
			return AKEY_5200_0 ^ shiftctrl;
		case '1':
			return AKEY_5200_1 ^ shiftctrl;
		case '2':
			return AKEY_5200_2 ^ shiftctrl;
		case '3':
			return AKEY_5200_3 ^ shiftctrl;
		case '4':
			return AKEY_5200_4 ^ shiftctrl;
		case '5':
			return AKEY_5200_5 ^ shiftctrl;
		case '6':
			return AKEY_5200_6 ^ shiftctrl;
		case '7':
			return AKEY_5200_7 ^ shiftctrl;
		case '8':
			return AKEY_5200_8 ^ shiftctrl;
		case '9':
			return AKEY_5200_9 ^ shiftctrl;
		case '#':
		case '=':
			return AKEY_5200_HASH ^ shiftctrl;
		case '*':
			return AKEY_5200_ASTERISK ^ shiftctrl;
		}
		return AKEY_NONE;
	}

	if (key_control)
		shiftctrl ^= AKEY_CTRL;

	switch (lastkey) {
	case SDLK_BACKQUOTE: /* fallthrough */
		/* These are the "Windows" keys, but they don't work on Windows*/
	case SDLK_LSUPER:
		return AKEY_ATARI ^ shiftctrl;
	case SDLK_RSUPER:
		if (INPUT_key_shift)
			return AKEY_CAPSLOCK;
		else
			return AKEY_CAPSTOGGLE;
	case SDLK_END:
	case SDLK_F6:
		return AKEY_HELP ^ shiftctrl;
	case SDLK_PAGEDOWN:
		return AKEY_F2 | AKEY_SHFT;
	case SDLK_PAGEUP:
		return AKEY_F1 | AKEY_SHFT;
	case SDLK_HOME:
		return key_control ? AKEY_LESS|shiftctrl : AKEY_CLEAR;
	case SDLK_PAUSE:
	case SDLK_F7:
		return AKEY_BREAK;
	case SDLK_CAPSLOCK:
		if (INPUT_key_shift)
			return AKEY_CAPSLOCK|shiftctrl;
		else
			return AKEY_CAPSTOGGLE|shiftctrl;
	case SDLK_SPACE:
		return AKEY_SPACE ^ shiftctrl;
	case SDLK_BACKSPACE:
		return AKEY_BACKSPACE|shiftctrl;
	case SDLK_RETURN:
		return AKEY_RETURN ^ shiftctrl;
	case SDLK_LEFT:
		return (INPUT_key_shift ? AKEY_PLUS : AKEY_LEFT) ^ shiftctrl;
	case SDLK_RIGHT:
		return (INPUT_key_shift ? AKEY_ASTERISK : AKEY_RIGHT) ^ shiftctrl;
	case SDLK_UP:
		return (INPUT_key_shift ? AKEY_MINUS : AKEY_UP) ^ shiftctrl;
	case SDLK_DOWN:
		return (INPUT_key_shift ? AKEY_EQUAL : AKEY_DOWN) ^ shiftctrl;
	case SDLK_ESCAPE:
		/* Windows takes ctrl+esc and ctrl+shift+esc */
		return AKEY_ESCAPE ^ shiftctrl;
	case SDLK_TAB:
#if HAVE_WINDOWS_H
		/* On Windows, when an SDL window has focus and LAlt+Tab is pressed,
		   a window-switching menu appears, but the LAlt+Tab key sequence is
		   still forwarded to the SDL window. In the effect the user cannot
		   switch with LAlt+Tab without the emulator registering unwanted key
		   presses. On other operating systems (e.g. GNU/Linux/KDE) everything
		   is OK, the key sequence is not registered by the emulator. This
		   hack fixes the behaviour on Windows. */
		if (kbhits[SDLK_LALT]) {
			key_pressed = 0;
			/* 1. In fullscreen software (non-OpenGL) mode, user presses LAlt, then presses Tab.
			      Atari800 window gets minimised and the window-switching menu appears.
			   2. User switches back to Atari800 without releasing LAlt.
			   3. User releases LAlt. Atari800 gets switched back to fullscreen.
			   In the above situation, the emulator would register pressing of LAlt but
			   would not register releasing of the key. It would think that LAlt is still
			   pressed. The hack below fixes the issue by causing SDL to assume LAlt is
			   not pressed. */
#if HAVE_OPENGL
			if (!VIDEOMODE_windowed && !SDL_VIDEO_opengl)
#else
			if (!VIDEOMODE_windowed)
#endif /* HAVE_OPENGL */
				kbhits[SDLK_LALT] = 0;
			return AKEY_NONE;
		}
#endif /* HAVE_WINDOWS_H */
		return AKEY_TAB ^ shiftctrl;
	case SDLK_DELETE:
		if (INPUT_key_shift)
			return AKEY_DELETE_LINE|shiftctrl;
		else
			return AKEY_DELETE_CHAR;
	case SDLK_INSERT:
		if (INPUT_key_shift)
			return AKEY_INSERT_LINE|shiftctrl;
		else
			return AKEY_INSERT_CHAR;
	}
	if (INPUT_cx85) switch (lastkey) {
	case SDLK_KP1:
		return AKEY_CX85_1;
	case SDLK_KP2:
		return AKEY_CX85_2;
	case SDLK_KP3:
		return AKEY_CX85_3;
	case SDLK_KP4:
		return AKEY_CX85_4;
	case SDLK_KP5:
		return AKEY_CX85_5;
	case SDLK_KP6:
		return AKEY_CX85_6;
	case SDLK_KP7:
		return AKEY_CX85_7;
	case SDLK_KP8:
		return AKEY_CX85_8;
	case SDLK_KP9:
		return AKEY_CX85_9;
	case SDLK_KP0:
		return AKEY_CX85_0;
	case SDLK_KP_PERIOD:
		return AKEY_CX85_PERIOD;
	case SDLK_KP_MINUS:
		return AKEY_CX85_MINUS;
	case SDLK_KP_ENTER:
		return AKEY_CX85_PLUS_ENTER;
	case SDLK_KP_DIVIDE:
		return (key_control ? AKEY_CX85_ESCAPE : AKEY_CX85_NO);
	case SDLK_KP_MULTIPLY:
		return AKEY_CX85_DELETE;
	case SDLK_KP_PLUS:
		return AKEY_CX85_YES;
	}

	/* Handle CTRL-0 to CTRL-9 and other control characters */
	if (key_control) {
		switch(lastuni) {
		case '.':
			return AKEY_FULLSTOP|shiftctrl;
		case ',':
			return AKEY_COMMA|shiftctrl;
		case ';':
			return AKEY_SEMICOLON|shiftctrl;
		}
		switch (lastkey) {
		case SDLK_PERIOD:
			return AKEY_FULLSTOP|shiftctrl;
		case SDLK_COMMA:
			return AKEY_COMMA|shiftctrl;
		case SDLK_SEMICOLON:
			return AKEY_SEMICOLON|shiftctrl;
		case SDLK_SLASH:
			return AKEY_SLASH|shiftctrl;
		case SDLK_BACKSLASH:
			/* work-around for Windows */
			return AKEY_ESCAPE|shiftctrl;
		case SDLK_0:
			return AKEY_CTRL_0|shiftctrl;
		case SDLK_1:
			return AKEY_CTRL_1|shiftctrl;
		case SDLK_2:
			return AKEY_CTRL_2|shiftctrl;
		case SDLK_3:
			return AKEY_CTRL_3|shiftctrl;
		case SDLK_4:
			return AKEY_CTRL_4|shiftctrl;
		case SDLK_5:
			return AKEY_CTRL_5|shiftctrl;
		case SDLK_6:
			return AKEY_CTRL_6|shiftctrl;
		case SDLK_7:
			return AKEY_CTRL_7|shiftctrl;
		case SDLK_8:
			return AKEY_CTRL_8|shiftctrl;
		case SDLK_9:
			return AKEY_CTRL_9|shiftctrl;
		}
	}

	/* Host Caps Lock will make lastuni switch case, so prevent this*/
    if(lastuni>='A' && lastuni <= 'Z' && !INPUT_key_shift) lastuni += 0x20;
    if(lastuni>='a' && lastuni <= 'z' && INPUT_key_shift) lastuni -= 0x20;
	/* Uses only UNICODE translation, no shift states (this was added to
	 * support non-US keyboard layouts)*/
	/* input.c takes care of removing invalid shift+control keys */
	switch (lastuni) {
	case 1:
		return AKEY_CTRL_a|shiftctrl;
	case 2:
		return AKEY_CTRL_b|shiftctrl;
	case 3:
		return AKEY_CTRL_c|shiftctrl;
	case 4:
		return AKEY_CTRL_d|shiftctrl;
	case 5:
		return AKEY_CTRL_e|shiftctrl;
	case 6:
		return AKEY_CTRL_f|shiftctrl;
	case 7:
		return AKEY_CTRL_g|shiftctrl;
	case 8:
		return AKEY_CTRL_h|shiftctrl;
	case 9:
		return AKEY_CTRL_i|shiftctrl;
	case 10:
		return AKEY_CTRL_j|shiftctrl;
	case 11:
		return AKEY_CTRL_k|shiftctrl;
	case 12:
		return AKEY_CTRL_l|shiftctrl;
	case 13:
		return AKEY_CTRL_m|shiftctrl;
	case 14:
		return AKEY_CTRL_n|shiftctrl;
	case 15:
		return AKEY_CTRL_o|shiftctrl;
	case 16:
		return AKEY_CTRL_p|shiftctrl;
	case 17:
		return AKEY_CTRL_q|shiftctrl;
	case 18:
		return AKEY_CTRL_r|shiftctrl;
	case 19:
		return AKEY_CTRL_s|shiftctrl;
	case 20:
		return AKEY_CTRL_t|shiftctrl;
	case 21:
		return AKEY_CTRL_u|shiftctrl;
	case 22:
		return AKEY_CTRL_v|shiftctrl;
	case 23:
		return AKEY_CTRL_w|shiftctrl;
	case 24:
		return AKEY_CTRL_x|shiftctrl;
	case 25:
		return AKEY_CTRL_y|shiftctrl;
	case 26:
		return AKEY_CTRL_z|shiftctrl;
	case 'A':
		return AKEY_A;
	case 'B':
		return AKEY_B;
	case 'C':
		return AKEY_C;
	case 'D':
		return AKEY_D;
	case 'E':
		return AKEY_E;
	case 'F':
		return AKEY_F;
	case 'G':
		return AKEY_G;
	case 'H':
		return AKEY_H;
	case 'I':
		return AKEY_I;
	case 'J':
		return AKEY_J;
	case 'K':
		return AKEY_K;
	case 'L':
		return AKEY_L;
	case 'M':
		return AKEY_M;
	case 'N':
		return AKEY_N;
	case 'O':
		return AKEY_O;
	case 'P':
		return AKEY_P;
	case 'Q':
		return AKEY_Q;
	case 'R':
		return AKEY_R;
	case 'S':
		return AKEY_S;
	case 'T':
		return AKEY_T;
	case 'U':
		return AKEY_U;
	case 'V':
		return AKEY_V;
	case 'W':
		return AKEY_W;
	case 'X':
		return AKEY_X;
	case 'Y':
		return AKEY_Y;
	case 'Z':
		return AKEY_Z;
	case ':':
		return AKEY_COLON;
	case '!':
		return AKEY_EXCLAMATION;
	case '@':
		return AKEY_AT;
	case '#':
		return AKEY_HASH;
	case '$':
		return AKEY_DOLLAR;
	case '%':
		return AKEY_PERCENT;
	case '^':
		return AKEY_CARET;
	case '&':
		return AKEY_AMPERSAND;
	case '*':
		return AKEY_ASTERISK;
	case '(':
		return AKEY_PARENLEFT;
	case ')':
		return AKEY_PARENRIGHT;
	case '+':
		return AKEY_PLUS;
	case '_':
		return AKEY_UNDERSCORE;
	case '"':
		return AKEY_DBLQUOTE;
	case '?':
		return AKEY_QUESTION;
	case '<':
		return AKEY_LESS;
	case '>':
		return AKEY_GREATER;
	case 'a':
		return AKEY_a;
	case 'b':
		return AKEY_b;
	case 'c':
		return AKEY_c;
	case 'd':
		return AKEY_d;
	case 'e':
		return AKEY_e;
	case 'f':
		return AKEY_f;
	case 'g':
		return AKEY_g;
	case 'h':
		return AKEY_h;
	case 'i':
		return AKEY_i;
	case 'j':
		return AKEY_j;
	case 'k':
		return AKEY_k;
	case 'l':
		return AKEY_l;
	case 'm':
		return AKEY_m;
	case 'n':
		return AKEY_n;
	case 'o':
		return AKEY_o;
	case 'p':
		return AKEY_p;
	case 'q':
		return AKEY_q;
	case 'r':
		return AKEY_r;
	case 's':
		return AKEY_s;
	case 't':
		return AKEY_t;
	case 'u':
		return AKEY_u;
	case 'v':
		return AKEY_v;
	case 'w':
		return AKEY_w;
	case 'x':
		return AKEY_x;
	case 'y':
		return AKEY_y;
	case 'z':
		return AKEY_z;
	case ';':
		return AKEY_SEMICOLON;
	case '0':
		return AKEY_0;
	case '1':
		return AKEY_1;
	case '2':
		return AKEY_2;
	case '3':
		return AKEY_3;
	case '4':
		return AKEY_4;
	case '5':
		return AKEY_5;
	case '6':
		return AKEY_6;
	case '7':
		return AKEY_7;
	case '8':
		return AKEY_8;
	case '9':
		return AKEY_9;
	case ',':
		return AKEY_COMMA;
	case '.':
		return AKEY_FULLSTOP;
	case '=':
		return AKEY_EQUAL;
	case '-':
		return AKEY_MINUS;
	case '\'':
		return AKEY_QUOTE;
	case '/':
		return AKEY_SLASH;
	case '\\':
		return AKEY_BACKSLASH;
	case '[':
		return AKEY_BRACKETLEFT;
	case ']':
		return AKEY_BRACKETRIGHT;
	case '|':
		return AKEY_BAR;
	}

	return AKEY_NONE;
}
    //------------------------------------------------------------------------
    int platform_support::run()
    {
        SDL_Event event;
        bool ev_flag = false;

        for(;;)
        {
            if(m_specific->m_update_flag)
            {
                on_draw();
                update_window();
                m_specific->m_update_flag = false;
            }

            ev_flag = false;
            if(m_wait_mode)
            {
                SDL_WaitEvent(&event);
                ev_flag = true;
            }
            else
            {
                if(SDL_PollEvent(&event))
                {
                    ev_flag = true;
                }
                else
                {
                    on_idle();
                }
            }

            if(ev_flag)
            {
                if(event.type == SDL_QUIT)
                {
                    break;
                }

                int y;
                unsigned flags = 0;

                switch (event.type) 
                {
                case SDL_VIDEORESIZE:
                    if(!init(event.resize.w, event.resize.h, m_window_flags)) return false;
                    on_resize(m_rbuf_window.width(), m_rbuf_window.height());
                    trans_affine_resizing(event.resize.w, event.resize.h);
                    m_specific->m_update_flag = true;
                    break;

                case SDL_KEYDOWN:
                    {
                        flags = 0;
                        if(event.key.keysym.mod & KMOD_SHIFT) flags |= kbd_shift;
                        if(event.key.keysym.mod & KMOD_CTRL)  flags |= kbd_ctrl;

                        bool left  = false;
                        bool up    = false;
                        bool right = false;
                        bool down  = false;

                        switch(event.key.keysym.sym)
                        {
                        case key_left:
                            left = true;
                            break;

                        case key_up:
                            up = true;
                            break;

                        case key_right:
                            right = true;
                            break;

                        case key_down:
                            down = true;
                            break;
                        }

                        if(m_ctrls.on_arrow_keys(left, right, down, up))
                        {
                            on_ctrl_change();
                            force_redraw();
                        }
                        else
                        {
                            on_key(m_specific->m_cur_x,
                                   m_specific->m_cur_y,
                                   event.key.keysym.sym,
                                   flags);
                        }
                    }
                    break;

                case SDL_MOUSEMOTION:
                    y = m_flip_y ? 
                        m_rbuf_window.height() - event.motion.y : 
                        event.motion.y;

                    m_specific->m_cur_x = event.motion.x;
                    m_specific->m_cur_y = y;
                    flags = 0;
                    if(event.motion.state & SDL_BUTTON(1)) flags |= mouse_left;
                    if(event.motion.state & SDL_BUTTON(3)) flags |= mouse_right;

                    if(m_ctrls.on_mouse_move(m_specific->m_cur_x, 
                                             m_specific->m_cur_y,
                                             (flags & mouse_left) != 0))
                    {
                        on_ctrl_change();
                        force_redraw();
                    }
                    else
                    {
                        on_mouse_move(m_specific->m_cur_x, 
                                      m_specific->m_cur_y, 
                                      flags);
                    }
		    SDL_Event eventtrash;
		    while (SDL_PeepEvents(&eventtrash, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION))!=0){;}
                    break;

                case SDL_MOUSEBUTTONDOWN:
                    y = m_flip_y ? 
                        m_rbuf_window.height() - event.motion.y : 
                        event.motion.y;

                    m_specific->m_cur_x = event.motion.x;
                    m_specific->m_cur_y = y;
                    flags = 0;
                    if(event.button.button == SDL_BUTTON_LEFT)  flags = mouse_left;
                    if(event.button.button == SDL_BUTTON_RIGHT) flags = mouse_right;

                    if(flags & mouse_left)
                    {
                        if(m_ctrls.on_mouse_button_down(m_specific->m_cur_x, 
                                                        m_specific->m_cur_y))
                        {
                            m_ctrls.set_cur(m_specific->m_cur_x, 
                                            m_specific->m_cur_y);
                            on_ctrl_change();
                            force_redraw();
                        }
                        else
                        {
                            if(m_ctrls.in_rect(m_specific->m_cur_x, 
                                               m_specific->m_cur_y))
                            {
                                if(m_ctrls.set_cur(m_specific->m_cur_x, 
                                                   m_specific->m_cur_y))
                                {
                                    on_ctrl_change();
                                    force_redraw();
                                }
                            }
                            else
                            {
                                on_mouse_button_down(m_specific->m_cur_x, 
                                                     m_specific->m_cur_y, 
                                                     flags);
                            }
                        }
                    }
                    if(flags & mouse_right)
                    {
                        on_mouse_button_down(m_specific->m_cur_x, 
                                             m_specific->m_cur_y, 
                                             flags);
                    }
                    break;

                case SDL_MOUSEBUTTONUP:
                    y = m_flip_y ? 
                        m_rbuf_window.height() - event.motion.y : 
                        event.motion.y;

                    m_specific->m_cur_x = event.motion.x;
                    m_specific->m_cur_y = y;
                    flags = 0;
                    if(m_ctrls.on_mouse_button_up(m_specific->m_cur_x, 
                                                  m_specific->m_cur_y))
                    {
                        on_ctrl_change();
                        force_redraw();
                    }
                    on_mouse_button_up(m_specific->m_cur_x, 
                                       m_specific->m_cur_y, 
                                       flags);
                    break;
                }
            }
        }
        return 0;
    }
Example #28
0
/////////////////////////////////////////////////////////////////
//
// Okay here goes a quick description of how a modal dialog
// using the SDL is realized:
// So when this modal dialog is invoked, we ARE actually between
// two globalLoop mutex calls, because we were invoked
// by some mouse click or other event
// So now we first attach a new event listener to our screen 
// object (so that all events sent end up in our own listener)
// and install our own event handler loop... But this can only
// be done when the globalMutex is unlocked first and locked 
// after...
//
/////////////////////////////////////////////////////////////////
PPModalDialog::ReturnCodes SDL_runModalLoop(PPScreen* screen, PPDialogBase* dialog)
{
	bool exitModalLoop = false;
	SDL_Event event;

	// screen might be disabled in a stackable fashion
	pp_uint32 screenEnableStackCount = 0;
	while (!screen->isDisplayEnabled())
	{
		screen->enableDisplay(true);
		screenEnableStackCount++;
	}

	// This is the responder for buttons invoked by the modal dialog
	ModalLoopResponder modalLoopResponder(exitModalLoop);

	dialog->setResponder(&modalLoopResponder);

	// Detach the event listener from the screen, this will actually detach the entire tracker from the screen
	EventListenerInterface* eventListener = screen->detachEventListener();

	// Instantinate our own event listener
	CustomEventListener customEventListener(eventListener);
	
	// Attach it
	screen->attachEventListener(&customEventListener);

	// Show it
	dialog->show();

	// Now to the tricky part, since a modal dialog has been invoked through a OS event, globalMutex is in locked state
	// so to allow further event processing we must unlock the mutex first
	// -- really messy and critical --
	if (globalMutex)
		globalMutex->unlock();

	// Create our own event loop
	while (!exitModalLoop && SDL_WaitEvent(&event)) 
	{
		switch (event.type) 
		{
			case SDL_MOUSEMOTION:
			{
				// ignore old mouse motion events in the event queue
				SDL_Event new_event;
				
				if (SDL_PeepEvents(&new_event, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION)) > 0) 
				{
					while (SDL_PeepEvents(&new_event, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION)) > 0);
					processSDLEvents(new_event);
				} 
				else 
				{
					processSDLEvents(event);
				}
				break;
			}
			
			case SDL_USEREVENT:
				processSDLUserEvents((const SDL_UserEvent&)event);
				break;
			
			default:
				processSDLEvents(event);
				break;
		}
	}	

	// pretend nothing happened at all, continue with main event loop after we're finished here
	if (globalMutex)
		globalMutex->lock();

	// re-attach tracker
	screen->attachEventListener(eventListener);	

	// if screen was disabled we enable it again
	while (screenEnableStackCount > 0)
	{
		screen->enableDisplay(false);
		screenEnableStackCount--;
	}
	
	return modalLoopResponder.getReturnCode();
}
Example #29
0
void PLATFORM_SetVideoMode(VIDEOMODE_resolution_t const *res, int windowed, VIDEOMODE_MODE_t mode, int rotate90)
{
	/* In SDL there's really no way to determine if a window is maximised. So we use a method
	   that's not 100% sure: if we notice, that the windows's horizontal size equals desktop
	   resolution, then we assume that the window is maximised. This works at least on Windows
	   and Linux/KDE. */
	window_maximised = windowed && res->width == desktop_resolution.width;

#if HAVE_WINDOWS_H
	/* On Windows, choose Windib or DirectX backend when switching between
	   fullscreen<->windowed. */
	if (!user_video_driver &&
	    SDL_VIDEO_screen != NULL &&
	    ((SDL_VIDEO_screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) == windowed) {
		if (windowed)
			SDL_putenv("SDL_VIDEODRIVER=windib");
		else
			SDL_putenv("SDL_VIDEODRIVER=directx");
		/* SDL_VIDEODRIVER is only used when initialising the video subsystem. */
		SDL_VIDEO_ReinitSDL();
	}
#if HAVE_OPENGL
	/* Reinitialise the video subsystem when switching between software<->OpenGL
	   to avoid various SDL glitches and segfaults that might appear depending on
	   the type of graphics hardware. */
	else if (SDL_VIDEO_screen != NULL && SDL_VIDEO_opengl != currently_opengl)
		SDL_VIDEO_ReinitSDL();
#endif /* HAVE_OPENGL */
#endif /* HAVE_WINDOWS_H */

#if HAVE_OPENGL
	if (SDL_VIDEO_opengl) {
		if (!currently_opengl)
			SDL_VIDEO_screen = NULL;
		/* Switching to OpenGL can fail when the host machine doesn't
		   support it. If so, revert to software mode. */
		if (!SDL_VIDEO_GL_SetVideoMode(res, windowed, mode, rotate90)) {
			SDL_VIDEO_GL_Cleanup();
			SDL_VIDEO_screen = NULL;
			SDL_VIDEO_opengl = SDL_VIDEO_opengl_available = FALSE;
			VIDEOMODE_Update();
		}
	} else {
		if (currently_opengl) {
			SDL_VIDEO_GL_Cleanup();
			SDL_VIDEO_screen = NULL;
		}
		SDL_VIDEO_SW_SetVideoMode(res, windowed, mode, rotate90);
	}
	currently_opengl = SDL_VIDEO_opengl;
#else
	SDL_VIDEO_SW_SetVideoMode(res, windowed, mode, rotate90);
#endif
	SDL_VIDEO_current_display_mode = mode;
	UpdateNtscFilter(mode);
	PLATFORM_DisplayScreen();

	/* For unknown reason (maybe window manager-related), when SDL_SetVideoMode
	   is called twice without calling SDL_PollEvent in between, SDL may throw
	   an SDL_VIDEORESIZE event. (Happens on KDE4 in windowed mode during
	   initialisation of the XEP80 handler (TV system = PAL), when it switches
	   between 60Hz and 50Hz modes rapidly). If this event was processed, it
	   would cause another screen resize, resulting in invalid window size. To
	   avoid the glitch, we ignore all pending SDL_VIDEORESIZE events after
	   each screen resize. */
	for (;;) {
		SDL_Event event;
		int found = FALSE;
		SDL_PumpEvents();
		while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_VIDEORESIZE)) > 0)
			found = TRUE;
		if (!found)
			break;
	}
}
Example #30
0
int input(struct inp_event *inp, int wait)
{
    int rc;
    SDL_Event event;
    SDL_Event peek;
    memset(&event, 0, sizeof(event));
    memset(&peek, 0, sizeof(peek));
    if (wait) {
        rc = SDL_WaitEvent(&event);
    } else
        rc = SDL_PollEvent(&event);
    if (!rc)
        return 0;
    inp->sym[0] = 0;
    inp->type = 0;
    inp->count = 1;
    switch(event.type) {
#if SDL_VERSION_ATLEAST(2,0,0)
    case SDL_MULTIGESTURE:
    case SDL_FINGERMOTION:
        if (DIRECT_MODE && !game_paused())
            return AGAIN;
        if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, event.type, event.type) > 0)
            return AGAIN; /* to avoid flickering */
        break;
    case SDL_FINGERUP:
#ifdef IOS
        touch_num = 0;
#endif
    case SDL_FINGERDOWN:
#ifdef IOS
        if (event.type == SDL_FINGERDOWN) {
            if (gfx_ticks() - touch_stamp > 100) {
                touch_num = 0;
                touch_stamp = gfx_ticks();
            }
            touch_num ++;
            if (touch_num >= 3) {
                inp->type = KEY_DOWN;
                inp->code = 0;
                strncpy(inp->sym, "escape", sizeof(inp->sym));
                break;
            }
        }
#endif
        gfx_finger_pos_scale(event.tfinger.x, event.tfinger.y, &inp->x, &inp->y);
        inp->type = (event.type == SDL_FINGERDOWN) ? FINGER_DOWN : FINGER_UP;
#ifndef PRIx64
        snprintf(inp->sym, sizeof(inp->sym), "%llx:%llx",
                 event.tfinger.fingerId,
                 event.tfinger.touchId);
#else
        snprintf(inp->sym, sizeof(inp->sym), "%"PRIx64":%"PRIx64,
                 event.tfinger.fingerId,
                 event.tfinger.touchId);
#endif
        break;
    case SDL_WINDOWEVENT:
        switch (event.window.event) {
        /*		case SDL_WINDOWEVENT_SHOWN: */
        case SDL_WINDOWEVENT_EXPOSED:
            gfx_flip();
            gfx_commit();
            break;
        case SDL_WINDOWEVENT_MINIMIZED:
        case SDL_WINDOWEVENT_RESTORED:
            m_minimized = (event.window.event == SDL_WINDOWEVENT_MINIMIZED && !opt_fs);
            snd_pause(!nopause_sw && m_minimized);
            break;
        case SDL_WINDOWEVENT_ENTER:
        case SDL_WINDOWEVENT_FOCUS_GAINED:
            m_focus = 1;
            if (opt_fs)
                mouse_cursor(0);
            break;
        case SDL_WINDOWEVENT_LEAVE:
            m_focus = 0;
            if (opt_fs)
                mouse_cursor(1); /* is it hack?*/
            break;
        default:
            break;
        }
        if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT) > 0)
            return AGAIN; /* to avoid flickering */
        return 0;
#else
    case SDL_ACTIVEEVENT:
        if (event.active.state & SDL_APPACTIVE) {
            m_minimized = !event.active.gain;
            snd_pause(!nopause_sw && m_minimized);
        }
        if (event.active.state & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) {
            if (event.active.gain) {
                m_focus = 1;
                if (opt_fs)
                    mouse_cursor(0);
            } else if (event.active.state & SDL_APPMOUSEFOCUS) {
                m_focus = 0;
                if (opt_fs)
                    mouse_cursor(1); /* is it hack?*/
            }
        }
#if SDL_VERSION_ATLEAST(1,3,0)
        if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, SDL_ACTIVEEVENT, SDL_ACTIVEEVENT) > 0)
#else
        if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, SDL_EVENTMASK(SDL_ACTIVEEVENT)) > 0)
#endif
            return AGAIN; /* to avoid flickering */
        return 0;
#endif
    case SDL_USEREVENT: {
        void (*p) (void*) = (void (*)(void*))event.user.data1;
        p(event.user.data2);
        return AGAIN;
    }
    case SDL_QUIT:
        game_running = 0;
        return -1;
    case SDL_KEYDOWN:	/* A key has been pressed */
#if SDL_VERSION_ATLEAST(2,0,0)
        if (event.key.repeat) {
            if (DIRECT_MODE && !game_paused()) /* do not send key repeats */
                return AGAIN;
            if (gfx_ticks() - last_press_ms < INPUT_REP_DELAY_MS)
                return AGAIN;
            if ((gfx_ticks() - last_repeat_ms) < INPUT_REP_INTERVAL_MS)
                return AGAIN;
            last_repeat_ms = gfx_ticks();
        } else {
            last_press_ms = gfx_ticks();
            last_repeat_ms = gfx_ticks();
        }
#endif
        inp->type = KEY_DOWN;
        inp->code = event.key.keysym.scancode;
#if SDL_VERSION_ATLEAST(1,3,0)
        strncpy(inp->sym, SDL_GetScancodeName(inp->code), sizeof(inp->sym));
#else
        strncpy(inp->sym, SDL_GetKeyName(event.key.keysym.sym), sizeof(inp->sym));
#endif
        inp->sym[sizeof(inp->sym) - 1] = 0;
        tolow(inp->sym);
#if SDL_VERSION_ATLEAST(1,3,0)
        key_compat(inp);
#endif
#if SDL_VERSION_ATLEAST(1,3,0) /* strange bug in some SDL2 env, with up/down events storm */
        if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, SDL_KEYDOWN, SDL_KEYUP) > 0) {
            if (peek.key.keysym.scancode == event.key.keysym.scancode &&
                    peek.key.repeat == 0)
                return AGAIN;
        }
#endif
        break;
    case SDL_KEYUP:
        inp->type = KEY_UP;
        inp->code = event.key.keysym.scancode;
#if SDL_VERSION_ATLEAST(1,3,0)
        strncpy(inp->sym, SDL_GetScancodeName(inp->code), sizeof(inp->sym));
#else
        strncpy(inp->sym, SDL_GetKeyName(event.key.keysym.sym), sizeof(inp->sym));
#endif
        inp->sym[sizeof(inp->sym) - 1] = 0;
        tolow(inp->sym);
#if SDL_VERSION_ATLEAST(1,3,0)
        key_compat(inp);
#endif
#if SDL_VERSION_ATLEAST(1,3,0) /* strange bug in some SDL2 env, with up/down events storm */
        if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, SDL_KEYDOWN, SDL_KEYUP) > 0) {
            if (event.key.keysym.scancode == peek.key.keysym.scancode &&
                    peek.key.repeat == 0)
                return AGAIN;
        }
#endif
        break;
    case SDL_MOUSEMOTION:
        m_focus = 1; /* ahhh */
        if (DIRECT_MODE && !game_paused())
            return AGAIN;
        inp->type = MOUSE_MOTION;
        inp->x = event.button.x;
        inp->y = event.button.y;
#if SDL_VERSION_ATLEAST(1,3,0)
        while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) > 0) {
#else
        while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)) > 0) {
#endif
            inp->x = peek.button.x;
            inp->y = peek.button.y;
        }
        break;
    case SDL_MOUSEBUTTONUP:
        inp->type = MOUSE_UP;
        inp->x = event.button.x;
        inp->y = event.button.y;
        inp->code = event.button.button;
        if (event.button.button == 4)
            inp->type = 0;
        else if (event.button.button == 5)
            inp->type = 0;
        break;
#if SDL_VERSION_ATLEAST(2,0,0)
    case SDL_MOUSEWHEEL:
        if (DIRECT_MODE && !game_paused())
            return AGAIN;

        inp->type = (event.wheel.y > 0) ? MOUSE_WHEEL_UP : MOUSE_WHEEL_DOWN;

        while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_MOUSEWHEEL, SDL_MOUSEWHEEL) > 0) {
            if (!((event.wheel.y > 0 &&
                    inp->type == MOUSE_WHEEL_UP) ||
                    (event.wheel.y < 0 &&
                     inp->type == MOUSE_WHEEL_DOWN)))
                break;
            inp->count ++;
        }
        break;
#endif
    case SDL_MOUSEBUTTONDOWN:
        m_focus = 1; /* ahhh */
        inp->type = MOUSE_DOWN;
        inp->x = event.button.x;
        inp->y = event.button.y;
        inp->code = event.button.button;
        if (event.button.button == 4)
            inp->type = MOUSE_WHEEL_UP;
        else if (event.button.button == 5)
            inp->type = MOUSE_WHEEL_DOWN;
#if SDL_VERSION_ATLEAST(1,3,0)
        while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONDOWN) > 0) {
#else
        while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEBUTTONDOWN)) > 0) {
#endif
            if (!((event.button.button == 4 &&
                    inp->type == MOUSE_WHEEL_UP) ||
                    (event.button.button == 5 &&
                     inp->type == MOUSE_WHEEL_DOWN)))
                break;
            inp->count ++;
        }
        break;
    default:
        break;
    }
    return 1;
}