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


C++ SDL_WM_GrabInput函数代码示例

本文整理汇总了C++中SDL_WM_GrabInput函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_WM_GrabInput函数的具体用法?C++ SDL_WM_GrabInput怎么用?C++ SDL_WM_GrabInput使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_WM_GrabInput函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: exaUpdate

bool exaUpdate()
{
	if (!isinit) return 1;
	SDL_Event event;

	_Clearkeys();
	if (typerepeats) _UpdateTypedKeys();
	_ProcessMouse();

	while (SDL_PollEvent (&event) ) {
		switch (event.type) {
		case SDL_ACTIVEEVENT:
			if (event.active.gain == 0) {
				iconified = true;
				SDL_WM_GrabInput (SDL_GRAB_OFF);
			} else {
				iconified = false;
				SDL_WM_GrabInput (SDL_GRAB_ON);
			}
			break;
		case SDL_VIDEORESIZE:
			break;
		case SDL_QUIT:
			return false;  //return 1 means the app shouldn't work anymore!!!
		case SDL_KEYDOWN:
			_Keydown (& event.key.keysym); //process key events
			break;
		case SDL_KEYUP:
			_Keyup (& event.key.keysym);
			break;
		case SDL_MOUSEBUTTONDOWN:
			if (event.button.button == SDL_BUTTON_WHEELUP) wheelup = true;
			if (event.button.button == SDL_BUTTON_WHEELDOWN) wheeldown = true;

			break;
		default:
			break;
		}
	}

	return true;
}
开发者ID:exaexa,项目名称:orthos,代码行数:42,代码来源:exa-base.cpp

示例2: findComponent

/**
 * Handles mouse up events
 */
void WindowLocations::mouseUp(SDL_MouseButtonEvent button) {
	if (button.x > 824  &&  this->scrollMode == false) {
		//Clicking sidebar. Find out if a component was hit.
		UIComponent *component = findComponent(button.x, button.y);

		//'Next player' button
		if (component == butNext) {
			if (playerInTurn >= gameEngine.getPlayerCount())
				this->startGame();
			else
				this->nextPlayer();
		}
		
		//'Back to main menu' button
		else if (component == butQuit) {
			this->close(0);
		}
	} else {
		//Clicking game area
		
		//Convert to world coordinates
		Coordinates* coords = this->graphics.getWorldCoordinates(button.x, button.y);
		
		Player *player;
		Ai *ai = NULL;
		player = gameEngine.getPlayer(playerInTurn);
		
		if (player)
			ai = player->getAI();
		
		//If AI is in turn, disable controls
		if (ai)
			player = NULL;
			
		//Set location
		if (player  &&  this->dragDistance < 5) {
			if (player->setLocation(coords->getX(), coords->getY()) == 0) {
				this->sounds.playSound(SOUND_CLICK);
				nextPlayer();
			} else {
				this->sounds.playSound(SOUND_TICK);
			}
		}
		
		delete coords;
	}

	//Deactivate scroll mode
	if (this->scrollMode) {
		SDL_WM_GrabInput(SDL_GRAB_OFF);
		SDL_ShowCursor(SDL_ENABLE);
		this->scrollMode = false;
	}
}
开发者ID:jluttine,项目名称:ipag,代码行数:57,代码来源:WindowLocations.cpp

示例3: SDL_ShowCursor

void ZGameWindow_Programmable::Hide()
{
  GameEnv->GuiManager.RemoveFrame(MainWindow);
  SDL_ShowCursor(SDL_DISABLE);
#ifdef GOTOZERO_ZERO
  SDL_WarpMouse(0,0);
#endif
  SDL_WM_GrabInput(SDL_GRAB_ON);
  GameEnv->Game_Events->SetEnableMouseEvents();
  Flag_Shown = false;
}
开发者ID:rajdakin,项目名称:Blackvoxel,代码行数:11,代码来源:ZGameWindow_Programmable.cpp

示例4: _screen

/**
 * Starts up SDL with all the subsystems and SDL_mixer for audio processing,
 * creates the display screen and sets up the cursor.
 * @param title Title of the game window.
 */
Game::Game(const std::string &title) : _screen(0), _cursor(0), _lang(0), _res(0), _save(0), _rules(0), _quit(false), _init(false), _mouseActive(true), _timeUntilNextFrame(0)
{
	Options::reload = false;
	Options::mute = false;

	// Initialize SDL
	if (SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		throw Exception(SDL_GetError());
	}
	Log(LOG_INFO) << "SDL initialized successfully.";

	// Initialize SDL_mixer
	if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
	{
		Log(LOG_ERROR) << SDL_GetError();
		Log(LOG_WARNING) << "No sound device detected, audio disabled.";
		Options::mute = true;
	}
	else
	{
		initAudio();
	}

	// trap the mouse inside the window
	SDL_WM_GrabInput(Options::captureMouse);
	
	// Set the window icon
	CrossPlatform::setWindowIcon(103, "openxcom.png");

	// Set the window caption
	SDL_WM_SetCaption(title.c_str(), 0);

	SDL_EnableUNICODE(1);

	// Create display
	_screen = new Screen();

	// Create cursor
	_cursor = new Cursor(9, 13);
	
	// Create invisible hardware cursor to workaround bug with absolute positioning pointing devices
	SDL_ShowCursor(SDL_ENABLE);
	Uint8 cursor = 0;
	SDL_SetCursor(SDL_CreateCursor(&cursor, &cursor, 1,1,0,0));

	// Create fps counter
	_fpsCounter = new FpsCounter(15, 5, 0, 0);

	// Create blank language
	_lang = new Language();

	_timeOfLastFrame = 0;
}
开发者ID:oculushut,项目名称:OpenXcom,代码行数:59,代码来源:Game.cpp

示例5: sdl_grab_start

static void sdl_grab_start(void)
{
    if (guest_cursor) {
        SDL_SetCursor(guest_sprite);
        SDL_WarpMouse(guest_x, guest_y);
    } else
        sdl_hide_cursor();
    SDL_WM_GrabInput(SDL_GRAB_ON);
    gui_grab = 1;
    sdl_update_caption();
}
开发者ID:freedesktop-unofficial-mirror,项目名称:spice__vdesktop,代码行数:11,代码来源:sdl.c

示例6: IN_DeactivateMouse

/*
===========
IN_DeactivateMouse
===========
*/
void IN_DeactivateMouse (void)
{
	if (!mouseinitialized)
		return;
	if (mouseactivatetoggle)
	{
		mouseactivatetoggle = false;
		mouseactive = false;
		SDL_WM_GrabInput (SDL_GRAB_OFF);
	}
}
开发者ID:crutchwalkfactory,项目名称:motocakerteam,代码行数:16,代码来源:in_sdl.c

示例7: SetupInput

void SetupInput()
{
	for (int port=0;port<4;port++)
	{
		kcode[port]=0xFFFF;
		rt[port]=0;
		lt[port]=0;
	}

	// Open joystick device
	int numjoys = SDL_NumJoysticks();
	printf("Number of Joysticks found = %i\n", numjoys);
	if (numjoys > 0)
		JoySDL = SDL_JoystickOpen(0);
	printf("Joystick openned\n");	
	if(JoySDL)
	{
		int AxisCount,ButtonCount;
		const char* Name;

		AxisCount   = 0;
		ButtonCount = 0;
//		Name[0]     = '\0';

		AxisCount = SDL_JoystickNumAxes(JoySDL);
		ButtonCount = SDL_JoystickNumButtons(JoySDL);
		Name = SDL_JoystickName(0);
		
		printf("SDK: Found '%s' joystick with %d axis and %d buttons\n",Name,AxisCount,ButtonCount);

		if (strcmp(Name,"Microsoft X-Box 360 pad")==0)
		{
			JMapBtn=JMapBtn_360;
			JMapAxis=JMapAxis_360;
			printf("Using Xbox 360 map\n");
		}
	} else printf("SDK: No Joystick Found\n");
	#ifdef TARGET_PANDORA
	float v;
	int j;
	for (int i=0; i<128; i++) {
		v=((float)i)/127.0f;
		v=(v+v*v)/2.0f;
		j=(int)(v*127.0f);
		if (j>127) j=127;
		JSensitivity[128-i]=-j;
		JSensitivity[128+i]=j;
	}
	#endif
	SDL_ShowCursor( 0 );
	if (SDL_WM_GrabInput( SDL_GRAB_ON ) != SDL_GRAB_ON)
		printf("SDK: Error while grabbing mouse\n");
}
开发者ID:SerzhAK,项目名称:reicast-emulator,代码行数:53,代码来源:main.cpp

示例8: vid_mouse_button

void vid_mouse_button (SDL_MouseButtonEvent *event)
{
    SDL_Event dummy_event;
    int32 cx;
    int32 cy;
    SIM_MOUSE_EVENT ev;
    t_bool state;

    if (!vid_mouse_captured) {
        if ((event->state == SDL_PRESSED) &&
                (event->button == SDL_BUTTON_LEFT)) {               /* left click and cursor not captured? */
            sim_debug (SIM_VID_DBG_KEY, vid_dev, "vid_mouse_button() - Cursor Captured\n");
            SDL_WM_GrabInput (SDL_GRAB_ON);                     /* lock cursor to window */
            SDL_ShowCursor (SDL_DISABLE);                       /* hide cursor */
            cx = vid_width / 2;
            cy = vid_height / 2;
            SDL_WarpMouse (cx, cy);                             /* move cursor to centre of window */
            SDL_PumpEvents ();
            while (SDL_PeepEvents (&dummy_event, 1, SDL_GETEVENT, SDL_MOUSEMOTIONMASK)) {};
            vid_mouse_captured = TRUE;
        }
        return;
    }
    if (!sim_is_running)
        return;
    if (SDL_SemWait (vid_mouse_events.sem) == 0) {
        sim_debug (SIM_VID_DBG_MOUSE, vid_dev, "Mouse Button Event: State: %d, Button: %d, (%d,%d)\n", event->state, event->button, event->x, event->y);
        if (vid_mouse_events.count < MAX_EVENTS) {
            state = (event->state == SDL_PRESSED) ? TRUE : FALSE;
            ev.x_rel = 0;
            ev.y_rel = 0;
            switch (event->button) {
            case SDL_BUTTON_LEFT:
                vid_mouse_events.b1_state = state;
                break;
            case SDL_BUTTON_MIDDLE:
                vid_mouse_events.b2_state = state;
                break;
            case SDL_BUTTON_RIGHT:
                vid_mouse_events.b3_state = state;
                break;
            }
            ev.b1_state = vid_mouse_events.b1_state;
            ev.b2_state = vid_mouse_events.b2_state;
            ev.b3_state = vid_mouse_events.b3_state;
            vid_mouse_events.events[vid_mouse_events.tail++] = ev;
            vid_mouse_events.count++;
            if (vid_mouse_events.tail == MAX_EVENTS)
                vid_mouse_events.tail = 0;
        }
        SDL_SemPost (vid_mouse_events.sem);
    }
}
开发者ID:charlesUnixPro,项目名称:dps8m,代码行数:53,代码来源:sim_video.c

示例9: SDL_ShowCursor

void WINDOW_SDL::ShowMouseCursor(bool value)
{
	if (value)
	{
		SDL_ShowCursor(SDL_ENABLE);
#if SDL_VERSION_ATLEAST(2,0,0)
		SDL_SetWindowGrab(window, SDL_FALSE);
#else
		SDL_WM_GrabInput(SDL_GRAB_OFF);
#endif
	}
	else
	{
		SDL_ShowCursor(SDL_DISABLE);
#if SDL_VERSION_ATLEAST(2,0,0)
		SDL_SetWindowGrab(window, SDL_TRUE);
#else
		SDL_WM_GrabInput(SDL_GRAB_ON);
#endif
	}
}
开发者ID:xacce,项目名称:vdrift,代码行数:21,代码来源:window.cpp

示例10: init

void init()
{
  heightfield hf;
  heightfieldinfo hfi;
  skybox sb;
  object3d plan = create_plan_xy(100, 100, 1, 1);
  material mat = material_create(NULL, 0, &color_red, 0, 0);
  matrix4 tmp;
  vector3 cam_pos = {0,50,0};
  vector3 cam_up = {0,1,0};
  vector3 cam_look = {0,50,-1};
  viewport vp = viewport_create(0, 0, display_width(screen), display_height(screen));

  /* Camera */
  camfps = camera_create(60, ZFAR, ZNEAR, &cam_pos, &cam_look, &cam_up, vp);

  /* Heightfied creation */
  hf = heightfield_create_from_file("data/height.png", 1000, 1000, 100);
  heightfield_set_textures_from_file(hf, "data/land.jpg", "data/detail.jpg");
  heightfield_set_detail_scale(hf, 50, 50);
  matrix4_to_rot_x(tmp, -90);
  heightfield_set_world_matrix(hf, tmp);

  /* Heightfield infos*/
  hfi = heightfieldinfo_create("data/land.jpg", hf, camfps, screen, 250, 250);

  /* Skybox */
  sb = skybox_create(camfps, "data/left.jpg", "data/right.jpg", "data/front.jpg", "data/back.jpg", "data/top.jpg", "data/bottom.jpg", 10);

  /* Test plane */
  object3d_set_material(plan, mat);

  /* Populate the scene */
  scn = scene_create();
  scene_set_camera(scn, camfps);
  scene_set_display(scn, screen);
  scene_add_object(scn, sb, (void *)skybox_to_opengl, NULL);
  scene_add_object(scn, hf, (void *)heightfield_to_opengl, NULL);
  scene_add_object(scn, plan, (void *)object3d_to_opengl, NULL);
  scene_add_object2d(scn, hfi, (void *)heightfieldinfo_to_opengl, NULL);

  fontgl_init();
  font = fontgl_create("data/vera.ttf", 800, 600, 16);
  fontgl_set_color(font, 1,0,0);

  glEnable(GL_CULL_FACE);
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);

  SDL_WarpMouse(CENTERX,CENTERY);
  SDL_WM_GrabInput(SDL_GRAB_ON);
  SDL_ShowCursor(SDL_DISABLE);
}
开发者ID:BackupTheBerlios,项目名称:sfox-svn,代码行数:53,代码来源:starmain.c

示例11: install_grabs

static void install_grabs(void)
{
    SDL_WM_GrabInput(SDL_GRAB_ON);
    SDL_ShowCursor(0);

    // This is a bug in the current SDL/macosx...have to toggle it a few
    //  times to get the cursor to hide.
#if defined(MACOS_X)
    SDL_ShowCursor(1);
    SDL_ShowCursor(0);
#endif
}
开发者ID:martinez-zea,项目名称:localconflict,代码行数:12,代码来源:sdl_glimp.c

示例12: SDL_ShowCursor

//----------------------------------------------------------------------------
void Video::grabAndWarpMouse()
{
    SDL_ShowCursor(SDL_DISABLE);
    SDL_WM_GrabInput(SDL_GRAB_ON);
    SDL_WarpMouse( _width/2,  _height/2);
    SDL_Event event;
    while( SDL_PollEvent( &event))
    {
        //remove any queued up events due to warping, etc.
        ;
    }
}
开发者ID:BackupTheBerlios,项目名称:sotu-svn,代码行数:13,代码来源:Video.cpp

示例13: GrabInput

static void GrabInput(bool grab, bool hide_cursor, bool set_state) {
#if defined(ID_DEDICATED)
	return;
#else
	if (set_state)
		grabbed = grab;

	if (hide_cursor)
		SDL_ShowCursor(SDL_DISABLE);
	else
		SDL_ShowCursor(SDL_ENABLE);

	if (in_nograb.GetBool())
		grab = false;

	if (grab)
		SDL_WM_GrabInput(SDL_GRAB_ON);
	else
		SDL_WM_GrabInput(SDL_GRAB_OFF);
#endif
}
开发者ID:Edgarins29,项目名称:Doom3,代码行数:21,代码来源:events.cpp

示例14: Sys_ErrorDialog

/*
==============
Sys_ErrorDialog

Display an error message
==============
*/
void Sys_ErrorDialog( const char *error )
{
	char         buffer[ 1024 ];
	unsigned int size;
	int          f;
	const char   *homepath = Cvar_VariableString( "fs_homepath" );
	const char   *gamedir = Cvar_VariableString( "fs_game" );
	const char   *fileName = "crashlog.txt";
	char         *ospath = FS_BuildOSPath( homepath, gamedir, fileName );

	Sys_Print( va( "%s\n", error ) );

#if !defined(DEDICATED) && !defined(BUILD_TTY_CLIENT)
	// We may have grabbed input devices. Need to release.
	if ( SDL_WasInit( SDL_INIT_VIDEO ) )
	{
		SDL_WM_GrabInput( SDL_GRAB_OFF );
	}

	Sys_Dialog( DT_ERROR, va( "%s. See \"%s\" for details.", error, ospath ), "Error" );
#endif

	// Make sure the write path for the crashlog exists...
	if ( !Sys_Mkdir( ospath ) )
	{
		Com_Printf( "ERROR: couldn't create path '%s' for crash log.\n", ospath );
		return;
	}

	// We might be crashing because we maxed out the Quake MAX_FILE_HANDLES,
	// which will come through here, so we don't want to recurse forever by
	// calling FS_FOpenFileWrite()...use the Unix system APIs instead.
	f = open( ospath, O_CREAT | O_TRUNC | O_WRONLY, 0640 );

	if ( f == -1 )
	{
		Com_Printf( "ERROR: couldn't open %s\n", fileName );
		return;
	}

	// We're crashing, so we don't care much if write() or close() fails.
	while ( ( size = CON_LogRead( buffer, sizeof( buffer ) ) ) > 0 )
	{
		if ( write( f, buffer, size ) != size )
		{
			Com_Printf( "ERROR: couldn't fully write to %s\n", fileName );
			break;
		}
	}

	close( f );
}
开发者ID:elbeardmorez,项目名称:Unvanquished,代码行数:59,代码来源:sys_unix.c

示例15: I_UpdateInputGrabbing

//
// I_UpdateInputGrabbing
//
// Determines if SDL should grab the mouse based on the game window having
// focus and the status of the menu and console.
//
static void I_UpdateInputGrabbing()
{
#ifndef GCONSOLE
	bool can_grab = false;
	bool grabbed = SDL_WM_GrabInput(SDL_GRAB_QUERY);

	if (!window_focused)
		can_grab = false;
	else if (vid_fullscreen)
		can_grab = true;
	else if (nomouse)
		can_grab = false;
	else if (configuring_controls)
		can_grab = true;
	else if (menuactive || ConsoleState == c_down || paused)
		can_grab = false;
	else if ((gamestate == GS_LEVEL || gamestate == GS_INTERMISSION) && !demoplayback)
		can_grab = true;

	// force I_ResumeMouse or I_PauseMouse if toggling between fullscreen/windowed
	static float prev_vid_fullscreen = vid_fullscreen;
	if (vid_fullscreen != prev_vid_fullscreen)
		grabbed = !can_grab;
	prev_vid_fullscreen = vid_fullscreen;

	// check if the window focus changed (or menu/console status changed)
	if (can_grab && !grabbed)
	{
		SDL_WM_GrabInput(SDL_GRAB_ON);
		I_ResumeMouse();
		I_FlushInput();
	}
	else if (grabbed && !can_grab)
	{
		SDL_WM_GrabInput(SDL_GRAB_OFF);
		I_PauseMouse();
	}
#endif
}
开发者ID:JohnnyonFlame,项目名称:odamex,代码行数:45,代码来源:i_input.cpp


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