CMessage.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef __CMESSAGE_H__
  2. #define __CMESSAGE_H__
  3. #include "global.h"
  4. #include <SDL_ttf.h>
  5. #include <SDL.h>
  6. #include "CPreGame.h"
  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. ComponentResolved();
  37. ComponentResolved(SComponent *Comp);
  38. ~ComponentResolved();
  39. };
  40. struct ComponentsToBlit
  41. {
  42. std::vector< std::vector<ComponentResolved*> > comps;
  43. int w, h;
  44. void blitCompsOnSur(SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret);
  45. ComponentsToBlit(std::vector<SComponent*> & SComps, int maxw, SDL_Surface* _or);
  46. ~ComponentsToBlit();
  47. };
  48. class CMessage
  49. {
  50. public:
  51. static std::pair<int,int> getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg);
  52. static std::vector<std::vector<SDL_Surface*> > * drawText(std::vector<std::string> * brtext, TTF_Font *font = NULL);
  53. static SDL_Surface * blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int & curh, SDL_Surface * ret, int xCenterPos=-1); //xPos==-1 works as if ret->w/2
  54. static void drawIWindow(CInfoWindow * ret, std::string text, int player, int charperline);
  55. static CSimpleWindow * genWindow(std::string text, int player, 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
  56. static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly,
  57. std::vector<CDefHandler*> *addPics=NULL, void * cb=NULL);
  58. static SDL_Surface * drawBox1(int w, int h, int playerColor=1);
  59. static void drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x=0, int y=0);
  60. static SDL_Surface * drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline=30, int imgToBmp=55);
  61. static std::vector<std::string> * breakText(std::string text, size_t line=30, bool userBreak=true, bool ifor=true); //line - chars per line
  62. static void init();
  63. static void dispose();
  64. };
  65. //
  66. #endif // __CMESSAGE_H__