Cafu Engine
1 /*
2 Cafu Engine,
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
10 #include "Tool.hpp"
11 #include "Math3D/Plane3.hpp"
12 #include "Templates/Array.hpp"
15 struct ClipResultT;
17 class ViewWindowT;
20 class ToolClipT : public ToolT
21 {
22  public:
24  /// The constructor.
25  ToolClipT(MapDocumentT& MapDoc, ToolManagerT& ToolMan, wxWindow* ParentOptionsBar);
27  /// The destructor.
28  ~ToolClipT();
30  /// This is called by the options bar whenever the clip mode has changed.
31  void NoteClipModeChanged();
34  // Implementations/overrides of ToolT methods.
35  int GetWxEventID() const { return ChildFrameT::ID_MENU_TOOLS_TOOL_CLIP; }
36  wxWindow* GetOptionsBar();
37  void OnActivate(ToolT* OldTool);
38  void OnDeactivate(ToolT* NewTool);
40  bool OnKeyDown2D (ViewWindow2DT& ViewWindow, wxKeyEvent& KE);
41  bool OnLMouseDown2D(ViewWindow2DT& ViewWindow, wxMouseEvent& ME);
42  bool OnLMouseUp2D (ViewWindow2DT& ViewWindow, wxMouseEvent& ME);
43  bool OnMouseMove2D (ViewWindow2DT& ViewWindow, wxMouseEvent& ME);
44  bool OnKeyDown3D (ViewWindow3DT& ViewWindow, wxKeyEvent& KE);
46  void RenderTool2D(Renderer2DT& Renderer) const;
47  void RenderTool3D(Renderer3DT& Renderer) const;
49  // The TypeSys related declarations for this class.
50  virtual const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; }
51  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
52  static const cf::TypeSys::TypeInfoT TypeInfo;
55  private:
57  enum ToolStateT
58  {
59  IDLE_EMPTY, ///< The initial state of the tool: The LMB has not yet been clicked, and the two points that define the clip plane are still undefined.
60  IDLE_HAVE_POINTS, ///< The clip points have been set, but currently none of them is being dragged.
61  DRAG_POINT_0, ///< The user is dragging the first clip point.
62  DRAG_POINT_1 ///< The user is dragging the second clip point.
63  };
66  /// Returns the index of the clip point in ViewWindow at PointWS (in window space), or -1 if none.
67  int HitTest(ViewWindow2DT& ViewWindow, const wxPoint& PointWS);
69  /// Updates the m_ClipResults, based on the the map documents current selection.
70  void UpdateClipResults();
72  /// Handles key down events that are common to the 2D and 3D views.
73  bool OnKeyDown(ViewWindowT& ViewWindow, wxKeyEvent& KE);
76  ToolStateT m_ToolState; ///< The state this tool is currently in.
77  Vector3fT m_ClipPoints[2]; ///< The two clip points that define the plane used for clipping the brushes.
78  int m_Clip3rdAxis; ///< The third axis of the view in which the m_ClipPoints were defined. This also defines one of the span vectors of the clip plane.
79  ArrayT<ClipResultT*> m_ClipResults; ///< The current results of the clipping operation, updated by UpdateClipResults(). Never touch the Workpiece member, it can be invalid whenever the user had a chance to interfere since the last call to UpdateClipResults(), e.g. by deleting (via the menu) the selected brushes!
80  bool m_DrawMeasurements; ///< Whether to draw dimensions of the clipped brushes in the 2D views.
82  OptionsBar_ClipBrushesToolT* m_OptionsBar; ///< The options bar for this tool.
83 };
85 #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
Definition: ToolClip.hpp:20
This class represents a CaWE "map" document.
Definition: MapDocument.hpp:45
This struct describes and holds the result of clipping a brush.
Definition: Clip.hpp:15
The destructor.
Definition: ToolClip.cpp:55
The options bar for the Clip Brushes tool.
Definition: ToolOptionsBars.hpp:205
void NoteClipModeChanged()
This is called by the options bar whenever the clip mode has changed.
Definition: ToolClip.cpp:70
ToolClipT(MapDocumentT &MapDoc, ToolManagerT &ToolMan, wxWindow *ParentOptionsBar)
The constructor.
Definition: ToolClip.cpp:43
This class represents a (superclass of a) 2D or 3D map view window.
Definition: ChildFrameViewWin.hpp:21
wxWindow * GetOptionsBar()
Returns the options bar window associated with this tool. NULL if no options bar has been assigned...
Definition: ToolClip.cpp:62
Definition: ChildFrameViewWin2D.hpp:24
Definition: ChildFrameViewWin3D.hpp:21
bool OnLMouseDown2D(ViewWindow2DT &ViewWindow, wxMouseEvent &ME)
Also used for LMB "double-click" events (use ME.ButtonDClick() for distinction).
Definition: ToolClip.cpp:114
int GetWxEventID() const
Returns the ID of the wxWidgets event (menu selection or toolbar button click) that is associated wit...
Definition: ToolClip.hpp:35
Definition: ToolManager.hpp:20
This is the base class for all tools in the map editor.
Definition: Tool.hpp:34
Definition: TypeSys.hpp:52
This class keeps type information (about an entity class that occurs in the game).
Definition: TypeSys.hpp:79