From 5838b7fe7e1b2d71125be5069c87559f5cfdd90e Mon Sep 17 00:00:00 2001 From: Leroy Hopson Date: Wed, 7 Jul 2021 21:34:10 +0700 Subject: [PATCH] Add support for mouse scroll Part of #4. --- addons/godot_xterm/native/src/terminal.cpp | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/addons/godot_xterm/native/src/terminal.cpp b/addons/godot_xterm/native/src/terminal.cpp index 6a5b7f2..32fbc82 100644 --- a/addons/godot_xterm/native/src/terminal.cpp +++ b/addons/godot_xterm/native/src/terminal.cpp @@ -1,8 +1,15 @@ // Copyright (c) 2021, Leroy Hopson (MIT License). +// This file contains snippets of code taken from Godot's TextEdit node. +// The snippet code is copyright of its authors and released under the MIT +// license: +// - Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur (MIT License). +// - Copyright (c) 2014-2021 Godot Engine contributors (MIT License). + #include "terminal.h" #include #include +#include #include #include #include @@ -359,6 +366,35 @@ void Terminal::_gui_input(Variant event) { tsm_vte_handle_keyboard(vte, keysym, ascii, mods, unicode ? unicode : TSM_VTE_INVALID); } + + Ref mb = event; + + if (mb.is_valid()) { + Vector2 mpos = mb->get_position(); + + if (mb->is_pressed()) { + if (mb->get_button_index() == GLOBAL_CONSTANT(BUTTON_WHEEL_UP)) { + if (mb->get_alt()) { + // Scroll 5 times as fast as normal (like in TextEdit). + tsm_screen_sb_up(screen, 15 * mb->get_factor()); + } else { + // Scroll 3 lines. + tsm_screen_sb_up(screen, 3 * mb->get_factor()); + } + update(); + } + if (mb->get_button_index() == GLOBAL_CONSTANT(BUTTON_WHEEL_DOWN)) { + if (mb->get_alt()) { + // Scroll 5 times as fast as normal (like in TextEdit). + tsm_screen_sb_down(screen, 15 * mb->get_factor()); + } else { + // Scroll 3 lines. + tsm_screen_sb_down(screen, 3 * mb->get_factor()); + } + update(); + } + } + } } void Terminal::_draw() {