2016-03-19 00:07:31 +00:00
|
|
|
#include "CInstruction.hpp"
|
|
|
|
#include "CFontRenderState.hpp"
|
2016-03-19 03:58:01 +00:00
|
|
|
#include "CTextRenderBuffer.hpp"
|
2016-03-20 06:37:08 +00:00
|
|
|
#include "CRasterFont.hpp"
|
2016-03-21 00:25:53 +00:00
|
|
|
#include "Graphics/CTexture.hpp"
|
2016-03-19 00:07:31 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
void CInstruction::GetAssets(std::vector<CToken>& assetsOut) const
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CInstruction::GetAssetCount() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CColorInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
|
|
|
|
{
|
|
|
|
state.SetColor(x4_cType, x8_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CColorOverrideInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
|
|
|
|
{
|
2016-03-21 00:25:53 +00:00
|
|
|
state.x30_colorOverrides[x4_overrideIdx] = true;
|
2016-03-19 00:07:31 +00:00
|
|
|
zeus::CColor convCol = state.ConvertToTextureSpace(x8_color);
|
2016-03-21 00:25:53 +00:00
|
|
|
state.x0_drawStrOpts.x4_colors[x4_overrideIdx] = convCol;
|
2016-03-19 00:07:31 +00:00
|
|
|
}
|
|
|
|
|
2016-03-19 03:58:01 +00:00
|
|
|
void CFontInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
|
|
|
|
{
|
|
|
|
buf->AddFontChange(x4_font);
|
2016-03-20 06:37:08 +00:00
|
|
|
state.x14_font = x4_font;
|
2016-03-19 03:58:01 +00:00
|
|
|
state.RefreshPalette();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFontInstruction::GetAssets(std::vector<CToken>& assetsOut) const
|
|
|
|
{
|
|
|
|
assetsOut.push_back(x4_font);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CFontInstruction::GetAssetCount() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-03-20 00:32:30 +00:00
|
|
|
void CLineExtraSpaceInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
|
2016-03-19 03:58:01 +00:00
|
|
|
{
|
|
|
|
state.x44_extraLineSpace = x4_extraSpace;
|
|
|
|
}
|
|
|
|
|
2016-03-20 06:37:08 +00:00
|
|
|
void CLineInstruction::TestLargestFont(s32 monoW, s32 monoH, s32 baseline)
|
2016-03-19 03:58:01 +00:00
|
|
|
{
|
2016-03-20 00:32:30 +00:00
|
|
|
if (!x18_largestBaseline)
|
2016-03-20 06:37:08 +00:00
|
|
|
x18_largestBaseline = baseline;
|
2016-03-20 00:32:30 +00:00
|
|
|
|
2016-03-20 06:37:08 +00:00
|
|
|
if (x14_largestMonoWidth < monoW)
|
|
|
|
monoW = x14_largestMonoWidth;
|
2016-03-20 00:32:30 +00:00
|
|
|
|
2016-03-20 06:37:08 +00:00
|
|
|
if (x10_largestMonoHeight < monoH)
|
2016-03-20 00:32:30 +00:00
|
|
|
{
|
2016-03-20 06:37:08 +00:00
|
|
|
x10_largestMonoHeight = monoH;
|
|
|
|
x18_largestBaseline = baseline;
|
2016-03-20 00:32:30 +00:00
|
|
|
}
|
2016-03-19 03:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLineInstruction::InvokeLTR(CFontRenderState& state) const
|
|
|
|
{
|
2016-03-20 06:37:08 +00:00
|
|
|
switch (x1c_just)
|
|
|
|
{
|
2016-03-21 00:25:53 +00:00
|
|
|
case EJustification::Left:
|
|
|
|
case EJustification::Full:
|
|
|
|
case EJustification::NLeft:
|
2016-03-20 06:37:08 +00:00
|
|
|
case EJustification::Seven:
|
|
|
|
state.x6c_curX = state.x54_curBlock->x4_offsetX;
|
|
|
|
break;
|
2016-03-21 00:25:53 +00:00
|
|
|
case EJustification::Center:
|
2016-03-20 06:37:08 +00:00
|
|
|
case EJustification::Eight:
|
|
|
|
state.x6c_curX = state.x54_curBlock->x4_offsetX +
|
2016-03-22 02:27:46 +00:00
|
|
|
state.x54_curBlock->xc_blockExtentX / 2 - x8_curX / 2;
|
2016-03-20 06:37:08 +00:00
|
|
|
break;
|
2016-03-21 00:25:53 +00:00
|
|
|
case EJustification::NCenter:
|
|
|
|
if (x4_wordCount == 1)
|
2016-03-20 06:37:08 +00:00
|
|
|
{
|
|
|
|
state.x6c_curX = state.x54_curBlock->x4_offsetX +
|
2016-03-22 02:27:46 +00:00
|
|
|
state.x54_curBlock->xc_blockExtentX / 2 - x8_curX / 2;
|
2016-03-20 06:37:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state.x6c_curX = state.x54_curBlock->x4_offsetX +
|
2016-03-22 02:27:46 +00:00
|
|
|
state.x54_curBlock->xc_blockExtentX / 2 -
|
2016-03-20 06:37:08 +00:00
|
|
|
state.x54_curBlock->x2c_lineX / 2;
|
|
|
|
}
|
|
|
|
break;
|
2016-03-21 00:25:53 +00:00
|
|
|
case EJustification::Right:
|
2016-03-20 06:37:08 +00:00
|
|
|
case EJustification::Nine:
|
|
|
|
state.x6c_curX = state.x54_curBlock->x4_offsetX +
|
2016-03-22 02:27:46 +00:00
|
|
|
state.x54_curBlock->xc_blockExtentX - x8_curX;
|
2016-03-20 06:37:08 +00:00
|
|
|
break;
|
2016-03-21 00:25:53 +00:00
|
|
|
case EJustification::NRight:
|
2016-03-20 06:37:08 +00:00
|
|
|
state.x6c_curX = state.x54_curBlock->x4_offsetX +
|
2016-03-22 02:27:46 +00:00
|
|
|
state.x54_curBlock->xc_blockExtentX -
|
2016-03-20 06:37:08 +00:00
|
|
|
state.x54_curBlock->x2c_lineX;
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.x74_currentLineInst)
|
|
|
|
{
|
|
|
|
const CLineInstruction& inst = *state.x74_currentLineInst;
|
|
|
|
s32 val = 0;
|
|
|
|
switch (state.x54_curBlock->x1c_vertJustification)
|
|
|
|
{
|
2016-03-21 00:25:53 +00:00
|
|
|
case EVerticalJustification::Top:
|
|
|
|
case EVerticalJustification::Center:
|
|
|
|
case EVerticalJustification::Bottom:
|
|
|
|
case EVerticalJustification::NTop:
|
|
|
|
case EVerticalJustification::NCenter:
|
|
|
|
case EVerticalJustification::NBottom:
|
2016-03-20 06:37:08 +00:00
|
|
|
val = inst.xc_curY;
|
|
|
|
break;
|
2016-03-21 00:25:53 +00:00
|
|
|
case EVerticalJustification::Full:
|
2016-03-22 02:27:46 +00:00
|
|
|
val = state.x54_curBlock->x10_blockExtentY - state.x54_curBlock->x30_lineY;
|
2016-03-20 06:37:08 +00:00
|
|
|
if (state.x54_curBlock->x34_lineCount > 1)
|
|
|
|
val /= state.x54_curBlock->x34_lineCount - 1;
|
|
|
|
else
|
|
|
|
val = 0;
|
|
|
|
val += inst.xc_curY;
|
|
|
|
break;
|
|
|
|
case EVerticalJustification::Seven:
|
|
|
|
val = state.x54_curBlock->x24_largestMonoH;
|
|
|
|
break;
|
|
|
|
case EVerticalJustification::Eight:
|
|
|
|
val = (inst.xc_curY - state.x54_curBlock->x24_largestMonoH) / 2 +
|
|
|
|
state.x54_curBlock->x24_largestMonoH;
|
|
|
|
break;
|
|
|
|
case EVerticalJustification::Nine:
|
|
|
|
val = state.x54_curBlock->x24_largestMonoH * 2 - inst.xc_curY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-03-21 00:25:53 +00:00
|
|
|
if (state.x54_curBlock->x1c_vertJustification != EVerticalJustification::Full)
|
2016-03-20 06:37:08 +00:00
|
|
|
val = val * state.x40_lineSpacing + state.x44_extraLineSpace;
|
|
|
|
|
|
|
|
state.x70_curY += val;
|
|
|
|
}
|
2016-03-19 03:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLineInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
|
|
|
|
{
|
|
|
|
InvokeLTR(state);
|
2016-03-21 00:25:53 +00:00
|
|
|
state.xa0_lineInitialized = true;
|
2016-03-19 03:58:01 +00:00
|
|
|
state.x74_currentLineInst = this;
|
|
|
|
}
|
|
|
|
|
2016-03-21 00:25:53 +00:00
|
|
|
void CLineSpacingInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
|
|
|
|
{
|
|
|
|
state.x40_lineSpacing = x4_lineSpacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPopStateInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
|
|
|
|
{
|
|
|
|
state.PopState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPushStateInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
|
|
|
|
{
|
|
|
|
state.PushState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRemoveColorOverrideInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
|
|
|
|
{
|
|
|
|
state.x30_colorOverrides[x4_idx] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CImageInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
|
|
|
|
{
|
|
|
|
if (x4_image.IsLoaded() && x4_image.x4_texs.size())
|
|
|
|
{
|
|
|
|
if (state.x54_curBlock->x14_direction == ETextDirection::Horizontal)
|
|
|
|
{
|
|
|
|
const CTexture* tex = x4_image.x4_texs[0].GetObj();
|
|
|
|
if (buf)
|
|
|
|
{
|
|
|
|
zeus::CVector2i coords(state.x6c_curX,
|
|
|
|
state.x70_curY + state.x74_currentLineInst->x18_largestBaseline -
|
|
|
|
tex->GetHeight() * x4_image.x14_pointsPerTexel.y * 2 / 3);
|
|
|
|
buf->AddImage(coords, x4_image);
|
|
|
|
}
|
|
|
|
state.x6c_curX += tex->GetWidth() * x4_image.x14_pointsPerTexel.x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-20 06:37:08 +00:00
|
|
|
void CTextInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
|
2016-03-20 00:32:30 +00:00
|
|
|
{
|
2016-03-20 06:37:08 +00:00
|
|
|
int xOut, yOut;
|
|
|
|
state.x14_font.GetObj()->DrawString(state.x0_drawStrOpts, state.x6c_curX,
|
|
|
|
state.x74_currentLineInst->x18_largestBaseline + state.x70_curY,
|
|
|
|
xOut, yOut, buf, x4_str.c_str(), x4_str.size());
|
|
|
|
state.x6c_curX = xOut;
|
2016-03-20 00:32:30 +00:00
|
|
|
}
|
|
|
|
|
2016-03-20 06:37:08 +00:00
|
|
|
void CBlockInstruction::TestLargestFont(s32 monoW, s32 monoH, s32 baseline)
|
|
|
|
{
|
|
|
|
if (!x28_largestBaseline)
|
|
|
|
x28_largestBaseline = baseline;
|
|
|
|
|
|
|
|
if (x20_largestMonoW < monoW)
|
|
|
|
monoW = x20_largestMonoW;
|
|
|
|
|
|
|
|
if (x24_largestMonoH < monoH)
|
|
|
|
{
|
|
|
|
x24_largestMonoH = monoH;
|
|
|
|
x28_largestBaseline = baseline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBlockInstruction::SetupPositionLTR(CFontRenderState& state) const
|
|
|
|
{
|
|
|
|
switch (x1c_vertJustification)
|
|
|
|
{
|
2016-03-21 00:25:53 +00:00
|
|
|
case EVerticalJustification::Top:
|
|
|
|
case EVerticalJustification::Full:
|
|
|
|
case EVerticalJustification::NTop:
|
2016-03-20 06:37:08 +00:00
|
|
|
case EVerticalJustification::Seven:
|
|
|
|
state.x70_curY = x8_offsetY;
|
|
|
|
break;
|
2016-03-21 00:25:53 +00:00
|
|
|
case EVerticalJustification::Center:
|
|
|
|
case EVerticalJustification::NCenter:
|
2016-03-22 02:27:46 +00:00
|
|
|
state.x70_curY = x8_offsetY + (x10_blockExtentY - x30_lineY) / 2;
|
2016-03-20 06:37:08 +00:00
|
|
|
break;
|
|
|
|
case EVerticalJustification::Eight:
|
2016-03-22 02:27:46 +00:00
|
|
|
state.x70_curY = x8_offsetY + (x10_blockExtentY - x34_lineCount * x24_largestMonoH) / 2;
|
2016-03-20 06:37:08 +00:00
|
|
|
break;
|
2016-03-21 00:25:53 +00:00
|
|
|
case EVerticalJustification::Bottom:
|
|
|
|
case EVerticalJustification::NBottom:
|
2016-03-22 02:27:46 +00:00
|
|
|
state.x70_curY = x8_offsetY + x10_blockExtentY - x30_lineY;
|
2016-03-20 06:37:08 +00:00
|
|
|
break;
|
|
|
|
case EVerticalJustification::Nine:
|
2016-03-22 02:27:46 +00:00
|
|
|
state.x70_curY = x8_offsetY + x10_blockExtentY - x34_lineCount * x24_largestMonoH;
|
2016-03-20 06:37:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBlockInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
|
2016-03-20 00:32:30 +00:00
|
|
|
{
|
2016-03-20 06:37:08 +00:00
|
|
|
state.x0_drawStrOpts.x0_direction = x14_direction;
|
|
|
|
state.x54_curBlock = (CBlockInstruction*)this;
|
|
|
|
if (x14_direction == ETextDirection::Horizontal)
|
|
|
|
SetupPositionLTR(state);
|
2016-03-20 00:32:30 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 00:25:53 +00:00
|
|
|
void CWordInstruction::InvokeLTR(CFontRenderState& state) const
|
|
|
|
{
|
|
|
|
CRasterFont* font = state.x14_font.GetObj();
|
|
|
|
wchar_t space = L' ';
|
|
|
|
int w, h;
|
|
|
|
font->GetSize(state.x0_drawStrOpts, w, h, &space, 1);
|
|
|
|
|
|
|
|
const CLineInstruction& inst = *state.x74_currentLineInst;
|
|
|
|
switch (state.x54_curBlock->x18_justification)
|
|
|
|
{
|
|
|
|
case EJustification::Full:
|
2016-03-22 02:27:46 +00:00
|
|
|
w += (state.x54_curBlock->xc_blockExtentX - inst.x8_curX) / (inst.x4_wordCount - 1);
|
2016-03-21 00:25:53 +00:00
|
|
|
break;
|
|
|
|
case EJustification::NLeft:
|
|
|
|
case EJustification::NCenter:
|
|
|
|
case EJustification::NRight:
|
|
|
|
w += (state.x54_curBlock->x2c_lineX - inst.x8_curX) / (inst.x4_wordCount - 1);
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int wOut = state.x6c_curX;
|
|
|
|
font->DrawSpace(state.x0_drawStrOpts, wOut,
|
|
|
|
inst.xc_curY - font->GetMonoHeight() + state.x70_curY, wOut, h, w);
|
|
|
|
state.x6c_curX = wOut;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CWordInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
|
|
|
|
{
|
|
|
|
if (state.xa0_lineInitialized)
|
|
|
|
{
|
|
|
|
state.xa0_lineInitialized = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.x0_drawStrOpts.x0_direction == ETextDirection::Horizontal)
|
|
|
|
InvokeLTR(state);
|
|
|
|
}
|
|
|
|
|
2016-03-19 00:07:31 +00:00
|
|
|
}
|