GuiSys Image geometry fixes

This commit is contained in:
Jack Andersen 2017-01-29 20:58:59 -10:00
parent e276bd3be9
commit 83baca806d
9 changed files with 38 additions and 36 deletions

View File

@ -34,20 +34,29 @@ void CTextSupportShader::CharacterInstance::SetMetrics(const CGlyph& glyph,
m_uv[3].assign(glyph.GetEndU(), 1.f - glyph.GetEndV(), layer);
}
void CTextSupportShader::ImageInstance::SetMetrics(const zeus::CVector2f& imgSize,
void CTextSupportShader::ImageInstance::SetMetrics(const CFontImageDef& imgDef,
const zeus::CVector2i& offset)
{
zeus::CVector2f imgSize;
if (imgDef.x4_texs.size())
{
const CTexture& tex = *imgDef.x4_texs[0].GetObj();
imgSize.assign(tex.GetWidth() * imgDef.x14_cropFactor.x,
tex.GetHeight() * imgDef.x14_cropFactor.y);
}
zeus::CVector2f cropPad = imgDef.x14_cropFactor * 0.5f;
m_pos[0].assign(offset.x, 0.f, offset.y);
m_uv[0].assign(0.f, 1.f);
m_uv[0].assign(0.5f - cropPad.x, 0.5f + cropPad.y);
m_pos[1].assign(offset.x + imgSize.x, 0.f, offset.y);
m_uv[1].assign(1.f, 1.f);
m_uv[1].assign(0.5f + cropPad.x, 0.5f + cropPad.y);
m_pos[2].assign(offset.x, 0.f, offset.y + imgSize.y);
m_uv[2].assign(0.f, 0.f);
m_uv[2].assign(0.5f - cropPad.x, 0.5f - cropPad.y);
m_pos[3].assign(offset.x + imgSize.x, 0.f, offset.y + imgSize.y);
m_uv[3].assign(1.f, 0.f);
m_uv[3].assign(0.5f + cropPad.x, 0.5f - cropPad.y);
}
void CTextSupportShader::Shutdown()

View File

@ -10,6 +10,7 @@ namespace urde
{
class CGlyph;
class CTextRenderBuffer;
class CFontImageDef;
class CTextSupportShader
{
@ -48,7 +49,7 @@ class CTextSupportShader
zeus::CVector3f m_pos[4];
zeus::CVector2f m_uv[4];
zeus::CColor m_color;
void SetMetrics(const zeus::CVector2f& imgSize, const zeus::CVector2i& offset);
void SetMetrics(const CFontImageDef& imgDef, const zeus::CVector2i& offset);
};
static hecl::VertexBufferPool<CharacterInstance> s_CharInsts;

View File

@ -5,16 +5,16 @@ namespace urde
{
CFontImageDef::CFontImageDef(const std::vector<TToken<CTexture>>& texs,
float interval, const zeus::CVector2f& vec)
: x0_fps(interval), x14_pointsPerTexel(vec)
float interval, const zeus::CVector2f& cropFactor)
: x0_fps(interval), x14_cropFactor(cropFactor)
{
x4_texs.reserve(texs.size());
for (const TToken<CTexture>& tok : texs)
x4_texs.push_back(tok);
}
CFontImageDef::CFontImageDef(const TToken<CTexture>& tex, const zeus::CVector2f& vec)
: x0_fps(0.f), x14_pointsPerTexel(vec)
CFontImageDef::CFontImageDef(const TToken<CTexture>& tex, const zeus::CVector2f& cropFactor)
: x0_fps(0.f), x14_cropFactor(cropFactor)
{
x4_texs.push_back(tex);
}
@ -30,13 +30,13 @@ bool CFontImageDef::IsLoaded() const
s32 CFontImageDef::CalculateBaseline() const
{
const CTexture* tex = x4_texs.front().GetObj();
return s32(tex->GetHeight() * x14_pointsPerTexel.y) * 2.5f / 3.f;
return s32(tex->GetHeight() * x14_cropFactor.y) * 2.5f / 3.f;
}
s32 CFontImageDef::CalculateHeight() const
{
const CTexture* tex = x4_texs.front().GetObj();
s32 scaledH = tex->GetHeight() * x14_pointsPerTexel.y;
s32 scaledH = tex->GetHeight() * x14_cropFactor.y;
return scaledH - (scaledH - CalculateBaseline());
}

View File

@ -14,11 +14,11 @@ class CFontImageDef
public:
float x0_fps;
std::vector<TLockedToken<CTexture>> x4_texs;
zeus::CVector2f x14_pointsPerTexel;
zeus::CVector2f x14_cropFactor;
CFontImageDef(const std::vector<TToken<CTexture>>& texs, float fps,
const zeus::CVector2f& vec);
CFontImageDef(const TToken<CTexture>& tex, const zeus::CVector2f& vec);
const zeus::CVector2f& cropFactor);
CFontImageDef(const TToken<CTexture>& tex, const zeus::CVector2f& cropFactor);
bool IsLoaded() const;
s32 CalculateBaseline() const;
s32 CalculateHeight() const;

View File

@ -84,12 +84,12 @@ void CGuiSys::ViewportResizeFrame(CGuiFrame* frame)
if (vpAspectRatio >= frame->m_aspectConstraint)
{
hPad = frame->m_aspectConstraint / vpAspectRatio;
vPad = frame->m_aspectConstraint / 1.36f;
vPad = frame->m_aspectConstraint / 1.38f;
}
else
{
hPad = 1.f;
vPad = vpAspectRatio / 1.36f;
vPad = vpAspectRatio / 1.38f;
}
frame->m_aspectTransform = zeus::CTransform::Scale({hPad, 1.f, vPad});
}

View File

@ -252,11 +252,11 @@ void CImageInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf)
zeus::CVector2i coords(state.xd4_curX, y);
buf->AddImage(coords, x4_image);
}
state.xd4_curX = state.xd4_curX + tex->GetWidth() * x4_image.x14_pointsPerTexel.y;
state.xd4_curX = state.xd4_curX + tex->GetWidth() * x4_image.x14_cropFactor.y;
}
else
{
int scale = state.xdc_currentLineInst->x8_curX - tex->GetWidth() * x4_image.x14_pointsPerTexel.y;
int scale = state.xdc_currentLineInst->x8_curX - tex->GetWidth() * x4_image.x14_cropFactor.y;
if (buf)
{
zeus::CVector2i coords(scale / 2 + state.xd4_curX, state.xd8_curY);

View File

@ -387,8 +387,8 @@ void CTextExecuteBuffer::AddImage(const CFontImageDef& image)
if (xa0_curBlock)
{
const CTexture* tex = image.x4_texs[0].GetObj();
int width = tex->GetWidth() * image.x14_pointsPerTexel.x;
int height = tex->GetHeight() * image.x14_pointsPerTexel.y;
int width = tex->GetWidth() * image.x14_cropFactor.x;
int height = tex->GetHeight() * image.x14_cropFactor.y;
if (xa4_curLine->x8_curX + width > xa0_curBlock->xc_blockExtentX && xa4_curLine->x4_wordCount > 0)
StartNewLine();

View File

@ -250,11 +250,11 @@ CFontImageDef CTextParser::GetImage(const char16_t* str, int len)
AdvanceTokenPos();
AdvanceCommaPos();
float scaleX = u16stof(&iterable[tokenPos]);
float cropX = u16stof(&iterable[tokenPos]);
AdvanceTokenPos();
AdvanceCommaPos();
float scaleY = u16stof(&iterable[tokenPos]);
float cropY = u16stof(&iterable[tokenPos]);
AdvanceTokenPos();
std::vector<TToken<CTexture>> texs;
@ -267,17 +267,17 @@ CFontImageDef CTextParser::GetImage(const char16_t* str, int len)
AdvanceTokenPos();
} while (commaPos != iterable.size());
return CFontImageDef(texs, interval, zeus::CVector2f(scaleX, scaleY));
return CFontImageDef(texs, interval, zeus::CVector2f(cropX, cropY));
}
else if (BeginsWith(str, len, u"SI"))
{
/* Scaled single texture */
AdvanceCommaPos();
float scaleX = u16stof(&iterable[tokenPos]);
float cropX = u16stof(&iterable[tokenPos]);
AdvanceTokenPos();
AdvanceCommaPos();
float scaleY = u16stof(&iterable[tokenPos]);
float cropY = u16stof(&iterable[tokenPos]);
AdvanceTokenPos();
AdvanceCommaPos();
@ -285,7 +285,7 @@ CFontImageDef CTextParser::GetImage(const char16_t* str, int len)
GetAssetIdFromString(&iterable[tokenPos])});
AdvanceTokenPos();
return CFontImageDef(tex, zeus::CVector2f(scaleX, scaleY));
return CFontImageDef(tex, zeus::CVector2f(cropX, cropY));
}
}

View File

@ -18,15 +18,7 @@ CTextRenderBuffer::CTextRenderBuffer(EMode mode, CGuiWidget::EGuiModelDrawFlags
CTextRenderBuffer::BooImage::BooImage(const CFontImageDef& imgDef, const zeus::CVector2i& offset)
: m_imageDef(imgDef)
{
zeus::CVector2f imgSize;
if (imgDef.x4_texs.size())
{
const CTexture& tex = *imgDef.x4_texs[0].GetObj();
imgSize.assign(tex.GetWidth() * imgDef.x14_pointsPerTexel.x,
tex.GetHeight() * imgDef.x14_pointsPerTexel.y);
}
m_imageData.SetMetrics(imgSize, offset);
m_imageData.SetMetrics(imgDef, offset);
}
void CTextRenderBuffer::BooPrimitiveMark::SetOpacity(CTextRenderBuffer& rb, float opacity)