g_erase.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 erase method, which is a standard part of
  16. libplot. It erases all objects on the graphics device display.
  17. This generic version is designed mostly for Plotters that do not do
  18. real-time plotting, and have no internal state. It simply resets the
  19. output buffer for the current `page', discarding all objects written
  20. to it. */
  21. #include "sys-defines.h"
  22. #include "extern.h"
  23. int
  24. _API_erase (S___(Plotter *_plotter))
  25. {
  26. bool retval1;
  27. int retval2 = 0;
  28. if (!_plotter->data->open)
  29. {
  30. _plotter->error (R___(_plotter)
  31. "erase: invalid operation");
  32. return -1;
  33. }
  34. _API_endpath (S___(_plotter)); /* flush path if any */
  35. switch ((int)_plotter->data->output_model)
  36. {
  37. case (int)PL_OUTPUT_NONE:
  38. /* Plotter doesn't do output, so do nothing */
  39. break;
  40. case (int)PL_OUTPUT_ONE_PAGE:
  41. case (int)PL_OUTPUT_ONE_PAGE_AT_A_TIME:
  42. case (int)PL_OUTPUT_PAGES_ALL_AT_ONCE:
  43. /* the builtin plOutbuf mechanism is being used for storing pages, so
  44. remove all stored graphics code from the buffer corresponding to
  45. the current page; reset page bounding box, etc. */
  46. if (_plotter->data->page) /* paranoid */
  47. _reset_outbuf (_plotter->data->page);
  48. break;
  49. case (int)PL_OUTPUT_VIA_CUSTOM_ROUTINES:
  50. case (int)PL_OUTPUT_VIA_CUSTOM_ROUTINES_IN_REAL_TIME:
  51. case (int)PL_OUTPUT_VIA_CUSTOM_ROUTINES_TO_NON_STREAM:
  52. /* Plotter does its own output, and doesn't use libplot's
  53. plOutbuf-based output system. So do nothing. */
  54. break;
  55. default: /* shouldn't happen */
  56. break;
  57. }
  58. /* Invoke Plotter-specific method to do device-dependent aspects of page
  59. erasure. For example, reset the elements of the Plotter that keep
  60. track of the output device's graphics state to their default
  61. values. */
  62. retval1 = _plotter->erase_page (S___(_plotter));
  63. /* if Plotter is using custom output routines, and is, or could be,
  64. drawing graphics in real time, flush out the erasure */
  65. if (_plotter->data->output_model ==
  66. PL_OUTPUT_VIA_CUSTOM_ROUTINES_IN_REAL_TIME
  67. || _plotter->data->output_model ==
  68. PL_OUTPUT_VIA_CUSTOM_ROUTINES_TO_NON_STREAM)
  69. retval2 = _API_flushpl (S___(_plotter));
  70. /* on to next frame */
  71. _plotter->data->frame_number++;
  72. return (retval1 == true && retval2 == 0 ? 0 : -1);
  73. }
  74. /* Plotter-specific things that take place when erase() is invoked. In a
  75. generic Plotter, this does nothing. */
  76. bool
  77. _pl_g_erase_page (S___(Plotter *_plotter))
  78. {
  79. return true;
  80. }