b_point.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include "sys-defines.h"
  20. #include "extern.h"
  21. #include "xmi.h"
  22. void
  23. _pl_b_paint_point (S___(Plotter *_plotter))
  24. {
  25. double xx, yy;
  26. int ixx, iyy;
  27. unsigned char red, green, blue;
  28. miGC *pGC;
  29. miPixel fgPixel, bgPixel, pixels[2];
  30. miPoint point, offset;
  31. if (_plotter->drawstate->pen_type != 0)
  32. /* have a pen to draw with */
  33. {
  34. /* convert point to floating-point device coordinates */
  35. xx = XD(_plotter->drawstate->pos.x, _plotter->drawstate->pos.y);
  36. yy = YD(_plotter->drawstate->pos.x, _plotter->drawstate->pos.y);
  37. /* round to integer device coordinates */
  38. ixx = IROUND(xx);
  39. iyy = IROUND(yy);
  40. /* compute 24-bit color */
  41. red = ((unsigned int)(_plotter->drawstate->fgcolor.red) >> 8) & 0xff;
  42. green = ((unsigned int)(_plotter->drawstate->fgcolor.green) >> 8) & 0xff;
  43. blue = ((unsigned int)(_plotter->drawstate->fgcolor.blue) >> 8) & 0xff;
  44. /* compute background and foreground color for miGC */
  45. bgPixel.type = MI_PIXEL_RGB_TYPE;
  46. bgPixel.u.rgb[0] = _plotter->drawstate->bgcolor.red & 0xff;
  47. bgPixel.u.rgb[1] = _plotter->drawstate->bgcolor.green & 0xff;
  48. bgPixel.u.rgb[2] = _plotter->drawstate->bgcolor.blue & 0xff;
  49. fgPixel.type = MI_PIXEL_RGB_TYPE;
  50. fgPixel.u.rgb[0] = red;
  51. fgPixel.u.rgb[1] = green;
  52. fgPixel.u.rgb[2] = blue;
  53. pixels[0] = bgPixel;
  54. pixels[1] = fgPixel;
  55. /* construct an miGC (graphics context for the libxmi module); copy
  56. attributes from the Plotter's GC to it */
  57. pGC = miNewGC (2, pixels);
  58. _set_common_mi_attributes (_plotter->drawstate, (void *)pGC);
  59. point.x = ixx;
  60. point.y = iyy;
  61. miDrawPoints ((miPaintedSet *)_plotter->b_painted_set,
  62. pGC, MI_COORD_MODE_ORIGIN, 1, &point);
  63. /* deallocate miGC */
  64. miDeleteGC (pGC);
  65. /* copy from painted set to canvas, and clear */
  66. offset.x = 0;
  67. offset.y = 0;
  68. miCopyPaintedSetToCanvas ((miPaintedSet *)_plotter->b_painted_set,
  69. (miCanvas *)_plotter->b_canvas,
  70. offset);
  71. miClearPaintedSet ((miPaintedSet *)_plotter->b_painted_set);
  72. }
  73. }