mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-06-24 08:54:43 -04:00
Basic move tool
This commit is contained in:
parent
45be4ee6b7
commit
190234ff39
8 changed files with 142 additions and 19 deletions
|
@ -444,6 +444,16 @@ show_pixel_grid={
|
|||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":72,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
left_move_tool={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":84,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
right_move_tool={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":true,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":84,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[locale]
|
||||
|
||||
|
|
|
@ -468,9 +468,10 @@ func change_button_texturerect(texture_button : TextureRect, new_file_name : Str
|
|||
|
||||
|
||||
func update_hint_tooltips() -> void:
|
||||
var root = get_tree().get_root()
|
||||
var root = control
|
||||
var tool_buttons = root.find_node("ToolButtons")
|
||||
|
||||
var rect_select : BaseButton = find_node_by_name(root, "RectSelect")
|
||||
var rect_select : BaseButton = tool_buttons.find_node("RectSelect")
|
||||
rect_select.hint_tooltip = tr("""Rectangular Selection
|
||||
|
||||
%s for left mouse button
|
||||
|
@ -478,6 +479,13 @@ func update_hint_tooltips() -> void:
|
|||
|
||||
Press %s to move the content""") % [InputMap.get_action_list("left_rectangle_select_tool")[0].as_text(), InputMap.get_action_list("right_rectangle_select_tool")[0].as_text(), "Shift"]
|
||||
|
||||
var move_select : BaseButton = tool_buttons.find_node("Move")
|
||||
move_select.hint_tooltip = tr("""Move
|
||||
|
||||
%s for left mouse button
|
||||
%s for right mouse button""") % [InputMap.get_action_list("left_move_tool")[0].as_text(), InputMap.get_action_list("right_move_tool")[0].as_text()]
|
||||
|
||||
|
||||
var zoom_tool : BaseButton = find_node_by_name(root, "Zoom")
|
||||
zoom_tool.hint_tooltip = tr("""Zoom
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ signal color_changed(color, button)
|
|||
|
||||
var _tools = {
|
||||
"RectSelect" : "res://src/Tools/RectSelect.tscn",
|
||||
"Move" : "res://src/Tools/Move.tscn",
|
||||
"Zoom" : "res://src/Tools/Zoom.tscn",
|
||||
"Pan" : "res://src/Tools/Pan.tscn",
|
||||
"ColorPicker" : "res://src/Tools/ColorPicker.tscn",
|
||||
|
|
55
src/Tools/Move.gd
Normal file
55
src/Tools/Move.gd
Normal file
|
@ -0,0 +1,55 @@
|
|||
extends BaseTool
|
||||
|
||||
|
||||
var starting_pos : Vector2
|
||||
var offset : Vector2
|
||||
|
||||
|
||||
func draw_start(position : Vector2) -> void:
|
||||
starting_pos = position
|
||||
offset = position
|
||||
if Global.current_project.selected_pixels:
|
||||
Global.selection_rectangle.move_start(true)
|
||||
|
||||
|
||||
func draw_move(position : Vector2) -> void:
|
||||
if Global.current_project.selected_pixels:
|
||||
Global.selection_rectangle.move_rect(position - offset)
|
||||
else:
|
||||
Global.canvas.move_preview_location = position - starting_pos
|
||||
offset = position
|
||||
|
||||
|
||||
func draw_end(position : Vector2) -> void:
|
||||
if starting_pos != Vector2.INF:
|
||||
var pixel_diff : Vector2 = position - starting_pos
|
||||
if pixel_diff != Vector2.ZERO:
|
||||
var project : Project = Global.current_project
|
||||
var image : Image = _get_draw_image()
|
||||
# var pixels := []
|
||||
# if project.selected_pixels:
|
||||
# pixels = project.selected_pixels.duplicate()
|
||||
# else:
|
||||
# for x in Global.current_project.size.x:
|
||||
# for y in Global.current_project.size.y:
|
||||
# var pos := Vector2(x, y)
|
||||
# pixels.append([pos, image.get_pixelv(pos)])
|
||||
|
||||
# print(pixels[3])
|
||||
if project.selected_pixels:
|
||||
Global.selection_rectangle.move_end()
|
||||
else:
|
||||
Global.canvas.move_preview_location = Vector2.ZERO
|
||||
var image_copy := Image.new()
|
||||
image_copy.copy_from(image)
|
||||
Global.canvas.handle_undo("Draw")
|
||||
image.fill(Color(0, 0, 0, 0))
|
||||
# image.blit_rect(image_copy, Rect2(Vector2.ZERO, project.size), pixel_diff)
|
||||
image.blit_rect(image_copy, Rect2(Vector2.ZERO, project.size), pixel_diff)
|
||||
# for pixel in pixels:
|
||||
## image.set_pixelv(pixel[0] + pixel_diff, Color.red)
|
||||
# image.set_pixelv(pixel[0] + pixel_diff, pixel[1])
|
||||
Global.canvas.handle_redo("Draw")
|
||||
|
||||
print(pixel_diff)
|
||||
starting_pos = Vector2.INF
|
23
src/Tools/Move.tscn
Normal file
23
src/Tools/Move.tscn
Normal file
|
@ -0,0 +1,23 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://src/Tools/BaseTool.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://src/Tools/Move.gd" type="Script" id=2]
|
||||
|
||||
|
||||
[node name="ToolOptions" instance=ExtResource( 1 )]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="PixelPerfect" parent="." index="1"]
|
||||
visible = false
|
||||
margin_top = 126.0
|
||||
margin_bottom = 150.0
|
||||
|
||||
[node name="EmptySpacer" parent="." index="2"]
|
||||
visible = false
|
||||
margin_top = 126.0
|
||||
margin_bottom = 138.0
|
||||
|
||||
[node name="Mirror" parent="." index="3"]
|
||||
visible = false
|
||||
margin_top = 126.0
|
||||
margin_bottom = 143.0
|
|
@ -7,6 +7,7 @@ var current_pixel := Vector2.ZERO
|
|||
var can_undo := true
|
||||
var cursor_image_has_changed := false
|
||||
var sprite_changed_this_frame := false # for optimization purposes
|
||||
var move_preview_location := Vector2.ZERO
|
||||
|
||||
onready var currently_visible_frame : Viewport = $CurrentlyVisibleFrame
|
||||
onready var current_frame_drawer = $CurrentlyVisibleFrame/CurrentFrameDrawer
|
||||
|
@ -29,7 +30,7 @@ func _draw() -> void:
|
|||
Global.small_preview_viewport.get_child(0).get_node("CanvasPreview").update()
|
||||
|
||||
var current_cels : Array = Global.current_project.frames[Global.current_project.current_frame].cels
|
||||
|
||||
var current_layer : int = Global.current_project.current_layer
|
||||
var _position := position
|
||||
var _scale := scale
|
||||
if Global.mirror_view:
|
||||
|
@ -40,7 +41,10 @@ func _draw() -> void:
|
|||
for i in range(Global.current_project.layers.size()):
|
||||
var modulate_color := Color(1, 1, 1, current_cels[i].opacity)
|
||||
if Global.current_project.layers[i].visible: # if it's visible
|
||||
draw_texture(current_cels[i].image_texture, Vector2.ZERO, modulate_color)
|
||||
if i == current_layer:
|
||||
draw_texture(current_cels[i].image_texture, move_preview_location, modulate_color)
|
||||
else:
|
||||
draw_texture(current_cels[i].image_texture, Vector2.ZERO, modulate_color)
|
||||
|
||||
if Global.onion_skinning:
|
||||
onion_skinning()
|
||||
|
|
|
@ -4,6 +4,7 @@ extends VBoxContainer
|
|||
# Node, shortcut
|
||||
onready var tools := [
|
||||
[$RectSelect, "rectangle_select"],
|
||||
[$Move, "move"],
|
||||
[$Zoom, "zoom"],
|
||||
[$Pan, "pan"],
|
||||
[$ColorPicker, "colorpicker"],
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=27 format=2]
|
||||
[gd_scene load_steps=28 format=2]
|
||||
|
||||
[ext_resource path="res://src/UI/ToolButtons.gd" type="Script" id=1]
|
||||
[ext_resource path="res://src/UI/Canvas/CanvasPreview.tscn" type="PackedScene" id=2]
|
||||
|
@ -23,10 +23,12 @@
|
|||
[ext_resource path="res://assets/graphics/dark_themes/tools/zoom.png" type="Texture" id=21]
|
||||
[ext_resource path="res://assets/graphics/dark_themes/tools/pan.png" type="Texture" id=22]
|
||||
[ext_resource path="res://src/UI/ViewportContainer.gd" type="Script" id=23]
|
||||
[ext_resource path="res://assets/graphics/dark_themes/tools/move.png" type="Texture" id=24]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=1]
|
||||
shader = ExtResource( 9 )
|
||||
shader_param/size = 10.0
|
||||
shader_param/alpha = 1.0
|
||||
shader_param/color1 = Color( 0.7, 0.7, 0.7, 1 )
|
||||
shader_param/color2 = Color( 1, 1, 1, 1 )
|
||||
shader_param/offset = Vector2( 0, 0 )
|
||||
|
@ -38,6 +40,7 @@ shader_param/follow_scale = false
|
|||
[sub_resource type="ShaderMaterial" id=2]
|
||||
shader = ExtResource( 9 )
|
||||
shader_param/size = 10.0
|
||||
shader_param/alpha = 1.0
|
||||
shader_param/color1 = Color( 0.7, 0.7, 0.7, 1 )
|
||||
shader_param/color2 = Color( 1, 1, 1, 1 )
|
||||
shader_param/offset = Vector2( 0, 0 )
|
||||
|
@ -84,7 +87,7 @@ __meta__ = {
|
|||
margin_left = 7.0
|
||||
margin_top = 7.0
|
||||
margin_right = 39.0
|
||||
margin_bottom = 291.0
|
||||
margin_bottom = 327.0
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 0
|
||||
script = ExtResource( 1 )
|
||||
|
@ -109,7 +112,7 @@ __meta__ = {
|
|||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Zoom" type="Button" parent="ToolPanel/PanelContainer/ToolButtons" groups=[
|
||||
[node name="Move" type="Button" parent="ToolPanel/PanelContainer/ToolButtons" groups=[
|
||||
"UIButtons",
|
||||
]]
|
||||
margin_top = 36.0
|
||||
|
@ -119,6 +122,24 @@ rect_min_size = Vector2( 32, 32 )
|
|||
mouse_default_cursor_shape = 2
|
||||
button_mask = 3
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="ToolPanel/PanelContainer/ToolButtons/Move"]
|
||||
margin_right = 32.0
|
||||
margin_bottom = 32.0
|
||||
texture = ExtResource( 24 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Zoom" type="Button" parent="ToolPanel/PanelContainer/ToolButtons" groups=[
|
||||
"UIButtons",
|
||||
]]
|
||||
margin_top = 72.0
|
||||
margin_right = 32.0
|
||||
margin_bottom = 104.0
|
||||
rect_min_size = Vector2( 32, 32 )
|
||||
mouse_default_cursor_shape = 2
|
||||
button_mask = 3
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="ToolPanel/PanelContainer/ToolButtons/Zoom"]
|
||||
margin_right = 32.0
|
||||
margin_bottom = 32.0
|
||||
|
@ -130,9 +151,9 @@ __meta__ = {
|
|||
[node name="Pan" type="Button" parent="ToolPanel/PanelContainer/ToolButtons" groups=[
|
||||
"UIButtons",
|
||||
]]
|
||||
margin_top = 72.0
|
||||
margin_top = 108.0
|
||||
margin_right = 32.0
|
||||
margin_bottom = 104.0
|
||||
margin_bottom = 140.0
|
||||
rect_min_size = Vector2( 32, 32 )
|
||||
mouse_default_cursor_shape = 2
|
||||
button_mask = 3
|
||||
|
@ -148,9 +169,9 @@ __meta__ = {
|
|||
[node name="ColorPicker" type="Button" parent="ToolPanel/PanelContainer/ToolButtons" groups=[
|
||||
"UIButtons",
|
||||
]]
|
||||
margin_top = 108.0
|
||||
margin_top = 144.0
|
||||
margin_right = 32.0
|
||||
margin_bottom = 140.0
|
||||
margin_bottom = 176.0
|
||||
rect_min_size = Vector2( 32, 32 )
|
||||
mouse_default_cursor_shape = 2
|
||||
button_mask = 3
|
||||
|
@ -166,9 +187,9 @@ __meta__ = {
|
|||
[node name="Pencil" type="Button" parent="ToolPanel/PanelContainer/ToolButtons" groups=[
|
||||
"UIButtons",
|
||||
]]
|
||||
margin_top = 144.0
|
||||
margin_top = 180.0
|
||||
margin_right = 32.0
|
||||
margin_bottom = 176.0
|
||||
margin_bottom = 212.0
|
||||
rect_min_size = Vector2( 32, 32 )
|
||||
mouse_default_cursor_shape = 2
|
||||
button_mask = 3
|
||||
|
@ -184,9 +205,9 @@ __meta__ = {
|
|||
[node name="Eraser" type="Button" parent="ToolPanel/PanelContainer/ToolButtons" groups=[
|
||||
"UIButtons",
|
||||
]]
|
||||
margin_top = 180.0
|
||||
margin_top = 216.0
|
||||
margin_right = 32.0
|
||||
margin_bottom = 212.0
|
||||
margin_bottom = 248.0
|
||||
rect_min_size = Vector2( 32, 32 )
|
||||
mouse_default_cursor_shape = 2
|
||||
button_mask = 3
|
||||
|
@ -202,9 +223,9 @@ __meta__ = {
|
|||
[node name="Bucket" type="Button" parent="ToolPanel/PanelContainer/ToolButtons" groups=[
|
||||
"UIButtons",
|
||||
]]
|
||||
margin_top = 216.0
|
||||
margin_top = 252.0
|
||||
margin_right = 32.0
|
||||
margin_bottom = 248.0
|
||||
margin_bottom = 284.0
|
||||
rect_min_size = Vector2( 32, 32 )
|
||||
mouse_default_cursor_shape = 2
|
||||
button_mask = 3
|
||||
|
@ -220,9 +241,9 @@ __meta__ = {
|
|||
[node name="LightenDarken" type="Button" parent="ToolPanel/PanelContainer/ToolButtons" groups=[
|
||||
"UIButtons",
|
||||
]]
|
||||
margin_top = 252.0
|
||||
margin_top = 288.0
|
||||
margin_right = 32.0
|
||||
margin_bottom = 284.0
|
||||
margin_bottom = 320.0
|
||||
rect_min_size = Vector2( 32, 32 )
|
||||
mouse_default_cursor_shape = 2
|
||||
button_mask = 3
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue