Cafu Engine
ChildFrame.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_GUIEDITOR_CHILD_FRAME_HPP_INCLUDED
8 #define CAFU_GUIEDITOR_CHILD_FRAME_HPP_INCLUDED
9 
10 #include "wx/docmdi.h"
11 #include "wx/aui/framemanager.h"
12 
13 #include "ToolManager.hpp"
14 #include "../CommandHistory.hpp"
15 
16 #include "Math3D/Vector2.hpp"
17 
18 
19 namespace cf { namespace TypeSys { class TypeInfoT; } }
20 
21 class ParentFrameT;
22 class GameConfigT;
23 class wxAuiToolBar;
24 
25 
26 namespace GuiEditor
27 {
28  class RenderWindowT;
29  class WindowHierarchyT;
30  class WindowInspectorT;
31  class GuiInspectorT;
32  class GuiDocumentT;
33 
34 
35  class ChildFrameT : public wxMDIChildFrame
36  {
37  public:
38 
39  /// Constructor to create a child frame for GUI editing.
40  /// @param Parent The parent frame of this child frame.
41  /// @param FileName Filename for this frame.
42  /// @param GuiDocument This frames gui document. The frame becomes the owner of the document, i.e. it is responsible for destructing it.
43  /// (\c GuiDocument is created externally so that this constructor doesn't fail on doc creation failure.)
44  ChildFrameT(ParentFrameT* Parent, const wxString& FileName, GuiDocumentT* GuiDocument);
45  ~ChildFrameT();
46 
47  GuiDocumentT* GetGuiDoc() { return m_GuiDocument; }
48 
49  ToolManagerT* GetToolManager() { return &m_ToolManager; }
50 
51  /// Snaps a single position coordinate to the current grid.
52  float SnapToGrid(float Value) const;
53 
54  /// Snaps a position in GUI space to the grid.
55  Vector2fT SnapToGrid(const Vector2fT& Position) const;
56 
57  /// [...]
58  /// All(!) commands for modifying the document must be submitted via this method.
59  bool SubmitCommand(CommandT* Command);
60 
61  bool Save(bool AskForFileName=false);
62 
63 
64  private:
65 
66  /// Recursively builds the "Components" menu, traversing the given TypeInfoT hierarchy.
67  static void BuildComponentsMenu(wxMenu* MenuParent, const cf::TypeSys::TypeInfoT* TypeParent);
68 
69  GuiDocumentT* m_GuiDocument;
70  wxString m_FileName;
71  GameConfigT* m_GameConfig;
72  CommandHistoryT m_History; ///< The command history.
73  unsigned long m_LastSavedAtCommandNr;
74 
75  bool m_SnapToGrid;
76  unsigned long m_GridSpacing;
77 
78  ToolManagerT m_ToolManager;
79 
80  wxAuiManager m_AUIManager;
81 
82  ParentFrameT* m_Parent;
83  RenderWindowT* m_RenderWindow;
84  WindowHierarchyT* m_WindowHierarchy;
85  WindowInspectorT* m_WindowInspector;
86  GuiInspectorT* m_GuiInspector;
87 
88  wxMenu* m_FileMenu;
89  wxMenu* m_EditMenu;
90  wxMenu* m_CreateMenu;
91  wxMenu* m_ViewMenu;
92 
93  wxAuiToolBar* m_ToolbarTools;
94 
95 
96  enum
97  {
98  ID_MENU_FILE_CLOSE=wxID_HIGHEST+1+2000,
99  ID_MENU_FILE_SAVE,
100  ID_MENU_FILE_SAVEAS,
101 
102  ID_MENU_EDIT_DELETE,
103  ID_MENU_EDIT_SNAP_TO_GRID,
104  ID_MENU_EDIT_SET_GRID_SIZE,
105 
106  ID_MENU_CREATE_WINDOW,
107  ID_MENU_CREATE_COMPONENT_FIRST,
108  ID_MENU_CREATE_COMPONENT_MAX = ID_MENU_CREATE_COMPONENT_FIRST + 100,
109 
110  ID_MENU_VIEW_WINDOW_HIERARCHY,
111  ID_MENU_VIEW_WINDOWINSPECTOR,
112  ID_MENU_VIEW_GUIINSPECTOR,
113  ID_MENU_VIEW_RESTORE_DEFAULT_LAYOUT,
114  ID_MENU_VIEW_RESTORE_USER_LAYOUT,
115  ID_MENU_VIEW_SAVE_USER_LAYOUT,
116 
117  ID_TOOLBAR_DOC_PREVIEW,
118 
119  ID_TOOLBAR_TOOL_SELECTION,
120  ID_TOOLBAR_TOOL_NEW_WINDOW,
121 
122  ID_TOOLBAR_WINDOW_MOVE_UP,
123  ID_TOOLBAR_WINDOW_MOVE_DOWN,
124  ID_TOOLBAR_WINDOW_ROTATE_CW,
125  ID_TOOLBAR_WINDOW_ROTATE_CCW,
126 
127  ID_TOOLBAR_TEXT_ALIGN_LEFT,
128  ID_TOOLBAR_TEXT_ALIGN_CENTER,
129  ID_TOOLBAR_TEXT_ALIGN_RIGHT,
130 
131  ID_TOOLBAR_ZOOM_IN,
132  ID_TOOLBAR_ZOOM_OUT,
133  ID_TOOLBAR_ZOOM_FIT,
134  ID_TOOLBAR_ZOOM_100
135  };
136 
137  void OnMenuFile(wxCommandEvent& CE);
138  void OnMenuFileUpdate(wxUpdateUIEvent& UE);
139  void OnMenuUndoRedo(wxCommandEvent& CE);
140  void OnUpdateEditUndoRedo(wxUpdateUIEvent& UE);
141  void OnMenuEditCut(wxCommandEvent& CE);
142  void OnMenuEditCopy(wxCommandEvent& CE);
143  void OnMenuEditPaste(wxCommandEvent& CE);
144  void OnMenuEditDelete(wxCommandEvent& CE);
145  void OnMenuEditGrid(wxCommandEvent& CE);
146  void OnMenuEditUpdate(wxUpdateUIEvent& UE);
147  void OnMenuCreate(wxCommandEvent& CE);
148  void OnMenuView(wxCommandEvent& CE);
149  void OnMenuViewUpdate(wxUpdateUIEvent& UE);
150  void OnClose(wxCloseEvent& CE);
151  void OnToolbar(wxCommandEvent& CE);
152 
153  DECLARE_EVENT_TABLE()
154  };
155 }
156 
157 #endif
Definition: GuiInspector.hpp:21
float SnapToGrid(float Value) const
Snaps a single position coordinate to the current grid.
Definition: ChildFrame.cpp:373
This class represents the CaWE parent (main) frame.
Definition: ParentFrame.hpp:33
Definition: CommandHistory.hpp:13
bool SubmitCommand(CommandT *Command)
[...] All(!) commands for modifying the document must be submitted via this method.
Definition: ChildFrame.cpp:393
Definition: RenderWindow.hpp:20
Definition: WindowInspector.hpp:26
Definition: ToolManager.hpp:20
ChildFrameT(ParentFrameT *Parent, const wxString &FileName, GuiDocumentT *GuiDocument)
Constructor to create a child frame for GUI editing.
Definition: ChildFrame.cpp:145
Definition: ChildFrame.hpp:35
The class describes the settings for a game/MOD.
Definition: GameConfig.hpp:32
Definition: GuiDocument.hpp:39
Definition: WindowHierarchy.hpp:24
This class represents a general command for implementing modifications to the applications document...
Definition: CommandPattern.hpp:30
This class keeps type information (about an entity class that occurs in the game).
Definition: TypeSys.hpp:79