1 /*
2   LICENSE
3   -------
4 Copyright 2005-2013 Nullsoft, Inc.
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9 
10   * Redistributions of source code must retain the above copyright notice,
11     this list of conditions and the following disclaimer.
12 
13   * Redistributions in binary form must reproduce the above copyright notice,
14     this list of conditions and the following disclaimer in the documentation
15     and/or other materials provided with the distribution.
16 
17   * Neither the name of Nullsoft nor the names of its contributors may be used to
18     endorse or promote products derived from this software without specific prior written permission.
19 
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
21 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 
30 #ifndef GEISS_TEXT_DRAWING_MANAGER
31 #define GEISS_TEXT_DRAWING_MANAGER 1
32 
33 #ifdef _DEBUG
34     #define D3D_DEBUG_INFO  // declare this before including d3d9.h
35 #endif
36 #include <d3d9.h>
37 #include <d3dx9.h>
38 #include "md_defines.h"
39 #include "..\nu\AutoWide.h"
40 
41 #define MAX_MSGS 4096
42 
43 typedef struct
44 {
45     wchar_t* msg;       // points to some character in g_szMsgPool[2][].
46     LPD3DXFONT pfont;   // note: iff this string is really a dark box, pfont will be NULL!
47     RECT rect;
48     DWORD flags;
49     DWORD color;
50     DWORD bgColor;
51     int added, deleted;        // temporary; used during DrawNow()
52     void* prev_dark_box_ptr;   // temporary; used during DrawNow()
53 }
54 td_string;
55 
56 class CTextManager
57 {
58 public:
59     CTextManager();
60     ~CTextManager();
61 
62     // note: if you can't create lpTextSurface full-size, don't create it at all!
63     void Init(LPDIRECT3DDEVICE9 lpDevice, IDirect3DTexture9* lpTextSurface, int bAdditive); // note: ok if lpTextSurface==NULL; in that case, text will be drawn directly to screen (but not til end anyway).
64     void Finish();
65 
66     // note: pFont must persist until DrawNow() is called!
67     int  DrawText(LPD3DXFONT pFont, char* szText, RECT* pRect, DWORD flags, DWORD color, bool bBlackBox, DWORD boxColor=0xFF000000); // actually queues the text!
68     int  DrawText(LPD3DXFONT pFont, char* szText, int len, RECT* pRect, DWORD flags, DWORD color, bool bBox, DWORD boxColor=0xFF000000) {
69         return DrawTextW(pFont, AutoWide(szText), pRect, flags, color, bBox, boxColor);
70     };
71     int  DrawTextW(LPD3DXFONT pFont, wchar_t* szText, RECT* pRect, DWORD flags, DWORD color, bool bBlackBox, DWORD boxColor=0xFF000000); // actually queues the text!
72     int  DrawTextW(LPD3DXFONT pFont, wchar_t* szText, int len, RECT* pRect, DWORD flags, DWORD color, bool bBox, DWORD boxColor=0xFF000000) {
73         return DrawTextW(pFont, szText, pRect, flags, color, bBox, boxColor);
74     };
75     void DrawBox(LPRECT pRect, DWORD boxColor);
DrawDarkBox(LPRECT pRect)76     void DrawDarkBox(LPRECT pRect) { DrawBox(pRect, 0xFF000000); }
77     void DrawNow();
78     void ClearAll(); // automatically called @ end of DrawNow()
79 
80 protected:
81     LPDIRECT3DDEVICE9    m_lpDevice;
82     IDirect3DTexture9*   m_lpTextSurface;
83     int                  m_blit_additively;
84 
85     int       m_nMsg[2];
86     td_string m_msg[2][MAX_MSGS];
87     wchar_t*  m_next_msg_start_ptr;
88     int       m_b;
89 };
90 
91 #endif