From 7993ebb76f1d14da443f85db370fc0cfd72e26ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Sun, 23 Feb 2025 13:46:43 +0100 Subject: [PATCH] gui updates and other fixes --- WickedEngine/wiGUI.cpp | 25 +++++++++++++++++-------- WickedEngine/wiGUI.h | 8 ++++++++ WickedEngine/wiRandom.h | 8 ++++++++ WickedEngine/wiRenderer.cpp | 12 ++++++++++++ WickedEngine/wiVersion.cpp | 2 +- 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/WickedEngine/wiGUI.cpp b/WickedEngine/wiGUI.cpp index 3a3d42ca7f..79f7eb1903 100644 --- a/WickedEngine/wiGUI.cpp +++ b/WickedEngine/wiGUI.cpp @@ -92,15 +92,18 @@ namespace wi::gui widget->priority = ~0u; } - if (widget->IsVisible() && widget->hitBox.intersects(pointerHitbox)) + const bool visible = widget->IsVisible(); + const WIDGETSTATE state = widget->GetState(); + + if (visible && widget->hitBox.intersects(pointerHitbox)) { focus = true; } - if (widget->GetState() > IDLE) + if (visible && state > IDLE) { focus = true; } - if (widget->GetState() > FOCUS) + if (visible && state > FOCUS) { force_disable = true; } @@ -678,13 +681,19 @@ namespace wi::gui theme.image.Apply(sprites[id].params); } theme.font.Apply(font.params); + SetShadowRadius(theme.shadow); SetShadowColor(theme.shadow_color); theme.tooltipFont.Apply(tooltipFont.params); theme.tooltipImage.Apply(tooltipSprite.params); + tooltip_shadow = theme.tooltip_shadow; tooltip_shadow_color = theme.tooltip_shadow_color; shadow_highlight = theme.shadow_highlight; shadow_highlight_color = theme.shadow_highlight_color; shadow_highlight_spread = theme.shadow_highlight_spread; + for (auto& x : sprites) + { + x.params.border_soften = theme.image.border_soften; + } } void Widget::AttachTo(Widget* parent) @@ -1290,7 +1299,7 @@ namespace wi::gui if (wrap_enabled) { - font.params.h_wrap = scale.x; + font.params.h_wrap = scale.x - margin_left - margin_right; } else { @@ -1300,10 +1309,10 @@ namespace wi::gui switch (font.params.h_align) { case wi::font::WIFALIGN_LEFT: - font.params.posX = translation.x + 2; + font.params.posX = translation.x + 2 + margin_left; break; case wi::font::WIFALIGN_RIGHT: - font.params.posX = translation.x + scale.x - 2; + font.params.posX = translation.x + scale.x - 2 - margin_right; break; case wi::font::WIFALIGN_CENTER: default: @@ -1313,10 +1322,10 @@ namespace wi::gui switch (font.params.v_align) { case wi::font::WIFALIGN_TOP: - font.params.posY = translation.y + 2; + font.params.posY = translation.y + 2 + margin_top; break; case wi::font::WIFALIGN_BOTTOM: - font.params.posY = translation.y + scale.y - 2; + font.params.posY = translation.y + scale.y - 2 - margin_bottom; break; case wi::font::WIFALIGN_CENTER: default: diff --git a/WickedEngine/wiGUI.h b/WickedEngine/wiGUI.h index 6b699f0d62..a23ae574e1 100644 --- a/WickedEngine/wiGUI.h +++ b/WickedEngine/wiGUI.h @@ -119,6 +119,7 @@ namespace wi::gui bool highlight = false; XMFLOAT3 highlight_color = XMFLOAT3(1, 1, 1); float highlight_spread = 1; + float border_soften = 0; void Apply(wi::image::Params& params) const { @@ -209,6 +210,7 @@ namespace wi::gui } } font; + float shadow = 1; // shadow radius wi::Color shadow_color = wi::Color::Shadow(); // shadow color for whole widget bool shadow_highlight = false; XMFLOAT3 shadow_highlight_color = XMFLOAT3(1, 1, 1); @@ -216,6 +218,7 @@ namespace wi::gui Image tooltipImage; Font tooltipFont; + float tooltip_shadow = 1; // shadow radius wi::Color tooltip_shadow_color = wi::Color::Shadow(); }; @@ -462,6 +465,11 @@ namespace wi::gui ScrollBar scrollbar; void SetWrapEnabled(bool value) { wrap_enabled = value; } + + float margin_left = 0; + float margin_right = 0; + float margin_top = 0; + float margin_bottom = 0; }; // Text input box diff --git a/WickedEngine/wiRandom.h b/WickedEngine/wiRandom.h index 7ed8a0da02..fc82e31309 100644 --- a/WickedEngine/wiRandom.h +++ b/WickedEngine/wiRandom.h @@ -30,11 +30,15 @@ namespace wi::random // gives an uint64 in range [min, max] inline uint64_t next_uint(uint64_t min, uint64_t max) { + if (min == max) + return min; return min + (next_uint() % (std::min(std::numeric_limits::max() - uint64_t(1), std::max(uint64_t(1), max - min)) + uint64_t(1))); } // gives an uint32 in range [min, max] inline uint32_t next_uint(uint32_t min, uint32_t max) { + if (min == max) + return min; return min + (uint32_t(next_uint()) % (std::min(std::numeric_limits::max() - uint32_t(1), std::max(uint32_t(1), max - min)) + uint32_t(1))); } @@ -47,11 +51,15 @@ namespace wi::random // gives an int64 in range [min, max] inline int64_t next_int(int64_t min, int64_t max) { + if (min == max) + return min; return min + int64_t(next_uint() % (std::min(std::numeric_limits::max() - int64_t(1), std::max(int64_t(1), max - min)) + int64_t(1))); // we roll next_uint here to avoid negative value messing with range mapping } // gives an int32 in range [min, max] inline int32_t next_int(int32_t min, int32_t max) { + if (min == max) + return min; return min + int32_t(next_uint() % (std::min(std::numeric_limits::max() - int32_t(1), std::max(int32_t(1), max - min)) + int32_t(1))); // we roll next_uint here to avoid negative value messing with range mapping } diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 91c0824e8b..7ddab4e40e 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -6217,6 +6217,10 @@ void DrawShadowmaps( const ObjectComponent& object = vis.scene->objects[i]; if (object.IsRenderable() && object.IsCastingShadow()) { + const float distance = wi::math::Distance(vis.camera->Eye, object.center); + if (distance > object.draw_distance + object.radius) // Note: here I use draw_distance instead of fadeDeistance because this doesn't account for impostor switch fade + continue; + // Determine which cascades the object is contained in: uint8_t camera_mask = 0; uint8_t shadow_lod = 0xFF; @@ -6338,6 +6342,10 @@ void DrawShadowmaps( const ObjectComponent& object = vis.scene->objects[i]; if (object.IsRenderable() && object.IsCastingShadow()) { + const float distance = wi::math::Distance(vis.camera->Eye, object.center); + if (distance > object.draw_distance + object.radius) // Note: here I use draw_distance instead of fadeDeistance because this doesn't account for impostor switch fade + continue; + uint8_t shadow_lod = 0xFF; uint8_t candidate_lod = (uint8_t)vis.scene->ComputeObjectLODForView(object, aabb, vis.scene->meshes[object.mesh_index], shcam.view_projection); shadow_lod = std::min(shadow_lod, candidate_lod); @@ -6490,6 +6498,10 @@ void DrawShadowmaps( const ObjectComponent& object = vis.scene->objects[i]; if (object.IsRenderable() && object.IsCastingShadow()) { + const float distance = wi::math::Distance(vis.camera->Eye, object.center); + if (distance > object.draw_distance + object.radius) // Note: here I use draw_distance instead of fadeDeistance because this doesn't account for impostor switch fade + continue; + // Check for each frustum, if object is visible from it: uint8_t camera_mask = 0; uint8_t shadow_lod = 0xFF; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index b4cdb2d294..546c4cfaab 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 688; + const int revision = 689; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);