You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
4.2KB

  1. //
  2. // "$Id: unittest_circles.cxx 7913 2010-11-29 18:18:27Z greg.ercolano $"
  3. //
  4. // Unit tests for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-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.
  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. #include <FL/Fl_Box.H>
  28. #include <FL/fl_draw.H>
  29. //
  30. //------- test the circle drawing capabilities of this implementation ----------
  31. //
  32. class CircleTest : public Fl_Box {
  33. public:
  34. static Fl_Widget *create() {
  35. return new CircleTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H);
  36. }
  37. CircleTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) {
  38. label("testing int drawing of circles and ovals (fl_arc, fl_pie)\n"
  39. "No red lines should be visible. "
  40. "If you see bright red pixels, the circle drawing alignment is off. "
  41. "If you see dark red pixels, your system supports anti-aliasing "
  42. "which should be of no concern. "
  43. "The green rectangles should not be overwritten by circle drawings.");
  44. align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP);
  45. box(FL_BORDER_BOX);
  46. }
  47. void draw() {
  48. Fl_Box::draw();
  49. int a = x()+10, b = y()+10; fl_color(FL_BLACK); fl_rect(a, b, 100, 100);
  50. // test fl_arc for full circles
  51. fl_color(FL_GREEN); fl_rect(a+ 9, b+ 9, 33, 33);
  52. fl_color(FL_RED); fl_xyline(a+24, b+10, a+27); fl_xyline(a+24, b+40, a+27);
  53. fl_yxline(a+10, b+24, b+27); fl_yxline(a+40, b+24, b+27);
  54. fl_color(FL_BLACK); fl_arc(a+10, b+10, 31, 31, 0.0, 360.0);
  55. // test fl_arc segmet 1
  56. fl_color(FL_GREEN); fl_rect(a+54, b+ 4, 43, 43);
  57. fl_rect(a+54, b+4, 18, 18); fl_rect(a+79, b+29, 18, 18);
  58. fl_color(FL_RED); fl_point(a+55, b+30); fl_point(a+70, b+45);
  59. fl_point(a+80, b+5); fl_point(a+95, b+20);
  60. fl_color(FL_BLACK); fl_arc(a+65, b+ 5, 31, 31, -35.0, 125.0);
  61. // test fl_arc segmet 2
  62. fl_color(FL_BLACK); fl_arc(a+55, b+15, 31, 31, 145.0, 305.0);
  63. // test fl_pie for full circles
  64. fl_color(FL_RED); fl_xyline(a+24, b+60, a+27); fl_xyline(a+24, b+90, a+27);
  65. fl_yxline(a+10, b+74, b+77); fl_yxline(a+40, b+74, b+77);
  66. fl_color(FL_GREEN); fl_rect(a+ 9, b+59, 33, 33);
  67. fl_color(FL_BLACK); fl_pie(a+10, b+60, 31, 31, 0.0, 360.0);
  68. // test fl_pie segmet 1
  69. fl_color(FL_GREEN); fl_rect(a+54, b+54, 43, 43);
  70. fl_rect(a+54, b+54, 18, 18); fl_rect(a+79, b+79, 18, 18);
  71. fl_point(a+79, b+71); fl_point(a+71, b+79);
  72. fl_color(FL_RED); fl_point(a+55, b+80); fl_point(a+70, b+95);
  73. fl_point(a+80, b+55); fl_point(a+95, b+70);
  74. fl_point(a+81, b+69); fl_point(a+69, b+81);
  75. fl_color(FL_BLACK); fl_pie(a+65, b+55, 31, 31, -30.0, 120.0);
  76. // test fl_pie segmet 2
  77. fl_color(FL_BLACK); fl_pie(a+55, b+65, 31, 31, 150.0, 300.0);
  78. //---- oval testing (horizontal squish)
  79. a +=120; b += 0; fl_color(FL_BLACK); fl_rect(a, b, 100, 100);
  80. fl_color(FL_GREEN);
  81. fl_rect(a+19, b+9, 63, 33); fl_rect(a+19, b+59, 63, 33);
  82. fl_color(FL_BLACK);
  83. fl_arc(a+20, b+10, 61, 31, 0, 360); fl_pie(a+20, b+60, 61, 31, 0, 360);
  84. //---- oval testing (horizontal squish)
  85. a += 120; b += 0; fl_color(FL_BLACK); fl_rect(a, b, 100, 100);
  86. fl_color(FL_GREEN);
  87. fl_rect(a+9, b+19, 33, 63); fl_rect(a+59, b+19, 33, 63);
  88. fl_color(FL_BLACK);
  89. fl_arc(a+10, b+20, 31, 61, 0, 360); fl_pie(a+60, b+20, 31, 61, 0, 360);
  90. }
  91. };
  92. UnitTest circle("circles and arcs", CircleTest::create);
  93. //
  94. // End of "$Id: unittest_circles.cxx 7913 2010-11-29 18:18:27Z greg.ercolano $"
  95. //