1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 09:09:47 +00:00

Don't use Global.main_viewport on guides, plus some static typing improvements

This commit is contained in:
Emmanouil Papadeas 2024-01-11 16:23:00 +02:00
parent 72bec41e63
commit 80bcfe200d
2 changed files with 18 additions and 25 deletions

View file

@ -34,12 +34,7 @@ func _input(event: InputEvent) -> void:
return return
visible = true visible = true
if event is InputEventMouseMotion: if event is InputEventMouseMotion:
var tmp_transform := get_canvas_transform().affine_inverse() var mouse_point := get_local_mouse_position().snapped(Vector2(0.5, 0.5))
var tmp_position := Global.main_viewport.get_local_mouse_position()
var mouse_point := (tmp_transform.basis_xform(tmp_position) + tmp_transform.origin).snapped(
Vector2(0.5, 0.5)
)
var project_size := Global.current_project.size var project_size := Global.current_project.size
if Rect2(Vector2.ZERO, project_size).has_point(mouse_point): if Rect2(Vector2.ZERO, project_size).has_point(mouse_point):
visible = true visible = true
@ -57,13 +52,13 @@ func _input(event: InputEvent) -> void:
func _draw() -> void: func _draw() -> void:
width = 2.0 / Global.camera.zoom.x width = 2.0 / Global.camera.zoom.x
var viewport_size := Global.main_viewport.size var viewport_size := get_viewport_rect().size
var zoom := Global.camera.zoom var zoom := Global.camera.zoom
# viewport_poly is an array of the points that make up the corners of the viewport # An array of the points that make up the corners of the viewport
var viewport_poly: PackedVector2Array = [ var viewport_poly := PackedVector2Array(
Vector2.ZERO, Vector2(viewport_size.x, 0), viewport_size, Vector2(0, viewport_size.y) [Vector2.ZERO, Vector2(viewport_size.x, 0), viewport_size, Vector2(0, viewport_size.y)]
] )
# Adjusting viewport_poly to take into account the camera offset, zoom, and rotation # Adjusting viewport_poly to take into account the camera offset, zoom, and rotation
for p in range(viewport_poly.size()): for p in range(viewport_poly.size()):
viewport_poly[p] = ( viewport_poly[p] = (

View file

@ -21,11 +21,9 @@ func _ready() -> void:
func _input(_event: InputEvent) -> void: func _input(_event: InputEvent) -> void:
if !visible: if not visible:
return return
var tmp_transform := get_canvas_transform().affine_inverse() mouse_pos = get_local_mouse_position()
var tmp_position: Vector2 = Global.main_viewport.get_local_mouse_position()
mouse_pos = tmp_transform.basis_xform(tmp_position) + tmp_transform.origin
var point0 := points[0] var point0 := points[0]
var point1 := points[1] var point1 := points[1]
@ -39,20 +37,20 @@ func _input(_event: InputEvent) -> void:
rect.position = point0 rect.position = point0
rect.end = point1 rect.end = point1
if ( if (
Input.is_action_just_pressed("left_mouse") Input.is_action_just_pressed(&"left_mouse")
and Global.can_draw and Global.can_draw
and Global.has_focus and Global.has_focus
and rect.has_point(mouse_pos) and rect.has_point(mouse_pos)
): ):
if ( if (
!Rect2(Vector2.ZERO, project.size).has_point(Global.canvas.current_pixel) !Rect2i(Vector2i.ZERO, project.size).has_point(Global.canvas.current_pixel)
or Global.move_guides_on_canvas or Global.move_guides_on_canvas
): ):
has_focus = true has_focus = true
Global.can_draw = false Global.can_draw = false
queue_redraw() queue_redraw()
if has_focus: if has_focus:
if Input.is_action_pressed("left_mouse"): if Input.is_action_pressed(&"left_mouse"):
if type == Types.HORIZONTAL: if type == Types.HORIZONTAL:
var yy := snappedf(mouse_pos.y, 0.5) var yy := snappedf(mouse_pos.y, 0.5)
points[0].y = yy points[0].y = yy
@ -62,7 +60,7 @@ func _input(_event: InputEvent) -> void:
points[0].x = xx points[0].x = xx
points[1].x = xx points[1].x = xx
modulate.a = 0.5 if _outside_canvas() else 1.0 modulate.a = 0.5 if _outside_canvas() else 1.0
elif Input.is_action_just_released("left_mouse"): elif Input.is_action_just_released(&"left_mouse"):
Global.can_draw = true Global.can_draw = true
has_focus = false has_focus = false
if _outside_canvas(): if _outside_canvas():
@ -75,13 +73,13 @@ func _input(_event: InputEvent) -> void:
func _draw() -> void: func _draw() -> void:
if !has_focus: if !has_focus:
return return
var viewport_size: Vector2 = Global.main_viewport.size var viewport_size := get_viewport_rect().size
var zoom: Vector2 = Global.camera.zoom var zoom := Global.camera.zoom
# viewport_poly is an array of the points that make up the corners of the viewport # An array of the points that make up the corners of the viewport
var viewport_poly := [ var viewport_poly := PackedVector2Array(
Vector2.ZERO, Vector2(viewport_size.x, 0), viewport_size, Vector2(0, viewport_size.y) [Vector2.ZERO, Vector2(viewport_size.x, 0), viewport_size, Vector2(0, viewport_size.y)]
] )
# Adjusting viewport_poly to take into account the camera offset, zoom, and rotation # Adjusting viewport_poly to take into account the camera offset, zoom, and rotation
for p in range(viewport_poly.size()): for p in range(viewport_poly.size()):
viewport_poly[p] = ( viewport_poly[p] = (