CMessage.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #include "FontBase.h"
  3. /*
  4. * CMessage.h, part of VCMI engine
  5. *
  6. * Authors: listed in file AUTHORS in main folder
  7. *
  8. * License: GNU General Public License v2.0 or later
  9. * Full text of license available in license.txt file, in main folder
  10. *
  11. */
  12. struct SDL_Surface;
  13. enum EWindowType {infoOnly, infoOK, yesOrNO};
  14. class CPreGame;
  15. class MapSel;
  16. class CSimpleWindow;
  17. class CInfoWindow;
  18. class CDefHandler;
  19. class SComponent;
  20. class CSelWindow;
  21. class CSelectableComponent;
  22. namespace NMessage
  23. {
  24. extern CDefHandler * ok, *cancel;
  25. extern std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
  26. extern SDL_Surface * background ;
  27. }
  28. struct ComponentResolved
  29. {
  30. SComponent *comp;
  31. SDL_Surface *img;
  32. std::vector<std::vector<SDL_Surface*> > * txt;
  33. int txtFontHeight;
  34. ComponentResolved(); //c-tor
  35. ComponentResolved(SComponent *Comp); //c-tor
  36. ~ComponentResolved(); //d-tor
  37. };
  38. struct ComponentsToBlit
  39. {
  40. std::vector< std::vector<ComponentResolved*> > comps;
  41. int w, h;
  42. void blitCompsOnSur(SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret);
  43. ComponentsToBlit(std::vector<SComponent*> & SComps, int maxw, SDL_Surface* _or); //c-tor
  44. ~ComponentsToBlit(); //d-tor
  45. };
  46. /// Class which draws formatted text messages and generates chat windows
  47. class CMessage
  48. {
  49. public:
  50. static std::pair<int,int> getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg, int fontHeight);
  51. static std::vector<std::vector<SDL_Surface*> > * drawText(std::vector<std::string> * brtext, int &fontHeigh, EFonts font = FONT_MEDIUM);
  52. static SDL_Surface * blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int fontHeight, int & curh, SDL_Surface * ret, int xCenterPos=-1); //xPos==-1 works as if ret->w/2
  53. static void drawIWindow(CInfoWindow * ret, std::string text, int player);
  54. static CSimpleWindow * genWindow(std::string text, int player, bool centerOnMouse=false, int Lmar=35, int Rmar=35, int Tmar=35, int Bmar=35);//supports h3 text formatting; player sets color of window, Lmar/Rmar/Tmar/Bmar are Left/Right/Top/Bottom margins
  55. static SDL_Surface * drawBox1(int w, int h, int playerColor=1);
  56. static void drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x=0, int y=0);
  57. static SDL_Surface * drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline=30, int imgToBmp=55);
  58. static std::vector<std::string> breakText(std::string text, size_t maxLineSize=30, const boost::function<int(char)> &charMetric = boost::function<int(char)>(), bool allowLeadingWhitespace = false);
  59. static std::vector<std::string> breakText(std::string text, size_t maxLineWidth, EFonts font);
  60. static void init();
  61. static void dispose();
  62. };