mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 14:45:41 +12:00
TouchScreen input (#6)
This commit is contained in:
parent
9aded6e556
commit
7c9d17f5ca
13 changed files with 349 additions and 128 deletions
|
@ -2,24 +2,20 @@ package com.panda3ds.pandroid.app;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.os.Handler;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.MotionEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
|
||||||
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.AlberDriver;
|
|
||||||
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;
|
||||||
import com.panda3ds.pandroid.view.PandaLayoutController;
|
import com.panda3ds.pandroid.view.PandaLayoutController;
|
||||||
import com.panda3ds.pandroid.view.controller.ControllerLayout;
|
|
||||||
|
|
||||||
public class GameActivity extends BaseActivity {
|
public class GameActivity extends BaseActivity {
|
||||||
private PandaGlSurfaceView pandaSurface;
|
private PandaGlSurfaceView pandaSurface;
|
||||||
|
@ -46,11 +42,21 @@ public class GameActivity extends BaseActivity {
|
||||||
.addView(pandaSurface, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
.addView(pandaSurface, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
|
|
||||||
controllerLayout = findViewById(R.id.controller_layout);
|
controllerLayout = findViewById(R.id.controller_layout);
|
||||||
|
|
||||||
controllerLayout.initialize();
|
controllerLayout.initialize();
|
||||||
|
|
||||||
((CheckBox)findViewById(R.id.hide_screen_controller))
|
((CheckBox)findViewById(R.id.hide_screen_controller))
|
||||||
.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
controllerLayout.setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE);
|
findViewById(R.id.overlay_controller)
|
||||||
|
.setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
||||||
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,8 @@ 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(){
|
this(value.x,value.y);
|
||||||
this(0.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector2(float value){
|
|
||||||
this(value,value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2(float x, float y){
|
public Vector2(float x, float y){
|
||||||
|
@ -23,4 +18,9 @@ public class Vector2 {
|
||||||
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) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,19 @@ 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.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.utils.Constants;
|
import com.panda3ds.pandroid.view.renderer.layout.ConsoleLayout;
|
||||||
|
import com.panda3ds.pandroid.view.renderer.ConsoleRenderer;
|
||||||
|
import com.panda3ds.pandroid.view.renderer.layout.DefaultScreenLayout;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer {
|
||||||
|
|
||||||
public class PandaGlRenderer implements GLSurfaceView.Renderer {
|
|
||||||
|
|
||||||
private final String romPath;
|
private final String romPath;
|
||||||
|
private ConsoleLayout displayLayout;
|
||||||
private int screenWidth, screenHeight;
|
private int screenWidth, screenHeight;
|
||||||
private int screenTexture;
|
private int screenTexture;
|
||||||
public int screenFbo;
|
public int screenFbo;
|
||||||
|
@ -24,6 +26,10 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer {
|
||||||
PandaGlRenderer(String romPath) {
|
PandaGlRenderer(String romPath) {
|
||||||
super();
|
super();
|
||||||
this.romPath = romPath;
|
this.romPath = romPath;
|
||||||
|
|
||||||
|
screenWidth = Resources.getSystem().getDisplayMetrics().widthPixels;
|
||||||
|
screenHeight = Resources.getSystem().getDisplayMetrics().heightPixels;
|
||||||
|
setLayout(new DefaultScreenLayout());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,8 +46,6 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer {
|
||||||
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
|
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
|
||||||
Log.i("pandroid", glGetString(GL_EXTENSIONS));
|
Log.i("pandroid", glGetString(GL_EXTENSIONS));
|
||||||
Log.w("pandroid", glGetString(GL_VERSION));
|
Log.w("pandroid", glGetString(GL_VERSION));
|
||||||
screenWidth = Resources.getSystem().getDisplayMetrics().widthPixels;
|
|
||||||
screenHeight = Resources.getSystem().getDisplayMetrics().heightPixels;
|
|
||||||
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
@ -71,40 +75,48 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer {
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, screenFbo);
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, screenFbo);
|
||||||
|
|
||||||
if (screenWidth > screenHeight) {
|
Rect topScreen = displayLayout.getTopDisplayBounds();
|
||||||
int topDisplayWidth = (int)((screenHeight / (float)Constants.N3DS_HEIGHT) * Constants.N3DS_WIDTH);
|
Rect bottomScreen = displayLayout.getBottomDisplayBounds();
|
||||||
int topDisplayHeight = screenHeight;
|
|
||||||
|
|
||||||
if (topDisplayWidth > screenWidth * 0.7){
|
glBlitFramebuffer(
|
||||||
topDisplayWidth = (int)(screenWidth * 0.7);
|
0, 480,
|
||||||
topDisplayHeight = (int)((topDisplayWidth / (float)Constants.N3DS_WIDTH) * Constants.N3DS_HEIGHT);
|
400, 240,
|
||||||
}
|
topScreen.left, screenHeight - topScreen.top,
|
||||||
|
topScreen.right, screenHeight - topScreen.bottom,
|
||||||
|
GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||||
|
|
||||||
int bottomDisplayHeight = (int)(((screenWidth - topDisplayWidth) / 320) * Constants.N3DS_HEIGHT);
|
glBlitFramebuffer(
|
||||||
int topDisplayY = screenHeight - topDisplayHeight;
|
40, 240,
|
||||||
int bottomDisplayY = screenHeight - bottomDisplayHeight;
|
360, 0,
|
||||||
|
bottomScreen.left, screenHeight - bottomScreen.top,
|
||||||
glBlitFramebuffer(0, Constants.N3DS_HEIGHT,
|
bottomScreen.right, screenHeight - bottomScreen.bottom,
|
||||||
Constants.N3DS_WIDTH, Constants.N3DS_HEIGHT * 2,
|
GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||||
0, topDisplayY,
|
|
||||||
topDisplayWidth,topDisplayY+topDisplayHeight,
|
|
||||||
GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
|
||||||
|
|
||||||
glBlitFramebuffer(
|
|
||||||
40, 0,
|
|
||||||
360, Constants.N3DS_HEIGHT,
|
|
||||||
topDisplayWidth, bottomDisplayY,
|
|
||||||
screenWidth,bottomDisplayY+bottomDisplayHeight,
|
|
||||||
GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
|
||||||
} else {
|
|
||||||
int h = (int)((screenWidth / (float)Constants.N3DS_WIDTH) * Constants.N3DS_HEIGHT * 2);
|
|
||||||
glBlitFramebuffer(0, 0, Constants.N3DS_WIDTH, Constants.N3DS_HEIGHT * 2, 0, screenHeight - h, screenWidth, screenHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSurfaceChanged(GL10 unused, int width, int height) {
|
public void onSurfaceChanged(GL10 unused, int width, int height) {
|
||||||
screenWidth = width;
|
screenWidth = width;
|
||||||
screenHeight = height;
|
screenHeight = height;
|
||||||
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
|
displayLayout.update(screenWidth, screenHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLayout(ConsoleLayout layout) {
|
||||||
|
displayLayout = layout;
|
||||||
|
displayLayout.setTopDisplaySourceSize(400, 240);
|
||||||
|
displayLayout.setBottomDisplaySourceSize(320, 240);
|
||||||
|
displayLayout.update(screenWidth, screenHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConsoleLayout getLayout() {
|
||||||
|
return displayLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBackendName() {
|
||||||
|
return "OpenGL";
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +1,22 @@
|
||||||
package com.panda3ds.pandroid.view;
|
package com.panda3ds.pandroid.view;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.Canvas;
|
||||||
import android.opengl.GLSurfaceView;
|
import android.opengl.GLSurfaceView;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public class PandaGlSurfaceView extends GLSurfaceView {
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.panda3ds.pandroid.math.Vector2;
|
||||||
|
import com.panda3ds.pandroid.utils.Constants;
|
||||||
|
import com.panda3ds.pandroid.view.controller.TouchEvent;
|
||||||
|
import com.panda3ds.pandroid.view.controller.nodes.TouchScreenNodeImpl;
|
||||||
|
import com.panda3ds.pandroid.view.renderer.ConsoleRenderer;
|
||||||
|
|
||||||
|
public class PandaGlSurfaceView extends GLSurfaceView implements TouchScreenNodeImpl {
|
||||||
final PandaGlRenderer renderer;
|
final PandaGlRenderer renderer;
|
||||||
|
private int size_width;
|
||||||
|
private int size_height;
|
||||||
|
|
||||||
public PandaGlSurfaceView(Context context, String romPath) {
|
public PandaGlSurfaceView(Context context, String romPath) {
|
||||||
super(context);
|
super(context);
|
||||||
|
@ -13,4 +25,26 @@ public class PandaGlSurfaceView extends GLSurfaceView {
|
||||||
renderer = new PandaGlRenderer(romPath);
|
renderer = new PandaGlRenderer(romPath);
|
||||||
setRenderer(renderer);
|
setRenderer(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConsoleRenderer getRenderer() {
|
||||||
|
return renderer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
size_width = getMeasuredWidth();
|
||||||
|
size_height = getMeasuredHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Vector2 getSize() {
|
||||||
|
return new Vector2(size_width, size_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTouch(TouchEvent event) {
|
||||||
|
onTouchScreenPress(renderer, event);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -58,5 +58,7 @@ public class PandaLayoutController extends ControllerLayout {
|
||||||
.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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
refreshChildren();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,18 @@ package com.panda3ds.pandroid.view.controller;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
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 java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class ControllerLayout extends RelativeLayout {
|
public class ControllerLayout extends RelativeLayout {
|
||||||
|
@ -34,8 +38,14 @@ public class ControllerLayout extends RelativeLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshChildren(){
|
public void refreshChildren(){
|
||||||
|
ArrayList<ControllerNode> nodes = new ArrayList<>();
|
||||||
|
populateNodesArray(this, nodes);
|
||||||
|
|
||||||
|
//Need Reverse: First view is in back and last view is in front for respect android View hierarchy
|
||||||
|
Collections.reverse(nodes);
|
||||||
|
|
||||||
controllerNodes.clear();
|
controllerNodes.clear();
|
||||||
populateNodesArray(this, controllerNodes);
|
controllerNodes.addAll(nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateNodesArray(ViewGroup group, ArrayList<ControllerNode> list){
|
private void populateNodesArray(ViewGroup group, ArrayList<ControllerNode> list){
|
||||||
|
@ -89,7 +99,7 @@ public class ControllerLayout extends RelativeLayout {
|
||||||
|
|
||||||
float cx = (pos.x - globalPosition[0]);
|
float cx = (pos.x - globalPosition[0]);
|
||||||
float cy = (pos.y - globalPosition[1]);
|
float cy = (pos.y - globalPosition[1]);
|
||||||
if( x > cx && x < cx+size.x && y > cy && y < cy+size.y){
|
if(item.isVisible() && x > cx && x < cx+size.x && y > cy && y < cy+size.y){
|
||||||
node = item;
|
node = item;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,10 @@ public interface ControllerNode {
|
||||||
return new Vector2(position[0], position[1]);
|
return new Vector2(position[0], position[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default boolean isVisible(){
|
||||||
|
return ((View)this).isShown();
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull Vector2 getSize();
|
@NonNull Vector2 getSize();
|
||||||
|
|
||||||
void onTouch(TouchEvent event);
|
void onTouch(TouchEvent event);
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
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;
|
||||||
|
import com.panda3ds.pandroid.view.controller.ControllerNode;
|
||||||
|
import com.panda3ds.pandroid.view.controller.TouchEvent;
|
||||||
|
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();;
|
||||||
|
|
||||||
|
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 y = (int) (event.getY() - bounds.top);
|
||||||
|
|
||||||
|
x = Math.round((x/(float)bounds.width())*320);
|
||||||
|
y = Math.round((y/(float)bounds.height())*240);
|
||||||
|
|
||||||
|
AlberDriver.TouchScreenDown(x,y);
|
||||||
|
|
||||||
|
me.setTag(R.id.TagEventHasDown, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasDownEvent && event.getAction() == TouchEvent.ACTION_UP){
|
||||||
|
AlberDriver.TouchScreenUp();
|
||||||
|
me.setTag(R.id.TagEventHasDown, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.panda3ds.pandroid.view.renderer;
|
||||||
|
|
||||||
|
import com.panda3ds.pandroid.view.renderer.layout.ConsoleLayout;
|
||||||
|
|
||||||
|
public interface ConsoleRenderer {
|
||||||
|
void setLayout(ConsoleLayout layout);
|
||||||
|
ConsoleLayout getLayout();
|
||||||
|
String getBackendName();
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.panda3ds.pandroid.view.renderer.layout;
|
||||||
|
|
||||||
|
import android.graphics.Rect;
|
||||||
|
|
||||||
|
import com.panda3ds.pandroid.math.Vector2;
|
||||||
|
|
||||||
|
public interface ConsoleLayout {
|
||||||
|
void update(int screenWidth, int screenHeight);
|
||||||
|
|
||||||
|
void setBottomDisplaySourceSize(int width, int height);
|
||||||
|
void setTopDisplaySourceSize(int width, int height);
|
||||||
|
|
||||||
|
Rect getBottomDisplayBounds();
|
||||||
|
Rect getTopDisplayBounds();
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
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 {
|
||||||
|
private final Rect topDisplay = new Rect();
|
||||||
|
private final Rect bottomDisplay = new Rect();
|
||||||
|
|
||||||
|
private final Vector2 screenSize = new Vector2(1.0F, 1.0F);
|
||||||
|
private final Vector2 topSourceSize = new Vector2(1.0F, 1.0F);
|
||||||
|
private final Vector2 bottomSourceSize = new Vector2(1.0F, 1.0F);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(int screenWidth, int screenHeight) {
|
||||||
|
screenSize.set(screenWidth, screenHeight);
|
||||||
|
updateBounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBottomDisplaySourceSize(int width, int height) {
|
||||||
|
bottomSourceSize.set(width,height);
|
||||||
|
updateBounds();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void setTopDisplaySourceSize(int width, int height) {
|
||||||
|
topSourceSize.set(width,height);
|
||||||
|
updateBounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBounds(){
|
||||||
|
int screenWidth = (int) screenSize.x;
|
||||||
|
int screenHeight = (int) screenSize.y;
|
||||||
|
|
||||||
|
if (screenWidth > screenHeight){
|
||||||
|
|
||||||
|
int topDisplayWidth = (int) ((screenHeight / topSourceSize.y) * topSourceSize.x);
|
||||||
|
int topDisplayHeight = screenHeight;
|
||||||
|
|
||||||
|
if (topDisplayWidth > (screenWidth*0.7)){
|
||||||
|
topDisplayWidth = (int) (screenWidth * 0.7);
|
||||||
|
topDisplayHeight = (int) ((topDisplayWidth/topSourceSize.x)* topSourceSize.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int bottomDisplayHeight = (int) (((screenWidth-topDisplayWidth)/ bottomSourceSize.x)* bottomSourceSize.y);
|
||||||
|
|
||||||
|
|
||||||
|
topDisplay.set(0, 0, topDisplayWidth, topDisplayHeight);
|
||||||
|
bottomDisplay.set(topDisplayWidth, 0, topDisplayWidth+(screenWidth-topDisplayWidth), bottomDisplayHeight);
|
||||||
|
} else {
|
||||||
|
int topScreenHeight = (int) ((screenWidth/ topSourceSize.x) * topSourceSize.y);
|
||||||
|
topDisplay.set(0,0,screenWidth,topScreenHeight);
|
||||||
|
|
||||||
|
int bottomDisplayHeight = (int)((screenWidth/ bottomSourceSize.x) * bottomSourceSize.y);
|
||||||
|
int bottomDisplayWidth = screenWidth;
|
||||||
|
int bottomDisplayX = 0;
|
||||||
|
|
||||||
|
if (topScreenHeight + bottomDisplayHeight > screenHeight){
|
||||||
|
bottomDisplayHeight = (screenHeight-topScreenHeight);
|
||||||
|
bottomDisplayWidth = (int) ((bottomDisplayHeight/ bottomSourceSize.y)*bottomSourceSize.x);
|
||||||
|
bottomDisplayX = (screenWidth-bottomDisplayX)/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
topDisplay.set(0,0, screenWidth,topScreenHeight);
|
||||||
|
bottomDisplay.set(bottomDisplayX, topScreenHeight, bottomDisplayX+bottomDisplayWidth,topScreenHeight+bottomDisplayHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Rect getBottomDisplayBounds() {
|
||||||
|
return bottomDisplay;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Rect getTopDisplayBounds() {
|
||||||
|
return topDisplay;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,105 +4,110 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="#000">
|
android:background="#000">
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:id="@+id/panda_gl_frame"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"/>
|
|
||||||
|
|
||||||
<com.panda3ds.pandroid.view.PandaLayoutController
|
<com.panda3ds.pandroid.view.PandaLayoutController
|
||||||
android:id="@+id/controller_layout"
|
android:id="@+id/controller_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
<LinearLayout
|
android:id="@+id/panda_gl_frame"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"/>
|
||||||
android:gravity="bottom"
|
|
||||||
android:padding="20dp">
|
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
android:id="@+id/overlay_controller"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="bottom"
|
||||||
|
android:padding="20dp">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
<com.panda3ds.pandroid.view.controller.nodes.Button
|
|
||||||
android:id="@+id/button_l"
|
|
||||||
android:layout_width="100dp"
|
|
||||||
android:layout_height="25dp"
|
|
||||||
android:layout_gravity="left"
|
|
||||||
style="@style/ControllerSimpleButton"
|
|
||||||
android:background="@drawable/simple_card_button_left"
|
|
||||||
android:text="L"/>
|
|
||||||
|
|
||||||
<com.panda3ds.pandroid.view.controller.nodes.Button
|
|
||||||
android:id="@+id/button_r"
|
|
||||||
android:layout_width="100dp"
|
|
||||||
android:layout_height="25dp"
|
|
||||||
android:layout_gravity="right"
|
|
||||||
style="@style/ControllerSimpleButton"
|
|
||||||
android:background="@drawable/simple_card_button_right"
|
|
||||||
android:text="R"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingTop="60dp">
|
|
||||||
|
|
||||||
<include layout="@layout/controller_dpad"/>
|
<com.panda3ds.pandroid.view.controller.nodes.Button
|
||||||
|
android:id="@+id/button_l"
|
||||||
<com.panda3ds.pandroid.view.controller.nodes.Joystick
|
|
||||||
android:id="@+id/left_analog"
|
|
||||||
android:layout_width="100dp"
|
android:layout_width="100dp"
|
||||||
android:layout_height="100dp"
|
android:layout_height="25dp"
|
||||||
android:layout_marginTop="20dp"
|
android:layout_gravity="left"
|
||||||
android:background="@drawable/simple_analog_background"
|
style="@style/ControllerSimpleButton"
|
||||||
android:foreground="@drawable/simple_circle_button"
|
android:background="@drawable/simple_card_button_left"
|
||||||
android:padding="40dp"/>
|
android:text="L"/>
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="end|bottom"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_gravity="center">
|
|
||||||
|
|
||||||
<include layout="@layout/controller_gamepad"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="bottom|center">
|
|
||||||
|
|
||||||
<com.panda3ds.pandroid.view.controller.nodes.Button
|
<com.panda3ds.pandroid.view.controller.nodes.Button
|
||||||
android:id="@+id/button_start"
|
android:id="@+id/button_r"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="25dp"
|
||||||
|
android:layout_gravity="right"
|
||||||
|
style="@style/ControllerSimpleButton"
|
||||||
|
android:background="@drawable/simple_card_button_right"
|
||||||
|
android:text="R"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingTop="60dp">
|
||||||
|
|
||||||
|
<include layout="@layout/controller_dpad"/>
|
||||||
|
|
||||||
|
<com.panda3ds.pandroid.view.controller.nodes.Joystick
|
||||||
|
android:id="@+id/left_analog"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="100dp"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:background="@drawable/simple_analog_background"
|
||||||
|
android:foreground="@drawable/simple_circle_button"
|
||||||
|
android:padding="40dp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="end|bottom"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_gravity="center">
|
||||||
|
|
||||||
|
<include layout="@layout/controller_gamepad"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/simple_card_button"
|
android:layout_gravity="bottom|center">
|
||||||
style="@style/ControllerSimpleButton"
|
|
||||||
android:paddingHorizontal="10dp"
|
|
||||||
android:text="START"/>
|
|
||||||
|
|
||||||
<com.panda3ds.pandroid.view.controller.nodes.Button
|
<com.panda3ds.pandroid.view.controller.nodes.Button
|
||||||
android:id="@+id/button_select"
|
android:id="@+id/button_start"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/simple_card_button"
|
android:background="@drawable/simple_card_button"
|
||||||
style="@style/ControllerSimpleButton"
|
style="@style/ControllerSimpleButton"
|
||||||
android:paddingHorizontal="10dp"
|
android:paddingHorizontal="10dp"
|
||||||
android:layout_marginLeft="10dp"
|
android:text="START"/>
|
||||||
android:text="SELECT"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
<com.panda3ds.pandroid.view.controller.nodes.Button
|
||||||
|
android:id="@+id/button_select"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/simple_card_button"
|
||||||
|
style="@style/ControllerSimpleButton"
|
||||||
|
android:paddingHorizontal="10dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:text="SELECT"/>
|
||||||
|
|
||||||
</FrameLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
</com.panda3ds.pandroid.view.PandaLayoutController>
|
</com.panda3ds.pandroid.view.PandaLayoutController>
|
||||||
|
|
||||||
|
|
4
src/pandroid/app/src/main/res/values/values.xml
Normal file
4
src/pandroid/app/src/main/res/values/values.xml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<item name="TagEventHasDown" type="id"/>
|
||||||
|
</resources>
|
Loading…
Add table
Reference in a new issue