Browse Source

Working on Drag and Drop and better way to wrap TurboBadger enums

Josh Engebretson 10 years ago
parent
commit
100c02aa49

+ 4 - 0
Source/Atomic/UI/UI.cpp

@@ -44,6 +44,7 @@ using namespace tb;
 #include "UISkinImage.h"
 #include "UITabContainer.h"
 #include "UISceneView.h"
+#include "UIDragDrop.h"
 
 namespace tb
 {
@@ -126,6 +127,9 @@ void UI::Initialize(const String& languageFile)
     rootWidget_->SetSize(width, height);
     rootWidget_->SetVisibilility(tb::WIDGET_VISIBILITY_VISIBLE);
 
+    // register the UIDragDrop subsystem
+    context_->RegisterSubsystem(new UIDragDrop(context_));
+
     SubscribeToEvent(E_MOUSEBUTTONDOWN, HANDLER(UI, HandleMouseButtonDown));
     SubscribeToEvent(E_MOUSEBUTTONUP, HANDLER(UI, HandleMouseButtonUp));
     SubscribeToEvent(E_MOUSEMOVE, HANDLER(UI, HandleMouseMove));

+ 123 - 0
Source/Atomic/UI/UIDragDrop.cpp

@@ -0,0 +1,123 @@
+
+#include <ThirdParty/TurboBadger/tb_widgets.h>
+
+#include "../IO/Log.h"
+#include "../Input/Input.h"
+#include "../Input/InputEvents.h"
+
+#include "UI.h"
+#include "UIWidget.h"
+#include "UIFontDescription.h"
+#include "UITextField.h"
+#include "UIImageWidget.h"
+#include "UISelectList.h"
+#include "UIDragDrop.h"
+
+using namespace tb;
+
+namespace Atomic
+{
+
+UIDragDrop::UIDragDrop(Context* context) : Object(context)
+{
+    SubscribeToEvent(E_MOUSEMOVE, HANDLER(UIDragDrop,HandleMouseMove));
+    SubscribeToEvent(E_MOUSEBUTTONUP, HANDLER(UIDragDrop,HandleMouseUp));
+    SubscribeToEvent(E_MOUSEBUTTONDOWN, HANDLER(UIDragDrop,HandleMouseDown));
+
+    SharedPtr<UIFontDescription> fd(new UIFontDescription(context));
+    fd->SetId("Vera");
+    fd->SetSize(12);
+
+    dragText_ = new UITextField(context);
+    dragText_->SetFontDescription(fd);
+    dragText_->SetText("This is a test!");
+    dragText_->SetGravity(WIDGET_GRAVITY_TOP);
+
+    UIPreferredSize* sz = dragText_->GetPreferredSize();
+    dragText_->SetRect(IntRect(0, 0, sz->GetMinWidth(), sz->GetMinHeight()));
+
+    dragWidget_ = new UIWidget(context);
+    dragWidget_->AddChild(dragText_);
+
+    sz = dragWidget_->GetPreferredSize();
+    dragWidget_->SetRect(IntRect(0, 0, sz->GetMinWidth(), sz->GetMinHeight()));
+
+    // put into hierarchy so we aren't pruned
+    TBWidget* root = GetSubsystem<UI>()->GetRootWidget();
+    root->AddChild(dragWidget_->GetInternalWidget());
+
+}
+
+UIDragDrop::~UIDragDrop()
+{
+
+}
+
+void UIDragDrop::HandleMouseDown(StringHash eventType, VariantMap& eventData)
+{
+    using namespace MouseButtonDown;
+
+    Input* input = GetSubsystem<Input>();
+
+    if (!input->IsMouseVisible())
+        return;
+
+    if ((eventData[P_BUTTONS].GetUInt() & MOUSEB_LEFT) && TBWidget::hovered_widget)
+    {
+        // see if we have a widget
+
+        TBWidget* tbw = TBWidget::hovered_widget;
+
+        while(tbw && !tbw->GetDelegate())
+        {
+            tbw = tbw->GetParent();
+        }
+
+        if (!tbw)
+            return;
+
+        UIWidget* widget = (UIWidget*) tbw->GetDelegate();
+
+        if (widget->GetType() == UISelectList::GetTypeStatic())
+        {
+            // handle select drag
+            LOGINFOF("DRAG Select: %s", widget->GetTypeName().CString());
+        }
+        else
+        {
+            SharedPtr<Object> dragObject(widget->GetDragObject());
+
+            dragWidget_->GetInternalWidget()->SetZ(WIDGET_Z_TOP);
+
+            if (dragObject.NotNull())
+                LOGINFOF("DRAG WIDGET: %s Object: %s", widget->GetTypeName().CString(), dragObject->GetTypeName().CString());
+            else
+                LOGINFOF("DRAG WIDGET: %s Object: None", widget->GetTypeName().CString());
+        }
+
+    }
+
+}
+
+void UIDragDrop::HandleMouseUp(StringHash eventType, VariantMap& eventData)
+{
+
+}
+
+void UIDragDrop::HandleMouseMove(StringHash eventType, VariantMap& eventData)
+{
+    using namespace MouseMove;
+
+    Input* input = GetSubsystem<Input>();
+
+    if (!input->IsMouseVisible())
+        return;
+
+    int x = eventData[P_X].GetInt();
+    int y = eventData[P_Y].GetInt();
+
+    dragWidget_->SetPosition(x, y - 20);
+
+}
+
+}

+ 40 - 0
Source/Atomic/UI/UIDragDrop.h

@@ -0,0 +1,40 @@
+
+#pragma once
+
+#include <Atomic/Core/Object.h>
+
+namespace Atomic
+{
+
+class UIWidget;
+class UIImageWidget;
+class UITextField;
+
+/// UIDragDrop subsystem,
+
+class UIDragDrop : public Object
+{
+
+    OBJECT(UIDragDrop);
+
+public:
+    /// Construct.
+    UIDragDrop(Context* context);
+    virtual ~UIDragDrop();
+
+private:
+
+    void HandleMouseDown(StringHash eventType, VariantMap& eventData);
+    void HandleMouseUp(StringHash eventType, VariantMap& eventData);
+    void HandleMouseMove(StringHash eventType, VariantMap& eventData);
+
+    SharedPtr<UIWidget> dragWidget_;
+    SharedPtr<UIImageWidget> dragImage_;
+    SharedPtr<UITextField> dragText_;
+
+    SharedPtr<Object> dragObject_;
+
+};
+
+
+}

+ 91 - 0
Source/Atomic/UI/UIPreferredSize.cpp

@@ -0,0 +1,91 @@
+
+#include "UIPreferredSize.h"
+
+namespace Atomic
+{
+
+UIPreferredSize::UIPreferredSize(int w, int h) :
+    preferredSize_(w, h)
+{
+    preferredSize_.max_w = w == 0 ? 10000 : w;
+    preferredSize_.max_h = h == 0 ? 10000 : h;
+}
+
+UIPreferredSize::~UIPreferredSize()
+{
+
+}
+
+int UIPreferredSize::GetMinWidth() const
+{
+    return preferredSize_.min_w;
+
+}
+
+int UIPreferredSize::GetMinHeight() const
+{
+    return preferredSize_.min_h;
+}
+
+int UIPreferredSize::GetMaxWidth() const
+{
+    return preferredSize_.max_w;
+}
+
+int UIPreferredSize::GetMaxHeight() const
+{
+    return preferredSize_.max_h;
+}
+
+int UIPreferredSize::GetPrefWidth() const
+{
+    return preferredSize_.pref_w;
+}
+
+int UIPreferredSize::GetPrefHeight() const
+{
+    return preferredSize_.pref_h;
+}
+
+UI_SIZE_DEP UIPreferredSize::GetSizeDep() const
+{
+    return (UI_SIZE_DEP) preferredSize_.size_dependency;
+}
+
+void UIPreferredSize::SetMinWidth(int w)
+{
+    preferredSize_.min_w = w;
+
+}
+
+void UIPreferredSize::SetMinHeight(int h)
+{
+    preferredSize_.min_h = h;
+}
+
+void UIPreferredSize::SetMaxWidth(int w)
+{
+    preferredSize_.max_w = w;
+}
+
+void UIPreferredSize::SetMaxHeight(int h)
+{
+    preferredSize_.max_h = h;
+}
+
+void UIPreferredSize::SetPrefWidth(int w)
+{
+    preferredSize_.pref_w = w;
+}
+
+void UIPreferredSize::SetPrefHeight(int h)
+{
+    preferredSize_.pref_h = h;
+}
+
+void UIPreferredSize::SetSizeDep(UI_SIZE_DEP dep)
+{
+    preferredSize_.size_dependency = (tb::SIZE_DEP) dep;
+}
+
+}

+ 68 - 0
Source/Atomic/UI/UIPreferredSize.h

@@ -0,0 +1,68 @@
+
+#pragma once
+
+#include <ThirdParty/TurboBadger/tb_widgets.h>
+#include <Atomic/Container/RefCounted.h>
+
+namespace tb
+{
+    class PreferredSize;
+}
+
+namespace Atomic
+{
+
+/// Defines how the size in one axis depend on the other axis when a widgets size is affected by constraints.
+enum UI_SIZE_DEP {
+    /// No dependency (Faster layout).
+    UI_SIZE_DEP_NONE						= tb::SIZE_DEP_NONE,
+    /// The width is dependant on the height. Additional layout pass may be required.
+    UI_SIZE_DEP_WIDTH_DEPEND_ON_HEIGHT		= tb::SIZE_DEP_WIDTH_DEPEND_ON_HEIGHT,
+    /// The height is dependant on the width. Additional layout pass may be required.
+    UI_SIZE_DEP_HEIGHT_DEPEND_ON_WIDTH		= tb::SIZE_DEP_HEIGHT_DEPEND_ON_WIDTH,
+    /// Both width and height are dependant on each other. Additional layout pass may be required.
+    UI_SIZE_DEP_BOTH						=	tb::SIZE_DEP_BOTH
+};
+
+class UIPreferredSize : public RefCounted
+{
+    friend class UIWidget;
+
+public:
+
+    UIPreferredSize(int w = 0, int h = 0);
+    virtual ~UIPreferredSize();
+
+    int GetMinWidth() const;
+    int GetMinHeight() const;
+
+    int GetMaxWidth() const;
+    int GetMaxHeight() const;
+
+    int GetPrefWidth() const;
+    int GetPrefHeight() const;
+
+    UI_SIZE_DEP GetSizeDep() const;
+
+    void SetMinWidth(int w);
+    void SetMinHeight(int h);
+
+    void SetMaxWidth(int w);
+    void SetMaxHeight(int h);
+
+    void SetPrefWidth(int w);
+    void SetPrefHeight(int h);
+
+    void SetSizeDep(UI_SIZE_DEP dep);
+
+private:
+
+    /// tb sync
+    void SetFromTBPreferredSize(const tb::PreferredSize& sz) { preferredSize_ = sz; }
+    const tb::PreferredSize& GetTBPreferredSize() { return preferredSize_; }
+
+    tb::PreferredSize preferredSize_;
+
+};
+
+}

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

@@ -15,7 +15,8 @@ namespace Atomic
 {
 
 UIWidget::UIWidget(Context* context, bool createWidget) : Object(context),
-    widget_(0)
+    widget_(0),
+    preferredSize_(new UIPreferredSize())
 {    
     AddRef();
 
@@ -55,6 +56,17 @@ bool UIWidget::Load(const String& filename)
     return true;
 }
 
+UIPreferredSize* UIWidget::GetPreferredSize()
+{
+    // error
+    if (!widget_)
+        return preferredSize_;
+
+    preferredSize_->SetFromTBPreferredSize(widget_->GetPreferredSize());
+
+    return preferredSize_;
+}
+
 UIWidget* UIWidget::GetWidget(const String& id)
 {
     if (!widget_)

+ 13 - 14
Source/Atomic/UI/UIWidget.h

@@ -1,14 +1,11 @@
 
 #pragma once
 
-#include <TurboBadger/tb_widgets.h>
-#include "../Core/Object.h"
+#include <ThirdParty/TurboBadger/tb_widgets.h>
 
-namespace tb
-{
-class TBWidget;
-}
+#include "../Core/Object.h"
 
+#include "UIPreferredSize.h"
 
 namespace Atomic
 {
@@ -30,26 +27,27 @@ public:
 
     bool Load(const String& filename);
 
+    const String& GetId();
+
+    UIWidget* GetParent();
+    UIWidget* GetContentRoot();
     IntRect GetRect();
-    void SetRect(IntRect r);
 
+    UIPreferredSize* GetPreferredSize();
+
+    void SetRect(IntRect r);    
     void SetSize(int width, int height);
     void SetPosition(int x, int y);
     void SetText(const String& text);
-
     void SetSkinBg(const String& id);
     void SetLayoutParams(UILayoutParams* params);
     void SetFontDescription(UIFontDescription* fd);
 
-    UIWidget* GetParent();
-    UIWidget* GetContentRoot();
-
     void RemoveChild(UIWidget* child, bool cleanup = true);
 
     void DeleteAllChildren();
 
-    // String ID
-    const String& GetId();
+    // String ID    
     virtual void SetId(const String& id);
 
     void Center();
@@ -97,9 +95,10 @@ protected:
     virtual void OnDelete();
 
     String id_;
-
     tb::TBWidget* widget_;
 
+    SharedPtr<UIPreferredSize> preferredSize_;
+
     SharedPtr<Object> dragObject_;
 
 };

+ 3 - 1
Source/AtomicEditorWork/Application/AEDragAndDrop.cpp

@@ -1,4 +1,4 @@
-
+/*
 #include <Atomic/IO/Log.h>
 #include <Atomic/Graphics/Graphics.h>
 #include <Atomic/Input/InputEvents.h>
@@ -116,3 +116,5 @@ void AEDragAndDrop::ConcludeDrag()
 }
 
 }
+
+*/

+ 2 - 1
Source/AtomicEditorWork/Application/AEDragAndDrop.h

@@ -1,4 +1,4 @@
-
+/*
 #pragma once
 
 #include <Atomic/Core/Object.h>
@@ -42,3 +42,4 @@ private:
 };
 
 }
+*/

+ 0 - 3
Source/AtomicEditorWork/Application/AEEditorApp.cpp

@@ -16,7 +16,6 @@
 #include <ToolCore/ToolSystem.h>
 #include <ToolCore/ToolEnvironment.h>
 
-#include "AEDragAndDrop.h"
 #include "AEEditorApp.h"
 
 // Move me
@@ -42,8 +41,6 @@ AEEditorApp::AEEditorApp(Context* context) :
 
 void AEEditorApp::Start()
 {
-    context_->RegisterSubsystem(new AEDragAndDrop(context_));
-
     Input* input = GetSubsystem<Input>();
     input->SetMouseVisible(true);
 

+ 2 - 0
Source/AtomicEditorWork/Application/AEMacDragAndDrop.h

@@ -1,3 +1,4 @@
+/*
 #pragma once
 
 namespace AtomicEditor
@@ -10,5 +11,6 @@ void InitDragAndDrop(AEDragAndDrop* dragAndDrop);
 void StartDragAndDrop();
 
 }
+*/
 
 

+ 4 - 1
Source/AtomicEditorWork/Application/AEMacDragAndDrop.mm

@@ -1,4 +1,4 @@
-
+/*
 #include <stdio.h>
 
 #include <ThirdParty/SDL/include/SDL.h>
@@ -134,6 +134,7 @@ void StartDragAndDrop()
                     owner:nil];
             [pboard setPropertyList:fileList forType:NSFilenamesPboardType];
 
+            // blocks
             [window dragImage:dragImage
                     at:dragPosition
                     offset:NSZeroSize
@@ -160,3 +161,5 @@ void InitDragAndDrop(AEDragAndDrop *dragAndDrop)
 
 }
 
+*/
+

+ 1 - 1
Source/ToolCore/Import/OpenAssetImporter.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2015 the Atomic project.
+// Copyright (c) 2008-2015 the Urho3D project.
 //
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to deal

+ 1 - 1
Source/ToolCore/Import/OpenAssetImporter.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2015 the Atomic project.
+// Copyright (c) 2008-2015 the Urho3D project.
 //
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to deal

+ 1 - 1
Source/ToolCore/Import/OpenAssetUtils.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2015 the Atomic project.
+// Copyright (c) 2008-2015 the Urho3D project.
 //
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to deal

+ 1 - 1
Source/ToolCore/Import/OpenAssetUtils.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2015 the Atomic project.
+// Copyright (c) 2008-2015 the Urho3D project.
 //
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to deal