CMessage.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. enum EWindowType {infoOnly, infoOK, yesOrNO};
  17. class CPreGame;
  18. class MapSel;
  19. class CSimpleWindow;
  20. class CInfoWindow;
  21. class CDefHandler;
  22. class SComponent;
  23. class CSelWindow;
  24. class CSelectableComponent;
  25. namespace NMessage
  26. {
  27. extern CDefHandler * ok, *cancel;
  28. extern std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
  29. extern SDL_Surface * background ;
  30. }
  31. struct ComponentResolved
  32. {
  33. SComponent *comp;
  34. SDL_Surface *img;
  35. std::vector<std::vector<SDL_Surface*> > * txt;
  36. int txtFontHeight;
  37. ComponentResolved(); //c-tor
  38. ComponentResolved(SComponent *Comp); //c-tor
  39. ~ComponentResolved(); //d-tor
  40. };
  41. struct ComponentsToBlit
  42. {
  43. std::vector< std::vector<ComponentResolved*> > comps;
  44. int w, h;
  45. void blitCompsOnSur(SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret);
  46. ComponentsToBlit(std::vector<SComponent*> & SComps, int maxw, SDL_Surface* _or); //c-tor
  47. ~ComponentsToBlit(); //d-tor
  48. };
  49. class CMessage
  50. {
  51. public:
  52. static std::pair<int,int> getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg, int fontHeight);
  53. static std::vector<std::vector<SDL_Surface*> > * drawText(std::vector<std::string> * brtext, int &fontHeigh, EFonts font = FONT_MEDIUM);
  54. 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
  55. static void drawIWindow(CInfoWindow * ret, std::string text, int player);
  56. 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
  57. static SDL_Surface * drawBox1(int w, int h, int playerColor=1);
  58. static void drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x=0, int y=0);
  59. static SDL_Surface * drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline=30, int imgToBmp=55);
  60. 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);
  61. static std::vector<std::string> breakText(std::string text, size_t maxLineWidth, EFonts font);
  62. static void init();
  63. static void dispose();
  64. };
  65. //
  66. #endif // __CMESSAGE_H__