Browse Source

Add Pixmap capability to Fl_Dial.

tags/v1.3.1000
Jonathan Moore Liles 13 years ago
parent
commit
fc9a9aa987
2 changed files with 77 additions and 2 deletions
  1. +24
    -2
      FL/Fl_Dial.H
  2. +53
    -0
      src/Fl_Dial.cxx

+ 24
- 2
FL/Fl_Dial.H View File

@@ -22,13 +22,20 @@
#pragma once #pragma once


#include <FL/Fl_Dial_Base.H> #include <FL/Fl_Dial_Base.H>
#include <FL/Fl_Image.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Window.H>


class Fl_Dial : public Fl_Dial_Base class Fl_Dial : public Fl_Dial_Base
{ {
static int _default_style; static int _default_style;
static Fl_Image *_default_image;


int _scaleticks; int _scaleticks;


Fl_Image *_pixmap;
int _last_pixmap_index;

void draw_knob ( void ); void draw_knob ( void );
void draw_scale ( int ox, int oy, int side ); void draw_scale ( int ox, int oy, int side );
void draw_cursor ( int ox, int oy, int sidei ); void draw_cursor ( int ox, int oy, int sidei );
@@ -58,15 +65,27 @@ public:
{ {
Fl_Dial_Base::type( n ); 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_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 enum
{ {
DEFAULT, DEFAULT,
BURNISHED_DIAL, BURNISHED_DIAL,
ARC_DIAL, ARC_DIAL,
PLASTIC_DIAL
PLASTIC_DIAL,
PIXMAP_DIAL
}; };




@@ -75,6 +94,9 @@ public:
{ {
_scaleticks = 12; _scaleticks = 12;
_pixmap = 0;
_last_pixmap_index = -1;

box( FL_NO_BOX ); box( FL_NO_BOX );
type( DEFAULT ); type( DEFAULT );
} }


+ 53
- 0
src/Fl_Dial.cxx View File

@@ -26,7 +26,10 @@
#include <math.h> #include <math.h>
#include <algorithm> #include <algorithm>


#include <FL/Fl_Shared_Image.H>

int Fl_Dial::_default_style = Fl_Dial::PLASTIC_DIAL; 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 /** This simple box is suitable for use with knob-type widgets. It
* comprises a border with shadow, and a cap with glare-lines akin * 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(); 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 ) if ( type() == ARC_DIAL )
{ {
/* fl_line_style( FL_SOLID, 0 ); */ /* fl_line_style( FL_SOLID, 0 ); */


Loading…
Cancel
Save