non/DPM.H

82 lines
2.7 KiB
C++
Raw Normal View History

2008-03-12 02:32:04 +01:00
/*******************************************************************************/
/* Copyright (C) 2008 Jonathan Moore Liles */
/* */
/* This program is free software; you can redistribute it and/or modify it */
/* under the terms of the GNU General Public License as published by the */
/* Free Software Foundation; either version 2 of the License, or (at your */
/* option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
/* more details. */
/* */
/* You should have received a copy of the GNU General Public License along */
/* with This program; see the file COPYING. If not,write to the Free Software */
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*******************************************************************************/
#pragma once
#include <FL/Fl_Valuator.H> // for FL_HORIZONTAL and FL_VERTICAL
#include "Meter.H"
2008-03-12 05:31:50 +01:00
class DPM : public Meter
{
2008-03-12 02:32:04 +01:00
2008-03-13 05:47:06 +01:00
int _segments;
2008-03-12 02:32:04 +01:00
2008-03-12 04:07:41 +01:00
int pos ( float v )
{
2008-03-13 05:47:06 +01:00
return deflection( v ) * _segments;
}
2008-03-12 06:23:12 +01:00
2008-03-13 05:47:06 +01:00
static float _dim;
static Fl_Color _gradient[];
static Fl_Color _dim_gradient[];
Fl_Color
div_color ( int i )
{
return _gradient[ i * 127 / _segments ];
}
Fl_Color
dim_div_color ( int i )
{
return _dim_gradient[ i * 127 / _segments ];
}
2008-03-12 02:32:04 +01:00
protected:
2008-03-12 22:35:08 +01:00
virtual void draw_label ( void );
2008-03-12 02:32:04 +01:00
virtual void draw ( void );
public:
DPM ( int X, int Y, int W, int H, const char *L = 0 );
2008-03-12 02:32:04 +01:00
// void value ( float v ) { if ( pos( v ) != pos( value() ) ) redraw(); Meter::value( v ) }
2008-03-12 05:31:50 +01:00
2008-03-13 05:47:06 +01:00
bool segments ( void ) const { return _segments; }
void segments ( int v ) { _segments = v; }
2008-03-12 02:32:04 +01:00
float dim ( void ) const { return _dim; }
void dim ( float v ) { _dim = v; redraw(); }
2008-03-13 05:47:06 +01:00
static
void
blend ( Fl_Color min, Fl_Color max )
{
for ( int i = 128; i-- ; )
_gradient[ i ] = fl_color_average( max, min, i / (float)128 );
2008-03-12 04:07:41 +01:00
2008-03-13 05:47:06 +01:00
for ( int i = 128; i-- ; )
_dim_gradient[ i ] = fl_color_average( FL_BLACK, _gradient[ i ], _dim );
}
2008-03-12 02:32:04 +01:00
};