// generated by Fast Light User Interface Designer (fluid) version 1.0100 #include "Fl_Knob.H" #include #include Fl_Knob::Fl_Knob(int xx,int yy,int ww,int hh,const char *l): Fl_Valuator(xx,yy,ww,hh,l) { int side; a1 = 35; a2 = 325; _type = DOTLIN; _percent = 0.3; _scaleticks = 10; _capr = _capg = _capb = -1; side = ww > hh ? hh:ww; _capsize = 100*(float)(side - 10) / (float)side; } Fl_Knob::~Fl_Knob() { } void Fl_Knob::draw() { int ox,oy,ww,hh,side; int capradius; int capoffset; float sa,ca,a_r; unsigned char rr,gg,bb; 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 = ww > hh ? hh:ww; int dam = damage(); capradius = (int)((side-11) * (_capsize / 100.0)); capoffset = (side - capradius)/2; if (dam & FL_DAMAGE_ALL) { int col = ((Fl_Widget *)parent())->color(); // Clear rectangle with parent color fl_color(col); fl_rectf(ox,oy,side,side); // Cast round shadow Fl::get_color((Fl_Color)col,rr,gg,bb); shadow(-60,rr,gg,bb); fl_pie(ox+9,oy+9,side-12,side-12,0,360); // Draw ticks draw_scale(ox,oy,side); col = color(); Fl::get_color((Fl_Color)col,rr,gg,bb); // Draw hilights of the button crown shadow(7,rr,gg,bb); fl_pie(ox+6,oy+6,side-12,side-12,40,50); fl_pie(ox+6,oy+6,side-12,side-12,260,270); shadow(15,rr,gg,bb); fl_pie(ox+6,oy+6,side-12,side-12,50,70); fl_pie(ox+6,oy+6,side-12,side-12,230,260); shadow(25,rr,gg,bb); fl_pie(ox+6,oy+6,side-12,side-12,70,80); fl_pie(ox+6,oy+6,side-12,side-12,220,230); shadow(30,rr,gg,bb); fl_pie(ox+6,oy+6,side-12,side-12,80,220); shadow(-9,rr,gg,bb); fl_pie(ox+6,oy+6,side-12,side-12,30,40); fl_pie(ox+6,oy+6,side-12,side-12,270,280); shadow(-18,rr,gg,bb); fl_pie(ox+6,oy+6,side-12,side-12,280,400); shadow(-28,rr,gg,bb); fl_pie(ox+6,oy+6,side-12,side-12,290,390); fl_color(FL_BLACK); fl_arc(ox+6,oy+6,side-11,side-11,0,360); } Fl::get_color((Fl_Color)color(),rr,gg,bb); // Draw button cap if (_capr != -1) { rr = _capr; gg = _capg; bb = _capb;} else Fl::get_color((Fl_Color)color(),rr,gg,bb); fl_color(rr,gg,bb); int xx = ox + capoffset; int yy = oy + capoffset; int dx = capradius; fl_pie(xx,yy,dx,dx,0,360); // Draw hilights of button cap shadow(10,rr,gg,bb); fl_pie(xx,yy,dx,dx,110,150); fl_pie(xx,yy,dx,dx,290,330); shadow(17,rr,gg,bb); fl_pie(xx,yy,dx,dx,120,140); fl_pie(xx,yy,dx,dx,300,320); shadow(30,rr,gg,bb); fl_pie(xx,yy,dx,dx,127,133); fl_pie(xx,yy,dx,dx,307,313); shadow(-7,rr,gg,bb); fl_pie(xx,yy,dx,dx,50,90); fl_pie(xx,yy,dx,dx,230,290); shadow(-15,rr,gg,bb); fl_pie(xx,yy,dx,dx,65,75); fl_pie(xx,yy,dx,dx,242,278); // Draw the button cursor draw_cursor(ox+side/2,oy+side/2,dx/2); fl_pop_clip(); } int Fl_Knob::handle(int event) { int ox,oy,ww,hh; ox = x() + 10; oy = y() + 10; ww = w() - 20; hh = h()-20; switch (event) { case FL_PUSH: handle_push(); case FL_DRAG: { int mx = Fl::event_x()-ox-ww/2; int my = Fl::event_y()-oy-hh/2; if (!mx && !my) return 1; double angle = 270-atan2((float)-my, (float)mx)*180/M_PI; double oldangle = (a2-a1)*(value()-minimum())/(maximum()-minimum()) + a1; while (angle < oldangle-180) angle += 360; while (angle > oldangle+180) angle -= 360; double val; if ((a1= a1)) { val = minimum(); } else if ((a1= a2) : (angle <= a2)) { val = maximum(); } else { val = minimum() + (maximum()-minimum())*(angle-a1)/(a2-a1); } handle_drag(clamp(round(val))); } return 1; case FL_RELEASE: handle_release(); return 1; default: return 0; } return 0; } void Fl_Knob::shadow(const int offs,const uchar r,uchar g,uchar b) { int rr,gg,bb; rr = r + offs; rr = rr > 255 ? 255:rr; rr = rr < 0 ? 0:rr; gg = g + offs; gg = gg > 255 ? 255:gg; gg = gg < 0 ? 0:gg; bb = b + offs; bb = bb > 255 ? 255:bb; bb = bb < 0 ? 0:bb; fl_color((uchar)rr,(uchar)gg,(uchar)bb); } void Fl_Knob::draw_scale(const int ox,const int oy,const int side) { float x1,y1,x2,y2,rds,cx,cy,ca,sa; float minv,maxv,curv; rds = side / 2; cx = ox + side / 2; cy = oy + side / 2; if (!(_type & DOTLOG_3)) { 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_BLACK); fl_line((int)x1,(int)y1,(int)x2,(int)y2); fl_color(FL_WHITE); if (sa*ca >=0) fl_line((int)x1+1,(int)y1+1,(int)x2+1,(int)y2+1); else fl_line((int)x1+1,(int)y1-1,(int)x2+1,(int)y2-1); } } else { int nb_dec = (_type & DOTLOG_3); for (int k = 0; k < nb_dec; k++) { double a_step = (10.0*3.14159/6.0) / nb_dec; double a_orig = -(3.14159/3.0) + k * a_step; for (int a = (k) ? 2:1; a <= 10; ) { double na = a_orig + log10((double)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_BLACK); fl_line((int)x1,(int)y1,(int)x2,(int)y2); fl_color(FL_WHITE); if (sa*ca <0) fl_line((int)x1+1,(int)y1+1,(int)x2+1,(int)y2+1); else fl_line((int)x1+1,(int)y1-1,(int)x2+1,(int)y2-1); if ((a == 1) || (nb_dec == 1)) a += 1; else a += 2; } } } } void Fl_Knob::draw_cursor(const int ox,const int oy,const int side) { float rds,cur,cx,cy; double angle; // rds = (side-40) * _capsize / 100.0; rds=side; cur = _percent * rds / 2; // cx = ox + side / 2; // cy = oy + side / 2; cx = ox;cy = oy; angle = (a2-a1)*(value()-minimum())/(maximum()-minimum()) + a1; fl_push_matrix(); fl_scale(1,1); fl_translate(cx,cy); fl_rotate(-angle); fl_translate(0,rds-cur-2.0); if (_type 1.0) _percent = 1.0; if (visible()) damage(FL_DAMAGE_CHILD); } void Fl_Knob::scaleticks(const int tck) { _scaleticks = tck; if (_scaleticks < 0) _scaleticks = 0; if (_scaleticks > 31) _scaleticks = 31; if (visible()) damage(FL_DAMAGE_ALL); } void Fl_Knob::capsize(const float percent) { if (percent > 100) return; if (percent < 40) return; _capsize = percent; } void Fl_Knob::capcolor(const Fl_Color col) { uchar rr,gg,bb; Fl::get_color(col,rr,gg,bb); _capr = rr; _capg = gg; _capb = bb; } void Fl_Knob::capcolor(const uchar cr,const uchar cg,const uchar cb) { _capr = cr; _capg = cg; _capb = cb; }