implement analog input centering
This commit is contained in:
@@ -16,8 +16,9 @@ ScreenCenterImage::ScreenCenterImage( CString sClassName ) : ScreenWithMenuEleme
|
|||||||
{
|
{
|
||||||
LOG->Trace( "ScreenCenterImage::ScreenCenterImage()" );
|
LOG->Trace( "ScreenCenterImage::ScreenCenterImage()" );
|
||||||
|
|
||||||
#ifdef _XBOX
|
ZERO( m_fScale );
|
||||||
PREFSMAN->resizing = true;
|
|
||||||
|
#if defined(XBOX)
|
||||||
CStringArray strArray;
|
CStringArray strArray;
|
||||||
CString text("Use the left analog stick to translate the screen and right right analog stick to scale");
|
CString text("Use the left analog stick to translate the screen and right right analog stick to scale");
|
||||||
strArray.push_back(text);
|
strArray.push_back(text);
|
||||||
@@ -39,124 +40,147 @@ ScreenCenterImage::ScreenCenterImage( CString sClassName ) : ScreenWithMenuEleme
|
|||||||
ScreenCenterImage::~ScreenCenterImage()
|
ScreenCenterImage::~ScreenCenterImage()
|
||||||
{
|
{
|
||||||
LOG->Trace( "ScreenCenterImage::~ScreenCenterImage()" );
|
LOG->Trace( "ScreenCenterImage::~ScreenCenterImage()" );
|
||||||
#ifdef _XBOX
|
|
||||||
PREFSMAN->resizing = false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ScreenCenterImage::DrawPrimitives()
|
|
||||||
{
|
|
||||||
Screen::DrawPrimitives();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScreenCenterImage::Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
|
void ScreenCenterImage::Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
|
||||||
{
|
{
|
||||||
if( IsTransitioning() )
|
if( IsTransitioning() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( type == IET_RELEASE )
|
if( type == IET_FIRST_PRESS )
|
||||||
return;
|
|
||||||
|
|
||||||
bool bHoldingShift =
|
|
||||||
INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, KEY_RSHIFT)) ||
|
|
||||||
INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, KEY_LSHIFT));
|
|
||||||
|
|
||||||
int iScale;
|
|
||||||
switch( type )
|
|
||||||
{
|
{
|
||||||
case IET_SLOW_REPEAT: iScale = 4; break;
|
if( DeviceI.device == DEVICE_KEYBOARD && DeviceI.button == KEY_SPACE )
|
||||||
case IET_FAST_REPEAT: iScale = 16; break;
|
{
|
||||||
default: iScale = 1; break;
|
PREFSMAN->m_iCenterImageTranslateX = PREFSMAN->m_iCenterImageTranslateY = 0;
|
||||||
|
PREFSMAN->m_fCenterImageScaleX = PREFSMAN->m_fCenterImageScaleY = 1;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _XBOX
|
switch( MenuI.button )
|
||||||
switch(DeviceI.button)
|
|
||||||
{
|
|
||||||
case JOY_9:
|
|
||||||
if(!IsTransitioning())
|
|
||||||
{
|
{
|
||||||
|
case MENU_BUTTON_START:
|
||||||
SCREENMAN->PlayStartSound();
|
SCREENMAN->PlayStartSound();
|
||||||
StartTransitioning( SM_GoToNextScreen );
|
StartTransitioning( SM_GoToNextScreen );
|
||||||
}
|
return;
|
||||||
break;
|
|
||||||
case JOY_10:
|
case MENU_BUTTON_BACK:
|
||||||
if(!IsTransitioning())
|
|
||||||
{
|
|
||||||
SCREENMAN->PlayBackSound();
|
SCREENMAN->PlayBackSound();
|
||||||
StartTransitioning( SM_GoToPrevScreen );
|
StartTransitioning( SM_GoToPrevScreen );
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
#endif
|
}
|
||||||
|
|
||||||
switch( DeviceI.button )
|
|
||||||
{
|
|
||||||
case KEY_SPACE:
|
|
||||||
PREFSMAN->m_iCenterImageTranslateX = 0;
|
|
||||||
PREFSMAN->m_iCenterImageTranslateY = 0;
|
|
||||||
PREFSMAN->m_fCenterImageScaleX = 1;
|
|
||||||
PREFSMAN->m_fCenterImageScaleY = 1;
|
|
||||||
break;
|
|
||||||
case KEY_LEFT:
|
|
||||||
if( bHoldingShift )
|
|
||||||
PREFSMAN->m_fCenterImageScaleX -= 0.001f * iScale;
|
|
||||||
else
|
|
||||||
PREFSMAN->m_iCenterImageTranslateX -= 1 * iScale;
|
|
||||||
break;
|
|
||||||
case KEY_RIGHT:
|
|
||||||
if( bHoldingShift )
|
|
||||||
PREFSMAN->m_fCenterImageScaleX += 0.001f * iScale;
|
|
||||||
else
|
|
||||||
PREFSMAN->m_iCenterImageTranslateX += 1 * iScale;
|
|
||||||
break;
|
|
||||||
case KEY_UP:
|
|
||||||
if( bHoldingShift )
|
|
||||||
PREFSMAN->m_fCenterImageScaleY -= 0.001f * iScale;
|
|
||||||
else
|
|
||||||
PREFSMAN->m_iCenterImageTranslateY -= 1 * iScale;
|
|
||||||
break;
|
|
||||||
case KEY_DOWN:
|
|
||||||
if( bHoldingShift )
|
|
||||||
PREFSMAN->m_fCenterImageScaleY += 0.001f * iScale;
|
|
||||||
else
|
|
||||||
PREFSMAN->m_iCenterImageTranslateY += 1 * iScale;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool bIncrease = false;
|
||||||
|
|
||||||
|
Axis axis = NUM_AXES;
|
||||||
|
switch( MenuI.button )
|
||||||
|
{
|
||||||
|
case MENU_BUTTON_UP: axis = AXIS_TRANS_Y; bIncrease = false; break;
|
||||||
|
case MENU_BUTTON_DOWN: axis = AXIS_TRANS_Y; bIncrease = true; break;
|
||||||
|
case MENU_BUTTON_LEFT: axis = AXIS_TRANS_X; bIncrease = false; break;
|
||||||
|
case MENU_BUTTON_RIGHT: axis = AXIS_TRANS_X; bIncrease = true; break;
|
||||||
|
default:
|
||||||
|
if( !DeviceI.IsJoystick() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Secondary axes aren't always mapped correctly; for example, PS2 converters
|
||||||
|
* tend to map the right stick to weird things, and every one is different,
|
||||||
|
* so they usually won't work. */
|
||||||
switch( DeviceI.button )
|
switch( DeviceI.button )
|
||||||
{
|
{
|
||||||
case KEY_SPACE:
|
case JOY_UP: axis = AXIS_TRANS_Y; bIncrease = false; break;
|
||||||
case KEY_LEFT:
|
case JOY_DOWN: axis = AXIS_TRANS_Y; bIncrease = true; break;
|
||||||
case KEY_RIGHT:
|
case JOY_LEFT: axis = AXIS_TRANS_X; bIncrease = false; break;
|
||||||
case KEY_UP:
|
case JOY_RIGHT: axis = AXIS_TRANS_X; bIncrease = true; break;
|
||||||
case KEY_DOWN:
|
case JOY_UP_2: axis = AXIS_SCALE_Y; bIncrease = false; break;
|
||||||
|
case JOY_DOWN_2: axis = AXIS_SCALE_Y; bIncrease = true; break;
|
||||||
|
case JOY_LEFT_2: axis = AXIS_SCALE_X; bIncrease = false; break;
|
||||||
|
case JOY_RIGHT_2: axis = AXIS_SCALE_X; bIncrease = true; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( axis == NUM_AXES )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, KEY_RSHIFT)) ||
|
||||||
|
INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, KEY_LSHIFT)) )
|
||||||
|
{
|
||||||
|
const Axis switch_axis[] = { AXIS_SCALE_X, AXIS_SCALE_Y, AXIS_TRANS_X, AXIS_TRANS_Y };
|
||||||
|
axis = switch_axis[axis];
|
||||||
|
}
|
||||||
|
|
||||||
|
float fScale = 1.0f;
|
||||||
|
if( type == IET_RELEASE )
|
||||||
|
fScale = 0;
|
||||||
|
|
||||||
|
if( DeviceI.level >= 0 )
|
||||||
|
{
|
||||||
|
/* Increase the dead zone. XXX: input drivers should handle dead zones */
|
||||||
|
if( DeviceI.level < 0.10f )
|
||||||
|
fScale = 0;
|
||||||
|
else
|
||||||
|
fScale = SCALE( DeviceI.level, 0.10f, 1.0f, 0.0f, 1.0f );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( DeviceI.level < 0 )
|
||||||
|
{
|
||||||
|
switch( type )
|
||||||
|
{
|
||||||
|
case IET_SLOW_REPEAT: fScale *= 4; break;
|
||||||
|
case IET_FAST_REPEAT: fScale *= 16; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !bIncrease )
|
||||||
|
fScale *= -1;
|
||||||
|
|
||||||
|
Move( axis, fScale );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fScale = SCALE( fScale, 0.0f, 1.0f, 0.0f, 25.0f );
|
||||||
|
fScale = powf( fScale, 2.0f );
|
||||||
|
|
||||||
|
if( !bIncrease )
|
||||||
|
fScale *= -1;
|
||||||
|
|
||||||
|
m_fScale[axis] = fScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenCenterImage::Move( Axis axis, float fDelta )
|
||||||
|
{
|
||||||
|
float fValues[4] =
|
||||||
|
{
|
||||||
|
(float) PREFSMAN->m_iCenterImageTranslateX,
|
||||||
|
(float) PREFSMAN->m_iCenterImageTranslateY,
|
||||||
|
PREFSMAN->m_fCenterImageScaleX,
|
||||||
|
PREFSMAN->m_fCenterImageScaleY
|
||||||
|
};
|
||||||
|
|
||||||
|
if( axis == AXIS_SCALE_X || axis == AXIS_SCALE_Y )
|
||||||
|
fDelta *= 0.001f;
|
||||||
|
|
||||||
|
fValues[axis] += fDelta;
|
||||||
|
|
||||||
|
PREFSMAN->m_iCenterImageTranslateX = lrintf( fValues[0] );
|
||||||
|
PREFSMAN->m_iCenterImageTranslateY = lrintf( fValues[1] );
|
||||||
|
PREFSMAN->m_fCenterImageScaleX = fValues[2];
|
||||||
|
PREFSMAN->m_fCenterImageScaleY = fValues[3];
|
||||||
|
|
||||||
DISPLAY->ChangeCentering(
|
DISPLAY->ChangeCentering(
|
||||||
PREFSMAN->m_iCenterImageTranslateX,
|
PREFSMAN->m_iCenterImageTranslateX,
|
||||||
PREFSMAN->m_iCenterImageTranslateY,
|
PREFSMAN->m_iCenterImageTranslateY,
|
||||||
PREFSMAN->m_fCenterImageScaleX,
|
PREFSMAN->m_fCenterImageScaleX,
|
||||||
PREFSMAN->m_fCenterImageScaleY );
|
PREFSMAN->m_fCenterImageScaleY );
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch( DeviceI.button )
|
void ScreenCenterImage::Update( float fDeltaTime )
|
||||||
{
|
{
|
||||||
case KEY_ESC:
|
for( int i = 0; i < NUM_AXES; ++i )
|
||||||
if(!IsTransitioning())
|
Move( (Axis) i, m_fScale[i] * fDeltaTime );
|
||||||
{
|
|
||||||
SCREENMAN->PlayBackSound();
|
Screen::Update( fDeltaTime );
|
||||||
StartTransitioning( SM_GoToPrevScreen );
|
|
||||||
}
|
|
||||||
case KEY_ENTER:
|
|
||||||
case KEY_KP_ENTER:
|
|
||||||
if(!IsTransitioning())
|
|
||||||
{
|
|
||||||
SCREENMAN->PlayStartSound();
|
|
||||||
StartTransitioning( SM_GoToNextScreen );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenCenterImage::HandleScreenMessage( const ScreenMessage SM )
|
void ScreenCenterImage::HandleScreenMessage( const ScreenMessage SM )
|
||||||
|
|||||||
@@ -16,11 +16,16 @@ public:
|
|||||||
virtual ~ScreenCenterImage();
|
virtual ~ScreenCenterImage();
|
||||||
|
|
||||||
virtual void Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI );
|
virtual void Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI );
|
||||||
|
virtual void Update( float fDeltaTime );
|
||||||
virtual void HandleScreenMessage( const ScreenMessage SM );
|
virtual void HandleScreenMessage( const ScreenMessage SM );
|
||||||
void DrawPrimitives();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BitmapText m_textInstructions;
|
BitmapText m_textInstructions;
|
||||||
|
|
||||||
|
enum Axis { AXIS_TRANS_X, AXIS_TRANS_Y, AXIS_SCALE_X, AXIS_SCALE_Y, NUM_AXES };
|
||||||
|
float m_fScale[NUM_AXES];
|
||||||
|
|
||||||
|
void Move( Axis axis, float fDeltaTime );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user