mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-03-12 22:35:18 +00:00
Minor guide and rulers performance boost
Got rid of their _process methods, Guides have input instead, and the rulers get updated when the camera zoom or offset change.
This commit is contained in:
parent
06d19c8e48
commit
b21455cfd0
6 changed files with 34 additions and 30 deletions
|
@ -1,5 +1,6 @@
|
|||
extends Camera2D
|
||||
|
||||
|
||||
var tween : Tween
|
||||
var zoom_min := Vector2(0.005, 0.005)
|
||||
var zoom_max := Vector2.ONE
|
||||
|
@ -7,10 +8,12 @@ var viewport_container : ViewportContainer
|
|||
var mouse_pos := Vector2.ZERO
|
||||
var drag := false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
viewport_container = get_parent().get_parent()
|
||||
tween = Tween.new()
|
||||
add_child(tween)
|
||||
tween.connect("tween_step", self, "_on_tween_step")
|
||||
|
||||
|
||||
# Get the speed multiplier for when you've pressed
|
||||
|
@ -117,6 +120,9 @@ func _input(event : InputEvent) -> void:
|
|||
elif is_action_direction_released(event):
|
||||
process_direction_action_released(event)
|
||||
|
||||
Global.horizontal_ruler.update()
|
||||
Global.vertical_ruler.update()
|
||||
|
||||
|
||||
# Zoom Camera
|
||||
func zoom_camera(dir : int) -> void:
|
||||
|
@ -145,3 +151,9 @@ func zoom_camera(dir : int) -> void:
|
|||
offset = offset + (-0.5 * viewport_size + mouse_pos) * (prev_zoom - zoom)
|
||||
if name == "Camera2D":
|
||||
Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %"
|
||||
|
||||
|
||||
|
||||
func _on_tween_step(_object: Object, _key: NodePath, _elapsed: float, _value: Object) -> void:
|
||||
Global.horizontal_ruler.update()
|
||||
Global.vertical_ruler.update()
|
||||
|
|
|
@ -528,6 +528,9 @@ func camera_zoom() -> void:
|
|||
Global.camera2.offset = size / 2
|
||||
Global.camera_preview.offset = size / 2
|
||||
|
||||
Global.horizontal_ruler.update()
|
||||
Global.vertical_ruler.update()
|
||||
|
||||
func handle_undo(action : String) -> void:
|
||||
if !can_undo:
|
||||
return
|
||||
|
|
|
@ -666,12 +666,16 @@ func _on_FitToFrameButton_pressed() -> void:
|
|||
Global.camera.zoom = Vector2(bigger_canvas_axis, bigger_canvas_axis) / smaller_viewport_axis
|
||||
Global.camera.offset = Global.canvas.size / 2
|
||||
Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %"
|
||||
Global.horizontal_ruler.update()
|
||||
Global.vertical_ruler.update()
|
||||
|
||||
|
||||
func _on_100ZoomButton_pressed() -> void:
|
||||
Global.camera.zoom = Vector2.ONE
|
||||
Global.camera.offset = Global.canvas.size / 2
|
||||
Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %"
|
||||
Global.horizontal_ruler.update()
|
||||
Global.vertical_ruler.update()
|
||||
|
||||
|
||||
func _on_LeftHorizontalMirroring_toggled(button_pressed) -> void:
|
||||
|
|
|
@ -13,8 +13,8 @@ func _ready() -> void:
|
|||
width = 0.1
|
||||
default_color = Global.guide_color
|
||||
|
||||
# warning-ignore:unused_argument
|
||||
func _process(delta : float) -> void:
|
||||
|
||||
func _input(_event : InputEvent):
|
||||
width = Global.camera.zoom.x * 2
|
||||
mouse_pos = get_local_mouse_position()
|
||||
var point0 := points[0]
|
||||
|
|
|
@ -9,27 +9,12 @@ var minor_subdivision := 4
|
|||
var first : Vector2
|
||||
var last : Vector2
|
||||
|
||||
onready var _prev_camera_offset: Vector2 = Global.camera.offset
|
||||
onready var _prev_camera_zoom: Vector2 = Global.camera.zoom
|
||||
|
||||
func _ready() -> void:
|
||||
Global.main_viewport.connect("item_rect_changed", self, "update")
|
||||
|
||||
# warning-ignore:unused_argument
|
||||
func _process(delta : float) -> void:
|
||||
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
|
||||
# Code taken and modified from Godot's source code
|
||||
func _draw() -> void:
|
||||
var transform := Transform2D()
|
||||
var ruler_transform := Transform2D()
|
||||
|
@ -70,11 +55,12 @@ func _draw() -> void:
|
|||
else:
|
||||
draw_line(Vector2(position.x + RULER_WIDTH, RULER_WIDTH * 0.66), Vector2(position.x + RULER_WIDTH, RULER_WIDTH), Color.white)
|
||||
|
||||
|
||||
func _on_HorizontalRuler_pressed() -> void:
|
||||
if !Global.show_guides:
|
||||
return
|
||||
var mouse_pos := get_local_mouse_position()
|
||||
if mouse_pos.x < RULER_WIDTH: #For double guides
|
||||
if mouse_pos.x < RULER_WIDTH: # For double guides
|
||||
Global.vertical_ruler._on_VerticalRuler_pressed()
|
||||
var guide := Guide.new()
|
||||
guide.type = guide.Types.HORIZONTAL
|
||||
|
@ -83,3 +69,11 @@ func _on_HorizontalRuler_pressed() -> void:
|
|||
Global.canvas.add_child(guide)
|
||||
Global.has_focus = false
|
||||
update()
|
||||
|
||||
|
||||
func _on_HorizontalRuler_mouse_entered() -> void:
|
||||
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
|
||||
|
|
|
@ -9,22 +9,12 @@ var minor_subdivision := 4
|
|||
var first : Vector2
|
||||
var last : Vector2
|
||||
|
||||
onready var _prev_camera_offset: Vector2 = Global.camera.offset
|
||||
onready var _prev_camera_zoom: Vector2 = Global.camera.zoom
|
||||
|
||||
func _ready() -> void:
|
||||
Global.main_viewport.connect("item_rect_changed", self, "update")
|
||||
|
||||
# warning-ignore:unused_argument
|
||||
func _process(delta : float) -> void:
|
||||
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
|
||||
# Code taken and modified from Godot's source code
|
||||
func _draw() -> void:
|
||||
var transform := Transform2D()
|
||||
var ruler_transform := Transform2D()
|
||||
|
@ -68,6 +58,7 @@ func _draw() -> void:
|
|||
else:
|
||||
draw_line(Vector2(RULER_WIDTH * 0.66, position.y), Vector2(RULER_WIDTH, position.y), Color.white)
|
||||
|
||||
|
||||
func _on_VerticalRuler_pressed() -> void:
|
||||
if !Global.show_guides:
|
||||
return
|
||||
|
|
Loading…
Add table
Reference in a new issue