From fc9a9aa987248bbbafcd3304600d52a6bd8e3072 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sun, 29 Apr 2012 17:48:43 -0700 Subject: [PATCH] Add Pixmap capability to Fl_Dial. --- FL/Fl_Dial.H | 26 ++++++++++++++++++++++-- src/Fl_Dial.cxx | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/FL/Fl_Dial.H b/FL/Fl_Dial.H index ce4c179..8d93c92 100644 --- a/FL/Fl_Dial.H +++ b/FL/Fl_Dial.H @@ -22,13 +22,20 @@ #pragma once #include +#include +#include +#include class Fl_Dial : public Fl_Dial_Base { static int _default_style; + static Fl_Image *_default_image; int _scaleticks; + Fl_Image *_pixmap; + int _last_pixmap_index; + void draw_knob ( void ); void draw_scale ( int ox, int oy, int side ); void draw_cursor ( int ox, int oy, int sidei ); @@ -58,15 +65,27 @@ public: { Fl_Dial_Base::type( n ); } - + + virtual void value_damage ( void ) + { + if ( window() ) + window()->damage( FL_DAMAGE_ALL, x(), y(), w(), h() ); + } + static void default_style ( int n ) { Fl_Dial::_default_style = n; } + static void default_image ( Fl_Image *i ) { Fl_Dial::_default_image = i; } + + void pixmap ( Fl_Image *i ) { _pixmap = i; } + + Fl_Image* pixmap ( void ) { return _pixmap; } enum { DEFAULT, BURNISHED_DIAL, ARC_DIAL, - PLASTIC_DIAL + PLASTIC_DIAL, + PIXMAP_DIAL }; @@ -75,6 +94,9 @@ public: { _scaleticks = 12; + _pixmap = 0; + _last_pixmap_index = -1; + box( FL_NO_BOX ); type( DEFAULT ); } diff --git a/src/Fl_Dial.cxx b/src/Fl_Dial.cxx index dc5e384..56cff62 100644 --- a/src/Fl_Dial.cxx +++ b/src/Fl_Dial.cxx @@ -26,7 +26,10 @@ #include #include +#include + int Fl_Dial::_default_style = Fl_Dial::PLASTIC_DIAL; +Fl_Image *Fl_Dial::_default_image = 0; /** This simple box is suitable for use with knob-type widgets. It * comprises a border with shadow, and a cap with glare-lines akin @@ -137,6 +140,56 @@ Fl_Dial::draw ( void ) double angle = ( angle2() - angle1() ) * ( value() - minimum()) / ( maximum() - minimum() ) + angle1(); + if ( type() == PIXMAP_DIAL ) + { + Fl_Image *im = pixmap(); + + if ( !im ) + im = Fl_Dial::_default_image; + + if ( im ) + { + + fl_push_clip( x(), y(), w(), h() ); + + const int knob_width = im->h(); + const int frames = im->w() / im->h(); + + const int index = knob_width * (int)( ( frames - 1 ) * ( value() - minimum()) / ( maximum() - minimum() )); + + /* if ( ( damage() == FL_DAMAGE_ALL ) || */ + /* ( ( damage() & FL_DAMAGE_EXPOSE ) && */ + /* index != _last_pixmap_index ) ) */ + { + + /* FIXME: Why doesn't this work? */ + /* if ( ! active_r() ) */ + /* { */ + /* im->inactive(); */ + /* } */ + + im->draw( x() + ( w() / 2 ) - ( knob_width / 2 ), + y() + ( h() / 2 ) - ( knob_width / 2 ), + knob_width, + knob_width, + index, + 0 ); + + + _last_pixmap_index = index; + } + + fl_pop_clip(); + } + else + { + /* missing image... */ + } + + return; + + } + if ( type() == ARC_DIAL ) { /* fl_line_style( FL_SOLID, 0 ); */