2002-01-01 18:11:33 +03:00
|
|
|
//
|
|
|
|
// Line style demo for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2010-11-29 00:12:59 +03:00
|
|
|
// Copyright 2000-2010 by Bill Spitzak and others.
|
2002-01-01 18:11:33 +03:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
2002-01-01 18:11:33 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
2002-01-01 18:11:33 +03:00
|
|
|
//
|
|
|
|
|
2000-05-14 00:03:20 +04:00
|
|
|
#include <FL/Fl.H>
|
2009-04-21 13:09:37 +04:00
|
|
|
#include <FL/Fl_Double_Window.H>
|
2000-05-14 00:03:20 +04:00
|
|
|
#include <FL/Fl_Value_Slider.H>
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
#include <FL/Fl_Choice.H>
|
2008-12-21 16:48:14 +03:00
|
|
|
#include <FL/Fl_Check_Button.H>
|
|
|
|
#include <FL/Fl_Box.H>
|
2000-05-14 00:03:20 +04:00
|
|
|
|
2009-04-21 13:09:37 +04:00
|
|
|
Fl_Double_Window *form;
|
2010-11-23 18:00:06 +03:00
|
|
|
Fl_Slider *sliders[9];
|
2000-05-14 00:03:20 +04:00
|
|
|
Fl_Choice *choice[3];
|
2008-12-21 16:48:14 +03:00
|
|
|
Fl_Check_Button *draw_line;
|
2000-05-14 00:03:20 +04:00
|
|
|
|
2009-04-21 13:09:37 +04:00
|
|
|
class test_box: public Fl_Double_Window {
|
2022-12-30 21:14:36 +03:00
|
|
|
void draw() FL_OVERRIDE;
|
2000-05-14 00:03:20 +04:00
|
|
|
public:
|
|
|
|
test_box(int x,int y,int w,int h,const char *l=0)
|
2009-04-21 13:09:37 +04:00
|
|
|
: Fl_Double_Window(x,y,w,h,l) {}
|
2000-05-14 00:03:20 +04:00
|
|
|
}*test;
|
|
|
|
|
|
|
|
void test_box::draw() {
|
2009-04-21 13:09:37 +04:00
|
|
|
Fl_Double_Window::draw();
|
2000-05-14 00:03:20 +04:00
|
|
|
fl_color((uchar)(sliders[0]->value()),
|
2020-07-01 19:03:10 +03:00
|
|
|
(uchar)(sliders[1]->value()),
|
|
|
|
(uchar)(sliders[2]->value()));
|
2010-11-23 18:00:06 +03:00
|
|
|
// dashes
|
|
|
|
char dashes[5];
|
|
|
|
dashes[0] = char(sliders[5]->value());
|
|
|
|
dashes[1] = char(sliders[6]->value());
|
|
|
|
dashes[2] = char(sliders[7]->value());
|
|
|
|
dashes[3] = char(sliders[8]->value());
|
|
|
|
dashes[4] = 0;
|
2000-05-14 00:03:20 +04:00
|
|
|
fl_line_style(
|
2023-02-02 22:54:19 +03:00
|
|
|
(int)(choice[0]->mvalue()->argument() +
|
2010-12-09 02:58:32 +03:00
|
|
|
choice[1]->mvalue()->argument() +
|
2023-02-02 22:54:19 +03:00
|
|
|
choice[2]->mvalue()->argument()),
|
|
|
|
(int)(sliders[3]->value()), // width
|
2010-11-23 18:00:06 +03:00
|
|
|
dashes);
|
|
|
|
|
2008-12-21 16:48:14 +03:00
|
|
|
// draw the defined fl_rect and fl_vertex first and then
|
|
|
|
// the additional one-pixel line, if enabled
|
2010-11-23 18:00:06 +03:00
|
|
|
// sliders[4] = x/y coordinate translation (default = 10)
|
2008-12-21 16:48:14 +03:00
|
|
|
|
2008-12-21 17:05:36 +03:00
|
|
|
for (int i=0; i<draw_line->value()+1; i++) {
|
2010-11-23 18:00:06 +03:00
|
|
|
int move = (int)sliders[4]->value();
|
|
|
|
fl_rect(move,move,w()-20,h()-20);
|
2008-12-21 16:48:14 +03:00
|
|
|
fl_begin_line();
|
2010-11-23 18:00:06 +03:00
|
|
|
fl_vertex(move+25, move+25);
|
|
|
|
fl_vertex(w()-45+move, h()-45+move);
|
|
|
|
fl_vertex(w()-50+move, move+25);
|
|
|
|
fl_vertex(move+25, h()/2-10+move);
|
2008-12-21 16:48:14 +03:00
|
|
|
fl_end_line();
|
|
|
|
// you must reset the line type when done:
|
|
|
|
fl_line_style(FL_SOLID);
|
|
|
|
fl_color(FL_BLACK);
|
|
|
|
}
|
2000-05-14 00:03:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Fl_Menu_Item style_menu[] = {
|
2020-07-01 19:03:10 +03:00
|
|
|
{"FL_SOLID", 0, 0, (void*)FL_SOLID},
|
|
|
|
{"FL_DASH", 0, 0, (void*)FL_DASH},
|
|
|
|
{"FL_DOT", 0, 0, (void*)FL_DOT},
|
2000-05-14 00:03:20 +04:00
|
|
|
{"FL_DASHDOT",0, 0, (void*)FL_DASHDOT},
|
|
|
|
{"FL_DASHDOTDOT", 0, 0, (void*)FL_DASHDOTDOT},
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
Fl_Menu_Item cap_menu[] = {
|
2020-07-01 19:03:10 +03:00
|
|
|
{"default", 0, 0, 0},
|
|
|
|
{"FL_CAP_FLAT", 0, 0, (void*)FL_CAP_FLAT},
|
|
|
|
{"FL_CAP_ROUND", 0, 0, (void*)FL_CAP_ROUND},
|
|
|
|
{"FL_CAP_SQUARE", 0, 0, (void*)FL_CAP_SQUARE},
|
2000-05-14 00:03:20 +04:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
Fl_Menu_Item join_menu[] = {
|
2020-07-01 19:03:10 +03:00
|
|
|
{"default", 0, 0, 0},
|
|
|
|
{"FL_JOIN_MITER", 0, 0, (void*)FL_JOIN_MITER},
|
|
|
|
{"FL_JOIN_ROUND", 0, 0, (void*)FL_JOIN_ROUND},
|
|
|
|
{"FL_JOIN_BEVEL", 0, 0, (void*)FL_JOIN_BEVEL},
|
2000-05-14 00:03:20 +04:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
void do_redraw(Fl_Widget*,void*)
|
|
|
|
{
|
|
|
|
test->redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void makeform(const char *) {
|
2010-11-23 18:00:06 +03:00
|
|
|
form = new Fl_Double_Window(500,250,"fl_line_style() test");
|
2000-05-14 00:03:20 +04:00
|
|
|
sliders[0]= new Fl_Value_Slider(280,10,180,20,"R");
|
|
|
|
sliders[0]->bounds(0,255);
|
|
|
|
sliders[1]= new Fl_Value_Slider(280,30,180,20,"G");
|
|
|
|
sliders[1]->bounds(0,255);
|
|
|
|
sliders[2]= new Fl_Value_Slider(280,50,180,20,"B");
|
|
|
|
sliders[2]->bounds(0,255);
|
|
|
|
choice[0]= new Fl_Choice(280,70,180,20,"Style");
|
|
|
|
choice[0]->menu(style_menu);
|
|
|
|
choice[1]= new Fl_Choice(280,90,180,20,"Cap");
|
|
|
|
choice[1]->menu(cap_menu);
|
|
|
|
choice[2]= new Fl_Choice(280,110,180,20,"Join");
|
|
|
|
choice[2]->menu(join_menu);
|
|
|
|
sliders[3]= new Fl_Value_Slider(280,130,180,20,"Width");
|
|
|
|
sliders[3]->bounds(0,20);
|
2010-11-23 18:00:06 +03:00
|
|
|
sliders[4]= new Fl_Value_Slider(280,150,180,20,"Move");
|
|
|
|
sliders[4]->bounds(-10,20);
|
|
|
|
draw_line = new Fl_Check_Button(280,170,20,20,"&Line");
|
2008-12-21 16:48:14 +03:00
|
|
|
draw_line->align(FL_ALIGN_LEFT);
|
2010-11-23 18:00:06 +03:00
|
|
|
new Fl_Box (305,170,160,20,"add a 1-pixel black line");
|
|
|
|
sliders[5] = new Fl_Slider(200,210,70,20,"Dash");
|
|
|
|
sliders[5]->align(FL_ALIGN_TOP_LEFT);
|
2000-05-14 00:03:20 +04:00
|
|
|
sliders[5]->bounds(0,40);
|
2010-11-23 18:00:06 +03:00
|
|
|
sliders[6] = new Fl_Slider(270,210,70,20);
|
2000-05-14 00:03:20 +04:00
|
|
|
sliders[6]->bounds(0,40);
|
2010-11-23 18:00:06 +03:00
|
|
|
sliders[7] = new Fl_Slider(340,210,70,20);
|
2000-05-14 00:03:20 +04:00
|
|
|
sliders[7]->bounds(0,40);
|
2010-11-23 18:00:06 +03:00
|
|
|
sliders[8] = new Fl_Slider(410,210,70,20);
|
|
|
|
sliders[8]->bounds(0,40);
|
2000-05-14 00:03:20 +04:00
|
|
|
int i;
|
2010-11-23 18:00:06 +03:00
|
|
|
for (i=0;i<9;i++) {
|
2000-05-14 00:03:20 +04:00
|
|
|
sliders[i]->type(1);
|
2010-11-23 18:00:06 +03:00
|
|
|
if (i<5) sliders[i]->align(FL_ALIGN_LEFT);
|
2000-05-14 00:03:20 +04:00
|
|
|
sliders[i]->callback((Fl_Callback*)do_redraw);
|
|
|
|
sliders[i]->step(1);
|
|
|
|
}
|
2008-12-21 16:48:14 +03:00
|
|
|
sliders[0]->value(255); // R
|
|
|
|
sliders[1]->value(100); // G
|
|
|
|
sliders[2]->value(100); // B
|
2010-11-23 18:00:06 +03:00
|
|
|
sliders[4]->value(10); // move line coordinates
|
2008-12-21 16:48:14 +03:00
|
|
|
draw_line->value(0);
|
|
|
|
draw_line->callback((Fl_Callback*)do_redraw);
|
2000-05-14 00:03:20 +04:00
|
|
|
for (i=0;i<3;i++) {
|
|
|
|
choice[i]->value(0);
|
|
|
|
choice[i]->callback((Fl_Callback*)do_redraw);
|
|
|
|
}
|
2010-11-23 18:00:06 +03:00
|
|
|
test = new test_box(0,0,200,200);
|
2000-05-14 00:03:20 +04:00
|
|
|
test->end();
|
|
|
|
form->resizable(test);
|
|
|
|
form->end();
|
|
|
|
}
|
|
|
|
|
2000-06-08 11:50:23 +04:00
|
|
|
int main(int argc, char **argv) {
|
2000-05-14 00:03:20 +04:00
|
|
|
makeform(argv[0]);
|
|
|
|
form->show(argc,argv);
|
|
|
|
return Fl::run();
|
|
|
|
}
|