This repository has been archived by the owner on Jan 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
demo.gd
124 lines (86 loc) · 2.9 KB
/
demo.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
extends Panel
var cursor = Vector2(0,0)
var terminal
var current_style
# color pickers
onready var fg_picker = get_node("VBoxContainer/HBoxContainer/fg_color")
onready var bg_picker = get_node("VBoxContainer/HBoxContainer/bg_color")
# font selector
onready var font_select = get_node("VBoxContainer/HBoxContainer/font_style")
var draw_mouse = false
func _ready():
terminal = get_node("VBoxContainer/Terminal")
# load additional fonts
terminal.add_font(preload("res://fonts/Ubuntu_mono_bold.tres"))
terminal.add_font(preload("res://fonts/Ubuntu_mono_italic.tres"))
terminal.add_font(preload("res://fonts/Ubuntu_mono_italic_bold.tres"))
terminal._on_resize()
terminal.redraw_terminal()
# current terminal style
current_style = terminal.Style.new(fg_picker.get_color(), bg_picker.get_color(), 0)
# add menu items for fonts
font_select.add_item("Normal", 0)
font_select.add_item("Bold", 1)
font_select.add_item("Italic", 2)
font_select.add_item("Bold Italic", 3)
font_select.select(0)
# Enter button
func _on_enter_pressed():
var string = get_node("VBoxContainer/HBoxContainer/LineEdit").get_text()
cursor = terminal.write_string(cursor.x, cursor.y, string, current_style)
cursor.x += 1
if cursor.x >= terminal.grid.x - 1:
_on_new_line_pressed()
# redraw terminal
terminal.redraw_terminal()
# When you press enter key while writing
func _on_LineEdit_text_entered( text ):
_on_enter_pressed()
get_node("VBoxContainer/HBoxContainer/LineEdit").set_text("")
func resize_font(size):
terminal.resize_fonts(size)
terminal._on_resize()
terminal.redraw_terminal()
# font+ button
func _on_font_plus_pressed():
resize_font(1)
# font- button
func _on_font_minus_pressed():
resize_font(-1)
func _on_clean_pressed():
var c = get_node("VBoxContainer/HBoxContainer/LineEdit").get_text()
c = c.left(1)
if c.empty():
c = " "
cursor = Vector2()
terminal.defaultStyle.bg = current_style.bg
terminal.write_all(c, current_style)
terminal.redraw_terminal()
func _on_font_style_item_selected( ID ):
current_style.font = ID
func _on_fg_color_color_changed( color ):
current_style.fg = color
func _on_bg_color_color_changed( color ):
current_style.bg = color
func _on_new_line_pressed():
# go to begginig of next line
cursor.x = 0
cursor.y += 1
if cursor.y >= terminal.grid.y - 1:
cursor.y = 0
func _on_Terminal_input_event( ev ):
if ev.type == InputEvent.MOUSE_MOTION and draw_mouse:
var c = terminal.get_cell(Vector2(ev.x, ev.y))
terminal.write(c.x, c.y, "#", current_style)
terminal.redraw_terminal()
func _on_draw_toggled( pressed ):
draw_mouse = pressed
func _on_Panel_resized():
if terminal != null:
OS.set_window_title("Terminal: %s" % terminal.grid)
# using internal apis
func _on_rand_bg_pressed():
for i in range(terminal.buffer.get_size()):
terminal.buffer.bgcolors[i] = Color(randf(), randf(), randf())
terminal._draw_buffer.request_full_redraw()
terminal.redraw_terminal()