StateSetManipulator 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGGA_STATESET_MANIPULATOR
  14. #define OSGGA_STATESET_MANIPULATOR 1
  15. #include <osgGA/Export>
  16. #include <osgGA/GUIEventAdapter>
  17. #include <osgGA/GUIActionAdapter>
  18. #include <osgGA/GUIEventHandler>
  19. #include <osg/StateSet>
  20. #include <osg/PolygonMode>
  21. namespace osgGA {
  22. /**
  23. Experimental class, not been looked at for a while, but which will
  24. be returned to at some point :-\
  25. */
  26. class OSGGA_EXPORT StateSetManipulator : public GUIEventHandler
  27. {
  28. public:
  29. StateSetManipulator(osg::StateSet* stateset=0);
  30. virtual const char* className() const { return "StateSetManipulator"; }
  31. /** attach a StateSet to the manipulator to be used for specifying view.*/
  32. virtual void setStateSet(osg::StateSet*);
  33. /** get the attached a StateSet.*/
  34. virtual osg::StateSet * getStateSet();
  35. /** get the attached a StateSet.*/
  36. virtual const osg::StateSet * getStateSet() const;
  37. /** Handle events, return true if handled, false otherwise.*/
  38. virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
  39. /** Get the keyboard and mouse usage of this manipulator.*/
  40. virtual void getUsage(osg::ApplicationUsage& usage) const;
  41. void setMaximumNumOfTextureUnits(unsigned int i) { _maxNumOfTextureUnits = i; }
  42. unsigned int getMaximumNumOfTextureUnits() const { return _maxNumOfTextureUnits; }
  43. void setBackfaceEnabled(bool newbackface);
  44. bool getBackfaceEnabled() const {return _backface;};
  45. void setLightingEnabled(bool newlighting);
  46. bool getLightingEnabled() const {return _lighting;};
  47. void setTextureEnabled(bool newtexture);
  48. bool getTextureEnabled() const {return _texture;};
  49. void setPolygonMode(osg::PolygonMode::Mode newpolygonmode);
  50. osg::PolygonMode::Mode getPolygonMode() const;
  51. void cyclePolygonMode();
  52. void setKeyEventToggleBackfaceCulling(int key) { _keyEventToggleBackfaceCulling = key; }
  53. int getKeyEventToggleBackfaceCulling() const { return _keyEventToggleBackfaceCulling; }
  54. void setKeyEventToggleLighting(int key) { _keyEventToggleLighting = key; }
  55. int getKeyEventToggleLighting() const { return _keyEventToggleLighting; }
  56. void setKeyEventToggleTexturing(int key) { _keyEventToggleTexturing = key; }
  57. int getKeyEventToggleTexturing() const { return _keyEventToggleTexturing; }
  58. void setKeyEventCyclePolygonMode(int key) { _keyEventCyclePolygonMode = key; }
  59. int getKeyEventCyclePolygonMode() const { return _keyEventCyclePolygonMode; }
  60. protected:
  61. virtual ~StateSetManipulator();
  62. void clone();
  63. osg::ref_ptr<osg::StateSet> _stateset;
  64. bool _initialized;
  65. bool _backface;
  66. bool _lighting;
  67. bool _texture;
  68. unsigned int _maxNumOfTextureUnits;
  69. int _keyEventToggleBackfaceCulling;
  70. int _keyEventToggleLighting;
  71. int _keyEventToggleTexturing;
  72. int _keyEventCyclePolygonMode;
  73. osg::PolygonMode* getOrCreatePolygonMode();
  74. };
  75. }
  76. #endif