mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-03-03 18:13:16 +00:00
code improvements
This commit is contained in:
parent
cd5e7cc254
commit
faaa692d1f
3 changed files with 20 additions and 21 deletions
|
@ -29,6 +29,8 @@ func _draw() -> void:
|
||||||
|
|
||||||
func draw_move_measurement():
|
func draw_move_measurement():
|
||||||
var p_size = Global.current_project.size
|
var p_size = Global.current_project.size
|
||||||
|
var dashed_color = line_color
|
||||||
|
dashed_color.a = 0.5
|
||||||
# Draw boundary
|
# Draw boundary
|
||||||
var boundary = Rect2i(rect_bounds)
|
var boundary = Rect2i(rect_bounds)
|
||||||
boundary.position += Global.canvas.move_preview_location
|
boundary.position += Global.canvas.move_preview_location
|
||||||
|
@ -63,29 +65,23 @@ func draw_move_measurement():
|
||||||
lines.append([bottom, p_vertical[0]])
|
lines.append([bottom, p_vertical[0]])
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if !Rect2i(Vector2.ZERO, p_size + Vector2i.ONE).has_point(line[1]):
|
if !Rect2i(Vector2.ZERO, p_size + Vector2i.ONE).has_point(line[1]):
|
||||||
|
var point_a := Vector2.ZERO
|
||||||
|
var point_b := Vector2.ZERO
|
||||||
# project lines if needed
|
# project lines if needed
|
||||||
if line[1] == p_vertical[0]: # upper horizontal projection
|
if line[1] == p_vertical[0]: # upper horizontal projection
|
||||||
draw_dashed_line(
|
point_a = Vector2(p_size.x / 2, 0)
|
||||||
Vector2(p_size.x / 2, 0), Vector2(top.x, 0), line_color, apparent_width
|
point_b = Vector2(top.x, 0)
|
||||||
)
|
|
||||||
elif line[1] == p_vertical[1]: # lower horizontal projection
|
elif line[1] == p_vertical[1]: # lower horizontal projection
|
||||||
draw_dashed_line(
|
point_a = Vector2(p_size.x / 2, p_size.y)
|
||||||
Vector2(p_size.x / 2, p_size.y),
|
point_b = Vector2(bottom.x, p_size.y)
|
||||||
Vector2(bottom.x, p_size.y),
|
|
||||||
line_color,
|
|
||||||
apparent_width
|
|
||||||
)
|
|
||||||
elif line[1] == p_horizontal[0]: # left vertical projection
|
elif line[1] == p_horizontal[0]: # left vertical projection
|
||||||
draw_dashed_line(
|
point_a = Vector2(0, p_size.y / 2)
|
||||||
Vector2(0, p_size.y / 2), Vector2(0, left.y), line_color, apparent_width
|
point_b = Vector2(0, left.y)
|
||||||
)
|
|
||||||
elif line[1] == p_horizontal[1]: # right vertical projection
|
elif line[1] == p_horizontal[1]: # right vertical projection
|
||||||
draw_dashed_line(
|
point_a = Vector2(p_size.x, p_size.y / 2)
|
||||||
Vector2(p_size.x, p_size.y / 2),
|
point_b = Vector2(p_size.x, right.y)
|
||||||
Vector2(p_size.x, right.y),
|
var offset = (point_b - point_a).normalized() * (boundary.size / 2.0)
|
||||||
line_color,
|
draw_dashed_line(point_a + offset, point_b + offset, dashed_color, apparent_width)
|
||||||
apparent_width
|
|
||||||
)
|
|
||||||
draw_line(line[0], line[1], line_color, apparent_width)
|
draw_line(line[0], line[1], line_color, apparent_width)
|
||||||
var string_vec = line[0] + (line[1] - line[0]) / 2
|
var string_vec = line[0] + (line[1] - line[0]) / 2
|
||||||
draw_set_transform(Vector2.ZERO, Global.camera.rotation, Vector2.ONE / Global.camera.zoom)
|
draw_set_transform(Vector2.ZERO, Global.camera.rotation, Vector2.ONE / Global.camera.zoom)
|
||||||
|
@ -105,7 +101,10 @@ func _input(_event: InputEvent) -> void:
|
||||||
func _prepare_movement_rect():
|
func _prepare_movement_rect():
|
||||||
var project := Global.current_project
|
var project := Global.current_project
|
||||||
if project.has_selection:
|
if project.has_selection:
|
||||||
rect_bounds = Global.canvas.selection.big_bounding_rectangle
|
rect_bounds = Global.canvas.selection.preview_image.get_used_rect()
|
||||||
|
rect_bounds.position += Vector2i(
|
||||||
|
Global.canvas.selection.big_bounding_rectangle.position
|
||||||
|
)
|
||||||
return
|
return
|
||||||
if rect_bounds.has_area():
|
if rect_bounds.has_area():
|
||||||
return
|
return
|
||||||
|
|
|
@ -78,5 +78,3 @@ func _draw() -> void:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
draw_set_transform(viewport_poly[0], Global.camera.rotation, zoom / 2)
|
|
||||||
|
|
|
@ -5,10 +5,12 @@
|
||||||
[node name="MouseGuideContainer" type="Node2D"]
|
[node name="MouseGuideContainer" type="Node2D"]
|
||||||
|
|
||||||
[node name="Vertical" type="Line2D" parent="."]
|
[node name="Vertical" type="Line2D" parent="."]
|
||||||
|
visible = false
|
||||||
points = PackedVector2Array(0, 19999, 0, -19999)
|
points = PackedVector2Array(0, 19999, 0, -19999)
|
||||||
script = ExtResource("2")
|
script = ExtResource("2")
|
||||||
|
|
||||||
[node name="Horizontal" type="Line2D" parent="."]
|
[node name="Horizontal" type="Line2D" parent="."]
|
||||||
|
visible = false
|
||||||
points = PackedVector2Array(-19999, 0, 19999, 0)
|
points = PackedVector2Array(-19999, 0, 19999, 0)
|
||||||
script = ExtResource("2")
|
script = ExtResource("2")
|
||||||
type = 1
|
type = 1
|
||||||
|
|
Loading…
Add table
Reference in a new issue