Flu_Spinner.H 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // $Id: Flu_Spinner.h,v 1.11 2004/10/22 16:17:45 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_SPINNER_H
  13. #define _FLU_SPINNER_H
  14. #include <FL/Fl_Valuator.H>
  15. #include <FL/Fl_Input.H>
  16. #include <FL/Fl_Group.H>
  17. #include "FLU/Flu_Enumerations.H"
  18. //! This class provides a simple spinner widget similar to Fl_Counter, except the manipulator buttons are vertical and you can click, click and hold, or click and drag to change the value
  19. class FLU_EXPORT Flu_Spinner : public Fl_Valuator
  20. {
  21. DECLARE_CLASS_CHEAP_RTTI_2(Flu_Spinner, Fl_Valuator)
  22. class NoTabInput : public Fl_Input
  23. {
  24. public:
  25. NoTabInput( Flu_Spinner *s, int x, int y, int w, int h, const char *l = 0 );
  26. int handle( int event );
  27. void draw();
  28. Flu_Spinner *spinner;
  29. };
  30. public:
  31. //! Normal FLTK widget constructor
  32. Flu_Spinner( int x, int y, int w, int h, const char *l = 0 );
  33. //! Default destructor
  34. ~Flu_Spinner();
  35. //! Get whether the spinner automatically changes when you hold the button down
  36. inline bool enable_repeating() const
  37. { return _doRepeat; }
  38. //! Set whether the spinner automatically changes when you hold the button down
  39. inline void enable_repeating( bool b )
  40. { _doRepeat = b; }
  41. //! Set the auto repeating parameters
  42. /*! \param initialDelay is how long to wait before repeating starts. Default is 0.5 seconds
  43. \param initialTime is how long to wait between value changes. Default is 0.1 seconds (i.e. 10x per second)
  44. \param rapidDelay is how long to wait before repeating more quickly. Default is 2 seconds
  45. \param rapidTime is how long to wait between rapid value changes. Default is 0.02 seconds (i.e. 50x per second)
  46. */
  47. inline void repeat( float initialDelay, float initialTime, float rapidDelay, float rapidTime )
  48. { _initialDelay = initialDelay; _repeatTime[0] = initialTime; _rapidDelay = rapidDelay;_repeatTime[1] = rapidTime; }
  49. //! Get when the input calls the callback
  50. inline int input_when() const
  51. { return _input.when(); }
  52. //! Set when the input calls the callback
  53. inline void input_when( int w )
  54. { _input.when(w); }
  55. //! Get whether the input field can be edited. Default is \c true
  56. inline bool editable() const
  57. { return _editable; }
  58. //! Set whether the input field can be edited.
  59. inline void editable( bool b )
  60. { _editable = b; }
  61. //! Override of Fl_Widget::handle()
  62. int handle( int );
  63. //! Override of Fl_Widget::resize()
  64. void resize( int X, int Y, int W, int H );
  65. //! The default range for Fl_Valuators is [0,1]. This function sets the range of the spinner to +/- infinity
  66. inline void unlimited_range()
  67. { range( -3.4e+38f, 3.4e+38f ); }
  68. //! Set whether the value "wraps" to the range during interaction
  69. inline void wrap_range( bool b )
  70. { _wrapRange = b; }
  71. //! Set whether the value "wraps" to the range during interaction
  72. inline bool wrap_range() const
  73. { return _wrapRange; }
  74. //! Override of Fl_Valuator::precision()
  75. inline void precision( int p )
  76. { Fl_Valuator::precision(p); value_damage(); }
  77. //! Override of Fl_Valuator::value_damage()
  78. void value_damage();
  79. //! Override of Fl_Valuator::hide()
  80. inline void hide()
  81. { Fl_Valuator::hide(); _input.hide(); }
  82. //! Override of Fl_Valuator::show()
  83. inline void show()
  84. { Fl_Valuator::show(); _input.show(); }
  85. //! Get the font for the widget value
  86. inline Fl_Font valuefont() const { return (Fl_Font)_input.textfont(); }
  87. //! Set the font for the widget value
  88. inline void valuefont( uchar s ) { _input.textfont(s); }
  89. //! Get the size of the font for the widget value
  90. inline uchar valuesize() const { return _input.textsize(); }
  91. //! Set the size of the font for the widget value
  92. inline void valuesize( uchar s ) { _input.textsize(s); }
  93. //! Get the background color of the widget value
  94. inline Fl_Color valuecolor() const { return (Fl_Color)_input.color(); }
  95. //! Set the background color for the widget value
  96. inline void valuecolor( unsigned s ) { _input.color(s); }
  97. //! Set the background and selection color for the widget value
  98. inline void valuecolor( unsigned s, unsigned s1 ) { _input.color(s,s1); }
  99. //! Get the color of the font for the widget value
  100. inline Fl_Color valuefontcolor() const { return (Fl_Color)_input.textcolor(); }
  101. //! Set the color of the font for the widget value
  102. inline void valuefontcolor( unsigned s ) { _input.textcolor(s); }
  103. protected:
  104. void _setvalue( double v );
  105. friend class NoTabInput;
  106. NoTabInput _input;
  107. uchar _valbox[2];
  108. bool _up, _pushed, _editable, _dragging;
  109. float _totalTime;
  110. double _lastValue;
  111. int _lastY;
  112. float _initialDelay, _repeatTime[2], _rapidDelay;
  113. bool _doRepeat, _wrapRange;
  114. static void input_cb( Fl_Widget*, void* v );
  115. static void repeat_callback(void *);
  116. void increment_cb();
  117. protected:
  118. void draw();
  119. };
  120. #endif