TDME2  1.9.200
Editor.cpp
Go to the documentation of this file.
2 
3 #include <cstdlib>
4 #include <memory>
5 #include <string>
6 #include <vector>
7 
8 #include <tdme/tdme.h>
9 #include <tdme/utilities/Time.h>
10 
11 #include <tdme/engine/Color4.h>
14 #include <tdme/engine/Engine.h>
16 #include <tdme/engine/Version.h>
17 #include <tdme/gui/GUI.h>
23 #include <tdme/utilities/Console.h>
25 
26 using std::make_unique;
27 using std::string;
28 using std::unique_ptr;
29 using std::vector;
30 
32 
34 
41 using tdme::gui::GUI;
49 
50 Editor* Editor::instance = nullptr;
51 
52 Editor::Editor()
53 {
54  Tools::loadSettings(this);
55  Editor::instance = this;
56  engine = Engine::getInstance();
58  view = nullptr;
59  viewInitialized = false;
60  viewNew = nullptr;
61  popUps = make_unique<PopUps>();
62  editorView = nullptr;
63  quitRequested = false;
64 }
65 
67 }
68 
69 int Editor::main(int argc, char** argv)
70 {
71  Console::println(string("Editor ") + Version::getVersion());
72  Console::println(Version::getCopyright());
73  Console::println();
74  //
75  EngineMiniScript::registerDataTypes();
76  //
77  auto tdmeEditor = new Editor();
78  return tdmeEditor->run(argc, argv, "Editor", nullptr, Application::WINDOW_HINT_MAXIMIZED);
79 }
80 
82  if (editorView == nullptr) return false;
83  return editorView->getScreenController()->isFullScreen();
84 }
85 
86 void Editor::setView(View* view)
87 {
88  viewNew = view;
89 }
90 
92 {
93  return view;
94 }
95 
97 {
98  quitRequested = true;
99 }
100 
102 {
103  if (viewNew != nullptr) {
104  if (view != nullptr && viewInitialized == true) {
105  view->deactivate();
106  view->dispose();
107  viewInitialized = false;
108  }
109  view = viewNew;
110  viewNew = nullptr;
111  }
112  if (view != nullptr) {
113  if (viewInitialized == false) {
114  view->initialize();
115  view->activate();
116  viewInitialized = true;
117  }
118  view->display();
119  }
120  engine->display();
121  engine->getGUI()->render();
122  engine->getGUI()->handleEvents();
123  if (view != nullptr) view->tick();
124  if (quitRequested == true) {
125  if (view != nullptr) {
126  view->deactivate();
127  view->dispose();
128  }
129  Application::exit(0);
130  }
131 }
132 
134 {
135  if (view != nullptr && viewInitialized == true) {
136  view->deactivate();
137  view->dispose();
138  view = nullptr;
139  }
140  popUps->dispose();
141  engine->dispose();
142  Tools::oseDispose();
143 }
144 
146 {
147  engine->initialize();
148  // TODO: settings maybe for the next 2
149  Application::setVSyncEnabled(true);
150  Application::setLimitFPS(true);
151  engine->setSceneColor(Color4(39.0f / 255.0f, 39.0f / 255.0f, 39.0f / 255.0f, 1.0f));
153  Tools::oseInit();
154  popUps->initialize();
155  setView((editorView = make_unique<EditorView>(popUps.get())).get());
156 }
157 
158 void Editor::reshape(int width, int height)
159 {
160  engine->reshape(width, height);
161 }
162 
163 void Editor::onDrop(const vector<string>& paths) {
164  editorView->onDrop(paths);
165 }
166 
168  editorView->getScreenController()->closeProject();
169 }
void setInputEventHandler(InputEventHandler *inputEventHandler)
Set input event handler.
Color 4 definition class.
Definition: Color4.h:18
Engine main class.
Definition: Engine.h:131
void reshape(int32_t width, int32_t height)
Reshape.
Definition: Engine.cpp:972
void display()
Renders the scene.
Definition: Engine.cpp:1361
void initialize()
Initialize render engine.
Definition: Engine.cpp:733
void setPartition(Partition *partition)
Set partition.
Definition: Engine.cpp:352
void dispose()
Shutdown the engine.
Definition: Engine.cpp:2071
void setSceneColor(const Color4 &sceneColor)
Set scene color.
Definition: Engine.h:1159
Bogus/Simple partition implementation.
Prototype definition.
Definition: Prototype.h:55
GUI module class.
Definition: GUI.h:64
void handleEvents(bool clearEvents=true)
Handle screen events.
Definition: GUI.cpp:507
void render()
Render GUIs.
Definition: GUI.cpp:324
void display()
Renders the scene.
Definition: Editor.cpp:101
void quit()
Request to exit the viewer.
Definition: Editor.cpp:96
void initialize()
Initialize tdme scene editor.
Definition: Editor.cpp:145
static int main(int argc, char **argv)
Main.
Definition: Editor.cpp:69
Editor()
Public constructor.
Definition: Editor.cpp:52
unique_ptr< EditorView > editorView
Definition: Editor.h:40
void reshape(int width, int height)
Reshape tdme scene editor.
Definition: Editor.cpp:158
static STATIC_DLL_IMPEXT Editor * instance
Definition: Editor.h:33
void onClose()
On close.
Definition: Editor.cpp:167
void setView(View *view)
Set up new view.
Definition: Editor.cpp:86
void dispose()
Shutdown tdme viewer.
Definition: Editor.cpp:133
unique_ptr< PopUps > popUps
Definition: Editor.h:39
void onDrop(const vector< string > &paths)
On drop.
Definition: Editor.cpp:163
Pop ups controller accessor class.
Definition: PopUps.h:29
Console class.
Definition: Console.h:29
Time utility class.
Definition: Time.h:20
View interface, this combines application logic, regarding a application view, with screen controller...
Definition: View.h:11
virtual void deactivate()=0
Deactivate view.
virtual void activate()=0
Activate view.
virtual void display()=0
Renders the view.
virtual void initialize()=0
Initiates the view.
virtual void dispose()=0
Disposes the view.
virtual void tick()=0
Tick.