mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Fixed issue #9 and custom brush cursor indicator position
- Fixed issue #9 where custom brushes would get drawn outside of a rectangle selection. They only get drawn inside the selection, just like the normal pixel brush. - The custom brush cursor indicator (that follows the mouse cursor position) wasn't aligned with the image's pixels. Now it is. - Fixed small bug when opening sprites. Had to do with has_focus's initial state. - Removed Main Theme.tres because it was pointless.
This commit is contained in:
parent
eb29cd3268
commit
420ec63aeb
|
@ -1,7 +0,0 @@
|
||||||
[gd_resource type="Theme" load_steps=2 format=2]
|
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id=1]
|
|
||||||
bg_color = Color( 0.239216, 0.231373, 0.270588, 1 )
|
|
||||||
|
|
||||||
[resource]
|
|
||||||
PanelContainer/styles/panel = SubResource( 1 )
|
|
46
Main.tscn
46
Main.tscn
|
@ -1,15 +1,14 @@
|
||||||
[gd_scene load_steps=11 format=2]
|
[gd_scene load_steps=10 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Scripts/Main.gd" type="Script" id=1]
|
[ext_resource path="res://Scripts/Main.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://Main Theme.tres" type="Theme" id=2]
|
[ext_resource path="res://Assets/Graphics/left.png" type="Texture" id=2]
|
||||||
[ext_resource path="res://Assets/Graphics/left.png" type="Texture" id=3]
|
[ext_resource path="res://Assets/Graphics/right.png" type="Texture" id=3]
|
||||||
[ext_resource path="res://Assets/Graphics/right.png" type="Texture" id=4]
|
[ext_resource path="res://Prefabs/BrushButton.tscn" type="PackedScene" id=4]
|
||||||
[ext_resource path="res://Prefabs/BrushButton.tscn" type="PackedScene" id=5]
|
[ext_resource path="res://Prefabs/Canvas.tscn" type="PackedScene" id=5]
|
||||||
[ext_resource path="res://Prefabs/Canvas.tscn" type="PackedScene" id=6]
|
[ext_resource path="res://Scripts/CameraMovement.gd" type="Script" id=6]
|
||||||
[ext_resource path="res://Scripts/CameraMovement.gd" type="Script" id=7]
|
[ext_resource path="res://Scripts/SelectionRectangle.gd" type="Script" id=7]
|
||||||
[ext_resource path="res://Scripts/SelectionRectangle.gd" type="Script" id=8]
|
[ext_resource path="res://Scripts/SecondViewport.gd" type="Script" id=8]
|
||||||
[ext_resource path="res://Scripts/SecondViewport.gd" type="Script" id=9]
|
[ext_resource path="res://Scripts/AboutDialog.gd" type="Script" id=9]
|
||||||
[ext_resource path="res://Scripts/AboutDialog.gd" type="Script" id=10]
|
|
||||||
|
|
||||||
[node name="Control" type="Control"]
|
[node name="Control" type="Control"]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
|
@ -17,6 +16,7 @@ anchor_bottom = 1.0
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="UI" type="HBoxContainer" parent="."]
|
[node name="UI" type="HBoxContainer" parent="."]
|
||||||
|
editor/display_folded = true
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
|
@ -47,7 +47,6 @@ margin_bottom = 20.0
|
||||||
margin_right = 35.0
|
margin_right = 35.0
|
||||||
margin_bottom = 20.0
|
margin_bottom = 20.0
|
||||||
mouse_default_cursor_shape = 2
|
mouse_default_cursor_shape = 2
|
||||||
theme = ExtResource( 2 )
|
|
||||||
text = "File"
|
text = "File"
|
||||||
|
|
||||||
[node name="EditMenu" type="MenuButton" parent="UI/ToolPanel/Tools/MenusAndTools/MenuItems"]
|
[node name="EditMenu" type="MenuButton" parent="UI/ToolPanel/Tools/MenusAndTools/MenuItems"]
|
||||||
|
@ -55,7 +54,6 @@ margin_left = 39.0
|
||||||
margin_right = 75.0
|
margin_right = 75.0
|
||||||
margin_bottom = 20.0
|
margin_bottom = 20.0
|
||||||
mouse_default_cursor_shape = 2
|
mouse_default_cursor_shape = 2
|
||||||
theme = ExtResource( 2 )
|
|
||||||
text = "Edit"
|
text = "Edit"
|
||||||
|
|
||||||
[node name="ViewMenu" type="MenuButton" parent="UI/ToolPanel/Tools/MenusAndTools/MenuItems"]
|
[node name="ViewMenu" type="MenuButton" parent="UI/ToolPanel/Tools/MenusAndTools/MenuItems"]
|
||||||
|
@ -63,7 +61,6 @@ margin_left = 79.0
|
||||||
margin_right = 121.0
|
margin_right = 121.0
|
||||||
margin_bottom = 20.0
|
margin_bottom = 20.0
|
||||||
mouse_default_cursor_shape = 2
|
mouse_default_cursor_shape = 2
|
||||||
theme = ExtResource( 2 )
|
|
||||||
text = "View"
|
text = "View"
|
||||||
|
|
||||||
[node name="HelpMenu" type="MenuButton" parent="UI/ToolPanel/Tools/MenusAndTools/MenuItems"]
|
[node name="HelpMenu" type="MenuButton" parent="UI/ToolPanel/Tools/MenusAndTools/MenuItems"]
|
||||||
|
@ -71,7 +68,6 @@ margin_left = 125.0
|
||||||
margin_right = 167.0
|
margin_right = 167.0
|
||||||
margin_bottom = 20.0
|
margin_bottom = 20.0
|
||||||
mouse_default_cursor_shape = 2
|
mouse_default_cursor_shape = 2
|
||||||
theme = ExtResource( 2 )
|
|
||||||
text = "Help"
|
text = "Help"
|
||||||
|
|
||||||
[node name="ToolsContainer" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"]
|
[node name="ToolsContainer" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"]
|
||||||
|
@ -90,7 +86,7 @@ button_mask = 3
|
||||||
text = "Pencil"
|
text = "Pencil"
|
||||||
|
|
||||||
[node name="LeftIndicator" type="Sprite" parent="UI/ToolPanel/Tools/MenusAndTools/ToolsContainer/Pencil"]
|
[node name="LeftIndicator" type="Sprite" parent="UI/ToolPanel/Tools/MenusAndTools/ToolsContainer/Pencil"]
|
||||||
texture = ExtResource( 3 )
|
texture = ExtResource( 2 )
|
||||||
centered = false
|
centered = false
|
||||||
offset = Vector2( 0, -10 )
|
offset = Vector2( 0, -10 )
|
||||||
|
|
||||||
|
@ -106,7 +102,7 @@ button_mask = 3
|
||||||
text = "Eraser"
|
text = "Eraser"
|
||||||
|
|
||||||
[node name="RightIndicator" type="Sprite" parent="UI/ToolPanel/Tools/MenusAndTools/ToolsContainer/Eraser"]
|
[node name="RightIndicator" type="Sprite" parent="UI/ToolPanel/Tools/MenusAndTools/ToolsContainer/Eraser"]
|
||||||
texture = ExtResource( 4 )
|
texture = ExtResource( 3 )
|
||||||
centered = false
|
centered = false
|
||||||
offset = Vector2( 35, -10 )
|
offset = Vector2( 35, -10 )
|
||||||
|
|
||||||
|
@ -332,16 +328,16 @@ scroll_vertical_enabled = false
|
||||||
margin_right = 36.0
|
margin_right = 36.0
|
||||||
margin_bottom = 36.0
|
margin_bottom = 36.0
|
||||||
|
|
||||||
[node name="PixelBrushButton" parent="UI/ToolPanel/Tools/BrushesContainer/BrushHBoxContainer" instance=ExtResource( 5 )]
|
[node name="PixelBrushButton" parent="UI/ToolPanel/Tools/BrushesContainer/BrushHBoxContainer" instance=ExtResource( 4 )]
|
||||||
|
|
||||||
[node name="LeftBrushIndicator" type="Sprite" parent="UI/ToolPanel/Tools/BrushesContainer/BrushHBoxContainer/PixelBrushButton"]
|
[node name="LeftBrushIndicator" type="Sprite" parent="UI/ToolPanel/Tools/BrushesContainer/BrushHBoxContainer/PixelBrushButton"]
|
||||||
scale = Vector2( 0.8, 0.8 )
|
scale = Vector2( 0.8, 0.8 )
|
||||||
texture = ExtResource( 3 )
|
texture = ExtResource( 2 )
|
||||||
centered = false
|
centered = false
|
||||||
|
|
||||||
[node name="RightBrushIndicator" type="Sprite" parent="UI/ToolPanel/Tools/BrushesContainer/BrushHBoxContainer/PixelBrushButton"]
|
[node name="RightBrushIndicator" type="Sprite" parent="UI/ToolPanel/Tools/BrushesContainer/BrushHBoxContainer/PixelBrushButton"]
|
||||||
scale = Vector2( 0.8, 0.8 )
|
scale = Vector2( 0.8, 0.8 )
|
||||||
texture = ExtResource( 4 )
|
texture = ExtResource( 3 )
|
||||||
centered = false
|
centered = false
|
||||||
offset = Vector2( 28, 0 )
|
offset = Vector2( 28, 0 )
|
||||||
|
|
||||||
|
@ -375,18 +371,18 @@ size = Vector2( 544, 464 )
|
||||||
handle_input_locally = false
|
handle_input_locally = false
|
||||||
render_target_update_mode = 3
|
render_target_update_mode = 3
|
||||||
|
|
||||||
[node name="Canvas" parent="UI/CanvasAndTimeline/HBoxContainer/ViewportContainer/Viewport" instance=ExtResource( 6 )]
|
[node name="Canvas" parent="UI/CanvasAndTimeline/HBoxContainer/ViewportContainer/Viewport" instance=ExtResource( 5 )]
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="UI/CanvasAndTimeline/HBoxContainer/ViewportContainer/Viewport"]
|
[node name="Camera2D" type="Camera2D" parent="UI/CanvasAndTimeline/HBoxContainer/ViewportContainer/Viewport"]
|
||||||
current = true
|
current = true
|
||||||
zoom = Vector2( 0.15, 0.15 )
|
zoom = Vector2( 0.15, 0.15 )
|
||||||
script = ExtResource( 7 )
|
script = ExtResource( 6 )
|
||||||
|
|
||||||
[node name="SelectionRectangle" type="Polygon2D" parent="UI/CanvasAndTimeline/HBoxContainer/ViewportContainer/Viewport"]
|
[node name="SelectionRectangle" type="Polygon2D" parent="UI/CanvasAndTimeline/HBoxContainer/ViewportContainer/Viewport"]
|
||||||
z_index = 1
|
z_index = 1
|
||||||
color = Color( 0.0823529, 0.694118, 0.623529, 0.592157 )
|
color = Color( 0.0823529, 0.694118, 0.623529, 0.592157 )
|
||||||
polygon = PoolVector2Array( 0, 0, 0, 0, 0, 0, 0, 0 )
|
polygon = PoolVector2Array( 0, 0, 0, 0, 0, 0, 0, 0 )
|
||||||
script = ExtResource( 8 )
|
script = ExtResource( 7 )
|
||||||
|
|
||||||
[node name="ViewportSeparator" type="VSeparator" parent="UI/CanvasAndTimeline/HBoxContainer"]
|
[node name="ViewportSeparator" type="VSeparator" parent="UI/CanvasAndTimeline/HBoxContainer"]
|
||||||
visible = false
|
visible = false
|
||||||
|
@ -408,12 +404,12 @@ stretch = true
|
||||||
size = Vector2( 266, 464 )
|
size = Vector2( 266, 464 )
|
||||||
handle_input_locally = false
|
handle_input_locally = false
|
||||||
render_target_update_mode = 0
|
render_target_update_mode = 0
|
||||||
script = ExtResource( 9 )
|
script = ExtResource( 8 )
|
||||||
|
|
||||||
[node name="Camera2D2" type="Camera2D" parent="UI/CanvasAndTimeline/HBoxContainer/ViewportContainer2/Viewport"]
|
[node name="Camera2D2" type="Camera2D" parent="UI/CanvasAndTimeline/HBoxContainer/ViewportContainer2/Viewport"]
|
||||||
current = true
|
current = true
|
||||||
zoom = Vector2( 0.15, 0.15 )
|
zoom = Vector2( 0.15, 0.15 )
|
||||||
script = ExtResource( 7 )
|
script = ExtResource( 6 )
|
||||||
|
|
||||||
[node name="AnimationTimeline" type="Panel" parent="UI/CanvasAndTimeline"]
|
[node name="AnimationTimeline" type="Panel" parent="UI/CanvasAndTimeline"]
|
||||||
editor/display_folded = true
|
editor/display_folded = true
|
||||||
|
@ -936,7 +932,7 @@ editor/display_folded = true
|
||||||
margin_right = 284.0
|
margin_right = 284.0
|
||||||
margin_bottom = 186.0
|
margin_bottom = 186.0
|
||||||
window_title = "About Pixelorama"
|
window_title = "About Pixelorama"
|
||||||
script = ExtResource( 10 )
|
script = ExtResource( 9 )
|
||||||
|
|
||||||
[node name="AboutUI" type="VBoxContainer" parent="AboutDialog"]
|
[node name="AboutUI" type="VBoxContainer" parent="AboutDialog"]
|
||||||
margin_left = 8.0
|
margin_left = 8.0
|
||||||
|
|
|
@ -135,7 +135,6 @@ func _process(delta) -> void:
|
||||||
Global.selection_rectangle.polygon[2] = end_pos
|
Global.selection_rectangle.polygon[2] = end_pos
|
||||||
Global.selection_rectangle.polygon[3] = Vector2(start_pos.x, end_pos.y)
|
Global.selection_rectangle.polygon[3] = Vector2(start_pos.x, end_pos.y)
|
||||||
|
|
||||||
|
|
||||||
if !is_making_line:
|
if !is_making_line:
|
||||||
previous_mouse_pos = mouse_pos
|
previous_mouse_pos = mouse_pos
|
||||||
previous_mouse_pos.x = clamp(previous_mouse_pos.x, location.x, location.x + size.x)
|
previous_mouse_pos.x = clamp(previous_mouse_pos.x, location.x, location.x + size.x)
|
||||||
|
@ -254,8 +253,8 @@ func _draw() -> void:
|
||||||
var start_pos_y = mouse_pos.y - (Global.left_brush_size >> 1)
|
var start_pos_y = mouse_pos.y - (Global.left_brush_size >> 1)
|
||||||
draw_rect(Rect2(start_pos_x, start_pos_y, Global.left_brush_size, Global.left_brush_size), Color.blue, false)
|
draw_rect(Rect2(start_pos_x, start_pos_y, Global.left_brush_size, Global.left_brush_size), Color.blue, false)
|
||||||
Global.BRUSH_TYPES.CUSTOM:
|
Global.BRUSH_TYPES.CUSTOM:
|
||||||
var custom_brush_size = Global.custom_left_brush_image.get_size()
|
var custom_brush_size = Global.custom_left_brush_image.get_size() - Vector2.ONE
|
||||||
var dst : Vector2 = mouse_pos - custom_brush_size / 4
|
var dst := rectangle_center(mouse_pos, custom_brush_size)
|
||||||
draw_texture(Global.custom_left_brush_texture, dst)
|
draw_texture(Global.custom_left_brush_texture, dst)
|
||||||
|
|
||||||
if Global.right_square_indicator_visible:
|
if Global.right_square_indicator_visible:
|
||||||
|
@ -265,8 +264,8 @@ func _draw() -> void:
|
||||||
var start_pos_y = mouse_pos.y - (Global.right_brush_size >> 1)
|
var start_pos_y = mouse_pos.y - (Global.right_brush_size >> 1)
|
||||||
draw_rect(Rect2(start_pos_x, start_pos_y, Global.right_brush_size, Global.right_brush_size), Color.red, false)
|
draw_rect(Rect2(start_pos_x, start_pos_y, Global.right_brush_size, Global.right_brush_size), Color.red, false)
|
||||||
Global.BRUSH_TYPES.CUSTOM:
|
Global.BRUSH_TYPES.CUSTOM:
|
||||||
var custom_brush_size = Global.custom_right_brush_image.get_size()
|
var custom_brush_size = Global.custom_right_brush_image.get_size() - Vector2.ONE
|
||||||
var dst : Vector2 = mouse_pos - custom_brush_size / 4
|
var dst := rectangle_center(mouse_pos, custom_brush_size)
|
||||||
draw_texture(Global.custom_right_brush_texture, dst)
|
draw_texture(Global.custom_right_brush_texture, dst)
|
||||||
|
|
||||||
func generate_layer_panels() -> void:
|
func generate_layer_panels() -> void:
|
||||||
|
@ -362,10 +361,38 @@ func draw_pixel(pos : Vector2, color : Color, brush_size : int, brush_type : int
|
||||||
sprite_changed_this_frame = true
|
sprite_changed_this_frame = true
|
||||||
|
|
||||||
Global.BRUSH_TYPES.CUSTOM:
|
Global.BRUSH_TYPES.CUSTOM:
|
||||||
var custom_brush_size = custom_brush_image.get_size()
|
var custom_brush_size := custom_brush_image.get_size() - Vector2.ONE
|
||||||
var dst : Vector2 = pos - custom_brush_size / 4
|
pos = pos.floor()
|
||||||
var src_rect := Rect2(Vector2.ZERO, custom_brush_size)
|
var dst := rectangle_center(pos, custom_brush_size)
|
||||||
#src_rect = src_rect.clip(Rect2(west_limit - dst.x, north_limit - dst.y, east_limit - custom_brush_size.x, south_limit - custom_brush_size.y))
|
var src_rect := Rect2(Vector2.ZERO, custom_brush_size + Vector2.ONE)
|
||||||
|
#Rectangle with the same size as the brush, but at cursor's position
|
||||||
|
var pos_rect_position := rectangle_center(pos, custom_brush_size)
|
||||||
|
var pos_rect := Rect2(pos_rect_position, custom_brush_size + Vector2.ONE)
|
||||||
|
|
||||||
|
#The selection rectangle
|
||||||
|
#If there's no rectangle, the whole canvas is considered a selection
|
||||||
|
var selection_rect := Rect2()
|
||||||
|
selection_rect.position = Vector2(west_limit, north_limit)
|
||||||
|
selection_rect.end = Vector2(east_limit, south_limit)
|
||||||
|
#Intersection of the position rectangle and selection
|
||||||
|
var pos_rect_clipped := pos_rect.clip(selection_rect)
|
||||||
|
#If the size is 0, that means that the brush wasn't positioned inside the selection
|
||||||
|
if pos_rect_clipped.size == Vector2.ZERO:
|
||||||
|
return
|
||||||
|
|
||||||
|
#According to the relative position of pos_rect to selection_rect, ...
|
||||||
|
#... manipulate src_rect so only the pixels INSIDE the selection get drawn
|
||||||
|
if pos_rect.position.x < selection_rect.position.x:
|
||||||
|
src_rect.position.x += pos_rect.size.x - pos_rect_clipped.size.x
|
||||||
|
dst.x += pos_rect.size.x - pos_rect_clipped.size.x
|
||||||
|
if pos_rect.end.x > selection_rect.end.x:
|
||||||
|
src_rect.size.x = pos_rect_clipped.size.x
|
||||||
|
|
||||||
|
if pos_rect.position.y < selection_rect.position.y:
|
||||||
|
src_rect.position.y += pos_rect.size.y - pos_rect_clipped.size.y
|
||||||
|
dst.y += pos_rect.size.y - pos_rect_clipped.size.y
|
||||||
|
if pos_rect.end.y > selection_rect.end.y:
|
||||||
|
src_rect.size.y = pos_rect_clipped.size.y
|
||||||
|
|
||||||
if color.a > 0: #If it's the pencil
|
if color.a > 0: #If it's the pencil
|
||||||
layers[current_layer_index][0].blend_rect(custom_brush_image, src_rect, dst)
|
layers[current_layer_index][0].blend_rect(custom_brush_image, src_rect, dst)
|
||||||
|
@ -376,8 +403,9 @@ func draw_pixel(pos : Vector2, color : Color, brush_size : int, brush_type : int
|
||||||
custom_brush.resize(custom_brush_size.x * brush_size, custom_brush_size.y * brush_size, Image.INTERPOLATE_NEAREST)
|
custom_brush.resize(custom_brush_size.x * brush_size, custom_brush_size.y * brush_size, Image.INTERPOLATE_NEAREST)
|
||||||
var custom_brush_blended = Global.blend_image_with_color(custom_brush, color, 1)
|
var custom_brush_blended = Global.blend_image_with_color(custom_brush, color, 1)
|
||||||
layers[current_layer_index][0].blit_rect_mask(custom_brush_blended, custom_brush, src_rect, dst)
|
layers[current_layer_index][0].blit_rect_mask(custom_brush_blended, custom_brush, src_rect, dst)
|
||||||
|
|
||||||
layers[current_layer_index][0].lock()
|
layers[current_layer_index][0].lock()
|
||||||
update_texture(current_layer_index)
|
sprite_changed_this_frame = true
|
||||||
|
|
||||||
#Bresenham's Algorithm
|
#Bresenham's Algorithm
|
||||||
#Thanks to https://godotengine.org/qa/35276/tile-based-line-drawing-algorithm-efficiency
|
#Thanks to https://godotengine.org/qa/35276/tile-based-line-drawing-algorithm-efficiency
|
||||||
|
@ -446,8 +474,16 @@ func flood_fill(pos : Vector2, target_color : Color, replace_color : Color) -> v
|
||||||
q.append(south)
|
q.append(south)
|
||||||
sprite_changed_this_frame = true
|
sprite_changed_this_frame = true
|
||||||
|
|
||||||
|
#I wish GDScript supported function overloading, I could add more versions of these scripts...
|
||||||
|
#...but with a Rect2() parameter instead of 2 Vector2()s
|
||||||
|
|
||||||
|
#Checks if a point is inside a rectangle
|
||||||
func point_in_rectangle(p : Vector2, coord1 : Vector2, coord2 : Vector2) -> bool:
|
func point_in_rectangle(p : Vector2, coord1 : Vector2, coord2 : Vector2) -> bool:
|
||||||
return p.x > coord1.x && p.y > coord1.y && p.x < coord2.x && p.y < coord2.y
|
return p.x > coord1.x && p.y > coord1.y && p.x < coord2.x && p.y < coord2.y
|
||||||
|
|
||||||
|
#Returns the position in the middle of a rectangle
|
||||||
|
func rectangle_center(pos : Vector2, size : Vector2) -> Vector2:
|
||||||
|
return (pos - size / 2).floor()
|
||||||
|
|
||||||
func _on_Timer_timeout() -> void:
|
func _on_Timer_timeout() -> void:
|
||||||
Global.can_draw = true
|
Global.can_draw = true
|
|
@ -4,7 +4,7 @@ var current_frame := 0 setget set_current_frame_label
|
||||||
# warning-ignore:unused_class_variable
|
# warning-ignore:unused_class_variable
|
||||||
var can_draw := false
|
var can_draw := false
|
||||||
# warning-ignore:unused_class_variable
|
# warning-ignore:unused_class_variable
|
||||||
var has_focus := true
|
var has_focus := false
|
||||||
# warning-ignore:unused_class_variable
|
# warning-ignore:unused_class_variable
|
||||||
var onion_skinning_past_rate := 0
|
var onion_skinning_past_rate := 0
|
||||||
# warning-ignore:unused_class_variable
|
# warning-ignore:unused_class_variable
|
||||||
|
|
Loading…
Reference in a new issue