the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 93 lines 3.6 kB view raw
1#pragma once 2 3class XUI_FontData; 4 5// 4J This class is partially based of the ATG font implementation, modified to suit our uses for XUI 6 7//-------------------------------------------------------------------------------------- 8// Flags for the Font::DrawText() function (Or them together to combine features) 9//-------------------------------------------------------------------------------------- 10#define ATGFONT_LEFT 0x00000000 11#define ATGFONT_RIGHT 0x00000001 12#define ATGFONT_CENTER_X 0x00000002 13#define ATGFONT_CENTER_Y 0x00000004 14#define ATGFONT_TRUNCATED 0x00000008 15 16class XUI_Font 17{ 18public: 19 XUI_FontData *m_fontData; 20 21public: 22 const int m_iFontData; 23 const float m_fScaleFactor; 24 25 FLOAT m_fXScaleFactor; // Scaling constants 26 FLOAT m_fYScaleFactor; 27 FLOAT m_fSlantFactor; // For italics 28 DOUBLE m_dRotCos; // Precalculated sine and cosine for italic like rotation 29 DOUBLE m_dRotSin; 30 31 D3DRECT m_rcWindow; // Bounds rect if the text window, modify via accessors only! 32 FLOAT m_fCursorX; // Current text cursor 33 FLOAT m_fCursorY; 34 35 BOOL m_bRotate; 36 37 DWORD m_dwNestedBeginCount; 38 39 wstring m_fontName; 40 wstring m_fallbackFont; 41 DWORD refCount; 42public: 43 float getScaleFactor() { return m_fScaleFactor; } 44 void GetScaleFactors(FLOAT *pfXScaleFactor, FLOAT *pfYScaleFactor) { *pfXScaleFactor = m_fScaleFactor; *pfYScaleFactor = m_fScaleFactor; } 45 // Accessor functions 46 inline VOID SetSlantFactor( FLOAT fSlantFactor ) 47 { 48 m_fSlantFactor = fSlantFactor; 49 } 50 51 inline VOID SetScaleFactors( FLOAT fXScaleFactor, FLOAT fYScaleFactor ) 52 { 53 // m_fXScaleFactor = m_fYScaleFactor = m_fScaleFactor; 54 } 55 56 void SetFallbackFont(const wstring &fallbackFont) { m_fallbackFont = fallbackFont; } 57 void IncRefCount() { ++refCount; } 58 void DecRefCount() { --refCount; } 59 60public: 61 XUI_Font(int iFontData, float scaleFactor, XUI_FontData *fontData); 62 ~XUI_Font(); 63 64 // Returns the dimensions of a text string 65 VOID GetTextExtent( const WCHAR* strText, FLOAT* pWidth, 66 FLOAT* pHeight, BOOL bFirstLineOnly=FALSE ) const; 67 FLOAT GetTextWidth( const WCHAR* strText ) const; 68 FLOAT GetCharAdvance( const WCHAR* strChar ) const; 69 70 VOID SetWindow(const D3DRECT &rcWindow ); 71 VOID SetWindow( LONG x1, LONG y1, LONG x2, LONG y2 ); 72 VOID GetWindow(D3DRECT &rcWindow) const; 73 VOID SetCursorPosition( FLOAT fCursorX, FLOAT fCursorY ); 74 VOID SetRotationFactor( FLOAT fRotationFactor ); 75 76 // Function to create a texture containing rendered text 77 D3DTexture* CreateTexture( const WCHAR* strText, 78 D3DCOLOR dwBackgroundColor = 0x00000000, 79 D3DCOLOR dwTextColor = 0xffffffff, 80 D3DFORMAT d3dFormat = D3DFMT_A8R8G8B8 ); 81 82 // Public calls to render text. Callers can simply call DrawText(), but for 83 // performance, they should batch multiple calls together, bracketed by calls to 84 // Begin() and End(). 85 VOID Begin(); 86 VOID DrawText( DWORD dwColor, const WCHAR* strText, DWORD dwFlags=0L, 87 FLOAT fMaxPixelWidth = 0.0f ); 88 VOID DrawText( FLOAT sx, FLOAT sy, DWORD dwColor, const WCHAR* strText, 89 DWORD dwFlags=0L, FLOAT fMaxPixelWidth = 0.0f, bool darken = false ); 90 VOID DrawShadowText( FLOAT sx, FLOAT sy, DWORD dwColor, DWORD dwShadowColor, const WCHAR* strText, 91 DWORD dwFlags=0L, FLOAT fMaxPixelWidth = 0.0f ); 92 VOID End(); 93};