TDME2  1.9.200
EditorScreenController.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <memory>
5 #include <string>
6 #include <unordered_map>
7 #include <vector>
8 
9 #include <tdme/tdme.h>
11 #include <tdme/engine/fwd-tdme.h>
31 #include <tdme/utilities/Console.h>
33 
34 using std::map;
35 using std::string;
36 using std::unique_ptr;
37 using std::unordered_map;
38 using std::vector;
39 
68 
69 /**
70  * Editor screen controller
71  * @author Andreas Drewke
72  */
74  : public ScreenController
75  , public GUIActionListener
76  , public GUIChangeListener
77  , public GUIFocusListener
80  , public GUIDragRequestListener
81 {
82 public:
83  enum FileType {
101  };
102 
103  /**
104  * Editor tab view
105  */
107  public:
109 
110  private:
111  string id;
112  string name;
114  unique_ptr<TabView> tabView;
116 
117  public:
118  /**
119  * Public default constructor
120  */
122 
123  /**
124  * Public constructor
125  * @param id id
126  * @param name name
127  * @param type type
128  * @param tabView tab view
129  * @param frameBufferNode frame buffer node
130  */
132  const string& id,
133  const string& name,
134  TabType type,
135  TabView* tabView,
137  ):
138  id(id),
139  name(name),
140  type(type),
141  tabView(unique_ptr<TabView>(tabView)),
143  {}
144 
145  /**
146  * @return id
147  */
148  inline const string& getId() {
149  return id;
150  }
151 
152  /**
153  * @return id
154  */
155  inline const string& getName() {
156  return name;
157  }
158 
159  /**
160  * @return tab type
161  */
162  inline TabType getType() {
163  return type;
164  }
165 
166  /**
167  * @return tab view
168  */
169  inline TabView* getTabView() {
170  return tabView.get();
171  }
172 
173  /**
174  * @return frame buffer GUI node
175  */
177  return frameBufferNode;
178  }
179 
180  };
181 
182 private:
183  EditorView* view { nullptr };
184  GUIScreenNode* screenNode { nullptr };
187  GUIParentNode* tabs { nullptr };
188  GUIParentNode* tabsHeader { nullptr };
190  GUIElementNode* outliner { nullptr };
194  string projectPath;
196  unordered_map<string, EditorTabView> tabViews;
197  vector<EditorTabView*> tabViewVector;
199  int64_t timeFileNameSearchTerm { -1LL };
201 
204  vector<string> logMessages;
205  bool logUpdateRequired { false };
206 
207  //
208  class FileOpenThread: public Thread {
209  public:
210  // forbid class copy
212 
213  /**
214  * Constructor
215  * @param tabId tab id
216  * @param fileType file type
217  * @param absoluteFileName absolute file name
218  */
220 
221  /**
222  * @return tab id
223  */
224  inline const string& getTabId() {
225  return tabId;
226  }
227 
228  /**
229  * @return file type
230  */
232  return fileType;
233  }
234 
235  /**
236  * @return absolute filename
237  */
238  inline const string& getAbsoluteFileName() {
239  return absoluteFileName;
240  }
241 
242  /**
243  * @return error message
244  */
245  inline const string& getErrorMessage() {
246  return errorMessage;
247  }
248 
249  /**
250  * @return progress
251  */
252  inline float getProgress() {
253  return progress;
254  }
255 
256  /**
257  * @return prototype
258  */
259  inline unique_ptr<Prototype>& getPrototype() {
260  return prototype;
261  }
262 
263  /**
264  * @return scene
265  */
266  inline unique_ptr<Scene>& getScene() {
267  return scene;
268  }
269 
270  /**
271  * @return if error occurred during opening files
272  */
273  inline bool isError() {
274  return error;
275  }
276 
277  /**
278  * @return if thread has finished
279  */
280  inline bool isFinished() {
281  return finished;
282  }
283 
284  /**
285  * Run
286  */
287  virtual void run();
288  private:
290  string tabId;
292  string errorMessage;
293  float progress { 0.0f };
294 
295  unique_ptr<Prototype> prototype;
296  unique_ptr<Scene> scene;
297  bool error { false };
298  volatile bool finished { false };
299  };
300 
301  unique_ptr<FileOpenThread> fileOpenThread;
302 
303  struct FileEntity {
304  string id;
305  string buttonXML;
306  Texture* thumbnailTexture { nullptr };
307  bool scrollTo { false };
308  };
309 
310  //
311  class ScanFilesThread: public Thread {
312  public:
313  // forbid class copy
315 
316  /**
317  * Constructor
318  * @param pathName path name
319  */
321 
322  /**
323  * @return path name
324  */
325  inline const string& getPathName() {
326  return pathName;
327  }
328 
329  /**
330  * @return error message
331  */
332  inline const string& getErrorMessage() {
333  return errorMessage;
334  }
335 
336  /**
337  * @return progress
338  */
339  inline float getProgress() {
340  return progress;
341  }
342 
343  /**
344  * @return if error occurred during opening files
345  */
346  inline bool isError() {
347  return error;
348  }
349 
350  /**
351  * @return if thread has finished
352  */
353  inline bool isFinished() {
354  return finished;
355  }
356 
357  /**
358  * Run
359  */
360  virtual void run();
361 
362  private:
364  string pathName;
365  string searchTerm;
366  string errorMessage;
367  float progress { 0.0f };
368 
369  bool error { false };
370  volatile bool finished { false };
371  };
372 
374  vector<unique_ptr<FileEntity>> fileEntities;
375 
378 
379  /**
380  * Lock file entities mutex
381  */
382  inline void lockFileEntities() {
384  }
385 
386  /**
387  * Unlock file entities mutex
388  */
389  inline void unlockFileEntities() {
391  }
392 
393  /**
394  * @return file entities
395  */
396  inline vector<unique_ptr<FileEntity>>& getFileEntities() {
397  return fileEntities;
398  }
399 
400  unique_ptr<ScanFilesThread> scanFilesThread;
401  vector<unique_ptr<FileEntity>> pendingFileEntities;
402 
403 public:
404  // forbid class copy
406 
407  /**
408  * Public constructor
409  * @param view view
410  */
412 
413  /**
414  * Public destructor
415  */
417 
418  // overridden methods
419  GUIScreenNode* getScreenNode() override;
420  void initialize() override;
421  void dispose() override;
422 
423  /**
424  * Set screen caption
425  * @param text text
426  */
427  void setScreenCaption(const string& text);
428 
429  // overridden methods
430  void onChange(GUIElementNode* node) override;
431  void onAction(GUIActionListenerType type, GUIElementNode* node) override;
432  void onFocus(GUIElementNode* node) override;
433  void onUnfocus(GUIElementNode* node) override;
434  void onContextMenuRequest(GUIElementNode* node, int mouseX, int mouseY) override;
435  void onTooltipShowRequest(GUINode* node, int mouseX, int mouseY) override;
436  void onTooltipCloseRequest() override;
437  void onDragRequest(GUIElementNode* node, int mouseX, int mouseY) override;
438 
439  /**
440  * @return project path
441  */
442  const string& getProjectPath() {
443  return projectPath;
444  }
445 
446  /**
447  * Open project
448  * @param pathName path name
449  */
450  void openProject(const string& pathName);
451 
452  /**
453  * On open project
454  */
455  void onOpenProject();
456 
457  /**
458  * Scan project paths
459  */
460  void scanProjectPaths();
461 
462  /**
463  * Scan project paths
464  * @param path path
465  * @param xml xml
466  */
467  void scanProjectPaths(const string& path, string& xml);
468 
469  /**
470  * Reload files
471  */
472  void reload();
473 
474  /**
475  * Browse to file name
476  * @param fileName file name
477  */
478  void browseTo(const string& fileName);
479 
480  /**
481  * Close tab
482  * @param tabId tab id
483  */
484  void closeTab(const string& tabId);
485 
486  /**
487  * Close tabs
488  */
489  void closeTabs();
490 
491  /**
492  * Close project
493  */
494  void closeProject();
495 
496  /**
497  * Clear project path files
498  */
499  void clearProjectPathFiles();
500 
501  /**
502  * Scan project path files
503  */
505 
506  /**
507  * Start scan files
508  */
509  void startScanFiles();
510 
511  /**
512  * Stop scan files
513  */
514  void stopScanFiles();
515 
516  /**
517  * Reset scan files
518  */
519  void resetScanFiles();
520 
521  /**
522  * Add project path files pending file entities
523  */
524  void addPendingFileEntities();
525 
526  /**
527  * Set relative project path
528  * @param relativeProjectPath relative project path
529  */
530  void setRelativeProjectPath(const string& relativeProjectPath);
531 
532  /**
533  * On add file
534  * @param type type
535  */
536  void onAddFile(const string& type);
537 
538  /**
539  * On add file
540  * @param pathName path name
541  * @param fileName file name
542  * @param type type
543  */
544  void addFile(const string& pathName, const string& fileName, const string& type);
545 
546  /**
547  * On open file
548  * @param absoluteProjectFileName absolute project file name
549  */
550  inline void onOpenFile(const string& absoluteFileName) {
551  openFile(absoluteFileName);
552  }
553 
554  /**
555  * Open file
556  * @param absoluteProjectFileName absolute project file name
557  */
558  void openFile(const string& absoluteFileName);
559 
560  /**
561  * On open file finish
562  * @param tabId tab id
563  * @param fileType file type
564  * @param absoluteFileName absolute file name
565  * @param prototype prototype
566  * @param scene scene
567  */
568  void onOpenFileFinish(const string& tabId, FileType fileType, const string& absoluteFileName, unique_ptr<Prototype> prototype, unique_ptr<Scene> scene);
569 
570  /**
571  * Store outliner state
572  * @param outlinerState outliner state
573  */
574  void storeOutlinerState(TabView::OutlinerState& outlinerState);
575 
576  /**
577  * Restore outliner state
578  * @param outlinerState outliner state
579  */
580  void restoreOutlinerState(const TabView::OutlinerState& outlinerState);
581 
582  /**
583  * @return outliner selection
584  */
585  const string getOutlinerSelection();
586 
587  /**
588  * Set outliner selection
589  * @param newSelectionValue new selection value
590  */
591  void setOutlinerSelection(const string& newSelectionValue);
592 
593  /**
594  * Set outliner content
595  * @param xml xml
596  */
597  void setOutlinerContent(const string& xml);
598 
599  /**
600  * Set outliner add content
601  * @param xml xml
602  */
603  void setOutlinerAddDropDownContent(const string& xml);
604 
605  /**
606  * Set details content
607  * @param xml xml
608  */
609  void setDetailsContent(const string& xml);
610 
611  /**
612  * @return is full screen
613  */
614  bool isFullScreen();
615 
616  /**
617  * Update full screen menu entry
618  */
620 
621  /**
622  * Update tabs menu entries
623  */
624  void updateTabsMenuEntries();
625 
626  /**
627  * Set fullscreen
628  * @param fullScreen full screen
629  */
630  void setFullScreen(bool fullScreen);
631 
632  /**
633  * Enable scene screen menu entry
634  */
635  void enableSceneMenuEntry();
636 
637  /**
638  * Disable scene screen menu entry
639  */
640  void disableSceneMenuEntry();
641 
642  /**
643  * Show the information pop up / modal
644  * @param caption caption
645  * @param message message
646  */
647  void showInfoPopUp(const string& caption, const string& message);
648 
649  /**
650  * Get engine viewport constraints
651  * @param viewPortNode view port node
652  * @param left left
653  * @param top top
654  * @param width width
655  * @param height height
656  */
657  void getViewPort(GUINode* viewPortNode, int& left, int& top, int& width, int& height);
658 
659  /**
660  * @return selected tab id
661  */
662  const string getSelectedTabId();
663 
664  /**
665  * Returns editor tabs
666  * @return tabs
667  */
668  inline vector<EditorTabView*>& getTabs() {
669  return tabViewVector;
670  }
671 
672  /**
673  * Returns editor tab view by given tab id
674  * @param tabId editor tab id
675  * @return tab
676  */
677  inline EditorTabView* getTab(const string& tabId) {
678  auto tabViewIt = tabViews.find(tabId);
679  if (tabViewIt != tabViews.end()){
680  return &tabViewIt->second;
681  }
682  return nullptr;
683  }
684 
685  /**
686  * @return selected tab
687  */
689  return getTab(getSelectedTabId());
690  }
691 
692  /**
693  * Get tab at given index
694  * @return tab at given index
695  */
696  inline EditorTabView* getTabAt(int idx) {
697  if (idx < 0 || idx >= tabViewVector.size()) return nullptr;
698  return tabViewVector[idx];
699  }
700 
701  /**
702  * Select tab with given id
703  * @param tabId tab id
704  */
705  bool selectTab(const string& tabId);
706 
707  /**
708  * @return tab count
709  */
710  inline int getTabCount() {
711  return tabViewVector.size();
712  }
713 
714  /**
715  * @return selected tab index
716  */
717  int getSelectedTabIdx();
718 
719  /**
720  * Select tab at given index
721  * @param idx index
722  */
723  bool selectTabAt(int idx);
724 
725  /**
726  * Tick
727  */
728  void tick();
729 
730  /**
731  * On quit
732  */
733  void onQuit();
734 
735  /**
736  * Is drop on node
737  * @param dropX drop x
738  * @param dropY drop y
739  * @param nodeId node id
740  * @return drop is on node or not
741  */
742  bool isDropOnNode(int dropX, int dropY, const string& nodeId);
743 
744  /**
745  * Returns relative path within project path
746  * @param absoluteFileName absolute file name
747  * @return relative path within project path
748  */
749  inline const string getRelativePath(const string& absoluteFileName) {
750  auto absoluteFileNameUnix = StringTools::replace(absoluteFileName, "\\", "/");
751  auto projectPathUnix = StringTools::replace(projectPath, "\\", "/");
752  if (StringTools::startsWith(absoluteFileNameUnix, projectPathUnix + "/") == false) return absoluteFileNameUnix;
753  return StringTools::substring(absoluteFileNameUnix, projectPathUnix.size() + 1);
754  }
755 
756  /**
757  * On drop
758  * @param paths paths of items that were dropped
759  */
760  void onDrop(const vector<string>& paths);
761 
762  /**
763  * Update log
764  */
765  void updateLog();
766 };
Engine main class.
Definition: Engine.h:131
Frame buffer class.
Definition: FrameBuffer.h:22
Texture entity.
Definition: Texture.h:24
Prototype definition.
Definition: Prototype.h:55
Scene definition.
Definition: Scene.h:50
GUI node base class.
Definition: GUINode.h:64
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:42
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
Mutex implementation.
Definition: Mutex.h:19
void unlock()
Unlocks this mutex.
Definition: Mutex.h:54
void lock()
Locks the mutex, additionally mutex locks will block until other locks have been unlocked.
Definition: Mutex.h:47
Base class for threads.
Definition: Thread.h:20
EditorTabView(const string &id, const string &name, TabType type, TabView *tabView, GUIImageNode *frameBufferNode)
Public constructor.
bool isDropOnNode(int dropX, int dropY, const string &nodeId)
Is drop on node.
EditorTabView * getTab(const string &tabId)
Returns editor tab view by given tab id.
void onContextMenuRequest(GUIElementNode *node, int mouseX, int mouseY) override
On context menu request.
void onOpenFile(const string &absoluteFileName)
On open file.
const string getRelativePath(const string &absoluteFileName)
Returns relative path within project path.
void setOutlinerSelection(const string &newSelectionValue)
Set outliner selection.
void browseTo(const string &fileName)
Browse to file name.
EditorTabView * getTabAt(int idx)
Get tab at given index.
void setOutlinerAddDropDownContent(const string &xml)
Set outliner add content.
void setOutlinerContent(const string &xml)
Set outliner content.
void restoreOutlinerState(const TabView::OutlinerState &outlinerState)
Restore outliner state.
void onChange(GUIElementNode *node) override
On change.
void addPendingFileEntities()
Add project path files pending file entities.
void setScreenCaption(const string &text)
Set screen caption.
void storeOutlinerState(TabView::OutlinerState &outlinerState)
Store outliner state.
void setRelativeProjectPath(const string &relativeProjectPath)
Set relative project path.
void onUnfocus(GUIElementNode *node) override
On unfocus.
void onTooltipCloseRequest() override
On tooltip close request.
void setDetailsContent(const string &xml)
Set details content.
void onDragRequest(GUIElementNode *node, int mouseX, int mouseY) override
On drag request.
void onFocus(GUIElementNode *node) override
On focus.
vector< EditorTabView * > & getTabs()
Returns editor tabs.
void showInfoPopUp(const string &caption, const string &message)
Show the information pop up / modal.
void onAction(GUIActionListenerType type, GUIElementNode *node) override
void onOpenFileFinish(const string &tabId, FileType fileType, const string &absoluteFileName, unique_ptr< Prototype > prototype, unique_ptr< Scene > scene)
On open file finish.
void getViewPort(GUINode *viewPortNode, int &left, int &top, int &width, int &height)
Get engine viewport constraints.
bool selectTab(const string &tabId)
Select tab with given id.
void addFile(const string &pathName, const string &fileName, const string &type)
On add file.
void openFile(const string &absoluteFileName)
Open file.
void onTooltipShowRequest(GUINode *node, int mouseX, int mouseY) override
On tooltip show request.
Console class.
Definition: Console.h:29
String tools class.
Definition: StringTools.h:22
GUI action listener interface.
GUI change listener interface.
GUI focus listener interface.
GUI node padding entity.
Screen controller, which connects GUI screen definition with code.
Tab controller, which connects UI with logic.
Definition: TabController.h:34
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6