API Documentation
Loading...
Searching...
No Matches
MouseController.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Design
28File: MouseController
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Camera.h>
34#if NDEVR_VIEWPORT
35#include <NDEVR/SoftwareService.h>
36#include <NDEVR/Resource.h>
37#include <NDEVR/Event.h>
38#include <NDEVR/INIInterface.h>
39namespace NDEVR
40{
41 /**--------------------------------------------------------------------------------------------------
42 \brief A base class for adding functionality to the user mouse inputs.
43 **/
44 class NDEVR_DESIGN_API MouseControllerBase : public SoftwareService
45 {
46 public:
47 virtual bool processMouseEvent(const MouseEvent& event, DesignObjectLookup* lookup, Camera* camera) = 0;
48 };
49 class SnapController;
50
51 class DesignObjectLookup;
52
53 /**--------------------------------------------------------------------------------------------------
54 \brief Contains logic for executing actions based on user mouse inputs
55 **/
56 class MouseController final : public INIInterface, public MouseControllerBase, public SoftwareServiceManager
57 {
58 public:
59 enum ReferencePoint : uint01
60 {
61 e_map_center
62 , e_mouse_center
63 , e_screen_center
64 };
65 enum MouseAction : uint01
66 {
67 e_ignore
68 , e_select
69 , e_inv_select
70 , e_orbit
71 , e_pan
72 , e_look_around
73 , e_zoom
74 , e_inv_zoom
75 , e_context_menu
76
77 , e_command
78 };
79 enum MouseSelectionMode
80 {
81 e_select_model
82 , e_select_model_base
83 , e_select_material
84 , e_select_geometry
85 , e_select_bone
86 };
87 class MouseActions
88 {
89 public:
90 Resource<MouseAction> drag_action;
91 Resource<MouseAction> click_action;
92 Resource<MouseAction> double_click_action;
93 Resource<MouseSelectionMode> selection_mode;
94 Resource<ReferencePoint> prefered_reference;
95 Resource<fltp04> sensitivity;
96 Resource<Vector<2, bool>> inverted;
97
98 Resource<ReferencePoint> double_click_reference;
99 public:
100 MouseActions();
101 MouseActions(const MouseActions& actions);
102 };
103 public:
104 NDEVR_DESIGN_API MouseController();
105 NDEVR_DESIGN_API virtual ~MouseController();
106 MouseActions center_mouse_action;
107 MouseActions left_mouse_action;
108 MouseActions right_mouse_action;
109 MouseActions wheel_mouse_action;
110
111 public:
112 NDEVR_DESIGN_API void setParkeDefaults();
113 NDEVR_DESIGN_API MouseAction getAction(const MouseEvent& event) const;
114 NDEVR_DESIGN_API MouseActions& getDefaultAction(MouseEvent::MouseClickType type);
115 NDEVR_DESIGN_API const MouseActions& getDefaultAction(MouseEvent::MouseClickType type) const;
116
117 NDEVR_DESIGN_API bool processMouseEvent(const MouseEvent& event, DesignObjectLookup* lookup, Camera* camera) override;
118
119 NDEVR_DESIGN_API void addController(UUID id, MouseControllerBase* controller);
120 NDEVR_DESIGN_API void removeController(UUID id);
121 bool contextMenuRequested() const { return m_request_context_menu; }
122 void resetContextMenuRequested() { m_request_context_menu = false; }
123 bool selectionRequested() const { return m_request_selection; }
124 void resetSelectionRequested() { m_request_selection = false; }
125 const MouseEvent& lastMouseEvent() const { return m_last_mouse_event; }
126 Resource<Buffer<UUID>> selected;
127 Resource<UUID> selected_layer;
128 Resource<UUID> focus;
129 Resource<String> cursor;
130 Resource<String> information;
131 Resource<uint04> number_of_mouse_events;
132 Resource<uint04> number_of_mouse_clicks;
133 private:
134 Matrix<fltp08> m_parent_transform;
135 CameraAnimation m_original_camera;
136 Vector<2, fltp08> m_screen_percent_0;
137 fltp08 m_last_valid_distance;
138 bool m_is_dragging;
139 bool m_is_mouse_scrolling;
140 bool m_is_touch_scrolling;
141
142 MouseEvent m_last_mouse_event;
143 private:
144
145
146 void getINI(INIFactory& factory) override;
147 void setReferencePoint(ReferencePoint ref, Camera* camera);
148 bool processGrips(const MouseEvent& event, DesignObjectLookup* lookup, Camera* camera);
149 //void updateCenterOfScreen(DesignObjectLookup* lookup);
150 void updateCenterOfMouse(DesignObjectLookup* lookup, Camera* camera, bool update_distance);
151 void setView(MouseAction act, ReferencePoint ref, const Vector<2, fltp08>& screen_percent, Camera* camera);
152 void mouseScrolled(fltp04 scroll_distance, Camera* camera);
153 void touchScrolled(fltp04 scroll_distance, Camera* camera);
154 void mouseClicked(const MouseEvent& e, DesignObjectLookup* lookup, Camera* camera);
155 void mouseChangeView(const MouseEvent& e, Camera* camera);
156 protected:
157 bool m_request_context_menu;
158 bool m_request_selection;
159 bool m_ignore_next_event_if_click;//If the next event is a click, ignore it
160 Dictionary<UUID, MouseControllerBase*> m_controller_lookup;
161 Buffer<MouseControllerBase*> m_controllers;
162 DynamicPointer<SnapController> m_snap_controller;
163 };
164};
165#endif
166
167
#define NDEVR_DESIGN_API
Definition DLLInfo.h:55
Definition ACIColor.h:37
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149