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.

133 lines
3.8KB

  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. int _blink_interval;
  26. bool _blinking;
  27. static void
  28. update_cb ( void *v )
  29. {
  30. ((Fl_Blink_Button*)v)->update_cb();
  31. }
  32. float
  33. blink_interval_as_fraction_of_seceond ( void ) const
  34. {
  35. return (float)_blink_interval / 1000;
  36. }
  37. void
  38. update_cb ( void )
  39. {
  40. Fl::repeat_timeout( blink_interval_as_fraction_of_seceond(), update_cb, this );
  41. _on = ! _on;
  42. redraw();
  43. }
  44. public:
  45. enum
  46. {
  47. SLOW=500,
  48. MEDIUM=300,
  49. FAST=100,
  50. DEFAULT=500
  51. };
  52. Fl_Blink_Button ( int X, int Y, int W, int H, const char *L=0 )
  53. : Fl_Button( X, Y, W, H, L )
  54. {
  55. _blinking = true;
  56. _on = false;
  57. _blink_interval = DEFAULT;
  58. type( FL_TOGGLE_BUTTON );
  59. }
  60. virtual
  61. ~Fl_Blink_Button ()
  62. {
  63. if ( value() )
  64. Fl::remove_timeout( update_cb, this );
  65. }
  66. void blink ( bool b )
  67. {
  68. _blinking = b;
  69. if ( ! b )
  70. _on = true;
  71. }
  72. bool blink ( void ) const
  73. {
  74. return _blinking;
  75. }
  76. void
  77. blink_interval ( float v )
  78. {
  79. _blink_interval = v * 1000;
  80. if ( value() )
  81. {
  82. Fl::remove_timeout( update_cb, this );
  83. Fl::add_timeout( blink_interval_as_fraction_of_seceond(), update_cb, this );
  84. }
  85. }
  86. virtual void value ( float v )
  87. {
  88. if ( v )
  89. {
  90. if ( _blinking )
  91. Fl::add_timeout( blink_interval_as_fraction_of_seceond(), update_cb, this );
  92. Fl_Button::value( v );
  93. redraw();
  94. }
  95. else
  96. {
  97. Fl_Button::value( v );
  98. Fl::remove_timeout( update_cb, this );
  99. redraw();
  100. }
  101. }
  102. virtual float value ( void ) { return Fl_Button::value(); }
  103. virtual void
  104. draw ( void )
  105. {
  106. draw_box( value() ? box() : down_box(), x(), y(), w(), h(), ( value() != 0 && _on ) ? selection_color() : color() );
  107. draw_label();
  108. }
  109. };