Fix label size and text bounding box

This commit is contained in:
Georg Hagen
2025-01-13 23:46:05 +01:00
parent 2b87ed58b2
commit 968fa5a735
2 changed files with 5 additions and 7 deletions

View File

@@ -105,9 +105,9 @@ namespace OpenVulkano::Scene
Math::Vector2f padding = m_settings.padding * 2;
if (m_settings.hasArrow) padding.y += m_settings.arrowLength;
m_labelData.textSize = Math::Vector2f(m_bbox.GetSize()) + padding * 2;
m_labelData.bboxCenter = { m_bbox.GetCenter() };
if (m_settings.hasArrow) m_labelData.bboxCenter.y -= m_settings.arrowLength;
m_labelData.textSize = m_bbox.GetSize() + padding;
m_labelData.bboxCenter = m_bbox.GetCenter();
if (m_settings.hasArrow) m_labelData.bboxCenter.y -= m_settings.arrowLength * 0.5f;
}
std::optional<RayHit> LabelDrawable::Intersect(const Ray& ray) const

View File

@@ -9,9 +9,7 @@
#include "Shader/Shader.hpp"
#include "Scene/IFontAtlasGenerator.hpp"
#include "Base/Logger.hpp"
#include "Image/ImageLoader.hpp"
#include "DataFormat.hpp"
#include <fstream>
#include <utf8.h>
namespace OpenVulkano::Scene
@@ -97,7 +95,7 @@ namespace OpenVulkano::Scene
double cursorX = pos.x;
const double lineHeight = m_atlasData->GetLineHeight();
double posY = pos.y;
Math::Vector3f bmin(pos, 0), bmax(pos, 0);
Math::Vector2f bmin(pos), bmax(pos);
for (auto begin = text.begin(), end = text.end(); begin != end;)
{
uint32_t c = utf8::next(begin, end);
@@ -131,13 +129,13 @@ namespace OpenVulkano::Scene
// when setting for depth comparison operator will be available( <= )
cursorX += info.advance + 0.08;
if (!m_symbolCount) bmin.x = vertices->position[0].x;
bmax.x = std::max(bmax.x, vertices->position[1].x);
bmax.y = std::max(bmax.y, vertices->position[2].y);
bmin.y = std::min(bmin.y, vertices->position[1].y);
vertices++;
m_symbolCount++;
}
bmin.x = vertices->position[0].x;
m_bbox.Init(bmin, bmax);
if (!GetShader()) SetShader(GetDefaultShader(m_atlasData->GetAtlasType()));