2
0

CMessage.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef __CMESSAGE_H__
  2. #define __CMESSAGE_H__
  3. #include "FontBase.h"
  4. #include "../global.h"
  5. //#include <SDL.h>
  6. #include <boost/function.hpp>
  7. /*
  8. * CMessage.h, part of VCMI engine
  9. *
  10. * Authors: listed in file AUTHORS in main folder
  11. *
  12. * License: GNU General Public License v2.0 or later
  13. * Full text of license available in license.txt file, in main folder
  14. *
  15. */
  16. struct SDL_Surface;
  17. enum EWindowType {infoOnly, infoOK, yesOrNO};
  18. class CPreGame;
  19. class MapSel;
  20. class CSimpleWindow;
  21. class CInfoWindow;
  22. class CDefHandler;
  23. class SComponent;
  24. class CSelWindow;
  25. class CSelectableComponent;
  26. namespace NMessage
  27. {
  28. extern CDefHandler * ok, *cancel;
  29. extern std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
  30. extern SDL_Surface * background ;
  31. }
  32. struct ComponentResolved
  33. {
  34. SComponent *comp;
  35. SDL_Surface *img;
  36. std::vector<std::vector<SDL_Surface*> > * txt;
  37. int txtFontHeight;
  38. ComponentResolved(); //c-tor
  39. ComponentResolved(SComponent *Comp); //c-tor
  40. ~ComponentResolved(); //d-tor
  41. };
  42. struct ComponentsToBlit
  43. {
  44. std::vector< std::vector<ComponentResolved*> > comps;
  45. int w, h;
  46. void blitCompsOnSur(SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret);
  47. ComponentsToBlit(std::vector<SComponent*> & SComps, int maxw, SDL_Surface* _or); //c-tor
  48. ~ComponentsToBlit(); //d-tor
  49. };
  50. /// Class which draws formatted text messages and generates chat windows
  51. class CMessage
  52. {
  53. public:
  54. static std::pair<int,int> getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg, int fontHeight);
  55. static std::vector<std::vector<SDL_Surface*> > * drawText(std::vector<std::string> * brtext, int &fontHeigh, EFonts font = FONT_MEDIUM);
  56. 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
  57. static void drawIWindow(CInfoWindow * ret, std::string text, int player);
  58. 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
  59. static SDL_Surface * drawBox1(int w, int h, int playerColor=1);
  60. static void drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x=0, int y=0);
  61. static SDL_Surface * drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline=30, int imgToBmp=55);
  62. 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);
  63. static std::vector<std::string> breakText(std::string text, size_t maxLineWidth, EFonts font);
  64. static void init();
  65. static void dispose();
  66. };
  67. //
  68. #endif // __CMESSAGE_H__