From 3dcf9e963e3d3c5d209cd3676c2f979a58c6c1ab Mon Sep 17 00:00:00 2001 From: TheBrokenRail <17478432+TheBrokenRail@users.noreply.github.com> Date: Sun, 26 Sep 2021 12:04:09 -0400 Subject: Touch UI support for desktop builds (#10729) --- src/client/clientlauncher.cpp | 7 ++----- src/client/game.cpp | 21 ++++++++++++--------- src/client/renderingengine.cpp | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) (limited to 'src/client') diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 6ab610670..95be72ca0 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -38,9 +38,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #if USE_SOUND #include "sound_openal.h" #endif -#ifdef __ANDROID__ - #include "porting.h" -#endif /* mainmenumanager.h */ @@ -147,8 +144,8 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255, 0, 0, 0)); skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 70, 120, 50)); skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255, 255, 255, 255)); -#ifdef __ANDROID__ - float density = porting::getDisplayDensity(); +#ifdef HAVE_TOUCHSCREENGUI + float density = RenderingEngine::getDisplayDensity(); skin->setSize(gui::EGDS_CHECK_BOX_WIDTH, (s32)(17.0f * density)); skin->setSize(gui::EGDS_SCROLLBAR_SIZE, (s32)(14.0f * density)); skin->setSize(gui::EGDS_WINDOW_BUTTON_WIDTH, (s32)(15.0f * density)); diff --git a/src/client/game.cpp b/src/client/game.cpp index 6eb09adfa..f7fd7abf9 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -566,7 +566,7 @@ public: } }; -#ifdef __ANDROID__ +#ifdef HAVE_TOUCHSCREENGUI #define SIZE_TAG "size[11,5.5]" #else #define SIZE_TAG "size[11,5.5,true]" // Fixed size on desktop @@ -901,8 +901,10 @@ private: bool m_does_lost_focus_pause_game = false; int m_reset_HW_buffer_counter = 0; -#ifdef __ANDROID__ +#ifdef HAVE_TOUCHSCREENGUI bool m_cache_hold_aux1; +#endif +#ifdef __ANDROID__ bool m_android_chat_open; #endif }; @@ -940,7 +942,7 @@ Game::Game() : readSettings(); -#ifdef __ANDROID__ +#ifdef HAVE_TOUCHSCREENGUI m_cache_hold_aux1 = false; // This is initialised properly later #endif @@ -1065,7 +1067,7 @@ void Game::run() set_light_table(g_settings->getFloat("display_gamma")); -#ifdef __ANDROID__ +#ifdef HAVE_TOUCHSCREENGUI m_cache_hold_aux1 = g_settings->getBool("fast_move") && client->checkPrivilege("fast"); #endif @@ -1845,6 +1847,7 @@ void Game::processUserInput(f32 dtime) else if (g_touchscreengui) { /* on touchscreengui step may generate own input events which ain't * what we want in case we just did clear them */ + g_touchscreengui->show(); g_touchscreengui->step(dtime); } #endif @@ -2157,7 +2160,7 @@ void Game::toggleFast() m_game_ui->showTranslatedStatusText("Fast mode disabled"); } -#ifdef __ANDROID__ +#ifdef HAVE_TOUCHSCREENGUI m_cache_hold_aux1 = fast_move && has_fast_privs; #endif } @@ -2495,10 +2498,10 @@ void Game::updatePlayerControl(const CameraOrientation &cam) control.movement_direction = 0.0f; } -#ifdef ANDROID - /* For Android, simulate holding down AUX1 (fast move) if the user has +#ifdef HAVE_TOUCHSCREENGUI + /* For touch, simulate holding down AUX1 (fast move) if the user has * the fast_move setting toggled on. If there is an aux1 key defined for - * Android then its meaning is inverted (i.e. holding aux1 means walk and + * touch then its meaning is inverted (i.e. holding aux1 means walk and * not fast) */ if (m_cache_hold_aux1) { @@ -4184,7 +4187,7 @@ void Game::showDeathFormspec() #define GET_KEY_NAME(KEY) gettext(getKeySetting(#KEY).name()) void Game::showPauseMenu() { -#ifdef __ANDROID__ +#ifdef HAVE_TOUCHSCREENGUI static const std::string control_text = strgettext("Default Controls:\n" "No menu visible:\n" "- single tap: button activate\n" diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 0fdbc95dc..723865db4 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -598,7 +598,7 @@ static float calcDisplayDensity() float RenderingEngine::getDisplayDensity() { static float cached_display_density = calcDisplayDensity(); - return cached_display_density; + return cached_display_density * g_settings->getFloat("display_density_factor"); } #elif defined(_WIN32) @@ -626,14 +626,14 @@ float RenderingEngine::getDisplayDensity() display_density = calcDisplayDensity(get_video_driver()); cached = true; } - return display_density; + return display_density * g_settings->getFloat("display_density_factor"); } #else float RenderingEngine::getDisplayDensity() { - return g_settings->getFloat("screen_dpi") / 96.0; + return (g_settings->getFloat("screen_dpi") / 96.0) * g_settings->getFloat("display_density_factor"); } #endif -- cgit v1.2.3