UITabContainer.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 <TurboBadger/tb_tab_container.h>
  25. #include "UI.h"
  26. #include "UIEvents.h"
  27. #include "UITabContainer.h"
  28. using namespace tb;
  29. namespace Atomic
  30. {
  31. UITabContainer::UITabContainer(Context* context, bool createWidget) : UIWidget(context, false)
  32. {
  33. if (createWidget)
  34. {
  35. widget_ = new TBTabContainer();
  36. widget_->SetDelegate(this);
  37. GetSubsystem<UI>()->WrapWidget(this, widget_);
  38. }
  39. }
  40. UITabContainer::~UITabContainer()
  41. {
  42. }
  43. UIWidget* UITabContainer::GetCurrentPageWidget()
  44. {
  45. if (!widget_)
  46. return 0;
  47. TBWidget* w = ((TBTabContainer*)widget_)->GetCurrentPageWidget();
  48. return GetSubsystem<UI>()->WrapWidget(w);
  49. }
  50. int UITabContainer::GetNumPages()
  51. {
  52. if (!widget_)
  53. return 0;
  54. return ((TBTabContainer*)widget_)->GetNumPages();
  55. }
  56. UILayout* UITabContainer::GetTabLayout()
  57. {
  58. if (!widget_)
  59. return 0;
  60. TBLayout* layout = ((TBTabContainer*)widget_)->GetTabLayout();
  61. if (!layout)
  62. return 0;
  63. UI* ui = GetSubsystem<UI>();
  64. return (UILayout*) ui->WrapWidget(layout);
  65. }
  66. void UITabContainer::SetCurrentPage(int page)
  67. {
  68. if (!widget_)
  69. return;
  70. ((TBTabContainer*)widget_)->SetCurrentPage(page);
  71. }
  72. bool UITabContainer::OnEvent(const tb::TBWidgetEvent &ev)
  73. {
  74. return UIWidget::OnEvent(ev);
  75. }
  76. }