From e18b6c5a21880125284d2a1e9dfb5471d5bc2bec Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Wed, 22 Jan 2020 20:23:40 +0100 Subject: GUIFormSpecMenu: Shift+Click listring workaround for MacOS event.MouseInput.Shift is not implemented for MacOS --- src/gui/guiFormSpecMenu.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 632b15992..74578111e 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -4075,6 +4075,9 @@ enum ButtonEventType : u8 bool GUIFormSpecMenu::OnEvent(const SEvent& event) { + // WORKAROUND: event.MouseInput.Shift is not implemented for MacOS + static thread_local bool is_shift_down = false; + if (event.EventType==EET_KEY_INPUT_EVENT) { KeyPress kp(event.KeyInput); if (event.KeyInput.PressedDown && ( @@ -4084,6 +4087,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) return true; } + is_shift_down = event.KeyInput.Shift; + if (m_client != NULL && event.KeyInput.PressedDown && (kp == getKeySetting("keymap_screenshot"))) { m_client->makeScreenshot(); @@ -4133,6 +4138,9 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) event.MouseInput.isRightPressed() && getItemAtPos(m_pointer).i != getItemAtPos(m_old_pointer).i))) { + // WORKAROUND: In case shift was pressed prior showing the formspec + is_shift_down |= event.MouseInput.Shift; + // Get selected item and hovered/clicked item (s) m_old_tooltip_id = -1; @@ -4263,7 +4271,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) else // left count = s_count; - if (!event.MouseInput.Shift) { + if (!is_shift_down) { // no shift: select item m_selected_amount = count; m_selected_dragging = button != BET_WHEEL_DOWN; -- cgit v1.2.3 From f2c8c6bf51e608ad6f71710032b8ae017b84fd3d Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 13 Dec 2020 18:25:13 +0100 Subject: Revert "GUIFormSpecMenu: Shift+Click listring workaround for MacOS" The commit caused Shift-Clicking issues on Linux due to another Irrlicht bug where KeyInput.Shift released keys do not trigger OnEvent() MacOS users should build using a recent Irrlicht 1.8 development version. See also: https://sourceforge.net/p/irrlicht/patches/321/ --- src/gui/guiFormSpecMenu.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'src/gui') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 74578111e..632b15992 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -4075,9 +4075,6 @@ enum ButtonEventType : u8 bool GUIFormSpecMenu::OnEvent(const SEvent& event) { - // WORKAROUND: event.MouseInput.Shift is not implemented for MacOS - static thread_local bool is_shift_down = false; - if (event.EventType==EET_KEY_INPUT_EVENT) { KeyPress kp(event.KeyInput); if (event.KeyInput.PressedDown && ( @@ -4087,8 +4084,6 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) return true; } - is_shift_down = event.KeyInput.Shift; - if (m_client != NULL && event.KeyInput.PressedDown && (kp == getKeySetting("keymap_screenshot"))) { m_client->makeScreenshot(); @@ -4138,9 +4133,6 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) event.MouseInput.isRightPressed() && getItemAtPos(m_pointer).i != getItemAtPos(m_old_pointer).i))) { - // WORKAROUND: In case shift was pressed prior showing the formspec - is_shift_down |= event.MouseInput.Shift; - // Get selected item and hovered/clicked item (s) m_old_tooltip_id = -1; @@ -4271,7 +4263,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) else // left count = s_count; - if (!is_shift_down) { + if (!event.MouseInput.Shift) { // no shift: select item m_selected_amount = count; m_selected_dragging = button != BET_WHEEL_DOWN; -- cgit v1.2.3 From d0a38f694d483fbd9c0554c8d7175a94097fd67e Mon Sep 17 00:00:00 2001 From: Thomas--S Date: Tue, 15 Dec 2020 19:06:36 +0100 Subject: Formspec: Allow to specify frame loop for model[] (#10679) Add the ability to specify an animation frame loop range for the model[] formspec element. --- doc/lua_api.txt | 6 +++++- src/gui/guiFormSpecMenu.cpp | 21 ++++++++++++++++----- src/gui/guiScene.cpp | 9 +++++++++ src/gui/guiScene.h | 1 + 4 files changed, 31 insertions(+), 6 deletions(-) (limited to 'src/gui') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index f5c07fe85..ddb6d4e19 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -2277,7 +2277,7 @@ Elements * `frame duration`: Milliseconds between each frame. `0` means the frames don't advance. * `frame start` (Optional): The index of the frame to start on. Default `1`. -### `model[,;,;;;;;;]` +### `model[,;,;;;;;;;]` * Show a mesh model. * `name`: Element name that can be used for styling @@ -2288,6 +2288,9 @@ Elements The axes are euler angles in degrees. * `continuous` (Optional): Whether the rotation is continuous. Default `false`. * `mouse control` (Optional): Whether the model can be controlled with the mouse. Default `true`. +* `frame loop range` (Optional): Range of the animation frames. + * Defaults to the full range of all available frames. + * Syntax: `,` ### `item_image[,;,;]` @@ -2789,6 +2792,7 @@ Some types may inherit styles from parent types. * image_button * item_image_button * label +* model * pwdfield, inherits from field * scrollbar * tabheader diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 632b15992..ed197d0d1 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -70,7 +70,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define MY_CHECKPOS(a,b) \ if (v_pos.size() != 2) { \ - errorstream<< "Invalid pos for element " << a << "specified: \"" \ + errorstream<< "Invalid pos for element " << a << " specified: \"" \ << parts[b] << "\"" << std::endl; \ return; \ } @@ -78,7 +78,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define MY_CHECKGEOM(a,b) \ if (v_geom.size() != 2) { \ errorstream<< "Invalid geometry for element " << a << \ - "specified: \"" << parts[b] << "\"" << std::endl; \ + " specified: \"" << parts[b] << "\"" << std::endl; \ return; \ } /* @@ -2725,7 +2725,7 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element) { std::vector parts = split(element, ';'); - if (parts.size() < 5 || (parts.size() > 8 && + if (parts.size() < 5 || (parts.size() > 9 && m_formspec_version <= FORMSPEC_API_VERSION)) { errorstream << "Invalid model element (" << parts.size() << "): '" << element << "'" << std::endl; @@ -2733,8 +2733,8 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element) } // Avoid length checks by resizing - if (parts.size() < 8) - parts.resize(8); + if (parts.size() < 9) + parts.resize(9); std::vector v_pos = split(parts[0], ','); std::vector v_geom = split(parts[1], ','); @@ -2744,6 +2744,7 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element) std::vector vec_rot = split(parts[5], ','); bool inf_rotation = is_yes(parts[6]); bool mousectrl = is_yes(parts[7]) || parts[7].empty(); // default true + std::vector frame_loop = split(parts[8], ','); MY_CHECKPOS("model", 0); MY_CHECKGEOM("model", 1); @@ -2794,6 +2795,16 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element) e->enableContinuousRotation(inf_rotation); e->enableMouseControl(mousectrl); + s32 frame_loop_begin = 0; + s32 frame_loop_end = 0x7FFFFFFF; + + if (frame_loop.size() == 2) { + frame_loop_begin = stoi(frame_loop[0]); + frame_loop_end = stoi(frame_loop[1]); + } + + e->setFrameLoop(frame_loop_begin, frame_loop_end); + auto style = getStyleForElement("model", spec.fname); e->setStyles(style); e->drop(); diff --git a/src/gui/guiScene.cpp b/src/gui/guiScene.cpp index 08f119e07..5f4c50b91 100644 --- a/src/gui/guiScene.cpp +++ b/src/gui/guiScene.cpp @@ -152,6 +152,15 @@ void GUIScene::setStyles(const std::array &sty setBackgroundColor(style.getColor(StyleSpec::BGCOLOR, m_bgcolor)); } +/** + * Sets the frame loop range for the mesh + */ +void GUIScene::setFrameLoop(s32 begin, s32 end) +{ + if (m_mesh->getStartFrame() != begin || m_mesh->getEndFrame() != end) + m_mesh->setFrameLoop(begin, end); +} + /* Camera control functions */ inline void GUIScene::calcOptimalDistance() diff --git a/src/gui/guiScene.h b/src/gui/guiScene.h index 707e6f66a..08eb7f350 100644 --- a/src/gui/guiScene.h +++ b/src/gui/guiScene.h @@ -36,6 +36,7 @@ public: scene::IAnimatedMeshSceneNode *setMesh(scene::IAnimatedMesh *mesh = nullptr); void setTexture(u32 idx, video::ITexture *texture); void setBackgroundColor(const video::SColor &color) noexcept { m_bgcolor = color; }; + void setFrameLoop(s32 begin, s32 end); void enableMouseControl(bool enable) noexcept { m_mouse_ctrl = enable; }; void setRotation(v2f rot) noexcept { m_custom_rot = rot; }; void enableContinuousRotation(bool enable) noexcept { m_inf_rot = enable; }; -- cgit v1.2.3 From 74762470b2aa11a5271b846549ff14b86c1705d2 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 23 Dec 2020 22:03:49 +0100 Subject: Fix some minor code issues all over the place --- CMakeLists.txt | 8 +------- lib/lua/CMakeLists.txt | 13 ++----------- src/CMakeLists.txt | 23 ----------------------- src/client/content_cao.cpp | 4 ++-- src/client/game.cpp | 36 +++++------------------------------- src/client/hud.cpp | 6 +++--- src/client/mapblock_mesh.cpp | 4 ++-- src/client/tile.cpp | 7 +++++++ src/filesys.cpp | 22 ++++++++-------------- src/gui/touchscreengui.cpp | 3 +-- src/irrlicht_changes/CGUITTFont.h | 2 +- src/irrlicht_changes/irrUString.h | 4 ++-- src/mapgen/mapgen_v7.cpp | 2 +- src/mapgen/treegen.cpp | 3 ++- src/network/serverpackethandler.cpp | 2 +- src/nodedef.cpp | 2 +- src/script/cpp_api/s_security.cpp | 7 +++---- src/util/srp.cpp | 4 ++-- src/util/string.cpp | 2 +- 19 files changed, 45 insertions(+), 109 deletions(-) (limited to 'src/gui') diff --git a/CMakeLists.txt b/CMakeLists.txt index 78d551168..1d53fcffd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,9 @@ -cmake_minimum_required(VERSION 2.6) - -if(${CMAKE_VERSION} STREQUAL "2.8.2") - # Bug http://vtk.org/Bug/view.php?id=11020 - message(WARNING "CMake/CPack version 2.8.2 will not create working .deb packages!") -endif() +cmake_minimum_required(VERSION 3.5) # This can be read from ${PROJECT_NAME} after project() is called project(minetest) set(PROJECT_NAME_CAPITALIZED "Minetest") -# Works only for cmake 3.1 and greater set(CMAKE_CXX_STANDARD 11) set(GCC_MINIMUM_VERSION "4.8") set(CLANG_MINIMUM_VERSION "3.4") diff --git a/lib/lua/CMakeLists.txt b/lib/lua/CMakeLists.txt index 119dd6302..5d0dc0f70 100644 --- a/lib/lua/CMakeLists.txt +++ b/lib/lua/CMakeLists.txt @@ -1,5 +1,3 @@ -cmake_minimum_required(VERSION 2.4 FATAL_ERROR) - project(lua C) set(LUA_VERSION_MAJOR 5) @@ -15,9 +13,8 @@ set(LIBS) if(APPLE) set(DEFAULT_POSIX TRUE) - set(DEFAULT_DLOPEN ON) - # use this on Mac OS X 10.3- - option(LUA_USE_MACOSX "Mac OS X 10.3-" OFF) + set(DEFAULT_DLOPEN OFF) + set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_MACOSX") elseif(UNIX OR CYGWIN) set(DEFAULT_POSIX TRUE) elseif(WIN32) @@ -32,12 +29,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(DEFAULT_DLOPEN ON) endif() -# For "Mac OS X 10.3-" -if(LUA_USE_MACOSX) - set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_MACOSX") - set(LUA_USE_DLOPEN FALSE) -endif(LUA_USE_MACOSX) - option(LUA_USE_DLOPEN "Enable dlopen support." ${DEFAULT_DLOPEN}) mark_as_advanced(LUA_USE_DLOPEN) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b8ce69f1d..b6bba6e8d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,3 @@ -cmake_minimum_required(VERSION 2.6) - project(minetest) INCLUDE(CheckIncludeFiles) @@ -124,27 +122,6 @@ option(ENABLE_FREETYPE "Enable FreeType2 (TrueType fonts and basic unicode suppo set(USE_FREETYPE FALSE) if(ENABLE_FREETYPE) -## -## Note: FindFreetype.cmake seems to have been fixed in recent versions of -## CMake. If issues persist, re-enable this workaround specificially for the -## failing platforms. -## -# if(UNIX) -# include(FindPkgConfig) -# if(PKG_CONFIG_FOUND) -# pkg_check_modules(FREETYPE QUIET freetype2) -# if(FREETYPE_FOUND) -# SET(FREETYPE_PKGCONFIG_FOUND TRUE) -# SET(FREETYPE_LIBRARY ${FREETYPE_LIBRARIES}) -# # Because CMake is idiotic -# string(REPLACE ";" " " FREETYPE_CFLAGS_STR ${FREETYPE_CFLAGS}) -# string(REPLACE ";" " " FREETYPE_LDFLAGS_STR ${FREETYPE_LDFLAGS}) -# endif(FREETYPE_FOUND) -# endif(PKG_CONFIG_FOUND) -# endif(UNIX) -# if(NOT FREETYPE_FOUND) -# find_package(Freetype) -# endif() find_package(Freetype) if(FREETYPE_FOUND) message(STATUS "Freetype enabled.") diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index c645900aa..c65977b44 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -1165,7 +1165,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) } } - if (!getParent() && std::fabs(m_prop.automatic_rotate) > 0.001) { + if (!getParent() && node && fabs(m_prop.automatic_rotate) > 0.001f) { // This is the child node's rotation. It is only used for automatic_rotate. v3f local_rot = node->getRotation(); local_rot.Y = modulo360f(local_rot.Y - dtime * core::RADTODEG * @@ -1174,7 +1174,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) } if (!getParent() && m_prop.automatic_face_movement_dir && - (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)) { + (fabs(m_velocity.Z) > 0.001f || fabs(m_velocity.X) > 0.001f)) { float target_yaw = atan2(m_velocity.Z, m_velocity.X) * 180 / M_PI + m_prop.automatic_face_movement_dir_offset; float max_rotation_per_sec = diff --git a/src/client/game.cpp b/src/client/game.cpp index 6151d2aa6..9e942f47a 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -186,7 +186,7 @@ struct LocalFormspecHandler : public TextDest return; } - if (m_client && m_client->modsLoaded()) + if (m_client->modsLoaded()) m_client->getScript()->on_formspec_input(m_formname, fields); } @@ -583,7 +583,7 @@ public: virtual IShaderConstantSetter* create() { - GameGlobalShaderConstantSetter *scs = new GameGlobalShaderConstantSetter( + auto *scs = new GameGlobalShaderConstantSetter( m_sky, m_force_fog_off, m_fog_range, m_client); if (!m_sky) created_nosky.push_back(scs); @@ -1338,7 +1338,7 @@ bool Game::createClient(const GameStartData &start_data) return false; } - GameGlobalShaderConstantSetterFactory *scsf = new GameGlobalShaderConstantSetterFactory( + auto *scsf = new GameGlobalShaderConstantSetterFactory( &m_flags.force_fog_off, &runData.fog_range, client); shader_src->addShaderConstantSetterFactory(scsf); @@ -1348,20 +1348,14 @@ bool Game::createClient(const GameStartData &start_data) /* Camera */ camera = new Camera(*draw_control, client); - if (!camera || !camera->successfullyCreated(*error_message)) + if (!camera->successfullyCreated(*error_message)) return false; client->setCamera(camera); /* Clouds */ - if (m_cache_enable_clouds) { + if (m_cache_enable_clouds) clouds = new Clouds(smgr, -1, time(0)); - if (!clouds) { - *error_message = "Memory allocation error (clouds)"; - errorstream << *error_message << std::endl; - return false; - } - } /* Skybox */ @@ -1369,12 +1363,6 @@ bool Game::createClient(const GameStartData &start_data) scsf->setSky(sky); skybox = NULL; // This is used/set later on in the main run loop - if (!sky) { - *error_message = "Memory allocation error sky"; - errorstream << *error_message << std::endl; - return false; - } - /* Pre-calculated values */ video::ITexture *t = texture_src->getTexture("crack_anylength.png"); @@ -1404,12 +1392,6 @@ bool Game::createClient(const GameStartData &start_data) hud = new Hud(guienv, client, player, &player->inventory); - if (!hud) { - *error_message = "Memory error: could not create HUD"; - errorstream << *error_message << std::endl; - return false; - } - mapper = client->getMinimap(); if (mapper && client->modsLoaded()) @@ -1431,11 +1413,6 @@ bool Game::initGui() // Chat backend and console gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(), -1, chat_backend, client, &g_menumgr); - if (!gui_chat_console) { - *error_message = "Could not allocate memory for chat console"; - errorstream << *error_message << std::endl; - return false; - } #ifdef HAVE_TOUCHSCREENGUI @@ -1492,9 +1469,6 @@ bool Game::connectToServer(const GameStartData &start_data, itemdef_manager, nodedef_manager, sound, eventmgr, connect_address.isIPv6(), m_game_ui.get()); - if (!client) - return false; - client->m_simple_singleplayer_mode = simple_singleplayer_mode; infostream << "Connecting to server at "; diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 8d8411ca1..e956c2738 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -1055,9 +1055,9 @@ void drawItemStack( if (def.type == ITEM_TOOL && item.wear != 0) { // Draw a progressbar - float barheight = rect.getHeight() / 16; - float barpad_x = rect.getWidth() / 16; - float barpad_y = rect.getHeight() / 16; + float barheight = static_cast(rect.getHeight()) / 16; + float barpad_x = static_cast(rect.getWidth()) / 16; + float barpad_y = static_cast(rect.getHeight()) / 16; core::rect progressrect( rect.UpperLeftCorner.X + barpad_x, diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index dac25a066..4c43fcb61 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -1201,13 +1201,13 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset): MapBlockMesh::~MapBlockMesh() { for (scene::IMesh *m : m_mesh) { - if (m_enable_vbo && m) + if (m_enable_vbo) { for (u32 i = 0; i < m->getMeshBufferCount(); i++) { scene::IMeshBuffer *buf = m->getMeshBuffer(i); RenderingEngine::get_video_driver()->removeHardwareBuffer(buf); } + } m->drop(); - m = NULL; } delete m_minimap_mapblock; } diff --git a/src/client/tile.cpp b/src/client/tile.cpp index d03588b2b..37836d0df 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -1633,6 +1633,13 @@ bool TextureSource::generateImagePart(std::string part_of_name, /* IMPORTANT: When changing this, getTextureForMesh() needs to be * updated too. */ + if (!baseimg) { + errorstream << "generateImagePart(): baseimg == NULL " + << "for part_of_name=\"" << part_of_name + << "\", cancelling." << std::endl; + return false; + } + // Apply the "clean transparent" filter, if configured. if (g_settings->getBool("texture_clean_transparent")) imageCleanTransparent(baseimg, 127); diff --git a/src/filesys.cpp b/src/filesys.cpp index 2470b1b64..28a33f4d0 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -295,31 +295,26 @@ bool RecursiveDelete(const std::string &path) infostream<<"Removing \""<(argv)); // Execv shouldn't return. Failed. _exit(1); @@ -331,7 +326,6 @@ bool RecursiveDelete(const std::string &path) pid_t tpid; do{ tpid = wait(&child_status); - //if(tpid != child_pid) process_terminated(tpid); }while(tpid != child_pid); return (child_status == 0); } diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index 0d64aa618..e1a971462 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -881,8 +881,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) s32 dyj = event.TouchInput.Y - m_screensize.Y + button_size * 5.0f / 2.0f; bool inside_joystick = (dxj * dxj + dyj * dyj <= button_size * button_size * 1.5 * 1.5); - if (m_joystick_has_really_moved || - (!m_joystick_has_really_moved && inside_joystick) || + if (m_joystick_has_really_moved || inside_joystick || (!m_fixed_joystick && distance_sq > m_touchscreen_threshold * m_touchscreen_threshold)) { m_joystick_has_really_moved = true; diff --git a/src/irrlicht_changes/CGUITTFont.h b/src/irrlicht_changes/CGUITTFont.h index cf64934a2..310f74f67 100644 --- a/src/irrlicht_changes/CGUITTFont.h +++ b/src/irrlicht_changes/CGUITTFont.h @@ -356,7 +356,7 @@ namespace gui load_flags = FT_LOAD_DEFAULT | FT_LOAD_RENDER; if (!useHinting()) load_flags |= FT_LOAD_NO_HINTING; if (!useAutoHinting()) load_flags |= FT_LOAD_NO_AUTOHINT; - if (useMonochrome()) load_flags |= FT_LOAD_MONOCHROME | FT_LOAD_TARGET_MONO | FT_RENDER_MODE_MONO; + if (useMonochrome()) load_flags |= FT_LOAD_MONOCHROME | FT_LOAD_TARGET_MONO; else load_flags |= FT_LOAD_TARGET_NORMAL; } u32 getWidthFromCharacter(wchar_t c) const; diff --git a/src/irrlicht_changes/irrUString.h b/src/irrlicht_changes/irrUString.h index b628c092c..09172ee6d 100644 --- a/src/irrlicht_changes/irrUString.h +++ b/src/irrlicht_changes/irrUString.h @@ -1331,7 +1331,7 @@ public: { u32 i; const uchar16_t* oa = other.c_str(); - for(i=0; array[i] && oa[i] && i < n; ++i) + for(i=0; i < n && array[i] && oa[i]; ++i) if (array[i] != oa[i]) return false; @@ -1350,7 +1350,7 @@ public: if (!str) return false; u32 i; - for(i=0; array[i] && str[i] && i < n; ++i) + for(i=0; i < n && array[i] && str[i]; ++i) if (array[i] != str[i]) return false; diff --git a/src/mapgen/mapgen_v7.cpp b/src/mapgen/mapgen_v7.cpp index cc5f5726d..91f004518 100644 --- a/src/mapgen/mapgen_v7.cpp +++ b/src/mapgen/mapgen_v7.cpp @@ -297,7 +297,7 @@ int MapgenV7::getSpawnLevelAtPoint(v2s16 p) int iters = 256; while (iters > 0 && y <= max_spawn_y) { if (!getMountainTerrainAtPoint(p.X, y + 1, p.Y)) { - if (y <= water_level || y > max_spawn_y) + if (y <= water_level) return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point // y + 1 due to biome 'dust' diff --git a/src/mapgen/treegen.cpp b/src/mapgen/treegen.cpp index e633d800a..ec7771439 100644 --- a/src/mapgen/treegen.cpp +++ b/src/mapgen/treegen.cpp @@ -406,7 +406,8 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, v3f(position.X, position.Y, position.Z - 1), tree_definition ); - } if (!stack_orientation.empty()) { + } + if (!stack_orientation.empty()) { s16 size = 1; for (x = -size; x <= size; x++) for (y = -size; y <= size; y++) diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 3db4eb286..c636d01e1 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -316,7 +316,7 @@ void Server::handleCommand_Init2(NetworkPacket* pkt) // Send active objects { PlayerSAO *sao = getPlayerSAO(peer_id); - if (client && sao) + if (sao) SendActiveObjectRemoveAdd(client, sao); } diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 80013192d..f9d15a9f6 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -617,7 +617,7 @@ static void fillTileAttribs(ITextureSource *tsrc, TileLayer *layer, bool has_scale = tiledef.scale > 0; bool use_autoscale = tsettings.autoscale_mode == AUTOSCALE_FORCE || (tsettings.autoscale_mode == AUTOSCALE_ENABLE && !has_scale); - if (use_autoscale && layer->texture) { + if (use_autoscale) { auto texture_size = layer->texture->getOriginalSize(); float base_size = tsettings.node_texture_size; float size = std::fmin(texture_size.Width, texture_size.Height); diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp index 01333b941..63058d7c3 100644 --- a/src/script/cpp_api/s_security.cpp +++ b/src/script/cpp_api/s_security.cpp @@ -398,10 +398,9 @@ bool ScriptApiSecurity::safeLoadFile(lua_State *L, const char *path, const char lua_pushfstring(L, "%s: %s", path, strerror(errno)); return false; } - chunk_name = new char[strlen(display_name) + 2]; - chunk_name[0] = '@'; - chunk_name[1] = '\0'; - strcat(chunk_name, display_name); + size_t len = strlen(display_name) + 2; + chunk_name = new char[len]; + snprintf(chunk_name, len, "@%s", display_name); } size_t start = 0; diff --git a/src/util/srp.cpp b/src/util/srp.cpp index f4d369d68..ceb2fef9e 100644 --- a/src/util/srp.cpp +++ b/src/util/srp.cpp @@ -1015,10 +1015,10 @@ void srp_user_process_challenge(struct SRPUser *usr, goto cleanup_and_exit; *bytes_M = usr->M; - if (len_M) *len_M = hash_length(usr->hash_alg); + *len_M = hash_length(usr->hash_alg); } else { *bytes_M = NULL; - if (len_M) *len_M = 0; + *len_M = 0; } cleanup_and_exit: diff --git a/src/util/string.cpp b/src/util/string.cpp index 8381a29c5..3ac3b8cf0 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -633,7 +633,7 @@ static bool parseNamedColorString(const std::string &value, video::SColor &color color_name = value; } - color_name = lowercase(value); + color_name = lowercase(color_name); std::map::const_iterator it; it = named_colors.colors.find(color_name); -- cgit v1.2.3 From 09d7fbd645888aac32d089ff528ac1d1eb87e72d Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Thu, 24 Dec 2020 14:26:42 +0100 Subject: Fix item tooltip background color not working --- src/gui/guiFormSpecMenu.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index ed197d0d1..61112b570 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -3718,7 +3718,8 @@ void GUIFormSpecMenu::showTooltip(const std::wstring &text, { EnrichedString ntext(text); ntext.setDefaultColor(color); - ntext.setBackground(bgcolor); + if (!ntext.hasBackground()) + ntext.setBackground(bgcolor); setStaticText(m_tooltip_element, ntext); -- cgit v1.2.3 From ff921f6989cc6e8e0be6bf9ac196e90331bb3eb4 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Fri, 1 Jan 2021 17:03:34 +0100 Subject: Formspecs: Fix broken texture escaping with model[] --- src/gui/guiFormSpecMenu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 61112b570..973fc60a8 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -2787,7 +2787,7 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element) auto meshnode = e->setMesh(mesh); for (u32 i = 0; i < textures.size() && i < meshnode->getMaterialCount(); ++i) - e->setTexture(i, m_tsrc->getTexture(textures[i])); + e->setTexture(i, m_tsrc->getTexture(unescape_string(textures[i]))); if (vec_rot.size() >= 2) e->setRotation(v2f(stof(vec_rot[0]), stof(vec_rot[1]))); -- cgit v1.2.3 From 58a709096ef8ff17644cf201f25b1831d9506514 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Mon, 4 Jan 2021 20:19:20 +0100 Subject: refacto: factorize multiple code parts from guiEditbox childs (#10782) --- src/gui/CMakeLists.txt | 1 + src/gui/guiEditBox.cpp | 95 ++++++++++++++++ src/gui/guiEditBox.h | 103 +++++++++++++++++ src/gui/guiEditBoxWithScrollbar.cpp | 113 +------------------ src/gui/guiEditBoxWithScrollbar.h | 66 +---------- src/gui/intlGUIEditBox.cpp | 216 +++++++++--------------------------- src/gui/intlGUIEditBox.h | 63 +---------- 7 files changed, 266 insertions(+), 391 deletions(-) create mode 100644 src/gui/guiEditBox.cpp create mode 100644 src/gui/guiEditBox.h (limited to 'src/gui') diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 5305e7ad3..fdd36914a 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -7,6 +7,7 @@ set(gui_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/guiButtonItemImage.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiChatConsole.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiConfirmRegistration.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/guiEditBox.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiEditBoxWithScrollbar.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiEngine.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiFormSpecMenu.cpp diff --git a/src/gui/guiEditBox.cpp b/src/gui/guiEditBox.cpp new file mode 100644 index 000000000..159bd38ac --- /dev/null +++ b/src/gui/guiEditBox.cpp @@ -0,0 +1,95 @@ +/* +Minetest +Copyright (C) 2021 Minetest + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "guiEditBox.h" + +#include "IGUISkin.h" +#include "IGUIEnvironment.h" +#include "IGUIFont.h" + +GUIEditBox::~GUIEditBox() +{ + if (m_override_font) + m_override_font->drop(); +} + +void GUIEditBox::setOverrideFont(IGUIFont *font) +{ + if (m_override_font == font) + return; + + if (m_override_font) + m_override_font->drop(); + + m_override_font = font; + + if (m_override_font) + m_override_font->grab(); + + breakText(); +} + +//! Get the font which is used right now for drawing +IGUIFont *GUIEditBox::getActiveFont() const +{ + if (m_override_font) + return m_override_font; + IGUISkin *skin = Environment->getSkin(); + if (skin) + return skin->getFont(); + return 0; +} + +//! Sets another color for the text. +void GUIEditBox::setOverrideColor(video::SColor color) +{ + m_override_color = color; + m_override_color_enabled = true; +} + +video::SColor GUIEditBox::getOverrideColor() const +{ + return m_override_color; +} + +//! Sets if the text should use the overide color or the color in the gui skin. +void GUIEditBox::enableOverrideColor(bool enable) +{ + m_override_color_enabled = enable; +} + +//! Enables or disables word wrap +void GUIEditBox::setWordWrap(bool enable) +{ + m_word_wrap = enable; + breakText(); +} + +//! Enables or disables newlines. +void GUIEditBox::setMultiLine(bool enable) +{ + m_multiline = enable; +} + +//! Enables or disables automatic scrolling with cursor position +//! \param enable: If set to true, the text will move around with the cursor position +void GUIEditBox::setAutoScroll(bool enable) +{ + m_autoscroll = enable; +} diff --git a/src/gui/guiEditBox.h b/src/gui/guiEditBox.h new file mode 100644 index 000000000..c673f2f5f --- /dev/null +++ b/src/gui/guiEditBox.h @@ -0,0 +1,103 @@ +/* +Minetest +Copyright (C) 2021 Minetest + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include "IGUIEditBox.h" +#include "IOSOperator.h" +#include "guiScrollBar.h" + +using namespace irr; +using namespace irr::gui; + +class GUIEditBox : public IGUIEditBox +{ +public: + GUIEditBox(IGUIEnvironment *environment, IGUIElement *parent, s32 id, + core::rect rectangle) : + IGUIEditBox(environment, parent, id, rectangle) + { + } + + virtual ~GUIEditBox(); + + //! Sets another skin independent font. + virtual void setOverrideFont(IGUIFont *font = 0); + + virtual IGUIFont *getOverrideFont() const { return m_override_font; } + + //! Get the font which is used right now for drawing + /** Currently this is the override font when one is set and the + font of the active skin otherwise */ + virtual IGUIFont *getActiveFont() const; + + //! Sets another color for the text. + virtual void setOverrideColor(video::SColor color); + + //! Gets the override color + virtual video::SColor getOverrideColor() const; + + //! Sets if the text should use the overide color or the + //! color in the gui skin. + virtual void enableOverrideColor(bool enable); + + //! Checks if an override color is enabled + /** \return true if the override color is enabled, false otherwise */ + virtual bool isOverrideColorEnabled(void) const + { + return m_override_color_enabled; + } + + //! Enables or disables word wrap for using the edit box as multiline text editor. + virtual void setWordWrap(bool enable); + + //! Checks if word wrap is enabled + //! \return true if word wrap is enabled, false otherwise + virtual bool isWordWrapEnabled() const { return m_word_wrap; } + + //! Enables or disables newlines. + /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired, + instead a newline character will be inserted. */ + virtual void setMultiLine(bool enable); + + //! Checks if multi line editing is enabled + //! \return true if mult-line is enabled, false otherwise + virtual bool isMultiLineEnabled() const { return m_multiline; } + + //! Enables or disables automatic scrolling with cursor position + //! \param enable: If set to true, the text will move around with the cursor + //! position + virtual void setAutoScroll(bool enable); + + //! Checks to see if automatic scrolling is enabled + //! \return true if automatic scrolling is enabled, false if not + virtual bool isAutoScrollEnabled() const { return m_autoscroll; } + +protected: + virtual void breakText() = 0; + + gui::IGUIFont *m_override_font = nullptr; + + bool m_override_color_enabled = false; + bool m_word_wrap = false; + bool m_multiline = false; + bool m_autoscroll = true; + + video::SColor m_override_color = video::SColor(101, 255, 255, 255); +}; \ No newline at end of file diff --git a/src/gui/guiEditBoxWithScrollbar.cpp b/src/gui/guiEditBoxWithScrollbar.cpp index 169425a9a..7f9fdafd7 100644 --- a/src/gui/guiEditBoxWithScrollbar.cpp +++ b/src/gui/guiEditBoxWithScrollbar.cpp @@ -22,16 +22,14 @@ optional? dragging selected text numerical */ - //! constructor GUIEditBoxWithScrollBar::GUIEditBoxWithScrollBar(const wchar_t* text, bool border, IGUIEnvironment* environment, IGUIElement* parent, s32 id, const core::rect& rectangle, bool writable, bool has_vscrollbar) - : IGUIEditBox(environment, parent, id, rectangle), m_mouse_marking(false), - m_border(border), m_background(true), m_override_color_enabled(false), m_mark_begin(0), m_mark_end(0), - m_override_color(video::SColor(101, 255, 255, 255)), m_override_font(0), m_last_break_font(0), + : GUIEditBox(environment, parent, id, rectangle), m_mouse_marking(false), + m_border(border), m_background(true), m_mark_begin(0), m_mark_end(0), m_last_break_font(0), m_operator(0), m_blink_start_time(0), m_cursor_pos(0), m_hscroll_pos(0), m_vscroll_pos(0), m_max(0), - m_word_wrap(false), m_multiline(false), m_autoscroll(true), m_passwordbox(false), + m_passwordbox(false), m_passwordchar(L'*'), m_halign(EGUIA_UPPERLEFT), m_valign(EGUIA_CENTER), m_current_text_rect(0, 0, 1, 1), m_frame_rect(rectangle), m_scrollbar_width(0), m_vscrollbar(NULL), m_writable(writable), @@ -69,9 +67,6 @@ GUIEditBoxWithScrollBar::GUIEditBoxWithScrollBar(const wchar_t* text, bool borde //! destructor GUIEditBoxWithScrollBar::~GUIEditBoxWithScrollBar() { - if (m_override_font) - m_override_font->drop(); - if (m_operator) m_operator->drop(); @@ -80,54 +75,6 @@ GUIEditBoxWithScrollBar::~GUIEditBoxWithScrollBar() } -//! Sets another skin independent font. -void GUIEditBoxWithScrollBar::setOverrideFont(IGUIFont* font) -{ - if (m_override_font == font) - return; - - if (m_override_font) - m_override_font->drop(); - - m_override_font = font; - - if (m_override_font) - m_override_font->grab(); - - breakText(); -} - -//! Gets the override font (if any) -IGUIFont * GUIEditBoxWithScrollBar::getOverrideFont() const -{ - return m_override_font; -} - -//! Get the font which is used right now for drawing -IGUIFont* GUIEditBoxWithScrollBar::getActiveFont() const -{ - if (m_override_font) - return m_override_font; - IGUISkin* skin = Environment->getSkin(); - if (skin) - return skin->getFont(); - return 0; -} - -//! Sets another color for the text. -void GUIEditBoxWithScrollBar::setOverrideColor(video::SColor color) -{ - m_override_color = color; - m_override_color_enabled = true; -} - - -video::SColor GUIEditBoxWithScrollBar::getOverrideColor() const -{ - return m_override_color; -} - - //! Turns the border on or off void GUIEditBoxWithScrollBar::setDrawBorder(bool border) { @@ -140,24 +87,6 @@ void GUIEditBoxWithScrollBar::setDrawBackground(bool draw) m_background = draw; } -//! Sets if the text should use the overide color or the color in the gui skin. -void GUIEditBoxWithScrollBar::enableOverrideColor(bool enable) -{ - m_override_color_enabled = enable; -} - -bool GUIEditBoxWithScrollBar::isOverrideColorEnabled() const -{ - return m_override_color_enabled; -} - -//! Enables or disables word wrap -void GUIEditBoxWithScrollBar::setWordWrap(bool enable) -{ - m_word_wrap = enable; - breakText(); -} - void GUIEditBoxWithScrollBar::updateAbsolutePosition() { @@ -170,26 +99,6 @@ void GUIEditBoxWithScrollBar::updateAbsolutePosition() } } -//! Checks if word wrap is enabled -bool GUIEditBoxWithScrollBar::isWordWrapEnabled() const -{ - return m_word_wrap; -} - - -//! Enables or disables newlines. -void GUIEditBoxWithScrollBar::setMultiLine(bool enable) -{ - m_multiline = enable; -} - - -//! Checks if multi line editing is enabled -bool GUIEditBoxWithScrollBar::isMultiLineEnabled() const -{ - return m_multiline; -} - void GUIEditBoxWithScrollBar::setPasswordBox(bool password_box, wchar_t password_char) { @@ -850,22 +759,6 @@ void GUIEditBoxWithScrollBar::setText(const wchar_t* text) } -//! Enables or disables automatic scrolling with cursor position -//! \param enable: If set to true, the text will move around with the cursor position -void GUIEditBoxWithScrollBar::setAutoScroll(bool enable) -{ - m_autoscroll = enable; -} - - -//! Checks to see if automatic scrolling is enabled -//! \return true if automatic scrolling is enabled, false if not -bool GUIEditBoxWithScrollBar::isAutoScrollEnabled() const -{ - return m_autoscroll; -} - - //! Gets the area of the text in the edit box //! \return Returns the size in pixels of the text core::dimension2du GUIEditBoxWithScrollBar::getTextDimension() diff --git a/src/gui/guiEditBoxWithScrollbar.h b/src/gui/guiEditBoxWithScrollbar.h index 77538e2f7..5ae58b934 100644 --- a/src/gui/guiEditBoxWithScrollbar.h +++ b/src/gui/guiEditBoxWithScrollbar.h @@ -5,15 +5,10 @@ #ifndef GUIEDITBOXWITHSCROLLBAR_HEADER #define GUIEDITBOXWITHSCROLLBAR_HEADER -#include "IGUIEditBox.h" -#include "IOSOperator.h" -#include "guiScrollBar.h" +#include "guiEditBox.h" #include -using namespace irr; -using namespace irr::gui; - -class GUIEditBoxWithScrollBar : public IGUIEditBox +class GUIEditBoxWithScrollBar : public GUIEditBox { public: @@ -25,61 +20,13 @@ public: //! destructor virtual ~GUIEditBoxWithScrollBar(); - //! Sets another skin independent font. - virtual void setOverrideFont(IGUIFont* font = 0); - - //! Gets the override font (if any) - /** \return The override font (may be 0) */ - virtual IGUIFont* getOverrideFont() const; - - //! Get the font which is used right now for drawing - /** Currently this is the override font when one is set and the - font of the active skin otherwise */ - virtual IGUIFont* getActiveFont() const; - - //! Sets another color for the text. - virtual void setOverrideColor(video::SColor color); - - //! Gets the override color - virtual video::SColor getOverrideColor() const; - - //! Sets if the text should use the overide color or the - //! color in the gui skin. - virtual void enableOverrideColor(bool enable); - - //! Checks if an override color is enabled - /** \return true if the override color is enabled, false otherwise */ - virtual bool isOverrideColorEnabled(void) const; - //! Sets whether to draw the background virtual void setDrawBackground(bool draw); //! Turns the border on or off virtual void setDrawBorder(bool border); - //! Enables or disables word wrap for using the edit box as multiline text editor. - virtual void setWordWrap(bool enable); - - //! Checks if word wrap is enabled - //! \return true if word wrap is enabled, false otherwise - virtual bool isWordWrapEnabled() const; - - //! Enables or disables newlines. - /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired, - instead a newline character will be inserted. */ - virtual void setMultiLine(bool enable); - //! Checks if multi line editing is enabled - //! \return true if mult-line is enabled, false otherwise - virtual bool isMultiLineEnabled() const; - - //! Enables or disables automatic scrolling with cursor position - //! \param enable: If set to true, the text will move around with the cursor position - virtual void setAutoScroll(bool enable); - - //! Checks to see if automatic scrolling is enabled - //! \return true if automatic scrolling is enabled, false if not - virtual bool isAutoScrollEnabled() const; //! Gets the size area of the text in the edit box //! \return Returns the size in pixels of the text @@ -137,7 +84,7 @@ public: protected: //! Breaks the single text line. - void breakText(); + virtual void breakText(); //! sets the area of the given line void setTextRect(s32 line); //! returns the line number that the cursor is on @@ -164,12 +111,11 @@ protected: bool m_mouse_marking; bool m_border; bool m_background; - bool m_override_color_enabled; + s32 m_mark_begin; s32 m_mark_end; - video::SColor m_override_color; - gui::IGUIFont *m_override_font, *m_last_break_font; + gui::IGUIFont *m_last_break_font; IOSOperator* m_operator; u32 m_blink_start_time; @@ -177,7 +123,7 @@ protected: s32 m_hscroll_pos, m_vscroll_pos; // scroll position in characters u32 m_max; - bool m_word_wrap, m_multiline, m_autoscroll, m_passwordbox; + bool m_passwordbox; wchar_t m_passwordchar; EGUI_ALIGNMENT m_halign, m_valign; diff --git a/src/gui/intlGUIEditBox.cpp b/src/gui/intlGUIEditBox.cpp index 8be63fd6f..e917f73c1 100644 --- a/src/gui/intlGUIEditBox.cpp +++ b/src/gui/intlGUIEditBox.cpp @@ -59,7 +59,7 @@ namespace gui intlGUIEditBox::intlGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment, IGUIElement* parent, s32 id, const core::rect& rectangle, bool writable, bool has_vscrollbar) - : IGUIEditBox(environment, parent, id, rectangle), + : GUIEditBox(environment, parent, id, rectangle), Border(border), FrameRect(rectangle), m_scrollbar_width(0), m_vscrollbar(NULL), m_writable(writable) { @@ -108,9 +108,6 @@ intlGUIEditBox::intlGUIEditBox(const wchar_t* text, bool border, //! destructor intlGUIEditBox::~intlGUIEditBox() { - if (OverrideFont) - OverrideFont->drop(); - if (Operator) Operator->drop(); @@ -118,52 +115,6 @@ intlGUIEditBox::~intlGUIEditBox() m_vscrollbar->drop(); } - -//! Sets another skin independent font. -void intlGUIEditBox::setOverrideFont(IGUIFont* font) -{ - if (OverrideFont == font) - return; - - if (OverrideFont) - OverrideFont->drop(); - - OverrideFont = font; - - if (OverrideFont) - OverrideFont->grab(); - - breakText(); -} - -IGUIFont * intlGUIEditBox::getOverrideFont() const -{ - return OverrideFont; -} - -//! Get the font which is used right now for drawing -IGUIFont* intlGUIEditBox::getActiveFont() const -{ - if ( OverrideFont ) - return OverrideFont; - IGUISkin* skin = Environment->getSkin(); - if (skin) - return skin->getFont(); - return 0; -} - -//! Sets another color for the text. -void intlGUIEditBox::setOverrideColor(video::SColor color) -{ - OverrideColor = color; - OverrideColorEnabled = true; -} - -video::SColor intlGUIEditBox::getOverrideColor() const -{ - return OverrideColor; -} - //! Turns the border on or off void intlGUIEditBox::setDrawBorder(bool border) { @@ -175,25 +126,6 @@ void intlGUIEditBox::setDrawBackground(bool draw) { } -//! Sets if the text should use the overide color or the color in the gui skin. -void intlGUIEditBox::enableOverrideColor(bool enable) -{ - OverrideColorEnabled = enable; -} - -bool intlGUIEditBox::isOverrideColorEnabled() const -{ - return OverrideColorEnabled; -} - -//! Enables or disables word wrap -void intlGUIEditBox::setWordWrap(bool enable) -{ - WordWrap = enable; - breakText(); -} - - void intlGUIEditBox::updateAbsolutePosition() { core::rect oldAbsoluteRect(AbsoluteRect); @@ -204,28 +136,6 @@ void intlGUIEditBox::updateAbsolutePosition() } } - -//! Checks if word wrap is enabled -bool intlGUIEditBox::isWordWrapEnabled() const -{ - return WordWrap; -} - - -//! Enables or disables newlines. -void intlGUIEditBox::setMultiLine(bool enable) -{ - MultiLine = enable; -} - - -//! Checks if multi line editing is enabled -bool intlGUIEditBox::isMultiLineEnabled() const -{ - return MultiLine; -} - - void intlGUIEditBox::setPasswordBox(bool passwordBox, wchar_t passwordChar) { PasswordBox = passwordBox; @@ -464,7 +374,7 @@ bool intlGUIEditBox::processKey(const SEvent& event) case KEY_END: { s32 p = Text.size(); - if (WordWrap || MultiLine) + if (m_word_wrap || m_multiline) { p = getLineFromPos(CursorPos); p = BrokenTextPositions[p] + (s32)BrokenText[p].size(); @@ -492,7 +402,7 @@ bool intlGUIEditBox::processKey(const SEvent& event) { s32 p = 0; - if (WordWrap || MultiLine) + if (m_word_wrap || m_multiline) { p = getLineFromPos(CursorPos); p = BrokenTextPositions[p]; @@ -514,7 +424,7 @@ bool intlGUIEditBox::processKey(const SEvent& event) } break; case KEY_RETURN: - if (MultiLine) + if (m_multiline) { inputChar(L'\n'); return true; @@ -567,7 +477,7 @@ bool intlGUIEditBox::processKey(const SEvent& event) BlinkStartTime = porting::getTimeMs(); break; case KEY_UP: - if (MultiLine || (WordWrap && BrokenText.size() > 1) ) + if (m_multiline || (m_word_wrap && BrokenText.size() > 1) ) { s32 lineNo = getLineFromPos(CursorPos); s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin > MarkEnd ? MarkBegin : MarkEnd); @@ -598,7 +508,7 @@ bool intlGUIEditBox::processKey(const SEvent& event) } break; case KEY_DOWN: - if (MultiLine || (WordWrap && BrokenText.size() > 1) ) + if (m_multiline || (m_word_wrap && BrokenText.size() > 1) ) { s32 lineNo = getLineFromPos(CursorPos); s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin < MarkEnd ? MarkBegin : MarkEnd); @@ -791,8 +701,8 @@ void intlGUIEditBox::draw() // draw the text - IGUIFont* font = OverrideFont; - if (!OverrideFont) + IGUIFont* font = m_override_font; + if (!m_override_font) font = skin->getFont(); s32 cursorLine = 0; @@ -813,7 +723,7 @@ void intlGUIEditBox::draw() core::stringw s, s2; // get mark position - const bool ml = (!PasswordBox && (WordWrap || MultiLine)); + const bool ml = (!PasswordBox && (m_word_wrap || m_multiline)); const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; const s32 hlineStart = ml ? getLineFromPos(realmbgn) : 0; @@ -822,14 +732,14 @@ void intlGUIEditBox::draw() // Save the override color information. // Then, alter it if the edit box is disabled. - const bool prevOver = OverrideColorEnabled; - const video::SColor prevColor = OverrideColor; + const bool prevOver = m_override_color_enabled; + const video::SColor prevColor = m_override_color; if (!Text.empty()) { - if (!IsEnabled && !OverrideColorEnabled) + if (!IsEnabled && !m_override_color_enabled) { - OverrideColorEnabled = true; - OverrideColor = skin->getColor(EGDC_GRAY_TEXT); + m_override_color_enabled = true; + m_override_color = skin->getColor(EGDC_GRAY_TEXT); } for (s32 i=0; i < lineCount; ++i) @@ -870,7 +780,7 @@ void intlGUIEditBox::draw() // draw normal text font->draw(txtLine->c_str(), CurrentTextRect, - OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT), + m_override_color_enabled ? m_override_color : skin->getColor(EGDC_BUTTON_TEXT), false, true, &localClipRect); // draw mark and marked text @@ -914,20 +824,20 @@ void intlGUIEditBox::draw() if (!s.empty()) font->draw(s.c_str(), CurrentTextRect, - OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT), + m_override_color_enabled ? m_override_color : skin->getColor(EGDC_HIGH_LIGHT_TEXT), false, true, &localClipRect); } } // Return the override color information to its previous settings. - OverrideColorEnabled = prevOver; - OverrideColor = prevColor; + m_override_color_enabled = prevOver; + m_override_color = prevColor; } // draw cursor - if (WordWrap || MultiLine) + if (m_word_wrap || m_multiline) { cursorLine = getLineFromPos(CursorPos); txtLine = &BrokenText[cursorLine]; @@ -943,7 +853,7 @@ void intlGUIEditBox::draw() CurrentTextRect.UpperLeftCorner.X += charcursorpos; font->draw(L"_", CurrentTextRect, - OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT), + m_override_color_enabled ? m_override_color : skin->getColor(EGDC_BUTTON_TEXT), false, true, &localClipRect); } } @@ -965,22 +875,6 @@ void intlGUIEditBox::setText(const wchar_t* text) } -//! Enables or disables automatic scrolling with cursor position -//! \param enable: If set to true, the text will move around with the cursor position -void intlGUIEditBox::setAutoScroll(bool enable) -{ - AutoScroll = enable; -} - - -//! Checks to see if automatic scrolling is enabled -//! \return true if automatic scrolling is enabled, false if not -bool intlGUIEditBox::isAutoScrollEnabled() const -{ - return AutoScroll; -} - - //! Gets the area of the text in the edit box //! \return Returns the size in pixels of the text core::dimension2du intlGUIEditBox::getTextDimension() @@ -1096,12 +990,12 @@ bool intlGUIEditBox::processMouse(const SEvent& event) s32 intlGUIEditBox::getCursorPos(s32 x, s32 y) { - IGUIFont* font = OverrideFont; + IGUIFont* font = m_override_font; IGUISkin* skin = Environment->getSkin(); - if (!OverrideFont) + if (!m_override_font) font = skin->getFont(); - const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1; + const u32 lineCount = (m_word_wrap || m_multiline) ? BrokenText.size() : 1; core::stringw *txtLine = NULL; s32 startPos = 0; @@ -1118,8 +1012,8 @@ s32 intlGUIEditBox::getCursorPos(s32 x, s32 y) // is it inside this region? if (y >= CurrentTextRect.UpperLeftCorner.Y && y <= CurrentTextRect.LowerRightCorner.Y) { // we've found the clicked line - txtLine = (WordWrap || MultiLine) ? &BrokenText[curr_line_idx] : &Text; - startPos = (WordWrap || MultiLine) ? BrokenTextPositions[curr_line_idx] : 0; + txtLine = (m_word_wrap || m_multiline) ? &BrokenText[curr_line_idx] : &Text; + startPos = (m_word_wrap || m_multiline) ? BrokenTextPositions[curr_line_idx] : 0; break; } } @@ -1144,14 +1038,14 @@ void intlGUIEditBox::breakText() { IGUISkin* skin = Environment->getSkin(); - if ((!WordWrap && !MultiLine) || !skin) + if ((!m_word_wrap && !m_multiline) || !skin) return; BrokenText.clear(); // need to reallocate :/ BrokenTextPositions.set_used(0); - IGUIFont* font = OverrideFont; - if (!OverrideFont) + IGUIFont* font = m_override_font; + if (!m_override_font) font = skin->getFont(); if (!font) @@ -1190,7 +1084,7 @@ void intlGUIEditBox::breakText() } // don't break if we're not a multi-line edit box - if (!MultiLine) + if (!m_multiline) lineBreak = false; if (c == L' ' || c == 0 || i == (size-1)) @@ -1201,7 +1095,7 @@ void intlGUIEditBox::breakText() s32 whitelgth = font->getDimension(whitespace.c_str()).Width; s32 worldlgth = font->getDimension(word.c_str()).Width; - if (WordWrap && length + worldlgth + whitelgth > elWidth) + if (m_word_wrap && length + worldlgth + whitelgth > elWidth) { // break to next line length = worldlgth; @@ -1260,14 +1154,14 @@ void intlGUIEditBox::setTextRect(s32 line) if (!skin) return; - IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont(); + IGUIFont* font = m_override_font ? m_override_font : skin->getFont(); if (!font) return; // get text dimension - const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1; - if (WordWrap || MultiLine) + const u32 lineCount = (m_word_wrap || m_multiline) ? BrokenText.size() : 1; + if (m_word_wrap || m_multiline) { d = font->getDimension(BrokenText[line].c_str()); } @@ -1328,7 +1222,7 @@ void intlGUIEditBox::setTextRect(s32 line) s32 intlGUIEditBox::getLineFromPos(s32 pos) { - if (!WordWrap && !MultiLine) + if (!m_word_wrap && !m_multiline) return 0; s32 i=0; @@ -1387,7 +1281,7 @@ void intlGUIEditBox::inputChar(wchar_t c) void intlGUIEditBox::calculateScrollPos() { - if (!AutoScroll) + if (!m_autoscroll) return; // calculate horizontal scroll position @@ -1395,18 +1289,18 @@ void intlGUIEditBox::calculateScrollPos() setTextRect(cursLine); // don't do horizontal scrolling when wordwrap is enabled. - if (!WordWrap) + if (!m_word_wrap) { // get cursor position IGUISkin* skin = Environment->getSkin(); if (!skin) return; - IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont(); + IGUIFont* font = m_override_font ? m_override_font : skin->getFont(); if (!font) return; - core::stringw *txtLine = MultiLine ? &BrokenText[cursLine] : &Text; - s32 cPos = MultiLine ? CursorPos - BrokenTextPositions[cursLine] : CursorPos; + core::stringw *txtLine = m_multiline ? &BrokenText[cursLine] : &Text; + s32 cPos = m_multiline ? CursorPos - BrokenTextPositions[cursLine] : CursorPos; s32 cStart = CurrentTextRect.UpperLeftCorner.X + HScrollPos + font->getDimension(txtLine->subString(0, cPos).c_str()).Width; @@ -1423,7 +1317,7 @@ void intlGUIEditBox::calculateScrollPos() // todo: adjust scrollbar } - if (!WordWrap && !MultiLine) + if (!m_word_wrap && !m_multiline) return; // vertical scroll position @@ -1468,8 +1362,8 @@ void intlGUIEditBox::createVScrollBar() { s32 fontHeight = 1; - if (OverrideFont) { - fontHeight = OverrideFont->getDimension(L"").Height; + if (m_override_font) { + fontHeight = m_override_font->getDimension(L"").Height; } else { if (IGUISkin* skin = Environment->getSkin()) { if (IGUIFont* font = skin->getFont()) { @@ -1520,7 +1414,7 @@ void intlGUIEditBox::updateVScrollBar() m_vscrollbar->setPageSize(s32(getTextDimension().Height)); } - if (!m_vscrollbar->isVisible() && MultiLine) { + if (!m_vscrollbar->isVisible() && m_multiline) { AbsoluteRect.LowerRightCorner.X -= m_scrollbar_width; m_vscrollbar->setVisible(true); @@ -1548,20 +1442,20 @@ void intlGUIEditBox::serializeAttributes(io::IAttributes* out, io::SAttributeRea { // IGUIEditBox::serializeAttributes(out,options); - out->addBool ("OverrideColorEnabled",OverrideColorEnabled ); - out->addColor ("OverrideColor", OverrideColor); - // out->addFont("OverrideFont",OverrideFont); - out->addInt ("MaxChars", Max); - out->addBool ("WordWrap", WordWrap); - out->addBool ("MultiLine", MultiLine); - out->addBool ("AutoScroll", AutoScroll); - out->addBool ("PasswordBox", PasswordBox); + out->addBool ("OverrideColorEnabled", m_override_color_enabled ); + out->addColor ("OverrideColor", m_override_color); + // out->addFont("OverrideFont",m_override_font); + out->addInt ("MaxChars", Max); + out->addBool ("WordWrap", m_word_wrap); + out->addBool ("MultiLine", m_multiline); + out->addBool ("AutoScroll", m_autoscroll); + out->addBool ("PasswordBox", PasswordBox); core::stringw ch = L" "; ch[0] = PasswordChar; - out->addString("PasswordChar", ch.c_str()); - out->addEnum ("HTextAlign", HAlign, GUIAlignmentNames); - out->addEnum ("VTextAlign", VAlign, GUIAlignmentNames); - out->addBool ("Writable", m_writable); + out->addString("PasswordChar", ch.c_str()); + out->addEnum ("HTextAlign", HAlign, GUIAlignmentNames); + out->addEnum ("VTextAlign", VAlign, GUIAlignmentNames); + out->addBool ("Writable", m_writable); IGUIEditBox::serializeAttributes(out,options); } diff --git a/src/gui/intlGUIEditBox.h b/src/gui/intlGUIEditBox.h index 9d643495e..a1e423aa2 100644 --- a/src/gui/intlGUIEditBox.h +++ b/src/gui/intlGUIEditBox.h @@ -7,16 +7,15 @@ #include "IrrCompileConfig.h" //#ifdef _IRR_COMPILE_WITH_GUI_ -#include +#include "guiEditBox.h" #include "irrArray.h" #include "IOSOperator.h" -#include "guiScrollBar.h" namespace irr { namespace gui { - class intlGUIEditBox : public IGUIEditBox + class intlGUIEditBox : public GUIEditBox { public: @@ -28,32 +27,6 @@ namespace gui //! destructor virtual ~intlGUIEditBox(); - //! Sets another skin independent font. - virtual void setOverrideFont(IGUIFont* font=0); - - //! Gets the override font (if any) - /** \return The override font (may be 0) */ - virtual IGUIFont* getOverrideFont() const; - - //! Get the font which is used right now for drawing - /** Currently this is the override font when one is set and the - font of the active skin otherwise */ - virtual IGUIFont* getActiveFont() const; - - //! Sets another color for the text. - virtual void setOverrideColor(video::SColor color); - - //! Gets the override color - virtual video::SColor getOverrideColor() const; - - //! Sets if the text should use the overide color or the - //! color in the gui skin. - virtual void enableOverrideColor(bool enable); - - //! Checks if an override color is enabled - /** \return true if the override color is enabled, false otherwise */ - virtual bool isOverrideColorEnabled(void) const; - //! Sets whether to draw the background virtual void setDrawBackground(bool draw); @@ -64,30 +37,6 @@ namespace gui virtual bool isDrawBorderEnabled() const { return Border; } - //! Enables or disables word wrap for using the edit box as multiline text editor. - virtual void setWordWrap(bool enable); - - //! Checks if word wrap is enabled - //! \return true if word wrap is enabled, false otherwise - virtual bool isWordWrapEnabled() const; - - //! Enables or disables newlines. - /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired, - instead a newline character will be inserted. */ - virtual void setMultiLine(bool enable); - - //! Checks if multi line editing is enabled - //! \return true if mult-line is enabled, false otherwise - virtual bool isMultiLineEnabled() const; - - //! Enables or disables automatic scrolling with cursor position - //! \param enable: If set to true, the text will move around with the cursor position - virtual void setAutoScroll(bool enable); - - //! Checks to see if automatic scrolling is enabled - //! \return true if automatic scrolling is enabled, false if not - virtual bool isAutoScrollEnabled() const; - //! Gets the size area of the text in the edit box //! \return Returns the size in pixels of the text virtual core::dimension2du getTextDimension(); @@ -143,7 +92,7 @@ namespace gui protected: //! Breaks the single text line. - void breakText(); + virtual void breakText(); //! sets the area of the given line void setTextRect(s32 line); //! returns the line number that the cursor is on @@ -169,12 +118,9 @@ namespace gui bool MouseMarking = false; bool Border; - bool OverrideColorEnabled = false; s32 MarkBegin = 0; s32 MarkEnd = 0; - video::SColor OverrideColor = video::SColor(101,255,255,255); - gui::IGUIFont *OverrideFont = nullptr; gui::IGUIFont *LastBreakFont = nullptr; IOSOperator *Operator = nullptr; @@ -184,9 +130,6 @@ namespace gui s32 VScrollPos = 0; // scroll position in characters u32 Max = 0; - bool WordWrap = false; - bool MultiLine = false; - bool AutoScroll = true; bool PasswordBox = false; wchar_t PasswordChar = L'*'; EGUI_ALIGNMENT HAlign = EGUIA_UPPERLEFT; -- cgit v1.2.3