Bladeren bron

Layout and RenderTarget updates

Josh Engebretson 10 jaren geleden
bovenliggende
commit
ce452e2741

+ 12 - 4
Source/AtomicEditor/Source/Editors/JSResourceEditor.cpp

@@ -49,10 +49,15 @@ JSResourceEditor ::JSResourceEditor(Context* context, const String &fullpath, TB
     currentFindPos_(-1)
 {
 
-    TBLayout* layout = rootContentLayout_ = new TBLayout();
-    layout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
-    layout->SetSize(container_->GetRect().w, container_->GetRect().h);
+    rootContentWidget_ = new TBWidget();
+    rootContentWidget_->SetGravity(WIDGET_GRAVITY_ALL);
+
+    TBLayout* layout = new TBLayout();
+    layout->SetLayoutSize(LAYOUT_SIZE_GRAVITY);
     layout->SetGravity(WIDGET_GRAVITY_ALL);
+    layout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
+
+    rootContentWidget_->AddChild(layout);
 
     TBContainer* c = new TBContainer();
     c->SetGravity(WIDGET_GRAVITY_ALL);
@@ -103,7 +108,7 @@ JSResourceEditor ::JSResourceEditor(Context* context, const String &fullpath, TB
     layout->AddChild(c);
     layout->SetSpacing(0);
 
-    container_->GetContentRoot()->AddChild(layout);
+    container_->GetContentRoot()->AddChild(rootContentWidget_);
 
     TBStyleEdit* sedit = text->GetStyleEdit();
     TBTextTheme* theme = new TBTextTheme();
@@ -357,6 +362,9 @@ void JSResourceEditor::HandleUpdate(StringHash eventType, VariantMap& eventData)
     if (!styleEdit_)
         return;
 
+    // FIXME
+    rootContentWidget_->SetSize(rootContentWidget_->GetParent()->GetRect().w, rootContentWidget_->GetParent()->GetRect().h);
+
     // sync line number
     lineNumberList_->GetScrollContainer()->ScrollTo(0, styleEdit_->scroll_y);
     lineNumberList_->SetValue(styleEdit_->GetCaretLine());

+ 1 - 1
Source/AtomicEditor/Source/Editors/ResourceEditor.cpp

@@ -52,7 +52,7 @@ public:
 
 ResourceEditor::ResourceEditor(Context* context, const String& fullpath, TBTabContainer* container):
     Object(context), fullpath_(fullpath), container_(container),
-    editorTabLayout_(0), rootContentLayout_(0), button_(0)
+    editorTabLayout_(0), rootContentWidget_(0), button_(0)
 {
 
     String filename = GetFileNameAndExtension(fullpath_);

+ 2 - 2
Source/AtomicEditor/Source/Editors/ResourceEditor.h

@@ -41,14 +41,14 @@ public:
 
     const String& GetFullPath() { return fullpath_; }
 
-    TBLayout* GetRootContentLayout() { return rootContentLayout_; }
+    TBWidget* GetRootContentWidget() { return rootContentWidget_; }
 
 protected:
 
     String fullpath_;
     TBTabContainer* container_;
     EditorTabLayout* editorTabLayout_;
-    TBLayout* rootContentLayout_;
+    TBWidget* rootContentWidget_;
     TBButton* button_;
 
 private:

+ 9 - 12
Source/AtomicEditor/Source/Editors/SceneEditor3D/SceneEditor3D.cpp

@@ -33,16 +33,10 @@ namespace AtomicEditor
 {
 
 SceneEditor3D ::SceneEditor3D(Context* context, const String &fullpath, TBTabContainer *container) :
-    ResourceEditor(context, fullpath, container),
-    layout_(0),
-    view3DContainer_(0)
+    ResourceEditor(context, fullpath, container)
 {
-    layout_ = rootContentLayout_ = new TBLayout();
-    layout_->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
-    layout_->SetSize(container_->GetRect().w, container_->GetRect().h);
-
-    view3DContainer_ = new TBContainer();
-    view3DContainer_->SetGravity(WIDGET_GRAVITY_ALL);
+    rootContentWidget_ = new TBWidget();
+    rootContentWidget_->SetGravity(WIDGET_GRAVITY_ALL);
 
     ResourceCache* cache = GetSubsystem<ResourceCache>();
 
@@ -60,11 +54,10 @@ SceneEditor3D ::SceneEditor3D(Context* context, const String &fullpath, TBTabCon
 
     TBWidgetDelegate* delegate = sceneView_->GetWidgetDelegate();
     delegate->SetGravity(WIDGET_GRAVITY_ALL);
-    view3DContainer_->AddChild(delegate);
 
-    layout_->AddChild(view3DContainer_);
+    rootContentWidget_->AddChild(delegate);
 
-    container_->GetContentRoot()->AddChild(layout_);
+    container_->GetContentRoot()->AddChild(rootContentWidget_);
 
     gizmo3D_ = new Gizmo3D(context_);
     gizmo3D_->SetView(sceneView_);
@@ -116,6 +109,10 @@ void SceneEditor3D::SelectNode(Node* node)
 
 void SceneEditor3D::HandleUpdate(StringHash eventType, VariantMap& eventData)
 {    
+
+    // FIXME
+    rootContentWidget_->SetSize(rootContentWidget_->GetParent()->GetRect().w, rootContentWidget_->GetParent()->GetRect().h);
+
     Vector<Node*> editNodes;
     editNodes.Push(selectedNode_);
     gizmo3D_->Update(editNodes);

+ 0 - 3
Source/AtomicEditor/Source/Editors/SceneEditor3D/SceneEditor3D.h

@@ -59,9 +59,6 @@ private:
 
     SharedPtr<Gizmo3D> gizmo3D_;
 
-    TBLayout* layout_;
-    TBContainer* view3DContainer_;
-
     WeakPtr<Node> selectedNode_;
 
 };

+ 1 - 1
Source/AtomicEditor/Source/Editors/SceneEditor3D/SceneView3D.cpp

@@ -36,7 +36,7 @@ namespace AtomicEditor
 {
 
 SceneView3D ::SceneView3D(Context* context, SceneEditor3D *sceneEditor) :
-    View3D(context),
+    UIView3D(context),
     yaw_(0.0f),
     pitch_(0.0f),
     mouseLeftDown_(false),

+ 1 - 1
Source/AtomicEditor/Source/Editors/SceneEditor3D/SceneView3D.h

@@ -26,7 +26,7 @@ namespace AtomicEditor
 
 class SceneEditor3D;
 
-class SceneView3D: public View3D
+class SceneView3D: public UIView3D
 {
     OBJECT(SceneView3D);
 

+ 18 - 2
Source/AtomicEditor/Source/Editors/TextResourceEditor.cpp

@@ -33,12 +33,16 @@ TextResourceEditor ::TextResourceEditor(Context* context, const String &fullpath
     modified_(false),
     currentFindPos_(-1)
 {
+    rootContentWidget_ = new TBWidget();
+    rootContentWidget_->SetGravity(WIDGET_GRAVITY_ALL);
 
-    TBLayout* layout = rootContentLayout_ = new TBLayout();
+    TBLayout* layout =  new TBLayout();
     layout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
     layout->SetSize(container_->GetRect().w, container_->GetRect().h);
     layout->SetGravity(WIDGET_GRAVITY_ALL);
 
+    rootContentWidget_->AddChild(layout);
+
     TBContainer* c = new TBContainer();
     c->SetGravity(WIDGET_GRAVITY_ALL);
 
@@ -67,7 +71,7 @@ TextResourceEditor ::TextResourceEditor(Context* context, const String &fullpath
     layout->AddChild(c);
     layout->SetSpacing(0);
 
-    container_->GetContentRoot()->AddChild(layout);
+    container_->GetContentRoot()->AddChild(rootContentWidget_);
 
     TBStyleEdit* sedit = text->GetStyleEdit();
     sedit->text_change_listener = this;
@@ -80,6 +84,8 @@ TextResourceEditor ::TextResourceEditor(Context* context, const String &fullpath
 
     styleEdit_ = sedit;
 
+    SubscribeToEvent(E_UPDATE, HANDLER(TextResourceEditor, HandleUpdate));
+
 }
 
 TextResourceEditor::~TextResourceEditor()
@@ -193,6 +199,16 @@ bool TextResourceEditor::OnEvent(const TBWidgetEvent &ev)
     return false;
 }
 
+void TextResourceEditor::HandleUpdate(StringHash eventType, VariantMap& eventData)
+{
+
+    if (!styleEdit_)
+        return;
+
+    // FIXME
+    rootContentWidget_->SetSize(rootContentWidget_->GetParent()->GetRect().w, rootContentWidget_->GetParent()->GetRect().h);
+}
+
 
 void TextResourceEditor::FindTextClose()
 {

+ 2 - 0
Source/AtomicEditor/Source/Editors/TextResourceEditor.h

@@ -37,6 +37,8 @@ public:
 
 private:
 
+    void HandleUpdate(StringHash eventType, VariantMap& eventData);
+
     void UpdateLineNumbers();
 
     tb::TBStyleEdit* styleEdit_;

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

@@ -45,7 +45,7 @@ UIPlayer::UIPlayer(Context* context):
 
     Graphics* graphics = GetSubsystem<Graphics>();
 
-    view3D_ = new View3D(context_);
+    view3D_ = new UIView3D(context_);
 
     // horrible hack
     Viewport* viewport = view3D_->GetViewport();

+ 1 - 1
Source/AtomicEditor/Source/Player/UIPlayer.h

@@ -39,7 +39,7 @@ public:
 private:
 
     void HandleUpdate(StringHash eventType, VariantMap& eventData);
-    SharedPtr<View3D> view3D_;
+    SharedPtr<UIView3D> view3D_;
     WeakPtr<AEPlayer> aePlayer_;
 
 

+ 1 - 3
Source/AtomicEditor/Source/UI/UIResourceFrame.cpp

@@ -49,8 +49,6 @@ ResourceFrame::ResourceFrame(Context* context) :
 
     delegate_->SetGravity(WIDGET_GRAVITY_ALL);
 
-    //delegate_->SetVisibilility(WIDGET_VISIBILITY_INVISIBLE);
-
     issueswidget_ = new IssuesWidget(context_);
     errorswidget_ = new ErrorsWidget(context_);
     consolewidget_ = new ConsoleWidget(context_);
@@ -154,7 +152,7 @@ void ResourceFrame::EditResource(const String& fullpath)
         }
 
         editors_[fullpath] = editor;
-        editorLookup_[editor->GetRootContentLayout()] = editor;
+        editorLookup_[editor->GetRootContentWidget()] = editor;
         tabcontainer_->SetCurrentPage(tabcontainer_->GetNumPages()-1);
 
     }

+ 38 - 19
Source/AtomicEditor/Source/UI/UIView3D.cpp

@@ -6,11 +6,15 @@
 
 #include "AtomicEditor.h"
 
+
 #include <Atomic/UI/TBUI.h>
 #include <Atomic/IO/Log.h>
+#include <Atomic/Engine/Engine.h>
 #include <Atomic/Graphics/Graphics.h>
 #include <Atomic/Graphics/Camera.h>
 #include <Atomic/Graphics/RenderPath.h>
+#include <Atomic/Graphics/Renderer.h>
+#include <Atomic/Core/CoreEvents.h>
 
 #include "UIView3D.h"
 
@@ -24,11 +28,12 @@ namespace AtomicEditor
 {
 
 
-View3D::View3D(Context* context) :
+UIView3D::UIView3D(Context* context) :
     AEWidget(context),
     rttFormat_(Graphics::GetRGBFormat()),
     autoUpdate_(false),
-    size_(-1, -1)
+    size_(-1, -1),
+    resizeRequired_(false)
 {
     renderTexture_ = new Texture2D(context_);
     depthTexture_ = new Texture2D(context_);
@@ -39,9 +44,11 @@ View3D::View3D(Context* context) :
 
     view3DWidget_->view3D_ = this;
     delegate_->AddChild(view3DWidget_);
+
+   SubscribeToEvent(E_ENDFRAME, HANDLER(UIView3D, HandleEndFrame));
 }
 
-View3D::~View3D()
+UIView3D::~UIView3D()
 {
     // FIXME: need to refactor Light2D viewport handling
     if (viewport_.NotNull())
@@ -53,18 +60,28 @@ View3D::~View3D()
 
 }
 
-bool View3D::OnEvent(const TBWidgetEvent &ev)
+bool UIView3D::OnEvent(const TBWidgetEvent &ev)
 {
     return false;
 }
 
+void UIView3D::HandleEndFrame(StringHash eventType, VariantMap& eventData)
+{
+    if (resizeRequired_)
+    {
+        TBRect rect = view3DWidget_->GetRect();
+        OnResize(IntVector2(rect.w, rect.h));
+        resizeRequired_ = false;
+    }
+
+}
+
 
-void View3D::OnResize(const IntVector2 &newSize)
+void UIView3D::OnResize(const IntVector2 &newSize)
 {
     if (newSize.x_ == size_.x_ && newSize.y_ == size_.y_)
         return;
 
-    size_ = newSize;
     int width = newSize.x_;
     int height = newSize.y_;
 
@@ -73,18 +90,19 @@ void View3D::OnResize(const IntVector2 &newSize)
         viewport_->SetRect(IntRect(0, 0, width, height));
         renderTexture_->SetSize(width, height, rttFormat_, TEXTURE_RENDERTARGET);
         depthTexture_->SetSize(width, height, Graphics::GetDepthStencilFormat(), TEXTURE_DEPTHSTENCIL);
+
         RenderSurface* surface = renderTexture_->GetRenderSurface();
         surface->SetViewport(0, viewport_);
         surface->SetUpdateMode(autoUpdate_ ? SURFACE_UPDATEALWAYS : SURFACE_MANUALUPDATE);
         surface->SetLinkedDepthStencil(depthTexture_->GetRenderSurface());
 
-        if (!autoUpdate_)
-            surface->QueueUpdate();
+        size_ = newSize;
+
     }
 }
 
 
-void View3D::SetView(Scene* scene, Camera* camera)
+void UIView3D::SetView(Scene* scene, Camera* camera)
 {
     scene_ = scene;
     cameraNode_ = camera ? camera->GetNode() : 0;
@@ -94,7 +112,7 @@ void View3D::SetView(Scene* scene, Camera* camera)
     QueueUpdate();
 }
 
-void View3D::SetFormat(unsigned format)
+void UIView3D::SetFormat(unsigned format)
 {
     if (format != rttFormat_)
     {
@@ -102,7 +120,7 @@ void View3D::SetFormat(unsigned format)
     }
 }
 
-void View3D::SetAutoUpdate(bool enable)
+void UIView3D::SetAutoUpdate(bool enable)
 {
     if (enable != autoUpdate_)
     {
@@ -113,7 +131,7 @@ void View3D::SetAutoUpdate(bool enable)
     }
 }
 
-void View3D::QueueUpdate()
+void UIView3D::QueueUpdate()
 {
     if (!autoUpdate_)
     {
@@ -123,27 +141,27 @@ void View3D::QueueUpdate()
     }
 }
 
-Scene* View3D::GetScene() const
+Scene* UIView3D::GetScene() const
 {
     return scene_;
 }
 
-Node* View3D::GetCameraNode() const
+Node* UIView3D::GetCameraNode() const
 {
     return cameraNode_;
 }
 
-Texture2D* View3D::GetRenderTexture() const
+Texture2D* UIView3D::GetRenderTexture() const
 {
     return renderTexture_;
 }
 
-Texture2D* View3D::GetDepthTexture() const
+Texture2D* UIView3D::GetDepthTexture() const
 {
     return depthTexture_;
 }
 
-Viewport* View3D::GetViewport() const
+Viewport* UIView3D::GetViewport() const
 {
     return viewport_;
 }
@@ -164,13 +182,13 @@ View3DWidget::View3DWidget()
     data[32] = 0; data[33] = color; data[34] = 0; data[35] = 1;
 }
 
+
 void View3DWidget::OnPaint(const PaintProps &paint_props)
 {
     if (view3D_.Null())
         return;
 
     TBRect rect = GetRect();
-
     ConvertToRoot(rect.x, rect.y);
 
     IntVector2 size = view3D_->GetSize();
@@ -179,7 +197,8 @@ void View3DWidget::OnPaint(const PaintProps &paint_props)
     {
         size.x_ = rect.w;
         size.y_ = rect.h;
-        view3D_->OnResize(size);
+        view3D_->SetResizeRequired();
+        return;
     }
 
     float* data = &vertexData_[0];

+ 12 - 7
Source/AtomicEditor/Source/UI/UIView3D.h

@@ -17,11 +17,11 @@ using namespace Atomic;
 namespace AtomicEditor
 {
 
-class View3D;
+class UIView3D;
 
 class View3DWidget : public TBWidget
 {
-    friend class View3D;
+    friend class UIView3D;
 
 public:
     // For safe typecasting
@@ -33,21 +33,21 @@ public:
 
 private:
 
-    WeakPtr<View3D> view3D_;
+    WeakPtr<UIView3D> view3D_;
     PODVector<float> vertexData_;
 
 };
 
 
-class View3D : public AEWidget
+class UIView3D : public AEWidget
 {
-    OBJECT(View3D);
+    OBJECT(UIView3D);
 
 public:
     /// Construct.
-    View3D(Context* context);
+    UIView3D(Context* context);
     /// Destruct.
-    virtual ~View3D();
+    virtual ~UIView3D();
 
     /// React to resize.
     void OnResize(const IntVector2& newSize);
@@ -76,12 +76,15 @@ public:
     /// Return viewport.
     Viewport* GetViewport() const;
 
+    void SetResizeRequired() {resizeRequired_ = true;}
     const IntVector2& GetSize() const { return size_; }
 
     virtual bool OnEvent(const TBWidgetEvent &ev);
 
 protected:
 
+    void HandleEndFrame(StringHash eventType, VariantMap& eventData);
+
     /// Renderable texture.
     SharedPtr<Texture2D> renderTexture_;
     /// Depth stencil texture.
@@ -97,6 +100,8 @@ protected:
     /// Render texture auto update mode.
     bool autoUpdate_;
 
+    bool resizeRequired_;
+
     IntVector2 size_;
 
     View3DWidget* view3DWidget_;