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