Skip to content

Commit 1a8130e

Browse files
committed
- Refactor editor. Flix01's docking stuff doesn't work any more. Use regular ImGui and wait for the viewport/docking native solution (WIP. Buggy)
1 parent 8888a78 commit 1a8130e

File tree

24 files changed

+338
-824
lines changed

24 files changed

+338
-824
lines changed

Source Code/Core/Headers/PlatformContext.h

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class PlatformContext {
107107
inline const TaskPool& taskPool() const { return *_taskPool; }
108108

109109
Kernel& kernel();
110+
const Kernel& kernel() const;
111+
110112
DisplayWindow& activeWindow();
111113
Input::InputInterface& input();
112114

Source Code/Core/PlatformContext.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ Kernel& PlatformContext::kernel() {
104104
return _kernel;
105105
}
106106

107+
const Kernel& PlatformContext::kernel() const {
108+
return _kernel;
109+
}
110+
107111
void PlatformContext::onThreadCreated(const std::thread::id& threadID) {
108112
_gfx->onThreadCreated(threadID);
109113
}

Source Code/Editor/Editor.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ Editor::~Editor()
7272
}
7373

7474
void Editor::idle() {
75-
assert(IS_IN_RANGE_INCLUSIVE(window_opacity, 0, 255));
76-
7775
if (window_opacity != previous_window_opacity) {
7876
context().activeWindow().opacity(to_U8(window_opacity));
7977
previous_window_opacity = window_opacity;
@@ -176,7 +174,7 @@ bool Editor::init(const vec2<U16>& renderResolution) {
176174
}
177175

178176
ImGui::SetCurrentContext(_imguiContext[to_base(Context::Editor)]);
179-
_panelManager->init(_mainWindow->getDrawableSize());
177+
_panelManager->init(renderResolution);
180178

181179
ImGui::ResetStyle(_currentTheme);
182180

Source Code/Editor/Headers/Editor.h

+12-3
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ namespace Attorney {
5252
class EditorWindowManager;
5353
class EditorPanelManager;
5454
class EditorOutputWindow;
55+
class EditorSceneViewWindow;
5556
};
5657

5758
class MenuBar;
5859
class OutputWindow;
5960
class PanelManager;
6061
class DisplayWindow;
6162
class SceneGraphNode;
63+
class SceneViewWindow;
6264
class PlatformContext;
6365
class ApplicationOutput;
6466

@@ -81,6 +83,7 @@ class Editor : public PlatformContextComponent,
8183
friend class Attorney::EditorWindowManager;
8284
friend class Attorney::EditorPanelManager;
8385
friend class Attorney::EditorOutputWindow;
86+
friend class Attorney::EditorSceneViewWindow;
8487

8588
public:
8689
enum class Context : U8 {
@@ -224,13 +227,19 @@ namespace Attorney {
224227
friend class Divide::OutputWindow;
225228
};
226229

227-
class EditorPanelManager {
228-
//private:
229-
public: //ToDo: fix this -Ionut
230+
class EditorSceneViewWindow {
231+
private:
230232
static void setScenePreviewRect(Editor& editor, const Rect<I32>& rect) {
231233
editor.setScenePreviewRect(rect);
232234
}
233235

236+
237+
friend class Divide::SceneViewWindow;
238+
};
239+
240+
class EditorPanelManager {
241+
//private:
242+
public: //ToDo: fix this -Ionut
234243
static void setTransformSettings(Editor& editor, const TransformSettings& settings) {
235244
editor.setTransformSettings(settings);
236245
}

Source Code/Editor/Widgets/DockedWindows/Headers/PropertyWindow.h

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace Divide {
3939

4040
class Material;
4141
class Transform;
42+
class SceneGraphNode;
43+
4244
struct EditorComponentField;
4345
class PropertyWindow : public DockedWindow, public PlatformContextComponent {
4446
public:
@@ -47,7 +49,12 @@ class PropertyWindow : public DockedWindow, public PlatformContextComponent {
4749

4850
void draw() override;
4951

52+
const char* name() const override;
5053
protected:
54+
55+
const vector<I64>& selections() const;
56+
SceneGraphNode* node(I64 guid) const;
57+
5158
//return true if the field has been modified
5259
bool processField(EditorComponentField& field);
5360
bool processBasicField(EditorComponentField& field);
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,47 @@
1-
/*
2-
Copyright (c) 2018 DIVIDE-Studio
3-
Copyright (c) 2009 Ionut Cava
4-
5-
This file is part of DIVIDE Framework.
6-
7-
Permission is hereby granted, free of charge, to any person obtaining a copy
8-
of this software
9-
and associated documentation files (the "Software"), to deal in the Software
10-
without restriction,
11-
including without limitation the rights to use, copy, modify, merge, publish,
12-
distribute, sublicense,
13-
and/or sell copies of the Software, and to permit persons to whom the
14-
Software is furnished to do so,
15-
subject to the following conditions:
16-
17-
The above copyright notice and this permission notice shall be included in
18-
all copies or substantial portions of the Software.
19-
20-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21-
IMPLIED,
22-
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23-
PARTICULAR PURPOSE AND NONINFRINGEMENT.
24-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25-
DAMAGES OR OTHER LIABILITY,
26-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27-
IN CONNECTION WITH THE SOFTWARE
28-
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29-
30-
*/
31-
32-
#ifndef _DIVIDE_EDITOR_TABBED_WINDOW_H_
33-
#define _DIVIDE_EDITOR_TABBED_WINDOW_H_
34-
35-
#include "Platform/Headers/PlatformDefines.h"
36-
namespace Divide {
37-
38-
class TabbedWindow {
39-
public:
40-
explicit TabbedWindow(const stringImpl& name);
41-
~TabbedWindow();
42-
43-
ImGui::TabWindow& impl();
44-
const ImGui::TabWindow& impl() const;
45-
46-
public:
47-
static bool loadFromFile(ImGui::TabWindow* tabWindows, size_t count);
48-
static bool saveToFile(const ImGui::TabWindow* tabWindows, size_t count);
49-
50-
protected:
51-
stringImpl _name;
52-
ImGui::TabWindow _impl;
53-
54-
protected:
55-
static stringImpl s_savePath;
56-
};
57-
58-
}; //namespace Divide
59-
60-
#endif //_DIVIDE_EDITOR_TABBED_WINDOW_H_
1+
/*
2+
Copyright (c) 2018 DIVIDE-Studio
3+
Copyright (c) 2009 Ionut Cava
4+
5+
This file is part of DIVIDE Framework.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software
9+
and associated documentation files (the "Software"), to deal in the Software
10+
without restriction,
11+
including without limitation the rights to use, copy, modify, merge, publish,
12+
distribute, sublicense,
13+
and/or sell copies of the Software, and to permit persons to whom the
14+
Software is furnished to do so,
15+
subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in
18+
all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED,
22+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23+
PARTICULAR PURPOSE AND NONINFRINGEMENT.
24+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25+
DAMAGES OR OTHER LIABILITY,
26+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27+
IN CONNECTION WITH THE SOFTWARE
28+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29+
30+
*/
31+
32+
#ifndef _SCENE_VIEW_WINDOW_H_
33+
#define _SCENE_VIEW_WINDOW_H_
34+
35+
#include "Editor/Widgets/Headers/DockedWindow.h"
36+
37+
namespace Divide {
38+
class SceneViewWindow : public DockedWindow {
39+
public:
40+
SceneViewWindow(PanelManager& parent);
41+
~SceneViewWindow();
42+
43+
void draw() override;
44+
};
45+
}; //namespace Divide
46+
47+
#endif //_SCENE_VIEW_WINDOW_H_

Source Code/Editor/Widgets/DockedWindows/PropertyWindow.cpp

+33-13
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,13 @@ namespace Divide {
137137
processBasicField(projMatrixField);
138138
}
139139
} else {
140-
SceneManager& sceneManager = context().kernel().sceneManager();
141-
Scene& activeScene = sceneManager.getActiveScene();
140+
const vector<I64>& crtSelections = selections();
141+
for (I64 nodeGUID : crtSelections) {
142+
SceneGraphNode* sgnNode = node(nodeGUID);
143+
if (sgnNode != nullptr) {
144+
ImGui::Text(sgnNode->name().c_str());
142145

143-
const vector<I64>& selections = activeScene.getCurrentSelection();
144-
for (I64 nodeGUID : selections) {
145-
SceneGraphNode* node = activeScene.sceneGraph().findNode(nodeGUID);
146-
if (node != nullptr) {
147-
ImGui::Text(node->name().c_str());
148-
149-
vectorEASTL<EditorComponent*>& editorComp = Attorney::SceneGraphNodeEditor::editorComponents(*node);
146+
vectorEASTL<EditorComponent*>& editorComp = Attorney::SceneGraphNodeEditor::editorComponents(*sgnNode);
150147
for (EditorComponent* comp : editorComp) {
151148
if (ImGui::CollapsingHeader(comp->name().c_str()))
152149
{
@@ -164,8 +161,22 @@ namespace Divide {
164161
}
165162
}
166163
}
164+
165+
const vector<I64>& PropertyWindow::selections() const {
166+
const SceneManager& sceneManager = context().kernel().sceneManager();
167+
const Scene& activeScene = sceneManager.getActiveScene();
168+
169+
return activeScene.getCurrentSelection();
170+
}
171+
172+
SceneGraphNode* PropertyWindow::node(I64 guid) const {
173+
const SceneManager& sceneManager = context().kernel().sceneManager();
174+
const Scene& activeScene = sceneManager.getActiveScene();
167175

168-
bool PropertyWindow::processField(EditorComponentField& field) {
176+
return activeScene.sceneGraph().findNode(guid);
177+
}
178+
179+
bool PropertyWindow::processField(EditorComponentField& field) {
169180
bool ret = false;
170181
switch (field._type) {
171182
case EditorComponentFieldType::PUSH_TYPE: {
@@ -417,9 +428,6 @@ namespace Divide {
417428
}
418429

419430
void PropertyWindow::drawTransformSettings() {
420-
ImGui::Separator();
421-
ImGui::CollapsingHeader("TEST");
422-
423431
bool enableGizmo = Attorney::PanelManagerDockedWindows::editorEnableGizmo(_parent);
424432
ImGui::Checkbox("Transform Gizmo", &enableGizmo);
425433
Attorney::PanelManagerDockedWindows::editorEnableGizmo(_parent, enableGizmo);
@@ -483,4 +491,16 @@ namespace Divide {
483491
_parent.setTransformSettings(settings);
484492
}
485493
}
494+
495+
const char* PropertyWindow::name() const {
496+
const vector<I64> nodes = selections();
497+
if (nodes.empty()) {
498+
return DockedWindow::name();
499+
}
500+
if (nodes.size() == 1) {
501+
return node(nodes.front())->name().c_str();
502+
}
503+
504+
return Util::StringFormat("%s, %s, ...", node(nodes[0])->name().c_str(), node(nodes[1])->name().c_str()).c_str();
505+
}
486506
}; //namespace Divide
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#include "stdafx.h"
2+
3+
#include "Headers/SceneViewWindow.h"
4+
#include "Widgets/Headers/PanelManager.h"
5+
6+
#include "Editor/Headers/Editor.h"
7+
#include "Core/Headers/PlatformContext.h"
8+
#include "Platform/Video/Headers/GFXDevice.h"
9+
#include "Platform/Video/Textures/Headers/Texture.h"
10+
11+
#include <imgui_internal.h>
12+
13+
namespace Divide {
14+
15+
SceneViewWindow::SceneViewWindow(PanelManager& parent)
16+
: DockedWindow(parent, "SceneView")
17+
{
18+
19+
}
20+
21+
SceneViewWindow::~SceneViewWindow()
22+
{
23+
24+
}
25+
26+
void SceneViewWindow::draw() {
27+
ImVec2 size(0.0f, 0.0f);
28+
ImGuiWindow* window = ImGui::GetCurrentWindow();
29+
30+
const RenderTarget& rt = _parent.context().gfx().renderTargetPool().renderTarget(RenderTargetID(RenderTargetUsage::EDITOR));
31+
const Texture_ptr& gameView = rt.getAttachment(RTAttachmentType::Colour, 0).texture();
32+
33+
int w = (int)gameView->getWidth();
34+
int h = (int)gameView->getHeight();
35+
36+
if (window && !window->SkipItems && h > 0) {
37+
38+
float zoom = 0.85f;
39+
ImVec2 curPos = ImGui::GetCursorPos();
40+
const ImVec2 wndSz(size.x > 0 ? size.x : ImGui::GetWindowSize().x - curPos.x, size.y > 0 ? size.y : ImGui::GetWindowSize().y - curPos.y);
41+
IM_ASSERT(wndSz.x != 0 && wndSz.y != 0 && zoom != 0);
42+
43+
ImRect bb(window->DC.CursorPos, ImVec2(window->DC.CursorPos.x + wndSz.x, window->DC.CursorPos.y + wndSz.y));
44+
ImGui::ItemSize(bb);
45+
if (ImGui::ItemAdd(bb, NULL)) {
46+
47+
ImVec2 imageSz = wndSz - ImVec2(0.2f, 0.2f);
48+
ImVec2 remainingWndSize(0, 0);
49+
const float aspectRatio = (float)w / (float)h;
50+
51+
if (aspectRatio != 0) {
52+
const float wndAspectRatio = wndSz.x / wndSz.y;
53+
if (aspectRatio >= wndAspectRatio) {
54+
imageSz.y = imageSz.x / aspectRatio;
55+
remainingWndSize.y = wndSz.y - imageSz.y;
56+
}
57+
else {
58+
imageSz.x = imageSz.y*aspectRatio;
59+
remainingWndSize.x = wndSz.x - imageSz.x;
60+
}
61+
}
62+
63+
const float zoomFactor = .5f / zoom;
64+
ImVec2 uvExtension = ImVec2(2.f*zoomFactor, 2.f*zoomFactor);
65+
if (remainingWndSize.x > 0) {
66+
const float remainingSizeInUVSpace = 2.f*zoomFactor*(remainingWndSize.x / imageSz.x);
67+
const float deltaUV = uvExtension.x;
68+
const float remainingUV = 1.f - deltaUV;
69+
if (deltaUV < 1) {
70+
float adder = (remainingUV < remainingSizeInUVSpace ? remainingUV : remainingSizeInUVSpace);
71+
uvExtension.x += adder;
72+
remainingWndSize.x -= adder * zoom * imageSz.x;
73+
imageSz.x += adder * zoom * imageSz.x;
74+
}
75+
}
76+
if (remainingWndSize.y > 0) {
77+
const float remainingSizeInUVSpace = 2.f*zoomFactor*(remainingWndSize.y / imageSz.y);
78+
const float deltaUV = uvExtension.y;
79+
const float remainingUV = 1.f - deltaUV;
80+
if (deltaUV < 1) {
81+
float adder = (remainingUV < remainingSizeInUVSpace ? remainingUV : remainingSizeInUVSpace);
82+
uvExtension.y += adder;
83+
remainingWndSize.y -= adder * zoom * imageSz.y;
84+
imageSz.y += adder * zoom * imageSz.y;
85+
}
86+
}
87+
88+
89+
ImVec2 startPos = bb.Min, endPos = bb.Max;
90+
startPos.x += remainingWndSize.x*.5f;
91+
startPos.y += remainingWndSize.y*.5f;
92+
endPos.x = startPos.x + imageSz.x;
93+
endPos.y = startPos.y + imageSz.y;
94+
95+
const ImGuiID id = (ImGuiID)((U64)&_parent) + 1;
96+
ImGui::PushID(id);
97+
98+
window->DrawList->AddImage((void *)(intptr_t)gameView->getHandle(), startPos, endPos, ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f));
99+
100+
Attorney::EditorSceneViewWindow::setScenePreviewRect(_parent.context().editor(), Rect<I32>(startPos.x, startPos.y, endPos.x, endPos.y));
101+
102+
ImGui::PopID();
103+
}
104+
}
105+
}
106+
};

0 commit comments

Comments
 (0)