/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx

https://github.com/fltk/fltk · C++ · 95 lines · 59 code · 13 blank · 23 comment · 16 complexity · 342893c90371d64e4402e71c4fd62a0d MD5 · raw file

  1. //
  2. // Portable drawing routines for the Fast Light Tool Kit (FLTK).
  3. //
  4. // Copyright 1998-2018 by Bill Spitzak and others.
  5. //
  6. // This library is free software. Distribution and use rights are outlined in
  7. // the file "COPYING" which should have been included with this file. If this
  8. // file is missing or damaged, see the license at:
  9. //
  10. // https://www.fltk.org/COPYING.php
  11. //
  12. // Please see the following page on how to report bugs and issues:
  13. //
  14. // https://www.fltk.org/bugs.php
  15. //
  16. /**
  17. \file Fl_Xlib_Graphics_Driver_vertex.cxx
  18. \brief Portable drawing code for drawing arbitrary shapes with
  19. simple 2D transformations, implemented for X11 Xlib.
  20. */
  21. #include <config.h>
  22. #include "Fl_Xlib_Graphics_Driver.H"
  23. #include <FL/fl_draw.H>
  24. #include <FL/platform.H>
  25. #include <FL/math.h>
  26. void Fl_Xlib_Graphics_Driver::end_points() {
  27. if (n>1) XDrawPoints(fl_display, fl_window, gc_, (XPoint*)p, n, 0);
  28. }
  29. void Fl_Xlib_Graphics_Driver::end_line() {
  30. if (n < 2) {
  31. end_points();
  32. return;
  33. }
  34. if (n>1) XDrawLines(fl_display, fl_window, gc_, (XPoint*)p, n, 0);
  35. }
  36. void Fl_Xlib_Graphics_Driver::end_loop() {
  37. fixloop();
  38. if (n>2) {
  39. transformed_vertex0(p[0].x - line_delta_, p[0].y - line_delta_);
  40. }
  41. end_line();
  42. }
  43. void Fl_Xlib_Graphics_Driver::end_polygon() {
  44. fixloop();
  45. if (n < 3) {
  46. end_line();
  47. return;
  48. }
  49. if (n>2) XFillPolygon(fl_display, fl_window, gc_, (XPoint*)p, n, Convex, 0);
  50. }
  51. void Fl_Xlib_Graphics_Driver::begin_complex_polygon() {
  52. begin_polygon();
  53. gap_ = 0;
  54. }
  55. void Fl_Xlib_Graphics_Driver::gap() {
  56. while (n>gap_+2 && p[n-1].x == p[gap_].x && p[n-1].y == p[gap_].y) n--;
  57. if (n > gap_+2) {
  58. transformed_vertex0(p[gap_].x - line_delta_, p[gap_].y - line_delta_);
  59. gap_ = n;
  60. } else {
  61. n = gap_;
  62. }
  63. }
  64. void Fl_Xlib_Graphics_Driver::end_complex_polygon() {
  65. gap();
  66. if (n < 3) {
  67. end_line();
  68. return;
  69. }
  70. if (n>2) XFillPolygon(fl_display, fl_window, gc_, (XPoint*)p, n, 0, 0);
  71. }
  72. // shortcut the closed circles so they use XDrawArc:
  73. // warning: these do not draw rotated ellipses correctly!
  74. // See fl_arc.c for portable version.
  75. void Fl_Xlib_Graphics_Driver::ellipse_unscaled(double xt, double yt, double rx, double ry) {
  76. int llx = (int)rint(xt-rx);
  77. int w = (int)rint(xt+rx)-llx;
  78. int lly = (int)rint(yt-ry);
  79. int h = (int)rint(yt+ry)-lly;
  80. (what == POLYGON ? XFillArc : XDrawArc)
  81. (fl_display, fl_window, gc_, llx, lly, w, h, 0, 360*64);
  82. }