/indra/llui/lltooltip.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 166 lines · 105 code · 26 blank · 35 comment · 0 complexity · 5e616c5446fcf5319c1c44d528188346 MD5 · raw file

  1. /**
  2. * @file lltooltip.h
  3. * @brief LLToolTipMgr class definition and related classes
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLTOOLTIP_H
  27. #define LL_LLTOOLTIP_H
  28. // Library includes
  29. #include "llsingleton.h"
  30. #include "llinitparam.h"
  31. #include "llpanel.h"
  32. #include "llstyle.h"
  33. //
  34. // Classes
  35. //
  36. class LLToolTipView : public LLView
  37. {
  38. public:
  39. struct Params : public LLInitParam::Block<Params, LLView::Params>
  40. {
  41. Params();
  42. };
  43. LLToolTipView(const LLToolTipView::Params&);
  44. /*virtual*/ BOOL handleHover(S32 x, S32 y, MASK mask);
  45. /*virtual*/ BOOL handleMouseDown(S32 x, S32 y, MASK mask);
  46. /*virtual*/ BOOL handleMiddleMouseDown(S32 x, S32 y, MASK mask);
  47. /*virtual*/ BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
  48. /*virtual*/ BOOL handleScrollWheel( S32 x, S32 y, S32 clicks );
  49. void drawStickyRect();
  50. /*virtual*/ void draw();
  51. };
  52. class LLToolTip : public LLPanel
  53. {
  54. public:
  55. struct StyledText : public LLInitParam::Block<StyledText>
  56. {
  57. Mandatory<std::string> text;
  58. Optional<LLStyle::Params> style;
  59. };
  60. struct Params : public LLInitParam::Block<Params, LLPanel::Params>
  61. {
  62. typedef boost::function<void(void)> click_callback_t;
  63. Optional<std::string> message;
  64. Multiple<StyledText> styled_message;
  65. Optional<LLCoordGL> pos;
  66. Optional<F32> delay_time,
  67. visible_time_over, // time for which tooltip is visible while mouse on it
  68. visible_time_near, // time for which tooltip is visible while mouse near it
  69. visible_time_far; // time for which tooltip is visible while mouse moved away
  70. Optional<LLRect> sticky_rect;
  71. Optional<const LLFontGL*> font;
  72. Optional<LLUIImage*> image;
  73. Optional<LLUIColor> text_color;
  74. Optional<bool> time_based_media,
  75. web_based_media,
  76. media_playing;
  77. Optional<click_callback_t> click_callback,
  78. click_playmedia_callback,
  79. click_homepage_callback;
  80. Optional<S32> max_width,
  81. padding;
  82. Optional<bool> wrap;
  83. Params();
  84. };
  85. /*virtual*/ void draw();
  86. /*virtual*/ BOOL handleHover(S32 x, S32 y, MASK mask);
  87. /*virtual*/ void onMouseLeave(S32 x, S32 y, MASK mask);
  88. /*virtual*/ void setVisible(BOOL visible);
  89. bool isFading();
  90. F32 getVisibleTime();
  91. bool hasClickCallback();
  92. LLToolTip(const Params& p);
  93. void initFromParams(const LLToolTip::Params& params);
  94. private:
  95. class LLTextBox* mTextBox;
  96. class LLButton* mInfoButton;
  97. class LLButton* mPlayMediaButton;
  98. class LLButton* mHomePageButton;
  99. LLFrameTimer mFadeTimer;
  100. LLFrameTimer mVisibleTimer;
  101. bool mHasClickCallback;
  102. S32 mPadding; // pixels
  103. };
  104. // used for the inspector tooltips which need different background images etc.
  105. class LLInspector : public LLToolTip
  106. {
  107. public:
  108. struct Params : public LLInitParam::Block<Params, LLToolTip::Params>
  109. {};
  110. };
  111. class LLToolTipMgr : public LLSingleton<LLToolTipMgr>
  112. {
  113. LOG_CLASS(LLToolTipMgr);
  114. public:
  115. LLToolTipMgr();
  116. void show(const LLToolTip::Params& params);
  117. void show(const std::string& message);
  118. void unblockToolTips();
  119. void blockToolTips();
  120. void hideToolTips();
  121. bool toolTipVisible();
  122. LLRect getToolTipRect();
  123. LLRect getMouseNearRect();
  124. void updateToolTipVisibility();
  125. private:
  126. void createToolTip(const LLToolTip::Params& params);
  127. bool mToolTipsBlocked;
  128. class LLToolTip* mToolTip;
  129. // tooltip creation is deferred until the UI is drawn every frame
  130. // so the last tooltip to be created in a given frame will win
  131. LLToolTip::Params mLastToolTipParams; // description of last tooltip we showed
  132. LLToolTip::Params mNextToolTipParams; // description of next tooltip we want to show
  133. bool mNeedsToolTip; // do we want to show a tooltip
  134. LLRect mMouseNearRect;
  135. };
  136. //
  137. // Globals
  138. //
  139. extern LLToolTipView *gToolTipView;
  140. #endif