Menu.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #ifndef UI_MENU_H
  24. #define UI_MENU_H
  25. #include "Button.h"
  26. //! A menu element that optionally shows a popup
  27. class Menu : public Button
  28. {
  29. DEFINE_TYPE(Menu);
  30. //! Construct with name
  31. Menu(const std::string& name = std::string());
  32. //! Destruct
  33. virtual ~Menu();
  34. //! Set UI element style from XML data
  35. virtual void setStyle(const XMLElement& element, ResourceCache* cache);
  36. //! React to mouse click
  37. virtual void onClick(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers);
  38. //! React to the popup being shown
  39. virtual void onShowPopup();
  40. //! Set popup element to show on selection
  41. void setPopup(UIElement* element);
  42. //! Set popup element offset
  43. void setPopupOffset(const IntVector2& offset);
  44. //! Set popup element offset
  45. void setPopupOffset(int x, int y);
  46. //! Force the popup to show or hide
  47. void showPopup(bool enable);
  48. //! Return popup element
  49. UIElement* getPopup() const { return mPopup; }
  50. //! Return popup element offset
  51. const IntVector2& getPopupOffset() const { return mPopupOffset; }
  52. //! Return whether popup is open
  53. bool getShowPopup() const { return mShowPopup; }
  54. protected:
  55. //! Popup element
  56. SharedPtr<UIElement> mPopup;
  57. //! Popup element offset
  58. IntVector2 mPopupOffset;
  59. //! Show popup flag
  60. bool mShowPopup;
  61. private:
  62. //! Handle focus change attempt in case the popup needs to be hidden
  63. void handleTryFocus(StringHash eventType, VariantMap& eventData);
  64. };
  65. #endif // UI_MENU_H