From fdc8c05f0731b6ca7f3986ad7d2bc9cc710fb48e Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Wed, 31 Jul 2024 03:52:30 +0300 Subject: [PATCH] Optimize shape drawing Shape previews also need to be optimized somehow, including some of the selection tool's previews --- src/Classes/Drawers.gd | 4 +++- src/Tools/BaseShapeDrawer.gd | 7 ++++++- src/Tools/BaseShapeDrawer.tscn | 17 +++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Classes/Drawers.gd b/src/Classes/Drawers.gd index 669ab0bd7..e0ad0c600 100644 --- a/src/Classes/Drawers.gd +++ b/src/Classes/Drawers.gd @@ -69,12 +69,14 @@ func set_pixel(image: Image, position: Vector2i, color: Color, ignore_mirroring var project := Global.current_project if not Tools.check_alpha_lock(image, position): drawers[0].set_pixel(image, position, color, color_op) + SteamManager.set_achievement("ACH_FIRST_PIXEL") if ignore_mirroring: return + if not Tools.horizontal_mirror and not Tools.vertical_mirror: + return # Handle mirroring var mirrored_positions := Tools.get_mirrored_positions(position, project) for i in mirrored_positions.size(): var mirror_pos := mirrored_positions[i] if project.can_pixel_get_drawn(mirror_pos) && not Tools.check_alpha_lock(image, mirror_pos): drawers[i + 1].set_pixel(image, mirror_pos, color, color_op) - SteamManager.set_achievement("ACH_FIRST_PIXEL") diff --git a/src/Tools/BaseShapeDrawer.gd b/src/Tools/BaseShapeDrawer.gd index ad36b6ff0..2b9c77c72 100644 --- a/src/Tools/BaseShapeDrawer.gd +++ b/src/Tools/BaseShapeDrawer.gd @@ -179,11 +179,16 @@ func _draw_shape(origin: Vector2i, dest: Vector2i) -> void: var rect := _get_result_rect(origin, dest) var points := _get_points(rect.size) prepare_undo("Draw Shape") + var images := _get_selected_draw_images() + var thickness_vector := rect.position - Vector2i((Vector2(0.5, 0.5) * (_thickness - 1)).ceil()) for point in points: # Reset drawer every time because pixel perfect sometimes breaks the tool _drawer.reset() # Draw each point offsetted based on the shape's thickness - draw_tool(rect.position + point - Vector2i((Vector2(0.5, 0.5) * (_thickness - 1)).ceil())) + var draw_pos := point + thickness_vector + if Global.current_project.can_pixel_get_drawn(draw_pos): + for image in images: + _drawer.set_pixel(image, draw_pos, tool_slot.color) commit_undo() diff --git a/src/Tools/BaseShapeDrawer.tscn b/src/Tools/BaseShapeDrawer.tscn index 3d7c6c2a4..243e93646 100644 --- a/src/Tools/BaseShapeDrawer.tscn +++ b/src/Tools/BaseShapeDrawer.tscn @@ -1,9 +1,13 @@ -[gd_scene load_steps=4 format=3 uid="uid://n40lhf8hm7o1"] +[gd_scene load_steps=5 format=3 uid="uid://n40lhf8hm7o1"] [ext_resource type="Script" path="res://src/Tools/BaseShapeDrawer.gd" id="1"] [ext_resource type="PackedScene" uid="uid://ubyatap3sylf" path="res://src/Tools/BaseDraw.tscn" id="2"] [ext_resource type="PackedScene" uid="uid://yjhp0ssng2mp" path="res://src/UI/Nodes/ValueSlider.tscn" id="3"] +[sub_resource type="ButtonGroup" id="ButtonGroup_mvrqm"] +resource_name = "rotate" +allow_unpress = true + [node name="ToolOptions" instance=ExtResource("2")] script = ExtResource("1") @@ -22,7 +26,16 @@ tooltip_text = "Fills the drawn shape with color, instead of drawing a hollow sh mouse_default_cursor_shape = 2 text = "Fill Shape" -[node name="Brush" parent="." index="4"] +[node name="Rotate90" parent="RotationOptions/Rotate" index="0"] +button_group = SubResource("ButtonGroup_mvrqm") + +[node name="Rotate180" parent="RotationOptions/Rotate" index="1"] +button_group = SubResource("ButtonGroup_mvrqm") + +[node name="Rotate270" parent="RotationOptions/Rotate" index="2"] +button_group = SubResource("ButtonGroup_mvrqm") + +[node name="Brush" parent="." index="5"] visible = false [connection signal="value_changed" from="ThicknessSlider" to="." method="_on_Thickness_value_changed"]