root/cafu/trunk/CaWE/Tool.hpp

Revision 457, 8.0 KB (checked in by Carsten, 4 months ago)

Using UltraEdit's multi-line search-and-replace-in-files feature, replaced


^#ifndef _(CAFU|CF|CFS|CA)_(.*)_$
^#define _\1_\2_$

with

#ifndef CAFU_\2_INCLUDED
#define CAFU_\2_INCLUDED

and


^#ifndef _(.*)_HPP_$
^#define _\1_HPP_$

with

#ifndef CAFU_\1_HPP_INCLUDED
#define CAFU_\1_HPP_INCLUDED

Closes #91.

Line 
1/*
2=================================================================================
3This file is part of Cafu, the open-source game engine and graphics engine
4for multiplayer, cross-platform, real-time 3D action.
5Copyright (C) 2002-2012 Carsten Fuchs Software.
6
7Cafu is free software: you can redistribute it and/or modify it under the terms
8of the GNU General Public License as published by the Free Software Foundation,
9either version 3 of the License, or (at your option) any later version.
10
11Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13PURPOSE. See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with Cafu. If not, see <http://www.gnu.org/licenses/>.
17
18For support and more information about Cafu, visit us at <http://www.cafu.de>.
19=================================================================================
20*/
21
22#ifndef CAFU_TOOL_HPP_INCLUDED
23#define CAFU_TOOL_HPP_INCLUDED
24
25#include "ChildFrame.hpp"   // Make it easy for ToolT derivatives to implement the GetWxEventID() method.
26#include "TypeSys.hpp"
27
28
29class MapDocumentT;
30class MapElementT;
31class Renderer2DT;
32class Renderer3DT;
33class ViewWindow2DT;
34class ViewWindow3DT;
35class wxContextMenuEvent;
36class wxKeyEvent;
37class wxMouseEvent;
38class wxPoint;
39class wxWindow;
40
41
42/// The TypeInfoTs of all ToolT derived classes must register with this TypeInfoManT instance.
43cf::TypeSys::TypeInfoManT& GetToolTIM();
44
45
46/// This is the base class for all tools in the map editor.
47/// The 2D and 3D views keep a ToolT reference to the currently active tool,
48/// forwarding their key events, mouse events and render requests to it.
49class ToolT
50{
51    public:
52
53    /// Parameters for creating a tool via the TypeSys.
54    class ToolCreateParamsT : public cf::TypeSys::CreateParamsT
55    {
56        public:
57
58        /// The constructor.
59        /// @param MapDoc_             The map document for which the tool will be created.
60        /// @param ToolMan_            The tool manager that manages the tool.
61        /// @param ParentOptionsBar_   The window that is the designated parent for the tools options bar.
62        ToolCreateParamsT(MapDocumentT& MapDoc_, ToolManagerT& ToolMan_, wxWindow* ParentOptionsBar_);
63
64        MapDocumentT& MapDoc;           ///< The map document for which the tool will be created.
65        ToolManagerT& ToolMan;          ///< The tool manager that manages the tool.
66        wxWindow*     ParentOptionsBar; ///< The window that is the designated parent for the tools options bar.
67    };
68
69
70    /// The constructor.
71    ToolT(MapDocumentT& MapDoc, ToolManagerT& ToolMan);
72
73    /// The destructor.
74    virtual ~ToolT() { }
75
76    /// Returns the ID of the wxWidgets event (menu selection or toolbar button click) that is associated with activating this tool.
77    virtual int GetWxEventID() const=0;
78
79    /// Returns the options bar window associated with this tool. NULL if no options bar has been assigned.
80    virtual wxWindow* GetOptionsBar() { return NULL; }
81
82    void Activate(ToolT* OldTool);
83    void Deactivate(ToolT* NewTool);
84    bool IsActiveTool() const { return m_IsActiveTool; }
85
86    virtual bool CanDeactivate() { return true; }
87    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.
88    virtual void RenderTool2D(Renderer2DT& Renderer) const { }
89    virtual void RenderTool3D(Renderer3DT& Renderer) const { }
90    virtual bool UpdateStatusBar(ChildFrameT* ChildFrame) const { return false; }
91
92    // Event handlers for events chain-forwarded by the 2D view windows.
93    virtual bool OnKeyDown2D    (ViewWindow2DT& ViewWindow, wxKeyEvent&         KE) { return false; }
94    virtual bool OnKeyUp2D      (ViewWindow2DT& ViewWindow, wxKeyEvent&         KE) { return false; }
95    virtual bool OnChar2D       (ViewWindow2DT& ViewWindow, wxKeyEvent&         KE) { return false; }
96    virtual bool OnLMouseDown2D (ViewWindow2DT& ViewWindow, wxMouseEvent&       ME) { return false; }   ///< Also used for LMB "double-click" events (use ME.ButtonDClick() for distinction).
97    virtual bool OnLMouseUp2D   (ViewWindow2DT& ViewWindow, wxMouseEvent&       ME) { return false; }
98    virtual bool OnMMouseDown2D (ViewWindow2DT& ViewWindow, wxMouseEvent&       ME) { return false; }   ///< Also used for MMB "double-click" events (use ME.ButtonDClick() for distinction).
99    virtual bool OnMMouseUp2D   (ViewWindow2DT& ViewWindow, wxMouseEvent&       ME) { return false; }
100    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.
101    virtual bool OnMouseWheel2D (ViewWindow2DT& ViewWindow, wxMouseEvent&       ME) { return false; }
102    virtual bool OnMouseMove2D  (ViewWindow2DT& ViewWindow, wxMouseEvent&       ME) { return false; }
103    virtual int  OnContextMenu2D(ViewWindow2DT& ViewWindow, wxContextMenuEvent& CE, wxMenu& Menu);
104
105    // Event handlers for events chain-forwarded by the 3D view windows.
106    virtual bool OnKeyDown3D    (ViewWindow3DT& ViewWindow, wxKeyEvent&         KE) { return false; }
107    virtual bool OnKeyUp3D      (ViewWindow3DT& ViewWindow, wxKeyEvent&         KE) { return false; }
108    virtual bool OnChar3D       (ViewWindow3DT& ViewWindow, wxKeyEvent&         KE) { return false; }
109    virtual bool OnLMouseDown3D (ViewWindow3DT& ViewWindow, wxMouseEvent&       ME) { return false; }   ///< Also used for LMB "double-click" events (use ME.ButtonDClick() for distinction).
110    virtual bool OnLMouseUp3D   (ViewWindow3DT& ViewWindow, wxMouseEvent&       ME) { return false; }
111    virtual bool OnMMouseDown3D (ViewWindow3DT& ViewWindow, wxMouseEvent&       ME) { return false; }   ///< Also used for MMB "double-click" events (use ME.ButtonDClick() for distinction).
112    virtual bool OnMMouseUp3D   (ViewWindow3DT& ViewWindow, wxMouseEvent&       ME) { return false; }
113    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.
114    virtual bool OnMouseWheel3D (ViewWindow3DT& ViewWindow, wxMouseEvent&       ME) { return false; }
115    virtual bool OnMouseMove3D  (ViewWindow3DT& ViewWindow, wxMouseEvent&       ME) { return false; }
116    virtual int  OnContextMenu3D(ViewWindow3DT& ViewWindow, wxContextMenuEvent& CE, wxMenu& Menu);
117    virtual bool OnIdle3D       (ViewWindow3DT& ViewWindow, const wxPoint&   Point) { return false; }
118
119    // The TypeSys related declarations for this class.
120    virtual const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; }
121    static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
122    static const cf::TypeSys::TypeInfoT TypeInfo;
123
124
125    protected:
126
127    MapDocumentT& m_MapDoc;     ///< The document that is modified by this tool.
128    ToolManagerT& m_ToolMan;    ///< The tool manager that manages this tool.
129
130
131    private:
132
133    ToolT(const ToolT&);                ///< Use of the Copy    Constructor is not allowed.
134    void operator = (const ToolT&);     ///< Use of the Assignment Operator is not allowed.
135
136    // These methods employ the "Non-Virtual Interface Idiom" as described by Scott Meyers in his
137    // book "Effective C++, 3rd Edition" in item 35 ("Consider alternatives to virtual functions.").
138    virtual void OnActivate(ToolT* OldTool) { }
139    virtual void OnDeactivate(ToolT* NewTool) { }
140
141    bool m_IsActiveTool;    ///< Indicates whether this tool is the currently active tool.
142};
143
144#endif
Note: See TracBrowser for help on using the browser.