1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-20 12:33:14 +00:00

Selection modes (#798)

* Fix a typo

this is required because this is "Paint" Selection
(so it's not supposed to cancel selection if we click outside the canvas)

* Added Selction Modes

Default, Add, Subtract, Intersect

* removed whitespace

* better options

* Removed Separators from headers

* formatting

* more formatting that i didnt notice

* Solved Shortcut conflict

* remove whitespace
This commit is contained in:
Variable 2022-12-31 23:13:27 +05:00 committed by GitHub
parent f16132decb
commit cbeef73fac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 96 additions and 44 deletions

View file

@ -19,7 +19,7 @@ func _ready() -> void:
color_rect.color = Global.left_tool_color
else:
color_rect.color = Global.right_tool_color
$Header/Label.text = Tools.tools[name].display_name
$Label.text = Tools.tools[name].display_name
load_config()

View file

@ -15,26 +15,11 @@ margin_right = 116.0
margin_bottom = 4.0
rect_min_size = Vector2( 0, 4 )
[node name="Header" type="HBoxContainer" parent="."]
[node name="Label" type="Label" parent="."]
margin_top = 8.0
margin_right = 116.0
margin_bottom = 22.0
custom_constants/separation = 0
[node name="HSeparator2" type="HSeparator" parent="Header"]
margin_right = 23.0
margin_bottom = 14.0
size_flags_horizontal = 3
[node name="Label" type="Label" parent="Header"]
margin_left = 23.0
margin_right = 92.0
margin_bottom = 14.0
theme_type_variation = "Header"
text = "Tool Name"
[node name="HSeparator" type="HSeparator" parent="Header"]
margin_left = 92.0
margin_right = 116.0
margin_bottom = 14.0
size_flags_horizontal = 3
align = 1
autowrap = true

View file

@ -5,7 +5,9 @@ var _similarity := 100
func get_config() -> Dictionary:
return {"similarity": _similarity}
var config := .get_config()
config["similarity"] = _similarity
return config
func set_config(config: Dictionary) -> void:
@ -23,6 +25,7 @@ func _on_Similarity_value_changed(value: float) -> void:
func apply_selection(position: Vector2) -> void:
.apply_selection(position)
var project: Project = Global.current_project
if position.x < 0 or position.y < 0:
return

View file

@ -65,6 +65,7 @@ func draw_preview() -> void:
func apply_selection(_position: Vector2) -> void:
.apply_selection(_position)
var project: Project = Global.current_project
if !_add and !_subtract and !_intersect:
Global.canvas.selection.clear_selection()

View file

@ -71,6 +71,7 @@ func draw_preview() -> void:
func apply_selection(_position) -> void:
.apply_selection(_position)
var project: Project = Global.current_project
var cleared := false
if !_add and !_subtract and !_intersect:

View file

@ -7,6 +7,7 @@ var _allegro_image_segments: Array
func apply_selection(position: Vector2) -> void:
.apply_selection(position)
var project: Project = Global.current_project
var size: Vector2 = project.size
if position.x < 0 or position.y < 0 or position.x >= size.x or position.y >= size.y:

View file

@ -13,11 +13,11 @@ var _draw_points := []
func get_config() -> Dictionary:
return {
"brush_type": _brush.type,
"brush_index": _brush.index,
"brush_size": _brush_size,
}
var config := .get_config()
config["brush_type"] = _brush.type
config["brush_index"] = _brush.index
config["brush_size"] = _brush_size
return config
func set_config(config: Dictionary) -> void:
@ -99,12 +99,14 @@ func draw_preview() -> void:
func apply_selection(_position) -> void:
.apply_selection(_position)
var project: Project = Global.current_project
var cleared := false
if !_add and !_subtract and !_intersect:
cleared = true
Global.canvas.selection.clear_selection()
if _draw_points.size() > 1:
# This is paint selection so we've done >= 1 nstead of > 1
if _draw_points.size() >= 1:
var selection_map_copy := SelectionMap.new()
selection_map_copy.copy_from(project.selection_map)
if _intersect:

View file

@ -105,6 +105,7 @@ func draw_preview() -> void:
func apply_selection(_position) -> void:
.apply_selection(_position)
if !_ready_to_apply:
return
var project: Project = Global.current_project

View file

@ -88,6 +88,7 @@ func draw_preview() -> void:
func apply_selection(_position: Vector2) -> void:
.apply_selection(_position)
var project: Project = Global.current_project
if !_add and !_subtract and !_intersect:
Global.canvas.selection.clear_selection()

View file

@ -1,6 +1,8 @@
class_name SelectionTool
extends BaseTool
enum Mode { DEFAULT, ADD, SUBTRACT, INTERSECT }
var undo_data: Dictionary
var _move := false
var _move_content := true
@ -10,6 +12,7 @@ var _offset := Vector2.ZERO
# click multiple times to create a selection
var _ongoing_selection := false
var _mode_selected := 0
var _add := false # Shift + Mouse Click
var _subtract := false # Ctrl + Mouse Click
var _intersect := false # Shift + Ctrl + Mouse Click
@ -28,6 +31,32 @@ onready var timer: Timer = $Timer
func _ready() -> void:
set_spinbox_values()
refresh_options()
func refresh_options():
# The existence of this function is to ensure all items
# are added when we are selecting an option (Bad things will happen if i dont do this...)
$Modes.clear()
$Modes.add_item("Default (New Selection)")
$Modes.add_item("Add to Selection")
$Modes.add_item("Subtract from Selection")
$Modes.add_item("Intersection of Selections")
$Modes.select(_mode_selected)
func get_config() -> Dictionary:
var config := .get_config()
config["mode_selected"] = _mode_selected
return config
func set_config(config: Dictionary) -> void:
_mode_selected = config.get("mode_selected", 0)
func update_config() -> void:
refresh_options()
func set_spinbox_values() -> void:
@ -173,7 +202,22 @@ func draw_end(position: Vector2) -> void:
func apply_selection(_position: Vector2) -> void:
pass
# if a shortcut is activated then that will be obeyed instead
match _mode_selected:
Mode.ADD:
if !_subtract && !_intersect:
_add = true
Mode.SUBTRACT:
if !_add && !_intersect:
_subtract = true
Mode.INTERSECT:
if !_add && !_subtract:
_intersect = true
func _on_Modes_item_selected(index: int) -> void:
_mode_selected = index
save_config()
func _set_cursor_text(rect: Rect2) -> void:

View file

@ -7,60 +7,73 @@
[node name="ToolOptions" instance=ExtResource( 1 )]
script = ExtResource( 2 )
[node name="PositionLabel" type="Label" parent="." index="2"]
[node name="ModeLabel" type="Label" parent="." index="2"]
margin_top = 26.0
margin_right = 116.0
margin_bottom = 40.0
text = "Position:"
text = "Mode:"
[node name="XSpinBox" parent="." index="3" instance=ExtResource( 3 )]
[node name="Modes" type="OptionButton" parent="." index="3"]
margin_top = 44.0
margin_right = 116.0
margin_bottom = 68.0
margin_bottom = 64.0
align = 1
[node name="PositionLabel" type="Label" parent="." index="4"]
margin_top = 68.0
margin_right = 116.0
margin_bottom = 82.0
text = "Position:"
[node name="XSpinBox" parent="." index="5" instance=ExtResource( 3 )]
margin_top = 86.0
margin_right = 116.0
margin_bottom = 110.0
hint_tooltip = "X coordinate of the top left corner"
allow_greater = true
allow_lesser = true
prefix = "X:"
[node name="YSpinBox" parent="." index="4" instance=ExtResource( 3 )]
margin_top = 72.0
[node name="YSpinBox" parent="." index="6" instance=ExtResource( 3 )]
margin_top = 114.0
margin_right = 116.0
margin_bottom = 96.0
margin_bottom = 138.0
hint_tooltip = "Y coordinate of the top left corner"
allow_greater = true
allow_lesser = true
prefix = "Y:"
[node name="SizeLabel" type="Label" parent="." index="5"]
margin_top = 100.0
[node name="SizeLabel" type="Label" parent="." index="7"]
margin_top = 142.0
margin_right = 116.0
margin_bottom = 114.0
margin_bottom = 156.0
text = "Size:"
[node name="WSpinBox" parent="." index="6" instance=ExtResource( 3 )]
margin_top = 118.0
[node name="WSpinBox" parent="." index="8" instance=ExtResource( 3 )]
margin_top = 160.0
margin_right = 116.0
margin_bottom = 142.0
margin_bottom = 184.0
hint_tooltip = "Width of selection"
min_value = 1.0
value = 1.0
allow_greater = true
prefix = "W:"
[node name="HSpinBox" parent="." index="7" instance=ExtResource( 3 )]
margin_top = 146.0
[node name="HSpinBox" parent="." index="9" instance=ExtResource( 3 )]
margin_top = 188.0
margin_right = 116.0
margin_bottom = 170.0
margin_bottom = 212.0
hint_tooltip = "Height of selection"
min_value = 1.0
value = 1.0
allow_greater = true
prefix = "H:"
[node name="Timer" type="Timer" parent="." index="8"]
[node name="Timer" type="Timer" parent="." index="10"]
wait_time = 0.2
one_shot = true
[connection signal="item_selected" from="Modes" to="." method="_on_Modes_item_selected"]
[connection signal="value_changed" from="XSpinBox" to="." method="_on_position_value_changed" binds= [ true ]]
[connection signal="value_changed" from="YSpinBox" to="." method="_on_position_value_changed" binds= [ false ]]
[connection signal="value_changed" from="WSpinBox" to="." method="_on_size_value_changed" binds= [ true ]]