mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 11:33:06 +00:00
square analog stick for testing
This commit is contained in:
parent
9f94465979
commit
d2e51e97c0
58
app/app.iml
58
app/app.iml
@ -8,12 +8,10 @@
|
|||||||
</facet>
|
</facet>
|
||||||
<facet type="android" name="Android">
|
<facet type="android" name="Android">
|
||||||
<configuration>
|
<configuration>
|
||||||
<option name="SELECTED_BUILD_VARIANT" value="nonRootDebug" />
|
<option name="SELECTED_BUILD_VARIANT" value="nonRootRelease" />
|
||||||
<option name="ASSEMBLE_TASK_NAME" value="assembleNonRootDebug" />
|
<option name="ASSEMBLE_TASK_NAME" value="assembleNonRootRelease" />
|
||||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileNonRootDebugSources" />
|
<option name="COMPILE_JAVA_TASK_NAME" value="compileNonRootReleaseSources" />
|
||||||
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleNonRootDebugTest" />
|
<option name="SOURCE_GEN_TASK_NAME" value="generateNonRootReleaseSources" />
|
||||||
<option name="SOURCE_GEN_TASK_NAME" value="generateNonRootDebugSources" />
|
|
||||||
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateNonRootDebugTestSources" />
|
|
||||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||||
@ -23,28 +21,22 @@
|
|||||||
</facet>
|
</facet>
|
||||||
</component>
|
</component>
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||||
<output url="file://$MODULE_DIR$/build/intermediates/classes/nonRoot/debug" />
|
<output url="file://$MODULE_DIR$/build/intermediates/classes/nonRoot/release" />
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/nonRoot/debug" isTestSource="false" generated="true" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/nonRoot/release" isTestSource="false" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/nonRoot/debug" isTestSource="false" generated="true" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/nonRoot/release" isTestSource="false" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/nonRoot/debug" isTestSource="false" generated="true" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/nonRoot/release" isTestSource="false" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/nonRoot/debug" isTestSource="false" generated="true" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/nonRoot/release" isTestSource="false" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/nonRoot/debug" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/nonRoot/release" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/nonRoot/debug" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/nonRoot/release" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/nonRootDebug/res" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/nonRootRelease/res" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/nonRootDebug/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/nonRootRelease/resources" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/nonRootDebug/assets" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/nonRootRelease/assets" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/nonRootDebug/aidl" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/nonRootRelease/aidl" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/nonRootDebug/java" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/nonRootRelease/java" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/nonRootDebug/jni" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/nonRootRelease/jni" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/nonRootDebug/rs" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/nonRootRelease/rs" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/nonRoot/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/nonRoot/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/nonRoot/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/nonRoot/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/nonRoot/debug" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/nonRoot/debug" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/nonRoot/res" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/nonRoot/res" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/nonRoot/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/nonRoot/resources" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/nonRoot/assets" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/nonRoot/assets" type="java-resource" />
|
||||||
@ -59,13 +51,13 @@
|
|||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestNonRoot/java" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTestNonRoot/java" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestNonRoot/jni" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTestNonRoot/jni" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestNonRoot/rs" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTestNonRoot/rs" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/release/res" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/release/resources" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/release/assets" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/release/aidl" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/release/java" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/release/jni" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/release/rs" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||||
|
@ -6,6 +6,7 @@ import android.graphics.Color;
|
|||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -19,6 +20,10 @@ public class AnalogStick extends VirtualControllerElement
|
|||||||
float radius_complete = 0;
|
float radius_complete = 0;
|
||||||
float radius_dead_zone = 0;
|
float radius_dead_zone = 0;
|
||||||
float radius_analog_stick = 0;
|
float radius_analog_stick = 0;
|
||||||
|
|
||||||
|
float position_pressed_x = 0;
|
||||||
|
float position_pressed_y = 0;
|
||||||
|
|
||||||
float position_stick_x = 0;
|
float position_stick_x = 0;
|
||||||
float position_stick_y = 0;
|
float position_stick_y = 0;
|
||||||
|
|
||||||
@ -75,9 +80,9 @@ public class AnalogStick extends VirtualControllerElement
|
|||||||
@Override
|
@Override
|
||||||
protected void onSizeChanged(int w, int h, int oldw, int oldh)
|
protected void onSizeChanged(int w, int h, int oldw, int oldh)
|
||||||
{
|
{
|
||||||
radius_complete = getPercent(getCorrectWidth() / 2, 95);
|
radius_complete = getPercent(getCorrectWidth() / 2, 40);
|
||||||
radius_dead_zone = getPercent(getCorrectWidth() / 2, 20);
|
radius_dead_zone = getPercent(getCorrectWidth() / 2, 20);
|
||||||
radius_analog_stick = getPercent(getCorrectWidth() / 2, 30);
|
radius_analog_stick = getPercent(getCorrectWidth() / 2, 20);
|
||||||
|
|
||||||
super.onSizeChanged(w, h, oldw, oldh);
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
}
|
}
|
||||||
@ -102,12 +107,21 @@ public class AnalogStick extends VirtualControllerElement
|
|||||||
paint.setColor(pressedColor);
|
paint.setColor(pressedColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius_complete, paint);
|
canvas.drawRect(0, 0,
|
||||||
|
getWidth(), getHeight(),
|
||||||
|
paint);
|
||||||
|
|
||||||
paint.setColor(normalColor);
|
paint.setColor(normalColor);
|
||||||
|
|
||||||
// draw dead zone
|
// draw dead zone
|
||||||
|
if (analogStickActive)
|
||||||
|
{
|
||||||
|
canvas.drawCircle(position_pressed_x, position_pressed_y, radius_dead_zone, paint);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius_dead_zone, paint);
|
canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius_dead_zone, paint);
|
||||||
|
}
|
||||||
|
|
||||||
// draw stick depending on state (no movement, moved, active(out of dead zone))
|
// draw stick depending on state (no movement, moved, active(out of dead zone))
|
||||||
if (analogStickActive)
|
if (analogStickActive)
|
||||||
@ -244,15 +258,54 @@ public class AnalogStick extends VirtualControllerElement
|
|||||||
|
|
||||||
private void updatePosition(float x, float y)
|
private void updatePosition(float x, float y)
|
||||||
{
|
{
|
||||||
float way_x = -(getWidth() / 2 - x);
|
float way_x;
|
||||||
float way_y = -(getHeight() / 2 - y);
|
float way_y;
|
||||||
|
|
||||||
|
if (x > position_pressed_x)
|
||||||
|
{
|
||||||
|
way_x = x - position_pressed_x;
|
||||||
|
|
||||||
|
if (way_x > radius_complete)
|
||||||
|
{
|
||||||
|
way_x = radius_complete;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
way_x = -(position_pressed_x - x);
|
||||||
|
|
||||||
|
if (way_x < -radius_complete)
|
||||||
|
{
|
||||||
|
way_x = -radius_complete;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y > position_pressed_y)
|
||||||
|
{
|
||||||
|
way_y = y - position_pressed_y;
|
||||||
|
|
||||||
|
if (way_y > radius_complete)
|
||||||
|
{
|
||||||
|
way_y = radius_complete;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
way_y = -(position_pressed_y - y);
|
||||||
|
|
||||||
|
if (way_y < -radius_complete)
|
||||||
|
{
|
||||||
|
way_y = -radius_complete;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float movement_x = 0;
|
float movement_x = 0;
|
||||||
float movement_y = 0;
|
float movement_y = 0;
|
||||||
|
|
||||||
double movement_radius = getMovementRadius(way_x, way_y);
|
double movement_radius = getMovementRadius(way_x, way_y);
|
||||||
double movement_angle = getAngle(way_x, way_y);
|
//double movement_angle = getAngle(way_x, way_y);
|
||||||
|
|
||||||
|
/*
|
||||||
// chop radius if out of outer circle
|
// chop radius if out of outer circle
|
||||||
if (movement_radius > (radius_complete - radius_analog_stick))
|
if (movement_radius > (radius_complete - radius_analog_stick))
|
||||||
{
|
{
|
||||||
@ -269,8 +322,13 @@ public class AnalogStick extends VirtualControllerElement
|
|||||||
movement_x = -(1 / complete) * correlated_x;
|
movement_x = -(1 / complete) * correlated_x;
|
||||||
movement_y = (1 / complete) * correlated_y;
|
movement_y = (1 / complete) * correlated_y;
|
||||||
|
|
||||||
position_stick_x = getWidth() / 2 - correlated_x;
|
*/
|
||||||
position_stick_y = getHeight() / 2 - correlated_y;
|
|
||||||
|
movement_x = (1 / radius_complete) * way_x;
|
||||||
|
movement_y = -(1 / radius_complete) * way_y;
|
||||||
|
|
||||||
|
position_stick_x = position_pressed_x + way_x;
|
||||||
|
position_stick_y = position_pressed_y + way_y;
|
||||||
|
|
||||||
// check if analog stick is outside of dead zone
|
// check if analog stick is outside of dead zone
|
||||||
if (movement_radius > radius_dead_zone)
|
if (movement_radius > radius_dead_zone)
|
||||||
@ -296,13 +354,17 @@ public class AnalogStick extends VirtualControllerElement
|
|||||||
// get masked (not specific to a pointer) action
|
// get masked (not specific to a pointer) action
|
||||||
int action = event.getActionMasked();
|
int action = event.getActionMasked();
|
||||||
_CLICK_STATE lastClickState = click_state;
|
_CLICK_STATE lastClickState = click_state;
|
||||||
boolean wasPressed = analogStickActive;
|
boolean wasActive = analogStickActive;
|
||||||
|
|
||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
case MotionEvent.ACTION_POINTER_DOWN:
|
case MotionEvent.ACTION_POINTER_DOWN:
|
||||||
{
|
{
|
||||||
|
position_pressed_x = event.getX();
|
||||||
|
position_pressed_y = event.getY();
|
||||||
|
|
||||||
|
analogStickActive = true;
|
||||||
viewPressed = true;
|
viewPressed = true;
|
||||||
// check for double click
|
// check for double click
|
||||||
if (lastClickState == _CLICK_STATE.SINGLE && timeLastClick + timeoutDoubleClick > System.currentTimeMillis())
|
if (lastClickState == _CLICK_STATE.SINGLE && timeLastClick + timeoutDoubleClick > System.currentTimeMillis())
|
||||||
@ -324,11 +386,6 @@ public class AnalogStick extends VirtualControllerElement
|
|||||||
}
|
}
|
||||||
case MotionEvent.ACTION_MOVE:
|
case MotionEvent.ACTION_MOVE:
|
||||||
{
|
{
|
||||||
if (analogStickActive || timeLastClick + timeoutDoubleClick < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
analogStickActive = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
@ -348,7 +405,7 @@ public class AnalogStick extends VirtualControllerElement
|
|||||||
{ // when is pressed calculate new positions (will trigger movement if necessary)
|
{ // when is pressed calculate new positions (will trigger movement if necessary)
|
||||||
updatePosition(event.getX(), event.getY());
|
updatePosition(event.getX(), event.getY());
|
||||||
}
|
}
|
||||||
else if (wasPressed)
|
else if (wasActive)
|
||||||
{
|
{
|
||||||
moveActionCallback(0, 0);
|
moveActionCallback(0, 0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user