From b6c8761e108eade0d1451580fbacf1e3d3f6a957 Mon Sep 17 00:00:00 2001 From: pecksin Date: Thu, 18 Mar 2021 16:47:36 -0400 Subject: re-apply everything manually because git --- src/gui/guiChatConsole.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/gui/guiChatConsole.cpp') diff --git a/src/gui/guiChatConsole.cpp b/src/gui/guiChatConsole.cpp index ef471106d..f5336e3ad 100644 --- a/src/gui/guiChatConsole.cpp +++ b/src/gui/guiChatConsole.cpp @@ -90,6 +90,8 @@ GUIChatConsole::GUIChatConsole( // set default cursor options setCursor(true, true, 2.0, 0.1); + + m_cache_clickable_chat_weblinks = g_settings->getBool("clickable_chat_weblinks"); } GUIChatConsole::~GUIChatConsole() @@ -321,6 +323,7 @@ void GUIChatConsole::drawText() #if USE_FREETYPE if (m_font->getType() == irr::gui::EGFT_CUSTOM) { + // Draw colored text if FreeType is enabled irr::gui::CGUITTFont *tmp = dynamic_cast(m_font); tmp->draw( @@ -404,9 +407,24 @@ bool GUIChatConsole::OnEvent(const SEvent& event) { ChatPrompt &prompt = m_chat_backend->getPrompt(); + static bool isctrldown; // track this for mouse event - if(event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown) + if(event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown) { + // CTRL up + if(event.KeyInput.Key == KEY_LCONTROL || event.KeyInput.Key == KEY_RCONTROL || !event.KeyInput.Control) + { + isctrldown = false; + } + } + else if(event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown) + { + // CTRL down + if(event.KeyInput.Key == KEY_LCONTROL || event.KeyInput.Key == KEY_RCONTROL || event.KeyInput.Control) + { + isctrldown = true; + } + // Key input if (KeyPress(event.KeyInput) == getKeySetting("keymap_console")) { closeConsole(); @@ -624,6 +642,18 @@ bool GUIChatConsole::OnEvent(const SEvent& event) s32 rows = myround(-3.0 * event.MouseInput.Wheel); m_chat_backend->scroll(rows); } + // Middle click opens weblink, if enabled in config + else if(m_cache_clickable_chat_weblinks && ( + event.MouseInput.Event == EMIE_MMOUSE_PRESSED_DOWN || + (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN && isctrldown) + )) + { + // 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); + } + } } return Parent ? Parent->OnEvent(event) : false; -- cgit v1.2.3 From 038a317c213db41227beaa014100dc43b46e392c Mon Sep 17 00:00:00 2001 From: pecksin Date: Fri, 19 Mar 2021 16:25:44 -0400 Subject: user-configurable 'ctrl' keys for ctrl-leftclick in chat weblinks --- src/gui/guiChatConsole.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 3 deletions(-) (limited to 'src/gui/guiChatConsole.cpp') diff --git a/src/gui/guiChatConsole.cpp b/src/gui/guiChatConsole.cpp index f5336e3ad..08d26efc2 100644 --- a/src/gui/guiChatConsole.cpp +++ b/src/gui/guiChatConsole.cpp @@ -90,8 +90,19 @@ GUIChatConsole::GUIChatConsole( // set default cursor options setCursor(true, true, 2.0, 0.1); - + m_cache_clickable_chat_weblinks = g_settings->getBool("clickable_chat_weblinks"); + if(m_cache_clickable_chat_weblinks) + { + std::string ctrlkeystoparse = g_settings->get("chat_weblink_ctrl_keys"); + if(setupChatClickCtrlKeys(ctrlkeystoparse) == 0) + { + // if fail then try again w hardcoded string + g_logger.log(LL_WARNING, "Failed to parse chat_weblink_ctrl_keys. Using hardcoded default."); + ctrlkeystoparse = "KEY_CONTROL,KEY_LCONTROL,KEY_RCONTROL"; + setupChatClickCtrlKeys(ctrlkeystoparse); + } + } } GUIChatConsole::~GUIChatConsole() @@ -412,7 +423,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) if(event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown) { // CTRL up - if(event.KeyInput.Key == KEY_LCONTROL || event.KeyInput.Key == KEY_RCONTROL || !event.KeyInput.Control) + if(isInCtrlKeys(event.KeyInput.Key) || !event.KeyInput.Control) { isctrldown = false; } @@ -420,7 +431,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) else if(event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown) { // CTRL down - if(event.KeyInput.Key == KEY_LCONTROL || event.KeyInput.Key == KEY_RCONTROL || event.KeyInput.Control) + if(isInCtrlKeys(event.KeyInput.Key) || event.KeyInput.Control) { isctrldown = true; } @@ -669,3 +680,53 @@ void GUIChatConsole::setVisible(bool visible) } } +// Return how many "ctrl" keycodes successfully found in string, or 0 on fail +int GUIChatConsole::setupChatClickCtrlKeys(std::string inputline) +{ + m_cache_chat_weblink_ctrl_keys.clear(); + + irr::EKEY_CODE kc; + std::string stemp; + size_t startpos = 0, endpos = 0; + while(startpos < inputline.size()) + { + // Foreach delimited string, + endpos = inputline.find(',', startpos); + endpos = std::min(endpos, inputline.find(' ', startpos)); + // Ignore space/comma + if(endpos == startpos) + { + ++endpos; + } + // Ignore consecutive space/comma + else if(endpos - startpos > 1) + { + // If valid keycode, add it to cached list + stemp = inputline.substr(startpos, endpos - startpos); + kc = keyname_to_keycode_safemode(stemp.c_str()); + if(kc != irr::KEY_KEY_CODES_COUNT) + { + m_cache_chat_weblink_ctrl_keys.push_back(kc); + } + else + { + stemp = "Ignoring unknown keycode '" + stemp + "' for chat_weblink_ctrl_keys, check your conf"; + g_logger.log(LL_WARNING, stemp); + } + } + startpos = endpos; + } + + return m_cache_chat_weblink_ctrl_keys.size(); +} + +bool GUIChatConsole::isInCtrlKeys(const irr::EKEY_CODE& kc) +{ + // To avoid including + for(size_t i=0; i Date: Mon, 22 Mar 2021 17:21:28 -0400 Subject: minor cleanup --- src/gui/guiChatConsole.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/gui/guiChatConsole.cpp') diff --git a/src/gui/guiChatConsole.cpp b/src/gui/guiChatConsole.cpp index 08d26efc2..527a28bdb 100644 --- a/src/gui/guiChatConsole.cpp +++ b/src/gui/guiChatConsole.cpp @@ -334,7 +334,6 @@ void GUIChatConsole::drawText() #if USE_FREETYPE if (m_font->getType() == irr::gui::EGFT_CUSTOM) { - // Draw colored text if FreeType is enabled irr::gui::CGUITTFont *tmp = dynamic_cast(m_font); tmp->draw( -- cgit v1.2.3 From 1b39c96683f984b82432cb9f9417245680982b41 Mon Sep 17 00:00:00 2001 From: pecksin Date: Mon, 22 Mar 2021 20:57:29 -0400 Subject: only use user-configured ctrl keys for weblink click --- src/gui/guiChatConsole.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gui/guiChatConsole.cpp') diff --git a/src/gui/guiChatConsole.cpp b/src/gui/guiChatConsole.cpp index 527a28bdb..c27ade23d 100644 --- a/src/gui/guiChatConsole.cpp +++ b/src/gui/guiChatConsole.cpp @@ -422,7 +422,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) if(event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown) { // CTRL up - if(isInCtrlKeys(event.KeyInput.Key) || !event.KeyInput.Control) + if(isInCtrlKeys(event.KeyInput.Key)) { isctrldown = false; } @@ -430,7 +430,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) else if(event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown) { // CTRL down - if(isInCtrlKeys(event.KeyInput.Key) || event.KeyInput.Control) + if(isInCtrlKeys(event.KeyInput.Key)) { isctrldown = true; } -- cgit v1.2.3 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