Flu_Dual_Slider.H 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // $Id: Flu_Dual_Slider.h,v 1.9 2004/10/14 18:59:36 jbryan Exp $
  2. /***************************************************************
  3. * FLU - FLTK Utility Widgets
  4. * Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University
  5. *
  6. * This file and its content is protected by a software license.
  7. * You should have received a copy of this license with this file.
  8. * If not, please contact the Ohio Supercomputer Center immediately:
  9. * Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212
  10. *
  11. ***************************************************************/
  12. #ifndef _FLU_DUAL_SLIDER_H
  13. #define _FLU_DUAL_SLIDER_H
  14. #include <FL/Fl.H>
  15. #include <FL/Fl_Valuator.H>
  16. #include <FL/Fl_Slider.H>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include "FLU/Flu_Enumerations.H"
  21. //! This class is essentially an Fl_Slider but with two handles. type() can be one of FL_HOR_SLIDER, FL_HOR_NICE_SLIDER, FL_VERT_SLIDER, FL_VERT_NICE_SLIDER
  22. class FLU_EXPORT Flu_Dual_Slider : public Fl_Valuator
  23. {
  24. public:
  25. //! Normal FLTK widget constructor
  26. Flu_Dual_Slider( int x, int y, int w, int h, const char *l = 0 );
  27. //! Default destructor
  28. ~Flu_Dual_Slider();
  29. //! Override of Fl_Valuator::handle
  30. int handle( int event );
  31. //! Override of Fl_Valuator::handle
  32. void draw();
  33. //! Set whether the low and high values can be the same (\c true), or whether they are exclusive (\c false). Default is \c false
  34. inline void overlap( bool b )
  35. { _overlap = b; }
  36. //! Get whether the low and high values can be the same
  37. inline bool overlap() const
  38. { return _overlap; }
  39. //! Set the low value of the slider
  40. inline void low_value( float v )
  41. { lowValue = v; _lVal = (lowValue-minimum())/(maximum()-minimum()); Fl_Valuator::value(v); }
  42. //! Get the low value of the slider
  43. inline float low_value() const
  44. { return minimum()>maximum() ? (minimum()+maximum()-highValue) : lowValue; }
  45. //! Set the high value of the slider
  46. inline void high_value( float v )
  47. { highValue = v; _hVal = (highValue-minimum())/(maximum()-minimum()); Fl_Valuator::value(v); }
  48. //! Get the high value of the slider
  49. inline float high_value() const
  50. { return minimum()>maximum() ? (minimum()+maximum()-lowValue) : highValue; }
  51. //! Convenience routine to set low_value() and high_value() at once
  52. inline void value( float lo, float hi )
  53. { low_value(lo); high_value(hi); }
  54. //! \return \b true if the low value slider is currently grabbed by the mouse, \c false otherwise
  55. inline bool low_grabbed() const
  56. { return _lGrabbed; }
  57. //! \return \b true if the high value slider is currently grabbed by the mouse, \c false otherwise
  58. inline bool high_grabbed() const
  59. { return _hGrabbed; }
  60. DECLARE_CLASS_CHEAP_RTTI_2(Flu_Dual_Slider, Fl_Valuator)
  61. protected:
  62. inline bool _horizontal()
  63. { return( type() == FL_HOR_NICE_SLIDER || type() == FL_HOR_SLIDER ); }
  64. inline bool _nice()
  65. { return( type() == FL_HOR_NICE_SLIDER || type() == FL_VERT_NICE_SLIDER ); }
  66. float highValue, lowValue;
  67. bool _lFocus, _flip, _overlap;
  68. int _grab, _delta;
  69. float _lVal, _hVal;
  70. int _lHandle[4], _hHandle[4];
  71. bool _lGrabbed, _hGrabbed;
  72. int _grabDelta;
  73. };
  74. #endif