Picture.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #ifndef _Picture_h_
  2. #define _Picture_h_
  3. /* Picture.h
  4. *
  5. * Copyright (C) 1992-2005,2007-2016,2018 Paul Boersma
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /* A self-recording picture inside a DrawingArea widget.
  21. All drawing is kept in a Graphics.
  22. If the picture is sensitive,
  23. the user can select the viewport by dragging the mouse across the drawing area.
  24. If the viewport is smaller than the entire drawing area, it is highlighted.
  25. Usage:
  26. You should put highlighting off during drawing.
  27. Do not use the workstation Graphics routines,
  28. like clearWs, flushWs, closeWs, updateWs, setWsViewport.
  29. Example:
  30. Picture p = Picture_create (myDrawingArea);
  31. Graphics g = Picture_peekGraphics (p);
  32. Picture_unhighlight (p);
  33. Graphics_setTextAlignment (g, Graphics_CENTRE, Graphics_HALF);
  34. Graphics_text (g, 0.5, 0.7, U"Hello");
  35. Graphics_text (g, 0.5, 0.6, U"there");
  36. Picture_highlight (p);
  37. ... (event handling)
  38. Picture_unhighlight (p);
  39. Graphics_text (g, 0.5, 0.3, U"Goodbye");
  40. Picture_highlight (p);
  41. ... (event handling)
  42. Picture_writeToEpsFile (p, U"HelloGoodbye.eps", false, false);
  43. Picture_print (p, GraphicsPostscript_FINE);
  44. Picture_remove (& p);
  45. */
  46. #include "Gui.h"
  47. Thing_define (Picture, Thing) {
  48. GuiDrawingArea drawingArea;
  49. autoGraphics graphics, selectionGraphics;
  50. bool sensitive;
  51. double selx1, selx2, sely1, sely2; // selection in NDC co-ordinates
  52. void (*selectionChangedCallback) (Picture, void *, double, double, double, double);
  53. void *selectionChangedClosure;
  54. bool backgrounding, mouseSelectsInnerViewport;
  55. void v_destroy () noexcept
  56. override;
  57. };
  58. autoPicture Picture_create (GuiDrawingArea drawingArea, bool sensitive);
  59. /*
  60. Function:
  61. create an empty self-recording picture inside 'drawingArea'.
  62. Precondition:
  63. 'drawingArea' must have been realized.
  64. Postconditions:
  65. a Graphics has been created from Graphics_create_macintosh or Graphics_create_xwindow;
  66. the workstation viewport of this Graphics is [0, 1] x [0, 1];
  67. selection is [0, 1] x [0, 1] (NDC), which is invisible;
  68. */
  69. Graphics Picture_peekGraphics (Picture me);
  70. /*
  71. Function:
  72. return the Graphics object.
  73. Usage:
  74. send the graphics output that you want to be in the picture to this Graphics,
  75. bracketed by calls to Picture_startRecording and Picture_stopRecording.
  76. */
  77. void Picture_unhighlight (Picture me);
  78. /*
  79. Function:
  80. hide the viewport.
  81. Usage:
  82. call just before sending graphics output.
  83. */
  84. void Picture_highlight (Picture me);
  85. /*
  86. Function:
  87. visualize the viewport.
  88. Usage:
  89. call just after sending graphics output.
  90. */
  91. void Picture_setSelectionChangedCallback (Picture me,
  92. void (*selectionChangedCallback) (Picture, void *closure,
  93. double x1NDC, double x2NDC, double y1NDC, double y2NDC),
  94. void *selectionChangedClosure);
  95. void Picture_setMouseSelectsInnerViewport (Picture me, int mouseSelectsInnerViewport);
  96. void Picture_erase (Picture me); // clears the screen
  97. void Picture_writeToPraatPictureFile (Picture me, MelderFile file);
  98. void Picture_readFromPraatPictureFile (Picture me, MelderFile file);
  99. void Picture_writeToEpsFile (Picture me, MelderFile file, bool includeFonts, bool useSilipaPS);
  100. void Picture_writeToPdfFile (Picture me, MelderFile file);
  101. void Picture_writeToPngFile_300 (Picture me, MelderFile file);
  102. void Picture_writeToPngFile_600 (Picture me, MelderFile file);
  103. void Picture_print (Picture me);
  104. void Picture_printToPostScriptPrinter (Picture me, int spots, int paperSize, int rotation, double magnification);
  105. #ifdef macintosh
  106. void Picture_copyToClipboard (Picture me);
  107. #endif
  108. #ifdef _WIN32
  109. void Picture_copyToClipboard (Picture me);
  110. void Picture_writeToWindowsMetafile (Picture me, MelderFile file);
  111. #endif
  112. void Picture_setSelection
  113. (Picture me, double x1NDC, double x2NDC, double y1NDC, double y2NDC, bool notify);
  114. /*
  115. Preconditions:
  116. 0.0 <= x1NDC < x2NDC <= 1.0;
  117. 0.0 <= y1NDC < y2NDC <= 1.0;
  118. */
  119. void Picture_background (Picture me);
  120. void Picture_foreground (Picture me);
  121. /* End of file Picture.h */
  122. #endif