g_box.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* This file is part of the GNU plotutils package. Copyright (C) 1995,
  2. 1996, 1997, 1998, 1999, 2000, 2005, 2008, Free Software Foundation, Inc.
  3. The GNU plotutils package is free software. You may redistribute it
  4. and/or modify it under the terms of the GNU General Public License as
  5. published by the Free Software foundation; either version 2, or (at your
  6. option) any later version.
  7. The GNU plotutils package is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with the GNU plotutils package; see the file COPYING. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  14. Boston, MA 02110-1301, USA. */
  15. /* This file contains the box method, which is a standard part of libplot.
  16. It draws an object: a box, or upright rectangle with diagonal corners
  17. x0,y0 and x1,y1. Boxes are one of the three types of primitive closed
  18. path that libplot supports, along with circles and ellipses. */
  19. /* Most Plotters obviously require that the map from the user frame to the
  20. device frame preserve coordinate axes, in order to draw a box as a
  21. primitive (if it isn't, what results will be rotated or skewed). The
  22. constraints on the user frame -> device frame map (e.g., it must
  23. preserve axes) are specified by the internal `allowed_box_scaling'
  24. parameter, which this code checks. */
  25. #include "sys-defines.h"
  26. #include "extern.h"
  27. int
  28. _API_fbox (R___(Plotter *_plotter) double x0, double y0, double x1, double y1)
  29. {
  30. double xnew, ynew;
  31. plPoint p0, p1;
  32. bool clockwise;
  33. if (!_plotter->data->open)
  34. {
  35. _plotter->error (R___(_plotter)
  36. "fbox: invalid operation");
  37. return -1;
  38. }
  39. /* If a simple path is under construction (so that endsubpath() must not
  40. have been invoked), flush out the whole compound path. (It may
  41. include other, previously drawn simple paths.) */
  42. if (_plotter->drawstate->path)
  43. _API_endpath (S___(_plotter));
  44. /* begin a new path */
  45. _plotter->drawstate->path = _new_plPath ();
  46. p0.x = x0;
  47. p0.y = y0;
  48. p1.x = x1;
  49. p1.y = y1;
  50. clockwise = _plotter->drawstate->orientation < 0 ? true : false;
  51. if (!_plotter->drawstate->points_are_connected)
  52. /* line type is `disconnected': just plot a pseudo-box consisting of
  53. four line segments, which will ultimately be displayed (see
  54. g_endpath.c) as four filled circles (one at each vertex) */
  55. _add_box_as_lines (_plotter->drawstate->path,
  56. p0, p1, clockwise);
  57. else
  58. /* general case */
  59. {
  60. /* Add box to path buffer, as a primitive only if (1) this Plotter
  61. supports box primitives, and (2) it isn't to be edged, or if it's
  62. to be edged solid (not dashed). The latter restriction is to
  63. prevent confusion over the starting point, along the edge of box,
  64. for the dashing pattern. */
  65. if ((_plotter->drawstate->pen_type == 0 /* not edged */
  66. ||
  67. (_plotter->drawstate->dash_array_in_effect == false
  68. && _plotter->drawstate->line_type == PL_L_SOLID)) /* solid edge */
  69. &&
  70. ((_plotter->data->allowed_box_scaling == AS_ANY)
  71. ||
  72. (_plotter->data->allowed_box_scaling == AS_AXES_PRESERVED
  73. && _plotter->drawstate->transform.axes_preserved)))
  74. /* add box as a primitive */
  75. _add_box (_plotter->drawstate->path,
  76. p0, p1, clockwise);
  77. else
  78. /* add box as a polyline */
  79. _add_box_as_lines (_plotter->drawstate->path,
  80. p0, p1, clockwise);
  81. if (_plotter->drawstate->path->type == PATH_SEGMENT_LIST)
  82. /* pass all the newly added segments to the Plotter-specific
  83. function maybe_paint_segments(), since some Plotters plot paths
  84. in real time, i.e., prepaint them, rather than waiting until
  85. endpath() is called */
  86. _plotter->maybe_prepaint_segments (R___(_plotter) 0);
  87. }
  88. /* move to center (libplot convention) */
  89. xnew = 0.5 * (x0 + x1);
  90. ynew = 0.5 * (y0 + y1);
  91. _plotter->drawstate->pos.x = xnew;
  92. _plotter->drawstate->pos.y = ynew;
  93. return 0;
  94. }