diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 1c04c1630..1d8410575 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -57,6 +57,8 @@ var guide_color := Color.purple var checker_size := 10 var checker_color_1 := Color(0.47, 0.47, 0.47, 1) var checker_color_2 := Color(0.34, 0.35, 0.34, 1) +var checker_follow_movement := false +var checker_follow_scale := false var autosave_interval := 1.0 var enable_autosave := true diff --git a/src/CameraMovement.gd b/src/CameraMovement.gd index 0446f62b9..64759f4aa 100644 --- a/src/CameraMovement.gd +++ b/src/CameraMovement.gd @@ -5,17 +5,26 @@ var tween : Tween var zoom_min := Vector2(0.005, 0.005) var zoom_max := Vector2.ONE var viewport_container : ViewportContainer +var transparent_checker : ColorRect var mouse_pos := Vector2.ZERO var drag := false func _ready() -> void: viewport_container = get_parent().get_parent() + transparent_checker = get_parent().get_node("TransparentChecker") tween = Tween.new() add_child(tween) tween.connect("tween_step", self, "_on_tween_step") + update_transparent_checker_offset() +func update_transparent_checker_offset() -> void: + var o = get_global_transform_with_canvas().get_origin() + var s = get_global_transform_with_canvas().get_scale() + o.y = get_viewport_rect().size.y - o.y + transparent_checker.update_offset(o, s) + # Get the speed multiplier for when you've pressed # a movement key for the given amount of time func dir_move_zoom_multiplier(press_time : float) -> float: @@ -92,6 +101,7 @@ func process_direction_action_pressed(event: InputEvent) -> void: var this_direction_press_time : float = Global.key_move_press_time[dir] var move_speed := dir_move_zoom_multiplier(this_direction_press_time) offset = offset + move_speed * increment * directional_sign_multipliers[dir] * zoom + update_transparent_checker_offset() # Process an action for a release direction action @@ -117,6 +127,7 @@ func _input(event : InputEvent) -> void: zoom_camera(1) elif event is InputEventMouseMotion && drag: offset = offset - event.relative * zoom + update_transparent_checker_offset() elif is_action_direction_pressed(event): process_direction_action_pressed(event) elif is_action_direction_released(event): @@ -154,6 +165,7 @@ func zoom_camera(dir : int) -> void: zoom = zoom_max offset = offset + (-0.5 * viewport_size + mouse_pos) * (prev_zoom - zoom) + update_transparent_checker_offset() if name == "Camera2D": Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %" elif name == "CameraPreview": @@ -163,6 +175,16 @@ func zoom_camera(dir : int) -> void: func _on_tween_step(_object: Object, _key: NodePath, _elapsed: float, _value: Object) -> void: Global.horizontal_ruler.update() Global.vertical_ruler.update() + update_transparent_checker_offset() + + +func zoom_100(): + zoom = Vector2.ONE + offset = Global.current_project.size / 2 + update_transparent_checker_offset() + Global.zoom_level_label.text = str(round(100 / zoom.x)) + " %" + Global.horizontal_ruler.update() + Global.vertical_ruler.update() func fit_to_frame(size : Vector2) -> void: @@ -185,6 +207,7 @@ func fit_to_frame(size : Vector2) -> void: zoom = Vector2(1 / ratio, 1 / ratio) offset = size / 2 + update_transparent_checker_offset() if name == "Camera2D": Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %" Global.horizontal_ruler.update() diff --git a/src/Preferences/PreferencesDialog.gd b/src/Preferences/PreferencesDialog.gd index 0ab70d109..003e6a8ff 100644 --- a/src/Preferences/PreferencesDialog.gd +++ b/src/Preferences/PreferencesDialog.gd @@ -23,6 +23,8 @@ var preferences = [ ["checker_size", "Canvas/CheckerOptions/CheckerSizeValue", "value", Global.checker_size], ["checker_color_1", "Canvas/CheckerOptions/CheckerColor1", "color", Global.checker_color_1], ["checker_color_2", "Canvas/CheckerOptions/CheckerColor2", "color", Global.checker_color_2], + ["checker_follow_movement", "Canvas/CheckerOptions/CheckerFollowMovement", "pressed", Global.checker_follow_movement], + ["checker_follow_scale", "Canvas/CheckerOptions/CheckerFollowScale", "pressed", Global.checker_follow_scale], ] var selected_item := 0 @@ -116,7 +118,7 @@ func preference_update(prop : String) -> void: if prop in ["grid_width", "grid_height", "grid_color"]: Global.canvas.update() - if prop in ["checker_size", "checker_color_1", "checker_color_2"]: + if prop in ["checker_size", "checker_color_1", "checker_color_2", "checker_follow_movement", "checker_follow_scale"]: Global.transparent_checker._ready() if prop in ["guide_color"]: diff --git a/src/Preferences/PreferencesDialog.tscn b/src/Preferences/PreferencesDialog.tscn index 767311597..406800613 100644 --- a/src/Preferences/PreferencesDialog.tscn +++ b/src/Preferences/PreferencesDialog.tscn @@ -356,6 +356,38 @@ hint_tooltip = "Second color of the transparent checker background" mouse_default_cursor_shape = 2 color = Color( 0.341176, 0.34902, 0.341176, 1 ) +[node name="Label" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/CheckerOptions"] +margin_top = -181.0 +margin_right = 110.0 +margin_bottom = -167.0 +rect_min_size = Vector2( 110, 0 ) +text = "Follow Canvas Movement" + +[node name="CheckerFollowMovement" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/CheckerOptions"] +margin_left = 114.0 +margin_top = -186.0 +margin_right = 161.0 +margin_bottom = -162.0 +hint_tooltip = "The transparent checker follow the movement of canvas " +mouse_default_cursor_shape = 2 +text = "On" + +[node name="Label2" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/CheckerOptions"] +margin_top = -181.0 +margin_right = 110.0 +margin_bottom = -167.0 +rect_min_size = Vector2( 110, 0 ) +text = "Follow Canvas Zoom Level" + +[node name="CheckerFollowScale" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/CheckerOptions"] +margin_left = 114.0 +margin_top = -186.0 +margin_right = 161.0 +margin_bottom = -162.0 +hint_tooltip = "The transparent checker follow the zoom level of canvas " +mouse_default_cursor_shape = 2 +text = "On" + [node name="Image" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"] visible = false margin_top = 240.0 diff --git a/src/Shaders/TransparentChecker.shader b/src/Shaders/TransparentChecker.shader index c4ac57ba6..ff5c4bb55 100644 --- a/src/Shaders/TransparentChecker.shader +++ b/src/Shaders/TransparentChecker.shader @@ -4,9 +4,24 @@ render_mode unshaded; uniform float size = 10.0; uniform vec4 color1 : hint_color = vec4(0.7, 0.7, 0.7, 1.0); uniform vec4 color2 : hint_color = vec4(1.0); +uniform vec2 offset = vec2(0.0); +uniform vec2 scale = vec2(0.0); +uniform vec2 rect_size = vec2(0.0); +uniform bool follow_movement = false; +uniform bool follow_scale = false; void fragment() { - vec2 pos = mod(FRAGCOORD.xy, size * 2.0); + vec2 ref_pos = FRAGCOORD.xy; + if (follow_scale) { + if (!follow_movement) + ref_pos /= scale; + else + ref_pos = UV * rect_size; + } + else if (follow_movement) + ref_pos -= mod(offset, size * 2.0); + + vec2 pos = mod(ref_pos, size * 2.0); bool c1 = any(lessThan(pos, vec2(size))); bool c2 = any(greaterThanEqual(pos, vec2(size))); float c = c1 && c2 ? 1.0: 0.0; diff --git a/src/Tools/Zoom.gd b/src/Tools/Zoom.gd index 01f6a15d3..a04d57727 100644 --- a/src/Tools/Zoom.gd +++ b/src/Tools/Zoom.gd @@ -15,11 +15,7 @@ func _on_FitToFrame_pressed(): func _on_100_pressed(): - Global.camera.zoom = Vector2.ONE - Global.camera.offset = Global.current_project.size / 2 - Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %" - Global.horizontal_ruler.update() - Global.vertical_ruler.update() + Global.camera.zoom_100() func get_config() -> Dictionary: diff --git a/src/UI/CanvasPreviewContainer.gd b/src/UI/CanvasPreviewContainer.gd index 35ce94f52..28a74c453 100644 --- a/src/UI/CanvasPreviewContainer.gd +++ b/src/UI/CanvasPreviewContainer.gd @@ -9,6 +9,7 @@ onready var play_button : Button = $SettingsContainer/VBoxContainer/PlayButton func _on_PreviewZoomSlider_value_changed(value : float) -> void: camera.zoom = -Vector2(value, value) camera.save_values_to_project() + camera.update_transparent_checker_offset() func _on_PlayButton_toggled(button_pressed : bool) -> void: diff --git a/src/UI/TransparentChecker.gd b/src/UI/TransparentChecker.gd index 2b5c98955..158233c49 100644 --- a/src/UI/TransparentChecker.gd +++ b/src/UI/TransparentChecker.gd @@ -9,3 +9,14 @@ func _ready() -> void: material.set_shader_param("size", Global.checker_size) material.set_shader_param("color1", Global.checker_color_1) material.set_shader_param("color2", Global.checker_color_2) + material.set_shader_param("follow_movement", Global.checker_follow_movement) + material.set_shader_param("follow_scale", Global.checker_follow_scale) + + +func update_offset(offset : Vector2, scale : Vector2) -> void: + material.set_shader_param("offset", offset) + material.set_shader_param("scale", scale) + + +func _on_TransparentChecker_resized(): + material.set_shader_param("rect_size", rect_size) diff --git a/src/UI/TransparentChecker.tscn b/src/UI/TransparentChecker.tscn index 9b01ef466..7fa0d5116 100644 --- a/src/UI/TransparentChecker.tscn +++ b/src/UI/TransparentChecker.tscn @@ -15,3 +15,7 @@ margin_right = 40.0 margin_bottom = 40.0 mouse_filter = 2 script = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} +[connection signal="resized" from="." to="." method="_on_TransparentChecker_resized"]