Skip to content

Commit

Permalink
feature: layer focus using shortcut '.' (blender like)
Browse files Browse the repository at this point in the history
  • Loading branch information
ywmaa committed Aug 23, 2023
1 parent e280824 commit 8aa9d90
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
4 changes: 2 additions & 2 deletions UI/panels/graph/Camera2D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const KEY_MOVE_ACTION_NAMES := ["ui_left", "ui_right", "ui_up", "ui_down"]
const CAMERA_SPEED_RATE := 15.0

var zoom_min := Vector2(0.005, 0.005)
var zoom_max := Vector2.ONE
var zoom_max := Vector2(5,5)
var viewport_container: SubViewportContainer
var transparent_checker: ColorRect
var mouse_pos := Vector2.ZERO
Expand Down Expand Up @@ -223,7 +223,7 @@ func fit_to_frame(size: Vector2) -> void:
ratio = 0.1 # Set it to a non-zero value just in case

ratio = clamp(ratio, 0.1, ratio)
zoom = Vector2(1 / ratio, 1 / ratio)
zoom = Vector2(1 / ratio, 1 / ratio) - (Vector2.ONE*0.01)
zoom_changed()


Expand Down
21 changes: 21 additions & 0 deletions UI/panels/graph/graph.gd
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,27 @@ func _process(_delta):
if Input.is_action_just_pressed("show_tool_bar"):
tool_bar.visible = !tool_bar.visible
ToolsManager.camera = camera
if Input.is_action_just_pressed("focus"):
if ProjectsManager.project.layers.selected_layers.is_empty():
return
var camera_position = Vector2.ZERO
for layer in ProjectsManager.project.layers.selected_layers:
camera_position += layer.main_object.global_position
camera_position = camera_position/ProjectsManager.project.layers.selected_layers.size()

# var margin = Vector2(100, 100)
var r = Rect2(Vector2.ZERO, Vector2.ZERO)
for i in ProjectsManager.project.layers.selected_layers.size():
var layer = ProjectsManager.project.layers.selected_layers[i]
if i == 0:
r = Rect2(layer.main_object.global_position, layer.size*layer.scale)
continue
r = r.expand(layer.main_object.global_position)
# r = r.grow_individual(margin.x, margin.y, margin.x, margin.y)

camera.fit_to_frame(r.size)
camera.offset = camera_position




Expand Down
6 changes: 6 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ crop={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":67,"key_label":0,"unicode":99,"echo":false,"script":null)
]
}
focus={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":46,"key_label":0,"unicode":46,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194436,"key_label":0,"unicode":46,"echo":false,"script":null)
]
}

[rendering]

Expand Down
10 changes: 5 additions & 5 deletions src/layers/paint_layer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func refresh():
position = Vector2.ZERO #Just Invoking the setter, no need to assign a value


func get_rect() -> Rect2:
var graph : MTGraph = mt_globals.main_window.get_current_graph_edit()
var camera = graph.camera
var canvas_position : Vector2 = graph.size/2-camera.offset*(camera.zoom)
return Rect2(canvas_position+(main_object.position*camera.zoom)-(Vector2(10,10)*main_object.scale*camera.zoom/2),Vector2(10,10)*main_object.scale*camera.zoom)
#func get_rect() -> Rect2:
## var graph : MTGraph = mt_globals.main_window.get_current_graph_edit()
# var camera = graph.camera
# var canvas_position : Vector2 = graph.size/2-camera.offset*(camera.zoom)
# return Rect2(canvas_position+(main_object.position*camera.zoom)-(Vector2(10,10)*main_object.scale*camera.zoom/2),Vector2(10,10)*main_object.scale*camera.zoom)

0 comments on commit 8aa9d90

Please sign in to comment.