pull vendor
This commit is contained in:
140
vendor/JXInput/0.3.4/java/de/hardcode/jxinput/virtual/JXVirtualInputDevice.java
vendored
Normal file
140
vendor/JXInput/0.3.4/java/de/hardcode/jxinput/virtual/JXVirtualInputDevice.java
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 9. April 2002, 22:40
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.virtual;
|
||||
|
||||
|
||||
import de.hardcode.jxinput.*;
|
||||
|
||||
|
||||
/**
|
||||
* Virtual input device.
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class JXVirtualInputDevice implements JXInputDevice
|
||||
{
|
||||
private static final String DEVICENAME = "Virtual Device";
|
||||
|
||||
/** The driver doing all the real work. */
|
||||
private final VirtualDriver mDriver = new VirtualDriver();
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of JXKeyboardInputDevice.
|
||||
*/
|
||||
public JXVirtualInputDevice()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The virtual input device needs to be updated regularly.
|
||||
*/
|
||||
public final void update( long deltaT )
|
||||
{
|
||||
//
|
||||
// Delegate the update call to the driver.
|
||||
//
|
||||
mDriver.update( deltaT );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a virtual axis object with a certain ID, e.g. Axis.ID_X.
|
||||
*/
|
||||
public VirtualAxis createAxis( int id )
|
||||
{
|
||||
VirtualAxis a;
|
||||
a = new VirtualAxis( id );
|
||||
mDriver.registerVirtualAxis( id, a );
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
public void removeAxis( VirtualAxis a )
|
||||
{
|
||||
mDriver.unregisterVirtualAxis( a );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//*********************************************************************************************
|
||||
//
|
||||
// Implement JXInputDevice
|
||||
//
|
||||
//*********************************************************************************************
|
||||
|
||||
public Axis getAxis(int idx)
|
||||
{
|
||||
return mDriver.getAxis( idx );
|
||||
}
|
||||
|
||||
|
||||
public Button getButton(int idx)
|
||||
{
|
||||
// No virtual buttons.
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Directional getDirectional(int idx)
|
||||
{
|
||||
// No virtual directionals.
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Maximum number of axes as an upper bound for index values. */
|
||||
public int getMaxNumberOfAxes()
|
||||
{
|
||||
return Axis.NUMBER_OF_ID;
|
||||
}
|
||||
|
||||
/** Maximum number of buttons as an upper bound for index values. */
|
||||
public int getMaxNumberOfButtons()
|
||||
{
|
||||
// No virtual buttons.
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Maximum number of directional features as an upper bound for index values. */
|
||||
public int getMaxNumberOfDirectionals()
|
||||
{
|
||||
// No virtual directionals.
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Devices may have a name.
|
||||
* This name might be provided by a system dependant driver.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return DEVICENAME;
|
||||
}
|
||||
|
||||
/** Actual number of available axes. */
|
||||
public int getNumberOfAxes()
|
||||
{
|
||||
// No axes on keyboard.
|
||||
return mDriver.getNumberOfAxes();
|
||||
}
|
||||
|
||||
/** Actual number of available buttons. */
|
||||
public int getNumberOfButtons()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Actual number of available directional features. */
|
||||
public int getNumberOfDirectionals()
|
||||
{
|
||||
// No directionals on keyboard.
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
207
vendor/JXInput/0.3.4/java/de/hardcode/jxinput/virtual/VirtualAxis.java
vendored
Normal file
207
vendor/JXInput/0.3.4/java/de/hardcode/jxinput/virtual/VirtualAxis.java
vendored
Normal file
@@ -0,0 +1,207 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 11. April 2002, 23:40
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.virtual;
|
||||
|
||||
import de.hardcode.jxinput.Axis;
|
||||
import de.hardcode.jxinput.Button;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author J<>rg Plewe
|
||||
*/
|
||||
public class VirtualAxis
|
||||
implements Axis
|
||||
{
|
||||
|
||||
private int mType = Axis.TRANSLATION;
|
||||
private final int mID;
|
||||
private String mName = "VirtualAxis";
|
||||
private double mCurrentValue = 0;
|
||||
|
||||
private Button mButtonIncrease = null;
|
||||
private Button mButtonDecrease = null;
|
||||
private double mSpeed = 1.0 / 500.0;
|
||||
private double mSpringSpeed = 1.0 / 500.0;
|
||||
|
||||
/**
|
||||
* Creates a new instance of VirtualAxis.
|
||||
*/
|
||||
public VirtualAxis( int id )
|
||||
{
|
||||
mID = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the type of this axis to be either <code>Axis.ROTATION</code>,
|
||||
* <code>Axis.TRANSLATION</code> or <code>Axis.SLIDER</code>.
|
||||
*/
|
||||
public void setType( int type )
|
||||
{
|
||||
if ( Axis.ROTATION != type
|
||||
&& Axis.TRANSLATION != type
|
||||
&& Axis.SLIDER != type
|
||||
)
|
||||
throw new InvalidParameterException( "Invalid type for axis!" );
|
||||
|
||||
mType = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update features under my control.
|
||||
*/
|
||||
final void update( long deltaT )
|
||||
{
|
||||
double change = mSpeed * deltaT;
|
||||
double springchange = mSpringSpeed * deltaT;
|
||||
boolean doincrease = ( null != mButtonIncrease && mButtonIncrease.getState() );
|
||||
boolean dodecrease = ( null != mButtonDecrease && mButtonDecrease.getState() );
|
||||
boolean iscontrolled = doincrease || dodecrease;
|
||||
|
||||
double controlledchange = 0.0;
|
||||
if ( doincrease )
|
||||
controlledchange += change;
|
||||
if ( dodecrease )
|
||||
controlledchange -= change;
|
||||
|
||||
mCurrentValue += controlledchange;
|
||||
|
||||
if ( mCurrentValue > 0.0 && ! doincrease )
|
||||
{
|
||||
springchange = Math.min( mCurrentValue, springchange );
|
||||
mCurrentValue -= springchange;
|
||||
}
|
||||
if ( mCurrentValue < 0.0 && ! dodecrease )
|
||||
{
|
||||
springchange = Math.min( -mCurrentValue, springchange );
|
||||
mCurrentValue += springchange;
|
||||
}
|
||||
|
||||
//
|
||||
// Hold value within range
|
||||
//
|
||||
if ( mCurrentValue > 1.0 )
|
||||
mCurrentValue = 1.0;
|
||||
double lowerlimit = Axis.SLIDER == mType ? 0.0 : -1.0;
|
||||
if ( mCurrentValue < lowerlimit )
|
||||
mCurrentValue = lowerlimit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the button to increase the axis for a single button axis.
|
||||
*/
|
||||
public final void setIncreaseButton( Button b )
|
||||
{
|
||||
if ( null == b )
|
||||
throw new InvalidParameterException( "Button may not be null!" );
|
||||
|
||||
mButtonIncrease = b;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the buttons to increase and descrease the axis.
|
||||
*/
|
||||
public final void setButtons( Button increase, Button decrease )
|
||||
{
|
||||
if ( null == increase || null == decrease )
|
||||
throw new InvalidParameterException( "Buttons may not be null!" );
|
||||
|
||||
mButtonIncrease = increase;
|
||||
mButtonDecrease = decrease;
|
||||
}
|
||||
|
||||
|
||||
public final void setSpeed( double speed )
|
||||
{
|
||||
mSpeed = speed;
|
||||
}
|
||||
|
||||
public final void setSpringSpeed( double springspeed )
|
||||
{
|
||||
mSpringSpeed = springspeed;
|
||||
}
|
||||
|
||||
|
||||
public final void setTimeFor0To1( int ms )
|
||||
{
|
||||
if ( 0 >= ms )
|
||||
mSpeed = 0.0;
|
||||
else
|
||||
mSpeed = 1.0/ ms;
|
||||
}
|
||||
public final void setTimeFor1To0( int ms )
|
||||
{
|
||||
if ( 0 >= ms )
|
||||
mSpringSpeed = 0.0;
|
||||
else
|
||||
mSpringSpeed = 1.0/ ms;
|
||||
}
|
||||
|
||||
|
||||
public final void setName( String name )
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
//*********************************************************************************************
|
||||
//
|
||||
// Implement Axis
|
||||
//
|
||||
//*********************************************************************************************
|
||||
|
||||
/**
|
||||
* Features may have a name provided e.g. by the driver.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inform about the resolution of the axis.
|
||||
*
|
||||
* @return resolution, e.g. 2^-16
|
||||
*/
|
||||
public double getResolution()
|
||||
{
|
||||
return 1.0/65536.0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the type of the axis.
|
||||
* @return [ TRANSLATION | ROTATION | SLIDER ]
|
||||
*/
|
||||
public int getType()
|
||||
{
|
||||
return mType;
|
||||
}
|
||||
|
||||
/** Returns the current value of the axis.
|
||||
* The range of the result depends on the axis type.
|
||||
*
|
||||
* @return value [-1.0,1.0] or [0.0,1.0]
|
||||
*/
|
||||
public double getValue()
|
||||
{
|
||||
return mCurrentValue;
|
||||
}
|
||||
|
||||
/** Denote wether this feature has changed beyond it's resolution since it got last
|
||||
* updated.
|
||||
*/
|
||||
public boolean hasChanged()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
95
vendor/JXInput/0.3.4/java/de/hardcode/jxinput/virtual/VirtualDriver.java
vendored
Normal file
95
vendor/JXInput/0.3.4/java/de/hardcode/jxinput/virtual/VirtualDriver.java
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 9. April 2002, 22:43
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.virtual;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import de.hardcode.jxinput.Axis;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This is the main worker class for JXVirtualInputDevice.
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
class VirtualDriver
|
||||
{
|
||||
|
||||
private final VirtualAxis[] mVAxes = new VirtualAxis[ Axis.NUMBER_OF_ID ];
|
||||
|
||||
/**
|
||||
* Creates a new instance of KeyboardDriver.
|
||||
*/
|
||||
VirtualDriver()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update features under my control.
|
||||
*/
|
||||
final void update( long deltaT )
|
||||
{
|
||||
//
|
||||
// Delegate the update call to the axes in use.
|
||||
//
|
||||
for ( int i = 0; i < mVAxes.length; i++ )
|
||||
{
|
||||
if ( null != mVAxes[ i ] )
|
||||
mVAxes[ i ].update( deltaT );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* How many axes are registered?
|
||||
*/
|
||||
final int getNumberOfAxes()
|
||||
{
|
||||
int ctr = 0;
|
||||
for ( int i = 0; i < mVAxes.length; i++ )
|
||||
{
|
||||
if ( null != mVAxes[ i ] )
|
||||
ctr++;
|
||||
}
|
||||
return ctr;
|
||||
}
|
||||
|
||||
Axis getAxis(int idx)
|
||||
{
|
||||
return mVAxes[ idx ];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Place a new axis under my observation.
|
||||
*/
|
||||
final void registerVirtualAxis( int id, VirtualAxis a )
|
||||
{
|
||||
mVAxes[ id ] = a;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an axis from my control.
|
||||
*/
|
||||
final void unregisterVirtualAxis( VirtualAxis a )
|
||||
{
|
||||
for ( int i = 0; i < mVAxes.length; ++i )
|
||||
{
|
||||
if ( mVAxes[ i ] == a )
|
||||
{
|
||||
mVAxes[ i ] = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
vendor/JXInput/0.3.4/java/de/hardcode/jxinput/virtual/package.html
vendored
Normal file
11
vendor/JXInput/0.3.4/java/de/hardcode/jxinput/virtual/package.html
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>de.hardcode.jxinput.virtual</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
Allows to define virtual axes that are not derived from any device
|
||||
but from other JXInput feature objects.
|
||||
</BODY>
|
||||
</HTML>
|
||||
Reference in New Issue
Block a user