UIMenuWindow.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <TurboBadger/tb_widgets.h>
  2. #include <TurboBadger/tb_widgets_common.h>
  3. #include <TurboBadger/tb_menu_window.h>
  4. #include "UI.h"
  5. #include "UIEvents.h"
  6. #include "UIWidget.h"
  7. #include "UISelectItem.h"
  8. #include "UIMenuWindow.h"
  9. using namespace tb;
  10. namespace Atomic
  11. {
  12. UIMenuWindow::UIMenuWindow(Context* context, UIWidget* target, const String& id) : UIWidget(context, false)
  13. , source_(0)
  14. {
  15. widget_ = new TBMenuWindow(target->GetInternalWidget(), TBID(id.CString()));
  16. widget_->SetDelegate(this);
  17. GetSubsystem<UI>()->WrapWidget(this, widget_);
  18. }
  19. UIMenuWindow::~UIMenuWindow()
  20. {
  21. if (source_)
  22. delete source_;
  23. }
  24. void UIMenuWindow::Show(UISelectItemSource* source, int x, int y)
  25. {
  26. if (source_)
  27. delete source_;
  28. source_ = source->GetTBItemSource();
  29. if (x != -1 && y != -1)
  30. {
  31. ((TBMenuWindow*)widget_)->Show(source_, TBPopupAlignment(TBPoint(x, y)));
  32. }
  33. else
  34. {
  35. ((TBMenuWindow*)widget_)->Show(source_, TBPopupAlignment());
  36. }
  37. }
  38. bool UIMenuWindow::OnEvent(const tb::TBWidgetEvent &ev)
  39. {
  40. return false;
  41. }
  42. void UIMenuWindow::Close()
  43. {
  44. if (!widget_)
  45. return;
  46. ((TBMenuWindow*)widget_)->Close();
  47. }
  48. }