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 
18 class SoState;
19 class SoHandleEventAction;
21 
22 // This class is used by SoView2DExtensions for additional data, don't use
23 // it for other purposes!
24 class View2DPosition;
25 
28 {
30  friend class SoInteractionHandler;
31 
32 public:
35 
36  // Constructor given an array of 2 components.
37  SoPointerPosition(const int v[2]);
38 
39  // Constructor given 2 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 
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 
98 private:
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
Definition: SoKeyGrabber.h:71
#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.
SoPointerPosition & setValue(int x, int y)
Sets the value of vector from two individual components.
void getValue(int &x, int &y) const
SoHandleEventAction * getAction() const
bool isNull() const
int manhattanLength() const
const View2DPosition * getView2DPosition() const
void set(T *data)
Sets pointer to additional position data, e.g., for SoView2D or SoDiagram2D.
SoPointerPosition(const SoPointerPosition &other)=default
SoState * getState() const
SoPointerPosition(int x, int y)
T * get() const
Gets pointer to additional position data.
SoPointerPosition()
Default constructor.
This class stores all position information needed by SoView2DExtensions to handle the pointer positio...
bool operator==(const Tmat2< DT > &a, const Tmat2< DT > &b)
a == b ? Return true if yes.
Definition: mlMatrix2.h:425
bool operator!=(const Tmat2< DT > &a, const Tmat2< DT > &b)
a != b ? Return true if yes.
Definition: mlMatrix2.h:433