UIScrollContainer.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include <TurboBadger/tb_widgets.h>
  23. #include <TurboBadger/tb_widgets_common.h>
  24. #include <Atomic/IO/Log.h>
  25. #include "UIEvents.h"
  26. #include "UI.h"
  27. #include "UIScrollContainer.h"
  28. using namespace tb;
  29. namespace Atomic
  30. {
  31. UIScrollContainer::UIScrollContainer(Context* context, bool createWidget) : UIWidget(context, false)
  32. {
  33. if (createWidget)
  34. {
  35. widget_ = new TBScrollContainer();
  36. widget_->SetDelegate(this);
  37. GetSubsystem<UI>()->WrapWidget(this, widget_);
  38. }
  39. }
  40. UIScrollContainer::~UIScrollContainer()
  41. {
  42. }
  43. void UIScrollContainer::SetScrollMode(UI_SCROLL_MODE mode)
  44. {
  45. if (!widget_)
  46. return;
  47. ((TBScrollContainer*) widget_)->SetScrollMode((tb::SCROLL_MODE) mode);
  48. }
  49. void UIScrollContainer::SetAdaptToContentSize(bool adapt)
  50. {
  51. if (!widget_)
  52. return;
  53. ((TBScrollContainer*) widget_)->SetAdaptToContentSize(adapt);
  54. }
  55. bool UIScrollContainer::GetAdaptToContentSize()
  56. {
  57. if (!widget_)
  58. return false;
  59. return ((TBScrollContainer*) widget_)->GetAdaptToContentSize();
  60. }
  61. void UIScrollContainer::SetAdaptContentSize(bool adapt)
  62. {
  63. if (!widget_)
  64. return;
  65. ((TBScrollContainer*) widget_)->SetAdaptContentSize(adapt);
  66. }
  67. bool UIScrollContainer::GetAdaptContentSize()
  68. {
  69. if (!widget_)
  70. return false;
  71. return ((TBScrollContainer*) widget_)->GetAdaptContentSize();
  72. }
  73. UI_SCROLL_MODE UIScrollContainer::GetScrollMode()
  74. {
  75. if (!widget_)
  76. return UI_SCROLL_MODE_OFF;
  77. return (UI_SCROLL_MODE) ((TBScrollContainer*) widget_)->GetScrollMode();
  78. }
  79. void UIScrollContainer::ScrollTo(int x, int y)
  80. {
  81. if (!widget_)
  82. return;
  83. return ((TBScrollContainer *)widget_)->ScrollTo(x, y);
  84. }
  85. bool UIScrollContainer::OnEvent(const tb::TBWidgetEvent &ev)
  86. {
  87. return UIWidget::OnEvent(ev);
  88. }
  89. void UIScrollContainer::AddChild(UIWidget* child)
  90. {
  91. if (!widget_ || !child || !child->GetInternalWidget() )
  92. return;
  93. ((TBScrollContainer*) widget_)->GetContentRoot()->AddChild(child->GetInternalWidget());
  94. }
  95. }