1 //
2 // "$Id$"
3 //
4 // Fl_Scroll test program for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file.  If this
10 // file is missing or damaged, see the license at:
11 //
12 //     http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 //     http://www.fltk.org/str.php
17 //
18 
19 #include <FL/Fl.H>
20 #include <FL/Fl_Double_Window.H>
21 #include <FL/Fl_Scroll.H>
22 #include <FL/Fl_Light_Button.H>
23 #include <FL/Fl_Choice.H>
24 #include <FL/Fl_Box.H>
25 #include <string.h>
26 #include <stdio.h>
27 #include <FL/fl_draw.H>
28 #include <FL/math.h>
29 
30 class Drawing : public Fl_Widget {
31   void draw();
32 public:
Drawing(int X,int Y,int W,int H,const char * L)33   Drawing(int X,int Y,int W,int H,const char* L) : Fl_Widget(X,Y,W,H,L) {
34     align(FL_ALIGN_TOP);
35     box(FL_FLAT_BOX);
36     color(FL_WHITE);
37   }
38 };
39 
draw()40 void Drawing::draw() {
41   draw_box();
42   fl_push_matrix();
43   fl_translate(x()+w()/2, y()+h()/2);
44   fl_scale(w()/2, h()/2);
45   fl_color(FL_BLACK);
46   for (int i = 0; i < 20; i++) {
47     for (int j = i+1; j < 20; j++) {
48       fl_begin_line();
49       fl_vertex(cos(M_PI*i/10+.1), sin(M_PI*i/10+.1));
50       fl_vertex(cos(M_PI*j/10+.1), sin(M_PI*j/10+.1));
51       fl_end_line();
52     }
53   }
54   fl_pop_matrix();
55 }
56 
57 Fl_Scroll* thescroll;
58 
box_cb(Fl_Widget * o,void *)59 void box_cb(Fl_Widget* o, void*) {
60   thescroll->box(((Fl_Button*)o)->value() ? FL_DOWN_FRAME : FL_NO_BOX);
61   thescroll->redraw();
62 }
63 
type_cb(Fl_Widget *,void * v)64 void type_cb(Fl_Widget*, void* v) {
65   thescroll->type((uchar)((fl_intptr_t)v));
66   thescroll->redraw();
67 }
68 
69 Fl_Menu_Item choices[] = {
70   {"0", 0, type_cb, (void*)0},
71   {"HORIZONTAL", 0, type_cb, (void*)Fl_Scroll::HORIZONTAL},
72   {"VERTICAL", 0, type_cb, (void*)Fl_Scroll::VERTICAL},
73   {"BOTH", 0, type_cb, (void*)Fl_Scroll::BOTH},
74   {"HORIZONTAL_ALWAYS", 0, type_cb, (void*)Fl_Scroll::HORIZONTAL_ALWAYS},
75   {"VERTICAL_ALWAYS", 0, type_cb, (void*)Fl_Scroll::VERTICAL_ALWAYS},
76   {"BOTH_ALWAYS", 0, type_cb, (void*)Fl_Scroll::BOTH_ALWAYS},
77   {0}
78 };
79 
align_cb(Fl_Widget *,void * v)80 void align_cb(Fl_Widget*, void* v) {
81   thescroll->scrollbar.align((uchar)((fl_intptr_t)v));
82   thescroll->redraw();
83 }
84 
85 Fl_Menu_Item align_choices[] = {
86   {"left+top", 0, align_cb, (void*)(FL_ALIGN_LEFT+FL_ALIGN_TOP)},
87   {"left+bottom", 0, align_cb, (void*)(FL_ALIGN_LEFT+FL_ALIGN_BOTTOM)},
88   {"right+top", 0, align_cb, (void*)(FL_ALIGN_RIGHT+FL_ALIGN_TOP)},
89   {"right+bottom", 0, align_cb, (void*)(FL_ALIGN_RIGHT+FL_ALIGN_BOTTOM)},
90   {0}
91 };
92 
main(int argc,char ** argv)93 int main(int argc, char** argv) {
94   Fl_Window window(5*75,400);
95   window.box(FL_NO_BOX);
96   Fl_Scroll scroll(0,0,5*75,300);
97 
98   int n = 0;
99   for (int y=0; y<16; y++) for (int x=0; x<5; x++) {
100     char buf[20]; sprintf(buf,"%d",n++);
101     Fl_Button* b = new Fl_Button(x*75,y*25+(y>=8?5*75:0),75,25);
102     b->copy_label(buf);
103     b->color(n);
104     b->labelcolor(FL_WHITE);
105   }
106   Drawing drawing(0,8*25,5*75,5*75,0);
107   scroll.end();
108   window.resizable(scroll);
109 
110   Fl_Box box(0,300,5*75,window.h()-300); // gray area below the scroll
111   box.box(FL_FLAT_BOX);
112 
113   Fl_Light_Button but1(150, 310, 200, 25, "box");
114   but1.callback(box_cb);
115 
116   Fl_Choice choice(150, 335, 200, 25, "type():");
117   choice.menu(choices);
118   choice.value(3);
119 
120   Fl_Choice achoice(150, 360, 200, 25, "scrollbar.align():");
121   achoice.menu(align_choices);
122   achoice.value(3);
123 
124   thescroll = &scroll;
125 
126   //scroll.box(FL_DOWN_BOX);
127   //scroll.type(Fl_Scroll::VERTICAL);
128   window.end();
129   window.show(argc,argv);
130   return Fl::run();
131 }
132 
133 //
134 // End of "$Id$".
135 //
136