Esempio n. 1
0
//
// ISDL12KeyboardInputDevice::resume
//
// Sets the internal state to enable all input for this device.
//
// NOTE: SDL_EventState clears the SDL event queue so only call this after all
// SDL events have been processed in all SDL input device instances.
//
void ISDL12KeyboardInputDevice::resume()
{
	mActive = true;
	reset();
	SDL_EventState(SDL_KEYDOWN, SDL_ENABLE);
	SDL_EventState(SDL_KEYUP, SDL_ENABLE);
}
Esempio n. 2
0
//
// ISDL12InputSubsystem::ISDL12InputSubsystem
//
ISDL12InputSubsystem::ISDL12InputSubsystem() :
	IInputSubsystem(),
	mInputGrabbed(false)
{
	// Initialize the joystick subsystem and open a joystick if use_joystick is enabled. -- Hyper_Eye
	SDL_InitSubSystem(SDL_INIT_JOYSTICK);

	// Tell SDL to ignore events from the input devices
	// IInputDevice constructors will enable these events when they're initialized.
	SDL_EventState(SDL_KEYDOWN, SDL_IGNORE);
	SDL_EventState(SDL_KEYUP, SDL_IGNORE);

	SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
	SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE);
	SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE);

	SDL_EventState(SDL_JOYAXISMOTION, SDL_IGNORE);
	SDL_EventState(SDL_JOYBALLMOTION, SDL_IGNORE);
	SDL_EventState(SDL_JOYHATMOTION, SDL_IGNORE);
	SDL_EventState(SDL_JOYBUTTONDOWN, SDL_IGNORE);
	SDL_EventState(SDL_JOYBUTTONUP, SDL_IGNORE);

	SDL_ShowCursor(false);
	grabInput();
}
Esempio n. 3
0
int stick_init( int device_index ) {

  int cnt = 0;

  /* Initialize SDL with joystick support and event support (through video) */
  if (SDL_Init(SDL_INIT_JOYSTICK|SDL_INIT_VIDEO) < 0)
  {
    printf("Could not initialize SDL: %s.\n", SDL_GetError());
    exit(-1);
  }

  //Quit SDL at exit
  atexit(SDL_Quit);

  //Start the event handler, disable all but joystick events and quit handler
  SDL_EventState(SDL_ACTIVEEVENT,SDL_IGNORE);
  SDL_EventState(SDL_KEYDOWN,SDL_IGNORE);
  SDL_EventState(SDL_KEYUP,SDL_IGNORE);
  SDL_EventState(SDL_MOUSEMOTION,SDL_IGNORE);
  SDL_EventState(SDL_MOUSEBUTTONDOWN,SDL_IGNORE);
  SDL_EventState(SDL_MOUSEBUTTONUP,SDL_IGNORE);
  //SDL_EventState(SDL_JOYAXISMOTION,SDL_IGNORE);
  //SDL_EventState(SDL_JOYBALLMOTION,SDL_IGNORE);
  //SDL_EventState(SDL_JOYHATMOTION,SDL_IGNORE);
  //SDL_EventState(SDL_JOYBUTTONDOWN,SDL_IGNORE);
  //SDL_EventState(SDL_JOYBUTTONUP,SDL_IGNORE);
  SDL_EventState(SDL_VIDEORESIZE,SDL_IGNORE);
  SDL_EventState(SDL_VIDEOEXPOSE,SDL_IGNORE);
  //SDL_EventState(SDL_QUIT,SDL_IGNORE);
  SDL_EventState(SDL_USEREVENT,SDL_IGNORE);
  SDL_EventState(SDL_SYSWMEVENT,SDL_IGNORE);

  //Check there are actually joysticks attached
  if (!SDL_NumJoysticks())
  {
    fprintf(stderr,"Error: No joysticks attached!\n");
    SDL_Quit();
    return(1);
  }

  /* test device_index, else look for a suitable device */
  if (init_sdl_device(device_index) != 0)
  {
    printf("Failed to open joystick at SDL device index %d, attempting to find a suitable joystick...\n",device_index);
    for (cnt = 0; cnt < STICK_INPUT_DEV_MAX; cnt++) {
      if (init_sdl_device(cnt) == 0) break;
    }
    printf("Found an alternative device!\n");
  }

  /* return 1 if no device found */
  if (cnt == STICK_INPUT_DEV_MAX) {
    fprintf(stderr,"ERROR: no suitable joystick found [%s:%d]\n",
        __FILE__,__LINE__);
    SDL_Quit();
    return(1);
  }

  return 0;
}
Esempio n. 4
0
Index::Index()
{
	/** random **/
	
	srand(time(0));
    
    /** SDL **/
    
    SDL_Init(SDL_INIT_VIDEO);
    SDL_WM_SetCaption("Snake by Ceytix",NULL);
    
    screen = SDL_SetVideoMode(750, 810, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
    indexPicture = IMG_Load("files/pictures/index.png");
    levelChoicePicture = IMG_Load("files/pictures/levelchoice.png");
    creditsPicture = IMG_Load("files/pictures/credits.png");
    
    pos.x = 0;
    pos.y = 0;
    
    /** SDL Events **/
    
    SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
    SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE);
    SDL_EventState(SDL_KEYUP, SDL_IGNORE);
    
    /** Snake **/
    
    game = new Snake();
}
/*
 * Turn off controller events
 */
int
SDL_GameControllerEventState(int state)
{
#if SDL_EVENTS_DISABLED
    return SDL_IGNORE;
#else
    const Uint32 event_list[] = {
        SDL_CONTROLLERAXISMOTION, SDL_CONTROLLERBUTTONDOWN, SDL_CONTROLLERBUTTONUP,
        SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEREMOVED, SDL_CONTROLLERDEVICEREMAPPED,
    };
    unsigned int i;

    switch (state) {
    case SDL_QUERY:
        state = SDL_IGNORE;
        for (i = 0; i < SDL_arraysize(event_list); ++i) {
            state = SDL_EventState(event_list[i], SDL_QUERY);
            if (state == SDL_ENABLE) {
                break;
            }
        }
        break;
    default:
        for (i = 0; i < SDL_arraysize(event_list); ++i) {
            SDL_EventState(event_list[i], state);
        }
        break;
    }
    return (state);
#endif /* SDL_EVENTS_DISABLED */
}
Esempio n. 6
0
static void initSDL(void)
{

  //SDL initialisation
  if (SDL_Init(SDL_INIT_JOYSTICK) < 0 )
  {
    printf("Could not initialize SDL(%s)\n", SDL_GetError());
    fe_exit();
  }
  atexit(SDL_Quit);
  keyssnes = SDL_GetKeyState(NULL);
  SDL_SetVideoMode(0, 0, 16, SDL_SWSURFACE);

  SDL_EventState(SDL_ACTIVEEVENT,SDL_IGNORE);
  SDL_EventState(SDL_SYSWMEVENT,SDL_IGNORE);
  SDL_EventState(SDL_VIDEORESIZE,SDL_IGNORE);
  SDL_EventState(SDL_USEREVENT,SDL_IGNORE);
  SDL_ShowCursor(SDL_DISABLE);

  joy[0] = SDL_JoystickOpen(0);

  if(joy[0]) {
    if(SDL_JoystickEventState(SDL_ENABLE) != SDL_ENABLE) {
      printf("Could not set joystick event state: %s\n", SDL_GetError());
      fe_exit();
    }
  }
}
Esempio n. 7
0
int
SDL_JoystickEventState(int state)
{
#if SDL_EVENTS_DISABLED
    return SDL_DISABLE;
#else
    const Uint32 event_list[] = {
        SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION,
        SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED
    };
    unsigned int i;

    switch (state) {
    case SDL_QUERY:
        state = SDL_DISABLE;
        for (i = 0; i < SDL_arraysize(event_list); ++i) {
            state = SDL_EventState(event_list[i], SDL_QUERY);
            if (state == SDL_ENABLE) {
                break;
            }
        }
        break;
    default:
        for (i = 0; i < SDL_arraysize(event_list); ++i) {
            SDL_EventState(event_list[i], state);
        }
        break;
    }
    return (state);
#endif /* SDL_EVENTS_DISABLED */
}
Esempio n. 8
0
int main(int argc, char **argv)
{
	int i, rc;

	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
	SDL_EventState(SDL_KEYDOWN, SDL_ENABLE);
	SDL_EventState(SDL_QUIT, SDL_ENABLE);

	for (i = 1; i < argc; i++) {
		if (argv[i][0] == '-') {
			switch (argv[i][1]) {
			case 'h':
				usage(argc, argv);
				return 0;
			default:
				usage(argc, argv);
				return 1;
			}
			continue;
		}
		rc = mng_read(argv[i], argv[i], mng_callback);
		if (rc < 0)
			fprintf(stderr, "reading '%s' returned %d\n", argv[i], rc);
	}

	return 0;
}
Esempio n. 9
0
int SDL_JoystickEventState(int state)
{
#ifdef DISABLE_EVENTS
	return SDL_IGNORE;
#else
	const Uint8 event_list[] = {
		SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION,
		SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP,
	};
	int i;

	switch (state) {
		case SDL_QUERY:
			state = SDL_IGNORE;
			for ( i=0; i<SDL_TABLESIZE(event_list); ++i ) {
				state = SDL_EventState(event_list[i],SDL_QUERY);
				if ( state == SDL_ENABLE ) {
					break;
				}
			}
			break;
		default:
			for ( i=0; i<SDL_TABLESIZE(event_list); ++i ) {
				SDL_EventState(event_list[i], state);
			}
			break;
	}
	return(state);
#endif /* DISABLE_EVENTS */
}
Esempio n. 10
0
int vo_sdl_init(void)
{
    reinit = 0;

    if (!SDL_WasInit(SDL_INIT_VIDEO)) {
        // Unfortunately SDL_WINDOWID must be set at SDL_Init
        // and is ignored afterwards, thus it cannot work per-file.
        // Also, a value of 0 does not work for selecting the root window.
        if (WinID > 0) {
            char envstr[20];
            snprintf(envstr, sizeof(envstr), "0x%"PRIx64, WinID);
            setenv("SDL_WINDOWID", envstr, 1);
        }
        if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0)
            return 0;
    }

    // Setup Keyrepeats (500/30 are defaults)
    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, 100 /*SDL_DEFAULT_REPEAT_INTERVAL*/);

    // Easiest way to get uppercase characters
    SDL_EnableUNICODE(1);

    // We don't want those in our event queue.
    SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
    SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
    SDL_EventState(SDL_USEREVENT, SDL_IGNORE);

    // Try to get a sensible default for fullscreen.
    get_screensize();

    return 1;
}
Esempio n. 11
0
void
MainMenu::optionsBackButtonClicked(Button* )
{
    getConfig()->save();
    if( getConfig()->videoX != SDL_GetVideoSurface()->w || getConfig()->videoY != SDL_GetVideoSurface()->h)
    {
        if( getConfig()->restartOnChangeScreen )
        {
            quitState = RESTART;
            running = false;
        }
        else
        {
            //SDL_IGNORE to avoid forth and back jumping resolution
            SDL_EventState(SDL_VIDEORESIZE, SDL_IGNORE);
            initVideo( getConfig()->videoX, getConfig()->videoY);
            currentMenu->resize(getConfig()->videoX, getConfig()->videoY);
            SDL_EventState(SDL_VIDEORESIZE, SDL_ENABLE);
            gotoMainMenu();
        }
    }
    else if( currentLanguage != getConfig()->language )
    {
        unsetenv("LINCITY_LANG");
        quitState = RESTART;
        running = false;
    }
    else
    {
        gotoMainMenu();
    }
}
Esempio n. 12
0
int init_SDL(void)
{
    joy[0]=0;
    joy[1]=0;
    joy[2]=0;
    joy[3]=0;

    if (SDL_Init(SDL_INIT_JOYSTICK) < 0) {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        return(0);
    }
    sdlscreen = SDL_SetVideoMode(0,0, 16, SDL_SWSURFACE);

    //We handle up to four joysticks
    if(SDL_NumJoysticks())
    {
        int i;
        SDL_JoystickEventState(SDL_ENABLE);

        for(i=0;i<SDL_NumJoysticks();i++) {
            joy[i]=SDL_JoystickOpen(i);

            //Check for valid joystick, some keyboards
            //aren't SDL compatible
            if(joy[i])
            {
                if (SDL_JoystickNumAxes(joy[i]) > 28)
                {
                    SDL_JoystickClose(joy[i]);
                    joy[i]=0;
                    logoutput("Error detected invalid joystick/keyboard\n");
                }
                else
                    joyCount++;
            }
        }
        if(joy[0])
            logoutput("Found %d joysticks\n",joyCount);
    }
    else
        joyCount=1;

    //sq frig number of players for keyboard
    //joyCount=2;

    SDL_EventState(SDL_ACTIVEEVENT,SDL_IGNORE);
    SDL_EventState(SDL_SYSWMEVENT,SDL_IGNORE);
    SDL_EventState(SDL_VIDEORESIZE,SDL_IGNORE);
    SDL_EventState(SDL_USEREVENT,SDL_IGNORE);
    SDL_ShowCursor(SDL_DISABLE);

    //Initialise dispmanx
    bcm_host_init();

    //Clean exits, hopefully!
    atexit(exitfunc);

    return(1);
}
Esempio n. 13
0
Direction TBFE::runEngine()
{
  frame_++;
  bool checkOnce=false;
  while(logic_.pollEvent() || !checkOnce)
    {
      SDL_Event currentSdlEvent=logic_.getEvent();
      checkEvents();
      //Normal KeyBoard Events
      if (currentSdlEvent.type==SDL_KEYDOWN && logic_.isEventNew())
	{	  
	  if (logic_.checkKeyDown(27))
	    {
	      quit_=true;
	    };
	};
      checkOnce=true;
    };
  PositionI mapDimensions=Current_Map.getDimensions();
  if (keyControl_==true)
    {
      logic_.playerMovement(Main_Player);
    };
  renderWindow_.finalRender(true);  
  
  if (frameRate_.GetTicks() > 1000)
    {
      frameRate_.Start();
      time_++;
      int Minutes=time_-(time_/100)*100;
      if (Minutes>=60)
	{
	  time_+=100-Minutes;
	};
      if (time_>2400)
	{
	  time_=0;
	};
      frame_=0;
      if (!showMouse_ && (mousePosition_.X!=screenDimensions_.X/2 || mousePosition_.Y!=screenDimensions_.Y/2))
	{
	  SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
	  SDL_WarpMouse(mouseCenter_.X,mouseCenter_.Y);
	  SDL_WM_GrabInput( SDL_GRAB_ON );
	  SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
	};
      return SECOND;
    };
  gameSpeed_=60/(frame_*1000/frameRate_.GetTicks());
  if (gameSpeed_>3)
    {
      gameSpeed_=3;
    };
  if (quit_==true)
    {
      return QUIT;
    };
  return NORMAL;
};
Esempio n. 14
0
//
// ISDL12MouseInputDevice::pause
//
// Sets the internal state to ignore all input for this device.
//
// NOTE: SDL_EventState clears the SDL event queue so only call this after all
// SDL events have been processed in all SDL input device instances.
//
void ISDL12MouseInputDevice::pause()
{
	mActive = false;
	SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
	SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE);
	SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE);
	SDL_ShowCursor(true);
}
Esempio n. 15
0
void initkeyb(void)
{
    SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
    SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE);
    SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE);

    SDL_SetEventFilter(Handler);
}
Esempio n. 16
0
void CCursorHandler::centerCursor()
{
	this->xpos = (screen->w / 2.) - (currentCursor->pos.w / 2.);
	this->ypos = (screen->h / 2.) - (currentCursor->pos.h / 2.);
	SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
	SDL_WarpMouse(this->xpos, this->ypos);
	SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
}
Esempio n. 17
0
//
// ISDL12MouseInputDevice::resume
//
// Sets the internal state to enable all input for this device.
//
// NOTE: SDL_EventState clears the SDL event queue so only call this after all
// SDL events have been processed in all SDL input device instances.
//
void ISDL12MouseInputDevice::resume()
{
	mActive = true;
	SDL_ShowCursor(false);
	reset();
	SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
	SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_ENABLE);
	SDL_EventState(SDL_MOUSEBUTTONUP, SDL_ENABLE);
}
Esempio n. 18
0
bool SDL2Window::initializeFramework() {
	
	arx_assert(s_mainWindow == NULL, "SDL only supports one window"); // TODO it supports multiple windows now!
	arx_assert(m_displayModes.empty());
	
	const char * headerVersion = ARX_STR(SDL_MAJOR_VERSION) "." ARX_STR(SDL_MINOR_VERSION)
	                             "." ARX_STR(SDL_PATCHLEVEL);
	CrashHandler::setVariable("SDL version (headers)", headerVersion);
	
	if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) {
		LogError << "Failed to initialize SDL: " << SDL_GetError();
		return false;
	}
	
	#ifdef ARX_DEBUG
	// No SDL, this is more annoying than helpful!
	#if defined(SIGINT)
	signal(SIGINT, SIG_DFL);
	#endif
	#if defined(SIGTERM)
	signal(SIGTERM, SIG_DFL);
	#endif
	#endif
	
	SDL_version ver;
	SDL_GetVersion(&ver);
	std::ostringstream runtimeVersion;
	runtimeVersion << int(ver.major) << '.' << int(ver.minor) << '.' << int(ver.patch);
	CrashHandler::setVariable("SDL version (runtime)", runtimeVersion.str());
	LogInfo << "Using SDL " << runtimeVersion.str();
	
	int ndisplays = SDL_GetNumVideoDisplays();
	for(int display = 0; display < ndisplays; display++) {
		int modes = SDL_GetNumDisplayModes(display);
		for(int i = 0; i < modes; i++) {
			SDL_DisplayMode mode;
			if(SDL_GetDisplayMode(display, i, &mode) >= 0) {
				m_displayModes.push_back(Vec2i(mode.w, mode.h));
			}
		}
	}
	
	std::sort(m_displayModes.begin(), m_displayModes.end());
	m_displayModes.erase(std::unique(m_displayModes.begin(), m_displayModes.end()),
	                     m_displayModes.end());
	
	s_mainWindow = this;
	
	SDL_SetEventFilter(eventFilter, NULL);
	
	SDL_EventState(SDL_WINDOWEVENT, SDL_ENABLE);
	SDL_EventState(SDL_QUIT,        SDL_ENABLE);
	SDL_EventState(SDL_SYSWMEVENT,  SDL_IGNORE);
	SDL_EventState(SDL_USEREVENT,   SDL_IGNORE);
	
	return true;
}
Esempio n. 19
0
void CCursorHandler::centerCursor()
{
	SDL_Surface *cursor = this->cursors[mode]->ourImages[number].bitmap;
	this->xpos = (screen->w / 2.) - (cursor->w / 2.);
	this->ypos = (screen->h / 2.) - (cursor->h / 2.);
	SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);	
	SDL_WarpMouse(this->xpos, this->ypos);
	SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
}
Esempio n. 20
0
//
// ISDL12JoystickInputDevice::pause
//
// Sets the internal state to ignore all input for this device.
//
// NOTE: SDL_EventState clears the SDL event queue so only call this after all
// SDL events have been processed in all SDL input device instances.
//
void ISDL12JoystickInputDevice::pause()
{
	mActive = false;
	SDL_EventState(SDL_JOYAXISMOTION, SDL_IGNORE);
	SDL_EventState(SDL_JOYBALLMOTION, SDL_IGNORE);
	SDL_EventState(SDL_JOYHATMOTION, SDL_IGNORE);
	SDL_EventState(SDL_JOYBUTTONDOWN, SDL_IGNORE);
	SDL_EventState(SDL_JOYBUTTONUP, SDL_IGNORE);
}
Esempio n. 21
0
File: testwm2.c Progetto: STJr/SRB2
int
main(int argc, char *argv[])
{
    int i;

    /* Enable standard application logging */
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

    SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);

    /* Initialize test framework */
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    if (!state) {
        return 1;
    }
    for (i = 1; i < argc;) {
        int consumed;

        consumed = SDLTest_CommonArg(state, i);
        if (consumed == 0) {
            consumed = -1;
        }
        if (consumed < 0) {
            SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
            quit(1);
        }
        i += consumed;
    }
    if (!SDLTest_CommonInit(state)) {
        quit(2);
    }

    SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
    SDL_EventState(SDL_DROPTEXT, SDL_ENABLE);

    for (i = 0; i < state->num_windows; ++i) {
        SDL_Renderer *renderer = state->renderers[i];
        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
        SDL_RenderClear(renderer);
    }
 
    /* Main render loop */
    done = 0;
#ifdef __EMSCRIPTEN__
    emscripten_set_main_loop(loop, 0, 1);
#else
    while (!done) {
        loop();
    }
#endif
    SDL_FreeCursor(cursor);

    quit(0);
    /* keep the compiler happy ... */
    return(0);
}
Esempio n. 22
0
//
// ISDL12JoystickInputDevice::resume
//
// Sets the internal state to enable all input for this device.
//
// NOTE: SDL_EventState clears the SDL event queue so only call this after all
// SDL events have been processed in all SDL input device instances.
//
void ISDL12JoystickInputDevice::resume()
{
	mActive = true;
	reset();
	SDL_EventState(SDL_JOYAXISMOTION, SDL_ENABLE);
	SDL_EventState(SDL_JOYBALLMOTION, SDL_ENABLE);
	SDL_EventState(SDL_JOYHATMOTION, SDL_ENABLE);
	SDL_EventState(SDL_JOYBUTTONDOWN, SDL_ENABLE);
	SDL_EventState(SDL_JOYBUTTONUP, SDL_ENABLE);
}
Esempio n. 23
0
void	event_state_mouse(int state)
{
	SDL_EventState(SDL_MOUSEMOTION, state);
	SDL_EventState(SDL_MOUSEBUTTONDOWN, state);
	SDL_EventState(SDL_MOUSEBUTTONUP, state);
	SDL_EventState(SDL_APPMOUSEFOCUS, state);
	if (state == SDL_IGNORE)
		SDL_ShowCursor(SDL_DISABLE);
	else
		SDL_ShowCursor(SDL_ENABLE);
}
Esempio n. 24
0
/**
 * \brief Global initializations. Must be called at the begining of your
 *        program.
 */
void bear::input::system::initialize()
{
  if ( !SDL_WasInit(SDL_INIT_VIDEO) )
    if ( SDL_InitSubSystem(SDL_INIT_VIDEO) != 0 )
      throw claw::exception( SDL_GetError() );

  if ( SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0 )
    throw claw::exception( SDL_GetError() );

#ifndef __ANDROID__
  // Disable keyboard events on Android because SDL_TEXTINPUT makes the keyboard
  // visible.
  SDL_EventState( SDL_TEXTINPUT, SDL_ENABLE );
  SDL_EventState( SDL_KEYDOWN, SDL_ENABLE );
#endif

  SDL_EventState( SDL_MOUSEBUTTONDOWN, SDL_ENABLE );
  SDL_EventState( SDL_MOUSEBUTTONUP, SDL_ENABLE );
  SDL_EventState( SDL_MOUSEWHEEL, SDL_ENABLE );
  SDL_EventState( SDL_FINGERDOWN, SDL_ENABLE );
  SDL_EventState( SDL_FINGERUP, SDL_ENABLE );
  SDL_EventState( SDL_FINGERMOTION, SDL_ENABLE );

  // force the creation of the instance
  get_instance().refresh();
} // system::initialize()
Esempio n. 25
0
void Screen_Init(void)
{
	SDL_ShowCursor(SDL_DISABLE);

	change_vidmode ();

	cursor = IMG_Load("cursor.png");
	
	/* Configure some SDL stuff: */
	SDL_WM_SetCaption(PROG_NAME, "Frontier");
	SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
	SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_ENABLE);
	SDL_EventState(SDL_MOUSEBUTTONUP, SDL_ENABLE);
}
Esempio n. 26
0
File: jess.c Progetto: kunaldeo/JESS
void init_video_32(void)
{


  /***************** DISPLAY INITIALISATION ******************/
  if (SDL_Init (SDL_INIT_VIDEO) < 0)
    {
      fprintf (stderr, "SDL Init failed : %s\n", SDL_GetError ());
      exit (1);
    }
  printf("SDL init Ok\n");

  screen = SDL_SetVideoMode (resx, resy, 32, SCREENFLAG);
  if (screen == NULL)
    {
      fprintf (stderr, "Graphic mode is not available: %s\n",
	       SDL_GetError ());
      exit (1);
    }

 

  printf("SDL Setvideo mode Ok\n");

  SDL_ShowCursor(0);
  SDL_EventState (SDL_ACTIVEEVENT, SDL_IGNORE);
  SDL_EventState (SDL_MOUSEMOTION, SDL_IGNORE);

  printf("SDL Event State Ok\n");
  /***************************************************************/

  /******************* COLOR COMPUTATION  ********************/

/*   random_palette(); */

/*   printf("SDL set color Ok\n"); */

  /****************** INDEX *************************************/
  pitch = screen->pitch;
  printf ("Pitch : %i\n", pitch);
  pixel = ((unsigned char *) screen->pixels);
#ifdef DEBUG
  printf("Screen address: %p\n", pixel);
#endif
  bpp = screen->format->BytesPerPixel;
#ifdef DEBUG
  printf ("Bytes per pixels: %i\n", bpp);
#endif
}
Esempio n. 27
0
/**
 * Handle moving over the minimap.
 * Will change the camera center when mouse moved in mouse-moving mode
 * @param action Pointer to an action.
 * @param state State that the action handlers belong to.
*/
void MiniMapView::mouseOver(Action *action, State *state)
{
	InteractiveSurface::mouseOver(action, state);

	if (isMouseScrolling && action->getDetails()->type == SDL_MOUSEMOTION)
	{
		isMouseScrolled = true;

		// Set the mouse cursor back
		SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
		SDL_WarpMouse(xBeforeMouseScrolling, yBeforeMouseScrolling);
		SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);

		// Check the threshold
		if (!mouseMovedOverThreshold)
		{
			absMouseMoveX += action->getDetails()->motion.xrel;
			absMouseMoveY += action->getDetails()->motion.yrel;
			mouseMovedOverThreshold = ((std::abs(absMouseMoveX) > _battleGame->getScrollButtonPixelTolerancy()) || (std::abs(absMouseMoveY) > _battleGame->getScrollButtonPixelTolerancy()));
		}

		// Calculate the move
		mouseScrollX += action->getDetails()->motion.xrel * _battleGame->getScrollButtonInvertMode();
		mouseScrollY += action->getDetails()->motion.yrel * _battleGame->getScrollButtonInvertMode();
		int newX = posBeforeMouseScrolling.x + mouseScrollX / 3;
		int newY = posBeforeMouseScrolling.y + mouseScrollY / 3;

		// Keep the limits...
		if (newX < -1 || _camera->getMapLength() < newX)
		{
			mouseScrollX -= action->getDetails()->motion.xrel * _battleGame->getScrollButtonInvertMode();
			newX = posBeforeMouseScrolling.x + mouseScrollX / 3;
		}
		if (newY < -1 || _camera->getMapWidth() < newY)
		{
			mouseScrollY -= action->getDetails()->motion.yrel * _battleGame->getScrollButtonInvertMode();
			newY = posBeforeMouseScrolling.y + mouseScrollY / 3;
		}

		// Scrolling
		_camera->centerOnPosition(Position(newX,newY,_camera->getViewHeight()));
		_redraw = true;

		// We don't want to look the mouse-cursor jumping :)
		action->getDetails()->motion.x=xBeforeMouseScrolling; action->getDetails()->motion.y=yBeforeMouseScrolling;
		_game->getCursor()->handle(action);
	}
}
Esempio n. 28
0
void SDLVideo::doRender() {
	pictureFormat.res = VIDEO_RESOLUTION;
	pictureFormat.format = YUV420P;
	window = SDL_CreateWindow("Signals SDLVideo renderer", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, pictureFormat.res.width, pictureFormat.res.height, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
	if (!window)
		throw error(format("Couldn't set create window: %s", SDL_GetError()));

	renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	if (!renderer) {
		SDL_DestroyWindow(window);
		throw error(format("Couldn't set create renderer: %s", SDL_GetError()));
	}
	m_dataQueue.push(nullptr); //unlock the constructor

	createTexture();

	SDL_EventState(SDL_KEYUP, SDL_IGNORE); //ignore key up events, they don't even get filtered

	m_NumFrames = 0;

	for(;;) {
		auto data = m_dataQueue.pop();
		if(!data)
			break;
		if (!processOneFrame(data))
			break;
	}

	SDL_DestroyTexture(texture);
	SDL_DestroyRenderer(renderer);
	SDL_DestroyWindow(window);
}
Esempio n. 29
0
INLINE BOOL Input::Initialize()
{
	Log(TAG "Initializing...");
	BOOL r = this->Reset();
	#if defined(WIN32) && defined(DEBUG)
	SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
	#endif

	MEMSET(parJoy, '\0', sizeof(parJoy));
	SDL_InitSubSystem(SDL_INIT_JOYSTICK);

	iJoystickCount = SDL_NumJoysticks();
	if (iJoystickCount)
	{
		SDL_JoystickEventState(SDL_ENABLE);

		Log(TAG "Joystick(s): ");
		for (u32 i = 0; i < iJoystickCount; i++)
		{
			parJoy[i] = SDL_JoystickOpen(i);
			if (parJoy[i])
			{
				Log("Opened Joystick %d:", i);
				Log(TAG "\tName: %s", SDL_JoystickName(i));
				Log(TAG "\t\tAxes: %d", SDL_JoystickNumAxes(parJoy[i]));
				Log(TAG "\t\tButtons: %d", SDL_JoystickNumButtons(parJoy[i]));
				Log(TAG "\t\tHats: %d", SDL_JoystickNumHats(parJoy[i]));
				Log(TAG "\t\tBalls: %d", SDL_JoystickNumBalls(parJoy[i]));
			}
		}
	}
	Log(TAG "Initialization completed.");

	return r;
}
Esempio n. 30
0
static mrb_value
mrb_sdl2_input_event_state(mrb_state *mrb, mrb_value self)
{
  mrb_int type, state;
  mrb_get_args(mrb, "ii", &type, &state);
  return mrb_fixnum_value(SDL_EventState(type, state));
}