1
0

textmgr.h 3.8 KB

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