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.

107 lines
3.4KB

  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.H>
  20. #include <FL/Fl_Scrollbar.H>
  21. #include <FL/Fl_Slider.H>
  22. #include <stdio.h>
  23. class Scalebar : public Fl_Scrollbar
  24. {
  25. int _zoom;
  26. bool _zoom_changed;
  27. int _zoom_min;
  28. int _zoom_max;
  29. void constrain ( void )
  30. {
  31. if ( _zoom > _zoom_max )
  32. _zoom = _zoom_max;
  33. else
  34. if ( _zoom < _zoom_min )
  35. _zoom = _zoom_min;
  36. }
  37. void maybe_do_callback ( int z )
  38. {
  39. if ( z != _zoom )
  40. {
  41. _zoom_changed = true;
  42. do_callback();
  43. _zoom_changed = false;
  44. slider_size( w() / maximum() );
  45. }
  46. }
  47. public:
  48. Scalebar ( int X, int Y, int W, int H ) : Fl_Scrollbar ( X, Y, W, H )
  49. {
  50. _zoom = 1;
  51. _zoom_min = 0;
  52. _zoom_max = 4;
  53. _zoom_changed = false;
  54. step( 1 );
  55. }
  56. bool zoom_changed ( void ) const { return _zoom_changed; }
  57. double zoom ( void ) const { return _zoom; }
  58. void zoom ( int v ) { int z = _zoom ; _zoom = v; constrain(); maybe_do_callback( z ); }
  59. // double value ( void ) const { return Fl_Slider::value(); }
  60. void zoom_range ( int zmin, int zmax ) { _zoom_min = zmin; _zoom_max = zmax; }
  61. void zoom_out ( void ) { int z = _zoom; ++_zoom; constrain(); maybe_do_callback( z ); }
  62. void zoom_in ( void ) {int z = _zoom; --_zoom; constrain(); maybe_do_callback( z ); }
  63. int
  64. handle ( int m )
  65. {
  66. switch ( m )
  67. {
  68. case FL_MOUSEWHEEL:
  69. {
  70. if ( ! Fl::event_ctrl() )
  71. return 0;
  72. int d = Fl::event_dy();
  73. double z = _zoom;
  74. _zoom += d;
  75. constrain();
  76. maybe_do_callback( z );
  77. return 1;
  78. }
  79. default:
  80. return Fl_Scrollbar::handle( m );
  81. }
  82. }
  83. };