x_point.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. /* The internal point-drawing function, which point() is a wrapper around.
  16. It draws a point at the current location. There is no standard
  17. definition of `point', so any Plotter is free to implement this as it
  18. sees fit. */
  19. /* This version is for XDrawablePlotters and XPlotters. It calls
  20. _maybe_handle_x_events(), which is a no-op for the former but not the
  21. latter (it flushes the X output buffer and may also check for events).
  22. Since point() is used mostly by people drawing images, it may be invoked
  23. a great many times. To speed things up, the call to
  24. _maybe_handle_x_events() is performed only once per X_POINT_FLUSH_PERIOD
  25. invocations of this function. */
  26. #define X_POINT_FLUSH_PERIOD 8
  27. #include "sys-defines.h"
  28. #include "extern.h"
  29. void
  30. _pl_x_paint_point (S___(Plotter *_plotter))
  31. {
  32. double xx, yy;
  33. int ix, iy;
  34. plColor oldcolor, newcolor;
  35. if (_plotter->drawstate->pen_type != 0)
  36. /* have a pen to draw with */
  37. {
  38. /* set pen color as foreground color in GC used for drawing (but
  39. first, check whether we can avoid a function call) */
  40. newcolor = _plotter->drawstate->fgcolor;
  41. oldcolor = _plotter->drawstate->x_current_fgcolor; /* as stored in gc */
  42. if (newcolor.red != oldcolor.red
  43. || newcolor.green != oldcolor.green
  44. || newcolor.blue != oldcolor.blue
  45. || ! _plotter->drawstate->x_gc_fgcolor_status)
  46. _pl_x_set_pen_color (S___(_plotter));
  47. xx = XD(_plotter->drawstate->pos.x, _plotter->drawstate->pos.y);
  48. yy = YD(_plotter->drawstate->pos.x, _plotter->drawstate->pos.y);
  49. ix = IROUND(xx);
  50. iy = IROUND(yy);
  51. if (_plotter->x_double_buffering != X_DBL_BUF_NONE)
  52. /* double buffering, have a `x_drawable3' to draw into */
  53. XDrawPoint (_plotter->x_dpy, _plotter->x_drawable3,
  54. _plotter->drawstate->x_gc_fg,
  55. ix, iy);
  56. else
  57. /* not double buffering, have no `x_drawable3' */
  58. {
  59. if (_plotter->x_drawable1)
  60. XDrawPoint (_plotter->x_dpy, _plotter->x_drawable1,
  61. _plotter->drawstate->x_gc_fg,
  62. ix, iy);
  63. if (_plotter->x_drawable2)
  64. XDrawPoint (_plotter->x_dpy, _plotter->x_drawable2,
  65. _plotter->drawstate->x_gc_fg,
  66. ix, iy);
  67. }
  68. }
  69. /* maybe flush X output buffer and handle X events (a no-op for
  70. XDrawablePlotters, which is overridden for XPlotters) */
  71. if (_plotter->x_paint_pixel_count % X_POINT_FLUSH_PERIOD == 0)
  72. _maybe_handle_x_events (S___(_plotter));
  73. _plotter->x_paint_pixel_count++;
  74. }