diff options
-rw-r--r-- | SConstruct | 15 | ||||
-rw-r--r-- | doc/classes/DynamicFontData.xml | 2 | ||||
-rw-r--r-- | doc/classes/RichTextLabel.xml | 4 | ||||
-rw-r--r-- | drivers/vulkan/rendering_device_vulkan.cpp | 13 | ||||
-rw-r--r-- | drivers/vulkan/rendering_device_vulkan.h | 167 | ||||
-rw-r--r-- | drivers/vulkan/vulkan_context.h | 30 | ||||
-rw-r--r-- | editor/project_manager.cpp | 6 | ||||
-rw-r--r-- | methods.py | 24 | ||||
-rw-r--r-- | modules/opus/config.py | 2 | ||||
-rw-r--r-- | modules/theora/config.py | 2 | ||||
-rw-r--r-- | modules/vorbis/config.py | 2 | ||||
-rw-r--r-- | modules/webm/config.py | 5 | ||||
-rw-r--r-- | scene/gui/rich_text_label.cpp | 299 | ||||
-rw-r--r-- | scene/gui/rich_text_label.h | 5 | ||||
-rw-r--r-- | scene/resources/dynamic_font.cpp | 2 |
15 files changed, 271 insertions, 307 deletions
diff --git a/SConstruct b/SConstruct index 27e6c5f2d3..b424363dc8 100644 --- a/SConstruct +++ b/SConstruct @@ -86,6 +86,7 @@ env_base.__class__.add_library = methods.add_library env_base.__class__.add_program = methods.add_program env_base.__class__.CommandNoCache = methods.CommandNoCache env_base.__class__.disable_warnings = methods.disable_warnings +env_base.__class__.module_check_dependencies = methods.module_check_dependencies env_base["x86_libtheora_opt_gcc"] = False env_base["x86_libtheora_opt_vc"] = False @@ -607,14 +608,12 @@ if selected_platform in platform_list: env.Append(CPPDEFINES=["MINIZIP_ENABLED"]) editor_module_list = ["regex"] - for x in editor_module_list: - if not env["module_" + x + "_enabled"]: - if env["tools"]: - print( - "Build option 'module_" + x + "_enabled=no' cannot be used with 'tools=yes' (editor), " - "only with 'tools=no' (export template)." - ) - Exit(255) + if env["tools"] and not env.module_check_dependencies("tools", editor_module_list): + print( + "Build option 'module_" + x + "_enabled=no' cannot be used with 'tools=yes' (editor), " + "only with 'tools=no' (export template)." + ) + Exit(255) if not env["verbose"]: methods.no_verbose(sys, env) diff --git a/doc/classes/DynamicFontData.xml b/doc/classes/DynamicFontData.xml index 2b4ec17bf1..483da96f3f 100644 --- a/doc/classes/DynamicFontData.xml +++ b/doc/classes/DynamicFontData.xml @@ -12,7 +12,7 @@ </methods> <members> <member name="antialiased" type="bool" setter="set_antialiased" getter="is_antialiased" default="true"> - If [code]true[/code], the font is rendered with anti-aliasing. + If [code]true[/code], the font is rendered with anti-aliasing. This property applies both to the main font and its outline (if it has one). </member> <member name="font_path" type="String" setter="set_font_path" getter="get_font_path" default=""""> The path to the vector font file. diff --git a/doc/classes/RichTextLabel.xml b/doc/classes/RichTextLabel.xml index efc0c9d600..db036d7d88 100644 --- a/doc/classes/RichTextLabel.xml +++ b/doc/classes/RichTextLabel.xml @@ -20,8 +20,10 @@ </argument> <argument index="2" name="height" type="int" default="0"> </argument> + <argument index="3" name="color" type="Color" default="Color( 1, 1, 1, 1 )"> + </argument> <description> - Adds an image's opening and closing tags to the tag stack, optionally providing a [code]width[/code] and [code]height[/code] to resize the image. + Adds an image's opening and closing tags to the tag stack, optionally providing a [code]width[/code] and [code]height[/code] to resize the image and a [code]color[/code] to tint the image. If [code]width[/code] or [code]height[/code] is set to 0, the image size will be adjusted in order to keep the original aspect ratio. </description> </method> diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp index efd4f057fd..c9e78678a8 100644 --- a/drivers/vulkan/rendering_device_vulkan.cpp +++ b/drivers/vulkan/rendering_device_vulkan.cpp @@ -35,6 +35,7 @@ #include "core/os/os.h" #include "core/project_settings.h" #include "drivers/vulkan/vulkan_context.h" + #include "thirdparty/spirv-reflect/spirv_reflect.h" //#define FORCE_FULL_BARRIER @@ -5905,7 +5906,7 @@ void RenderingDeviceVulkan::draw_list_bind_render_pipeline(DrawListID p_list, RI if (pipeline->push_constant_size) { dl->state.pipeline_push_constant_stages = pipeline->push_constant_stages; #ifdef DEBUG_ENABLED - dl->validation.pipeline_push_constant_suppplied = false; + dl->validation.pipeline_push_constant_supplied = false; #endif } @@ -6036,7 +6037,7 @@ void RenderingDeviceVulkan::draw_list_set_push_constant(DrawListID p_list, const #endif vkCmdPushConstants(dl->command_buffer, dl->state.pipeline_layout, dl->state.pipeline_push_constant_stages, 0, p_data_size, p_data); #ifdef DEBUG_ENABLED - dl->validation.pipeline_push_constant_suppplied = true; + dl->validation.pipeline_push_constant_supplied = true; #endif } @@ -6064,7 +6065,7 @@ void RenderingDeviceVulkan::draw_list_draw(DrawListID p_list, bool p_use_indices if (dl->validation.pipeline_push_constant_size > 0) { //using push constants, check that they were supplied - ERR_FAIL_COND_MSG(!dl->validation.pipeline_push_constant_suppplied, + ERR_FAIL_COND_MSG(!dl->validation.pipeline_push_constant_supplied, "The shader in this pipeline requires a push constant to be set before drawing, but it's not present."); } @@ -6300,7 +6301,7 @@ void RenderingDeviceVulkan::compute_list_bind_compute_pipeline(ComputeListID p_l if (pipeline->push_constant_size) { cl->state.pipeline_push_constant_stages = pipeline->push_constant_stages; #ifdef DEBUG_ENABLED - cl->validation.pipeline_push_constant_suppplied = false; + cl->validation.pipeline_push_constant_supplied = false; #endif } @@ -6433,7 +6434,7 @@ void RenderingDeviceVulkan::compute_list_set_push_constant(ComputeListID p_list, #endif vkCmdPushConstants(cl->command_buffer, cl->state.pipeline_layout, cl->state.pipeline_push_constant_stages, 0, p_data_size, p_data); #ifdef DEBUG_ENABLED - cl->validation.pipeline_push_constant_suppplied = true; + cl->validation.pipeline_push_constant_supplied = true; #endif } @@ -6460,7 +6461,7 @@ void RenderingDeviceVulkan::compute_list_dispatch(ComputeListID p_list, uint32_t if (cl->validation.pipeline_push_constant_size > 0) { //using push constants, check that they were supplied - ERR_FAIL_COND_MSG(!cl->validation.pipeline_push_constant_suppplied, + ERR_FAIL_COND_MSG(!cl->validation.pipeline_push_constant_supplied, "The shader in this pipeline requires a push constant to be set before drawing, but it's not present."); } diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h index 6b75154a8d..eac3250bf7 100644 --- a/drivers/vulkan/rendering_device_vulkan.h +++ b/drivers/vulkan/rendering_device_vulkan.h @@ -42,7 +42,9 @@ #endif #endif #include "vk_mem_alloc.h" + #include <vulkan/vulkan.h> + //todo: //compute //push constants @@ -202,15 +204,10 @@ class RenderingDeviceVulkan : public RenderingDevice { Error _insert_staging_block(); struct Buffer { - uint32_t size; - VkBuffer buffer; - VmaAllocation allocation; + uint32_t size = 0; + VkBuffer buffer = VK_NULL_HANDLE; + VmaAllocation allocation = nullptr; VkDescriptorBufferInfo buffer_info; //used for binding - Buffer() { - size = 0; - buffer = VK_NULL_HANDLE; - allocation = nullptr; - } }; Error _buffer_allocate(Buffer *p_buffer, uint32_t p_size, uint32_t p_usage, VmaMemoryUsage p_mapping); @@ -570,7 +567,7 @@ class RenderingDeviceVulkan : public RenderingDevice { struct DescriptorPoolKey { union { struct { - uint16_t uniform_type[UNIFORM_TYPE_MAX]; //using 16 bits because, for sending arrays, each element is a pool set. + uint16_t uniform_type[UNIFORM_TYPE_MAX]; // Using 16 bits because, for sending arrays, each element is a pool set. }; struct { uint64_t key1; @@ -712,106 +709,67 @@ class RenderingDeviceVulkan : public RenderingDevice { Vector<SplitDrawListAllocator> split_draw_list_allocators; struct DrawList { - VkCommandBuffer command_buffer; //if persistent, this is owned, otherwise it's shared with the ringbuffer + VkCommandBuffer command_buffer; // If persistent, this is owned, otherwise it's shared with the ringbuffer. Rect2i viewport; struct SetState { - uint32_t pipeline_expected_format; - uint32_t uniform_set_format; - VkDescriptorSet descriptor_set; + uint32_t pipeline_expected_format = 0; + uint32_t uniform_set_format = 0; + VkDescriptorSet descriptor_set = VK_NULL_HANDLE; RID uniform_set; - bool bound; - SetState() { - bound = false; - pipeline_expected_format = 0; - uniform_set_format = 0; - descriptor_set = VK_NULL_HANDLE; - } + bool bound = false; }; struct State { SetState sets[MAX_UNIFORM_SETS]; - uint32_t set_count; + uint32_t set_count = 0; RID pipeline; RID pipeline_shader; - VkPipelineLayout pipeline_layout; + VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; RID vertex_array; RID index_array; - uint32_t pipeline_push_constant_stages; - - State() { - set_count = 0; - pipeline_layout = VK_NULL_HANDLE; - pipeline_push_constant_stages = 0; - } + uint32_t pipeline_push_constant_stages = 0; } state; -#ifdef DEBUG_ENABLED +#ifdef DEBUG_ENABLED struct Validation { - bool active; //means command buffer was not closes, so you can keep adding things - FramebufferFormatID framebuffer_format; - //actual render pass values - uint32_t dynamic_state; - VertexFormatID vertex_format; //INVALID_ID if not set - uint32_t vertex_array_size; //0 if not set - uint32_t vertex_max_instances_allowed; - bool index_buffer_uses_restart_indices; - uint32_t index_array_size; //0 if index buffer not set - uint32_t index_array_max_index; + bool active = true; // Means command buffer was not closed, so you can keep adding things. + FramebufferFormatID framebuffer_format = INVALID_ID; + // Actual render pass values. + uint32_t dynamic_state = 0; + VertexFormatID vertex_format = INVALID_ID; + uint32_t vertex_array_size = 0; + uint32_t vertex_max_instances_allowed = 0xFFFFFFFF; + bool index_buffer_uses_restart_indices = false; + uint32_t index_array_size = 0; + uint32_t index_array_max_index = 0; uint32_t index_array_offset; Vector<uint32_t> set_formats; Vector<bool> set_bound; Vector<RID> set_rids; - //last pipeline set values - bool pipeline_active; - uint32_t pipeline_dynamic_state; - VertexFormatID pipeline_vertex_format; + // Last pipeline set values. + bool pipeline_active = false; + uint32_t pipeline_dynamic_state = 0; + VertexFormatID pipeline_vertex_format = INVALID_ID; RID pipeline_shader; - uint32_t invalid_set_from; - bool pipeline_uses_restart_indices; + uint32_t invalid_set_from = 0; + bool pipeline_uses_restart_indices = false; uint32_t pipeline_primitive_divisor; uint32_t pipeline_primitive_minimum; Vector<uint32_t> pipeline_set_formats; - uint32_t pipeline_push_constant_size; - bool pipeline_push_constant_suppplied; - - Validation() { - active = true; - dynamic_state = 0; - vertex_format = INVALID_ID; - vertex_array_size = 0; - vertex_max_instances_allowed = 0xFFFFFFFF; - framebuffer_format = INVALID_ID; - index_array_size = 0; //not sent - index_array_max_index = 0; //not set - index_buffer_uses_restart_indices = false; - invalid_set_from = 0; - - //pipeline state initalize - pipeline_active = false; - pipeline_dynamic_state = 0; - pipeline_vertex_format = INVALID_ID; - pipeline_uses_restart_indices = false; - pipeline_push_constant_size = 0; - pipeline_push_constant_suppplied = false; - } + uint32_t pipeline_push_constant_size = 0; + bool pipeline_push_constant_supplied = false; } validation; #else struct Validation { - uint32_t vertex_array_size; //0 if not set - uint32_t index_array_size; //0 if index buffer not set + uint32_t vertex_array_size = 0; + uint32_t index_array_size = 0; uint32_t index_array_offset; - - Validation() { - vertex_array_size = 0; - index_array_size = 0; //not sent - } } validation; - #endif }; - DrawList *draw_list; //one for regular draw lists, multiple for split. + DrawList *draw_list; // One for regular draw lists, multiple for split. uint32_t draw_list_count; bool draw_list_split; Vector<RID> draw_list_bound_textures; @@ -828,62 +786,39 @@ class RenderingDeviceVulkan : public RenderingDevice { /**********************/ struct ComputeList { - VkCommandBuffer command_buffer; //if persistent, this is owned, otherwise it's shared with the ringbuffer + VkCommandBuffer command_buffer; // If persistent, this is owned, otherwise it's shared with the ringbuffer. struct SetState { - uint32_t pipeline_expected_format; - uint32_t uniform_set_format; - VkDescriptorSet descriptor_set; + uint32_t pipeline_expected_format = 0; + uint32_t uniform_set_format = 0; + VkDescriptorSet descriptor_set = VK_NULL_HANDLE; RID uniform_set; - bool bound; - SetState() { - bound = false; - pipeline_expected_format = 0; - uniform_set_format = 0; - descriptor_set = VK_NULL_HANDLE; - } + bool bound = false; }; struct State { Set<Texture *> textures_to_sampled_layout; - SetState sets[MAX_UNIFORM_SETS]; - uint32_t set_count; + uint32_t set_count = 0; RID pipeline; RID pipeline_shader; - VkPipelineLayout pipeline_layout; - uint32_t pipeline_push_constant_stages; - - State() { - set_count = 0; - pipeline_layout = VK_NULL_HANDLE; - pipeline_push_constant_stages = 0; - } + VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; + uint32_t pipeline_push_constant_stages = 0; } state; -#ifdef DEBUG_ENABLED +#ifdef DEBUG_ENABLED struct Validation { - bool active; //means command buffer was not closes, so you can keep adding things + bool active = true; // Means command buffer was not closed, so you can keep adding things. Vector<uint32_t> set_formats; Vector<bool> set_bound; Vector<RID> set_rids; - //last pipeline set values - bool pipeline_active; + // Last pipeline set values. + bool pipeline_active = false; RID pipeline_shader; - uint32_t invalid_set_from; + uint32_t invalid_set_from = 0; Vector<uint32_t> pipeline_set_formats; - uint32_t pipeline_push_constant_size; - bool pipeline_push_constant_suppplied; - - Validation() { - active = true; - invalid_set_from = 0; - - //pipeline state initalize - pipeline_active = false; - pipeline_push_constant_size = 0; - pipeline_push_constant_suppplied = false; - } + uint32_t pipeline_push_constant_size = 0; + bool pipeline_push_constant_supplied = false; } validation; #endif }; diff --git a/drivers/vulkan/vulkan_context.h b/drivers/vulkan/vulkan_context.h index ff1215ff5d..3f4cfac123 100644 --- a/drivers/vulkan/vulkan_context.h +++ b/drivers/vulkan/vulkan_context.h @@ -80,29 +80,15 @@ class VulkanContext { } SwapchainImageResources; struct Window { - bool is_minimzed; - VkSurfaceKHR surface; - VkSwapchainKHR swapchain; - SwapchainImageResources *swapchain_image_resources; - VkPresentModeKHR presentMode; - uint32_t current_buffer; - int width; - int height; + VkSurfaceKHR surface = VK_NULL_HANDLE; + VkSwapchainKHR swapchain = VK_NULL_HANDLE; + SwapchainImageResources *swapchain_image_resources = VK_NULL_HANDLE; + VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t current_buffer = 0; + int width = 0; + int height = 0; VkCommandPool present_cmd_pool; //for separate present queue - - VkRenderPass render_pass; - - Window() { - width = 0; - height = 0; - render_pass = VK_NULL_HANDLE; - current_buffer = 0; - surface = VK_NULL_HANDLE; - swapchain_image_resources = VK_NULL_HANDLE; - swapchain = VK_NULL_HANDLE; - is_minimzed = false; - presentMode = VK_PRESENT_MODE_FIFO_KHR; - } + VkRenderPass render_pass = VK_NULL_HANDLE; }; struct LocalDevice { diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index dc5ff6a5eb..499f7d4017 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -916,6 +916,8 @@ public: icon = nullptr; icon_needs_reload = true; hover = false; + + set_focus_mode(FocusMode::FOCUS_ALL); } void set_is_favorite(bool fav) { @@ -1739,6 +1741,10 @@ void ProjectList::_panel_input(const Ref<InputEvent> &p_ev, Node *p_hb) { select_project(clicked_index); } + if (_selected_project_keys.has(clicked_project.project_key)) { + clicked_project.control->grab_focus(); + } + emit_signal(SIGNAL_SELECTION_CHANGED); if (!mb->get_control() && mb->is_doubleclick()) { diff --git a/methods.py b/methods.py index c1245cd95a..756db19e9a 100644 --- a/methods.py +++ b/methods.py @@ -231,6 +231,30 @@ def disable_module(self): self.disabled_modules.append(self.current_module) +def module_check_dependencies(self, module, dependencies): + """ + Checks if module dependencies are enabled for a given module, + and prints a warning if they aren't. + Meant to be used in module `can_build` methods. + Returns a boolean (True if dependencies are satisfied). + """ + missing_deps = [] + for dep in dependencies: + opt = "module_{}_enabled".format(dep) + if not opt in self or not self[opt]: + missing_deps.append(dep) + + if missing_deps != []: + print( + "Disabling '{}' module as the following dependencies are not satisfied: {}".format( + module, ", ".join(missing_deps) + ) + ) + return False + else: + return True + + def use_windows_spawn_fix(self, platform=None): if os.name != "nt": diff --git a/modules/opus/config.py b/modules/opus/config.py index d22f9454ed..9ff7b2dece 100644 --- a/modules/opus/config.py +++ b/modules/opus/config.py @@ -1,5 +1,5 @@ def can_build(env, platform): - return True + return env.module_check_dependencies("opus", ["ogg"]) def configure(env): diff --git a/modules/theora/config.py b/modules/theora/config.py index 413acce2df..b063ed51f9 100644 --- a/modules/theora/config.py +++ b/modules/theora/config.py @@ -1,5 +1,5 @@ def can_build(env, platform): - return True + return env.module_check_dependencies("theora", ["ogg", "vorbis"]) def configure(env): diff --git a/modules/vorbis/config.py b/modules/vorbis/config.py index d22f9454ed..8a384e3066 100644 --- a/modules/vorbis/config.py +++ b/modules/vorbis/config.py @@ -1,5 +1,5 @@ def can_build(env, platform): - return True + return env.module_check_dependencies("vorbis", ["ogg"]) def configure(env): diff --git a/modules/webm/config.py b/modules/webm/config.py index 93b49d177a..99f8ace114 100644 --- a/modules/webm/config.py +++ b/modules/webm/config.py @@ -1,5 +1,8 @@ def can_build(env, platform): - return platform not in ["iphone"] + if platform in ["iphone"]: + return False + + return env.module_check_dependencies("webm", ["ogg", "opus", "vorbis"]) def configure(env): diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index a57408b83b..d5c065bd55 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -646,7 +646,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } if (p_mode == PROCESS_DRAW && visible) { - img->image->draw_rect(ci, Rect2(p_ofs + Point2(align_ofs + wofs, y + lh - font->get_descent() - img->size.height), img->size)); + img->image->draw_rect(ci, Rect2(p_ofs + Point2(align_ofs + wofs, y + lh - font->get_descent() - img->size.height), img->size), false, img->color); } p_char_count++; @@ -1443,6 +1443,46 @@ void RichTextLabel::_fetch_item_fx_stack(Item *p_item, Vector<ItemFX *> &r_stack } } +Color RichTextLabel::_get_color_from_string(const String &p_color_str, const Color &p_default_color) { + if (p_color_str.begins_with("#")) { + return Color::html(p_color_str); + } else if (p_color_str == "aqua") { + return Color(0, 1, 1); + } else if (p_color_str == "black") { + return Color(0, 0, 0); + } else if (p_color_str == "blue") { + return Color(0, 0, 1); + } else if (p_color_str == "fuchsia") { + return Color(1, 0, 1); + } else if (p_color_str == "gray" || p_color_str == "grey") { + return Color(0.5, 0.5, 0.5); + } else if (p_color_str == "green") { + return Color(0, 0.5, 0); + } else if (p_color_str == "lime") { + return Color(0, 1, 0); + } else if (p_color_str == "maroon") { + return Color(0.5, 0, 0); + } else if (p_color_str == "navy") { + return Color(0, 0, 0.5); + } else if (p_color_str == "olive") { + return Color(0.5, 0.5, 0); + } else if (p_color_str == "purple") { + return Color(0.5, 0, 0.5); + } else if (p_color_str == "red") { + return Color(1, 0, 0); + } else if (p_color_str == "silver") { + return Color(0.75, 0.75, 0.75); + } else if (p_color_str == "teal") { + return Color(0, 0.5, 0.5); + } else if (p_color_str == "white") { + return Color(1, 1, 1); + } else if (p_color_str == "yellow") { + return Color(1, 1, 0); + } else { + return p_default_color; + } +} + bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item) { Item *item = p_item; @@ -1636,7 +1676,7 @@ void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_sub } } -void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, const int p_height) { +void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, const int p_height, const Color &p_color) { if (current->type == ITEM_TABLE) { return; } @@ -1645,6 +1685,7 @@ void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, ItemImage *item = memnew(ItemImage); item->image = p_image; + item->color = p_color; if (p_width > 0) { // custom width @@ -2034,7 +2075,32 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { String tag = p_bbcode.substr(brk_pos + 1, brk_end - brk_pos - 1); Vector<String> split_tag_block = tag.split(" ", false); - String bbcode = !split_tag_block.empty() ? split_tag_block[0] : ""; + + // Find optional parameters. + String bbcode_name; + typedef Map<String, String> OptionMap; + OptionMap bbcode_options; + if (!split_tag_block.empty()) { + bbcode_name = split_tag_block[0]; + for (int i = 1; i < split_tag_block.size(); i++) { + const String &expr = split_tag_block[i]; + int value_pos = expr.find("="); + if (value_pos > -1) { + bbcode_options[expr.substr(0, value_pos)] = expr.substr(value_pos + 1); + } + } + } else { + bbcode_name = tag; + } + + // Find main parameter. + String bbcode_value; + int main_value_pos = bbcode_name.find("="); + if (main_value_pos > -1) { + bbcode_value = bbcode_name.substr(main_value_pos + 1); + bbcode_name = bbcode_name.substr(0, main_value_pos); + } + if (tag.begins_with("/") && tag_stack.size()) { bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1, tag.length()); @@ -2160,7 +2226,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { push_meta(url); pos = brk_end + 1; tag_stack.push_front("url"); - } else if (tag == "img") { + } else if (bbcode_name == "img") { int end = p_bbcode.find("[", brk_end); if (end == -1) { end = p_bbcode.length(); @@ -2170,80 +2236,42 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { Ref<Texture2D> texture = ResourceLoader::load(image, "Texture2D"); if (texture.is_valid()) { - add_image(texture); - } - - pos = end; - tag_stack.push_front(tag); - } else if (tag.begins_with("img=")) { - int width = 0; - int height = 0; - - String params = tag.substr(4, tag.length()); - int sep = params.find("x"); - if (sep == -1) { - width = params.to_int(); - } else { - width = params.substr(0, sep).to_int(); - height = params.substr(sep + 1, params.length()).to_int(); - } + Color color = Color(1.0, 1.0, 1.0); + OptionMap::Element *color_option = bbcode_options.find("color"); + if (color_option) { + color = _get_color_from_string(color_option->value(), color); + } - int end = p_bbcode.find("[", brk_end); - if (end == -1) { - end = p_bbcode.length(); - } + int width = 0; + int height = 0; + if (!bbcode_value.empty()) { + int sep = bbcode_value.find("x"); + if (sep == -1) { + width = bbcode_value.to_int(); + } else { + width = bbcode_value.substr(0, sep).to_int(); + height = bbcode_value.substr(sep + 1).to_int(); + } + } else { + OptionMap::Element *width_option = bbcode_options.find("width"); + if (width_option) { + width = width_option->value().to_int(); + } - String image = p_bbcode.substr(brk_end + 1, end - brk_end - 1); + OptionMap::Element *height_option = bbcode_options.find("height"); + if (height_option) { + height = height_option->value().to_int(); + } + } - Ref<Texture2D> texture = ResourceLoader::load(image, "Texture"); - if (texture.is_valid()) { - add_image(texture, width, height); + add_image(texture, width, height, color); } pos = end; - tag_stack.push_front("img"); + tag_stack.push_front(bbcode_name); } else if (tag.begins_with("color=")) { - String col = tag.substr(6, tag.length()); - Color color; - - if (col.begins_with("#")) { - color = Color::html(col); - } else if (col == "aqua") { - color = Color(0, 1, 1); - } else if (col == "black") { - color = Color(0, 0, 0); - } else if (col == "blue") { - color = Color(0, 0, 1); - } else if (col == "fuchsia") { - color = Color(1, 0, 1); - } else if (col == "gray" || col == "grey") { - color = Color(0.5, 0.5, 0.5); - } else if (col == "green") { - color = Color(0, 0.5, 0); - } else if (col == "lime") { - color = Color(0, 1, 0); - } else if (col == "maroon") { - color = Color(0.5, 0, 0); - } else if (col == "navy") { - color = Color(0, 0, 0.5); - } else if (col == "olive") { - color = Color(0.5, 0.5, 0); - } else if (col == "purple") { - color = Color(0.5, 0, 0.5); - } else if (col == "red") { - color = Color(1, 0, 0); - } else if (col == "silver") { - color = Color(0.75, 0.75, 0.75); - } else if (col == "teal") { - color = Color(0, 0.5, 0.5); - } else if (col == "white") { - color = Color(1, 1, 1); - } else if (col == "yellow") { - color = Color(1, 1, 0); - } else { - color = base_color; - } - + String color_str = tag.substr(6, tag.length()); + Color color = _get_color_from_string(color_str, base_color); push_color(color); pos = brk_end + 1; tag_stack.push_front("color"); @@ -2261,113 +2289,90 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pos = brk_end + 1; tag_stack.push_front("font"); - } else if (bbcode == "fade") { - int startIndex = 0; - int length = 10; + } else if (bbcode_name == "fade") { + int start_index = 0; + OptionMap::Element *start_option = bbcode_options.find("start"); + if (start_option) { + start_index = start_option->value().to_int(); + } - if (split_tag_block.size() > 1) { - split_tag_block.remove(0); - for (int i = 0; i < split_tag_block.size(); i++) { - String expr = split_tag_block[i]; - if (expr.begins_with("start=")) { - String start_str = expr.substr(6, expr.length()); - startIndex = start_str.to_int(); - } else if (expr.begins_with("length=")) { - String end_str = expr.substr(7, expr.length()); - length = end_str.to_int(); - } - } + int length = 10; + OptionMap::Element *length_option = bbcode_options.find("length"); + if (length_option) { + length = length_option->value().to_int(); } - push_fade(startIndex, length); + push_fade(start_index, length); pos = brk_end + 1; tag_stack.push_front("fade"); - } else if (bbcode == "shake") { + } else if (bbcode_name == "shake") { int strength = 5; - float rate = 20.0f; + OptionMap::Element *strength_option = bbcode_options.find("level"); + if (strength_option) { + strength = strength_option->value().to_int(); + } - if (split_tag_block.size() > 1) { - split_tag_block.remove(0); - for (int i = 0; i < split_tag_block.size(); i++) { - String expr = split_tag_block[i]; - if (expr.begins_with("level=")) { - String str_str = expr.substr(6, expr.length()); - strength = str_str.to_int(); - } else if (expr.begins_with("rate=")) { - String rate_str = expr.substr(5, expr.length()); - rate = rate_str.to_float(); - } - } + float rate = 20.0f; + OptionMap::Element *rate_option = bbcode_options.find("rate"); + if (rate_option) { + rate = rate_option->value().to_float(); } push_shake(strength, rate); pos = brk_end + 1; tag_stack.push_front("shake"); set_process_internal(true); - } else if (bbcode == "wave") { + } else if (bbcode_name == "wave") { float amplitude = 20.0f; - float period = 5.0f; + OptionMap::Element *amplitude_option = bbcode_options.find("amp"); + if (amplitude_option) { + amplitude = amplitude_option->value().to_float(); + } - if (split_tag_block.size() > 1) { - split_tag_block.remove(0); - for (int i = 0; i < split_tag_block.size(); i++) { - String expr = split_tag_block[i]; - if (expr.begins_with("amp=")) { - String amp_str = expr.substr(4, expr.length()); - amplitude = amp_str.to_float(); - } else if (expr.begins_with("freq=")) { - String period_str = expr.substr(5, expr.length()); - period = period_str.to_float(); - } - } + float period = 5.0f; + OptionMap::Element *period_option = bbcode_options.find("freq"); + if (period_option) { + period = period_option->value().to_float(); } push_wave(period, amplitude); pos = brk_end + 1; tag_stack.push_front("wave"); set_process_internal(true); - } else if (bbcode == "tornado") { + } else if (bbcode_name == "tornado") { float radius = 10.0f; - float frequency = 1.0f; + OptionMap::Element *radius_option = bbcode_options.find("radius"); + if (radius_option) { + radius = radius_option->value().to_float(); + } - if (split_tag_block.size() > 1) { - split_tag_block.remove(0); - for (int i = 0; i < split_tag_block.size(); i++) { - String expr = split_tag_block[i]; - if (expr.begins_with("radius=")) { - String amp_str = expr.substr(7, expr.length()); - radius = amp_str.to_float(); - } else if (expr.begins_with("freq=")) { - String period_str = expr.substr(5, expr.length()); - frequency = period_str.to_float(); - } - } + float frequency = 1.0f; + OptionMap::Element *frequency_option = bbcode_options.find("freq"); + if (frequency_option) { + frequency = frequency_option->value().to_float(); } push_tornado(frequency, radius); pos = brk_end + 1; tag_stack.push_front("tornado"); set_process_internal(true); - } else if (bbcode == "rainbow") { + } else if (bbcode_name == "rainbow") { float saturation = 0.8f; + OptionMap::Element *saturation_option = bbcode_options.find("sat"); + if (saturation_option) { + saturation = saturation_option->value().to_float(); + } + float value = 0.8f; - float frequency = 1.0f; + OptionMap::Element *value_option = bbcode_options.find("val"); + if (value_option) { + value = value_option->value().to_float(); + } - if (split_tag_block.size() > 1) { - split_tag_block.remove(0); - for (int i = 0; i < split_tag_block.size(); i++) { - String expr = split_tag_block[i]; - if (expr.begins_with("sat=")) { - String sat_str = expr.substr(4, expr.length()); - saturation = sat_str.to_float(); - } else if (expr.begins_with("val=")) { - String val_str = expr.substr(4, expr.length()); - value = val_str.to_float(); - } else if (expr.begins_with("freq=")) { - String freq_str = expr.substr(5, expr.length()); - frequency = freq_str.to_float(); - } - } + float frequency = 1.0f; + OptionMap::Element *frequency_option = bbcode_options.find("freq"); + if (frequency_option) { + frequency = frequency_option->value().to_float(); } push_rainbow(saturation, value, frequency); @@ -2634,7 +2639,7 @@ void RichTextLabel::_bind_methods() { ClassDB::bind_method(D_METHOD("get_text"), &RichTextLabel::get_text); ClassDB::bind_method(D_METHOD("add_text", "text"), &RichTextLabel::add_text); ClassDB::bind_method(D_METHOD("set_text", "text"), &RichTextLabel::set_text); - ClassDB::bind_method(D_METHOD("add_image", "image", "width", "height"), &RichTextLabel::add_image, DEFVAL(0), DEFVAL(0)); + ClassDB::bind_method(D_METHOD("add_image", "image", "width", "height", "color"), &RichTextLabel::add_image, DEFVAL(0), DEFVAL(0), DEFVAL(Color(1.0, 1.0, 1.0))); ClassDB::bind_method(D_METHOD("newline"), &RichTextLabel::add_newline); ClassDB::bind_method(D_METHOD("remove_line", "line"), &RichTextLabel::remove_line); ClassDB::bind_method(D_METHOD("push_font", "font"), &RichTextLabel::push_font); diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 019edf5d45..4cec435568 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -149,6 +149,7 @@ private: struct ItemImage : public Item { Ref<Texture2D> image; Size2 size; + Color color; ItemImage() { type = ITEM_IMAGE; } }; @@ -381,6 +382,8 @@ private: bool _find_by_type(Item *p_item, ItemType p_type); void _fetch_item_fx_stack(Item *p_item, Vector<ItemFX *> &r_stack); + static Color _get_color_from_string(const String &p_color_str, const Color &p_default_color); + void _update_scroll(); void _update_fx(ItemFrame *p_frame, float p_delta_time); void _scroll_changed(double); @@ -406,7 +409,7 @@ protected: public: String get_text(); void add_text(const String &p_text); - void add_image(const Ref<Texture2D> &p_image, const int p_width = 0, const int p_height = 0); + void add_image(const Ref<Texture2D> &p_image, const int p_width = 0, const int p_height = 0, const Color &p_color = Color(1.0, 1.0, 1.0)); void add_newline(); bool remove_line(const int p_line); void push_font(const Ref<Font> &p_font); diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index 3b4e4b73f8..3d99556a10 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -567,7 +567,7 @@ DynamicFontAtSize::Character DynamicFontAtSize::_make_outline_char(CharType p_ch if (FT_Glyph_Stroke(&glyph, stroker, 1) != 0) { goto cleanup_glyph; } - if (FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, nullptr, 1) != 0) { + if (FT_Glyph_To_Bitmap(&glyph, font->antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, nullptr, 1) != 0) { goto cleanup_glyph; } |