~ubuntu-branches/debian/sid/3depict/sid

« back to all changes in this revision

Viewing changes to src/select.h

  • Committer: Bazaar Package Importer
  • Author(s): D Haley
  • Date: 2010-08-09 21:23:50 UTC
  • Revision ID: james.westby@ubuntu.com-20100809212350-cg6yumndhwi3bqws
Tags: upstream-0.0.1
ImportĀ upstreamĀ versionĀ 0.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      select,h - Opengl interaction header. 
 
3
 *      Copyright (C) 2010, D Haley 
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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/>.
 
17
*/
 
18
 
 
19
 
 
20
#ifndef SELECT_H
 
21
#define SELECT_H
 
22
 
 
23
class SelectionDevice;
 
24
class SelectionBinding;
 
25
 
 
26
#include "filter.h"
 
27
#include "drawables.h"
 
28
#include "viscontrol.h"
 
29
 
 
30
#include <vector>
 
31
 
 
32
//Mouse button flags
 
33
enum
 
34
{
 
35
        SELECT_BUTTON_LEFT=1,
 
36
        SELECT_BUTTON_MIDDLE=2,
 
37
        SELECT_BUTTON_RIGHT=4,
 
38
};
 
39
 
 
40
//!Keyboard keydown flags
 
41
enum
 
42
{
 
43
        FLAG_NONE=0,
 
44
        FLAG_CMD=1, //control (non-mac) or "clover" key (mac)
 
45
        FLAG_SHIFT=2, //Left or right shift key.
 
46
};
 
47
 
 
48
//!Allowable binding modes
 
49
enum
 
50
{
 
51
        BIND_MODE_FLOAT_SCALE,
 
52
        BIND_MODE_FLOAT_TRANSLATE,
 
53
        BIND_MODE_POINT3D_TRANSLATE,
 
54
        BIND_MODE_POINT3D_ROTATE,
 
55
};
 
56
 
 
57
//!Bindable data types (data types that SelectionBinding can work with)
 
58
enum
 
59
{
 
60
        BIND_TYPE_FLOAT,
 
61
        BIND_TYPE_POINT3D
 
62
};
 
63
 
 
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
 
69
{
 
70
        private:
 
71
                //Pointer to drawable that generates selection events
 
72
                const DrawableObj *obj;
 
73
                float *drawableFloat;
 
74
                Point3D *drawablePoint3D;
 
75
                //Pointer to filter who owns this binding
 
76
                const Filter *owner;
 
77
        
 
78
                //ID number for parent to know which of its bindings this is
 
79
                unsigned int bindingId;
 
80
 
 
81
                //Binding type
 
82
                unsigned int dataType;
 
83
 
 
84
                //Binding button (ORed together)
 
85
                unsigned int bindButtons;
 
86
                
 
87
                //Binding key (ORed together)
 
88
                unsigned int bindKeys;
 
89
 
 
90
                //Binding mode
 
91
                unsigned int bindMode;
 
92
 
 
93
                //Original value of data type (probably more mem efficient ot use a void*...)
 
94
                float cachedValFloat;
 
95
                Point3D cachedValPoint3D;
 
96
 
 
97
                bool valModified;
 
98
 
 
99
                //limits in floating point
 
100
                float fMin,fMax;
 
101
 
 
102
        public:
 
103
                SelectionBinding();
 
104
 
 
105
                //!Returns true if this binding will be activated given the current flags
 
106
                bool isActive(unsigned int button,unsigned int curModifierFlags);
 
107
 
 
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);
 
111
 
 
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);
 
115
 
 
116
                //!Set the interaction method. (example translate, scale, rotate etc)
 
117
                void setInteractionMode(unsigned int bindMode);
 
118
                
 
119
                //!Get the interaction mode 
 
120
                unsigned int getInteractionMode() const { return bindMode;};
 
121
                
 
122
                //!Get the mouse button
 
123
                unsigned int getMouseButtons() const { return bindButtons;};
 
124
                
 
125
                //!Get the mouse button
 
126
                unsigned int getKeyFlags() const { return bindKeys;};
 
127
 
 
128
                //!Set the limits for a floating point data type
 
129
                void setFloatLimits(float min,float max);
 
130
 
 
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;
 
136
 
 
137
                //!Apply the user ineraction specified. set permanent=true to
 
138
                //make it such that this is not undone during the next transform, 
 
139
                //or call to reset()
 
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);
 
143
 
 
144
 
 
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;
 
149
 
 
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;
 
154
 
 
155
                unsigned int getID() const { return bindingId;};
 
156
 
 
157
                //!True if the binding has modified the data
 
158
                bool modified() const {return valModified;};
 
159
};
 
160
 
 
161
class SelectionDevice
 
162
{
 
163
        private:
 
164
                std::vector<SelectionBinding> bindingVec;
 
165
                const Filter *target;
 
166
        public:
 
167
                //!Create a new selection device
 
168
                SelectionDevice(const Filter *p);
 
169
 
 
170
                //!Copy constructor (not implemented)
 
171
                SelectionDevice(const SelectionDevice &copySrc);
 
172
        
 
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);
 
177
 
 
178
                bool getBinding(const DrawableObj *d, unsigned int mouseFlags, 
 
179
                                unsigned int keyFlags,  SelectionBinding* &b);
 
180
 
 
181
                bool getAvailBindings(const DrawableObj *d, vector<const SelectionBinding*> &b) const;
 
182
                void getModifiedBindings(vector<std::pair<const Filter *,SelectionBinding> > &bindings);
 
183
};
 
184
 
 
185
#endif
 
186