Skip to content

Commit

Permalink
Merge pull request #742 from aaronfranke/2d-to-control
Browse files Browse the repository at this point in the history
Convert some 2D nodes to Control nodes in GDPaint and Pseudolocalization demos
  • Loading branch information
aaronfranke authored May 9, 2022
2 parents 4af3876 + 5f1776b commit ae57eb2
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 180 deletions.
File renamed without changes.
File renamed without changes
File renamed without changes.
27 changes: 8 additions & 19 deletions 2d/gd_paint/paint_control.gd → gui/gd_paint/paint_control.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ extends Control
const UNDO_MODE_SHAPE = -2
# A constant for whether or not we can undo.
const UNDO_NONE = -1
# How large is the image (it's actually the size of DrawingAreaBG, because that's our background canvas).
const IMAGE_SIZE = Vector2(674, 600)

# Enums for the various modes and brush shapes that can be applied.
enum BrushModes {
Expand All @@ -20,9 +18,6 @@ enum BrushShapes {
CIRCLE,
}

# The top-left position of the canvas.
var TL_node

# A list to hold all of the dictionaries that make up each brush.
var brush_data_list = []

Expand All @@ -48,20 +43,15 @@ var brush_shape = BrushShapes.CIRCLE;
# in the _draw function for more details).
var bg_color = Color.WHITE

func _ready():
# Get the top left position node. We need this to find out whether or not the mouse is inside the canvas.
TL_node = get_node(^"TLPos")
set_process(true)
@onready var drawing_area = $"../DrawingAreaBG"


func _process(_delta):
var mouse_pos = get_viewport().get_mouse_position()

# Check if the mouse is currently inside the canvas/drawing-area.
is_mouse_in_drawing_area = false
if mouse_pos.x > TL_node.global_position.x:
if mouse_pos.y > TL_node.global_position.y:
is_mouse_in_drawing_area = true
var drawing_area_rect := Rect2(drawing_area.position, drawing_area.size)
is_mouse_in_drawing_area = drawing_area_rect.has_point(mouse_pos)

if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
# If we do not have a position for when the mouse was first clicked, then this must
Expand Down Expand Up @@ -110,11 +100,10 @@ func check_if_mouse_is_inside_canvas():
# Make sure the mouse click starting position is inside the canvas.
# This is so if we start out click outside the canvas (say chosing a color from the color picker)
# and then move our mouse back into the canvas, it won't start painting.
if mouse_click_start_pos.x > TL_node.global_position.x:
if mouse_click_start_pos.y > TL_node.global_position.y:
# Make sure the current mouse position is inside the canvas.
if is_mouse_in_drawing_area:
return true
if Rect2(drawing_area.position, drawing_area.size).has_point(mouse_click_start_pos):
# Make sure the current mouse position is inside the canvas.
if is_mouse_in_drawing_area:
return true
return false


Expand Down Expand Up @@ -244,7 +233,7 @@ func save_picture(path):
# Get the viewport image.
var img = get_viewport().get_texture().get_image()
# Crop the image so we only have canvas area.
var cropped_image = img.get_rect(Rect2(TL_node.global_position, IMAGE_SIZE))
var cropped_image = img.get_rect(Rect2(drawing_area.position, drawing_area.size))

# Save the image with the passed in path we got from the save dialog.
cropped_image.save_png(path)
131 changes: 91 additions & 40 deletions 2d/gd_paint/paint_root.tscn → gui/gd_paint/paint_root.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=6 format=3 uid="uid://bhjmyer4wlwy2"]
[gd_scene load_steps=10 format=3 uid="uid://bhjmyer4wlwy2"]

[ext_resource type="Script" path="res://paint_control.gd" id="1"]
[ext_resource type="Script" path="res://tools_panel.gd" id="2"]
Expand All @@ -10,6 +10,22 @@ bg_color = Color(1, 1, 1, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_npkcn"]
bg_color = Color(0.2, 0.2, 0.2, 1)

[sub_resource type="AtlasTexture" id="AtlasTexture_v0gbg"]
atlas = ExtResource( "3" )
region = Rect2(0, 0, 16, 16)

[sub_resource type="AtlasTexture" id="AtlasTexture_j7akv"]
atlas = ExtResource( "3" )
region = Rect2(16, 0, 16, 16)

[sub_resource type="AtlasTexture" id="AtlasTexture_63q87"]
atlas = ExtResource( "3" )
region = Rect2(0, 16, 16, 16)

[sub_resource type="AtlasTexture" id="AtlasTexture_t52fe"]
atlas = ExtResource( "3" )
region = Rect2(16, 16, 16, 16)

[node name="PaintRoot" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
Expand All @@ -33,9 +49,6 @@ script = ExtResource( "1" )
metadata/_edit_layout_mode = 1
metadata/_edit_use_custom_anchors = false

[node name="TLPos" type="Position2D" parent="PaintControl"]
position = Vector2(350, 0)

[node name="ToolsPanel" type="Panel" parent="."]
offset_right = 350.0
offset_bottom = 600.0
Expand All @@ -61,12 +74,18 @@ offset_bottom = 85.0
metadata/_edit_layout_mode = 0
metadata/_edit_use_custom_anchors = false

[node name="Sprite2D" type="Sprite2D" parent="ToolsPanel/ButtonToolPencil"]
position = Vector2(27, 26)
scale = Vector2(2.5, 2.5)
texture = ExtResource( "3" )
region_enabled = true
region_rect = Rect2(0, 0, 16, 16)
[node name="TextureRect" type="TextureRect" parent="ToolsPanel/ButtonToolPencil"]
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 5.0
offset_top = 5.0
offset_right = -5.0
offset_bottom = -5.0
grow_horizontal = 2
grow_vertical = 2
texture = SubResource( "AtlasTexture_v0gbg" )
metadata/_edit_layout_mode = 1
metadata/_edit_use_custom_anchors = false

[node name="ButtonToolEraser" type="Button" parent="ToolsPanel"]
offset_left = 110.0
Expand All @@ -76,12 +95,18 @@ offset_bottom = 85.0
metadata/_edit_layout_mode = 0
metadata/_edit_use_custom_anchors = false

[node name="Sprite2D" type="Sprite2D" parent="ToolsPanel/ButtonToolEraser"]
position = Vector2(29, 26)
scale = Vector2(2.5, 2.5)
texture = ExtResource( "3" )
region_enabled = true
region_rect = Rect2(16, 0, 16, 16)
[node name="TextureRect2" type="TextureRect" parent="ToolsPanel/ButtonToolEraser"]
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 5.0
offset_top = 5.0
offset_right = -5.0
offset_bottom = -5.0
grow_horizontal = 2
grow_vertical = 2
texture = SubResource( "AtlasTexture_j7akv" )
metadata/_edit_layout_mode = 1
metadata/_edit_use_custom_anchors = false

[node name="ButtonToolRectangle" type="Button" parent="ToolsPanel"]
offset_left = 180.0
Expand All @@ -91,12 +116,18 @@ offset_bottom = 85.0
metadata/_edit_layout_mode = 0
metadata/_edit_use_custom_anchors = false

[node name="Sprite2D" type="Sprite2D" parent="ToolsPanel/ButtonToolRectangle"]
position = Vector2(28, 26)
scale = Vector2(2.5, 2.5)
texture = ExtResource( "3" )
region_enabled = true
region_rect = Rect2(0, 16, 16, 16)
[node name="TextureRect" type="TextureRect" parent="ToolsPanel/ButtonToolRectangle"]
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 5.0
offset_top = 5.0
offset_right = -5.0
offset_bottom = -5.0
grow_horizontal = 2
grow_vertical = 2
texture = SubResource( "AtlasTexture_63q87" )
metadata/_edit_layout_mode = 1
metadata/_edit_use_custom_anchors = false

[node name="ButtonToolCircle" type="Button" parent="ToolsPanel"]
offset_left = 250.0
Expand All @@ -106,12 +137,18 @@ offset_bottom = 85.0
metadata/_edit_layout_mode = 0
metadata/_edit_use_custom_anchors = false

[node name="Sprite2D" type="Sprite2D" parent="ToolsPanel/ButtonToolCircle"]
position = Vector2(28, 26)
scale = Vector2(2.5, 2.5)
texture = ExtResource( "3" )
region_enabled = true
region_rect = Rect2(16, 16, 16, 16)
[node name="TextureRect" type="TextureRect" parent="ToolsPanel/ButtonToolCircle"]
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 5.0
offset_top = 5.0
offset_right = -5.0
offset_bottom = -5.0
grow_horizontal = 2
grow_vertical = 2
texture = SubResource( "AtlasTexture_t52fe" )
metadata/_edit_layout_mode = 1
metadata/_edit_use_custom_anchors = false

[node name="LabelBrushColor" type="Label" parent="ToolsPanel"]
offset_left = 20.0
Expand Down Expand Up @@ -172,12 +209,18 @@ offset_bottom = 114.0
metadata/_edit_layout_mode = 0
metadata/_edit_use_custom_anchors = false

[node name="Sprite2D" type="Sprite2D" parent="ToolsPanel/BrushSettings/ButtonShapeBox"]
position = Vector2(27, 27)
scale = Vector2(2.5, 2.5)
texture = ExtResource( "3" )
region_enabled = true
region_rect = Rect2(0, 16, 16, 16)
[node name="TextureRect" type="TextureRect" parent="ToolsPanel/BrushSettings/ButtonShapeBox"]
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 5.0
offset_top = 5.0
offset_right = -5.0
offset_bottom = -5.0
grow_horizontal = 2
grow_vertical = 2
texture = SubResource( "AtlasTexture_63q87" )
metadata/_edit_layout_mode = 1
metadata/_edit_use_custom_anchors = false

[node name="ButtonShapeCircle" type="Button" parent="ToolsPanel/BrushSettings"]
offset_left = 190.0
Expand All @@ -187,12 +230,18 @@ offset_bottom = 114.0
metadata/_edit_layout_mode = 0
metadata/_edit_use_custom_anchors = false

[node name="Sprite2D" type="Sprite2D" parent="ToolsPanel/BrushSettings/ButtonShapeCircle"]
position = Vector2(28, 27)
scale = Vector2(2.5, 2.5)
texture = ExtResource( "3" )
region_enabled = true
region_rect = Rect2(16, 16, 16, 16)
[node name="TextureRect" type="TextureRect" parent="ToolsPanel/BrushSettings/ButtonShapeCircle"]
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 5.0
offset_top = 5.0
offset_right = -5.0
offset_bottom = -5.0
grow_horizontal = 2
grow_vertical = 2
texture = SubResource( "AtlasTexture_t52fe" )
metadata/_edit_layout_mode = 1
metadata/_edit_use_custom_anchors = false

[node name="LabelBackgroundColor" type="Label" parent="ToolsPanel"]
offset_left = 20.0
Expand Down Expand Up @@ -251,6 +300,8 @@ metadata/_edit_layout_mode = 0
metadata/_edit_use_custom_anchors = false

[node name="SaveFileDialog" type="FileDialog" parent="."]
size = Vector2i(800, 300)
min_size = Vector2i(800, 300)
access = 2
filters = PackedStringArray("*.png")
show_hidden_files = true
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
45 changes: 17 additions & 28 deletions gui/pseudolocalization/Pseudolocalization.gd
Original file line number Diff line number Diff line change
@@ -1,78 +1,67 @@
extends Node2D
extends Control

func _ready():
$HBoxContainer/Pseudolocalization_options/accents.button_pressed = ProjectSettings.get("internationalization/pseudolocalization/replace_with_accents")
$HBoxContainer/Pseudolocalization_options/toggle.button_pressed = TranslationServer.pseudolocalization_enabled
$HBoxContainer/Pseudolocalization_options/fakebidi.button_pressed = ProjectSettings.get("internationalization/pseudolocalization/fake_bidi")
$HBoxContainer/Pseudolocalization_options/doublevowels.button_pressed = ProjectSettings.get("internationalization/pseudolocalization/double_vowels")
$HBoxContainer/Pseudolocalization_options/override.button_pressed = ProjectSettings.get("internationalization/pseudolocalization/override")
$HBoxContainer/Pseudolocalization_options/skipplaceholders.button_pressed = ProjectSettings.get("internationalization/pseudolocalization/skip_placeholders")
$HBoxContainer/Pseudolocalization_options/prefix/TextEdit.text = ProjectSettings.get("internationalization/pseudolocalization/prefix")
$HBoxContainer/Pseudolocalization_options/suffix/TextEdit.text = ProjectSettings.get("internationalization/pseudolocalization/suffix")
$HBoxContainer/Pseudolocalization_options/exp_ratio/TextEdit.text = str(ProjectSettings.get("internationalization/pseudolocalization/expansion_ratio"))
pass
$Main/Pseudolocalization_options/accents.button_pressed = ProjectSettings.get("internationalization/pseudolocalization/replace_with_accents")
$Main/Pseudolocalization_options/toggle.button_pressed = TranslationServer.pseudolocalization_enabled
$Main/Pseudolocalization_options/fakebidi.button_pressed = ProjectSettings.get("internationalization/pseudolocalization/fake_bidi")
$Main/Pseudolocalization_options/doublevowels.button_pressed = ProjectSettings.get("internationalization/pseudolocalization/double_vowels")
$Main/Pseudolocalization_options/override.button_pressed = ProjectSettings.get("internationalization/pseudolocalization/override")
$Main/Pseudolocalization_options/skipplaceholders.button_pressed = ProjectSettings.get("internationalization/pseudolocalization/skip_placeholders")
$Main/Pseudolocalization_options/prefix/TextEdit.text = ProjectSettings.get("internationalization/pseudolocalization/prefix")
$Main/Pseudolocalization_options/suffix/TextEdit.text = ProjectSettings.get("internationalization/pseudolocalization/suffix")
$Main/Pseudolocalization_options/exp_ratio/TextEdit.text = str(ProjectSettings.get("internationalization/pseudolocalization/expansion_ratio"))


func _on_accents_toggled(button_pressed):
ProjectSettings.set("internationalization/pseudolocalization/replace_with_accents", button_pressed)
TranslationServer.reload_pseudolocalization()
pass


func _on_toggle_toggled(button_pressed):
TranslationServer.pseudolocalization_enabled = button_pressed
pass


func _on_fakebidi_toggled(button_pressed):
ProjectSettings.set("internationalization/pseudolocalization/fake_bidi", button_pressed)
TranslationServer.reload_pseudolocalization()
pass


func _on_prefix_changed():
ProjectSettings.set("internationalization/pseudolocalization/prefix", $HBoxContainer/Pseudolocalization_options/prefix/TextEdit.text)
ProjectSettings.set("internationalization/pseudolocalization/prefix", $Main/Pseudolocalization_options/prefix/TextEdit.text)
TranslationServer.reload_pseudolocalization()
pass


func _on_suffix_changed():
ProjectSettings.set("internationalization/pseudolocalization/suffix", $HBoxContainer/Pseudolocalization_options/suffix/TextEdit.text)
ProjectSettings.set("internationalization/pseudolocalization/suffix", $Main/Pseudolocalization_options/suffix/TextEdit.text)
TranslationServer.reload_pseudolocalization()
pass


func _on_Pseudolocalize_pressed():
$HBoxContainer/Pseudolocalizer/Result.text = TranslationServer.pseudolocalize($HBoxContainer/Pseudolocalizer/Key.text)
pass
$Main/Pseudolocalizer/Result.text = TranslationServer.pseudolocalize($Main/Pseudolocalizer/Key.text)


func _on_doublevowels_toggled(button_pressed):
ProjectSettings.set("internationalization/pseudolocalization/double_vowels", button_pressed)
TranslationServer.reload_pseudolocalization()
pass


func _on_expansion_ratio_text_changed():
float()
var ratio = ($HBoxContainer/Pseudolocalization_options/exp_ratio/TextEdit.text).to_float()
var ratio = ($Main/Pseudolocalization_options/exp_ratio/TextEdit.text).to_float()
if ratio > 1:
ratio = 1
$HBoxContainer/Pseudolocalization_options/exp_ratio/TextEdit.text = str(ratio)
$Main/Pseudolocalization_options/exp_ratio/TextEdit.text = str(ratio)
if ratio < 0:
ratio = 0
$HBoxContainer/Pseudolocalization_options/exp_ratio/TextEdit.text = str(ratio)
$Main/Pseudolocalization_options/exp_ratio/TextEdit.text = str(ratio)
ProjectSettings.set("internationalization/pseudolocalization/expansion_ratio", ratio)
TranslationServer.reload_pseudolocalization()
pass


func _on_override_toggled(button_pressed):
ProjectSettings.set("internationalization/pseudolocalization/override", button_pressed)
TranslationServer.reload_pseudolocalization()
pass


func _on_skipplaceholders_toggled(button_pressed):
ProjectSettings.set("internationalization/pseudolocalization/skip_placeholders", button_pressed)
TranslationServer.reload_pseudolocalization()
pass
Loading

0 comments on commit ae57eb2

Please sign in to comment.