the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 147 lines 4.6 kB view raw
1#pragma once 2using namespace std; 3#include <xuirender.h> 4 5#include "..\..\Common\UI\UIFontData.h" 6 7// 4J This class is partially based of the ATG font implementation 8//-------------------------------------------------------------------------------------- 9// Name: GLYPH_ATTR 10// Desc: Structure to hold information about one glyph (font character image) 11//-------------------------------------------------------------------------------------- 12typedef struct GLYPH_ATTR 13{ 14 WORD tu1, tv1, tu2, tv2; // Texture coordinates for the image 15 SHORT wOffset; // Pixel offset for glyph start 16 SHORT wWidth; // Pixel width of the glyph 17 SHORT wAdvance; // Pixels to advance after the glyph 18 WORD wMask; // Channel mask 19} GLYPH_ATTR; 20 21// 22// These two structures are mapped to data loaded from disk. 23// DO NOT ALTER ANY ENTRIES OR YOU WILL BREAK 24// COMPATIBILITY WITH THE FONT FILE 25// 26 27// Font description 28 29#define ATGCALCFONTFILEHEADERSIZE(x) ( sizeof(DWORD) + (sizeof(FLOAT)*4) + sizeof(WORD) + (sizeof(WCHAR)*(x)) ) 30#define ATGFONTFILEVERSION 5 31 32typedef struct FontFileHeaderImage_t { 33 DWORD m_dwFileVersion; // Version of the font file (Must match FONTFILEVERSION) 34 FLOAT m_fFontHeight; // Height of the font strike in pixels 35 FLOAT m_fFontTopPadding; // Padding above the strike zone 36 FLOAT m_fFontBottomPadding; // Padding below the strike zone 37 FLOAT m_fFontYAdvance; // Number of pixels to move the cursor for a line feed 38 WORD m_cMaxGlyph; // Number of font characters (Should be an odd number to maintain DWORD Alignment) 39 WCHAR m_TranslatorTable[1]; // ASCII to Glyph lookup table, NOTE: It's m_cMaxGlyph+1 in size. 40 // Entry 0 maps to the "Unknown" glyph. 41} FontFileHeaderImage_t; 42 43// Font strike array. Immediately follows the FontFileHeaderImage_t 44// structure image 45 46typedef struct FontFileStrikesImage_t { 47 DWORD m_dwNumGlyphs; // Size of font strike array (First entry is the unknown glyph) 48 GLYPH_ATTR m_Glyphs[1]; // Array of font strike uv's etc... NOTE: It's m_dwNumGlyphs in size 49} FontFileStrikesImage_t; 50 51typedef struct _CharMetrics 52{ 53 // units are pixels at current font size 54 55 float fMinX; // min x coordinate 56 float fMinY; // min y coordinate 57 float fMaxX; // max x coordinate 58 float fMaxY; // max y coordinate 59 float fAdvance; // advance value 60} CharMetrics; 61 62class XUI_FontData 63{ 64public: 65 int getMaxGlyph(); 66 float getFontHeight(); 67 float getFontTopPadding(); 68 float getFontBottomPadding(); 69 float getFontYAdvance(); 70 float getFontMaxWidth(); 71 float getMaxDescent(); 72 float getMaxAscent(); 73 int getImageWidth(); 74 int getImageHeight(); 75 76 typedef struct 77 { 78 friend class XUI_FontData; 79 80 private: 81 unsigned short m_glyphId; 82 XUI_FontData *m_parent; 83 84 public: 85 bool hasChar() { return true; } 86 float getMinX(); 87 float getMinY(); 88 float getMaxX(); 89 float getMaxY(); 90 float getAdvance(); 91 int getGlyphId(); 92 int tu1(); 93 int tu2(); 94 int tv1(); 95 int tv2(); // Texture coordinates for the image 96 short getOffset(); // Pixel offset for glyph start 97 short getWidth(); // Pixel width of the glyph 98 short getWAdvance(); // Pixels to advance after the glyph 99 WORD getMask(); // Channel mask, tv2; 100 } SChar; 101 102 SChar getChar(const wchar_t strChar); 103 104 // D3D rendering objects 105 D3DTexture* m_pFontTexture; 106 int m_iFontTexture; 107 108private: 109 unordered_map<wchar_t, unsigned short> m_TranslatorMap; 110 111 CharMetrics *m_characterMetrics; 112 113 // Translator table for supporting unicode ranges 114 DWORD m_cMaxGlyph; // Number of entries in the translator table 115 116 // Glyph data for the font 117 DWORD m_dwNumGlyphs; // Number of valid glyphs 118 GLYPH_ATTR* m_Glyphs; // Array of glyphs 119 120 DWORD m_dwNestedBeginCount; 121 122 123protected: 124 CFontData *m_fontData; 125 126public: 127 // Accessor functions 128 inline D3DTexture* GetTexture() const 129 { 130 return m_pFontTexture; 131 } 132 133public: 134 XUI_FontData(); 135 ~XUI_FontData(); 136 137 // Functions to create and destroy the internal objects 138 HRESULT Create( SFontData &sfontdata ); 139 //HRESULT Create( D3DTexture* pFontTexture, const VOID* pFontData ); 140 HRESULT Create( int iFontTexture, const VOID* pFontData ); 141 VOID Destroy(); 142 143 //FLOAT GetCharAdvance( const WCHAR* strChar ); 144 //FLOAT GetCharWidth( const WCHAR* strChar ); 145 //void GetCharMetrics( const WCHAR* strChar, XUICharMetrics *xuiMetrics); 146 //unsigned short getGlyphId(wchar_t character); 147};