From 037a797afc7fdc4e6a3a2d6f74a49ec1f584d732 Mon Sep 17 00:00:00 2001 From: Martin Zabinski Date: Fri, 27 Dec 2019 14:43:26 +0100 Subject: [PATCH] only redraw HorizontalRuler and VerticalRuler when needed --- Scripts/Rulers/HorizontalRuler.gd | 14 +++++++++++++- Scripts/Rulers/VerticalRuler.gd | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Scripts/Rulers/HorizontalRuler.gd b/Scripts/Rulers/HorizontalRuler.gd index fa93ddaa2..3ce3ff7de 100644 --- a/Scripts/Rulers/HorizontalRuler.gd +++ b/Scripts/Rulers/HorizontalRuler.gd @@ -9,14 +9,25 @@ var minor_subdivision := 4 var first : Vector2 var last : Vector2 +onready var _prev_camera_offset := Global.camera.offset +onready var _prev_camera_zoom := Global.camera.zoom + +func _ready() -> void: + Global.main_viewport.connect("item_rect_changed", self, "update") + # warning-ignore:unused_argument func _process(delta : float) -> void: - update() var mouse_pos := get_local_mouse_position() if mouse_pos.x < RULER_WIDTH: #For double guides mouse_default_cursor_shape = Control.CURSOR_FDIAGSIZE else: mouse_default_cursor_shape = Control.CURSOR_VSPLIT + if Global.camera.offset != _prev_camera_offset: + _prev_camera_offset = Global.camera.offset + update() + if Global.camera.zoom != _prev_camera_zoom: + _prev_camera_zoom = Global.camera.zoom + update() #Code taken and modified from Godot's source code func _draw() -> void: @@ -71,3 +82,4 @@ func _on_HorizontalRuler_pressed() -> void: guide.add_point(Vector2(99999, Global.canvas.current_pixel.y)) Global.canvas.add_child(guide) Global.has_focus = false + update() diff --git a/Scripts/Rulers/VerticalRuler.gd b/Scripts/Rulers/VerticalRuler.gd index 220e40e94..886fb3d80 100644 --- a/Scripts/Rulers/VerticalRuler.gd +++ b/Scripts/Rulers/VerticalRuler.gd @@ -9,9 +9,20 @@ var minor_subdivision := 4 var first : Vector2 var last : Vector2 +onready var _prev_camera_offset := Global.camera.offset +onready var _prev_camera_zoom := Global.camera.zoom + +func _ready() -> void: + Global.main_viewport.connect("item_rect_changed", self, "update") + # warning-ignore:unused_argument func _process(delta : float) -> void: - update() + if Global.camera.offset != _prev_camera_offset: + _prev_camera_offset = Global.camera.offset + update() + if Global.camera.zoom != _prev_camera_zoom: + _prev_camera_zoom = Global.camera.zoom + update() #Code taken and modified from Godot's source code func _draw() -> void: @@ -66,3 +77,4 @@ func _on_VerticalRuler_pressed() -> void: guide.add_point(Vector2(Global.canvas.current_pixel.x, 99999)) Global.canvas.add_child(guide) Global.has_focus = false + update()