aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Xbox/Font/XUI_Font.h
blob: 1b6278e3c9a834f3ae65147a50db50e7ae54479b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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();
};