1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef TrenchBroom_ToolBoxConnector
21 #define TrenchBroom_ToolBoxConnector
22 
23 #include "View/InputState.h"
24 #include "View/PickRequest.h"
25 
26 #include <wx/wx.h>
27 
28 namespace TrenchBroom {
29     namespace Model {
30         class PickResult;
31     }
32 
33     namespace Renderer {
34         class Camera;
35         class RenderBatch;
36         class RenderContext;
37     }
38 
39     namespace View {
40         class ToolController;
41         class ToolBox;
42         class ToolChain;
43 
44         class ToolBoxConnector {
45         private:
46             wxWindow* m_window;
47             ToolBox* m_toolBox;
48             ToolChain* m_toolChain;
49 
50             InputState m_inputState;
51 
52             wxLongLong m_clickTime;
53             wxPoint m_clickPos;
54             wxPoint m_lastMousePos;
55             bool m_ignoreNextDrag;
56         public:
57             ToolBoxConnector(wxWindow* window);
58             virtual ~ToolBoxConnector();
59 
60             const Ray3& pickRay() const;
61             const Model::PickResult& pickResult() const;
62 
63             void updatePickResult();
64             void updateLastActivation();
65         protected:
66             void setToolBox(ToolBox& toolBox);
67             void addTool(ToolController* tool);
68         public: // drag and drop
69             bool dragEnter(wxCoord x, wxCoord y, const String& text);
70             bool dragMove(wxCoord x, wxCoord y, const String& text);
71             void dragLeave();
72             bool dragDrop(wxCoord x, wxCoord y, const String& text);
73         public: // cancel
74             bool cancel();
75         protected: // rendering
76             void setRenderOptions(Renderer::RenderContext& renderContext);
77             void renderTools(Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch);
78         private:
79             void bindEvents();
80             void unbindEvents();
81 
82             void OnKey(wxKeyEvent& event);
83             void OnMouseButton(wxMouseEvent& event);
84             void OnMouseDoubleClick(wxMouseEvent& event);
85             void OnMouseMotion(wxMouseEvent& event);
86             void OnMouseWheel(wxMouseEvent& event);
87             void OnMouseCaptureLost(wxMouseCaptureLostEvent& event);
88             void OnSetFocus(wxFocusEvent& event);
89             void OnKillFocus(wxFocusEvent& event);
90         private:
91             bool isWithinClickDistance(const wxPoint& pos) const;
92 
93             void captureMouse();
94             void releaseMouse();
95             void cancelDrag();
96 
97             ModifierKeyState modifierKeys();
98             bool setModifierKeys();
99             bool clearModifierKeys();
100             void updateModifierKeys();
101 
102             MouseButtonState mouseButton(wxMouseEvent& event);
103             void mouseMoved(const wxPoint& position);
104 
105             void showPopupMenu();
106         private:
107             virtual PickRequest doGetPickRequest(int x, int y) const = 0;
108             virtual Model::PickResult doPick(const Ray3& pickRay) const = 0;
109             virtual void doShowPopupMenu();
110         };
111     }
112 }
113 
114 #endif /* defined(TrenchBroom_ToolBoxConnector) */
115