2
* select,h - Opengl interaction header.
3
* Copyright (C) 2010, D Haley
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
class SelectionDevice;
24
class SelectionBinding;
27
#include "drawables.h"
28
#include "viscontrol.h"
36
SELECT_BUTTON_MIDDLE=2,
37
SELECT_BUTTON_RIGHT=4,
40
//!Keyboard keydown flags
44
FLAG_CMD=1, //control (non-mac) or "clover" key (mac)
45
FLAG_SHIFT=2, //Left or right shift key.
48
//!Allowable binding modes
51
BIND_MODE_FLOAT_SCALE,
52
BIND_MODE_FLOAT_TRANSLATE,
53
BIND_MODE_POINT3D_TRANSLATE,
54
BIND_MODE_POINT3D_ROTATE,
57
//!Bindable data types (data types that SelectionBinding can work with)
64
//!This class is used to pool together a graphical representation (via the drawable), of
65
//an object with its internal data structural representation. This allows the user
66
//to grapple with the drawable representation and feed this into the scene.
67
//This class binds ONE drawable object to a set of actions based upon key and button combinations.
68
class SelectionBinding
71
//Pointer to drawable that generates selection events
72
const DrawableObj *obj;
74
Point3D *drawablePoint3D;
75
//Pointer to filter who owns this binding
78
//ID number for parent to know which of its bindings this is
79
unsigned int bindingId;
82
unsigned int dataType;
84
//Binding button (ORed together)
85
unsigned int bindButtons;
87
//Binding key (ORed together)
88
unsigned int bindKeys;
91
unsigned int bindMode;
93
//Original value of data type (probably more mem efficient ot use a void*...)
95
Point3D cachedValPoint3D;
99
//limits in floating point
105
//!Returns true if this binding will be activated given the current flags
106
bool isActive(unsigned int button,unsigned int curModifierFlags);
108
//!Set the binding for a float DO NOT CACHE THE DRAWABLEOBJ-> THAT IS BAD
109
void setBinding(unsigned int buttonFlags, unsigned int modifierFlags,
110
unsigned int bindingID, float *fDrawable, const DrawableObj *d);
112
//!Set the binding for a Point3D. DO NOT CACHE THE DRAWABLEOBJ-> THAT IS BAD
113
void setBinding(unsigned int buttonFlags, unsigned int modifierFlags,
114
unsigned int bindingID, Point3D *fDrawable, const DrawableObj *d);
116
//!Set the interaction method. (example translate, scale, rotate etc)
117
void setInteractionMode(unsigned int bindMode);
119
//!Get the interaction mode
120
unsigned int getInteractionMode() const { return bindMode;};
122
//!Get the mouse button
123
unsigned int getMouseButtons() const { return bindButtons;};
125
//!Get the mouse button
126
unsigned int getKeyFlags() const { return bindKeys;};
128
//!Set the limits for a floating point data type
129
void setFloatLimits(float min,float max);
131
//!Is this binding for the following object?
132
bool matchesDrawable(const DrawableObj *d,
133
unsigned int mouseFlags, unsigned int keyFlags) const;
134
//!Is this binding for the following object?
135
bool matchesDrawable(const DrawableObj *d) const;
137
//!Apply the user ineraction specified. set permanent=true to
138
//make it such that this is not undone during the next transform,
140
//worldvec is the vector along which to transform the object (subject to
141
//interpretation by the "interaction mode" (bindmode) setting)
142
void applyTransform(const Point3D &worldVec,bool permanent=false);
145
//!Map the screen coords world coords, given the mouse and keyflags
146
//coeffs are 0: right 1: forwards 2: up ( right hand rule)
147
void computeWorldVectorCoeffs(unsigned int buttonFlags,
148
unsigned int modifierFlags,Point3D &xCoeffs,Point3D &yCoeffs) const;
150
//!Retrieve the current value from the drawable representation
151
void getValue(float &f) const;
152
//!Retreive the current value from the drawable representation
153
void getValue(Point3D &p) const;
155
unsigned int getID() const { return bindingId;};
157
//!True if the binding has modified the data
158
bool modified() const {return valModified;};
161
class SelectionDevice
164
std::vector<SelectionBinding> bindingVec;
165
const Filter *target;
167
//!Create a new selection device
168
SelectionDevice(const Filter *p);
170
//!Copy constructor (not implemented)
171
SelectionDevice(const SelectionDevice ©Src);
173
//!Bind a floating point type between the graphical and internal reps.
174
//note that it is a BUG to attempt to bind any object that uses a
175
//display list in its internal representation.
176
void addBinding(SelectionBinding b);
178
bool getBinding(const DrawableObj *d, unsigned int mouseFlags,
179
unsigned int keyFlags, SelectionBinding* &b);
181
bool getAvailBindings(const DrawableObj *d, vector<const SelectionBinding*> &b) const;
182
void getModifiedBindings(vector<std::pair<const Filter *,SelectionBinding> > &bindings);