Ejemplo n.º 1
0
static void I_ReadMouse(void)
{
    int x, y;
    event_t ev;

#if SDL_VERSION_ATLEAST(1, 3, 0)
    SDL_GetRelativeMouseState(0, &x, &y);
#else
    SDL_GetRelativeMouseState(&x, &y);
#endif

    if (x != 0 || y != 0) 
    {
        ev.type = ev_mouse;
        ev.data1 = mouse_button_state;
        ev.data2 = AccelerateMouse(x);

        if (!novert)
        {
            ev.data3 = -AccelerateMouse(y);
        }
        else
        {
            ev.data3 = 0;
        }
        
        D_PostEvent(&ev);
    }

    if (MouseShouldBeGrabbed())
    {
        CenterMouse();
    }
}
Ejemplo n.º 2
0
void srv_get_mouse_movement()
{
	srv_mouse_button = SDL_GetRelativeMouseState(&srv_micky_x, &srv_micky_y);
	if (MouseRude)
	{
		SDL_WarpMouse(width/2,height/2);
		srv_Events();
		srv_crap_button = SDL_GetRelativeMouseState(&srv_crap_x, &srv_crap_y);
	}
}
Ejemplo n.º 3
0
static void CenterMouse(void)
{
    // Warp the the screen center

    SDL_WarpMouse(screen->w / 2, screen->h / 2);

    // Clear any relative movement caused by warping

    SDL_PumpEvents();
#if SDL_VERSION_ATLEAST(1, 3, 0)
    SDL_GetRelativeMouseState(0, NULL, NULL);
#else
    SDL_GetRelativeMouseState(NULL, NULL);
#endif
}
Ejemplo n.º 4
0
static void sdl_send_mouse_event(int dz)
{
    int dx, dy, state, buttons;
    state = SDL_GetRelativeMouseState(&dx, &dy);
    buttons = 0;
    if (state & SDL_BUTTON(SDL_BUTTON_LEFT))
        buttons |= MOUSE_EVENT_LBUTTON;
    if (state & SDL_BUTTON(SDL_BUTTON_RIGHT))
        buttons |= MOUSE_EVENT_RBUTTON;
    if (state & SDL_BUTTON(SDL_BUTTON_MIDDLE))
        buttons |= MOUSE_EVENT_MBUTTON;

    if (kbd_mouse_is_absolute()) {
        if (!absolute_enabled) {
            sdl_hide_cursor();
            if (gui_grab) {
                sdl_grab_end();
            }
            absolute_enabled = 1;
        }

        SDL_GetMouseState(&dx, &dy);
        dx = dx * 0x7FFF / width;
        dy = dy * 0x7FFF / height;
    } else if (absolute_enabled) {
        sdl_show_cursor();
        absolute_enabled = 0;
    }

    kbd_mouse_event(dx, dy, dz, buttons);
}
Ejemplo n.º 5
0
static void UpdateGrab(void)
{
    static boolean currently_grabbed = false;
    boolean grab;

    grab = MouseShouldBeGrabbed();

    if (screensaver_mode)
    {
        // Hide the cursor in screensaver mode

        SetShowCursor(false);
    }
    else if (grab && !currently_grabbed)
    {
        SetShowCursor(false);
        CenterMouse();
    }
    else if (!grab && currently_grabbed)
    {
        SetShowCursor(true);

        // When releasing the mouse from grab, warp the mouse cursor to
        // the bottom-right of the screen. This is a minimally distracting
        // place for it to appear - we may only have released the grab
        // because we're at an end of level intermission screen, for
        // example.

        SDL_WarpMouse(screen->w - 16, screen->h - 16);
        SDL_GetRelativeMouseState(NULL, NULL);
    }

    currently_grabbed = grab;

}
Ejemplo n.º 6
0
//
// Read the change in mouse state to generate mouse motion events
//
// This is to combine all mouse movement for a tic into one mouse
// motion event.
void I_ReadMouse(void)
{
    int x, y;
    event_t ev;

    SDL_GetRelativeMouseState(&x, &y);

    if (x != 0 || y != 0) 
    {
        ev.type = ev_mouse;
        ev.data1 = mouse_button_state;
        ev.data2 = AccelerateMouse(x);

        if (!novert)
        {
            ev.data3 = -AccelerateMouse(y);
        }
        else
        {
            ev.data3 = 0;
        }

        // XXX: undefined behaviour since event is scoped to
        // this function
        D_PostEvent(&ev);
    }
}
// FUNCTION ======	inputHanding
void inputHanding(){
    float posstep = 0.1;
	SDL_Event event;
	while(SDL_PollEvent(&event)){
		if( event.type == SDL_KEYDOWN ){
            switch( event.key.keysym.sym ){
                case SDLK_ESCAPE: quit(); break;
                case SDLK_w: modelPos[1] +=posstep; break;
                case SDLK_s: modelPos[1] -=posstep; break;
                case SDLK_a: modelPos[0] +=posstep; break;
                case SDLK_d: modelPos[0] -=posstep; break;
                case SDLK_q: modelPos[2] +=posstep*10; break;
                case SDLK_e: modelPos[2] -=posstep*10; break;
                //case SDLK_r:  world.fireProjectile( warrior1 ); break;
            }
		}
		if( event.type == SDL_QUIT){ quit();  };
	}

	int dmx,dmy;
	SDL_GetMouseState( &mouseX, &mouseY );
    Uint32 buttons = SDL_GetRelativeMouseState( &dmx, &dmy);
    //printf( " %i %i \n", mx,my );
    float mouseRotSpeed = 0.01;
    if ( buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) {
        Quat4f q; q.fromTrackball( 0, 0, -dmx*mouseRotSpeed, dmy*mouseRotSpeed );
        //printf( " %i %i  (%3.3f,%3.3f,%3.3f,%3.3f) \n", dmx,dmy, q.x,q.y,q.z,q.w );
        //qCamera.qmul_T( q );
        qCamera.qmul( q );
        //qCamera.normalize();
    }
}
Ejemplo n.º 8
0
//
// Read the change in mouse state to generate mouse motion events
//
// This is to combine all mouse movement for a tic into one mouse
// motion event.
static void I_ReadMouse(void)
{
  static int mouse_currently_grabbed = true;
  int x, y;
  event_t ev;

  if (!usemouse)
    return;

  if (!MouseShouldBeGrabbed())
  {
    mouse_currently_grabbed = false;
    return;
  }

  if (!mouse_currently_grabbed && !desired_fullscreen)
  {
    CenterMouse();
    mouse_currently_grabbed = true;
  }

  SDL_GetRelativeMouseState(&x, &y);

  if (x != 0 || y != 0) 
  {
    ev.type = ev_mouse;
    ev.data1 = I_SDLtoDoomMouseState(SDL_GetMouseState(NULL, NULL));
    ev.data2 = x << 5;
    ev.data3 = (-y) << 5;

    D_PostEvent(&ev);
  }

  CenterMouse();
}
Ejemplo n.º 9
0
void
checkMouse (data_t * gfx, mouse_t * mouse, int *sel, int nops, int off)
{
  int rx = 0, ry = 0;
  int no = MIN (gfx->mMaxOps, nops);

  mouse->clicked = SDL_GetMouseState (&(mouse->x), &(mouse->y));

  if (mouse->x >= gfx->menuX
      && mouse->x < gfx->menuX + gfx->menuW
      && mouse->y >= gfx->menuY
      && mouse->y < gfx->menuY + SFont_TextHeight (gfx->menufont) * no)
    {

      if (((mouse->clicked = SDL_GetRelativeMouseState (&rx, &ry)) || rx != 0
	   || ry != 0))
	*sel =
	  (mouse->y - gfx->menuY) / SFont_TextHeight (gfx->menufont) + off;

      if (!mouse->clicked)
	setMouseState (mouse, M_OVER);
      else
	setMouseState (mouse, M_DOWN);
    }
  else
    {
      if (!mouse->clicked)
	setMouseState (mouse, M_IDLE);
      else
	setMouseState (mouse, M_DOWN);
    }
}
Ejemplo n.º 10
0
void VGUI_CursorSelect(enum VGUI_DefaultCursor cursor )
{
	qboolean oldstate = host.mouse_visible;
	if( cls.key_dest != key_game || cl.refdef.paused )
		return;
#ifdef XASH_SDL
	
	switch( cursor )
	{
		case dc_user:
		case dc_none:
			host.mouse_visible = false;
			break;
		default:
		host.mouse_visible = true;
		SDL_SetRelativeMouseMode( SDL_FALSE );
		SDL_SetCursor( s_pDefaultCursor[cursor] );
		break;
	}
	if( host.mouse_visible )
	{
		SDL_ShowCursor( true );
	}
	else
	{
		SDL_ShowCursor( false );
		if( oldstate )
			SDL_GetRelativeMouseState( 0, 0 );
	}
	//SDL_SetRelativeMouseMode(false);
#endif
}
Ejemplo n.º 11
0
void CInput::MouseRelative(float *x, float *y)
{
	if(!m_InputGrabbed)
		return;

	int nx = 0, ny = 0;
	float Sens = g_Config.m_InpMousesens/100.0f;

	SDL_GetRelativeMouseState(&nx,&ny);

	vec2 j = vec2(0.0f, 0.0f);

	if(m_pJoystick)
	{
		const float Max = 50.0f;
		j.x = static_cast<float>(SDL_JoystickGetAxis(m_pJoystick, g_Config.m_JoystickX)) / 32768.0f * Max;
		j.y = static_cast<float>(SDL_JoystickGetAxis(m_pJoystick, g_Config.m_JoystickY)) / 32768.0f * Max;
		const float Len = length(j);

		if (Len <= g_Config.m_JoystickTolerance) {
			j = vec2(0.0f, 0.0f);
		} else {
			const vec2 nj = Len > 0.0f ? j / Len : vec2(0.0f, 0.0f);
			j = nj * fminf(Len, Max) - nj * g_Config.m_JoystickTolerance;
		}
	}

	*x = (nx + j.x)*Sens;
	*y = (ny + j.y)*Sens;
}
Ejemplo n.º 12
0
void sysdep_display_update_mouse(void)
{
   int i;
   int x,y;
   Uint8 buttons;

   if(sdl_always_use_mouse || (sdl_input_grabbed == SDL_GRAB_ON) ||
      sysdep_display_params.fullscreen)
   {
     buttons = SDL_GetRelativeMouseState( &x, &y);
     sysdep_display_mouse_data[0].deltas[0] = x;
     sysdep_display_mouse_data[0].deltas[1] = y;
     for(i=0;i<SYSDEP_DISPLAY_MOUSE_BUTTONS;i++) {
        sysdep_display_mouse_data[0].buttons[i] = buttons & (0x01 << i);
     }
   }
   else
   {
     sysdep_display_mouse_data[0].deltas[0] = 0;
     sysdep_display_mouse_data[0].deltas[1] = 0;
     for(i=0;i<SYSDEP_DISPLAY_MOUSE_BUTTONS;i++) {
        sysdep_display_mouse_data[0].buttons[i] = 0;
     }
   }
}
Ejemplo n.º 13
0
    void Player::handleEvent(SDL_Event e, SDL_Renderer *r, cpSpace *space, Skillmanager *sManager, cpVect & moveVect) {
        //Rotation
        if( e.type == SDL_MOUSEMOTION) {
            int x,y;
            SDL_GetRelativeMouseState(&x,&y);
            if( x<-1 )
                rotLeft();
            if( x>1 )
                rotRight();
        }

        //If the right button was pressed
        if ( e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_RIGHT ) {
            Rpressed = true;
        } else if ( e.type == SDL_MOUSEBUTTONUP && e.button.button == SDL_BUTTON_RIGHT ) {
                Rpressed = false;
                mVel = cpvzero;
        }

        //If the left button was pressed
        if ( e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT ) {
            Lpressed = true;
        } else if ( e.type == SDL_MOUSEBUTTONUP && e.button.button == SDL_BUTTON_LEFT ) {
            Lpressed = false;
        }

        // If q was pressed
        if ( (e.type == SDL_KEYDOWN) && (e.key.keysym.sym == SDLK_q)) {
                if (sManager->cdCheck(1) == 1 ) {
                    sManager->resetCd(1);
                    mVectp = cpvmult(vectorForward(),50);
                    moveVect = cpvadd(moveVect,mVectp);
                }
        }
    }
Ejemplo n.º 14
0
/*
===========
IN_Accumulate
===========
*/
void CL_DLLEXPORT IN_Accumulate(void)
{
	//only accumulate mouse if we are not moving the camera with the mouse
	if(!iMouseInUse && !g_iVisibleMouse)
	{
		if(mouseactive)
		{
#ifdef _WIN32
			if(!m_bRawInput)
			{
				if(!m_bMouseThread)
				{
					GetCursorPos(&current_pos);

					mx_accum += current_pos.x - gEngfuncs.GetWindowCenterX();
					my_accum += current_pos.y - gEngfuncs.GetWindowCenterY();
				}
			}
			else
#endif
			{
				int deltaX, deltaY;
				SDL_GetRelativeMouseState(&deltaX, &deltaY);
				mx_accum += deltaX;
				my_accum += deltaY;
			}
			// force the mouse to the center, so there's room to move
			IN_ResetMouse();
		}
	}
}
Ejemplo n.º 15
0
/**
 * Skips relative mouse movement for current frame.
 * We need to ignore the movement event generated when
 * mouse cursor is warped to window centre for the first time.
 */
static void IN_SkipRelativeMouseMove( void )
{
	if( mouse_relative ) {
		SDL_GetRelativeMouseState( &mx, &my );
		mx = my = 0;
	}
}
Ejemplo n.º 16
0
void Controls::Look(Player *pPlayer)
{
	int mouse_dx, mouse_dy;
	//float dAngle, dAzimuth;
	
	int MAX_MOUSE_MOTION = 40;
	
	(Uint8)SDL_GetRelativeMouseState(&mouse_dx, &mouse_dy);	
	
	if (mouse_dx>MAX_MOUSE_MOTION)
		mouse_dx = MAX_MOUSE_MOTION;
	else if (mouse_dx<-MAX_MOUSE_MOTION) 
		mouse_dx = -MAX_MOUSE_MOTION;
	
	if (mouse_dy>MAX_MOUSE_MOTION) 
		mouse_dy = MAX_MOUSE_MOTION;
	else if (mouse_dy<-MAX_MOUSE_MOTION) 
		mouse_dy = -MAX_MOUSE_MOTION;
	
	//mouse sensitivity is currently hard-coded..
	// TO DO: ensure that the sensitivity is such that, given the screen size,
	// the cross-hairs can move by less than a pixel relative to the furthest squares
	//dAngle   = 0.5e-3f * 2.0*M_PI*(float)mouse_dx;	
	//dAzimuth = -0.5e-3f * 2.0*M_PI*(float)mouse_dy;	
	
	int dims[2];
	SDLview::Instance()->getViewDims(dims);
	
	pPlayer->MoveCrossHairs(  static_cast<float>(mouse_dx) / static_cast<float>(dims[0]),
							 -static_cast<float>(mouse_dy) / static_cast<float>(dims[1]) );

}
Ejemplo n.º 17
0
static void GrabMouse(qbool grab, qbool raw)
{
	if ((grab && mouse_active && raw == in_raw.integer) || (!grab && !mouse_active) || !mouseinitialized || !sdl_window)
		return;

	if (!r_fullscreen.integer && in_grab_windowed_mouse.integer == 0)
	{
		if (!mouse_active)
			return;
		grab = 0;
	}
	// set initial position
	if (!raw && grab) {
		SDL_WarpMouseInWindow(sdl_window, glConfig.vidWidth / 2, glConfig.vidHeight / 2);
		old_x = glConfig.vidWidth / 2;
		old_y = glConfig.vidHeight / 2;
	}

	SDL_SetWindowGrab(sdl_window, grab ? SDL_TRUE : SDL_FALSE);
	SDL_SetRelativeMouseMode((raw && grab) ? SDL_TRUE : SDL_FALSE);
	SDL_GetRelativeMouseState(NULL, NULL);
	SDL_ShowCursor(grab ? SDL_DISABLE : SDL_ENABLE);
	SDL_SetCursor(NULL); /* Force rewrite of it */

	mouse_active = grab;
}
Ejemplo n.º 18
0
	void update(long double dt){
		_fireTimer -= (float)dt;

		if (_fireTimer < 0.f)
			_fireTimer = 0.f;

		int mouseRX, mouseRY;

		SDL_GetRelativeMouseState(&mouseRX, &mouseRY);

		// Rotate camera FPS style
		_physics->rotationForce(Vector3f((float)(mouseRY * _sensitivity * dt), (float)(mouseRX * _sensitivity * dt), 0.f));

		const Uint8* keyDown = SDL_GetKeyboardState(0);

		// W = forward
		if (keyDown[SDL_SCANCODE_W])
			_physics->pushForce((float)(_pushSpeed * dt));

		if (keyDown[SDL_SCANCODE_S])
			_physics->pushForce((float)((-_pushSpeed / 100) * dt));

		// Left Mouse = Fire bullet
		if (SDL_GetMouseState(0, 0) & SDL_BUTTON(SDL_BUTTON_LEFT) && !_fired && !_fireTimer){
			Entity* bullet = EntityManager::createEntity<Bullet>("bullet", ID());
			bullet->invoke(&Component::load);
			_fireTimer = 0.5f;
			_fired = true;
		}
		else if (!SDL_GetMouseState(0, 0) & SDL_BUTTON(SDL_BUTTON_LEFT) && _fired){
			_fired = false;
		}		
	}
Ejemplo n.º 19
0
void Input::DoKeyEvents()
{
	int numOfKeys;
	const Uint8* keyStates = SDL_GetKeyboardState(&numOfKeys);
	int mouse_x;
	int mouse_y;
	int mouse_relx;
	int mouse_rely;

	SDL_GetMouseState(&mouse_x, &mouse_y);
	SDL_GetRelativeMouseState(&mouse_relx, &mouse_rely);

	if(mouseMoveEvent)
	{
		mouseMoveEvent(mouse_x, mouse_y, mouse_relx, mouse_rely);
	}

	for(int i = 0; i < numOfKeys; i++)
	{
		if(keyStates[i])
		{
			//calls the function with the associated scan code
			auto it = function_map.find((SDL_Scancode)i);
			if(it != function_map.end())
			{
				it->second();
			}
		}
	}
}
Ejemplo n.º 20
0
//
// I_ReadMouse
//
// haleyjd 10/23/08: from Choco-Doom:
//
// Read the change in mouse state to generate mouse motion events
//
// This is to combine all mouse movement for a tic into one mouse
// motion event.
//
static void I_ReadMouse(SDL_Window *window)
{
   int x, y;
   event_t ev;
   static Uint8 previous_state = 137;
   Uint8 state;

   SDL_PumpEvents();

   state = SDL_GetRelativeMouseState(&x, &y);

   if(state != previous_state)
      previous_state = state;

   if(x != 0 || y != 0)
   {
      ev.type = ev_mouse;
      ev.data1 = SDL_MOUSEMOTION;
      if(mouseAccel_type == ACCELTYPE_CHOCO)
      {
         // SoM: So the values that go to Eternity should be 16.16 fixed point...
         ev.data2 =  AccelerateMouse(x);
         ev.data3 = -AccelerateMouse(y);
      }
      else if(mouseAccel_type == ACCELTYPE_CUSTOM) // [CG] 01/20/12 Custom acceleration
      {
         ev.data2 =  CustomAccelerateMouse(x);
         ev.data3 = -CustomAccelerateMouse(y);
      }

      D_PostEvent(&ev);
   }
}
Ejemplo n.º 21
0
void SDL_INPUT_Mouse(void)
{
	Uint8 buttons;

	if(INPUT_direct_mouse) {
		int potx, poty;

		buttons = SDL_GetMouseState(&potx, &poty);
		if(potx < 0) potx = 0;
		if(poty < 0) poty = 0;
		potx = (double)potx * (228.0 / (double)SDL_VIDEO_width);
		poty = (double)poty * (228.0 / (double)SDL_VIDEO_height);
		if(potx > 227) potx = 227;
		if(poty > 227) poty = 227;
		POKEY_POT_input[INPUT_mouse_port << 1] = 227 - potx;
		POKEY_POT_input[(INPUT_mouse_port << 1) + 1] = 227 - poty;
	} else {
		buttons = SDL_GetRelativeMouseState(&INPUT_mouse_delta_x, &INPUT_mouse_delta_y);
	}

	INPUT_mouse_buttons =
		((buttons & SDL_BUTTON(1)) ? 1 : 0) |
		((buttons & SDL_BUTTON(2)) ? 2 : 0) |
		((buttons & SDL_BUTTON(3)) ? 4 : 0);
}
Ejemplo n.º 22
0
void CameraController::Update(float dt)
{
    if (node == 0)
        return;

    const Uint8 *keys = SDL_GetKeyboardState(0);

    const float speed = 6.0f;
    const float sensitivity = 0.25f;

    // Camera movement

    Vector3 pos = node->GetPosition();
    Vector3 right, up, look;
    node->GetBasisVectors(right, up, look);

    Vector3 dir(0.0f, 0.0f, 0.0f);

    if (keys[SDL_SCANCODE_W])
        dir += look;
    if (keys[SDL_SCANCODE_S])
        dir -= look;
    if (keys[SDL_SCANCODE_A])
        dir -= right;
    if (keys[SDL_SCANCODE_D])
        dir += right;
    if (keys[SDL_SCANCODE_SPACE])
        dir += Vector3(0.0f, 1.0f, 0.0f);
    if (keys[SDL_SCANCODE_LCTRL])
        dir -= Vector3(0.0f, 1.0f, 0.0f);

    float speedup = 1.0f;
    if (keys[SDL_SCANCODE_LSHIFT])
        speedup = 2.0f;

    dir.SafeNormalize();
    pos += dir * (speed * speedup * dt);

    node->SetPosition(pos);

    // Camera rotation

    int relMouseX, relMouseY;
    if (SDL_GetRelativeMouseState(&relMouseX, &relMouseY) & SDL_BUTTON(SDL_BUTTON_LEFT))
    {
        SDL_SetRelativeMouseMode(SDL_TRUE);

        cameraAngles.y += relMouseX * sensitivity;
        cameraAngles.x += relMouseY * sensitivity;
        cameraAngles.y = Math::WrapAngleDegrees(cameraAngles.y);
        cameraAngles.x = Math::Clamp(cameraAngles.x, -90.0f, 90.0f);

        Matrix3 rot = Matrix3::RotationYXZ(cameraAngles);
        node->SetRotation(rot);
    }
    else
    {
        SDL_SetRelativeMouseMode(SDL_FALSE);
    }
}
Ejemplo n.º 23
0
void mouse_get_delta( int *dx, int *dy, int *dz )
{
	*dz = Mouse.delta_z;
	Mouse.delta_x = 0;
	Mouse.delta_y = 0;
	Mouse.delta_z = 0;
	SDL_GetRelativeMouseState(dx, dy);
}
Ejemplo n.º 24
0
static void sdl_poll_mouse(sdl_input_t *sdl)
{
   Uint8 btn = SDL_GetRelativeMouseState(&sdl->mouse_x, &sdl->mouse_y);
   SDL_GetMouseState(&sdl->mouse_abs_x, &sdl->mouse_abs_y);
   sdl->mouse_l = SDL_BUTTON(SDL_BUTTON_LEFT) & btn ? 1 : 0;
   sdl->mouse_r = SDL_BUTTON(SDL_BUTTON_RIGHT) & btn ? 1 : 0;
   sdl->mouse_m = SDL_BUTTON(SDL_BUTTON_MIDDLE) & btn ? 1 : 0;
}
Ejemplo n.º 25
0
void handle_mouse_motion(SDL_MouseMotionEvent motion){
  //  std::cout<<motion.xrel<< " "<<motion.yrel<<" "<<motion.x<< " "<<motion.y<<std::endl;
  int x=0, y=0;
  if(SDL_GetRelativeMouseState(&x, &y) & SDL_BUTTON(1) && x!=0 && y!= 0){
    int i = floor(x * (N+2)/SCREEN_WIDTH);
    int j = floor(y * (M+2)/SCREEN_HEIGHT);
    simulation->add_force(motion.x, motion.y, i, j);
    std::cout<<"button 1 "<<x<<" "<<y<<std::endl;
  }
  if(SDL_GetRelativeMouseState(&x, &y) & SDL_BUTTON(2) && x!=0 && y!= 0){
    std::cout<<"button 2 "<<x<<" "<<y<<std::endl;
  }
  if(SDL_GetRelativeMouseState(&x, &y) & SDL_BUTTON(3) && x!=0 && y!= 0){
    std::cout<<"button 3 "<<x<<" "<<y<<std::endl;
  }

}
Ejemplo n.º 26
0
/*
====================================================================
Enter a string and return True if ENTER received and False
if ESCAPE received.
====================================================================
*/
int enter_string( StkFont *font, char *caption, char *edit, int limit )
{
    SDL_Event event;
    int go_on = 1;
    int ret = 0;
    SDL_Surface *buffer = 
        stk_surface_create( SDL_SWSURFACE, stk_display->w, stk_display->h );
    int length = strlen( edit );

    SDL_SetColorKey(buffer, 0, 0);

    stk_surface_blit( stk_display, 0,0,-1,-1, buffer, 0,0 );
    font->align = STK_FONT_ALIGN_CENTER_X | STK_FONT_ALIGN_CENTER_Y;

    while ( go_on && !stk_quit_request ) {

        stk_surface_fill( stk_display, 0,0,-1,-1, 0x0 );
        stk_surface_alpha_blit( buffer, 0,0,-1,-1, stk_display, 0,0, 128 );
        stk_font_write(font, stk_display, stk_display->w / 2, stk_display->h / 2, STK_OPAQUE, caption);
        write_text_with_cursor(font, stk_display, stk_display->w / 2, stk_display->h / 2 + font->height, edit, STK_OPAQUE);
        stk_display_update( STK_UPDATE_ALL );
        event.type = SDL_NOEVENT;
        SDL_PollEvent(&event);
        /* TEST */
        switch ( event.type ) {
            case SDL_QUIT: stk_quit_request = 1; break;
            case SDL_KEYDOWN:
                switch ( event.key.keysym.sym ) {
                    case SDLK_ESCAPE:
                        ret = 0;
                        go_on = 0;
                        break;
                    case SDLK_RETURN:
                        ret = 1;
                        go_on = 0;
                        break;
                    case SDLK_BACKSPACE:
                        if ( length > 0 ) edit[--length] = 0;
                        break;
                    default:
                        if ( event.key.keysym.sym >= 32 && event.key.keysym.sym < 128 && length < limit ) {
                            edit[length++] = event.key.keysym.unicode;
                            edit[length] = 0;
                        }
                        break;
                }
                break;
        }
    }
    stk_surface_blit( buffer, 0,0,-1,-1, stk_display, 0,0 );
    stk_display_update( STK_UPDATE_ALL );
    SDL_FreeSurface(buffer);

    /* reset the relative position so paddle wont jump */
    SDL_GetRelativeMouseState(0,0);

    return ret;
}
Ejemplo n.º 27
0
static void sdl_grab_start(void)
{
    sdl_hide_cursor();
    SDL_WM_GrabInput(SDL_GRAB_ON);
    /* dummy read to avoid moving the mouse */
    SDL_GetRelativeMouseState(NULL, NULL);
    gui_grab = 1;
    sdl_update_caption();
}
Ejemplo n.º 28
0
// Warp the mouse back to the middle of the screen
static void CenterMouse(void)
{
  // Warp the the screen center
  SDL_WarpMouse((unsigned short)(REAL_SCREENWIDTH/2), (unsigned short)(REAL_SCREENHEIGHT/2));

  // Clear any relative movement caused by warping
  SDL_PumpEvents();
  SDL_GetRelativeMouseState(NULL, NULL);
}
Ejemplo n.º 29
0
void VGUI_SetVisible ( qboolean state )
{
	host.input_enabled=state;
	host.mouse_visible=state;
#ifdef XASH_SDL
	SDL_ShowCursor( state );
	if(!state) SDL_GetRelativeMouseState( 0, 0 );
#endif
}
Ejemplo n.º 30
0
TCOD_mouse_t TCOD_mouse_get_status() {
	TCOD_mouse_t ms;
	int charWidth, charHeight;
	static bool lbut=false;
	static bool rbut=false;
	static bool mbut=false;
	Uint8 buttons;
	SDL_PumpEvents();

	buttons = SDL_GetMouseState(&ms.x,&ms.y);
	SDL_GetRelativeMouseState(&ms.dx,&ms.dy);
	ms.lbutton = (buttons & SDL_BUTTON(SDL_BUTTON_LEFT)) ? 1 : 0;
	ms.lbutton_pressed=false;
	if (ms.lbutton) lbut=true;
	else if( lbut ) {
		lbut=false;
		ms.lbutton_pressed=true;
	}
	if ( mouse_force_bl ) {
		ms.lbutton_pressed=true;
		mouse_force_bl=false;
	}

	ms.rbutton = (buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) ? 1 : 0;
	ms.rbutton_pressed=false;
	if (ms.rbutton) rbut=true;
	else if( rbut ) {
		rbut=false;
		ms.rbutton_pressed=true;
	}
	if ( mouse_force_br ) {
		ms.rbutton_pressed=true;
		mouse_force_br=false;
	}

	ms.mbutton = (buttons & SDL_BUTTON(SDL_BUTTON_MIDDLE)) ? 1 : 0;
	ms.mbutton_pressed=false;
	if (ms.mbutton) mbut=true;
	else if( mbut ) {
		mbut=false;
		ms.mbutton_pressed=true;
	}
	if ( mouse_force_bm ) {
		ms.mbutton_pressed=true;
		mouse_force_bm=false;
	}

	ms.wheel_up = (buttons & SDL_BUTTON(SDL_BUTTON_WHEELUP)) ? 1 : 0;
	ms.wheel_down = (buttons & SDL_BUTTON(SDL_BUTTON_WHEELDOWN)) ? 1 : 0;
	TCOD_sys_get_char_size(&charWidth,&charHeight);
	ms.cx = (ms.x - fullscreen_offsetx) / charWidth;
	ms.cy = (ms.y - fullscreen_offsety) / charHeight;
	ms.dcx = ms.dx / charWidth;
	ms.dcy = ms.dy / charHeight;
	return ms;
}