aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Xbox/Font/XUI_Font.h
diff options
context:
space:
mode:
authordaoge_cmd <3523206925@qq.com>2026-03-01 12:16:08 +0800
committerdaoge_cmd <3523206925@qq.com>2026-03-01 12:16:08 +0800
commitb691c43c44ff180d10e7d4a9afc83b98551ff586 (patch)
tree3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.Client/Xbox/Font/XUI_Font.h
parentdef8cb415354ac390b7e89052a50605285f1aca9 (diff)
Initial commit
Diffstat (limited to 'Minecraft.Client/Xbox/Font/XUI_Font.h')
-rw-r--r--Minecraft.Client/Xbox/Font/XUI_Font.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/Minecraft.Client/Xbox/Font/XUI_Font.h b/Minecraft.Client/Xbox/Font/XUI_Font.h
new file mode 100644
index 00000000..1b6278e3
--- /dev/null
+++ b/Minecraft.Client/Xbox/Font/XUI_Font.h
@@ -0,0 +1,93 @@
+#pragma once
+
+class XUI_FontData;
+
+// 4J This class is partially based of the ATG font implementation, modified to suit our uses for XUI
+
+//--------------------------------------------------------------------------------------
+// Flags for the Font::DrawText() function (Or them together to combine features)
+//--------------------------------------------------------------------------------------
+#define ATGFONT_LEFT 0x00000000
+#define ATGFONT_RIGHT 0x00000001
+#define ATGFONT_CENTER_X 0x00000002
+#define ATGFONT_CENTER_Y 0x00000004
+#define ATGFONT_TRUNCATED 0x00000008
+
+class XUI_Font
+{
+public:
+ XUI_FontData *m_fontData;
+
+public:
+ const int m_iFontData;
+ const float m_fScaleFactor;
+
+ FLOAT m_fXScaleFactor; // Scaling constants
+ FLOAT m_fYScaleFactor;
+ FLOAT m_fSlantFactor; // For italics
+ DOUBLE m_dRotCos; // Precalculated sine and cosine for italic like rotation
+ DOUBLE m_dRotSin;
+
+ D3DRECT m_rcWindow; // Bounds rect if the text window, modify via accessors only!
+ FLOAT m_fCursorX; // Current text cursor
+ FLOAT m_fCursorY;
+
+ BOOL m_bRotate;
+
+ DWORD m_dwNestedBeginCount;
+
+ wstring m_fontName;
+ wstring m_fallbackFont;
+ DWORD refCount;
+public:
+ float getScaleFactor() { return m_fScaleFactor; }
+ void GetScaleFactors(FLOAT *pfXScaleFactor, FLOAT *pfYScaleFactor) { *pfXScaleFactor = m_fScaleFactor; *pfYScaleFactor = m_fScaleFactor; }
+ // Accessor functions
+ inline VOID SetSlantFactor( FLOAT fSlantFactor )
+ {
+ m_fSlantFactor = fSlantFactor;
+ }
+
+ inline VOID SetScaleFactors( FLOAT fXScaleFactor, FLOAT fYScaleFactor )
+ {
+ // m_fXScaleFactor = m_fYScaleFactor = m_fScaleFactor;
+ }
+
+ void SetFallbackFont(const wstring &fallbackFont) { m_fallbackFont = fallbackFont; }
+ void IncRefCount() { ++refCount; }
+ void DecRefCount() { --refCount; }
+
+public:
+ XUI_Font(int iFontData, float scaleFactor, XUI_FontData *fontData);
+ ~XUI_Font();
+
+ // Returns the dimensions of a text string
+ VOID GetTextExtent( const WCHAR* strText, FLOAT* pWidth,
+ FLOAT* pHeight, BOOL bFirstLineOnly=FALSE ) const;
+ FLOAT GetTextWidth( const WCHAR* strText ) const;
+ FLOAT GetCharAdvance( const WCHAR* strChar ) const;
+
+ VOID SetWindow(const D3DRECT &rcWindow );
+ VOID SetWindow( LONG x1, LONG y1, LONG x2, LONG y2 );
+ VOID GetWindow(D3DRECT &rcWindow) const;
+ VOID SetCursorPosition( FLOAT fCursorX, FLOAT fCursorY );
+ VOID SetRotationFactor( FLOAT fRotationFactor );
+
+ // Function to create a texture containing rendered text
+ D3DTexture* CreateTexture( const WCHAR* strText,
+ D3DCOLOR dwBackgroundColor = 0x00000000,
+ D3DCOLOR dwTextColor = 0xffffffff,
+ D3DFORMAT d3dFormat = D3DFMT_A8R8G8B8 );
+
+ // Public calls to render text. Callers can simply call DrawText(), but for
+ // performance, they should batch multiple calls together, bracketed by calls to
+ // Begin() and End().
+ VOID Begin();
+ VOID DrawText( DWORD dwColor, const WCHAR* strText, DWORD dwFlags=0L,
+ FLOAT fMaxPixelWidth = 0.0f );
+ VOID DrawText( FLOAT sx, FLOAT sy, DWORD dwColor, const WCHAR* strText,
+ DWORD dwFlags=0L, FLOAT fMaxPixelWidth = 0.0f, bool darken = false );
+ VOID DrawShadowText( FLOAT sx, FLOAT sy, DWORD dwColor, DWORD dwShadowColor, const WCHAR* strText,
+ DWORD dwFlags=0L, FLOAT fMaxPixelWidth = 0.0f );
+ VOID End();
+}; \ No newline at end of file