Skip to content

Commit

Permalink
Front: Fix individual button scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Gillou68310 committed Jul 16, 2015
1 parent 5badbd4 commit 88dd98e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
41 changes: 24 additions & 17 deletions src/paulscode/android/mupen64plusae/input/map/TouchMap.java
Expand Up @@ -69,6 +69,9 @@ public class TouchMap
/** Folder containing the images. */
protected String skinFolder;

/** Scaling factor to apply to images. */
protected float scale = 1.0f;

/** Button scaling factor. */
protected ArrayList<Float> buttonScaling;

Expand Down Expand Up @@ -221,16 +224,16 @@ public void resize( int w, int h )
// Recompute button locations
for( int i = 0; i < buttonImages.size(); i++ )
{
buttonImages.get( i ).setScale( buttonScaling.get( i ) );
buttonImages.get( i ).setScale( ( buttonScaling.get( i ) * scale ) );
buttonImages.get( i ).fitPercent( buttonX.get( i ), buttonY.get( i ), w, h );
buttonMasks.get( i ).setScale( buttonScaling.get( i ) );
buttonMasks.get( i ).setScale( ( buttonScaling.get( i ) * scale ) );
buttonMasks.get( i ).fitPercent( buttonX.get( i ), buttonY.get( i ), w, h );
}

// Recompute analog background location
if( analogBackImage != null )
{
analogBackImage.setScale( analogBackScaling );
analogBackImage.setScale( ( analogBackScaling * scale ) );
analogBackImage.fitPercent( analogBackX, analogBackY, w, h );
}
}
Expand Down Expand Up @@ -263,7 +266,7 @@ public int getButtonPress( int xLocation, int yLocation )
{
// Get the mask color at this location
int c = buttonMasks.get( i ).image.getPixel( (int) ( ( xLocation - buttonMasks.get( i ).x ) /
buttonScaling.get( i ) ), (int) ( ( yLocation - buttonMasks.get( i ).y ) / buttonScaling.get( i ) ) );
( buttonScaling.get( i ) * scale ) ), (int) ( ( yLocation - buttonMasks.get( i ).y ) / ( buttonScaling.get( i ) * scale ) ) );

// Ignore the alpha component if any
int rgb = c & 0x00ffffff;
Expand Down Expand Up @@ -348,10 +351,10 @@ public Point getAnalogDisplacement( int xLocation, int yLocation )
return new Point( 0, 0 );

// Distance from center along x-axis
int dX = xLocation - ( analogBackImage.x + (int) ( analogBackImage.hWidth * analogBackScaling ) );
int dX = xLocation - ( analogBackImage.x + (int) ( analogBackImage.hWidth * ( analogBackScaling * scale ) ) );

// Distance from center along y-axis
int dY = yLocation - ( analogBackImage.y + (int) ( analogBackImage.hHeight * analogBackScaling ) );
int dY = yLocation - ( analogBackImage.y + (int) ( analogBackImage.hHeight * ( analogBackScaling * scale ) ) );

return new Point( dX, dY );
}
Expand All @@ -378,7 +381,7 @@ public Rect getAnalogFrame()
*/
public Point getConstrainedDisplacement( int dX, int dY )
{
final float dC = (int) ( analogMaximum * analogBackScaling );
final float dC = (int) ( analogMaximum * ( analogBackScaling * scale ) );
final float dA = dC * FloatMath.sqrt( 0.5f );
final float signX = (dX < 0) ? -1 : 1;
final float signY = (dY < 0) ? -1 : 1;
Expand All @@ -404,7 +407,7 @@ public Point getConstrainedDisplacement( int dX, int dY )
*/
public float getAnalogStrength( float displacement )
{
displacement /= analogBackScaling;
displacement /= ( analogBackScaling * scale );
float p = ( displacement - analogDeadzone ) / ( analogMaximum - analogDeadzone );
return Utility.clamp( p, 0.0f, 1.0f );
}
Expand All @@ -418,7 +421,7 @@ public float getAnalogStrength( float displacement )
*/
public boolean isInCaptureRange( float displacement )
{
displacement /= analogBackScaling;
displacement /= ( analogBackScaling * scale );
return ( displacement >= analogDeadzone ) && ( displacement < analogMaximum + analogPadding );
}

Expand Down Expand Up @@ -462,21 +465,25 @@ public void updateButton( Profile profile, String name, int w, int h )
{
analogBackX = x;
analogBackY = y;
analogBackImage.setScale( analogBackScaling );
analogBackImage.fitPercent( analogBackX, analogBackY, w, h );

if( analogForeImage != null )
{
int cX = analogBackImage.x + (int) ( analogBackImage.hWidth * ( analogBackScaling * scale ) );
int cY = analogBackImage.y + (int) ( analogBackImage.hHeight * ( analogBackScaling * scale ) );
analogForeImage.fitCenter( cX, cY, analogBackImage.x, analogBackImage.y,
(int) ( analogBackImage.width * ( analogBackScaling * scale ) ), (int) ( analogBackImage.height * ( analogBackScaling * scale ) ) );
}
}
else
{

for( int i = 0; i < buttonNames.size(); i++ )
{
if ( buttonNames.get( i ).equals( name ) )
{
buttonX.set( i, x );
buttonY.set( i, y );
buttonImages.get( i ).setScale( buttonScaling.get( i ) );
buttonImages.get( i ).fitPercent( buttonX.get( i ), buttonY.get( i ), w, h );
buttonMasks.get( i ).setScale( buttonScaling.get( i ) );
buttonMasks.get( i ).fitPercent( buttonX.get( i ), buttonY.get( i ), w, h );
}
}
Expand Down Expand Up @@ -548,7 +555,7 @@ protected void loadAnalog( Profile profile, boolean animated )
{
int x = profile.getInt( "analog-x", -1 );
int y = profile.getInt( "analog-y", -1 );
int scale = profile.getInt("analog-scale", 100);
int scaling = profile.getInt("analog-scale", 100);

if( x >= 0 && y >= 0 )
{
Expand All @@ -571,7 +578,7 @@ protected void loadAnalog( Profile profile, boolean animated )
analogDeadzone = (int) ( analogBackImage.hWidth * ( profile.getFloat( "analog-min", 1 ) / 100.0f ) );
analogMaximum = (int) ( analogBackImage.hWidth * ( profile.getFloat( "analog-max", 55 ) / 100.0f ) );
analogPadding = (int) ( analogBackImage.hWidth * ( profile.getFloat( "analog-buff", 55 ) / 100.0f ) );
analogBackScaling = (float) scale / 100.f;
analogBackScaling = (float) scaling / 100.f;
}
}

Expand All @@ -585,7 +592,7 @@ protected void loadButton( Profile profile, String name )
{
int x = profile.getInt( name + "-x", -1 );
int y = profile.getInt( name + "-y", -1 );
int scale = profile.getInt( name + "-scale", 100);
int scaling = profile.getInt( name + "-scale", 100);

if( x >= 0 && y >= 0 )
{
Expand All @@ -597,7 +604,7 @@ protected void loadButton( Profile profile, String name )
// Load the displayed and mask images
buttonImages.add( new Image( mResources, skinFolder + "/" + name + ".png" ) );
buttonMasks.add( new Image( mResources, skinFolder + "/" + name + "-mask.png" ) );
buttonScaling.add( (float) scale / 100.f );
buttonScaling.add( (float) scaling / 100.f );
}
}

Expand Down
33 changes: 14 additions & 19 deletions src/paulscode/android/mupen64plusae/input/map/VisibleTouchMap.java
Expand Up @@ -156,7 +156,7 @@ public void resize( int w, int h, DisplayMetrics metrics )
cacheHeight = h;
cacheMetrics = metrics;

float scale = 1.0f;
scale = 1.0f;

if( metrics != null )
{
Expand All @@ -170,11 +170,6 @@ public void resize( int w, int h, DisplayMetrics metrics )
scale = Math.min( scaleW, scaleH );
}

for( int i = 0; i < buttonScaling.size(); i++ )
buttonScaling.set( i, buttonScaling.get( i ) * scale);

analogBackScaling *= scale;

resize( w, h );
}

Expand All @@ -191,11 +186,11 @@ public void resize( int w, int h )
// Compute analog foreground location (centered)
if( analogBackImage != null && analogForeImage != null )
{
int cX = analogBackImage.x + (int) ( analogBackImage.hWidth * analogBackScaling );
int cY = analogBackImage.y + (int) ( analogBackImage.hHeight * analogBackScaling );
analogForeImage.setScale( analogBackScaling );
int cX = analogBackImage.x + (int) ( analogBackImage.hWidth * ( analogBackScaling * scale ) );
int cY = analogBackImage.y + (int) ( analogBackImage.hHeight * ( analogBackScaling * scale ) );
analogForeImage.setScale( ( analogBackScaling * scale ) );
analogForeImage.fitCenter( cX, cY, analogBackImage.x, analogBackImage.y,
(int) ( analogBackImage.width * analogBackScaling ), (int) ( analogBackImage.height * analogBackScaling ) );
(int) ( analogBackImage.width * ( analogBackScaling * scale ) ), (int) ( analogBackImage.height * ( analogBackScaling * scale ) ) );
}

// Compute auto-hold overlay locations
Expand All @@ -204,23 +199,23 @@ public void resize( int w, int h )
if( autoHoldImages[i] != null )
{
String name = ASSET_NAMES.get( i );
float scale = 1.f;
float scaling = 1.f;

for( int j = 0; j < buttonNames.size(); j++ )
{
if ( buttonNames.get( j ).equals( name ) )
scale = buttonScaling.get( j );
scaling = buttonScaling.get( j );
}

autoHoldImages[i].setScale( scale );
autoHoldImages[i].setScale( ( scaling * scale ) );
autoHoldImages[i].fitPercent( autoHoldX[i], autoHoldY[i], w, h );
}
}

// Compute FPS frame location

// TODO: FPS scaling
float fpsScale = 1.f;
float fpsScale = 1.f * scale;
if( mFpsMinScale > fpsScale )
fpsScale = mFpsMinScale;
if( mFpsFrame != null )
Expand Down Expand Up @@ -322,20 +317,20 @@ public boolean updateAnalog( float axisFractionX, float axisFractionY )
if( analogForeImage != null && analogBackImage != null )
{
// Get the location of stick center
int hX = (int) ( ( analogBackImage.hWidth + ( axisFractionX * analogMaximum ) ) * analogBackScaling );
int hY = (int) ( ( analogBackImage.hHeight - ( axisFractionY * analogMaximum ) ) * analogBackScaling );
int hX = (int) ( ( analogBackImage.hWidth + ( axisFractionX * analogMaximum ) ) * ( analogBackScaling * scale ) );
int hY = (int) ( ( analogBackImage.hHeight - ( axisFractionY * analogMaximum ) ) * ( analogBackScaling * scale ) );

// Use other values if invalid
if( hX < 0 )
hX = (int) ( analogBackImage.hWidth * analogBackScaling );
hX = (int) ( analogBackImage.hWidth * ( analogBackScaling * scale ) );
if( hY < 0 )
hY = (int) ( analogBackImage.hHeight * analogBackScaling );
hY = (int) ( analogBackImage.hHeight * ( analogBackScaling * scale ) );

// Update the position of the stick
int cX = analogBackImage.x + hX;
int cY = analogBackImage.y + hY;
analogForeImage.fitCenter( cX, cY, analogBackImage.x, analogBackImage.y,
(int) ( analogBackImage.width * analogBackScaling ), (int) ( analogBackImage.height * analogBackScaling ) );
(int) ( analogBackImage.width * ( analogBackScaling * scale ) ), (int) ( analogBackImage.height * ( analogBackScaling * scale ) ) );
return true;
}
return false;
Expand Down

0 comments on commit 88dd98e

Please sign in to comment.