CGuiHandler.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #pragma once
  2. #include "../../lib/CStopWatch.h"
  3. #include "SPoint.h"
  4. class FPSManager;
  5. class IStatusBar;
  6. class CIntObject;
  7. class IUpdateable;
  8. class IShowActivatable;
  9. class IShowable;
  10. /*
  11. * CGuiHandler.h, part of VCMI engine
  12. *
  13. * Authors: listed in file AUTHORS in main folder
  14. *
  15. * License: GNU General Public License v2.0 or later
  16. * Full text of license available in license.txt file, in main folder
  17. *
  18. */
  19. // Handles GUI logic and drawing
  20. class CGuiHandler
  21. {
  22. public:
  23. FPSManager * mainFPSmng; //to keep const framerate
  24. CStopWatch th;
  25. std::list<IShowActivatable *> listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on)
  26. IStatusBar * statusbar;
  27. //active GUI elements (listening for events
  28. std::list<CIntObject*> lclickable;
  29. std::list<CIntObject*> rclickable;
  30. std::list<CIntObject*> hoverable;
  31. std::list<CIntObject*> keyinterested;
  32. std::list<CIntObject*> motioninterested;
  33. std::list<CIntObject*> timeinterested;
  34. std::list<CIntObject*> wheelInterested;
  35. std::list<CIntObject*> doubleClickInterested;
  36. //objs to blit
  37. std::vector<IShowable*> objsToBlit;
  38. SDL_Event * current; //current event - can be set to NULL to stop handling event
  39. IUpdateable *curInt;
  40. SPoint lastClick;
  41. unsigned lastClickTime;
  42. bool terminate;
  43. CGuiHandler();
  44. ~CGuiHandler();
  45. void run(); // holds the main loop for the whole program after initialization and manages the update/rendering system
  46. void totalRedraw(); //forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering
  47. void simpleRedraw(); //update only top interface and draw background from buffer, sets a flag, method gets called at the end of the rendering
  48. void popInt(IShowActivatable *top); //removes given interface from the top and activates next
  49. void popIntTotally(IShowActivatable *top); //deactivates, deletes, removes given interface from the top and activates next
  50. void pushInt(IShowActivatable *newInt); //deactivate old top interface, activates this one and pushes to the top
  51. void popInts(int howMany); //pops one or more interfaces - deactivates top, deletes and removes given number of interfaces, activates new front
  52. IShowActivatable *topInt(); //returns top interface
  53. void updateTime(); //handles timeInterested
  54. void handleEvents(); //takes events from queue and calls interested objects
  55. void handleEvent(SDL_Event *sEvent);
  56. void handleMouseMotion(SDL_Event *sEvent);
  57. void handleMoveInterested( const SDL_MouseMotionEvent & motion );
  58. void fakeMouseMove();
  59. void breakEventHandling(); //current event won't be propagated anymore
  60. void drawFPSCounter(); // draws the FPS to the upper left corner of the screen
  61. ui8 defActionsDef; //default auto actions
  62. ui8 captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list
  63. std::list<CIntObject *> createdObj; //stack of objs being created
  64. static CIntObject * moveChild(CIntObject *obj, CIntObject *from, CIntObject *to, bool adjustPos = false);
  65. static SDLKey arrowToNum(SDLKey key); //converts arrow key to according numpad key
  66. static SDLKey numToDigit(SDLKey key);//converts numpad digit key to normal digit key
  67. static bool isNumKey(SDLKey key, bool number = true); //checks if key is on numpad (numbers - check only for numpad digits)
  68. static bool isArrowKey(SDLKey key);
  69. };
  70. extern CGuiHandler GH; //global gui handler
  71. template <typename T> void pushIntT()
  72. {
  73. GH.pushInt(new T());
  74. }
  75. struct SObjectConstruction
  76. {
  77. CIntObject *myObj;
  78. SObjectConstruction(CIntObject *obj);
  79. ~SObjectConstruction();
  80. };
  81. struct SSetCaptureState
  82. {
  83. bool previousCapture;
  84. ui8 prevActions;
  85. SSetCaptureState(bool allow, ui8 actions);
  86. ~SSetCaptureState();
  87. };
  88. namespace Colors
  89. {
  90. SDL_Color createColor(int r, int g, int b);
  91. const SDL_Color MetallicGold = createColor(173, 142, 66);
  92. const SDL_Color Yellow = createColor(242, 226, 110);
  93. };
  94. #define OBJ_CONSTRUCTION SObjectConstruction obj__i(this)
  95. #define OBJ_CONSTRUCTION_CAPTURING_ALL defActions = 255; SSetCaptureState obj__i1(true, 255); SObjectConstruction obj__i(this)
  96. #define BLOCK_CAPTURING SSetCaptureState obj__i(false, 0)
  97. #define BLOCK_CAPTURING_DONT_TOUCH_REC_ACTIONS SSetCaptureState obj__i(false, GH.defActionsDef)