Update NTK.
[nondaw.git] / mixer / src / DPM.H
blobc0611400cfdf164a97c75435e6e10570b0a03cac
2 /*******************************************************************************/
3 /* Copyright (C) 2008 Jonathan Moore Liles                                     */
4 /*                                                                             */
5 /* This program is free software; you can redistribute it and/or modify it     */
6 /* under the terms of the GNU General Public License as published by the       */
7 /* Free Software Foundation; either version 2 of the License, or (at your      */
8 /* option) any later version.                                                  */
9 /*                                                                             */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       */
12 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   */
13 /* more details.                                                               */
14 /*                                                                             */
15 /* You should have received a copy of the GNU General Public License along     */
16 /* with This program; see the file COPYING.  If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18 /*******************************************************************************/
20 #pragma once
22 #include <FL/Fl_Valuator.H> // for FL_HORIZONTAL and FL_VERTICAL
24 #include "Meter.H"
26 class DPM : public Meter
28     char peak_string[10];
30     int _segments;
31     int _pixels_per_segment;
32     int _last_drawn_hi_segment;
34     float _value;
36     int pos ( float v )
37         {
38             return deflection( v ) * _segments;
39         }
41     static float _dim;
42     static Fl_Color _gradient[];
43     static Fl_Color _dim_gradient[];
45     Fl_Color
46     div_color ( int i )
47         {
48             return _gradient[ i * 127 / _segments ];
49         }
51     Fl_Color
52     dim_div_color ( int i )
53         {
54             return _dim_gradient[ i * 127 / _segments ];
55         }
58 protected:
60     virtual void draw_label ( void );
61     virtual void draw ( void );
62     virtual void resize ( int, int, int, int );
64 public:
66     DPM ( int X, int Y, int W, int H,  const char *L = 0 );
68     void value ( float v )
69         {
70             if ( _value != v )
71             {
72                 if ( pos( v ) != pos( _value ) ) 
73                     Meter::value( v );
74             }
76             _value = v;
77         }
79     float value ( void ) const
80         {
81             return _value;
82         }
84     void pixels_per_segment ( int v ) { _pixels_per_segment = v; }
86     float dim ( void ) const { return _dim; }
87     void dim ( float v ) { _dim = v; redraw(); }
89     static
90     void
91     blend ( Fl_Color min, Fl_Color max )
92         {
93             for ( int i = 128; i-- ; )
94                 _gradient[ i ] = fl_color_average( max, min, i / (float)128 );
96             for ( int i = 128; i-- ; )
97                 _dim_gradient[ i ] = fl_color_average( FL_BLACK, _gradient[ i ], _dim );
98         }