metaforce/Runtime/GuiSys/CTextRenderBuffer.hpp

83 lines
2.5 KiB
C++
Raw Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
2016-03-19 00:07:31 +00:00
#include <utility>
#include <vector>
#include "Runtime/CToken.hpp"
#include "Runtime/RetroTypes.hpp"
#include "Runtime/Graphics/Shaders/CTextSupportShader.hpp"
#include "Runtime/GuiSys/CFontImageDef.hpp"
#include "Runtime/GuiSys/CGuiWidget.hpp"
#include <zeus/CColor.hpp>
#include <zeus/CMatrix4f.hpp>
#include <zeus/CVector2f.hpp>
#include <zeus/CVector2i.hpp>
2016-03-22 08:15:00 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
class CGlyph;
2016-03-19 00:07:31 +00:00
class CGraphicsPalette;
class CRasterFont;
2016-12-30 06:37:01 +00:00
class CTextExecuteBuffer;
2016-03-19 00:07:31 +00:00
2016-03-21 22:01:19 +00:00
using CTextColor = zeus::CColor;
2018-12-08 05:30:43 +00:00
class CTextRenderBuffer {
friend class CGuiTextSupport;
friend class CTextSupportShader;
2016-03-19 00:07:31 +00:00
public:
2022-05-14 06:47:29 +00:00
enum class Command { CharacterRender, ImageRender, FontChange, PaletteChange, Invalid = -1 };
struct Primitive {
CTextColor x0_color1;
Command x4_command;
s16 x8_xPos;
s16 xa_zPos;
char16_t xc_glyph;
u8 xe_imageIndex;
};
2018-12-08 05:30:43 +00:00
enum class EMode { AllocTally, BufferFill };
2016-03-22 08:15:00 +00:00
2016-03-19 00:07:31 +00:00
private:
2018-12-08 05:30:43 +00:00
EMode x0_mode;
std::vector<TToken<CRasterFont>> x4_fonts;
std::vector<CFontImageDef> x14_images;
std::vector<int> x24_primOffsets;
std::vector<char> x34_bytecode;
u32 x44_blobSize = 0;
u32 x48_curBytecodeOffset = 0;
2022-05-14 06:47:29 +00:00
s8 x4c_activeFont = -1;
s8 x4d_activePalette = -1;
s8 x4e_queuedFont = -1;
s8 x4f_queuedPalette = -1;
2022-05-14 06:47:29 +00:00
rstl::reserved_vector<std::unique_ptr<CGraphicsPalette>, 64> x50_palettes;
s32 x254_nextPalette = 0;
2016-03-22 08:15:00 +00:00
2016-03-19 00:07:31 +00:00
public:
CTextRenderBuffer(CTextRenderBuffer&& other) noexcept;
2022-05-14 06:47:29 +00:00
CTextRenderBuffer(EMode mode);
~CTextRenderBuffer();
CTextRenderBuffer& operator=(CTextRenderBuffer&& other) noexcept;
void SetPrimitive(const Primitive&, int);
[[nodiscard]] Primitive GetPrimitive(int) const;
2022-05-14 06:47:29 +00:00
[[nodiscard]] u32 GetPrimitiveCount() const { return x24_primOffsets.size(); }
[[nodiscard]] u8* GetOutStream();
[[nodiscard]] u32 GetCurLen();
void VerifyBuffer();
int GetMatchingPaletteIndex(const CGraphicsPalette& palette);
2022-05-14 06:47:29 +00:00
[[nodiscard]] CGraphicsPalette* GetNextAvailablePalette();
void AddPaletteChange(const CGraphicsPalette& palette);
2018-12-08 05:30:43 +00:00
void SetMode(EMode mode);
2022-05-14 06:47:29 +00:00
void Render(const CTextColor& col, float time);
2018-12-08 05:30:43 +00:00
void AddImage(const zeus::CVector2i& offset, const CFontImageDef& image);
2022-05-14 06:47:29 +00:00
void AddCharacter(const zeus::CVector2i& offset, char16_t ch, const CTextColor& color);
2018-12-08 05:30:43 +00:00
void AddFontChange(const TToken<CRasterFont>& font);
2022-05-14 06:47:29 +00:00
[[nodiscard]] bool HasSpaceAvailable(const zeus::CVector2i& origin, const zeus::CVector2i& extent);
[[nodiscard]] std::pair<zeus::CVector2i, zeus::CVector2i> AccumulateTextBounds();
2016-12-30 06:37:01 +00:00
};
2021-04-10 08:42:06 +00:00
} // namespace metaforce