Skip to content

Commit

Permalink
Convert SceneEl in meshimporter to use CStringView (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Nov 9, 2023
1 parent 13915dc commit 350fadb
Showing 1 changed file with 24 additions and 38 deletions.
62 changes: 24 additions & 38 deletions src/OpenSimCreator/UI/Tabs/MeshImporterTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,9 @@ namespace
// adopted from: https://easings.net/#easeOutElastic

constexpr float c4 = 2.0f*std::numbers::pi_v<float> / 3.0f;
float const normalized = osc::Clamp(x, 0.0f, 1.0f);

if (x <= 0.0f)
{
return 0.0f;
}

if (x >= 1.0f)
{
return 1.0f;
}

return std::pow(2.0f, -5.0f*x) * std::sin((x*10.0f - 0.75f) * c4) + 1.0f;
return std::pow(2.0f, -5.0f*normalized) * std::sin((normalized*10.0f - 0.75f) * c4) + 1.0f;
}

// returns the transform, but rotated such that the given axis points along the
Expand Down Expand Up @@ -589,34 +580,29 @@ namespace
return m_ID;
}

char const* GetNameCStr() const
{
return m_Name.c_str();
}

std::string_view GetNameSV() const
CStringView getName() const
{
return m_Name;
}

char const* GetNamePluralizedCStr() const
CStringView getNamePluralized() const
{
return m_NamePluralized.c_str();
return m_NamePluralized;
}

char const* GetNameOptionallyPluralized() const
CStringView getNameOptionallyPluralized() const
{
return m_NameOptionallyPluralized.c_str();
return m_NameOptionallyPluralized;
}

char const* GetIconCStr() const
CStringView getIconUTF8() const
{
return m_Icon.c_str();
return m_Icon;
}

char const* GetDescriptionCStr() const
CStringView getDescription() const
{
return m_Description.c_str();
return m_Description;
}

int32_t FetchAddUniqueCounter() const
Expand Down Expand Up @@ -648,7 +634,7 @@ namespace
std::string GenerateName(SceneElClass const& c)
{
std::stringstream ss;
ss << c.GetNameSV() << c.FetchAddUniqueCounter();
ss << c.getName() << c.FetchAddUniqueCounter();
return std::move(ss).str();
}

Expand Down Expand Up @@ -2484,19 +2470,19 @@ namespace
}
void operator()(MeshEl const& m) final
{
m_SS << '(' << m.GetClass().GetNameSV() << ", " << m.getPath().filename().string() << ", attached to " << GetLabel(m_Mg, m.getParentID()) << ')';
m_SS << '(' << m.GetClass().getName() << ", " << m.getPath().filename().string() << ", attached to " << GetLabel(m_Mg, m.getParentID()) << ')';
}
void operator()(BodyEl const& b) final
{
m_SS << '(' << b.GetClass().GetNameSV() << ')';
m_SS << '(' << b.GetClass().getName() << ')';
}
void operator()(JointEl const& j) final
{
m_SS << '(' << j.GetSpecificTypeName() << ", " << GetLabel(m_Mg, j.getChildID()) << " --> " << GetLabel(m_Mg, j.getParentID()) << ')';
}
void operator()(StationEl const& s) final
{
m_SS << '(' << s.GetClass().GetNameSV() << ", attached to " << GetLabel(m_Mg, s.getParentID()) << ')';
m_SS << '(' << s.GetClass().getName() << ", attached to " << GetLabel(m_Mg, s.getParentID()) << ')';
}

private:
Expand Down Expand Up @@ -6014,7 +6000,7 @@ namespace
ImGui::BeginTooltip();
ImGui::TextUnformatted(se->GetLabel().c_str());
ImGui::SameLine();
ImGui::TextDisabled("(%s, click to choose)", se->GetClass().GetNameCStr());
ImGui::TextDisabled("(%s, click to choose)", se->GetClass().getName().c_str());
ImGui::EndTooltip();
}
}
Expand Down Expand Up @@ -7279,11 +7265,11 @@ class osc::MeshImporterTab::Impl final : public LayerHost {

void DrawSceneElContextMenuContentHeader(SceneEl const& e)
{
ImGui::Text("%s %s", e.GetClass().GetIconCStr(), e.GetLabel().c_str());
ImGui::Text("%s %s", e.GetClass().getIconUTF8().c_str(), e.GetLabel().c_str());
ImGui::SameLine();
ImGui::TextDisabled("%s", GetContextMenuSubHeaderText(m_Shared->GetModelGraph(), e).c_str());
ImGui::SameLine();
osc::DrawHelpMarker(e.GetClass().GetNameCStr(), e.GetClass().GetDescriptionCStr());
osc::DrawHelpMarker(e.GetClass().getName(), e.GetClass().getDescription());
ImGui::Separator();
}

Expand All @@ -7302,7 +7288,7 @@ class osc::MeshImporterTab::Impl final : public LayerHost {
if (ImGui::IsItemDeactivatedAfterEdit())
{
std::stringstream ss;
ss << "changed " << e.GetClass().GetNameSV() << " name";
ss << "changed " << e.GetClass().getName() << " name";
m_Shared->CommitCurrentModelGraph(std::move(ss).str());
}
ImGui::SameLine();
Expand Down Expand Up @@ -8102,9 +8088,9 @@ class osc::MeshImporterTab::Impl final : public LayerHost {
{
ModelGraph& mg = m_Shared->UpdModelGraph();

ImGui::Text("%s %s", c.GetIconCStr(), c.GetNamePluralizedCStr());
ImGui::Text("%s %s", c.getIconUTF8().c_str(), c.getNamePluralized().c_str());
ImGui::SameLine();
osc::DrawHelpMarker(c.GetNamePluralizedCStr(), c.GetDescriptionCStr());
osc::DrawHelpMarker(c.getNamePluralized(), c.getDescription());
SpacerDummy();
ImGui::Indent();

Expand Down Expand Up @@ -8160,7 +8146,7 @@ class osc::MeshImporterTab::Impl final : public LayerHost {

if (empty)
{
ImGui::TextDisabled("(no %s)", c.GetNamePluralizedCStr());
ImGui::TextDisabled("(no %s)", c.getNamePluralized().c_str());
}
ImGui::Unindent();
}
Expand Down Expand Up @@ -8205,7 +8191,7 @@ class osc::MeshImporterTab::Impl final : public LayerHost {
auto& e = mg.AddEl<StationEl>(UIDT<StationEl>{}, c_GroundID, Vec3{}, GenerateName(StationEl::Class()));
SelectOnly(mg, e);
}
osc::DrawTooltipIfItemHovered("Add Station", StationEl::Class().GetDescriptionCStr());
osc::DrawTooltipIfItemHovered("Add Station", StationEl::Class().getDescription());

ImGui::PopStyleVar();
}
Expand Down Expand Up @@ -8507,7 +8493,7 @@ class osc::MeshImporterTab::Impl final : public LayerHost {
void DrawSceneElTooltip(SceneEl const& e) const
{
ImGui::BeginTooltip();
ImGui::Text("%s %s", e.GetClass().GetIconCStr(), e.GetLabel().c_str());
ImGui::Text("%s %s", e.GetClass().getIconUTF8().c_str(), e.GetLabel().c_str());
ImGui::SameLine();
ImGui::TextDisabled("%s", GetContextMenuSubHeaderText(m_Shared->GetModelGraph(), e).c_str());
ImGui::EndTooltip();
Expand Down

0 comments on commit 350fadb

Please sign in to comment.