CMessage.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #ifndef CMESSAGE_H
  2. #define CMESSAGE_H
  3. #include "SDL_TTF.h"
  4. #include "CSemiDefHandler.h"
  5. #include "CDefHandler.h"
  6. enum EWindowType {infoOnly, infoOK, yesOrNO};
  7. class CPreGame;
  8. class MapSel;
  9. typedef void(CPreGame::*ttt)();
  10. template <class T=ttt> class CGroup;
  11. template <class T=ttt> class CPoinGroup ;
  12. struct OverButton
  13. {
  14. int ID;
  15. int type;
  16. SDL_Rect pos;
  17. CDefHandler* imgs;
  18. int state;
  19. virtual void show() ;
  20. virtual void press(bool down=true);
  21. OverButton(){state=0;}
  22. };
  23. struct HighButton: public OverButton
  24. {
  25. HighButton( SDL_Rect Pos, CDefHandler* Imgs, bool Sel=false, int id=-1)
  26. {type=0;imgs=Imgs;selectable=Sel;selected=false;state=0;pos=Pos;ID=id;highlightable=false;};
  27. HighButton(){}
  28. bool selectable, selected;
  29. bool highlightable, highlighted;
  30. virtual void hover(bool on=true)=0;
  31. virtual void select(bool on=true)=0;
  32. };
  33. template <class T=ttt> struct Button: public HighButton
  34. {
  35. CGroup<T> * ourGroup;
  36. Button( SDL_Rect Pos, T Fun,CDefHandler* Imgs, bool Sel=false, CGroup<T>* gr=NULL, int id=-1)
  37. :HighButton(Pos,Imgs,Sel,id),ourGroup(gr),fun(Fun){type=1;};
  38. Button(){ourGroup=NULL;type=1;};
  39. T fun;
  40. virtual void hover(bool on=true);
  41. virtual void select(bool on=true);
  42. };
  43. template <class T=ttt> struct SetrButton: public Button<T>
  44. {
  45. int key, * poin;
  46. virtual void press(bool down=true);
  47. SetrButton(){type=0;selectable=selected=false;state=0;highlightable=false;}
  48. };
  49. template<class T=CPreGame> class Slider
  50. { //
  51. public:
  52. bool vertical; // false means horizontal
  53. SDL_Rect pos; // position
  54. Button<void(Slider::*)()> up, down, //or left/right
  55. slider;
  56. int positionsAmnt, capacity;// capacity - amount of positions dispplayed at once
  57. int whereAreWe; // first displayed thing
  58. bool moving;
  59. void(T::*fun)(int);
  60. void clickDown(int x, int y, bool bzgl=true);
  61. void clickUp(int x, int y, bool bzgl=true);
  62. void mMove(int x, int y, bool bzgl=true);
  63. void moveUp();
  64. void moveDown();
  65. void deactivate();
  66. void activate();
  67. Slider(int x, int y, int h, int amnt, int cap, bool ver);
  68. void updateSlid();
  69. void handleIt(SDL_Event sev);
  70. };
  71. //template<class T=void(CPreGame::*)(int)>
  72. template<class T=ttt> struct IntBut: public Button<T>
  73. {
  74. public:
  75. int key;
  76. int * what;
  77. IntBut(){type=2;fun=NULL;highlightable=false;};
  78. IntBut( SDL_Rect Pos, T Fun,CDefHandler* Imgs, bool Sel, int Key, int * What)
  79. : Button(Pos,Fun,Imgs,Sel,gr),key(My),key(Key),what(What){ourGroup=gr;type=2;fun=NULL;};
  80. void set(){*what=key;};
  81. };
  82. template<class T=ttt> struct IntSelBut: public Button<T>
  83. {
  84. public:
  85. CPoinGroup<T> * ourGroup;
  86. int key;
  87. IntSelBut(){};
  88. IntSelBut( SDL_Rect Pos, T Fun,CDefHandler* Imgs, bool Sel=false, CPoinGroup<T>* gr=NULL, int My=-1)
  89. : Button(Pos,Fun,Imgs,Sel,gr),key(My){ourGroup=gr;type=1;};
  90. void select(bool on=true) {(*this).Button::select(on);ourGroup->setYour(this);}
  91. };
  92. template <class T=ttt> class CPoinGroup :public CGroup<T>
  93. {
  94. public:
  95. int * gdzie; //where (po polsku, bo by by³o s³owo kluczowe :/)
  96. void setYour(IntSelBut<T> * your){*gdzie=your->key;};
  97. };
  98. template <class T=ttt> class CGroup
  99. {
  100. public:
  101. Button<T> * selected;
  102. int type; // 1=sinsel
  103. CGroup():selected(NULL),type(0){};
  104. };
  105. class CMessage
  106. {
  107. public:
  108. static std::vector<std::string> * breakText(std::string text, int line=30);
  109. CDefHandler * piecesOfBox;
  110. SDL_Surface * background;
  111. SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly,
  112. std::vector<CDefHandler*> *addPics=NULL, void * cb=NULL);
  113. SDL_Surface * drawBox1(int w, int h);
  114. CMessage();
  115. };
  116. //
  117. #endif //CMESSAGE_H