CMessage.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef __CMESSAGE_H__
  2. #define __CMESSAGE_H__
  3. #include "FontBase.h"
  4. #include "../global.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. int txtFontHeight;
  36. ComponentResolved(); //c-tor
  37. ComponentResolved(SComponent *Comp); //c-tor
  38. ~ComponentResolved(); //d-tor
  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); //c-tor
  46. ~ComponentsToBlit(); //d-tor
  47. };
  48. class CMessage
  49. {
  50. public:
  51. static std::pair<int,int> getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg, int fontHeight);
  52. static std::vector<std::vector<SDL_Surface*> > * drawText(std::vector<std::string> * brtext, int &fontHeigh, EFonts font = FONT_MEDIUM);
  53. 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
  54. static void drawIWindow(CInfoWindow * ret, std::string text, int player, int charperline);
  55. 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
  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 maxLineSize=30, bool userBreak=true, bool ifor=true);
  62. static void init();
  63. static void dispose();
  64. };
  65. //
  66. #endif // __CMESSAGE_H__