2009-04-12 17:48:03 +04:00
|
|
|
//
|
|
|
|
// Unit tests for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2022-02-19 14:55:06 +03:00
|
|
|
// Copyright 1998-2022 by Bill Spitzak and others.
|
2009-04-12 17:48:03 +04: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
|
2009-04-12 17:48:03 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2009-04-12 17:48:03 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
2009-04-12 17:48:03 +04:00
|
|
|
//
|
|
|
|
|
2022-02-06 17:22:24 +03:00
|
|
|
#include "unittests.h"
|
|
|
|
|
|
|
|
#include <config.h>
|
2009-04-12 17:48:03 +04:00
|
|
|
#include <FL/Fl_Box.H>
|
|
|
|
#include <FL/fl_draw.H>
|
2022-02-06 17:22:24 +03:00
|
|
|
#include <FL/math.h>
|
|
|
|
#if HAVE_GL
|
|
|
|
#include <FL/Fl_Gl_Window.H>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// --- test drawing circles and arcs ------
|
|
|
|
//
|
|
|
|
|
|
|
|
void arc(int xi, int yi, int w, int h, double a1, double a2)
|
|
|
|
{
|
|
|
|
if (a2<=a1) return;
|
|
|
|
|
|
|
|
double rx = w/2.0;
|
|
|
|
double ry = h/2.0;
|
|
|
|
double x = xi + rx + 0.5;
|
|
|
|
double y = yi + ry + 0.5;
|
|
|
|
double circ = M_PI*0.5*(rx+ry);
|
2022-02-26 20:19:43 +03:00
|
|
|
int i, segs = int(circ * (a2-a1) / 100);
|
2022-02-06 17:22:24 +03:00
|
|
|
if (segs<3) segs = 3;
|
|
|
|
|
|
|
|
a1 = a1/180*M_PI;
|
|
|
|
a2 = a2/180*M_PI;
|
|
|
|
double step = (a2-a1)/segs;
|
|
|
|
|
2022-02-26 20:19:43 +03:00
|
|
|
int nx = int(x + cos(a1)*rx);
|
|
|
|
int ny = int(y - sin(a1)*ry);
|
2022-02-06 17:22:24 +03:00
|
|
|
fl_point(nx, ny);
|
|
|
|
for (i=segs; i>0; i--) {
|
2022-02-21 18:51:20 +03:00
|
|
|
a1 += step;
|
2022-02-26 20:19:43 +03:00
|
|
|
nx = int(x + cos(a1)*rx);
|
|
|
|
ny = int(y - sin(a1)*ry);
|
2022-02-06 17:22:24 +03:00
|
|
|
fl_point(nx, ny);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_circles() {
|
|
|
|
int a = 0, b = 0, w=40, h=40;
|
|
|
|
// ---- 1: draw a circle and a filled circle
|
|
|
|
fl_color(FL_RED);
|
|
|
|
arc(a+1, b+1, w-2, h-2, 0.0, 360.0);
|
|
|
|
fl_color(FL_GREEN);
|
|
|
|
arc(a, b, w, h, 0.0, 360.0);
|
|
|
|
arc(a+2, b+2, w-4, h-4, 0.0, 360.0);
|
|
|
|
fl_color(FL_BLACK);
|
|
|
|
fl_arc(a+1, b+1, w-1, h-1, 0.0, 360.0);
|
|
|
|
// ----
|
|
|
|
fl_color(FL_RED);
|
|
|
|
arc(a+1+50, b+1, w-2, h-2, 0.0, 360.0);
|
|
|
|
fl_color(FL_GREEN);
|
|
|
|
arc(a+50, b, w, h, 0.0, 360.0);
|
|
|
|
fl_color(FL_BLACK);
|
|
|
|
fl_pie(a+1+50, b+1, w-1, h-1, 0.0, 360.0);
|
|
|
|
b+=44;
|
|
|
|
// ---- 2: draw arcs and pies
|
|
|
|
fl_color(FL_RED);
|
2022-12-17 15:16:57 +03:00
|
|
|
// arc(a-5, b-5, w+10, h+10, 45.0, 315.0);
|
2022-02-06 17:22:24 +03:00
|
|
|
arc(a+1, b+1, w-2, h-2, 45.0, 315.0);
|
2022-12-17 15:16:57 +03:00
|
|
|
// arc(a+5, b+5, w-10, h-10, 45.0, 315.0);
|
|
|
|
// arc(a+10, b+10, w-20, h-20, 45.0, 315.0);
|
2022-02-06 17:22:24 +03:00
|
|
|
fl_color(FL_GREEN);
|
|
|
|
arc(a, b, w, h, 45.0, 315.0);
|
|
|
|
arc(a+2, b+2, w-4, h-4, 45.0, 315.0);
|
|
|
|
fl_color(FL_BLACK);
|
2022-12-17 15:16:57 +03:00
|
|
|
// fl_arc(a-5, b-5, w+10, h+10, 45.0, 315.0);
|
2022-02-06 17:22:24 +03:00
|
|
|
fl_arc(a+1, b+1, w-1, h-1, 45.0, 315.0);
|
2022-12-17 15:16:57 +03:00
|
|
|
// fl_arc(a+5, b+5, w-10, h-10, 45.0, 315.0);
|
|
|
|
// fl_arc(a+10, b+10, w-20, h-20, 45.0, 315.0);
|
2022-02-06 17:22:24 +03:00
|
|
|
fl_color(FL_RED);
|
|
|
|
// ----
|
|
|
|
arc(a+1+50, b+1, w-2, h-2, 45.0, 315.0);
|
|
|
|
fl_line(a+50+20, b+20, a+50+20+14, b+20-14);
|
|
|
|
fl_line(a+50+20, b+20, a+50+20+14, b+20+14);
|
|
|
|
fl_color(FL_GREEN);
|
|
|
|
arc(a+50, b, w, h, 45.0, 315.0);
|
|
|
|
fl_line(a+50+21, b+20, a+50+21+14, b+20-14);
|
|
|
|
fl_line(a+50+21, b+20, a+50+21+14, b+20+14);
|
|
|
|
fl_color(FL_BLACK);
|
|
|
|
fl_pie(a+1+50, b+1, w-1, h-1, 45.0, 315.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_GL
|
|
|
|
|
2022-12-17 15:16:57 +03:00
|
|
|
class Ut_GL_Circle_Test : public Fl_Gl_Window {
|
2022-02-06 17:22:24 +03:00
|
|
|
public:
|
2022-12-17 15:16:57 +03:00
|
|
|
Ut_GL_Circle_Test(int x, int y, int w, int h)
|
|
|
|
: Fl_Gl_Window(x, y, w, h) {
|
2022-02-06 17:22:24 +03:00
|
|
|
box(FL_FLAT_BOX);
|
|
|
|
}
|
2022-12-30 21:14:36 +03:00
|
|
|
void draw() FL_OVERRIDE {
|
2022-02-06 17:22:24 +03:00
|
|
|
draw_begin();
|
|
|
|
Fl_Window::draw();
|
|
|
|
draw_circles();
|
|
|
|
draw_end();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2022-12-17 15:16:57 +03:00
|
|
|
class Ut_Native_Circle_Test : public Fl_Window {
|
2022-02-06 17:22:24 +03:00
|
|
|
public:
|
2022-12-17 15:16:57 +03:00
|
|
|
Ut_Native_Circle_Test(int x, int y, int w, int h)
|
|
|
|
: Fl_Window(x, y, w, h) {
|
2022-02-06 17:22:24 +03:00
|
|
|
box(FL_FLAT_BOX);
|
|
|
|
end();
|
|
|
|
}
|
2022-12-30 21:14:36 +03:00
|
|
|
void draw() FL_OVERRIDE {
|
2022-02-06 17:22:24 +03:00
|
|
|
Fl_Window::draw();
|
|
|
|
draw_circles();
|
|
|
|
}
|
|
|
|
};
|
2009-04-12 17:48:03 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
//------- test the circle drawing capabilities of this implementation ----------
|
|
|
|
//
|
2022-12-17 15:16:57 +03:00
|
|
|
class Ut_Circle_Test : public Fl_Group {
|
2020-07-01 19:03:10 +03:00
|
|
|
public:
|
|
|
|
static Fl_Widget *create() {
|
2022-12-17 15:16:57 +03:00
|
|
|
return new Ut_Circle_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
|
2009-04-12 17:48:03 +04:00
|
|
|
}
|
2022-12-17 15:16:57 +03:00
|
|
|
Ut_Circle_Test(int x, int y, int w, int h)
|
|
|
|
: Fl_Group(x, y, w, h) {
|
2022-02-06 17:22:24 +03:00
|
|
|
label("Testing fast circle, arc, and pie drawing\n\n"
|
2009-04-12 17:48:03 +04:00
|
|
|
"No red lines should be visible. "
|
2022-02-06 17:22:24 +03:00
|
|
|
"The green outlines should not be overwritten by circle drawings.");
|
2009-04-12 17:48:03 +04:00
|
|
|
align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP);
|
|
|
|
box(FL_BORDER_BOX);
|
2022-02-06 17:22:24 +03:00
|
|
|
|
|
|
|
int a = x+16, b = y+34;
|
2022-12-17 15:16:57 +03:00
|
|
|
Fl_Box* t = new Fl_Box(a, b-24, 80, 18, "native");
|
2022-02-06 17:22:24 +03:00
|
|
|
t->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
|
|
|
|
|
2022-12-17 15:16:57 +03:00
|
|
|
/* NativeCircleTest *nr = */ new Ut_Native_Circle_Test(a+23, b-1, 200, 200);
|
2022-02-06 17:22:24 +03:00
|
|
|
|
|
|
|
t = new Fl_Box(a, b, 18, 18, "1");
|
|
|
|
t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW);
|
|
|
|
t->tooltip(// Title:
|
|
|
|
"Testing circle alignment.\n\n"
|
|
|
|
// Description:
|
|
|
|
"This draws a black circle and a black disc, surrounded by a green frame.\n\n"
|
|
|
|
// Things to look out for:
|
|
|
|
"If green pixels are missing, circle drawing must be adjusted (see fl_arc, fl_pie).\n\n"
|
|
|
|
"If red pixels are showing, line width or aligment may be off."
|
|
|
|
);
|
|
|
|
b+=44;
|
|
|
|
t = new Fl_Box(a, b, 18, 18, "2");
|
|
|
|
t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW);
|
|
|
|
t->tooltip(// Title:
|
|
|
|
"Testing arc and pie drawing.\n\n"
|
|
|
|
// Description:
|
|
|
|
"This draws a black frame, surrounded on the inside and outside by a green frame.\n\n"
|
|
|
|
// Things to look out for:
|
|
|
|
"If green pixels are missing or red pixels are showing, rectangular frame drawing schould be adjusted (see fl_rect).\n\n"
|
|
|
|
"If red pixels show in the corners of the frame in hidpi mode, line endings should be adjusted."
|
|
|
|
);
|
|
|
|
|
|
|
|
#if HAVE_GL
|
|
|
|
|
|
|
|
a = x+16+250, b = y+34;
|
|
|
|
t = new Fl_Box(a, b-24, 80, 18, "OpenGL");
|
|
|
|
t->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
|
|
|
|
|
2022-12-17 15:16:57 +03:00
|
|
|
/* GLCircleTest *glr = */ new Ut_GL_Circle_Test(a+31, b-1, 200, 200);
|
2022-02-06 17:22:24 +03:00
|
|
|
|
|
|
|
t = new Fl_Box(a, b, 26, 18, "1a");
|
|
|
|
t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW);
|
|
|
|
t->tooltip(// Title:
|
|
|
|
"Testing circle alignment.\n\n"
|
|
|
|
// Description:
|
|
|
|
"This draws a black circle and a black disc, surrounded by a green frame.\n\n"
|
|
|
|
// Things to look out for:
|
|
|
|
"If green pixels are missing, circle drawing must be adjusted (see fl_arc, fl_pie).\n\n"
|
|
|
|
"If red pixels are showing, line width or aligment may be off."
|
|
|
|
);
|
|
|
|
b+=44;
|
|
|
|
t = new Fl_Box(a, b, 26, 18, "2a");
|
|
|
|
t->box(FL_ROUNDED_BOX); t->color(FL_YELLOW);
|
|
|
|
t->tooltip(// Title:
|
|
|
|
"Testing arc and pie drawing.\n\n"
|
|
|
|
// Description:
|
|
|
|
"This draws a black frame, surrounded on the inside and outside by a green frame.\n\n"
|
|
|
|
// Things to look out for:
|
|
|
|
"If green pixels are missing or red pixels are showing, rectangular frame drawing schould be adjusted (see fl_rect).\n\n"
|
|
|
|
"If red pixels show in the corners of the frame in hidpi mode, line endings should be adjusted."
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
t = new Fl_Box(x+w-1,y+h-1, 1, 1);
|
|
|
|
resizable(t);
|
2009-04-12 17:48:03 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-12-17 15:16:57 +03:00
|
|
|
UnitTest circle(UT_TEST_CIRCLES, "Circles and Arcs", Ut_Circle_Test::create);
|