CMessage.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. enum EWindowType {infoOnly, infoOK, yesOrNO};
  8. class CPreGame;
  9. class MapSel;
  10. class CSimpleWindow;
  11. class CInfoWindow;
  12. class CDefHandler;
  13. class SComponent;
  14. class CSelWindow;
  15. class CSelectableComponent;
  16. namespace NMessage
  17. {
  18. extern CDefHandler * ok, *cancel;
  19. extern std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
  20. extern SDL_Surface * background ;
  21. }
  22. struct ComponentResolved
  23. {
  24. SComponent *comp;
  25. SDL_Surface *img;
  26. std::vector<std::vector<SDL_Surface*> > * txt;
  27. ComponentResolved();
  28. ComponentResolved(SComponent *Comp);
  29. ~ComponentResolved();
  30. };
  31. struct ComponentsToBlit
  32. {
  33. std::vector< std::vector<ComponentResolved*> > comps;
  34. int w, h;
  35. void blitCompsOnSur(SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret);
  36. ComponentsToBlit(std::vector<SComponent*> & SComps, int maxw, SDL_Surface* _or);
  37. ~ComponentsToBlit();
  38. };
  39. class CMessage
  40. {
  41. public:
  42. static std::pair<int,int> getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg);
  43. static std::vector<std::vector<SDL_Surface*> > * drawText(std::vector<std::string> * brtext, TTF_Font *font = NULL);
  44. 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
  45. static void drawIWindow(CInfoWindow * ret, std::string text, int player, int charperline);
  46. 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
  47. static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly,
  48. std::vector<CDefHandler*> *addPics=NULL, void * cb=NULL);
  49. static SDL_Surface * drawBox1(int w, int h, int playerColor=1);
  50. static void drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x=0, int y=0);
  51. static SDL_Surface * drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline=30, int imgToBmp=55);
  52. static std::vector<std::string> * breakText(std::string text, size_t line=30, bool userBreak=true, bool ifor=true); //line - chars per line
  53. static void init();
  54. static void dispose();
  55. };
  56. //
  57. #endif // __CMESSAGE_H__