PageRenderTime 38ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/lltoggleablemenu.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 101 lines | 60 code | 15 blank | 26 comment | 6 complexity | e2ce03a036261754643bd53d2d2f05ce MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltoggleablemenu.cpp
  3. * @brief Menu toggled by a button press
  4. *
  5. * $LicenseInfo:firstyear=2009&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. #include "linden_common.h"
  27. #include "lltoggleablemenu.h"
  28. #include "lluictrlfactory.h"
  29. static LLDefaultChildRegistry::Register<LLToggleableMenu> r("toggleable_menu");
  30. LLToggleableMenu::LLToggleableMenu(const LLToggleableMenu::Params& p)
  31. : LLMenuGL(p),
  32. mButtonRect(),
  33. mVisibilityChangeSignal(NULL),
  34. mClosedByButtonClick(false)
  35. {
  36. }
  37. LLToggleableMenu::~LLToggleableMenu()
  38. {
  39. delete mVisibilityChangeSignal;
  40. }
  41. boost::signals2::connection LLToggleableMenu::setVisibilityChangeCallback(const commit_signal_t::slot_type& cb)
  42. {
  43. if (!mVisibilityChangeSignal) mVisibilityChangeSignal = new commit_signal_t();
  44. return mVisibilityChangeSignal->connect(cb);
  45. }
  46. // virtual
  47. void LLToggleableMenu::handleVisibilityChange (BOOL curVisibilityIn)
  48. {
  49. S32 x,y;
  50. LLUI::getMousePositionLocal(LLUI::getRootView(), &x, &y);
  51. if (!curVisibilityIn && mButtonRect.pointInRect(x, y))
  52. {
  53. mClosedByButtonClick = true;
  54. }
  55. if (mVisibilityChangeSignal)
  56. {
  57. (*mVisibilityChangeSignal)(this,
  58. LLSD().with("visibility", curVisibilityIn).with("closed_by_button_click", mClosedByButtonClick));
  59. }
  60. }
  61. void LLToggleableMenu::setButtonRect(const LLRect& rect, LLView* current_view)
  62. {
  63. LLRect screen;
  64. current_view->localRectToScreen(rect, &screen);
  65. mButtonRect = screen;
  66. }
  67. void LLToggleableMenu::setButtonRect(LLView* current_view)
  68. {
  69. LLRect rect = current_view->getLocalRect();
  70. setButtonRect(rect, current_view);
  71. }
  72. bool LLToggleableMenu::toggleVisibility()
  73. {
  74. if (mClosedByButtonClick)
  75. {
  76. mClosedByButtonClick = false;
  77. return false;
  78. }
  79. if (getVisible())
  80. {
  81. setVisible(FALSE);
  82. mClosedByButtonClick = false;
  83. return false;
  84. }
  85. return true;
  86. }