~ubuntu-branches/ubuntu/trusty/3depict/trusty-proposed

« back to all changes in this revision

Viewing changes to src/gl/select.h

  • Committer: Package Import Robot
  • Author(s): D Haley
  • Date: 2013-07-20 18:31:32 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20130720183132-5ak932y2x6pwo4fs
Tags: 0.0.14-1
* Update to upstream, 0.0.14
* Enable mathgl2.x configure option
* Modify build-depends, libmgl-dev >= 2.1.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#ifndef SELECT_H
21
21
#define SELECT_H
22
22
 
23
 
#include "drawables.h"
 
23
#include <vector>
24
24
 
 
25
class DrawableObj;
 
26
class Filter;
 
27
class Point3D;
25
28
 
26
29
//Mouse button flags
27
30
enum
157
160
                bool modified() const {return valModified;};
158
161
};
159
162
 
160
 
template<class T> class SelectionDevice
 
163
class SelectionDevice
161
164
{
162
165
        private:
163
166
                std::vector<SelectionBinding> bindingVec;
164
 
                const T *target;
 
167
                const Filter *target;
165
168
public:
166
169
                //!Create a new selection device
167
 
                SelectionDevice(const T *p);
 
170
                SelectionDevice(const Filter *p);
168
171
 
169
172
                //!Copy constructor (not implemented)
170
173
                SelectionDevice(const SelectionDevice &copySrc);
177
180
                bool getBinding(const DrawableObj *d, unsigned int mouseFlags, 
178
181
                                unsigned int keyFlags,  SelectionBinding* &b);
179
182
 
180
 
                bool getAvailBindings(const DrawableObj *d, vector<const SelectionBinding*> &b) const;
181
 
                void getModifiedBindings(vector<std::pair<const T *,SelectionBinding> > &bindings);
 
183
                bool getAvailBindings(const DrawableObj *d, std::vector<const SelectionBinding*> &b) const;
 
184
                void getModifiedBindings(std::vector<std::pair<const Filter *,SelectionBinding> > &bindings);
 
185
 
 
186
                size_t getNumBindings() const { return bindingVec.size(); }
182
187
};
183
188
 
184
 
template<class T>
185
 
SelectionDevice<T>::SelectionDevice(const T *p) : target(p)
186
 
{
187
 
}
188
 
 
189
 
template<class T>
190
 
void SelectionDevice<T>::addBinding(SelectionBinding b)
191
 
{
192
 
        bindingVec.push_back(b);
193
 
}
194
 
 
195
 
template<class T>
196
 
bool SelectionDevice<T>::getBinding(const DrawableObj *d,unsigned int mouseFlags, 
197
 
                                        unsigned int keyFlags,SelectionBinding* &b)
198
 
{
199
 
 
200
 
        unsigned int keyMask=0;
201
 
 
202
 
 
203
 
        bool found=false;
204
 
 
205
 
        for(unsigned int ui=0;ui<bindingVec.size();ui++)
206
 
        {
207
 
                if(bindingVec[ui].matchesDrawable(d,mouseFlags,keyFlags))
208
 
                {
209
 
                        if(!found)
210
 
                        {
211
 
                                //we found one.
212
 
                                found=true;
213
 
                                b=&(bindingVec[ui]);
214
 
                                keyMask=b->getKeyFlags();
215
 
                                continue;
216
 
                        }
217
 
 
218
 
                        //OK, we already have one, but we can be "trumped"
219
 
                        //by a more complex keymask.
220
 
                        if( (keyMask & bindingVec[ui].getKeyFlags() )== keyMask)
221
 
                        {
222
 
                                b=&(bindingVec[ui]);
223
 
                                keyMask=b->getKeyFlags();
224
 
                        }
225
 
                }
226
 
        }
227
 
 
228
 
 
229
 
        //This selection device does not match
230
 
        //the targeted object.
231
 
        return found;
232
 
}
233
 
 
234
 
template<class T>
235
 
void SelectionDevice<T>::getModifiedBindings(vector<std::pair<const T *,SelectionBinding> > &bindings)
236
 
{
237
 
        ASSERT(target);
238
 
        for(unsigned int ui=0;ui<bindingVec.size();ui++)
239
 
        {
240
 
                if(bindingVec[ui].modified())
241
 
                        bindings.push_back(std::make_pair(target,bindingVec[ui]));
242
 
        }
243
 
}
244
 
 
245
 
template<class T>
246
 
bool SelectionDevice<T>::getAvailBindings(const DrawableObj *d,vector<const SelectionBinding*> &b) const
247
 
{
248
 
        ASSERT(b.empty());
249
 
        for(unsigned int ui=0;ui<bindingVec.size();ui++)
250
 
        {
251
 
                if(bindingVec[ui].matchesDrawable(d))
252
 
                        b.push_back(&(bindingVec[ui]));
253
 
        }
254
 
 
255
 
 
256
 
        return b.size();
257
 
}
258
 
 
259
189
#endif
260
190