Skip to content

Commit

Permalink
Remove extra variables, and fix aspect ratio from GLSurfaceRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBRDeveloper committed Nov 28, 2023
1 parent 88170a1 commit 1cc4b64
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
public class PandaGlRenderer implements GLSurfaceView.Renderer {

private final String romPath;
int screenWidth, screenHeight;
int screenTexture;
private int screenWidth, screenHeight;
private int screenTexture;
public int screenFbo;

PandaGlRenderer(String romPath) {
super();
this.romPath = romPath;
}


@Override
protected void finalize() throws Throwable {
if (screenTexture != 0) {
Expand Down Expand Up @@ -68,10 +67,38 @@ public void onSurfaceCreated(GL10 unused, EGLConfig config) {
public void onDrawFrame(GL10 unused) {
if (AlberDriver.HasRomLoaded()) {
AlberDriver.RunFrame(screenFbo);
int h = (int) ((screenWidth/400.0)*480);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;

import com.panda3ds.pandroid.AlberDriver;
import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.utils.Constants;
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.Joystick;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,20 @@ private void processTouch(boolean up, float x, float y, int index){

if ((!activeTouchEvents.containsKey(index))){
if (up)return;
ControllerNode touch = null;
ControllerNode node = null;
for (ControllerNode item: controllerNodes){
Vector2 pos = item.getPosition();
Vector2 size= item.getSize();

float cx = (pos.x - globalPosition[0]);
float cy = (pos.y - globalPosition[1]);
if( x > cx && x < cx+size.x && y > cy && y < cy+size.y){
touch = item;
node = item;
break;
}
}
if (touch != null){
activeTouchEvents.put(index, touch);
if (node != null){
activeTouchEvents.put(index, node);
action = TouchEvent.ACTION_DOWN;
} else {
return;
Expand All @@ -104,15 +104,15 @@ private void processTouch(boolean up, float x, float y, int index){

if (up) action = TouchEvent.ACTION_UP;

ControllerNode touch = activeTouchEvents.get(index);
Vector2 pos = touch.getPosition();
ControllerNode node = activeTouchEvents.get(index);
Vector2 pos = node.getPosition();
pos.x -= globalPosition[0];
pos.y -= globalPosition[1];

x -= pos.x;
y -= pos.y;

touch.onTouch(new TouchEvent(x,y,action));
node.onTouch(new TouchEvent(x,y,action));

if(up){
activeTouchEvents.remove(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
public class Joystick extends BasicControllerNode implements ControllerNode {
private float stick_x = 0;
private float stick_y = 0;
private float density = 0;

private int size_width = 0;
private int size_height= 0;
Expand All @@ -43,7 +42,6 @@ public Joystick(Context context, AttributeSet attrs, int defStyleAttr) {

private final Paint paint = new Paint();


@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Expand All @@ -54,8 +52,6 @@ public void onDrawForeground(Canvas canvas) {
size_width = getWidth();
size_height = getHeight();

density = getResources().getDisplayMetrics().density;

int analogIconSize = size_width-getPaddingLeft();

float middleIconSize = analogIconSize / 2.0F;
Expand Down Expand Up @@ -110,17 +106,17 @@ public Vector2 getSize() {
@Override
public void onTouch(TouchEvent event) {

float v = density * 75;
float middle = size_width/2.0F;

float x = event.getX();
float y = event.getY();

x = Math.max(0, Math.min(v*2, x));
y = Math.max(0, Math.min(v*2, y));
x = Math.max(0, Math.min(middle*2, x));
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){
stick_x = 0;
Expand All @@ -130,6 +126,7 @@ public void onTouch(TouchEvent event) {
if (joystickListener != null){
joystickListener.onJoystickAxisChange(this, stick_x, stick_y);
}

invalidate();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<?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>
<shape>
<solid android:color="#0000"/>
<stroke android:color="#6FFF" android:width="1dp"/>
<corners android:radius="999dp"/>
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"/>
</shape>
</item>
</selector>
<item>
<shape>
<solid android:color="#0000"/>
<stroke android:color="#6FFF" android:width="1dp"/>
<corners android:radius="999dp"/>
</shape>
</item>
</layer-list>

0 comments on commit 1cc4b64

Please sign in to comment.