/
imanipulator.h
152 lines (123 loc) · 4.21 KB
/
imanipulator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#pragma once
#include <memory>
#include <string>
#include "imodule.h"
#include "irenderview.h"
template<typename Element> class BasicVector2;
typedef BasicVector2<double> Vector2;
class Matrix4;
class VolumeTest;
class SelectionTest;
class IRenderableCollector;
class RenderSystem;
typedef std::shared_ptr<RenderSystem> RenderSystemPtr;
namespace selection
{
struct WorkZone;
/**
* A Manipulator is an object which contains one or more
* ManipulatorComponents, each of which can be manipulated by the user. For
* example, the rotation Manipulator draws several circles which cause rotations
* around specific axes.
*/
class IManipulator
{
public:
using Ptr = std::shared_ptr<IManipulator>;
// Manipulator type enum, user-defined manipulators should return "Custom"
enum Type
{
Drag,
Translate,
Rotate,
Scale,
Clip,
ModelScale,
Custom
};
enum class Context
{
Scene, // manipulate regular map elements
TextureTool, // manipualte UV coordinates
};
/**
* Part of a Manipulator which can be operated upon by the user.
*
* \see Manipulator
*/
class Component
{
public:
virtual ~Component() {}
/**
* Called when the user successfully activates this component. The calling code provides
* information about the view we're operating in, the starting device coords and the
* location of the current selection pivot.
*/
virtual void beginTransformation(const Matrix4& pivot2world, const VolumeTest& view, const Vector2& devicePoint) = 0;
struct Constraint
{
enum Flags
{
Unconstrained = 0, // no keyboard modifier held
Type1 = 1 << 0, // usually: shift held down
Grid = 1 << 1, // usually: ctrl NOT held down
Type3 = 1 << 2, // usually: alt held down
};
};
/**
* Called during mouse movement, the component is asked to calculate the deltas and distances
* it needs to perform the translation/rotation/scale/whatever the operator does on the selected objects.
* The pivot2world transform relates to the original pivot location at the time the transformation started.
* If the constrained flags are not 0, they indicate the user is holding down a key during movement,
* usually the SHIFT or CTRL key. It's up to the component to decide how to handle the constraint.
*/
virtual void transform(const Matrix4& pivot2world, const VolumeTest& view, const Vector2& devicePoint, unsigned int flags) = 0;
};
virtual ~IManipulator() {}
// ID and Type management
virtual std::size_t getId() const = 0;
virtual void setId(std::size_t id) = 0;
virtual Type getType() const = 0;
/**
* Get the currently-active ManipulatorComponent. This is determined by the
* most recent selection test.
*/
virtual Component* getActiveComponent() = 0;
virtual void testSelect(SelectionTest& test, const Matrix4& pivot2world) {}
virtual void setSelected(bool select) = 0;
virtual bool isSelected() const = 0;
};
/**
* A Scene Manipulator is a renderable object that can submit renderable components
* to a RenderableCollector to show in the XY and Camera views.
*/
class ISceneManipulator :
public IManipulator
{
public:
using Ptr = std::shared_ptr<ISceneManipulator>;
virtual ~ISceneManipulator() {}
// Prepares this manipulator for rendering
virtual void onPreRender(const RenderSystemPtr& renderSystem, const VolumeTest& volume) = 0;
// Renders the manipulator's visual representation to the scene
virtual void render(IRenderableCollector& collector, const VolumeTest& volume) = 0;
// Removes / hides the renderables of this manipulator
virtual void clearRenderables() = 0;
// Manipulators should indicate whether component editing is supported or not
virtual bool supportsComponentManipulation() const = 0;
};
/**
* A Texture Tool Manipulator is a 2D-renderable object that does the rendering itself
* without taking the path of a RenderableCollector.
*/
class ITextureToolManipulator :
public IManipulator
{
public:
using Ptr = std::shared_ptr<ITextureToolManipulator>;
virtual ~ITextureToolManipulator() {}
// Renders the manipulator's visual representation to the scene (absolute UV coordinates)
virtual void renderComponents(const render::IRenderView& view, const Matrix4& pivot2World) = 0;
};
}