mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-08 03:51:39 +12:00
Run clang-format on .java files
This commit is contained in:
parent
a40e74a15d
commit
ed0864d24f
24 changed files with 634 additions and 771 deletions
1
src/pandroid/app/.gitignore
vendored
1
src/pandroid/app/.gitignore
vendored
|
@ -1 +0,0 @@
|
||||||
/build
|
|
|
@ -36,11 +36,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
implementation("androidx.appcompat:appcompat:1.6.1")
|
implementation("androidx.appcompat:appcompat:1.6.1")
|
||||||
implementation("com.google.android.material:material:1.8.0")
|
implementation("com.google.android.material:material:1.8.0")
|
||||||
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
|
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
|
||||||
testImplementation("junit:junit:4.13.2")
|
|
||||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
|
||||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
|
|
||||||
}
|
}
|
|
@ -1,10 +1,7 @@
|
||||||
package com.panda3ds.pandroid;
|
package com.panda3ds.pandroid;
|
||||||
|
|
||||||
public class AlberDriver {
|
public class AlberDriver {
|
||||||
|
AlberDriver() { super(); }
|
||||||
AlberDriver() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static native void Initialize();
|
public static native void Initialize();
|
||||||
public static native void RunFrame(int fbo);
|
public static native void RunFrame(int fbo);
|
||||||
|
@ -18,7 +15,5 @@ public class AlberDriver {
|
||||||
public static native void TouchScreenUp();
|
public static native void TouchScreenUp();
|
||||||
public static native void TouchScreenDown(int x, int y);
|
public static native void TouchScreenDown(int x, int y);
|
||||||
|
|
||||||
static {
|
static { System.loadLibrary("Alber"); }
|
||||||
System.loadLibrary("Alber");
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -2,5 +2,4 @@ package com.panda3ds.pandroid.app;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
public class BaseActivity extends AppCompatActivity {
|
public class BaseActivity extends AppCompatActivity {}
|
||||||
}
|
|
||||||
|
|
|
@ -9,9 +9,7 @@ import android.view.WindowManager;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.panda3ds.pandroid.R;
|
import com.panda3ds.pandroid.R;
|
||||||
import com.panda3ds.pandroid.utils.Constants;
|
import com.panda3ds.pandroid.utils.Constants;
|
||||||
import com.panda3ds.pandroid.view.PandaGlSurfaceView;
|
import com.panda3ds.pandroid.view.PandaGlSurfaceView;
|
||||||
|
@ -27,7 +25,6 @@ public class GameActivity extends BaseActivity {
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
if (!intent.hasExtra(Constants.EXTRA_PATH)) {
|
if (!intent.hasExtra(Constants.EXTRA_PATH)) {
|
||||||
|
|
||||||
setContentView(new FrameLayout(this));
|
setContentView(new FrameLayout(this));
|
||||||
Toast.makeText(this, "Invalid rom path!", Toast.LENGTH_LONG).show();
|
Toast.makeText(this, "Invalid rom path!", Toast.LENGTH_LONG).show();
|
||||||
finish();
|
finish();
|
||||||
|
@ -45,12 +42,9 @@ public class GameActivity extends BaseActivity {
|
||||||
|
|
||||||
controllerLayout.initialize();
|
controllerLayout.initialize();
|
||||||
|
|
||||||
((CheckBox)findViewById(R.id.hide_screen_controller))
|
((CheckBox) findViewById(R.id.hide_screen_controller)).setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
findViewById(R.id.overlay_controller).setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE);
|
||||||
findViewById(R.id.overlay_controller)
|
|
||||||
.setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.panda3ds.pandroid.app;
|
package com.panda3ds.pandroid.app;
|
||||||
|
|
||||||
|
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
|
||||||
|
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
|
||||||
import static android.provider.Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION;
|
import static android.provider.Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -7,15 +9,10 @@ import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
|
|
||||||
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
|
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
|
|
||||||
import com.panda3ds.pandroid.utils.Constants;
|
|
||||||
import com.panda3ds.pandroid.R;
|
import com.panda3ds.pandroid.R;
|
||||||
|
import com.panda3ds.pandroid.utils.Constants;
|
||||||
import com.panda3ds.pandroid.utils.PathUtils;
|
import com.panda3ds.pandroid.utils.PathUtils;
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity {
|
public class MainActivity extends BaseActivity {
|
||||||
|
@ -44,9 +41,7 @@ public class MainActivity extends BaseActivity {
|
||||||
|
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
findViewById(R.id.load_rom).setOnClickListener(v->{
|
findViewById(R.id.load_rom).setOnClickListener(v -> { openFile(); });
|
||||||
openFile();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,8 +50,7 @@ public class MainActivity extends BaseActivity {
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
String path = PathUtils.getPath(getApplicationContext(), data.getData());
|
String path = PathUtils.getPath(getApplicationContext(), data.getData());
|
||||||
Toast.makeText(getApplicationContext(), "pandroid opening " + path, Toast.LENGTH_LONG).show();
|
Toast.makeText(getApplicationContext(), "pandroid opening " + path, Toast.LENGTH_LONG).show();
|
||||||
startActivity(new Intent(this, GameActivity.class)
|
startActivity(new Intent(this, GameActivity.class).putExtra(Constants.EXTRA_PATH, path));
|
||||||
.putExtra(Constants.EXTRA_PATH, path));
|
|
||||||
}
|
}
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,22 +2,16 @@ package com.panda3ds.pandroid.math;
|
||||||
|
|
||||||
public class Vector2 {
|
public class Vector2 {
|
||||||
public float x, y;
|
public float x, y;
|
||||||
public Vector2(Vector2 value){
|
public Vector2(Vector2 value) { this(value.x, value.y); }
|
||||||
this(value.x,value.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector2(float x, float y) {
|
public Vector2(float x, float y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float distanceTo(Vector2 vec){
|
public float distanceTo(Vector2 vec) { return distance(x, y, vec.x, vec.y); }
|
||||||
return distance(x,y,vec.x, vec.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float distance(float x, float y, float x2, float y2){
|
public static float distance(float x, float y, float x2, float y2) { return (float) Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2)); }
|
||||||
return (float) Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(float x, float y) {
|
public void set(float x, float y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.panda3ds.pandroid.utils;
|
package com.panda3ds.pandroid.utils;
|
||||||
|
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
|
||||||
public static final int INPUT_KEY_UP = 1 << 6;
|
public static final int INPUT_KEY_UP = 1 << 6;
|
||||||
public static final int INPUT_KEY_DOWN = 1 << 7;
|
public static final int INPUT_KEY_DOWN = 1 << 7;
|
||||||
public static final int INPUT_KEY_LEFT = 1 << 5;
|
public static final int INPUT_KEY_LEFT = 1 << 5;
|
||||||
|
|
|
@ -10,25 +10,19 @@ import android.provider.DocumentsContract;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
|
||||||
public class PathUtils {
|
public class PathUtils {
|
||||||
|
|
||||||
public static String getPath(final Context context, final Uri uri) {
|
public static String getPath(final Context context, final Uri uri) {
|
||||||
|
|
||||||
// DocumentProvider
|
// DocumentProvider
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, uri)) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, uri)) {
|
||||||
|
|
||||||
if (isExternalStorageDocument(uri)) { // ExternalStorageProvider
|
if (isExternalStorageDocument(uri)) { // ExternalStorageProvider
|
||||||
final String docId = DocumentsContract.getDocumentId(uri);
|
final String docId = DocumentsContract.getDocumentId(uri);
|
||||||
final String[] split = docId.split(":");
|
final String[] split = docId.split(":");
|
||||||
final String type = split[0];
|
final String type = split[0];
|
||||||
String storageDefinition;
|
String storageDefinition;
|
||||||
|
|
||||||
|
|
||||||
if ("primary".equalsIgnoreCase(type)) {
|
if ("primary".equalsIgnoreCase(type)) {
|
||||||
|
|
||||||
return Environment.getExternalStorageDirectory() + "/" + split[1];
|
return Environment.getExternalStorageDirectory() + "/" + split[1];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (Environment.isExternalStorageRemovable()) {
|
if (Environment.isExternalStorageRemovable()) {
|
||||||
storageDefinition = "EXTERNAL_STORAGE";
|
storageDefinition = "EXTERNAL_STORAGE";
|
||||||
|
|
||||||
|
@ -42,8 +36,7 @@ public class PathUtils {
|
||||||
} else if (isDownloadsDocument(uri)) { // DownloadsProvider
|
} else if (isDownloadsDocument(uri)) { // DownloadsProvider
|
||||||
|
|
||||||
final String id = DocumentsContract.getDocumentId(uri);
|
final String id = DocumentsContract.getDocumentId(uri);
|
||||||
final Uri contentUri = ContentUris.withAppendedId(
|
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
|
||||||
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
|
|
||||||
|
|
||||||
return getDataColumn(context, contentUri, null, null);
|
return getDataColumn(context, contentUri, null, null);
|
||||||
|
|
||||||
|
@ -62,9 +55,7 @@ public class PathUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
final String selection = "_id=?";
|
final String selection = "_id=?";
|
||||||
final String[] selectionArgs = new String[]{
|
final String[] selectionArgs = new String[] {split[1]};
|
||||||
split[1]
|
|
||||||
};
|
|
||||||
|
|
||||||
return getDataColumn(context, contentUri, selection, selectionArgs);
|
return getDataColumn(context, contentUri, selection, selectionArgs);
|
||||||
}
|
}
|
||||||
|
@ -72,8 +63,7 @@ public class PathUtils {
|
||||||
} else if ("content".equalsIgnoreCase(uri.getScheme())) { // MediaStore (and general)
|
} else if ("content".equalsIgnoreCase(uri.getScheme())) { // MediaStore (and general)
|
||||||
|
|
||||||
// Return the remote address
|
// Return the remote address
|
||||||
if (isGooglePhotosUri(uri))
|
if (isGooglePhotosUri(uri)) return uri.getLastPathSegment();
|
||||||
return uri.getLastPathSegment();
|
|
||||||
|
|
||||||
return getDataColumn(context, uri, null, null);
|
return getDataColumn(context, uri, null, null);
|
||||||
|
|
||||||
|
@ -85,12 +75,9 @@ public class PathUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
|
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
|
||||||
|
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
final String column = "_data";
|
final String column = "_data";
|
||||||
final String[] projection = {
|
final String[] projection = {column};
|
||||||
column
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
|
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
|
||||||
|
@ -99,27 +86,16 @@ public class PathUtils {
|
||||||
return cursor.getString(column_index);
|
return cursor.getString(column_index);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null)
|
if (cursor != null) cursor.close();
|
||||||
cursor.close();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isExternalStorageDocument(Uri uri) { return "com.android.externalstorage.documents".equals(uri.getAuthority()); }
|
||||||
|
|
||||||
public static boolean isExternalStorageDocument(Uri uri) {
|
public static boolean isDownloadsDocument(Uri uri) { return "com.android.providers.downloads.documents".equals(uri.getAuthority()); }
|
||||||
return "com.android.externalstorage.documents".equals(uri.getAuthority());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public static boolean isMediaDocument(Uri uri) { return "com.android.providers.media.documents".equals(uri.getAuthority()); }
|
||||||
|
|
||||||
public static boolean isDownloadsDocument(Uri uri) {
|
public static boolean isGooglePhotosUri(Uri uri) { return "com.google.android.apps.photos.content".equals(uri.getAuthority()); }
|
||||||
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isMediaDocument(Uri uri) {
|
|
||||||
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isGooglePhotosUri(Uri uri) {
|
|
||||||
return "com.google.android.apps.photos.content".equals(uri.getAuthority());
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,22 +1,20 @@
|
||||||
package com.panda3ds.pandroid.view;
|
package com.panda3ds.pandroid.view;
|
||||||
|
|
||||||
import javax.microedition.khronos.egl.EGLConfig;
|
|
||||||
import javax.microedition.khronos.opengles.GL10;
|
|
||||||
|
|
||||||
import static android.opengl.GLES32.*;
|
import static android.opengl.GLES32.*;
|
||||||
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.opengl.GLSurfaceView;
|
import android.opengl.GLSurfaceView;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.panda3ds.pandroid.AlberDriver;
|
import com.panda3ds.pandroid.AlberDriver;
|
||||||
import com.panda3ds.pandroid.view.renderer.layout.ConsoleLayout;
|
import com.panda3ds.pandroid.utils.Constants;
|
||||||
import com.panda3ds.pandroid.view.renderer.ConsoleRenderer;
|
import com.panda3ds.pandroid.view.renderer.ConsoleRenderer;
|
||||||
|
import com.panda3ds.pandroid.view.renderer.layout.ConsoleLayout;
|
||||||
import com.panda3ds.pandroid.view.renderer.layout.DefaultScreenLayout;
|
import com.panda3ds.pandroid.view.renderer.layout.DefaultScreenLayout;
|
||||||
|
import javax.microedition.khronos.egl.EGLConfig;
|
||||||
|
import javax.microedition.khronos.opengles.GL10;
|
||||||
|
|
||||||
public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer {
|
public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer {
|
||||||
|
|
||||||
private final String romPath;
|
private final String romPath;
|
||||||
private ConsoleLayout displayLayout;
|
private ConsoleLayout displayLayout;
|
||||||
private int screenWidth, screenHeight;
|
private int screenWidth, screenHeight;
|
||||||
|
@ -79,19 +77,15 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer
|
||||||
Rect bottomScreen = displayLayout.getBottomDisplayBounds();
|
Rect bottomScreen = displayLayout.getBottomDisplayBounds();
|
||||||
|
|
||||||
glBlitFramebuffer(
|
glBlitFramebuffer(
|
||||||
0, Constants.N3DS_FULL_HEIGHT,
|
0, Constants.N3DS_FULL_HEIGHT, Constants.N3DS_WIDTH, Constants.N3DS_HALF_HEIGHT, topScreen.left, screenHeight - topScreen.top,
|
||||||
Constants.N3DS_WIDTH, Constants.N3DS_HALF_HEIGHT,
|
topScreen.right, screenHeight - topScreen.bottom, GL_COLOR_BUFFER_BIT, GL_LINEAR
|
||||||
topScreen.left, screenHeight - topScreen.top,
|
);
|
||||||
topScreen.right, screenHeight - topScreen.bottom,
|
|
||||||
GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
|
||||||
|
|
||||||
// Remove the black bars on the bottom screen
|
// Remove the black bars on the bottom screen
|
||||||
glBlitFramebuffer(
|
glBlitFramebuffer(
|
||||||
40, Constants.N3DS_HALF_HEIGHT,
|
40, Constants.N3DS_HALF_HEIGHT, Constants.N3DS_WIDTH - 40, 0, bottomScreen.left, screenHeight - bottomScreen.top, bottomScreen.right,
|
||||||
Constants.N3DS_WIDTH - 40, 0,
|
screenHeight - bottomScreen.bottom, GL_COLOR_BUFFER_BIT, GL_LINEAR
|
||||||
bottomScreen.left, screenHeight - bottomScreen.top,
|
);
|
||||||
bottomScreen.right, screenHeight - bottomScreen.bottom,
|
|
||||||
GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,7 @@ import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.opengl.GLSurfaceView;
|
import android.opengl.GLSurfaceView;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.panda3ds.pandroid.math.Vector2;
|
import com.panda3ds.pandroid.math.Vector2;
|
||||||
import com.panda3ds.pandroid.utils.Constants;
|
import com.panda3ds.pandroid.utils.Constants;
|
||||||
import com.panda3ds.pandroid.view.controller.TouchEvent;
|
import com.panda3ds.pandroid.view.controller.TouchEvent;
|
||||||
|
@ -26,9 +24,7 @@ public class PandaGlSurfaceView extends GLSurfaceView implements TouchScreenNode
|
||||||
setRenderer(renderer);
|
setRenderer(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConsoleRenderer getRenderer() {
|
public ConsoleRenderer getRenderer() { return renderer; }
|
||||||
return renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.panda3ds.pandroid.view;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
import com.panda3ds.pandroid.AlberDriver;
|
import com.panda3ds.pandroid.AlberDriver;
|
||||||
import com.panda3ds.pandroid.R;
|
import com.panda3ds.pandroid.R;
|
||||||
import com.panda3ds.pandroid.utils.Constants;
|
import com.panda3ds.pandroid.utils.Constants;
|
||||||
|
@ -11,51 +10,38 @@ import com.panda3ds.pandroid.view.controller.nodes.Button;
|
||||||
import com.panda3ds.pandroid.view.controller.nodes.Joystick;
|
import com.panda3ds.pandroid.view.controller.nodes.Joystick;
|
||||||
|
|
||||||
public class PandaLayoutController extends ControllerLayout {
|
public class PandaLayoutController extends ControllerLayout {
|
||||||
public PandaLayoutController(Context context) {
|
public PandaLayoutController(Context context) { super(context); }
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PandaLayoutController(Context context, AttributeSet attrs) {
|
public PandaLayoutController(Context context, AttributeSet attrs) { super(context, attrs); }
|
||||||
super(context, attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PandaLayoutController(Context context, AttributeSet attrs, int defStyleAttr) {
|
public PandaLayoutController(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PandaLayoutController(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
public PandaLayoutController(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
int[] keyButtonList = {
|
int[] keyButtonList = {R.id.button_a, Constants.INPUT_KEY_A, R.id.button_b, Constants.INPUT_KEY_B,
|
||||||
R.id.button_a, Constants.INPUT_KEY_A,
|
R.id.button_y, Constants.INPUT_KEY_Y, R.id.button_x, Constants.INPUT_KEY_X,
|
||||||
R.id.button_b, Constants.INPUT_KEY_B,
|
|
||||||
R.id.button_y, Constants.INPUT_KEY_Y,
|
|
||||||
R.id.button_x, Constants.INPUT_KEY_X,
|
|
||||||
|
|
||||||
R.id.button_left, Constants.INPUT_KEY_LEFT,
|
R.id.button_left, Constants.INPUT_KEY_LEFT, R.id.button_right, Constants.INPUT_KEY_RIGHT,
|
||||||
R.id.button_right, Constants.INPUT_KEY_RIGHT,
|
R.id.button_up, Constants.INPUT_KEY_UP, R.id.button_down, Constants.INPUT_KEY_DOWN,
|
||||||
R.id.button_up, Constants.INPUT_KEY_UP,
|
|
||||||
R.id.button_down, Constants.INPUT_KEY_DOWN,
|
|
||||||
|
|
||||||
R.id.button_start, Constants.INPUT_KEY_START,
|
R.id.button_start, Constants.INPUT_KEY_START, R.id.button_select, Constants.INPUT_KEY_SELECT,
|
||||||
R.id.button_select, Constants.INPUT_KEY_SELECT,
|
|
||||||
|
|
||||||
R.id.button_l, Constants.INPUT_KEY_L,
|
R.id.button_l, Constants.INPUT_KEY_L, R.id.button_r, Constants.INPUT_KEY_R};
|
||||||
R.id.button_r, Constants.INPUT_KEY_R
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; i < keyButtonList.length; i += 2) {
|
for (int i = 0; i < keyButtonList.length; i += 2) {
|
||||||
final int keyCode = keyButtonList[i + 1];
|
final int keyCode = keyButtonList[i + 1];
|
||||||
((Button) findViewById(keyButtonList[i])).setStateListener((btn, pressed) -> {
|
((Button) findViewById(keyButtonList[i])).setStateListener((btn, pressed) -> {
|
||||||
if (pressed) AlberDriver.KeyDown(keyCode);
|
if (pressed)
|
||||||
else AlberDriver.KeyUp(keyCode);
|
AlberDriver.KeyDown(keyCode);
|
||||||
|
else
|
||||||
|
AlberDriver.KeyUp(keyCode);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
((Joystick)findViewById(R.id.left_analog))
|
((Joystick) findViewById(R.id.left_analog)).setJoystickListener((joystick, axisX, axisY) -> {
|
||||||
.setJoystickListener((joystick, axisX, axisY) -> {
|
|
||||||
AlberDriver.SetCirclepadAxis((int) (axisX * 0x9C), (int) (axisY * 0x9C) * -1);
|
AlberDriver.SetCirclepadAxis((int) (axisX * 0x9C), (int) (axisY * 0x9C) * -1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -7,31 +7,22 @@ import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
|
|
||||||
import com.panda3ds.pandroid.math.Vector2;
|
import com.panda3ds.pandroid.math.Vector2;
|
||||||
import com.panda3ds.pandroid.utils.Constants;
|
import com.panda3ds.pandroid.utils.Constants;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class ControllerLayout extends RelativeLayout {
|
public class ControllerLayout extends RelativeLayout {
|
||||||
|
|
||||||
private final HashMap<Integer, ControllerNode> activeTouchEvents = new HashMap<>();
|
private final HashMap<Integer, ControllerNode> activeTouchEvents = new HashMap<>();
|
||||||
private final ArrayList<ControllerNode> controllerNodes = new ArrayList<>();
|
private final ArrayList<ControllerNode> controllerNodes = new ArrayList<>();
|
||||||
|
|
||||||
public ControllerLayout(Context context) {
|
public ControllerLayout(Context context) { this(context, null); }
|
||||||
this(context,null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ControllerLayout(Context context, AttributeSet attrs) {
|
public ControllerLayout(Context context, AttributeSet attrs) { this(context, attrs, 0); }
|
||||||
this(context, attrs,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ControllerLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
public ControllerLayout(Context context, AttributeSet attrs, int defStyleAttr) { this(context, attrs, defStyleAttr, 0); }
|
||||||
this(context, attrs, defStyleAttr,0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
public ControllerLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
public ControllerLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
@ -152,5 +143,4 @@ public class ControllerLayout extends RelativeLayout {
|
||||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
package com.panda3ds.pandroid.view.controller;
|
package com.panda3ds.pandroid.view.controller;
|
||||||
|
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.panda3ds.pandroid.math.Vector2;
|
import com.panda3ds.pandroid.math.Vector2;
|
||||||
|
|
||||||
public interface ControllerNode {
|
public interface ControllerNode {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
default Vector2 getPosition() {
|
default Vector2 getPosition() {
|
||||||
View me = (View) this;
|
View me = (View) this;
|
||||||
|
@ -18,9 +14,7 @@ public interface ControllerNode {
|
||||||
return new Vector2(position[0], position[1]);
|
return new Vector2(position[0], position[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean isVisible(){
|
default boolean isVisible() { return ((View) this).isShown(); }
|
||||||
return ((View)this).isShown();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull Vector2 getSize();
|
@NonNull Vector2 getSize();
|
||||||
|
|
||||||
|
|
|
@ -8,17 +8,11 @@ public class TouchEvent {
|
||||||
private final int action;
|
private final int action;
|
||||||
private final float x, y;
|
private final float x, y;
|
||||||
|
|
||||||
public float getX() {
|
public float getX() { return x; }
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getY() {
|
public float getY() { return y; }
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAction() {
|
public int getAction() { return action; }
|
||||||
return action;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TouchEvent(float x, float y, int action) {
|
public TouchEvent(float x, float y, int action) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
|
|
|
@ -2,23 +2,15 @@ package com.panda3ds.pandroid.view.controller.nodes;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.widget.AppCompatTextView;
|
import androidx.appcompat.widget.AppCompatTextView;
|
||||||
|
|
||||||
import com.panda3ds.pandroid.view.controller.ControllerNode;
|
import com.panda3ds.pandroid.view.controller.ControllerNode;
|
||||||
|
|
||||||
public abstract class BasicControllerNode extends AppCompatTextView implements ControllerNode {
|
public abstract class BasicControllerNode extends AppCompatTextView implements ControllerNode {
|
||||||
public BasicControllerNode(@NonNull Context context) {
|
public BasicControllerNode(@NonNull Context context) { super(context); }
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasicControllerNode(@NonNull Context context, @Nullable AttributeSet attrs) {
|
public BasicControllerNode(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); }
|
||||||
super(context, attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasicControllerNode(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
public BasicControllerNode(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,9 @@ import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.widget.AppCompatTextView;
|
import androidx.appcompat.widget.AppCompatTextView;
|
||||||
|
|
||||||
import com.panda3ds.pandroid.math.Vector2;
|
import com.panda3ds.pandroid.math.Vector2;
|
||||||
import com.panda3ds.pandroid.view.controller.ControllerNode;
|
import com.panda3ds.pandroid.view.controller.ControllerNode;
|
||||||
import com.panda3ds.pandroid.view.controller.TouchEvent;
|
import com.panda3ds.pandroid.view.controller.TouchEvent;
|
||||||
|
@ -48,13 +46,9 @@ public class Button extends BasicControllerNode {
|
||||||
setGravity(Gravity.CENTER);
|
setGravity(Gravity.CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStateListener(ButtonStateListener stateListener) {
|
public void setStateListener(ButtonStateListener stateListener) { this.stateListener = stateListener; }
|
||||||
this.stateListener = stateListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPressed() {
|
public boolean isPressed() { return pressed; }
|
||||||
return pressed;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,16 +6,13 @@ import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.widget.AppCompatTextView;
|
import androidx.appcompat.widget.AppCompatTextView;
|
||||||
|
|
||||||
import com.panda3ds.pandroid.math.Vector2;
|
import com.panda3ds.pandroid.math.Vector2;
|
||||||
import com.panda3ds.pandroid.view.controller.ControllerNode;
|
import com.panda3ds.pandroid.view.controller.ControllerNode;
|
||||||
import com.panda3ds.pandroid.view.controller.TouchEvent;
|
import com.panda3ds.pandroid.view.controller.TouchEvent;
|
||||||
import com.panda3ds.pandroid.view.controller.listeners.JoystickListener;
|
import com.panda3ds.pandroid.view.controller.listeners.JoystickListener;
|
||||||
|
|
||||||
|
|
||||||
public class Joystick extends BasicControllerNode implements ControllerNode {
|
public class Joystick extends BasicControllerNode implements ControllerNode {
|
||||||
private float stick_x = 0;
|
private float stick_x = 0;
|
||||||
private float stick_y = 0;
|
private float stick_y = 0;
|
||||||
|
@ -25,13 +22,9 @@ public class Joystick extends BasicControllerNode implements ControllerNode {
|
||||||
|
|
||||||
private JoystickListener joystickListener;
|
private JoystickListener joystickListener;
|
||||||
|
|
||||||
public Joystick(Context context) {
|
public Joystick(Context context) { this(context, null); }
|
||||||
this(context,null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Joystick(Context context, AttributeSet attrs) {
|
public Joystick(Context context, AttributeSet attrs) { this(context, attrs, 0); }
|
||||||
this(context, attrs,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Joystick(Context context, AttributeSet attrs, int defStyleAttr) {
|
public Joystick(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
|
@ -72,11 +65,9 @@ public class Joystick extends BasicControllerNode implements ControllerNode {
|
||||||
stick_x = Math.max(-1.0f, Math.min(1.0f, stick_x));
|
stick_x = Math.max(-1.0f, Math.min(1.0f, stick_x));
|
||||||
stick_y = Math.max(-1.0f, Math.min(1.0f, stick_y));
|
stick_y = Math.max(-1.0f, Math.min(1.0f, stick_y));
|
||||||
|
|
||||||
|
|
||||||
float x = middle - middleIconSize + rx;
|
float x = middle - middleIconSize + rx;
|
||||||
float y = middle - middleIconSize + ry;
|
float y = middle - middleIconSize + ry;
|
||||||
|
|
||||||
|
|
||||||
Drawable foreground = getForeground();
|
Drawable foreground = getForeground();
|
||||||
if (foreground != null) {
|
if (foreground != null) {
|
||||||
foreground.setBounds((int) x, (int) y, (int) (x + analogIconSize), (int) (y + analogIconSize));
|
foreground.setBounds((int) x, (int) y, (int) (x + analogIconSize), (int) (y + analogIconSize));
|
||||||
|
@ -86,16 +77,9 @@ public class Joystick extends BasicControllerNode implements ControllerNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 getAxis() {
|
public Vector2 getAxis() { return new Vector2(Math.max(-1.0F, Math.min(1.0F, stick_x)), Math.max(-1.0F, Math.min(1.0F, stick_y))); }
|
||||||
return new Vector2(
|
|
||||||
Math.max(-1.0F, Math.min(1.0F, stick_x)),
|
|
||||||
Math.max(-1.0F, Math.min(1.0F, stick_y))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setJoystickListener(JoystickListener joystickListener) {
|
public void setJoystickListener(JoystickListener joystickListener) { this.joystickListener = joystickListener; }
|
||||||
this.joystickListener = joystickListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
|
@ -105,7 +89,6 @@ public class Joystick extends BasicControllerNode implements ControllerNode {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTouch(TouchEvent event) {
|
public void onTouch(TouchEvent event) {
|
||||||
|
|
||||||
float middle = size_width / 2.0F;
|
float middle = size_width / 2.0F;
|
||||||
|
|
||||||
float x = event.getX();
|
float x = event.getX();
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.panda3ds.pandroid.view.controller.nodes;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.panda3ds.pandroid.AlberDriver;
|
import com.panda3ds.pandroid.AlberDriver;
|
||||||
import com.panda3ds.pandroid.R;
|
import com.panda3ds.pandroid.R;
|
||||||
import com.panda3ds.pandroid.utils.Constants;
|
import com.panda3ds.pandroid.utils.Constants;
|
||||||
|
@ -13,11 +12,11 @@ import com.panda3ds.pandroid.view.renderer.ConsoleRenderer;
|
||||||
|
|
||||||
public interface TouchScreenNodeImpl extends ControllerNode {
|
public interface TouchScreenNodeImpl extends ControllerNode {
|
||||||
default void onTouchScreenPress(ConsoleRenderer renderer, TouchEvent event) {
|
default void onTouchScreenPress(ConsoleRenderer renderer, TouchEvent event) {
|
||||||
|
|
||||||
View me = (View) this;
|
View me = (View) this;
|
||||||
boolean hasDownEvent = me.getTag(R.id.TagEventHasDown) != null && (boolean) me.getTag(R.id.TagEventHasDown);
|
boolean hasDownEvent = me.getTag(R.id.TagEventHasDown) != null && (boolean) me.getTag(R.id.TagEventHasDown);
|
||||||
|
|
||||||
Rect bounds = renderer.getLayout().getBottomDisplayBounds();;
|
Rect bounds = renderer.getLayout().getBottomDisplayBounds();
|
||||||
|
;
|
||||||
|
|
||||||
if (event.getX() >= bounds.left && event.getY() >= bounds.top && event.getX() <= bounds.right && event.getY() <= bounds.bottom) {
|
if (event.getX() >= bounds.left && event.getY() >= bounds.top && event.getX() <= bounds.right && event.getY() <= bounds.bottom) {
|
||||||
int x = (int) (event.getX() - bounds.left);
|
int x = (int) (event.getX() - bounds.left);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.panda3ds.pandroid.view.renderer.layout;
|
package com.panda3ds.pandroid.view.renderer.layout;
|
||||||
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
|
||||||
import com.panda3ds.pandroid.math.Vector2;
|
import com.panda3ds.pandroid.math.Vector2;
|
||||||
|
|
||||||
public interface ConsoleLayout {
|
public interface ConsoleLayout {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.panda3ds.pandroid.view.renderer.layout;
|
||||||
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.util.Size;
|
import android.util.Size;
|
||||||
|
|
||||||
import com.panda3ds.pandroid.math.Vector2;
|
import com.panda3ds.pandroid.math.Vector2;
|
||||||
|
|
||||||
public class DefaultScreenLayout implements ConsoleLayout {
|
public class DefaultScreenLayout implements ConsoleLayout {
|
||||||
|
@ -35,7 +34,6 @@ public class DefaultScreenLayout implements ConsoleLayout {
|
||||||
int screenHeight = (int) screenSize.y;
|
int screenHeight = (int) screenSize.y;
|
||||||
|
|
||||||
if (screenWidth > screenHeight) {
|
if (screenWidth > screenHeight) {
|
||||||
|
|
||||||
int topDisplayWidth = (int) ((screenHeight / topSourceSize.y) * topSourceSize.x);
|
int topDisplayWidth = (int) ((screenHeight / topSourceSize.y) * topSourceSize.x);
|
||||||
int topDisplayHeight = screenHeight;
|
int topDisplayHeight = screenHeight;
|
||||||
|
|
||||||
|
@ -46,7 +44,6 @@ public class DefaultScreenLayout implements ConsoleLayout {
|
||||||
|
|
||||||
int bottomDisplayHeight = (int) (((screenWidth - topDisplayWidth) / bottomSourceSize.x) * bottomSourceSize.y);
|
int bottomDisplayHeight = (int) (((screenWidth - topDisplayWidth) / bottomSourceSize.x) * bottomSourceSize.y);
|
||||||
|
|
||||||
|
|
||||||
topDisplay.set(0, 0, topDisplayWidth, topDisplayHeight);
|
topDisplay.set(0, 0, topDisplayWidth, topDisplayHeight);
|
||||||
bottomDisplay.set(topDisplayWidth, 0, topDisplayWidth + (screenWidth - topDisplayWidth), bottomDisplayHeight);
|
bottomDisplay.set(topDisplayWidth, 0, topDisplayWidth + (screenWidth - topDisplayWidth), bottomDisplayHeight);
|
||||||
} else {
|
} else {
|
||||||
|
@ -68,7 +65,6 @@ public class DefaultScreenLayout implements ConsoleLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getBottomDisplayBounds() {
|
public Rect getBottomDisplayBounds() {
|
||||||
return bottomDisplay;
|
return bottomDisplay;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue