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

New tool: Select by Color (temporary icon)

When the user clicks on a pixel, all pixels of the same color are being selected. Shift adds to the selection, Ctrl subtracts. The icon and the hint tooltip are temporary.
This commit is contained in:
Manolis Papadeas 2021-04-19 18:50:43 +03:00
parent dd2bec4c19
commit fccd37360a
15 changed files with 240 additions and 21 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/colorselect.png-298f0e2c6d8874c063b65a51db97d7bf.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/blue_themes/tools/colorselect.png"
dest_files=[ "res://.import/colorselect.png-298f0e2c6d8874c063b65a51db97d7bf.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

View file

@ -0,0 +1,13 @@
[remap]
importer="image"
type="Image"
path="res://.import/colorselect_cursor.png-4ef918151476710e2b5b5727913a4294.image"
[deps]
source_file="res://assets/graphics/cursor_icons/colorselect_cursor.png"
dest_files=[ "res://.import/colorselect_cursor.png-4ef918151476710e2b5b5727913a4294.image" ]
[params]

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/colorselect.png-d0f20875bad3719d98e094b8ccf34fa6.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/dark_themes/tools/colorselect.png"
dest_files=[ "res://.import/colorselect.png-d0f20875bad3719d98e094b8ccf34fa6.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/colorselect.png-80b70629f82a4496f3b0f1ffef36b499.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/light_themes/tools/colorselect.png"
dest_files=[ "res://.import/colorselect.png-80b70629f82a4496f3b0f1ffef36b499.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View file

@ -508,6 +508,16 @@ invert_selection={
"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":73,"unicode":0,"echo":false,"script":null)
]
}
left_color_select_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":87,"unicode":0,"echo":false,"script":null)
]
}
right_color_select_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":87,"unicode":0,"echo":false,"script":null)
]
}
[locale]

View file

@ -479,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 color_select : BaseButton = tool_buttons.find_node("ColorSelect")
color_select.hint_tooltip = tr("""Select By Color
%s for left mouse button
%s for right mouse button""") % [InputMap.get_action_list("left_color_select_tool")[0].as_text(), InputMap.get_action_list("right_color_select_tool")[0].as_text()]
var move_select : BaseButton = tool_buttons.find_node("Move")
move_select.hint_tooltip = tr("""Move

View file

@ -40,6 +40,7 @@ signal color_changed(color, button)
var _tools = {
"RectSelect" : "res://src/Tools/RectSelect.tscn",
"ColorSelect" : "res://src/Tools/ColorSelect.tscn",
"Move" : "res://src/Tools/Move.tscn",
"Zoom" : "res://src/Tools/Zoom.tscn",
"Pan" : "res://src/Tools/Pan.tscn",

39
src/Tools/ColorSelect.gd Normal file
View file

@ -0,0 +1,39 @@
extends BaseTool
var undo_data : Dictionary
func draw_start(_position : Vector2) -> void:
Global.canvas.selection.move_content_confirm()
undo_data = Global.canvas.selection._get_undo_data(false)
func draw_move(_position : Vector2) -> void:
pass
func draw_end(position : Vector2) -> void:
var subtract_from_selection : bool = Tools.control
var project : Project = Global.current_project
if position.x < 0 or position.y < 0:
return
if position.x > project.size.x - 1 or position.y > project.size.y - 1:
return
if !Tools.shift and !subtract_from_selection:
Global.canvas.selection.clear_selection()
var selection_bitmap_copy : BitMap = project.selection_bitmap.duplicate()
var cel_image := Image.new()
cel_image.copy_from(project.frames[project.current_frame].cels[project.current_layer].image)
cel_image.lock()
var color := cel_image.get_pixelv(position)
for x in cel_image.get_width():
for y in cel_image.get_width():
var pos := Vector2(x, y)
if color.is_equal_approx(cel_image.get_pixelv(pos)):
selection_bitmap_copy.set_bit(pos, !subtract_from_selection)
cel_image.unlock()
project.selection_bitmap = selection_bitmap_copy
Global.canvas.selection.big_bounding_rectangle = project.get_selection_rectangle(project.selection_bitmap)
Global.canvas.selection.commit_undo("Rectangle Select", undo_data)

View file

@ -0,0 +1,20 @@
[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/ColorSelect.gd" type="Script" id=2]
[node name="ToolOptions" instance=ExtResource( 1 )]
script = ExtResource( 2 )
[node name="PixelPerfect" parent="." index="1"]
visible = false
[node name="EmptySpacer" parent="." index="2"]
visible = false
margin_top = 18.0
margin_bottom = 30.0
[node name="Mirror" parent="." index="3"]
visible = false
margin_top = 18.0
margin_bottom = 35.0

View file

@ -4,6 +4,7 @@ extends VBoxContainer
# Node, shortcut
onready var tools := [
[$RectSelect, "rectangle_select"],
[$ColorSelect, "color_select"],
[$Move, "move"],
[$Zoom, "zoom"],
[$Pan, "pan"],

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=31 format=2]
[gd_scene load_steps=32 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]
@ -27,6 +27,7 @@
[ext_resource path="res://assets/graphics/dark_themes/tools/ellipsetool.png" type="Texture" id=25]
[ext_resource path="res://assets/graphics/dark_themes/tools/move.png" type="Texture" id=26]
[ext_resource path="res://assets/graphics/tool_backgrounds/r.png" type="Texture" id=27]
[ext_resource path="res://assets/graphics/dark_themes/tools/colorselect.png" type="Texture" id=28]
[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 9 )
@ -90,7 +91,7 @@ __meta__ = {
margin_left = 7.0
margin_top = 7.0
margin_right = 39.0
margin_bottom = 399.0
margin_bottom = 435.0
size_flags_horizontal = 4
size_flags_vertical = 0
script = ExtResource( 1 )
@ -122,7 +123,7 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Move" type="Button" parent="ToolPanel/PanelContainer/ToolButtons" groups=[
[node name="ColorSelect" type="Button" parent="ToolPanel/PanelContainer/ToolButtons" groups=[
"UIButtons",
]]
margin_top = 36.0
@ -132,6 +133,31 @@ rect_min_size = Vector2( 32, 32 )
mouse_default_cursor_shape = 2
button_mask = 3
[node name="Background" type="TextureRect" parent="ToolPanel/PanelContainer/ToolButtons/ColorSelect"]
margin_right = 32.0
margin_bottom = 32.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ToolIcon" type="TextureRect" parent="ToolPanel/PanelContainer/ToolButtons/ColorSelect"]
margin_right = 32.0
margin_bottom = 32.0
texture = ExtResource( 28 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Move" 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="Background" type="TextureRect" parent="ToolPanel/PanelContainer/ToolButtons/Move"]
margin_right = 32.0
margin_bottom = 32.0
@ -150,9 +176,9 @@ __meta__ = {
[node name="Zoom" 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
@ -175,9 +201,9 @@ __meta__ = {
[node name="Pan" 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
@ -200,9 +226,9 @@ __meta__ = {
[node name="ColorPicker" 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
@ -225,9 +251,9 @@ __meta__ = {
[node name="Pencil" 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
@ -251,9 +277,9 @@ __meta__ = {
[node name="Eraser" 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
@ -277,9 +303,9 @@ __meta__ = {
[node name="Bucket" 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
@ -302,9 +328,9 @@ __meta__ = {
[node name="LightenDarken" type="Button" parent="ToolPanel/PanelContainer/ToolButtons" groups=[
"UIButtons",
]]
margin_top = 288.0
margin_top = 324.0
margin_right = 32.0
margin_bottom = 320.0
margin_bottom = 356.0
rect_min_size = Vector2( 32, 32 )
mouse_default_cursor_shape = 2
button_mask = 3
@ -327,9 +353,9 @@ __meta__ = {
[node name="RectangleTool" type="Button" parent="ToolPanel/PanelContainer/ToolButtons" groups=[
"UIButtons",
]]
margin_top = 324.0
margin_top = 360.0
margin_right = 32.0
margin_bottom = 356.0
margin_bottom = 392.0
rect_min_size = Vector2( 32, 32 )
mouse_default_cursor_shape = 2
button_mask = 3
@ -352,9 +378,9 @@ __meta__ = {
[node name="EllipseTool" type="Button" parent="ToolPanel/PanelContainer/ToolButtons" groups=[
"UIButtons",
]]
margin_top = 360.0
margin_top = 396.0
margin_right = 32.0
margin_bottom = 392.0
margin_bottom = 428.0
rect_min_size = Vector2( 32, 32 )
mouse_default_cursor_shape = 2
button_mask = 3