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_InputState
21 #define TrenchBroom_InputState
22 
23 #include "TrenchBroom.h"
24 #include "VecMath.h"
25 #include "Model/PickResult.h"
26 #include "View/PickRequest.h"
27 
28 namespace TrenchBroom {
29     namespace Renderer {
30         class Camera;
31     }
32 
33     namespace View {
34         typedef unsigned int ModifierKeyState;
35         namespace ModifierKeys {
36             static const ModifierKeyState MKNone      = 0;
37             static const ModifierKeyState MKShift     = 1 << 0;
38             static const ModifierKeyState MKCtrlCmd   = 1 << 1; // Cmd on Mac, Ctrl on other systems
39             static const ModifierKeyState MKAlt       = 1 << 2;
40             static const ModifierKeyState MKDontCare  = 1 << 3;
41         }
42 
43         typedef enum {
44             MK_Yes,
45             MK_No,
46             MK_DontCare
47         } ModifierKeyPressed;
48 
49         typedef unsigned int MouseButtonState;
50         namespace MouseButtons {
51             static const MouseButtonState MBNone      = 0;
52             static const MouseButtonState MBLeft      = 1 << 0;
53             static const MouseButtonState MBRight     = 1 << 1;
54             static const MouseButtonState MBMiddle    = 1 << 2;
55         }
56 
57         class Grid;
58 
59         class InputState {
60         private:
61             ModifierKeyState m_modifierKeys;
62             MouseButtonState m_mouseButtons;
63             int m_mouseX;
64             int m_mouseY;
65             int m_mouseDX;
66             int m_mouseDY;
67             float m_scrollX;
68             float m_scrollY;
69 
70             bool m_anyToolDragging;
71             PickRequest m_pickRequest;
72             Model::PickResult m_pickResult;
73         public:
74             InputState();
75             InputState(const int mouseX, const int mouseY);
76             virtual ~InputState();
77 
78             virtual ModifierKeyState modifierKeys() const;
79             bool modifierKeysDown(ModifierKeyState keys) const;
80             bool modifierKeysPressed(ModifierKeyState keys) const;
81             bool checkModifierKeys(ModifierKeyState key1, ModifierKeyState key2 = ModifierKeys::MKDontCare, ModifierKeyState key3 = ModifierKeys::MKDontCare, ModifierKeyState key4 = ModifierKeys::MKDontCare) const;
82             bool checkModifierKeys(ModifierKeyPressed ctrl, ModifierKeyPressed alt, ModifierKeyPressed shift) const;
83             bool checkModifierKey(ModifierKeyPressed state, ModifierKeyState key) const;
84 
85             MouseButtonState mouseButtons() const;
86             bool mouseButtonsDown(MouseButtonState buttons) const;
87             bool mouseButtonsPressed(const MouseButtonState buttons) const;
88                        int mouseX() const;
89             int mouseY() const;
90             int mouseDX() const;
91             int mouseDY() const;
92 
93             float scrollX() const;
94             float scrollY() const;
95 
96             void setModifierKeys(const ModifierKeyState keys);
97             void clearModifierKeys();
98             void mouseDown(const MouseButtonState button);
99             void mouseUp(const MouseButtonState button);
100             void clearMouseButtons();
101             void mouseMove(const int mouseX, const int mouseY, const int mouseDX, const int mouseDY);
102             void scroll(const float scrollX, const float scrollY);
103 
104             bool anyToolDragging() const;
105             void setAnyToolDragging(bool anyToolDragging);
106 
107             const Ray3& pickRay() const;
108             const Vec3 defaultPoint() const;
109             const Vec3 defaultPointUnderMouse() const;
110             const Renderer::Camera& camera() const;
111             void setPickRequest(const PickRequest& pickRequest);
112 
113             const Model::PickResult& pickResult() const;
114             void setPickResult(Model::PickResult& pickResult);
115         };
116     }
117 }
118 
119 #endif /* defined(TrenchBroom_InputState) */
120