CMessage.h 2.9 KB

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