1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

add follow canvas movement and scale option to transparent checker (#311)

This commit is contained in:
Kinwailo 2020-08-18 03:30:58 +08:00 committed by GitHub
parent b998c87bcc
commit 39808082b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 93 additions and 7 deletions

View file

@ -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

View file

@ -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()

View file

@ -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"]:

View file

@ -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

View file

@ -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;

View file

@ -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:

View file

@ -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:

View file

@ -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)

View file

@ -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"]