summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/3d/physics_body.cpp124
-rw-r--r--scene/3d/physics_body.h17
-rw-r--r--scene/3d/ray_cast.cpp86
-rw-r--r--scene/3d/ray_cast.h7
-rw-r--r--scene/gui/base_button.cpp2
-rw-r--r--scene/gui/dialogs.cpp55
-rw-r--r--scene/gui/text_edit.cpp144
-rw-r--r--scene/gui/text_edit.h14
-rw-r--r--scene/main/http_request.cpp2
-rw-r--r--scene/resources/animation.cpp4
-rw-r--r--scene/resources/default_theme/default_theme.cpp6
-rw-r--r--scene/resources/style_box.cpp5
-rw-r--r--scene/resources/texture.cpp16
13 files changed, 410 insertions, 72 deletions
diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp
index 94f34d6fb3..98babedf0d 100644
--- a/scene/3d/physics_body.cpp
+++ b/scene/3d/physics_body.cpp
@@ -28,6 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "physics_body.h"
+#include "method_bind_ext.inc"
#include "scene/scene_string_names.h"
void PhysicsBody::_notification(int p_what) {
@@ -907,6 +908,19 @@ bool KinematicBody::_ignores_mode(PhysicsServer::BodyMode p_mode) const {
return true;
}
+void KinematicBody::revert_motion() {
+
+ Transform gt = get_global_transform();
+ gt.origin -= travel; //I do hope this is correct.
+ travel = Vector3();
+ set_global_transform(gt);
+}
+
+Vector3 KinematicBody::get_travel() const {
+
+ return travel;
+}
+
Vector3 KinematicBody::move(const Vector3 &p_motion) {
//give me back regular physics engine logic
@@ -1097,10 +1111,111 @@ Vector3 KinematicBody::move(const Vector3 &p_motion) {
Transform gt = get_global_transform();
gt.origin += motion;
set_global_transform(gt);
+ travel = motion;
return p_motion - motion;
}
+Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_floor_direction, const Vector3 &p_ceil_direction, float p_slope_stop_min_velocity, int p_max_bounces, float p_floor_max_angle, float p_ceil_max_angle) {
+
+ /*
+ Things to note:
+ 1. This function is basically the KinematicBody2D function ported over.
+ 2. The 'travel' variable and stuff relating to it exists more or less for this function's sake.
+ 3. Someone is going to have to document this, so here's an example for them:
+ vel = move_and_slide(vel, Vector3(0, 1, 0), Vector3(0, -1, 0), 0.1);
+ Very useful for FPS controllers so long as you control horizontal motion properly - even for Quake-style AABB colliders.
+ The slope stop system is... rather weird, and it's correct operation depends on what scale your game is built on,
+ but as far as I can tell in theory it's suppposed to be a way of turning impassable slopes into invisible walls.
+ It can also be a pain, since there's a better-known way of defining such things: "let gravity do the work".
+ If you don't like it, set it to positive infinity.
+ 4. Might be a bug somewhere else in physics: When there are two CollisionShape nodes with a shared Shape, only one is considered, I think.
+ Test this further.
+ */
+
+ Vector3 motion = (move_and_slide_floor_velocity + p_linear_velocity) * get_fixed_process_delta_time();
+ Vector3 lv = p_linear_velocity;
+
+ move_and_slide_on_floor = false;
+ move_and_slide_on_ceiling = false;
+ move_and_slide_on_wall = false;
+ move_and_slide_colliders.clear();
+ move_and_slide_floor_velocity = Vector3();
+
+ while (p_max_bounces) {
+
+ motion = move(motion);
+
+ if (is_colliding()) {
+
+ bool hit_horizontal = false; //hit floor or ceiling
+
+ if (p_floor_direction != Vector3()) {
+ if (get_collision_normal().dot(p_floor_direction) >= Math::cos(p_floor_max_angle)) { //floor
+
+ hit_horizontal = true;
+ move_and_slide_on_floor = true;
+ move_and_slide_floor_velocity = get_collider_velocity();
+
+ //Note: These two lines are the only lines that really changed between 3D/2D, see if it can't be reused somehow???
+ Vector2 hz_velocity = Vector2(lv.x - move_and_slide_floor_velocity.x, lv.z - move_and_slide_floor_velocity.z);
+ if (get_travel().length() < 1 && hz_velocity.length() < p_slope_stop_min_velocity) {
+ revert_motion();
+ return Vector3();
+ }
+ }
+ }
+
+ if (p_ceil_direction != Vector3()) {
+ if (get_collision_normal().dot(p_ceil_direction) >= Math::cos(p_ceil_max_angle)) { //ceiling
+ hit_horizontal = true;
+ move_and_slide_on_ceiling = true;
+ }
+ }
+
+ //if it hit something but didn't hit a floor or ceiling, it is by default a wall
+ //(this imitates the pre-specifiable-ceiling logic more or less, except ceiling is optional)
+ if (!hit_horizontal) {
+ move_and_slide_on_wall = true;
+ }
+
+ Vector3 n = get_collision_normal();
+ motion = motion.slide(n);
+ lv = lv.slide(n);
+ Variant collider = _get_collider();
+ if (collider.get_type() != Variant::NIL) {
+ move_and_slide_colliders.push_back(collider);
+ }
+
+ } else {
+ break;
+ }
+
+ p_max_bounces--;
+ if (motion == Vector3())
+ break;
+ }
+
+ return lv;
+}
+
+bool KinematicBody::is_move_and_slide_on_floor() const {
+
+ return move_and_slide_on_floor;
+}
+bool KinematicBody::is_move_and_slide_on_wall() const {
+
+ return move_and_slide_on_wall;
+}
+bool KinematicBody::is_move_and_slide_on_ceiling() const {
+
+ return move_and_slide_on_ceiling;
+}
+Array KinematicBody::get_move_and_slide_colliders() const {
+
+ return move_and_slide_colliders;
+}
+
Vector3 KinematicBody::move_to(const Vector3 &p_position) {
return move(p_position - get_global_transform().origin);
@@ -1223,6 +1338,7 @@ void KinematicBody::_bind_methods() {
ClassDB::bind_method(D_METHOD("move", "rel_vec"), &KinematicBody::move);
ClassDB::bind_method(D_METHOD("move_to", "position"), &KinematicBody::move_to);
+ ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "floor_normal", "ceil_normal", "slope_stop_min_velocity", "max_bounces", "floor_max_angle", "ceil_max_angle"), &KinematicBody::move_and_slide, DEFVAL(Vector3(0, 0, 0)), DEFVAL(Vector3(0, 0, 0)), DEFVAL(5), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(Math::deg2rad((float)45)));
ClassDB::bind_method(D_METHOD("can_teleport_to", "position"), &KinematicBody::can_teleport_to);
@@ -1249,6 +1365,14 @@ void KinematicBody::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collision_margin", "pixels"), &KinematicBody::set_collision_margin);
ClassDB::bind_method(D_METHOD("get_collision_margin", "pixels"), &KinematicBody::get_collision_margin);
+ ClassDB::bind_method(D_METHOD("get_travel"), &KinematicBody::get_travel);
+ ClassDB::bind_method(D_METHOD("revert_motion"), &KinematicBody::revert_motion);
+
+ ClassDB::bind_method(D_METHOD("get_move_and_slide_colliders"), &KinematicBody::get_move_and_slide_colliders);
+ ClassDB::bind_method(D_METHOD("is_move_and_slide_on_floor"), &KinematicBody::is_move_and_slide_on_floor);
+ ClassDB::bind_method(D_METHOD("is_move_and_slide_on_ceiling"), &KinematicBody::is_move_and_slide_on_ceiling);
+ ClassDB::bind_method(D_METHOD("is_move_and_slide_on_wall"), &KinematicBody::is_move_and_slide_on_wall);
+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with/static"), "set_collide_with_static_bodies", "can_collide_with_static_bodies");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with/kinematic"), "set_collide_with_kinematic_bodies", "can_collide_with_kinematic_bodies");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with/rigid"), "set_collide_with_rigid_bodies", "can_collide_with_rigid_bodies");
diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h
index c62f6be13f..d13f84dc15 100644
--- a/scene/3d/physics_body.h
+++ b/scene/3d/physics_body.h
@@ -275,6 +275,13 @@ class KinematicBody : public PhysicsBody {
Vector3 collider_vel;
ObjectID collider;
int collider_shape;
+ Vector3 travel;
+
+ Vector3 move_and_slide_floor_velocity;
+ bool move_and_slide_on_floor;
+ bool move_and_slide_on_ceiling;
+ bool move_and_slide_on_wall;
+ Array move_and_slide_colliders;
Variant _get_collider() const;
@@ -295,6 +302,10 @@ public:
bool can_teleport_to(const Vector3 &p_position);
bool is_colliding() const;
+
+ Vector3 get_travel() const; // Set by move and others. Consider unreliable except immediately after a move call.
+ void revert_motion();
+
Vector3 get_collision_pos() const;
Vector3 get_collision_normal() const;
Vector3 get_collider_velocity() const;
@@ -316,6 +327,12 @@ public:
void set_collision_margin(float p_margin);
float get_collision_margin() const;
+ Vector3 move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_floor_direction = Vector3(0, 0, 0), const Vector3 &p_ceil_direction = Vector3(0, 0, 0), float p_slope_stop_min_velocity = 5, int p_max_bounces = 4, float p_floor_max_angle = Math::deg2rad((float)45), float p_ceil_max_angle = Math::deg2rad((float)45));
+ bool is_move_and_slide_on_floor() const;
+ bool is_move_and_slide_on_wall() const;
+ bool is_move_and_slide_on_ceiling() const;
+ Array get_move_and_slide_colliders() const;
+
KinematicBody();
~KinematicBody();
};
diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast.cpp
index f984d8f06d..d3b4577c42 100644
--- a/scene/3d/ray_cast.cpp
+++ b/scene/3d/ray_cast.cpp
@@ -30,12 +30,15 @@
#include "ray_cast.h"
#include "collision_object.h"
+#include "mesh_instance.h"
#include "servers/physics_server.h"
void RayCast::set_cast_to(const Vector3 &p_point) {
cast_to = p_point;
if (is_inside_tree() && (get_tree()->is_editor_hint() || get_tree()->is_debugging_collisions_hint()))
update_gizmo();
+ if (is_inside_tree() && get_tree()->is_debugging_collisions_hint())
+ _update_debug_shape();
}
Vector3 RayCast::get_cast_to() const {
@@ -95,6 +98,13 @@ void RayCast::set_enabled(bool p_enabled) {
set_fixed_process(p_enabled);
if (!p_enabled)
collided = false;
+
+ if (is_inside_tree() && get_tree()->is_debugging_collisions_hint()) {
+ if (p_enabled)
+ _update_debug_shape();
+ else
+ _clear_debug_shape();
+ }
}
bool RayCast::is_enabled() const {
@@ -110,6 +120,9 @@ void RayCast::_notification(int p_what) {
if (enabled && !get_tree()->is_editor_hint()) {
set_fixed_process(true);
+
+ if (get_tree()->is_debugging_collisions_hint())
+ _update_debug_shape();
} else
set_fixed_process(false);
@@ -120,13 +133,23 @@ void RayCast::_notification(int p_what) {
set_fixed_process(false);
}
+ if (debug_shape)
+ _clear_debug_shape();
+
} break;
case NOTIFICATION_FIXED_PROCESS: {
if (!enabled)
break;
+ bool prev_collision_state = collided;
_update_raycast_state();
+ if (prev_collision_state != collided && get_tree()->is_debugging_collisions_hint()) {
+ if (debug_material.is_valid()) {
+ Ref<FixedSpatialMaterial> line_material = static_cast<Ref<FixedSpatialMaterial> >(debug_material);
+ line_material->set_albedo(collided ? Color(1.0, 0, 0) : Color(1.0, 0.8, 0.6));
+ }
+ }
} break;
}
@@ -232,6 +255,68 @@ void RayCast::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "type_mask", PROPERTY_HINT_FLAGS, "Static,Kinematic,Rigid,Character,Area"), "set_type_mask", "get_type_mask");
}
+void RayCast::_create_debug_shape() {
+
+ if (!debug_material.is_valid()) {
+ debug_material = Ref<FixedSpatialMaterial>(memnew(FixedSpatialMaterial));
+
+ Ref<FixedSpatialMaterial> line_material = static_cast<Ref<FixedSpatialMaterial> >(debug_material);
+ line_material->set_flag(FixedSpatialMaterial::FLAG_UNSHADED, true);
+ line_material->set_line_width(3.0);
+ line_material->set_albedo(Color(1.0, 0.8, 0.6));
+ }
+
+ Ref<Mesh> mesh = memnew(Mesh);
+
+ MeshInstance *mi = memnew(MeshInstance);
+ mi->set_mesh(mesh);
+
+ add_child(mi);
+ debug_shape = mi;
+}
+
+void RayCast::_update_debug_shape() {
+
+ if (!enabled)
+ return;
+
+ if (!debug_shape)
+ _create_debug_shape();
+
+ MeshInstance *mi = static_cast<MeshInstance *>(debug_shape);
+ if (!mi->get_mesh().is_valid())
+ return;
+
+ Ref<Mesh> mesh = mi->get_mesh();
+ if (mesh->get_surface_count() > 0)
+ mesh->surface_remove(0);
+
+ Array a;
+ a.resize(Mesh::ARRAY_MAX);
+
+ Vector<Vector3> verts;
+ verts.push_back(Vector3());
+ verts.push_back(cast_to);
+ a[Mesh::ARRAY_VERTEX] = verts;
+
+ mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, a);
+ mesh->surface_set_material(0, debug_material);
+}
+
+void RayCast::_clear_debug_shape() {
+
+ if (!debug_shape)
+ return;
+
+ MeshInstance *mi = static_cast<MeshInstance *>(debug_shape);
+ if (mi->is_inside_tree())
+ mi->queue_delete();
+ else
+ memdelete(mi);
+
+ debug_shape = NULL;
+}
+
RayCast::RayCast() {
enabled = false;
@@ -241,4 +326,5 @@ RayCast::RayCast() {
layer_mask = 1;
type_mask = PhysicsDirectSpaceState::TYPE_MASK_COLLISION;
cast_to = Vector3(0, -1, 0);
+ debug_shape = NULL;
}
diff --git a/scene/3d/ray_cast.h b/scene/3d/ray_cast.h
index 7ab7b57db3..63a53d724f 100644
--- a/scene/3d/ray_cast.h
+++ b/scene/3d/ray_cast.h
@@ -50,6 +50,13 @@ class RayCast : public Spatial {
uint32_t layer_mask;
uint32_t type_mask;
+ Node *debug_shape;
+ Ref<Material> debug_material;
+
+ void _create_debug_shape();
+ void _update_debug_shape();
+ void _clear_debug_shape();
+
protected:
void _notification(int p_what);
void _update_raycast_state();
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index ee4f8736d7..839dcc3678 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -38,6 +38,8 @@ void BaseButton::_unpress_group() {
if (!button_group.is_valid())
return;
+ status.pressed = true;
+
for (Set<BaseButton *>::Element *E = button_group->buttons.front(); E; E = E->next()) {
if (E->get() == this)
continue;
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index 2ec72a2948..835775e13b 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -36,6 +36,8 @@
#include "editor/editor_node.h"
#endif
+// WindowDialog
+
void WindowDialog::_post_popup() {
drag_type = DRAG_NONE; // just in case
@@ -51,11 +53,11 @@ void WindowDialog::_fix_size() {
Size2i viewport_size = get_viewport_rect().size;
// Windows require additional padding to keep the window chrome visible.
- Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog");
- float top = panel->get_margin(MARGIN_TOP);
- float left = panel->get_margin(MARGIN_LEFT);
- float bottom = panel->get_margin(MARGIN_BOTTOM);
- float right = panel->get_margin(MARGIN_RIGHT);
+ Ref<StyleBoxTexture> panel = get_stylebox("panel", "WindowDialog");
+ float top = panel->get_expand_margin_size(MARGIN_TOP);
+ float left = panel->get_expand_margin_size(MARGIN_LEFT);
+ float bottom = panel->get_expand_margin_size(MARGIN_BOTTOM);
+ float right = panel->get_expand_margin_size(MARGIN_RIGHT);
pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right));
pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom));
@@ -74,9 +76,9 @@ bool WindowDialog::has_point(const Point2 &p_point) const {
Rect2 r(Point2(), get_size());
// Enlarge upwards for title bar.
- int titlebar_height = get_constant("titlebar_height", "WindowDialog");
- r.pos.y -= titlebar_height;
- r.size.y += titlebar_height;
+ int title_height = get_constant("title_height", "WindowDialog");
+ r.pos.y -= title_height;
+ r.size.y += title_height;
// Inflate by the resizable border thickness.
if (resizable) {
@@ -173,30 +175,21 @@ void WindowDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
-
RID canvas = get_canvas_item();
- Size2 size = get_size();
+ // Draw the background.
Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog");
- int margin_left = static_cast<int>(panel->get_margin(MARGIN_LEFT));
- int margin_top = static_cast<int>(panel->get_margin(MARGIN_TOP));
- int margin_right = static_cast<int>(panel->get_margin(MARGIN_RIGHT));
- int margin_bottom = static_cast<int>(panel->get_margin(MARGIN_BOTTOM));
-
- Rect2 rect;
- rect.pos.x = -margin_left;
- rect.pos.y = -margin_top;
- rect.size.width = size.width + margin_left + margin_right;
- rect.size.height = size.height + margin_top + margin_bottom;
-
- panel->draw(canvas, rect);
+ Size2 size = get_size();
+ panel->draw(canvas, Rect2(0, 0, size.x, size.y));
- int title_height = get_constant("title_height", "WindowDialog");
+ // Draw the title bar text.
+ Ref<Font> title_font = get_font("title_font", "WindowDialog");
Color title_color = get_color("title_color", "WindowDialog");
- Ref<Font> font = get_font("title_font", "WindowDialog");
- int ofs = (size.width - font->get_string_size(title).width) / 2;
- draw_string(font, Point2(ofs, -title_height + font->get_ascent()), title, title_color, size.width - panel->get_minimum_size().width);
-
+ int title_height = get_constant("title_height", "WindowDialog");
+ int font_height = title_font->get_height() - title_font->get_descent() * 2;
+ int x = (size.x - title_font->get_string_size(title).x) / 2;
+ int y = (-title_height + font_height) / 2;
+ title_font->draw(canvas, Point2(x, y), title, title_color, size.x - panel->get_minimum_size().x);
} break;
case NOTIFICATION_THEME_CHANGED:
@@ -238,12 +231,12 @@ int WindowDialog::_drag_hit_test(const Point2 &pos) const {
int drag_type = DRAG_NONE;
if (resizable) {
- int titlebar_height = get_constant("titlebar_height", "WindowDialog");
+ int title_height = get_constant("title_height", "WindowDialog");
int scaleborder_size = get_constant("scaleborder_size", "WindowDialog");
Rect2 rect = get_rect();
- if (pos.y < (-titlebar_height + scaleborder_size))
+ if (pos.y < (-title_height + scaleborder_size))
drag_type = DRAG_RESIZE_TOP;
else if (pos.y >= (rect.size.height - scaleborder_size))
drag_type = DRAG_RESIZE_BOTTOM;
@@ -317,6 +310,8 @@ WindowDialog::WindowDialog() {
WindowDialog::~WindowDialog() {
}
+// PopupDialog
+
void PopupDialog::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
@@ -554,6 +549,8 @@ AcceptDialog::AcceptDialog() {
AcceptDialog::~AcceptDialog() {
}
+// ConfirmationDialog
+
void ConfirmationDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_cancel:Button"), &ConfirmationDialog::get_cancel);
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 69a90535df..3c8545bd75 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -101,15 +101,15 @@ void TextEdit::Text::set_font(const Ref<Font> &p_font) {
font = p_font;
}
-void TextEdit::Text::set_tab_size(int p_tab_size) {
+void TextEdit::Text::set_indent_size(int p_indent_size) {
- tab_size = p_tab_size;
+ indent_size = p_indent_size;
}
void TextEdit::Text::_update_line_cache(int p_line) const {
int w = 0;
- int tab_w = font->get_char_size(' ').width * tab_size;
+ int tab_w = font->get_char_size(' ').width * indent_size;
int len = text[p_line].data.length();
const CharType *str = text[p_line].data.c_str();
@@ -456,7 +456,7 @@ void TextEdit::_notification(int p_what) {
int visible_rows = get_visible_rows();
- int tab_w = cache.font->get_char_size(' ').width * tab_size;
+ int tab_w = cache.font->get_char_size(' ').width * indent_size;
Color color = cache.font_color;
int in_region = -1;
@@ -1305,7 +1305,38 @@ void TextEdit::backspace_at_cursor() {
_is_pair_left_symbol(text[cursor.line][cursor.column - 1])) {
_consume_backspace_for_pair_symbol(prev_line, prev_column);
} else {
- _remove_text(prev_line, prev_column, cursor.line, cursor.column);
+ // handle space indentation
+ if (cursor.column - indent_size >= 0 && indent_using_spaces) {
+
+ // if there is enough spaces to count as a tab
+ bool unindent = true;
+ for (int i = 1; i <= indent_size; i++) {
+ if (text[cursor.line][cursor.column - i] != ' ') {
+ unindent = false;
+ break;
+ }
+ }
+
+ // and it is before the first character
+ int i = 0;
+ while (i < cursor.column && i < text[cursor.line].length()) {
+ if (text[cursor.line][i] != ' ' && text[cursor.line][i] != '\t') {
+ unindent = false;
+ break;
+ }
+ i++;
+ }
+
+ // then we can remove it as a single character.
+ if (unindent) {
+ _remove_text(cursor.line, cursor.column - indent_size, cursor.line, cursor.column);
+ prev_column = cursor.column - indent_size;
+ } else {
+ _remove_text(prev_line, prev_column, cursor.line, cursor.column);
+ }
+ } else {
+ _remove_text(prev_line, prev_column, cursor.line, cursor.column);
+ }
}
cursor_set_line(prev_line);
@@ -1328,7 +1359,11 @@ void TextEdit::indent_selection_right() {
for (int i = start_line; i <= end_line; i++) {
String line_text = get_line(i);
- line_text = '\t' + line_text;
+ if (indent_using_spaces) {
+ line_text = space_indent + line_text;
+ } else {
+ line_text = '\t' + line_text;
+ }
set_line(i, line_text);
}
@@ -1359,8 +1394,8 @@ void TextEdit::indent_selection_left() {
if (line_text.begins_with("\t")) {
line_text = line_text.substr(1, line_text.length());
set_line(i, line_text);
- } else if (line_text.begins_with(" ")) {
- line_text = line_text.substr(4, line_text.length());
+ } else if (line_text.begins_with(space_indent)) {
+ line_text = line_text.substr(indent_size, line_text.length());
set_line(i, line_text);
}
}
@@ -1931,17 +1966,39 @@ void TextEdit::_gui_input(const InputEvent &p_gui_input) {
String ins = "\n";
//keep indentation
+ int space_count = 0;
for (int i = 0; i < text[cursor.line].length(); i++) {
- if (text[cursor.line][i] == '\t')
- ins += "\t";
- else
+ if (text[cursor.line][i] == '\t') {
+ if (indent_using_spaces) {
+ ins += space_indent;
+ } else {
+ ins += "\t";
+ }
+ space_count = 0;
+ } else if (text[cursor.line][i] == ' ') {
+ space_count++;
+
+ if (space_count == indent_size) {
+ if (indent_using_spaces) {
+ ins += space_indent;
+ } else {
+ ins += "\t";
+ }
+ space_count = 0;
+ }
+ } else {
break;
+ }
}
if (auto_indent) {
// indent once again if previous line will end with ':'
// (i.e. colon precedes current cursor position)
if (cursor.column > 0 && text[cursor.line][cursor.column - 1] == ':') {
- ins += "\t";
+ if (indent_using_spaces) {
+ ins += space_indent;
+ } else {
+ ins += "\t";
+ }
}
}
@@ -1987,15 +2044,36 @@ void TextEdit::_gui_input(const InputEvent &p_gui_input) {
} else {
if (k.mod.shift) {
+ //simple unindent
int cc = cursor.column;
- if (cc > 0 && cc <= text[cursor.line].length() && text[cursor.line][cursor.column - 1] == '\t') {
- //simple unindent
+ if (cc > 0 && cc <= text[cursor.line].length()) {
+ if (text[cursor.line][cursor.column - 1] == '\t') {
+ backspace_at_cursor();
+ } else {
+ if (cursor.column - indent_size >= 0) {
+
+ bool unindent = true;
+ for (int i = 1; i <= indent_size; i++) {
+ if (text[cursor.line][cursor.column - i] != ' ') {
+ unindent = false;
+ break;
+ }
+ }
- backspace_at_cursor();
+ if (unindent) {
+ _remove_text(cursor.line, cursor.column - indent_size, cursor.line, cursor.column);
+ cursor_set_column(cursor.column - indent_size);
+ }
+ }
+ }
}
} else {
//simple indent
- _insert_text_at_cursor("\t");
+ if (indent_using_spaces) {
+ _insert_text_at_cursor(space_indent);
+ } else {
+ _insert_text_at_cursor("\t");
+ }
}
}
@@ -3103,7 +3181,7 @@ int TextEdit::get_char_pos_for(int p_px, String p_str) const {
int px = 0;
int c = 0;
- int tab_w = cache.font->get_char_size(' ').width * tab_size;
+ int tab_w = cache.font->get_char_size(' ').width * indent_size;
while (c < p_str.length()) {
@@ -3135,7 +3213,7 @@ int TextEdit::get_column_x_offset(int p_char, String p_str) {
int px = 0;
- int tab_w = cache.font->get_char_size(' ').width * tab_size;
+ int tab_w = cache.font->get_char_size(' ').width * indent_size;
for (int i = 0; i < p_char; i++) {
@@ -3952,10 +4030,24 @@ void TextEdit::_push_current_op() {
current_op.chain_forward = false;
}
-void TextEdit::set_tab_size(const int p_size) {
+void TextEdit::set_indent_using_spaces(const bool p_use_spaces) {
+ indent_using_spaces = p_use_spaces;
+}
+
+bool TextEdit::is_indent_using_spaces() const {
+ return indent_using_spaces;
+}
+
+void TextEdit::set_indent_size(const int p_size) {
ERR_FAIL_COND(p_size <= 0);
- tab_size = p_size;
- text.set_tab_size(p_size);
+ indent_size = p_size;
+ text.set_indent_size(p_size);
+
+ space_indent = "";
+ for (int i = 0; i < p_size; i++) {
+ space_indent += " ";
+ }
+
update();
}
@@ -4448,8 +4540,8 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_text"), &TextEdit::get_text);
ClassDB::bind_method(D_METHOD("get_line", "line"), &TextEdit::get_line);
- ClassDB::bind_method(D_METHOD("cursor_set_column", "column", "adjust_viewport"), &TextEdit::cursor_set_column, DEFVAL(false));
- ClassDB::bind_method(D_METHOD("cursor_set_line", "line", "adjust_viewport"), &TextEdit::cursor_set_line, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("cursor_set_column", "column", "adjust_viewport"), &TextEdit::cursor_set_column, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("cursor_set_line", "line", "adjust_viewport"), &TextEdit::cursor_set_line, DEFVAL(true));
ClassDB::bind_method(D_METHOD("cursor_get_column"), &TextEdit::cursor_get_column);
ClassDB::bind_method(D_METHOD("cursor_get_line"), &TextEdit::cursor_get_line);
@@ -4542,8 +4634,8 @@ TextEdit::TextEdit() {
cache.breakpoint_gutter_width = 0;
breakpoint_gutter_width = 0;
- tab_size = 4;
- text.set_tab_size(tab_size);
+ indent_size = 4;
+ text.set_indent_size(indent_size);
text.clear();
//text.insert(1,"Mongolia..");
//text.insert(2,"PAIS GENEROSO!!");
@@ -4631,6 +4723,8 @@ TextEdit::TextEdit() {
auto_brace_completion_enabled = false;
brace_matching_enabled = false;
highlight_all_occurrences = false;
+ indent_using_spaces = false;
+ space_indent = " ";
auto_indent = false;
insert_mode = false;
window_has_focus = true;
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index d5fe2950f4..905ea46bd7 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -141,12 +141,12 @@ class TextEdit : public Control {
const Vector<ColorRegion> *color_regions;
mutable Vector<Line> text;
Ref<Font> font;
- int tab_size;
+ int indent_size;
void _update_line_cache(int p_line) const;
public:
- void set_tab_size(int p_tab_size);
+ void set_indent_size(int p_indent_size);
void set_font(const Ref<Font> &p_font);
void set_color_regions(const Vector<ColorRegion> *p_regions) { color_regions = p_regions; }
int get_line_width(int p_line) const;
@@ -163,7 +163,7 @@ class TextEdit : public Control {
void clear();
void clear_caches();
_FORCE_INLINE_ const String &operator[](int p_line) const { return text[p_line].data; }
- Text() { tab_size = 4; }
+ Text() { indent_size = 4; }
};
struct TextOperation {
@@ -221,7 +221,9 @@ class TextEdit : public Control {
int max_chars;
bool readonly;
bool syntax_coloring;
- int tab_size;
+ bool indent_using_spaces;
+ int indent_size;
+ String space_indent;
Timer *caret_blink_timer;
bool caret_blink_enabled;
@@ -461,7 +463,9 @@ public:
void redo();
void clear_undo_history();
- void set_tab_size(const int p_size);
+ void set_indent_using_spaces(const bool p_use_spaces);
+ bool is_indent_using_spaces() const;
+ void set_indent_size(const int p_size);
void set_draw_tabs(bool p_draw);
bool is_drawing_tabs() const;
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index 783afc8b58..a9b2dba186 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.cpp
@@ -29,6 +29,8 @@
/*************************************************************************/
#include "http_request.h"
+#include "version.h"
+
void HTTPRequest::_redirect_request(const String &p_new_url) {
}
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index cebec379e6..545c700354 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -1761,8 +1761,8 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons
Vector3 v02, v01;
real_t a02, a01;
- r02.get_axis_and_angle(v02, a02);
- r01.get_axis_and_angle(v01, a01);
+ r02.get_axis_angle(v02, a02);
+ r01.get_axis_angle(v01, a01);
if (Math::abs(a02) > p_max_optimizable_angle)
return false;
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index d7c44e0363..3a824a56a3 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -532,10 +532,8 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref<
// WindowDialog
- Ref<StyleBoxTexture> style_pp_win = sb_expand(make_stylebox(popup_window_png, 10, 26, 10, 8), 8, 24, 8, 6);
- t->set_stylebox("panel", "WindowDialog", style_pp_win);
- t->set_constant("titlebar_height", "WindowDialog", 20 * scale);
- t->set_constant("scaleborder_size", "WindowDialog", 4);
+ t->set_stylebox("panel", "WindowDialog", sb_expand(make_stylebox(popup_window_png, 10, 26, 10, 8), 8, 24, 8, 6));
+ t->set_constant("scaleborder_size", "WindowDialog", 4 * scale);
t->set_font("title_font", "WindowDialog", large_font);
t->set_color("title_color", "WindowDialog", Color(0, 0, 0));
diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp
index 35158806ca..13529c8572 100644
--- a/scene/resources/style_box.cpp
+++ b/scene/resources/style_box.cpp
@@ -138,6 +138,11 @@ void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const {
texture->get_rect_region(rect, src_rect, rect, src_rect);
+ rect.pos.x -= expand_margin[MARGIN_LEFT];
+ rect.pos.y -= expand_margin[MARGIN_TOP];
+ rect.size.x += expand_margin[MARGIN_LEFT] + expand_margin[MARGIN_RIGHT];
+ rect.size.y += expand_margin[MARGIN_TOP] + expand_margin[MARGIN_BOTTOM];
+
VisualServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, draw_center, modulate);
}
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index 0889306bad..f0ac30a76e 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -459,25 +459,27 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &fla
flags = f->get_32(); //texture flags!
uint32_t df = f->get_32(); //data format
+ /*
print_line("width: " + itos(tw));
print_line("height: " + itos(th));
print_line("flags: " + itos(flags));
print_line("df: " + itos(df));
+ */
if (request_3d_callback && df & FORMAT_BIT_DETECT_3D) {
- print_line("request detect 3D at " + p_path);
+ //print_line("request detect 3D at " + p_path);
VS::get_singleton()->texture_set_detect_3d_callback(texture, _requested_3d, this);
} else {
- print_line("not requesting detect 3D at " + p_path);
+ //print_line("not requesting detect 3D at " + p_path);
VS::get_singleton()->texture_set_detect_3d_callback(texture, NULL, NULL);
}
if (request_srgb_callback && df & FORMAT_BIT_DETECT_SRGB) {
- print_line("request detect srgb at " + p_path);
+ //print_line("request detect srgb at " + p_path);
VS::get_singleton()->texture_set_detect_srgb_callback(texture, _requested_srgb, this);
} else {
+ //print_line("not requesting detect srgb at " + p_path);
VS::get_singleton()->texture_set_detect_srgb_callback(texture, NULL, NULL);
- print_line("not requesting detect srgb at " + p_path);
}
if (!(df & FORMAT_BIT_STREAM)) {
@@ -493,7 +495,7 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &fla
uint32_t mipmaps = f->get_32();
uint32_t size = f->get_32();
- print_line("mipmaps: " + itos(mipmaps));
+ //print_line("mipmaps: " + itos(mipmaps));
while (mipmaps > 1 && p_size_limit > 0 && (sw > p_size_limit || sh > p_size_limit)) {
@@ -539,7 +541,7 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &fla
mipmap_images.push_back(img);
}
- print_line("mipmap read total: " + itos(mipmap_images.size()));
+ //print_line("mipmap read total: " + itos(mipmap_images.size()));
memdelete(f); //no longer needed
@@ -626,7 +628,7 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &fla
{
PoolVector<uint8_t>::Write w = img_data.write();
int bytes = f->get_buffer(w.ptr(), total_size - ofs);
- print_line("requested read: " + itos(total_size - ofs) + " but got: " + itos(bytes));
+ //print_line("requested read: " + itos(total_size - ofs) + " but got: " + itos(bytes));
memdelete(f);