Use cairo to draw everything.
[ntk.git] / test / line_style.cxx
blob02f5471c1f00f53e2817e57fcd484374e55d2b5f
1 //
2 // "$Id: line_style.cxx 7982 2010-12-08 23:58:32Z AlbrechtS $"
3 //
4 // Line style demo for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 2000-2010 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.
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.
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.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 #include <FL/Fl.H>
29 #include <FL/Fl_Double_Window.H>
30 #include <FL/Fl_Value_Slider.H>
31 #include <FL/fl_draw.H>
32 #include <FL/Fl_Choice.H>
33 #include <FL/Fl_Check_Button.H>
34 #include <FL/Fl_Box.H>
36 Fl_Double_Window *form;
37 Fl_Slider *sliders[9];
38 Fl_Choice *choice[3];
39 Fl_Check_Button *draw_line;
41 class test_box: public Fl_Double_Window {
42 void draw();
43 public:
44 test_box(int x,int y,int w,int h,const char *l=0)
45 : Fl_Double_Window(x,y,w,h,l) {}
46 }*test;
48 void test_box::draw() {
49 Fl_Double_Window::draw();
50 fl_color((uchar)(sliders[0]->value()),
51 (uchar)(sliders[1]->value()),
52 (uchar)(sliders[2]->value()));
53 // dashes
54 char dashes[5];
55 dashes[0] = char(sliders[5]->value());
56 dashes[1] = char(sliders[6]->value());
57 dashes[2] = char(sliders[7]->value());
58 dashes[3] = char(sliders[8]->value());
59 dashes[4] = 0;
60 fl_line_style(
61 choice[0]->mvalue()->argument() +
62 choice[1]->mvalue()->argument() +
63 choice[2]->mvalue()->argument(),
64 long(sliders[3]->value()), // width
65 dashes);
67 // draw the defined fl_rect and fl_vertex first and then
68 // the additional one-pixel line, if enabled
69 // sliders[4] = x/y coordinate translation (default = 10)
71 for (int i=0; i<draw_line->value()+1; i++) {
72 int move = (int)sliders[4]->value();
73 fl_rect(move,move,w()-20,h()-20);
74 fl_begin_line();
75 fl_vertex(move+25, move+25);
76 fl_vertex(w()-45+move, h()-45+move);
77 fl_vertex(w()-50+move, move+25);
78 fl_vertex(move+25, h()/2-10+move);
79 fl_end_line();
80 // you must reset the line type when done:
81 fl_line_style(FL_SOLID);
82 fl_color(FL_BLACK);
86 Fl_Menu_Item style_menu[] = {
87 {"FL_SOLID", 0, 0, (void*)FL_SOLID},
88 {"FL_DASH", 0, 0, (void*)FL_DASH},
89 {"FL_DOT", 0, 0, (void*)FL_DOT},
90 {"FL_DASHDOT",0, 0, (void*)FL_DASHDOT},
91 {"FL_DASHDOTDOT", 0, 0, (void*)FL_DASHDOTDOT},
92 {0}
95 Fl_Menu_Item cap_menu[] = {
96 {"default", 0, 0, 0},
97 {"FL_CAP_FLAT", 0, 0, (void*)FL_CAP_FLAT},
98 {"FL_CAP_ROUND", 0, 0, (void*)FL_CAP_ROUND},
99 {"FL_CAP_SQUARE", 0, 0, (void*)FL_CAP_SQUARE},
103 Fl_Menu_Item join_menu[] = {
104 {"default", 0, 0, 0},
105 {"FL_JOIN_MITER", 0, 0, (void*)FL_JOIN_MITER},
106 {"FL_JOIN_ROUND", 0, 0, (void*)FL_JOIN_ROUND},
107 {"FL_JOIN_BEVEL", 0, 0, (void*)FL_JOIN_BEVEL},
111 void do_redraw(Fl_Widget*,void*)
113 test->redraw();
116 void makeform(const char *) {
117 form = new Fl_Double_Window(500,250,"fl_line_style() test");
118 sliders[0]= new Fl_Value_Slider(280,10,180,20,"R");
119 sliders[0]->bounds(0,255);
120 sliders[1]= new Fl_Value_Slider(280,30,180,20,"G");
121 sliders[1]->bounds(0,255);
122 sliders[2]= new Fl_Value_Slider(280,50,180,20,"B");
123 sliders[2]->bounds(0,255);
124 choice[0]= new Fl_Choice(280,70,180,20,"Style");
125 choice[0]->menu(style_menu);
126 choice[1]= new Fl_Choice(280,90,180,20,"Cap");
127 choice[1]->menu(cap_menu);
128 choice[2]= new Fl_Choice(280,110,180,20,"Join");
129 choice[2]->menu(join_menu);
130 sliders[3]= new Fl_Value_Slider(280,130,180,20,"Width");
131 sliders[3]->bounds(0,20);
132 sliders[4]= new Fl_Value_Slider(280,150,180,20,"Move");
133 sliders[4]->bounds(-10,20);
134 draw_line = new Fl_Check_Button(280,170,20,20,"&Line");
135 draw_line->align(FL_ALIGN_LEFT);
136 new Fl_Box (305,170,160,20,"add a 1-pixel black line");
137 sliders[5] = new Fl_Slider(200,210,70,20,"Dash");
138 sliders[5]->align(FL_ALIGN_TOP_LEFT);
139 sliders[5]->bounds(0,40);
140 sliders[6] = new Fl_Slider(270,210,70,20);
141 sliders[6]->bounds(0,40);
142 sliders[7] = new Fl_Slider(340,210,70,20);
143 sliders[7]->bounds(0,40);
144 sliders[8] = new Fl_Slider(410,210,70,20);
145 sliders[8]->bounds(0,40);
146 int i;
147 for (i=0;i<9;i++) {
148 sliders[i]->type(1);
149 if (i<5) sliders[i]->align(FL_ALIGN_LEFT);
150 sliders[i]->callback((Fl_Callback*)do_redraw);
151 sliders[i]->step(1);
153 sliders[0]->value(255); // R
154 sliders[1]->value(100); // G
155 sliders[2]->value(100); // B
156 sliders[4]->value(10); // move line coordinates
157 draw_line->value(0);
158 draw_line->callback((Fl_Callback*)do_redraw);
159 for (i=0;i<3;i++) {
160 choice[i]->value(0);
161 choice[i]->callback((Fl_Callback*)do_redraw);
163 test = new test_box(0,0,200,200);
164 test->end();
165 form->resizable(test);
166 form->end();
169 int main(int argc, char **argv) {
170 makeform(argv[0]);
171 form->show(argc,argv);
172 return Fl::run();
176 // End of "$Id: line_style.cxx 7982 2010-12-08 23:58:32Z AlbrechtS $".