mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-25 10:40:25 +01:00
Add scroll support
This commit is contained in:
parent
d59a925ca1
commit
3bed9e7b0f
2 changed files with 29 additions and 0 deletions
|
@ -176,6 +176,7 @@ String Terminal::write(const Variant data)
|
||||||
void Terminal::_gui_input(const Ref<InputEvent> &event) {
|
void Terminal::_gui_input(const Ref<InputEvent> &event) {
|
||||||
_handle_key_input(event);
|
_handle_key_input(event);
|
||||||
_handle_selection(event);
|
_handle_selection(event);
|
||||||
|
_handle_mouse_wheel(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terminal::_notification(int what)
|
void Terminal::_notification(int what)
|
||||||
|
@ -658,6 +659,31 @@ void Terminal::_handle_key_input(Ref<InputEventKey> event) {
|
||||||
accept_event();
|
accept_event();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Terminal::_handle_mouse_wheel(Ref<InputEventMouseButton> event) {
|
||||||
|
if (!event.is_valid() || !event->is_pressed())
|
||||||
|
return;
|
||||||
|
|
||||||
|
void (*scroll_func)(tsm_screen *, unsigned int) = nullptr;
|
||||||
|
|
||||||
|
switch (event->get_button_index()) {
|
||||||
|
case MOUSE_BUTTON_WHEEL_UP:
|
||||||
|
scroll_func = &tsm_screen_sb_up;
|
||||||
|
break;
|
||||||
|
case MOUSE_BUTTON_WHEEL_DOWN:
|
||||||
|
scroll_func = &tsm_screen_sb_down;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (scroll_func != nullptr) {
|
||||||
|
// Scroll 5 times as fast as normal if alt is pressed (like TextEdit).
|
||||||
|
// Otherwise, just scroll 3 lines.
|
||||||
|
int speed = event->is_alt_pressed() ? 15 : 3;
|
||||||
|
double factor = event->get_factor();
|
||||||
|
(*scroll_func)(screen, speed * factor);
|
||||||
|
queue_redraw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Terminal::_handle_selection(Ref<InputEventMouse> event) {
|
void Terminal::_handle_selection(Ref<InputEventMouse> event) {
|
||||||
if (!event.is_valid())
|
if (!event.is_valid())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <godot_cpp/classes/image_texture.hpp>
|
#include <godot_cpp/classes/image_texture.hpp>
|
||||||
#include <godot_cpp/classes/input_event_key.hpp>
|
#include <godot_cpp/classes/input_event_key.hpp>
|
||||||
#include <godot_cpp/classes/input_event_mouse.hpp>
|
#include <godot_cpp/classes/input_event_mouse.hpp>
|
||||||
|
#include <godot_cpp/classes/input_event_mouse_button.hpp>
|
||||||
#include <godot_cpp/classes/rendering_server.hpp>
|
#include <godot_cpp/classes/rendering_server.hpp>
|
||||||
#include <godot_cpp/classes/shader_material.hpp>
|
#include <godot_cpp/classes/shader_material.hpp>
|
||||||
#include <godot_cpp/classes/timer.hpp>
|
#include <godot_cpp/classes/timer.hpp>
|
||||||
|
@ -154,6 +155,8 @@ namespace godot
|
||||||
void initialize_input();
|
void initialize_input();
|
||||||
void _handle_key_input(Ref<InputEventKey> event);
|
void _handle_key_input(Ref<InputEventKey> event);
|
||||||
|
|
||||||
|
void _handle_mouse_wheel(Ref<InputEventMouseButton> event);
|
||||||
|
|
||||||
enum SelectionMode { NONE, POINTER };
|
enum SelectionMode { NONE, POINTER };
|
||||||
bool selecting = false;
|
bool selecting = false;
|
||||||
SelectionMode selection_mode = SelectionMode::NONE;
|
SelectionMode selection_mode = SelectionMode::NONE;
|
||||||
|
|
Loading…
Reference in a new issue