Cafu Engine
ToolSelection.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_TOOL_SELECTION_HPP_INCLUDED
8 #define CAFU_GUIEDITOR_TOOL_SELECTION_HPP_INCLUDED
9 
10 #include "Tool.hpp"
11 
12 #include "Math3D/Vector2.hpp"
13 #include "Templates/Array.hpp"
14 #include "wx/gdicmn.h"
15 
16 
17 namespace GuiEditor
18 {
19  class GuiDocumentT;
20  class ChildFrameT;
21 
22 
23  class ToolSelectionT : public ToolI
24  {
25  public:
26 
27  ToolSelectionT(GuiDocumentT* GuiDocument, ChildFrameT* Parent);
28 
29  ToolID GetID() const { return TOOL_SELECTION; }
30 
31  void Activate();
32  void Deactivate();
33 
34  void RenderTool(RenderWindowT* RenderWindow);
35 
36  bool OnKeyDown(RenderWindowT* RenderWindow, wxKeyEvent& KE);
37 
38  bool OnLMouseDown(RenderWindowT* RenderWindow, wxMouseEvent& ME);
39  bool OnLMouseUp (RenderWindowT* RenderWindow, wxMouseEvent& ME);
40  bool OnMouseMove (RenderWindowT* RenderWindow, wxMouseEvent& ME);
41  bool OnRMouseUp (RenderWindowT* RenderWindow, wxMouseEvent& ME);
42 
43 
44  private:
45 
46  /// This enumeration defines the essential states of this tool.
47  /// Note that in each tool state, the selection can contain any number of map elements.
48  enum ToolStateT
49  {
50  /// The LMB is up and nothing is currently happening.
51  /// The mouse cursor however is updated to indicate a likely next state if the button is pressed at the current position.
52  TS_IDLE,
53 
54  /// One of the window handles is currently being dragged, transforming the selected window(s).
55  TS_DRAG_HANDLE
56  };
57 
58  enum TrafoHandleT
59  {
60  NONE,
61  TRANSLATE,
62  SCALE_N,
63  SCALE_NE,
64  SCALE_E,
65  SCALE_SE,
66  SCALE_S,
67  SCALE_SW,
68  SCALE_W,
69  SCALE_NW,
70  ROTATE
71  };
72 
73  /// Window attributes that are changed by a transformation.
74  struct WindowStateT
75  {
76  Vector2fT Position;
77  Vector2fT Size;
78  float Rotation;
79  };
80 
81 
82  TrafoHandleT GetHandle(const Vector2fT& GuiPos) const;
83  wxCursor SuggestCursor(TrafoHandleT TrafoHandle) const;
84 
85  GuiDocumentT* m_GuiDocument;
86  ChildFrameT* m_Parent;
87 
88  ToolStateT m_ToolState;
89  TrafoHandleT m_DragState;
90 
91  ArrayT<WindowStateT> m_WindowStates; ///< Holds all original window states of the currently transformed windows.
92  float m_RotStartAngle; ///< The rotation angle at which the transform was started.
93  Vector2fT m_LastMousePos; ///< Last known mouse position, in GUI coordinates.
94  };
95 }
96 
97 #endif
This class represents a child frame.
Definition: ChildFrame.hpp:55
Definition: RenderWindow.hpp:20
Definition: Tool.hpp:28
Definition: ChildFrame.hpp:35
Definition: GuiDocument.hpp:39
Definition: ToolSelection.hpp:23