# data file for the Fltk User Interface Designer (fluid)
version 1.0105 
header_name {.h} 
code_name {.cc}
decl {//Copyright (c) 2003-2005 Nasca Octavian Paul} {} 

decl {//License: GNU GPL version 2} {} 

decl {\#include <FL/Fl_Dial.H>} {public
} 

decl {\#include <FL/fl_draw.H>} {public
} 

decl {\#include <stdio.h>} {public
} 

decl {\#include <math.h>} {public
} 

class WidgetPDial {: {public Fl_Dial}
} {
  Function {WidgetPDial(int x,int y, int w, int h, const char *label=0):Fl_Dial(x,y,w,h,label)} {} {
    code {oldvalue=0.0;} {}
  }
  Function {handle(int event)} {return_type int
  } {
    code {double dragsize,v,min=minimum(),max=maximum();
int my;

switch (event){
case FL_PUSH:oldvalue=value();
case FL_DRAG:
     my=-(Fl::event_y()-y()-h()/2);

     dragsize=200.0;
     if (Fl::event_state(FL_BUTTON1)==0) dragsize*=10;
     v=oldvalue+my/dragsize*(max-min);
     if (v<min) v=min;
        else if (v>max) v=max;

     //printf("%d   %g    %g\\n",my,v,oldvalue);     
     value(v);
     value_damage();
     if (this->when()!=0) do_callback();
     return(1); 
     break;
case FL_RELEASE:
     if (this->when()==0) do_callback();
	return(1);
     break;
};
return(0);} {selected
    }
  }
  Function {drawgradient(int cx,int cy,int sx,double m1,double m2)} {return_type void
  } {
    code {for (int i=(int)(m1*sx);i<(int)(m2*sx);i++){
   double tmp=1.0-pow(i*1.0/sx,2.0);
   pdialcolor(140+(int) (tmp*90),140+(int)(tmp*90),140+(int) (tmp*100));
   fl_arc(cx+sx/2-i/2,cy+sx/2-i/2,i,i,0,360);
};} {}
  }
  Function {draw()} {} {
    code {int cx=x(),cy=y(),sx=w(),sy=h();


//clears the button face
pdialcolor(190,190,200);
fl_pie(cx-1,cy-1,sx+2,sy+2,0,360);

//Draws the button face (gradinet)
drawgradient(cx,cy,sx,0.5,1.0);

double val=(value()-minimum())/(maximum()-minimum());

//draws the scale
pdialcolor(220,220,250);
double a1=angle1(),a2=angle2();
for (int i=0;i<12;i++){
   double a=-i/12.0*360.0-val*(a2-a1)-a1;
   fl_pie(cx,cy,sx,sy,a+270-3,a+3+270);
};

drawgradient(cx,cy,sx,0.0,0.75);

//draws the value
double a=-(a2-a1)*val-a1;





//draws the max and min points
pdialcolor(0,100,200);
int xp=(int)(cx+sx/2.0+sx/2.0*sin(angle1()/180.0*3.141592));
int yp=(int)(cy+sy/2.0+sy/2.0*cos(angle1()/180.0*3.141592));
fl_pie(xp-2,yp-2,4,4,0,360);

xp=(int)(cx+sx/2.0+sx/2.0*sin(angle2()/180.0*3.141592));
yp=(int)(cy+sy/2.0+sy/2.0*cos(angle2()/180.0*3.141592));
fl_pie(xp-2,yp-2,4,4,0,360);





fl_push_matrix();

  fl_translate(cx+sx/2,cy+sy/2);
  fl_rotate(a-90.0); 

  fl_translate(sx/2,0);


  fl_begin_polygon();
   pdialcolor(0,0,0);
   fl_vertex(-10,-4);
   fl_vertex(-10,4);
   fl_vertex(0,0);  
  fl_end_polygon();
 

fl_pop_matrix();} {}
  }
  Function {pdialcolor(int r,int g,int b)} {} {
    code {if (active_r()) fl_color(r,g,b);
   else fl_color(160-(160-r)/3,160-(160-b)/3,160-(160-b)/3);} {}
  }
  decl {double oldvalue;} {}
}