aboutsummaryrefslogtreecommitdiff
path: root/src/lib/FL/WidgetPDial.fl
blob: 5b7ec052bcdf57eed2e7a097f5af9defeead19fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# 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 or later} {} 

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;} {}
}