CEDRIC  Revision_backup-2009-02
Selectable.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright (C) 2008 Boris Iven, Max Hermann
4  *
5  * This file is part of the "CEDRIC Event Display" application.
6  *
7  *****************************************************************************/
8 
9 #ifndef SELECTABLE_H
10 #define SELECTABLE_H
11 
12 #include "PickingHandler.h"
13 #include <osgGA/GUIEventAdapter>
14 
16 {
17 public:
18  Selectable(): m_selected(false), m_highlighted(false) {}
19  virtual ~Selectable() { if( s_current==this ) s_current=0; }
20 
21  virtual bool onSelect( bool selected ) = 0;
22  virtual bool onHighlight( bool highlighted ) = 0;
23 
24  virtual const std::string& toolTip( osg::Node* ) { static std::string empty(""); return empty; }
25 
26  static bool selectCurrent( bool select=true );
27  static bool toggleCurrent();
28 
29  static void resetCurrent() { s_current = 0; }
30 
31  static Selectable* getCurrent() { return s_current; }
32 
33 protected:
34  bool isSelected() const { return m_selected; }
35 
38  virtual void onMouseOver ( const osgGA::GUIEventAdapter* ea, osg::Node* );
39  virtual void onMouseEnter( const osgGA::GUIEventAdapter* ea, osg::Node* );
40  virtual void onMouseLeave( const osgGA::GUIEventAdapter* ea );
42 
43 private:
44  // toolTipNode is managed by PickingHandler and set before onMouseEnter() call.
45  // This allows for changing the toolTipNode when multiple Viewer windows (and multiple PickingHandlers) are used.
46  //~ void setToolTipNode( osgText::Text* node ) { m_toolTipNode = node; }
47  //~ osgText::Text* getToolTipNode() { return m_toolTipNode.get(); }
48 
49  //~ void setToolTip( std::string text ) { if( _toolTipNode.valid() ) _toolTipNode->setText(text); }
50  //~ void setToolTipPosition( float x, float y, float z ) { if( _toolTipNode.valid() ) _toolTipNode->setPosition( osg::Vec3(x,y,z) ); }
51 
52  bool m_selected;
53  bool m_highlighted;
54 
55  static Selectable* s_current;
56 };
57 
58 #endif
virtual ~Selectable()
Definition: Selectable.h:19
virtual bool onSelect(bool selected)=0
static bool toggleCurrent()
Definition: Selectable.cpp:25
Definition: Selectable.h:15
static Selectable * getCurrent()
Definition: Selectable.h:31
static void resetCurrent()
Definition: Selectable.h:29
bool isSelected() const
Definition: Selectable.h:34
static bool selectCurrent(bool select=true)
Definition: Selectable.cpp:16
virtual void onMouseOver(const osgGA::GUIEventAdapter *ea, osg::Node *)
Definition: Selectable.cpp:34
virtual void onMouseEnter(const osgGA::GUIEventAdapter *ea, osg::Node *)
Definition: Selectable.cpp:39
virtual const std::string & toolTip(osg::Node *)
Definition: Selectable.h:24
Selectable()
Definition: Selectable.h:18
Definition: PickingHandler.h:21
virtual void onMouseLeave(const osgGA::GUIEventAdapter *ea)
Definition: Selectable.cpp:52
virtual bool onHighlight(bool highlighted)=0