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