ScrollView.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_SCROLLVIEW_H
  24. #define UI_SCROLLVIEW_H
  25. #include "BorderImage.h"
  26. class Slider;
  27. //! A scrollable view for showing child widgets
  28. class ScrollView : public BorderImage
  29. {
  30. DEFINE_TYPE(ScrollView);
  31. public:
  32. //! Construct with name
  33. ScrollView(const std::string& name = std::string());
  34. //! Destruct
  35. virtual ~ScrollView();
  36. //! Set UI element style from XML data
  37. virtual void setStyle(const XMLElement& element, ResourceCache* cache);
  38. //! Perform UI element update
  39. virtual void update(float timeStep);
  40. //! Set view offset from the top-left corner
  41. void setViewPosition(const IntVector2& position);
  42. //! Set view offset from the top-left corner
  43. void setViewPosition(int x, int y);
  44. //! Set total view size
  45. void setViewSize(const IntVector2& position);
  46. //! Set total view size
  47. void setViewSize(int x, int y);
  48. //! Set horizontal slider
  49. void setHorizontalSlider(Slider* slider);
  50. //! Set vertical slider
  51. void setVerticalSlider(Slider* slider);
  52. //! Return view offset from the top-left corner
  53. const IntVector2& getViewPosition() const { return mViewPosition; }
  54. //! Return total view size
  55. const IntVector2& getViewSize() const { return mViewSize; }
  56. //! Return horizontal slider
  57. Slider* getHorizontalSlider() const { return mHorizontalSlider; }
  58. //! Return vertical slider
  59. Slider* getVerticalSlider() const { return mVerticalSlider; }
  60. protected:
  61. //! Update the view from sliders if available
  62. void updateViewFromSliders();
  63. //! Update the sliders' ranges and positions
  64. void updateSliders();
  65. //! Limit and update view with a new position
  66. void updateView(const IntVector2& position);
  67. //! Horizontal slider
  68. WeakPtr<Slider> mHorizontalSlider;
  69. //! Vertical slider
  70. WeakPtr<Slider> mVerticalSlider;
  71. //! Current view offset from the top-left corner
  72. IntVector2 mViewPosition;
  73. //! Total view size
  74. IntVector2 mViewSize;
  75. //! Last known own size
  76. IntVector2 mLastSize;
  77. };
  78. #endif // UI_SCROLLVIEW_H