MeVisLab Toolbox Reference
SoPointerPosition.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2008, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef SO_POINTER_POSITION_H
14#define SO_POINTER_POSITION_H
15
17
18class SoState;
19class SoHandleEventAction;
21
22// This class is used by SoView2DExtensions for additional data, do not use
23// it for other purposes!
24class View2DPosition;
25
28{
31
32public:
35
36 // Constructor given an array of two components.
37 SoPointerPosition(const int v[2]);
38
39 // Constructor given two individual components.
40 SoPointerPosition(int x, int y);
41
42 // Default copy constructor.
43 SoPointerPosition(const SoPointerPosition& other) = default;
44
47 bool isNull() const;
48
51 int manhattanLength() const;
52
54 int x() const { return _vec[0]; }
56 int y() const { return _vec[1]; }
57
59 void getValue(int &x, int &y) const;
60
62 SoPointerPosition & setValue(const int v[2]);
63
65 SoPointerPosition & setValue(int x, int y);
66
68 int operator [](int i) const { return (_vec[i]); }
69
71 SoPointerPosition& operator =(const SoPointerPosition &u);
72
74 friend SOMANAGEDINTERACTION_API bool operator ==(const SoPointerPosition &v1, const SoPointerPosition &v2);
76 friend SOMANAGEDINTERACTION_API bool operator !=(const SoPointerPosition &v1, const SoPointerPosition &v2)
77 { return !(v1 == v2); }
78
80 SoHandleEventAction* getAction() const { return _action; }
81
83 SoState* getState() const;
84
86 template <class T>
87 void set(T* data) { _data = data; }
88
92 template <class T>
93 T* get() const { return static_cast<T*>(_data); }
94
96 const View2DPosition* getView2DPosition() const { return get<View2DPosition>(); }
97
98private:
100 void setAction(SoHandleEventAction* action) { _action = action; }
101
103 int _vec[2];
104
105 // The action from which the event originated, from which the position was taken
106 SoHandleEventAction* _action;
107
108 // This pointer is used by SoView2D and SoDiagram2D for additional data:
109 void* _data;
110};
111
112#endif // __SoPointerPosition_H
@ T
#define SOMANAGEDINTERACTION_API
File to resolve system dependencies in View2D library.
SoInteractionHandler is a mix-in class for instances of SoNode to handle the interactions it provides...
SoPointerPosition manages the current position of the mouse cursor.
SoPointerPosition(const int v[2])
SoPointerPosition & setValue(const int v[2])
Sets the value of vector from array of two components.
SoHandleEventAction * getAction() const
Returns the Inventor action.
T * get() const
Returns a pointer to additional position data.
const View2DPosition * getView2DPosition() const
Returns the additional data as View2DPosition. Legacy support, rather use get<View2DPosition>().
void getValue(int &x, int &y) const
Returns the position as two individual components.
bool isNull() const
Returns whether the stored position is the coordinate system's origin (0/0).
int manhattanLength() const
Returns the manhattan distance of this position to the coordinate system's origin.
void set(T *data)
Sets a pointer to additional position data, e.g., for SoView2D or SoDiagram2D.
SoPointerPosition(const SoPointerPosition &other)=default
SoState * getState() const
Returns the Inventor state.
SoPointerPosition(int x, int y)
int x() const
Returns the x-component of this position.
int y() const
Returns the y-component of this position.
SoPointerPosition & setValue(int x, int y)
Sets the value of vector from two individual components.
SoPointerPosition()
Default constructor.
This class stores all position information needed by SoView2DExtensions to handle the pointer positio...