FunctionEditor.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #ifndef _FunctionEditor_h_
  2. #define _FunctionEditor_h_
  3. /* FunctionEditor.h
  4. *
  5. * Copyright (C) 1992-2011,2012,2013,2014,2015,2017 Paul Boersma
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "Editor.h"
  21. #include "Graphics.h"
  22. #include "Function.h"
  23. struct FunctionEditor_picture {
  24. /* KEEP IN SYNC WITH PREFS. */
  25. bool garnish;
  26. };
  27. Thing_define (FunctionEditor, Editor) {
  28. /* Subclass may change the following attributes, */
  29. /* but has to respect the invariants, */
  30. /* and has to call FunctionEditor_marksChanged () */
  31. /* immediately after making the changes. */
  32. double tmin, tmax, startWindow, endWindow;
  33. double startSelection, endSelection; // markers
  34. /* These attributes are all expressed in seconds. Invariants: */
  35. /* tmin <= startWindow < endWindow <= tmax; */
  36. /* tmin <= (startSelection, endSelection) <= tmax; */
  37. autoGraphics graphics; // used in the 'draw' method
  38. int functionViewerLeft, functionViewerRight; // size of drawing areas in pixels
  39. int selectionViewerLeft, selectionViewerRight; // size of drawing areas in pixels
  40. int height; // size of drawing areas in pixels
  41. GuiText text; // optional text at top
  42. int shiftKeyPressed; // information for the 'play' method
  43. bool playingCursor, playingSelection; // information for end of play
  44. struct FunctionEditor_picture picture;
  45. /* Private: */
  46. GuiDrawingArea drawingArea;
  47. GuiScrollBar scrollBar;
  48. GuiCheckButton groupButton;
  49. GuiObject bottomArea;
  50. bool group, enableUpdates;
  51. int nrect;
  52. struct { double left, right, bottom, top; } rect [8];
  53. double marker [1 + 3], playCursor, startZoomHistory, endZoomHistory;
  54. int numberOfMarkers;
  55. void v_destroy () noexcept
  56. override;
  57. void v_info ()
  58. override;
  59. void v_createMenus ()
  60. override;
  61. void v_createMenuItems_file (EditorMenu)
  62. override;
  63. void v_createMenuItems_query (EditorMenu)
  64. override;
  65. void v_createChildren ()
  66. override;
  67. void v_createHelpMenuItems (EditorMenu)
  68. override;
  69. void v_dataChanged ()
  70. override;
  71. virtual void v_draw () { }
  72. /*
  73. * Message: "draw your part of the data between startWindow and endWindow."
  74. */
  75. virtual void v_drawSelectionViewer () { }
  76. virtual void v_drawRealTimeSelectionViewer (int /* phase */, double /* time */) { }
  77. virtual void v_prepareDraw () { } // for less flashing
  78. virtual conststring32 v_format_domain () { return U"Time domain:"; }
  79. virtual const char *v_format_short () { return u8"%.3f"; }
  80. virtual const char *v_format_long () { return u8"%f"; }
  81. virtual conststring32 v_format_units () { return U"seconds"; }
  82. virtual const char *v_format_totalDuration () { return u8"Total duration %f seconds"; }
  83. virtual const char *v_format_window () { return u8"Visible part %f seconds"; }
  84. virtual const char *v_format_selection () { return u8"%f (%.3f / s)"; }
  85. virtual int v_fixedPrecision_long () { return 6; }
  86. virtual bool v_hasText () { return false; }
  87. virtual void v_play (double /* timeFrom */, double /* timeTo */) { }
  88. /*
  89. * Message: "the user clicked in one of the rectangles above or below the data window."
  90. */
  91. virtual bool v_click (double xWC, double yWC, bool shiftKeyPressed);
  92. /*
  93. * Message: "the user clicked in data window with the left mouse button."
  94. * 'xWC' is the time;
  95. * 'yWC' is a value between 0.0 (bottom) and 1.0 (top);
  96. * 'shiftKeyPressed' flags if the Shift key was held down during the click.
  97. * Constraints:
  98. * Return FunctionEditor_UPDATE_NEEDED if you want a window update, i.e.,
  99. * if your 'click' moves the cursor or otherwise changes the appearance of the data.
  100. * Return FunctionEditor_NO_UPDATE_NEEDED if you do not want a window update, e.g.,
  101. * if your 'click' method just 'plays' something or puts a dialog on the screen.
  102. * In the latter case, the 'ok' callback of the dialog should
  103. * call FunctionEditor_marksChanged if necessary.
  104. * Behaviour of FunctionEditor::click ():
  105. * moves the cursor to 'xWC', drags to create a selection, or extends the selection.
  106. */
  107. virtual void v_clickSelectionViewer (double xWC, double yWC);
  108. virtual bool v_clickB (double xWC, double yWC);
  109. virtual bool v_clickE (double xWC, double yWC);
  110. virtual int v_playCallback (int phase, double tmin, double tmax, double t);
  111. virtual void v_updateText () { }
  112. virtual void v_prefs_addFields (EditorCommand) { }
  113. virtual void v_prefs_setValues (EditorCommand) { }
  114. virtual void v_prefs_getValues (EditorCommand) { }
  115. virtual void v_createMenuItems_file_draw (EditorMenu) { }
  116. virtual void v_createMenuItems_file_extract (EditorMenu) { }
  117. virtual void v_createMenuItems_file_write (EditorMenu) { }
  118. virtual void v_createMenuItems_view (EditorMenu);
  119. virtual void v_createMenuItems_view_timeDomain (EditorMenu);
  120. virtual void v_createMenuItems_view_audio (EditorMenu);
  121. virtual void v_highlightSelection (double left, double right, double bottom, double top);
  122. virtual void v_unhighlightSelection (double left, double right, double bottom, double top);
  123. virtual double v_getBottomOfSoundArea () { return 0.0; }
  124. virtual double v_getBottomOfSoundAndAnalysisArea () { return 0.0; }
  125. virtual void v_form_pictureSelection (EditorCommand);
  126. virtual void v_ok_pictureSelection (EditorCommand);
  127. virtual void v_do_pictureSelection (EditorCommand);
  128. #include "FunctionEditor_prefs.h"
  129. };
  130. int theFunctionEditor_playCallback (FunctionEditor me, int phase, double tmin, double tmax, double t);
  131. /*
  132. Attributes:
  133. data: must be a Function.
  134. int clickB (double xWC, double yWC);
  135. "user clicked in data window with the middle mouse button (Mac: control- or option-click)."
  136. 'xWC' is the time; 'yWC' is a value between 0.0 (bottom) and 1.0 (top).
  137. For the return value, see the 'click' method.
  138. FunctionEditor::clickB simply moves the start of the selection (B) to 'xWC',
  139. with the sole statement 'my startSelection = xWC'.
  140. int clickE (double xWC, double yWC);
  141. "user clicked in data window with the right mouse button (Mac: command-click)."
  142. 'xWC' is the time; 'yWC' is a value between 0.0 (bottom) and 1.0 (top).
  143. For the return value, see the 'click' method.
  144. FunctionEditor::clickB simply moves the end of the selection (E) to 'xWC',
  145. with the sole statement 'my endSelection = xWC'.
  146. void key (unsigned char key);
  147. "user typed a key to the data window."
  148. FunctionEditor::key ignores this message.
  149. */
  150. #define FunctionEditor_UPDATE_NEEDED true
  151. #define FunctionEditor_NO_UPDATE_NEEDED false
  152. void FunctionEditor_init (FunctionEditor me, conststring32 title, Function data);
  153. /*
  154. Function:
  155. creates an Editor with a drawing area, a scroll bar and some buttons.
  156. Postconditions:
  157. my drawingArea is attached to the form at all sides,
  158. my scrollBar only to the bottom, left and right sides.
  159. */
  160. void FunctionEditor_marksChanged (FunctionEditor me, bool needsUpdateGroup);
  161. /*
  162. Function:
  163. update optional text field, the scroll bar, the drawing area and the buttons,
  164. from the current total time, window, cursor, and selection,
  165. and redraw the contents.
  166. If needsUpdateGroup is true, this will be done for all the editors in the group.
  167. Usage:
  168. call this after a change in any of the markers or in the duration of the data.
  169. */
  170. void FunctionEditor_shift (FunctionEditor me, double shift, bool needsUpdateGroup);
  171. /*
  172. Function:
  173. shift (scroll) the window through time, keeping the window length constant.
  174. Usage:
  175. call this after a search.
  176. */
  177. void FunctionEditor_updateText (FunctionEditor me);
  178. /*
  179. Function:
  180. update the optional text widget.
  181. Usage:
  182. call this after moving the cursor, if that would have to change the text.
  183. The generic FunctionEditor also calls this if one of the other marks have changed.
  184. Behaviour:
  185. we just call the updateText method, which the inheritor will have to modify,
  186. since FunctionEditor::updateText does nothing.
  187. */
  188. void FunctionEditor_redraw (FunctionEditor me);
  189. /*
  190. Function:
  191. update the drawing area of a single editor.
  192. Usage:
  193. calls this after she changes a view option (font, scaling, hide/show xx)
  194. or after any of the data have changed. In the latter case, also call Editor_broadcastChange.
  195. Behaviour:
  196. we just call Graphics_updateWs (my graphics).
  197. */
  198. void FunctionEditor_enableUpdates (FunctionEditor me, bool enable);
  199. /*
  200. Function:
  201. temporarily disable update event to cause 'draw' messages.
  202. Usage:
  203. If you call from your 'draw' method routines that may trigger expose events,
  204. you should bracket those routines between
  205. FunctionEditor_enableUpdates (me, false);
  206. and
  207. FunctionEditor_enableUpdates (me, true);
  208. This may happen if you call an analysis routine which calls Melder_progress.
  209. */
  210. void FunctionEditor_ungroup (FunctionEditor me);
  211. /*
  212. Function:
  213. force me out of the group.
  214. Usage:
  215. Start cut or paste methods by calling this routine,
  216. as the grouped editors will not be synchronized
  217. after either of those actions. Worse, the selection
  218. may get outside the common interval of the editors.
  219. */
  220. /* Some routines to enforce common look to all function editors. */
  221. /* The x axis of the window is supposed to have been set to [my startWindow, my endWindow]. */
  222. /* Preconditions: default line type, default line width. */
  223. /* Postconditions: default line type, default line width, undefined colour, undefined text alignment. */
  224. void FunctionEditor_drawRangeMark (FunctionEditor me, double yWC, conststring32 yWC_string, conststring32 units, int verticalAlignment);
  225. void FunctionEditor_drawCursorFunctionValue (FunctionEditor me, double yWC, conststring32 yWC_string, conststring32 units);
  226. void FunctionEditor_insertCursorFunctionValue (FunctionEditor me, double yWC, conststring32 yWC_string, conststring32 units, double minimum, double maximum);
  227. void FunctionEditor_drawHorizontalHair (FunctionEditor me, double yWC, conststring32 yWC_string, conststring32 units);
  228. void FunctionEditor_drawGridLine (FunctionEditor me, double yWC);
  229. void FunctionEditor_garnish (FunctionEditor me); // Optionally selection times and selection hairs.
  230. /* End of file FunctionEditor.h */
  231. #endif