mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-22 05:23:14 +00:00
Made Guide.gd a bit easier to read
This commit is contained in:
parent
95cf6afb47
commit
0b1ea0d680
1 changed files with 79 additions and 87 deletions
|
@ -73,99 +73,91 @@ func _input(_event: InputEvent) -> void:
|
||||||
|
|
||||||
|
|
||||||
func _draw() -> void:
|
func _draw() -> void:
|
||||||
if has_focus:
|
if !has_focus:
|
||||||
var viewport_size: Vector2 = Global.main_viewport.rect_size
|
return
|
||||||
var zoom: Vector2 = Global.camera.zoom
|
var viewport_size: Vector2 = Global.main_viewport.rect_size
|
||||||
|
var zoom: Vector2 = Global.camera.zoom
|
||||||
|
|
||||||
# viewport_poly is an array of the points that make up the corners of the viewport
|
# viewport_poly is an array of the points that make up the corners of the viewport
|
||||||
var viewport_poly := [
|
var viewport_poly := [
|
||||||
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] = (
|
||||||
viewport_poly[p].rotated(Global.camera.rotation) * zoom
|
viewport_poly[p].rotated(Global.camera.rotation) * zoom
|
||||||
+ Vector2(
|
+ Vector2(
|
||||||
(
|
(
|
||||||
Global.camera.offset.x
|
Global.camera.offset.x
|
||||||
- (viewport_size.rotated(Global.camera.rotation).x / 2) * zoom.x
|
- (viewport_size.rotated(Global.camera.rotation).x / 2) * zoom.x
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Global.camera.offset.y
|
Global.camera.offset.y
|
||||||
- (viewport_size.rotated(Global.camera.rotation).y / 2) * zoom.y
|
- (viewport_size.rotated(Global.camera.rotation).y / 2) * zoom.y
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
var string := (
|
var string := (
|
||||||
"%spx"
|
"%spx"
|
||||||
% str(stepify(mouse_pos.y if type == Types.HORIZONTAL else mouse_pos.x, 0.5))
|
% str(stepify(mouse_pos.y if type == Types.HORIZONTAL else mouse_pos.x, 0.5))
|
||||||
)
|
)
|
||||||
var color: Color = Global.control.theme.get_color("font_color", "Label")
|
var color: Color = Global.control.theme.get_color("font_color", "Label")
|
||||||
# X and Y offsets for nicer looking spacing
|
# X and Y offsets for nicer looking spacing
|
||||||
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
|
||||||
|
|
||||||
# Draw the string where the guide intersects with the viewport poly
|
var font_string_size := font.get_string_size(string)
|
||||||
# Priority is top edge, then left, then right
|
var font_height := font.get_height()
|
||||||
var intersection = Geometry.segment_intersects_segment_2d(
|
# Draw the string where the guide intersects with the viewport poly
|
||||||
points[0], points[1], viewport_poly[0], viewport_poly[1]
|
# Priority is top edge, then left, then right
|
||||||
)
|
var intersection = Geometry.segment_intersects_segment_2d(
|
||||||
if intersection:
|
points[0], points[1], viewport_poly[0], viewport_poly[1]
|
||||||
draw_set_transform(intersection, Global.camera.rotation, zoom * 2)
|
)
|
||||||
if (
|
|
||||||
intersection.distance_squared_to(viewport_poly[0])
|
|
||||||
< intersection.distance_squared_to(viewport_poly[1])
|
|
||||||
):
|
|
||||||
draw_string(font, Vector2(x_offset, font.get_height()), string, color)
|
|
||||||
else:
|
|
||||||
draw_string(
|
|
||||||
font,
|
|
||||||
Vector2(-font.get_string_size(string).x - x_offset, font.get_height()),
|
|
||||||
string,
|
|
||||||
color
|
|
||||||
)
|
|
||||||
return
|
|
||||||
intersection = Geometry.segment_intersects_segment_2d(
|
|
||||||
points[0], points[1], viewport_poly[3], viewport_poly[0]
|
|
||||||
)
|
|
||||||
if intersection:
|
|
||||||
draw_set_transform(intersection, Global.camera.rotation, zoom * 2)
|
|
||||||
if (
|
|
||||||
intersection.distance_squared_to(viewport_poly[3])
|
|
||||||
< intersection.distance_squared_to(viewport_poly[0])
|
|
||||||
):
|
|
||||||
draw_string(font, Vector2(x_offset, y_offset), string, color)
|
|
||||||
else:
|
|
||||||
draw_string(font, Vector2(x_offset, font.get_height()), string, color)
|
|
||||||
return
|
|
||||||
intersection = Geometry.segment_intersects_segment_2d(
|
|
||||||
points[0], points[1], viewport_poly[1], viewport_poly[2]
|
|
||||||
)
|
|
||||||
if intersection:
|
|
||||||
draw_set_transform(intersection, Global.camera.rotation, zoom * 2)
|
|
||||||
if (
|
|
||||||
intersection.distance_squared_to(viewport_poly[1])
|
|
||||||
< intersection.distance_squared_to(viewport_poly[2])
|
|
||||||
):
|
|
||||||
draw_string(
|
|
||||||
font,
|
|
||||||
Vector2(-font.get_string_size(string).x - x_offset, font.get_height()),
|
|
||||||
string,
|
|
||||||
color
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
draw_string(
|
|
||||||
font,
|
|
||||||
Vector2(-font.get_string_size(string).x - x_offset, y_offset),
|
|
||||||
string,
|
|
||||||
color
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
# If there's no intersection with a viewport edge, show string in top left corner
|
if intersection:
|
||||||
draw_set_transform(viewport_poly[0], Global.camera.rotation, zoom * 2)
|
draw_set_transform(intersection, Global.camera.rotation, zoom * 2)
|
||||||
draw_string(font, Vector2(x_offset, font.get_height()), string, color)
|
if (
|
||||||
|
intersection.distance_squared_to(viewport_poly[0])
|
||||||
|
< intersection.distance_squared_to(viewport_poly[1])
|
||||||
|
):
|
||||||
|
draw_string(font, Vector2(x_offset, font_height), string, color)
|
||||||
|
else:
|
||||||
|
draw_string(font, Vector2(-font_string_size.x - x_offset, font_height), string, color)
|
||||||
|
return
|
||||||
|
|
||||||
|
intersection = Geometry.segment_intersects_segment_2d(
|
||||||
|
points[0], points[1], viewport_poly[3], viewport_poly[0]
|
||||||
|
)
|
||||||
|
if intersection:
|
||||||
|
draw_set_transform(intersection, Global.camera.rotation, zoom * 2)
|
||||||
|
if (
|
||||||
|
intersection.distance_squared_to(viewport_poly[3])
|
||||||
|
< intersection.distance_squared_to(viewport_poly[0])
|
||||||
|
):
|
||||||
|
draw_string(font, Vector2(x_offset, y_offset), string, color)
|
||||||
|
else:
|
||||||
|
draw_string(font, Vector2(x_offset, font_height), string, color)
|
||||||
|
return
|
||||||
|
|
||||||
|
intersection = Geometry.segment_intersects_segment_2d(
|
||||||
|
points[0], points[1], viewport_poly[1], viewport_poly[2]
|
||||||
|
)
|
||||||
|
|
||||||
|
if intersection:
|
||||||
|
draw_set_transform(intersection, Global.camera.rotation, zoom * 2)
|
||||||
|
if (
|
||||||
|
intersection.distance_squared_to(viewport_poly[1])
|
||||||
|
< intersection.distance_squared_to(viewport_poly[2])
|
||||||
|
):
|
||||||
|
draw_string(font, Vector2(-font_string_size.x - x_offset, font_height), string, color)
|
||||||
|
else:
|
||||||
|
draw_string(font, Vector2(-font_string_size.x - x_offset, y_offset), string, color)
|
||||||
|
return
|
||||||
|
|
||||||
|
# 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_string(font, Vector2(x_offset, font_height), string, color)
|
||||||
|
|
||||||
|
|
||||||
func outside_canvas() -> bool:
|
func outside_canvas() -> bool:
|
||||||
|
|
Loading…
Add table
Reference in a new issue