mirror of
https://github.com/Relintai/GraphicsEditor.git
synced 2024-11-12 08:15:17 +01:00
Fixed ColorPicker and added time debug class
This commit is contained in:
parent
a08067aed1
commit
174a3aa450
32
addons/graphics_editor/ColorPicker.gd
Normal file
32
addons/graphics_editor/ColorPicker.gd
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
tool
|
||||||
|
extends ColorPickerButton
|
||||||
|
|
||||||
|
var color_picking = false
|
||||||
|
var mouse_on_top = false
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
var color_picker = get_picker()
|
||||||
|
var color_picker_button = color_picker.get_children()[0].get_children()[1]
|
||||||
|
color_picker_button.disconnect("pressed", color_picker, "_screen_pick_pressed")
|
||||||
|
color_picker_button.connect("pressed", self, "color_picker_button_pressed")
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
if color_picking and not mouse_on_top:
|
||||||
|
var editor = get_node("/root/Editor")
|
||||||
|
var paint_canvas = get_node("/root/Editor/PaintCanvasContainer/PaintCanvas")
|
||||||
|
var highlighted_color = paint_canvas.get_pixel_cell_color_v(editor.cell_mouse_position)
|
||||||
|
if not highlighted_color == null:
|
||||||
|
color = highlighted_color
|
||||||
|
|
||||||
|
func color_picker_button_pressed():
|
||||||
|
if not color_picking:
|
||||||
|
color_picking = true
|
||||||
|
|
||||||
|
func _on_ColorPicker_focus_exited():
|
||||||
|
color_picking = false
|
||||||
|
|
||||||
|
func _on_ColorPicker_mouse_entered():
|
||||||
|
mouse_on_top = true
|
||||||
|
|
||||||
|
func _on_ColorPicker_mouse_exited():
|
||||||
|
mouse_on_top = false
|
@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=11 format=2]
|
[gd_scene load_steps=12 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://addons/graphics_editor/Editor.gd" type="Script" id=1]
|
[ext_resource path="res://addons/graphics_editor/Editor.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://addons/graphics_editor/PaintCanvasContainer.gd" type="Script" id=2]
|
[ext_resource path="res://addons/graphics_editor/PaintCanvasContainer.gd" type="Script" id=2]
|
||||||
@ -7,9 +7,10 @@
|
|||||||
[ext_resource path="res://addons/graphics_editor/CanvasOutline.gd" type="Script" id=5]
|
[ext_resource path="res://addons/graphics_editor/CanvasOutline.gd" type="Script" id=5]
|
||||||
[ext_resource path="res://addons/graphics_editor/Navbar.gd" type="Script" id=6]
|
[ext_resource path="res://addons/graphics_editor/Navbar.gd" type="Script" id=6]
|
||||||
[ext_resource path="res://addons/graphics_editor/MenuButtonExtended.gd" type="Script" id=7]
|
[ext_resource path="res://addons/graphics_editor/MenuButtonExtended.gd" type="Script" id=7]
|
||||||
[ext_resource path="res://addons/graphics_editor/TextInfo.gd" type="Script" id=8]
|
[ext_resource path="res://addons/graphics_editor/ColorPicker.gd" type="Script" id=8]
|
||||||
[ext_resource path="res://addons/graphics_editor/SaveFileDialog.gd" type="Script" id=9]
|
[ext_resource path="res://addons/graphics_editor/TextInfo.gd" type="Script" id=9]
|
||||||
[ext_resource path="res://addons/graphics_editor/Settings.tscn" type="PackedScene" id=10]
|
[ext_resource path="res://addons/graphics_editor/SaveFileDialog.gd" type="Script" id=10]
|
||||||
|
[ext_resource path="res://addons/graphics_editor/Settings.tscn" type="PackedScene" id=11]
|
||||||
|
|
||||||
[node name="Editor" type="Control"]
|
[node name="Editor" type="Control"]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
@ -51,7 +52,7 @@ color = Color( 0.639216, 0.639216, 0.639216, 1 )
|
|||||||
[node name="VisualGrid2" parent="PaintCanvasContainer/PaintCanvas/Grids" instance=ExtResource( 4 )]
|
[node name="VisualGrid2" parent="PaintCanvasContainer/PaintCanvas/Grids" instance=ExtResource( 4 )]
|
||||||
mouse_filter = 2
|
mouse_filter = 2
|
||||||
color = Color( 1, 1, 1, 1 )
|
color = Color( 1, 1, 1, 1 )
|
||||||
size = 160.0
|
size = 160
|
||||||
|
|
||||||
[node name="CanvasOutline" type="Control" parent="PaintCanvasContainer/PaintCanvas"]
|
[node name="CanvasOutline" type="Control" parent="PaintCanvasContainer/PaintCanvas"]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
@ -126,6 +127,7 @@ text = "Rainbow Tool"
|
|||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
margin_top = 210.0
|
margin_top = 210.0
|
||||||
margin_bottom = 240.0
|
margin_bottom = 240.0
|
||||||
|
script = ExtResource( 8 )
|
||||||
|
|
||||||
[node name="Layers" type="Control" parent="ToolMenu"]
|
[node name="Layers" type="Control" parent="ToolMenu"]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
@ -146,7 +148,7 @@ anchor_bottom = 1.0
|
|||||||
margin_top = -40.0
|
margin_top = -40.0
|
||||||
|
|
||||||
[node name="TextInfo" type="Control" parent="BottomPanel"]
|
[node name="TextInfo" type="Control" parent="BottomPanel"]
|
||||||
script = ExtResource( 8 )
|
script = ExtResource( 9 )
|
||||||
|
|
||||||
[node name="SaveFileDialog" type="FileDialog" parent="."]
|
[node name="SaveFileDialog" type="FileDialog" parent="."]
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
@ -158,9 +160,9 @@ margin_top = -165.0
|
|||||||
margin_right = 340.0
|
margin_right = 340.0
|
||||||
margin_bottom = 165.0
|
margin_bottom = 165.0
|
||||||
filters = PoolStringArray( "*.png ; PNG Images" )
|
filters = PoolStringArray( "*.png ; PNG Images" )
|
||||||
script = ExtResource( 9 )
|
script = ExtResource( 10 )
|
||||||
|
|
||||||
[node name="Settings" parent="." instance=ExtResource( 10 )]
|
[node name="Settings" parent="." instance=ExtResource( 11 )]
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
anchor_top = 0.5
|
anchor_top = 0.5
|
||||||
anchor_right = 0.5
|
anchor_right = 0.5
|
||||||
@ -175,6 +177,9 @@ margin_bottom = 150.0
|
|||||||
[connection signal="pressed" from="ToolMenu/Buttons/BucketTool" to="." method="_on_BucketTool_pressed"]
|
[connection signal="pressed" from="ToolMenu/Buttons/BucketTool" to="." method="_on_BucketTool_pressed"]
|
||||||
[connection signal="pressed" from="ToolMenu/Buttons/RainbowTool" to="." method="_on_RainbowTool_pressed"]
|
[connection signal="pressed" from="ToolMenu/Buttons/RainbowTool" to="." method="_on_RainbowTool_pressed"]
|
||||||
[connection signal="color_changed" from="ToolMenu/Buttons/ColorPicker" to="." method="_on_ColorPicker_color_changed"]
|
[connection signal="color_changed" from="ToolMenu/Buttons/ColorPicker" to="." method="_on_ColorPicker_color_changed"]
|
||||||
|
[connection signal="focus_exited" from="ToolMenu/Buttons/ColorPicker" to="ToolMenu/Buttons/ColorPicker" method="_on_ColorPicker_focus_exited"]
|
||||||
|
[connection signal="mouse_entered" from="ToolMenu/Buttons/ColorPicker" to="ToolMenu/Buttons/ColorPicker" method="_on_ColorPicker_mouse_entered"]
|
||||||
|
[connection signal="mouse_exited" from="ToolMenu/Buttons/ColorPicker" to="ToolMenu/Buttons/ColorPicker" method="_on_ColorPicker_mouse_exited"]
|
||||||
[connection signal="about_to_show" from="SaveFileDialog" to="SaveFileDialog" method="_on_SaveFileDialog_about_to_show"]
|
[connection signal="about_to_show" from="SaveFileDialog" to="SaveFileDialog" method="_on_SaveFileDialog_about_to_show"]
|
||||||
[connection signal="confirmed" from="SaveFileDialog" to="SaveFileDialog" method="_on_SaveFileDialog_confirmed"]
|
[connection signal="confirmed" from="SaveFileDialog" to="SaveFileDialog" method="_on_SaveFileDialog_confirmed"]
|
||||||
[connection signal="file_selected" from="SaveFileDialog" to="SaveFileDialog" method="_on_SaveFileDialog_file_selected"]
|
[connection signal="file_selected" from="SaveFileDialog" to="SaveFileDialog" method="_on_SaveFileDialog_file_selected"]
|
||||||
|
@ -283,8 +283,18 @@ func get_pixels_from_line(vec2_1, vec2_2):
|
|||||||
|
|
||||||
#even though the function checks for it, we can't afford adding more functions to the call stack
|
#even though the function checks for it, we can't afford adding more functions to the call stack
|
||||||
#because godot has a limit until it crashes
|
#because godot has a limit until it crashes
|
||||||
var flood_fill_queue = 0
|
|
||||||
func flood_fill(x, y, target_color, replacement_color):
|
func flood_fill(x, y, target_color, replacement_color):
|
||||||
|
var time_debug = util.time_debug.new()
|
||||||
|
time_debug.start()
|
||||||
|
flood_fill_main(x, y, target_color, replacement_color)
|
||||||
|
time_debug.end()
|
||||||
|
print("Bucket fill time passed: msec: %s | sec: %s" % [time_debug.get_time_passed(), time_debug.get_time_passed() / float(1000)])
|
||||||
|
return
|
||||||
|
|
||||||
|
var flood_fill_queue = 0
|
||||||
|
func flood_fill_main(x, y, target_color, replacement_color):
|
||||||
|
|
||||||
#yield(get_tree().create_timer(1), "timeout")
|
#yield(get_tree().create_timer(1), "timeout")
|
||||||
flood_fill_queue += 1
|
flood_fill_queue += 1
|
||||||
if not cell_in_canvas_region(x, y):
|
if not cell_in_canvas_region(x, y):
|
||||||
@ -298,21 +308,20 @@ func flood_fill(x, y, target_color, replacement_color):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
set_pixel_cell(x, y, replacement_color)
|
set_pixel_cell(x, y, replacement_color)
|
||||||
if flood_fill_queue >= 500:
|
if flood_fill_queue >= 200:
|
||||||
print(flood_fill_queue)
|
|
||||||
yield(get_tree().create_timer(0.01), "timeout")
|
yield(get_tree().create_timer(0.01), "timeout")
|
||||||
#up
|
#up
|
||||||
if get_pixel_cell_color(x, y - 1) == target_color:
|
if get_pixel_cell_color(x, y - 1) == target_color:
|
||||||
flood_fill(x, y - 1, target_color, replacement_color)
|
flood_fill_main(x, y - 1, target_color, replacement_color)
|
||||||
#down
|
#down
|
||||||
if get_pixel_cell_color(x, y + 1) == target_color:
|
if get_pixel_cell_color(x, y + 1) == target_color:
|
||||||
flood_fill(x, y + 1, target_color, replacement_color)
|
flood_fill_main(x, y + 1, target_color, replacement_color)
|
||||||
#left
|
#left
|
||||||
if get_pixel_cell_color(x - 1, y) == target_color:
|
if get_pixel_cell_color(x - 1, y) == target_color:
|
||||||
flood_fill(x - 1, y, target_color, replacement_color)
|
flood_fill_main(x - 1, y, target_color, replacement_color)
|
||||||
#right
|
#right
|
||||||
if get_pixel_cell_color(x + 1, y) == target_color:
|
if get_pixel_cell_color(x + 1, y) == target_color:
|
||||||
flood_fill(x + 1, y, target_color, replacement_color)
|
flood_fill_main(x + 1, y, target_color, replacement_color)
|
||||||
flood_fill_queue -= 1
|
flood_fill_queue -= 1
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -20,6 +20,9 @@ func set_cell(x, y, color):
|
|||||||
image.set_pixel(x, y, color)
|
image.set_pixel(x, y, color)
|
||||||
update_chunk()
|
update_chunk()
|
||||||
|
|
||||||
|
func get_cell(x, y):
|
||||||
|
return image.get_pixel(x, y)
|
||||||
|
|
||||||
func _on_VisibilityNotifier2D_screen_entered():
|
func _on_VisibilityNotifier2D_screen_entered():
|
||||||
visible = true
|
visible = true
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
[ext_resource path="res://addons/graphics_editor/Settings.gd" type="Script" id=1]
|
[ext_resource path="res://addons/graphics_editor/Settings.gd" type="Script" id=1]
|
||||||
|
|
||||||
[node name="Settings" type="WindowDialog"]
|
[node name="Settings" type="WindowDialog"]
|
||||||
visible = true
|
|
||||||
margin_top = 20.0
|
margin_top = 20.0
|
||||||
margin_right = 310.0
|
margin_right = 310.0
|
||||||
margin_bottom = 320.0
|
margin_bottom = 320.0
|
||||||
|
@ -1,6 +1,21 @@
|
|||||||
tool
|
tool
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
class time_debug:
|
||||||
|
var start_time = 0.0
|
||||||
|
var end_time = 0.0
|
||||||
|
|
||||||
|
func start():
|
||||||
|
start_time = OS.get_ticks_msec()
|
||||||
|
return start_time
|
||||||
|
|
||||||
|
func end():
|
||||||
|
end_time = OS.get_ticks_msec()
|
||||||
|
return end_time
|
||||||
|
|
||||||
|
func get_time_passed():
|
||||||
|
return end_time - start_time
|
||||||
|
|
||||||
static func color_from_array(color_array):
|
static func color_from_array(color_array):
|
||||||
var r = color_array[0]
|
var r = color_array[0]
|
||||||
var g = color_array[1]
|
var g = color_array[1]
|
||||||
|
Loading…
Reference in New Issue
Block a user