praat_picture.cpp 85 KB

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