TextDrawer.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. FinalSun/FinalAlert 2 Mission Editor
  3. Copyright (C) 1999-2024 Electronic Arts, Inc.
  4. Authored by Matthias Wagner
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. #include <ddraw.h>
  17. #include <afx.h>
  18. #include <string>
  19. #include "Vec2.h"
  20. // Very simple class that renders text through a prepared DirectDraw surface
  21. // Only supports ASCII chars 32 to 126, only supports monospace font
  22. // This is for rendering waypoint ids or credits on map without using GDI during rendering, nothing fancy
  23. class TextDrawer
  24. {
  25. public:
  26. TextDrawer(IDirectDraw4* pDirectDraw, int fontSizeInPoints, COLORREF col, COLORREF shadowCol=CLR_INVALID);
  27. bool isValid() const;
  28. void RenderText(IDirectDrawSurface4* target, int x, int y, const std::string& text, bool centered=false) const;
  29. ProjectedVec GetExtent(const std::string& text) const;
  30. private:
  31. CComPtr<IDirectDrawSurface4> m_fontSurface;
  32. ProjectedVec m_charExtent;
  33. int m_fontSizeInPoints;
  34. int m_fontSizeInPixels;
  35. COLORREF m_col;
  36. COLORREF m_shadowCol;
  37. };