| 1 |
/* NoulliGridEditor.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 2018-2023 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 "NoulliGridEditor.h" |
| 20 |
#include "EditorM.h" |
| 21 |
|
| 22 |
#include "enums_getText.h" |
| 23 |
#include "NoulliGridEditor_enums.h" |
| 24 |
#include "enums_getValue.h" |
| 25 |
#include "NoulliGridEditor_enums.h" |
| 26 |
|
| 27 |
Thing_implement (NoulliGridEditor, FunctionEditor, 0); |
| 28 |
|
| 29 |
#include "Prefs_define.h" |
| 30 |
#include "NoulliGridEditor_prefs.h" |
| 31 |
#include "Prefs_install.h" |
| 32 |
#include "NoulliGridEditor_prefs.h" |
| 33 |
#include "Prefs_copyToInstance.h" |
| 34 |
#include "NoulliGridEditor_prefs.h" |
| 35 |
|
| 36 |
static void drawSelectionOrWindow (NoulliGridEditor me, double tmin, double tmax, conststring32 header) { |
| 37 |
for (integer itier = 1; itier <= my noulliGrid() -> tiers.size; itier ++) { |
| 38 |
if (itier == 1) { |
| 39 |
Graphics_setColour (my graphics.get(), Melder_BLACK); |
| 40 |
Graphics_setTextAlignment (my graphics.get(), kGraphics_horizontalAlignment::CENTRE, Graphics_BOTTOM); |
| 41 |
Graphics_text (my graphics.get(), 0.0, 1.0, header); |
| 42 |
} |
| 43 |
autoNoulliPoint average = NoulliGrid_average (my noulliGrid(), itier, tmin, tmax); |
| 44 |
integer winningCategory = NoulliPoint_getWinningCategory (average.get()); |
| 45 |
conststring32 winningCategoryName = my noulliGrid() -> categoryNames [winningCategory].get(); |
| 46 |
if (winningCategory != 0 && average -> probabilities [winningCategory] > 1.0/3.0) { |
| 47 |
const bool shouldDrawPicture = |
| 48 |
(my instancePref_showCategoryInSelectionViewerAs() == kNoulliGridEditor_showCategoryInSelectionViewerAs::PICTURE || |
| 49 |
my instancePref_showCategoryInSelectionViewerAs() == kNoulliGridEditor_showCategoryInSelectionViewerAs::PICTURE_AND_TEXT) |
| 50 |
&& |
| 51 |
(Melder_equ_firstCharacterCaseInsensitive (winningCategoryName, U"happy") || |
| 52 |
Melder_equ_firstCharacterCaseInsensitive (winningCategoryName, U"neutral") || |
| 53 |
Melder_equ_firstCharacterCaseInsensitive (winningCategoryName, U"sad") || |
| 54 |
Melder_equ_firstCharacterCaseInsensitive (winningCategoryName, U"scared") || |
| 55 |
Melder_equ_firstCharacterCaseInsensitive (winningCategoryName, U"angry")); |
| 56 |
if (shouldDrawPicture) { |
| 57 |
Graphics_setColour (my graphics.get(), Melder_cyclingBackgroundColour (winningCategory)); |
| 58 |
Graphics_fillEllipse (my graphics.get(), -0.985, +0.985, -0.985, +0.985); |
| 59 |
Graphics_setColour (my graphics.get(), Melder_cyclingTextColour (winningCategory)); |
| 60 |
/* |
| 61 |
Draw the eyes. |
| 62 |
*/ |
| 63 |
if (Melder_equ_firstCharacterCaseInsensitive (winningCategoryName, U"happy")) { |
| 64 |
Graphics_setLineWidth (my graphics.get(), 15.0); |
| 65 |
const double dx = 0.375, y = 0.10, radius = 0.18, angle = 85.0; |
| 66 |
Graphics_arc (my graphics.get(), - dx, y, radius, 90.0 - angle, 90.0 + angle); // left eye |
| 67 |
Graphics_arc (my graphics.get(), + dx, y, radius, 90.0 - angle, 90.0 + angle); // right eye |
| 68 |
} else { |
| 69 |
const double dx = 0.375, y = 0.1875, radius = 0.125; |
| 70 |
Graphics_fillCircle (my graphics.get(), - dx, y, radius); // left eye |
| 71 |
Graphics_fillCircle (my graphics.get(), + dx, y, radius); // right eye |
| 72 |
} |
| 73 |
/* |
| 74 |
Draw the mouth. |
| 75 |
*/ |
| 76 |
Graphics_setLineWidth (my graphics.get(), 8.0); |
| 77 |
if (Melder_equ_firstCharacterCaseInsensitive (winningCategoryName, U"happy")) { |
| 78 |
const double y = -0.20, radius = 0.35, angle = 55.0; |
| 79 |
Graphics_arc (my graphics.get(), 0.0, y, radius, 270.0 - angle, 270.0 + angle); |
| 80 |
} else if (Melder_equ_firstCharacterCaseInsensitive (winningCategoryName, U"neutral")) { |
| 81 |
Graphics_setLineWidth (my graphics.get(), 13.0); |
| 82 |
const double dx = 0.20, y = -0.50; |
| 83 |
Graphics_line (my graphics.get(), - dx, y, + dx, y); |
| 84 |
} else if (Melder_equ_firstCharacterCaseInsensitive (winningCategoryName, U"sad")) { |
| 85 |
const double y = -0.80, radius = 0.35, angle = 55.0; |
| 86 |
Graphics_arc (my graphics.get(), 0.0, y, radius, 90.0 - angle, 90.0 + angle); |
| 87 |
} else if (Melder_equ_firstCharacterCaseInsensitive (winningCategoryName, U"scared")) { |
| 88 |
const double y = -0.50, dx = 0.10, dy = 0.25; |
| 89 |
Graphics_fillEllipse (my graphics.get(), - dx, + dx, y - dy, y + dy); |
| 90 |
} else if (Melder_equ_firstCharacterCaseInsensitive (winningCategoryName, U"angry")) { |
| 91 |
const double y = -0.80, radius = 0.35, angle = 55.0; |
| 92 |
Graphics_arc (my graphics.get(), 0.0, y, radius, 90.0 - angle, 90.0 + angle); |
| 93 |
} |
| 94 |
/* |
| 95 |
Draw the eyebrows. |
| 96 |
*/ |
| 97 |
Graphics_setLineWidth (my graphics.get(), 12.0); |
| 98 |
if (Melder_equ_firstCharacterCaseInsensitive (winningCategoryName, U"sad")) { |
| 99 |
const double dx1 = 0.60, dx2 = 0.30, y1 = 0.40, y2 = 0.60; |
| 100 |
Graphics_line (my graphics.get(), - dx2, y2, - dx1, y1); // left eyebrow |
| 101 |
Graphics_line (my graphics.get(), + dx1, y1, + dx2, y2); // right eyebrow |
| 102 |
} else if (Melder_equ_firstCharacterCaseInsensitive (winningCategoryName, U"scared")) { |
| 103 |
const double dx1 = 0.60, dx2 = 0.30, y1 = 0.45, y2 = 0.60; |
| 104 |
Graphics_line (my graphics.get(), - dx2, y2, - dx1, y1); // left eyebrow |
| 105 |
Graphics_line (my graphics.get(), + dx1, y1, + dx2, y2); // right eyebrow |
| 106 |
} else if (Melder_equ_firstCharacterCaseInsensitive (winningCategoryName, U"angry")) { |
| 107 |
const double dx1 = 0.25, dx2 = 0.55, y1 = 0.40, y2 = 0.60; |
| 108 |
Graphics_line (my graphics.get(), - dx2, y2, - dx1, y1); // left eyebrow |
| 109 |
Graphics_line (my graphics.get(), + dx1, y1, + dx2, y2); // right eyebrow |
| 110 |
} |
| 111 |
Graphics_setLineWidth (my graphics.get(), 1.0); |
| 112 |
} else { |
| 113 |
Graphics_setColour (my graphics.get(), Melder_cyclingBackgroundColour (winningCategory)); |
| 114 |
Graphics_fillEllipse (my graphics.get(), -0.985, +0.985, -0.985, +0.985); |
| 115 |
} |
| 116 |
if (my instancePref_showCategoryInSelectionViewerAs() == kNoulliGridEditor_showCategoryInSelectionViewerAs::COLOUR_AND_TEXT || |
| 117 |
my instancePref_showCategoryInSelectionViewerAs() == kNoulliGridEditor_showCategoryInSelectionViewerAs::PICTURE_AND_TEXT || |
| 118 |
my instancePref_showCategoryInSelectionViewerAs() == kNoulliGridEditor_showCategoryInSelectionViewerAs::PICTURE && ! shouldDrawPicture) |
| 119 |
{ |
| 120 |
Graphics_setColour (my graphics.get(), Melder_cyclingTextColour (winningCategory)); |
| 121 |
Graphics_setTextAlignment (my graphics.get(), kGraphics_horizontalAlignment::CENTRE, Graphics_HALF); |
| 122 |
Graphics_text (my graphics.get(), 0.0, 0.0, winningCategoryName); |
| 123 |
} |
| 124 |
} else { |
| 125 |
Graphics_setColour (my graphics.get(), Melder_WHITE); |
| 126 |
Graphics_fillEllipse (my graphics.get(), -0.985, +0.985, -0.985, +0.985); |
| 127 |
Graphics_setColour (my graphics.get(), Melder_BLACK); |
| 128 |
Graphics_setTextAlignment (my graphics.get(), kGraphics_horizontalAlignment::CENTRE, Graphics_HALF); |
| 129 |
Graphics_text (my graphics.get(), 0.0, 0.0, U"?"); |
| 130 |
} |
| 131 |
} |
| 132 |
Graphics_setColour (my graphics.get(), Melder_BLACK); |
| 133 |
} |
| 134 |
|
| 135 |
void structNoulliGridEditor :: v_drawSelectionViewer () { |
| 136 |
Graphics_setWindow (our graphics.get(), -1.0, +1.0, -1.0, +1.0); |
| 137 |
Graphics_setColour (our graphics.get(), DataGuiColour_WINDOW_BACKGROUND); |
| 138 |
Graphics_fillRectangle (our graphics.get(), -1.0, +1.0, -1.0, +1.0); |
| 139 |
drawSelectionOrWindow (this, our startSelection, our endSelection, U""); |
| 140 |
} |
| 141 |
|
| 142 |
void structNoulliGridEditor :: v_drawRealTimeSelectionViewer (double time) { |
| 143 |
Graphics_setWindow (our graphics.get(), -1.0, +1.0, -1.0, +1.0); |
| 144 |
drawSelectionOrWindow (this, time - 1.0, time + 1.0, U""); |
| 145 |
} |
| 146 |
|
| 147 |
OPTIONMENU_ENUM_VARIABLE (kNoulliGridEditor_showCategoryInSelectionViewerAs, v_prefs_addFields__showCategoryInSelectionViewerAs) |
| 148 |
void structNoulliGridEditor :: v_prefs_addFields (EditorCommand cmd) { |
| 149 |
OPTIONMENU_ENUM_FIELD (kNoulliGridEditor_showCategoryInSelectionViewerAs, v_prefs_addFields__showCategoryInSelectionViewerAs, |
| 150 |
U"Show category in selection viewer as", kNoulliGridEditor_showCategoryInSelectionViewerAs::DEFAULT) |
| 151 |
} |
| 152 |
void structNoulliGridEditor :: v_prefs_setValues (EditorCommand cmd) { |
| 153 |
SET_ENUM (v_prefs_addFields__showCategoryInSelectionViewerAs, kNoulliGridEditor_showCategoryInSelectionViewerAs, our instancePref_showCategoryInSelectionViewerAs()) |
| 154 |
} |
| 155 |
void structNoulliGridEditor :: v_prefs_getValues (EditorCommand /* cmd */) { |
| 156 |
our setInstancePref_showCategoryInSelectionViewerAs (v_prefs_addFields__showCategoryInSelectionViewerAs); |
| 157 |
} |
| 158 |
|
| 159 |
autoNoulliGridEditor NoulliGridEditor_create (conststring32 title, NoulliGrid noulliGrid, Sound optionalSoundToCopy) { |
| 160 |
try { |
| 161 |
autoNoulliGridEditor me = Thing_new (NoulliGridEditor); |
| 162 |
my noulliGridArea() = NoulliGridArea_create (true, nullptr, me.get()); |
| 163 |
if (optionalSoundToCopy) |
| 164 |
my soundArea() = SoundArea_create (false, optionalSoundToCopy, me.get()); |
| 165 |
FunctionEditor_init (me.get(), title, noulliGrid); |
| 166 |
return me; |
| 167 |
} catch (MelderError) { |
| 168 |
Melder_throw (U"NoulliGrid window not created."); |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
/* End of file NoulliGridEditor.cpp */ |
| 173 |
|