2008-07-26 08:49:18 +02: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. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
2012-12-10 07:06:39 +01:00
|
|
|
#pragma once
|
|
|
|
|
2008-07-26 08:49:18 +02:00
|
|
|
#include <FL/Fl_Button.H>
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
|
2012-04-14 23:11:58 +02:00
|
|
|
/* Kind of like Fl_Light_Button except that the whole thing is the
|
|
|
|
* indicator and it can optionally blink */
|
|
|
|
|
|
|
|
class Fl_Blink_Button : public Fl_Button
|
2008-07-26 08:49:18 +02:00
|
|
|
{
|
|
|
|
bool _on;
|
2012-11-06 08:50:28 +01:00
|
|
|
int _blink_interval;
|
2012-04-14 23:11:58 +02:00
|
|
|
bool _blinking;
|
2012-12-10 07:06:39 +01:00
|
|
|
bool _ignore_input;
|
2008-07-26 08:49:18 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
update_cb ( void *v )
|
|
|
|
{
|
2012-04-14 23:11:58 +02:00
|
|
|
((Fl_Blink_Button*)v)->update_cb();
|
2008-07-26 08:49:18 +02:00
|
|
|
}
|
|
|
|
|
2012-11-16 10:01:53 +01:00
|
|
|
|
|
|
|
float
|
|
|
|
blink_interval_as_fraction_of_seceond ( void ) const
|
|
|
|
{
|
|
|
|
return (float)_blink_interval / 1000;
|
|
|
|
}
|
|
|
|
|
2008-07-26 08:49:18 +02:00
|
|
|
void
|
|
|
|
update_cb ( void )
|
|
|
|
{
|
2012-11-16 10:01:53 +01:00
|
|
|
Fl::repeat_timeout( blink_interval_as_fraction_of_seceond(), update_cb, this );
|
2008-07-26 08:49:18 +02:00
|
|
|
|
|
|
|
_on = ! _on;
|
|
|
|
|
|
|
|
redraw();
|
|
|
|
}
|
2012-04-14 23:11:58 +02:00
|
|
|
|
2008-07-26 08:49:18 +02:00
|
|
|
public:
|
|
|
|
|
2012-11-06 08:50:28 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SLOW=500,
|
|
|
|
MEDIUM=300,
|
|
|
|
FAST=100,
|
|
|
|
DEFAULT=500
|
|
|
|
};
|
2010-01-19 06:46:23 +01:00
|
|
|
|
2012-12-02 01:14:01 +01:00
|
|
|
Fl_Blink_Button ( int X, int Y, int W, int H, const char *L=0 )
|
2008-07-26 08:49:18 +02:00
|
|
|
: Fl_Button( X, Y, W, H, L )
|
|
|
|
{
|
2012-04-14 23:11:58 +02:00
|
|
|
_blinking = true;
|
2008-07-26 08:49:18 +02:00
|
|
|
_on = false;
|
2012-12-10 07:06:39 +01:00
|
|
|
_ignore_input = false;
|
2010-01-19 06:46:23 +01:00
|
|
|
_blink_interval = DEFAULT;
|
|
|
|
|
2008-07-26 08:49:18 +02:00
|
|
|
type( FL_TOGGLE_BUTTON );
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
2012-04-14 23:11:58 +02:00
|
|
|
~Fl_Blink_Button ()
|
2008-07-26 08:49:18 +02:00
|
|
|
{
|
2012-03-14 02:44:26 +01:00
|
|
|
if ( value() )
|
|
|
|
Fl::remove_timeout( update_cb, this );
|
2008-07-26 08:49:18 +02:00
|
|
|
}
|
2012-04-14 23:11:58 +02:00
|
|
|
|
2012-12-10 07:06:39 +01:00
|
|
|
void ignore_input ( bool b )
|
|
|
|
{
|
|
|
|
_ignore_input = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ignore_input ( void ) const
|
|
|
|
{
|
|
|
|
return _ignore_input;
|
|
|
|
}
|
|
|
|
|
2012-04-14 23:11:58 +02:00
|
|
|
void blink ( bool b )
|
|
|
|
{
|
|
|
|
_blinking = b;
|
|
|
|
if ( ! b )
|
|
|
|
_on = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool blink ( void ) const
|
|
|
|
{
|
|
|
|
return _blinking;
|
|
|
|
}
|
2008-07-26 08:49:18 +02:00
|
|
|
|
2010-01-19 06:46:23 +01:00
|
|
|
void
|
2012-04-14 23:11:58 +02:00
|
|
|
blink_interval ( float v )
|
2010-01-19 06:46:23 +01:00
|
|
|
{
|
2012-11-06 08:50:28 +01:00
|
|
|
_blink_interval = v * 1000;
|
2012-03-14 02:44:26 +01:00
|
|
|
if ( value() )
|
|
|
|
{
|
|
|
|
Fl::remove_timeout( update_cb, this );
|
2012-11-16 10:01:53 +01:00
|
|
|
Fl::add_timeout( blink_interval_as_fraction_of_seceond(), update_cb, this );
|
2012-03-14 02:44:26 +01:00
|
|
|
}
|
2010-01-19 06:46:23 +01:00
|
|
|
}
|
|
|
|
|
2012-03-14 02:44:26 +01:00
|
|
|
virtual void value ( float v )
|
|
|
|
{
|
2013-03-13 01:56:43 +01:00
|
|
|
bool b = v;
|
|
|
|
|
|
|
|
if ( b != value() )
|
2012-03-14 02:44:26 +01:00
|
|
|
{
|
2013-03-13 01:56:43 +01:00
|
|
|
if ( b )
|
2012-12-10 07:06:39 +01:00
|
|
|
{
|
|
|
|
if ( _blinking )
|
2013-03-13 01:56:43 +01:00
|
|
|
{
|
|
|
|
/* just to be safe.. */
|
|
|
|
Fl::remove_timeout( update_cb, this );
|
2012-12-10 07:06:39 +01:00
|
|
|
Fl::add_timeout( blink_interval_as_fraction_of_seceond(), update_cb, this );
|
2013-03-13 01:56:43 +01:00
|
|
|
}
|
|
|
|
Fl_Button::value( b );
|
2012-12-10 07:06:39 +01:00
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-13 01:56:43 +01:00
|
|
|
Fl_Button::value( b );
|
2012-12-10 07:06:39 +01:00
|
|
|
Fl::remove_timeout( update_cb, this );
|
|
|
|
redraw();
|
|
|
|
}
|
2012-03-14 02:44:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 01:56:43 +01:00
|
|
|
virtual float value ( void ) { return (bool)Fl_Button::value(); }
|
2012-03-14 02:44:26 +01:00
|
|
|
|
2008-07-26 08:49:18 +02:00
|
|
|
virtual void
|
|
|
|
draw ( void )
|
|
|
|
{
|
2012-12-10 07:06:39 +01:00
|
|
|
draw_box( value() ? box() : down_box(), x(), y(), w(), h(),
|
|
|
|
( value() != 0 && _on ) ? selection_color() : color() );
|
2008-07-26 08:49:18 +02:00
|
|
|
draw_label();
|
|
|
|
}
|
2012-12-10 07:06:39 +01:00
|
|
|
|
|
|
|
virtual int handle ( int m )
|
|
|
|
{
|
|
|
|
if ( _ignore_input )
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return Fl_Button::handle( m );
|
|
|
|
}
|
2008-07-26 08:49:18 +02:00
|
|
|
};
|