WIP: timeline drawing, still buggy
This commit is contained in:
71
Scripts/Timeline.gd
Normal file
71
Scripts/Timeline.gd
Normal file
@@ -0,0 +1,71 @@
|
||||
@tool
|
||||
class_name Timeline
|
||||
extends Control
|
||||
|
||||
@export var font_scale: float = 1.0
|
||||
@export var time_offset: float = 0.0
|
||||
@export var grid_space_seconds: float = 0.25
|
||||
@export var label_interval_seconds: float = 1.0
|
||||
@export var line_thickness: int = 1
|
||||
@export var primary_line_step: int = 4
|
||||
@export var cursor_width: int = 8
|
||||
@export var base_scale: float = 2.0
|
||||
@export var zoom: float = 1.0
|
||||
|
||||
@export var min_zoom: float = 0.1
|
||||
|
||||
func _draw():
|
||||
draw_intervals()
|
||||
# draw_top_time_labels()
|
||||
pass
|
||||
|
||||
func _gui_input(event):
|
||||
var zoom_factor = 1.1
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
|
||||
zoom /= zoom_factor
|
||||
queue_redraw()
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_WHEEL_UP:
|
||||
zoom *= zoom_factor
|
||||
queue_redraw()
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_WHEEL_LEFT:
|
||||
time_offset -= 0.1 / zoom
|
||||
queue_redraw()
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_WHEEL_RIGHT:
|
||||
time_offset += 0.1 / zoom
|
||||
queue_redraw()
|
||||
|
||||
zoom = max(min_zoom, zoom)
|
||||
time_offset = max(0.0, time_offset)
|
||||
|
||||
func draw_intervals():
|
||||
var font = get_theme_default_font()
|
||||
var font_size = get_theme_default_font_size()
|
||||
|
||||
var current_width = size.x
|
||||
var current_height = size.y
|
||||
|
||||
var primary_color = get_theme_color("line_primary_color", "Timeline")
|
||||
var secondary_color = get_theme_color("line_secondary_color", "Timeline")
|
||||
|
||||
var interval = grid_space_seconds * base_scale * zoom * current_width
|
||||
|
||||
var first_line_index = roundi(time_offset / grid_space_seconds)
|
||||
var first_line_position = -(time_offset - (first_line_index * grid_space_seconds)) * interval
|
||||
|
||||
var line_count = ceil(current_width / interval) + 4
|
||||
|
||||
var current_position = first_line_position
|
||||
|
||||
for i in range(first_line_index, first_line_index + line_count):
|
||||
if current_position > current_width:
|
||||
break
|
||||
|
||||
if current_position >= -interval:
|
||||
var color = secondary_color
|
||||
if i % primary_line_step == 0:
|
||||
draw_string(font, Vector2(current_position, 0), str(i * grid_space_seconds), HORIZONTAL_ALIGNMENT_CENTER, -1, font_size * font_scale)
|
||||
color = primary_color
|
||||
|
||||
draw_line(Vector2(current_position, 0), Vector2(current_position, current_height), color, line_thickness)
|
||||
|
||||
current_position += interval
|
||||
Reference in New Issue
Block a user