GraphicsEditor/addons/graphics_editor/VisualGrid.gd

40 lines
1.0 KiB
GDScript3
Raw Normal View History

2019-08-04 09:57:42 +02:00
tool
extends Control
export var color = Color()
export var size:int = 16
2019-08-04 09:57:42 +02:00
export var zoom = 0
export var offset = Vector2(0, 0)
2020-10-25 18:39:10 +01:00
func _enter_tree():
set_process(true)
2019-08-04 09:57:42 +02:00
func _draw():
if size == 0:
size = 1
var temp_size = size + zoom
var wrap_offset = Vector2(wrapf(offset.x, 0, temp_size), wrapf(offset.y, 0, temp_size))
2020-10-25 18:39:10 +01:00
var ceil_x = ceil(rect_size.x / temp_size)
var ceil_y = ceil(rect_size.y / temp_size)
2019-08-04 09:57:42 +02:00
for i in ceil_y:
var start_x = Vector2(0, (i * temp_size) + wrap_offset.y)
2019-08-05 02:16:14 +02:00
var end_x = Vector2(rect_size.x, (i * temp_size) + wrap_offset.y)
2020-10-25 18:39:10 +01:00
# var end_x = Vector2(int(rect_size.x) + size - int(rect_size.x) % size, (i * temp_size) + wrap_offset.y)
2019-08-04 09:57:42 +02:00
draw_line(start_x, end_x, color, 1)
for i in ceil_x:
var start_y = Vector2((i * temp_size) + wrap_offset.x, 0)
2020-10-25 18:39:10 +01:00
var end_y = Vector2((i * temp_size) + (wrap_offset.x), rect_size.y)
# var end_y = Vector2((i * temp_size) + (wrap_offset.x), int(rect_size.y) + size - int(rect_size.y) % size)
2019-08-04 09:57:42 +02:00
draw_line(start_y, end_y, color, 1)
2020-10-25 18:39:10 +01:00
2019-08-04 09:57:42 +02:00
func _process(delta):
2019-11-23 12:33:43 +01:00
update()