1
0

Mobile: use SDL_IsTablet() to determine the device type

This commit is contained in:
Maksym H 2023-08-22 01:51:20 +03:00
parent 8daac0ba49
commit 1c1acc3cfb
9 changed files with 27 additions and 19 deletions

View File

@ -2146,7 +2146,7 @@ void Game::openConsole(float scale, const wchar_t *line)
gui_chat_console->setAndroidChatOpen(true); gui_chat_console->setAndroidChatOpen(true);
} }
if (!g_settings->getBool("device_is_tablet")) if (!RenderingEngine::isTablet())
return; return;
#endif #endif

View File

@ -791,13 +791,23 @@ v2u32 RenderingEngine::getDisplaySize()
} }
#endif // __ANDROID__/__IOS__ #endif // __ANDROID__/__IOS__
bool RenderingEngine::isTablet()
{
#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
static const bool isTablet = SDL_IsTablet();
return isTablet;
#else
return false;
#endif
}
bool RenderingEngine::isHighDpi() bool RenderingEngine::isHighDpi()
{ {
#if defined(__MACH__) && defined(__APPLE__) && !defined(__IOS__) #if defined(__MACH__) && defined(__APPLE__) && !defined(__IOS__)
return g_settings->getFloat("screen_dpi") / 72.0f >= 2; return g_settings->getFloat("screen_dpi") / 72.0f >= 2;
#elif defined(__IOS__) #elif defined(__IOS__)
float density = RenderingEngine::getDisplayDensity(); float density = RenderingEngine::getDisplayDensity();
return g_settings->getBool("device_is_tablet") ? (density >= 2) : (density >= 3); return isTablet() ? (density >= 2) : (density >= 3);
#else #else
return RenderingEngine::getDisplayDensity() >= 3; return RenderingEngine::getDisplayDensity() >= 3;
#endif #endif

View File

@ -50,6 +50,7 @@ public:
static const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type); static const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type);
static float getDisplayDensity(); static float getDisplayDensity();
static v2u32 getDisplaySize(); static v2u32 getDisplaySize();
static bool isTablet();
static bool isHighDpi(); static bool isHighDpi();
bool setupTopLevelWindow(const std::string &name); bool setupTopLevelWindow(const std::string &name);

View File

@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapgen/mapgen.h" // Mapgen::setDefaultSettings #include "mapgen/mapgen.h" // Mapgen::setDefaultSettings
#include "util/string.h" #include "util/string.h"
#ifdef __ANDROID__ #ifndef SERVER
#include "client/renderingengine.h" #include "client/renderingengine.h"
#endif #endif
@ -496,7 +496,9 @@ void set_default_settings()
settings->setDefault("screen_dpi", "72"); settings->setDefault("screen_dpi", "72");
settings->setDefault("display_density_factor", "1"); settings->setDefault("display_density_factor", "1");
settings->setDefault("device_is_tablet", "false"); #ifndef SERVER
settings->setDefault("device_is_tablet", std::to_string(RenderingEngine::isTablet()));
#endif
// Altered settings for macOS // Altered settings for macOS
#if defined(__MACH__) && defined(__APPLE__) && !defined(__IOS__) #if defined(__MACH__) && defined(__APPLE__) && !defined(__IOS__)
@ -540,6 +542,11 @@ void set_default_settings()
settings->setDefault("autosave_screensize", "false"); settings->setDefault("autosave_screensize", "false");
settings->setDefault("recent_chat_messages", "6"); settings->setDefault("recent_chat_messages", "6");
if (RenderingEngine::isTablet()) {
settings->setDefault("recent_chat_messages", "8");
settings->setDefault("console_message_height", "0.4");
}
// Set the optimal settings depending on the memory size [Android] | model [iOS] // Set the optimal settings depending on the memory size [Android] | model [iOS]
#ifdef __ANDROID__ #ifdef __ANDROID__
float memoryMax = porting::getTotalSystemMemory(); float memoryMax = porting::getTotalSystemMemory();
@ -644,10 +651,6 @@ void set_default_settings()
// 7" tablets // 7" tablets
g_settings->setDefault("hud_scaling", "0.9"); g_settings->setDefault("hud_scaling", "0.9");
g_settings->setDefault("selectionbox_width", "6"); g_settings->setDefault("selectionbox_width", "6");
} else if (x_inches >= 7.0) {
settings->setDefault("device_is_tablet", "true");
settings->setDefault("recent_chat_messages", "8");
settings->setDefault("console_message_height", "0.4");
} }
if (x_inches <= 4.5) { if (x_inches <= 4.5) {
@ -676,12 +679,6 @@ void set_default_settings()
settings->setDefault("debug_log_level", "none"); settings->setDefault("debug_log_level", "none");
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
settings->setDefault("device_is_tablet", "true");
settings->setDefault("recent_chat_messages", "8");
settings->setDefault("console_message_height", "0.4");
}
// Set the size of the elements depending on the screen size // Set the size of the elements depending on the screen size
if SDVersion4Inch { if SDVersion4Inch {
// 4" iPhone and iPod Touch // 4" iPhone and iPod Touch

View File

@ -101,7 +101,7 @@ void GUIConfirmRegistration::regenerateGui(v2u32 screensize)
*/ */
float s = MYMIN(screensize.X / 600.f, screensize.Y / 360.f); float s = MYMIN(screensize.X / 600.f, screensize.Y / 360.f);
#if HAVE_TOUCHSCREENGUI #if HAVE_TOUCHSCREENGUI
s *= g_settings->getBool("device_is_tablet") ? 0.7f : 0.8f; s *= RenderingEngine::isTablet() ? 0.7f : 0.8f;
#else #else
s *= 0.5f; s *= 0.5f;
#endif #endif

View File

@ -530,7 +530,7 @@ void GUIEngine::drawHeader(video::IVideoDriver *driver)
core::rect<s32> splashrect(0, 0, splashsize.X, splashsize.Y); core::rect<s32> splashrect(0, 0, splashsize.X, splashsize.Y);
splashrect += v2s32((screensize.Width/2)-(splashsize.X/2), 0); splashrect += v2s32((screensize.Width/2)-(splashsize.X/2), 0);
if (g_settings->getBool("device_is_tablet")) if (RenderingEngine::isTablet())
splashrect += v2s32(0, splashsize.Y/4); splashrect += v2s32(0, splashsize.Y/4);
#endif #endif

View File

@ -3394,7 +3394,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
double prefer_imgsize = padded_screensize.Y / 10 * gui_scaling; double prefer_imgsize = padded_screensize.Y / 10 * gui_scaling;
// Try to fit 13 coordinates on large tablets. // Try to fit 13 coordinates on large tablets.
if (g_settings->getBool("device_is_tablet")) if (RenderingEngine::isTablet())
prefer_imgsize = padded_screensize.Y / 13 * gui_scaling; prefer_imgsize = padded_screensize.Y / 13 * gui_scaling;
#else #else
// Desktop computers have more space, so try to fit 15 coordinates. // Desktop computers have more space, so try to fit 15 coordinates.

View File

@ -137,7 +137,7 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
float s = MYMIN(screensize.X / 835.f, screensize.Y / 430.f); float s = MYMIN(screensize.X / 835.f, screensize.Y / 430.f);
#if HAVE_TOUCHSCREENGUI #if HAVE_TOUCHSCREENGUI
s *= g_settings->getBool("device_is_tablet") ? 0.8f : 0.9f; s *= RenderingEngine::isTablet() ? 0.8f : 0.9f;
#else #else
s *= 0.75f; s *= 0.75f;
#endif #endif

View File

@ -90,7 +90,7 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize)
*/ */
float s = MYMIN(screensize.X / 380.f, screensize.Y / 180.f); float s = MYMIN(screensize.X / 380.f, screensize.Y / 180.f);
#if HAVE_TOUCHSCREENGUI #if HAVE_TOUCHSCREENGUI
s *= g_settings->getBool("device_is_tablet") ? 0.4f : 0.5f; s *= RenderingEngine::isTablet() ? 0.4f : 0.5f;
#else #else
s *= 0.35f; s *= 0.35f;
#endif #endif