diff --git a/src/client/game.cpp b/src/client/game.cpp index 603f7425d..9820a62f3 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2146,7 +2146,7 @@ void Game::openConsole(float scale, const wchar_t *line) gui_chat_console->setAndroidChatOpen(true); } - if (!g_settings->getBool("device_is_tablet")) + if (!RenderingEngine::isTablet()) return; #endif diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 0bee0a044..dd6742f86 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -791,13 +791,23 @@ v2u32 RenderingEngine::getDisplaySize() } #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() { #if defined(__MACH__) && defined(__APPLE__) && !defined(__IOS__) return g_settings->getFloat("screen_dpi") / 72.0f >= 2; #elif defined(__IOS__) float density = RenderingEngine::getDisplayDensity(); - return g_settings->getBool("device_is_tablet") ? (density >= 2) : (density >= 3); + return isTablet() ? (density >= 2) : (density >= 3); #else return RenderingEngine::getDisplayDensity() >= 3; #endif diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index 4f9e2d902..39eec52eb 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -50,6 +50,7 @@ public: static const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type); static float getDisplayDensity(); static v2u32 getDisplaySize(); + static bool isTablet(); static bool isHighDpi(); bool setupTopLevelWindow(const std::string &name); diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index af1d1725c..184b3c26a 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapgen/mapgen.h" // Mapgen::setDefaultSettings #include "util/string.h" -#ifdef __ANDROID__ +#ifndef SERVER #include "client/renderingengine.h" #endif @@ -496,7 +496,9 @@ void set_default_settings() settings->setDefault("screen_dpi", "72"); 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 #if defined(__MACH__) && defined(__APPLE__) && !defined(__IOS__) @@ -540,6 +542,11 @@ void set_default_settings() settings->setDefault("autosave_screensize", "false"); 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] #ifdef __ANDROID__ float memoryMax = porting::getTotalSystemMemory(); @@ -644,10 +651,6 @@ void set_default_settings() // 7" tablets g_settings->setDefault("hud_scaling", "0.9"); 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) { @@ -676,12 +679,6 @@ void set_default_settings() 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 if SDVersion4Inch { // 4" iPhone and iPod Touch diff --git a/src/gui/guiConfirmRegistration.cpp b/src/gui/guiConfirmRegistration.cpp index a70630522..3effcfbc9 100644 --- a/src/gui/guiConfirmRegistration.cpp +++ b/src/gui/guiConfirmRegistration.cpp @@ -101,7 +101,7 @@ void GUIConfirmRegistration::regenerateGui(v2u32 screensize) */ float s = MYMIN(screensize.X / 600.f, screensize.Y / 360.f); #if HAVE_TOUCHSCREENGUI - s *= g_settings->getBool("device_is_tablet") ? 0.7f : 0.8f; + s *= RenderingEngine::isTablet() ? 0.7f : 0.8f; #else s *= 0.5f; #endif diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index 632995120..9d1387f39 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -530,7 +530,7 @@ void GUIEngine::drawHeader(video::IVideoDriver *driver) core::rect splashrect(0, 0, splashsize.X, splashsize.Y); 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); #endif diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index cdcdc57be..5b690a5ed 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -3394,7 +3394,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) double prefer_imgsize = padded_screensize.Y / 10 * gui_scaling; // 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; #else // Desktop computers have more space, so try to fit 15 coordinates. diff --git a/src/gui/guiKeyChangeMenu.cpp b/src/gui/guiKeyChangeMenu.cpp index 736a2bebd..8cffe9edf 100644 --- a/src/gui/guiKeyChangeMenu.cpp +++ b/src/gui/guiKeyChangeMenu.cpp @@ -137,7 +137,7 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) float s = MYMIN(screensize.X / 835.f, screensize.Y / 430.f); #if HAVE_TOUCHSCREENGUI - s *= g_settings->getBool("device_is_tablet") ? 0.8f : 0.9f; + s *= RenderingEngine::isTablet() ? 0.8f : 0.9f; #else s *= 0.75f; #endif diff --git a/src/gui/guiVolumeChange.cpp b/src/gui/guiVolumeChange.cpp index fbd192108..0dc0bc6f1 100644 --- a/src/gui/guiVolumeChange.cpp +++ b/src/gui/guiVolumeChange.cpp @@ -90,7 +90,7 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize) */ float s = MYMIN(screensize.X / 380.f, screensize.Y / 180.f); #if HAVE_TOUCHSCREENGUI - s *= g_settings->getBool("device_is_tablet") ? 0.4f : 0.5f; + s *= RenderingEngine::isTablet() ? 0.4f : 0.5f; #else s *= 0.35f; #endif