Debian Codegraph @

foned/FunctionArea.cpp

raw symbols SCIP
1 /* FunctionArea.cpp
2 *
3 * Copyright (C) 2022 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
19 #include "FunctionArea.h"
20 #include "EditorM.h"
21
22 Thing_implement (FunctionArea, Thing, 0);
23
24 #include "Prefs_define.h"
25 #include "FunctionArea_prefs.h"
26 #include "Prefs_install.h"
27 #include "FunctionArea_prefs.h"
28 #include "Prefs_copyToInstance.h"
29 #include "FunctionArea_prefs.h"
30
31 GuiMenuItem FunctionAreaMenu_addCommand (EditorMenu me, conststring32 itemTitle /* cattable */, uint32 flags,
32 FunctionAreaCommandCallback commandCallback, FunctionArea commandBoss)
33 {
34 return DataGuiMenu_addCommand (me, itemTitle, flags, commandCallback.get(), commandBoss);
35 }
36
37 static bool v_form_pictureSelection__drawSelectionTimes;
38 static bool v_form_pictureSelection__drawSelectionHairs;
39 void structFunctionArea :: v_form_pictureSelection (EditorCommand cmd) {
40 UiForm_addBoolean (cmd -> d_uiform.get(), & v_form_pictureSelection__drawSelectionTimes, nullptr, U"Draw selection times", true);
41 UiForm_addBoolean (cmd -> d_uiform.get(), & v_form_pictureSelection__drawSelectionHairs, nullptr, U"Draw selection hairs", true);
42 }
43 void structFunctionArea :: v_ok_pictureSelection (EditorCommand cmd) {
44 SET_BOOLEAN (v_form_pictureSelection__drawSelectionTimes, our classPref_picture_drawSelectionTimes())
45 SET_BOOLEAN (v_form_pictureSelection__drawSelectionHairs, our classPref_picture_drawSelectionHairs())
46 }
47 void structFunctionArea :: v_do_pictureSelection (EditorCommand /* cmd */) {
48 our setClassPref_picture_drawSelectionTimes (v_form_pictureSelection__drawSelectionTimes);
49 our setClassPref_picture_drawSelectionHairs (v_form_pictureSelection__drawSelectionHairs);
50 }
51
52 void FunctionArea_drawRightMark (FunctionArea me, double yWC, conststring32 yWC_string, conststring32 units, int verticalAlignment) {
53 static MelderString text;
54 MelderString_copy (& text, yWC_string, units);
55 double textWidth = Graphics_textWidth (my graphics(), text.string) + Graphics_dxMMtoWC (my graphics(), 0.5);
56 if (verticalAlignment != Graphics_HALF)
57 Graphics_line (my graphics(), my endWindow(), yWC, my endWindow() + textWidth, yWC);
58 Graphics_setTextAlignment (my graphics(), Graphics_LEFT, verticalAlignment);
59 if (verticalAlignment == Graphics_BOTTOM)
60 yWC -= Graphics_dyMMtoWC (my graphics(), 0.5);
61 Graphics_text (my graphics(), my endWindow(), yWC, text.string);
62 }
63
64 void FunctionArea_drawLegend_ (FunctionArea me,
65 conststring32 cattableText1, MelderColour colour1,
66 conststring32 cattableText2, MelderColour colour2,
67 conststring32 cattableText3, MelderColour colour3,
68 conststring32 cattableText4, MelderColour colour4
69 ) {
70 FunctionArea_setViewport (me);
71 Graphics_setWindow (my graphics(), 0.0, 1.0, my bottom_pxlt(), my top_pxlt());
72 Graphics_setColour (my graphics(), colour1);
73 Graphics_setTextAlignment (my graphics(), kGraphics_horizontalAlignment::RIGHT, Graphics_BASELINE);
74 double fontSize = Graphics_inqFontSize (my graphics()), oldFontSize = fontSize;
75 Graphics_setFont (my graphics(), kGraphics_font::TIMES);
76 //Graphics_setFontStyle (my graphics(), Graphics_ITALIC);
77 if (! cattableText1) cattableText1 = U"";
78 if (! cattableText2) cattableText2 = U"";
79 if (! cattableText3) cattableText3 = U"";
80 if (! cattableText4) cattableText4 = U"";
81 double lengthText1 = Graphics_textWidth (my graphics(), cattableText1);
82 double lengthText2 = Graphics_textWidth (my graphics(), cattableText2);
83 double lengthText3 = Graphics_textWidth (my graphics(), cattableText3);
84 double lengthText4 = Graphics_textWidth (my graphics(), cattableText4);
85 conststring32 separator1 = ( cattableText1 [0] != U'\0' &&
86 (cattableText2 [0] != U'\0' || cattableText3 [0] != U'\0' || cattableText4 [0] != U'\0') ? U" " : U"" );
87 conststring32 separator2 = ( cattableText2 [0] != U'\0' &&
88 (cattableText3 [0] != U'\0' || cattableText4 [0] != U'\0') ? U" " : U"" );
89 conststring32 separator3 = ( cattableText3 [0] != U'\0' &&
90 cattableText4 [0] != U'\0' ? U" " : U"" );
91 double lengthSep1 = Graphics_textWidth (my graphics(), separator1);
92 double lengthSep2 = Graphics_textWidth (my graphics(), separator2);
93 double lengthSep3 = Graphics_textWidth (my graphics(), separator3);
94 double totalLength = lengthText1 + lengthSep1 + lengthText2 + lengthSep2 +
95 lengthText3 + lengthSep3 + lengthText4;
96 if (totalLength > 1.0) {
97 fontSize = floor (fontSize / totalLength);
98 Graphics_setFontSize (my graphics(), fontSize);
99 lengthText1 = Graphics_textWidth (my graphics(), cattableText1);
100 lengthText2 = Graphics_textWidth (my graphics(), cattableText2);
101 lengthText3 = Graphics_textWidth (my graphics(), cattableText3);
102 lengthText4 = Graphics_textWidth (my graphics(), cattableText4);
103 lengthSep1 = Graphics_textWidth (my graphics(), separator1);
104 lengthSep2 = Graphics_textWidth (my graphics(), separator2);
105 lengthSep3 = Graphics_textWidth (my graphics(), separator3);
106 }
107 totalLength = lengthText1 + lengthSep1 + lengthText2 + lengthSep2 +
108 lengthText3 + lengthSep3 + lengthText4;
109 if (totalLength > 1.0) {
110 fontSize -= 1.0;
111 Graphics_setFontSize (my graphics(), fontSize);
112 lengthText1 = Graphics_textWidth (my graphics(), cattableText1);
113 lengthText2 = Graphics_textWidth (my graphics(), cattableText2);
114 lengthText3 = Graphics_textWidth (my graphics(), cattableText3);
115 lengthText4 = Graphics_textWidth (my graphics(), cattableText4);
116 lengthSep1 = Graphics_textWidth (my graphics(), separator1);
117 lengthSep2 = Graphics_textWidth (my graphics(), separator2);
118 lengthSep3 = Graphics_textWidth (my graphics(), separator3);
119 }
120 Graphics_setColour (my graphics(), colour1);
121 const double y = my top_pxlt() + 2;
122 Graphics_text (my graphics(), 1.0 - lengthText4 - lengthSep3 - lengthText3 - lengthSep2 - lengthText2 - lengthSep1,
123 y, cattableText1);
124 Graphics_setColour (my graphics(), colour2);
125 Graphics_text (my graphics(), 1.0 - lengthText4 - lengthSep3 - lengthText3 - lengthSep2,
126 y, cattableText2);
127 Graphics_setColour (my graphics(), colour3);
128 Graphics_text (my graphics(), 1.0 - lengthText4 - lengthSep3,
129 y, cattableText3);
130 Graphics_setColour (my graphics(), colour4);
131 Graphics_text (my graphics(), 1.0,
132 y, cattableText4);
133 Graphics_setColour (my graphics(), Melder_BLACK);
134 Graphics_text (my graphics(), 1.0 - lengthText4 - lengthSep3 - lengthText3 - lengthSep2 - lengthText2,
135 y, separator1);
136 Graphics_text (my graphics(), 1.0 - lengthText4 - lengthSep3 - lengthText3,
137 y, separator2);
138 Graphics_text (my graphics(), 1.0 - lengthText4,
139 y, separator3);
140 Graphics_setFont (my graphics(), kGraphics_font::HELVETICA);
141 Graphics_setFontStyle (my graphics(), Graphics_NORMAL);
142 Graphics_setFontSize (my graphics(), oldFontSize);
143 }
144
145 void FunctionArea_garnishPicture (FunctionArea me) {
146 if (my classPref_picture_drawSelectionTimes()) {
147 if (my startSelection() >= my startWindow() && my startSelection() <= my endWindow())
148 Graphics_markTop (my pictureGraphics(), my startSelection(), true, true, false, nullptr);
149 if (my endSelection() != my startSelection() && my endSelection() >= my startWindow() && my endSelection() <= my endWindow())
150 Graphics_markTop (my pictureGraphics(), my endSelection(), true, true, false, nullptr);
151 }
152 if (my classPref_picture_drawSelectionHairs()) {
153 if (my startSelection() >= my startWindow() && my startSelection() <= my endWindow())
154 Graphics_markTop (my pictureGraphics(), my startSelection(), false, false, true, nullptr);
155 if (my endSelection() != my startSelection() && my endSelection() >= my startWindow() && my endSelection() <= my endWindow())
156 Graphics_markTop (my pictureGraphics(), my endSelection(), false, false, true, nullptr);
157 }
158 }
159
160 /* End of file FunctionArea.cpp */