SDL: option to draw in the display cutout area that actually works

This commit is contained in:
Sergii Pylypenko
2021-05-22 02:05:10 +03:00
parent ed8df2e026
commit 206ee15e1f
8 changed files with 150 additions and 138 deletions

View File

@@ -324,6 +324,9 @@ echo >> AndroidAppSettings.cfg
echo "# Immersive mode - Android will hide on-screen Home/Back keys. Looks bad if you invoke Android keyboard. (y) / (n)" >> AndroidAppSettings.cfg
echo ImmersiveMode=$ImmersiveMode >> AndroidAppSettings.cfg
echo >> AndroidAppSettings.cfg
echo "# Draw in the display cutout area. (y) / (n)" >> AndroidAppSettings.cfg
echo DrawInDisplayCutout=$DrawInDisplayCutout >> AndroidAppSettings.cfg
echo >> AndroidAppSettings.cfg
echo "# Hide Android system mouse cursor image when USB mouse is attached (y) or (n) - the app must draw it's own mouse cursor" >> AndroidAppSettings.cfg
echo HideSystemMousePointer=$HideSystemMousePointer >> AndroidAppSettings.cfg
echo >> AndroidAppSettings.cfg
@@ -894,6 +897,12 @@ else
ImmersiveMode=true
fi
if [ "$DrawInDisplayCutout" = "y" ]; then
DrawInDisplayCutout=true
else
DrawInDisplayCutout=false
fi
if [ "$HideSystemMousePointer" = "n" ]; then
HideSystemMousePointer=false
else
@@ -977,6 +986,7 @@ $SEDI "s/public static boolean AppUsesMultitouch = .*;/public static boolean App
$SEDI "s/public static boolean NonBlockingSwapBuffers = .*;/public static boolean NonBlockingSwapBuffers = $NonBlockingSwapBuffers;/" project/src/Globals.java
$SEDI "s/public static boolean ResetSdlConfigForThisVersion = .*;/public static boolean ResetSdlConfigForThisVersion = $ResetSdlConfigForThisVersion;/" project/src/Globals.java
$SEDI "s/public static boolean ImmersiveMode = .*;/public static boolean ImmersiveMode = $ImmersiveMode;/" project/src/Globals.java
$SEDI "s/public static boolean DrawInDisplayCutout = .*;/public static boolean DrawInDisplayCutout = $DrawInDisplayCutout;/" project/src/Globals.java
$SEDI "s/public static boolean HideSystemMousePointer = .*;/public static boolean HideSystemMousePointer = $HideSystemMousePointer;/" project/src/Globals.java
$SEDI "s|public static String DeleteFilesOnUpgrade = .*;|public static String DeleteFilesOnUpgrade = \"$DeleteFilesOnUpgrade\";|" project/src/Globals.java
$SEDI "s/public static int AppTouchscreenKeyboardKeysAmount = .*;/public static int AppTouchscreenKeyboardKeysAmount = $AppTouchscreenKeyboardKeysAmount;/" project/src/Globals.java

View File

@@ -1219,13 +1219,6 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call
synchronized (this) {
mWidth = w;
mHeight = h;
if (Globals.DrawInDisplayCutout) {
final Rect r = new Rect();
MainActivity.instance._videoLayout.getWindowVisibleDisplayFrame(r);
//mWidth = r.width();
//mHeight = r.height();
//Log.v("SDL", "GLSurfaceView_SDL::onWindowResize(): adjusted to display cutout: " + mWidth + "x" + mHeight);
}
mSizeChanged = true;
mRenderer.onWindowResize(w, h);
notify();

View File

@@ -91,7 +91,7 @@ class Globals
public static boolean HorizontalOrientation = true;
public static boolean AutoDetectOrientation = false;
public static boolean ImmersiveMode = true;
public static boolean DrawInDisplayCutout = true;
public static boolean DrawInDisplayCutout = false;
public static boolean HideSystemMousePointer = false;
public static boolean DownloadToSdcard = true;
public static boolean PhoneHasArrowKeys = false;

View File

@@ -117,6 +117,8 @@ public class MainActivity extends Activity
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// We need to load Globals.DrawInDisplayCutout option to correctly set fullscreen mode, it can only be done from onCreate()
Settings.LoadConfig(this);
DimSystemStatusBar.dim(null, getWindow());
Log.i("SDL", "libSDL: Creating startup screen");
@@ -208,8 +210,9 @@ public class MainActivity extends Activity
public MainActivity Parent;
public void run()
{
Settings.Load(Parent);
Settings.ProcessConfig(Parent);
setScreenOrientation();
DimSystemStatusBar.dim(_videoLayout, getWindow());
loaded.release();
loadedLibraries.release();
if( _btn != null )
@@ -1503,21 +1506,22 @@ class DimSystemStatusBar
{
// Immersive mode, I already hear curses when system bar reappears mid-game from the slightest swipe at the bottom of the screen
//Log.i("SDL", "libSDL: Enabling fullscreen, Android SDK " + android.os.Build.VERSION.SDK_INT + " VERSION_CODES.P " + android.os.Build.VERSION_CODES.P);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P && Globals.ImmersiveMode)
if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P )
{
//Log.i("SDL", "libSDL: Setting display cutout mode to SHORT_EDGES");
window.getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
if (Globals.DrawInDisplayCutout)
window.getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
else
window.getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
}
//window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
//window.getDecorView().setSystemUiVisibility(android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
// android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
// android.view.View.SYSTEM_UI_FLAG_FULLSCREEN);
if (view != null)
{
//view.setFitsSystemWindows(false);
view.setSystemUiVisibility(android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
android.view.View.SYSTEM_UI_FLAG_FULLSCREEN);
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
}
else

View File

@@ -87,6 +87,7 @@ public class Settings
static boolean settingsChanged = false;
static final int SETTINGS_FILE_VERSION = 5;
static boolean convertButtonSizeFromOldSdlVersion = false;
static int settingsAppVersion = 0;
static void Save(final MainActivity p)
{
@@ -191,6 +192,7 @@ public class Settings
out.writeBoolean(Globals.ForceHardwareMouse);
convertButtonSizeFromOldSdlVersion = false;
out.writeBoolean(convertButtonSizeFromOldSdlVersion);
out.writeBoolean(Globals.DrawInDisplayCutout);
out.close();
settingsLoaded = true;
@@ -200,82 +202,8 @@ public class Settings
} catch ( IOException e ) {};
}
static void Load( final MainActivity p )
static boolean LoadConfig( final MainActivity p )
{
if(settingsLoaded) // Prevent starting twice
{
return;
}
Log.i("SDL", "libSDL: Settings.Load(): enter");
nativeInitKeymap();
for( int i = 0; i < SDL_Keys.JAVA_KEYCODE_LAST; i++ )
{
int sdlKey = nativeGetKeymapKey(i);
int idx = 0;
for(int ii = 0; ii < SDL_Keys.values.length; ii++)
if(SDL_Keys.values[ii] == sdlKey)
idx = ii;
Globals.RemapHwKeycode[i] = idx;
}
for( int i = 0; i < Globals.RemapScreenKbKeycode.length; i++ )
{
int sdlKey = nativeGetKeymapKeyScreenKb(i);
int idx = 0;
for(int ii = 0; ii < SDL_Keys.values.length; ii++)
if(SDL_Keys.values[ii] == sdlKey)
idx = ii;
Globals.RemapScreenKbKeycode[i] = idx;
}
Globals.ScreenKbControlsShown[0] = (Globals.AppNeedsArrowKeys || Globals.AppUsesJoystick);
Globals.ScreenKbControlsShown[1] = Globals.AppNeedsTextInput;
for( int i = 2; i < Globals.ScreenKbControlsShown.length; i++ )
Globals.ScreenKbControlsShown[i] = ( i - 2 < Globals.AppTouchscreenKeyboardKeysAmount );
if( Globals.AppUsesSecondJoystick )
Globals.ScreenKbControlsShown[8] = true;
if( Globals.AppUsesThirdJoystick )
Globals.ScreenKbControlsShown[9] = true;
for( int i = 0; i < Globals.RemapMultitouchGestureKeycode.length; i++ )
{
int sdlKey = nativeGetKeymapKeyMultitouchGesture(i);
int idx = 0;
for(int ii = 0; ii < SDL_Keys.values.length; ii++)
if(SDL_Keys.values[ii] == sdlKey)
idx = ii;
Globals.RemapMultitouchGestureKeycode[i] = idx;
}
for( int i = 0; i < Globals.MultitouchGesturesUsed.length; i++ )
Globals.MultitouchGesturesUsed[i] = true;
// Adjust coordinates of on-screen buttons from 800x480
int displayX = 800;
int displayY = 480;
try {
DisplayMetrics dm = new DisplayMetrics();
p.getWindowManager().getDefaultDisplay().getMetrics(dm);
displayX = dm.widthPixels;
displayY = dm.heightPixels;
} catch (Exception eeeee) {}
for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ )
{
Globals.ScreenKbControlsLayout[i][0] *= (float)displayX / 800.0f;
Globals.ScreenKbControlsLayout[i][2] *= (float)displayX / 800.0f;
Globals.ScreenKbControlsLayout[i][1] *= (float)displayY / 480.0f;
Globals.ScreenKbControlsLayout[i][3] *= (float)displayY / 480.0f;
// Make them square
int wh = Math.min( Globals.ScreenKbControlsLayout[i][2] - Globals.ScreenKbControlsLayout[i][0], Globals.ScreenKbControlsLayout[i][3] - Globals.ScreenKbControlsLayout[i][1] );
Globals.ScreenKbControlsLayout[i][2] = Globals.ScreenKbControlsLayout[i][0] + wh;
Globals.ScreenKbControlsLayout[i][3] = Globals.ScreenKbControlsLayout[i][1] + wh;
}
Log.i("SDL", "android.os.Build.MODEL: " + android.os.Build.MODEL);
if( (android.os.Build.MODEL.equals("GT-N7000") || android.os.Build.MODEL.equals("SGH-I717"))
&& android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.GINGERBREAD_MR1 )
{
// Samsung Galaxy Note generates a keypress when you hover a stylus over the screen, and that messes up OpenTTD dialogs
// ICS update sends events in a proper way
Globals.RemapHwKeycode[112] = SDL_1_2_Keycodes.SDLK_UNKNOWN;
}
convertButtonSizeFromOldSdlVersion = false;
try {
ObjectInputStream settingsFile = new ObjectInputStream(new FileInputStream( p.getFilesDir().getAbsolutePath() + "/" + SettingsFileName ));
if( settingsFile.readInt() != SETTINGS_FILE_VERSION )
@@ -362,7 +290,7 @@ public class Settings
Globals.OptionalDataDownload[i] = settingsFile.readBoolean();
settingsFile.readBoolean(); // Unused
Globals.TouchscreenKeyboardDrawSize = settingsFile.readInt();
int cfgVersion = settingsFile.readInt();
settingsAppVersion = settingsFile.readInt();
// Gyroscope calibration data, now unused
settingsFile.readFloat();
settingsFile.readFloat();
@@ -388,19 +316,112 @@ public class Settings
Globals.TvBorders = settingsFile.readBoolean();
Globals.ForceHardwareMouse = settingsFile.readBoolean();
convertButtonSizeFromOldSdlVersion = settingsFile.readBoolean();
Globals.DrawInDisplayCutout = settingsFile.readBoolean();
settingsLoaded = true;
Log.i("SDL", "libSDL: Settings.Load(): loaded settings successfully");
Log.i("SDL", "libSDL: Settings.LoadConfig(): loaded settings successfully");
settingsFile.close();
Log.i("SDL", "libSDL: old cfg version " + cfgVersion + ", our version " + p.getApplicationVersion());
if( cfgVersion != p.getApplicationVersion() )
return true;
} catch( FileNotFoundException e ) {
Log.i("SDL", "libSDL: settings file not found: " + e);
} catch( SecurityException e ) {
Log.i("SDL", "libSDL: settings file cannot be opened: " + e);
} catch( IOException e ) {
Log.i("SDL", "libSDL: settings file cannot be read: " + e);
}
return false;
}
static void ProcessConfig( final MainActivity p )
{
if( settingsLoaded ) // Prevent starting twice
{
return;
}
Log.i("SDL", "libSDL: Settings.ProcessConfig(): enter");
nativeInitKeymap();
for( int i = 0; i < SDL_Keys.JAVA_KEYCODE_LAST; i++ )
{
int sdlKey = nativeGetKeymapKey(i);
int idx = 0;
for(int ii = 0; ii < SDL_Keys.values.length; ii++)
if(SDL_Keys.values[ii] == sdlKey)
idx = ii;
Globals.RemapHwKeycode[i] = idx;
}
for( int i = 0; i < Globals.RemapScreenKbKeycode.length; i++ )
{
int sdlKey = nativeGetKeymapKeyScreenKb(i);
int idx = 0;
for(int ii = 0; ii < SDL_Keys.values.length; ii++)
if(SDL_Keys.values[ii] == sdlKey)
idx = ii;
Globals.RemapScreenKbKeycode[i] = idx;
}
Globals.ScreenKbControlsShown[0] = (Globals.AppNeedsArrowKeys || Globals.AppUsesJoystick);
Globals.ScreenKbControlsShown[1] = Globals.AppNeedsTextInput;
for( int i = 2; i < Globals.ScreenKbControlsShown.length; i++ )
Globals.ScreenKbControlsShown[i] = ( i - 2 < Globals.AppTouchscreenKeyboardKeysAmount );
if( Globals.AppUsesSecondJoystick )
Globals.ScreenKbControlsShown[8] = true;
if( Globals.AppUsesThirdJoystick )
Globals.ScreenKbControlsShown[9] = true;
for( int i = 0; i < Globals.RemapMultitouchGestureKeycode.length; i++ )
{
int sdlKey = nativeGetKeymapKeyMultitouchGesture(i);
int idx = 0;
for(int ii = 0; ii < SDL_Keys.values.length; ii++)
if(SDL_Keys.values[ii] == sdlKey)
idx = ii;
Globals.RemapMultitouchGestureKeycode[i] = idx;
}
for( int i = 0; i < Globals.MultitouchGesturesUsed.length; i++ )
Globals.MultitouchGesturesUsed[i] = true;
// Adjust coordinates of on-screen buttons from 800x480
int displayX = 800;
int displayY = 480;
try {
DisplayMetrics dm = new DisplayMetrics();
p.getWindowManager().getDefaultDisplay().getMetrics(dm);
displayX = dm.widthPixels;
displayY = dm.heightPixels;
} catch (Exception eeeee) {}
for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ )
{
Globals.ScreenKbControlsLayout[i][0] *= (float)displayX / 800.0f;
Globals.ScreenKbControlsLayout[i][2] *= (float)displayX / 800.0f;
Globals.ScreenKbControlsLayout[i][1] *= (float)displayY / 480.0f;
Globals.ScreenKbControlsLayout[i][3] *= (float)displayY / 480.0f;
// Make them square
int wh = Math.min( Globals.ScreenKbControlsLayout[i][2] - Globals.ScreenKbControlsLayout[i][0], Globals.ScreenKbControlsLayout[i][3] - Globals.ScreenKbControlsLayout[i][1] );
Globals.ScreenKbControlsLayout[i][2] = Globals.ScreenKbControlsLayout[i][0] + wh;
Globals.ScreenKbControlsLayout[i][3] = Globals.ScreenKbControlsLayout[i][1] + wh;
}
Log.i("SDL", "android.os.Build.MODEL: " + android.os.Build.MODEL);
if( (android.os.Build.MODEL.equals("GT-N7000") || android.os.Build.MODEL.equals("SGH-I717"))
&& android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.GINGERBREAD_MR1 )
{
// Samsung Galaxy Note generates a keypress when you hover a stylus over the screen, and that messes up OpenTTD dialogs
// ICS update sends events in a proper way
Globals.RemapHwKeycode[112] = SDL_1_2_Keycodes.SDLK_UNKNOWN;
}
convertButtonSizeFromOldSdlVersion = false;
settingsLoaded = LoadConfig(p);
if (settingsLoaded)
{
Log.i("SDL", "libSDL: Settings.ProcessConfig(): loaded settings successfully");
Log.i("SDL", "libSDL: old app version " + settingsAppVersion + ", new app version " + p.getApplicationVersion());
if( settingsAppVersion != p.getApplicationVersion() )
{
DeleteFilesOnUpgrade(p);
if( Globals.ResetSdlConfigForThisVersion )
{
Log.i("SDL", "libSDL: old cfg version " + cfgVersion + ", our version " + p.getApplicationVersion() + " and we need to clean up config file");
Log.i("SDL", "libSDL: old app version " + settingsAppVersion + ", new app version " + p.getApplicationVersion() + " and we need to clean up config file");
// Delete settings file, and restart the application
DeleteSdlConfigOnUpgradeAndRestart(p);
}
@@ -408,26 +429,21 @@ public class Settings
}
return;
} catch( FileNotFoundException e ) {
Log.i("SDL", "libSDL: settings file not found: " + e);
} catch( SecurityException e ) {
Log.i("SDL", "libSDL: settings file cannot be opened: " + e);
} catch( IOException e ) {
Log.i("SDL", "libSDL: settings file cannot be read: " + e);
DeleteFilesOnUpgrade(p);
if (convertButtonSizeFromOldSdlVersion && Globals.TouchscreenKeyboardSize + 1 < Globals.TOUCHSCREEN_KEYBOARD_CUSTOM)
{
Globals.TouchscreenKeyboardSize ++; // New default button size is bigger, but we are keeping old button size for existing installations
//if (Globals.AppTouchscreenKeyboardKeysAmount <= 4 && Globals.TouchscreenKeyboardSize + 1 < Globals.TOUCHSCREEN_KEYBOARD_CUSTOM)
// Globals.TouchscreenKeyboardSize ++; // If there are only 4 buttons they are even bigger
}
if( Globals.ResetSdlConfigForThisVersion )
{
Log.i("SDL", "libSDL: old cfg version unknown or too old, our version " + p.getApplicationVersion() + " and we need to clean up config file");
DeleteSdlConfigOnUpgradeAndRestart(p);
}
};
}
Log.i("SDL", "libSDL: settings cannot be loaded");
DeleteFilesOnUpgrade(p);
if (convertButtonSizeFromOldSdlVersion && Globals.TouchscreenKeyboardSize + 1 < Globals.TOUCHSCREEN_KEYBOARD_CUSTOM)
{
Globals.TouchscreenKeyboardSize ++; // New default button size is bigger, but we are keeping old button size for existing installations
//if (Globals.AppTouchscreenKeyboardKeysAmount <= 4 && Globals.TouchscreenKeyboardSize + 1 < Globals.TOUCHSCREEN_KEYBOARD_CUSTOM)
// Globals.TouchscreenKeyboardSize ++; // If there are only 4 buttons they are even bigger
}
if( Globals.ResetSdlConfigForThisVersion && settingsAppVersion != 0 )
{
Log.i("SDL", "libSDL: old cfg version unknown or too old, our version " + p.getApplicationVersion() + " and we need to clean up config file");
DeleteSdlConfigOnUpgradeAndRestart(p);
}
if( Globals.DataDir.length() == 0 )
{

View File

@@ -703,14 +703,6 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
hh = topView.getHeight() - topView.getHeight() % 2;
}
if (Globals.DrawInDisplayCutout) {
final Rect r = new Rect();
context._videoLayout.getWindowVisibleDisplayFrame(r);
//ww = r.width();
//hh = r.height();
//Log.v("SDL", "DemoRenderer.onWindowResize(): adjusted to display cutout");
}
Display display = context.getWindowManager().getDefaultDisplay();
if (mWidth != 0 && mHeight != 0 && (mWidth != ww || mHeight != hh))

View File

@@ -180,7 +180,7 @@ AppUsesMultitouch=y
AppRecordsAudio=y
# Application needs read/write access SD card. Always disable it, unless you want to access user photos and downloads. (y) / (n)
AccessSdCard=
AccessSdCard=n
# Application needs to read it's own OBB file. Enable this if you are using Play Store expansion files. (y) / (n)
ReadObbFile=y
@@ -189,10 +189,13 @@ ReadObbFile=y
AccessInternet=y
# Immersive mode - Android will hide on-screen Home/Back keys. Looks bad if you invoke Android keyboard. (y) / (n)
ImmersiveMode=
ImmersiveMode=y
# Draw in the display cutout area. (y) / (n)
DrawInDisplayCutout=y
# Hide Android system mouse cursor image when USB mouse is attached (y) or (n) - the app must draw it's own mouse cursor
HideSystemMousePointer=
HideSystemMousePointer=y
# Application implements Android-specific routines to put to background, and will not draw anything to screen
# between SDL_ACTIVEEVENT lost / gained notifications - you should check for them
@@ -269,7 +272,6 @@ APP_PLATFORM=
# Specify architectures to compile, 'all' or 'y' to compile for all architectures.
# Available architectures: armeabi-v7a arm64-v8a x86 x86_64
MultiABI='armeabi-v7a x86 arm64-v8a x86_64'
MultiABI='arm64-v8a'
# Optional shared libraries to compile - removing some of them will save space

View File

@@ -1,5 +0,0 @@
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
</resources>