1 | // |
---|
2 | // "$Id$" |
---|
3 | // |
---|
4 | // Fl_Scroll test program for the Fast Light Tool Kit (FLTK). |
---|
5 | // |
---|
6 | // Copyright 1998-2005 by Bill Spitzak and others. |
---|
7 | // |
---|
8 | // This library is free software; you can redistribute it and/or |
---|
9 | // modify it under the terms of the GNU Library General Public |
---|
10 | // License as published by the Free Software Foundation; either |
---|
11 | // version 2 of the License, or (at your option) any later version. |
---|
12 | // |
---|
13 | // This library is distributed in the hope that it will be useful, |
---|
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | // Library General Public License for more details. |
---|
17 | // |
---|
18 | // You should have received a copy of the GNU Library General Public |
---|
19 | // License along with this library; if not, write to the Free Software |
---|
20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
21 | // USA. |
---|
22 | // |
---|
23 | // Please report all bugs and problems on the following page: |
---|
24 | // |
---|
25 | // http://www.fltk.org/str.php |
---|
26 | // |
---|
27 | |
---|
28 | #include <FL/Fl.H> |
---|
29 | #include <FL/Fl_Double_Window.H> |
---|
30 | #include <FL/Fl_Scroll.H> |
---|
31 | #include <FL/Fl_Light_Button.H> |
---|
32 | #include <FL/Fl_Choice.H> |
---|
33 | #include <FL/Fl_Box.H> |
---|
34 | #include <string.h> |
---|
35 | #include <stdio.h> |
---|
36 | #include <FL/fl_draw.H> |
---|
37 | #include <FL/math.h> |
---|
38 | |
---|
39 | class Drawing : public Fl_Widget { |
---|
40 | void draw(); |
---|
41 | public: |
---|
42 | Drawing(int X,int Y,int W,int H,const char* L) : Fl_Widget(X,Y,W,H,L) { |
---|
43 | align(FL_ALIGN_TOP); |
---|
44 | box(FL_FLAT_BOX); |
---|
45 | color(FL_WHITE); |
---|
46 | } |
---|
47 | }; |
---|
48 | |
---|
49 | void Drawing::draw() { |
---|
50 | draw_box(); |
---|
51 | fl_push_matrix(); |
---|
52 | fl_translate(x()+w()/2, y()+h()/2); |
---|
53 | fl_scale(w()/2, h()/2); |
---|
54 | fl_color(FL_BLACK); |
---|
55 | for (int i = 0; i < 20; i++) { |
---|
56 | for (int j = i+1; j < 20; j++) { |
---|
57 | fl_begin_line(); |
---|
58 | fl_vertex(cos(M_PI*i/10+.1), sin(M_PI*i/10+.1)); |
---|
59 | fl_vertex(cos(M_PI*j/10+.1), sin(M_PI*j/10+.1)); |
---|
60 | fl_end_line(); |
---|
61 | } |
---|
62 | } |
---|
63 | fl_pop_matrix(); |
---|
64 | } |
---|
65 | |
---|
66 | Fl_Scroll* thescroll; |
---|
67 | |
---|
68 | void box_cb(Fl_Widget* o, void*) { |
---|
69 | thescroll->box(((Fl_Button*)o)->value() ? FL_DOWN_FRAME : FL_NO_BOX); |
---|
70 | thescroll->redraw(); |
---|
71 | } |
---|
72 | |
---|
73 | void type_cb(Fl_Widget*, void* v) { |
---|
74 | thescroll->type((uchar)((long)v)); |
---|
75 | thescroll->redraw(); |
---|
76 | } |
---|
77 | |
---|
78 | Fl_Menu_Item choices[] = { |
---|
79 | {"0", 0, type_cb, (void*)0}, |
---|
80 | {"HORIZONTAL", 0, type_cb, (void*)Fl_Scroll::HORIZONTAL}, |
---|
81 | {"VERTICAL", 0, type_cb, (void*)Fl_Scroll::VERTICAL}, |
---|
82 | {"BOTH", 0, type_cb, (void*)Fl_Scroll::BOTH}, |
---|
83 | {"HORIZONTAL_ALWAYS", 0, type_cb, (void*)Fl_Scroll::HORIZONTAL_ALWAYS}, |
---|
84 | {"VERTICAL_ALWAYS", 0, type_cb, (void*)Fl_Scroll::VERTICAL_ALWAYS}, |
---|
85 | {"BOTH_ALWAYS", 0, type_cb, (void*)Fl_Scroll::BOTH_ALWAYS}, |
---|
86 | {0} |
---|
87 | }; |
---|
88 | |
---|
89 | void align_cb(Fl_Widget*, void* v) { |
---|
90 | thescroll->scrollbar.align((uchar)((long)v)); |
---|
91 | thescroll->redraw(); |
---|
92 | } |
---|
93 | |
---|
94 | Fl_Menu_Item align_choices[] = { |
---|
95 | {"left+top", 0, align_cb, (void*)(FL_ALIGN_LEFT+FL_ALIGN_TOP)}, |
---|
96 | {"left+bottom", 0, align_cb, (void*)(FL_ALIGN_LEFT+FL_ALIGN_BOTTOM)}, |
---|
97 | {"right+top", 0, align_cb, (void*)(FL_ALIGN_RIGHT+FL_ALIGN_TOP)}, |
---|
98 | {"right+bottom", 0, align_cb, (void*)(FL_ALIGN_RIGHT+FL_ALIGN_BOTTOM)}, |
---|
99 | {0} |
---|
100 | }; |
---|
101 | |
---|
102 | int main(int argc, char** argv) { |
---|
103 | Fl_Window window(5*75,400); |
---|
104 | window.box(FL_NO_BOX); |
---|
105 | Fl_Scroll scroll(0,0,5*75,300); |
---|
106 | |
---|
107 | int n = 0; |
---|
108 | for (int y=0; y<16; y++) for (int x=0; x<5; x++) { |
---|
109 | char buf[20]; sprintf(buf,"%d",n++); |
---|
110 | Fl_Button* b = new Fl_Button(x*75,y*25+(y>=8?5*75:0),75,25); |
---|
111 | b->copy_label(buf); |
---|
112 | b->color(n); |
---|
113 | b->labelcolor(FL_WHITE); |
---|
114 | } |
---|
115 | Drawing drawing(0,8*25,5*75,5*75,0); |
---|
116 | scroll.end(); |
---|
117 | window.resizable(scroll); |
---|
118 | |
---|
119 | Fl_Box box(0,300,5*75,window.h()-300); // gray area below the scroll |
---|
120 | box.box(FL_FLAT_BOX); |
---|
121 | |
---|
122 | Fl_Light_Button but1(150, 310, 200, 25, "box"); |
---|
123 | but1.callback(box_cb); |
---|
124 | |
---|
125 | Fl_Choice choice(150, 335, 200, 25, "type():"); |
---|
126 | choice.menu(choices); |
---|
127 | choice.value(3); |
---|
128 | |
---|
129 | Fl_Choice achoice(150, 360, 200, 25, "scrollbar.align():"); |
---|
130 | achoice.menu(align_choices); |
---|
131 | achoice.value(3); |
---|
132 | |
---|
133 | thescroll = &scroll; |
---|
134 | |
---|
135 | //scroll.box(FL_DOWN_BOX); |
---|
136 | //scroll.type(Fl_Scroll::VERTICAL); |
---|
137 | window.end(); |
---|
138 | window.show(argc,argv); |
---|
139 | return Fl::run(); |
---|
140 | } |
---|
141 | |
---|
142 | // |
---|
143 | // End of "$Id$". |
---|
144 | // |
---|