Skip to content

Commit

Permalink
gui updates and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Feb 23, 2025
1 parent bc3cf30 commit 7993ebb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
25 changes: 17 additions & 8 deletions WickedEngine/wiGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
{
Expand All @@ -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:
Expand All @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions WickedEngine/wiGUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -209,13 +210,15 @@ 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);
float shadow_highlight_spread = 1;

Image tooltipImage;
Font tooltipFont;
float tooltip_shadow = 1; // shadow radius
wi::Color tooltip_shadow_color = wi::Color::Shadow();
};

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions WickedEngine/wiRandom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>::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<uint32_t>::max() - uint32_t(1), std::max(uint32_t(1), max - min)) + uint32_t(1)));
}

Expand All @@ -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<int64_t>::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<int32_t>::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
}

Expand Down
12 changes: 12 additions & 0 deletions WickedEngine/wiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 7993ebb

Please sign in to comment.