mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-08-09 01:28:45 +00:00
Remove extra variables, and fix aspect ratio from GLSurfaceRenderer
This commit is contained in:
parent
88170a14fc
commit
1cc4b648a2
5 changed files with 54 additions and 28 deletions
|
@ -16,8 +16,8 @@ import java.util.ArrayList;
|
||||||
public class PandaGlRenderer implements GLSurfaceView.Renderer {
|
public class PandaGlRenderer implements GLSurfaceView.Renderer {
|
||||||
|
|
||||||
private final String romPath;
|
private final String romPath;
|
||||||
int screenWidth, screenHeight;
|
private int screenWidth, screenHeight;
|
||||||
int screenTexture;
|
private int screenTexture;
|
||||||
public int screenFbo;
|
public int screenFbo;
|
||||||
|
|
||||||
PandaGlRenderer(String romPath) {
|
PandaGlRenderer(String romPath) {
|
||||||
|
@ -25,7 +25,6 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer {
|
||||||
this.romPath = romPath;
|
this.romPath = romPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() throws Throwable {
|
protected void finalize() throws Throwable {
|
||||||
if (screenTexture != 0) {
|
if (screenTexture != 0) {
|
||||||
|
@ -68,10 +67,38 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer {
|
||||||
public void onDrawFrame(GL10 unused) {
|
public void onDrawFrame(GL10 unused) {
|
||||||
if (AlberDriver.HasRomLoaded()) {
|
if (AlberDriver.HasRomLoaded()) {
|
||||||
AlberDriver.RunFrame(screenFbo);
|
AlberDriver.RunFrame(screenFbo);
|
||||||
int h = (int) ((screenWidth/400.0)*480);
|
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, screenFbo);
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, screenFbo);
|
||||||
glBlitFramebuffer(0, 0, 400, 480, 0, screenHeight-h, screenWidth, screenHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
if (screenWidth > screenHeight) {
|
||||||
|
int topDisplayWidth = (int) ((screenHeight / 240.0) * 400);
|
||||||
|
int topDisplayHeight = screenHeight;
|
||||||
|
|
||||||
|
if (topDisplayWidth > (screenWidth*0.7)){
|
||||||
|
topDisplayWidth = (int) (screenWidth * 0.7);
|
||||||
|
topDisplayHeight = (int) ((topDisplayWidth/400.0)*240);
|
||||||
|
}
|
||||||
|
|
||||||
|
int bottomDisplayHeight = (int) (((screenWidth-topDisplayWidth)/320)*240);
|
||||||
|
|
||||||
|
int topDisplayY = screenHeight-topDisplayHeight;
|
||||||
|
int bottomDisplayY = screenHeight-bottomDisplayHeight;
|
||||||
|
|
||||||
|
glBlitFramebuffer(0, 240,
|
||||||
|
400, 480,
|
||||||
|
0, topDisplayY,
|
||||||
|
topDisplayWidth,topDisplayY+topDisplayHeight,
|
||||||
|
GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||||
|
|
||||||
|
glBlitFramebuffer(
|
||||||
|
40, 0,
|
||||||
|
360, 240,
|
||||||
|
topDisplayWidth, bottomDisplayY,
|
||||||
|
screenWidth,bottomDisplayY+bottomDisplayHeight,
|
||||||
|
GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||||
|
} else {
|
||||||
|
int h = (int) ((screenWidth / 400.0) * 480);
|
||||||
|
glBlitFramebuffer(0, 0, 400, 480, 0, screenHeight - h, screenWidth, screenHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,11 @@ package com.panda3ds.pandroid.view;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
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;
|
||||||
import com.panda3ds.pandroid.view.controller.ControllerLayout;
|
import com.panda3ds.pandroid.view.controller.ControllerLayout;
|
||||||
import com.panda3ds.pandroid.view.controller.listeners.JoystickListener;
|
|
||||||
import com.panda3ds.pandroid.view.controller.nodes.Button;
|
import com.panda3ds.pandroid.view.controller.nodes.Button;
|
||||||
import com.panda3ds.pandroid.view.controller.nodes.Joystick;
|
import com.panda3ds.pandroid.view.controller.nodes.Joystick;
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class ControllerLayout extends RelativeLayout {
|
||||||
|
|
||||||
if ((!activeTouchEvents.containsKey(index))){
|
if ((!activeTouchEvents.containsKey(index))){
|
||||||
if (up)return;
|
if (up)return;
|
||||||
ControllerNode touch = null;
|
ControllerNode node = null;
|
||||||
for (ControllerNode item: controllerNodes){
|
for (ControllerNode item: controllerNodes){
|
||||||
Vector2 pos = item.getPosition();
|
Vector2 pos = item.getPosition();
|
||||||
Vector2 size= item.getSize();
|
Vector2 size= item.getSize();
|
||||||
|
@ -90,12 +90,12 @@ 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( x > cx && x < cx+size.x && y > cy && y < cy+size.y){
|
||||||
touch = item;
|
node = item;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (touch != null){
|
if (node != null){
|
||||||
activeTouchEvents.put(index, touch);
|
activeTouchEvents.put(index, node);
|
||||||
action = TouchEvent.ACTION_DOWN;
|
action = TouchEvent.ACTION_DOWN;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
@ -104,15 +104,15 @@ public class ControllerLayout extends RelativeLayout {
|
||||||
|
|
||||||
if (up) action = TouchEvent.ACTION_UP;
|
if (up) action = TouchEvent.ACTION_UP;
|
||||||
|
|
||||||
ControllerNode touch = activeTouchEvents.get(index);
|
ControllerNode node = activeTouchEvents.get(index);
|
||||||
Vector2 pos = touch.getPosition();
|
Vector2 pos = node.getPosition();
|
||||||
pos.x -= globalPosition[0];
|
pos.x -= globalPosition[0];
|
||||||
pos.y -= globalPosition[1];
|
pos.y -= globalPosition[1];
|
||||||
|
|
||||||
x -= pos.x;
|
x -= pos.x;
|
||||||
y -= pos.y;
|
y -= pos.y;
|
||||||
|
|
||||||
touch.onTouch(new TouchEvent(x,y,action));
|
node.onTouch(new TouchEvent(x,y,action));
|
||||||
|
|
||||||
if(up){
|
if(up){
|
||||||
activeTouchEvents.remove(index);
|
activeTouchEvents.remove(index);
|
||||||
|
|
|
@ -19,7 +19,6 @@ 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;
|
||||||
private float density = 0;
|
|
||||||
|
|
||||||
private int size_width = 0;
|
private int size_width = 0;
|
||||||
private int size_height= 0;
|
private int size_height= 0;
|
||||||
|
@ -43,7 +42,6 @@ public class Joystick extends BasicControllerNode implements ControllerNode {
|
||||||
|
|
||||||
private final Paint paint = new Paint();
|
private final Paint paint = new Paint();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
|
@ -54,8 +52,6 @@ public class Joystick extends BasicControllerNode implements ControllerNode {
|
||||||
size_width = getWidth();
|
size_width = getWidth();
|
||||||
size_height = getHeight();
|
size_height = getHeight();
|
||||||
|
|
||||||
density = getResources().getDisplayMetrics().density;
|
|
||||||
|
|
||||||
int analogIconSize = size_width-getPaddingLeft();
|
int analogIconSize = size_width-getPaddingLeft();
|
||||||
|
|
||||||
float middleIconSize = analogIconSize / 2.0F;
|
float middleIconSize = analogIconSize / 2.0F;
|
||||||
|
@ -110,17 +106,17 @@ public class Joystick extends BasicControllerNode implements ControllerNode {
|
||||||
@Override
|
@Override
|
||||||
public void onTouch(TouchEvent event) {
|
public void onTouch(TouchEvent event) {
|
||||||
|
|
||||||
float v = density * 75;
|
float middle = size_width/2.0F;
|
||||||
|
|
||||||
float x = event.getX();
|
float x = event.getX();
|
||||||
float y = event.getY();
|
float y = event.getY();
|
||||||
|
|
||||||
x = Math.max(0, Math.min(v*2, x));
|
x = Math.max(0, Math.min(middle*2, x));
|
||||||
y = Math.max(0, Math.min(v*2, y));
|
y = Math.max(0, Math.min(middle*2, y));
|
||||||
|
|
||||||
stick_x = ((x-v)/v);
|
stick_x = ((x-middle)/middle);
|
||||||
|
|
||||||
stick_y = ((y-v)/v);
|
stick_y = ((y-middle)/middle);
|
||||||
|
|
||||||
if (event.getAction() == TouchEvent.ACTION_UP){
|
if (event.getAction() == TouchEvent.ACTION_UP){
|
||||||
stick_x = 0;
|
stick_x = 0;
|
||||||
|
@ -130,6 +126,7 @@ public class Joystick extends BasicControllerNode implements ControllerNode {
|
||||||
if (joystickListener != null){
|
if (joystickListener != null){
|
||||||
joystickListener.onJoystickAxisChange(this, stick_x, stick_y);
|
joystickListener.onJoystickAxisChange(this, stick_x, stick_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item>
|
<item>
|
||||||
<shape>
|
<shape>
|
||||||
<solid android:color="#0000"/>
|
|
||||||
<stroke android:color="#6FFF" android:width="1dp"/>
|
|
||||||
<corners android:radius="999dp"/>
|
|
||||||
<padding
|
<padding
|
||||||
android:left="10dp"
|
android:left="10dp"
|
||||||
android:top="10dp"
|
android:top="10dp"
|
||||||
|
@ -12,4 +9,11 @@
|
||||||
android:bottom="10dp"/>
|
android:bottom="10dp"/>
|
||||||
</shape>
|
</shape>
|
||||||
</item>
|
</item>
|
||||||
</selector>
|
<item>
|
||||||
|
<shape>
|
||||||
|
<solid android:color="#0000"/>
|
||||||
|
<stroke android:color="#6FFF" android:width="1dp"/>
|
||||||
|
<corners android:radius="999dp"/>
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</layer-list>
|
Loading…
Add table
Add a link
Reference in a new issue