Cafu Engine
ParentFrame.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_PARENT_FRAME_HPP_INCLUDED
8 #define CAFU_PARENT_FRAME_HPP_INCLUDED
9 
10 #include "Templates/Array.hpp"
11 #include "Templates/Pointer.hpp"
12 #include "wx/docview.h" // Needed for wxFileHistory.
13 #include "wx/mdi.h"
14 
15 #if __linux__
16 #define HMODULE void*
17 #endif
18 
19 
20 class wxGLCanvas;
21 class wxGLContext;
22 class wxFileName;
23 class ChildFrameT;
24 class GameConfigT;
25 class MapDocumentT;
26 namespace ModelEditor { class ChildFrameT; }
27 namespace GuiEditor { class ChildFrameT; }
28 namespace cf { namespace GuiSys { class WindowT; } }
29 namespace MatSys { class TextureMapI; }
30 
31 
32 /// This class represents the CaWE parent (main) frame.
33 class ParentFrameT : public wxMDIParentFrame
34 {
35  public:
36 
37  /// IDs for the controls whose events we are interested in.
38  /// This is a public enum so that our children (and possibly grandchildren) can have controls
39  /// that trigger these events as well, e.g. child frames that duplicate our menu items or dialogs
40  /// (any children of the child frames) that provide buttons for the same events.
41  /// The IDs that the ParentFrameT class uses start at wxID_HIGHEST+1+1000 and the IDs that the various
42  /// ChildFrameT classes (map, gui, and model editors) use start at wxID_HIGHEST+1+2000. This way, the
43  /// children of the child frames (dialogs, panes, toolbars, ...) can start their own ID enumerations
44  /// at wxID_HIGHEST+1. This keeps all IDs nicely unique when events bubble up from the dialogs, pane
45  /// and toolbars first to the child frame and finally to the parent frame.
46  /// See the "Events and Event Handling: How Events are Processed" in the wx documentation for more details.
47  enum
48  {
49  ID_MENU_FILE_NEW_MAP=wxID_HIGHEST+1+1000,
50  ID_MENU_FILE_NEW_MODEL,
51  ID_MENU_FILE_NEW_GUI,
52  ID_MENU_FILE_NEW_FONT,
53  ID_MENU_FILE_OPEN,
54  ID_MENU_FILE_OPEN_CMDLINE,
55  ID_MENU_FILE_CONFIGURE,
56  ID_MENU_FILE_EXIT,
57 
58  // Note that the entire "Windows" menu is provided and managed by wx.
59  // ID_MENU_WINDOW_NEW,
60  // ID_MENU_WINDOW_CASCADE,
61  // ID_MENU_WINDOW_TILE,
62  // ID_MENU_WINDOW_ARRANGE_ICONS,
63  // ID_MENU_WINDOW_LOG_MESSAGES,
64 
65  ID_MENU_HELP_CONTENTS,
66  ID_MENU_HELP_CAFU_WEBSITE,
67  ID_MENU_HELP_CAFU_FORUM,
68  ID_MENU_HELP_SET_FRAME_SIZE,
69  ID_MENU_HELP_D3_MTR_CONVERTER,
70  ID_MENU_HELP_ABOUT
71  };
72 
73 
74  /// The constructor.
75  ParentFrameT(wxCmdLineParser& Parser);
76 
77  /// The destructor.
78  ~ParentFrameT();
79 
80  ChildFrameT* GetActiveMapChildFrame() const; ///< Returns the currently active child frame or NULL if no map childframe is active (e.g. no map open or GUI editor is active).
81  MapDocumentT* GetActiveMapDoc() const; ///< Returns the document of the currently active map child frame or NULL if no map document is active.
82 
83  // These member variables are public because they must be available to other code anyway.
84  wxGLCanvas* m_GLCanvas; ///< Our persistent "home" of the shared GL context. Used whenever there is no view.
85  wxGLContext* m_GLContext; ///< The OpenGL rendering context that represents our app-global OpenGL state.
86  MatSys::TextureMapI* m_WhiteTexture; ///< A white texture map that is set as default lightmap whenever nothing else is available.
87  wxFileHistory m_FileHistory; ///< The file history of our and all our childrens "File" menu.
88  ArrayT<ChildFrameT*> m_ChildFrames; ///< The list where all map child frames register themselves on construction and unregister on destruction.
89  ArrayT<ModelEditor::ChildFrameT*> m_MdlChildFrames; ///< The list where all model child frames register themselves on construction and unregister on destruction.
90  ArrayT<GuiEditor::ChildFrameT*> m_GuiChildFrames; ///< The list where all GUI child frames register themselves on construction and unregister on destruction.
91  ArrayT< IntrusivePtrT<cf::GuiSys::WindowT> > m_GuiClipboard; ///< The common clipboard for all GUI Editor child frames.
92 
93  /// The OpenGL attribute list for this window. The same list must be used for all child windows, so that they get identical pixel formats!
94  static int OpenGLAttributeList[];
95 
96 
97  private:
98 
99  /// A helper function for opening or creating Cafu documents (maps, models or GUIs), for learning which game config should be used
100  /// (first by extrapolating the config from the document path or (if unsuccessful) by querying it from the user).
101  GameConfigT* AskUserForGameConfig(const wxFileName& DocumentPath) const;
102 
103  /// Using the specified game config, this method opens the specified file in a new child frame:
104  /// It inspects the suffix of the given filename in order to determine the proper document type (map, model or GUI),
105  /// creates the document from the file, and finally creates a new child frame for the newly loaded document.
106  /// Files that have an ambiguous filename suffix (e.g. ".map") must have a type specifier appended to their filename.
107  /// Currently supported type specifiers are " (HL1)", " (HL2)" and " (D3)".
108  /// Errors on opening the file are gracefully handled and the user is informed.
109  wxMDIChildFrame* OpenFile(GameConfigT* GameConfig, wxString FileName);
110 
111 #ifdef __WXGTK__
112  void OnSize (wxSizeEvent& SE);
113 #endif
114  void OnShow (wxShowEvent& SE); ///< Event handler for "has been shown" events.
115  void OnClose (wxCloseEvent& CE); ///< Event handler for close events, e.g. after a system close button or command or a call to Close(). See wx Window Deletion Overview for more details.
116  void OnMenuFile(wxCommandEvent& CE); ///< Event handler for File menu events.
117  void OnMenuHelp(wxCommandEvent& CE); ///< Event handler for Help menu events.
118 
119  wxCmdLineParser& m_CmdLineParser;
120  HMODULE m_RendererDLL;
121 
122  DECLARE_EVENT_TABLE()
123 };
124 
125 #endif
wxGLCanvas * m_GLCanvas
Our persistent "home" of the shared GL context. Used whenever there is no view.
Definition: ParentFrame.hpp:84
This class represents a CaWE "map" document.
Definition: MapDocument.hpp:45
This class represents the CaWE parent (main) frame.
Definition: ParentFrame.hpp:33
static int OpenGLAttributeList[]
The OpenGL attribute list for this window. The same list must be used for all child windows...
Definition: ParentFrame.hpp:94
wxGLContext * m_GLContext
The OpenGL rendering context that represents our app-global OpenGL state.
Definition: ParentFrame.hpp:85
~ParentFrameT()
The destructor.
Definition: ParentFrame.cpp:173
This class represents a child frame.
Definition: ChildFrame.hpp:55
MatSys::TextureMapI * m_WhiteTexture
A white texture map that is set as default lightmap whenever nothing else is available.
Definition: ParentFrame.hpp:86
ChildFrameT * GetActiveMapChildFrame() const
Returns the currently active child frame or NULL if no map childframe is active (e.g. no map open or GUI editor is active).
Definition: ParentFrame.cpp:205
This is an interface to a texture-map.
Definition: TextureMap.hpp:23
ArrayT< IntrusivePtrT< cf::GuiSys::WindowT > > m_GuiClipboard
The common clipboard for all GUI Editor child frames.
Definition: ParentFrame.hpp:91
MapDocumentT * GetActiveMapDoc() const
Returns the document of the currently active map child frame or NULL if no map document is active...
Definition: ParentFrame.cpp:216
ArrayT< GuiEditor::ChildFrameT * > m_GuiChildFrames
The list where all GUI child frames register themselves on construction and unregister on destruction...
Definition: ParentFrame.hpp:90
The class describes the settings for a game/MOD.
Definition: GameConfig.hpp:32
ArrayT< ModelEditor::ChildFrameT * > m_MdlChildFrames
The list where all model child frames register themselves on construction and unregister on destructi...
Definition: ParentFrame.hpp:89
ArrayT< ChildFrameT * > m_ChildFrames
The list where all map child frames register themselves on construction and unregister on destruction...
Definition: ParentFrame.hpp:88
ParentFrameT(wxCmdLineParser &Parser)
The constructor.
Definition: ParentFrame.cpp:87
wxFileHistory m_FileHistory
The file history of our and all our childrens "File" menu.
Definition: ParentFrame.hpp:87