mirror of
https://github.com/fltk/fltk.git
synced 2026-05-25 00:53:39 +08:00
Add a unit test for drawing complex shapes (#565)
This commit is contained in:
@@ -234,6 +234,8 @@ public:
|
||||
// support of "complex shapes"
|
||||
void push_matrix();
|
||||
void pop_matrix();
|
||||
void load_identity();
|
||||
void load_matrix(double a, double b, double c, double d, double x, double y);
|
||||
void mult_matrix(double a, double b, double c, double d, double x, double y);
|
||||
void rotate(double d);
|
||||
void translate(double x,double y);
|
||||
|
||||
@@ -550,6 +550,19 @@ inline void fl_translate(double x, double y) {
|
||||
inline void fl_rotate(double d) {
|
||||
fl_graphics_driver->rotate(d);
|
||||
}
|
||||
/**
|
||||
Set the transformation matrix to identity.
|
||||
*/
|
||||
inline void fl_load_identity() {
|
||||
fl_graphics_driver->load_identity();
|
||||
}
|
||||
/**
|
||||
Set the current transformation matrix.
|
||||
\param[in] a,b,c,d,x,y transformation matrix elements
|
||||
*/
|
||||
inline void fl_load_matrix(double a, double b, double c, double d, double x, double y) {
|
||||
fl_graphics_driver->load_matrix(a, b, c, d, x, y);
|
||||
}
|
||||
/**
|
||||
Concatenate another transformation onto the current one.
|
||||
|
||||
|
||||
@@ -557,6 +557,12 @@ severely limits the accuracy of these functions for complex
|
||||
graphics, so use OpenGL when greater accuracy and/or performance
|
||||
is required.
|
||||
|
||||
void fl_load_matrix(double a,double b,double c,double d,double x,double y)
|
||||
void fl_load_identity()
|
||||
|
||||
\par
|
||||
Set the current transformation.
|
||||
|
||||
void fl_push_matrix() <br>
|
||||
void fl_pop_matrix()
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ Fl_Graphics_Driver::Fl_Graphics_Driver()
|
||||
p_size = 0;
|
||||
xpoint = NULL;
|
||||
what = NONE;
|
||||
n = 0;
|
||||
};
|
||||
|
||||
/** Destructor */
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
// double Fl_OpenGL_Graphics_Driver::transform_dy(double x, double y)
|
||||
|
||||
void Fl_OpenGL_Graphics_Driver::begin_points() {
|
||||
Fl_Graphics_Driver::begin_points();
|
||||
glBegin(GL_POINTS);
|
||||
}
|
||||
|
||||
@@ -49,6 +50,7 @@ void Fl_OpenGL_Graphics_Driver::end_points() {
|
||||
}
|
||||
|
||||
void Fl_OpenGL_Graphics_Driver::begin_line() {
|
||||
Fl_Graphics_Driver::begin_line();
|
||||
glBegin(GL_LINE_STRIP);
|
||||
}
|
||||
|
||||
@@ -57,6 +59,7 @@ void Fl_OpenGL_Graphics_Driver::end_line() {
|
||||
}
|
||||
|
||||
void Fl_OpenGL_Graphics_Driver::begin_loop() {
|
||||
Fl_Graphics_Driver::begin_loop();
|
||||
glBegin(GL_LINE_LOOP);
|
||||
}
|
||||
|
||||
@@ -65,6 +68,7 @@ void Fl_OpenGL_Graphics_Driver::end_loop() {
|
||||
}
|
||||
|
||||
void Fl_OpenGL_Graphics_Driver::begin_polygon() {
|
||||
Fl_Graphics_Driver::begin_polygon();
|
||||
glBegin(GL_POLYGON);
|
||||
}
|
||||
|
||||
@@ -73,6 +77,7 @@ void Fl_OpenGL_Graphics_Driver::end_polygon() {
|
||||
}
|
||||
|
||||
void Fl_OpenGL_Graphics_Driver::begin_complex_polygon() {
|
||||
Fl_Graphics_Driver::begin_complex_polygon();
|
||||
glBegin(GL_POLYGON);
|
||||
}
|
||||
|
||||
|
||||
+7
-6
@@ -46,21 +46,22 @@ void Fl_Graphics_Driver::curve(double X0, double Y0,
|
||||
fl_transformed_vertex(x,y);
|
||||
|
||||
double x1 = fl_transform_x(X1,Y1);
|
||||
double yy1 = fl_transform_y(X1,Y1);
|
||||
double y1 = fl_transform_y(X1,Y1);
|
||||
double x2 = fl_transform_x(X2,Y2);
|
||||
double y2 = fl_transform_y(X2,Y2);
|
||||
double x3 = fl_transform_x(X3,Y3);
|
||||
double y3 = fl_transform_y(X3,Y3);
|
||||
|
||||
// find the area:
|
||||
double a = fabs((x-x2)*(y3-yy1)-(y-y2)*(x3-x1));
|
||||
double b = fabs((x-x3)*(y2-yy1)-(y-y3)*(x2-x1));
|
||||
double a = fabs((x-x2)*(y3-y1)-(y-y2)*(x3-x1));
|
||||
double b = fabs((x-x3)*(y2-y1)-(y-y3)*(x2-x1));
|
||||
if (b > a) a = b;
|
||||
|
||||
// use that to guess at the number of segments:
|
||||
int nSeg = int(sqrt(a)/4);
|
||||
if (nSeg > 1) {
|
||||
if (nSeg > 100) nSeg = 100; // make huge curves not hang forever
|
||||
if (nSeg < 9) nSeg = 9; // make tiny curevs look bearable
|
||||
|
||||
double e = 1.0/nSeg;
|
||||
|
||||
@@ -74,9 +75,9 @@ void Fl_Graphics_Driver::curve(double X0, double Y0,
|
||||
double dx2 = dx3 + 2*xb*e*e;
|
||||
|
||||
// calculate the coefficients of 3rd order equation:
|
||||
double ya = (y3-3*y2+3*yy1-y);
|
||||
double yb = 3*(y2-2*yy1+y);
|
||||
double yc = 3*(yy1-y);
|
||||
double ya = (y3-3*y2+3*y1-y);
|
||||
double yb = 3*(y2-2*y1+y);
|
||||
double yc = 3*(y1-y);
|
||||
// calculate the forward differences:
|
||||
double dy1 = ((ya*e+yb)*e+yc)*e;
|
||||
double dy3 = 6*ya*e*e*e;
|
||||
|
||||
@@ -57,6 +57,21 @@ void Fl_Graphics_Driver::pop_matrix() {
|
||||
m = stack[--sptr];
|
||||
}
|
||||
|
||||
/** see fl_load_identity() */
|
||||
void Fl_Graphics_Driver::load_identity() {
|
||||
m = m0;
|
||||
}
|
||||
|
||||
/** see fl_load_matrix() */
|
||||
void Fl_Graphics_Driver::load_matrix(double a, double b, double c, double d, double x, double y) {
|
||||
m.a = a;
|
||||
m.b = b;
|
||||
m.c = c;
|
||||
m.d = d;
|
||||
m.x = x;
|
||||
m.y = y;
|
||||
}
|
||||
|
||||
/** see fl_mult_matrix() */
|
||||
void Fl_Graphics_Driver::mult_matrix(double a, double b, double c, double d, double x, double y) {
|
||||
matrix o;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -297,7 +297,7 @@ public:
|
||||
"This draws 2 lines at differnet widths, and one connected line.\n\n"
|
||||
// Things to look out for:
|
||||
"Green and red pixels mark the beginning and end of single lines."
|
||||
"The line caps should be flat, the joints shoould be of type \"miter\"."
|
||||
"The line caps should be flat, the joints should be of type \"miter\"."
|
||||
);
|
||||
|
||||
#if HAVE_GL
|
||||
@@ -371,7 +371,7 @@ public:
|
||||
"This draws 2 lines at differnet widths, and one connected line.\n\n"
|
||||
// Things to look out for:
|
||||
"Green and red pixels mark the beginning and end of single lines."
|
||||
"The line caps should be flat, the joints shoould be of type \"miter\"."
|
||||
"The line caps should be flat, the joints should be of type \"miter\"."
|
||||
);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ int main(int argc, char **argv) {
|
||||
Fl::visual(FL_RGB);
|
||||
Fl::use_high_res_GL(1);
|
||||
mainwin = new MainWindow(MAINWIN_W, MAINWIN_H, "FLTK Unit Tests");
|
||||
mainwin->size_range(MAINWIN_W, MAINWIN_H);
|
||||
browser = new Fl_Hold_Browser(BROWSER_X, BROWSER_Y, BROWSER_W, BROWSER_H, "Unit Tests");
|
||||
browser->align(FL_ALIGN_TOP|FL_ALIGN_LEFT);
|
||||
browser->when(FL_WHEN_CHANGED);
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ enum {
|
||||
kTestPoints,
|
||||
kTestFastShapes,
|
||||
kTestCircles,
|
||||
// kTestComplexShapes,
|
||||
kTestComplexShapes,
|
||||
kTestText,
|
||||
kTestSymbol,
|
||||
kTestImages,
|
||||
|
||||
Reference in New Issue
Block a user