CMessage.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef __CMESSAGE_H__
  2. #define __CMESSAGE_H__
  3. #include "global.h"
  4. #include <SDL_ttf.h>
  5. #include <SDL.h>
  6. /*
  7. * CMessage.h, part of VCMI engine
  8. *
  9. * Authors: listed in file AUTHORS in main folder
  10. *
  11. * License: GNU General Public License v2.0 or later
  12. * Full text of license available in license.txt file, in main folder
  13. *
  14. */
  15. enum EWindowType {infoOnly, infoOK, yesOrNO};
  16. class CPreGame;
  17. class MapSel;
  18. class CSimpleWindow;
  19. class CInfoWindow;
  20. class CDefHandler;
  21. class SComponent;
  22. class CSelWindow;
  23. class CSelectableComponent;
  24. namespace NMessage
  25. {
  26. extern CDefHandler * ok, *cancel;
  27. extern std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
  28. extern SDL_Surface * background ;
  29. }
  30. struct ComponentResolved
  31. {
  32. SComponent *comp;
  33. SDL_Surface *img;
  34. std::vector<std::vector<SDL_Surface*> > * txt;
  35. ComponentResolved(); //c-tor
  36. ComponentResolved(SComponent *Comp); //c-tor
  37. ~ComponentResolved(); //d-tor
  38. };
  39. struct ComponentsToBlit
  40. {
  41. std::vector< std::vector<ComponentResolved*> > comps;
  42. int w, h;
  43. void blitCompsOnSur(SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret);
  44. ComponentsToBlit(std::vector<SComponent*> & SComps, int maxw, SDL_Surface* _or); //c-tor
  45. ~ComponentsToBlit(); //d-tor
  46. };
  47. class CMessage
  48. {
  49. public:
  50. static std::pair<int,int> getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg);
  51. static std::vector<std::vector<SDL_Surface*> > * drawText(std::vector<std::string> * brtext, TTF_Font *font = NULL);
  52. 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
  53. static void drawIWindow(CInfoWindow * ret, std::string text, int player, int charperline);
  54. 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
  55. static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly,
  56. std::vector<CDefHandler*> *addPics=NULL, void * cb=NULL);
  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, bool userBreak=true, bool ifor=true);
  61. static void init();
  62. static void dispose();
  63. };
  64. //
  65. #endif // __CMESSAGE_H__