Browse Source

Mixer: Add new 'plastic' knob type. Make knob type to display configurable.

tags/non-daw-v1.1.0
Jonathan Moore Liles 13 years ago
parent
commit
26fa9eba3b
7 changed files with 270 additions and 85 deletions
  1. +0
    -43
      FL/Crystal_Boxtypes.C
  2. +0
    -2
      FL/Crystal_Boxtypes.H
  3. +189
    -19
      FL/Fl_Arc_Dial.C
  4. +40
    -4
      FL/Fl_Arc_Dial.H
  5. +2
    -3
      mixer/src/Controller_Module.C
  6. +25
    -0
      mixer/src/Mixer.C
  7. +14
    -14
      mixer/src/Module_Parameter_Editor.C

+ 0
- 43
FL/Crystal_Boxtypes.C View File

@@ -25,47 +25,6 @@
#include <FL/fl_draw.H> #include <FL/fl_draw.H>
#include <string.h> #include <string.h>



/** This simple box is suitable for use with knob-type widgets. It
* comprises a border with shadow, and a cap with glare-lines akin
* to those seen on burnished aluminum knobs. */
static void
burnished_oval_box ( int x, int y, int w, int h, Fl_Color c )
{
/* draw background */
fl_color( fl_darker( c ) );
fl_pie( x, y, w, h, 0, 360 );
fl_color( fl_darker( fl_darker( c ) ) );
fl_pie( x, y, w, h, 180 + 215, 180 + 45 );

/* shrink */
x += 4;
y += 4;
w -= 7;
h -= 7;

/* draw cap */
fl_color( c );
fl_pie( x, y, w, h, 0, 360 );

/* draw glare */

const int a1 = 10;
const int a2 = 90;

fl_color( fl_color_average( FL_WHITE, c, 0.15f ) );
fl_pie( x, y, w, h, a1, a2 );
fl_pie( x, y, w, h, 180 + a1, 180 + a2 );
fl_color( fl_color_average( FL_WHITE, c, 0.25f ) );

const int d = (a2 - a1) / 2;
fl_pie( x, y, w, h, a1 + (d / 2), a2 - (d / 2) );
fl_pie( x, y, w, h, 180 + a1 + (d / 2), 180 + a2 - (d / 2) );
}



/* Crystal boxes, base (obviously) on the FLTK1 'plastic' boxes, but /* Crystal boxes, base (obviously) on the FLTK1 'plastic' boxes, but
* without the rude color blending and with a slightly enhanced * without the rude color blending and with a slightly enhanced
* appearance. */ * appearance. */
@@ -414,8 +373,6 @@ down_round ( int x, int y, int w, int h, Fl_Color c )
void void
init_crystal_boxtypes ( void ) init_crystal_boxtypes ( void )
{ {
Fl::set_boxtype( FL_BURNISHED_OVAL_BOX, burnished_oval_box, 4, 4, 7, 7 );

/* replace the plastic boxes... (is there a better way?) */ /* replace the plastic boxes... (is there a better way?) */
Fl::set_boxtype( FL_PLASTIC_UP_BOX, up_box, 4,4,8,8 ); Fl::set_boxtype( FL_PLASTIC_UP_BOX, up_box, 4,4,8,8 );
Fl::set_boxtype( FL_PLASTIC_DOWN_BOX, down_box, 2,2,4,4 ); Fl::set_boxtype( FL_PLASTIC_DOWN_BOX, down_box, 2,2,4,4 );


+ 0
- 2
FL/Crystal_Boxtypes.H View File

@@ -19,6 +19,4 @@


#include <FL/Fl.H> #include <FL/Fl.H>


#define FL_BURNISHED_OVAL_BOX (Fl_Boxtype)(FL_FREE_BOXTYPE+0)

void init_crystal_boxtypes ( void ); void init_crystal_boxtypes ( void );

+ 189
- 19
FL/Fl_Arc_Dial.C View File

@@ -25,6 +25,56 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <algorithm>

int Fl_Arc_Dial::_default_knob_style = Fl_Arc_Dial::PLASTIC_DIAL;

/** This simple box is suitable for use with knob-type widgets. It
* comprises a border with shadow, and a cap with glare-lines akin
* to those seen on burnished aluminum knobs. */
static void
burnished_oval_box ( int x, int y, int w, int h, Fl_Color c )
{
/* draw background */
fl_color( fl_darker( c ) );
fl_pie( x, y, w, h, 0, 360 );
fl_color( fl_darker( fl_darker( c ) ) );
fl_pie( x, y, w, h, 180 + 215, 180 + 45 );

/* shrink */
x += 4;
y += 4;
w -= 7;
h -= 7;

/* draw cap */
fl_color( c );
fl_pie( x, y, w, h, 0, 360 );

/* draw glare */

const int a1 = 10;
const int a2 = 90;

fl_color( fl_color_average( FL_WHITE, c, 0.15f ) );
fl_pie( x, y, w, h, a1, a2 );
fl_pie( x, y, w, h, 180 + a1, 180 + a2 );
fl_color( fl_color_average( FL_WHITE, c, 0.25f ) );

const int d = (a2 - a1) / 2;
fl_pie( x, y, w, h, a1 + (d / 2), a2 - (d / 2) );
fl_pie( x, y, w, h, 180 + a1 + (d / 2), 180 + a2 - (d / 2) );
}



void
Fl_Arc_Dial::draw_box ( void )
{
if ( type() == ARC_DIAL )
fl_draw_box( FL_ROUNDED_BOX, x(), y(), w(), h(), color() );
}


int int
Fl_Arc_Dial::handle ( int m ) Fl_Arc_Dial::handle ( int m )
@@ -74,7 +124,6 @@ Fl_Arc_Dial::handle ( int m )
return Fl_Dial::handle( m ); return Fl_Dial::handle( m );
} }



void void
Fl_Arc_Dial::draw ( void ) Fl_Arc_Dial::draw ( void )
{ {
@@ -93,45 +142,166 @@ Fl_Arc_Dial::draw ( void )


double angle = ( angle2() - angle1() ) * ( value() - minimum()) / ( maximum() - minimum() ) + angle1(); double angle = ( angle2() - angle1() ) * ( value() - minimum()) / ( maximum() - minimum() ) + angle1();


fl_line_style( FL_SOLID, W / 6 );


X += W / 8; X += W / 8;
Y += H / 8; Y += H / 8;
W -= W / 4; W -= W / 4;
H -= H / 4; H -= H / 4;


if ( box() == FL_NO_BOX )
if ( type() == ARC_DIAL )
{ {
/* draw backgrond arc */
fl_color( fl_color_average( FL_BLACK, selection_color(), 0.80f ) );
fl_line_style( FL_SOLID, W / 6 );

/* background arc */
fl_color( fl_darker( color() ) );
fl_arc( X, Y, W, H, 270 - angle1(), 270 - angle2() ); fl_arc( X, Y, W, H, 270 - angle1(), 270 - angle2() );
}


fl_color( selection_color() );
// fl_color( fl_color_average( FL_RED, selection_color(), ( value() - minimum() ) / ( maximum() - minimum() ) ) );
/* foreground arc */
fl_color( selection_color() );
fl_arc( X, Y, W, H, 270 - angle1(), 270 - angle );


fl_line_style( FL_SOLID, 0 );


if ( type() == FL_FILL_DIAL )
fl_arc( X, Y, W, H, 270 - angle1(), 270 - angle );
else
fl_color( fl_contrast( labelcolor(), color() ) );
}
else if ( type() == PLASTIC_DIAL || type() == BURNISHED_DIAL )
{ {
// fl_color( fl_color_average( FL_RED, selection_color(), ( value() - minimum() ) / ( maximum() - minimum() ) ) );
draw_knob();
fl_line_style( FL_SOLID, W / 6 );
fl_color( fl_contrast( selection_color(), FL_BACKGROUND_COLOR ) );
const int d = 6; const int d = 6;

/* account for edge conditions */ /* account for edge conditions */
angle = angle < angle1() + d ? angle1() + d : angle; angle = angle < angle1() + d ? angle1() + d : angle;
angle = angle > angle2() - d ? angle2() - d : angle; angle = angle > angle2() - d ? angle2() - d : angle;
fl_arc( X + 5, Y + 5 , W - 10, H - 10, 270 - (angle - d), 270 - (angle + d) );

fl_line_style( FL_SOLID, 0 );


fl_arc( X, Y, W, H, 270 - (angle - d), 270 - (angle + d) );
} }


fl_line_style( FL_SOLID, 0 );
char s[10];
fl_font( FL_HELVETICA, 8 );
snprintf( s, sizeof( s ), "%.1f", value() );
if ( type() == ARC_DIAL )
fl_draw( s, X, Y, W, H, FL_ALIGN_BOTTOM );
else
if ( type() == PLASTIC_DIAL )
{
fl_draw( s, x(), y(), w(), H, FL_ALIGN_BOTTOM );
}


fl_color( labelcolor() );


char s[10];
}


fl_font( FL_HELVETICA, 8 );
void
Fl_Arc_Dial::draw_knob ( void )
{
int ox, oy, ww, hh, side;
ox = x();
oy = y();
ww = w();
hh = h();
draw_label();
fl_clip(ox, oy, ww, hh);
if (ww > hh)
{
side = hh;
ox = ox + (ww - side) / 2;
}
else
{
side = ww;
oy = oy + (hh - side) / 2;
}
side = w() > h() ? hh : ww;


snprintf( s, sizeof( s ), "%.1f", value() );
fl_draw( s, X, Y, W, H, FL_ALIGN_BOTTOM );
// background
/* fl_color(FL_BACKGROUND_COLOR); */
/* fl_rectf(ox, oy, side, side); */
/* scale color */
fl_color(fl_color_average(color(), FL_BACKGROUND2_COLOR, .6));


fl_pie(ox + 1, oy + 3, side - 2, side - 12, 0, 360);
// scale
draw_scale(ox, oy, side);

Fl_Color c = active_r() ? fl_color_average(FL_BACKGROUND_COLOR, FL_WHITE, .7) : FL_INACTIVE_COLOR;

if ( type() == BURNISHED_DIAL )
{
burnished_oval_box( ox + 5, oy + 5, side - 12, side - 12, c );
}
else
{
fl_color(FL_BACKGROUND_COLOR);
fl_pie(ox + 6, oy + 6, side - 12, side - 12, 0, 360);

// shadow

fl_color(fl_color_average(FL_BACKGROUND_COLOR, FL_BLACK, .8f));
fl_pie(ox + 8, oy + 12, side - 16, side - 16, 0, 360);
fl_color(fl_color_average(FL_BACKGROUND_COLOR, FL_BLACK, .2f));
fl_pie(ox + 9, oy + 12, side - 18, side - 18, 0, 360);

// knob edge
fl_color( c);


fl_pie(ox + 8, oy + 8, side - 16, side - 16, 0, 360);

fl_color(fl_color_average(FL_BACKGROUND_COLOR, FL_WHITE, .6));
fl_pie(ox + 10, oy + 10, side - 20, side - 20, 0, 360);
}
fl_pop_clip();
}


void
Fl_Arc_Dial::draw_scale ( int ox, int oy, int side )
{
float x1, y1, x2, y2, rds, cx, cy, ca, sa;
rds = side / 2;
cx = ox + side / 2;
cy = oy + side / 2;
if (_scaleticks == 0)
return;
double a_step = (10.0 * 3.14159 / 6.0) / _scaleticks;
double a_orig = -(3.14159 / 3.0);
for (int a = 0; a <= _scaleticks; a++)
{
double na = a_orig + a * a_step;
ca = cos(na);
sa = sin(na);
x1 = cx + (rds) * ca;
y1 = cy - (rds) * sa;
x2 = cx + (rds - 6) * ca;
y2 = cy - (rds - 6) * sa;
fl_color(FL_BACKGROUND_COLOR);
fl_line(x1, y1, x2, y2);
}
}

void
Fl_Arc_Dial::scaleticks ( int tck )
{
_scaleticks = tck;
if (_scaleticks < 0)
_scaleticks = 0;
if (_scaleticks > 31)
_scaleticks = 31;
if (visible())
damage(FL_DAMAGE_ALL);
} }

+ 40
- 4
FL/Fl_Arc_Dial.H View File

@@ -23,22 +23,58 @@


#include <FL/Fl_Dial.H> #include <FL/Fl_Dial.H>


#include <algorithm>

class Fl_Arc_Dial : public Fl_Dial class Fl_Arc_Dial : public Fl_Dial
{ {
static int _default_knob_style;

int _scaleticks;

void draw_knob ( void );
void draw_scale ( int ox, int oy, int side );
void draw_cursor ( int ox, int oy, int sidei );



protected: protected:


virtual int handle ( int ); virtual int handle ( int );
virtual void draw ( void ); virtual void draw ( void );

virtual void draw_box ( void );
public: public:


void scaleticks ( int tck );

int
type ( void ) const
{
if ( Fl_Dial::type() == DEFAULT )
return Fl_Arc_Dial::_default_knob_style;
else
return Fl_Dial::type();
}

void type ( int n )
{
Fl_Dial::type( n );
}
static void default_knob_style ( int n ) { Fl_Arc_Dial::_default_knob_style = n; }

enum
{
DEFAULT,
BURNISHED_DIAL,
ARC_DIAL,
PLASTIC_DIAL
};


Fl_Arc_Dial ( int X, int Y, int W, int H, const char *L = 0 ) : Fl_Arc_Dial ( int X, int Y, int W, int H, const char *L = 0 ) :
Fl_Dial( X, Y, W, H, L ) Fl_Dial( X, Y, W, H, L )
{ {
box( FL_OVAL_BOX );
_scaleticks = 12;
box( FL_NO_BOX );
} }


}; };

+ 2
- 3
mixer/src/Controller_Module.C View File

@@ -371,9 +371,8 @@ Controller_Module::connect_to ( Port *p )
o->minimum( p->hints.minimum ); o->minimum( p->hints.minimum );
o->maximum( p->hints.maximum ); o->maximum( p->hints.maximum );
} }

o->box( FL_BURNISHED_OVAL_BOX );
o->color( fl_darker( fl_darker( FL_GRAY ) ) );
o->color( fl_darker( FL_GRAY ) );
o->selection_color( FL_WHITE ); o->selection_color( FL_WHITE );
o->value( p->control_value() ); o->value( p->control_value() );
} }


+ 25
- 0
mixer/src/Mixer.C View File

@@ -282,6 +282,27 @@ void Mixer::cb_menu(Fl_Widget* o) {
{ {
color_scheme( "gray" ); color_scheme( "gray" );
} }
else if (! strcmp( picked, "&Options/&Display/&Knobs/&Burnished") )
{
Fl_Arc_Dial::default_knob_style( Fl_Arc_Dial::BURNISHED_DIAL );
if ( Fl::first_window() )
for ( Fl_Window *w = Fl::first_window(); ( w = Fl::next_window( w ) ); )
w->redraw();
}
else if (! strcmp( picked, "&Options/&Display/&Knobs/&Arc") )
{
Fl_Arc_Dial::default_knob_style( Fl_Arc_Dial::ARC_DIAL );
if ( Fl::first_window() )
for ( Fl_Window *w = Fl::first_window(); ( w = Fl::next_window( w ) ); )
w->redraw();
}
else if (! strcmp( picked, "&Options/&Display/&Knobs/&Plastic") )
{
Fl_Arc_Dial::default_knob_style( Fl_Arc_Dial::PLASTIC_DIAL );
if ( Fl::first_window() )
for ( Fl_Window *w = Fl::first_window(); ( w = Fl::next_window( w ) ); )
w->redraw();
}
else if ( ! strcmp( picked, "&Help/&About" ) ) else if ( ! strcmp( picked, "&Help/&About" ) )
{ {
About_Dialog ab( PIXMAP_PATH "/non-mixer/icon-256x256.png" ); About_Dialog ab( PIXMAP_PATH "/non-mixer/icon-256x256.png" );
@@ -350,6 +371,10 @@ Mixer::Mixer ( int X, int Y, int W, int H, const char *L ) :
o->add( "_&Options/&Display/&Colors/&Light", 0, 0, 0, FL_MENU_RADIO ); o->add( "_&Options/&Display/&Colors/&Light", 0, 0, 0, FL_MENU_RADIO );
o->add( "_&Options/&Display/&Colors/&Gray", 0, 0, 0, FL_MENU_RADIO ); o->add( "_&Options/&Display/&Colors/&Gray", 0, 0, 0, FL_MENU_RADIO );
o->add( "_&Options/&Display/&Colors/&System", 0, 0, 0, FL_MENU_RADIO ); o->add( "_&Options/&Display/&Colors/&System", 0, 0, 0, FL_MENU_RADIO );
o->add( "_&Options/&Display/&Knobs/&Arc", 0, 0, 0, FL_MENU_RADIO | FL_MENU_VALUE );
o->add( "_&Options/&Display/&Knobs/&Burnished", 0, 0, 0, FL_MENU_RADIO );
o->add( "_&Options/&Display/&Knobs/&Plastic", 0, 0, 0, FL_MENU_RADIO );
o->add( "_&Options/&Display/&Colors/&System", 0, 0, 0, FL_MENU_RADIO );
o->add( "&Help/&Manual" ); o->add( "&Help/&Manual" );
o->add( "&Help/&About" ); o->add( "&Help/&About" );
o->callback( cb_menu, this ); o->callback( cb_menu, this );


+ 14
- 14
mixer/src/Module_Parameter_Editor.C View File

@@ -27,7 +27,7 @@
#include <FL/Fl_Box.H> #include <FL/Fl_Box.H>
#include <FL/Fl_Menu_Button.H> #include <FL/Fl_Menu_Button.H>
#include <FL/Fl_Counter.H> #include <FL/Fl_Counter.H>
#include "FL/Boxtypes.H"
#include "FL/Crystal_Boxtypes.H"
#include "FL/Fl_Flowpack.H" #include "FL/Fl_Flowpack.H"
#include "FL/Fl_Labelpad_Group.H" #include "FL/Fl_Labelpad_Group.H"
#include "FL/Fl_Value_SliderX.H" #include "FL/Fl_Value_SliderX.H"
@@ -193,7 +193,7 @@ Module_Parameter_Editor::make_controls ( void )
{ {
if ( mode_choice->value() == 0 ) if ( mode_choice->value() == 0 )
{ {
Fl_Arc_Dial *o = new Fl_Arc_Dial( 0, 0, 50, 50, p->name() );
Fl_Arc_Dial *o = new Fl_Arc_Dial( 0, 0, 60, 60, p->name() );
w = o; w = o;


if ( p->hints.ranged ) if ( p->hints.ranged )
@@ -204,12 +204,9 @@ Module_Parameter_Editor::make_controls ( void )
o->maximum( p->hints.maximum ); o->maximum( p->hints.maximum );
} }


// o->box( FL_BURNISHED_OVAL_BOX );
o->box( FL_ROUNDED_BOX );
o->color( fl_darker( fl_darker( FL_GRAY ) ) );
o->color( FL_GRAY );
o->selection_color( FL_WHITE ); o->selection_color( FL_WHITE );
o->value( p->control_value() ); o->value( p->control_value() );
o->type( FL_FILL_DIAL );


// o->step( fabs( ( o->maximum() - o->minimum() ) ) / 32.0f ); // o->step( fabs( ( o->maximum() - o->minimum() ) ) / 32.0f );
} }
@@ -220,8 +217,10 @@ Module_Parameter_Editor::make_controls ( void )


if ( mode_choice->value() == 1 ) if ( mode_choice->value() == 1 )
{ {
o->type( FL_HORIZONTAL );
o->size( 120, 24 );
// o->type( FL_HORIZONTAL );
o->type( FL_HOR_NICE_SLIDER );

o->size( 120, 36 );
if ( p->hints.ranged ) if ( p->hints.ranged )
{ {
o->minimum( p->hints.minimum ); o->minimum( p->hints.minimum );
@@ -230,18 +229,19 @@ Module_Parameter_Editor::make_controls ( void )
} }
else else
{ {
o->type( FL_VERTICAL );
o->size( 32, 120 );
// o->type( FL_VERTICAL );
o->type(FL_VERT_NICE_SLIDER);

o->size( 36, 120 );
/* have to reverse the meaning of these to get the /* have to reverse the meaning of these to get the
* orientation of the slider right */ * orientation of the slider right */
o->maximum( p->hints.minimum ); o->maximum( p->hints.minimum );
o->minimum( p->hints.maximum ); o->minimum( p->hints.maximum );
} }


// o->step( fabs( ( o->maximum() - o->minimum() ) ) / 32.0f );
o->slider( FL_THIN_UP_BOX );
o->color( fl_darker( fl_darker( FL_GRAY ) ) );
o->selection_color( FL_WHITE );
o->slider( FL_UP_BOX );
o->color( FL_BACKGROUND2_COLOR );
o->selection_color( FL_GRAY );
o->value( p->control_value() ); o->value( p->control_value() );
} }




Loading…
Cancel
Save