PageRenderTime 68ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llinspect.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 149 lines | 95 code | 17 blank | 37 comment | 10 complexity | 0cf16757233335305bbb725cffdb008f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llinspect.cpp
  3. *
  4. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2010, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. #include "llviewerprecompiledheaders.h"
  26. #include "llinspect.h"
  27. #include "lltooltip.h"
  28. #include "llcontrol.h" // LLCachedControl
  29. #include "llui.h" // LLUI::sSettingsGroups
  30. #include "llviewermenu.h"
  31. LLInspect::LLInspect(const LLSD& key)
  32. : LLFloater(key),
  33. mCloseTimer(),
  34. mOpenTimer()
  35. {
  36. }
  37. LLInspect::~LLInspect()
  38. {
  39. }
  40. // virtual
  41. void LLInspect::draw()
  42. {
  43. static LLCachedControl<F32> FADE_TIME(*LLUI::sSettingGroups["config"], "InspectorFadeTime", 1.f);
  44. static LLCachedControl<F32> STAY_TIME(*LLUI::sSettingGroups["config"], "InspectorShowTime", 1.f);
  45. if (mOpenTimer.getStarted())
  46. {
  47. LLFloater::draw();
  48. if (mOpenTimer.getElapsedTimeF32() > STAY_TIME)
  49. {
  50. mOpenTimer.stop();
  51. mCloseTimer.start();
  52. }
  53. }
  54. else if (mCloseTimer.getStarted())
  55. {
  56. F32 alpha = clamp_rescale(mCloseTimer.getElapsedTimeF32(), 0.f, FADE_TIME, 1.f, 0.f);
  57. LLViewDrawContext context(alpha);
  58. LLFloater::draw();
  59. if (mCloseTimer.getElapsedTimeF32() > FADE_TIME)
  60. {
  61. closeFloater(false);
  62. }
  63. }
  64. else
  65. {
  66. LLFloater::draw();
  67. }
  68. }
  69. // virtual
  70. void LLInspect::onOpen(const LLSD& data)
  71. {
  72. LLFloater::onOpen(data);
  73. mCloseTimer.stop();
  74. mOpenTimer.start();
  75. }
  76. // virtual
  77. void LLInspect::onFocusLost()
  78. {
  79. LLFloater::onFocusLost();
  80. // Start closing when we lose focus
  81. mCloseTimer.start();
  82. mOpenTimer.stop();
  83. }
  84. // virtual
  85. BOOL LLInspect::handleHover(S32 x, S32 y, MASK mask)
  86. {
  87. mOpenTimer.pause();
  88. return LLView::handleHover(x, y, mask);
  89. }
  90. BOOL LLInspect::handleToolTip(S32 x, S32 y, MASK mask)
  91. {
  92. BOOL handled = FALSE;
  93. //delegate handling of tooltip to the hovered child
  94. LLView* child_handler = childFromPoint(x,y);
  95. if (child_handler && !child_handler->getToolTip().empty())// show tooltip if a view has non-empty tooltip message
  96. {
  97. //build LLInspector params to get correct tooltip setting, etc. background image
  98. LLInspector::Params params;
  99. params.fillFrom(LLUICtrlFactory::instance().getDefaultParams<LLInspector>());
  100. params.message = child_handler->getToolTip();
  101. //set up delay if there is no visible tooltip at this moment
  102. params.delay_time = LLToolTipMgr::instance().toolTipVisible() ? 0.f : LLUI::sSettingGroups["config"]->getF32( "ToolTipDelay" );
  103. LLToolTipMgr::instance().show(params);
  104. handled = TRUE;
  105. }
  106. return handled;
  107. }
  108. // virtual
  109. void LLInspect::onMouseLeave(S32 x, S32 y, MASK mask)
  110. {
  111. mOpenTimer.unpause();
  112. }
  113. bool LLInspect::childHasVisiblePopupMenu()
  114. {
  115. // Child text-box may spawn a pop-up menu, if mouse is over the menu, Inspector
  116. // will hide(which is not expected).
  117. // This is an attempt to find out if child control has spawned a menu.
  118. LLView* child_menu = gMenuHolder->getVisibleMenu();
  119. if(child_menu)
  120. {
  121. LLRect floater_rc = calcScreenRect();
  122. LLRect menu_screen_rc = child_menu->calcScreenRect();
  123. S32 mx, my;
  124. LLUI::getMousePositionScreen(&mx, &my);
  125. // This works wrong if we spawn a menu near Inspector and menu overlaps Inspector.
  126. if(floater_rc.overlaps(menu_screen_rc) && menu_screen_rc.pointInRect(mx, my))
  127. {
  128. return true;
  129. }
  130. }
  131. return false;
  132. }