mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-22 01:30:25 +01:00
Move scroll handling to GDScript
Just expose the underlying libtsm methods from gdnative, but write all the logic in gdscript. Makes it much easier to customize and update.
This commit is contained in:
parent
748941f7ff
commit
fae28006cf
3 changed files with 44 additions and 35 deletions
|
@ -1,11 +1,5 @@
|
|||
// 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 <Dictionary.hpp>
|
||||
#include <InputEventKey.hpp>
|
||||
|
@ -289,6 +283,9 @@ void Terminal::_register_methods() {
|
|||
|
||||
register_method("write", &Terminal::write);
|
||||
|
||||
register_method("sb_up", &Terminal::sb_up);
|
||||
register_method("sb_down", &Terminal::sb_down);
|
||||
|
||||
register_method("_update_theme", &Terminal::update_theme);
|
||||
register_method("_update_size", &Terminal::update_theme);
|
||||
|
||||
|
@ -366,35 +363,6 @@ void Terminal::_gui_input(Variant event) {
|
|||
tsm_vte_handle_keyboard(vte, keysym, ascii, mods,
|
||||
unicode ? unicode : TSM_VTE_INVALID);
|
||||
}
|
||||
|
||||
Ref<InputEventMouseButton> 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() {
|
||||
|
@ -600,3 +568,13 @@ void Terminal::write(String data) {
|
|||
|
||||
tsm_vte_input(vte, u8, len);
|
||||
}
|
||||
|
||||
void Terminal::sb_up(int num) {
|
||||
tsm_screen_sb_up(screen, num);
|
||||
update();
|
||||
}
|
||||
|
||||
void Terminal::sb_down(int num) {
|
||||
tsm_screen_sb_down(screen, num);
|
||||
update();
|
||||
}
|
|
@ -56,6 +56,9 @@ public:
|
|||
|
||||
void write(String data);
|
||||
|
||||
void sb_up(int num);
|
||||
void sb_down(int num);
|
||||
|
||||
enum UpdateMode {
|
||||
DISABLED,
|
||||
AUTO,
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
# Copyright (c) 2021, Leroy Hopson (MIT License).
|
||||
#
|
||||
# This file contains snippets of code derived from Godot's TextEdit node.
|
||||
# These snippets are copyright of their 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).
|
||||
tool
|
||||
extends Control
|
||||
|
||||
|
@ -87,6 +93,28 @@ func _refresh():
|
|||
|
||||
func _gui_input(event):
|
||||
_native_terminal._gui_input(event)
|
||||
_handle_mouse_wheel(event)
|
||||
|
||||
|
||||
func _handle_mouse_wheel(event: InputEventMouseButton):
|
||||
if not event or not event.is_pressed():
|
||||
return
|
||||
|
||||
if event.button_index == BUTTON_WHEEL_UP:
|
||||
if event.alt:
|
||||
# Scroll 5 times as fast as normal (like TextEdit).
|
||||
_native_terminal.sb_up(15 * event.factor)
|
||||
else:
|
||||
# Scroll 3 lines.
|
||||
_native_terminal.sb_up(3 * event.factor)
|
||||
|
||||
if event.button_index == BUTTON_WHEEL_DOWN:
|
||||
if event.alt:
|
||||
# Scroll 5 times as fast as normal (like TextEdit).
|
||||
_native_terminal.sb_down(15 * event.factor)
|
||||
else:
|
||||
# Scroll 3 lines.
|
||||
_native_terminal.sb_down(3 * event.factor)
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
|
|
Loading…
Reference in a new issue