| 1 | #ifndef _Picture_h_ |
| 2 | #define _Picture_h_ |
| 3 | /* Picture.h |
| 4 | * |
| 5 | * Copyright (C) 1992-2005,2007-2016,2018,2020,2022,2025 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 3 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 | |
| 21 | /* A self-recording picture inside a DrawingArea widget. |
| 22 | All drawing is kept in a Graphics. |
| 23 | If the picture is sensitive, |
| 24 | the user can select the viewport by dragging the mouse across the drawing area. |
| 25 | If the viewport is smaller than the entire drawing area, it is highlighted. |
| 26 | Usage: |
| 27 | Do not use the workstation Graphics routines, |
| 28 | like clearWs, flushWs, closeWs, updateWs, setWsViewport. |
| 29 | Example: |
| 30 | autoPicture p = Picture_create (myDrawingArea); |
| 31 | Graphics g = Picture_peekGraphics (p.get()); |
| 32 | Graphics_setTextAlignment (g, Graphics_CENTRE, Graphics_HALF); |
| 33 | Graphics_text (g, 0.5, 0.7, U"Hello"); |
| 34 | Graphics_text (g, 0.5, 0.6, U"there"); |
| 35 | Graphics_text (g, 0.5, 0.3, U"Goodbye"); |
| 36 | Picture_writeToPngFile_300 (p, U"HelloGoodbye.png"); |
| 37 | Picture_print (p.get()); |
| 38 | */ |
| 39 | |
| 40 | #include "Gui.h" |
| 41 | |
| 42 | Thing_define (Picture, Thing) { |
| 43 | GuiDrawingArea drawingArea; |
| 44 | autoGraphics graphics, selectionGraphics; |
| 45 | bool sensitive; |
| 46 | double selx1, selx2, sely1, sely2; // selection in NDC co-ordinates |
| 47 | void (*selectionChangedCallback) (Picture, void *, double, double, double, double); |
| 48 | void *selectionChangedClosure; |
| 49 | bool mouseSelectsInnerViewport; |
| 50 | }; |
| 51 | |
| 52 | /* |
| 53 | The drawing area is a rectangle measuring 60x60 inches. |
| 54 | */ |
| 55 | constexpr double Picture_WIDTH = 60.0; |
| 56 | constexpr double Picture_HEIGHT = 60.0; |
| 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 | |
| 70 | Graphics Picture_peekGraphics (Picture me); |
| 71 | /* |
| 72 | Function: |
| 73 | return the Graphics object. |
| 74 | Usage: |
| 75 | send the graphics output that you want to be in the picture to this Graphics, |
| 76 | bracketed by calls to Picture_startRecording and Picture_stopRecording. |
| 77 | */ |
| 78 | |
| 79 | void Picture_setSelectionChangedCallback (Picture me, |
| 80 | void (*selectionChangedCallback) (Picture, void *closure, |
| 81 | double x1NDC, double x2NDC, double y1NDC, double y2NDC), |
| 82 | void *selectionChangedClosure); |
| 83 | |
| 84 | void Picture_setMouseSelectsInnerViewport (Picture me, int mouseSelectsInnerViewport); |
| 85 | |
| 86 | void Picture_erase (Picture me); // clears the screen |
| 87 | |
| 88 | void Picture_writeToPraatPictureFile (Picture me, MelderFile file); |
| 89 | void Picture_readFromPraatPictureFile (Picture me, MelderFile file); |
| 90 | |
| 91 | void Picture_writeToEpsFile (Picture me, MelderFile file, bool includeFonts, bool useSilipaPS); |
| 92 | void Picture_writeToPdfFile (Picture me, MelderFile file); |
| 93 | void Picture_writeToPngFile_300 (Picture me, MelderFile file); |
| 94 | void Picture_writeToPngFile_600 (Picture me, MelderFile file); |
| 95 | |
| 96 | void Picture_print (Picture me); |
| 97 | void Picture_printToPostScriptPrinter (Picture me, int spots, int paperSize, int rotation, double magnification); |
| 98 | #ifdef macintosh |
| 99 | void Picture_copyToClipboard (Picture me); |
| 100 | #endif |
| 101 | #ifdef _WIN32 |
| 102 | void Picture_copyToClipboard (Picture me); |
| 103 | void Picture_writeToWindowsMetafile (Picture me, MelderFile file); |
| 104 | #endif |
| 105 | |
| 106 | void Picture_setSelection |
| 107 | (Picture me, double x1NDC, double x2NDC, double y1NDC, double y2NDC); |
| 108 | /* |
| 109 | Preconditions: |
| 110 | 0.0 <= x1NDC < x2NDC <= 1.0; |
| 111 | 0.0 <= y1NDC < y2NDC <= 1.0; |
| 112 | */ |
| 113 | |
| 114 | /* End of file Picture.h */ |
| 115 | #endif // !_Picture_h_ |