CGuiHandler.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * CGuiHandler.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. class Point;
  13. class Rect;
  14. VCMI_LIB_NAMESPACE_END
  15. enum class MouseButton;
  16. class ShortcutHandler;
  17. class FramerateManager;
  18. class IStatusBar;
  19. class CIntObject;
  20. class IUpdateable;
  21. class IShowActivatable;
  22. class IRenderHandler;
  23. class IScreenHandler;
  24. class WindowHandler;
  25. class EventDispatcher;
  26. class InputHandler;
  27. // Handles GUI logic and drawing
  28. class CGuiHandler
  29. {
  30. private:
  31. /// Fake no-op version status bar, for use in windows that have no status bar
  32. std::shared_ptr<IStatusBar> fakeStatusBar;
  33. /// Status bar of current window, if any. Uses weak_ptr to allow potential hanging reference after owned window has been deleted
  34. std::weak_ptr<IStatusBar> currentStatusBar;
  35. std::unique_ptr<ShortcutHandler> shortcutsHandlerInstance;
  36. std::unique_ptr<WindowHandler> windowHandlerInstance;
  37. std::unique_ptr<IScreenHandler> screenHandlerInstance;
  38. std::unique_ptr<IRenderHandler> renderHandlerInstance;
  39. std::unique_ptr<FramerateManager> framerateManagerInstance;
  40. std::unique_ptr<EventDispatcher> eventDispatcherInstance;
  41. std::unique_ptr<InputHandler> inputHandlerInstance;
  42. public:
  43. boost::mutex interfaceMutex;
  44. /// returns current position of mouse cursor, relative to vcmi window
  45. const Point & getCursorPosition() const;
  46. ShortcutHandler & shortcuts();
  47. FramerateManager & framerate();
  48. EventDispatcher & events();
  49. InputHandler & input();
  50. /// Returns current logical screen dimensions
  51. /// May not match size of window if user has UI scaling different from 100%
  52. Point screenDimensions() const;
  53. /// returns true if Alt is currently pressed down
  54. bool isKeyboardAltDown() const;
  55. /// returns true if Ctrl is currently pressed down
  56. /// on Apple system, this also tests for Cmd key
  57. /// For use with keyboard-based events
  58. bool isKeyboardCtrlDown() const;
  59. /// on Apple systems, returns true if Cmd key is pressed
  60. /// on other systems, returns true if Ctrl is pressed
  61. /// /// For use with mouse-based events
  62. bool isKeyboardCmdDown() const;
  63. /// returns true if Shift is currently pressed down
  64. bool isKeyboardShiftDown() const;
  65. void startTextInput(const Rect & where);
  66. void stopTextInput();
  67. IScreenHandler & screenHandler();
  68. IRenderHandler & renderHandler();
  69. WindowHandler & windows();
  70. /// Returns currently active status bar. Guaranteed to be non-null
  71. std::shared_ptr<IStatusBar> statusbar();
  72. /// Set currently active status bar
  73. void setStatusbar(std::shared_ptr<IStatusBar>);
  74. IUpdateable *curInt;
  75. bool captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list
  76. std::list<CIntObject *> createdObj; //stack of objs being created
  77. CGuiHandler();
  78. ~CGuiHandler();
  79. void init();
  80. void renderFrame();
  81. /// called whenever SDL_WINDOWEVENT_RESTORED is reported or the user selects a different resolution, requiring to center/resize all windows
  82. void onScreenResize(bool resolutionChanged);
  83. void handleEvents(); //takes events from queue and calls interested objects
  84. void fakeMouseMove();
  85. void drawFPSCounter(); // draws the FPS to the upper left corner of the screen
  86. bool amIGuiThread();
  87. /// Calls provided functor in main thread on next execution frame
  88. void dispatchMainThread(const std::function<void()> & functor);
  89. };
  90. extern CGuiHandler GH; //global gui handler