diff options
author | pecksin <pexin@protonmail.com> | 2021-03-23 18:18:44 -0400 |
---|---|---|
committer | pecksin <pexin@protonmail.com> | 2021-03-23 18:18:44 -0400 |
commit | 7e8e3153e5227eb9b35ed2379efb54d17ba9aeae (patch) | |
tree | 87d3e0c6c048555c2e0179f29e6fbd39379dadc0 /src | |
parent | c18be120855d4219d7e06ed674121eb7f6a93ea5 (diff) | |
download | minetest-7e8e3153e5227eb9b35ed2379efb54d17ba9aeae.tar.gz minetest-7e8e3153e5227eb9b35ed2379efb54d17ba9aeae.tar.bz2 minetest-7e8e3153e5227eb9b35ed2379efb54d17ba9aeae.zip |
move middleClick() into guiChatConsole.cpp where it belongs
Diffstat (limited to 'src')
-rw-r--r-- | src/chat.cpp | 58 | ||||
-rw-r--r-- | src/chat.h | 4 | ||||
-rw-r--r-- | src/gui/guiChatConsole.cpp | 58 | ||||
-rw-r--r-- | src/gui/guiChatConsole.h | 4 |
4 files changed, 60 insertions, 64 deletions
diff --git a/src/chat.cpp b/src/chat.cpp index c58b6e7cb..9bceb3535 100644 --- a/src/chat.cpp +++ b/src/chat.cpp @@ -28,8 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/strfnd.h" #include "util/string.h" #include "util/numeric.h" -#include "porting.h" -#include "gettext.h" ChatBuffer::ChatBuffer(u32 scrollback): m_scrollback(scrollback) @@ -886,59 +884,3 @@ void ChatBackend::scrollPageUp() { m_console_buffer.scroll(-(s32)m_console_buffer.getRows()); } - -void ChatBackend::middleClick(s32 col, s32 row) -{ - // Prevent accidental rapid clicking - static u32 oldtime = 0; - // seriously.. - u32 newtime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); - - // 0.6 seconds should suffice - if(newtime - oldtime < 600) - return; - oldtime = newtime; - - const std::vector<ChatFormattedFragment> & frags = getConsoleBuffer().getFormattedLine(row).fragments; - std::string weblink = ""; // from frag meta - - // Identify targetted fragment, if exists - int ind = frags.size() - 1; - while(u32(col - 1) < frags[ind].column) - { - --ind; - } - if(ind > -1) - { - weblink = frags[ind].meta; - } - - // Debug help - std::string ws; - ws = "Middleclick: (" + std::to_string(col) + ',' + std::to_string(row) + ')' + " frags:"; - for(u32 i=0;i<frags.size();++i) - { - if(ind == int(i)) - ws += '*'; - ws += std::to_string(frags.at(i).column) + '(' - + std::to_string(frags.at(i).text.size()) + "),"; - } - g_logger.log(LL_VERBOSE, ws); - - // User notification - std::string mesg; - if(weblink.size() != 0) - { - mesg = " * "; - if(porting::open_url(weblink)) - { - mesg += gettext("Opening webpage"); - } - else - { - mesg += gettext("Failed to open webpage"); - } - mesg += " '" + weblink + "'"; - addUnparsedMessage(utf8_to_wide(mesg)); - } -} diff --git a/src/chat.h b/src/chat.h index bb40af048..d7d27646f 100644 --- a/src/chat.h +++ b/src/chat.h @@ -289,10 +289,6 @@ public: void scrollPageDown(); void scrollPageUp(); - // Handle middle click at this font position - // If clicked fragment has a web url, send it to the system default web browser - void middleClick(s32 col, s32 row); - // Resize recent buffer based on settings void applySettings(); diff --git a/src/gui/guiChatConsole.cpp b/src/gui/guiChatConsole.cpp index c27ade23d..6330d95d4 100644 --- a/src/gui/guiChatConsole.cpp +++ b/src/gui/guiChatConsole.cpp @@ -661,7 +661,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) // because console prompt and hardcoded margins if(event.MouseInput.Y / m_fontsize.Y < (m_height / m_fontsize.Y) - 1 ) { - m_chat_backend->middleClick(event.MouseInput.X / m_fontsize.X, event.MouseInput.Y / m_fontsize.Y); + middleClick(event.MouseInput.X / m_fontsize.X, event.MouseInput.Y / m_fontsize.Y); } } } @@ -729,3 +729,59 @@ bool GUIChatConsole::isInCtrlKeys(const irr::EKEY_CODE& kc) } return false; } + +void GUIChatConsole::middleClick(s32 col, s32 row) +{ + // Prevent accidental rapid clicking + static u32 oldtime = 0; + // seriously.. + u32 newtime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); + + // 0.6 seconds should suffice + if(newtime - oldtime < 600) + return; + oldtime = newtime; + + const std::vector<ChatFormattedFragment> & frags = m_chat_backend->getConsoleBuffer().getFormattedLine(row).fragments; + std::string weblink = ""; // from frag meta + + // Identify targetted fragment, if exists + int ind = frags.size() - 1; + while(u32(col - 1) < frags[ind].column) + { + --ind; + } + if(ind > -1) + { + weblink = frags[ind].meta; + } + + // Debug help + std::string ws; + ws = "Middleclick: (" + std::to_string(col) + ',' + std::to_string(row) + ')' + " frags:"; + for(u32 i=0;i<frags.size();++i) + { + if(ind == int(i)) + ws += '*'; + ws += std::to_string(frags.at(i).column) + '(' + + std::to_string(frags.at(i).text.size()) + "),"; + } + g_logger.log(LL_VERBOSE, ws); + + // User notification + std::string mesg; + if(weblink.size() != 0) + { + mesg = " * "; + if(porting::open_url(weblink)) + { + mesg += gettext("Opening webpage"); + } + else + { + mesg += gettext("Failed to open webpage"); + } + mesg += " '" + weblink + "'"; + m_chat_backend->addUnparsedMessage(utf8_to_wide(mesg)); + } +} diff --git a/src/gui/guiChatConsole.h b/src/gui/guiChatConsole.h index 0618f2956..169fb7eb7 100644 --- a/src/gui/guiChatConsole.h +++ b/src/gui/guiChatConsole.h @@ -82,9 +82,11 @@ private: void drawText(); void drawPrompt(); - // Parse conf and populate "ctrl" keys for clickable chat + // Clickable weblink stuff int setupChatClickCtrlKeys(std::string inputline); bool isInCtrlKeys(const irr::EKEY_CODE& kc); + // If clicked fragment has a web url, send it to the system default web browser + void middleClick(s32 col, s32 row); private: ChatBackend* m_chat_backend; |