Josh Engebretson 10 rokov pred
rodič
commit
6e5a29326b

+ 1 - 0
Source/Atomic/UI/UIButton.cpp

@@ -31,6 +31,7 @@ bool UIButton::OnEvent(const tb::TBWidgetEvent &ev)
         VariantMap eventData;
         VariantMap eventData;
         ConvertEvent(this, ev, eventData);
         ConvertEvent(this, ev, eventData);
         SendEvent(E_WIDGETEVENT, eventData);
         SendEvent(E_WIDGETEVENT, eventData);
+
         // this is catching the window close button
         // this is catching the window close button
         return true;
         return true;
     }
     }

+ 44 - 0
Source/Atomic/UI/UIMenuWindow.cpp

@@ -0,0 +1,44 @@
+
+#include <TurboBadger/tb_widgets.h>
+#include <TurboBadger/tb_widgets_common.h>
+#include <TurboBadger/tb_menu_window.h>
+
+#include "UIEvents.h"
+#include "UIWidget.h"
+#include "UISelectItem.h"
+#include "UIMenuWindow.h"
+
+using namespace tb;
+
+namespace Atomic
+{
+
+UIMenuWindow::UIMenuWindow(Context* context, UIWidget* target, const String& id) : UIWidget(context, false)
+  , source_(0)
+{
+    widget_ = new TBMenuWindow(target->GetInternalWidget(), TBID(id.CString()));
+    widget_->SetDelegate(this);
+}
+
+UIMenuWindow::~UIMenuWindow()
+{
+    if (source_)
+        delete source_;
+}
+
+void UIMenuWindow::Show(UISelectItemSource* source)
+{
+    if (source_)
+        delete source_;
+
+    source_ = source->GetTBItemSource();
+
+    ((TBMenuWindow*)widget_)->Show(source_, TBPopupAlignment());
+}
+
+bool UIMenuWindow::OnEvent(const tb::TBWidgetEvent &ev)
+{
+    return false;
+}
+
+}

+ 33 - 0
Source/Atomic/UI/UIMenuWindow.h

@@ -0,0 +1,33 @@
+
+#pragma once
+
+#include <TurboBadger/tb_select_item.h>
+#include "UIWidget.h"
+
+namespace Atomic
+{
+
+class UISelectItemSource;
+
+class UIMenuWindow : public UIWidget
+{
+    OBJECT(UIMenuWindow)
+
+public:
+
+    UIMenuWindow(Context* context, UIWidget* target, const String& id);
+    virtual ~UIMenuWindow();
+
+    void Show(UISelectItemSource* source);
+
+protected:
+
+    virtual bool OnEvent(const tb::TBWidgetEvent &ev);
+
+private:
+
+    tb::TBGenericStringItemSource* source_;
+
+};
+
+}

+ 80 - 0
Source/Atomic/UI/UISelectItem.cpp

@@ -0,0 +1,80 @@
+
+#include "UISelectItem.h"
+
+using namespace tb;
+
+namespace Atomic
+{
+
+UISelectItem::UISelectItem(Context* context, const String &str, const String &id, const String &skinImage) : Object(context)
+    , subSource_(0)
+{
+    SetID(id);
+    SetString(str);
+    SetSkinImage(skinImage);
+}
+
+UISelectItem::~UISelectItem()
+{
+
+}
+
+void UISelectItem::SetID(const String& id)
+{
+    id_ = TBID(id.CString());
+}
+
+void UISelectItem::SetSkinImage(const String& skinImage)
+{
+    skinImage_ = TBID(skinImage.CString());
+}
+
+void UISelectItem::SetSubSource(UISelectItemSource *subSource)
+{
+    subSource_ = subSource;
+}
+
+tb::TBGenericStringItem* UISelectItem::GetTBItem()
+{
+    tb::TBGenericStringItem* item;
+    if (!subSource_)
+    {
+         item = new tb::TBGenericStringItem(str_.CString(), id_);
+         if (skinImage_)
+             item->SetSkinImage(skinImage_);
+    }
+    else
+    {
+        item = new tb::TBGenericStringItem(str_.CString(), subSource_->GetTBItemSource());
+    }
+
+    return item;
+}
+
+// Source
+
+UISelectItemSource::UISelectItemSource(Context* context) : Object(context)
+{
+
+}
+
+UISelectItemSource::~UISelectItemSource()
+{
+
+}
+
+tb::TBGenericStringItemSource* UISelectItemSource::GetTBItemSource()
+{
+    // caller's responsibility to clean up
+    TBGenericStringItemSource* src = new TBGenericStringItemSource();
+
+    for (List<SharedPtr<UISelectItem> >::Iterator itr = items_.Begin(); itr != items_.End(); itr++)
+    {
+        tb::TBGenericStringItem* tbitem = (*itr)->GetTBItem();
+        src->AddItem(tbitem);
+    }
+
+    return src;
+}
+
+}

+ 64 - 0
Source/Atomic/UI/UISelectItem.h

@@ -0,0 +1,64 @@
+
+#pragma once
+
+#include <TurboBadger/tb_widgets.h>
+#include <TurboBadger/tb_select_item.h>
+
+#include "../Core/Object.h"
+#include "../Container/List.h"
+
+namespace Atomic
+{
+
+class UISelectItemSource;
+
+class UISelectItem : public Object
+{
+    OBJECT(UISelectItem)
+
+public:
+
+    UISelectItem(Context* context, const String& str = String::EMPTY, const String& id = String::EMPTY, const String& skinImage = String::EMPTY);
+    virtual ~UISelectItem();
+
+    void SetString(const String& str) { str_ = str; }
+    void SetID(const String& id);
+    void SetSkinImage(const String& skinImage);
+    void SetSubSource(UISelectItemSource *subSource);
+
+    tb::TBGenericStringItem* GetTBItem();
+
+private:
+
+    String str_;
+
+    // TBID
+    tb::TBID id_;
+    // TBID
+    tb::TBID skinImage_;
+
+    SharedPtr<UISelectItemSource> subSource_;
+
+};
+
+class UISelectItemSource : public Object
+{
+    OBJECT(UISelectItemSource)
+
+public:
+
+    UISelectItemSource(Context* context);
+    virtual ~UISelectItemSource();
+
+    void AddItem(UISelectItem* item) { items_.Push(SharedPtr<UISelectItem>(item)); }
+
+    // caller's responsibility to clean up
+    tb::TBGenericStringItemSource* GetTBItemSource();
+
+private:
+
+    List<SharedPtr<UISelectItem>> items_;
+
+};
+
+}

+ 18 - 1
Source/Atomic/UI/UIWidget.cpp

@@ -103,12 +103,21 @@ bool UIWidget::SetText(const String& text)
     return widget_->SetText(text.CString());
     return widget_->SetText(text.CString());
 }
 }
 
 
+void UIWidget::SetPosition(int x, int y)
+{
+    if (!widget_)
+        return;
+
+    widget_->SetPosition(TBPoint(x, y));
+
+}
+
 void UIWidget::SetSize(int width, int height)
 void UIWidget::SetSize(int width, int height)
 {
 {
     if (!widget_)
     if (!widget_)
         return;
         return;
 
 
-    widget_->SetSize(width, height);
+    widget_->SetSize(width, height);       
 }
 }
 
 
 void UIWidget::Center()
 void UIWidget::Center()
@@ -124,4 +133,12 @@ void UIWidget::Center()
 
 
 }
 }
 
 
+bool UIWidget::OnEvent(const tb::TBWidgetEvent &ev)
+{
+    if (ev.type == EVENT_TYPE_CLICK)
+        return false;
+
+    return false;
+}
+
 }
 }

+ 2 - 1
Source/Atomic/UI/UIWidget.h

@@ -28,6 +28,7 @@ public:
     bool Load(const String& filename);
     bool Load(const String& filename);
 
 
     void SetSize(int width, int height);
     void SetSize(int width, int height);
+    void SetPosition(int x, int y);
     bool SetText(const String& text);
     bool SetText(const String& text);
 
 
     void Center();
     void Center();
@@ -44,7 +45,7 @@ protected:
 
 
     void SetWidget(tb::TBWidget* widget);
     void SetWidget(tb::TBWidget* widget);
 
 
-    virtual bool OnEvent(const tb::TBWidgetEvent &ev) { return false; }
+    virtual bool OnEvent(const tb::TBWidgetEvent &ev);
     virtual void OnDelete();
     virtual void OnDelete();
 
 
     tb::TBWidget* widget_;
     tb::TBWidget* widget_;

+ 1 - 1
Source/AtomicEditor/Source/Player/AEPlayerApplication.cpp

@@ -162,7 +162,7 @@ void AEPlayerApplication::Start()
     UI* tbui = GetSubsystem<UI>();
     UI* tbui = GetSubsystem<UI>();
 
 
     tbui->Initialize("UI/language/lng_en.tb.txt");
     tbui->Initialize("UI/language/lng_en.tb.txt");
-    tbui->LoadSkin("UI/default_skin/skin.tb.txt", "");
+    tbui->LoadSkin("UI/default_skin/skin.tb.txt", "Skin/skin.tb.txt");
     tbui->AddFont("UI/fonts/vera.ttf", "Vera");
     tbui->AddFont("UI/fonts/vera.ttf", "Vera");
     tbui->SetDefaultFont("Vera", 12);
     tbui->SetDefaultFont("Vera", 12);
 
 

+ 1 - 1
Source/AtomicJS/JSBind/modules/UI.json

@@ -2,7 +2,7 @@
 	"name" : "UI",
 	"name" : "UI",
 	"sources" : ["UI"],
 	"sources" : ["UI"],
 	"includes" : ["<Atomic/Graphics/Material.h>", "<Atomic/Scene/Node.h>", "<Atomic/Scene/Scene.h>", "<Atomic/Graphics/Texture2D.h>"],
 	"includes" : ["<Atomic/Graphics/Material.h>", "<Atomic/Scene/Node.h>", "<Atomic/Scene/Scene.h>", "<Atomic/Graphics/Texture2D.h>"],
-	"classes" : ["UIWidget", "UIView", "UIWindow", "UIButton", "UITextField"],
+	"classes" : ["UIWidget", "UIView", "UIWindow", "UIButton", "UITextField", "UISelectItem", "UISelectItemSource", "UIMenuWindow"],
 	"overloads" : {
 	"overloads" : {
 	}
 	}
 }
 }