12int EditorInspector::findIndex(
const std::string &
id)
const {
13 for (
int i = 0; i < static_cast<int>(fields_.size()); ++i) {
14 if (fields_[i].
id ==
id)
return i;
19EditorInspector::Field *EditorInspector::find(
const std::string &
id) {
20 int i = findIndex(
id);
21 return i < 0 ? nullptr : &fields_[i];
24const EditorInspector::Field *EditorInspector::find(
const std::string &
id)
const {
25 int i = findIndex(
id);
26 return i < 0 ? nullptr : &fields_[i];
30 float minV,
float maxV,
float step) {
31 if (
id.empty() || findIndex(
id) >= 0)
throw Exception(
"EditorInspector::addFloat: bad id");
45 if (
id.empty() || findIndex(
id) >= 0)
throw Exception(
"EditorInspector::addFloat3: bad id");
57 if (
id.empty() || findIndex(
id) >= 0)
throw Exception(
"EditorInspector::addBool: bad id");
67 const std::string &
value) {
68 if (
id.empty() || findIndex(
id) >= 0)
throw Exception(
"EditorInspector::addString: bad id");
78 const std::string &choicesCsv,
const std::string &selected) {
79 if (
id.empty() || findIndex(
id) >= 0)
throw Exception(
"EditorInspector::addChoice: bad id");
84 f.choices = choicesCsv;
90 if (index < 0 || index >=
static_cast<int>(fields_.size()))
91 throw Exception(
"EditorInspector::getFieldKind: bad index");
92 return fields_[
index].kind;
95 if (index < 0 || index >=
static_cast<int>(fields_.size()))
96 throw Exception(
"EditorInspector::getFieldId: bad index");
97 return fields_[
index].id;
100 if (index < 0 || index >=
static_cast<int>(fields_.size()))
101 throw Exception(
"EditorInspector::getFieldLabel: bad index");
102 return fields_[
index].label;
106 const Field *
f = find(
id);
107 if (!
f ||
f->kind !=
"float")
throw Exception(
"EditorInspector::getFloat: missing float field");
113 if (!
f ||
f->kind !=
"float")
throw Exception(
"EditorInspector::setFloat: missing float field");
121 const Field *
f = find(
id);
122 if (!
f ||
f->kind !=
"float")
throw Exception(
"EditorInspector::getFloatMin: missing");
126 const Field *
f = find(
id);
127 if (!
f ||
f->kind !=
"float")
throw Exception(
"EditorInspector::getFloatMax: missing");
131 const Field *
f = find(
id);
132 if (!
f ||
f->kind !=
"float")
throw Exception(
"EditorInspector::getFloatStep: missing");
137 const Field *
f = find(
id);
138 if (!
f ||
f->kind !=
"float3")
throw Exception(
"EditorInspector::getFloat3X: missing");
142 const Field *
f = find(
id);
143 if (!
f ||
f->kind !=
"float3")
throw Exception(
"EditorInspector::getFloat3Y: missing");
147 const Field *
f = find(
id);
148 if (!
f ||
f->kind !=
"float3")
throw Exception(
"EditorInspector::getFloat3Z: missing");
154 if (!
f ||
f->kind !=
"float3")
throw Exception(
"EditorInspector::setFloat3: missing");
155 if (
f->f0 !=
x ||
f->f1 !=
y ||
f->f2 !=
z) {
164 const Field *
f = find(
id);
165 if (!
f ||
f->kind !=
"bool")
throw Exception(
"EditorInspector::getBool: missing");
171 if (!
f ||
f->kind !=
"bool")
throw Exception(
"EditorInspector::setBool: missing");
179 const Field *
f = find(
id);
180 if (!
f ||
f->kind !=
"string")
throw Exception(
"EditorInspector::getString: missing");
186 if (!
f ||
f->kind !=
"string")
throw Exception(
"EditorInspector::setString: missing");
194 const Field *
f = find(
id);
195 if (!
f ||
f->kind !=
"choice")
throw Exception(
"EditorInspector::getChoice: missing");
201 if (!
f ||
f->kind !=
"choice")
throw Exception(
"EditorInspector::setChoice: missing");
209 const Field *
f = find(
id);
210 if (!
f ||
f->kind !=
"choice")
throw Exception(
"EditorInspector::getChoicesCsv: missing");
215 const Field *
f = find(
id);
216 return f &&
f->dirty;
221 if (
f)
f->dirty =
false;
225 for (
auto &
f : fields_)
f.dirty =
false;
230 const int n =
static_cast<int>(fields_.size());
231 if (
n == 0)
return "";
232 for (
int k = 0; k <
n; ++k) {
233 int i = (pollCursor_ + k) %
n;
234 if (fields_[i].
dirty) {
235 fields_[i].dirty =
false;
236 pollCursor_ = (i + 1) %
n;
237 return fields_[i].id;
EVENGINE_API_FOUNDATION public API.
void addFloat(const std::string &id, const std::string &label, float value, float minV, float maxV, float step)
Adds float.
std::string getFieldKind(int index) const
Returns the field kind.
bool isDirty(const std::string &id) const
True when dirty.
void setFloat3(const std::string &id, float x, float y, float z)
Sets the float 3.
float getFloatStep(const std::string &id) const
Returns the float step.
std::string getFieldLabel(int index) const
Returns the field label.
float getFloat3X(const std::string &id) const
Returns the float 3 x.
void setChoice(const std::string &id, const std::string &value)
Sets the choice.
std::string getString(const std::string &id) const
Returns the string.
void clearDirty(const std::string &id)
Clears dirty.
std::string pollChangedId()
Returns next dirty field id, or "" if none.
void setFloat(const std::string &id, float value)
Sets the float.
std::string getChoice(const std::string &id) const
Returns the choice.
std::string getChoicesCsv(const std::string &id) const
Returns the choices csv.
void addString(const std::string &id, const std::string &label, const std::string &value)
Adds string.
float getFloat(const std::string &id) const
Returns the float.
float getFloat3Z(const std::string &id) const
Returns the float 3 z.
std::string getFieldId(int index) const
Returns the field id.
void setString(const std::string &id, const std::string &value)
Sets the string.
void setBool(const std::string &id, bool value)
Sets the bool.
void addBool(const std::string &id, const std::string &label, bool value)
Adds bool.
float getFloatMax(const std::string &id) const
Returns the float max.
float getFloatMin(const std::string &id) const
Returns the float min.
void addFloat3(const std::string &id, const std::string &label, float x, float y, float z)
Adds float 3.
bool getBool(const std::string &id) const
Returns the bool.
void addChoice(const std::string &id, const std::string &label, const std::string &choicesCsv, const std::string &selected)
Adds choice.
void clearAllDirty()
Clears all dirty.
float getFloat3Y(const std::string &id) const
Returns the float 3 y.