From 7e8e3153e5227eb9b35ed2379efb54d17ba9aeae Mon Sep 17 00:00:00 2001 From: pecksin Date: Tue, 23 Mar 2021 18:18:44 -0400 Subject: move middleClick() into guiChatConsole.cpp where it belongs --- src/gui/guiChatConsole.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) (limited to 'src/gui/guiChatConsole.cpp') 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::system_clock::now().time_since_epoch()).count(); + + // 0.6 seconds should suffice + if(newtime - oldtime < 600) + return; + oldtime = newtime; + + const std::vector & 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;iaddUnparsedMessage(utf8_to_wide(mesg)); + } +} -- cgit v1.2.3