Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.6KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #include <FL/Fl_Button.H>
  19. #include <FL/Fl.H>
  20. /* Kind of like Fl_Light_Button except that the whole thing is the
  21. * indicator and it can optionally blink */
  22. class Fl_Blink_Button : public Fl_Button
  23. {
  24. bool _on;
  25. float _blink_interval;
  26. bool _blinking;
  27. static void
  28. update_cb ( void *v )
  29. {
  30. ((Fl_Blink_Button*)v)->update_cb();
  31. }
  32. void
  33. update_cb ( void )
  34. {
  35. Fl::repeat_timeout( _blink_interval, update_cb, this );
  36. _on = ! _on;
  37. redraw();
  38. }
  39. public:
  40. static const float SLOW = 0.5f;
  41. static const float MEDIUM = 0.3f;
  42. static const float FAST = 0.1f;
  43. static const float DEFAULT = 0.5f;
  44. Fl_Blink_Button ( int X, int Y, int W, int H, const char *L )
  45. : Fl_Button( X, Y, W, H, L )
  46. {
  47. _blinking = true;
  48. _on = false;
  49. _blink_interval = DEFAULT;
  50. type( FL_TOGGLE_BUTTON );
  51. }
  52. virtual
  53. ~Fl_Blink_Button ()
  54. {
  55. if ( value() )
  56. Fl::remove_timeout( update_cb, this );
  57. }
  58. void blink ( bool b )
  59. {
  60. _blinking = b;
  61. if ( ! b )
  62. _on = true;
  63. }
  64. bool blink ( void ) const
  65. {
  66. return _blinking;
  67. }
  68. void
  69. blink_interval ( float v )
  70. {
  71. _blink_interval = v;
  72. if ( value() )
  73. {
  74. Fl::remove_timeout( update_cb, this );
  75. Fl::add_timeout( _blink_interval, update_cb, this );
  76. }
  77. }
  78. virtual void value ( float v )
  79. {
  80. if ( v )
  81. {
  82. if ( _blinking )
  83. Fl::add_timeout( _blink_interval, update_cb, this );
  84. Fl_Button::value( v );
  85. redraw();
  86. }
  87. else
  88. {
  89. Fl_Button::value( v );
  90. Fl::remove_timeout( update_cb, this );
  91. redraw();
  92. }
  93. }
  94. virtual float value ( void ) { return Fl_Button::value(); }
  95. virtual void
  96. draw ( void )
  97. {
  98. draw_box( value() ? box() : down_box(), x(), y(), w(), h(), ( value() != 0 && _on ) ? selection_color() : color() );
  99. draw_label();
  100. }
  101. };