mirror of
https://github.com/FWGS/xash3d-fwgs
synced 2024-11-25 11:19:59 +01:00
Implement screen resolution changing
This commit is contained in:
parent
b0099a2c5d
commit
00ff0ced07
@ -263,6 +263,55 @@
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="@string/immersive_mode" />
|
||||
<CheckBox
|
||||
android:id="@+id/resolution"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="@string/resolution" />
|
||||
<RadioGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:background="#444444"
|
||||
android:orientation="vertical"
|
||||
android:weightSum="1">
|
||||
<RadioButton android:id="@+id/resolution_scale_r" android:text="@string/resolution_scale" android:layout_width="wrap_content" android:layout_height="wrap_content" />
|
||||
<EditText
|
||||
android:id="@+id/resolution_scale"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="3dp" />
|
||||
|
||||
<RadioButton android:id="@+id/resolution_custom_r" android:text="@string/resolution_custom" android:layout_width="wrap_content" android:layout_height="wrap_content" />
|
||||
<EditText
|
||||
android:id="@+id/resolution_width"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="3dp" />
|
||||
<EditText
|
||||
android:id="@+id/resolution_height"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="3dp" />
|
||||
|
||||
|
||||
</RadioGroup>
|
||||
<TextView
|
||||
android:id="@+id/textView7"
|
||||
android:layout_marginBottom="10dp"
|
||||
|
@ -70,4 +70,8 @@
|
||||
<string name="lollipop_write_fail_msg">Due to writing politics of newer Android versions, you can\'t use this storage. </string>
|
||||
<string name="kitkat_write_fail_msg">Due to writing politics of Android 4.4, you can\'t use this storage. </string>
|
||||
<string name="readonly_fs_fail_msg">Seems you have read-only filesystem. </string>
|
||||
<string name="resolution">Fixed screen resolution (experimental)</string>
|
||||
<string name="resolution_scale">Scale screen keeping aspect ratio</string>
|
||||
<string name="resolution_custom">Specify custom screen width and height</string>
|
||||
|
||||
</resources>
|
||||
|
@ -16,6 +16,7 @@ import in.celest.xash3d.hl.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import org.json.*;
|
||||
import android.preference.*;
|
||||
|
||||
public class LauncherActivity extends Activity {
|
||||
// public final static String ARGV = "in.celest.xash3d.MESSAGE";
|
||||
@ -31,7 +32,9 @@ public class LauncherActivity extends Activity {
|
||||
static SharedPreferences mPref;
|
||||
static Spinner pixelSpinner;
|
||||
static TextView tvResPath;
|
||||
|
||||
static EditText resScale, resWidth, resHeight;
|
||||
static RadioButton radioScale, radioCustom;
|
||||
static CheckBox resolution;
|
||||
String getDefaultPath()
|
||||
{
|
||||
File dir = Environment.getExternalStorageDirectory();
|
||||
@ -126,6 +129,12 @@ public class LauncherActivity extends Activity {
|
||||
resizeWorkaround = (ToggleButton) findViewById( R.id.enableResizeWorkaround );
|
||||
tvResPath = (TextView) findViewById( R.id.textView_path );
|
||||
immersiveMode = (CheckBox) findViewById( R.id.immersive_mode );
|
||||
resolution = (CheckBox) findViewById(R.id.resolution);
|
||||
resWidth = (EditText) findViewById(R.id.resolution_width);
|
||||
resHeight = (EditText) findViewById(R.id.resolution_height);
|
||||
resScale = (EditText) findViewById(R.id.resolution_scale);
|
||||
radioCustom = (RadioButton) findViewById(R.id.resolution_custom_r);
|
||||
radioScale = (RadioButton) findViewById(R.id.resolution_scale_r);
|
||||
|
||||
final String[] list = {
|
||||
"32 bit (RGBA8888)",
|
||||
@ -170,7 +179,13 @@ public class LauncherActivity extends Activity {
|
||||
cmdArgs.setText(mPref.getString("argv","-dev 3 -log"));
|
||||
pixelSpinner.setSelection(mPref.getInt("pixelformat", 0));
|
||||
resizeWorkaround.setChecked(mPref.getBoolean("enableResizeWorkaround", true));
|
||||
|
||||
resolution.setChecked(mPref.getBoolean("resolution_fixed", false ));
|
||||
resWidth.setText(String.valueOf(mPref.getInt("resolution_width",854)));
|
||||
resHeight.setText(String.valueOf(mPref.getInt("resolution_height",480)));
|
||||
resScale.setText(String.valueOf(mPref.getFloat("resolution_scale",2.0f)));
|
||||
if( mPref.getBoolean("resolution_custom", false) )
|
||||
radioCustom.setChecked(true);
|
||||
else radioScale.setChecked(true);
|
||||
if( sdk >= 19 )
|
||||
{
|
||||
immersiveMode.setChecked(mPref.getBoolean("immersive_mode", true));
|
||||
@ -216,6 +231,14 @@ public class LauncherActivity extends Activity {
|
||||
editor.putInt("pixelformat", pixelSpinner.getSelectedItemPosition());
|
||||
editor.putBoolean("enableResizeWorkaround",resizeWorkaround.isChecked());
|
||||
editor.putBoolean("check_updates", checkUpdates.isChecked());
|
||||
editor.putBoolean("resolution_fixed", resolution.isChecked());
|
||||
editor.putBoolean("resolution_custom", radioCustom.isChecked());
|
||||
editor.putFloat("resolution_scale", Float.valueOf(resScale.getText().toString()));
|
||||
editor.putInt("resolution_width", Integer.valueOf(resWidth.getText().toString()));
|
||||
editor.putInt("resolution_height", Integer.valueOf(resHeight.getText().toString()));
|
||||
|
||||
|
||||
|
||||
if( sdk >= 19 )
|
||||
editor.putBoolean("immersive_mode", immersiveMode.isChecked());
|
||||
else
|
||||
|
@ -58,6 +58,8 @@ public class XashActivity extends Activity {
|
||||
public static Vibrator mVibrator;
|
||||
public static boolean fMouseShown = true;
|
||||
public static boolean fGDBSafe = false;
|
||||
public static float mScale = 0, mTouchScaleX = 1, mTouchScaleY = 1;
|
||||
public static int mForceHeight = 0, mForceWidth = 0;
|
||||
|
||||
private static boolean mHasVibrator;
|
||||
private int mReturingWithResultCode = 0;
|
||||
@ -426,6 +428,21 @@ public class XashActivity extends Activity {
|
||||
|
||||
mVibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
|
||||
|
||||
if( mPref.getBoolean("resolution_fixed", false) )
|
||||
{
|
||||
if( mPref.getBoolean("resolution_custom", false) )
|
||||
{
|
||||
mForceWidth = mPref.getInt( "resolution_width", 854 );
|
||||
mForceHeight = mPref.getInt( "resolution_height", 480 );
|
||||
if( mForceWidth < 10 || mForceHeight < 10 )
|
||||
mForceWidth = mForceHeight = 0;
|
||||
}
|
||||
else
|
||||
mScale = mPref.getFloat( "resolution_scale", 1 );
|
||||
if( mScale < 0.5 )
|
||||
mScale = 0;
|
||||
}
|
||||
|
||||
mHasVibrator = ( mVibrator != null );
|
||||
if( sdk >= 11 )
|
||||
mHasVibrator = ( mVibrator != null ) && ( handler.hasVibrator() );
|
||||
@ -790,6 +807,7 @@ public class XashActivity extends Activity {
|
||||
{
|
||||
// Transfer the task to the main thread as a Runnable
|
||||
mSingleton.runOnUiThread(new ShowTextInputTask(show));
|
||||
//if( show == 1 )mSurface.getHolder().setSizeFromLayout();
|
||||
}
|
||||
|
||||
public static void setIcon(String path)
|
||||
@ -883,6 +901,7 @@ class EngineSurface extends SurfaceView implements SurfaceHolder.Callback, View.
|
||||
private EGLDisplay mEGLDisplay;
|
||||
private EGL10 mEGL;
|
||||
private EGLConfig mEGLConfig;
|
||||
private boolean resizing = false;
|
||||
public static final String TAG = "XASH3D-EngineSurface";
|
||||
|
||||
// Sensors
|
||||
@ -911,6 +930,8 @@ class EngineSurface extends SurfaceView implements SurfaceHolder.Callback, View.
|
||||
return;
|
||||
XashActivity.nativeSetPause(0);
|
||||
XashActivity.mEnginePaused = false;
|
||||
//holder.setFixedSize(640,480);
|
||||
//SurfaceHolder.setFixedSize(640,480);
|
||||
}
|
||||
|
||||
// Called when we lose the surface
|
||||
@ -926,14 +947,36 @@ class EngineSurface extends SurfaceView implements SurfaceHolder.Callback, View.
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
|
||||
{
|
||||
Log.v(TAG, "surfaceChanged()");
|
||||
if( ( XashActivity.mForceHeight!= 0 && XashActivity.mForceWidth!= 0 || XashActivity.mScale!= 0 ) && !resizing )
|
||||
{
|
||||
int newWidth, newHeight;
|
||||
resizing = true;
|
||||
if( XashActivity.mForceHeight != 0 && XashActivity.mForceWidth != 0 )
|
||||
{
|
||||
newWidth = XashActivity.mForceWidth;
|
||||
newHeight = XashActivity.mForceHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
newWidth = (int)(getWidth() / XashActivity.mScale);
|
||||
newHeight = (int)(getHeight() / XashActivity.mScale);
|
||||
}
|
||||
holder.setFixedSize( newWidth, newHeight );
|
||||
XashActivity.mTouchScaleX = (float)newWidth / getWidth();
|
||||
XashActivity.mTouchScaleY = (float)newHeight / getHeight();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
XashActivity.onNativeResize(width, height);
|
||||
//holder.setFixedSize(width/2,height/2);
|
||||
// Now start up the C app thread
|
||||
if (mEngThread == null) {
|
||||
|
||||
mEngThread = new Thread(new XashMain(), "EngineThread");
|
||||
mEngThread.start();
|
||||
}
|
||||
resizing = false;
|
||||
}
|
||||
|
||||
public void engineThreadJoin()
|
||||
@ -1284,8 +1327,8 @@ class EngineTouchListener_v5 implements View.OnTouchListener{
|
||||
}
|
||||
for (i = 0; i < pointerCount; i++) {
|
||||
pointerFingerId = event.getPointerId(i);
|
||||
x = event.getX(i);
|
||||
y = event.getY(i);
|
||||
x = event.getX(i)*XashActivity.mTouchScaleX;
|
||||
y = event.getY(i)*XashActivity.mTouchScaleY;
|
||||
XashActivity.nativeTouch(pointerFingerId, 2, x, y);
|
||||
}
|
||||
break;
|
||||
@ -1324,8 +1367,8 @@ class EngineTouchListener_v5 implements View.OnTouchListener{
|
||||
|
||||
pointerFingerId = event.getPointerId(i);
|
||||
|
||||
x = event.getX(i);
|
||||
y = event.getY(i);
|
||||
x = event.getX(i)*XashActivity.mTouchScaleX;
|
||||
y = event.getY(i)*XashActivity.mTouchScaleY;
|
||||
if( action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP )
|
||||
XashActivity.nativeTouch(pointerFingerId,1, x, y);
|
||||
if( action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN )
|
||||
@ -1335,8 +1378,8 @@ class EngineTouchListener_v5 implements View.OnTouchListener{
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
for (i = 0; i < pointerCount; i++) {
|
||||
pointerFingerId = event.getPointerId(i);
|
||||
x = event.getX(i);
|
||||
y = event.getY(i);
|
||||
x = event.getX(i)*XashActivity.mTouchScaleX;
|
||||
y = event.getY(i)*XashActivity.mTouchScaleY;
|
||||
XashActivity.nativeTouch(pointerFingerId, 1, x, y);
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user