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

« back to all changes in this revision

Viewing changes to src/gl/select.cpp

  • 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:
16
16
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
17
*/
18
18
 
 
19
 
 
20
#include "common/mathfuncs.h"
 
21
#include "common/assertion.h"
 
22
#include "gl/drawables.h"
 
23
 
19
24
#include "select.h"
 
25
using std::vector;
 
26
 
 
27
SelectionDevice::SelectionDevice(const Filter *p) : target(p)
 
28
{
 
29
}
 
30
 
 
31
void SelectionDevice::addBinding(SelectionBinding b)
 
32
{
 
33
        bindingVec.push_back(b);
 
34
}
 
35
 
 
36
bool SelectionDevice::getBinding(const DrawableObj *d,unsigned int mouseFlags, 
 
37
                                        unsigned int keyFlags,SelectionBinding* &b)
 
38
{
 
39
 
 
40
        unsigned int keyMask=0;
 
41
 
 
42
 
 
43
        bool found=false;
 
44
 
 
45
        for(unsigned int ui=0;ui<bindingVec.size();ui++)
 
46
        {
 
47
                if(bindingVec[ui].matchesDrawable(d,mouseFlags,keyFlags))
 
48
                {
 
49
                        if(!found)
 
50
                        {
 
51
                                //we found one.
 
52
                                found=true;
 
53
                                b=&(bindingVec[ui]);
 
54
                                keyMask=b->getKeyFlags();
 
55
                                continue;
 
56
                        }
 
57
 
 
58
                        //OK, we already have one, but we can be "trumped"
 
59
                        //by a more complex keymask.
 
60
                        if( (keyMask & bindingVec[ui].getKeyFlags() )== keyMask)
 
61
                        {
 
62
                                b=&(bindingVec[ui]);
 
63
                                keyMask=b->getKeyFlags();
 
64
                        }
 
65
                }
 
66
        }
 
67
 
 
68
 
 
69
        //This selection device does not match
 
70
        //the targeted object.
 
71
        return found;
 
72
}
 
73
 
 
74
void SelectionDevice::getModifiedBindings(vector<std::pair<const Filter *,SelectionBinding> > &bindings)
 
75
{
 
76
        ASSERT(target);
 
77
        for(unsigned int ui=0;ui<bindingVec.size();ui++)
 
78
        {
 
79
                if(bindingVec[ui].modified())
 
80
                        bindings.push_back(std::make_pair(target,bindingVec[ui]));
 
81
        }
 
82
}
 
83
 
 
84
bool SelectionDevice::getAvailBindings(const DrawableObj *d,vector<const SelectionBinding*> &b) const
 
85
{
 
86
        ASSERT(b.empty());
 
87
        for(unsigned int ui=0;ui<bindingVec.size();ui++)
 
88
        {
 
89
                if(bindingVec[ui].matchesDrawable(d))
 
90
                        b.push_back(&(bindingVec[ui]));
 
91
        }
 
92
 
 
93
 
 
94
        return b.size();
 
95
}
20
96
 
21
97
 
22
98
SelectionBinding::SelectionBinding()
223
299
        return (obj == d);
224
300
}
225
301
 
 
302