Browse Source

Merge pull request #734 from voylin/GDPaint4.0Update

GD Paint Demo Update to 4.0
Aaron Franke 3 years ago
parent
commit
7349ccc6a0

+ 1 - 1
2d/gd_paint/README.md

@@ -6,7 +6,7 @@ and eraser, as well as a rectangle and a circle brush.
 
 Language: GDScript
 
-Renderer: GLES 2
+Renderer: Vulkan Mobile
 
 Check out this demo on the asset library: https://godotengine.org/asset-library/asset/517
 

+ 14 - 15
2d/gd_paint/icon.png.import

@@ -1,8 +1,9 @@
 [remap]
 
 importer="texture"
-type="StreamTexture2D"
-path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
+type="CompressedTexture2D"
+uid="uid://crrwsngk16wkg"
+path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"
 metadata={
 "vram_texture": false
 }
@@ -10,26 +11,24 @@ metadata={
 [deps]
 
 source_file="res://icon.png"
-dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"]
+dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"]
 
 [params]
 
 compress/mode=0
 compress/lossy_quality=0.7
-compress/hdr_mode=0
+compress/hdr_compression=1
 compress/bptc_ldr=0
 compress/normal_map=0
-flags/repeat=0
-flags/filter=true
-flags/mipmaps=false
-flags/anisotropic=false
-flags/srgb=2
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
 process/fix_alpha_border=true
 process/premult_alpha=false
-process/HDR_as_SRGB=false
-process/invert_color=false
 process/normal_map_invert_y=false
-stream=false
-size_limit=0
-detect_3d=true
-svg/scale=1.0
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1

+ 2 - 4
2d/gd_paint/paint_control.gd

@@ -5,7 +5,7 @@ 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(930, 720)
+const IMAGE_SIZE = Vector2(674, 600)
 
 # Enums for the various modes and brush shapes that can be applied.
 enum BrushModes {
@@ -242,11 +242,9 @@ func save_picture(path):
 	await RenderingServer.frame_post_draw
 
 	# Get the viewport image.
-	var img = get_viewport().get_texture().get_data()
+	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))
-	# Flip the image on the Y-axis (it's flipped upside down by default).
-	cropped_image.flip_y()
 
 	# Save the image with the passed in path we got from the save dialog.
 	cropped_image.save_png(path)

+ 114 - 86
2d/gd_paint/paint_root.tscn

@@ -1,114 +1,128 @@
-[gd_scene load_steps=5 format=2]
+[gd_scene load_steps=5 format=3 uid="uid://bhjmyer4wlwy2"]
 
-[ext_resource path="res://paint_control.gd" type="Script" id=1]
-[ext_resource path="res://tools_panel.gd" type="Script" id=2]
-[ext_resource path="res://paint_tools.png" type="Texture2D" id=3]
+[ext_resource type="Script" path="res://paint_control.gd" id="1"]
+[ext_resource type="Script" path="res://tools_panel.gd" id="2"]
+[ext_resource type="Texture2D" uid="uid://cdqq0m3rrlbva" path="res://paint_tools.png" id="3"]
 
-[sub_resource type="StyleBoxFlat" id=1]
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_4ksjc"]
 bg_color = Color(1, 1, 1, 1)
 
 [node name="PaintRoot" type="Control"]
-offset_right = 40.0
-offset_bottom = 40.0
-__meta__ = {
-"_edit_use_anchors_": false
-}
+anchor_right = 1.0
+anchor_bottom = 1.0
 
 [node name="DrawingAreaBG" type="Panel" parent="."]
 offset_left = 350.0
-offset_right = 1280.0
-offset_bottom = 720.0
-custom_styles/panel = SubResource( 1 )
+offset_right = 1024.0
+offset_bottom = 600.0
+theme_override_styles/panel = SubResource( "StyleBoxFlat_4ksjc" )
+metadata/_edit_layout_mode = 0
+metadata/_edit_use_custom_anchors = false
 
 [node name="PaintControl" type="Control" parent="."]
-offset_right = 40.0
-offset_bottom = 40.0
-script = ExtResource( 1 )
-__meta__ = {
-"_edit_use_anchors_": false
-}
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+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 = 720.0
-script = ExtResource( 2 )
+offset_bottom = 600.0
+script = ExtResource( "2" )
+metadata/_edit_layout_mode = 0
+metadata/_edit_use_custom_anchors = false
 
 [node name="LabelTools" type="Label" parent="ToolsPanel"]
 offset_left = 20.0
-offset_top = 10.0
+offset_top = 6.0
 offset_right = 330.0
-offset_bottom = 24.0
+offset_bottom = 32.0
 text = "Selected tool: Pencil"
-align = 1
+metadata/_edit_layout_mode = 0
+metadata/_edit_use_custom_anchors = false
 
 [node name="ButtonToolPencil" type="Button" parent="ToolsPanel"]
 offset_left = 40.0
-offset_top = 40.0
-offset_right = 100.0
-offset_bottom = 100.0
+offset_top = 30.0
+offset_right = 95.0
+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(30, 30)
+position = Vector2(27, 26)
 scale = Vector2(2.5, 2.5)
-texture = ExtResource( 3 )
+texture = ExtResource( "3" )
 region_enabled = true
 region_rect = Rect2(0, 0, 16, 16)
 
 [node name="ButtonToolEraser" type="Button" parent="ToolsPanel"]
 offset_left = 110.0
-offset_top = 40.0
-offset_right = 170.0
-offset_bottom = 100.0
+offset_top = 30.0
+offset_right = 165.0
+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(30, 30)
+position = Vector2(29, 26)
 scale = Vector2(2.5, 2.5)
-texture = ExtResource( 3 )
+texture = ExtResource( "3" )
 region_enabled = true
 region_rect = Rect2(16, 0, 16, 16)
 
 [node name="ButtonToolRectangle" type="Button" parent="ToolsPanel"]
 offset_left = 180.0
-offset_top = 40.0
-offset_right = 240.0
-offset_bottom = 100.0
+offset_top = 30.0
+offset_right = 235.0
+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(30, 30)
+position = Vector2(28, 26)
 scale = Vector2(2.5, 2.5)
-texture = ExtResource( 3 )
+texture = ExtResource( "3" )
 region_enabled = true
 region_rect = Rect2(0, 16, 16, 16)
 
 [node name="ButtonToolCircle" type="Button" parent="ToolsPanel"]
 offset_left = 250.0
-offset_top = 40.0
-offset_right = 310.0
-offset_bottom = 100.0
+offset_top = 30.0
+offset_right = 305.0
+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(30, 30)
+position = Vector2(28, 26)
 scale = Vector2(2.5, 2.5)
-texture = ExtResource( 3 )
+texture = ExtResource( "3" )
 region_enabled = true
 region_rect = Rect2(16, 16, 16, 16)
 
 [node name="LabelBrushColor" type="Label" parent="ToolsPanel"]
 offset_left = 20.0
-offset_top = 120.0
+offset_top = 91.0
 offset_right = 330.0
-offset_bottom = 134.0
+offset_bottom = 117.0
 text = "Current color"
-align = 1
+metadata/_edit_layout_mode = 0
+metadata/_edit_use_custom_anchors = false
 
 [node name="ColorPickerBrush" type="ColorPickerButton" parent="ToolsPanel"]
 offset_left = 20.0
-offset_top = 140.0
+offset_top = 115.0
 offset_right = 330.0
-offset_bottom = 190.0
+offset_bottom = 155.0
+metadata/_edit_layout_mode = 0
+metadata/_edit_use_custom_anchors = false
 
 [node name="BrushSettings" type="Control" parent="ToolsPanel"]
 offset_top = 200.0
@@ -117,106 +131,120 @@ offset_bottom = 375.0
 
 [node name="LabelBrushSize" type="Label" parent="ToolsPanel/BrushSettings"]
 offset_left = 20.0
-offset_top = 10.0
+offset_top = -37.0
 offset_right = 330.0
-offset_bottom = 24.0
+offset_bottom = -11.0
 text = "Brush size: 32px"
-align = 1
+metadata/_edit_layout_mode = 0
+metadata/_edit_use_custom_anchors = false
 
 [node name="HScrollBarBrushSize" type="HScrollBar" parent="ToolsPanel/BrushSettings"]
 offset_left = 20.0
-offset_top = 30.0
+offset_top = -8.0
 offset_right = 330.0
-offset_bottom = 60.0
+offset_bottom = 17.0
 min_value = 2.0
 step = 1.0
 value = 32.0
+metadata/_edit_layout_mode = 0
+metadata/_edit_use_custom_anchors = false
 
 [node name="LabelBrushShape" type="Label" parent="ToolsPanel/BrushSettings"]
 offset_left = 20.0
-offset_top = 80.0
+offset_top = 29.0
 offset_right = 330.0
-offset_bottom = 94.0
+offset_bottom = 55.0
 text = "Brush shape: Circle"
-align = 1
+metadata/_edit_layout_mode = 0
+metadata/_edit_use_custom_anchors = false
 
 [node name="ButtonShapeBox" type="Button" parent="ToolsPanel/BrushSettings"]
 offset_left = 100.0
-offset_top = 100.0
-offset_right = 160.0
-offset_bottom = 160.0
+offset_top = 59.0
+offset_right = 155.0
+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(30, 30)
+position = Vector2(27, 27)
 scale = Vector2(2.5, 2.5)
-texture = ExtResource( 3 )
+texture = ExtResource( "3" )
 region_enabled = true
 region_rect = Rect2(0, 16, 16, 16)
 
 [node name="ButtonShapeCircle" type="Button" parent="ToolsPanel/BrushSettings"]
 offset_left = 190.0
-offset_top = 100.0
-offset_right = 250.0
-offset_bottom = 160.0
+offset_top = 59.0
+offset_right = 245.0
+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(30, 30)
+position = Vector2(28, 27)
 scale = Vector2(2.5, 2.5)
-texture = ExtResource( 3 )
+texture = ExtResource( "3" )
 region_enabled = true
 region_rect = Rect2(16, 16, 16, 16)
 
 [node name="LabelBackgroundColor" type="Label" parent="ToolsPanel"]
 offset_left = 20.0
-offset_top = 400.0
+offset_top = 323.0
 offset_right = 330.0
-offset_bottom = 414.0
+offset_bottom = 349.0
 text = "Background color"
-align = 1
+metadata/_edit_layout_mode = 0
+metadata/_edit_use_custom_anchors = false
 
 [node name="ColorPickerBackground" type="ColorPickerButton" parent="ToolsPanel"]
 offset_left = 20.0
-offset_top = 420.0
+offset_top = 351.0
 offset_right = 330.0
-offset_bottom = 470.0
+offset_bottom = 391.0
 color = Color(1, 1, 1, 1)
 edit_alpha = false
+metadata/_edit_layout_mode = 0
+metadata/_edit_use_custom_anchors = false
 
 [node name="LabelStats" type="Label" parent="ToolsPanel"]
 modulate = Color(0.414062, 0.414062, 0.414062, 1)
 offset_left = 20.0
-offset_top = 590.0
+offset_top = 463.0
 offset_right = 330.0
-offset_bottom = 604.0
+offset_bottom = 489.0
 text = "Brush objects: 00000"
-align = 1
+metadata/_edit_layout_mode = 0
+metadata/_edit_use_custom_anchors = false
 
 [node name="ButtonUndo" type="Button" parent="ToolsPanel"]
 offset_left = 10.0
-offset_top = 520.0
+offset_top = 415.0
 offset_right = 340.0
-offset_bottom = 560.0
+offset_bottom = 450.0
 text = "Undo last stroke"
+metadata/_edit_layout_mode = 0
+metadata/_edit_use_custom_anchors = false
 
 [node name="ButtonSave" type="Button" parent="ToolsPanel"]
 offset_left = 10.0
-offset_top = 620.0
+offset_top = 506.0
 offset_right = 340.0
-offset_bottom = 660.0
+offset_bottom = 541.0
 text = "Save picture"
+metadata/_edit_layout_mode = 0
+metadata/_edit_use_custom_anchors = false
 
 [node name="ButtonClear" type="Button" parent="ToolsPanel"]
 offset_left = 10.0
-offset_top = 670.0
+offset_top = 550.0
 offset_right = 340.0
-offset_bottom = 710.0
+offset_bottom = 585.0
 text = "Clear picture"
+metadata/_edit_layout_mode = 0
+metadata/_edit_use_custom_anchors = false
 
 [node name="SaveFileDialog" type="FileDialog" parent="."]
-offset_right = 600.0
-offset_bottom = 400.0
-resizable = true
 access = 2
 filters = PackedStringArray("*.png")
-current_dir = "/home/aaronfranke/workspace/godot-demo-projects/2d/gd_paint"
-current_path = "/home/aaronfranke/workspace/godot-demo-projects/2d/gd_paint/"
+show_hidden_files = true

+ 14 - 15
2d/gd_paint/paint_tools.png.import

@@ -1,8 +1,9 @@
 [remap]
 
 importer="texture"
-type="StreamTexture2D"
-path="res://.godot/imported/paint_tools.png-224b64b7ddb26189a369199f6d686b79.stex"
+type="CompressedTexture2D"
+uid="uid://cdqq0m3rrlbva"
+path="res://.godot/imported/paint_tools.png-224b64b7ddb26189a369199f6d686b79.ctex"
 metadata={
 "vram_texture": false
 }
@@ -10,26 +11,24 @@ metadata={
 [deps]
 
 source_file="res://paint_tools.png"
-dest_files=["res://.godot/imported/paint_tools.png-224b64b7ddb26189a369199f6d686b79.stex"]
+dest_files=["res://.godot/imported/paint_tools.png-224b64b7ddb26189a369199f6d686b79.ctex"]
 
 [params]
 
 compress/mode=0
 compress/lossy_quality=0.7
-compress/hdr_mode=0
+compress/hdr_compression=1
 compress/bptc_ldr=0
 compress/normal_map=0
-flags/repeat=0
-flags/filter=true
-flags/mipmaps=false
-flags/anisotropic=false
-flags/srgb=2
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
 process/fix_alpha_border=true
 process/premult_alpha=false
-process/HDR_as_SRGB=false
-process/invert_color=false
 process/normal_map_invert_y=false
-stream=false
-size_limit=0
-detect_3d=true
-svg/scale=1.0
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1

+ 9 - 12
2d/gd_paint/project.godot

@@ -6,7 +6,7 @@
 ;   [section] ; section goes between []
 ;   param=value ; assign values to parameters
 
-config_version=4
+config_version=5
 
 [application]
 
@@ -16,21 +16,18 @@ It supports different types of 'brushes': a basic pen/pencil
 and eraser, as well as a rectangle and a circle brush."
 run/main_scene="res://paint_root.tscn"
 config/icon="res://icon.png"
+config/features=PackedStringArray("4.0")
 
-[display]
+[debug]
 
-window/size/width=1280
-window/size/height=720
-window/dpi/allow_hidpi=true
-window/stretch/mode="2d"
-window/stretch/aspect="keep"
+gdscript/warnings/redundant_await=false
 
-[gdnative]
+[display]
 
-singletons=[]
+window/size/window_width_override=1280
+window/size/window_height_override=720
+window/stretch/mode="canvas_items"
 
 [rendering]
 
-quality/driver/driver_name="GLES2"
-vram_compression/import_etc=true
-vram_compression/import_etc2=false
+vulkan/rendering/back_end=1

+ 2 - 2
2d/gd_paint/tools_panel.gd

@@ -39,7 +39,7 @@ func _ready():
 
 func _physics_process(_delta):
 	# Update the status label with the newest brush element count.
-	label_stats.text = "Brush objects: " + String(paint_control.brush_data_list.size())
+	label_stats.text = "Brush objects: " + str(paint_control.brush_data_list.size())
 
 
 func button_pressed(button_name):
@@ -104,7 +104,7 @@ func background_color_changed(color):
 func brush_size_changed(value):
 	# Change the size of the brush, and update the label to reflect the new value.
 	paint_control.brush_size = ceil(value)
-	label_brush_size.text = "Brush size: " + String(ceil(value)) + "px"
+	label_brush_size.text = "Brush size: " + str(ceil(value)) + "px"
 
 
 func save_file_selected(path):