diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/base_button.cpp | 2 | ||||
-rw-r--r-- | scene/gui/rich_text_label.cpp | 66 | ||||
-rw-r--r-- | scene/gui/rich_text_label.h | 4 | ||||
-rw-r--r-- | scene/resources/material.cpp | 116 | ||||
-rw-r--r-- | scene/resources/material.h | 29 |
5 files changed, 199 insertions, 18 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 5713a35b7a..04c0817b15 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -39,7 +39,7 @@ void BaseButton::_unpress_group() { if (!button_group.is_valid()) return; - status.pressed = true; + status.pressed = false; for (Set<BaseButton *>::Element *E = button_group->buttons.front(); E; E = E->next()) { if (E->get() == this) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 71b9c4ec72..d9287e6f63 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -84,7 +84,7 @@ Rect2 RichTextLabel::_get_text_rect() { Ref<StyleBox> style = get_stylebox("normal"); return Rect2(style->get_offset(), get_size() - style->get_minimum_size()); } -void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Point2i &p_click_pos, Item **r_click_item, int *r_click_char, bool *r_outside, int p_char_count) { +int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Point2i &p_click_pos, Item **r_click_item, int *r_click_char, bool *r_outside, int p_char_count) { RID ci; if (r_outside) @@ -104,9 +104,11 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int int line = 0; int spaces = 0; + int height = get_size().y; + if (p_mode != PROCESS_CACHE) { - ERR_FAIL_INDEX(line, l.offset_caches.size()); + ERR_FAIL_INDEX_V(line, l.offset_caches.size(), 0); line_ofs = l.offset_caches[line]; } @@ -133,12 +135,20 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int //line height should be the font height for the first time, this ensures that an empty line will never have zero height and successive newlines are displayed int line_height = cfont->get_height(); + int nonblank_line_count = 0; //number of nonblank lines as counted during PROCESS_DRAW + Variant meta; +#define RETURN return nonblank_line_count + #define NEW_LINE \ { \ if (p_mode != PROCESS_CACHE) { \ line++; \ + if (!line_is_blank) { \ + nonblank_line_count++; \ + } \ + line_is_blank = true; \ if (line < l.offset_caches.size()) \ line_ofs = l.offset_caches[line]; \ wofs = margin; \ @@ -168,7 +178,7 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int if (r_outside) *r_outside = true; \ *r_click_item = it; \ *r_click_char = rchar; \ - return; \ + RETURN; \ } \ } @@ -185,7 +195,7 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int if (r_outside) *r_outside = true; \ *r_click_item = it; \ *r_click_char = rchar; \ - return; \ + RETURN; \ } \ NEW_LINE \ } @@ -196,7 +206,7 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int if (r_outside) *r_outside = false; \ *r_click_item = it; \ *r_click_char = rchar; \ - return; \ + RETURN; \ } \ wofs += m_width; \ } @@ -206,6 +216,9 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int line_height = m_height; \ } +#define YRANGE_VISIBLE(m_top, m_height) \ + (m_height > 0 && ((m_top >= 0 && m_top < height) || ((m_top + m_height - 1) >= 0 && (m_top + m_height - 1) < height))) + Color selection_fg; Color selection_bg; @@ -214,8 +227,10 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int selection_fg = get_color("font_color_selected"); selection_bg = get_color("selection_color"); } + int rchar = 0; int lh = 0; + bool line_is_blank = true; while (it) { @@ -327,7 +342,10 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int int cw = 0; - bool visible = visible_characters < 0 || p_char_count < visible_characters; + bool visible = visible_characters < 0 || p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - (fh - 0 * ascent), fh); //getting rid of ascent seems to work?? + if (visible) + line_is_blank = false; + if (c[i] == '\t') visible = false; @@ -384,7 +402,9 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int ENSURE_WIDTH(img->image->get_width()); - bool visible = visible_characters < 0 || p_char_count < visible_characters; + bool visible = visible_characters < 0 || p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - font->get_descent() - img->image->get_height(), img->image->get_height()); + if (visible) + line_is_blank = false; if (p_mode == PROCESS_DRAW && visible) { img->image->draw(ci, p_ofs + Point2(align_ofs + wofs, y + lh - font->get_descent() - img->image->get_height())); @@ -398,8 +418,10 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int case ITEM_NEWLINE: { lh = 0; - if (p_mode != PROCESS_CACHE) + if (p_mode != PROCESS_CACHE) { lh = line < l.height_caches.size() ? l.height_caches[line] : 1; + line_is_blank = true; + } } break; case ITEM_TABLE: { @@ -436,7 +458,7 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int idx++; } - //compute available width and total radio (for expanders) + //compute available width and total ratio (for expanders) int total_ratio = 0; int available_width = p_width - hseparation * (table->columns.size() - 1); @@ -494,12 +516,14 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int int lines_ofs = p_ofs.y + offset.y + draw_ofs.y; bool visible = lines_ofs < get_size().height && lines_ofs + lines_h >= 0; + if (visible) + line_is_blank = false; for (int i = 0; i < frame->lines.size(); i++) { if (visible) { if (p_mode == PROCESS_DRAW) { - _process_line(frame, p_ofs + offset + draw_ofs + Vector2(0, yofs), ly, table->columns[column].width, i, PROCESS_DRAW, cfont, ccolor); + nonblank_line_count += _process_line(frame, p_ofs + offset + draw_ofs + Vector2(0, yofs), ly, table->columns[column].width, i, PROCESS_DRAW, cfont, ccolor); } else if (p_mode == PROCESS_POINTER) { _process_line(frame, p_ofs + offset + draw_ofs + Vector2(0, yofs), ly, table->columns[column].width, i, PROCESS_POINTER, cfont, ccolor, p_click_pos, r_click_item, r_click_char, r_outside); } @@ -547,15 +571,17 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int if (r_outside) *r_outside = true; *r_click_item = itp; *r_click_char = rchar; - return; + RETURN; } break; } } - NEW_LINE; + RETURN; + +#undef RETURN #undef NEW_LINE #undef ENSURE_WIDTH #undef ADVANCE @@ -665,14 +691,14 @@ void RichTextLabel::_notification(int p_what) { if (from_line >= main->lines.size()) break; //nothing to draw - int y = (main->lines[from_line].height_accum_cache - main->lines[from_line].height_cache) - ofs; Ref<Font> base_font = get_font("normal_font"); Color base_color = get_color("default_color"); + visible_line_count = 0; while (y < size.height && from_line < main->lines.size()) { - _process_line(main, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_DRAW, base_font, base_color, Point2i(), NULL, NULL, NULL, total_chars); + visible_line_count += _process_line(main, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_DRAW, base_font, base_color, Point2i(), NULL, NULL, NULL, total_chars); total_chars += main->lines[from_line].char_count; from_line++; } @@ -1013,7 +1039,7 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) { if (p_frame->first_invalid_line == p_frame->lines.size()) return; - //validate invalid lines!s + //validate invalid lines Size2 size = get_size(); Rect2 text_rect = _get_text_rect(); @@ -1665,6 +1691,12 @@ int RichTextLabel::get_line_count() const { return current_frame->lines.size(); } +int RichTextLabel::get_visible_line_count() const { + if (!is_visible()) + return 0; + return visible_line_count; +} + void RichTextLabel::set_selection_enabled(bool p_enabled) { selection.enabled = p_enabled; @@ -1907,6 +1939,9 @@ void RichTextLabel::_bind_methods() { ClassDB::bind_method(D_METHOD("set_use_bbcode", "enable"), &RichTextLabel::set_use_bbcode); ClassDB::bind_method(D_METHOD("is_using_bbcode"), &RichTextLabel::is_using_bbcode); + ClassDB::bind_method(D_METHOD("get_line_count"), &RichTextLabel::get_line_count); + ClassDB::bind_method(D_METHOD("get_visible_line_count"), &RichTextLabel::get_visible_line_count); + ADD_GROUP("BBCode", "bbcode_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bbcode_enabled"), "set_use_bbcode", "is_using_bbcode"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "bbcode_text", PROPERTY_HINT_MULTILINE_TEXT), "set_bbcode", "get_bbcode"); @@ -1995,6 +2030,7 @@ RichTextLabel::RichTextLabel() { visible_characters = -1; percent_visible = 1; + visible_line_count = 0; set_clip_contents(true); } diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 4db2c3a8e9..24c1e5eb59 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -217,6 +217,7 @@ private: int scroll_w; bool updating_scroll; int current_idx; + int visible_line_count; int tab_size; bool underline_meta; @@ -260,7 +261,7 @@ private: int visible_characters; float percent_visible; - void _process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Point2i &p_click_pos = Point2i(), Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL, int p_char_count = 0); + int _process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Point2i &p_click_pos = Point2i(), Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL, int p_char_count = 0); void _find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL); Ref<Font> _find_font(Item *p_item); @@ -325,6 +326,7 @@ public: void scroll_to_line(int p_line); int get_line_count() const; + int get_visible_line_count() const; VScrollBar *get_v_scroll() { return vscroll; } diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index abe9a00c3f..553e9b9905 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -268,6 +268,10 @@ void SpatialMaterial::init_shaders() { shader_names->grow = "grow"; + shader_names->proximity_fade_distance = "proximity_fade_distance"; + shader_names->distance_fade_min = "distance_fade_min"; + shader_names->distance_fade_max = "distance_fade_max"; + shader_names->metallic_texture_channel = "metallic_texture_channel"; shader_names->roughness_texture_channel = "roughness_texture_channel"; shader_names->ao_texture_channel = "ao_texture_channel"; @@ -401,6 +405,14 @@ void SpatialMaterial::_update_shader() { code += "uniform float grow;\n"; } + if (proximity_fade_enabled) { + code += "uniform float proximity_fade_distance;\n"; + } + if (distance_fade_enabled) { + code += "uniform float distance_fade_min;\n"; + code += "uniform float distance_fade_max;\n"; + } + if (flags[FLAG_USE_ALPHA_SCISSOR]) { code += "uniform float alpha_scissor_threshold;\n"; } @@ -725,10 +737,21 @@ void SpatialMaterial::_update_shader() { code += "\tALBEDO *= 1.0 - ref_amount;\n"; code += "\tALPHA = 1.0;\n"; - } else if (features[FEATURE_TRANSPARENT] || features[FLAG_USE_ALPHA_SCISSOR]) { + } else if (features[FEATURE_TRANSPARENT] || features[FLAG_USE_ALPHA_SCISSOR] || distance_fade_enabled || proximity_fade_enabled) { code += "\tALPHA = albedo.a * albedo_tex.a;\n"; } + if (proximity_fade_enabled) { + code += "\tfloat depth_tex = textureLod(DEPTH_TEXTURE,SCREEN_UV,0.0).r;\n"; + code += "\tvec4 world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV*2.0-1.0,depth_tex*2.0-1.0,1.0);\n"; + code += "\tworld_pos.xyz/=world_pos.w;\n"; + code += "\tALPHA*=clamp(1.0-smoothstep(world_pos.z+proximity_fade_distance,world_pos.z,VERTEX.z),0.0,1.0);\n"; + } + + if (distance_fade_enabled) { + code += "\tALPHA*=clamp(smoothstep(distance_fade_min,distance_fade_max,-VERTEX.z),0.0,1.0);\n"; + } + if (features[FEATURE_RIM]) { if (flags[FLAG_UV1_USE_TRIPLANAR]) { code += "\tvec2 rim_tex = triplanar_texture(texture_rim,uv1_power_normal,uv1_triplanar_pos).xy;\n"; @@ -1231,6 +1254,14 @@ void SpatialMaterial::_validate_property(PropertyInfo &property) const { property.usage = 0; } + if (property.name == "proximity_fade_distacne" && !proximity_fade_enabled) { + property.usage = 0; + } + + if ((property.name == "distance_fade_max_distance" || property.name == "distance_fade_min_distance") && !distance_fade_enabled) { + property.usage = 0; + } + if (property.name == "params_alpha_scissor_threshold" && !flags[FLAG_USE_ALPHA_SCISSOR]) { property.usage = 0; } @@ -1526,6 +1557,60 @@ void SpatialMaterial::set_on_top_of_alpha() { set_flag(FLAG_DISABLE_DEPTH_TEST, true); } +void SpatialMaterial::set_proximity_fade(bool p_enable) { + + proximity_fade_enabled = p_enable; + _queue_shader_change(); + _change_notify(); +} + +bool SpatialMaterial::is_proximity_fade_enabled() const { + + return proximity_fade_enabled; +} + +void SpatialMaterial::set_proximity_fade_distance(float p_distance) { + + proximity_fade_distance = p_distance; + VS::get_singleton()->material_set_param(_get_material(), shader_names->proximity_fade_distance, p_distance); +} +float SpatialMaterial::get_proximity_fade_distance() const { + + return proximity_fade_distance; +} + +void SpatialMaterial::set_distance_fade(bool p_enable) { + + distance_fade_enabled = p_enable; + _queue_shader_change(); + _change_notify(); +} +bool SpatialMaterial::is_distance_fade_enabled() const { + + return distance_fade_enabled; +} + +void SpatialMaterial::set_distance_fade_max_distance(float p_distance) { + + distance_fade_max_distance = p_distance; + VS::get_singleton()->material_set_param(_get_material(), shader_names->distance_fade_max, distance_fade_max_distance); +} +float SpatialMaterial::get_distance_fade_max_distance() const { + + return distance_fade_max_distance; +} + +void SpatialMaterial::set_distance_fade_min_distance(float p_distance) { + + distance_fade_min_distance = p_distance; + VS::get_singleton()->material_set_param(_get_material(), shader_names->distance_fade_min, distance_fade_min_distance); +} + +float SpatialMaterial::get_distance_fade_min_distance() const { + + return distance_fade_min_distance; +} + void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_albedo", "albedo"), &SpatialMaterial::set_albedo); @@ -1672,6 +1757,21 @@ void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_refraction_texture_channel", "channel"), &SpatialMaterial::set_refraction_texture_channel); ClassDB::bind_method(D_METHOD("get_refraction_texture_channel"), &SpatialMaterial::get_refraction_texture_channel); + ClassDB::bind_method(D_METHOD("set_proximity_fade", "enabled"), &SpatialMaterial::set_proximity_fade); + ClassDB::bind_method(D_METHOD("is_proximity_fade_enabled"), &SpatialMaterial::is_proximity_fade_enabled); + + ClassDB::bind_method(D_METHOD("set_proximity_fade_distance", "distance"), &SpatialMaterial::set_proximity_fade_distance); + ClassDB::bind_method(D_METHOD("get_proximity_fade_distance"), &SpatialMaterial::get_proximity_fade_distance); + + ClassDB::bind_method(D_METHOD("set_distance_fade", "enabled"), &SpatialMaterial::set_distance_fade); + ClassDB::bind_method(D_METHOD("is_distance_fade_enabled"), &SpatialMaterial::is_distance_fade_enabled); + + ClassDB::bind_method(D_METHOD("set_distance_fade_max_distance", "distance"), &SpatialMaterial::set_distance_fade_max_distance); + ClassDB::bind_method(D_METHOD("get_distance_fade_max_distance"), &SpatialMaterial::get_distance_fade_max_distance); + + ClassDB::bind_method(D_METHOD("set_distance_fade_min_distance", "distance"), &SpatialMaterial::set_distance_fade_min_distance); + ClassDB::bind_method(D_METHOD("get_distance_fade_min_distance"), &SpatialMaterial::get_distance_fade_min_distance); + ADD_GROUP("Flags", "flags_"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_transparent"), "set_feature", "get_feature", FEATURE_TRANSPARENT); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_unshaded"), "set_flag", "get_flag", FLAG_UNSHADED); @@ -1795,6 +1895,14 @@ void SpatialMaterial::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "uv2_triplanar"), "set_flag", "get_flag", FLAG_UV2_USE_TRIPLANAR); ADD_PROPERTY(PropertyInfo(Variant::REAL, "uv2_triplanar_sharpness", PROPERTY_HINT_EXP_EASING), "set_uv2_triplanar_blend_sharpness", "get_uv2_triplanar_blend_sharpness"); + ADD_GROUP("Proximity Fade", "proximity_fade_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "proximity_fade_enable"), "set_proximity_fade", "is_proximity_fade_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "proximity_fade_distance", PROPERTY_HINT_RANGE, "0,4096,0.1"), "set_proximity_fade_distance", "get_proximity_fade_distance"); + ADD_GROUP("Distance Fade", "distance_fade_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "distance_fade_enable"), "set_distance_fade", "is_distance_fade_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "distance_fade_min_distance", PROPERTY_HINT_RANGE, "0,4096,0.1"), "set_distance_fade_min_distance", "get_distance_fade_min_distance"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "distance_fade_max_distance", PROPERTY_HINT_RANGE, "0,4096,0.1"), "set_distance_fade_max_distance", "get_distance_fade_max_distance"); + BIND_ENUM_CONSTANT(TEXTURE_ALBEDO); BIND_ENUM_CONSTANT(TEXTURE_METALLIC); BIND_ENUM_CONSTANT(TEXTURE_ROUGHNESS); @@ -1916,6 +2024,12 @@ SpatialMaterial::SpatialMaterial() set_particles_anim_loop(false); set_alpha_scissor_threshold(0.98); + proximity_fade_enabled = false; + distance_fade_enabled = false; + set_proximity_fade_distance(1); + set_distance_fade_min_distance(0); + set_distance_fade_max_distance(10); + set_metallic_texture_channel(TEXTURE_CHANNEL_RED); set_roughness_texture_channel(TEXTURE_CHANNEL_RED); set_ao_texture_channel(TEXTURE_CHANNEL_RED); diff --git a/scene/resources/material.h b/scene/resources/material.h index fdb11982a8..0c33891897 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -232,6 +232,8 @@ private: uint64_t deep_parallax : 1; uint64_t billboard_mode : 2; uint64_t grow : 1; + uint64_t proximity_fade : 1; + uint64_t distance_fade : 1; }; uint64_t key; @@ -274,6 +276,8 @@ private: mk.billboard_mode = billboard_mode; mk.deep_parallax = deep_parallax ? 1 : 0; mk.grow = grow_enabled; + mk.proximity_fade = proximity_fade_enabled; + mk.distance_fade = distance_fade_enabled; return mk; } @@ -308,6 +312,9 @@ private: StringName uv1_blend_sharpness; StringName uv2_blend_sharpness; StringName grow; + StringName proximity_fade_distance; + StringName distance_fade_min; + StringName distance_fade_max; StringName metallic_texture_channel; StringName roughness_texture_channel; @@ -370,6 +377,13 @@ private: int deep_parallax_min_layers; int deep_parallax_max_layers; + bool proximity_fade_enabled; + float proximity_fade_distance; + + bool distance_fade_enabled; + float distance_fade_max_distance; + float distance_fade_min_distance; + BlendMode blend_mode; BlendMode detail_blend_mode; DepthDrawMode depth_draw_mode; @@ -535,6 +549,21 @@ public: void set_on_top_of_alpha(); + void set_proximity_fade(bool p_enable); + bool is_proximity_fade_enabled() const; + + void set_proximity_fade_distance(float p_distance); + float get_proximity_fade_distance() const; + + void set_distance_fade(bool p_enable); + bool is_distance_fade_enabled() const; + + void set_distance_fade_max_distance(float p_distance); + float get_distance_fade_max_distance() const; + + void set_distance_fade_min_distance(float p_distance); + float get_distance_fade_min_distance() const; + void set_metallic_texture_channel(TextureChannel p_channel); TextureChannel get_metallic_texture_channel() const; void set_roughness_texture_channel(TextureChannel p_channel); |