diff --git a/builtin/fstk/buttonbar.lua b/builtin/fstk/buttonbar.lua index effd0eba7bb8e..1070416f762a8 100644 --- a/builtin/fstk/buttonbar.lua +++ b/builtin/fstk/buttonbar.lua @@ -18,7 +18,7 @@ local BASE_SPACING = 0.1 -local SCROLL_BTN_WIDTH = TOUCHSCREEN_GUI and 0.8 or 0.5 +local SCROLL_BTN_WIDTH = core.settings:get_bool("enable_touch") and 0.8 or 0.5 local function buttonbar_formspec(self) if self.hidden then diff --git a/builtin/mainmenu/content/dlg_contentstore.lua b/builtin/mainmenu/content/dlg_contentstore.lua index e567fcef7a244..c45d321e5f2a0 100644 --- a/builtin/mainmenu/content/dlg_contentstore.lua +++ b/builtin/mainmenu/content/dlg_contentstore.lua @@ -898,7 +898,7 @@ local function get_info_formspec(text) return table.concat({ "formspec_version[6]", "size[15.75,9.5]", - TOUCHSCREEN_GUI and "padding[0.01,0.01]" or "position[0.5,0.55]", + core.settings:get_bool("enable_touch") and "padding[0.01,0.01]" or "position[0.5,0.55]", "label[4,4.35;", text, "]", "container[0,", H - 0.8 - 0.375, "]", @@ -928,7 +928,7 @@ function store.get_formspec(dlgdata) local formspec = { "formspec_version[6]", "size[15.75,9.5]", - TOUCHSCREEN_GUI and "padding[0.01,0.01]" or "position[0.5,0.55]", + core.settings:get_bool("enable_touch") and "padding[0.01,0.01]" or "position[0.5,0.55]", "style[status,downloading,queued;border=false]", @@ -1175,8 +1175,8 @@ end function store.handle_events(event) if event == "DialogShow" then - -- On mobile, don't show the "MINETEST" header behind the dialog. - mm_game_theme.set_engine(TOUCHSCREEN_GUI) + -- On touchscreen, Don't show the "MINETEST" header behind the dialog. + mm_game_theme.set_engine(core.settings:get_bool("enable_touch")) -- If the store is already loaded, auto-install packages here. do_auto_install() diff --git a/builtin/mainmenu/settings/dlg_settings.lua b/builtin/mainmenu/settings/dlg_settings.lua index 01ff2dcb0e6d5..459e5b62671a9 100644 --- a/builtin/mainmenu/settings/dlg_settings.lua +++ b/builtin/mainmenu/settings/dlg_settings.lua @@ -316,8 +316,8 @@ local function check_requirements(name, requires) local special = { android = PLATFORM == "Android", desktop = PLATFORM ~= "Android", - touchscreen_gui = TOUCHSCREEN_GUI, - keyboard_mouse = not TOUCHSCREEN_GUI, + touchscreen_gui = core.settings:get_bool("enable_touch"), + keyboard_mouse = not core.settings:get_bool("enable_touch"), shaders_support = shaders_support, shaders = core.settings:get_bool("enable_shaders") and shaders_support, opengl = video_driver == "opengl", @@ -449,13 +449,13 @@ local function get_formspec(dialogdata) local extra_h = 1 -- not included in tabsize.height local tabsize = { - width = TOUCHSCREEN_GUI and 16.5 or 15.5, - height = TOUCHSCREEN_GUI and (10 - extra_h) or 12, + width = core.settings:get_bool("enable_touch") and 16.5 or 15.5, + height = core.settings:get_bool("enable_touch") and (10 - extra_h) or 12, } - local scrollbar_w = TOUCHSCREEN_GUI and 0.6 or 0.4 + local scrollbar_w = core.settings:get_bool("enable_touch") and 0.6 or 0.4 - local left_pane_width = TOUCHSCREEN_GUI and 4.5 or 4.25 + local left_pane_width = core.settings:get_bool("enable_touch") and 4.5 or 4.25 local search_width = left_pane_width + scrollbar_w - (0.75 * 2) local back_w = 3 @@ -468,7 +468,7 @@ local function get_formspec(dialogdata) local fs = { "formspec_version[6]", "size[", tostring(tabsize.width), ",", tostring(tabsize.height + extra_h), "]", - TOUCHSCREEN_GUI and "padding[0.01,0.01]" or "", + core.settings:get_bool("enable_touch") and "padding[0.01,0.01]" or "", "bgcolor[#0000]", -- HACK: this is needed to allow resubmitting the same formspec diff --git a/builtin/mainmenu/tab_local.lua b/builtin/mainmenu/tab_local.lua index c35a3f6fba7af..ff1a22398caac 100644 --- a/builtin/mainmenu/tab_local.lua +++ b/builtin/mainmenu/tab_local.lua @@ -94,7 +94,7 @@ function singleplayer_refresh_gamebar() local btnbar = buttonbar_create( "game_button_bar", - TOUCHSCREEN_GUI and {x = 0, y = 7.25} or {x = 0, y = 7.475}, + core.settings:get_bool("enable_touch") and {x = 0, y = 7.25} or {x = 0, y = 7.475}, {x = 15.5, y = 1.25}, "#000000", game_buttonbar_button_handler) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 0af96cc3307b0..5470f83708001 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -148,6 +148,11 @@ invert_hotbar_mouse_wheel (Hotbar: Invert mouse wheel direction) bool false [*Touchscreen] +# Enables the touch screen. +# If disabled, touchscreen wouldn't be usable in-game +# Changing this setting requires a restart. +enable_touch (Enable Touchscreen) bool true + # The length in pixels it takes for touchscreen interaction to start. # # Requires: touchscreen_gui diff --git a/doc/compiling/README.md b/doc/compiling/README.md index f4812e77d36a8..d7c850bcc56fb 100644 --- a/doc/compiling/README.md +++ b/doc/compiling/README.md @@ -37,7 +37,7 @@ General options and their default values: INSTALL_DEVTEST=FALSE - Whether the Development Test game should be installed alongside Minetest USE_GPROF=FALSE - Enable profiling using GProf VERSION_EXTRA= - Text to append to version (e.g. VERSION_EXTRA=foobar -> Minetest 0.4.9-foobar) - ENABLE_TOUCH=FALSE - Enable Touchscreen support (requires support by IrrlichtMt) + ENABLE_TOUCH=FALSE - Enable Touchscreen support by default (requires support by IrrlichtMt) Library specific options: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e0fdc7c1a3fa..28dd47adf2db5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -109,9 +109,10 @@ if(BUILD_CLIENT AND ENABLE_SOUND) endif() endif() -option(ENABLE_TOUCH "Enable Touchscreen support" FALSE) +option(ENABLE_TOUCH "Enable touchscreen by default" FALSE) if(ENABLE_TOUCH) - add_definitions(-DHAVE_TOUCHSCREENGUI) + message(STATUS "Touchscreen support enabled by default.") + add_definitions(-DENABLE_TOUCH) endif() if(BUILD_CLIENT) diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 80381dc6ec97b..26865f736d3f9 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -256,10 +256,8 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) m_rendering_engine->get_video_driver()->setTextureCreationFlag( video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map")); -#ifdef HAVE_TOUCHSCREENGUI receiver->m_touchscreengui = new TouchScreenGUI(m_rendering_engine->get_raw_device(), receiver); g_touchscreengui = receiver->m_touchscreengui; -#endif the_game( kill, @@ -286,11 +284,9 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) m_rendering_engine->get_scene_manager()->clear(); -#ifdef HAVE_TOUCHSCREENGUI delete g_touchscreengui; g_touchscreengui = NULL; receiver->m_touchscreengui = NULL; -#endif // If no main menu, show error and exit if (skip_main_menu) { diff --git a/src/client/game.cpp b/src/client/game.cpp index af225924a680b..b0f4cf4b9d9ef 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -691,12 +691,6 @@ class GameGlobalShaderConstantSetterFactory : public IShaderConstantSetterFactor } }; -#ifdef HAVE_TOUCHSCREENGUI -#define SIZE_TAG "size[11,5.5]" -#else -#define SIZE_TAG "size[11,5.5,true]" // Fixed size on desktop -#endif - /**************************************************************************** ****************************************************************************/ @@ -1046,13 +1040,11 @@ class Game { // this happens in pause menu in singleplayer bool m_is_paused = false; -#ifdef HAVE_TOUCHSCREENGUI bool m_cache_hold_aux1; bool m_touch_use_crosshair; inline bool isNoCrosshairAllowed() { return !m_touch_use_crosshair && camera->getCameraMode() == CAMERA_MODE_FIRST; } -#endif #ifdef __ANDROID__ bool m_android_chat_open; #endif @@ -1101,9 +1093,7 @@ Game::Game() : readSettings(); -#ifdef HAVE_TOUCHSCREENGUI m_cache_hold_aux1 = false; // This is initialised properly later -#endif } @@ -1207,9 +1197,7 @@ bool Game::startup(bool *kill, m_first_loop_after_window_activation = true; -#ifdef HAVE_TOUCHSCREENGUI m_touch_use_crosshair = g_settings->getBool("touch_use_crosshair"); -#endif g_client_translations->clear(); @@ -1244,10 +1232,8 @@ void Game::run() set_light_table(g_settings->getFloat("display_gamma")); -#ifdef HAVE_TOUCHSCREENGUI m_cache_hold_aux1 = g_settings->getBool("fast_move") && client->checkPrivilege("fast"); -#endif const irr::core::dimension2du initial_screen_size( g_settings->getU16("screen_w"), @@ -1333,9 +1319,8 @@ void Game::shutdown() if (formspec) formspec->quitMenu(); -#ifdef HAVE_TOUCHSCREENGUI - g_touchscreengui->hide(); -#endif + if (g_settings->getBool("enable_touch")) + g_touchscreengui->hide(); showOverlayMessage(N_("Shutting down..."), 0, 0, false); @@ -1489,12 +1474,12 @@ bool Game::createClient(const GameStartData &start_data) return false; bool could_connect, connect_aborted; -#ifdef HAVE_TOUCHSCREENGUI - if (g_touchscreengui) { + + if (g_settings->getBool("enable_touch") && g_touchscreengui) { g_touchscreengui->init(texture_src); g_touchscreengui->hide(); } -#endif + if (!connectToServer(start_data, &could_connect, &connect_aborted)) return false; @@ -1529,11 +1514,10 @@ bool Game::createClient(const GameStartData &start_data) if (client->modsLoaded()) client->getScript()->on_camera_ready(camera); client->setCamera(camera); -#ifdef HAVE_TOUCHSCREENGUI - if (g_touchscreengui) { + + if (g_settings->getBool("enable_touch") && g_touchscreengui) { g_touchscreengui->setUseCrosshair(!isNoCrosshairAllowed()); } -#endif /* Clouds */ @@ -1602,13 +1586,9 @@ bool Game::initGui() gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(), -1, chat_backend, client, &g_menumgr); -#ifdef HAVE_TOUCHSCREENGUI - - if (g_touchscreengui) + if (g_settings->getBool("enable_touch") && g_touchscreengui) g_touchscreengui->show(); -#endif - return true; } @@ -2018,18 +1998,17 @@ void Game::processUserInput(f32 dtime) } else { input->clear(); } -#ifdef HAVE_TOUCHSCREENGUI - g_touchscreengui->hide(); -#endif + + if (g_settings->getBool("enable_touch")) + g_touchscreengui->hide(); + } else { -#ifdef HAVE_TOUCHSCREENGUI - if (g_touchscreengui) { + if (g_settings->getBool("enable_touch") && 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 m_game_focused = true; } @@ -2221,13 +2200,11 @@ void Game::processItemSelection(u16 *new_playeritem) } } -#ifdef HAVE_TOUCHSCREENGUI - if (g_touchscreengui) { + if (g_settings->getBool("enable_touch") && g_touchscreengui) { std::optional selection = g_touchscreengui->getHotbarSelection(); if (selection) *new_playeritem = *selection; } -#endif // Clamp selection again in case it wasn't changed but max_item was *new_playeritem = MYMIN(*new_playeritem, max_item); @@ -2374,9 +2351,7 @@ void Game::toggleFast() m_game_ui->showTranslatedStatusText("Fast mode disabled"); } -#ifdef HAVE_TOUCHSCREENGUI m_cache_hold_aux1 = fast_move && has_fast_privs; -#endif } @@ -2674,12 +2649,10 @@ f32 Game::getSensitivityScaleFactor() const void Game::updateCameraOrientation(CameraOrientation *cam, float dtime) { -#ifdef HAVE_TOUCHSCREENGUI - if (g_touchscreengui) { + if (g_settings->getBool("enable_touch") && g_touchscreengui) { cam->camera_yaw += g_touchscreengui->getYawChange(); cam->camera_pitch += g_touchscreengui->getPitchChange(); } else { -#endif v2s32 center(driver->getScreenSize().Width / 2, driver->getScreenSize().Height / 2); v2s32 dist = input->getMousePos() - center; @@ -2693,9 +2666,7 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime) if (dist.X != 0 || dist.Y != 0) input->setMousePos(center.X, center.Y); -#ifdef HAVE_TOUCHSCREENGUI } -#endif if (m_cache_enable_joysticks) { f32 sens_scale = getSensitivityScaleFactor(); @@ -2740,16 +2711,14 @@ void Game::updatePlayerControl(const CameraOrientation &cam) control.movement_direction = atan2(dx, 1.0f); } -#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 * touch then its meaning is inverted (i.e. holding aux1 means walk and * not fast) */ - if (m_cache_hold_aux1) { + if (g_settings->getBool("enable_touch") && m_cache_hold_aux1) { control.aux1 = control.aux1 ^ true; } -#endif client->setPlayerControl(control); @@ -3216,10 +3185,8 @@ void Game::updateCamera(f32 dtime) camera->toggleCameraMode(); -#ifdef HAVE_TOUCHSCREENGUI - if (g_touchscreengui) + if (g_settings->getBool("enable_touch") && g_touchscreengui) g_touchscreengui->setUseCrosshair(!isNoCrosshairAllowed()); -#endif // Make the player visible depending on camera mode. playercao->updateMeshCulling(); @@ -3320,8 +3287,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud) } shootline.end = shootline.start + camera_direction * BS * d; -#ifdef HAVE_TOUCHSCREENGUI - if (g_touchscreengui && isNoCrosshairAllowed()) { + if (g_settings->getBool("enable_touch") && g_touchscreengui && isNoCrosshairAllowed()) { shootline = g_touchscreengui->getShootline(); // Scale shootline to the acual distance the player can reach shootline.end = shootline.start + @@ -3329,7 +3295,6 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud) shootline.start += intToFloat(camera_offset, BS); shootline.end += intToFloat(camera_offset, BS); } -#endif PointedThing pointed = updatePointedThing(shootline, selected_def.liquids_pointable, @@ -4290,10 +4255,10 @@ void Game::drawScene(ProfilerGraph *graph, RunStats *stats) bool draw_crosshair = ( (player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) && (this->camera->getCameraMode() != CAMERA_MODE_THIRD_FRONT)); -#ifdef HAVE_TOUCHSCREENGUI - if (this->isNoCrosshairAllowed()) + + if (g_settings->getBool("enable_touch") && isNoCrosshairAllowed()) draw_crosshair = false; -#endif + this->m_rendering_engine->draw_scene(sky_color, this->m_game_ui->m_flags.show_hud, this->m_game_ui->m_flags.show_minimap, draw_wield_tool, draw_crosshair); @@ -4417,9 +4382,15 @@ void Game::readSettings() void Game::showDeathFormspec() { + std::string size_tag; + if (g_settings->getBool("enable_touch")) + size_tag = "size[11,5.5]"; + else + size_tag = "size[11,5.5,true]"; // Fixed size on desktop + static std::string formspec_str = std::string("formspec_version[1]") + - SIZE_TAG + size_tag + "bgcolor[#320000b4;true]" "label[4.85,1.35;" + gettext("You died") + "]" "button_exit[4,3;3,0.5;btn_respawn;" + gettext("Respawn") + "]" @@ -4441,61 +4412,65 @@ void Game::showDeathFormspec() #define GET_KEY_NAME(KEY) gettext(getKeySetting(#KEY).name()) void Game::showPauseMenu() { -#ifdef HAVE_TOUCHSCREENGUI - static const std::string control_text = strgettext("Controls:\n" - "No menu open:\n" - "- slide finger: look around\n" - "- tap: place/use\n" - "- long tap: dig/punch/use\n" - "Menu/inventory open:\n" - "- double tap (outside):\n" - " --> close\n" - "- touch stack, touch slot:\n" - " --> move stack\n" - "- touch&drag, tap 2nd finger\n" - " --> place single item to slot\n" + std::string control_text, size_tag; + + if (g_settings->getBool("enable_touch")) { + size_tag = "size[11,5.5]"; + control_text = strgettext("Controls:\n" + "No menu open:\n" + "- slide finger: look around\n" + "- tap: place/use\n" + "- long tap: dig/punch/use\n" + "Menu/inventory open:\n" + "- double tap (outside):\n" + " --> close\n" + "- touch stack, touch slot:\n" + " --> move stack\n" + "- touch&drag, tap 2nd finger\n" + " --> place single item to slot\n" + ); + } else { + size_tag = "size[11,5.5,true]"; // Fixed size on desktop + static const std::string control_text_template = strgettext("Controls:\n" + "- %s: move forwards\n" + "- %s: move backwards\n" + "- %s: move left\n" + "- %s: move right\n" + "- %s: jump/climb up\n" + "- %s: dig/punch/use\n" + "- %s: place/use\n" + "- %s: sneak/climb down\n" + "- %s: drop item\n" + "- %s: inventory\n" + "- Mouse: turn/look\n" + "- Mouse wheel: select item\n" + "- %s: chat\n" ); -#else - static const std::string control_text_template = strgettext("Controls:\n" - "- %s: move forwards\n" - "- %s: move backwards\n" - "- %s: move left\n" - "- %s: move right\n" - "- %s: jump/climb up\n" - "- %s: dig/punch/use\n" - "- %s: place/use\n" - "- %s: sneak/climb down\n" - "- %s: drop item\n" - "- %s: inventory\n" - "- Mouse: turn/look\n" - "- Mouse wheel: select item\n" - "- %s: chat\n" - ); - char control_text_buf[600]; - - porting::mt_snprintf(control_text_buf, sizeof(control_text_buf), control_text_template.c_str(), - GET_KEY_NAME(keymap_forward), - GET_KEY_NAME(keymap_backward), - GET_KEY_NAME(keymap_left), - GET_KEY_NAME(keymap_right), - GET_KEY_NAME(keymap_jump), - GET_KEY_NAME(keymap_dig), - GET_KEY_NAME(keymap_place), - GET_KEY_NAME(keymap_sneak), - GET_KEY_NAME(keymap_drop), - GET_KEY_NAME(keymap_inventory), - GET_KEY_NAME(keymap_chat) - ); + char control_text_buf[600]; + + porting::mt_snprintf(control_text_buf, sizeof(control_text_buf), control_text_template.c_str(), + GET_KEY_NAME(keymap_forward), + GET_KEY_NAME(keymap_backward), + GET_KEY_NAME(keymap_left), + GET_KEY_NAME(keymap_right), + GET_KEY_NAME(keymap_jump), + GET_KEY_NAME(keymap_dig), + GET_KEY_NAME(keymap_place), + GET_KEY_NAME(keymap_sneak), + GET_KEY_NAME(keymap_drop), + GET_KEY_NAME(keymap_inventory), + GET_KEY_NAME(keymap_chat) + ); - std::string control_text = std::string(control_text_buf); - str_formspec_escape(control_text); -#endif + control_text = std::string(control_text_buf); + str_formspec_escape(control_text); + } float ypos = simple_singleplayer_mode ? 0.7f : 0.1f; std::ostringstream os; - os << "formspec_version[1]" << SIZE_TAG + os << "formspec_version[1]" << size_tag << "button_exit[4," << (ypos++) << ";3,0.5;btn_continue;" << strgettext("Continue") << "]"; diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 5d3de7bfbf670..f209ce221a6f8 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -39,10 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "wieldmesh.h" #include "client/renderingengine.h" #include "client/minimap.h" - -#ifdef HAVE_TOUCHSCREENGUI #include "gui/touchscreengui.h" -#endif #define OBJECT_CROSSHAIR_LINE_SIZE 8 #define CROSSHAIR_LINE_SIZE 10 @@ -292,10 +289,8 @@ void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount, drawItem(mainlist->getItem(i), item_rect, (i + 1) == selectitem); -#ifdef HAVE_TOUCHSCREENGUI - if (is_hotbar && g_touchscreengui) + if (g_settings->getBool("enable_touch") && is_hotbar && g_touchscreengui) g_touchscreengui->registerHotbarRect(i, item_rect); -#endif } } @@ -739,10 +734,8 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, void Hud::drawHotbar(u16 playeritem) { -#ifdef HAVE_TOUCHSCREENGUI - if (g_touchscreengui) + if (g_settings->getBool("enable_touch") && g_touchscreengui) g_touchscreengui->resetHotbarRects(); -#endif InventoryList *mainlist = inventory->getList("main"); if (mainlist == NULL) { diff --git a/src/client/inputhandler.cpp b/src/client/inputhandler.cpp index 7b54ac93d6fc4..82303c4558832 100644 --- a/src/client/inputhandler.cpp +++ b/src/client/inputhandler.cpp @@ -102,11 +102,9 @@ bool MyEventReceiver::OnEvent(const SEvent &event) React to nothing here if a menu is active */ if (isMenuActive()) { -#ifdef HAVE_TOUCHSCREENGUI if (m_touchscreengui) { m_touchscreengui->setVisible(false); } -#endif return g_menumgr.preprocessEvent(event); } @@ -130,12 +128,10 @@ bool MyEventReceiver::OnEvent(const SEvent &event) return true; } -#ifdef HAVE_TOUCHSCREENGUI } else if (m_touchscreengui && event.EventType == irr::EET_TOUCH_INPUT_EVENT) { // In case of touchscreengui, we have to handle different events m_touchscreengui->translateEvent(event); return true; -#endif } else if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) { // joystick may be nullptr if game is launched with '--random-input' parameter diff --git a/src/client/inputhandler.h b/src/client/inputhandler.h index 81bed61a8e5fe..6d768c4a4ba55 100644 --- a/src/client/inputhandler.h +++ b/src/client/inputhandler.h @@ -24,10 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "keycode.h" #include "renderingengine.h" - -#ifdef HAVE_TOUCHSCREENGUI #include "gui/touchscreengui.h" -#endif class InputHandler; @@ -203,16 +200,12 @@ class MyEventReceiver : public IEventReceiver MyEventReceiver() { -#ifdef HAVE_TOUCHSCREENGUI m_touchscreengui = NULL; -#endif } JoystickController *joystick = nullptr; -#ifdef HAVE_TOUCHSCREENGUI TouchScreenGUI *m_touchscreengui; -#endif private: s32 mouse_wheel = 0; @@ -332,11 +325,9 @@ class RealInputHandler : public InputHandler return 0.0f; return 1.0f; // If there is a keyboard event, assume maximum speed } -#ifdef HAVE_TOUCHSCREENGUI - return m_receiver->m_touchscreengui->getMovementSpeed(); -#else + if (m_receiver->m_touchscreengui->getMovementSpeed()) + return m_receiver->m_touchscreengui->getMovementSpeed(); return joystick.getMovementSpeed(); -#endif } virtual float getMovementDirection() @@ -355,12 +346,9 @@ class RealInputHandler : public InputHandler if (x != 0 || z != 0) /* If there is a keyboard event, it takes priority */ return atan2(x, z); - else -#ifdef HAVE_TOUCHSCREENGUI + else if (m_receiver->m_touchscreengui->getMovementDirection()) return m_receiver->m_touchscreengui->getMovementDirection(); -#else - return joystick.getMovementDirection(); -#endif + return joystick.getMovementDirection(); } virtual bool cancelPressed() diff --git a/src/clientdynamicinfo.h b/src/clientdynamicinfo.h index 547329b0660cf..2763b71037532 100644 --- a/src/clientdynamicinfo.h +++ b/src/clientdynamicinfo.h @@ -68,7 +68,7 @@ struct ClientDynamicInfo #ifndef SERVER static v2f32 calculateMaxFSSize(v2u32 render_target_size, f32 gui_scaling) { f32 factor = -#ifdef HAVE_TOUCHSCREENGUI +#ifdef __ANDROID__ 10 / gui_scaling; #else 15 / gui_scaling; diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 4505bdc2c4237..73a885931dcc4 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -39,6 +39,11 @@ void set_default_settings() // Client settings->setDefault("address", ""); settings->setDefault("enable_sound", "true"); +#if ENABLE_TOUCH + settings->setDefault("enable_touch", "true"); +#else + settings->setDefault("enable_touch", "false"); +#endif settings->setDefault("sound_volume", "0.8"); settings->setDefault("sound_volume_unfocused", "0.3"); settings->setDefault("mute_sound", "false"); @@ -90,7 +95,7 @@ void set_default_settings() settings->setDefault("keymap_cmd_local", "."); settings->setDefault("keymap_minimap", "KEY_KEY_V"); settings->setDefault("keymap_console", "KEY_F10"); -#if HAVE_TOUCHSCREENGUI +#if ENABLE_TOUCH // See https://github.com/minetest/minetest/issues/12792 settings->setDefault("keymap_rangeselect", "KEY_KEY_R"); #else @@ -192,7 +197,11 @@ void set_default_settings() settings->setDefault("screen_h", "600"); settings->setDefault("window_maximized", "false"); settings->setDefault("autosave_screensize", "true"); +#ifdef ENABLE_TOUCH + settings->setDefault("fullscreen", "true"); +#else settings->setDefault("fullscreen", "false"); +#endif settings->setDefault("vsync", "false"); settings->setDefault("fov", "72"); settings->setDefault("leaves_style", "fancy"); @@ -297,7 +306,7 @@ void set_default_settings() settings->setDefault("aux1_descends", "false"); settings->setDefault("doubletap_jump", "false"); settings->setDefault("always_fly_fast", "true"); -#ifdef HAVE_TOUCHSCREENGUI +#ifdef ENABLE_TOUCH settings->setDefault("autojump", "true"); #else settings->setDefault("autojump", "false"); @@ -476,21 +485,23 @@ void set_default_settings() settings->setDefault("keymap_sneak", "KEY_SHIFT"); #endif -#ifdef HAVE_TOUCHSCREENGUI settings->setDefault("touchscreen_threshold", "20"); settings->setDefault("touchscreen_sensitivity", "0.2"); +#ifdef ENABLE_TOUCH settings->setDefault("touch_use_crosshair", "false"); settings->setDefault("fixed_virtual_joystick", "false"); settings->setDefault("virtual_joystick_triggers_aux1", "false"); settings->setDefault("clickable_chat_weblinks", "false"); #else + settings->setDefault("touch_use_crosshair", "true"); + settings->setDefault("fixed_virtual_joystick", "true"); + settings->setDefault("virtual_joystick_triggers_aux1", "true"); settings->setDefault("clickable_chat_weblinks", "true"); #endif // Altered settings for Android #ifdef __ANDROID__ settings->setDefault("screen_w", "0"); settings->setDefault("screen_h", "0"); - settings->setDefault("fullscreen", "true"); settings->setDefault("performance_tradeoffs", "true"); settings->setDefault("max_simultaneous_block_sends_per_client", "10"); settings->setDefault("emergequeue_limit_diskonly", "16"); diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 4434b14a01f27..87575f3203bc8 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -1,8 +1,3 @@ -set(extra_gui_SRCS "") -if(ENABLE_TOUCH) - set(extra_gui_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/touchscreengui.cpp) -endif() - set(gui_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/guiAnimatedImage.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiBackgroundImage.cpp @@ -29,6 +24,6 @@ set(gui_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/guiVolumeChange.cpp ${CMAKE_CURRENT_SOURCE_DIR}/modalMenu.cpp ${CMAKE_CURRENT_SOURCE_DIR}/profilergraph.cpp - ${extra_gui_SRCS} + ${CMAKE_CURRENT_SOURCE_DIR}/touchscreengui.cpp PARENT_SCOPE ) diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 445c5b902d223..f86961cf1c991 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -315,13 +315,11 @@ void GUIFormSpecMenu::parseSize(parserData* data, const std::string &element) data->invsize.Y = MYMAX(0, stof(parts[1])); lockSize(false); -#ifndef HAVE_TOUCHSCREENGUI - if (parts.size() == 3) { + if (!g_settings->getBool("enable_touch") && parts.size() == 3) { if (parts[2] == "true") { lockSize(true,v2u32(800,600)); } } -#endif data->explicit_size = true; return; } @@ -3283,14 +3281,15 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) s32 min_screen_dim = std::min(padded_screensize.X, padded_screensize.Y); -#ifdef HAVE_TOUCHSCREENGUI - // In Android, the preferred imgsize should be larger to accommodate the - // smaller screensize. - double prefer_imgsize = min_screen_dim / 10 * gui_scaling; -#else - // Desktop computers have more space, so try to fit 15 coordinates. - double prefer_imgsize = min_screen_dim / 15 * gui_scaling; -#endif + double prefer_imgsize; + if (g_settings->getBool("enable_touch")) { + // The preferred imgsize should be larger to accommodate the + // smaller screensize. + prefer_imgsize = min_screen_dim / 10 * gui_scaling; + } else { + // Desktop computers have more space, so try to fit 15 coordinates. + prefer_imgsize = min_screen_dim / 15 * gui_scaling; + } // Try to use the preferred imgsize, but if that's bigger than the maximum // size, use the maximum size. use_imgsize = std::min(prefer_imgsize, @@ -3657,9 +3656,8 @@ void GUIFormSpecMenu::drawMenu() } // On touchscreens, m_pointer is set by GUIModalMenu::preprocessEvent instead. -#ifndef HAVE_TOUCHSCREENGUI - m_pointer = RenderingEngine::get_raw_device()->getCursorControl()->getPosition(); -#endif + if (!g_settings->getBool("enable_touch")) + m_pointer = RenderingEngine::get_raw_device()->getCursorControl()->getPosition(); /* Draw fields/buttons tooltips and update the mouse cursor @@ -3667,11 +3665,11 @@ void GUIFormSpecMenu::drawMenu() gui::IGUIElement *hovered = Environment->getRootGUIElement()->getElementFromPoint(m_pointer); -#ifndef HAVE_TOUCHSCREENGUI + gui::ICursorControl *cursor_control = RenderingEngine::get_raw_device()-> - getCursorControl(); + getCursorControl(); gui::ECURSOR_ICON current_cursor_icon = cursor_control->getActiveIcon(); -#endif + bool hovered_element_found = false; if (hovered) { @@ -3715,11 +3713,9 @@ void GUIFormSpecMenu::drawMenu() m_tooltips[field.fname].bgcolor); } -#ifndef HAVE_TOUCHSCREENGUI - if (field.ftype != f_HyperText && // Handled directly in guiHyperText + if (!g_settings->getBool("enable_touch") && field.ftype != f_HyperText && // Handled directly in guiHyperText current_cursor_icon != field.fcursor_icon) cursor_control->setActiveIcon(field.fcursor_icon); -#endif hovered_element_found = true; @@ -3728,12 +3724,10 @@ void GUIFormSpecMenu::drawMenu() } } - if (!hovered_element_found) { + if (!g_settings->getBool("enable_touch") && !hovered_element_found) { // no element is hovered -#ifndef HAVE_TOUCHSCREENGUI if (current_cursor_icon != ECI_NORMAL) cursor_control->setActiveIcon(ECI_NORMAL); -#endif } m_tooltip_element->draw(); @@ -3764,16 +3758,16 @@ void GUIFormSpecMenu::showTooltip(const std::wstring &text, v2u32 screenSize = Environment->getVideoDriver()->getScreenSize(); int tooltip_offset_x = m_btn_height; int tooltip_offset_y = m_btn_height; -#ifdef HAVE_TOUCHSCREENGUI - tooltip_offset_x *= 3; - tooltip_offset_y = 0; - if (m_pointer.X > (s32)screenSize.X / 2) - tooltip_offset_x = -(tooltip_offset_x + tooltip_width); - - // Hide tooltip after ETIE_LEFT_UP - if (m_pointer.X == 0) - return; -#endif + if (g_settings->getBool("enable_touch")) { + tooltip_offset_x *= 3; + tooltip_offset_y = 0; + if (m_pointer.X > (s32)screenSize.X / 2) + tooltip_offset_x = -(tooltip_offset_x + tooltip_width); + + // Hide tooltip after ETIE_LEFT_UP + if (m_pointer.X == 0) + return; + } // Calculate and set the tooltip position s32 tooltip_x = m_pointer.X + tooltip_offset_x; @@ -4326,14 +4320,12 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) } } -#ifdef HAVE_TOUCHSCREENGUI // The second touch (see GUIModalMenu::preprocessEvent() function) ButtonEventType touch = BET_OTHER; if (event.EventType == EET_TOUCH_INPUT_EVENT) { if (event.TouchInput.Event == ETIE_LEFT_UP) touch = BET_RIGHT; } -#endif // Set this number to a positive value to generate a move action // from m_selected_item to s. @@ -4678,8 +4670,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) break; } -#ifdef HAVE_TOUCHSCREENGUI - if (touch == BET_RIGHT && m_selected_item && !m_left_dragging) { + if (g_settings->getBool("enable_touch") && touch == BET_RIGHT && m_selected_item && !m_left_dragging) { if (!s.isValid()) { // Not a valid slot if (!getAbsoluteClippingRect().isPointInside(m_pointer)) @@ -4698,7 +4689,6 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) } } } -#endif // Update left-dragged slots if (m_left_dragging && m_left_drag_stacks.size() > 1) { @@ -5067,10 +5057,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) } } -#ifdef HAVE_TOUCHSCREENGUI - if (m_second_touch) + if (g_settings->getBool("enable_touch") && m_second_touch) return true; // Stop propagating the event -#endif return Parent ? Parent->OnEvent(event) : false; } diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index 66771f2e2066c..5330eb2724068 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -1052,14 +1052,15 @@ void GUIHyperText::checkHover(s32 X, s32 Y) } } -#ifndef HAVE_TOUCHSCREENGUI + if (g_settings->getBool("enable_touch")) + return; + if (m_drawer.m_hovertag) RenderingEngine::get_raw_device()->getCursorControl()->setActiveIcon( gui::ECI_HAND); else RenderingEngine::get_raw_device()->getCursorControl()->setActiveIcon( gui::ECI_NORMAL); -#endif } bool GUIHyperText::OnEvent(const SEvent &event) @@ -1075,12 +1076,12 @@ bool GUIHyperText::OnEvent(const SEvent &event) if (event.EventType == EET_GUI_EVENT && event.GUIEvent.EventType == EGET_ELEMENT_LEFT) { m_drawer.m_hovertag = nullptr; -#ifndef HAVE_TOUCHSCREENGUI - gui::ICursorControl *cursor_control = - RenderingEngine::get_raw_device()->getCursorControl(); - if (cursor_control->isVisible()) - cursor_control->setActiveIcon(gui::ECI_NORMAL); -#endif + if (!g_settings->getBool("enable_touch")) { + gui::ICursorControl *cursor_control = + RenderingEngine::get_raw_device()->getCursorControl(); + if (cursor_control->isVisible()) + cursor_control->setActiveIcon(gui::ECI_NORMAL); + } } if (event.EventType == EET_MOUSE_INPUT_EVENT) { diff --git a/src/gui/guiInventoryList.cpp b/src/gui/guiInventoryList.cpp index 6f1d28e0b0006..c906b5adc719f 100644 --- a/src/gui/guiInventoryList.cpp +++ b/src/gui/guiInventoryList.cpp @@ -152,10 +152,11 @@ void GUIInventoryList::draw() // Add hovering tooltip bool show_tooltip = !item.empty() && hovering && !selected_item; -#ifdef HAVE_TOUCHSCREENGUI - // Make it possible to see item tooltips on touchscreens - show_tooltip |= hovering && selected && m_fs_menu->getSelectedAmount() != 0; -#endif + + if (g_settings->getBool("enable_touch")) { + // Make it possible to see item tooltips on touchscreens + show_tooltip |= hovering && selected && m_fs_menu->getSelectedAmount() != 0; + } if (show_tooltip) { std::string tooltip = orig_item.getDescription(client->idef()); if (m_fs_menu->doTooltipAppendItemname()) diff --git a/src/gui/guiPasswordChange.cpp b/src/gui/guiPasswordChange.cpp index e100643a40315..596140b1418b5 100644 --- a/src/gui/guiPasswordChange.cpp +++ b/src/gui/guiPasswordChange.cpp @@ -24,10 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include - -#ifdef HAVE_TOUCHSCREENGUI - #include "client/renderingengine.h" -#endif +#include "client/renderingengine.h" #include "porting.h" #include "gettext.h" @@ -66,11 +63,8 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize) /* Calculate new sizes and positions */ -#ifdef HAVE_TOUCHSCREENGUI const float s = m_gui_scale * RenderingEngine::getDisplayDensity() / 2; -#else - const float s = m_gui_scale; -#endif + DesiredRect = core::rect( screensize.X / 2 - 580 * s / 2, screensize.Y / 2 - 300 * s / 2, diff --git a/src/gui/guiTable.cpp b/src/gui/guiTable.cpp index b5042802a50d9..09b64f9cc83fe 100644 --- a/src/gui/guiTable.cpp +++ b/src/gui/guiTable.cpp @@ -77,11 +77,9 @@ GUITable::GUITable(gui::IGUIEnvironment *env, setTabStop(true); setTabOrder(-1); updateAbsolutePosition(); -#ifdef HAVE_TOUCHSCREENGUI - float density = 1; // dp scaling is applied by the skin -#else + float density = RenderingEngine::getDisplayDensity(); -#endif + core::rect relative_rect = m_scrollbar->getRelativePosition(); s32 width = (relative_rect.getWidth() / (2.0 / 3.0)) * density * g_settings->getFloat("gui_scaling", 0.5f, 20.0f); diff --git a/src/gui/modalMenu.cpp b/src/gui/modalMenu.cpp index d4322c9f76543..d90f91d93fe4e 100644 --- a/src/gui/modalMenu.cpp +++ b/src/gui/modalMenu.cpp @@ -24,10 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "gettext.h" #include "porting.h" #include "settings.h" - -#ifdef HAVE_TOUCHSCREENGUI #include "touchscreengui.h" -#endif GUIModalMenu::GUIModalMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, bool remap_dbl_click) : @@ -41,11 +38,12 @@ GUIModalMenu::GUIModalMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, { m_gui_scale = std::max(g_settings->getFloat("gui_scaling"), 0.5f); const float screen_dpi_scale = RenderingEngine::getDisplayDensity(); -#ifdef HAVE_TOUCHSCREENGUI - m_gui_scale *= 1.1f - 0.3f * screen_dpi_scale + 0.2f * screen_dpi_scale * screen_dpi_scale; -#else - m_gui_scale *= screen_dpi_scale; -#endif + + if (g_settings->getBool("enable_touch")) { + m_gui_scale *= 1.1f - 0.3f * screen_dpi_scale + 0.2f * screen_dpi_scale * screen_dpi_scale; + } else { + m_gui_scale *= screen_dpi_scale; + } setVisible(true); m_menumgr->createdMenu(this); @@ -102,10 +100,8 @@ void GUIModalMenu::quitMenu() Environment->removeFocus(this); m_menumgr->deletingMenu(this); this->remove(); -#ifdef HAVE_TOUCHSCREENGUI - if (g_touchscreengui && m_touchscreen_visible) + if (g_settings->getBool("enable_touch") && g_touchscreengui && m_touchscreen_visible) g_touchscreengui->show(); -#endif } bool GUIModalMenu::DoubleClickDetection(const SEvent &event) @@ -169,8 +165,6 @@ static bool isChild(gui::IGUIElement *tocheck, gui::IGUIElement *parent) return false; } -#ifdef HAVE_TOUCHSCREENGUI - bool GUIModalMenu::simulateMouseEvent( gui::IGUIElement *target, ETOUCH_INPUT_EVENT touch_event) { @@ -227,8 +221,6 @@ void GUIModalMenu::leave() m_hovered.reset(); } -#endif - bool GUIModalMenu::preprocessEvent(const SEvent &event) { #ifdef __ANDROID__ @@ -268,7 +260,6 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event) } #endif -#ifdef HAVE_TOUCHSCREENGUI if (event.EventType == EET_TOUCH_INPUT_EVENT) { irr_ptr holder; holder.grab(this); // keep this alive until return (it might be dropped downstream [?]) @@ -306,7 +297,6 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event) return true; } } -#endif if (event.EventType == EET_MOUSE_INPUT_EVENT) { s32 x = event.MouseInput.X; diff --git a/src/gui/modalMenu.h b/src/gui/modalMenu.h index f811bafc97781..1ea0d985ef585 100644 --- a/src/gui/modalMenu.h +++ b/src/gui/modalMenu.h @@ -76,11 +76,9 @@ class GUIModalMenu : public gui::IGUIElement #ifdef __ANDROID__ std::string m_jni_field_name; #endif -#ifdef HAVE_TOUCHSCREENGUI // This is set to true if the menu is currently processing a second-touch event. bool m_second_touch = false; bool m_touchscreen_visible = true; -#endif private: struct clickpos @@ -102,11 +100,9 @@ class GUIModalMenu : public gui::IGUIElement // wants to launch other menus bool m_allow_focus_removal = false; -#ifdef HAVE_TOUCHSCREENGUI irr_ptr m_hovered; bool simulateMouseEvent(gui::IGUIElement *target, ETOUCH_INPUT_EVENT touch_event); void enter(gui::IGUIElement *element); void leave(); -#endif }; diff --git a/src/main.cpp b/src/main.cpp index d85afe97a7661..57c9486fb0e54 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,9 +50,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "gui/guiEngine.h" #include "gui/mainmenumanager.h" #endif -#ifdef HAVE_TOUCHSCREENGUI - #include "gui/touchscreengui.h" -#endif +#include "gui/touchscreengui.h" // for version information only extern "C" { diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index 73f8c49a10f66..c576b6ce8ab93 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -153,13 +153,6 @@ ScriptApiBase::ScriptApiBase(ScriptingType type): lua_pushstring(m_luastack, porting::getPlatformName()); lua_setglobal(m_luastack, "PLATFORM"); -#ifdef HAVE_TOUCHSCREENGUI - lua_pushboolean(m_luastack, true); -#else - lua_pushboolean(m_luastack, false); -#endif - lua_setglobal(m_luastack, "TOUCHSCREEN_GUI"); - // Make sure Lua uses the right locale setlocale(LC_NUMERIC, "C"); }