1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-22 13:33:13 +00:00

Made Guide.gd a bit easier to read

This commit is contained in:
Emmanouil Papadeas 2022-07-15 21:13:46 +03:00
parent 95cf6afb47
commit 0b1ea0d680

View file

@ -73,7 +73,8 @@ func _input(_event: InputEvent) -> void:
func _draw() -> void: func _draw() -> void:
if has_focus: if !has_focus:
return
var viewport_size: Vector2 = Global.main_viewport.rect_size var viewport_size: Vector2 = Global.main_viewport.rect_size
var zoom: Vector2 = Global.camera.zoom var zoom: Vector2 = Global.camera.zoom
@ -106,26 +107,25 @@ func _draw() -> void:
var x_offset := 5 var x_offset := 5
var y_offset := -7 # Only used where the string is above the guide var y_offset := -7 # Only used where the string is above the guide
var font_string_size := font.get_string_size(string)
var font_height := font.get_height()
# Draw the string where the guide intersects with the viewport poly # Draw the string where the guide intersects with the viewport poly
# Priority is top edge, then left, then right # Priority is top edge, then left, then right
var intersection = Geometry.segment_intersects_segment_2d( var intersection = Geometry.segment_intersects_segment_2d(
points[0], points[1], viewport_poly[0], viewport_poly[1] points[0], points[1], viewport_poly[0], viewport_poly[1]
) )
if intersection: if intersection:
draw_set_transform(intersection, Global.camera.rotation, zoom * 2) draw_set_transform(intersection, Global.camera.rotation, zoom * 2)
if ( if (
intersection.distance_squared_to(viewport_poly[0]) intersection.distance_squared_to(viewport_poly[0])
< intersection.distance_squared_to(viewport_poly[1]) < intersection.distance_squared_to(viewport_poly[1])
): ):
draw_string(font, Vector2(x_offset, font.get_height()), string, color) draw_string(font, Vector2(x_offset, font_height), string, color)
else: else:
draw_string( draw_string(font, Vector2(-font_string_size.x - x_offset, font_height), string, color)
font,
Vector2(-font.get_string_size(string).x - x_offset, font.get_height()),
string,
color
)
return return
intersection = Geometry.segment_intersects_segment_2d( intersection = Geometry.segment_intersects_segment_2d(
points[0], points[1], viewport_poly[3], viewport_poly[0] points[0], points[1], viewport_poly[3], viewport_poly[0]
) )
@ -137,35 +137,27 @@ func _draw() -> void:
): ):
draw_string(font, Vector2(x_offset, y_offset), string, color) draw_string(font, Vector2(x_offset, y_offset), string, color)
else: else:
draw_string(font, Vector2(x_offset, font.get_height()), string, color) draw_string(font, Vector2(x_offset, font_height), string, color)
return return
intersection = Geometry.segment_intersects_segment_2d( intersection = Geometry.segment_intersects_segment_2d(
points[0], points[1], viewport_poly[1], viewport_poly[2] points[0], points[1], viewport_poly[1], viewport_poly[2]
) )
if intersection: if intersection:
draw_set_transform(intersection, Global.camera.rotation, zoom * 2) draw_set_transform(intersection, Global.camera.rotation, zoom * 2)
if ( if (
intersection.distance_squared_to(viewport_poly[1]) intersection.distance_squared_to(viewport_poly[1])
< intersection.distance_squared_to(viewport_poly[2]) < intersection.distance_squared_to(viewport_poly[2])
): ):
draw_string( draw_string(font, Vector2(-font_string_size.x - x_offset, font_height), string, color)
font,
Vector2(-font.get_string_size(string).x - x_offset, font.get_height()),
string,
color
)
else: else:
draw_string( draw_string(font, Vector2(-font_string_size.x - x_offset, y_offset), string, color)
font,
Vector2(-font.get_string_size(string).x - x_offset, y_offset),
string,
color
)
return return
# If there's no intersection with a viewport edge, show string in top left corner # If there's no intersection with a viewport edge, show string in top left corner
draw_set_transform(viewport_poly[0], Global.camera.rotation, zoom * 2) draw_set_transform(viewport_poly[0], Global.camera.rotation, zoom * 2)
draw_string(font, Vector2(x_offset, font.get_height()), string, color) draw_string(font, Vector2(x_offset, font_height), string, color)
func outside_canvas() -> bool: func outside_canvas() -> bool: