UIMenubar.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "AtomicEditor.h"
  5. #include <Atomic/UI/TBUI.h>
  6. #include <Atomic/IO/Log.h>
  7. #include "UIMenubar.h"
  8. using namespace tb;
  9. namespace tb {
  10. // THIS MUST MATCH TBSimpleLayoutItemWidget in tb_select_item.cpp
  11. class TBSimpleLayoutItemWidget : public TBLayout, private TBWidgetListener
  12. {
  13. public:
  14. TBSimpleLayoutItemWidget(TBID image, TBSelectItemSource *source, const char *str);
  15. ~TBSimpleLayoutItemWidget();
  16. virtual bool OnEvent(const TBWidgetEvent &ev);
  17. private:
  18. TBSelectItemSource *m_source;
  19. TBTextField m_textfield;
  20. TBSkinImage m_image;
  21. TBSkinImage m_image_arrow;
  22. TBMenuWindow *m_menu; ///< Points to the submenu window if opened
  23. virtual void OnWidgetDelete(TBWidget *widget);
  24. void OpenSubMenu();
  25. void CloseSubMenu();
  26. };
  27. }
  28. namespace AtomicEditor
  29. {
  30. // == AdvancedItemWidget ======================================================
  31. MenubarItemWidget::MenubarItemWidget(MenubarItem *item, MenubarItemSource *source,
  32. TBSelectItemViewer *source_viewer, int index)
  33. : m_source(source)
  34. , m_source_viewer(source_viewer)
  35. , m_index(index)
  36. {
  37. SetSkinBg(TBIDC("TBSelectItem"));
  38. SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
  39. SetLayoutDistributionPosition(LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP);
  40. SetPaintOverflowFadeout(false);
  41. TBWidget* root = GetContentRoot();
  42. TBFontDescription fd;
  43. fd.SetID(TBIDC("Monaco-Bold"));
  44. fd.SetSize(12);
  45. TBTextField* text = new TBTextField();
  46. text->SetIgnoreInput(true);
  47. text->SetText(item->str);
  48. text->SetFontDescription(fd);
  49. root->AddChild(text);
  50. if (item->shortcut_.Length())
  51. {
  52. TBWidget* spacer = new TBWidget();
  53. spacer->SetIgnoreInput(true);
  54. spacer->SetGravity(WIDGET_GRAVITY_LEFT_RIGHT);
  55. root->AddChild(spacer);
  56. TBTextField* shortcut = new TBTextField();
  57. shortcut->SetIgnoreInput(true);
  58. shortcut->SetText(item->shortcut_.CString());
  59. shortcut->SetFontDescription(fd);
  60. shortcut->SetGravity(WIDGET_GRAVITY_RIGHT);
  61. root->AddChild(shortcut);
  62. }
  63. }
  64. bool MenubarItemWidget::OnEvent(const TBWidgetEvent &ev)
  65. {
  66. if (m_source && ev.type == EVENT_TYPE_CLICK && ev.target == this)
  67. {
  68. //OpenSubMenu();
  69. return false;
  70. }
  71. return false;
  72. }
  73. // == AdvancedItemSource ======================================================
  74. bool MenubarItemSource::Filter(int index, const char *filter)
  75. {
  76. return true;
  77. }
  78. TBWidget *MenubarItemSource::CreateItemWidget(int index, TBSelectItemViewer *viewer)
  79. {
  80. const char *string = GetItemString(index);
  81. TBSelectItemSource *sub_source = GetItemSubSource(index);
  82. TBID image = GetItemImage(index);
  83. if (sub_source || image)
  84. {
  85. if (TBSimpleLayoutItemWidget *itemwidget = new TBSimpleLayoutItemWidget(image, sub_source, string))
  86. return itemwidget;
  87. }
  88. else if (string && *string == '-')
  89. {
  90. if (TBSeparator *separator = new TBSeparator)
  91. {
  92. separator->SetGravity(WIDGET_GRAVITY_ALL);
  93. separator->SetSkinBg(TBIDC("AESeparator"));
  94. return separator;
  95. }
  96. }
  97. else if (TBLayout *layout = new MenubarItemWidget(GetItem(index), this, viewer, index))
  98. {
  99. layout->SetID(GetItem(index)->id);
  100. return layout;
  101. }
  102. return NULL;
  103. }
  104. }