Debian Codegraph @

sys/praat_picture.cpp

raw
1 /* praat_picture.cpp
2 *
3 * Copyright (C) 1992-2025 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "praatP.h"
20 #include "praatM.h"
21 #include "Picture.h"
22 #include "Printer.h"
23 #include "machine.h"
24 #include "Formula.h"
25 #include "site.h"
26
27 #include "GuiP.h"
28 #include "DemoEditor.h"
29
30 #pragma mark - Saved settings
31
32 static bool praat_mouseSelectsInnerViewport;
33
34 void praat_picture_prefs () {
35 Preferences_addEnum (U"Picture.font", & theCurrentPraatPicture -> font, kGraphics_font, kGraphics_font::DEFAULT);
36 Preferences_addDouble (U"Picture.fontSize", & theCurrentPraatPicture -> fontSize, 10.0);
37 Preferences_addBool (U"Picture.mouseSelectsInnerViewport", & praat_mouseSelectsInnerViewport, false);
38 }
39
40 #pragma mark - Singletons
41
42 static autoPicture praat_picture;
43
44 /********** CALLBACKS OF THE PICTURE MENUS **********/
45
46 #pragma mark - Font menu: font part
47
48 static GuiMenuItem praatButton_fonts [1 + (int) kGraphics_font::MAX];
49
50 static void updateFontMenu () {
51 if (! theCurrentPraatApplication -> batch) {
52 Melder_clip ((int) kGraphics_font::MIN, (int *) & theCurrentPraatPicture -> font, (int) kGraphics_font::MAX);
53 for (int i = (int) kGraphics_font::MIN; i <= (int) kGraphics_font::MAX; i ++)
54 GuiMenuItem_check (praatButton_fonts [i], (int) theCurrentPraatPicture -> font == i);
55 }
56 }
57 static void GRAPHICS_NONE__Times ();
58 DIRECT (GRAPHICS_NONE__Times) {
59 GRAPHICS_NONE
60 Graphics_setFont (GRAPHICS, theCurrentPraatPicture -> font = kGraphics_font::TIMES);
61 GRAPHICS_NONE_END
62 if (theCurrentPraatPicture == & theForegroundPraatPicture)
63 updateFontMenu ();
64 }
65 DIRECT (GRAPHICS_NONE__Helvetica) {
66 GRAPHICS_NONE
67 Graphics_setFont (GRAPHICS, theCurrentPraatPicture -> font = kGraphics_font::HELVETICA);
68 GRAPHICS_NONE_END
69 if (theCurrentPraatPicture == & theForegroundPraatPicture)
70 updateFontMenu ();
71 }
72 DIRECT (GRAPHICS_NONE__Palatino) {
73 GRAPHICS_NONE
74 Graphics_setFont (GRAPHICS, theCurrentPraatPicture -> font = kGraphics_font::PALATINO);
75 GRAPHICS_NONE_END
76 if (theCurrentPraatPicture == & theForegroundPraatPicture)
77 updateFontMenu ();
78 }
79 DIRECT (GRAPHICS_NONE__Courier) {
80 GRAPHICS_NONE
81 Graphics_setFont (GRAPHICS, theCurrentPraatPicture -> font = kGraphics_font::COURIER);
82 GRAPHICS_NONE_END
83 if (theCurrentPraatPicture == & theForegroundPraatPicture)
84 updateFontMenu ();
85 }
86
87 #pragma mark - Font menu: size part
88
89 static GuiMenuItem praatButton_10, praatButton_12, praatButton_14, praatButton_18, praatButton_24;
90
91 static void updateSizeMenu () {
92 if (! theCurrentPraatApplication -> batch) {
93 GuiMenuItem_check (praatButton_10, theCurrentPraatPicture -> fontSize == 10.0);
94 GuiMenuItem_check (praatButton_12, theCurrentPraatPicture -> fontSize == 12.0);
95 GuiMenuItem_check (praatButton_14, theCurrentPraatPicture -> fontSize == 14.0);
96 GuiMenuItem_check (praatButton_18, theCurrentPraatPicture -> fontSize == 18.0);
97 GuiMenuItem_check (praatButton_24, theCurrentPraatPicture -> fontSize == 24.0);
98 }
99 }
100 DIRECT (GRAPHICS_10) {
101 GRAPHICS_NONE
102 Graphics_setFontSize (GRAPHICS, theCurrentPraatPicture -> fontSize = 10.0);
103 GRAPHICS_NONE_END
104 if (theCurrentPraatPicture == & theForegroundPraatPicture)
105 updateSizeMenu ();
106 }
107 DIRECT (GRAPHICS_12) {
108 GRAPHICS_NONE
109 Graphics_setFontSize (GRAPHICS, theCurrentPraatPicture -> fontSize = 12.0);
110 GRAPHICS_NONE_END
111 if (theCurrentPraatPicture == & theForegroundPraatPicture)
112 updateSizeMenu ();
113 }
114 DIRECT (GRAPHICS_14) {
115 GRAPHICS_NONE
116 Graphics_setFontSize (GRAPHICS, theCurrentPraatPicture -> fontSize = 14.0);
117 GRAPHICS_NONE_END
118 if (theCurrentPraatPicture == & theForegroundPraatPicture)
119 updateSizeMenu ();
120 }
121 DIRECT (GRAPHICS_18) {
122 GRAPHICS_NONE
123 Graphics_setFontSize (GRAPHICS, theCurrentPraatPicture -> fontSize = 18.0);
124 GRAPHICS_NONE_END
125 if (theCurrentPraatPicture == & theForegroundPraatPicture)
126 updateSizeMenu ();
127 }
128 DIRECT (GRAPHICS_24) {
129 GRAPHICS_NONE
130 Graphics_setFontSize (GRAPHICS, theCurrentPraatPicture -> fontSize = 24.0);
131 GRAPHICS_NONE_END
132 if (theCurrentPraatPicture == & theForegroundPraatPicture)
133 updateSizeMenu ();
134 }
135 FORM (GRAPHICS_Font_size, U"Praat picture: Font size", U"Font menu") {
136 POSITIVE (fontSize, U"Font size (points)", U"10")
137 OK
138 SET_REAL (fontSize, (integer) theCurrentPraatPicture -> fontSize);
139 DO
140 GRAPHICS_NONE
141 Graphics_setFontSize (GRAPHICS, theCurrentPraatPicture -> fontSize = fontSize);
142 GRAPHICS_NONE_END
143 if (theCurrentPraatPicture == & theForegroundPraatPicture)
144 updateSizeMenu ();
145 }
146
147 /*static void setFontSize_keepInnerViewport (int fontSize) {
148 double xmargin = praat_size * 4.2 / 72.0, ymargin = praat_size * 2.8 / 72.0;
149 if (xmargin > 0.4 * (x2NDC - x1NDC)) xmargin = 0.4 * (x2NDC - x1NDC);
150 if (ymargin > 0.4 * (y2NDC - y1NDC)) ymargin = 0.4 * (y2NDC - y1NDC);
151 x1NDC += xmargin;
152 x2NDC -= xmargin;
153 y1NDC += ymargin;
154 y2NDC -= ymargin;
155 xmargin = fontSize * 4.2 / 72.0, ymargin = fontSize * 2.8 / 72.0;
156 if (xmargin > 2 * (x2NDC - x1NDC)) xmargin = 2 * (x2NDC - x1NDC);
157 if (ymargin > 2 * (y2NDC - y1NDC)) ymargin = 2 * (y2NDC - y1NDC);
158 x1NDC -= xmargin;
159 x2NDC += xmargin;
160 y1NDC -= ymargin;
161 y2NDC += ymargin;
162 {
163 autoPraatPictureOpen picture;
164 Graphics_setFontSize (GRAPHICS, praat_size = fontSize);
165 }
166 Picture_setSelection (praat_picture.get(), x1NDC, x2NDC, y1NDC, y2NDC);
167 updateSizeMenu ();
168 }*/
169
170 #pragma mark - Select menu
171
172 static GuiMenuItem praatButton_innerViewport, praatButton_outerViewport;
173
174 static void updateViewportMenu () {
175 if (! theCurrentPraatApplication -> batch) {
176 GuiMenuItem_check (praatButton_innerViewport, praat_mouseSelectsInnerViewport ? 1 : 0);
177 GuiMenuItem_check (praatButton_outerViewport, praat_mouseSelectsInnerViewport ? 0 : 1);
178 }
179 }
180
181 DIRECT (GRAPHICS_MouseSelectsInnerViewport) {
182 if (theCurrentPraatPicture != & theForegroundPraatPicture)
183 Melder_throw (U"Mouse commands are not available inside pictures.");
184 {// scope
185 autoPraatPictureOpen picture;
186 Picture_setMouseSelectsInnerViewport (praat_picture.get(), praat_mouseSelectsInnerViewport = true);
187 }
188 updateViewportMenu ();
189 END_NO_NEW_DATA
190 }
191
192 DIRECT (GRAPHICS_MouseSelectsOuterViewport) {
193 if (theCurrentPraatPicture != & theForegroundPraatPicture)
194 Melder_throw (U"Mouse commands are not available inside pictures.");
195 {// scope
196 autoPraatPictureOpen picture;
197 Picture_setMouseSelectsInnerViewport (praat_picture.get(), praat_mouseSelectsInnerViewport = false);
198 }
199 updateViewportMenu ();
200 END_NO_NEW_DATA
201 }
202
203 FORM (GRAPHICS_SelectInnerViewport, U"Praat picture: Select inner viewport", U"Select inner viewport...") {
204 COMMENT (U"The viewport is the selected rectangle in the Picture window.")
205 COMMENT (U"It is where your next drawing will appear.")
206 COMMENT (U"The rectangle you select here will not include the margins.")
207 COMMENT (U"")
208 REAL (left, U"left Horizontal range (inches)", U"0.0")
209 REAL (right, U"right Horizontal range (inches)", U"6.0")
210 REAL (top, U"left Vertical range (inches)", U"0.0")
211 REAL (bottom, U"right Vertical range (inches)", U"6.0")
212 OK
213 double xmargin = theCurrentPraatPicture -> fontSize * 4.2 / 72.0, ymargin = theCurrentPraatPicture -> fontSize * 2.8 / 72.0;
214 Melder_clipRight (& ymargin, 0.4 * (theCurrentPraatPicture -> y2NDC - theCurrentPraatPicture -> y1NDC));
215 Melder_clipRight (& xmargin, 0.4 * (theCurrentPraatPicture -> x2NDC - theCurrentPraatPicture -> x1NDC));
216 SET_REAL (left, theCurrentPraatPicture -> x1NDC + xmargin)
217 SET_REAL (right, theCurrentPraatPicture -> x2NDC - xmargin)
218 SET_REAL (top, Picture_HEIGHT - theCurrentPraatPicture -> y2NDC + ymargin)
219 SET_REAL (bottom, Picture_HEIGHT - theCurrentPraatPicture -> y1NDC - ymargin)
220 DO
221 //Melder_require (praat_commandsWithExternalSideEffectsAreAllowed (), U"Viewport commands are not available inside manuals.");
222 double xmargin = theCurrentPraatPicture -> fontSize * 4.2 / 72.0, ymargin = theCurrentPraatPicture -> fontSize * 2.8 / 72.0;
223 trace (U"1: xmargin ", xmargin, U" ymargin ", ymargin);
224 if (theCurrentPraatPicture != & theForegroundPraatPicture) {
225 integer x1DC, x2DC, y1DC, y2DC;
226 Graphics_inqWsViewport (GRAPHICS, & x1DC, & x2DC, & y1DC, & y2DC);
227 double x1wNDC, x2wNDC, y1wNDC, y2wNDC;
228 Graphics_inqWsWindow (GRAPHICS, & x1wNDC, & x2wNDC, & y1wNDC, & y2wNDC);
229 const double wDC = (x2DC - x1DC) / (x2wNDC - x1wNDC);
230 const double hDC = integer_abs (y2DC - y1DC) / (y2wNDC - y1wNDC);
231 xmargin *= Graphics_getResolution (GRAPHICS) / wDC;
232 ymargin *= Graphics_getResolution (GRAPHICS) / hDC;
233 }
234 Melder_clipRight (& xmargin, 2.0 * (right - left));
235 Melder_clipRight (& ymargin, 2.0 * (bottom - top));
236 trace (U"2: xmargin ", xmargin, U" ymargin ", ymargin);
237 if (left == right)
238 Melder_throw (U"The left and right edges of the viewport cannot be equal.\nPlease change the horizontal range.");
239 Melder_sort (& left, & right);
240 if (top == bottom)
241 Melder_throw (U"The top and bottom edges of the viewport cannot be equal.\nPlease change the vertical range.");
242 theCurrentPraatPicture -> x1NDC = left - xmargin;
243 theCurrentPraatPicture -> x2NDC = right + xmargin;
244 if (theCurrentPraatPicture == & theForegroundPraatPicture) {
245 Melder_sort (& top, & bottom);
246 theCurrentPraatPicture -> y1NDC = (Picture_HEIGHT - bottom) - ymargin;
247 theCurrentPraatPicture -> y2NDC = (Picture_HEIGHT - top) + ymargin;
248 Picture_setSelection (praat_picture.get(), theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC,
249 theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
250 Graphics_updateWs (GRAPHICS);
251 } else if (theCurrentPraatObjects != & theForegroundPraatObjects) { // in manual?
252 Melder_sort (& top, & bottom);
253 double x1wNDC, x2wNDC, y1wNDC, y2wNDC;
254 Graphics_inqWsWindow (GRAPHICS, & x1wNDC, & x2wNDC, & y1wNDC, & y2wNDC);
255 const double height_NDC = y2wNDC - y1wNDC;
256 theCurrentPraatPicture -> y1NDC = height_NDC - bottom - ymargin;
257 theCurrentPraatPicture -> y2NDC = height_NDC - top + ymargin;
258 } else {
259 Melder_sort (& bottom, & top);
260 theCurrentPraatPicture -> y1NDC = bottom - ymargin;
261 theCurrentPraatPicture -> y2NDC = top + ymargin;
262 Graphics_setViewport (GRAPHICS,
263 theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC,
264 theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC
265 ); // to ensure that Demo_x() updates
266 }
267 trace (U"3:"
268 U" x1NDC ", theCurrentPraatPicture -> x1NDC,
269 U" x2NDC ", theCurrentPraatPicture -> x2NDC,
270 U" y1NDC ", theCurrentPraatPicture -> y1NDC,
271 U" y2NDC ", theCurrentPraatPicture -> y2NDC
272 );
273 END_NO_NEW_DATA
274 }
275
276 FORM (GRAPHICS_SelectOuterViewport, U"Praat picture: Select outer viewport", U"Select outer viewport...") {
277 COMMENT (U"The viewport is the selected rectangle in the Picture window.")
278 COMMENT (U"It is where your next drawing will appear.")
279 COMMENT (U"The rectangle you select here will include the margins.")
280 COMMENT (U"")
281 REAL (left, U"left Horizontal range (inches)", U"0.0")
282 REAL (right, U"right Horizontal range (inches)", U"6.0")
283 REAL (top, U"left Vertical range (inches)", U"0.0")
284 REAL (bottom, U"right Vertical range (inches)", U"6.0")
285 OK
286 SET_REAL (left, theCurrentPraatPicture -> x1NDC)
287 SET_REAL (right, theCurrentPraatPicture -> x2NDC)
288 SET_REAL (top, Picture_HEIGHT - theCurrentPraatPicture -> y2NDC)
289 SET_REAL (bottom, Picture_HEIGHT - theCurrentPraatPicture -> y1NDC)
290 DO
291 //Melder_require (praat_commandsWithExternalSideEffectsAreAllowed (), U"Viewport commands are not available inside manuals.");
292 if (left == right)
293 Melder_throw (U"The left and right edges of the viewport cannot be equal.\nPlease change the horizontal range.");
294 Melder_sort (& left, & right);
295 if (top == bottom)
296 Melder_throw (U"The top and bottom edges of the viewport cannot be equal.\nPlease change the vertical range.");
297 theCurrentPraatPicture -> x1NDC = left;
298 theCurrentPraatPicture -> x2NDC = right;
299 if (theCurrentPraatPicture == & theForegroundPraatPicture) {
300 Melder_sort (& top, & bottom);
301 theCurrentPraatPicture -> y1NDC = Picture_HEIGHT - bottom;
302 theCurrentPraatPicture -> y2NDC = Picture_HEIGHT - top;
303 Picture_setSelection (praat_picture.get(), theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC,
304 theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
305 Graphics_updateWs (GRAPHICS);
306 } else if (theCurrentPraatObjects != & theForegroundPraatObjects) { // in manual?
307 Melder_sort (& top, & bottom);
308 double x1wNDC, x2wNDC, y1wNDC, y2wNDC;
309 Graphics_inqWsWindow (GRAPHICS, & x1wNDC, & x2wNDC, & y1wNDC, & y2wNDC);
310 const double height_NDC = y2wNDC - y1wNDC;
311 theCurrentPraatPicture -> y1NDC = height_NDC - bottom;
312 theCurrentPraatPicture -> y2NDC = height_NDC - top;
313 } else {
314 Melder_sort (& bottom, & top);
315 theCurrentPraatPicture -> y1NDC = bottom;
316 theCurrentPraatPicture -> y2NDC = top;
317 Graphics_setViewport (GRAPHICS,
318 theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC,
319 theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC
320 ); // to ensure that Demo_x() updates
321 }
322 END_NO_NEW_DATA
323 }
324
325 FORM (GRAPHICS_ViewportText, U"Praat picture: Viewport text", U"Viewport text...") {
326 CHOICEx (horizontalAlignment, U"Horizontal alignment", 2, 0)
327 OPTION (U"left")
328 OPTION (U"centre")
329 OPTION (U"right")
330 CHOICEx (verticalAlignment, U"Vertical alignment", 2, 0)
331 OPTION (U"bottom")
332 OPTION (U"half")
333 OPTION (U"top")
334 REAL (rotation, U"Rotation (degrees)", U"0")
335 TEXTFIELD (text, U"Text", U"", 3)
336 OK
337 DO
338 double x1WC, x2WC, y1WC, y2WC;
339 autoPraatPictureOpen picture;
340 Graphics_inqWindow (GRAPHICS, & x1WC, & x2WC, & y1WC, & y2WC);
341 Graphics_setWindow (GRAPHICS, 0, 1, 0, 1);
342 Graphics_setTextAlignment (GRAPHICS, (kGraphics_horizontalAlignment) horizontalAlignment, verticalAlignment);
343 Graphics_setTextRotation (GRAPHICS, rotation);
344 Graphics_text (GRAPHICS, horizontalAlignment == 0 ? 0.0 : horizontalAlignment == 1 ? 0.5 : 1.0,
345 verticalAlignment == 0 ? 0.0 : verticalAlignment == 1 ? 0.5 : 1.0, text);
346 Graphics_setTextRotation (GRAPHICS, 0.0);
347 Graphics_setWindow (GRAPHICS, x1WC, x2WC, y1WC, y2WC);
348 END_NO_NEW_DATA
349 }
350
351 #pragma mark - Pen menu
352
353 static GuiMenuItem praatButton_lines [4];
354 static GuiMenuItem praatButton_black, praatButton_white, praatButton_red, praatButton_green, praatButton_blue,
355 praatButton_yellow, praatButton_cyan, praatButton_magenta, praatButton_maroon, praatButton_lime, praatButton_navy,
356 praatButton_teal, praatButton_purple, praatButton_olive, praatButton_pink, praatButton_silver, praatButton_grey;
357
358 static void updatePenMenu () {
359 if (! theCurrentPraatApplication -> batch) {
360 for (int i = Graphics_DRAWN; i <= Graphics_DASHED; i ++)
361 GuiMenuItem_check (praatButton_lines [i], theCurrentPraatPicture -> lineType == i);
362 GuiMenuItem_check (praatButton_black , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_BLACK));
363 GuiMenuItem_check (praatButton_white , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_WHITE));
364 GuiMenuItem_check (praatButton_red , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_RED));
365 GuiMenuItem_check (praatButton_green , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_GREEN));
366 GuiMenuItem_check (praatButton_blue , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_BLUE));
367 GuiMenuItem_check (praatButton_yellow , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_YELLOW));
368 GuiMenuItem_check (praatButton_cyan , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_CYAN));
369 GuiMenuItem_check (praatButton_magenta , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_MAGENTA));
370 GuiMenuItem_check (praatButton_maroon , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_MAROON));
371 GuiMenuItem_check (praatButton_lime , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_LIME));
372 GuiMenuItem_check (praatButton_navy , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_NAVY));
373 GuiMenuItem_check (praatButton_teal , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_TEAL));
374 GuiMenuItem_check (praatButton_purple , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_PURPLE));
375 GuiMenuItem_check (praatButton_olive , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_OLIVE));
376 GuiMenuItem_check (praatButton_pink , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_PINK));
377 GuiMenuItem_check (praatButton_silver , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_SILVER));
378 GuiMenuItem_check (praatButton_grey , MelderColour_equal (theCurrentPraatPicture -> colour, Melder_GREY));
379 }
380 }
381
382 DIRECT (GRAPHICS_Solid_line) {
383 GRAPHICS_NONE
384 Graphics_setLineType (GRAPHICS, theCurrentPraatPicture -> lineType = Graphics_DRAWN);
385 GRAPHICS_NONE_END
386 if (theCurrentPraatPicture == & theForegroundPraatPicture)
387 updatePenMenu ();
388 }
389 DIRECT (GRAPHICS_Dotted_line) {
390 GRAPHICS_NONE
391 Graphics_setLineType (GRAPHICS, theCurrentPraatPicture -> lineType = Graphics_DOTTED);
392 GRAPHICS_NONE_END
393 if (theCurrentPraatPicture == & theForegroundPraatPicture)
394 updatePenMenu ();
395 }
396 DIRECT (GRAPHICS_Dashed_line) {
397 GRAPHICS_NONE
398 Graphics_setLineType (GRAPHICS, theCurrentPraatPicture -> lineType = Graphics_DASHED);
399 GRAPHICS_NONE_END
400 if (theCurrentPraatPicture == & theForegroundPraatPicture)
401 updatePenMenu ();
402 }
403 DIRECT (GRAPHICS_Dashed_dotted_line) {
404 GRAPHICS_NONE
405 Graphics_setLineType (GRAPHICS, theCurrentPraatPicture -> lineType = Graphics_DASHED_DOTTED);
406 GRAPHICS_NONE_END
407 if (theCurrentPraatPicture == & theForegroundPraatPicture)
408 updatePenMenu ();
409 }
410
411 FORM (GRAPHICS_Line_width, U"Praat picture: Line width", nullptr) {
412 POSITIVE (lineWidth, U"Line width", U"1.0")
413 OK
414 SET_REAL (lineWidth, theCurrentPraatPicture -> lineWidth)
415 DO
416 GRAPHICS_NONE
417 Graphics_setLineWidth (GRAPHICS, theCurrentPraatPicture -> lineWidth = lineWidth);
418 GRAPHICS_NONE_END
419 }
420
421 FORM (GRAPHICS_Arrow_size, U"Praat picture: Arrow size", nullptr) {
422 POSITIVE (arrowSize, U"Arrow size", U"1.0")
423 OK
424 SET_REAL (arrowSize, theCurrentPraatPicture -> arrowSize)
425 DO
426 GRAPHICS_NONE
427 Graphics_setArrowSize (GRAPHICS, theCurrentPraatPicture -> arrowSize = arrowSize);
428 GRAPHICS_NONE_END
429 }
430
431 FORM (GRAPHICS_Speckle_size, U"Praat picture: Speckle size", nullptr) {
432 COMMENT (U"Here you determine the diameter (in millimetres)")
433 COMMENT (U"of the dots that are drawn by \"speckle\" commands.")
434 POSITIVE (speckleSize, U"Speckle size (mm)", U"1.0")
435 OK
436 SET_REAL (speckleSize, theCurrentPraatPicture -> speckleSize)
437 DO
438 GRAPHICS_NONE
439 Graphics_setSpeckleSize (GRAPHICS, theCurrentPraatPicture -> speckleSize = speckleSize);
440 GRAPHICS_NONE_END
441 }
442
443 static void setColour (MelderColour colour) {
444 {// scope
445 autoPraatPictureOpen picture;
446 Graphics_setColour (GRAPHICS, colour);
447 }
448 theCurrentPraatPicture -> colour = colour;
449 if (theCurrentPraatPicture == & theForegroundPraatPicture)
450 updatePenMenu ();
451 }
452 DIRECT (GRAPHICS_Black) { setColour (Melder_BLACK); END_NO_NEW_DATA }
453 DIRECT (GRAPHICS_White) { setColour (Melder_WHITE); END_NO_NEW_DATA }
454 DIRECT (GRAPHICS_Red) { setColour (Melder_RED); END_NO_NEW_DATA }
455 DIRECT (GRAPHICS_Green) { setColour (Melder_GREEN); END_NO_NEW_DATA }
456 DIRECT (GRAPHICS_Blue) { setColour (Melder_BLUE); END_NO_NEW_DATA }
457 DIRECT (GRAPHICS_Yellow) { setColour (Melder_YELLOW); END_NO_NEW_DATA }
458 DIRECT (GRAPHICS_Cyan) { setColour (Melder_CYAN); END_NO_NEW_DATA }
459 DIRECT (GRAPHICS_Magenta) { setColour (Melder_MAGENTA); END_NO_NEW_DATA }
460 DIRECT (GRAPHICS_Maroon) { setColour (Melder_MAROON); END_NO_NEW_DATA }
461 DIRECT (GRAPHICS_Lime) { setColour (Melder_LIME); END_NO_NEW_DATA }
462 DIRECT (GRAPHICS_Navy) { setColour (Melder_NAVY); END_NO_NEW_DATA }
463 DIRECT (GRAPHICS_Teal) { setColour (Melder_TEAL); END_NO_NEW_DATA }
464 DIRECT (GRAPHICS_Purple) { setColour (Melder_PURPLE); END_NO_NEW_DATA }
465 DIRECT (GRAPHICS_Olive) { setColour (Melder_OLIVE); END_NO_NEW_DATA }
466 DIRECT (GRAPHICS_Pink) { setColour (Melder_PINK); END_NO_NEW_DATA }
467 DIRECT (GRAPHICS_Silver) { setColour (Melder_SILVER); END_NO_NEW_DATA }
468 DIRECT (GRAPHICS_Grey) { setColour (Melder_GREY); END_NO_NEW_DATA }
469
470 FORM (GRAPHICS_Colour, U"Praat picture: Colour", nullptr) {
471 COLOUR (colour, U"Colour (0-1, name, or {r,g,b})", U"0.0")
472 OK
473 DO
474 GRAPHICS_NONE
475 Graphics_setColour (GRAPHICS, theCurrentPraatPicture -> colour = colour);
476 GRAPHICS_NONE_END
477 if (theCurrentPraatPicture == & theForegroundPraatPicture)
478 updatePenMenu ();
479 }
480
481 #pragma mark - File menu
482
483 FORM_READ (GRAPHICS_Picture_readFromPraatPictureFile, U"Read picture from praat picture file", nullptr, false) {
484 Picture_readFromPraatPictureFile (praat_picture.get(), file);
485 END_NO_NEW_DATA
486 }
487
488 FORM_SAVE (GRAPHICS_Picture_writeToEpsFile, U"Save picture as Encapsulated PostScript file", nullptr, U"praat.eps") {
489 Picture_writeToEpsFile (praat_picture.get(), file, true, false);
490 END_NO_NEW_DATA
491 }
492
493 FORM_SAVE (GRAPHICS_Picture_writeToFontlessEpsFile_xipa, U"Save as fontless EPS file", nullptr, U"praat.eps") {
494 Picture_writeToEpsFile (praat_picture.get(), file, false, false);
495 END_NO_NEW_DATA
496 }
497
498 FORM_SAVE (GRAPHICS_Picture_writeToFontlessEpsFile_silipa, U"Save as fontless EPS file", nullptr, U"praat.eps") {
499 Picture_writeToEpsFile (praat_picture.get(), file, false, true);
500 END_NO_NEW_DATA
501 }
502
503 FORM_SAVE (GRAPHICS_Picture_writeToPdfFile, U"Save as PDF file", nullptr, U"praat.pdf") {
504 if (theCurrentPraatPicture == & theForegroundPraatPicture) {
505 Picture_writeToPdfFile (praat_picture.get(), file);
506 } else {
507 try {
508 //autoPraatPictureOpen picture;
509 autoGraphics graphics = Graphics_create_pdffile (file, 300, undefined, 10.24, undefined, 7.68);
510 Graphics_play (GRAPHICS, graphics.get());
511 } catch (MelderError) {
512 Melder_throw (U"Picture not written to PDF file ", file, U".");
513 }
514 }
515 END_NO_NEW_DATA
516 }
517
518 FORM_SAVE (GRAPHICS_Picture_writeToPngFile_300, U"Save as PNG file", nullptr, U"praat.png") {
519 if (theCurrentPraatPicture == & theForegroundPraatPicture) {
520 Picture_writeToPngFile_300 (praat_picture.get(), file);
521 } else {
522 try {
523 autoGraphics graphics = Graphics_create_pngfile (file, 300, 0.0, 10.24, 0.0, 7.68);
524 Graphics_play (GRAPHICS, graphics.get());
525 } catch (MelderError) {
526 Melder_throw (U"Picture not written to PNG file ", file, U".");
527 }
528 }
529 END_NO_NEW_DATA
530 }
531
532 FORM_SAVE (GRAPHICS_Picture_writeToPngFile_600, U"Save as PNG file", nullptr, U"praat.png") {
533 if (theCurrentPraatPicture == & theForegroundPraatPicture) {
534 Picture_writeToPngFile_600 (praat_picture.get(), file);
535 } else {
536 try {
537 autoGraphics graphics = Graphics_create_pngfile (file, 600, 0.0, 10.24, 0.0, 7.68);
538 Graphics_play (GRAPHICS, graphics.get());
539 } catch (MelderError) {
540 Melder_throw (U"Picture not written to PNG file ", file, U".");
541 }
542 }
543 END_NO_NEW_DATA
544 }
545
546
547 FORM_SAVE (GRAPHICS_Picture_writeToPraatPictureFile, U"Save as Praat picture file", nullptr, U"praat.prapic") {
548 Picture_writeToPraatPictureFile (praat_picture.get(), file);
549 END_NO_NEW_DATA
550 }
551
552 #ifdef macintosh
553 DIRECT (GRAPHICS_Page_setup) {
554 Printer_pageSetup ();
555 END_NO_NEW_DATA
556 }
557 #endif
558
559 FORM (GRAPHICS_PostScript_settings, U"PostScript settings", U"PostScript settings...") {
560 #if defined (_WIN32)
561 BOOLEAN (allowDirectPostscript, U"Allow direct PostScript", true);
562 #endif
563 CHOICE_ENUM (kGraphicsPostscript_spots, greyResolution,
564 U"Grey resolution", kGraphicsPostscript_spots::DEFAULT)
565 #if defined (UNIX)
566 CHOICE_ENUM (kGraphicsPostscript_paperSize, paperSize,
567 U"Paper size", kGraphicsPostscript_paperSize::DEFAULT)
568 CHOICE_ENUM (kGraphicsPostscript_orientation, orientation,
569 U"Orientation", kGraphicsPostscript_orientation::DEFAULT)
570 POSITIVE (magnification, U"Magnification", U"1.0");
571 #if defined (linux)
572 TEXTFIELD (printCommand, U"Print command", U"lpr %s", 4)
573 #else
574 TEXTFIELD (printCommand, U"Print command", U"lp -c %s", 4)
575 #endif
576 #endif
577 CHOICE_ENUM (kGraphicsPostscript_fontChoiceStrategy, fontChoiceStrategy,
578 U"Font choice strategy", kGraphicsPostscript_fontChoiceStrategy::DEFAULT)
579 OK
580 #if defined (_WIN32)
581 SET_BOOLEAN (allowDirectPostscript, thePrinter. allowDirectPostScript)
582 #endif
583 SET_ENUM (greyResolution, kGraphicsPostscript_spots, thePrinter. spots)
584 #if defined (UNIX)
585 SET_ENUM (paperSize, kGraphicsPostscript_paperSize, thePrinter. paperSize)
586 SET_ENUM (orientation, kGraphicsPostscript_orientation, thePrinter. orientation)
587 SET_REAL (magnification, thePrinter. magnification)
588 SET_STRING (printCommand, Site_getPrintCommand ())
589 #endif
590 SET_ENUM (fontChoiceStrategy, kGraphicsPostscript_fontChoiceStrategy, thePrinter. fontChoiceStrategy)
591 DO
592 INFO_NONE
593 #if defined (_WIN32)
594 thePrinter. allowDirectPostScript = allowDirectPostscript;
595 #endif
596 thePrinter. spots = greyResolution;
597 #if defined (UNIX)
598 thePrinter. paperSize = paperSize;
599 if (thePrinter. paperSize == kGraphicsPostscript_paperSize::A3) {
600 thePrinter. paperWidth = 842 * thePrinter. resolution / 72;
601 thePrinter. paperHeight = 1191 * thePrinter. resolution / 72;
602 } else if (thePrinter. paperSize == kGraphicsPostscript_paperSize::US_LETTER) {
603 thePrinter. paperWidth = 612 * thePrinter. resolution / 72;
604 thePrinter. paperHeight = 792 * thePrinter. resolution / 72;
605 } else {
606 thePrinter. paperWidth = 595 * thePrinter. resolution / 72;
607 thePrinter. paperHeight = 842 * thePrinter. resolution / 72;
608 }
609 thePrinter. orientation = orientation;
610 thePrinter. magnification = magnification;
611 Site_setPrintCommand (printCommand);
612 #endif
613 thePrinter. fontChoiceStrategy = fontChoiceStrategy;
614 INFO_NONE_END
615 }
616
617 DIRECT (GRAPHICS_Print) {
618 Picture_print (praat_picture.get());
619 END_NO_NEW_DATA
620 }
621
622 #ifdef _WIN32
623 FORM_SAVE (GRAPHICS_Picture_writeToWindowsMetafile, U"Save as Windows metafile", nullptr, U"praat.emf") {
624 Picture_writeToWindowsMetafile (praat_picture.get(), file);
625 END_NO_NEW_DATA
626 }
627
628 #endif
629
630 #if defined (_WIN32) || defined (macintosh)
631 DIRECT (GRAPHICS_Copy_picture_to_clipboard) {
632 Picture_copyToClipboard (praat_picture.get());
633 END_NO_NEW_DATA
634 }
635 #endif
636
637 #pragma mark - Edit menu
638
639 DIRECT (GRAPHICS_Undo) {
640 Graphics_undoGroup (GRAPHICS);
641 Graphics_updateWs (GRAPHICS);
642 END_NO_NEW_DATA
643 }
644
645 DIRECT (GRAPHICS_Erase_all) {
646 //TRACE
647 if (theCurrentPraatPicture == & theForegroundPraatPicture) {
648 trace(1);
649 Picture_erase (praat_picture.get()); // this kills the recording
650 } else {
651 trace(2);
652 Graphics_clearRecording (GRAPHICS);
653 if (Demo_hasGraphics (GRAPHICS)) {
654 trace (3);
655 Graphics_clearWs (GRAPHICS);
656 }
657 }
658 END_NO_NEW_DATA
659 }
660
661 #pragma mark - World menu
662
663 FORM (GRAPHICS_Text, U"Praat picture: Text", U"Text...") {
664 REAL (horizontalPosition, U"Horizontal position", U"0.0")
665 OPTIONMENU_ENUM (kGraphics_horizontalAlignment, horizontalAlignment,
666 U"Horizontal alignment", kGraphics_horizontalAlignment::LEFT)
667 REAL (verticalPosition, U"Vertical position", U"0.0")
668 OPTIONMENUx (verticalAlignment, U"Vertical alignment", 2, 0)
669 OPTION (U"bottom")
670 OPTION (U"half")
671 OPTION (U"top")
672 TEXTFIELD (text, U"Text", U"", 4)
673 OK
674 DO
675 GRAPHICS_NONE
676 Graphics_setTextAlignment (GRAPHICS, horizontalAlignment, verticalAlignment);
677 Graphics_setInner (GRAPHICS);
678 Graphics_text (GRAPHICS, horizontalPosition, verticalPosition, text);
679 Graphics_unsetInner (GRAPHICS);
680 GRAPHICS_NONE_END
681 }
682
683 FORM (GRAPHICS_TextSpecial, U"Praat picture: Text special", nullptr) {
684 REAL (horizontalPosition, U"Horizontal position", U"0.0")
685 OPTIONMENU_ENUM (kGraphics_horizontalAlignment, horizontalAlignment,
686 U"Horizontal alignment", kGraphics_horizontalAlignment::LEFT)
687 REAL (verticalPosition, U"Vertical position", U"0.0")
688 OPTIONMENUx (verticalAlignment, U"Vertical alignment", 2, 0)
689 OPTION (U"bottom")
690 OPTION (U"half")
691 OPTION (U"top")
692 OPTIONMENU_ENUM (kGraphics_font, font, U"Font", kGraphics_font::DEFAULT)
693 POSITIVE (fontSize, U"Font size", U"10")
694 SENTENCE (rotation, U"Rotation (degrees or dx;dy)", U"0")
695 TEXTFIELD (text, U"Text", U"", 4)
696 OK
697 DO
698 kGraphics_font currentFont = Graphics_inqFont (GRAPHICS);
699 const double currentSize = Graphics_inqFontSize (GRAPHICS);
700 GRAPHICS_NONE
701 Graphics_setTextAlignment (GRAPHICS, horizontalAlignment, verticalAlignment);
702 Graphics_setInner (GRAPHICS);
703 Graphics_setFont (GRAPHICS, (kGraphics_font) font);
704 Graphics_setFontSize (GRAPHICS, fontSize);
705 const char32 *semicolon = str32chr (rotation, ';');
706 if (semicolon) {
707 conststring32 dx = rotation, dy = semicolon + 1;
708 Graphics_setTextRotation_vector (GRAPHICS, Melder_atof (dx), Melder_atof (dy));
709 } else {
710 Graphics_setTextRotation (GRAPHICS, Melder_atof (rotation));
711 }
712 Graphics_text (GRAPHICS, horizontalPosition, verticalPosition, text);
713 Graphics_setFont (GRAPHICS, currentFont);
714 Graphics_setFontSize (GRAPHICS, currentSize);
715 Graphics_setTextRotation (GRAPHICS, 0.0);
716 Graphics_unsetInner (GRAPHICS);
717 GRAPHICS_NONE_END
718 }
719
720 FORM (GRAPHICS_RectangleText_MaximalFit, U"Praat picture: Rectangle text (maximal fit)", nullptr) {
721 REAL (fromX, U"From x", U"0.0")
722 REAL (toX, U"To x", U"1.0")
723 OPTIONMENU_ENUM (kGraphics_horizontalAlignment, horizontalAlignment,
724 U"Horizontal alignment", kGraphics_horizontalAlignment::LEFT)
725 REAL (minimumHorizontalMargin_in_textHeights, U"Minimal horizontal margin (in text heights)", U"0.10")
726 REAL (minimumHorizontalMargin_mm, U"Minimal horizontal margin (mm)", U"0.5")
727 REAL (fromY, U"From y", U"0.0")
728 REAL (toY, U"To y", U"1.0")
729 OPTIONMENUx (verticalAlignment, U"Vertical alignment", 2, 0)
730 OPTION (U"bottom")
731 OPTION (U"half")
732 OPTION (U"top")
733 REAL (minimumVerticalMargin_in_textHeights, U"Minimal vertical margin (in text heights)", U"0.18")
734 REAL (minimumVerticalMargin_mm, U"Minimal vertical margin (mm)", U"0.25")
735 TEXTFIELD (text, U"Text", U"", 4)
736 OK
737 DO
738 GRAPHICS_NONE
739 Graphics_setTextAlignment (GRAPHICS, horizontalAlignment, verticalAlignment);
740 Graphics_setInner (GRAPHICS);
741 Graphics_rectangleText_maximalFit (GRAPHICS, fromX, toX, minimumHorizontalMargin_in_textHeights, minimumHorizontalMargin_mm,
742 fromY, toY, minimumVerticalMargin_in_textHeights, minimumVerticalMargin_mm, text);
743 Graphics_unsetInner (GRAPHICS);
744 GRAPHICS_NONE_END
745 }
746
747 FORM (GRAPHICS_RectangleText_WrapAndTruncate, U"Praat picture: Rectangle text (wrap & truncate)", nullptr) {
748 REAL (fromX, U"From x", U"0.0")
749 REAL (toX, U"To x", U"1.0")
750 OPTIONMENU_ENUM (kGraphics_horizontalAlignment, horizontalAlignment,
751 U"Horizontal alignment", kGraphics_horizontalAlignment::LEFT)
752 REAL (fromY, U"From y", U"0.0")
753 REAL (toY, U"To y", U"1.0")
754 OPTIONMENUx (verticalAlignment, U"Vertical alignment", 2, 0)
755 OPTION (U"bottom")
756 OPTION (U"half")
757 OPTION (U"top")
758 TEXTFIELD (text, U"Text", U"", 4)
759 OK
760 DO
761 GRAPHICS_NONE
762 Graphics_setTextAlignment (GRAPHICS, horizontalAlignment, verticalAlignment);
763 Graphics_setInner (GRAPHICS);
764 Graphics_rectangleText_wrapAndTruncate (GRAPHICS, fromX, toX, fromY, toY, text);
765 Graphics_unsetInner (GRAPHICS);
766 GRAPHICS_NONE_END
767 }
768
769 FORM (GRAPHICS_DrawLine, U"Praat picture: Draw line", nullptr) {
770 REAL (fromX, U"From x", U"0.0")
771 REAL (fromY, U"From y", U"0.0")
772 REAL (toX, U"To x", U"1.0")
773 REAL (toY, U"To y", U"1.0")
774 OK
775 DO
776 GRAPHICS_NONE
777 Graphics_setInner (GRAPHICS);
778 Graphics_line (GRAPHICS, fromX, fromY, toX, toY);
779 Graphics_unsetInner (GRAPHICS);
780 GRAPHICS_NONE_END
781 }
782
783 FORM (GRAPHICS_DrawArrow, U"Praat picture: Draw arrow", nullptr) {
784 REAL (fromX, U"From x", U"0.0")
785 REAL (fromY, U"From y", U"0.0")
786 REAL (toX, U"To x", U"1.0")
787 REAL (toY, U"To y", U"1.0")
788 OK
789 DO
790 GRAPHICS_NONE
791 Graphics_setInner (GRAPHICS);
792 Graphics_arrow (GRAPHICS, fromX, fromY, toX, toY);
793 Graphics_unsetInner (GRAPHICS);
794 GRAPHICS_NONE_END
795 }
796
797 FORM (GRAPHICS_DrawDoubleArrow, U"Praat picture: Draw double arrow", nullptr) {
798 REAL (fromX, U"From x", U"0.0")
799 REAL (fromY, U"From y", U"0.0")
800 REAL (toX, U"To x", U"1.0")
801 REAL (toY, U"To y", U"1.0")
802 OK
803 DO
804 GRAPHICS_NONE
805 Graphics_setInner (GRAPHICS);
806 Graphics_doubleArrow (GRAPHICS, fromX, fromY, toX, toY);
807 Graphics_unsetInner (GRAPHICS);
808 GRAPHICS_NONE_END
809 }
810
811 Thing_define (PraatPictureFunction, Daata) {
812 // new data:
813 public:
814 double xmin, xmax, dx, x1;
815 integer nx;
816 // overridden methods:
817 virtual bool v_hasGetXmin () const { return true; } virtual double v_getXmin () const { return xmin; }
818 virtual bool v_hasGetXmax () const { return true; } virtual double v_getXmax () const { return xmax; }
819 virtual bool v_hasGetNx () const { return true; } virtual double v_getNx () const { return nx; }
820 virtual bool v_hasGetDx () const { return true; } virtual double v_getDx () const { return dx; }
821 virtual bool v_hasGetX () const { return true; } virtual double v_getX (integer ix) const { return x1 + (ix - 1) * dx; }
822 };
823 Thing_implement (PraatPictureFunction, Daata, 0);
824
825 FORM (GRAPHICS_DrawFunction, U"Praat picture: Draw function", nullptr) {
826 COMMENT (U"This command assumes that the x and y axes")
827 COMMENT (U"have been set by a Draw command or by \"Axes...\".")
828 REAL (fromX, U"From x", U"0.0")
829 REAL (toX, U"To x", U"0.0 (= all)")
830 NATURAL (numberOfHorizontalSteps, U"Number of horizontal steps", U"1000")
831 FORMULA (formula, U"Formula", U"x^2 - x^4")
832 OK
833 DO
834 if (numberOfHorizontalSteps < 2)
835 return;
836 double x1WC, x2WC, y1WC, y2WC;
837 Graphics_inqWindow (GRAPHICS, & x1WC, & x2WC, & y1WC, & y2WC);
838 if (fromX == toX) {
839 fromX = x1WC;
840 toX = x2WC;
841 }
842 autoVEC y = raw_VEC (numberOfHorizontalSteps);
843 autoPraatPictureFunction function = Thing_new (PraatPictureFunction);
844 function -> xmin = x1WC;
845 function -> xmax = x2WC;
846 function -> nx = numberOfHorizontalSteps;
847 function -> x1 = fromX;
848 function -> dx = (toX - fromX) / (numberOfHorizontalSteps - 1);
849 Formula_compile (interpreter, function.get(), formula, kFormula_EXPRESSION_TYPE_NUMERIC, true);
850 Formula_Result result;
851 for (integer i = 1; i <= numberOfHorizontalSteps; i ++) {
852 Formula_run (1, i, & result);
853 y [i] = result. numericResult;
854 }
855 GRAPHICS_NONE
856 Graphics_setInner (GRAPHICS);
857 Graphics_function (GRAPHICS, & y [0], 1, numberOfHorizontalSteps, fromX, toX);
858 Graphics_unsetInner (GRAPHICS);
859 GRAPHICS_NONE_END
860 }
861
862 FORM (GRAPHICS_DrawRectangle, U"Praat picture: Draw rectangle", nullptr) {
863 REAL (fromX, U"From x", U"0.0")
864 REAL (toX, U"To x", U"1.0")
865 REAL (fromY, U"From y", U"0.0")
866 REAL (toY, U"To y", U"1.0")
867 OK
868 DO
869 GRAPHICS_NONE
870 Graphics_setInner (GRAPHICS);
871 Graphics_rectangle (GRAPHICS, fromX, toX, fromY, toY);
872 Graphics_unsetInner (GRAPHICS);
873 GRAPHICS_NONE_END
874 }
875
876 FORM (GRAPHICS_PaintRectangle, U"Praat picture: Paint rectangle", nullptr) {
877 COLOUR (colour, U"Colour (0-1, name, or {r,g,b})", U"0.5")
878 REAL (fromX, U"From x", U"0.0")
879 REAL (toX, U"To x", U"1.0")
880 REAL (fromY, U"From y", U"0.0")
881 REAL (toY, U"To y", U"1.0")
882 OK
883 DO
884 GRAPHICS_NONE
885 Graphics_setInner (GRAPHICS);
886 Graphics_setColour (GRAPHICS, colour);
887 Graphics_fillRectangle (GRAPHICS, fromX, toX, fromY, toY);
888 Graphics_unsetInner (GRAPHICS);
889 GRAPHICS_NONE_END
890 }
891
892 FORM (GRAPHICS_DrawRoundedRectangle, U"Praat picture: Draw rounded rectangle", nullptr) {
893 REAL (fromX, U"From x", U"0.0")
894 REAL (toX, U"To x", U"1.0")
895 REAL (fromY, U"From y", U"0.0")
896 REAL (toY, U"To y", U"1.0")
897 POSITIVE (radius, U"Radius (mm)", U"3.0")
898 OK
899 DO
900 GRAPHICS_NONE
901 Graphics_setInner (GRAPHICS);
902 Graphics_roundedRectangle (GRAPHICS, fromX, toX, fromY, toY, radius);
903 Graphics_unsetInner (GRAPHICS);
904 GRAPHICS_NONE_END
905 }
906
907 FORM (GRAPHICS_PaintRoundedRectangle, U"Praat picture: Paint rounded rectangle", nullptr) {
908 COLOUR (colour, U"Colour (0-1, name, or {r,g,b})", U"0.5")
909 REAL (fromX, U"From x", U"0.0")
910 REAL (toX, U"To x", U"1.0")
911 REAL (fromY, U"From y", U"0.0")
912 REAL (toY, U"To y", U"1.0")
913 POSITIVE (radius, U"Radius (mm)", U"3.0")
914 OK
915 DO
916 GRAPHICS_NONE
917 Graphics_setInner (GRAPHICS);
918 Graphics_setColour (GRAPHICS, colour);
919 Graphics_fillRoundedRectangle (GRAPHICS, fromX, toX, fromY, toY, radius);
920 Graphics_unsetInner (GRAPHICS);
921 GRAPHICS_NONE_END
922 }
923
924 FORM (GRAPHICS_DrawArc, U"Praat picture: Draw arc", nullptr) {
925 REAL (centreX, U"Centre x", U"0.0")
926 REAL (centreY, U"Centre y", U"0.0")
927 POSITIVE (radius, U"Radius (along x)", U"1.0")
928 REAL (fromAngle, U"From angle (degrees)", U"0.0")
929 REAL (toAngle, U"To angle (degrees)", U"90.0")
930 OK
931 DO
932 GRAPHICS_NONE
933 Graphics_setInner (GRAPHICS);
934 Graphics_arc (GRAPHICS, centreX, centreY, radius, fromAngle, toAngle);
935 Graphics_unsetInner (GRAPHICS);
936 GRAPHICS_NONE_END
937 }
938
939 FORM (GRAPHICS_DrawEllipse, U"Praat picture: Draw ellipse", nullptr) {
940 REAL (fromX, U"From x", U"0.0")
941 REAL (toX, U"To x", U"1.0")
942 REAL (fromY, U"From y", U"0.0")
943 REAL (toY, U"To y", U"1.0")
944 OK
945 DO
946 GRAPHICS_NONE
947 Graphics_setInner (GRAPHICS);
948 Graphics_ellipse (GRAPHICS, fromX, toX, fromY, toY);
949 Graphics_unsetInner (GRAPHICS);
950 GRAPHICS_NONE_END
951 }
952
953 FORM (GRAPHICS_PaintEllipse, U"Praat picture: Paint ellipse", nullptr) {
954 COLOUR (colour, U"Colour (0-1, name, or {r,g,b})", U"0.5")
955 REAL (fromX, U"From x", U"0.0")
956 REAL (toX, U"To x", U"1.0")
957 REAL (fromY, U"From y", U"0.0")
958 REAL (toY, U"To y", U"1.0")
959 OK
960 DO
961 GRAPHICS_NONE
962 Graphics_setInner (GRAPHICS);
963 Graphics_setColour (GRAPHICS, colour);
964 Graphics_fillEllipse (GRAPHICS, fromX, toX, fromY, toY);
965 Graphics_unsetInner (GRAPHICS);
966 GRAPHICS_NONE_END
967 }
968
969 FORM (GRAPHICS_DrawCircle, U"Praat picture: Draw circle", nullptr) {
970 REAL (centreX, U"Centre x", U"0.0")
971 REAL (centreY, U"Centre y", U"0.0")
972 POSITIVE (radius, U"Radius (along x)", U"1.0")
973 OK
974 DO
975 GRAPHICS_NONE
976 Graphics_setInner (GRAPHICS);
977 Graphics_circle (GRAPHICS, centreX, centreY, radius);
978 Graphics_unsetInner (GRAPHICS);
979 GRAPHICS_NONE_END
980 }
981
982 FORM (GRAPHICS_PaintCircle, U"Praat picture: Paint circle", nullptr) {
983 COLOUR (colour, U"Colour (0-1, name, or {r,g,b})", U"0.5")
984 REAL (centreX, U"Centre x", U"0.0")
985 REAL (centreY, U"Centre y", U"0.0")
986 POSITIVE (radius, U"Radius (along x)", U"1.0")
987 OK
988 DO
989 GRAPHICS_NONE
990 Graphics_setInner (GRAPHICS);
991 Graphics_setColour (GRAPHICS, colour);
992 Graphics_fillCircle (GRAPHICS, centreX, centreY, radius);
993 Graphics_unsetInner (GRAPHICS);
994 GRAPHICS_NONE_END
995 }
996
997 FORM (GRAPHICS_DrawCircle_mm, U"Praat picture: Draw circle (mm)", nullptr) {
998 REAL (centreX, U"Centre x", U"0.0")
999 REAL (centreY, U"Centre y", U"0.0")
1000 POSITIVE (diameter, U"Diameter (mm)", U"5.0")
1001 OK
1002 DO
1003 GRAPHICS_NONE
1004 Graphics_setInner (GRAPHICS);
1005 Graphics_circle_mm (GRAPHICS, centreX, centreY, diameter);
1006 Graphics_unsetInner (GRAPHICS);
1007 GRAPHICS_NONE_END
1008 }
1009
1010 FORM (GRAPHICS_PaintCircle_mm, U"Praat picture: Paint circle (mm)", nullptr) {
1011 COLOUR (colour, U"Colour (0-1, name, or {r,g,b})", U"0.5")
1012 REAL (centreX, U"Centre x", U"0.0")
1013 REAL (centreY, U"Centre y", U"0.0")
1014 POSITIVE (diameter, U"Diameter (mm)", U"5.0")
1015 OK
1016 DO
1017 GRAPHICS_NONE
1018 Graphics_setInner (GRAPHICS);
1019 Graphics_setColour (GRAPHICS, colour);
1020 Graphics_fillCircle_mm (GRAPHICS, centreX, centreY, diameter);
1021 Graphics_unsetInner (GRAPHICS);
1022 GRAPHICS_NONE_END
1023 }
1024
1025 FORM (GRAPHICS_InsertPictureFromFile, U"Praat picture: Insert picture from file", U"Insert picture from file...") {
1026 INFILE (fileName, U"File name", U"~/Desktop/paul.jpg")
1027 REAL (fromX, U"From x", U"0.0")
1028 REAL (toX, U"To x", U"1.0")
1029 REAL (fromY, U"From y", U"0.0")
1030 REAL (toY, U"To y", U"1.0")
1031 OK
1032 DO
1033 GRAPHICS_NONE
1034 Graphics_setInner (GRAPHICS);
1035 Graphics_imageFromFile (GRAPHICS, fileName, fromX, toX, fromY, toY);
1036 Graphics_unsetInner (GRAPHICS);
1037 GRAPHICS_NONE_END
1038 }
1039
1040 FORM (GRAPHICS_InsertPictureFromFile_embedded, U"Praat picture: Insert picture from file (embedded)", U"Insert picture from file (embedded)...") {
1041 INFILE (fileName, U"File name", U"~/Desktop/paul.jpg")
1042 REAL (fromX, U"From x", U"0.0")
1043 REAL (toX, U"To x", U"1.0")
1044 REAL (fromY, U"From y", U"0.0")
1045 REAL (toY, U"To y", U"1.0")
1046 OK
1047 DO
1048 GRAPHICS_NONE
1049 Graphics_setInner (GRAPHICS);
1050 Graphics_imageFromFile_embedded (GRAPHICS, fileName, fromX, toX, fromY, toY);
1051 Graphics_unsetInner (GRAPHICS);
1052 GRAPHICS_NONE_END
1053 }
1054
1055 FORM (GRAPHICS_Axes, U"Praat picture: Axes", U"Axes...") {
1056 REAL (left, U"left Left and right", U"0.0")
1057 REAL (right, U"right Left and right", U"1.0")
1058 REAL (bottom, U"left Bottom and top", U"0.0")
1059 REAL (top, U"right Bottom and top", U"1.0")
1060 OK
1061 double x1WC, x2WC, y1WC, y2WC;
1062 Graphics_inqWindow (GRAPHICS, & x1WC, & x2WC, & y1WC, & y2WC);
1063 SET_REAL (left, x1WC)
1064 SET_REAL (right, x2WC)
1065 SET_REAL (bottom, y1WC)
1066 SET_REAL (top, y2WC)
1067 DO
1068 if (left == right)
1069 Melder_throw (U"Left and right should not be equal.");
1070 if (top == bottom)
1071 Melder_throw (U"Top and bottom should not be equal.");
1072 GRAPHICS_NONE
1073 Graphics_setWindow (GRAPHICS, left, right, bottom, top);
1074 GRAPHICS_NONE_END
1075 }
1076
1077 #pragma mark - Margins menu
1078
1079 DIRECT (GRAPHICS_DrawInnerBox) {
1080 GRAPHICS_NONE
1081 Graphics_drawInnerBox (GRAPHICS);
1082 GRAPHICS_NONE_END
1083 }
1084
1085 FORM (GRAPHICS_TextLeft, U"Praat picture: Text left", U"Text left/right/top/bottom...") {
1086 BOOLEAN (farr, U"Far", true)
1087 TEXTFIELD (text, U"Text", U"", 3)
1088 OK
1089 DO
1090 GRAPHICS_NONE
1091 Graphics_textLeft (GRAPHICS, farr, text);
1092 GRAPHICS_NONE_END
1093 }
1094
1095 FORM (GRAPHICS_TextRight, U"Praat picture: Text right", U"Text left/right/top/bottom...") {
1096 BOOLEAN (farr, U"Far", true)
1097 TEXTFIELD (text, U"Text", U"", 3)
1098 OK
1099 DO
1100 GRAPHICS_NONE
1101 Graphics_textRight (GRAPHICS, farr, text);
1102 GRAPHICS_NONE_END
1103 }
1104
1105 FORM (GRAPHICS_TextTop, U"Praat picture: Text top", U"Text left/right/top/bottom...") {
1106 BOOLEAN (farr, U"Far", true)
1107 TEXTFIELD (text, U"Text", U"", 3)
1108 OK
1109 DO
1110 GRAPHICS_NONE
1111 Graphics_textTop (GRAPHICS, farr, text);
1112 GRAPHICS_NONE_END
1113 }
1114
1115 FORM (GRAPHICS_TextBottom, U"Praat picture: Text bottom", U"Text left/right/top/bottom...") {
1116 BOOLEAN (farr, U"Far", true)
1117 TEXTFIELD (text, U"Text", U"", 3)
1118 OK
1119 DO
1120 GRAPHICS_NONE
1121 Graphics_textBottom (GRAPHICS, farr, text);
1122 GRAPHICS_NONE_END
1123 }
1124
1125 #define FIELDS_MARKS_EVERY \
1126 POSITIVE (units, U"Units", U"1.0") \
1127 POSITIVE (distance, U"Distance", U"0.1") \
1128 BOOLEAN (writeNumbers, U"Write numbers", true) \
1129 BOOLEAN (drawTicks, U"Draw ticks", true) \
1130 BOOLEAN (drawDottedLines, U"Draw dotted lines", true)
1131
1132 FORM (GRAPHICS_MarksLeftEvery, U"Praat picture: Marks left every...", U"Marks left/right/top/bottom every...") {
1133 FIELDS_MARKS_EVERY
1134 OK
1135 DO
1136 GRAPHICS_NONE
1137 Graphics_marksLeftEvery (GRAPHICS, units, distance, writeNumbers, drawTicks, drawDottedLines);
1138 GRAPHICS_NONE_END
1139 }
1140
1141 FORM (GRAPHICS_MarksRightEvery, U"Praat picture: Marks right every...", U"Marks left/right/top/bottom every...") {
1142 FIELDS_MARKS_EVERY
1143 OK
1144 DO
1145 GRAPHICS_NONE
1146 Graphics_marksRightEvery (GRAPHICS, units, distance, writeNumbers, drawTicks, drawDottedLines);
1147 GRAPHICS_NONE_END
1148 }
1149
1150 FORM (GRAPHICS_MarksBottomEvery, U"Praat picture: Marks bottom every...", U"Marks left/right/top/bottom every...") {
1151 FIELDS_MARKS_EVERY
1152 OK
1153 DO
1154 GRAPHICS_NONE
1155 Graphics_marksBottomEvery (GRAPHICS, units, distance, writeNumbers, drawTicks, drawDottedLines);
1156 GRAPHICS_NONE_END
1157 }
1158
1159 FORM (GRAPHICS_MarksTopEvery, U"Praat picture: Marks top every...", U"Marks left/right/top/bottom every...") {
1160 FIELDS_MARKS_EVERY
1161 OK
1162 DO
1163 GRAPHICS_NONE
1164 Graphics_marksTopEvery (GRAPHICS, units, distance, writeNumbers, drawTicks, drawDottedLines);
1165 GRAPHICS_NONE_END
1166 }
1167
1168 #define FIELDS_MARKS \
1169 NATURAL (numberOfMarks, U"Number of marks", U"6") \
1170 BOOLEAN (writeNumbers, U"Write numbers", true) \
1171 BOOLEAN (drawTicks, U"Draw ticks", true) \
1172 BOOLEAN (drawDottedLines, U"Draw dotted lines", true)
1173
1174 FORM (GRAPHICS_MarksLeft, U"Praat picture: Marks left", U"Marks left/right/top/bottom...") {
1175 FIELDS_MARKS
1176 OK
1177 DO
1178 GRAPHICS_NONE
1179 if (numberOfMarks < 2)
1180 Melder_throw (U"The number of marks should be at least 2.");
1181 Graphics_marksLeft (GRAPHICS, numberOfMarks, writeNumbers, drawTicks, drawDottedLines);
1182 GRAPHICS_NONE_END
1183 }
1184
1185 FORM (GRAPHICS_MarksRight, U"Praat picture: Marks right", U"Marks left/right/top/bottom...") {
1186 FIELDS_MARKS
1187 OK
1188 DO
1189 GRAPHICS_NONE
1190 if (numberOfMarks < 2)
1191 Melder_throw (U"The number of marks should be at least 2.");
1192 Graphics_marksRight (GRAPHICS, numberOfMarks, writeNumbers, drawTicks, drawDottedLines);
1193 GRAPHICS_NONE_END
1194 }
1195
1196 FORM (GRAPHICS_MarksBottom, U"Praat picture: Marks bottom", U"Marks left/right/top/bottom...") {
1197 FIELDS_MARKS
1198 OK
1199 DO
1200 GRAPHICS_NONE
1201 if (numberOfMarks < 2)
1202 Melder_throw (U"The number of marks should be at least 2.");
1203 Graphics_marksBottom (GRAPHICS, numberOfMarks, writeNumbers, drawTicks, drawDottedLines);
1204 GRAPHICS_NONE_END
1205 }
1206
1207 FORM (GRAPHICS_MarksTop, U"Praat picture: Marks top", U"Marks left/right/top/bottom...") {
1208 FIELDS_MARKS
1209 OK
1210 DO
1211 GRAPHICS_NONE
1212 if (numberOfMarks < 2)
1213 Melder_throw (U"The number of marks should be at least 2.");
1214 Graphics_marksTop (GRAPHICS, numberOfMarks, writeNumbers, drawTicks, drawDottedLines);
1215 GRAPHICS_NONE_END
1216 }
1217
1218 #define FIELDS_MARKS_LOGARITHMIC \
1219 NATURAL (marksPerDecade, U"Marks per decade", U"3") \
1220 BOOLEAN (writeNumbers, U"Write numbers", true) \
1221 BOOLEAN (drawTicks, U"Draw ticks", true) \
1222 BOOLEAN (drawDottedLines, U"Draw dotted lines", true)
1223
1224 FORM (GRAPHICS_LogarithmicMarksLeft, U"Praat picture: Logarithmic marks left", U"Logarithmic marks left/right/top/bottom...") {
1225 FIELDS_MARKS_LOGARITHMIC
1226 OK
1227 DO
1228 GRAPHICS_NONE
1229 Graphics_marksLeftLogarithmic (GRAPHICS, marksPerDecade, writeNumbers, drawTicks, drawDottedLines);
1230 GRAPHICS_NONE_END
1231 }
1232
1233 FORM (GRAPHICS_LogarithmicMarksRight, U"Praat picture: Logarithmic marks right", U"Logarithmic marks left/right/top/bottom...") {
1234 FIELDS_MARKS_LOGARITHMIC
1235 OK
1236 DO
1237 GRAPHICS_NONE
1238 Graphics_marksRightLogarithmic (GRAPHICS, marksPerDecade, writeNumbers, drawTicks, drawDottedLines);
1239 GRAPHICS_NONE_END
1240 }
1241
1242 FORM (GRAPHICS_LogarithmicMarksBottom, U"Praat picture: Logarithmic marks bottom", U"Logarithmic marks left/right/top/bottom...") {
1243 FIELDS_MARKS_LOGARITHMIC
1244 OK
1245 DO
1246 GRAPHICS_NONE
1247 Graphics_marksBottomLogarithmic (GRAPHICS, marksPerDecade, writeNumbers, drawTicks, drawDottedLines);
1248 GRAPHICS_NONE_END
1249 }
1250
1251 FORM (GRAPHICS_LogarithmicMarksTop, U"Praat picture: Logarithmic marks top", U"Logarithmic marks left/right/top/bottom...") {
1252 FIELDS_MARKS_LOGARITHMIC
1253 OK
1254 DO
1255 GRAPHICS_NONE
1256 Graphics_marksTopLogarithmic (GRAPHICS, marksPerDecade, writeNumbers, drawTicks, drawDottedLines);
1257 GRAPHICS_NONE_END
1258 }
1259
1260 static void sortBoundingBox (double *x1WC, double *x2WC, double *y1WC, double *y2WC) {
1261 Melder_sort (x1WC, x2WC);
1262 Melder_sort (y1WC, y2WC);
1263 }
1264
1265 FORM (GRAPHICS_OneMarkLeft, U"Praat picture: One mark left", U"One mark left/right/top/bottom...") {
1266 REAL (position, U"Position", U"0.0")
1267 BOOLEAN (writeNumber, U"Write number", true)
1268 BOOLEAN (drawTick, U"Draw tick", true)
1269 BOOLEAN (drawDottedLine, U"Draw dotted line", true)
1270 TEXTFIELD (text, U"Draw text", U"", 3)
1271 OK
1272 DO
1273 double x1WC, x2WC, y1WC, y2WC;
1274 {// scope
1275 autoPraatPictureOpen picture;
1276 Graphics_inqWindow (GRAPHICS, & x1WC, & x2WC, & y1WC, & y2WC);
1277 }
1278 sortBoundingBox (& x1WC, & x2WC, & y1WC, & y2WC);
1279 const double dy = 0.2 * (y2WC - y1WC);
1280 if (position < y1WC - dy || position > y2WC + dy)
1281 Melder_throw (U"\"Position\" must be between ", y1WC, U" and ", y2WC, U".");
1282 GRAPHICS_NONE
1283 Graphics_markLeft (GRAPHICS, position, writeNumber, drawTick, drawDottedLine, text);
1284 GRAPHICS_NONE_END
1285 }
1286
1287 FORM (GRAPHICS_OneMarkRight, U"Praat picture: One mark right", U"One mark left/right/top/bottom...") {
1288 REAL (position, U"Position", U"0.0")
1289 BOOLEAN (writeNumber, U"Write number", true)
1290 BOOLEAN (drawTick, U"Draw tick", true)
1291 BOOLEAN (drawDottedLine, U"Draw dotted line", true)
1292 TEXTFIELD (text, U"Draw text", U"", 3)
1293 OK
1294 DO
1295 double x1WC, x2WC, y1WC, y2WC;
1296 {// scope
1297 autoPraatPictureOpen picture;
1298 Graphics_inqWindow (GRAPHICS, & x1WC, & x2WC, & y1WC, & y2WC);
1299 }
1300 sortBoundingBox (& x1WC, & x2WC, & y1WC, & y2WC);
1301 const double dy = 0.2 * (y2WC - y1WC);
1302 if (position < y1WC - dy || position > y2WC + dy)
1303 Melder_throw (U"\"Position\" must be between ", y1WC, U" and ", y2WC, U".");
1304 GRAPHICS_NONE
1305 Graphics_markRight (GRAPHICS, position, writeNumber, drawTick, drawDottedLine, text);
1306 GRAPHICS_NONE_END
1307 }
1308
1309 FORM (GRAPHICS_OneMarkTop, U"Praat picture: One mark top", U"One mark left/right/top/bottom...") {
1310 REAL (position, U"Position", U"0.0")
1311 BOOLEAN (writeNumber, U"Write number", true)
1312 BOOLEAN (drawTick, U"Draw tick", true)
1313 BOOLEAN (drawDottedLine, U"Draw dotted line", true)
1314 TEXTFIELD (text, U"Draw text", U"", 3)
1315 OK
1316 DO
1317 double x1WC, x2WC, y1WC, y2WC;
1318 {// scope
1319 autoPraatPictureOpen picture; // WHY?
1320 Graphics_inqWindow (GRAPHICS, & x1WC, & x2WC, & y1WC, & y2WC);
1321 }
1322 sortBoundingBox (& x1WC, & x2WC, & y1WC, & y2WC);
1323 const double dx = 0.2 * (x2WC - x1WC);
1324 if (position < x1WC - dx || position > x2WC + dx)
1325 Melder_throw (U"\"Position\" must be between ", x1WC, U" and ", x2WC, U".");
1326 GRAPHICS_NONE
1327 Graphics_markTop (GRAPHICS, position, writeNumber, drawTick, drawDottedLine, text);
1328 GRAPHICS_NONE_END
1329 }
1330
1331 FORM (GRAPHICS_OneMarkBottom, U"Praat picture: One mark bottom", U"One mark left/right/top/bottom...") {
1332 REAL (position, U"Position", U"0.0")
1333 BOOLEAN (writeNumber, U"Write number", true)
1334 BOOLEAN (drawTick, U"Draw tick", true)
1335 BOOLEAN (drawDottedLine, U"Draw dotted line", true)
1336 TEXTFIELD (text, U"Draw text", U"", 3)
1337 OK
1338 DO
1339 double x1WC, x2WC, y1WC, y2WC;
1340 {// scope
1341 autoPraatPictureOpen picture;
1342 Graphics_inqWindow (GRAPHICS, & x1WC, & x2WC, & y1WC, & y2WC);
1343 }
1344 sortBoundingBox (& x1WC, & x2WC, & y1WC, & y2WC);
1345 const double dx = 0.2 * (x2WC - x1WC);
1346 if (position < x1WC - dx || position > x2WC + dx)
1347 Melder_throw (U"\"Position\" must be between ", x1WC, U" and ", x2WC, U".");
1348 GRAPHICS_NONE
1349 Graphics_markBottom (GRAPHICS, position, writeNumber, drawTick, drawDottedLine, text);
1350 GRAPHICS_NONE_END
1351 }
1352
1353 FORM (GRAPHICS_OneLogarithmicMarkLeft, U"Praat picture: One logarithmic mark left", U"One logarithmic mark left/right/top/bottom...") {
1354 REAL (position, U"Position", U"1.0")
1355 BOOLEAN (writeNumber, U"Write number", 1)
1356 BOOLEAN (drawTick, U"Draw tick", 1)
1357 BOOLEAN (drawDottedLine, U"Draw dotted line", 1)
1358 TEXTFIELD (text, U"Draw text", U"", 3)
1359 OK
1360 DO
1361 double x1WC, x2WC, y1WC, y2WC;
1362 {// scope
1363 autoPraatPictureOpen picture;
1364 Graphics_inqWindow (GRAPHICS, & x1WC, & x2WC, & y1WC, & y2WC);
1365 }
1366 sortBoundingBox (& x1WC, & x2WC, & y1WC, & y2WC);
1367 const double dy = 0.2 * (y2WC - y1WC);
1368 if (position < pow (10, y1WC - dy) || position > pow (10, y2WC + dy))
1369 Melder_throw (U"\"Position\" must be between ", pow (10, y1WC), U" and ", pow (10, y2WC), U".");
1370 GRAPHICS_NONE
1371 Graphics_markLeftLogarithmic (GRAPHICS, position, writeNumber, drawTick, drawDottedLine, text);
1372 GRAPHICS_NONE_END
1373 }
1374
1375 FORM (GRAPHICS_OneLogarithmicMarkRight, U"Praat picture: One logarithmic mark right", U"One logarithmic mark left/right/top/bottom...") {
1376 REAL (position, U"Position", U"1.0")
1377 BOOLEAN (writeNumber, U"Write number", 1)
1378 BOOLEAN (drawTick, U"Draw tick", 1)
1379 BOOLEAN (drawDottedLine, U"Draw dotted line", 1)
1380 TEXTFIELD (text, U"Draw text", U"", 3)
1381 OK
1382 DO
1383 double x1WC, x2WC, y1WC, y2WC;
1384 {// scope
1385 autoPraatPictureOpen picture;
1386 Graphics_inqWindow (GRAPHICS, & x1WC, & x2WC, & y1WC, & y2WC);
1387 }
1388 sortBoundingBox (& x1WC, & x2WC, & y1WC, & y2WC);
1389 const double dy = 0.2 * (y2WC - y1WC);
1390 if (position < pow (10, y1WC - dy) || position > pow (10, y2WC + dy))
1391 Melder_throw (U"\"Position\" must be between ", pow (10, y1WC), U" and ", pow (10, y2WC), U".");
1392 GRAPHICS_NONE
1393 Graphics_markRightLogarithmic (GRAPHICS, position, writeNumber, drawTick, drawDottedLine, text);
1394 GRAPHICS_NONE_END
1395 }
1396
1397 FORM (GRAPHICS_OneLogarithmicMarkTop, U"Praat picture: One logarithmic mark top", U"One logarithmic mark left/right/top/bottom...") {
1398 REAL (position, U"Position", U"1.0")
1399 BOOLEAN (writeNumber, U"Write number", 1)
1400 BOOLEAN (drawTick, U"Draw tick", 1)
1401 BOOLEAN (drawDottedLine, U"Draw dotted line", 1)
1402 TEXTFIELD (text, U"Draw text", U"", 3)
1403 OK
1404 DO
1405 double x1WC, x2WC, y1WC, y2WC;
1406 {// scope
1407 autoPraatPictureOpen picture;
1408 Graphics_inqWindow (GRAPHICS, & x1WC, & x2WC, & y1WC, & y2WC);
1409 }
1410 sortBoundingBox (& x1WC, & x2WC, & y1WC, & y2WC);
1411 const double dx = 0.2 * (x2WC - x1WC);
1412 if (position < pow (10, x1WC - dx) || position > pow (10, x2WC + dx))
1413 Melder_throw (U"\"Position\" must be between ", pow (10, x1WC), U" and ", pow (10, x2WC), U".");
1414 GRAPHICS_NONE
1415 Graphics_markTopLogarithmic (GRAPHICS, position, writeNumber, drawTick, drawDottedLine, text);
1416 GRAPHICS_NONE_END
1417 }
1418
1419 FORM (GRAPHICS_OneLogarithmicMarkBottom, U"Praat picture: One logarithmic mark bottom", U"One logarithmic mark left/right/top/bottom...") {
1420 REAL (position, U"Position", U"1.0")
1421 BOOLEAN (writeNumber, U"Write number", 1)
1422 BOOLEAN (drawTick, U"Draw tick", 1)
1423 BOOLEAN (drawDottedLine, U"Draw dotted line", 1)
1424 TEXTFIELD (text, U"Draw text", U"", 3)
1425 OK
1426 DO
1427 double x1WC, x2WC, y1WC, y2WC;
1428 {// scope
1429 autoPraatPictureOpen picture;
1430 Graphics_inqWindow (GRAPHICS, & x1WC, & x2WC, & y1WC, & y2WC);
1431 }
1432 sortBoundingBox (& x1WC, & x2WC, & y1WC, & y2WC);
1433 const double dx = 0.2 * (x2WC - x1WC);
1434 if (position < pow (10, x1WC - dx) || position > pow (10, x2WC + dx))
1435 Melder_throw (U"\"Position\" must be between ", pow (10, x1WC), U" and ", pow (10, x2WC), U".");
1436 GRAPHICS_NONE
1437 Graphics_markBottomLogarithmic (GRAPHICS, position, writeNumber, drawTick, drawDottedLine, text);
1438 GRAPHICS_NONE_END
1439 }
1440
1441 FORM (GRAPHICS_HorizontalMmToWorldCoordinates, U"Compute horizontal distance in world coordinates", nullptr) {
1442 REAL (distance, U"Distance (mm)", U"10.0")
1443 OK
1444 DO
1445 QUERY_GRAPHICS_FOR_REAL
1446 Graphics_setFontSize (GRAPHICS, theCurrentPraatPicture -> fontSize);
1447 Graphics_setViewport (GRAPHICS, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC,
1448 theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
1449 Graphics_setInner (GRAPHICS);
1450 const double result = Graphics_dxMMtoWC (GRAPHICS, distance);
1451 Graphics_unsetInner (GRAPHICS);
1452 QUERY_GRAPHICS_FOR_REAL_END (U" (world coordinates)");
1453 }
1454
1455 FORM (GRAPHICS_HorizontalWorldCoordinatesToMm, U"Compute horizontal distance in millimetres", nullptr) {
1456 REAL (distance, U"Distance (wc)", U"0.1")
1457 OK
1458 DO
1459 QUERY_GRAPHICS_FOR_REAL // TODO: do we need autoPraatPictureOpen for any of these?
1460 Graphics_setFontSize (GRAPHICS, theCurrentPraatPicture -> fontSize);
1461 Graphics_setViewport (GRAPHICS, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC,
1462 theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
1463 Graphics_setInner (GRAPHICS);
1464 const double result = Graphics_dxWCtoMM (GRAPHICS, distance);
1465 Graphics_unsetInner (GRAPHICS);
1466 QUERY_GRAPHICS_FOR_REAL_END (U" mm")
1467 }
1468
1469 FORM (GRAPHICS_VerticalMmToWorldCoordinates, U"Compute vertical distance in world coordinates", nullptr) {
1470 REAL (distance, U"Distance (mm)", U"10.0")
1471 OK
1472 DO
1473 QUERY_GRAPHICS_FOR_REAL
1474 Graphics_setFontSize (GRAPHICS, theCurrentPraatPicture -> fontSize);
1475 Graphics_setViewport (GRAPHICS, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
1476 Graphics_setInner (GRAPHICS);
1477 const double result = Graphics_dyMMtoWC (GRAPHICS, distance);
1478 Graphics_unsetInner (GRAPHICS);
1479 QUERY_GRAPHICS_FOR_REAL_END (U" (world coordinates)")
1480 }
1481
1482 FORM (GRAPHICS_VerticalWorldCoordinatesToMm, U"Compute vertical distance in millimetres", nullptr) {
1483 REAL (distance, U"Distance (wc)", U"1.0")
1484 OK
1485 DO
1486 QUERY_GRAPHICS_FOR_REAL
1487 Graphics_setFontSize (GRAPHICS, theCurrentPraatPicture -> fontSize);
1488 Graphics_setViewport (GRAPHICS, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
1489 Graphics_setInner (GRAPHICS);
1490 const double result = Graphics_dyWCtoMM (GRAPHICS, distance);
1491 Graphics_unsetInner (GRAPHICS);
1492 QUERY_GRAPHICS_FOR_REAL_END (U" mm")
1493 }
1494
1495 FORM (GRAPHICS_TextWidth_worldCoordinates, U"Text width in world coordinates", nullptr) {
1496 TEXTFIELD (text, U"Text", U"Hello world", 3)
1497 OK
1498 DO
1499 QUERY_GRAPHICS_FOR_REAL
1500 Graphics_setInner (GRAPHICS);
1501 const double result = Graphics_textWidth (GRAPHICS, text);
1502 Graphics_unsetInner (GRAPHICS);
1503 QUERY_GRAPHICS_FOR_REAL_END (U" (world coordinates)")
1504 }
1505
1506 FORM (GRAPHICS_TextWidth_mm, U"Text width in millimetres", nullptr) {
1507 TEXTFIELD (text, U"Text", U"Hello world", 3)
1508 OK
1509 DO
1510 QUERY_GRAPHICS_FOR_REAL
1511 Graphics_setFont (GRAPHICS, theCurrentPraatPicture -> font);
1512 Graphics_setFontSize (GRAPHICS, theCurrentPraatPicture -> fontSize);
1513 Graphics_setViewport (GRAPHICS, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
1514 Graphics_setInner (GRAPHICS);
1515 const double result = Graphics_dxWCtoMM (GRAPHICS, Graphics_textWidth (GRAPHICS, text));
1516 Graphics_unsetInner (GRAPHICS);
1517 QUERY_GRAPHICS_FOR_REAL_END (U" mm")
1518 }
1519
1520 FORM (GRAPHICS_PostScriptTextWidth_worldCoordinates, U"PostScript text width in world coordinates", nullptr) {
1521 CHOICEx (phoneticFont, U"Phonetic font", 1, 0)
1522 OPTION (U"XIPA")
1523 OPTION (U"SILIPA")
1524 TEXTFIELD (text, U"Text", U"Hello world", 3)
1525 OK
1526 DO
1527 QUERY_GRAPHICS_FOR_REAL
1528 Graphics_setFont (GRAPHICS, theCurrentPraatPicture -> font);
1529 Graphics_setFontSize (GRAPHICS, theCurrentPraatPicture -> fontSize);
1530 Graphics_setViewport (GRAPHICS, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
1531 Graphics_setInner (GRAPHICS);
1532 const double result = Graphics_textWidth_ps (GRAPHICS, text, phoneticFont);
1533 Graphics_unsetInner (GRAPHICS);
1534 QUERY_GRAPHICS_FOR_REAL_END (U" (world coordinates)")
1535 }
1536
1537
1538 FORM (GRAPHICS_PostScriptTextWidth_mm, U"PostScript text width in millimetres", nullptr) {
1539 CHOICEx (phoneticFont, U"Phonetic font", 1, 0)
1540 OPTION (U"XIPA")
1541 OPTION (U"SILIPA")
1542 TEXTFIELD (text, U"Text", U"Hello world", 3)
1543 OK
1544 DO
1545 QUERY_GRAPHICS_FOR_REAL
1546 Graphics_setFont (GRAPHICS, theCurrentPraatPicture -> font);
1547 Graphics_setFontSize (GRAPHICS, theCurrentPraatPicture -> fontSize);
1548 Graphics_setViewport (GRAPHICS, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
1549 Graphics_setInner (GRAPHICS);
1550 const double result = Graphics_textWidth_ps_mm (GRAPHICS, text, phoneticFont);
1551 Graphics_unsetInner (GRAPHICS);
1552 QUERY_GRAPHICS_FOR_REAL_END (U" mm")
1553 }
1554
1555 #pragma mark - Help menu
1556
1557 DIRECT (HELP_PraatIntro_picture) { HELP (U"Intro") }
1558 DIRECT (HELP_SearchManual_Picture) { Melder_search (); END_WITH_NEW_DATA }
1559 DIRECT (HELP_PictureWindowHelp) { HELP (U"Picture window") }
1560 DIRECT (HELP_AboutSpecialSymbols) { HELP (U"Special symbols") }
1561 DIRECT (HELP_AboutTextStyles) { HELP (U"Text styles") }
1562 DIRECT (HELP_PhoneticSymbols) { HELP (U"Phonetic symbols") }
1563 DIRECT (GRAPHICS_Picture_settings_report) {
1564 INFO_NONE
1565 MelderInfo_open ();
1566 const conststring32 units = ( theCurrentPraatPicture == & theForegroundPraatPicture ? U" inches" : U"" );
1567 MelderInfo_writeLine (U"Outer viewport left: ", theCurrentPraatPicture -> x1NDC, units);
1568 MelderInfo_writeLine (U"Outer viewport right: ", theCurrentPraatPicture -> x2NDC, units);
1569 MelderInfo_writeLine (U"Outer viewport top: ",
1570 ( theCurrentPraatPicture != & theForegroundPraatPicture ?
1571 theCurrentPraatPicture -> y1NDC :
1572 Picture_HEIGHT - theCurrentPraatPicture -> y2NDC) ,
1573 units
1574 );
1575 MelderInfo_writeLine (U"Outer viewport bottom: ",
1576 ( theCurrentPraatPicture != & theForegroundPraatPicture ?
1577 theCurrentPraatPicture -> y2NDC :
1578 Picture_HEIGHT - theCurrentPraatPicture -> y1NDC ),
1579 units
1580 );
1581 MelderInfo_writeLine (U"Font size: ", theCurrentPraatPicture -> fontSize, U" points");
1582 double xmargin = theCurrentPraatPicture -> fontSize * 4.2 / 72.0;
1583 double ymargin = theCurrentPraatPicture -> fontSize * 2.8 / 72.0;
1584 if (theCurrentPraatPicture != & theForegroundPraatPicture) {
1585 integer x1DC, x2DC, y1DC, y2DC;
1586 Graphics_inqWsViewport (GRAPHICS, & x1DC, & x2DC, & y1DC, & y2DC);
1587 double x1wNDC, x2wNDC, y1wNDC, y2wNDC;
1588 Graphics_inqWsWindow (GRAPHICS, & x1wNDC, & x2wNDC, & y1wNDC, & y2wNDC);
1589 double wDC = (x2DC - x1DC) / (x2wNDC - x1wNDC);
1590 double hDC = integer_abs (y2DC - y1DC) / (y2wNDC - y1wNDC);
1591 xmargin *= Graphics_getResolution (GRAPHICS) / wDC;
1592 ymargin *= Graphics_getResolution (GRAPHICS) / hDC;
1593 }
1594 Melder_clipRight (& ymargin, 0.4 * (theCurrentPraatPicture -> y2NDC - theCurrentPraatPicture -> y1NDC));
1595 Melder_clipRight (& xmargin, 0.4 * (theCurrentPraatPicture -> x2NDC - theCurrentPraatPicture -> x1NDC));
1596 MelderInfo_writeLine (U"Inner viewport left: ", theCurrentPraatPicture -> x1NDC + xmargin, units);
1597 MelderInfo_writeLine (U"Inner viewport right: ", theCurrentPraatPicture -> x2NDC - xmargin, units);
1598 MelderInfo_writeLine (U"Inner viewport top: ",
1599 ( theCurrentPraatPicture != & theForegroundPraatPicture ?
1600 theCurrentPraatPicture -> y1NDC + ymargin :
1601 Picture_HEIGHT - theCurrentPraatPicture -> y2NDC + ymargin ),
1602 units
1603 );
1604 MelderInfo_writeLine (U"Inner viewport bottom: ",
1605 ( theCurrentPraatPicture != & theForegroundPraatPicture ?
1606 theCurrentPraatPicture -> y2NDC - ymargin :
1607 Picture_HEIGHT - theCurrentPraatPicture -> y1NDC - ymargin ),
1608 units
1609 );
1610 MelderInfo_writeLine (U"Font: ", kGraphics_font_getText (theCurrentPraatPicture -> font));
1611 MelderInfo_writeLine (U"Line type: ",
1612 theCurrentPraatPicture -> lineType == Graphics_DRAWN ? U"Solid" :
1613 theCurrentPraatPicture -> lineType == Graphics_DOTTED ? U"Dotted" :
1614 theCurrentPraatPicture -> lineType == Graphics_DASHED ? U"Dashed" :
1615 theCurrentPraatPicture -> lineType == Graphics_DASHED_DOTTED ? U"Dashed-dotted" :
1616 U"(unknown)"
1617 );
1618 MelderInfo_writeLine (U"Line width: ", theCurrentPraatPicture -> lineWidth);
1619 MelderInfo_writeLine (U"Arrow size: ", theCurrentPraatPicture -> arrowSize);
1620 MelderInfo_writeLine (U"Speckle size: ", theCurrentPraatPicture -> speckleSize);
1621 MelderInfo_writeLine (U"Colour: ", MelderColour_name (theCurrentPraatPicture -> colour));
1622 MelderInfo_writeLine (U"Red: ", theCurrentPraatPicture -> colour. red);
1623 MelderInfo_writeLine (U"Green: ", theCurrentPraatPicture -> colour. green);
1624 MelderInfo_writeLine (U"Blue: ", theCurrentPraatPicture -> colour. blue);
1625 double x1WC, x2WC, y1WC, y2WC;
1626 Graphics_inqWindow (GRAPHICS, & x1WC, & x2WC, & y1WC, & y2WC);
1627 MelderInfo_writeLine (U"Axis left: ", x1WC);
1628 MelderInfo_writeLine (U"Axis right: ", x2WC);
1629 MelderInfo_writeLine (U"Axis bottom: ", y1WC);
1630 MelderInfo_writeLine (U"Axis top: ", y2WC);
1631 MelderInfo_close ();
1632 INFO_NONE_END
1633 }
1634
1635 #pragma mark - Event callbacks
1636
1637 static void cb_selectionChanged (Picture p, void * /* closure */,
1638 double selx1, double selx2, double sely1, double sely2)
1639 /* The user selected a new viewport in the picture window. */
1640 {
1641 Melder_assert (p == praat_picture.get());
1642 theCurrentPraatPicture -> x1NDC = selx1;
1643 theCurrentPraatPicture -> x2NDC = selx2;
1644 theCurrentPraatPicture -> y1NDC = sely1;
1645 theCurrentPraatPicture -> y2NDC = sely2;
1646 if (praat_mouseSelectsInnerViewport) {
1647 const double fontSize = Graphics_inqFontSize (GRAPHICS);
1648 const double xmargin = Melder_clippedRight (fontSize * 4.2 / 72.0, 0.4 * (theCurrentPraatPicture -> x2NDC - theCurrentPraatPicture -> x1NDC));
1649 const double ymargin = Melder_clippedRight (fontSize * 2.8 / 72.0, 0.4 * (theCurrentPraatPicture -> y2NDC - theCurrentPraatPicture -> y1NDC));
1650 UiHistory_write (U"\nSelect inner viewport: ");
1651 UiHistory_write (Melder_single (theCurrentPraatPicture -> x1NDC + xmargin));
1652 UiHistory_write (U", ");
1653 UiHistory_write (Melder_single (theCurrentPraatPicture -> x2NDC - xmargin));
1654 UiHistory_write (U", ");
1655 UiHistory_write (Melder_single (Picture_HEIGHT - theCurrentPraatPicture -> y2NDC + ymargin));
1656 UiHistory_write (U", ");
1657 UiHistory_write (Melder_single (Picture_HEIGHT - theCurrentPraatPicture -> y1NDC - ymargin));
1658 } else {
1659 UiHistory_write (U"\nSelect outer viewport: ");
1660 UiHistory_write (Melder_single (theCurrentPraatPicture -> x1NDC));
1661 UiHistory_write (U", ");
1662 UiHistory_write (Melder_single (theCurrentPraatPicture -> x2NDC));
1663 UiHistory_write (U", ");
1664 UiHistory_write (Melder_single (Picture_HEIGHT - theCurrentPraatPicture -> y2NDC));
1665 UiHistory_write (U", ");
1666 UiHistory_write (Melder_single (Picture_HEIGHT - theCurrentPraatPicture -> y1NDC));
1667 }
1668 }
1669
1670 #pragma mark - Public functions
1671
1672 static GuiWindow thePictureWindow;
1673
1674 static GuiMenu fileMenu, editMenu, marginsMenu, worldMenu, selectMenu, fontMenu, penMenu, helpMenu;
1675
1676 GuiMenu praat_picture_resolveMenu (conststring32 menu) {
1677 return
1678 str32equ (menu, U"File") ? fileMenu :
1679 str32equ (menu, U"Edit") ? editMenu :
1680 str32equ (menu, U"Margins") ? marginsMenu :
1681 str32equ (menu, U"World") ? worldMenu :
1682 str32equ (menu, U"Select") ? selectMenu :
1683 str32equ (menu, U"Font") ? fontMenu :
1684 str32equ (menu, U"Pen") ? penMenu :
1685 str32equ (menu, U"Help") ? helpMenu :
1686 editMenu; // default
1687 }
1688
1689 void praat_picture_exit () {
1690 praat_picture. reset();
1691 }
1692
1693 void praat_picture_open () {
1694 Graphics_markGroup (GRAPHICS); // we start a group of graphics output here
1695 if (theCurrentPraatPicture == & theForegroundPraatPicture && ! theCurrentPraatApplication -> batch) {
1696 #if gtk
1697 gtk_window_present (GTK_WINDOW (thePictureWindow -> d_gtkWindow));
1698 #elif motif
1699 XtMapWidget (thePictureWindow -> d_xmShell);
1700 XMapRaised (XtDisplay (thePictureWindow -> d_xmShell), XtWindow (thePictureWindow -> d_xmShell));
1701 #elif cocoa
1702 GuiThing_show (thePictureWindow);
1703 #endif
1704 }
1705 /*
1706 Obsolete comment (noticed 2023-04-05):
1707 Foregoing drawing routines may have changed some of the output attributes
1708 that can be set by the user.
1709 Make sure that they have the right values before every drawing.
1710 This is especially necessary after an 'erase picture':
1711 the output attributes that were set by the user before the 'erase'
1712 must be recorded before copying to a PostScript file.
1713 */
1714 Graphics_setFont (GRAPHICS, theCurrentPraatPicture -> font);
1715 Graphics_setFontSize (GRAPHICS, theCurrentPraatPicture -> fontSize);
1716 Graphics_setLineType (GRAPHICS, theCurrentPraatPicture -> lineType);
1717 Graphics_setLineWidth (GRAPHICS, theCurrentPraatPicture -> lineWidth);
1718 Graphics_setArrowSize (GRAPHICS, theCurrentPraatPicture -> arrowSize);
1719 Graphics_setSpeckleSize (GRAPHICS, theCurrentPraatPicture -> speckleSize);
1720 Graphics_setColour (GRAPHICS, theCurrentPraatPicture -> colour);
1721
1722 Graphics_setViewport (GRAPHICS, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC,
1723 theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
1724 /* The following will dump the axes to the PostScript file after Erase all. BUG: should be somewhere else. */
1725 double x1WC, x2WC, y1WC, y2WC;
1726 Graphics_inqWindow (GRAPHICS, & x1WC, & x2WC, & y1WC, & y2WC);
1727 Graphics_setWindow (GRAPHICS, x1WC, x2WC, y1WC, y2WC);
1728 }
1729
1730 void praat_picture_close () {
1731 if (theCurrentPraatPicture != & theForegroundPraatPicture)
1732 return;
1733 if (! theCurrentPraatApplication -> batch)
1734 Graphics_updateWs (GRAPHICS);
1735 }
1736
1737 Graphics praat_picture_datagui_open (bool eraseFirst) {
1738 if (eraseFirst)
1739 Picture_erase (praat_picture.get());
1740 praat_picture_open ();
1741 return GRAPHICS;
1742 }
1743
1744 void praat_picture_datagui_close () {
1745 praat_picture_close ();
1746 }
1747
1748 DIRECT (menu_cb_quit) {
1749 Gui_runQuitApplicationCallback ();
1750 END_NO_NEW_DATA
1751 }
1752
1753 static autoDaata pictureRecognizer (integer nread, const char *header, MelderFile file) {
1754 if (nread < 2)
1755 return autoDaata ();
1756 if (strnequ (header, "PraatPicture", 12)) {
1757 Picture_readFromPraatPictureFile (praat_picture.get(), file);
1758 return Thing_new (Daata); // a dummy
1759 }
1760 return autoDaata ();
1761 }
1762
1763 void praat_picture_init (bool showPictureWindowAtStartUp) {
1764 GuiScrolledWindow scrollWindow;
1765 GuiDrawingArea drawingArea = nullptr;
1766 int margin, width, height, resolution, x, y;
1767 theCurrentPraatPicture -> lineType = Graphics_DRAWN;
1768 theCurrentPraatPicture -> colour = Melder_BLACK;
1769 theCurrentPraatPicture -> lineWidth = 1.0;
1770 theCurrentPraatPicture -> arrowSize = 1.0;
1771 theCurrentPraatPicture -> speckleSize = 1.0;
1772 theCurrentPraatPicture -> x1NDC = 0.0;
1773 theCurrentPraatPicture -> x2NDC = 6.0;
1774 theCurrentPraatPicture -> y1NDC = Picture_HEIGHT - 4.0;
1775 theCurrentPraatPicture -> y2NDC = Picture_HEIGHT;
1776
1777 Data_recognizeFileType (pictureRecognizer);
1778
1779 if (! theCurrentPraatApplication -> batch) {
1780 double screenX, screenY, screenWidth, screenHeight;
1781 Gui_getWindowPositioningBounds (& screenX, & screenY, & screenWidth, & screenHeight);
1782 resolution = Gui_getResolution (nullptr);
1783 #if defined (macintosh)
1784 margin = 2;
1785 width = 6 * resolution + 20;
1786 height = Machine_getMenuBarBottom () + 9 * resolution + 24;
1787 x = screenX + screenWidth - width - 14;
1788 y = screenY + 0;
1789 width += margin * 2;
1790 #elif defined (_WIN32)
1791 margin = 2;
1792 width = 6 * resolution + 22;
1793 height = 9 * resolution + 24;
1794 x = screenX + screenWidth - width - 17;
1795 y = screenY + 0;
1796 #else
1797 margin = 0;
1798 width = 6 * resolution + 30;
1799 height = width * 3 / 2 + Machine_getTitleBarHeight ();
1800 x = screenX + screenWidth - width - 10;
1801 y = screenY + 0;
1802 width += margin * 2;
1803 #endif
1804 thePictureWindow = GuiWindow_create (x, y, width, height, 400, 200, Melder_cat (Melder_upperCaseAppName(), U" Picture"), nullptr, nullptr, 0);
1805 GuiWindow_addMenuBar (thePictureWindow);
1806 }
1807 if (! theCurrentPraatApplication -> batch) {
1808 fileMenu = GuiMenu_createInWindow (thePictureWindow, U"File", 0);
1809 editMenu = GuiMenu_createInWindow (thePictureWindow, U"Edit", 0);
1810 marginsMenu = GuiMenu_createInWindow (thePictureWindow, U"Margins", 0);
1811 worldMenu = GuiMenu_createInWindow (thePictureWindow, U"World", 0);
1812 selectMenu = GuiMenu_createInWindow (thePictureWindow, U"Select", 0);
1813 penMenu = GuiMenu_createInWindow (thePictureWindow, U"Pen", 0);
1814 fontMenu = GuiMenu_createInWindow (thePictureWindow, U"Font", 0);
1815 helpMenu = GuiMenu_createInWindow (thePictureWindow, U"Help", 0);
1816 }
1817
1818 praat_addMenuCommand (U"Picture", U"File", U"Picture info || Picture settings report",
1819 nullptr, 0, GRAPHICS_Picture_settings_report); // alternative GuiMenu_DEPRECATED_2007
1820 praat_addMenuCommand (U"Picture", U"File", U"-- save --", nullptr, 0, nullptr);
1821 #if defined (macintosh) || defined (UNIX)
1822 praat_addMenuCommand (U"Picture", U"File", U"Save as PDF file... || Write to PDF file...",
1823 nullptr, 'S', GRAPHICS_Picture_writeToPdfFile); // alternative GuiMenu_DEPRECATED_2011
1824 #endif
1825 praat_addMenuCommand (U"Picture", U"File", U"Save as 300-dpi PNG file...",
1826 nullptr, 0, GRAPHICS_Picture_writeToPngFile_300);
1827 #if defined (_WIN32)
1828 praat_addMenuCommand (U"Picture", U"File", U"Save as 600-dpi PNG file...",
1829 nullptr, 'S', GRAPHICS_Picture_writeToPngFile_600);
1830 #endif
1831 #if defined (macintosh) || defined (UNIX)
1832 praat_addMenuCommand (U"Picture", U"File", U"Save as 600-dpi PNG file...",
1833 nullptr, 0, GRAPHICS_Picture_writeToPngFile_600);
1834 #endif
1835 praat_addMenuCommand (U"Picture", U"File", U"Save as EPS file", nullptr, 0, nullptr);
1836 praat_addMenuCommand (U"Picture", U"File", U"PostScript settings...",
1837 nullptr, GuiMenu_DEPTH_1 | GuiMenu_NO_API, GRAPHICS_PostScript_settings);
1838 praat_addMenuCommand (U"Picture", U"File", U"Save as EPS file... || Write to EPS file...",
1839 nullptr, 1, GRAPHICS_Picture_writeToEpsFile); // alternative GuiMenu_DEPRECATED_2011
1840 praat_addMenuCommand (U"Picture", U"File", U"Save as fontless EPS file (XIPA)... || Write to fontless EPS file (XIPA)...",
1841 nullptr, 1, GRAPHICS_Picture_writeToFontlessEpsFile_xipa); // alternative GuiMenu_DEPRECATED_2011
1842 praat_addMenuCommand (U"Picture", U"File", U"Save as fontless EPS file (SILIPA)... || Write to fontless EPS file (SILIPA)...",
1843 nullptr, 1, GRAPHICS_Picture_writeToFontlessEpsFile_silipa); // alternative GuiMenu_DEPRECATED_2011
1844 #ifdef _WIN32
1845 praat_addMenuCommand (U"Picture", U"File", U"Save as Windows metafile... || Write to Windows metafile...",
1846 nullptr, 0, GRAPHICS_Picture_writeToWindowsMetafile); // alternative GuiMenu_DEPRECATED_2011
1847 #endif
1848 praat_addMenuCommand (U"Picture", U"File", U"-- praat picture file --", nullptr, 0, nullptr);
1849 praat_addMenuCommand (U"Picture", U"File", U"Read from praat picture file...",
1850 nullptr, 0, GRAPHICS_Picture_readFromPraatPictureFile);
1851 praat_addMenuCommand (U"Picture", U"File", U"Save as praat picture file... || Write to praat picture file...",
1852 nullptr, 0, GRAPHICS_Picture_writeToPraatPictureFile); // alternative GuiMenu_DEPRECATED_2011
1853 praat_addMenuCommand (U"Picture", U"File", U"-- print --", nullptr, 0, nullptr);
1854 #if defined (macintosh)
1855 praat_addMenuCommand (U"Picture", U"File", U"Page setup...",
1856 nullptr, GuiMenu_NO_API, GRAPHICS_Page_setup);
1857 #endif
1858 praat_addMenuCommand (U"Picture", U"File", U"Print...", nullptr, 'P' | GuiMenu_NO_API, GRAPHICS_Print);
1859 #ifndef macintosh
1860 praat_addMenuCommand (U"Picture", U"File", U"-- close --", nullptr, 0, nullptr);
1861 //praat_addMenuCommand (U"Picture", U"File", U"Close", nullptr, 'W', menu_cb_close);
1862 praat_addMenuCommand (U"Picture", U"File", Melder_cat (U"Quit ", Melder_upperCaseAppName (), U" || Quit"), nullptr, 'Q', menu_cb_quit);
1863 #endif
1864
1865 praat_addMenuCommand (U"Picture", U"Edit", U"Undo", nullptr, 'Z' | GuiMenu_NO_API, GRAPHICS_Undo);
1866 #if defined (macintosh) || defined (_WIN32)
1867 praat_addMenuCommand (U"Picture", U"Edit", U"-- clipboard --", nullptr, 0, nullptr);
1868 praat_addMenuCommand (U"Picture", U"Edit", U"Copy to clipboard", nullptr, 'C' | GuiMenu_NO_API, GRAPHICS_Copy_picture_to_clipboard);
1869 #endif
1870 praat_addMenuCommand (U"Picture", U"Edit", U"-- erase --", nullptr, 0, nullptr);
1871 praat_addMenuCommand (U"Picture", U"Edit", U"Erase all", nullptr, 'E', GRAPHICS_Erase_all);
1872
1873 praat_addMenuCommand (U"Picture", U"Margins", U"Draw inner box", nullptr, 0, GRAPHICS_DrawInnerBox);
1874 praat_addMenuCommand (U"Picture", U"Margins", U"-- text --", nullptr, 0, nullptr);
1875 praat_addMenuCommand (U"Picture", U"Margins", U"Text left...", nullptr, 0, GRAPHICS_TextLeft);
1876 praat_addMenuCommand (U"Picture", U"Margins", U"Text right...", nullptr, 0, GRAPHICS_TextRight);
1877 praat_addMenuCommand (U"Picture", U"Margins", U"Text top...", nullptr, 0, GRAPHICS_TextTop);
1878 praat_addMenuCommand (U"Picture", U"Margins", U"Text bottom...", nullptr, 0, GRAPHICS_TextBottom);
1879 praat_addMenuCommand (U"Picture", U"Margins", U"-- marks every --", nullptr, 0, nullptr);
1880 praat_addMenuCommand (U"Picture", U"Margins", U"Marks left every...", nullptr, 0, GRAPHICS_MarksLeftEvery);
1881 praat_addMenuCommand (U"Picture", U"Margins", U"Marks right every...", nullptr, 0, GRAPHICS_MarksRightEvery);
1882 praat_addMenuCommand (U"Picture", U"Margins", U"Marks bottom every...", nullptr, 0, GRAPHICS_MarksBottomEvery);
1883 praat_addMenuCommand (U"Picture", U"Margins", U"Marks top every...", nullptr, 0, GRAPHICS_MarksTopEvery);
1884 praat_addMenuCommand (U"Picture", U"Margins", U"-- one mark --", nullptr, 0, nullptr);
1885 praat_addMenuCommand (U"Picture", U"Margins", U"One mark left...", nullptr, 0, GRAPHICS_OneMarkLeft);
1886 praat_addMenuCommand (U"Picture", U"Margins", U"One mark right...", nullptr, 0, GRAPHICS_OneMarkRight);
1887 praat_addMenuCommand (U"Picture", U"Margins", U"One mark bottom...", nullptr, 0, GRAPHICS_OneMarkBottom);
1888 praat_addMenuCommand (U"Picture", U"Margins", U"One mark top...", nullptr, 0, GRAPHICS_OneMarkTop);
1889 praat_addMenuCommand (U"Picture", U"Margins", U"-- marks --", nullptr, 0, nullptr);
1890 praat_addMenuCommand (U"Picture", U"Margins", U"Marks", nullptr, 0, nullptr);
1891 praat_addMenuCommand (U"Picture", U"Margins", U"Marks left...", nullptr, 1, GRAPHICS_MarksLeft);
1892 praat_addMenuCommand (U"Picture", U"Margins", U"Marks right...", nullptr, 1, GRAPHICS_MarksRight);
1893 praat_addMenuCommand (U"Picture", U"Margins", U"Marks bottom...", nullptr, 1, GRAPHICS_MarksBottom);
1894 praat_addMenuCommand (U"Picture", U"Margins", U"Marks top...", nullptr, 1, GRAPHICS_MarksTop);
1895 praat_addMenuCommand (U"Picture", U"Margins", U"Logarithmic marks", nullptr, 0, nullptr);
1896 praat_addMenuCommand (U"Picture", U"Margins", U"Logarithmic marks left...", nullptr, 1, GRAPHICS_LogarithmicMarksLeft);
1897 praat_addMenuCommand (U"Picture", U"Margins", U"Logarithmic marks right...", nullptr, 1, GRAPHICS_LogarithmicMarksRight);
1898 praat_addMenuCommand (U"Picture", U"Margins", U"Logarithmic marks bottom...", nullptr, 1, GRAPHICS_LogarithmicMarksBottom);
1899 praat_addMenuCommand (U"Picture", U"Margins", U"Logarithmic marks top...", nullptr, 1, GRAPHICS_LogarithmicMarksTop);
1900 praat_addMenuCommand (U"Picture", U"Margins", U"One logarithmic mark", nullptr, 0, nullptr);
1901 praat_addMenuCommand (U"Picture", U"Margins", U"One logarithmic mark left...", nullptr, 1, GRAPHICS_OneLogarithmicMarkLeft);
1902 praat_addMenuCommand (U"Picture", U"Margins", U"One logarithmic mark right...", nullptr, 1, GRAPHICS_OneLogarithmicMarkRight);
1903 praat_addMenuCommand (U"Picture", U"Margins", U"One logarithmic mark bottom...", nullptr, 1, GRAPHICS_OneLogarithmicMarkBottom);
1904 praat_addMenuCommand (U"Picture", U"Margins", U"One logarithmic mark top...", nullptr, 1, GRAPHICS_OneLogarithmicMarkTop);
1905 praat_addMenuCommand (U"Picture", U"Margins", U"-- axes --", nullptr, 0, nullptr);
1906 praat_addMenuCommand (U"Picture", U"Margins", U"Axes...", nullptr, 0, GRAPHICS_Axes);
1907
1908 praat_addMenuCommand (U"Picture", U"World", U"Text...", nullptr, 0, GRAPHICS_Text);
1909 praat_addMenuCommand (U"Picture", U"World", U"Text special...", nullptr, 0, GRAPHICS_TextSpecial);
1910 praat_addMenuCommand (U"Picture", U"World", U"Rectangle text (maximal fit)...", nullptr, 0, GRAPHICS_RectangleText_MaximalFit);
1911 praat_addMenuCommand (U"Picture", U"World", U"Rectangle text (wrap & truncate)...", nullptr, 0, GRAPHICS_RectangleText_WrapAndTruncate);
1912 praat_addMenuCommand (U"Picture", U"World", U"-- line --", nullptr, 0, nullptr);
1913 praat_addMenuCommand (U"Picture", U"World", U"Draw line...", nullptr, 0, GRAPHICS_DrawLine);
1914 praat_addMenuCommand (U"Picture", U"World", U"Draw arrow...", nullptr, 0, GRAPHICS_DrawArrow);
1915 praat_addMenuCommand (U"Picture", U"World", U"Draw two-way arrow...", nullptr, 0, GRAPHICS_DrawDoubleArrow);
1916 praat_addMenuCommand (U"Picture", U"World", U"-- function --", nullptr, 0, nullptr);
1917 praat_addMenuCommand (U"Picture", U"World", U"Draw function...", nullptr, 0, GRAPHICS_DrawFunction);
1918 praat_addMenuCommand (U"Picture", U"World", U"-- rectangle --", nullptr, 0, nullptr);
1919 praat_addMenuCommand (U"Picture", U"World", U"Draw rectangle...", nullptr, 0, GRAPHICS_DrawRectangle);
1920 praat_addMenuCommand (U"Picture", U"World", U"Paint rectangle...", nullptr, 0, GRAPHICS_PaintRectangle);
1921 praat_addMenuCommand (U"Picture", U"World", U"Draw rounded rectangle...", nullptr, 0, GRAPHICS_DrawRoundedRectangle);
1922 praat_addMenuCommand (U"Picture", U"World", U"Paint rounded rectangle...", nullptr, 0, GRAPHICS_PaintRoundedRectangle);
1923 praat_addMenuCommand (U"Picture", U"World", U"-- arc --", nullptr, 0, nullptr);
1924 praat_addMenuCommand (U"Picture", U"World", U"Draw arc...", nullptr, 0, GRAPHICS_DrawArc);
1925 praat_addMenuCommand (U"Picture", U"World", U"Draw ellipse...", nullptr, 0, GRAPHICS_DrawEllipse);
1926 praat_addMenuCommand (U"Picture", U"World", U"Paint ellipse...", nullptr, 0, GRAPHICS_PaintEllipse);
1927 praat_addMenuCommand (U"Picture", U"World", U"Draw circle...", nullptr, 0, GRAPHICS_DrawCircle);
1928 praat_addMenuCommand (U"Picture", U"World", U"Paint circle...", nullptr, 0, GRAPHICS_PaintCircle);
1929 praat_addMenuCommand (U"Picture", U"World", U"Draw circle (mm)...", nullptr, 0, GRAPHICS_DrawCircle_mm);
1930 praat_addMenuCommand (U"Picture", U"World", U"Paint circle (mm)...", nullptr, 0, GRAPHICS_PaintCircle_mm);
1931 praat_addMenuCommand (U"Picture", U"World", U"-- picture --", nullptr, 0, nullptr);
1932 praat_addMenuCommand (U"Picture", U"World", U"Insert picture from file...", nullptr, 0, GRAPHICS_InsertPictureFromFile);
1933 praat_addMenuCommand (U"Picture", U"World", U"Insert picture from file (embedded)...", nullptr, 0, GRAPHICS_InsertPictureFromFile_embedded);
1934 praat_addMenuCommand (U"Picture", U"World", U"-- axes --", nullptr, 0, nullptr);
1935 praat_addMenuCommand (U"Picture", U"World", U"Axes...", nullptr, 0, GRAPHICS_Axes);
1936 praat_addMenuCommand (U"Picture", U"World", U"Measure", nullptr, 0, nullptr);
1937 praat_addMenuCommand (U"Picture", U"World", U"Horizontal mm to world coordinates... || Horizontal mm to wc...",
1938 nullptr, 1, GRAPHICS_HorizontalMmToWorldCoordinates); // alternative GuiMenu_DEPRECATED_2016
1939 praat_addMenuCommand (U"Picture", U"World", U"Horizontal world coordinates to mm... || Horizontal wc to mm...",
1940 nullptr, 1, GRAPHICS_HorizontalWorldCoordinatesToMm);
1941 praat_addMenuCommand (U"Picture", U"World", U"Vertical mm to world coordinates... || Vertical mm to wc...",
1942 nullptr, 1, GRAPHICS_VerticalMmToWorldCoordinates);
1943 praat_addMenuCommand (U"Picture", U"World", U"Vertical world coordinates to mm... || Vertical wc to mm...",
1944 nullptr, 1, GRAPHICS_VerticalWorldCoordinatesToMm);
1945 praat_addMenuCommand (U"Picture", U"World", U"-- text measure --", nullptr, 1, nullptr);
1946 praat_addMenuCommand (U"Picture", U"World", U"Text width (world coordinates)... || Text width (wc)...",
1947 nullptr, 1, GRAPHICS_TextWidth_worldCoordinates);
1948 praat_addMenuCommand (U"Picture", U"World", U"Text width (mm)...",
1949 nullptr, 1, GRAPHICS_TextWidth_mm);
1950 praat_addMenuCommand (U"Picture", U"World", U"PostScript text width (world coordinates)... || PostScript text width (wc)...",
1951 nullptr, 1, GRAPHICS_PostScriptTextWidth_worldCoordinates); // alternative GuiMenu_DEPRECATED_2016
1952 praat_addMenuCommand (U"Picture", U"World", U"PostScript text width (mm)...",
1953 nullptr, 1, GRAPHICS_PostScriptTextWidth_mm);
1954
1955 praatButton_innerViewport = praat_addMenuCommand (U"Picture", U"Select",
1956 U"Mouse selects inner viewport", nullptr, GuiMenu_RADIO_FIRST | GuiMenu_NO_API, GRAPHICS_MouseSelectsInnerViewport);
1957 praatButton_outerViewport = praat_addMenuCommand (U"Picture", U"Select",
1958 U"Mouse selects outer viewport", nullptr, GuiMenu_RADIO_NEXT | GuiMenu_NO_API, GRAPHICS_MouseSelectsOuterViewport);
1959 praat_addMenuCommand (U"Picture", U"Select", U"-- select --", nullptr, 0, nullptr);
1960 praat_addMenuCommand (U"Picture", U"Select", U"Select inner viewport...",
1961 nullptr, 0, GRAPHICS_SelectInnerViewport);
1962 praat_addMenuCommand (U"Picture", U"Select", U"Select outer viewport... || Viewport...",
1963 nullptr, 0, GRAPHICS_SelectOuterViewport);
1964 praat_addMenuCommand (U"Picture", U"Select", U"-- viewport drawing --", nullptr, 0, nullptr);
1965 praat_addMenuCommand (U"Picture", U"Select", U"Viewport text...",
1966 nullptr, 0, GRAPHICS_ViewportText);
1967
1968 praatButton_lines [Graphics_DRAWN] = praat_addMenuCommand (U"Picture", U"Pen",
1969 U"Solid line", nullptr, GuiMenu_RADIO_FIRST, GRAPHICS_Solid_line);
1970 praat_addMenuCommand (U"Picture", U"Pen",
1971 U"Plain line", nullptr, GuiMenu_RADIO_NEXT | GuiMenu_DEPRECATED_2006, GRAPHICS_Solid_line);
1972 praatButton_lines [Graphics_DOTTED] = praat_addMenuCommand (U"Picture", U"Pen",
1973 U"Dotted line", nullptr, GuiMenu_RADIO_NEXT, GRAPHICS_Dotted_line);
1974 praatButton_lines [Graphics_DASHED] = praat_addMenuCommand (U"Picture", U"Pen",
1975 U"Dashed line", nullptr, GuiMenu_RADIO_NEXT, GRAPHICS_Dashed_line);
1976 praatButton_lines [Graphics_DASHED_DOTTED] = praat_addMenuCommand (U"Picture", U"Pen",
1977 U"Dashed-dotted line", nullptr, GuiMenu_RADIO_NEXT, GRAPHICS_Dashed_dotted_line);
1978 praat_addMenuCommand (U"Picture", U"Pen", U"-- line width --", nullptr, 0, nullptr);
1979 praat_addMenuCommand (U"Picture", U"Pen", U"Line width...", nullptr, 0, GRAPHICS_Line_width);
1980 praat_addMenuCommand (U"Picture", U"Pen", U"Arrow size...", nullptr, 0, GRAPHICS_Arrow_size);
1981 praat_addMenuCommand (U"Picture", U"Pen", U"Speckle size...", nullptr, 0, GRAPHICS_Speckle_size);
1982 praat_addMenuCommand (U"Picture", U"Pen", U"-- colour --", nullptr, 0, nullptr);
1983 praat_addMenuCommand (U"Picture", U"Pen", U"Colour...", nullptr, 0, GRAPHICS_Colour);
1984 praatButton_black = praat_addMenuCommand (U"Picture", U"Pen", U"Black", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Black);
1985 praatButton_white = praat_addMenuCommand (U"Picture", U"Pen", U"White", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_White);
1986 praatButton_red = praat_addMenuCommand (U"Picture", U"Pen", U"Red", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Red);
1987 praatButton_green = praat_addMenuCommand (U"Picture", U"Pen", U"Green", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Green);
1988 praatButton_blue = praat_addMenuCommand (U"Picture", U"Pen", U"Blue", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Blue);
1989 praatButton_yellow = praat_addMenuCommand (U"Picture", U"Pen", U"Yellow", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Yellow);
1990 praatButton_cyan = praat_addMenuCommand (U"Picture", U"Pen", U"Cyan", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Cyan);
1991 praatButton_magenta = praat_addMenuCommand (U"Picture", U"Pen", U"Magenta", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Magenta);
1992 praatButton_maroon = praat_addMenuCommand (U"Picture", U"Pen", U"Maroon", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Maroon);
1993 praatButton_lime = praat_addMenuCommand (U"Picture", U"Pen", U"Lime", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Lime);
1994 praatButton_navy = praat_addMenuCommand (U"Picture", U"Pen", U"Navy", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Navy);
1995 praatButton_teal = praat_addMenuCommand (U"Picture", U"Pen", U"Teal", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Teal);
1996 praatButton_purple = praat_addMenuCommand (U"Picture", U"Pen", U"Purple", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Purple);
1997 praatButton_olive = praat_addMenuCommand (U"Picture", U"Pen", U"Olive", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Olive);
1998 praatButton_pink = praat_addMenuCommand (U"Picture", U"Pen", U"Pink", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Pink);
1999 praatButton_silver = praat_addMenuCommand (U"Picture", U"Pen", U"Silver", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Silver);
2000 praatButton_grey = praat_addMenuCommand (U"Picture", U"Pen", U"Grey", nullptr, GuiMenu_CHECKBUTTON, GRAPHICS_Grey);
2001
2002 praat_addMenuCommand (U"Picture", U"Font", U"Font size...", nullptr, 0, GRAPHICS_Font_size);
2003 praatButton_10 = praat_addMenuCommand (U"Picture", U"Font", U"10", nullptr, GuiMenu_CHECKBUTTON | GuiMenu_NO_API, GRAPHICS_10);
2004 praatButton_12 = praat_addMenuCommand (U"Picture", U"Font", U"12", nullptr, GuiMenu_CHECKBUTTON | GuiMenu_NO_API, GRAPHICS_12);
2005 praatButton_14 = praat_addMenuCommand (U"Picture", U"Font", U"14", nullptr, GuiMenu_CHECKBUTTON | GuiMenu_NO_API, GRAPHICS_14);
2006 praatButton_18 = praat_addMenuCommand (U"Picture", U"Font", U"18", nullptr, GuiMenu_CHECKBUTTON | GuiMenu_NO_API, GRAPHICS_18);
2007 praatButton_24 = praat_addMenuCommand (U"Picture", U"Font", U"24", nullptr, GuiMenu_CHECKBUTTON | GuiMenu_NO_API, GRAPHICS_24);
2008 praat_addMenuCommand (U"Picture", U"Font", U"-- font ---", nullptr, 0, nullptr);
2009 praatButton_fonts [(int) kGraphics_font::TIMES] = praat_addMenuCommand (U"Picture", U"Font",
2010 U"Times", nullptr, GuiMenu_RADIO_FIRST, GRAPHICS_NONE__Times);
2011 praatButton_fonts [(int) kGraphics_font::HELVETICA] = praat_addMenuCommand (U"Picture", U"Font",
2012 U"Helvetica", nullptr, GuiMenu_RADIO_NEXT, GRAPHICS_NONE__Helvetica);
2013 praatButton_fonts [(int) kGraphics_font::PALATINO] = praat_addMenuCommand (U"Picture", U"Font",
2014 U"Palatino", nullptr, GuiMenu_RADIO_NEXT, GRAPHICS_NONE__Palatino);
2015 praatButton_fonts [(int) kGraphics_font::COURIER] = praat_addMenuCommand (U"Picture", U"Font",
2016 U"Courier", nullptr, GuiMenu_RADIO_NEXT, GRAPHICS_NONE__Courier);
2017
2018 praat_addMenuCommand (U"Picture", U"Help", U"Praat Intro", nullptr, 0, HELP_PraatIntro_picture);
2019 praat_addMenuCommand (U"Picture", U"Help", U"Picture window help", nullptr, '?', HELP_PictureWindowHelp);
2020 praat_addMenuCommand (U"Picture", U"Help", U"-- text formatting help --", nullptr, 0, nullptr);
2021 praat_addMenuCommand (U"Picture", U"Help", U"About special symbols", nullptr, 0, HELP_AboutSpecialSymbols);
2022 praat_addMenuCommand (U"Picture", U"Help", U"About text styles", nullptr, 0, HELP_AboutTextStyles);
2023 praat_addMenuCommand (U"Picture", U"Help", U"Phonetic symbols", nullptr, 0, HELP_PhoneticSymbols);
2024 praat_addMenuCommand (U"Picture", U"Help", U"-- manual --", nullptr, 0, nullptr);
2025 praat_addMenuCommand (U"Picture", U"Help",
2026 Melder_cat (U"Search ", Melder_upperCaseAppName(), U" manual..."),
2027 nullptr, 'M', HELP_SearchManual_Picture);
2028
2029 if (! theCurrentPraatApplication -> batch) {
2030 width = resolution * Picture_WIDTH;
2031 height = resolution * Picture_HEIGHT;
2032 scrollWindow = GuiScrolledWindow_createShown (thePictureWindow, margin, 0, Machine_getMenuBarBottom () + margin, 0, 1, 1, 0);
2033 drawingArea = GuiDrawingArea_createShown (scrollWindow, width, height,
2034 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, 0);
2035 GuiThing_show (thePictureWindow);
2036 }
2037
2038 // TODO: Paul: deze moet VOOR de update functies anders krijgen die void_me 0x0
2039 praat_picture = Picture_create (drawingArea, ! theCurrentPraatApplication -> batch);
2040 // READ THIS!
2041 Picture_setSelectionChangedCallback (praat_picture.get(), cb_selectionChanged, nullptr);
2042 theCurrentPraatPicture -> graphics = static_cast<Graphics> (Picture_peekGraphics (praat_picture.get()));
2043
2044 updatePenMenu ();
2045 updateFontMenu ();
2046 updateSizeMenu ();
2047 updateViewportMenu ();
2048
2049 if (! theCurrentPraatApplication -> batch && ! showPictureWindowAtStartUp) {
2050 #if gtk
2051 gtk_widget_hide (GTK_WIDGET (thePictureWindow -> d_gtkWindow));
2052 #elif motif
2053 ShowWindow (thePictureWindow -> d_xmShell -> window, SW_HIDE);
2054 #elif cocoa
2055 GuiThing_hide (thePictureWindow);
2056 #endif
2057 }
2058 }
2059
2060 void praat_picture_prefsChanged () {
2061 updateFontMenu ();
2062 updateSizeMenu ();
2063 updateViewportMenu ();
2064 Graphics_setFontSize (theCurrentPraatPicture -> graphics, theCurrentPraatPicture -> fontSize); // so that the thickness of the selection rectangle is correct
2065 Picture_setMouseSelectsInnerViewport (praat_picture.get(), praat_mouseSelectsInnerViewport);
2066 }
2067
2068 /* End of file praat_picture.cpp */