Non reinvents the DAW. Powerful enough to form a complete studio, fast and light enough to run on low-end hardware like the eeePC or Raspberry Pi, and so reliable that it can be used live https://non.tuxfamily.org/
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.

163 lines
4.5KB

  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. #pragma once
  19. #include <FL/Fl_Button.H>
  20. #include <FL/Fl.H>
  21. /* Kind of like Fl_Light_Button except that the whole thing is the
  22. * indicator and it can optionally blink */
  23. class Fl_Blink_Button : public Fl_Button
  24. {
  25. bool _on;
  26. int _blink_interval;
  27. bool _blinking;
  28. bool _ignore_input;
  29. static void
  30. update_cb ( void *v )
  31. {
  32. ((Fl_Blink_Button*)v)->update_cb();
  33. }
  34. float
  35. blink_interval_as_fraction_of_seceond ( void ) const
  36. {
  37. return (float)_blink_interval / 1000;
  38. }
  39. void
  40. update_cb ( void )
  41. {
  42. Fl::repeat_timeout( blink_interval_as_fraction_of_seceond(), update_cb, this );
  43. _on = ! _on;
  44. redraw();
  45. }
  46. public:
  47. enum
  48. {
  49. SLOW=500,
  50. MEDIUM=300,
  51. FAST=100,
  52. DEFAULT=500
  53. };
  54. Fl_Blink_Button ( int X, int Y, int W, int H, const char *L=0 )
  55. : Fl_Button( X, Y, W, H, L )
  56. {
  57. _blinking = true;
  58. _on = false;
  59. _ignore_input = false;
  60. _blink_interval = DEFAULT;
  61. type( FL_TOGGLE_BUTTON );
  62. }
  63. virtual
  64. ~Fl_Blink_Button ()
  65. {
  66. if ( value() )
  67. Fl::remove_timeout( update_cb, this );
  68. }
  69. void ignore_input ( bool b )
  70. {
  71. _ignore_input = b;
  72. }
  73. bool ignore_input ( void ) const
  74. {
  75. return _ignore_input;
  76. }
  77. void blink ( bool b )
  78. {
  79. _blinking = b;
  80. if ( ! b )
  81. _on = true;
  82. }
  83. bool blink ( void ) const
  84. {
  85. return _blinking;
  86. }
  87. void
  88. blink_interval ( float v )
  89. {
  90. _blink_interval = v * 1000;
  91. if ( value() )
  92. {
  93. Fl::remove_timeout( update_cb, this );
  94. Fl::add_timeout( blink_interval_as_fraction_of_seceond(), update_cb, this );
  95. }
  96. }
  97. virtual void value ( float v )
  98. {
  99. bool b = v;
  100. if ( b != value() )
  101. {
  102. if ( b )
  103. {
  104. if ( _blinking )
  105. {
  106. /* just to be safe.. */
  107. Fl::remove_timeout( update_cb, this );
  108. Fl::add_timeout( blink_interval_as_fraction_of_seceond(), update_cb, this );
  109. }
  110. Fl_Button::value( b );
  111. redraw();
  112. }
  113. else
  114. {
  115. Fl_Button::value( b );
  116. Fl::remove_timeout( update_cb, this );
  117. redraw();
  118. }
  119. }
  120. }
  121. virtual float value ( void ) { return (bool)Fl_Button::value(); }
  122. virtual void
  123. draw ( void )
  124. {
  125. draw_box( value() ? box() : down_box(), x(), y(), w(), h(),
  126. ( value() != 0 && _on ) ? selection_color() : color() );
  127. draw_label();
  128. }
  129. virtual int handle ( int m )
  130. {
  131. if ( _ignore_input )
  132. return 0;
  133. else
  134. return Fl_Button::handle( m );
  135. }
  136. };