-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrameworkParameterInterface.h
112 lines (95 loc) · 2.37 KB
/
FrameworkParameterInterface.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#pragma once
#include "CommonInterfaces/CommonParameterInterface.h"
#include <vector>
class FrameworkParameterInterface : public CommonParameterInterface
{
public:
enum ParamType
{
kParamType_Undefined,
kParamType_Slider,
kParamType_Button,
kParamType_ComboBox
};
struct Param
{
ParamType type = kParamType_Undefined;
std::string name;
SliderParams slider;
ButtonParams button;
ComboBoxParams comboBox;
float value = 0.f;
Param()
: slider(nullptr, nullptr)
, button(nullptr, 0, false)
, comboBox()
{
}
};
std::vector<Param> m_params;
public:
virtual ~FrameworkParameterInterface() override final { }
virtual void registerSliderFloatParameter(SliderParams& params) override final
{
Param p;
p.type = kParamType_Slider;
p.slider = params;
p.name = params.m_name;
m_params.push_back(p);
}
virtual void registerButtonParameter(ButtonParams& params) override final
{
Param p;
p.type = kParamType_Button;
p.button = params;
p.value = params.m_initialState ? 1.f : 0.f;
p.name = params.m_name;
m_params.push_back(p);
}
virtual void registerComboBox(ComboBoxParams& params) override final
{
Param p;
p.type = kParamType_ComboBox;
p.comboBox = params;
p.value = params.m_startItem;
m_params.push_back(p);
}
virtual void syncParameters() override final
{
for (auto & param : m_params)
{
if (param.type == kParamType_Slider)
{
float value = *param.slider.m_paramValuePointer;
if (value < param.slider.m_minVal)
value = param.slider.m_minVal;
if (value > param.slider.m_maxVal)
value = param.slider.m_maxVal;
*param.slider.m_paramValuePointer = value;
if (param.slider.m_callback != nullptr)
param.slider.m_callback(value, param.slider.m_userPointer);
}
else if (param.type == kParamType_ComboBox)
{
int value = (int)param.value;
if (value < 0)
value = 0;
if (value > param.comboBox.m_numItems - 1)
value = param.comboBox.m_numItems - 1;
param.value = value;
if (param.comboBox.m_callback != nullptr)
{
param.comboBox.m_callback(
param.comboBox.m_comboboxId,
param.comboBox.m_items[value],
param.comboBox.m_userPointer);
}
}
}
}
virtual void removeAllParameters() override final
{
m_params.clear();
}
virtual void setSliderValue(int sliderIndex, double sliderValue) override final { }
};