summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/capsule_shape_2d.cpp3
-rw-r--r--scene/resources/circle_shape_2d.cpp3
-rw-r--r--scene/resources/convex_polygon_shape_2d.cpp3
-rw-r--r--scene/resources/default_theme/default_theme.cpp2
-rw-r--r--scene/resources/font.cpp35
-rw-r--r--scene/resources/font.h13
-rw-r--r--scene/resources/packed_scene.cpp6
-rw-r--r--scene/resources/rectangle_shape_2d.cpp22
-rw-r--r--scene/resources/style_box.cpp13
-rw-r--r--scene/resources/surface_tool.cpp1
-rw-r--r--scene/resources/text_line.cpp1
-rw-r--r--scene/resources/text_paragraph.cpp2
-rw-r--r--scene/resources/visual_shader.cpp19
-rw-r--r--scene/resources/visual_shader.h3
14 files changed, 113 insertions, 13 deletions
diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp
index 3725d855f4..acf7319339 100644
--- a/scene/resources/capsule_shape_2d.cpp
+++ b/scene/resources/capsule_shape_2d.cpp
@@ -85,6 +85,9 @@ void CapsuleShape2D::draw(const RID &p_to_rid, const Color &p_color) {
Vector<Color> col;
col.push_back(p_color);
RenderingServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col);
+ RenderingServer::get_singleton()->canvas_item_add_polyline(p_to_rid, points, col);
+ // Draw the last segment as it's not drawn by `canvas_item_add_polyline()`.
+ RenderingServer::get_singleton()->canvas_item_add_line(p_to_rid, points[points.size() - 1], points[0], p_color);
}
Rect2 CapsuleShape2D::get_rect() const {
diff --git a/scene/resources/circle_shape_2d.cpp b/scene/resources/circle_shape_2d.cpp
index 735bf47482..a8a9c42fbd 100644
--- a/scene/resources/circle_shape_2d.cpp
+++ b/scene/resources/circle_shape_2d.cpp
@@ -79,6 +79,9 @@ void CircleShape2D::draw(const RID &p_to_rid, const Color &p_color) {
Vector<Color> col;
col.push_back(p_color);
RenderingServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col);
+ RenderingServer::get_singleton()->canvas_item_add_polyline(p_to_rid, points, col);
+ // Draw the last segment as it's not drawn by `canvas_item_add_polyline()`.
+ RenderingServer::get_singleton()->canvas_item_add_line(p_to_rid, points[points.size() - 1], points[0], p_color);
}
CircleShape2D::CircleShape2D() :
diff --git a/scene/resources/convex_polygon_shape_2d.cpp b/scene/resources/convex_polygon_shape_2d.cpp
index b4b200a7ff..7271614995 100644
--- a/scene/resources/convex_polygon_shape_2d.cpp
+++ b/scene/resources/convex_polygon_shape_2d.cpp
@@ -75,6 +75,9 @@ void ConvexPolygonShape2D::draw(const RID &p_to_rid, const Color &p_color) {
Vector<Color> col;
col.push_back(p_color);
RenderingServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col);
+ RenderingServer::get_singleton()->canvas_item_add_polyline(p_to_rid, points, col);
+ // Draw the last segment as it's not drawn by `canvas_item_add_polyline()`.
+ RenderingServer::get_singleton()->canvas_item_add_line(p_to_rid, points[points.size() - 1], points[0], p_color);
}
Rect2 ConvexPolygonShape2D::get_rect() const {
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 83ce243d3b..a94209c75f 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -676,6 +676,8 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_constant("hseparation", "PopupMenu", 4 * scale);
theme->set_constant("vseparation", "PopupMenu", 4 * scale);
theme->set_constant("outline_size", "PopupMenu", 0);
+ theme->set_constant("item_start_padding", "PopupMenu", 2 * scale);
+ theme->set_constant("item_end_padding", "PopupMenu", 2 * scale);
// GraphNode
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp
index 5acb75c3ce..6f87c524d8 100644
--- a/scene/resources/font.cpp
+++ b/scene/resources/font.cpp
@@ -55,6 +55,9 @@ void FontData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_underline_position", "size"), &FontData::get_underline_position);
ClassDB::bind_method(D_METHOD("get_underline_thickness", "size"), &FontData::get_underline_thickness);
+ ClassDB::bind_method(D_METHOD("get_spacing", "type"), &FontData::get_spacing);
+ ClassDB::bind_method(D_METHOD("set_spacing", "type", "value"), &FontData::set_spacing);
+
ClassDB::bind_method(D_METHOD("set_antialiased", "antialiased"), &FontData::set_antialiased);
ClassDB::bind_method(D_METHOD("get_antialiased"), &FontData::get_antialiased);
@@ -105,6 +108,13 @@ void FontData::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "distance_field_hint"), "set_distance_field_hint", "get_distance_field_hint");
ADD_PROPERTY(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), "set_hinting", "get_hinting");
+
+ ADD_GROUP("Extra Spacing", "extra_spacing");
+ ADD_PROPERTYI(PropertyInfo(Variant::INT, "extra_spacing_glyph"), "set_spacing", "get_spacing", SPACING_GLYPH);
+ ADD_PROPERTYI(PropertyInfo(Variant::INT, "extra_spacing_space"), "set_spacing", "get_spacing", SPACING_SPACE);
+
+ BIND_ENUM_CONSTANT(SPACING_GLYPH);
+ BIND_ENUM_CONSTANT(SPACING_SPACE);
}
bool FontData::_set(const StringName &p_name, const Variant &p_value) {
@@ -322,6 +332,27 @@ double FontData::get_variation(const String &p_name) const {
return TS->font_get_variation(rid, p_name);
}
+int FontData::get_spacing(int p_type) const {
+ if (rid == RID()) {
+ return 0;
+ }
+ if (p_type == SPACING_GLYPH) {
+ return TS->font_get_spacing_glyph(rid);
+ } else {
+ return TS->font_get_spacing_space(rid);
+ }
+}
+
+void FontData::set_spacing(int p_type, int p_value) {
+ ERR_FAIL_COND(rid == RID());
+ if (p_type == SPACING_GLYPH) {
+ TS->font_set_spacing_glyph(rid, p_value);
+ } else {
+ TS->font_set_spacing_space(rid, p_value);
+ }
+ emit_changed();
+}
+
void FontData::set_antialiased(bool p_antialiased) {
ERR_FAIL_COND(rid == RID());
TS->font_set_antialiased(rid, p_antialiased);
@@ -830,6 +861,8 @@ Size2 Font::get_multiline_string_size(const String &p_text, float p_width, int p
}
void Font::draw_string(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HAlign p_align, float p_width, int p_size, const Color &p_modulate, int p_outline_size, const Color &p_outline_modulate, uint8_t p_flags) const {
+ ERR_FAIL_COND(data.is_empty());
+
uint64_t hash = p_text.hash64();
hash = hash_djb2_one_64(p_size, hash);
@@ -860,6 +893,8 @@ void Font::draw_string(RID p_canvas_item, const Point2 &p_pos, const String &p_t
}
void Font::draw_multiline_string(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HAlign p_align, float p_width, int p_max_lines, int p_size, const Color &p_modulate, int p_outline_size, const Color &p_outline_modulate, uint8_t p_flags) const {
+ ERR_FAIL_COND(data.is_empty());
+
uint64_t hash = p_text.hash64();
hash = hash_djb2_one_64(p_size, hash);
diff --git a/scene/resources/font.h b/scene/resources/font.h
index 230ea26c7f..200373aa8c 100644
--- a/scene/resources/font.h
+++ b/scene/resources/font.h
@@ -42,6 +42,13 @@
class FontData : public Resource {
GDCLASS(FontData, Resource);
+public:
+ enum SpacingType {
+ SPACING_GLYPH,
+ SPACING_SPACE,
+ };
+
+private:
RID rid;
int base_size = 16;
String path;
@@ -84,6 +91,9 @@ public:
float get_underline_position(int p_size) const;
float get_underline_thickness(int p_size) const;
+ int get_spacing(int p_type) const;
+ void set_spacing(int p_type, int p_value);
+
void set_antialiased(bool p_antialiased);
bool get_antialiased() const;
@@ -140,7 +150,7 @@ class Font : public Resource {
public:
enum SpacingType {
SPACING_TOP,
- SPACING_BOTTOM
+ SPACING_BOTTOM,
};
private:
@@ -205,6 +215,7 @@ public:
~Font();
};
+VARIANT_ENUM_CAST(FontData::SpacingType);
VARIANT_ENUM_CAST(Font::SpacingType);
/*************************************************************************/
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index beb365d44e..5d351f51f7 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -469,6 +469,11 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
p_node->get_property_list(&plist);
StringName type = p_node->get_class();
+ Ref<Script> script = p_node->get_script();
+ if (script.is_valid()) {
+ script->update_exports();
+ }
+
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
@@ -484,7 +489,6 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
isdefault = bool(Variant::evaluate(Variant::OP_EQUAL, value, default_value));
}
- Ref<Script> script = p_node->get_script();
if (!isdefault && script.is_valid() && script->get_property_default_value(name, default_value)) {
isdefault = bool(Variant::evaluate(Variant::OP_EQUAL, value, default_value));
}
diff --git a/scene/resources/rectangle_shape_2d.cpp b/scene/resources/rectangle_shape_2d.cpp
index a5b909c9a7..0fd65d8c72 100644
--- a/scene/resources/rectangle_shape_2d.cpp
+++ b/scene/resources/rectangle_shape_2d.cpp
@@ -33,7 +33,7 @@
#include "servers/physics_server_2d.h"
#include "servers/rendering_server.h"
void RectangleShape2D::_update_shape() {
- PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), size / 2);
+ PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), size * 0.5);
emit_changed();
}
@@ -47,11 +47,27 @@ Vector2 RectangleShape2D::get_size() const {
}
void RectangleShape2D::draw(const RID &p_to_rid, const Color &p_color) {
- RenderingServer::get_singleton()->canvas_item_add_rect(p_to_rid, Rect2(-size / 2, size), p_color);
+ // Draw an outlined rectangle to make individual shapes easier to distinguish.
+ Vector<Vector2> stroke_points;
+ stroke_points.resize(5);
+ stroke_points.write[0] = -size * 0.5;
+ stroke_points.write[1] = Vector2(size.x, -size.y) * 0.5;
+ stroke_points.write[2] = size * 0.5;
+ stroke_points.write[3] = Vector2(-size.x, size.y) * 0.5;
+ stroke_points.write[4] = -size * 0.5;
+
+ Vector<Color> stroke_colors;
+ stroke_colors.resize(5);
+ for (int i = 0; i < 5; i++) {
+ stroke_colors.write[i] = (p_color);
+ }
+
+ RenderingServer::get_singleton()->canvas_item_add_rect(p_to_rid, Rect2(-size * 0.5, size), p_color);
+ RenderingServer::get_singleton()->canvas_item_add_polyline(p_to_rid, stroke_points, stroke_colors);
}
Rect2 RectangleShape2D::get_rect() const {
- return Rect2(-size / 2, size);
+ return Rect2(-size * 0.5, size);
}
real_t RectangleShape2D::get_enclosing_radius() const {
diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp
index 8e47c1c15c..9b80224c3f 100644
--- a/scene/resources/style_box.cpp
+++ b/scene/resources/style_box.cpp
@@ -937,8 +937,17 @@ void StyleBoxLine::_bind_methods() {
}
float StyleBoxLine::get_style_margin(Side p_side) const {
- ERR_FAIL_INDEX_V((int)p_side, 4, thickness);
- return thickness;
+ ERR_FAIL_INDEX_V((int)p_side, 4, 0);
+
+ if (vertical) {
+ if (p_side == SIDE_LEFT || p_side == SIDE_RIGHT) {
+ return thickness / 2.0;
+ }
+ } else if (p_side == SIDE_TOP || p_side == SIDE_BOTTOM) {
+ return thickness / 2.0;
+ }
+
+ return 0;
}
Size2 StyleBoxLine::get_center_size() const {
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index 5ce3532d42..47933bd69a 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -299,6 +299,7 @@ void SurfaceTool::add_triangle_fan(const Vector<Vector3> &p_vertices, const Vect
void SurfaceTool::add_index(int p_index) {
ERR_FAIL_COND(!begun);
+ ERR_FAIL_COND(p_index < 0);
format |= Mesh::ARRAY_FORMAT_INDEX;
index_array.push_back(p_index);
diff --git a/scene/resources/text_line.cpp b/scene/resources/text_line.cpp
index ed69c093cf..925867a1f2 100644
--- a/scene/resources/text_line.cpp
+++ b/scene/resources/text_line.cpp
@@ -167,6 +167,7 @@ void TextLine::set_bidi_override(const Vector<Vector2i> &p_override) {
}
bool TextLine::add_string(const String &p_text, const Ref<Font> &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language) {
+ ERR_FAIL_COND_V(p_fonts.is_null(), false);
bool res = TS->shaped_text_add_string(rid, p_text, p_fonts->get_rids(), p_size, p_opentype_features, p_language);
spacing_top = p_fonts->get_spacing(Font::SPACING_TOP);
spacing_bottom = p_fonts->get_spacing(Font::SPACING_BOTTOM);
diff --git a/scene/resources/text_paragraph.cpp b/scene/resources/text_paragraph.cpp
index 94957df510..444a4bb22a 100644
--- a/scene/resources/text_paragraph.cpp
+++ b/scene/resources/text_paragraph.cpp
@@ -243,6 +243,7 @@ TextServer::Orientation TextParagraph::get_orientation() const {
}
bool TextParagraph::set_dropcap(const String &p_text, const Ref<Font> &p_fonts, int p_size, const Rect2 &p_dropcap_margins, const Dictionary &p_opentype_features, const String &p_language) {
+ ERR_FAIL_COND_V(p_fonts.is_null(), false);
TS->shaped_text_clear(dropcap_rid);
dropcap_margins = p_dropcap_margins;
bool res = TS->shaped_text_add_string(dropcap_rid, p_text, p_fonts->get_rids(), p_size, p_opentype_features, p_language);
@@ -257,6 +258,7 @@ void TextParagraph::clear_dropcap() {
}
bool TextParagraph::add_string(const String &p_text, const Ref<Font> &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language) {
+ ERR_FAIL_COND_V(p_fonts.is_null(), false);
bool res = TS->shaped_text_add_string(rid, p_text, p_fonts->get_rids(), p_size, p_opentype_features, p_language);
spacing_top = p_fonts->get_spacing(Font::SPACING_TOP);
spacing_bottom = p_fonts->get_spacing(Font::SPACING_BOTTOM);
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index 438e130cf4..859546694f 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -585,6 +585,12 @@ bool VisualShader::is_port_types_compatible(int p_a, int p_b) const {
void VisualShader::connect_nodes_forced(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) {
ERR_FAIL_INDEX(p_type, TYPE_MAX);
Graph *g = &graph[p_type];
+
+ ERR_FAIL_COND(!g->nodes.has(p_from_node));
+ ERR_FAIL_INDEX(p_from_port, g->nodes[p_from_node].node->get_output_port_count());
+ ERR_FAIL_COND(!g->nodes.has(p_to_node));
+ ERR_FAIL_INDEX(p_to_port, g->nodes[p_to_node].node->get_input_port_count());
+
Connection c;
c.from_node = p_from_node;
c.from_port = p_from_port;
@@ -675,6 +681,8 @@ void VisualShader::get_node_connections(Type p_type, List<Connection> *r_connect
}
void VisualShader::set_mode(Mode p_mode) {
+ ERR_FAIL_INDEX_MSG(p_mode, Mode::MODE_MAX, vformat("Invalid shader mode: %d.", p_mode));
+
if (shader_mode == p_mode) {
return;
}
@@ -1398,11 +1406,11 @@ bool VisualShader::has_func_name(RenderingServer::ShaderMode p_mode, const Strin
}
void VisualShader::_update_shader() const {
- if (!dirty) {
+ if (!dirty.is_set()) {
return;
}
- dirty = false;
+ dirty.clear();
StringBuilder global_code;
StringBuilder global_code_per_node;
@@ -1588,11 +1596,11 @@ void VisualShader::_update_shader() const {
}
void VisualShader::_queue_update() {
- if (dirty) {
+ if (dirty.is_set()) {
return;
}
- dirty = true;
+ dirty.set();
call_deferred("_update_shader");
}
@@ -1612,7 +1620,7 @@ void VisualShader::_input_type_changed(Type p_type, int p_id) {
}
void VisualShader::rebuild() {
- dirty = true;
+ dirty.set();
_update_shader();
}
@@ -1666,6 +1674,7 @@ void VisualShader::_bind_methods() {
}
VisualShader::VisualShader() {
+ dirty.set();
for (int i = 0; i < TYPE_MAX; i++) {
Ref<VisualShaderNodeOutput> output;
output.instance();
diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h
index f3f3caf15e..ef724c7650 100644
--- a/scene/resources/visual_shader.h
+++ b/scene/resources/visual_shader.h
@@ -32,6 +32,7 @@
#define VISUAL_SHADER_H
#include "core/string/string_builder.h"
+#include "core/templates/safe_refcount.h"
#include "scene/gui/control.h"
#include "scene/resources/shader.h"
@@ -99,7 +100,7 @@ private:
static RenderModeEnums render_mode_enums[];
- volatile mutable bool dirty = true;
+ mutable SafeFlag dirty;
void _queue_update();
union ConnectionKey {