summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/animated_sprite_2d.cpp307
-rw-r--r--scene/2d/animated_sprite_2d.h32
-rw-r--r--scene/2d/tile_map.cpp2
-rw-r--r--scene/3d/sprite_3d.cpp307
-rw-r--r--scene/3d/sprite_3d.h31
-rw-r--r--scene/animation/animation_player.cpp10
-rw-r--r--scene/animation/animation_tree.cpp2
-rw-r--r--scene/gui/line_edit.cpp199
-rw-r--r--scene/gui/line_edit.h6
-rw-r--r--scene/gui/rich_text_label.cpp2
-rw-r--r--scene/gui/spin_box.cpp2
-rw-r--r--scene/gui/subviewport_container.cpp41
-rw-r--r--scene/gui/subviewport_container.h3
-rw-r--r--scene/gui/text_edit.cpp196
-rw-r--r--scene/gui/text_edit.h5
-rw-r--r--scene/resources/sprite_frames.cpp6
-rw-r--r--scene/resources/sprite_frames.h8
-rw-r--r--scene/resources/style_box.cpp5
-rw-r--r--scene/resources/texture.cpp32
-rw-r--r--scene/resources/tile_set.cpp46
-rw-r--r--scene/resources/tile_set.h8
21 files changed, 830 insertions, 420 deletions
diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp
index a4a965aa41..ccf9696d82 100644
--- a/scene/2d/animated_sprite_2d.cpp
+++ b/scene/2d/animated_sprite_2d.cpp
@@ -117,7 +117,6 @@ void AnimatedSprite2D::_validate_property(PropertyInfo &p_property) const {
}
if (p_property.name == "animation") {
- p_property.hint = PROPERTY_HINT_ENUM;
List<StringName> names;
frames->get_animation_list(&names);
names.sort_custom<StringName::AlphCompare>();
@@ -167,6 +166,12 @@ void AnimatedSprite2D::_validate_property(PropertyInfo &p_property) const {
void AnimatedSprite2D::_notification(int p_what) {
switch (p_what) {
+ case NOTIFICATION_READY: {
+ if (!Engine::get_singleton()->is_editor_hint() && !frames.is_null() && frames->has_animation(autoplay)) {
+ play(autoplay);
+ }
+ } break;
+
case NOTIFICATION_INTERNAL_PROCESS: {
if (frames.is_null() || !frames->has_animation(animation)) {
return;
@@ -176,7 +181,8 @@ void AnimatedSprite2D::_notification(int p_what) {
int i = 0;
while (remaining) {
// Animation speed may be changed by animation_finished or frame_changed signals.
- double speed = frames->get_animation_speed(animation) * Math::abs(speed_scale);
+ double speed = frames->get_animation_speed(animation) * speed_scale * custom_speed_scale * frame_speed_scale;
+ double abs_speed = Math::abs(speed);
if (speed == 0) {
return; // Do nothing.
@@ -185,53 +191,57 @@ void AnimatedSprite2D::_notification(int p_what) {
// Frame count may be changed by animation_finished or frame_changed signals.
int fc = frames->get_frame_count(animation);
- if (timeout <= 0) {
- int last_frame = fc - 1;
- if (!playing_backwards) {
- // Forward.
+ int last_frame = fc - 1;
+ if (!signbit(speed)) {
+ // Forwards.
+ if (frame_progress >= 1.0) {
if (frame >= last_frame) {
if (frames->get_animation_loop(animation)) {
frame = 0;
- emit_signal(SceneStringNames::get_singleton()->animation_finished);
+ emit_signal("animation_looped");
} else {
frame = last_frame;
- if (!is_over) {
- is_over = true;
- emit_signal(SceneStringNames::get_singleton()->animation_finished);
- }
+ pause();
+ emit_signal(SceneStringNames::get_singleton()->animation_finished);
+ return;
}
} else {
frame++;
}
- } else {
- // Reversed.
+ _calc_frame_speed_scale();
+ frame_progress = 0.0;
+ queue_redraw();
+ emit_signal(SceneStringNames::get_singleton()->frame_changed);
+ }
+ double to_process = MIN((1.0 - frame_progress) / abs_speed, remaining);
+ frame_progress += to_process * abs_speed;
+ remaining -= to_process;
+ } else {
+ // Backwards.
+ if (frame_progress <= 0) {
if (frame <= 0) {
if (frames->get_animation_loop(animation)) {
frame = last_frame;
- emit_signal(SceneStringNames::get_singleton()->animation_finished);
+ emit_signal("animation_looped");
} else {
frame = 0;
- if (!is_over) {
- is_over = true;
- emit_signal(SceneStringNames::get_singleton()->animation_finished);
- }
+ pause();
+ emit_signal(SceneStringNames::get_singleton()->animation_finished);
+ return;
}
} else {
frame--;
}
+ _calc_frame_speed_scale();
+ frame_progress = 1.0;
+ queue_redraw();
+ emit_signal(SceneStringNames::get_singleton()->frame_changed);
}
-
- timeout = _get_frame_duration();
-
- queue_redraw();
-
- emit_signal(SceneStringNames::get_singleton()->frame_changed);
+ double to_process = MIN(frame_progress / abs_speed, remaining);
+ frame_progress -= to_process * abs_speed;
+ remaining -= to_process;
}
- double to_process = MIN(timeout / speed, remaining);
- timeout -= to_process * speed;
- remaining -= to_process;
-
i++;
if (i > fc) {
return; // Prevents freezing if to_process is each time much less than remaining.
@@ -275,25 +285,37 @@ void AnimatedSprite2D::_notification(int p_what) {
}
void AnimatedSprite2D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) {
+ if (frames == p_frames) {
+ return;
+ }
+
if (frames.is_valid()) {
frames->disconnect(SceneStringNames::get_singleton()->changed, callable_mp(this, &AnimatedSprite2D::_res_changed));
}
-
+ stop();
frames = p_frames;
if (frames.is_valid()) {
frames->connect(SceneStringNames::get_singleton()->changed, callable_mp(this, &AnimatedSprite2D::_res_changed));
- }
- if (frames.is_null()) {
- frame = 0;
- } else {
- set_frame(frame);
+ List<StringName> al;
+ frames->get_animation_list(&al);
+ if (al.size() == 0) {
+ set_animation(StringName());
+ set_autoplay(String());
+ } else {
+ if (!frames->has_animation(animation)) {
+ set_animation(al[0]);
+ }
+ if (!frames->has_animation(autoplay)) {
+ set_autoplay(String());
+ }
+ }
}
notify_property_list_changed();
- _reset_timeout();
queue_redraw();
update_configuration_warnings();
+ emit_signal("sprite_frames_changed");
}
Ref<SpriteFrames> AnimatedSprite2D::get_sprite_frames() const {
@@ -301,44 +323,63 @@ Ref<SpriteFrames> AnimatedSprite2D::get_sprite_frames() const {
}
void AnimatedSprite2D::set_frame(int p_frame) {
+ set_frame_and_progress(p_frame, signbit(get_playing_speed()) ? 1.0 : 0.0);
+}
+
+int AnimatedSprite2D::get_frame() const {
+ return frame;
+}
+
+void AnimatedSprite2D::set_frame_progress(real_t p_progress) {
+ frame_progress = p_progress;
+}
+
+real_t AnimatedSprite2D::get_frame_progress() const {
+ return frame_progress;
+}
+
+void AnimatedSprite2D::set_frame_and_progress(int p_frame, real_t p_progress) {
if (frames.is_null()) {
return;
}
- if (frames->has_animation(animation)) {
- int limit = frames->get_frame_count(animation);
- if (p_frame >= limit) {
- p_frame = limit - 1;
- }
- }
+ bool has_animation = frames->has_animation(animation);
+ int end_frame = has_animation ? MAX(0, frames->get_frame_count(animation) - 1) : 0;
+ bool is_changed = frame != p_frame;
if (p_frame < 0) {
- p_frame = 0;
+ frame = 0;
+ } else if (has_animation && p_frame > end_frame) {
+ frame = end_frame;
+ } else {
+ frame = p_frame;
}
- if (frame == p_frame) {
- return;
- }
+ _calc_frame_speed_scale();
+ frame_progress = p_progress;
- frame = p_frame;
- _reset_timeout();
+ if (!is_changed) {
+ return; // No change, don't redraw.
+ }
queue_redraw();
emit_signal(SceneStringNames::get_singleton()->frame_changed);
}
-int AnimatedSprite2D::get_frame() const {
- return frame;
-}
-
void AnimatedSprite2D::set_speed_scale(float p_speed_scale) {
speed_scale = p_speed_scale;
- playing_backwards = signbit(speed_scale) != backwards;
}
float AnimatedSprite2D::get_speed_scale() const {
return speed_scale;
}
+float AnimatedSprite2D::get_playing_speed() const {
+ if (!playing) {
+ return 0;
+ }
+ return speed_scale * custom_speed_scale;
+}
+
void AnimatedSprite2D::set_centered(bool p_center) {
centered = p_center;
queue_redraw();
@@ -378,69 +419,130 @@ bool AnimatedSprite2D::is_flipped_v() const {
}
void AnimatedSprite2D::_res_changed() {
- set_frame(frame);
+ set_frame_and_progress(frame, frame_progress);
queue_redraw();
notify_property_list_changed();
}
-void AnimatedSprite2D::set_playing(bool p_playing) {
- if (playing == p_playing) {
- return;
+bool AnimatedSprite2D::is_playing() const {
+ return playing;
+}
+
+void AnimatedSprite2D::set_autoplay(const String &p_name) {
+ if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
+ WARN_PRINT("Setting autoplay after the node has been added to the scene has no effect.");
}
- playing = p_playing;
- playing_backwards = signbit(speed_scale) != backwards;
- set_process_internal(playing);
- notify_property_list_changed();
+
+ autoplay = p_name;
}
-bool AnimatedSprite2D::is_playing() const {
- return playing;
+String AnimatedSprite2D::get_autoplay() const {
+ return autoplay;
}
-void AnimatedSprite2D::play(const StringName &p_animation, bool p_backwards) {
- backwards = p_backwards;
- playing_backwards = signbit(speed_scale) != backwards;
+void AnimatedSprite2D::play(const StringName &p_name, float p_custom_scale, bool p_from_end) {
+ StringName name = p_name;
- if (p_animation) {
- set_animation(p_animation);
- if (frames.is_valid() && playing_backwards && get_frame() == 0) {
- set_frame(frames->get_frame_count(p_animation) - 1);
+ if (name == StringName()) {
+ name = animation;
+ }
+
+ ERR_FAIL_COND_MSG(frames == nullptr, vformat("There is no animation with name '%s'.", name));
+ ERR_FAIL_COND_MSG(!frames->get_animation_names().has(name), vformat("There is no animation with name '%s'.", name));
+
+ if (frames->get_frame_count(name) == 0) {
+ return;
+ }
+
+ playing = true;
+ custom_speed_scale = p_custom_scale;
+
+ int end_frame = MAX(0, frames->get_frame_count(animation) - 1);
+ if (name != animation) {
+ animation = name;
+ if (p_from_end) {
+ set_frame_and_progress(end_frame, 1.0);
+ } else {
+ set_frame_and_progress(0, 0.0);
}
+ emit_signal("animation_changed");
+ } else {
+ bool is_backward = signbit(speed_scale * custom_speed_scale);
+ if (p_from_end && is_backward && frame == 0 && frame_progress <= 0.0) {
+ set_frame_and_progress(end_frame, 1.0);
+ } else if (!p_from_end && !is_backward && frame == end_frame && frame_progress >= 1.0) {
+ set_frame_and_progress(0, 0.0);
+ }
+ }
+
+ notify_property_list_changed();
+ set_process_internal(true);
+}
+
+void AnimatedSprite2D::play_backwards(const StringName &p_name) {
+ play(p_name, -1, true);
+}
+
+void AnimatedSprite2D::_stop_internal(bool p_reset) {
+ playing = false;
+ if (p_reset) {
+ custom_speed_scale = 1.0;
+ set_frame_and_progress(0, 0.0);
}
+ notify_property_list_changed();
+ set_process_internal(false);
+}
- is_over = false;
- set_playing(true);
+void AnimatedSprite2D::pause() {
+ _stop_internal(false);
}
void AnimatedSprite2D::stop() {
- set_playing(false);
- backwards = false;
- _reset_timeout();
+ _stop_internal(true);
}
double AnimatedSprite2D::_get_frame_duration() {
if (frames.is_valid() && frames->has_animation(animation)) {
return frames->get_frame_duration(animation, frame);
}
- return 0.0;
+ return 1.0;
}
-void AnimatedSprite2D::_reset_timeout() {
- timeout = _get_frame_duration();
- is_over = false;
+void AnimatedSprite2D::_calc_frame_speed_scale() {
+ frame_speed_scale = 1.0 / _get_frame_duration();
}
-void AnimatedSprite2D::set_animation(const StringName &p_animation) {
- ERR_FAIL_COND_MSG(frames == nullptr, vformat("There is no animation with name '%s'.", p_animation));
- ERR_FAIL_COND_MSG(!frames->get_animation_names().has(p_animation), vformat("There is no animation with name '%s'.", p_animation));
+void AnimatedSprite2D::set_animation(const StringName &p_name) {
+ if (animation == p_name) {
+ return;
+ }
+
+ animation = p_name;
+
+ emit_signal("animation_changed");
- if (animation == p_animation) {
+ if (frames == nullptr) {
+ animation = StringName();
+ stop();
+ ERR_FAIL_MSG(vformat("There is no animation with name '%s'.", p_name));
+ }
+
+ int frame_count = frames->get_frame_count(animation);
+ if (animation == StringName() || frame_count == 0) {
+ stop();
return;
+ } else if (!frames->get_animation_names().has(animation)) {
+ animation = StringName();
+ stop();
+ ERR_FAIL_MSG(vformat("There is no animation with name '%s'.", p_name));
+ }
+
+ if (signbit(get_playing_speed())) {
+ set_frame_and_progress(frame_count - 1, 1.0);
+ } else {
+ set_frame_and_progress(0, 0.0);
}
- animation = p_animation;
- set_frame(0);
- _reset_timeout();
notify_property_list_changed();
queue_redraw();
}
@@ -468,17 +570,30 @@ void AnimatedSprite2D::get_argument_options(const StringName &p_function, int p_
Node::get_argument_options(p_function, p_idx, r_options);
}
+#ifndef DISABLE_DEPRECATED
+bool AnimatedSprite2D::_set(const StringName &p_name, const Variant &p_value) {
+ if ((p_name == SNAME("frames"))) {
+ set_sprite_frames(p_value);
+ return true;
+ }
+ return false;
+}
+#endif
void AnimatedSprite2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_sprite_frames", "sprite_frames"), &AnimatedSprite2D::set_sprite_frames);
ClassDB::bind_method(D_METHOD("get_sprite_frames"), &AnimatedSprite2D::get_sprite_frames);
- ClassDB::bind_method(D_METHOD("set_animation", "animation"), &AnimatedSprite2D::set_animation);
+ ClassDB::bind_method(D_METHOD("set_animation", "name"), &AnimatedSprite2D::set_animation);
ClassDB::bind_method(D_METHOD("get_animation"), &AnimatedSprite2D::get_animation);
- ClassDB::bind_method(D_METHOD("set_playing", "playing"), &AnimatedSprite2D::set_playing);
+ ClassDB::bind_method(D_METHOD("set_autoplay", "name"), &AnimatedSprite2D::set_autoplay);
+ ClassDB::bind_method(D_METHOD("get_autoplay"), &AnimatedSprite2D::get_autoplay);
+
ClassDB::bind_method(D_METHOD("is_playing"), &AnimatedSprite2D::is_playing);
- ClassDB::bind_method(D_METHOD("play", "anim", "backwards"), &AnimatedSprite2D::play, DEFVAL(StringName()), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("play", "name", "custom_speed", "from_end"), &AnimatedSprite2D::play, DEFVAL(StringName()), DEFVAL(1.0), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("play_backwards", "name"), &AnimatedSprite2D::play_backwards, DEFVAL(StringName()));
+ ClassDB::bind_method(D_METHOD("pause"), &AnimatedSprite2D::pause);
ClassDB::bind_method(D_METHOD("stop"), &AnimatedSprite2D::stop);
ClassDB::bind_method(D_METHOD("set_centered", "centered"), &AnimatedSprite2D::set_centered);
@@ -496,18 +611,28 @@ void AnimatedSprite2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_frame", "frame"), &AnimatedSprite2D::set_frame);
ClassDB::bind_method(D_METHOD("get_frame"), &AnimatedSprite2D::get_frame);
+ ClassDB::bind_method(D_METHOD("set_frame_progress", "progress"), &AnimatedSprite2D::set_frame_progress);
+ ClassDB::bind_method(D_METHOD("get_frame_progress"), &AnimatedSprite2D::get_frame_progress);
+
+ ClassDB::bind_method(D_METHOD("set_frame_and_progress", "frame", "progress"), &AnimatedSprite2D::set_frame_and_progress);
+
ClassDB::bind_method(D_METHOD("set_speed_scale", "speed_scale"), &AnimatedSprite2D::set_speed_scale);
ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimatedSprite2D::get_speed_scale);
+ ClassDB::bind_method(D_METHOD("get_playing_speed"), &AnimatedSprite2D::get_playing_speed);
+ ADD_SIGNAL(MethodInfo("sprite_frames_changed"));
+ ADD_SIGNAL(MethodInfo("animation_changed"));
ADD_SIGNAL(MethodInfo("frame_changed"));
+ ADD_SIGNAL(MethodInfo("animation_looped"));
ADD_SIGNAL(MethodInfo("animation_finished"));
ADD_GROUP("Animation", "");
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "frames", PROPERTY_HINT_RESOURCE_TYPE, "SpriteFrames"), "set_sprite_frames", "get_sprite_frames");
- ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "animation"), "set_animation", "get_animation");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "sprite_frames", PROPERTY_HINT_RESOURCE_TYPE, "SpriteFrames"), "set_sprite_frames", "get_sprite_frames");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "animation", PROPERTY_HINT_ENUM, ""), "set_animation", "get_animation");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_autoplay", "get_autoplay");
ADD_PROPERTY(PropertyInfo(Variant::INT, "frame"), "set_frame", "get_frame");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "frame_progress", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_frame_progress", "get_frame_progress");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale"), "set_speed_scale", "get_speed_scale");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing"), "set_playing", "is_playing");
ADD_GROUP("Offset", "");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset", PROPERTY_HINT_NONE, "suffix:px"), "set_offset", "get_offset");
diff --git a/scene/2d/animated_sprite_2d.h b/scene/2d/animated_sprite_2d.h
index c1d35f3a2f..ac53bd26ee 100644
--- a/scene/2d/animated_sprite_2d.h
+++ b/scene/2d/animated_sprite_2d.h
@@ -38,18 +38,19 @@ class AnimatedSprite2D : public Node2D {
GDCLASS(AnimatedSprite2D, Node2D);
Ref<SpriteFrames> frames;
+ String autoplay;
+
bool playing = false;
- bool playing_backwards = false;
- bool backwards = false;
StringName animation = "default";
int frame = 0;
float speed_scale = 1.0;
+ float custom_speed_scale = 1.0;
bool centered = true;
Point2 offset;
- bool is_over = false;
- float timeout = 0.0;
+ real_t frame_speed_scale = 1.0;
+ real_t frame_progress = 0.0;
bool hflip = false;
bool vflip = false;
@@ -57,10 +58,15 @@ class AnimatedSprite2D : public Node2D {
void _res_changed();
double _get_frame_duration();
- void _reset_timeout();
+ void _calc_frame_speed_scale();
+ void _stop_internal(bool p_reset);
+
Rect2 _get_rect() const;
protected:
+#ifndef DISABLE_DEPRECATED
+ bool _set(const StringName &p_name, const Variant &p_value);
+#endif
static void _bind_methods();
void _notification(int p_what);
void _validate_property(PropertyInfo &p_property) const;
@@ -82,20 +88,30 @@ public:
void set_sprite_frames(const Ref<SpriteFrames> &p_frames);
Ref<SpriteFrames> get_sprite_frames() const;
- void play(const StringName &p_animation = StringName(), bool p_backwards = false);
+ void play(const StringName &p_name = StringName(), float p_custom_scale = 1.0, bool p_from_end = false);
+ void play_backwards(const StringName &p_name = StringName());
+ void pause();
void stop();
- void set_playing(bool p_playing);
bool is_playing() const;
- void set_animation(const StringName &p_animation);
+ void set_animation(const StringName &p_name);
StringName get_animation() const;
+ void set_autoplay(const String &p_name);
+ String get_autoplay() const;
+
void set_frame(int p_frame);
int get_frame() const;
+ void set_frame_progress(real_t p_progress);
+ real_t get_frame_progress() const;
+
+ void set_frame_and_progress(int p_frame, real_t p_progress);
+
void set_speed_scale(float p_speed_scale);
float get_speed_scale() const;
+ float get_playing_speed() const;
void set_centered(bool p_center);
bool is_centered() const;
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 8c5aab4c80..a1304ab991 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -1379,7 +1379,7 @@ void TileMap::draw_tile(RID p_canvas_item, const Vector2i &p_position, const Ref
Color modulate = tile_data->get_modulate() * p_modulation;
// Compute the offset.
- Vector2i tile_offset = atlas_source->get_tile_effective_texture_offset(p_atlas_coords, p_alternative_tile);
+ Vector2i tile_offset = tile_data->get_texture_origin();
// Get destination rect.
Rect2 dest_rect;
diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp
index 71d76c0d1c..635c566ef8 100644
--- a/scene/3d/sprite_3d.cpp
+++ b/scene/3d/sprite_3d.cpp
@@ -866,7 +866,6 @@ void AnimatedSprite3D::_validate_property(PropertyInfo &p_property) const {
}
if (p_property.name == "animation") {
- p_property.hint = PROPERTY_HINT_ENUM;
List<StringName> names;
frames->get_animation_list(&names);
names.sort_custom<StringName::AlphCompare>();
@@ -916,6 +915,12 @@ void AnimatedSprite3D::_validate_property(PropertyInfo &p_property) const {
void AnimatedSprite3D::_notification(int p_what) {
switch (p_what) {
+ case NOTIFICATION_READY: {
+ if (!Engine::get_singleton()->is_editor_hint() && !frames.is_null() && frames->has_animation(autoplay)) {
+ play(autoplay);
+ }
+ } break;
+
case NOTIFICATION_INTERNAL_PROCESS: {
if (frames.is_null() || !frames->has_animation(animation)) {
return;
@@ -925,7 +930,8 @@ void AnimatedSprite3D::_notification(int p_what) {
int i = 0;
while (remaining) {
// Animation speed may be changed by animation_finished or frame_changed signals.
- double speed = frames->get_animation_speed(animation) * Math::abs(speed_scale);
+ double speed = frames->get_animation_speed(animation) * speed_scale * custom_speed_scale * frame_speed_scale;
+ double abs_speed = Math::abs(speed);
if (speed == 0) {
return; // Do nothing.
@@ -934,53 +940,57 @@ void AnimatedSprite3D::_notification(int p_what) {
// Frame count may be changed by animation_finished or frame_changed signals.
int fc = frames->get_frame_count(animation);
- if (timeout <= 0) {
- int last_frame = fc - 1;
- if (!playing_backwards) {
- // Forward.
+ int last_frame = fc - 1;
+ if (!signbit(speed)) {
+ // Forwards.
+ if (frame_progress >= 1.0) {
if (frame >= last_frame) {
if (frames->get_animation_loop(animation)) {
frame = 0;
- emit_signal(SceneStringNames::get_singleton()->animation_finished);
+ emit_signal("animation_looped");
} else {
frame = last_frame;
- if (!is_over) {
- is_over = true;
- emit_signal(SceneStringNames::get_singleton()->animation_finished);
- }
+ pause();
+ emit_signal(SceneStringNames::get_singleton()->animation_finished);
+ return;
}
} else {
frame++;
}
- } else {
- // Reversed.
+ _calc_frame_speed_scale();
+ frame_progress = 0.0;
+ _queue_redraw();
+ emit_signal(SceneStringNames::get_singleton()->frame_changed);
+ }
+ double to_process = MIN((1.0 - frame_progress) / abs_speed, remaining);
+ frame_progress += to_process * abs_speed;
+ remaining -= to_process;
+ } else {
+ // Backwards.
+ if (frame_progress <= 0) {
if (frame <= 0) {
if (frames->get_animation_loop(animation)) {
frame = last_frame;
- emit_signal(SceneStringNames::get_singleton()->animation_finished);
+ emit_signal("animation_looped");
} else {
frame = 0;
- if (!is_over) {
- is_over = true;
- emit_signal(SceneStringNames::get_singleton()->animation_finished);
- }
+ pause();
+ emit_signal(SceneStringNames::get_singleton()->animation_finished);
+ return;
}
} else {
frame--;
}
+ _calc_frame_speed_scale();
+ frame_progress = 1.0;
+ _queue_redraw();
+ emit_signal(SceneStringNames::get_singleton()->frame_changed);
}
-
- timeout = _get_frame_duration();
-
- _queue_redraw();
-
- emit_signal(SceneStringNames::get_singleton()->frame_changed);
+ double to_process = MIN(frame_progress / abs_speed, remaining);
+ frame_progress -= to_process * abs_speed;
+ remaining -= to_process;
}
- double to_process = MIN(timeout / speed, remaining);
- timeout -= to_process * speed;
- remaining -= to_process;
-
i++;
if (i > fc) {
return; // Prevents freezing if to_process is each time much less than remaining.
@@ -991,25 +1001,37 @@ void AnimatedSprite3D::_notification(int p_what) {
}
void AnimatedSprite3D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) {
+ if (frames == p_frames) {
+ return;
+ }
+
if (frames.is_valid()) {
frames->disconnect(SceneStringNames::get_singleton()->changed, callable_mp(this, &AnimatedSprite3D::_res_changed));
}
-
+ stop();
frames = p_frames;
if (frames.is_valid()) {
frames->connect(SceneStringNames::get_singleton()->changed, callable_mp(this, &AnimatedSprite3D::_res_changed));
- }
- if (frames.is_null()) {
- frame = 0;
- } else {
- set_frame(frame);
+ List<StringName> al;
+ frames->get_animation_list(&al);
+ if (al.size() == 0) {
+ set_animation(StringName());
+ set_autoplay(String());
+ } else {
+ if (!frames->has_animation(animation)) {
+ set_animation(al[0]);
+ }
+ if (!frames->has_animation(autoplay)) {
+ set_autoplay(String());
+ }
+ }
}
notify_property_list_changed();
- _reset_timeout();
_queue_redraw();
update_configuration_warnings();
+ emit_signal("sprite_frames_changed");
}
Ref<SpriteFrames> AnimatedSprite3D::get_sprite_frames() const {
@@ -1017,44 +1039,63 @@ Ref<SpriteFrames> AnimatedSprite3D::get_sprite_frames() const {
}
void AnimatedSprite3D::set_frame(int p_frame) {
+ set_frame_and_progress(p_frame, signbit(get_playing_speed()) ? 1.0 : 0.0);
+}
+
+int AnimatedSprite3D::get_frame() const {
+ return frame;
+}
+
+void AnimatedSprite3D::set_frame_progress(real_t p_progress) {
+ frame_progress = p_progress;
+}
+
+real_t AnimatedSprite3D::get_frame_progress() const {
+ return frame_progress;
+}
+
+void AnimatedSprite3D::set_frame_and_progress(int p_frame, real_t p_progress) {
if (frames.is_null()) {
return;
}
- if (frames->has_animation(animation)) {
- int limit = frames->get_frame_count(animation);
- if (p_frame >= limit) {
- p_frame = limit - 1;
- }
- }
+ bool has_animation = frames->has_animation(animation);
+ int end_frame = has_animation ? MAX(0, frames->get_frame_count(animation) - 1) : 0;
+ bool is_changed = frame != p_frame;
if (p_frame < 0) {
- p_frame = 0;
+ frame = 0;
+ } else if (has_animation && p_frame > end_frame) {
+ frame = end_frame;
+ } else {
+ frame = p_frame;
}
- if (frame == p_frame) {
- return;
- }
+ _calc_frame_speed_scale();
+ frame_progress = p_progress;
- frame = p_frame;
- _reset_timeout();
+ if (!is_changed) {
+ return; // No change, don't redraw.
+ }
_queue_redraw();
emit_signal(SceneStringNames::get_singleton()->frame_changed);
}
-int AnimatedSprite3D::get_frame() const {
- return frame;
-}
-
void AnimatedSprite3D::set_speed_scale(float p_speed_scale) {
speed_scale = p_speed_scale;
- playing_backwards = signbit(speed_scale) != backwards;
}
float AnimatedSprite3D::get_speed_scale() const {
return speed_scale;
}
+float AnimatedSprite3D::get_playing_speed() const {
+ if (!playing) {
+ return 0;
+ }
+ return speed_scale * custom_speed_scale;
+}
+
Rect2 AnimatedSprite3D::get_item_rect() const {
if (frames.is_null() || !frames->has_animation(animation)) {
return Rect2(0, 0, 1, 1);
@@ -1085,69 +1126,130 @@ Rect2 AnimatedSprite3D::get_item_rect() const {
}
void AnimatedSprite3D::_res_changed() {
- set_frame(frame);
+ set_frame_and_progress(frame, frame_progress);
_queue_redraw();
notify_property_list_changed();
}
-void AnimatedSprite3D::set_playing(bool p_playing) {
- if (playing == p_playing) {
- return;
+bool AnimatedSprite3D::is_playing() const {
+ return playing;
+}
+
+void AnimatedSprite3D::set_autoplay(const String &p_name) {
+ if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
+ WARN_PRINT("Setting autoplay after the node has been added to the scene has no effect.");
}
- playing = p_playing;
- playing_backwards = signbit(speed_scale) != backwards;
- set_process_internal(playing);
- notify_property_list_changed();
+
+ autoplay = p_name;
}
-bool AnimatedSprite3D::is_playing() const {
- return playing;
+String AnimatedSprite3D::get_autoplay() const {
+ return autoplay;
}
-void AnimatedSprite3D::play(const StringName &p_animation, bool p_backwards) {
- backwards = p_backwards;
- playing_backwards = signbit(speed_scale) != backwards;
+void AnimatedSprite3D::play(const StringName &p_name, float p_custom_scale, bool p_from_end) {
+ StringName name = p_name;
+
+ if (name == StringName()) {
+ name = animation;
+ }
+
+ ERR_FAIL_COND_MSG(frames == nullptr, vformat("There is no animation with name '%s'.", name));
+ ERR_FAIL_COND_MSG(!frames->get_animation_names().has(name), vformat("There is no animation with name '%s'.", name));
- if (p_animation) {
- set_animation(p_animation);
- if (frames.is_valid() && playing_backwards && get_frame() == 0) {
- set_frame(frames->get_frame_count(p_animation) - 1);
+ if (frames->get_frame_count(name) == 0) {
+ return;
+ }
+
+ playing = true;
+ custom_speed_scale = p_custom_scale;
+
+ int end_frame = MAX(0, frames->get_frame_count(animation) - 1);
+ if (name != animation) {
+ animation = name;
+ if (p_from_end) {
+ set_frame_and_progress(end_frame, 1.0);
+ } else {
+ set_frame_and_progress(0, 0.0);
+ }
+ emit_signal("animation_changed");
+ } else {
+ bool is_backward = signbit(speed_scale * custom_speed_scale);
+ if (p_from_end && is_backward && frame == 0 && frame_progress <= 0.0) {
+ set_frame_and_progress(end_frame, 1.0);
+ } else if (!p_from_end && !is_backward && frame == end_frame && frame_progress >= 1.0) {
+ set_frame_and_progress(0, 0.0);
}
}
- is_over = false;
- set_playing(true);
+ notify_property_list_changed();
+ set_process_internal(true);
+}
+
+void AnimatedSprite3D::play_backwards(const StringName &p_name) {
+ play(p_name, -1, true);
+}
+
+void AnimatedSprite3D::_stop_internal(bool p_reset) {
+ playing = false;
+ if (p_reset) {
+ custom_speed_scale = 1.0;
+ set_frame_and_progress(0, 0.0);
+ }
+ notify_property_list_changed();
+ set_process_internal(false);
+}
+
+void AnimatedSprite3D::pause() {
+ _stop_internal(false);
}
void AnimatedSprite3D::stop() {
- set_playing(false);
- backwards = false;
- _reset_timeout();
+ _stop_internal(true);
}
double AnimatedSprite3D::_get_frame_duration() {
if (frames.is_valid() && frames->has_animation(animation)) {
return frames->get_frame_duration(animation, frame);
}
- return 0.0;
+ return 1.0;
}
-void AnimatedSprite3D::_reset_timeout() {
- timeout = _get_frame_duration();
- is_over = false;
+void AnimatedSprite3D::_calc_frame_speed_scale() {
+ frame_speed_scale = 1.0 / _get_frame_duration();
}
-void AnimatedSprite3D::set_animation(const StringName &p_animation) {
- ERR_FAIL_COND_MSG(frames == nullptr, vformat("There is no animation with name '%s'.", p_animation));
- ERR_FAIL_COND_MSG(!frames->get_animation_names().has(p_animation), vformat("There is no animation with name '%s'.", p_animation));
+void AnimatedSprite3D::set_animation(const StringName &p_name) {
+ if (animation == p_name) {
+ return;
+ }
+
+ animation = p_name;
- if (animation == p_animation) {
+ emit_signal("animation_changed");
+
+ if (frames == nullptr) {
+ animation = StringName();
+ stop();
+ ERR_FAIL_MSG(vformat("There is no animation with name '%s'.", p_name));
+ }
+
+ int frame_count = frames->get_frame_count(animation);
+ if (animation == StringName() || frame_count == 0) {
+ stop();
return;
+ } else if (!frames->get_animation_names().has(animation)) {
+ animation = StringName();
+ stop();
+ ERR_FAIL_MSG(vformat("There is no animation with name '%s'.", p_name));
+ }
+
+ if (signbit(get_playing_speed())) {
+ set_frame_and_progress(frame_count - 1, 1.0);
+ } else {
+ set_frame_and_progress(0, 0.0);
}
- animation = p_animation;
- set_frame(0);
- _reset_timeout();
notify_property_list_changed();
_queue_redraw();
}
@@ -1175,35 +1277,58 @@ void AnimatedSprite3D::get_argument_options(const StringName &p_function, int p_
Node::get_argument_options(p_function, p_idx, r_options);
}
+#ifndef DISABLE_DEPRECATED
+bool AnimatedSprite3D::_set(const StringName &p_name, const Variant &p_value) {
+ if ((p_name == SNAME("frames"))) {
+ set_sprite_frames(p_value);
+ return true;
+ }
+ return false;
+}
+#endif
void AnimatedSprite3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_sprite_frames", "sprite_frames"), &AnimatedSprite3D::set_sprite_frames);
ClassDB::bind_method(D_METHOD("get_sprite_frames"), &AnimatedSprite3D::get_sprite_frames);
- ClassDB::bind_method(D_METHOD("set_animation", "animation"), &AnimatedSprite3D::set_animation);
+ ClassDB::bind_method(D_METHOD("set_animation", "name"), &AnimatedSprite3D::set_animation);
ClassDB::bind_method(D_METHOD("get_animation"), &AnimatedSprite3D::get_animation);
- ClassDB::bind_method(D_METHOD("set_playing", "playing"), &AnimatedSprite3D::set_playing);
+ ClassDB::bind_method(D_METHOD("set_autoplay", "name"), &AnimatedSprite3D::set_autoplay);
+ ClassDB::bind_method(D_METHOD("get_autoplay"), &AnimatedSprite3D::get_autoplay);
+
ClassDB::bind_method(D_METHOD("is_playing"), &AnimatedSprite3D::is_playing);
- ClassDB::bind_method(D_METHOD("play", "anim", "backwards"), &AnimatedSprite3D::play, DEFVAL(StringName()), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("play", "name", "custom_speed", "from_end"), &AnimatedSprite3D::play, DEFVAL(StringName()), DEFVAL(1.0), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("play_backwards", "name"), &AnimatedSprite3D::play_backwards, DEFVAL(StringName()));
+ ClassDB::bind_method(D_METHOD("pause"), &AnimatedSprite3D::pause);
ClassDB::bind_method(D_METHOD("stop"), &AnimatedSprite3D::stop);
ClassDB::bind_method(D_METHOD("set_frame", "frame"), &AnimatedSprite3D::set_frame);
ClassDB::bind_method(D_METHOD("get_frame"), &AnimatedSprite3D::get_frame);
+ ClassDB::bind_method(D_METHOD("set_frame_progress", "progress"), &AnimatedSprite3D::set_frame_progress);
+ ClassDB::bind_method(D_METHOD("get_frame_progress"), &AnimatedSprite3D::get_frame_progress);
+
+ ClassDB::bind_method(D_METHOD("set_frame_and_progress", "frame", "progress"), &AnimatedSprite3D::set_frame_and_progress);
+
ClassDB::bind_method(D_METHOD("set_speed_scale", "speed_scale"), &AnimatedSprite3D::set_speed_scale);
ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimatedSprite3D::get_speed_scale);
+ ClassDB::bind_method(D_METHOD("get_playing_speed"), &AnimatedSprite3D::get_playing_speed);
ClassDB::bind_method(D_METHOD("_res_changed"), &AnimatedSprite3D::_res_changed);
+ ADD_SIGNAL(MethodInfo("sprite_frames_changed"));
+ ADD_SIGNAL(MethodInfo("animation_changed"));
ADD_SIGNAL(MethodInfo("frame_changed"));
+ ADD_SIGNAL(MethodInfo("animation_looped"));
ADD_SIGNAL(MethodInfo("animation_finished"));
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "frames", PROPERTY_HINT_RESOURCE_TYPE, "SpriteFrames"), "set_sprite_frames", "get_sprite_frames");
- ADD_PROPERTY(PropertyInfo(Variant::STRING, "animation"), "set_animation", "get_animation");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "sprite_frames", PROPERTY_HINT_RESOURCE_TYPE, "SpriteFrames"), "set_sprite_frames", "get_sprite_frames");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "animation", PROPERTY_HINT_ENUM, ""), "set_animation", "get_animation");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_autoplay", "get_autoplay");
ADD_PROPERTY(PropertyInfo(Variant::INT, "frame"), "set_frame", "get_frame");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "frame_progress", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_frame_progress", "get_frame_progress");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale"), "set_speed_scale", "get_speed_scale");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing"), "set_playing", "is_playing");
}
AnimatedSprite3D::AnimatedSprite3D() {
diff --git a/scene/3d/sprite_3d.h b/scene/3d/sprite_3d.h
index c5509aa723..d0fd767d89 100644
--- a/scene/3d/sprite_3d.h
+++ b/scene/3d/sprite_3d.h
@@ -209,24 +209,29 @@ class AnimatedSprite3D : public SpriteBase3D {
GDCLASS(AnimatedSprite3D, SpriteBase3D);
Ref<SpriteFrames> frames;
+ String autoplay;
+
bool playing = false;
- bool playing_backwards = false;
- bool backwards = false;
StringName animation = "default";
int frame = 0;
float speed_scale = 1.0;
+ float custom_speed_scale = 1.0;
bool centered = false;
- bool is_over = false;
- double timeout = 0.0;
+ real_t frame_speed_scale = 1.0;
+ real_t frame_progress = 0.0;
void _res_changed();
double _get_frame_duration();
- void _reset_timeout();
+ void _calc_frame_speed_scale();
+ void _stop_internal(bool p_reset);
protected:
+#ifndef DISABLE_DEPRECATED
+ bool _set(const StringName &p_name, const Variant &p_value);
+#endif
virtual void _draw() override;
static void _bind_methods();
void _notification(int p_what);
@@ -236,20 +241,30 @@ public:
void set_sprite_frames(const Ref<SpriteFrames> &p_frames);
Ref<SpriteFrames> get_sprite_frames() const;
- void play(const StringName &p_animation = StringName(), bool p_backwards = false);
+ void play(const StringName &p_name = StringName(), float p_custom_scale = 1.0, bool p_from_end = false);
+ void play_backwards(const StringName &p_name = StringName());
+ void pause();
void stop();
- void set_playing(bool p_playing);
bool is_playing() const;
- void set_animation(const StringName &p_animation);
+ void set_animation(const StringName &p_name);
StringName get_animation() const;
+ void set_autoplay(const String &p_name);
+ String get_autoplay() const;
+
void set_frame(int p_frame);
int get_frame() const;
+ void set_frame_progress(real_t p_progress);
+ real_t get_frame_progress() const;
+
+ void set_frame_and_progress(int p_frame, real_t p_progress);
+
void set_speed_scale(float p_speed_scale);
float get_speed_scale() const;
+ float get_playing_speed() const;
virtual Rect2 get_item_rect() const override;
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index 77d82990d1..63e0fb6935 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -1722,8 +1722,11 @@ bool AnimationPlayer::is_playing() const {
void AnimationPlayer::set_current_animation(const String &p_anim) {
if (p_anim == "[stop]" || p_anim.is_empty()) {
stop();
- } else if (!is_playing() || playback.assigned != p_anim) {
+ } else if (!is_playing()) {
play(p_anim);
+ } else if (playback.assigned != p_anim) {
+ float speed = get_playing_speed();
+ play(p_anim, -1.0, speed, signbit(speed));
} else {
// Same animation, do not replay from start
}
@@ -1735,7 +1738,8 @@ String AnimationPlayer::get_current_animation() const {
void AnimationPlayer::set_assigned_animation(const String &p_anim) {
if (is_playing()) {
- play(p_anim);
+ float speed = get_playing_speed();
+ play(p_anim, -1.0, speed, signbit(speed));
} else {
ERR_FAIL_COND_MSG(!animation_set.has(p_anim), vformat("Animation not found: %s.", p_anim));
playback.current.pos = 0;
@@ -2217,7 +2221,7 @@ void AnimationPlayer::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle,Manual"), "set_process_callback", "get_process_callback");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "playback_default_blend_time", PROPERTY_HINT_RANGE, "0,4096,0.01,suffix:s"), "set_default_blend_time", "get_default_blend_time");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playback_active", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_active", "is_active");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "playback_speed", PROPERTY_HINT_RANGE, "-64,64,0.01"), "set_speed_scale", "get_speed_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale", PROPERTY_HINT_RANGE, "-64,64,0.01"), "set_speed_scale", "get_speed_scale");
ADD_PROPERTY(PropertyInfo(Variant::INT, "method_call_mode", PROPERTY_HINT_ENUM, "Deferred,Immediate"), "set_method_call_mode", "get_method_call_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "movie_quit_on_finish"), "set_movie_quit_on_finish_enabled", "is_movie_quit_on_finish_enabled");
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp
index a2a1a0aaef..05b6c72cbd 100644
--- a/scene/animation/animation_tree.cpp
+++ b/scene/animation/animation_tree.cpp
@@ -1411,7 +1411,7 @@ void AnimationTree::_process_graph(double p_delta) {
case Animation::TYPE_METHOD: {
#ifdef TOOLS_ENABLED
if (!can_call) {
- return;
+ continue;
}
#endif // TOOLS_ENABLED
TrackCacheMethod *t = static_cast<TrackCacheMethod *>(track);
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 5aa777b40c..dba08e16cb 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -247,7 +247,7 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
return;
}
if (b->is_pressed() && b->get_button_index() == MouseButton::RIGHT && context_menu_enabled) {
- _ensure_menu();
+ _update_context_menu();
menu->set_position(get_screen_position() + get_local_mouse_position());
menu->reset_size();
menu->popup();
@@ -452,7 +452,7 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
if (context_menu_enabled) {
if (k->is_action("ui_menu", true)) {
- _ensure_menu();
+ _update_context_menu();
Point2 pos = Point2(get_caret_pixel_pos().x, (get_size().y + theme_cache.font->get_height(theme_cache.font_size)) / 2);
menu->set_position(get_screen_position() + pos);
menu->reset_size();
@@ -2077,7 +2077,9 @@ bool LineEdit::is_menu_visible() const {
}
PopupMenu *LineEdit::get_menu() const {
- const_cast<LineEdit *>(this)->_ensure_menu();
+ if (!menu) {
+ const_cast<LineEdit *>(this)->_generate_context_menu();
+ }
return menu;
}
@@ -2335,6 +2337,115 @@ Key LineEdit::_get_menu_action_accelerator(const String &p_action) {
}
}
+void LineEdit::_generate_context_menu() {
+ menu = memnew(PopupMenu);
+ add_child(menu, false, INTERNAL_MODE_FRONT);
+
+ menu_dir = memnew(PopupMenu);
+ menu_dir->set_name("DirMenu");
+ menu_dir->add_radio_check_item(RTR("Same as Layout Direction"), MENU_DIR_INHERITED);
+ menu_dir->add_radio_check_item(RTR("Auto-Detect Direction"), MENU_DIR_AUTO);
+ menu_dir->add_radio_check_item(RTR("Left-to-Right"), MENU_DIR_LTR);
+ menu_dir->add_radio_check_item(RTR("Right-to-Left"), MENU_DIR_RTL);
+ menu->add_child(menu_dir, false, INTERNAL_MODE_FRONT);
+
+ menu_ctl = memnew(PopupMenu);
+ menu_ctl->set_name("CTLMenu");
+ menu_ctl->add_item(RTR("Left-to-Right Mark (LRM)"), MENU_INSERT_LRM);
+ menu_ctl->add_item(RTR("Right-to-Left Mark (RLM)"), MENU_INSERT_RLM);
+ menu_ctl->add_item(RTR("Start of Left-to-Right Embedding (LRE)"), MENU_INSERT_LRE);
+ menu_ctl->add_item(RTR("Start of Right-to-Left Embedding (RLE)"), MENU_INSERT_RLE);
+ menu_ctl->add_item(RTR("Start of Left-to-Right Override (LRO)"), MENU_INSERT_LRO);
+ menu_ctl->add_item(RTR("Start of Right-to-Left Override (RLO)"), MENU_INSERT_RLO);
+ menu_ctl->add_item(RTR("Pop Direction Formatting (PDF)"), MENU_INSERT_PDF);
+ menu_ctl->add_separator();
+ menu_ctl->add_item(RTR("Arabic Letter Mark (ALM)"), MENU_INSERT_ALM);
+ menu_ctl->add_item(RTR("Left-to-Right Isolate (LRI)"), MENU_INSERT_LRI);
+ menu_ctl->add_item(RTR("Right-to-Left Isolate (RLI)"), MENU_INSERT_RLI);
+ menu_ctl->add_item(RTR("First Strong Isolate (FSI)"), MENU_INSERT_FSI);
+ menu_ctl->add_item(RTR("Pop Direction Isolate (PDI)"), MENU_INSERT_PDI);
+ menu_ctl->add_separator();
+ menu_ctl->add_item(RTR("Zero-Width Joiner (ZWJ)"), MENU_INSERT_ZWJ);
+ menu_ctl->add_item(RTR("Zero-Width Non-Joiner (ZWNJ)"), MENU_INSERT_ZWNJ);
+ menu_ctl->add_item(RTR("Word Joiner (WJ)"), MENU_INSERT_WJ);
+ menu_ctl->add_item(RTR("Soft Hyphen (SHY)"), MENU_INSERT_SHY);
+ menu->add_child(menu_ctl, false, INTERNAL_MODE_FRONT);
+
+ menu->add_item(RTR("Cut"), MENU_CUT);
+ menu->add_item(RTR("Copy"), MENU_COPY);
+ menu->add_item(RTR("Paste"), MENU_PASTE);
+ menu->add_separator();
+ menu->add_item(RTR("Select All"), MENU_SELECT_ALL);
+ menu->add_item(RTR("Clear"), MENU_CLEAR);
+ menu->add_separator();
+ menu->add_item(RTR("Undo"), MENU_UNDO);
+ menu->add_item(RTR("Redo"), MENU_REDO);
+ menu->add_separator();
+ menu->add_submenu_item(RTR("Text Writing Direction"), "DirMenu", MENU_SUBMENU_TEXT_DIR);
+ menu->add_separator();
+ menu->add_check_item(RTR("Display Control Characters"), MENU_DISPLAY_UCC);
+ menu->add_submenu_item(RTR("Insert Control Character"), "CTLMenu", MENU_SUBMENU_INSERT_UCC);
+
+ menu->connect("id_pressed", callable_mp(this, &LineEdit::menu_option));
+ menu_dir->connect("id_pressed", callable_mp(this, &LineEdit::menu_option));
+ menu_ctl->connect("id_pressed", callable_mp(this, &LineEdit::menu_option));
+
+ menu->connect(SNAME("focus_entered"), callable_mp(this, &LineEdit::_validate_caret_can_draw));
+ menu->connect(SNAME("focus_exited"), callable_mp(this, &LineEdit::_validate_caret_can_draw));
+}
+
+void LineEdit::_update_context_menu() {
+ if (!menu) {
+ _generate_context_menu();
+ }
+
+ int idx = -1;
+
+#define MENU_ITEM_ACTION_DISABLED(m_menu, m_id, m_action, m_disabled) \
+ idx = m_menu->get_item_index(m_id); \
+ if (idx >= 0) { \
+ m_menu->set_item_accelerator(idx, shortcut_keys_enabled ? _get_menu_action_accelerator(m_action) : Key::NONE); \
+ m_menu->set_item_disabled(idx, m_disabled); \
+ }
+
+#define MENU_ITEM_ACTION(m_menu, m_id, m_action) \
+ idx = m_menu->get_item_index(m_id); \
+ if (idx >= 0) { \
+ m_menu->set_item_accelerator(idx, shortcut_keys_enabled ? _get_menu_action_accelerator(m_action) : Key::NONE); \
+ }
+
+#define MENU_ITEM_DISABLED(m_menu, m_id, m_disabled) \
+ idx = m_menu->get_item_index(m_id); \
+ if (idx >= 0) { \
+ m_menu->set_item_disabled(idx, m_disabled); \
+ }
+
+#define MENU_ITEM_CHECKED(m_menu, m_id, m_checked) \
+ idx = m_menu->get_item_index(m_id); \
+ if (idx >= 0) { \
+ m_menu->set_item_checked(idx, m_checked); \
+ }
+
+ MENU_ITEM_ACTION_DISABLED(menu, MENU_CUT, "ui_cut", !editable)
+ MENU_ITEM_ACTION(menu, MENU_COPY, "ui_copy")
+ MENU_ITEM_ACTION_DISABLED(menu, MENU_PASTE, "ui_paste", !editable)
+ MENU_ITEM_ACTION_DISABLED(menu, MENU_SELECT_ALL, "ui_text_select_all", !selecting_enabled)
+ MENU_ITEM_DISABLED(menu, MENU_CLEAR, !editable)
+ MENU_ITEM_ACTION_DISABLED(menu, MENU_UNDO, "ui_undo", !editable || !has_undo())
+ MENU_ITEM_ACTION_DISABLED(menu, MENU_REDO, "ui_redo", !editable || !has_redo())
+ MENU_ITEM_CHECKED(menu_dir, MENU_DIR_INHERITED, text_direction == TEXT_DIRECTION_INHERITED)
+ MENU_ITEM_CHECKED(menu_dir, MENU_DIR_AUTO, text_direction == TEXT_DIRECTION_AUTO)
+ MENU_ITEM_CHECKED(menu_dir, MENU_DIR_LTR, text_direction == TEXT_DIRECTION_LTR)
+ MENU_ITEM_CHECKED(menu_dir, MENU_DIR_RTL, text_direction == TEXT_DIRECTION_RTL)
+ MENU_ITEM_CHECKED(menu, MENU_DISPLAY_UCC, draw_control_chars)
+ MENU_ITEM_DISABLED(menu, MENU_SUBMENU_INSERT_UCC, !editable)
+
+#undef MENU_ITEM_ACTION_DISABLED
+#undef MENU_ITEM_ACTION
+#undef MENU_ITEM_DISABLED
+#undef MENU_ITEM_CHECKED
+}
+
void LineEdit::_validate_property(PropertyInfo &p_property) const {
if (!caret_blink_enabled && p_property.name == "caret_blink_interval") {
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
@@ -2429,11 +2540,13 @@ void LineEdit::_bind_methods() {
BIND_ENUM_CONSTANT(MENU_SELECT_ALL);
BIND_ENUM_CONSTANT(MENU_UNDO);
BIND_ENUM_CONSTANT(MENU_REDO);
+ BIND_ENUM_CONSTANT(MENU_SUBMENU_TEXT_DIR);
BIND_ENUM_CONSTANT(MENU_DIR_INHERITED);
BIND_ENUM_CONSTANT(MENU_DIR_AUTO);
BIND_ENUM_CONSTANT(MENU_DIR_LTR);
BIND_ENUM_CONSTANT(MENU_DIR_RTL);
BIND_ENUM_CONSTANT(MENU_DISPLAY_UCC);
+ BIND_ENUM_CONSTANT(MENU_SUBMENU_INSERT_UCC);
BIND_ENUM_CONSTANT(MENU_INSERT_LRM);
BIND_ENUM_CONSTANT(MENU_INSERT_RLM);
BIND_ENUM_CONSTANT(MENU_INSERT_LRE);
@@ -2496,86 +2609,6 @@ void LineEdit::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "structured_text_bidi_override_options"), "set_structured_text_bidi_override_options", "get_structured_text_bidi_override_options");
}
-void LineEdit::_ensure_menu() {
- if (!menu) {
- menu = memnew(PopupMenu);
- add_child(menu, false, INTERNAL_MODE_FRONT);
-
- menu_dir = memnew(PopupMenu);
- menu_dir->set_name("DirMenu");
- menu_dir->add_radio_check_item(RTR("Same as Layout Direction"), MENU_DIR_INHERITED);
- menu_dir->add_radio_check_item(RTR("Auto-Detect Direction"), MENU_DIR_AUTO);
- menu_dir->add_radio_check_item(RTR("Left-to-Right"), MENU_DIR_LTR);
- menu_dir->add_radio_check_item(RTR("Right-to-Left"), MENU_DIR_RTL);
- menu->add_child(menu_dir, false, INTERNAL_MODE_FRONT);
-
- menu_ctl = memnew(PopupMenu);
- menu_ctl->set_name("CTLMenu");
- menu_ctl->add_item(RTR("Left-to-Right Mark (LRM)"), MENU_INSERT_LRM);
- menu_ctl->add_item(RTR("Right-to-Left Mark (RLM)"), MENU_INSERT_RLM);
- menu_ctl->add_item(RTR("Start of Left-to-Right Embedding (LRE)"), MENU_INSERT_LRE);
- menu_ctl->add_item(RTR("Start of Right-to-Left Embedding (RLE)"), MENU_INSERT_RLE);
- menu_ctl->add_item(RTR("Start of Left-to-Right Override (LRO)"), MENU_INSERT_LRO);
- menu_ctl->add_item(RTR("Start of Right-to-Left Override (RLO)"), MENU_INSERT_RLO);
- menu_ctl->add_item(RTR("Pop Direction Formatting (PDF)"), MENU_INSERT_PDF);
- menu_ctl->add_separator();
- menu_ctl->add_item(RTR("Arabic Letter Mark (ALM)"), MENU_INSERT_ALM);
- menu_ctl->add_item(RTR("Left-to-Right Isolate (LRI)"), MENU_INSERT_LRI);
- menu_ctl->add_item(RTR("Right-to-Left Isolate (RLI)"), MENU_INSERT_RLI);
- menu_ctl->add_item(RTR("First Strong Isolate (FSI)"), MENU_INSERT_FSI);
- menu_ctl->add_item(RTR("Pop Direction Isolate (PDI)"), MENU_INSERT_PDI);
- menu_ctl->add_separator();
- menu_ctl->add_item(RTR("Zero-Width Joiner (ZWJ)"), MENU_INSERT_ZWJ);
- menu_ctl->add_item(RTR("Zero-Width Non-Joiner (ZWNJ)"), MENU_INSERT_ZWNJ);
- menu_ctl->add_item(RTR("Word Joiner (WJ)"), MENU_INSERT_WJ);
- menu_ctl->add_item(RTR("Soft Hyphen (SHY)"), MENU_INSERT_SHY);
- menu->add_child(menu_ctl, false, INTERNAL_MODE_FRONT);
-
- menu->connect("id_pressed", callable_mp(this, &LineEdit::menu_option));
- menu->connect(SNAME("focus_entered"), callable_mp(this, &LineEdit::_validate_caret_can_draw));
- menu->connect(SNAME("focus_exited"), callable_mp(this, &LineEdit::_validate_caret_can_draw));
- menu_dir->connect("id_pressed", callable_mp(this, &LineEdit::menu_option));
- menu_ctl->connect("id_pressed", callable_mp(this, &LineEdit::menu_option));
- }
-
- // Reorganize context menu.
- menu->clear();
- if (editable) {
- menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_cut") : Key::NONE);
- }
- menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_copy") : Key::NONE);
- if (editable) {
- menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_paste") : Key::NONE);
- }
- menu->add_separator();
- if (is_selecting_enabled()) {
- menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_text_select_all") : Key::NONE);
- }
- if (editable) {
- menu->add_item(RTR("Clear"), MENU_CLEAR);
- menu->add_separator();
- menu->add_item(RTR("Undo"), MENU_UNDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_undo") : Key::NONE);
- menu->add_item(RTR("Redo"), MENU_REDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_redo") : Key::NONE);
- }
- menu->add_separator();
- menu->add_submenu_item(RTR("Text Writing Direction"), "DirMenu");
- menu->add_separator();
- menu->add_check_item(RTR("Display Control Characters"), MENU_DISPLAY_UCC);
- menu->set_item_checked(menu->get_item_index(MENU_DISPLAY_UCC), draw_control_chars);
- if (editable) {
- menu->add_submenu_item(RTR("Insert Control Character"), "CTLMenu");
- }
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), text_direction == TEXT_DIRECTION_INHERITED);
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_AUTO), text_direction == TEXT_DIRECTION_AUTO);
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_LTR), text_direction == TEXT_DIRECTION_LTR);
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_RTL), text_direction == TEXT_DIRECTION_RTL);
-
- if (editable) {
- menu->set_item_disabled(menu->get_item_index(MENU_UNDO), !has_undo());
- menu->set_item_disabled(menu->get_item_index(MENU_REDO), !has_redo());
- }
-}
-
LineEdit::LineEdit(const String &p_placeholder) {
text_rid = TS->create_shaped_text();
_create_undo_state();
diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h
index 5107845a5e..81c506069a 100644
--- a/scene/gui/line_edit.h
+++ b/scene/gui/line_edit.h
@@ -46,11 +46,13 @@ public:
MENU_SELECT_ALL,
MENU_UNDO,
MENU_REDO,
+ MENU_SUBMENU_TEXT_DIR,
MENU_DIR_INHERITED,
MENU_DIR_AUTO,
MENU_DIR_LTR,
MENU_DIR_RTL,
MENU_DISPLAY_UCC,
+ MENU_SUBMENU_INSERT_UCC,
MENU_INSERT_LRM,
MENU_INSERT_RLM,
MENU_INSERT_LRE,
@@ -207,6 +209,8 @@ private:
void _create_undo_state();
Key _get_menu_action_accelerator(const String &p_action);
+ void _generate_context_menu();
+ void _update_context_menu();
void _shape();
void _fit_to_width();
@@ -239,8 +243,6 @@ private:
void _backspace(bool p_word = false, bool p_all_to_left = false);
void _delete(bool p_word = false, bool p_all_to_right = false);
- void _ensure_menu();
-
protected:
bool _is_over_clear_button(const Point2 &p_pos) const;
virtual void _update_theme_item_cache() override;
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 9baf7c9180..71ee3c8d0d 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -2808,7 +2808,7 @@ void RichTextLabel::_process_line_caches() {
int ctrl_height = get_size().height;
int fi = main->first_invalid_line.load();
- int total_chars = (fi == 0) ? 0 : (main->lines[fi].char_offset + main->lines[fi].char_count);
+ int total_chars = main->lines[fi].char_offset;
float total_height = (fi == 0) ? 0 : _calculate_line_vertical_offset(main->lines[fi - 1]);
for (int i = fi; i < (int)main->lines.size(); i++) {
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index dfc03c666b..f99b2edd54 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -368,7 +368,7 @@ void SpinBox::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "update_on_text_changed"), "set_update_on_text_changed", "get_update_on_text_changed");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "prefix"), "set_prefix", "get_prefix");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "suffix"), "set_suffix", "get_suffix");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "custom_arrow_step"), "set_custom_arrow_step", "get_custom_arrow_step");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "custom_arrow_step", PROPERTY_HINT_RANGE, "0,10000,0.0001,or_greater"), "set_custom_arrow_step", "get_custom_arrow_step");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "select_all_on_focus"), "set_select_all_on_focus", "is_select_all_on_focus");
}
diff --git a/scene/gui/subviewport_container.cpp b/scene/gui/subviewport_container.cpp
index 440597c24a..7c1d2f95a9 100644
--- a/scene/gui/subviewport_container.cpp
+++ b/scene/gui/subviewport_container.cpp
@@ -180,24 +180,51 @@ void SubViewportContainer::input(const Ref<InputEvent> &p_event) {
return;
}
- Transform2D xform = get_global_transform_with_canvas();
+ if (_is_propagated_in_gui_input(p_event)) {
+ return;
+ }
- if (stretch) {
- Transform2D scale_xf;
- scale_xf.scale(Vector2(shrink, shrink));
- xform *= scale_xf;
+ _send_event_to_viewports(p_event);
+}
+
+void SubViewportContainer::gui_input(const Ref<InputEvent> &p_event) {
+ ERR_FAIL_COND(p_event.is_null());
+
+ if (Engine::get_singleton()->is_editor_hint()) {
+ return;
}
- Ref<InputEvent> ev = p_event->xformed_by(xform.affine_inverse());
+ if (!_is_propagated_in_gui_input(p_event)) {
+ return;
+ }
+ if (stretch && shrink > 1) {
+ Transform2D xform;
+ xform.scale(Vector2(1, 1) / shrink);
+ _send_event_to_viewports(p_event->xformed_by(xform));
+ } else {
+ _send_event_to_viewports(p_event);
+ }
+}
+
+void SubViewportContainer::_send_event_to_viewports(const Ref<InputEvent> &p_event) {
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
if (!c || c->is_input_disabled()) {
continue;
}
- c->push_input(ev);
+ c->push_input(p_event);
+ }
+}
+
+bool SubViewportContainer::_is_propagated_in_gui_input(const Ref<InputEvent> &p_event) {
+ // Propagation of events with a position property happen in gui_input
+ // Propagation of other events happen in input
+ if (Object::cast_to<InputEventMouse>(*p_event) || Object::cast_to<InputEventScreenDrag>(*p_event) || Object::cast_to<InputEventScreenTouch>(*p_event) || Object::cast_to<InputEventGesture>(*p_event)) {
+ return true;
}
+ return false;
}
void SubViewportContainer::unhandled_input(const Ref<InputEvent> &p_event) {
diff --git a/scene/gui/subviewport_container.h b/scene/gui/subviewport_container.h
index d918c4a615..d3236b0c4e 100644
--- a/scene/gui/subviewport_container.h
+++ b/scene/gui/subviewport_container.h
@@ -39,6 +39,8 @@ class SubViewportContainer : public Container {
bool stretch = false;
int shrink = 1;
void _notify_viewports(int p_notification);
+ bool _is_propagated_in_gui_input(const Ref<InputEvent> &p_event);
+ void _send_event_to_viewports(const Ref<InputEvent> &p_event);
protected:
void _notification(int p_what);
@@ -52,6 +54,7 @@ public:
bool is_stretch_enabled() const;
virtual void input(const Ref<InputEvent> &p_event) override;
+ virtual void gui_input(const Ref<InputEvent> &p_event) override;
virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
void set_stretch_shrink(int p_shrink);
int get_stretch_shrink() const;
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 723f3fe7af..d785280701 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1861,7 +1861,7 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (context_menu_enabled) {
- _generate_context_menu();
+ _update_context_menu();
menu->set_position(get_screen_position() + mpos);
menu->reset_size();
menu->popup();
@@ -2141,7 +2141,7 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
// MISC.
if (k->is_action("ui_menu", true)) {
if (context_menu_enabled) {
- _generate_context_menu();
+ _update_context_menu();
adjust_viewport_to_caret();
menu->set_position(get_screen_position() + get_caret_draw_pos());
menu->reset_size();
@@ -3726,7 +3726,9 @@ void TextEdit::paste_primary_clipboard(int p_caret) {
// Context menu.
PopupMenu *TextEdit::get_menu() const {
- const_cast<TextEdit *>(this)->_generate_context_menu();
+ if (!menu) {
+ const_cast<TextEdit *>(this)->_generate_context_menu();
+ }
return menu;
}
@@ -6075,11 +6077,13 @@ void TextEdit::_bind_methods() {
BIND_ENUM_CONSTANT(MENU_SELECT_ALL);
BIND_ENUM_CONSTANT(MENU_UNDO);
BIND_ENUM_CONSTANT(MENU_REDO);
+ BIND_ENUM_CONSTANT(MENU_SUBMENU_TEXT_DIR);
BIND_ENUM_CONSTANT(MENU_DIR_INHERITED);
BIND_ENUM_CONSTANT(MENU_DIR_AUTO);
BIND_ENUM_CONSTANT(MENU_DIR_LTR);
BIND_ENUM_CONSTANT(MENU_DIR_RTL);
BIND_ENUM_CONSTANT(MENU_DISPLAY_UCC);
+ BIND_ENUM_CONSTANT(MENU_SUBMENU_INSERT_UCC);
BIND_ENUM_CONSTANT(MENU_INSERT_LRM);
BIND_ENUM_CONSTANT(MENU_INSERT_RLM);
BIND_ENUM_CONSTANT(MENU_INSERT_LRE);
@@ -6730,87 +6734,7 @@ void TextEdit::_paste_primary_clipboard_internal(int p_caret) {
grab_focus();
}
-/* Text. */
// Context menu.
-void TextEdit::_generate_context_menu() {
- if (!menu) {
- menu = memnew(PopupMenu);
- add_child(menu, false, INTERNAL_MODE_FRONT);
-
- menu_dir = memnew(PopupMenu);
- menu_dir->set_name("DirMenu");
- menu_dir->add_radio_check_item(RTR("Same as Layout Direction"), MENU_DIR_INHERITED);
- menu_dir->add_radio_check_item(RTR("Auto-Detect Direction"), MENU_DIR_AUTO);
- menu_dir->add_radio_check_item(RTR("Left-to-Right"), MENU_DIR_LTR);
- menu_dir->add_radio_check_item(RTR("Right-to-Left"), MENU_DIR_RTL);
- menu->add_child(menu_dir, false, INTERNAL_MODE_FRONT);
-
- menu_ctl = memnew(PopupMenu);
- menu_ctl->set_name("CTLMenu");
- menu_ctl->add_item(RTR("Left-to-Right Mark (LRM)"), MENU_INSERT_LRM);
- menu_ctl->add_item(RTR("Right-to-Left Mark (RLM)"), MENU_INSERT_RLM);
- menu_ctl->add_item(RTR("Start of Left-to-Right Embedding (LRE)"), MENU_INSERT_LRE);
- menu_ctl->add_item(RTR("Start of Right-to-Left Embedding (RLE)"), MENU_INSERT_RLE);
- menu_ctl->add_item(RTR("Start of Left-to-Right Override (LRO)"), MENU_INSERT_LRO);
- menu_ctl->add_item(RTR("Start of Right-to-Left Override (RLO)"), MENU_INSERT_RLO);
- menu_ctl->add_item(RTR("Pop Direction Formatting (PDF)"), MENU_INSERT_PDF);
- menu_ctl->add_separator();
- menu_ctl->add_item(RTR("Arabic Letter Mark (ALM)"), MENU_INSERT_ALM);
- menu_ctl->add_item(RTR("Left-to-Right Isolate (LRI)"), MENU_INSERT_LRI);
- menu_ctl->add_item(RTR("Right-to-Left Isolate (RLI)"), MENU_INSERT_RLI);
- menu_ctl->add_item(RTR("First Strong Isolate (FSI)"), MENU_INSERT_FSI);
- menu_ctl->add_item(RTR("Pop Direction Isolate (PDI)"), MENU_INSERT_PDI);
- menu_ctl->add_separator();
- menu_ctl->add_item(RTR("Zero-Width Joiner (ZWJ)"), MENU_INSERT_ZWJ);
- menu_ctl->add_item(RTR("Zero-Width Non-Joiner (ZWNJ)"), MENU_INSERT_ZWNJ);
- menu_ctl->add_item(RTR("Word Joiner (WJ)"), MENU_INSERT_WJ);
- menu_ctl->add_item(RTR("Soft Hyphen (SHY)"), MENU_INSERT_SHY);
- menu->add_child(menu_ctl, false, INTERNAL_MODE_FRONT);
-
- menu->connect("id_pressed", callable_mp(this, &TextEdit::menu_option));
- menu_dir->connect("id_pressed", callable_mp(this, &TextEdit::menu_option));
- menu_ctl->connect("id_pressed", callable_mp(this, &TextEdit::menu_option));
- }
-
- // Reorganize context menu.
- menu->clear();
- if (editable) {
- menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_cut") : Key::NONE);
- }
- menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_copy") : Key::NONE);
- if (editable) {
- menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_paste") : Key::NONE);
- }
- if (selecting_enabled || editable) {
- menu->add_separator();
- }
- if (selecting_enabled) {
- menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_text_select_all") : Key::NONE);
- }
- if (editable) {
- menu->add_item(RTR("Clear"), MENU_CLEAR);
- menu->add_separator();
- menu->add_item(RTR("Undo"), MENU_UNDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_undo") : Key::NONE);
- menu->add_item(RTR("Redo"), MENU_REDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_redo") : Key::NONE);
- }
- menu->add_separator();
- menu->add_submenu_item(RTR("Text Writing Direction"), "DirMenu");
- menu->add_separator();
- menu->add_check_item(RTR("Display Control Characters"), MENU_DISPLAY_UCC);
- menu->set_item_checked(menu->get_item_index(MENU_DISPLAY_UCC), draw_control_chars);
- if (editable) {
- menu->add_submenu_item(RTR("Insert Control Character"), "CTLMenu");
- }
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), text_direction == TEXT_DIRECTION_INHERITED);
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_AUTO), text_direction == TEXT_DIRECTION_AUTO);
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_LTR), text_direction == TEXT_DIRECTION_LTR);
- menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_RTL), text_direction == TEXT_DIRECTION_RTL);
-
- if (editable) {
- menu->set_item_disabled(menu->get_item_index(MENU_UNDO), !has_undo());
- menu->set_item_disabled(menu->get_item_index(MENU_REDO), !has_redo());
- }
-}
Key TextEdit::_get_menu_action_accelerator(const String &p_action) {
const List<Ref<InputEvent>> *events = InputMap::get_singleton()->action_get_events(p_action);
@@ -6837,6 +6761,112 @@ Key TextEdit::_get_menu_action_accelerator(const String &p_action) {
}
}
+void TextEdit::_generate_context_menu() {
+ menu = memnew(PopupMenu);
+ add_child(menu, false, INTERNAL_MODE_FRONT);
+
+ menu_dir = memnew(PopupMenu);
+ menu_dir->set_name("DirMenu");
+ menu_dir->add_radio_check_item(RTR("Same as Layout Direction"), MENU_DIR_INHERITED);
+ menu_dir->add_radio_check_item(RTR("Auto-Detect Direction"), MENU_DIR_AUTO);
+ menu_dir->add_radio_check_item(RTR("Left-to-Right"), MENU_DIR_LTR);
+ menu_dir->add_radio_check_item(RTR("Right-to-Left"), MENU_DIR_RTL);
+ menu->add_child(menu_dir, false, INTERNAL_MODE_FRONT);
+
+ menu_ctl = memnew(PopupMenu);
+ menu_ctl->set_name("CTLMenu");
+ menu_ctl->add_item(RTR("Left-to-Right Mark (LRM)"), MENU_INSERT_LRM);
+ menu_ctl->add_item(RTR("Right-to-Left Mark (RLM)"), MENU_INSERT_RLM);
+ menu_ctl->add_item(RTR("Start of Left-to-Right Embedding (LRE)"), MENU_INSERT_LRE);
+ menu_ctl->add_item(RTR("Start of Right-to-Left Embedding (RLE)"), MENU_INSERT_RLE);
+ menu_ctl->add_item(RTR("Start of Left-to-Right Override (LRO)"), MENU_INSERT_LRO);
+ menu_ctl->add_item(RTR("Start of Right-to-Left Override (RLO)"), MENU_INSERT_RLO);
+ menu_ctl->add_item(RTR("Pop Direction Formatting (PDF)"), MENU_INSERT_PDF);
+ menu_ctl->add_separator();
+ menu_ctl->add_item(RTR("Arabic Letter Mark (ALM)"), MENU_INSERT_ALM);
+ menu_ctl->add_item(RTR("Left-to-Right Isolate (LRI)"), MENU_INSERT_LRI);
+ menu_ctl->add_item(RTR("Right-to-Left Isolate (RLI)"), MENU_INSERT_RLI);
+ menu_ctl->add_item(RTR("First Strong Isolate (FSI)"), MENU_INSERT_FSI);
+ menu_ctl->add_item(RTR("Pop Direction Isolate (PDI)"), MENU_INSERT_PDI);
+ menu_ctl->add_separator();
+ menu_ctl->add_item(RTR("Zero-Width Joiner (ZWJ)"), MENU_INSERT_ZWJ);
+ menu_ctl->add_item(RTR("Zero-Width Non-Joiner (ZWNJ)"), MENU_INSERT_ZWNJ);
+ menu_ctl->add_item(RTR("Word Joiner (WJ)"), MENU_INSERT_WJ);
+ menu_ctl->add_item(RTR("Soft Hyphen (SHY)"), MENU_INSERT_SHY);
+ menu->add_child(menu_ctl, false, INTERNAL_MODE_FRONT);
+
+ menu->add_item(RTR("Cut"), MENU_CUT);
+ menu->add_item(RTR("Copy"), MENU_COPY);
+ menu->add_item(RTR("Paste"), MENU_PASTE);
+ menu->add_separator();
+ menu->add_item(RTR("Select All"), MENU_SELECT_ALL);
+ menu->add_item(RTR("Clear"), MENU_CLEAR);
+ menu->add_separator();
+ menu->add_item(RTR("Undo"), MENU_UNDO);
+ menu->add_item(RTR("Redo"), MENU_REDO);
+ menu->add_separator();
+ menu->add_submenu_item(RTR("Text Writing Direction"), "DirMenu", MENU_SUBMENU_TEXT_DIR);
+ menu->add_separator();
+ menu->add_check_item(RTR("Display Control Characters"), MENU_DISPLAY_UCC);
+ menu->add_submenu_item(RTR("Insert Control Character"), "CTLMenu", MENU_SUBMENU_INSERT_UCC);
+
+ menu->connect("id_pressed", callable_mp(this, &TextEdit::menu_option));
+ menu_dir->connect("id_pressed", callable_mp(this, &TextEdit::menu_option));
+ menu_ctl->connect("id_pressed", callable_mp(this, &TextEdit::menu_option));
+}
+
+void TextEdit::_update_context_menu() {
+ if (!menu) {
+ _generate_context_menu();
+ }
+
+ int idx = -1;
+
+#define MENU_ITEM_ACTION_DISABLED(m_menu, m_id, m_action, m_disabled) \
+ idx = m_menu->get_item_index(m_id); \
+ if (idx >= 0) { \
+ m_menu->set_item_accelerator(idx, shortcut_keys_enabled ? _get_menu_action_accelerator(m_action) : Key::NONE); \
+ m_menu->set_item_disabled(idx, m_disabled); \
+ }
+
+#define MENU_ITEM_ACTION(m_menu, m_id, m_action) \
+ idx = m_menu->get_item_index(m_id); \
+ if (idx >= 0) { \
+ m_menu->set_item_accelerator(idx, shortcut_keys_enabled ? _get_menu_action_accelerator(m_action) : Key::NONE); \
+ }
+
+#define MENU_ITEM_DISABLED(m_menu, m_id, m_disabled) \
+ idx = m_menu->get_item_index(m_id); \
+ if (idx >= 0) { \
+ m_menu->set_item_disabled(idx, m_disabled); \
+ }
+
+#define MENU_ITEM_CHECKED(m_menu, m_id, m_checked) \
+ idx = m_menu->get_item_index(m_id); \
+ if (idx >= 0) { \
+ m_menu->set_item_checked(idx, m_checked); \
+ }
+
+ MENU_ITEM_ACTION_DISABLED(menu, MENU_CUT, "ui_cut", !editable)
+ MENU_ITEM_ACTION(menu, MENU_COPY, "ui_copy")
+ MENU_ITEM_ACTION_DISABLED(menu, MENU_PASTE, "ui_paste", !editable)
+ MENU_ITEM_ACTION_DISABLED(menu, MENU_SELECT_ALL, "ui_text_select_all", !selecting_enabled)
+ MENU_ITEM_DISABLED(menu, MENU_CLEAR, !editable)
+ MENU_ITEM_ACTION_DISABLED(menu, MENU_UNDO, "ui_undo", !editable || !has_undo())
+ MENU_ITEM_ACTION_DISABLED(menu, MENU_REDO, "ui_redo", !editable || !has_redo())
+ MENU_ITEM_CHECKED(menu_dir, MENU_DIR_INHERITED, text_direction == TEXT_DIRECTION_INHERITED)
+ MENU_ITEM_CHECKED(menu_dir, MENU_DIR_AUTO, text_direction == TEXT_DIRECTION_AUTO)
+ MENU_ITEM_CHECKED(menu_dir, MENU_DIR_LTR, text_direction == TEXT_DIRECTION_LTR)
+ MENU_ITEM_CHECKED(menu_dir, MENU_DIR_RTL, text_direction == TEXT_DIRECTION_RTL)
+ MENU_ITEM_CHECKED(menu, MENU_DISPLAY_UCC, draw_control_chars)
+ MENU_ITEM_DISABLED(menu, MENU_SUBMENU_INSERT_UCC, !editable)
+
+#undef MENU_ITEM_ACTION_DISABLED
+#undef MENU_ITEM_ACTION
+#undef MENU_ITEM_DISABLED
+#undef MENU_ITEM_CHECKED
+}
+
/* Versioning */
void TextEdit::_push_current_op() {
if (pending_action_end) {
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 2ec2f39409..a084fa3833 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -87,11 +87,13 @@ public:
MENU_SELECT_ALL,
MENU_UNDO,
MENU_REDO,
+ MENU_SUBMENU_TEXT_DIR,
MENU_DIR_INHERITED,
MENU_DIR_AUTO,
MENU_DIR_LTR,
MENU_DIR_RTL,
MENU_DISPLAY_UCC,
+ MENU_SUBMENU_INSERT_UCC,
MENU_INSERT_LRM,
MENU_INSERT_RLM,
MENU_INSERT_LRE,
@@ -303,8 +305,9 @@ private:
PopupMenu *menu_dir = nullptr;
PopupMenu *menu_ctl = nullptr;
- void _generate_context_menu();
Key _get_menu_action_accelerator(const String &p_action);
+ void _generate_context_menu();
+ void _update_context_menu();
/* Versioning */
struct Caret;
diff --git a/scene/resources/sprite_frames.cpp b/scene/resources/sprite_frames.cpp
index c101974248..818be38681 100644
--- a/scene/resources/sprite_frames.cpp
+++ b/scene/resources/sprite_frames.cpp
@@ -36,7 +36,7 @@ void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture2D> &p_t
HashMap<StringName, Anim>::Iterator E = animations.find(p_anim);
ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist.");
- p_duration = MAX(0.0, p_duration);
+ p_duration = MAX(SPRITE_FRAME_MINIMUM_DURATION, p_duration);
Frame frame = { p_texture, p_duration };
@@ -57,7 +57,7 @@ void SpriteFrames::set_frame(const StringName &p_anim, int p_idx, const Ref<Text
return;
}
- p_duration = MAX(0.0, p_duration);
+ p_duration = MAX(SPRITE_FRAME_MINIMUM_DURATION, p_duration);
Frame frame = { p_texture, p_duration };
@@ -214,7 +214,7 @@ void SpriteFrames::_set_animations(const Array &p_animations) {
ERR_CONTINUE(!f.has("texture"));
ERR_CONTINUE(!f.has("duration"));
- Frame frame = { f["texture"], f["duration"] };
+ Frame frame = { f["texture"], MAX(SPRITE_FRAME_MINIMUM_DURATION, (float)f["duration"]) };
anim.frames.push_back(frame);
}
diff --git a/scene/resources/sprite_frames.h b/scene/resources/sprite_frames.h
index 61bead6948..6de2b4a37b 100644
--- a/scene/resources/sprite_frames.h
+++ b/scene/resources/sprite_frames.h
@@ -33,6 +33,8 @@
#include "scene/resources/texture.h"
+static const float SPRITE_FRAME_MINIMUM_DURATION = 0.01;
+
class SpriteFrames : public Resource {
GDCLASS(SpriteFrames, Resource);
@@ -89,10 +91,10 @@ public:
_FORCE_INLINE_ float get_frame_duration(const StringName &p_anim, int p_idx) const {
HashMap<StringName, Anim>::ConstIterator E = animations.find(p_anim);
- ERR_FAIL_COND_V_MSG(!E, 0.0, "Animation '" + String(p_anim) + "' doesn't exist.");
- ERR_FAIL_COND_V(p_idx < 0, 0.0);
+ ERR_FAIL_COND_V_MSG(!E, 1.0, "Animation '" + String(p_anim) + "' doesn't exist.");
+ ERR_FAIL_COND_V(p_idx < 0, 1.0);
if (p_idx >= E->value.frames.size()) {
- return 0.0;
+ return 1.0;
}
return E->value.frames[p_idx].duration;
diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp
index 0beb62185d..fbbe98d022 100644
--- a/scene/resources/style_box.cpp
+++ b/scene/resources/style_box.cpp
@@ -151,11 +151,6 @@ void StyleBoxTexture::set_texture(Ref<Texture2D> p_texture) {
return;
}
texture = p_texture;
- if (p_texture.is_null()) {
- region_rect = Rect2(0, 0, 0, 0);
- } else {
- region_rect = Rect2(Point2(), texture->get_size());
- }
emit_changed();
}
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index 85e21d6056..7e3156d2ff 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -653,7 +653,7 @@ Ref<Image> CompressedTexture2D::load_image_from_file(Ref<FileAccess> f, int p_si
uint32_t mipmaps = f->get_32();
Image::Format format = Image::Format(f->get_32());
- if (data_format == DATA_FORMAT_PNG || data_format == DATA_FORMAT_WEBP || data_format == DATA_FORMAT_BASIS_UNIVERSAL) {
+ if (data_format == DATA_FORMAT_PNG || data_format == DATA_FORMAT_WEBP) {
//look for a PNG or WebP file inside
int sw = w;
@@ -684,9 +684,7 @@ Ref<Image> CompressedTexture2D::load_image_from_file(Ref<FileAccess> f, int p_si
}
Ref<Image> img;
- if (data_format == DATA_FORMAT_BASIS_UNIVERSAL && Image::basis_universal_unpacker) {
- img = Image::basis_universal_unpacker(pv);
- } else if (data_format == DATA_FORMAT_PNG && Image::png_unpacker) {
+ if (data_format == DATA_FORMAT_PNG && Image::png_unpacker) {
img = Image::png_unpacker(pv);
} else if (data_format == DATA_FORMAT_WEBP && Image::webp_unpacker) {
img = Image::webp_unpacker(pv);
@@ -745,6 +743,32 @@ Ref<Image> CompressedTexture2D::load_image_from_file(Ref<FileAccess> f, int p_si
return image;
}
+ } else if (data_format == DATA_FORMAT_BASIS_UNIVERSAL) {
+ int sw = w;
+ int sh = h;
+ uint32_t size = f->get_32();
+ if (p_size_limit > 0 && (sw > p_size_limit || sh > p_size_limit)) {
+ //can't load this due to size limit
+ sw = MAX(sw >> 1, 1);
+ sh = MAX(sh >> 1, 1);
+ f->seek(f->get_position() + size);
+ return Ref<Image>();
+ }
+ Vector<uint8_t> pv;
+ pv.resize(size);
+ {
+ uint8_t *wr = pv.ptrw();
+ f->get_buffer(wr, size);
+ }
+ Ref<Image> img;
+ img = Image::basis_universal_unpacker(pv);
+ if (img.is_null() || img->is_empty()) {
+ ERR_FAIL_COND_V(img.is_null() || img->is_empty(), Ref<Image>());
+ }
+ format = img->get_format();
+ sw = MAX(sw >> 1, 1);
+ sh = MAX(sh >> 1, 1);
+ return img;
} else if (data_format == DATA_FORMAT_IMAGE) {
int size = Image::get_image_data_size(w, h, format, mipmaps ? true : false);
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index 5f3a757c09..12107dade5 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -4306,19 +4306,11 @@ Rect2i TileSetAtlasSource::get_tile_texture_region(Vector2i p_atlas_coords, int
return Rect2(origin, region_size);
}
-Vector2i TileSetAtlasSource::get_tile_effective_texture_offset(Vector2i p_atlas_coords, int p_alternative_tile) const {
- ERR_FAIL_COND_V_MSG(!tiles.has(p_atlas_coords), Vector2i(), vformat("TileSetAtlasSource has no tile at %s.", Vector2i(p_atlas_coords)));
- ERR_FAIL_COND_V_MSG(!has_alternative_tile(p_atlas_coords, p_alternative_tile), Vector2i(), vformat("TileSetAtlasSource has no alternative tile with id %d at %s.", p_alternative_tile, String(p_atlas_coords)));
- ERR_FAIL_COND_V(!tile_set, Vector2i());
-
- Vector2 margin = (get_tile_texture_region(p_atlas_coords).size - tile_set->get_tile_size()) / 2;
- margin = Vector2i(MAX(0, margin.x), MAX(0, margin.y));
- Vector2i effective_texture_offset = get_tile_data(p_atlas_coords, p_alternative_tile)->get_texture_offset();
- if (ABS(effective_texture_offset.x) > margin.x || ABS(effective_texture_offset.y) > margin.y) {
- effective_texture_offset = effective_texture_offset.clamp(-margin, margin);
- }
+bool TileSetAtlasSource::is_position_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Vector2 p_position) const {
+ Size2 size = get_tile_texture_region(p_atlas_coords).size;
+ Rect2 rect = Rect2(-size / 2 - get_tile_data(p_atlas_coords, p_alternative_tile)->get_texture_origin(), size);
- return effective_texture_offset;
+ return rect.has_point(p_position);
}
// Getters for texture and tile region (padded or not)
@@ -5070,7 +5062,7 @@ TileData *TileData::duplicate() {
output->flip_h = flip_h;
output->flip_v = flip_v;
output->transpose = transpose;
- output->tex_offset = tex_offset;
+ output->texture_origin = texture_origin;
output->material = material;
output->modulate = modulate;
output->z_index = z_index;
@@ -5120,13 +5112,13 @@ bool TileData::get_transpose() const {
return transpose;
}
-void TileData::set_texture_offset(Vector2i p_texture_offset) {
- tex_offset = p_texture_offset;
+void TileData::set_texture_origin(Vector2i p_texture_origin) {
+ texture_origin = p_texture_origin;
emit_signal(SNAME("changed"));
}
-Vector2i TileData::get_texture_offset() const {
- return tex_offset;
+Vector2i TileData::get_texture_origin() const {
+ return texture_origin;
}
void TileData::set_material(Ref<Material> p_material) {
@@ -5414,6 +5406,13 @@ Variant TileData::get_custom_data_by_layer_id(int p_layer_id) const {
}
bool TileData::_set(const StringName &p_name, const Variant &p_value) {
+#ifndef DISABLE_DEPRECATED
+ if (p_name == "texture_offset") {
+ texture_origin = p_value;
+ return true;
+ }
+#endif
+
Vector<String> components = String(p_name).split("/", true, 2);
if (components.size() == 2 && components[0].begins_with("occlusion_layer_") && components[0].trim_prefix("occlusion_layer_").is_valid_int()) {
@@ -5535,6 +5534,13 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
}
bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
+#ifndef DISABLE_DEPRECATED
+ if (p_name == "texture_offset") {
+ r_ret = texture_origin;
+ return true;
+ }
+#endif
+
Vector<String> components = String(p_name).split("/", true, 2);
if (tile_set) {
@@ -5716,8 +5722,8 @@ void TileData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_transpose"), &TileData::get_transpose);
ClassDB::bind_method(D_METHOD("set_material", "material"), &TileData::set_material);
ClassDB::bind_method(D_METHOD("get_material"), &TileData::get_material);
- ClassDB::bind_method(D_METHOD("set_texture_offset", "texture_offset"), &TileData::set_texture_offset);
- ClassDB::bind_method(D_METHOD("get_texture_offset"), &TileData::get_texture_offset);
+ ClassDB::bind_method(D_METHOD("set_texture_origin", "texture_origin"), &TileData::set_texture_origin);
+ ClassDB::bind_method(D_METHOD("get_texture_origin"), &TileData::get_texture_origin);
ClassDB::bind_method(D_METHOD("set_modulate", "modulate"), &TileData::set_modulate);
ClassDB::bind_method(D_METHOD("get_modulate"), &TileData::get_modulate);
ClassDB::bind_method(D_METHOD("set_z_index", "z_index"), &TileData::set_z_index);
@@ -5770,7 +5776,7 @@ void TileData::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_h"), "set_flip_h", "get_flip_h");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_v"), "set_flip_v", "get_flip_v");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transpose"), "set_transpose", "get_transpose");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "texture_offset", PROPERTY_HINT_NONE, "suffix:px"), "set_texture_offset", "get_texture_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "texture_origin", PROPERTY_HINT_NONE, "suffix:px"), "set_texture_origin", "get_texture_origin");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemMaterial,ShaderMaterial"), "set_material", "get_material");
ADD_PROPERTY(PropertyInfo(Variant::INT, "z_index"), "set_z_index", "get_z_index");
diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h
index 2d8c2bd5bd..044b46a701 100644
--- a/scene/resources/tile_set.h
+++ b/scene/resources/tile_set.h
@@ -721,7 +721,7 @@ public:
// Helpers.
Vector2i get_atlas_grid_size() const;
Rect2i get_tile_texture_region(Vector2i p_atlas_coords, int p_frame = 0) const;
- Vector2i get_tile_effective_texture_offset(Vector2i p_atlas_coords, int p_alternative_tile) const;
+ bool is_position_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Vector2 p_position) const;
// Getters for texture and tile region (padded or not)
Ref<Texture2D> get_runtime_texture() const;
@@ -787,7 +787,7 @@ private:
bool flip_h = false;
bool flip_v = false;
bool transpose = false;
- Vector2i tex_offset;
+ Vector2i texture_origin;
Ref<Material> material = Ref<Material>();
Color modulate = Color(1.0, 1.0, 1.0, 1.0);
int z_index = 0;
@@ -866,8 +866,8 @@ public:
void set_transpose(bool p_transpose);
bool get_transpose() const;
- void set_texture_offset(Vector2i p_texture_offset);
- Vector2i get_texture_offset() const;
+ void set_texture_origin(Vector2i p_texture_origin);
+ Vector2i get_texture_origin() const;
void set_material(Ref<Material> p_material);
Ref<Material> get_material() const;
void set_modulate(Color p_modulate);