Cafu Engine
Tool.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_TOOL_HPP_INCLUDED
8 #define CAFU_TOOL_HPP_INCLUDED
9 
10 #include "ChildFrame.hpp" // Make it easy for ToolT derivatives to implement the GetWxEventID() method.
11 #include "TypeSys.hpp"
12 
13 
14 class MapDocumentT;
15 class MapElementT;
16 class Renderer2DT;
17 class Renderer3DT;
18 class ViewWindow2DT;
19 class ViewWindow3DT;
20 class wxContextMenuEvent;
21 class wxKeyEvent;
22 class wxMouseEvent;
23 class wxPoint;
24 class wxWindow;
25 
26 
27 /// The TypeInfoTs of all ToolT derived classes must register with this TypeInfoManT instance.
28 cf::TypeSys::TypeInfoManT& GetToolTIM();
29 
30 
31 /// This is the base class for all tools in the map editor.
32 /// The 2D and 3D views keep a ToolT reference to the currently active tool,
33 /// forwarding their key events, mouse events and render requests to it.
34 class ToolT
35 {
36  public:
37 
38  /// Parameters for creating a tool via the TypeSys.
40  {
41  public:
42 
43  /// The constructor.
44  /// @param MapDoc_ The map document for which the tool will be created.
45  /// @param ToolMan_ The tool manager that manages the tool.
46  /// @param ParentOptionsBar_ The window that is the designated parent for the tools options bar.
47  ToolCreateParamsT(MapDocumentT& MapDoc_, ToolManagerT& ToolMan_, wxWindow* ParentOptionsBar_);
48 
49  MapDocumentT& MapDoc; ///< The map document for which the tool will be created.
50  ToolManagerT& ToolMan; ///< The tool manager that manages the tool.
51  wxWindow* ParentOptionsBar; ///< The window that is the designated parent for the tools options bar.
52  };
53 
54 
55  /// The constructor.
56  ToolT(MapDocumentT& MapDoc, ToolManagerT& ToolMan);
57 
58  /// The destructor.
59  virtual ~ToolT() { }
60 
61  /// Returns the ID of the wxWidgets event (menu selection or toolbar button click) that is associated with activating this tool.
62  virtual int GetWxEventID() const=0;
63 
64  /// Returns the options bar window associated with this tool. NULL if no options bar has been assigned.
65  virtual wxWindow* GetOptionsBar() { return NULL; }
66 
67  void Activate(ToolT* OldTool);
68  void Deactivate(ToolT* NewTool);
69  bool IsActiveTool() const { return m_IsActiveTool; }
70 
71  virtual bool CanDeactivate() { return true; }
72  virtual bool IsHiddenByTool(const MapElementT* Elem) const { return false; } ///< The caller calls this method in order to learn whether it should exempt the given map element Elem from normal 2D and 3D rendering. This is usually true when Elem is currently being modified by the tool and thus rendered (in a special way) by the tool itself. Examples include brushes being morphed and terrains being edited.
73  virtual void RenderTool2D(Renderer2DT& Renderer) const { }
74  virtual void RenderTool3D(Renderer3DT& Renderer) const { }
75  virtual bool UpdateStatusBar(ChildFrameT* ChildFrame) const { return false; }
76 
77  // Event handlers for events chain-forwarded by the 2D view windows.
78  virtual bool OnKeyDown2D (ViewWindow2DT& ViewWindow, wxKeyEvent& KE) { return false; }
79  virtual bool OnKeyUp2D (ViewWindow2DT& ViewWindow, wxKeyEvent& KE) { return false; }
80  virtual bool OnChar2D (ViewWindow2DT& ViewWindow, wxKeyEvent& KE) { return false; }
81  virtual bool OnLMouseDown2D (ViewWindow2DT& ViewWindow, wxMouseEvent& ME) { return false; } ///< Also used for LMB "double-click" events (use ME.ButtonDClick() for distinction).
82  virtual bool OnLMouseUp2D (ViewWindow2DT& ViewWindow, wxMouseEvent& ME) { return false; }
83  virtual bool OnMMouseDown2D (ViewWindow2DT& ViewWindow, wxMouseEvent& ME) { return false; } ///< Also used for MMB "double-click" events (use ME.ButtonDClick() for distinction).
84  virtual bool OnMMouseUp2D (ViewWindow2DT& ViewWindow, wxMouseEvent& ME) { return false; }
85  virtual bool OnRMouseClick2D(ViewWindow2DT& ViewWindow, wxMouseEvent& ME) { return false; } ///< For the RMB, only a "click" event is available, because the RMB is also used for mouse-looking and the context menu.
86  virtual bool OnMouseWheel2D (ViewWindow2DT& ViewWindow, wxMouseEvent& ME) { return false; }
87  virtual bool OnMouseMove2D (ViewWindow2DT& ViewWindow, wxMouseEvent& ME) { return false; }
88  virtual int OnContextMenu2D(ViewWindow2DT& ViewWindow, wxContextMenuEvent& CE, wxMenu& Menu);
89 
90  // Event handlers for events chain-forwarded by the 3D view windows.
91  virtual bool OnKeyDown3D (ViewWindow3DT& ViewWindow, wxKeyEvent& KE) { return false; }
92  virtual bool OnKeyUp3D (ViewWindow3DT& ViewWindow, wxKeyEvent& KE) { return false; }
93  virtual bool OnChar3D (ViewWindow3DT& ViewWindow, wxKeyEvent& KE) { return false; }
94  virtual bool OnLMouseDown3D (ViewWindow3DT& ViewWindow, wxMouseEvent& ME) { return false; } ///< Also used for LMB "double-click" events (use ME.ButtonDClick() for distinction).
95  virtual bool OnLMouseUp3D (ViewWindow3DT& ViewWindow, wxMouseEvent& ME) { return false; }
96  virtual bool OnMMouseDown3D (ViewWindow3DT& ViewWindow, wxMouseEvent& ME) { return false; } ///< Also used for MMB "double-click" events (use ME.ButtonDClick() for distinction).
97  virtual bool OnMMouseUp3D (ViewWindow3DT& ViewWindow, wxMouseEvent& ME) { return false; }
98  virtual bool OnRMouseClick3D(ViewWindow3DT& ViewWindow, wxMouseEvent& ME) { return false; } ///< For the RMB, only a "click" event is available, because the RMB is also used for mouse-looking and the context menu.
99  virtual bool OnMouseWheel3D (ViewWindow3DT& ViewWindow, wxMouseEvent& ME) { return false; }
100  virtual bool OnMouseMove3D (ViewWindow3DT& ViewWindow, wxMouseEvent& ME) { return false; }
101  virtual int OnContextMenu3D(ViewWindow3DT& ViewWindow, wxContextMenuEvent& CE, wxMenu& Menu);
102  virtual bool OnIdle3D (ViewWindow3DT& ViewWindow, const wxPoint& Point) { return false; }
103 
104  // The TypeSys related declarations for this class.
105  virtual const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; }
106  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
107  static const cf::TypeSys::TypeInfoT TypeInfo;
108 
109 
110  protected:
111 
112  MapDocumentT& m_MapDoc; ///< The document that is modified by this tool.
113  ToolManagerT& m_ToolMan; ///< The tool manager that manages this tool.
114 
115 
116  private:
117 
118  ToolT(const ToolT&); ///< Use of the Copy Constructor is not allowed.
119  void operator = (const ToolT&); ///< Use of the Assignment Operator is not allowed.
120 
121  // These methods employ the "Non-Virtual Interface Idiom" as described by Scott Meyers in his
122  // book "Effective C++, 3rd Edition" in item 35 ("Consider alternatives to virtual functions.").
123  virtual void OnActivate(ToolT* OldTool) { }
124  virtual void OnDeactivate(ToolT* NewTool) { }
125 
126  bool m_IsActiveTool; ///< Indicates whether this tool is the currently active tool.
127 };
128 
129 #endif
This class provides auxiliary means for rendering a 3D view.
Definition: Renderer3D.hpp:30
This class implements the rendering into a 2D view.
Definition: Renderer2D.hpp:22
ToolManagerT & ToolMan
The tool manager that manages the tool.
Definition: Tool.hpp:50
ToolCreateParamsT(MapDocumentT &MapDoc_, ToolManagerT &ToolMan_, wxWindow *ParentOptionsBar_)
The constructor.
Definition: Tool.cpp:25
This class represents a CaWE "map" document.
Definition: MapDocument.hpp:45
ToolT(MapDocumentT &MapDoc, ToolManagerT &ToolMan)
The constructor.
Definition: Tool.cpp:45
virtual int GetWxEventID() const =0
Returns the ID of the wxWidgets event (menu selection or toolbar button click) that is associated wit...
virtual bool OnRMouseClick2D(ViewWindow2DT &ViewWindow, wxMouseEvent &ME)
For the RMB, only a "click" event is available, because the RMB is also used for mouse-looking and th...
Definition: Tool.hpp:85
virtual ~ToolT()
The destructor.
Definition: Tool.hpp:59
virtual bool OnRMouseClick3D(ViewWindow3DT &ViewWindow, wxMouseEvent &ME)
For the RMB, only a "click" event is available, because the RMB is also used for mouse-looking and th...
Definition: Tool.hpp:98
virtual bool OnLMouseDown2D(ViewWindow2DT &ViewWindow, wxMouseEvent &ME)
Also used for LMB "double-click" events (use ME.ButtonDClick() for distinction).
Definition: Tool.hpp:81
This class represents a child frame.
Definition: ChildFrame.hpp:55
virtual bool IsHiddenByTool(const MapElementT *Elem) const
The caller calls this method in order to learn whether it should exempt the given map element Elem fr...
Definition: Tool.hpp:72
ToolManagerT & m_ToolMan
The tool manager that manages this tool.
Definition: Tool.hpp:113
This class manages the type infos.
Definition: TypeSys.hpp:145
MapDocumentT & m_MapDoc
The document that is modified by this tool.
Definition: Tool.hpp:112
virtual wxWindow * GetOptionsBar()
Returns the options bar window associated with this tool. NULL if no options bar has been assigned...
Definition: Tool.hpp:65
Definition: ChildFrameViewWin2D.hpp:24
Definition: ChildFrameViewWin3D.hpp:21
wxWindow * ParentOptionsBar
The window that is the designated parent for the tools options bar.
Definition: Tool.hpp:51
virtual bool OnMMouseDown3D(ViewWindow3DT &ViewWindow, wxMouseEvent &ME)
Also used for MMB "double-click" events (use ME.ButtonDClick() for distinction).
Definition: Tool.hpp:96
virtual bool OnMMouseDown2D(ViewWindow2DT &ViewWindow, wxMouseEvent &ME)
Also used for MMB "double-click" events (use ME.ButtonDClick() for distinction).
Definition: Tool.hpp:83
Parameters for creating a tool via the TypeSys.
Definition: Tool.hpp:39
virtual bool OnLMouseDown3D(ViewWindow3DT &ViewWindow, wxMouseEvent &ME)
Also used for LMB "double-click" events (use ME.ButtonDClick() for distinction).
Definition: Tool.hpp:94
Definition: ToolManager.hpp:20
This is the base class for all tools in the map editor.
Definition: Tool.hpp:34
MapDocumentT & MapDoc
The map document for which the tool will be created.
Definition: Tool.hpp:49
Definition: TypeSys.hpp:52
This class keeps type information (about an entity class that occurs in the game).
Definition: TypeSys.hpp:79
This is the base class for all elements ("objects") that can exist in a map.
Definition: MapElement.hpp:57