diff options
-rw-r--r-- | doc/classes/BitMap.xml | 13 | ||||
-rw-r--r-- | platform/linuxbsd/os_linuxbsd.cpp | 8 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 8 | ||||
-rw-r--r-- | scene/resources/bit_map.cpp | 2 | ||||
-rw-r--r-- | scene/resources/mesh_library.cpp | 33 |
5 files changed, 51 insertions, 13 deletions
diff --git a/doc/classes/BitMap.xml b/doc/classes/BitMap.xml index dc655ee3b0..ebcdcab75e 100644 --- a/doc/classes/BitMap.xml +++ b/doc/classes/BitMap.xml @@ -9,6 +9,12 @@ <tutorials> </tutorials> <methods> + <method name="convert_to_image" qualifiers="const"> + <return type="Image" /> + <description> + Returns an image of the same size as the bitmap and with a [enum Image.Format] of type [code]FORMAT_L8[/code]. [code]true[/code] bits of the bitmap are being converted into white pixels, and [code]false[/code] bits into black. + </description> + </method> <method name="create"> <return type="void" /> <argument index="0" name="size" type="Vector2" /> @@ -64,6 +70,13 @@ [code]epsilon[/code] is passed to RDP to control how accurately the polygons cover the bitmap: a lower [code]epsilon[/code] corresponds to more points in the polygons. </description> </method> + <method name="resize"> + <return type="void" /> + <argument index="0" name="new_size" type="Vector2" /> + <description> + Resizes the image to [code]new_size[/code]. + </description> + </method> <method name="set_bit"> <return type="void" /> <argument index="0" name="position" type="Vector2" /> diff --git a/platform/linuxbsd/os_linuxbsd.cpp b/platform/linuxbsd/os_linuxbsd.cpp index b5f127bb16..e95a865636 100644 --- a/platform/linuxbsd/os_linuxbsd.cpp +++ b/platform/linuxbsd/os_linuxbsd.cpp @@ -448,7 +448,7 @@ Error OS_LinuxBSD::move_to_trash(const String &p_path) { // Create needed directories for decided trash can location. { - DirAccess *dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + DirAccessRef dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); Error err = dir_access->make_dir_recursive(trash_path); // Issue an error if trash can is not created properly. @@ -457,7 +457,6 @@ Error OS_LinuxBSD::move_to_trash(const String &p_path) { ERR_FAIL_COND_V_MSG(err != OK, err, "Could not create the trash path \"" + trash_path + "\"/files"); err = dir_access->make_dir_recursive(trash_path + "/info"); ERR_FAIL_COND_V_MSG(err != OK, err, "Could not create the trash path \"" + trash_path + "\"/info"); - memdelete(dir_access); } // The trash can is successfully created, now we check that we don't exceed our file name length limit. @@ -497,16 +496,15 @@ Error OS_LinuxBSD::move_to_trash(const String &p_path) { String trash_info = "[Trash Info]\nPath=" + p_path.uri_encode() + "\nDeletionDate=" + timestamp + "\n"; { Error err; - FileAccess *file = FileAccess::open(trash_path + "/info/" + file_name + ".trashinfo", FileAccess::WRITE, &err); + FileAccessRef file = FileAccess::open(trash_path + "/info/" + file_name + ".trashinfo", FileAccess::WRITE, &err); ERR_FAIL_COND_V_MSG(err != OK, err, "Can't create trashinfo file:" + trash_path + "/info/" + file_name + ".trashinfo"); file->store_string(trash_info); file->close(); // Rename our resource before moving it to the trash can. - DirAccess *dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + DirAccessRef dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); err = dir_access->rename(p_path, p_path.get_base_dir() + "/" + file_name); ERR_FAIL_COND_V_MSG(err != OK, err, "Can't rename file \"" + p_path + "\""); - memdelete(dir_access); } // Move the given resource to the trash can. diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index fe1aaab557..7db1fae2b6 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -650,7 +650,7 @@ void TextEdit::_notification(int p_what) { } } - bool draw_placeholder = text[0].length() == 0; + bool draw_placeholder = text.size() == 1 && text[0].length() == 0; // Get the highlighted words. String highlighted_text = get_selected_text(); @@ -6020,7 +6020,7 @@ void TextEdit::_update_scrollbars() { h_scroll->set_begin(Point2(0, size.height - hmin.height)); h_scroll->set_end(Point2(size.width - vmin.width, size.height)); - bool draw_placeholder = text[0].length() == 0; + bool draw_placeholder = text.size() == 1 && text[0].length() == 0; int visible_rows = get_visible_line_count(); int total_rows = draw_placeholder ? placeholder_wraped_rows.size() - 1 : get_total_visible_line_count(); @@ -6101,7 +6101,7 @@ void TextEdit::_scroll_moved(double p_to_val) { } if (v_scroll->is_visible_in_tree()) { // Set line ofs and wrap ofs. - bool draw_placeholder = text[0].length() == 0; + bool draw_placeholder = text.size() == 1 && text[0].length() == 0; int v_scroll_i = floor(get_v_scroll()); int sc = 0; @@ -6116,7 +6116,7 @@ void TextEdit::_scroll_moved(double p_to_val) { } } n_line = MIN(n_line, text.size() - 1); - int line_wrap_amount = (text[0].length() == 0) ? placeholder_wraped_rows.size() - 1 : get_line_wrap_count(n_line); + int line_wrap_amount = draw_placeholder ? placeholder_wraped_rows.size() - 1 : get_line_wrap_count(n_line); int wi = line_wrap_amount - (sc - v_scroll_i - 1); wi = CLAMP(wi, 0, line_wrap_amount); diff --git a/scene/resources/bit_map.cpp b/scene/resources/bit_map.cpp index 25f169b6a2..c2988c2e8c 100644 --- a/scene/resources/bit_map.cpp +++ b/scene/resources/bit_map.cpp @@ -667,11 +667,13 @@ void BitMap::_bind_methods() { ClassDB::bind_method(D_METHOD("get_true_bit_count"), &BitMap::get_true_bit_count); ClassDB::bind_method(D_METHOD("get_size"), &BitMap::get_size); + ClassDB::bind_method(D_METHOD("resize", "new_size"), &BitMap::resize); ClassDB::bind_method(D_METHOD("_set_data"), &BitMap::_set_data); ClassDB::bind_method(D_METHOD("_get_data"), &BitMap::_get_data); ClassDB::bind_method(D_METHOD("grow_mask", "pixels", "rect"), &BitMap::grow_mask); + ClassDB::bind_method(D_METHOD("convert_to_image"), &BitMap::convert_to_image); ClassDB::bind_method(D_METHOD("opaque_to_polygons", "rect", "epsilon"), &BitMap::_opaque_to_polygons_bind, DEFVAL(2.0)); ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data"); diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp index 3db839a1d0..5168bf83eb 100644 --- a/scene/resources/mesh_library.cpp +++ b/scene/resources/mesh_library.cpp @@ -30,6 +30,8 @@ #include "mesh_library.h" +#include "box_shape_3d.h" + bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (name.begins_with("item/")) { @@ -255,12 +257,35 @@ int MeshLibrary::get_last_unused_item_id() const { } void MeshLibrary::_set_item_shapes(int p_item, const Array &p_shapes) { - ERR_FAIL_COND(p_shapes.size() & 1); + Array arr_shapes = p_shapes; + int size = p_shapes.size(); + if (size & 1) { + ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); + int prev_size = item_map[p_item].shapes.size() * 2; + + if (prev_size < size) { + // Check if last element is a shape. + Ref<Shape3D> shape = arr_shapes[size - 1]; + if (shape.is_null()) { + Ref<BoxShape3D> box_shape; + box_shape.instantiate(); + arr_shapes[size - 1] = box_shape; + } + + // Make sure the added element is a Transform3D. + arr_shapes.push_back(Transform3D()); + size++; + } else { + size--; + arr_shapes.resize(size); + } + } + Vector<ShapeData> shapes; - for (int i = 0; i < p_shapes.size(); i += 2) { + for (int i = 0; i < size; i += 2) { ShapeData sd; - sd.shape = p_shapes[i + 0]; - sd.local_transform = p_shapes[i + 1]; + sd.shape = arr_shapes[i + 0]; + sd.local_transform = arr_shapes[i + 1]; if (sd.shape.is_valid()) { shapes.push_back(sd); |