Android: get screen resolution from Irrlicht (part II)

This commit is contained in:
MoNTE48 2021-06-23 16:42:53 +03:00
parent 46ad1a831f
commit a59bc6946c
5 changed files with 39 additions and 26 deletions

View File

@ -36,6 +36,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "clientlauncher.h" #include "clientlauncher.h"
#include "version.h" #include "version.h"
#ifdef __ANDROID__
#include "defaultsettings.h"
#endif
#ifdef __IOS__ #ifdef __IOS__
namespace irr { namespace irr {
class CIrrDeviceiOS : public IrrlichtDevice { class CIrrDeviceiOS : public IrrlichtDevice {
@ -539,8 +542,13 @@ bool ClientLauncher::create_engine_device()
{ {
// Resolution selection // Resolution selection
bool fullscreen = g_settings->getBool("fullscreen"); bool fullscreen = g_settings->getBool("fullscreen");
#if defined(__ANDROID__) || defined(__IOS__)
u16 screenW = 0;
u16 screenH = 0;
#else
u16 screenW = g_settings->getU16("screenW"); u16 screenW = g_settings->getU16("screenW");
u16 screenH = g_settings->getU16("screenH"); u16 screenH = g_settings->getU16("screenH");
#endif
// bpp, fsaa, vsync // bpp, fsaa, vsync
bool vsync = g_settings->getBool("vsync"); bool vsync = g_settings->getBool("vsync");
@ -592,28 +600,7 @@ bool ClientLauncher::create_engine_device()
#ifdef __ANDROID__ #ifdef __ANDROID__
// Apply settings according to screen size // Apply settings according to screen size
// We can get real screen size only after device initialization finished // We can get real screen size only after device initialization finished
float x_inches = porting::getWindowSize().X / set_default_settings(g_settings);
(160.f * porting::getDisplayDensity());
if (x_inches <= 3.7) {
// small 4" phones
g_settings->setFloat("hud_scaling", 0.55);
g_settings->setU16("font_size", TTF_DEFAULT_FONT_SIZE - 1);
g_settings->setFloat("mouse_sensitivity", 0.3);
} else if (x_inches > 3.7 && x_inches <= 4.5) {
// medium phones
g_settings->setFloat("hud_scaling", 0.6);
g_settings->setU16("font_size", TTF_DEFAULT_FONT_SIZE - 1);
g_settings->setS16("selectionbox_width", 6);
} else if (x_inches > 4.5 && x_inches <= 5.5) {
// large 6" phones
g_settings->setFloat("hud_scaling", 0.7);
g_settings->setFloat("mouse_sensitivity", 0.15);
g_settings->setS16("selectionbox_width", 6);
} else if (x_inches > 5.5 && x_inches <= 6.5) {
// 7" tablets
g_settings->setFloat("hud_scaling", 0.9);
g_settings->setS16("selectionbox_width", 6);
}
#endif #endif
#ifdef __IOS__ #ifdef __IOS__
CIrrDeviceiOS* dev = (CIrrDeviceiOS*) device; CIrrDeviceiOS* dev = (CIrrDeviceiOS*) device;

View File

@ -399,8 +399,6 @@ void set_default_settings(Settings *settings) {
// Mobile Platform // Mobile Platform
#if defined(__ANDROID__) || defined(__IOS__) #if defined(__ANDROID__) || defined(__IOS__)
settings->setDefault("screenW", "0");
settings->setDefault("screenH", "0");
settings->setDefault("fullscreen", "true"); settings->setDefault("fullscreen", "true");
settings->setDefault("touchtarget", "true"); settings->setDefault("touchtarget", "true");
settings->setDefault("touchscreen_threshold", "20"); settings->setDefault("touchscreen_threshold", "20");
@ -510,6 +508,32 @@ void set_default_settings(Settings *settings) {
// Set font_path // Set font_path
settings->setDefault("mono_font_path", "/system/fonts/DroidSansMono.ttf"); settings->setDefault("mono_font_path", "/system/fonts/DroidSansMono.ttf");
settings->setDefault("fallback_font_path", "/system/fonts/DroidSans.ttf"); settings->setDefault("fallback_font_path", "/system/fonts/DroidSans.ttf");
v2u32 window_size = porting::getWindowSize();
if (window_size.X > 0) {
float x_inches = window_size.X /
(160.f * porting::getDisplayDensity());
if (x_inches <= 3.7) {
// small 4" phones
g_settings->setFloat("hud_scaling", 0.55);
g_settings->setU16("font_size", TTF_DEFAULT_FONT_SIZE - 1);
g_settings->setFloat("mouse_sensitivity", 0.3);
} else if (x_inches > 3.7 && x_inches <= 4.5) {
// medium phones
g_settings->setFloat("hud_scaling", 0.6);
g_settings->setU16("font_size", TTF_DEFAULT_FONT_SIZE - 1);
g_settings->setS16("selectionbox_width", 6);
} else if (x_inches > 4.5 && x_inches <= 5.5) {
// large 6" phones
g_settings->setFloat("hud_scaling", 0.7);
g_settings->setFloat("mouse_sensitivity", 0.15);
g_settings->setS16("selectionbox_width", 6);
} else if (x_inches > 5.5 && x_inches <= 6.5) {
// 7" tablets
g_settings->setFloat("hud_scaling", 0.9);
g_settings->setS16("selectionbox_width", 6);
}
}
#endif // Android #endif // Android
// iOS Settings // iOS Settings

View File

@ -755,6 +755,8 @@ void initIrrlicht(irr::IrrlichtDevice *device_)
v2u32 getWindowSize() v2u32 getWindowSize()
{ {
if (device == NULL)
return v2u32(0, 0);
return device->getVideoDriver()->getScreenSize(); return device->getVideoDriver()->getScreenSize();
} }

View File

@ -322,6 +322,6 @@ float getDisplayDensity()
} }
v2u32 getDisplaySize() { v2u32 getDisplaySize() {
return v2u32(0, 0); return porting::getWindowSize();
} }
} }

View File

@ -56,7 +56,7 @@ namespace porting {
} }
v2u32 getDisplaySize() { v2u32 getDisplaySize() {
return v2u32(0,0); return porting::getWindowSize();
} }
void setViewController(void *v) { void setViewController(void *v) {