Mixer: Improve knob and slider appearance.

pull/116/head
Jonathan Moore Liles 2013-05-28 22:11:07 -07:00
parent 6adba68975
commit 550fb651c7
10 changed files with 417 additions and 127 deletions

111
FL/Fl_DialX.C Normal file
View File

@ -0,0 +1,111 @@
/*******************************************************************************/
/* Copyright (C) 2013 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. */
/*******************************************************************************/
#include "Fl_DialX.H"
#include <FL/Fl.H>
#include <FL/fl_draw.H>
void
Fl_DialX::draw ( void )
{
int X,Y,S;
{
int ox, oy, ww, hh, side;
ox = x();
oy = y();
ww = w();
hh = h();
if (ww > hh)
{
side = hh;
ox = ox + (ww - side) / 2;
}
else
{
side = ww;
oy = oy + (hh - side) / 2;
}
side = w() > h() ? hh : ww;
X = ox;
Y = oy;
S = side;
}
draw_box();
draw_label();
double angle = ( angle2() - angle1() ) * ( value() - minimum()) / ( maximum() - minimum() ) + angle1();
fl_draw_box( box(), X, Y, S, S, color() );
/* shrink a bit */
int OX = x();
int OY = y();
X += S / 8;
Y += S / 8;
int OS = S;
S -= S / 4;
fl_line_style( FL_SOLID, S / 12 );
/* background arc */
fl_color( fl_darker( color() ) );
fl_arc( X, Y, S, S, 270 - angle1(), 270 - angle2() );
/* foreground arc */
fl_color( selection_color() );
fl_arc( X, Y, S, S, 270 - angle1(), 270 - angle );
fl_line_style( FL_SOLID, 0 );
if ( active_r() )
{
int W = OS;
int H = OS;
fl_push_matrix();
fl_translate(OX+W/2, OY+H/2);
fl_scale(W, H);
fl_rotate(310+angle);
fl_color( fl_color_add_alpha( FL_WHITE, 127 ));
fl_begin_polygon(); fl_circle(-0.26, 0.26, 0.12); fl_end_polygon();
fl_color( FL_WHITE );
fl_begin_polygon(); fl_circle(-0.26, 0.26, 0.06); fl_end_polygon();
fl_pop_matrix();
}
fl_color( fl_contrast( labelcolor(), color() ) );
if ( Fl::belowmouse() == this )
{
char s[10];
fl_font( FL_HELVETICA, 10 );
snprintf( s, sizeof( s ), "%.1f", value() );
fl_color( FL_FOREGROUND_COLOR );
fl_draw( s, X, Y, S, S, FL_ALIGN_CENTER );
}
}

36
FL/Fl_DialX.H Normal file
View File

@ -0,0 +1,36 @@
/*******************************************************************************/
/* Copyright (C) 2013 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_Dial.H>
class Fl_DialX : public Fl_Dial
{
public:
Fl_DialX ( int X, int Y, int W, int H, const char *L=0 ) : Fl_Dial(X,Y,W,H,L)
{
}
virtual void draw ( void );
virtual ~Fl_DialX() { }
};

120
FL/Fl_SliderX.C Normal file
View File

@ -0,0 +1,120 @@
/*******************************************************************************/
/* Copyright (C) 2013 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. */
/*******************************************************************************/
#include "Fl_SliderX.H"
#include <FL/Fl.H>
#include <FL/fl_draw.H>
void
Fl_SliderX::draw ( int X, int Y, int W, int H)
{
if (damage()&FL_DAMAGE_ALL) draw_box();
double val;
if (minimum() == maximum())
val = 0.5;
else {
val = (value()-minimum())/(maximum()-minimum());
if (val > 1.0) val = 1.0;
else if (val < 0.0) val = 0.0;
}
int ww = (horizontal() ? W : H);
int hh = (horizontal() ? H : W);
int xx, S;
/* S = int(val*ww+.5); */
/* if (minimum()>maximum()) {S = ww-S; xx = ww-S;} */
/* else xx = 0; */
{
//S = //int(ww+.5);
S = hh;
int T = (horizontal() ? H : W)/2+1;
// if (type()==FL_VERT_NICE_SLIDER || type()==FL_HOR_NICE_SLIDER) T += 4;
if (S < T) S = T;
xx = int(val*(ww-S)+.5);
}
int xsl, ysl, wsl, hsl;
if (horizontal()) {
xsl = X+xx;
wsl = S;
ysl = Y + hh/2;
hsl = hh/4;
} else {
ysl = Y+xx;
hsl = S;
xsl = X + hh/2;
wsl = hh/4;
}
{
fl_push_clip(X, Y, W, H);
draw_box();
fl_pop_clip();
Fl_Color black = active_r() ? FL_BLACK : FL_INACTIVE_COLOR;
}
//draw_bg(X, Y, W, H);
fl_line_style( FL_SOLID, hh/6 );
fl_color( fl_darker(color()) );
if ( horizontal() )
fl_line ( X + S/2, Y + hh/2, X + W - S/2, Y + hh/2 );
else
fl_line ( X + hh/2, Y + S/2, X + hh/2, Y + H - S/2 );
fl_color( selection_color() );
if ( horizontal() )
fl_line ( X + S/2, ysl, xsl + S/2, ysl );
else
fl_line ( X + S/2, Y + H - S/2, xsl, ysl + (S/2) );
fl_line_style( FL_SOLID, 0 );
fl_push_matrix();
if ( horizontal() )
fl_translate( xsl + (hh/2), ysl);
else
fl_translate( xsl, ysl + (hh/2) );
fl_color( fl_color_add_alpha( FL_WHITE, 127 ));
fl_begin_polygon(); fl_circle(0.0,0.0, hh/3); fl_end_polygon();
fl_color( FL_WHITE );
fl_begin_polygon(); fl_circle(0.0,0.0, hh/6); fl_end_polygon();
fl_pop_matrix();
draw_label(xsl, ysl, wsl, hsl);
if (Fl::focus() == this) {
draw_focus();
}
/* draw(x()+Fl::box_dx(box()), */
/* y()+Fl::box_dy(box()), */
/* w()-Fl::box_dw(box()), */
/* h()-Fl::box_dh(box())); */
}

37
FL/Fl_SliderX.H Normal file
View File

@ -0,0 +1,37 @@
/*******************************************************************************/
/* Copyright (C) 2013 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_Slider.H>
class Fl_SliderX : public Fl_Slider
{
public:
Fl_SliderX( int X, int Y, int W, int H, const char *L=0 ) : Fl_Slider(X,Y,W,H,L)
{
}
virtual ~Fl_SliderX ( ) { };
virtual void draw ( int X, int Y, int W, int H );
virtual void draw ( void ) { draw(x(),y(),w(),h()); }
};

View File

@ -20,38 +20,58 @@
#include "Fl_Value_SliderX.H"
int Fl_Value_SliderX::_default_style = NICE_SLIDER;
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <math.h>
void
Fl_Value_SliderX::draw ( void )
{
switch ( _default_style )
{
case NICE_SLIDER:
{
if ( FL_HORIZONTAL == _type )
Fl_Value_Slider::type( FL_HOR_NICE_SLIDER );
else
Fl_Value_Slider::type( FL_VERT_NICE_SLIDER );
break;
}
case FILL_SLIDER:
{
if ( FL_HORIZONTAL == _type )
Fl_Value_Slider::type( FL_HOR_FILL_SLIDER );
else
Fl_Value_Slider::type( FL_VERT_FILL_SLIDER );
break;
}
case SIMPLE_SLIDER:
{
if ( FL_HORIZONTAL == _type )
Fl_Value_Slider::type( FL_HOR_SLIDER );
else
Fl_Value_Slider::type( FL_VERT_SLIDER );
break;
}
}
Fl_Value_Slider::draw();
/**
Creates a new Fl_Value_SliderX widget using the given
position, size, and label string. The default boxtype is FL_DOWN_BOX.
*/
Fl_Value_SliderX::Fl_Value_SliderX(int X, int Y, int W, int H, const char*l)
: Fl_SliderX(X,Y,W,H,l) {
step(1,100);
textfont_ = FL_HELVETICA;
textsize_ = 10;
textcolor_ = FL_FOREGROUND_COLOR;
}
void Fl_Value_SliderX::draw() {
int sxx = x(), syy = y(), sww = w(), shh = h();
int bxx = x(), byy = y(), bww = w(), bhh = h();
if (horizontal()) {
bww = 35; sxx += 35; sww -= 35;
} else {
syy += 25; bhh = 25; shh -= 25;
}
if (damage()&FL_DAMAGE_ALL) draw_box(box(),sxx,syy,sww,shh,color());
Fl_SliderX::draw(sxx+Fl::box_dx(box()),
syy+Fl::box_dy(box()),
sww-Fl::box_dw(box()),
shh-Fl::box_dh(box()));
draw_box(box(),bxx,byy,bww,bhh,color());
char buf[128];
format(buf);
fl_font(textfont(), textsize());
fl_color(active_r() ? textcolor() : fl_inactive(textcolor()));
fl_draw(buf, bxx, byy, bww, bhh, FL_ALIGN_CLIP);
}
int Fl_Value_SliderX::handle(int event) {
if (event == FL_PUSH && Fl::visible_focus()) {
Fl::focus(this);
redraw();
}
int sxx = x(), syy = y(), sww = w(), shh = h();
if (horizontal()) {
sxx += 35; sww -= 35;
} else {
syy += 25; shh -= 25;
}
return Fl_SliderX::handle(event,
sxx+Fl::box_dx(box()),
syy+Fl::box_dy(box()),
sww-Fl::box_dw(box()),
shh-Fl::box_dh(box()));
}

View File

@ -17,41 +17,39 @@
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*******************************************************************************/
/* just like an Fl_Value_Slider, except that it responds to mousewheel events */
#ifndef Fl_Value_SliderX_H
#define Fl_Value_SliderX_H
#pragma once
#include <FL/Fl_Value_Slider.H>
#include <FL/Fl.H>
#include <math.h>
class Fl_Value_SliderX : public Fl_Value_Slider
{
static int _default_style;
int _type;
#include "Fl_SliderX.H"
/**
The Fl_Value_SliderX widget is a Fl_SliderX widget
with a box displaying the current value.
<P ALIGN=CENTER>\image html value_slider.png
\image latex value_slider.png "Fl_Value_SliderX" width=4cm
*/
class FL_EXPORT Fl_Value_SliderX : public Fl_SliderX {
Fl_Font textfont_;
Fl_Fontsize textsize_;
Fl_Color textcolor_;
protected:
void draw();
public:
enum
{
NICE_SLIDER,
SIMPLE_SLIDER,
FILL_SLIDER
};
static void default_style ( int n ) { Fl_Value_SliderX::_default_style = n; }
int type ( void ) const { return _type; }
void type ( int v ) { _type = v; }
Fl_Value_SliderX ( int X, int Y, int W, int H, const char *L = 0 )
: Fl_Value_Slider( X, Y, W, H, L )
{
}
virtual ~Fl_Value_SliderX() { }
virtual void draw ( void );
int handle(int);
Fl_Value_SliderX(int x,int y,int w,int h, const char *l = 0);
/** Gets the typeface of the text in the value box. */
Fl_Font textfont() const {return textfont_;}
/** Sets the typeface of the text in the value box. */
void textfont(Fl_Font s) {textfont_ = s;}
/** Gets the size of the text in the value box. */
Fl_Fontsize textsize() const {return textsize_;}
/** Sets the size of the text in the value box. */
void textsize(Fl_Fontsize s) {textsize_ = s;}
/** Gets the color of the text in the value box. */
Fl_Color textcolor() const {return textcolor_;}
/** Sets the color of the text in the value box. */
void textcolor(Fl_Color s) {textcolor_ = s;}
};
#endif

View File

@ -15,6 +15,8 @@ Fl_Menu_Settings.C
Fl_Scalepack.C
Fl_Text_Edit_Window.fl
Fl_Value_SliderX.C
Fl_DialX.C
Fl_SliderX.C
New_Project_Dialog.fl
event_name.C
menu_popup.C

View File

@ -31,7 +31,7 @@
#include <FL/Fl_Menu_.H>
#include <FL/Fl_Light_Button.H>
#include <FL/fl_draw.H>
#include "FL/Fl_Dial.H"
#include "FL/Fl_DialX.H"
#include "FL/Fl_Labelpad_Group.H"
#include "FL/Fl_Value_SliderX.H"
#include "Panner.H"
@ -362,8 +362,8 @@ Controller_Module::connect_to ( Port *p )
w = o;
o->type(4);
o->color(FL_DARK1);
o->selection_color(FL_RED);
o->color( FL_DARK1 );
o->selection_color( fl_color_average( FL_GRAY, FL_CYAN, 0.5 ) );
o->minimum(1.5);
o->maximum(0);
o->value(1);
@ -381,7 +381,7 @@ Controller_Module::connect_to ( Port *p )
}
else
{
{ Fl_Dial *o = new Fl_Dial( 0, 0, 50, 50, p->name() );
{ Fl_DialX *o = new Fl_DialX( 0, 0, 50, 50, p->name() );
w = o;
control = o;

View File

@ -289,36 +289,6 @@ void Mixer::cb_menu(Fl_Widget* o) {
{
fl_theme_chooser();
}
else if (! strcmp( picked, "&Options/&Display/&Knobs/&Burnished") )
{
Fl_Dial::default_style( Fl_Dial::BURNISHED_DIAL );
redraw_windows();
}
else if (! strcmp( picked, "&Options/&Display/&Knobs/&Arc") )
{
Fl_Dial::default_style( Fl_Dial::ARC_DIAL );
redraw_windows();
}
else if (! strcmp( picked, "&Options/&Display/&Knobs/&Plastic") )
{
Fl_Dial::default_style( Fl_Dial::PLASTIC_DIAL );
redraw_windows();
}
else if (! strcmp( picked, "&Options/&Display/&Sliders/&Nice") )
{
Fl_Value_SliderX::default_style( Fl_Value_SliderX::NICE_SLIDER );
redraw_windows();
}
else if (! strcmp( picked, "&Options/&Display/&Sliders/&Fill") )
{
Fl_Value_SliderX::default_style( Fl_Value_SliderX::FILL_SLIDER );
redraw_windows();
}
else if (! strcmp( picked, "&Options/&Display/&Sliders/&Simple") )
{
Fl_Value_SliderX::default_style( Fl_Value_SliderX::SIMPLE_SLIDER );
redraw_windows();
}
else if ( ! strcmp( picked, "&Help/&About" ) )
{
About_Dialog ab( PIXMAP_PATH "/non-mixer/icon-256x256.png" );
@ -444,13 +414,6 @@ Mixer::Mixer ( int X, int Y, int W, int H, const char *L ) :
o->add( "&Mixer/Add &N Strips" );
o->add( "&Mixer/&Import Strip" );
o->add( "&View/&Theme", 0, 0, 0 );
o->add( "_&Options/&Display/&Knobs/&Arc", 0, 0, 0, FL_MENU_RADIO );
o->add( "_&Options/&Display/&Knobs/&Burnished", 0, 0, 0, FL_MENU_RADIO );
o->add( "_&Options/&Display/&Knobs/&Plastic", 0, 0, 0, FL_MENU_RADIO | FL_MENU_VALUE );
o->add( "_&Options/&Display/&Sliders/&Nice", 0, 0, 0, FL_MENU_RADIO | FL_MENU_VALUE );
o->add( "_&Options/&Display/&Sliders/&Fill", 0, 0, 0, FL_MENU_RADIO );
o->add( "_&Options/&Display/&Sliders/&Simple", 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/&About" );
o->callback( cb_menu, this );
@ -760,19 +723,19 @@ Mixer::load_options ( void )
{
// save options
char *path;
asprintf( &path, "%s/options", user_config_dir );
((Fl_Menu_Settings*)menubar)->load( menubar->find_item( "&Options" ), path );
free( path );
/* char *path; */
/* asprintf( &path, "%s/options", user_config_dir ); */
/* ((Fl_Menu_Settings*)menubar)->load( menubar->find_item( "&Options" ), path ); */
/* free( path ); */
}
void
Mixer::save_options ( void )
{
char *path;
asprintf( &path, "%s/%s", user_config_dir, options_filename );
((Fl_Menu_Settings*)menubar)->dump( menubar->find_item( "&Options" ), path );
free( path );
/* char *path; */
/* asprintf( &path, "%s/%s", user_config_dir, options_filename ); */
/* ((Fl_Menu_Settings*)menubar)->dump( menubar->find_item( "&Options" ), path ); */
/* free( path ); */
}
void

View File

@ -32,7 +32,7 @@
#include "FL/Fl_Flowpack.H"
#include "FL/Fl_Labelpad_Group.H"
#include "FL/Fl_Value_SliderX.H"
#include "FL/Fl_Dial.H"
#include "FL/Fl_DialX.H"
#include "Module.H"
#include "Module_Parameter_Editor.H"
@ -145,6 +145,9 @@ Module_Parameter_Editor::make_controls ( void )
elevation_port_number = -1;
float elevation_value = 0.0f;
Fl_Color fc = fl_color_add_alpha( FL_CYAN, 200 );
Fl_Color bc = FL_BACKGROUND2_COLOR;
controls_by_port.resize( module->control_input.size() );
for ( unsigned int i = 0; i < module->control_input.size(); ++i )
@ -177,7 +180,7 @@ Module_Parameter_Editor::make_controls ( void )
{
Fl_Button *o = new Fl_Button( 0, 0, 30, 30, p->name() );
w = o;
o->selection_color( FL_GREEN );
o->selection_color( fc );
o->type( FL_TOGGLE_BUTTON );
o->value( p->control_value() );
}
@ -203,7 +206,7 @@ Module_Parameter_Editor::make_controls ( void )
{
if ( mode_choice->value() == 0 )
{
Fl_Dial *o = new Fl_Dial( 0, 0, 60, 60, p->name() );
Fl_DialX *o = new Fl_DialX( 0, 0, 60, 60, p->name() );
w = o;
if ( p->hints.ranged )
@ -213,9 +216,8 @@ Module_Parameter_Editor::make_controls ( void )
o->minimum( p->hints.minimum );
o->maximum( p->hints.maximum );
}
o->color( FL_GRAY );
o->selection_color( FL_WHITE );
o->color( bc );
o->selection_color( fc );
o->value( p->control_value() );
// o->step( fabs( ( o->maximum() - o->minimum() ) ) / 32.0f );
@ -229,7 +231,7 @@ Module_Parameter_Editor::make_controls ( void )
{
o->type( FL_HORIZONTAL );
o->size( 120, 36 );
o->size( 120, 24 );
if ( p->hints.ranged )
{
o->minimum( p->hints.minimum );
@ -240,17 +242,18 @@ Module_Parameter_Editor::make_controls ( void )
{
o->type( FL_VERTICAL );
o->size( 36, 120 );
o->size( 24, 120 );
/* have to reverse the meaning of these to get the
* orientation of the slider right */
o->maximum( p->hints.minimum );
o->minimum( p->hints.maximum );
}
o->textsize( 8 );
o->box( FL_NO_BOX );
o->slider( FL_UP_BOX );
// o->color( FL_BACKGROUND2_COLOR );
o->color( FL_BACKGROUND2_COLOR );
o->selection_color( FL_WHITE );
o->color( bc );
o->selection_color( fc );
o->value( p->control_value() );
}