OverlayHelper.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #ifndef __OVERLAY_HELPER_H
  11. #define __OVERLAY_HELPER_H
  12. #include "DS_List.h"
  13. namespace Ogre
  14. {
  15. class RenderWindow;
  16. class SceneManager;
  17. class OverlayContainer;
  18. class TextAreaOverlayElement;
  19. class BorderPanelOverlayElement;
  20. class OverlayElement;
  21. class Overlay;
  22. }
  23. // This classe makes it easier to use Ogre's overlay system. It provides the ability to fade overlays in and out and to automatically delete them
  24. // after time
  25. class OverlayHelper
  26. {
  27. public:
  28. OverlayHelper();
  29. ~OverlayHelper();
  30. void Startup(void);
  31. void Shutdown(void);
  32. void Update(unsigned int elapsedTimeMS);
  33. // Just returns a global overlay that I store. Useful functions on it are hide() and show()
  34. Ogre::Overlay* GetGlobalOverlay(void) const;
  35. // Fades an overlay element to some designated final alpha. You can autodelete the overlay after fading as well.
  36. void FadeOverlayElement(Ogre::OverlayElement* element, unsigned int totalTime, unsigned int fadeTimeMS, float finalAlpha, bool deleteAfterFade);
  37. // Equivalent to Ogre's function. All OverlayElements must be a child of a panel.
  38. Ogre::OverlayContainer* CreatePanel(const char *instanceName, bool addToGlobalOverlay=true);
  39. // Displays a single line of text. Doesn't handle text clipping or wrapping.
  40. Ogre::TextAreaOverlayElement *CreateTextArea(const char *instanceName, const char *fontName, Ogre::OverlayContainer* parent);
  41. // Equivalent to Ogre's function.
  42. Ogre::BorderPanelOverlayElement *CreateBorderPanel(const char *instanceName, Ogre::OverlayContainer* parent);
  43. // Destroy any overlay created with the above.
  44. // Safer because it removes the element from its children and parent.
  45. void SafeDestroyOverlayElement(Ogre::OverlayElement *item);
  46. // For internal use
  47. struct TimedOverlay
  48. {
  49. TimedOverlay();
  50. ~TimedOverlay();
  51. TimedOverlay(Ogre::OverlayElement *overlayElement, unsigned int totalTime, unsigned int fadeTimeMS, float finalAlpha, bool deleteAfterFade);
  52. Ogre::OverlayElement *overlayElement;
  53. unsigned int remainingTimeMS;
  54. unsigned int fadeTimeMS;
  55. float finalAlpha;
  56. float startFadeAlpha;
  57. bool deleteAfterFade;
  58. };
  59. protected:
  60. // A list of timed text elements with fade.
  61. // setColour
  62. DataStructures::List<TimedOverlay> timedOverlays;
  63. Ogre::Overlay* globalOverlay;
  64. unsigned int fadeTimeMSMS;
  65. };
  66. #endif
粤ICP备19079148号