diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/canvas_group.cpp | 87 | ||||
-rw-r--r-- | scene/2d/canvas_group.h | 59 | ||||
-rw-r--r-- | scene/main/canvas_item.cpp | 22 | ||||
-rw-r--r-- | scene/main/canvas_item.h | 4 | ||||
-rw-r--r-- | scene/register_scene_types.cpp | 2 | ||||
-rw-r--r-- | scene/resources/dynamic_font.cpp | 15 |
6 files changed, 187 insertions, 2 deletions
diff --git a/scene/2d/canvas_group.cpp b/scene/2d/canvas_group.cpp new file mode 100644 index 0000000000..39cae8e0c6 --- /dev/null +++ b/scene/2d/canvas_group.cpp @@ -0,0 +1,87 @@ +/*************************************************************************/ +/* canvas_group.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "canvas_group.h" + +void CanvasGroup::set_fit_margin(float p_fit_margin) { + ERR_FAIL_COND(p_fit_margin < 0.0); + + fit_margin = p_fit_margin; + RS::get_singleton()->canvas_item_set_canvas_group_mode(get_canvas_item(), RS::CANVAS_GROUP_MODE_TRANSPARENT, clear_margin, true, fit_margin, use_mipmaps); + + update(); +} + +float CanvasGroup::get_fit_margin() const { + return fit_margin; +} + +void CanvasGroup::set_clear_margin(float p_clear_margin) { + ERR_FAIL_COND(p_clear_margin < 0.0); + + clear_margin = p_clear_margin; + RS::get_singleton()->canvas_item_set_canvas_group_mode(get_canvas_item(), RS::CANVAS_GROUP_MODE_TRANSPARENT, clear_margin, true, clear_margin, use_mipmaps); + + update(); +} + +float CanvasGroup::get_clear_margin() const { + return clear_margin; +} + +void CanvasGroup::set_use_mipmaps(bool p_use_mipmaps) { + use_mipmaps = p_use_mipmaps; + RS::get_singleton()->canvas_item_set_canvas_group_mode(get_canvas_item(), RS::CANVAS_GROUP_MODE_TRANSPARENT, clear_margin, true, fit_margin, use_mipmaps); +} +bool CanvasGroup::is_using_mipmaps() const { + return use_mipmaps; +} + +void CanvasGroup::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_fit_margin", "fit_margin"), &CanvasGroup::set_fit_margin); + ClassDB::bind_method(D_METHOD("get_fit_margin"), &CanvasGroup::get_fit_margin); + + ClassDB::bind_method(D_METHOD("set_clear_margin", "clear_margin"), &CanvasGroup::set_clear_margin); + ClassDB::bind_method(D_METHOD("get_clear_margin"), &CanvasGroup::get_clear_margin); + + ClassDB::bind_method(D_METHOD("set_use_mipmaps", "use_mipmaps"), &CanvasGroup::set_use_mipmaps); + ClassDB::bind_method(D_METHOD("is_using_mipmaps"), &CanvasGroup::is_using_mipmaps); + + ADD_GROUP("Tweaks", ""); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fit_margin", PROPERTY_HINT_RANGE, "0,1024,1.0,or_greater"), "set_fit_margin", "get_fit_margin"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "clear_margin", PROPERTY_HINT_RANGE, "0,1024,1.0,or_greater"), "set_clear_margin", "get_clear_margin"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_mipmaps"), "set_use_mipmaps", "is_using_mipmaps"); +} + +CanvasGroup::CanvasGroup() { + set_fit_margin(10.0); //sets things +} +CanvasGroup::~CanvasGroup() { +} diff --git a/scene/2d/canvas_group.h b/scene/2d/canvas_group.h new file mode 100644 index 0000000000..19630befc7 --- /dev/null +++ b/scene/2d/canvas_group.h @@ -0,0 +1,59 @@ +/*************************************************************************/ +/* canvas_group.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef CANVASGROUP_H +#define CANVASGROUP_H + +#include "scene/2d/node_2d.h" + +class CanvasGroup : public Node2D { + GDCLASS(CanvasGroup, Node2D) + float fit_margin = 10.0; + float clear_margin = 10.0; + bool use_mipmaps = false; + +protected: + static void _bind_methods(); + +public: + void set_fit_margin(float p_fit_margin); + float get_fit_margin() const; + + void set_clear_margin(float p_clear_margin); + float get_clear_margin() const; + + void set_use_mipmaps(bool p_use_mipmaps); + bool is_using_mipmaps() const; + + CanvasGroup(); + ~CanvasGroup(); +}; + +#endif // CANVASGROUP_H diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index 6323b55378..740374d09e 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -32,6 +32,7 @@ #include "core/input/input.h" #include "core/message_queue.h" +#include "scene/2d/canvas_group.h" #include "scene/main/canvas_layer.h" #include "scene/main/viewport.h" #include "scene/main/window.h" @@ -1199,6 +1200,9 @@ void CanvasItem::_bind_methods() { ClassDB::bind_method(D_METHOD("set_texture_repeat", "mode"), &CanvasItem::set_texture_repeat); ClassDB::bind_method(D_METHOD("get_texture_repeat"), &CanvasItem::get_texture_repeat); + ClassDB::bind_method(D_METHOD("set_clip_children", "enable"), &CanvasItem::set_clip_children); + ClassDB::bind_method(D_METHOD("is_clipping_children"), &CanvasItem::is_clipping_children); + BIND_VMETHOD(MethodInfo("_draw")); ADD_GROUP("Visibility", ""); @@ -1208,6 +1212,7 @@ void CanvasItem::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_behind_parent"), "set_draw_behind_parent", "is_draw_behind_parent_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "top_level"), "set_as_top_level", "is_set_as_top_level"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_on_top", PROPERTY_HINT_NONE, "", 0), "_set_on_top", "_is_on_top"); //compatibility + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_children"), "set_clip_children", "is_clipping_children"); ADD_PROPERTY(PropertyInfo(Variant::INT, "light_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_light_mask", "get_light_mask"); ADD_GROUP("Texture", "texture_"); @@ -1383,6 +1388,22 @@ void CanvasItem::set_texture_repeat(TextureRepeat p_texture_repeat) { _change_notify(); } +void CanvasItem::set_clip_children(bool p_enabled) { + if (clip_children == p_enabled) { + return; + } + clip_children = p_enabled; + + if (Object::cast_to<CanvasGroup>(this) != nullptr) { + //avoid accidental bugs, make this not work on CanvasGroup + return; + } + RS::get_singleton()->canvas_item_set_canvas_group_mode(get_canvas_item(), clip_children ? RS::CANVAS_GROUP_MODE_OPAQUE : RS::CANVAS_GROUP_MODE_DISABLED); +} +bool CanvasItem::is_clipping_children() const { + return clip_children; +} + CanvasItem::TextureRepeat CanvasItem::get_texture_repeat() const { return texture_repeat; } @@ -1399,6 +1420,7 @@ CanvasItem::CanvasItem() : first_draw = false; drawing = false; behind = false; + clip_children = false; block_transform_notify = false; canvas_layer = nullptr; use_parent_material = false; diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h index 092fd17df3..412ef8079b 100644 --- a/scene/main/canvas_item.h +++ b/scene/main/canvas_item.h @@ -200,6 +200,7 @@ private: Window *window; bool first_draw; bool visible; + bool clip_children; bool pending_update; bool top_level; bool drawing; @@ -315,6 +316,9 @@ public: void update(); + void set_clip_children(bool p_enabled); + bool is_clipping_children() const; + virtual void set_light_mask(int p_light_mask); int get_light_mask() const; diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 76b68c8da8..f1dcc8e8a5 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -38,6 +38,7 @@ #include "scene/2d/audio_stream_player_2d.h" #include "scene/2d/back_buffer_copy.h" #include "scene/2d/camera_2d.h" +#include "scene/2d/canvas_group.h" #include "scene/2d/canvas_modulate.h" #include "scene/2d/collision_polygon_2d.h" #include "scene/2d/collision_shape_2d.h" @@ -602,6 +603,7 @@ void register_scene_types() { /* REGISTER 2D */ ClassDB::register_class<Node2D>(); + ClassDB::register_class<CanvasGroup>(); ClassDB::register_class<CPUParticles2D>(); ClassDB::register_class<GPUParticles2D>(); ClassDB::register_class<Sprite2D>(); diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index ad9d888480..a0ce6e1194 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -458,8 +458,19 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp //zero texture uint8_t *w = tex.imgdata.ptrw(); ERR_FAIL_COND_V(texsize * texsize * p_color_size > tex.imgdata.size(), ret); - for (int i = 0; i < texsize * texsize * p_color_size; i++) { - w[i] = 0; + + if (p_color_size == 2) { + for (int i = 0; i < texsize * texsize * p_color_size; i += 2) { + w[i + 0] = 255; + w[i + 1] = 0; + } + } else { + for (int i = 0; i < texsize * texsize * p_color_size; i += 4) { + w[i + 0] = 255; + w[i + 1] = 255; + w[i + 2] = 255; + w[i + 3] = 0; + } } } tex.offsets.resize(texsize); |