summaryrefslogtreecommitdiff
path: root/src/Fl_Roller.cxx
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>1998-10-06 18:21:25 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>1998-10-06 18:21:25 +0000
commitf9039b2ae21988783feae9b362818e7923e82d14 (patch)
tree6d6fe3679d73448758f9794e7d4d4f6b22a4adad /src/Fl_Roller.cxx
parent67e89232f9ba067825a158734a09e0fa21aacbe3 (diff)
Initial revision
git-svn-id: file:///fltk/svn/fltk/trunk@2 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Roller.cxx')
-rw-r--r--src/Fl_Roller.cxx111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/Fl_Roller.cxx b/src/Fl_Roller.cxx
new file mode 100644
index 000000000..5e175385f
--- /dev/null
+++ b/src/Fl_Roller.cxx
@@ -0,0 +1,111 @@
+// Fl_Roller.C
+
+// Rapid-App style knob
+
+#include <FL/Fl.H>
+#include <FL/Fl_Roller.H>
+#include <FL/fl_draw.H>
+#include <math.h>
+
+int Fl_Roller::handle(int event) {
+ static int ipos;
+ int newpos = horizontal() ? Fl::event_x() : Fl::event_y();
+ switch (event) {
+ case FL_PUSH:
+ handle_push();
+ ipos = newpos;
+ return 1;
+ case FL_DRAG:
+ handle_drag(clamp(round(increment(previous_value(),newpos-ipos))));
+ return 1;
+ case FL_RELEASE:
+ handle_release();
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+void Fl_Roller::draw() {
+ if (damage()&128) draw_box();
+ int X = x()+Fl::box_dx(box());
+ int Y = y()+Fl::box_dy(box());
+ int W = w()-Fl::box_dw(box())-1;
+ int H = h()-Fl::box_dh(box())-1;
+ int offset = step() ? int(value()/step()) : 0;
+ const double ARC = 1.5; // 1/2 the number of radians visible
+ const double delta = .2; // radians per knurl
+ if (horizontal()) { // horizontal one
+ // draw shaded ends of wheel:
+ int h1 = W/4+1; // distance from end that shading starts
+ fl_color(color()); fl_rectf(X+h1,Y,W-2*h1,H);
+ for (int i=0; h1; i++) {
+ fl_color((Fl_Color)(FL_GRAY-i-1));
+ int h2 = FL_GRAY-i-1 > FL_DARK3 ? 2*h1/3+1 : 0;
+ fl_rectf(X+h2,Y,h1-h2,H);
+ fl_rectf(X+W-h1,Y,h1-h2,H);
+ h1 = h2;
+ }
+ // draw ridges:
+ double junk;
+ for (double y = -ARC+modf(offset*sin(ARC)/(W/2)/delta,&junk)*delta;;
+ y += delta) {
+ int y1 = int((sin(y)/sin(ARC)+1)*W/2);
+ if (y1 <= 0) continue; else if (y1 >= W-1) break;
+ fl_color(FL_DARK3); fl_yxline(X+y1,Y+1,Y+H-1);
+ if (y < 0) y1--; else y1++;
+ fl_color(FL_LIGHT1);fl_yxline(X+y1,Y+1,Y+H-1);
+ }
+ // draw edges:
+ h1 = W/8+1; // distance from end the color inverts
+ fl_color(FL_DARK2);
+ fl_xyline(X+h1,Y+H-1,X+W-h1);
+ fl_color(FL_DARK3);
+ fl_yxline(X,Y+H,Y,X+h1);
+ fl_xyline(X+W-h1,Y,X+W);
+ fl_color(FL_LIGHT2);
+ fl_xyline(X+h1,Y-1,X+W-h1);
+ fl_yxline(X+W,Y,Y+H,X+W-h1);
+ fl_xyline(X+h1,Y+H,X);
+ } else { // vertical one
+ // draw shaded ends of wheel:
+ int h1 = H/4+1; // distance from end that shading starts
+ fl_color(color()); fl_rectf(X,Y+h1,W,H-2*h1);
+ for (int i=0; h1; i++) {
+ fl_color((Fl_Color)(FL_GRAY-i-1));
+ int h2 = FL_GRAY-i-1 > FL_DARK3 ? 2*h1/3+1 : 0;
+ fl_rectf(X,Y+h2,W,h1-h2);
+ fl_rectf(X,Y+H-h1,W,h1-h2);
+ h1 = h2;
+ }
+ // draw ridges:
+ double junk;
+ for (double y = -ARC+modf(offset*sin(ARC)/(H/2)/delta,&junk)*delta;
+ ; y += delta) {
+ int y1 = int((sin(y)/sin(ARC)+1)*H/2);
+ if (y1 <= 0) continue; else if (y1 >= H-1) break;
+ fl_color(FL_DARK3); fl_xyline(X+1,Y+y1,X+W-1);
+ if (y < 0) y1--; else y1++;
+ fl_color(FL_LIGHT1);fl_xyline(X+1,Y+y1,X+W-1);
+ }
+ // draw edges:
+ h1 = H/8+1; // distance from end the color inverts
+ fl_color(FL_DARK2);
+ fl_yxline(X+W-1,Y+h1,Y+H-h1);
+ fl_color(FL_DARK3);
+ fl_xyline(X+W,Y,X,Y+h1);
+ fl_yxline(X,Y+H-h1,Y+H);
+ fl_color(FL_LIGHT2);
+ fl_yxline(X,Y+h1,Y+H-h1);
+ fl_xyline(X,Y+H,X+W,Y+H-h1);
+ fl_yxline(X+W,Y+h1,Y);
+ }
+}
+
+Fl_Roller::Fl_Roller(int X,int Y,int W,int H,const char* L)
+ : Fl_Valuator(X,Y,W,H,L) {
+ box(FL_UP_FRAME);
+ step(1,1000);
+}
+
+// end of Fl_Roller.C