Skip to content

Commit 7f54d6b

Browse files
committed
ui cleanup
1 parent 3ec9319 commit 7f54d6b

File tree

12 files changed

+143
-58
lines changed

12 files changed

+143
-58
lines changed

clapeze/include/clapeze/params/baseParameter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ struct BaseParam {
1313
virtual bool ToText(double rawValue, etl::span<char>& outTextBuf) const = 0;
1414
virtual bool FromText(std::string_view text, double& outRawValue) const = 0;
1515
virtual double GetRawDefault() const = 0;
16+
virtual const std::string& GetName() const = 0;
17+
virtual const std::string& GetTooltip() const = 0;
1618

1719
const std::string& GetModule() const { return mModule; }
1820
void SetModule(std::string_view module) { mModule = module; }
1921
std::string mModule;
2022
};
21-
} // namespace clapeze
23+
} // namespace clapeze

clapeze/include/clapeze/params/baseParametersFeature.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class BaseParametersFeature : public BaseFeature {
6363
TMainHandle& GetMainHandle();
6464

6565
size_t GetNumParams() const;
66+
void ResetAllParamsToDefault();
6667

6768
protected:
6869
PluginHost& mHost;
@@ -182,6 +183,14 @@ template <BaseMainHandle TMainHandle, BaseAudioHandle TAudioHandle>
182183
size_t BaseParametersFeature<TMainHandle, TAudioHandle>::GetNumParams() const {
183184
return mNumParams;
184185
}
186+
template <BaseMainHandle TMainHandle, BaseAudioHandle TAudioHandle>
187+
void BaseParametersFeature<TMainHandle, TAudioHandle>::ResetAllParamsToDefault() {
188+
for(clap_id id = 0; id < mNumParams; ++id) {
189+
mMain.SetRawValue(id, GetBaseParam(id)->GetRawDefault());
190+
//RequestClear(id); // resets automation? idk if necessary
191+
}
192+
RequestRescan(CLAP_PARAM_RESCAN_VALUES);
193+
}
185194

186195
template <BaseMainHandle TMainHandle, BaseAudioHandle TAudioHandle>
187196
/*static*/ uint32_t BaseParametersFeature<TMainHandle, TAudioHandle>::_count(const clap_plugin_t* plugin) {

clapeze/include/clapeze/params/parameterTypes.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ struct NumericParam : public BaseParam {
5757
std::string_view mUnit = "")
5858
: mName(mName), mCurve(curve), mMin(mMin), mMax(mMax), mDefaultValue(mDefaultValue), mUnit(mUnit) {}
5959
bool FillInformation(clap_id id, clap_param_info_t* information) const override;
60+
const std::string& GetName() const override { return mName; }
61+
const std::string& GetTooltip() const override { static const std::string kEmpty = ""; return kEmpty; }
6062
double GetRawDefault() const override;
6163
bool ToText(double rawValue, etl::span<char>& outTextBuf) const override;
6264
bool FromText(std::string_view text, double& outRawValue) const override;
@@ -108,6 +110,8 @@ struct IntegerParam : public BaseParam {
108110
mUnitSingular(mUnitSingular) {}
109111

110112
bool FillInformation(clap_id id, clap_param_info_t* information) const override;
113+
const std::string& GetName() const override { return mName; }
114+
const std::string& GetTooltip() const override { static const std::string kEmpty = ""; return kEmpty; }
111115
double GetRawDefault() const override;
112116
bool ToText(double rawValue, etl::span<char>& outTextBuf) const override;
113117
bool FromText(std::string_view text, double& outRawValue) const override;
@@ -144,6 +148,8 @@ struct EnumParam : public BaseParam {
144148

145149
return true;
146150
}
151+
const std::string& GetName() const override { return mName; }
152+
const std::string& GetTooltip() const override { static const std::string kEmpty = ""; return kEmpty; }
147153
double GetRawDefault() const override {
148154
double rawDefault{};
149155
FromValue(mDefaultValue, rawDefault);

daw/src/gui/debugui.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,16 @@ class BaseParamKnob : public kitgui::Knob {
9090
protected:
9191
const std::string& GetName() const override { return mName; }
9292
double GetDefault() const override { return mParam.GetRawDefault(); }
93-
std::string FormatValueText(double value) const override {
93+
std::string ToValueText(double value) const override {
9494
std::string buf(20, '\0');
9595
etl::span<char> span{buf.data(), buf.size()};
9696
mParam.ToText(value, span);
9797
buf = buf.c_str();
9898
return buf;
9999
}
100+
bool FromValueText(std::string_view text, double& value) const override {
101+
return mParam.FromText(text, value);
102+
}
100103

101104
private:
102105
const clapeze::BaseParam& mParam;

daw/src/kitskeys/kitskeys.cpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,13 @@ class GuiApp : public kitgui::BaseApp {
421421
for (const auto& knobInfo : knobs) {
422422
clap_id id = static_cast<clap_id>(knobInfo.param);
423423
mKnobs.push_back(std::make_unique<kitgui::BaseParamKnob>(*mParams.GetBaseParam(id), id, knobInfo.node));
424-
auto pos = mScene->GetObjectScreenPositionByName(knobInfo.node);
425-
if (pos) {
424+
auto objectInfo = mScene->GetObjectScreenPositionByName(knobInfo.node);
425+
if (objectInfo) {
426426
// TODO: to size the knob appropriately we need the bounding range of the object and then transform the
427427
// corners of that into screen positions. for now, hardcoded.
428428
float w = 40.0f * scale;
429429
float hw = w * 0.5f;
430-
mKnobs.back()->mPos = {pos->x() - hw, pos->y() - hw};
430+
mKnobs.back()->mPos = {objectInfo->pos.x() - hw, objectInfo->pos.y() - hw};
431431
mKnobs.back()->mWidth = w;
432432
mKnobs.back()->mShowDebug = false;
433433
}
@@ -439,13 +439,13 @@ class GuiApp : public kitgui::BaseApp {
439439
for (const auto& knobInfo : toggles) {
440440
clap_id id = static_cast<clap_id>(knobInfo.param);
441441
mToggles.push_back(std::make_unique<kitgui::BaseParamToggle>(*mParams.GetBaseParam(id), id, knobInfo.node));
442-
auto pos = mScene->GetObjectScreenPositionByName(knobInfo.node);
443-
if (pos) {
442+
auto objectInfo = mScene->GetObjectScreenPositionByName(knobInfo.node);
443+
if (objectInfo) {
444444
// TODO: to size the knob appropriately we need the bounding range of the object and then transform the
445445
// corners of that into screen positions. for now, hardcoded.
446446
float w = 40.0f * scale;
447447
float hw = w * 0.5f;
448-
mToggles.back()->mPos = {pos->x() - hw, pos->y() - hw};
448+
mKnobs.back()->mPos = {objectInfo->pos.x() - hw, objectInfo->pos.y() - hw};
449449
mToggles.back()->mWidth = w;
450450
mToggles.back()->mShowDebug = false;
451451
}
@@ -490,14 +490,6 @@ class GuiApp : public kitgui::BaseApp {
490490
void OnUpdate() override {
491491
mParams.FlushFromAudio();
492492
mScene->Update();
493-
// imgui
494-
if (ImGui::BeginMenuBar()) {
495-
if (ImGui::BeginMenu("View")) {
496-
ImGui::MenuItem("Debug Window", NULL, &mShowDebugWindow);
497-
ImGui::EndMenu();
498-
}
499-
}
500-
501493
for (auto& knob : mKnobs) {
502494
clap_id id = knob->GetParamId();
503495
double raw = mParams.GetMainHandle().GetRawValue(id);
@@ -511,7 +503,7 @@ class GuiApp : public kitgui::BaseApp {
511503
raw = std::trunc(raw);
512504
}
513505
auto normalizedValue = kitdsp::clamp((raw - knob->mMin) / (knob->mMax - knob->mMin), 0.0, 1.0);
514-
constexpr float maxTurn = kitdsp::kPi * 2.0f * 0.25f;
506+
constexpr float maxTurn = kitdsp::kPi * 2.0f * 0.75f;
515507
mScene->SetObjectRotationByName(knob->GetSceneNode(),
516508
(static_cast<float>(normalizedValue) - 0.5f) * -maxTurn, kitgui::Scene::Axis::Y);
517509
}
@@ -531,12 +523,31 @@ class GuiApp : public kitgui::BaseApp {
531523
}
532524

533525
void OnGuiUpdate() override {
526+
if (ImGui::BeginMainMenuBar()) {
527+
ImGui::MenuItem("Help/About", NULL, &mShowHelpWindow);
528+
if(ImGui::MenuItem("Reset All")) {
529+
mParams.ResetAllParamsToDefault();
530+
}
531+
ImGui::MenuItem("Debug", NULL, &mShowDebugWindow);
532+
ImGui::EndMainMenuBar();
533+
}
534+
534535
if (ImGui::IsKeyPressed(ImGuiKey_GraveAccent)) {
535536
mShowDebugWindow = !mShowDebugWindow;
536537
}
537538

539+
if (mShowHelpWindow) {
540+
if (ImGui::Begin("Help", &mShowHelpWindow)) {
541+
ImGui::TextWrapped("KitsKeys is an intentionally simple-ish virtual analog polysynth. This is the first one I'm really dumping effort into the UI for so extra feedback there is very appreciated :)");
542+
ImGui::BulletText("Shift-click for fine adjustment");
543+
ImGui::BulletText("double-click to reset to default");
544+
ImGui::BulletText("right-click to get a text input");
545+
}
546+
ImGui::End();
547+
}
548+
538549
if (mShowDebugWindow) {
539-
if (ImGui::Begin("Debug Window", &mShowDebugWindow)) {
550+
if (ImGui::Begin("Debugger", &mShowDebugWindow)) {
540551
DebugParamList();
541552
}
542553
ImGui::End();
@@ -550,7 +561,8 @@ class GuiApp : public kitgui::BaseApp {
550561
std::unique_ptr<kitgui::Scene> mScene;
551562
std::vector<std::unique_ptr<kitgui::BaseParamKnob>> mKnobs;
552563
std::vector<std::unique_ptr<kitgui::BaseParamToggle>> mToggles;
553-
bool mShowDebugWindow = true;
564+
bool mShowDebugWindow = false;
565+
bool mShowHelpWindow = false;
554566
};
555567
#endif
556568

kitgui/include/kitgui/controls/knob.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ class Knob {
3030
return s;
3131
}
3232
virtual double GetDefault() const { return 0.5; }
33-
virtual std::string FormatValueText(double value) const { return fmt::format("{}", value); }
33+
virtual std::string ToValueText(double value) const { return fmt::format("{}", value); }
34+
virtual bool FromValueText(std::string_view str, double& value) const { return false; /* TODO */ }
3435

3536
private:
3637
static constexpr float kPi = 3.14159265359;
3738
};
38-
} // namespace kitgui
39+
} // namespace kitgui

kitgui/include/kitgui/gfx/scene.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
namespace kitgui {
99
class Context;
10+
11+
struct ObjectScreenPosition {
12+
kitgui::Vector2 pos;
13+
kitgui::Vector2 size;
14+
};
1015
/**
1116
* A scene represents a drawable instance of a loaded gltf/glb scene.
1217
* gltf scenes include drawable geometry, like 3d models, as well as camera and lighting information.
@@ -31,7 +36,7 @@ class Scene {
3136
// These methods are added as needed, so no rhyme or reason to what's supported really
3237
void PlayAnimationByName(std::string_view name);
3338
void SetObjectRotationByName(std::string_view name, float angleRadians, Axis axis);
34-
std::optional<kitgui::Vector2> GetObjectScreenPositionByName(std::string_view name);
39+
std::optional<ObjectScreenPosition> GetObjectScreenPositionByName(std::string_view name);
3540

3641
private:
3742
struct Impl;

kitgui/src/controls/knob.cpp

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
#include <imgui.h>
44
#include <imgui_internal.h>
5+
#include <misc/cpp/imgui_stdlib.h>
56
#include <cmath>
67
#include <string>
78
#include <algorithm>
89

910
namespace kitgui {
1011
bool Knob::Update(double& rawValueInOut) {
1112
// roughly adapted from https://github.com/altschuler/imgui-knobs/tree/main
12-
13-
auto itemWidth = mWidth ? (*mWidth) * ImGui::GetIO().FontGlobalScale : ImGui::GetTextLineHeight() * 2.0f;
13+
float scale = ImGui::GetIO().FontGlobalScale;
14+
auto itemWidth = mWidth ? (*mWidth) * scale : ImGui::GetTextLineHeight() * 2.0f;
1415
ImVec2 screen_pos = mPos ? ImVec2{mPos->x(), mPos->y()} : ImGui::GetCursorScreenPos();
1516

1617
ImGui::PushID(static_cast<void*>(this));
@@ -39,20 +40,51 @@ bool Knob::Update(double& rawValueInOut) {
3940
auto is_hovered = ImGui::IsItemHovered();
4041

4142
// responses
42-
if (is_active) {
43+
if (is_active || ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip)) {
4344
// tooltip counts as a window! so this works
44-
ImGui::SetNextWindowPos({screen_pos.x + itemWidth, screen_pos.y + (itemWidth * 0.5f)});
45-
ImGui::SetTooltip("%s", FormatValueText(rawValueInOut).c_str());
46-
} else if (ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip)) {
47-
// descriptive tooltip
48-
ImGui::SetTooltip("%s", GetName().c_str());
45+
float view_width = ImGui::GetMainViewport()->Size.x;
46+
bool pivot_left = screen_pos.x > view_width * 0.70f;
47+
if(pivot_left) {
48+
ImGui::SetNextWindowPos({screen_pos.x, screen_pos.y + (itemWidth * 0.5f)}, ImGuiCond_Always, {1.0, 0.0});
49+
}
50+
else {
51+
ImGui::SetNextWindowPos({screen_pos.x + itemWidth, screen_pos.y + (itemWidth * 0.5f)}, ImGuiCond_Always, {0.0, 0.0});
52+
}
53+
ImGui::SetNextWindowSize({0.0f, 0.0f}, ImGuiCond_Always);
54+
ImGui::SetTooltip("%s: %s", GetName().c_str(), ToValueText(rawValueInOut).c_str());
4955
}
5056

51-
if (is_active && ImGui::IsMouseDoubleClicked(0)) {
57+
if (is_active && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
5258
rawValueInOut = GetDefault();
5359
value_changed = true;
5460
}
5561

62+
static std::string sValueText{};
63+
static bool sPopupOpened{};
64+
if (is_hovered && ImGui::IsMouseReleased(ImGuiMouseButton_Right)) {
65+
ImGui::OpenPopup("editknob");
66+
sValueText = ToValueText(rawValueInOut);
67+
sPopupOpened = true;
68+
}
69+
70+
ImGui::SetNextWindowSize({160.0f*scale, 0.0f});
71+
if (ImGui::BeginPopup("editknob"))
72+
{
73+
if(ImGui::InputText("##", &sValueText, ImGuiInputTextFlags_EnterReturnsTrue)) {
74+
if(FromValueText(sValueText, rawValueInOut)) {
75+
// TODO validation
76+
value_changed = true;
77+
}
78+
ImGui::CloseCurrentPopup();
79+
}
80+
if (sPopupOpened) {
81+
// doesn't seem to work :/
82+
//ImGui::SetKeyboardFocusHere(-1);
83+
sPopupOpened = false;
84+
}
85+
ImGui::EndPopup();
86+
}
87+
5688
if (mShowDebug) {
5789
// Drawing using imgui primitives
5890
auto angle_min = mMinAngleRadians;

kitgui/src/gfx/drawables.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,4 @@ Magnum::SceneGraph::Drawable3D* DrawableCache::CreateDrawableFromMesh(MaterialCa
270270
}
271271
}
272272

273-
} // namespace kitgui
273+
} // namespace kitgui

kitgui/src/gfx/meshes.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <Magnum/GL/Mesh.h>
88
#include <Magnum/MeshTools/Compile.h>
99
#include <Magnum/MeshTools/GenerateIndices.h>
10+
#include <Magnum/MeshTools/BoundingVolume.h>
1011
#include <Magnum/Trade/AbstractImporter.h>
1112
#include <Magnum/Trade/MeshData.h>
1213
#include <fmt/format.h>
@@ -138,6 +139,7 @@ void MeshCache::LoadMeshes(Magnum::Trade::AbstractImporter& importer) {
138139
}
139140
mesh.mesh = MeshTools::compile(*meshData, flags);
140141
mesh.debugName = meshName;
142+
mesh.boundingBox = Magnum::MeshTools::boundingRange(meshData->positions3DAsArray());
141143
}
142144
}
143-
} // namespace kitgui
145+
} // namespace kitgui

0 commit comments

Comments
 (0)